dsh-openai-gateway
wutao-coder/dsh-openai-gateway
由真实 DSH Agent 会话支撑的 OpenAI 兼容网关。提供 Chat Completions 与 Responses 接口(含流式),按 Agent 预设跨 provider 模型路由,SQLite 持久化角色会话,自动工作区管理,并把工具执行与思考过程流式输出为思考内容,长任务不再让客户端干等。
安装
dsh plugin --profile web add github:wutao-coder/dsh-openai-gatewayREADME
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):
| Endpoint | Purpose |
|---|---|
POST /v1/chat/completions | Chat Completions API (streaming + non-streaming) |
POST /v1/responses | Responses API subset (streaming + non-streaming) |
GET /v1/models | Available 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. Whatevermodelthe client requests, the same-named agent preset serves it; the preset list is exactly what/v1/modelsreturns.- Session identity is the
(API key tenant, preset, X-Session-Id)triple: keys isolate tenants; the optionalX-Agent-Presetheader 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_callare 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
modelByPresetlets 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.codeon a DeepSeek account,standardon 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-alivecomment frames so proxies/gateways don't time out. - Mid-stream failures end with an explicit error frame (
event: erroron 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
| key | default | notes |
|---|---|---|
pathPrefix | /v1 | Route prefix for all three endpoints. |
modelOverride | host default | Global LLM model override for API sessions. |
modelByPreset | unset | Per-preset models: preset id → model id (cross-provider allowed). |
apiKeys | unset = no auth | One tenant per key; requests must carry Authorization: Bearer <key>. |
sessionMapMax | 5000 | Session-map entry cap (SQLite); 0 disables size eviction. |
sessionMapTtlDays | 0 | Map expiry in days (last-use timestamp, refreshed on reuse); 0 disables. |
streamProgress | true | Streamed execution progress (tool steps + thinking → reasoning_content). |
maxBodyBytes | 33554432 | Max JSON request body bytes. |
allowedOrigins | unset | Extra 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 | removerows 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
apiKeysset: an exactAuthorization: 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
allowedOriginsif needed. All three endpoints answerOPTIONSpreflights.
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.