Перейти к основному содержимому
W

dsh-openai-gateway

wutao-coder/dsh-openai-gateway

OpenAI-compatible agent gateway backed by real DSH agent sessions. Chat Completions and Responses endpoints with streaming, per-agent model routing across providers, persistent role sessions in SQLite, auto-managed per-agent workspaces, and streamed execution progress so long tasks never stall the client.

Установка

dsh plugin --profile web add github:wutao-coder/dsh-openai-gateway

README

dsh-openai-gateway

OpenAI-compatible HTTP surface for DeepSeek Harness, backed by real DSH agent sessions — tools, bash/file access, skills and preset personalities all included. This is an agent gateway, not a thin LLM proxy.

Origin

This plugin is a fork of the community project dsh-openai-api (first published in August 2026, maintained by its original author). The upstream project provided the most basic OpenAI-compatible endpoints plus a sidebar port display; this project is a large-scale rewrite and extension on top of it — role-session persistence, per-preset model routing with cross-provider resolution, a SQLite session map, automatic workspace management, and streamed execution progress with heartbeats are all additions of this fork. The scope and architecture outgrew the original project, so it now continues independently as dsh-openai-gateway.

Upgrading from dsh-openai-api needs no manual steps: deprecated config keys (cwd, sessionMapPath) are ignored, and the legacy openai-api/ data directory (session map + workspaces) is merged automatically into openai-gateway/ on first start.

Endpoints

Once installed into a profile, the harness web server additionally serves (prefix configurable, default /v1):

EndpointPurpose
POST /v1/chat/completionsChat Completions API (streaming + non-streaming)
POST /v1/responsesResponses API subset (streaming + non-streaming)
GET /v1/modelsAvailable models (= the agent preset list)

A sidebar API row shows the base URL, auth status, a copy-ready example and a one-click reachability probe.

Session model

  • model = agent preset id. Whatever model the client requests, the same-named agent preset serves it; the preset list is exactly what /v1/models returns.
  • Session identity is the (API key tenant, preset, X-Session-Id) triple: keys isolate tenants; the optional X-Agent-Preset header selects the preset; X-Session-Id (e.g. a role name) splits roles, and each role resumes its last session across restarts (archived sessions are recreated automatically).
  • The first request seeds a new session with the client's full message array; subsequent requests send only the latest turn.
  • Client tools / function_call are rejected — the agent decides which tools to use, not the client.

Model routing

LLM routing priority at session creation:

modelByPreset[preset id] → modelOverride → host default model
  • modelByPreset lets each preset use a different model, possibly from another provider — the plugin aggregates every provider's model catalog and resolves the owning provider automatically (e.g. code on a DeepSeek account, standard on Z.ai).
  • Online config changes take effect immediately (saving from the panel reloads the plugin); existing sessions keep the model they were created with.

Workspaces (automatic, not configurable)

Every agent preset gets its own workspace:

$DSH_HOME/openai-gateway/workspaces/<preset id>

Created on first use and registered in the web UI under the agent's name; sessions attach to the matching workspace group automatically.

Streaming

  • delta.content: committed assistant text (one frame per committed message, not per token).
  • delta.reasoning_content: the execution progress stream — tool calls (⏺ tool args), tool completions and thinking blocks stream here in real time (DeepSeek-compatible field; mainstream clients render it as a collapsible thinking pane). Long tasks no longer stall the client.
  • Heartbeat: streaming connections idle for over 15 seconds receive : keep-alive comment frames so proxies/gateways don't time out.
  • Mid-stream failures end with an explicit error frame (event: error on Responses), never a silent hang.
  • Progress forwarding is controlled by streamProgress (default on).

Install

dsh plugin --profile web add file:/absolute/path/to/dsh-openai-gateway

The bundle declares its own DSH composition, so the openai-gateway component is inserted automatically. Desktop installs can enable it instantly from the plugins page; CLI installs need a profile restart. Desktop ports are dynamically assigned — use the address shown in the sidebar API row.

Configuration

Override the component config in the profile patch layer ($DSH_HOME/profiles/web/cordis.patch.yml; desktop: profiles/desktop/):

- id: openai-gateway
  config:
    pathPrefix: /v1                    # optional, default shown
    # modelOverride: my-model          # optional; global LLM model override
    # modelByPreset:                   # optional; per-preset models
    #   code: deepseek-flash
    #   standard: glm-5.4
    # sessionMapMax: 5000              # optional; 0 disables size eviction
    # sessionMapTtlDays: 0             # optional; 0 disables expiry
    # streamProgress: true             # optional; streamed progress toggle
    # apiKeys:                         # optional; omit = no auth
    #   - sk-...
    # allowedOrigins:                  # optional; extra browser origins
    #   - https://example.com
    # maxBodyBytes: 33554432           # optional; body limit
keydefaultnotes
pathPrefix/v1Route prefix for all three endpoints.
modelOverridehost defaultGlobal LLM model override for API sessions.
modelByPresetunsetPer-preset models: preset id → model id (cross-provider allowed).
apiKeysunset = no authOne tenant per key; requests must carry Authorization: Bearer <key>.
sessionMapMax5000Session-map entry cap (SQLite); 0 disables size eviction.
sessionMapTtlDays0Map expiry in days (last-use timestamp, refreshed on reuse); 0 disables.
streamProgresstrueStreamed execution progress (tool steps + thinking → reasoning_content).
maxBodyBytes33554432Max JSON request body bytes.
allowedOriginsunsetExtra browser origins allowed to call cross-origin.

Deprecated (accepted but ignored): cwd, sessionMapPath. The session store (session-map.db, via Node 24's built-in node:sqlite) and workspaces live in the fixed data directory $DSH_HOME/openai-gateway/, created automatically.

Config can be edited from the settings page (saves reload the plugin instantly) or by editing the YAML and restarting the profile.

Settings page

The API Gateway page appears in Settings:

  • Connection card: base URL, auth status, reachability probe, curl examples.
  • Access table: route prefix, available agent presets.
  • Model routing table: global model override dropdown (candidates aggregate every provider's models, labeled by provider).
  • Per-preset overrides table: Agent preset | LLM model | remove rows with dropdowns on both sides and an add-row button.
  • Sessions & security table: browser origins, body limit, API key management (generate/reveal/delete), streamed-progress toggle.
  • Advanced collapse: session-map cap/expiry and the read-only data directory.

The ? next to a label shows its explanation on hover or click. Saving reloads the plugin instantly.

Auth & trust

  • With apiKeys set: an exact Authorization: Bearer <key> is required; the matched key is the tenant.
  • Without: no authentication at all — the listener is the only boundary; set keys before exposing it through tunnels or proxies.
  • Browser cross-origin calls from other origins are rejected even with a valid key; add origins to allowedOrigins if needed. All three endpoints answer OPTIONS preflights.

Development

node client/build.mjs         # build lib/client.js (browser half) from client/ sources
npm test                      # all tests (protocol smoke + unit + bundle consistency)
node client/build.mjs --check # verify bundle matches sources

Browser-half sources: client/model.js (pure functions), client/ui.js (panel & settings components), client/entry.js (slot registration), client/settings.js (settings page assembly), client/styles.css (DSH theme tokens). lib/client.js is generated — don't edit it.

The protocol smoke tests use stub agents, loopback ephemeral ports and a temp DSH_HOME; they never call real models or touch user data.

Похожие плагины