dsh-openrouter-provider-advisor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +163 -0
- package/README_EN.md +116 -0
- package/cordis.patch.yml +4 -0
- package/docs/images/provider-panel.png +0 -0
- package/docs/images/settings-weights.png +0 -0
- package/dsh.plugin.json +16 -0
- package/lib/client.js +1369 -0
- package/lib/index.js +954 -0
- package/lib/types/apply-provider.d.ts +52 -0
- package/lib/types/client/i18n.d.ts +24 -0
- package/lib/types/client/index.d.ts +4 -0
- package/lib/types/client/linked-weights.d.ts +3 -0
- package/lib/types/client/provider-panel-store.d.ts +42 -0
- package/lib/types/client/provider-panel.d.ts +47 -0
- package/lib/types/client/settings-card.d.ts +24 -0
- package/lib/types/client/weight-group.d.ts +22 -0
- package/lib/types/config.d.ts +24 -0
- package/lib/types/controller.d.ts +107 -0
- package/lib/types/directory.d.ts +39 -0
- package/lib/types/host-adapter.d.ts +64 -0
- package/lib/types/host-routes.d.ts +21 -0
- package/lib/types/index.d.ts +10 -0
- package/lib/types/openrouter.d.ts +34 -0
- package/lib/types/resolve-model.d.ts +23 -0
- package/lib/types/score.d.ts +5 -0
- package/lib/types/tools.d.ts +17 -0
- package/lib/types/types.d.ts +53 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zhuxiaofeng
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# dsh-openrouter-provider-advisor
|
|
2
|
+
|
|
3
|
+
同一个模型,不同 OpenRouter 供应商的价格、缓存费用、速度和稳定性可能相差很大。这个插件帮助 DeepSeek Harness 用户自动找到**更省钱、更合适的供应商**,并一键切换当前会话。
|
|
4
|
+
|
|
5
|
+
插件综合量化、速度、缓存重度价格、上下文与可用率,为当前模型给出 Top 5 供应商。你不需要逐个查价格、建 preset:点击一行即可同步切换当前会话与默认模型。
|
|
6
|
+
|
|
7
|
+
> **核心价值:在不更换模型的前提下,减少不必要的调用成本,并在价格、速度和可靠性之间找到更适合当前工作负载的线路。**
|
|
8
|
+
|
|
9
|
+
🌏 **中文** · [English](./README_EN.md)
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## 功能
|
|
14
|
+
|
|
15
|
+
- **帮助省钱**:比较同一模型在不同供应商的输入、输出和缓存读取价格,避免只看单一标价。
|
|
16
|
+
- **找到更合适的供应商**:价格不是唯一标准;速度、量化、上下文和可靠性一起参与排序。
|
|
17
|
+
- **当前模型推荐**:自动对齐 DSH 模型与 OpenRouter `author/slug`,不推荐无关模型。
|
|
18
|
+
- **四种策略**:综合最佳、价格优先、速度优先、上下文优先。
|
|
19
|
+
- **Code Agent 价格模型**:默认按输入 2%、输出 8%、缓存读取 90% 计算价格得分。
|
|
20
|
+
- **可靠性保护**:过滤不可用 endpoint,并按 OpenRouter 近 30 分钟 uptime 温和降权。
|
|
21
|
+
- **点击实时切换**:创建或更新 OpenRouter preset,切换当前会话并保存默认模型。
|
|
22
|
+
- **完整 DSH 模型目录**:复用 DSH 已有配置,不写死模型列表。
|
|
23
|
+
- **联动权重 UI**:滑块、百分比输入和锁定按钮协同调整,总和始终为 100%。
|
|
24
|
+
- **复用 DSH 凭据**:读取 OpenRouter provider 的 `apiKeyEnv`,API Key 不进入浏览器。
|
|
25
|
+
- **Agent 工具**:只读推荐免审批;Agent 发起切换时必须经过 DSH 原生审批。
|
|
26
|
+
- **中英文界面**:跟随 DSH 当前语言实时切换。
|
|
27
|
+
|
|
28
|
+
## 界面
|
|
29
|
+
|
|
30
|
+
| 供应商推荐与切换 | 权重与凭据状态 |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| 同一模型的供应商价格与性能放在一张表里,快速找到更省钱且适合当前任务的线路;点击一行立即切换。 | 联动滑块配置综合权重与缓存重度价格模型;顶部只展示 credential reference,不展示密钥。 |
|
|
33
|
+
| <img src="./docs/images/provider-panel.png" alt="供应商推荐面板" width="100%"> | <img src="./docs/images/settings-weights.png" alt="OpenRouter 权重设置" width="100%"> |
|
|
34
|
+
|
|
35
|
+
> 可用率来自 OpenRouter 近 30 分钟统计。刚发生的故障、限流和恢复可能存在检测延迟;它不是主动健康探测。
|
|
36
|
+
|
|
37
|
+
## 安装
|
|
38
|
+
|
|
39
|
+
前置条件:DSH `0.1.1-rc.2` 或更新版本、Node.js `^22.19.0` 或 `>=24`,并已在 **DSH 设置 → 模型** 中配置 OpenRouter provider/API Key。
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
dsh plugin --profile web add dsh-openrouter-provider-advisor@latest
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
安装后硬刷新浏览器:macOS 使用 `Cmd + Shift + R`,Windows/Linux 使用 `Ctrl + Shift + R`。若 Host 部分已在运行,重启一次 `dsh web`。
|
|
46
|
+
|
|
47
|
+
更新与卸载:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
dsh plugin --profile web add dsh-openrouter-provider-advisor@latest
|
|
51
|
+
dsh plugin --profile web remove dsh-openrouter-provider-advisor
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 使用
|
|
55
|
+
|
|
56
|
+
1. 在 DSH 中打开普通会话。
|
|
57
|
+
2. 点击左侧栏底部的 **OpenRouter 供应商**。
|
|
58
|
+
3. 选择要分析的 DSH 模型和推荐策略。
|
|
59
|
+
4. 查看分数与可用率,点击供应商完成切换。
|
|
60
|
+
5. 下一次请求将使用新的 `@preset/<model>-<provider>`。
|
|
61
|
+
|
|
62
|
+
切换按顺序执行:
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
创建/更新 OpenRouter preset
|
|
66
|
+
↓
|
|
67
|
+
写入 DSH OpenRouter 模型条目
|
|
68
|
+
↓
|
|
69
|
+
session.selectModel 切换当前会话
|
|
70
|
+
↓
|
|
71
|
+
保存为 DSH 默认模型
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
已经组装完成的请求不会被中途改写;切换从下一次请求开始生效。
|
|
75
|
+
|
|
76
|
+
## 推荐策略
|
|
77
|
+
|
|
78
|
+
综合最佳默认使用:量化 30%、速度 30%、价格 30%、上下文 10%。设置页中的“综合最佳评分权重”只影响综合最佳;价格、速度和上下文策略使用内置权重。
|
|
79
|
+
|
|
80
|
+
如果目标是优先降低费用,可以直接选择“价格优先”;如果希望控制成本但不牺牲太多速度和稳定性,使用默认“综合最佳”。推荐结果是决策辅助,不保证每次请求都落在绝对最低价线路。
|
|
81
|
+
|
|
82
|
+
默认价格模型针对 Code Agent 的高缓存流量:
|
|
83
|
+
|
|
84
|
+
```text
|
|
85
|
+
价格成本 = 输入价 × 2% + 输出价 × 8% + 缓存读取价 × 90%
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 可用率安全带
|
|
89
|
+
|
|
90
|
+
`status != 0` 的 endpoint 直接排除。其余 endpoint 使用温和的通用降权:
|
|
91
|
+
|
|
92
|
+
| OpenRouter 近 30 分钟 uptime | 保留分数 |
|
|
93
|
+
| --- | ---: |
|
|
94
|
+
| ≥99.5% | 100% |
|
|
95
|
+
| 99–99.5% | 85% |
|
|
96
|
+
| 97–99% | 60% |
|
|
97
|
+
| 90–97% | 30% |
|
|
98
|
+
| <90% | 5% |
|
|
99
|
+
| 无数据 | 70% |
|
|
100
|
+
|
|
101
|
+
用户设置可以让惩罚更严格,但不能绕过安全带。
|
|
102
|
+
|
|
103
|
+
## Agent 工具
|
|
104
|
+
|
|
105
|
+
- `recommend_openrouter_providers`:读取当前模型的推荐列表。
|
|
106
|
+
- `switch_openrouter_provider`:切换供应商;属于写操作,始终请求 DSH 用户审批。
|
|
107
|
+
|
|
108
|
+
人类在面板里点击供应商时视为明确操作,会直接执行切换。
|
|
109
|
+
|
|
110
|
+
## 凭据与安全
|
|
111
|
+
|
|
112
|
+
- 优先复用当前 DSH OpenRouter provider 的 `apiKeyEnv`,兼容回退 `OPENROUTER_API_KEY` reference。
|
|
113
|
+
- API Key 只在 Host 端解析,不进入 Client bundle、HTTP 响应或插件设置。
|
|
114
|
+
- Host 写接口只接受同源 JSON,请求体上限 64KB。
|
|
115
|
+
- OpenRouter 查询超时 15 秒,preset 写入超时 30 秒。
|
|
116
|
+
- Controller 不持久保存密钥;执行写操作前重新解析凭据。
|
|
117
|
+
- 插件不读取或传输会话正文、历史消息和用户文件。
|
|
118
|
+
|
|
119
|
+
## 数据来源与限制
|
|
120
|
+
|
|
121
|
+
插件只调用 OpenRouter 官方 API:
|
|
122
|
+
|
|
123
|
+
```text
|
|
124
|
+
GET /api/v1/models
|
|
125
|
+
GET /api/v1/models/{author}/{slug}/endpoints
|
|
126
|
+
POST /api/v1/presets/{slug}/chat/completions
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
不抓取产品页 HTML。OpenRouter 统计可能滞后于即时 `429`、超时和恢复;点击供应商会创建或更新真实 preset;切换上游可能使 KV cache 失效。
|
|
130
|
+
|
|
131
|
+
## 常见问题
|
|
132
|
+
|
|
133
|
+
| 现象 | 处理方式 |
|
|
134
|
+
| --- | --- |
|
|
135
|
+
| 找不到 `web` profile | 先运行一次 `dsh web`,再安装插件。 |
|
|
136
|
+
| 插件已安装但界面没变化 | 硬刷新浏览器;Host 有改动时重启 DSH。 |
|
|
137
|
+
| 未检测到 OpenRouter 凭据 | 在 DSH 设置 → 模型中配置 OpenRouter provider/API Key。 |
|
|
138
|
+
| 某供应商分数高但请求 429 | uptime 有统计延迟,临时切换到其他供应商。 |
|
|
139
|
+
| `minimum release age` | 等待 profile 安全策略允许该版本后重试。 |
|
|
140
|
+
| DSH 拒绝 `.env` 中的 `DEEPSEEK_BASE_URL` | 从项目 `.env` 移除,并在启动 DSH 的终端中 `export`。 |
|
|
141
|
+
|
|
142
|
+
## 本地源码开发
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
git clone https://github.com/xuanfengtechx/dsh-openrouter-provider-advisor.git
|
|
146
|
+
cd dsh-openrouter-provider-advisor
|
|
147
|
+
npm install
|
|
148
|
+
npm run verify
|
|
149
|
+
dsh plugin --profile web add -w "$PWD"
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
发布预演:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
npm pack --dry-run
|
|
156
|
+
npm publish --dry-run --access public
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
自动测试不会点击真实供应商,因为切换会在用户 OpenRouter 账号中创建或更新 preset。
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
[MIT](./LICENSE)
|
package/README_EN.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# dsh-openrouter-provider-advisor
|
|
2
|
+
|
|
3
|
+
The same model can have very different prices, cache-read costs, throughput, and reliability across OpenRouter providers. This plugin helps DeepSeek Harness users find a **more cost-efficient, better-fit provider** and switch in one click.
|
|
4
|
+
|
|
5
|
+
It combines quantization, speed, cache-heavy pricing, context, and uptime into a Top 5 for the current model. You no longer need to compare providers or create presets by hand: clicking a row updates both the active session and default model.
|
|
6
|
+
|
|
7
|
+
> **Core value: reduce avoidable inference spend without changing models, while finding a practical balance between cost, speed, and reliability.**
|
|
8
|
+
|
|
9
|
+
[中文](./README.md) · **English**
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## Highlights
|
|
14
|
+
|
|
15
|
+
- Compare input, output, and cache-read prices to help reduce spend.
|
|
16
|
+
- Find the best fit rather than blindly choosing the cheapest endpoint.
|
|
17
|
+
- Model-aware ranking without a hard-coded model catalog.
|
|
18
|
+
- Best overall, price-first, speed-first, and context-first strategies.
|
|
19
|
+
- Code Agent price blend: 2% input, 8% output, 90% cache-read by default.
|
|
20
|
+
- Gentle 30-minute uptime safety bands and hard filtering for unavailable endpoints.
|
|
21
|
+
- One-click switching for the active session and deployment default.
|
|
22
|
+
- Linked percentage sliders with locks; each group always totals 100%.
|
|
23
|
+
- Reuses DSH credential references; API keys never reach the browser.
|
|
24
|
+
- Read-only recommendation tool and approval-gated agent switching tool.
|
|
25
|
+
- Live Chinese/English UI following the DSH locale.
|
|
26
|
+
|
|
27
|
+
## Screenshots
|
|
28
|
+
|
|
29
|
+
| Provider ranking | Settings and credential status |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| Compare provider cost and performance for the same model, then click a row to switch. | Linked scoring weights and a cache-heavy global price model. |
|
|
32
|
+
| <img src="./docs/images/provider-panel.png" alt="Provider advisor panel" width="100%"> | <img src="./docs/images/settings-weights.png" alt="Provider advisor settings" width="100%"> |
|
|
33
|
+
|
|
34
|
+
> Uptime is OpenRouter's trailing 30-minute statistic. Fresh failures, rate limits, and recoveries may be detected with a delay; this is not an active health probe.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
Requirements: DSH `0.1.1-rc.2` or newer, Node.js `^22.19.0` or `>=24`, and an OpenRouter provider/API key configured in **DSH Settings → Models**.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
dsh plugin --profile web add dsh-openrouter-provider-advisor@latest
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Hard-refresh (`Cmd/Ctrl + Shift + R`). Restart `dsh web` if its Host half was already running.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Update
|
|
48
|
+
dsh plugin --profile web add dsh-openrouter-provider-advisor@latest
|
|
49
|
+
|
|
50
|
+
# Remove
|
|
51
|
+
dsh plugin --profile web remove dsh-openrouter-provider-advisor
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Use
|
|
55
|
+
|
|
56
|
+
Open a normal DSH session, click **OpenRouter Providers** in the left footer, pick a model and strategy, then click a provider. The next request uses `@preset/<model>-<provider>`.
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
create/update OpenRouter preset
|
|
60
|
+
↓
|
|
61
|
+
upsert DSH OpenRouter model entry
|
|
62
|
+
↓
|
|
63
|
+
session.selectModel
|
|
64
|
+
↓
|
|
65
|
+
save the DSH default model
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
An already assembled request is not rewritten mid-flight.
|
|
69
|
+
|
|
70
|
+
## Ranking
|
|
71
|
+
|
|
72
|
+
Best overall defaults to 30% quantization, 30% speed, 30% price, and 10% context. Cache-heavy cost is:
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
cost = input price × 2% + output price × 8% + cache-read price × 90%
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
| OpenRouter trailing 30-minute uptime | Score retained |
|
|
79
|
+
| --- | ---: |
|
|
80
|
+
| ≥99.5% | 100% |
|
|
81
|
+
| 99–99.5% | 85% |
|
|
82
|
+
| 97–99% | 60% |
|
|
83
|
+
| 90–97% | 30% |
|
|
84
|
+
| <90% | 5% |
|
|
85
|
+
| Missing | 70% |
|
|
86
|
+
|
|
87
|
+
Endpoints with nonzero status are excluded. User settings may make penalties stricter, never looser.
|
|
88
|
+
|
|
89
|
+
## Credentials and security
|
|
90
|
+
|
|
91
|
+
- Reuses the selected DSH OpenRouter profile's `apiKeyEnv`, with `OPENROUTER_API_KEY` as a compatibility fallback reference.
|
|
92
|
+
- Credential values stay Host-only and never appear in client code, HTTP responses, or settings.
|
|
93
|
+
- Mutation routes accept same-origin JSON only and cap bodies at 64KB.
|
|
94
|
+
- Reads time out after 15 seconds; preset writes after 30 seconds.
|
|
95
|
+
- Agent-initiated switching always uses native DSH approval.
|
|
96
|
+
- The plugin does not read conversation messages, history, or workspace files.
|
|
97
|
+
|
|
98
|
+
## Data sources and limits
|
|
99
|
+
|
|
100
|
+
Only official OpenRouter APIs are used: `/models`, `/models/{id}/endpoints`, and `/presets/{slug}/chat/completions`. The plugin does not scrape product pages. OpenRouter statistics may lag fresh upstream failures and recoveries.
|
|
101
|
+
|
|
102
|
+
## Development
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
git clone https://github.com/xuanfengtechx/dsh-openrouter-provider-advisor.git
|
|
106
|
+
cd dsh-openrouter-provider-advisor
|
|
107
|
+
npm install
|
|
108
|
+
npm run verify
|
|
109
|
+
npm pack --dry-run
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Automated tests stop before a real provider click because switching creates or versions an actual OpenRouter preset.
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
[MIT](./LICENSE)
|
package/cordis.patch.yml
ADDED
|
Binary file
|
|
Binary file
|
package/dsh.plugin.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "dsh-external/dsh-openrouter-provider-advisor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./lib/index.js",
|
|
5
|
+
"description": "OpenRouter 供应商推荐与安全切换:按质量、速度、缓存价格、上下文和可用率排序",
|
|
6
|
+
"engines": {
|
|
7
|
+
"dsh": ">=0.1.1-rc.2"
|
|
8
|
+
},
|
|
9
|
+
"contributes": {
|
|
10
|
+
"tools": ["recommend_openrouter_providers", "switch_openrouter_provider"],
|
|
11
|
+
"skills": []
|
|
12
|
+
},
|
|
13
|
+
"client": {
|
|
14
|
+
"main": "./lib/client.js"
|
|
15
|
+
}
|
|
16
|
+
}
|