funny0A0/dsh-egress-router ↗★ 0
dsh-egress-router
Per-endpoint loopback egress relay for DSH: route only the endpoints that need a proxy, keep everything else direct. 适合需要对特定API端点或域名进行精细化代理路由配置的开发者。
Other repositories with this package name
Install
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:funny0A0/dsh-egress-routerREADME
Read the full README ↗配置
cordis.patch.yml(只留代理表)
- id: egress-router
config:
proxies:
clash: http://127.0.0.1:7897
config.targets:声明要观察的端点
有些域名不在任何 provider 的 baseURL 里(自建服务、上游 API、暂时未接入的模型供应商),但你仍想一键检查。把它们写进 targets:
- id: egress-router
config:
proxies:
clash: http://127.0.0.1:7897
targets:
- { id: github, name: GitHub API, host: api.github.com, port: 443 }
- { id: hf, target: huggingface.co:443 }
- { id: ghcr, url: https://ghcr.io/v2/ }
三种写法等价(host + port / target: "host:port" / url)。它们会以「自定义」徽章出现在扫描结果里,可以 检查 与 测试,但 apply 会返回 not_patchable:没有可改写的 baseURL。
不要写
name: dsh-egress-router:bundles已经加载了本插件,再写name会被当成第二个实例。
受保护域名与已知端点(0.11.0)
- id: egress-router
config:
guarded:
- sso.mycorp.test # 追加到内置清单
origins:
acme: https://gateway.acme.test/v2 # provider → 真实公网端点
guarded:内置platform.deepseek.com、api.deepseek.com、registry.npmjs.org、awesome-dsh-plugin.com、dsh-plugin-catalog。追加项与内置项一样,只在页面列出、不提供改写。写成 URL(https://sso.mycorp.test/login)也可以,会自动归一成 host;匹配包含子域名,但不匹配evil-sso.mycorp.test这类伪后缀。origins:当账本里没有某个 provider 的原始地址时用它兜底(刚换机器、备份被清空、历史路由已被撤销都可能发生)。恢复回环路由时优先级是:路由记录 → 备份账本 →config.origins→ 内置端点(openrouter / gemini / moonshot / deepseek)。
本机中转(relay 路由,0.10.0)
没有 baseURL 的目标(CLI、别的插件、webhook、抓取脚本)改不了配置,但仍然可以走本机端口:
curl -s -X POST "http://127.0.0.1:/plugins/egress-router?op=routes" \
-H 'content-type: application/json' -H 'sec-fetch-site: same-origin' \
-d '{"action":"upsert","id":"relay:hf","target":"huggingface.co:443","listenPort":8793,"proxy":"clash"}'
之后把调用方地址换成 http://127.0.0.1:8793,请求经 Clash 转发到 huggingface.co:443;删除用 {"action":"delete","id":"relay:hf"}。这类路由不写 cordis.patch.yml,所以 restartRequired 恒为 false。
页面上的「本机中转(不改目标配置)」区块就是这两个调用的界面版:填目标与端口、选代理、点「新建中转」,之后可复制地址或删除。
config.discovery:声明式发现规则(0.11.0)
发现器默认用 baseURL、包依赖与已知供应商来推断用途。推断不准时不必等上游支持,写规则覆盖:
- id: egress-router
config:
discovery:
ignore:
- telemetry.example.com
rules:
- id: internal-api
match: { hostSuffix: corp.test }
kind: custom # llm | im | other | custom
name: 内部网关
confidence: certain # certain | probable | low
note: 走网关才能出网
- id: no-apply
match: { id: "llm:gemini" }
patchable: false
match字段:id(尾部*作前缀匹配)、kind、host、hostSuffix(自动去掉前导*.)、urlIncludes;同一行的多个条件是 AND。- 同一行命中第一条规则就停止,可覆盖
kind/name/patchable/guarded/confidence/note。 ignore里的 host 直接不出现;想「看得见但不动」请用guarded。?op=discover的响应用rulesApplied报告命中条数,被规则改过的行带rule:。
$DSH_HOME/storages/egress-router/state.json
version: 10、schemaVersion: 1。主要字段:
| 字段 | 说明 |
|---|---|
routes[] | { id, target, listenPort, proxy, tls, tuning, originBaseURL } |
listeners[] | 最近一次同步结果(ok / error),重启后可见 |
metrics{} | 每个路由的计数与延迟分位(样本在内存,重启从零累计) |
metricsTotals{} | 跨重启累计的 requests / bytesIn / bytesOut / errors 与首次计数时间 since |
backups[] | 配置备份账本(最多 20 条),回滚依据 |
patches{} | 补丁账本(自修复只处理这里记录过的) |
history[] | 审计流水(最多 50 条,重复行 60s 内折叠) |
hostContract / hostEnv | 宿主接受的注册形状与当时的平台/Node 版本 |
schemaVersion | 状态文档的对外形状版本(当前 1),由 lib/schema.js 校验;?op=state 的 schemaOk 为 false 时页面会显示具体字段 |
reconcilePaused{} | 漂移自愈的暂停窗口(原因 + 到期时间) |
bots{}从 v10 起移到同目录的bots.json({ version: 1, updatedAt, bots }),旧state.bots会在首次启动时自动迁移一次。机器人映射单独成文件,重装插件或重置状态时不会误丢。
机器人代理与环境变量
本插件不写 $DSH_HOME/.env。 该文件里的 DSH_TELEGRAM_PROXY 会让 DSH 启动器直接拒绝启动
(0.7.1 曾这样做,导致桌面版与 Web 版同时无法启动),所以代理只做两件事:
- 应用时注入
process.env,当前会话立即生效; - 记录在
bots.json,下次启动由插件在本进程重新注入。
如果你希望变量在 DSH 启动之前就存在(例如别的进程也要用),请设置操作系统环境变量: