dsh-provider-guard: Ensuring Model Calls Follow the UI-Selected Provider

Introduction

DeepSeek Harness (DSH) model invocation paths are often scattered across the main loop, auxiliary calls (title generation, compression, sub-agents, memory, web search, etc.). If each path hardcodes its own provider, cross-provider switching or fallback will silently occur in the background, making costs, routing, and logging uncontrollable. This plugin solves the problem by unifying the provider: it ensures all model calls follow the provider you select in the UI, without automatic switching or fallback, while also intercepting other providers’ dedicated endpoints—keeping regular network traffic unaffected.

What It Is

dsh-provider-guard is a DSH bundle plugin that enforces model calls to stay consistent with the provider currently selected in the UI. It intercepts main-loop requests and auxiliary calls that don’t match the current selection, and handles them according to configuration (block, reroute, or log only). The maintainer is tanqvv. The plugin runs with DSH process privileges; you should review the source code and license before installation.

Core Features

1. Follow UI Provider Selection

  • Main-loop requests are DSH’s deep-frozen llm/stream calls. The plugin checks whether the request’s provider matches the current UI selection. If it matches, the request is allowed through and logged; if not, it is handled according to blockAutoSwitch.
  • When you switch providers, the next main-loop request updates the record—no restart needed.
  • Auxiliary calls use the UI’s agentDefaultModel.currentSelection() as the reference; if there’s a mismatch, they are handled per the onForeignProvider configuration.

2. No Auto-Switch / No Fallback

  • Retries within the same provider are controlled by DSH’s retryPolicy (default: 5 attempts). The plugin will not attempt other providers after a failure.
  • If you want to stop on the first failure, set that provider’s retryPolicy.maxRetries to 0.
  • On a terminal failure, a notice is appended after the error: [dsh-provider-guard] No automatic switching or fallback to other providers. If this round ultimately fails, please manually switch providers in the model selector and retry.

3. Intercept Other Providers’ Dedicated Endpoints

  • Intercepts other providers’ model endpoints (e.g., DeepSeek web search api.deepseek.com/v1/tools/search, OpenAI image generation, etc.), controlled by blockForeignProviderHosts.
  • Regular network traffic (npm updates, WeChat login, dsh-remote heartbeats, general web scraping) is not affected.
  • Local loopback (localhost / 127.0.0.1 / ::1) is allowed by default; RFC1918 and other private networks must be enabled via allowPrivateNetwork.

4. Auxiliary Call Handling Strategies

onForeignProvider supports:

  • block (default): Immediately throws PROVIDER_MISMATCH. The chat box displays which auxiliary call triggered it, the provider it originally intended to use, and a note that “no automatic switching occurred.”
  • reroute: Clones the request, replaces it with the current provider and current model, then routes through llm.stream, using Symbol.for('dsh-provider-guard.bypass') to prevent recursion. Must be explicitly enabled.
  • audit: Log only; no rerouting.

5. Status Check

After installation, you can use the following command to check the current status:

provider_guard_status

You should see output similar to:

Following UI selection: Yes
Currently active: opencode-go / deepseek-v4.1-flash
Current provider endpoint: opencode.ai
Cross-provider model calls: reroute (routed to the currently selected model)

Installation & Activation

This is a standard DSH bundle package, supporting three installation methods.

Install via npm (after release)

dsh plugin --profile desktop add dsh-provider-guard
dsh plugin --profile web add dsh-provider-guard

Install via GitHub

dsh plugin --profile desktop add github:tanqvv/dsh-provider-guard#v0.2.3
dsh plugin --profile web add github:tanqvv/dsh-provider-guard#v0.2.3

Install via local tarball

dsh plugin --profile desktop add /path/to/dsh-provider-guard-0.2.3.tgz
dsh plugin --profile web add /path/to/dsh-provider-guard-0.2.3.tgz

After installation, the plugin is automatically added to dsh.profile.bundles and loads the default configuration (follow selection, block, blockAutoSwitch).

Optional: Write Profile Overrides

node /path/to/dsh-provider-guard/scripts/install.mjs --apply --bundle

Or double-click scripts/install.command. --bundle only writes profile overrides; --apply without --bundle is the fallback mode, which copies the plugin to $DSH_HOME/plugins and loads it via an absolute path.

Configuration Reference

Key Default Description
followSelection true Follow the UI’s current provider
fallbackProvider Installer writes current provider Fallback when UI selection cannot be read
fallbackModel Installer writes current model Model used during reroute
onForeignProvider block block (stop) / reroute (explicit reroute) / audit (log only)
blockAutoSwitch true Block when main-loop provider doesn’t match current selection
blockForeignProviderHosts true Intercept other providers’ model endpoints
providerHosts Built-in table Custom provider endpoints, e.g. { acme: ["gateway.acme.example"] }
allowLoopback true Allow localhost / 127.0.0.1 / ::1
allowPrivateNetwork false Allow RFC1918 and other private networks
mode enforce enforce is active; audit is log-only
auditLog $DSH_HOME/provider-guard/audit.jsonl Set to false to disable
logAllowed false Log allowed requests as well
maxRecent 200 Number of entries retained by the status tool

Built-in known provider endpoints (excerpt):

  • deepseek-official / deepseek → api.deepseek.com
  • opencode-go / opencode → opencode.ai
  • openai → api.openai.com
  • anthropic → api.anthropic.com
  • openrouter → openrouter.ai
  • google → generativelanguage.googleapis.com / aiplatform.googleapis.com
  • zai → api.z.ai / open.bigmodel.cn
  • moonshotai / moonshotai-cn → api.moonshot.ai / api.moonshot.cn
  • kimi-coding → api.kimi.com
  • minimax / minimax-cn → api.minimax.io / api.minimaxi.com

Add custom gateways via providerHosts; otherwise their dedicated endpoints won’t be recognized, and you’ll only have the llm/stream provider gate as a safety net.

Use Cases & Notes

Suitable for scenarios requiring unified provider cost and routing control, and to avoid unexpected switching or fallback. Review the source code and license before installation to ensure it fits your use case. The plugin runs with DSH process privileges; review the source code and license before installation.

Uninstall

# 1. Remove profile overrides (optional; the bundle will still load with default config if present)
node /path/to/dsh-provider-guard/scripts/install.mjs --uninstall --apply

# 2. Remove the bundle
dsh plugin --profile desktop remove dsh-provider-guard
dsh plugin --profile web remove dsh-provider-guard

--uninstall only removes the managed block from the profile; the bundle must be removed via dsh plugin remove to be fully taken out of dsh.profile.bundles and node_modules.

Boundaries

  • Only one provider is allowed at a time: both the main-loop gate and endpoint checks use the UI’s current selection as the reference. In multi-session scenarios, only the most recent UI selection’s provider can continue running.
  • Multi-session endpoint checks: HTTP endpoints without session context (e.g., web search) are judged against the UI’s current selection, not the originating session.
  • Subprocesses / Electron main process: bash subprocesses (curl, MCP, git) and Electron main process update/account traffic are outside the plugin’s process and not covered.
  • Reroute model capabilities: Auxiliary calls are swapped to the currently selected model. If the original call included images, tools, or special reasoning effort, the target model may reject it, and the error will be returned directly.
  • DNS / UDP: Not intercepted; the plugin only handles model calls and provider endpoints.

Development

node --test test/*.test.mjs
node scripts/smoke-provider.mjs   # Reroute / main-loop trust with real LlmRuntime

Summary

dsh-provider-guard unifies the provider, prevents auto-switching, and intercepts dedicated endpoints, ensuring model calls stay consistent with the UI selection—making cost, routing, and log management easier. Installation and configuration are covered by official documentation with examples; you can choose the block, reroute, or audit strategy as needed.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye