dsh-nikoapi 0.0.0-stage → 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.en.md +110 -0
- package/README.md +109 -2
- package/client.js +398 -0
- package/cordis.patch.yml +6 -0
- package/icon.svg +7 -0
- package/images/key_permissions.png +0 -0
- package/images/qrcode_main.jpg +0 -0
- package/images/qrcode_notify.jpg +0 -0
- package/index.js +736 -0
- package/lib/billing-expression.js +431 -0
- package/lib/costmeter-prices.js +96 -0
- package/lib/costmeter.js +162 -0
- package/lib/groups.js +68 -0
- package/lib/http.js +147 -0
- package/lib/models.js +192 -0
- package/lib/niko.js +254 -0
- package/lib/price-calculator.js +65 -0
- package/lib/pricing.js +174 -0
- package/lib/state.js +211 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +62 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SnowNight777
|
|
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.en.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# dsh-nikoapi
|
|
2
|
+
|
|
3
|
+
**English** · [简体中文](README.md)
|
|
4
|
+
|
|
5
|
+
 
|
|
6
|
+
|
|
7
|
+
## Foreword
|
|
8
|
+
|
|
9
|
+
This plugin exists to make the [NikoAPI](http://nikoapi.xyz) relay convenient to use. It is written by a member of the site's community group, as a labour of love — feedback and suggestions are welcome.
|
|
10
|
+
|
|
11
|
+
Questions about the API itself go to the group owner; the author only maintains and updates the plugin itself. If you want to be certain, review the code for safety before installing. Should a key leak or another security problem occur, the author is sincerely sorry but accepts no responsibility.
|
|
12
|
+
|
|
13
|
+
Site chat groups — click or scan to join:
|
|
14
|
+
|
|
15
|
+
[Official chat group](https://qm.qq.com/q/OsKxIZL9Ck)
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
[Official notice group](https://qm.qq.com/q/jArGMUFuKI)
|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
Connect NikoAPI model Keys to DeepSeek Harness: pick Keys and models in Settings, press **Confirm**, and the models appear in DSH's model picker. With `dsh-cost-meter` installed, price calculators register automatically.
|
|
24
|
+
|
|
25
|
+
| | |
|
|
26
|
+
| -------------------- | -------------------------------------------- |
|
|
27
|
+
| DSH version | `>= 0.2.2-rc.1 < 0.3.0` |
|
|
28
|
+
| Node.js | `>= 20` |
|
|
29
|
+
| Runtime dependencies | none (Node built-ins and DSH Host APIs only) |
|
|
30
|
+
| License | MIT |
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
**Option 1 (recommended):** install the package `dsh-nikoapi` through DSH's plugin manager, then confirm the plugin row is enabled.
|
|
35
|
+
|
|
36
|
+
**Option 2:** add the dependency to your profile's `package.json`, reinstall, and restart DSH:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{ "dependencies": { "dsh-nikoapi": "^0.1.0" } }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Restart DSH after installing; once **NikoAPI** appears in Settings, the install worked.
|
|
43
|
+
|
|
44
|
+
> A local `link:` install bypasses the `files` whitelist (everything in the directory is linked), so only an install **from npm** actually proves the packed file list is complete.
|
|
45
|
+
|
|
46
|
+
> The site address defaults to `https://nikoapi.xyz`; a self-hosted relay can change `baseUrl` in the plugin config.
|
|
47
|
+
|
|
48
|
+
## Quick start
|
|
49
|
+
|
|
50
|
+
1. Register and sign in on the main site.
|
|
51
|
+
2. After signing in, create an access token in the console under [Security & access](https://nikoapi.xyz/security). The recommended permission set lets the plugin use all of its features.
|
|
52
|
+
3. **DSH → Settings → NikoAPI → Connection**: paste the **management token** and press **Save**.
|
|
53
|
+
4. **Keys and groups** tab: press **Refresh** to load the remote Key directory. Only an explicit refresh goes to the network; otherwise the last synchronized cache is shown.
|
|
54
|
+
5. Select the model Keys to add, then press **Confirm**.
|
|
55
|
+
6. **Models** tab: preview the models available on the selected Keys, select them, and press **Confirm** again. The plugin reads back the credential, site address, capabilities, and exact model IDs before it creates one route per Key.
|
|
56
|
+
|
|
57
|
+
## One Key, one Provider
|
|
58
|
+
|
|
59
|
+
- Each Key gets exactly one route, with the stable ID `nikoapi-<Key ID>`. A Key is never split into multiple Providers.
|
|
60
|
+
- Protocols are aggregated per group, in priority order: `openai-responses` → `anthropic-messages` → `google-generative-ai` → `openai-completions`.
|
|
61
|
+
- Explicit GPT model IDs always use `openai-responses`, even when the site omits that declaration. This is the only model-ID protocol override.
|
|
62
|
+
- Every confirmed model on a Key shares that single protocol, so **keep mixed selections within what that protocol supports**.
|
|
63
|
+
- Models with the same ID are added per Key; each channel uses its own Key and group, and the current session's default model is never changed.
|
|
64
|
+
|
|
65
|
+
## Token permissions
|
|
66
|
+
|
|
67
|
+
Recommended token permissions:
|
|
68
|
+
|
|
69
|
+

|
|
70
|
+
|
|
71
|
+
Without `api_key:write` the group picker is read-only; everything else still works.
|
|
72
|
+
|
|
73
|
+
## Cost link
|
|
74
|
+
|
|
75
|
+
The plugin is linked with the `dsh-cost-meter` cost plugin, providing accurate accounting of site prices and balance queries.
|
|
76
|
+
|
|
77
|
+
Active automatically when `dsh-cost-meter` 1.9.78 or later is present; no checkbox needed. Without cost-meter the plugin still works, just without prices.
|
|
78
|
+
|
|
79
|
+
- Calculators are registered only for confirmed, enabled **exact** models whose routes passed verification.
|
|
80
|
+
- Model refreshes and the scheduled rate refresh both update rates; the Key directory is not reloaded by them and updates only through **Refresh**.
|
|
81
|
+
- The **Cost link** tab sets the rate-refresh interval (15 minutes by default) and offers **Refresh now**.
|
|
82
|
+
- When cost-meter is detected and its "billion-context assisted metering" switch is on, the plugin turns it off once (at most once per start; turning it back on later is not overridden). Reason: with that switch on, cost-meter replays skip the plugin's stored CNY quotes and fall back to official USD prices, so per-turn details no longer match.
|
|
83
|
+
- Beyond that, the plugin never modifies cost-meter's price configuration, balances, or recorded ledger entries.
|
|
84
|
+
|
|
85
|
+
## Credentials and privacy
|
|
86
|
+
|
|
87
|
+
- The management token and model Keys live in DSH's local credential store and are written one way; the UI never echoes them.
|
|
88
|
+
- Apart from the NikoAPI site itself, the plugin sends data nowhere.
|
|
89
|
+
|
|
90
|
+
## Troubleshooting
|
|
91
|
+
|
|
92
|
+
- **Keys and groups shows "Not connected"**: the token was not saved or has expired. Use **Update credential** to re-enter it.
|
|
93
|
+
- **"The plugin is updating; restart DSH and refresh the page"**: module generations differ after an upgrade. Restart DSH.
|
|
94
|
+
- **"The service is temporarily unavailable"**: refresh the page or restart DSH, then retry.
|
|
95
|
+
- **No prices**: `dsh-cost-meter` 1.9.78+ is missing, or the model is not confirmed or its route failed verification.
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm test # uses a local mock site and never reaches the network
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Feedback and suggestions
|
|
104
|
+
|
|
105
|
+
- Repository: <https://github.com/SnowNight777/dsh-nikoapi>
|
|
106
|
+
- Issues: <https://github.com/SnowNight777/dsh-nikoapi/issues>
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT © SnowNight777
|
package/README.md
CHANGED
|
@@ -1,3 +1,110 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-nikoapi
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](README.en.md) · **简体中文**
|
|
4
|
+
|
|
5
|
+
 
|
|
6
|
+
|
|
7
|
+
## 前言
|
|
8
|
+
|
|
9
|
+
本项目是为方便 [NikoAPI ](http://nikoapi.xyz) 中转站开发的便携插件,作者是站内的群友,插件纯为爱发电制作而成,欢迎大家使用以及提出建议和意见。
|
|
10
|
+
|
|
11
|
+
如遇到API使用的相关问题进群找群主,本人只负责插件本身的维护和更新,不放心的请在安装前请进行安全审查,如有遭遇key泄露等安全问题深感抱歉但本人概不负责。
|
|
12
|
+
|
|
13
|
+
站内群聊链接,点击或扫码加入:
|
|
14
|
+
|
|
15
|
+
[官方聊天扯淡群](https://qm.qq.com/q/OsKxIZL9Ck)
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
[官方通知群](https://qm.qq.com/q/jArGMUFuKI)
|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
23
|
+
把 NikoAPI 的模型 Key 接进 DeepSeek Harness:在设置里勾选 Key 与模型、点「确认」,模型就直接出现在 DSH 的模型选择器里。装了 `dsh-cost-meter` 的话,价格计算器也会自动挂上。
|
|
24
|
+
|
|
25
|
+
| | |
|
|
26
|
+
| ------- | ----------------------------- |
|
|
27
|
+
| DSH 版本 | `>= 0.2.2-rc.1 < 0.3.0` |
|
|
28
|
+
| Node.js | `>= 20` |
|
|
29
|
+
| 运行时依赖 | 零(只用 Node 内置模块与 DSH Host API) |
|
|
30
|
+
| 许可证 | MIT |
|
|
31
|
+
|
|
32
|
+
## 安装
|
|
33
|
+
|
|
34
|
+
**方式一(推荐)**:在 DSH 里用插件管理安装本包(包名 `dsh-nikoapi`),装好后确认插件行已启用。
|
|
35
|
+
|
|
36
|
+
**方式二**:把依赖写进 profile 的 `package.json`,重装并重启 DSH:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{ "dependencies": { "dsh-nikoapi": "^0.1.0" } }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
装完重启 DSH,设置里出现 **NikoAPI** 即安装成功。
|
|
43
|
+
|
|
44
|
+
> 本地用 `link:` 指向源码目录时,`files` 白名单不生效(目录里有什么就都有),所以只有**从 npm 安装**才能真正验证包里文件齐不齐。
|
|
45
|
+
|
|
46
|
+
> 站点地址默认是 `https://nikoapi.xyz`;自建中转可以在插件配置里改 `baseUrl`。
|
|
47
|
+
|
|
48
|
+
## 快速开始
|
|
49
|
+
|
|
50
|
+
1. 前往主站注册并登录账号
|
|
51
|
+
2. 登录成功后在控制台 → [安全与访问](https://nikoapi.xyz/security) 中创建访问令牌,权限建议按推荐配置,推荐配置可以使用完整插件功能。
|
|
52
|
+
3. **打开DSH → 设置 → NikoAPI →「连接设置」**:粘贴**管理访问令牌**,点「保存」。
|
|
53
|
+
4. **「Key 与分组」** 标签:点「刷新」拉取远端 Key 列表。只有主动刷新才会联网,平时显示「上次同步」的缓存。
|
|
54
|
+
5. 勾选要接入的模型 Key,点「确认」。
|
|
55
|
+
6. **「模型」** 标签:预览所选 Key 的可用模型,勾选后再次「确认」。插件会读回校验凭据、站点地址、能力与精确模型 ID,然后为每个 Key 建立一条路由。
|
|
56
|
+
|
|
57
|
+
## 一个 Key = 一条 Provider
|
|
58
|
+
|
|
59
|
+
- 每个 Key 严格只建一条路由,ID 固定为 `nikoapi-<Key ID>`,不会把一个 Key 拆成多个 Provider。
|
|
60
|
+
- 协议按分组聚合,优先级:`openai-responses` → `anthropic-messages` → `google-generative-ai` → `openai-completions`。
|
|
61
|
+
- GPT 模型 ID 固定走 `openai-responses`,即使站点漏报该声明——这是唯一按模型 ID 覆盖协议的规则。
|
|
62
|
+
- 同一 Key 下所有已确认模型共用这一个协议,所以**混选模型请限制在该协议支持范围内**。
|
|
63
|
+
- 同名模型按 Key 分别接入;每个渠道使用对应 Key 与分组,不改变当前会话的默认模型。
|
|
64
|
+
|
|
65
|
+
## 令牌权限
|
|
66
|
+
|
|
67
|
+
推荐令牌权限:
|
|
68
|
+
|
|
69
|
+

|
|
70
|
+
|
|
71
|
+
没有 `api_key:write` 时分组选择为只读,其余功能不受影响。
|
|
72
|
+
|
|
73
|
+
## 费用联动
|
|
74
|
+
|
|
75
|
+
本插件目前已与dsh-cost-meter费用插件联动,实现站内价格的精确统计和余额查询功能。
|
|
76
|
+
|
|
77
|
+
检测到 `dsh-cost-meter` 1.9.78 或更高版本时自动生效,无需勾选;没有 cost-meter 也能正常使用,只是没有价格。
|
|
78
|
+
|
|
79
|
+
- 只为**已确认、Key 已启用且路由校验通过**的精确模型注册同步价格计算器。
|
|
80
|
+
- 模型刷新与费率定时刷新都会更新费率;Key 列表不随之重载,由「刷新」按钮更新。
|
|
81
|
+
- 「费用联动」标签可改费率刷新间隔(默认 15 分钟)与「手动刷新」。
|
|
82
|
+
- 检测到 cost-meter 时,若其「billion-context 辅助计量」开关是开的,会自动关一次(每次启动最多一次,你之后手动开回不会被反复覆盖)。原因:开启时 cost-meter 回放会跳过本插件已存的人民币报价、改用官方美元价,回合明细对不上。
|
|
83
|
+
- 除此之外不修改 cost-meter 的价格配置、余额与已记录的账单。
|
|
84
|
+
|
|
85
|
+
## 凭据与隐私
|
|
86
|
+
|
|
87
|
+
- 管理令牌与模型 Key 保存在 DSH 本机凭据库,界面单向保存、不回显。
|
|
88
|
+
- 除 NikoAPI 站点本身,插件不向任何第三方发送数据。
|
|
89
|
+
|
|
90
|
+
## 常见问题
|
|
91
|
+
|
|
92
|
+
- **「Key 与分组」显示未连接**:令牌未保存或已失效,用「更新凭据」重填。
|
|
93
|
+
- **提示「插件正在更新,请重启 DSH 并刷新页面后重试」**:插件升级后模块代际不一致,重启即可。
|
|
94
|
+
- **提示服务暂不可用**:刷新页面或重启 DSH 后重试。
|
|
95
|
+
- **没有价格**:未安装 1.9.78 以上的 `dsh-cost-meter`,或模型尚未确认、路由未通过校验。
|
|
96
|
+
|
|
97
|
+
## 开发
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm test # 内置本地 mock 站点,不访问公网
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## 问题反馈及建议
|
|
104
|
+
|
|
105
|
+
- 仓库:<https://github.com/SnowNight777/dsh-nikoapi>
|
|
106
|
+
- 问题反馈:<https://github.com/SnowNight777/dsh-nikoapi/issues>
|
|
107
|
+
|
|
108
|
+
## 许可
|
|
109
|
+
|
|
110
|
+
MIT © SnowNight777
|