dsh-link-pulse 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/CHANGELOG.md +9 -0
- package/LICENSE +176 -0
- package/README.md +53 -0
- package/SECURITY.md +7 -0
- package/cordis.patch.yml +4 -0
- package/package.json +52 -0
- package/src/client.js +593 -0
- package/src/index.js +175 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# dsh-link-pulse
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/dsh-link-pulse)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
|
|
6
|
+
专为 **DeepSeek Harness (DSH) Web GUI** 打造的**模型链路与上游网关延迟感知插件**。解决日常使用 AI 时的“黑盒卡顿焦虑”,帮助用户一眼分清当前是本地网络拥堵、代理网关排队还是大模型自身在进行长思考(CoT)。
|
|
7
|
+
|
|
8
|
+
## 核心特性
|
|
9
|
+
|
|
10
|
+
- **100% 动态 Provider 发现**:自动从 `~/.dsh/settings.yaml` 读取已配置的所有模型网关(CPA、OpenCode GO、DeepSeek 官方直连等),绝不硬编码。
|
|
11
|
+
- **当前对话模型感知**:侧边栏常驻条目根据当前聊天选中的模型,动态显示对应供应商名称与实时延迟(如 `● CPA · Gemini 3.7 78ms`)。
|
|
12
|
+
- **原生样式像素级对齐**:状态圆点尺寸(`7px`)、呼吸光环与色彩变量严格对齐 `dsh-cpa-status` 与 `dsh-opencode-status`。
|
|
13
|
+
- **零 Token 消耗**:轻量级 TCP/TLS RTT 网络心跳探针,绝不消耗任何 API 配额。
|
|
14
|
+
- **多通道看板**:点击侧边栏条目即可呼出全局浮层面板,查看所有已接入 Provider 的实时测速对比并支持一键手动测速。
|
|
15
|
+
|
|
16
|
+
## 安装与更新
|
|
17
|
+
|
|
18
|
+
### 方式一:官方 npm 安装(推荐)
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
dsh plugin --profile web add dsh-link-pulse
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 方式二:GitHub 仓库直接安装
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
dsh plugin --profile web add github:j2st1n/dsh-link-pulse
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
> **说明**:
|
|
31
|
+
> - 纯原生 JS 零构建(Zero-build)架构,安装后重启 `dsh web` 即可立即生效。
|
|
32
|
+
|
|
33
|
+
### 卸载
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
dsh plugin --profile web remove dsh-link-pulse
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 延迟状态等级
|
|
40
|
+
|
|
41
|
+
| 延迟区间 | 状态颜色 | 质量评级 |
|
|
42
|
+
| :--- | :---: | :--- |
|
|
43
|
+
| $\le$ 200ms | 🟢 绿色 | 极佳(Excellent) |
|
|
44
|
+
| 200ms $\sim$ 600ms | 🟡 黄色 | 良好(Good) |
|
|
45
|
+
| > 600ms / 超时 | 🔴 红色 | 缓慢 / 离线(Slow / Timeout) |
|
|
46
|
+
|
|
47
|
+
## 安全声明
|
|
48
|
+
|
|
49
|
+
- 详见 [SECURITY.md](./SECURITY.md)。
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
[Apache-2.0](./LICENSE)
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## 零 Token 消耗与安全声明
|
|
4
|
+
|
|
5
|
+
1. **零 Token 消耗**:本插件探针采用 HTTP `HEAD` / `GET` 轻量级连接测试,仅测试网络往返延迟(RTT),绝不调用 `/chat/completions` 等模型推理接口,不消耗任何 Token 配额。
|
|
6
|
+
2. **本地配置只读**:插件后端仅以只读方式解析 `settings.yaml`,不写入或篡改任何系统配置与密钥。
|
|
7
|
+
3. **无敏感数据外泄**:所有探测数据仅供本地 DSH Web 界面消费,不向任何第三方上报遥测数据。
|
package/cordis.patch.yml
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-link-pulse",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Dynamic LLM provider gateway latency and health pulse probe for DeepSeek Harness",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"deepseek-harness",
|
|
9
|
+
"dsh",
|
|
10
|
+
"dsh-plugin",
|
|
11
|
+
"latency",
|
|
12
|
+
"probe",
|
|
13
|
+
"pulse",
|
|
14
|
+
"status-panel"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./src/index.js",
|
|
18
|
+
"./client": "./src/client.js",
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src",
|
|
23
|
+
"cordis.patch.yml",
|
|
24
|
+
"SECURITY.md",
|
|
25
|
+
"CHANGELOG.md",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"dsh": {
|
|
29
|
+
"bundle": {
|
|
30
|
+
"patch": "./cordis.patch.yml"
|
|
31
|
+
},
|
|
32
|
+
"client": {
|
|
33
|
+
"platform": "web",
|
|
34
|
+
"inject": []
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"js-yaml": "^4.1.0"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/j2st1n/dsh-link-pulse.git"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/j2st1n/dsh-link-pulse#readme",
|
|
45
|
+
"bugs": "https://github.com/j2st1n/dsh-link-pulse/issues",
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"test": "node --test"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/client.js
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-link-pulse',
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
const module = { exports: {} }
|
|
5
|
+
const exports = module.exports
|
|
6
|
+
const React = require('react')
|
|
7
|
+
const h = React.createElement
|
|
8
|
+
const { useEffect, useState, useCallback, useMemo } = React
|
|
9
|
+
|
|
10
|
+
const T = {
|
|
11
|
+
bg: 'var(--dsw-alias-bg-layer-2, #ffffff)',
|
|
12
|
+
layer: 'var(--dsw-alias-bg-layer-2, #ffffff)',
|
|
13
|
+
layer1: 'var(--dsw-alias-bg-layer-1, #f4f4f5)',
|
|
14
|
+
border: 'var(--dsw-alias-border-l1, rgba(0,0,0,.1))',
|
|
15
|
+
border2: 'var(--dsw-alias-border-l2, rgba(0,0,0,.15))',
|
|
16
|
+
label: 'var(--dsw-alias-label-primary, #18181b)',
|
|
17
|
+
secondary: 'var(--dsw-alias-label-secondary, #71717a)',
|
|
18
|
+
brand: 'var(--dsw-alias-brand-primary, #3b82f6)',
|
|
19
|
+
ok: 'var(--dsw-alias-state-success-primary, #22c55e)',
|
|
20
|
+
warn: 'var(--dsw-alias-state-warn-primary, #f59e0b)',
|
|
21
|
+
err: 'var(--dsw-alias-state-error-primary, #ef4444)',
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const CSS = `
|
|
25
|
+
@keyframes pulseFadeSlideUp { from { opacity: 0; transform: translateY(10px) scale(.98) } to { opacity: 1; transform: translateY(0) scale(1) } }
|
|
26
|
+
@keyframes pulseFadeIn { from { opacity: 0; transform: translateY(4px) } to { opacity: 1; transform: translateY(0) } }
|
|
27
|
+
@keyframes pulseSpin { to { transform: rotate(360deg) } }
|
|
28
|
+
@keyframes pulseGlow { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.45) } 70% { box-shadow: 0 0 0 5px rgba(34,197,94,0) } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0) } }
|
|
29
|
+
|
|
30
|
+
.pulse-panel-enter { animation: pulseFadeSlideUp .2s cubic-bezier(.2,.9,.3,1.2) both }
|
|
31
|
+
.pulse-btn { min-width: 0; transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease, opacity .15s ease }
|
|
32
|
+
.pulse-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-1)); border-color: var(--dsw-alias-border-l2) }
|
|
33
|
+
.pulse-btn:active:not(:disabled) { transform: scale(.97) }
|
|
34
|
+
.pulse-dot-live { animation: pulseGlow 2.4s ease-out infinite }
|
|
35
|
+
.pulse-spin { display: inline-block; animation: pulseSpin .8s linear infinite }
|
|
36
|
+
`
|
|
37
|
+
|
|
38
|
+
const dotStyle = (color) => ({
|
|
39
|
+
display: 'inline-block',
|
|
40
|
+
width: 7,
|
|
41
|
+
height: 7,
|
|
42
|
+
borderRadius: '50%',
|
|
43
|
+
background: color,
|
|
44
|
+
flexShrink: 0,
|
|
45
|
+
verticalAlign: 'middle',
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const btnBase = {
|
|
49
|
+
display: 'flex',
|
|
50
|
+
alignItems: 'center',
|
|
51
|
+
gap: 6,
|
|
52
|
+
padding: '4px 8px',
|
|
53
|
+
border: `1px solid ${T.border}`,
|
|
54
|
+
borderRadius: 6,
|
|
55
|
+
background: 'transparent',
|
|
56
|
+
color: T.label,
|
|
57
|
+
fontSize: 12,
|
|
58
|
+
lineHeight: '18px',
|
|
59
|
+
height: 28,
|
|
60
|
+
boxSizing: 'border-box',
|
|
61
|
+
cursor: 'pointer',
|
|
62
|
+
whiteSpace: 'nowrap',
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let overlayOpen = false
|
|
66
|
+
const listeners = new Set()
|
|
67
|
+
function setOverlay(val) {
|
|
68
|
+
overlayOpen = val
|
|
69
|
+
listeners.forEach((fn) => fn(val))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getQualityColor(quality, latencyMs) {
|
|
73
|
+
if (quality === 'excellent' || (latencyMs > 0 && latencyMs <= 200)) return T.ok
|
|
74
|
+
if (quality === 'good' || (latencyMs > 200 && latencyMs <= 600)) return T.warn
|
|
75
|
+
return T.err
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function formatModelShortName(modelId) {
|
|
79
|
+
if (!modelId) return 'Auto'
|
|
80
|
+
const m = modelId.toLowerCase()
|
|
81
|
+
if (m.includes('gemini-3.7') || m.includes('gemini-3-7')) return 'Gemini 3.7'
|
|
82
|
+
if (m.includes('gemini-2.5') || m.includes('gemini-2-5')) return 'Gemini 2.5'
|
|
83
|
+
if (m.includes('deepseek-v4-flash') || m.includes('v4-flash')) return 'V4 Flash'
|
|
84
|
+
if (m.includes('deepseek-v4-pro') || m.includes('v4-pro')) return 'V4 Pro'
|
|
85
|
+
if (m.includes('deepseek-chat')) return 'Chat'
|
|
86
|
+
if (m.includes('deepseek-reasoner')) return 'Reasoner'
|
|
87
|
+
if (m.includes('claude-3-7') || m.includes('claude-3.7')) return 'Claude 3.7'
|
|
88
|
+
if (m.includes('claude-3-5') || m.includes('claude-3.5')) return 'Claude 3.5'
|
|
89
|
+
if (m.includes('gpt-5')) return 'GPT-5.6'
|
|
90
|
+
if (m.includes('gpt-4o')) return 'GPT-4o'
|
|
91
|
+
if (m.includes('qwen3.7') || m.includes('qwen-3.7')) return 'Qwen 3.7'
|
|
92
|
+
if (m.includes('kimi-k3')) return 'Kimi K3'
|
|
93
|
+
if (m.includes('kimi-k2.7')) return 'Kimi K2.7'
|
|
94
|
+
if (m.includes('kimi')) return 'Kimi'
|
|
95
|
+
if (m.includes('minimax-m3')) return 'MiniMax M3'
|
|
96
|
+
if (m.includes('glm-5')) return 'GLM-5'
|
|
97
|
+
return modelId.split(/[-_]/)[0] || modelId
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function useActiveModel(defaultModel) {
|
|
101
|
+
const [activeModel, setActiveModel] = useState(defaultModel || 'gemini-3.7-flash-high')
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const detectModel = () => {
|
|
105
|
+
try {
|
|
106
|
+
const modelButton = document.querySelector(
|
|
107
|
+
'[data-slot="conversation.input.model"], button[class*="modelSelect"], div[class*="modelSelector"]',
|
|
108
|
+
)
|
|
109
|
+
if (modelButton && modelButton.textContent) {
|
|
110
|
+
const text = modelButton.textContent.trim()
|
|
111
|
+
if (text && text.length < 30) {
|
|
112
|
+
setActiveModel(text)
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch {}
|
|
117
|
+
if (defaultModel) setActiveModel(defaultModel)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
detectModel()
|
|
121
|
+
const timer = setInterval(detectModel, 3000)
|
|
122
|
+
return () => clearInterval(timer)
|
|
123
|
+
}, [defaultModel])
|
|
124
|
+
|
|
125
|
+
return activeModel
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function FooterEntry(props) {
|
|
129
|
+
const { wide } = props
|
|
130
|
+
const [isOpen, setIsOpen] = useState(overlayOpen)
|
|
131
|
+
const [data, setData] = useState(null)
|
|
132
|
+
const [loading, setLoading] = useState(false)
|
|
133
|
+
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
listeners.add(setIsOpen)
|
|
136
|
+
return () => listeners.delete(setIsOpen)
|
|
137
|
+
}, [])
|
|
138
|
+
|
|
139
|
+
const fetchData = useCallback(async () => {
|
|
140
|
+
try {
|
|
141
|
+
setLoading(true)
|
|
142
|
+
const res = await fetch('/api/link-pulse/status')
|
|
143
|
+
if (res.ok) {
|
|
144
|
+
const json = await res.json()
|
|
145
|
+
setData(json)
|
|
146
|
+
}
|
|
147
|
+
} catch {} finally {
|
|
148
|
+
setLoading(false)
|
|
149
|
+
}
|
|
150
|
+
}, [])
|
|
151
|
+
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
fetchData()
|
|
154
|
+
const timer = setInterval(fetchData, 45_000)
|
|
155
|
+
return () => clearInterval(timer)
|
|
156
|
+
}, [fetchData])
|
|
157
|
+
|
|
158
|
+
const defaultModel = data?.defaultModelConfig?.model || 'gemini-3.7-flash-high'
|
|
159
|
+
const activeModel = useActiveModel(defaultModel)
|
|
160
|
+
|
|
161
|
+
const activeProviderInfo = useMemo(() => {
|
|
162
|
+
if (!data || !data.providers) return null
|
|
163
|
+
const map = data.modelToProviderMap || {}
|
|
164
|
+
const pId = map[activeModel.toLowerCase()] || data.defaultModelConfig?.provider || 'cpa'
|
|
165
|
+
return data.providers.find((p) => p.id === pId) || data.providers[0] || null
|
|
166
|
+
}, [data, activeModel])
|
|
167
|
+
|
|
168
|
+
const currentLatency = activeProviderInfo?.probe?.latencyMs ?? -1
|
|
169
|
+
const currentQuality = activeProviderInfo?.probe?.quality || 'offline'
|
|
170
|
+
const statusColor = getQualityColor(currentQuality, currentLatency)
|
|
171
|
+
const providerDisplayName = activeProviderInfo?.name || 'CPA'
|
|
172
|
+
const modelShortName = formatModelShortName(activeModel)
|
|
173
|
+
|
|
174
|
+
const tooltipText = useMemo(() => {
|
|
175
|
+
if (!data?.providers) return '链路测速中...'
|
|
176
|
+
const lines = [`🎯 当前对话模型: ${activeModel}`]
|
|
177
|
+
lines.push(`🏢 归属供应商: ${providerDisplayName}`)
|
|
178
|
+
lines.push(`⚡ 实时往返延迟: ${currentLatency > 0 ? currentLatency + ' ms' : '检测中'}`)
|
|
179
|
+
lines.push('────────────────────────')
|
|
180
|
+
lines.push('🌐 已接入 Provider 链路一览:')
|
|
181
|
+
for (const p of data.providers) {
|
|
182
|
+
const lat = p.probe?.latencyMs > 0 ? `${p.probe.latencyMs}ms` : '离线'
|
|
183
|
+
lines.push(`• ${p.name}: ${lat}`)
|
|
184
|
+
}
|
|
185
|
+
return lines.join('\n')
|
|
186
|
+
}, [data, activeModel, providerDisplayName, currentLatency])
|
|
187
|
+
|
|
188
|
+
return h(
|
|
189
|
+
'button',
|
|
190
|
+
{
|
|
191
|
+
className: 'pulse-btn',
|
|
192
|
+
onClick: () => setOverlay(!isOpen),
|
|
193
|
+
title: tooltipText,
|
|
194
|
+
style: {
|
|
195
|
+
...btnBase,
|
|
196
|
+
width: '100%',
|
|
197
|
+
justifyContent: wide ? 'flex-start' : 'center',
|
|
198
|
+
borderColor: isOpen ? T.brand : T.border,
|
|
199
|
+
background: isOpen ? 'var(--dsw-alias-interactive-bg-hover, rgba(59,130,246,.12))' : 'transparent',
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
h('span', {
|
|
203
|
+
className: statusColor === T.ok ? 'pulse-dot-live' : undefined,
|
|
204
|
+
style: dotStyle(statusColor),
|
|
205
|
+
}),
|
|
206
|
+
wide &&
|
|
207
|
+
h(
|
|
208
|
+
'div',
|
|
209
|
+
{
|
|
210
|
+
style: {
|
|
211
|
+
display: 'flex',
|
|
212
|
+
alignItems: 'center',
|
|
213
|
+
justifyContent: 'space-between',
|
|
214
|
+
flex: 1,
|
|
215
|
+
overflow: 'hidden',
|
|
216
|
+
whiteSpace: 'nowrap',
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
h(
|
|
220
|
+
'div',
|
|
221
|
+
{
|
|
222
|
+
style: {
|
|
223
|
+
display: 'flex',
|
|
224
|
+
alignItems: 'center',
|
|
225
|
+
gap: 3,
|
|
226
|
+
overflow: 'hidden',
|
|
227
|
+
textOverflow: 'ellipsis',
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
h('span', { style: { fontWeight: 500, color: T.label } }, providerDisplayName),
|
|
231
|
+
h('span', { style: { color: T.secondary } }, '·'),
|
|
232
|
+
h('span', { style: { color: T.secondary, overflow: 'hidden', textOverflow: 'ellipsis' } }, modelShortName),
|
|
233
|
+
),
|
|
234
|
+
h(
|
|
235
|
+
'span',
|
|
236
|
+
{
|
|
237
|
+
style: {
|
|
238
|
+
fontSize: 11,
|
|
239
|
+
fontWeight: 600,
|
|
240
|
+
color: statusColor,
|
|
241
|
+
marginLeft: 6,
|
|
242
|
+
flexShrink: 0,
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
currentLatency > 0 ? `${currentLatency}ms` : '探测中',
|
|
246
|
+
),
|
|
247
|
+
),
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function OverlayPanel() {
|
|
252
|
+
const [isOpen, setIsOpen] = useState(overlayOpen)
|
|
253
|
+
const [data, setData] = useState(null)
|
|
254
|
+
const [loading, setLoading] = useState(false)
|
|
255
|
+
|
|
256
|
+
useEffect(() => {
|
|
257
|
+
listeners.add(setIsOpen)
|
|
258
|
+
return () => listeners.delete(setIsOpen)
|
|
259
|
+
}, [])
|
|
260
|
+
|
|
261
|
+
const fetchData = useCallback(async () => {
|
|
262
|
+
try {
|
|
263
|
+
setLoading(true)
|
|
264
|
+
const res = await fetch('/api/link-pulse/status')
|
|
265
|
+
if (res.ok) {
|
|
266
|
+
const json = await res.json()
|
|
267
|
+
setData(json)
|
|
268
|
+
}
|
|
269
|
+
} catch {} finally {
|
|
270
|
+
setLoading(false)
|
|
271
|
+
}
|
|
272
|
+
}, [])
|
|
273
|
+
|
|
274
|
+
useEffect(() => {
|
|
275
|
+
if (isOpen) fetchData()
|
|
276
|
+
}, [isOpen, fetchData])
|
|
277
|
+
|
|
278
|
+
const defaultModel = data?.defaultModelConfig?.model || 'gemini-3.7-flash-high'
|
|
279
|
+
const activeModel = useActiveModel(defaultModel)
|
|
280
|
+
|
|
281
|
+
const activeProviderInfo = useMemo(() => {
|
|
282
|
+
if (!data || !data.providers) return null
|
|
283
|
+
const map = data.modelToProviderMap || {}
|
|
284
|
+
const pId = map[activeModel.toLowerCase()] || data.defaultModelConfig?.provider || 'cpa'
|
|
285
|
+
return data.providers.find((p) => p.id === pId) || data.providers[0] || null
|
|
286
|
+
}, [data, activeModel])
|
|
287
|
+
|
|
288
|
+
if (!isOpen) return null
|
|
289
|
+
|
|
290
|
+
const providers = data?.providers || []
|
|
291
|
+
const currentLatency = activeProviderInfo?.probe?.latencyMs ?? -1
|
|
292
|
+
const currentQuality = activeProviderInfo?.probe?.quality || 'offline'
|
|
293
|
+
const statusColor = getQualityColor(currentQuality, currentLatency)
|
|
294
|
+
|
|
295
|
+
return h(
|
|
296
|
+
'div',
|
|
297
|
+
{
|
|
298
|
+
style: {
|
|
299
|
+
position: 'fixed',
|
|
300
|
+
inset: 0,
|
|
301
|
+
zIndex: 9999,
|
|
302
|
+
display: 'flex',
|
|
303
|
+
alignItems: 'center',
|
|
304
|
+
justifyContent: 'center',
|
|
305
|
+
background: 'rgba(0,0,0,.45)',
|
|
306
|
+
backdropFilter: 'blur(4px)',
|
|
307
|
+
},
|
|
308
|
+
onClick: (e) => {
|
|
309
|
+
if (e.target === e.currentTarget) setOverlay(false)
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
h(
|
|
313
|
+
'div',
|
|
314
|
+
{
|
|
315
|
+
className: 'pulse-panel-enter',
|
|
316
|
+
style: {
|
|
317
|
+
width: '92%',
|
|
318
|
+
maxWidth: '540px',
|
|
319
|
+
background: T.bg,
|
|
320
|
+
border: `1px solid ${T.border2}`,
|
|
321
|
+
borderRadius: '16px',
|
|
322
|
+
boxShadow: '0 20px 40px rgba(0,0,0,.25)',
|
|
323
|
+
color: T.label,
|
|
324
|
+
overflow: 'hidden',
|
|
325
|
+
fontFamily: 'system-ui, -apple-system, sans-serif',
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
h(
|
|
329
|
+
'div',
|
|
330
|
+
{
|
|
331
|
+
style: {
|
|
332
|
+
display: 'flex',
|
|
333
|
+
alignItems: 'center',
|
|
334
|
+
justifyContent: 'space-between',
|
|
335
|
+
padding: '16px 20px',
|
|
336
|
+
borderBottom: `1px solid ${T.border}`,
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
h(
|
|
340
|
+
'div',
|
|
341
|
+
{ style: { display: 'flex', alignItems: 'center', gap: '10px' } },
|
|
342
|
+
h('span', { style: { fontSize: '20px' } }, '📡'),
|
|
343
|
+
h(
|
|
344
|
+
'div',
|
|
345
|
+
null,
|
|
346
|
+
h('div', { style: { fontSize: '15px', fontWeight: 600 } }, '模型链路与上游延迟脉搏'),
|
|
347
|
+
h(
|
|
348
|
+
'div',
|
|
349
|
+
{ style: { fontSize: '11px', color: T.secondary } },
|
|
350
|
+
'仅探测本机实际接入的 LLM Provider 网关',
|
|
351
|
+
),
|
|
352
|
+
),
|
|
353
|
+
),
|
|
354
|
+
h(
|
|
355
|
+
'div',
|
|
356
|
+
{ style: { display: 'flex', alignItems: 'center', gap: '8px' } },
|
|
357
|
+
h(
|
|
358
|
+
'button',
|
|
359
|
+
{
|
|
360
|
+
className: 'pulse-btn',
|
|
361
|
+
onClick: fetchData,
|
|
362
|
+
disabled: loading,
|
|
363
|
+
style: {
|
|
364
|
+
display: 'flex',
|
|
365
|
+
alignItems: 'center',
|
|
366
|
+
gap: '4px',
|
|
367
|
+
padding: '5px 12px',
|
|
368
|
+
borderRadius: '6px',
|
|
369
|
+
border: `1px solid ${T.border}`,
|
|
370
|
+
background: 'transparent',
|
|
371
|
+
color: T.label,
|
|
372
|
+
fontSize: '12px',
|
|
373
|
+
fontWeight: 500,
|
|
374
|
+
cursor: 'pointer',
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
loading ? h('span', { className: 'pulse-spin' }, '⚡') : '⚡ 立即测速',
|
|
378
|
+
),
|
|
379
|
+
h(
|
|
380
|
+
'button',
|
|
381
|
+
{
|
|
382
|
+
className: 'pulse-btn',
|
|
383
|
+
onClick: () => setOverlay(false),
|
|
384
|
+
style: {
|
|
385
|
+
padding: '4px 8px',
|
|
386
|
+
borderRadius: '6px',
|
|
387
|
+
border: `1px solid ${T.border}`,
|
|
388
|
+
background: 'transparent',
|
|
389
|
+
color: T.secondary,
|
|
390
|
+
fontSize: '14px',
|
|
391
|
+
cursor: 'pointer',
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
'✕',
|
|
395
|
+
),
|
|
396
|
+
),
|
|
397
|
+
),
|
|
398
|
+
h(
|
|
399
|
+
'div',
|
|
400
|
+
{
|
|
401
|
+
style: {
|
|
402
|
+
padding: '20px',
|
|
403
|
+
display: 'flex',
|
|
404
|
+
flexDirection: 'column',
|
|
405
|
+
gap: '14px',
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
h(
|
|
409
|
+
'div',
|
|
410
|
+
{
|
|
411
|
+
style: {
|
|
412
|
+
background: T.layer1,
|
|
413
|
+
border: `1px solid ${T.border}`,
|
|
414
|
+
borderRadius: '12px',
|
|
415
|
+
padding: '14px 16px',
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
h(
|
|
419
|
+
'div',
|
|
420
|
+
{
|
|
421
|
+
style: {
|
|
422
|
+
display: 'flex',
|
|
423
|
+
justifyContent: 'space-between',
|
|
424
|
+
alignItems: 'center',
|
|
425
|
+
marginBottom: '8px',
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
h(
|
|
429
|
+
'div',
|
|
430
|
+
{ style: { display: 'flex', alignItems: 'center', gap: '8px' } },
|
|
431
|
+
h('span', { style: dotStyle(statusColor) }),
|
|
432
|
+
h('span', { style: { fontWeight: 600, fontSize: '14px' } }, activeModel),
|
|
433
|
+
h(
|
|
434
|
+
'span',
|
|
435
|
+
{
|
|
436
|
+
style: {
|
|
437
|
+
fontSize: '10px',
|
|
438
|
+
padding: '2px 6px',
|
|
439
|
+
borderRadius: '4px',
|
|
440
|
+
background: 'rgba(59,130,246,.15)',
|
|
441
|
+
color: T.brand,
|
|
442
|
+
fontWeight: 600,
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
`供应商: ${activeProviderInfo?.name || 'CPA'}`,
|
|
446
|
+
),
|
|
447
|
+
),
|
|
448
|
+
h(
|
|
449
|
+
'span',
|
|
450
|
+
{
|
|
451
|
+
style: {
|
|
452
|
+
fontSize: '16px',
|
|
453
|
+
fontWeight: 700,
|
|
454
|
+
color: statusColor,
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
currentLatency > 0 ? `${currentLatency} ms` : '检测中',
|
|
458
|
+
),
|
|
459
|
+
),
|
|
460
|
+
h(
|
|
461
|
+
'div',
|
|
462
|
+
{ style: { fontSize: '11px', color: T.secondary, wordBreak: 'break-all' } },
|
|
463
|
+
`网关端点: ${activeProviderInfo?.baseURL || '系统内置直连通道'}`,
|
|
464
|
+
),
|
|
465
|
+
),
|
|
466
|
+
h(
|
|
467
|
+
'div',
|
|
468
|
+
{
|
|
469
|
+
style: {
|
|
470
|
+
background: T.layer1,
|
|
471
|
+
border: `1px solid ${T.border}`,
|
|
472
|
+
borderRadius: '12px',
|
|
473
|
+
padding: '14px 16px',
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
h(
|
|
477
|
+
'div',
|
|
478
|
+
{
|
|
479
|
+
style: {
|
|
480
|
+
fontSize: '12px',
|
|
481
|
+
fontWeight: 600,
|
|
482
|
+
color: T.secondary,
|
|
483
|
+
marginBottom: '10px',
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
'🌐 已接入 Provider 链路测速对比',
|
|
487
|
+
),
|
|
488
|
+
h(
|
|
489
|
+
'div',
|
|
490
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
|
|
491
|
+
providers.map((p, idx) => {
|
|
492
|
+
const lat = p.probe?.latencyMs ?? -1
|
|
493
|
+
const qual = p.probe?.quality || 'offline'
|
|
494
|
+
const col = getQualityColor(qual, lat)
|
|
495
|
+
const isCurrent = activeProviderInfo?.id === p.id
|
|
496
|
+
|
|
497
|
+
return h(
|
|
498
|
+
'div',
|
|
499
|
+
{
|
|
500
|
+
key: idx,
|
|
501
|
+
style: {
|
|
502
|
+
display: 'flex',
|
|
503
|
+
justifyContent: 'space-between',
|
|
504
|
+
alignItems: 'center',
|
|
505
|
+
padding: '8px 10px',
|
|
506
|
+
borderRadius: '8px',
|
|
507
|
+
background: isCurrent ? 'rgba(59,130,246,.08)' : 'rgba(0,0,0,.03)',
|
|
508
|
+
border: `1px solid ${isCurrent ? 'rgba(59,130,246,.3)' : 'transparent'}`,
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
h(
|
|
512
|
+
'div',
|
|
513
|
+
null,
|
|
514
|
+
h(
|
|
515
|
+
'div',
|
|
516
|
+
{ style: { display: 'flex', alignItems: 'center', gap: '6px' } },
|
|
517
|
+
h('span', { style: dotStyle(col) }),
|
|
518
|
+
h('span', { style: { fontWeight: 600, fontSize: '12px' } }, p.name),
|
|
519
|
+
isCurrent &&
|
|
520
|
+
h(
|
|
521
|
+
'span',
|
|
522
|
+
{
|
|
523
|
+
style: {
|
|
524
|
+
fontSize: '9px',
|
|
525
|
+
color: T.brand,
|
|
526
|
+
fontWeight: 600,
|
|
527
|
+
},
|
|
528
|
+
},
|
|
529
|
+
'● 当前主力',
|
|
530
|
+
),
|
|
531
|
+
),
|
|
532
|
+
h(
|
|
533
|
+
'div',
|
|
534
|
+
{ style: { fontSize: '10px', color: T.secondary, marginTop: '2px' } },
|
|
535
|
+
p.baseURL || '官方内置通道',
|
|
536
|
+
),
|
|
537
|
+
),
|
|
538
|
+
h(
|
|
539
|
+
'div',
|
|
540
|
+
{ style: { textAlign: 'right' } },
|
|
541
|
+
h(
|
|
542
|
+
'div',
|
|
543
|
+
{ style: { fontWeight: 700, fontSize: '13px', color: col } },
|
|
544
|
+
lat > 0 ? `${lat} ms` : '超时/离线',
|
|
545
|
+
),
|
|
546
|
+
h(
|
|
547
|
+
'div',
|
|
548
|
+
{ style: { fontSize: '9px', color: T.secondary } },
|
|
549
|
+
lat > 0 ? (lat < 200 ? '极佳' : '良好') : '不可达',
|
|
550
|
+
),
|
|
551
|
+
),
|
|
552
|
+
)
|
|
553
|
+
}),
|
|
554
|
+
),
|
|
555
|
+
),
|
|
556
|
+
),
|
|
557
|
+
),
|
|
558
|
+
)
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function apply(ctx) {
|
|
562
|
+
ctx.effect(() => {
|
|
563
|
+
const el = document.createElement('style')
|
|
564
|
+
el.id = 'dsh-link-pulse-styles'
|
|
565
|
+
el.textContent = CSS
|
|
566
|
+
document.head.appendChild(el)
|
|
567
|
+
return () => el.remove()
|
|
568
|
+
})
|
|
569
|
+
|
|
570
|
+
ctx.effect(() =>
|
|
571
|
+
ctx.slots.inject('sidebar.footer.action', () =>
|
|
572
|
+
ctx.slots.register(
|
|
573
|
+
{ name: 'sidebar.footer.action', id: 'link-pulse', order: -10 },
|
|
574
|
+
(props) => h(FooterEntry, props),
|
|
575
|
+
),
|
|
576
|
+
),
|
|
577
|
+
)
|
|
578
|
+
|
|
579
|
+
ctx.effect(() =>
|
|
580
|
+
ctx.slots.inject('shell.overlay', () =>
|
|
581
|
+
ctx.slots.register(
|
|
582
|
+
{ name: 'shell.overlay', id: 'link-pulse-panel', order: 5 },
|
|
583
|
+
() => h(OverlayPanel),
|
|
584
|
+
),
|
|
585
|
+
),
|
|
586
|
+
)
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
exports.apply = apply
|
|
590
|
+
exports.inject = ['slots']
|
|
591
|
+
return module.exports
|
|
592
|
+
},
|
|
593
|
+
})
|
package/src/index.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import jsYaml from 'js-yaml'
|
|
5
|
+
|
|
6
|
+
export const name = 'link-pulse'
|
|
7
|
+
export const inject = ['webServer']
|
|
8
|
+
|
|
9
|
+
function getSettingsPath() {
|
|
10
|
+
const dshHome = process.env.DSH_HOME || path.join(os.homedir(), '.dsh')
|
|
11
|
+
return path.join(dshHome, 'settings.yaml')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function loadDynamicProviders() {
|
|
15
|
+
const settingsPath = getSettingsPath()
|
|
16
|
+
let settings = {}
|
|
17
|
+
if (fs.existsSync(settingsPath)) {
|
|
18
|
+
try {
|
|
19
|
+
const raw = fs.readFileSync(settingsPath, 'utf8')
|
|
20
|
+
settings = jsYaml.load(raw) || {}
|
|
21
|
+
} catch {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const providersConfig = settings['llm-pi-ai']?.providers || {}
|
|
25
|
+
const defaultModelConfig = settings['agent-default-model'] || {
|
|
26
|
+
provider: 'cpa',
|
|
27
|
+
model: 'gemini-3.7-flash-high',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const providers = []
|
|
31
|
+
const modelToProviderMap = {}
|
|
32
|
+
|
|
33
|
+
for (const [providerId, pConfig] of Object.entries(providersConfig)) {
|
|
34
|
+
const rawModels = pConfig.models || []
|
|
35
|
+
const modelList = rawModels.map((m) => (typeof m === 'string' ? m : m.id || m.name)).filter(Boolean)
|
|
36
|
+
|
|
37
|
+
for (const m of modelList) {
|
|
38
|
+
modelToProviderMap[m.toLowerCase()] = providerId
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let targetBaseUrl = pConfig.baseURL || ''
|
|
42
|
+
if (!targetBaseUrl && providerId === 'opencode-go') {
|
|
43
|
+
targetBaseUrl = 'https://api.deepseek.com'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
providers.push({
|
|
47
|
+
id: providerId,
|
|
48
|
+
name: providerId.toUpperCase(),
|
|
49
|
+
baseURL: targetBaseUrl,
|
|
50
|
+
api: pConfig.api || 'openai-responses',
|
|
51
|
+
models: modelList,
|
|
52
|
+
isDefault: defaultModelConfig.provider === providerId,
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!providers.some((p) => p.id === 'deepseek' || p.id === 'deepseek-official')) {
|
|
57
|
+
const dsModels = ['deepseek-chat', 'deepseek-reasoner', 'deepseek-v3', 'deepseek-r1']
|
|
58
|
+
for (const m of dsModels) {
|
|
59
|
+
if (!modelToProviderMap[m]) {
|
|
60
|
+
modelToProviderMap[m] = 'deepseek'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
providers.push({
|
|
64
|
+
id: 'deepseek',
|
|
65
|
+
name: 'DeepSeek 官方',
|
|
66
|
+
baseURL: 'https://api.deepseek.com',
|
|
67
|
+
api: 'deepseek-native',
|
|
68
|
+
models: dsModels,
|
|
69
|
+
isDefault: defaultModelConfig.provider === 'deepseek',
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
providers,
|
|
75
|
+
defaultModelConfig,
|
|
76
|
+
modelToProviderMap,
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function probeLatency(url) {
|
|
81
|
+
if (!url || !/^https?:\/\//i.test(url)) {
|
|
82
|
+
return { latencyMs: -1, status: 'no_url', quality: 'offline', error: '无有效网络地址' }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let probeUrl = url
|
|
86
|
+
try {
|
|
87
|
+
const parsed = new URL(url)
|
|
88
|
+
probeUrl = `${parsed.protocol}//${parsed.host}`
|
|
89
|
+
} catch {}
|
|
90
|
+
|
|
91
|
+
const start = performance.now()
|
|
92
|
+
const controller = new AbortController()
|
|
93
|
+
const timeoutId = setTimeout(() => controller.abort(), 3500)
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
const res = await fetch(probeUrl, {
|
|
97
|
+
method: 'HEAD',
|
|
98
|
+
signal: controller.signal,
|
|
99
|
+
headers: { 'User-Agent': 'DSH-LinkPulse/1.0' },
|
|
100
|
+
}).catch(async () => {
|
|
101
|
+
return await fetch(probeUrl, {
|
|
102
|
+
method: 'GET',
|
|
103
|
+
signal: controller.signal,
|
|
104
|
+
headers: { 'User-Agent': 'DSH-LinkPulse/1.0' },
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
clearTimeout(timeoutId)
|
|
109
|
+
const latencyMs = Math.round(performance.now() - start)
|
|
110
|
+
|
|
111
|
+
let quality = 'excellent'
|
|
112
|
+
if (latencyMs > 600) quality = 'slow'
|
|
113
|
+
else if (latencyMs > 200) quality = 'good'
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
latencyMs,
|
|
117
|
+
httpStatus: res.status,
|
|
118
|
+
quality,
|
|
119
|
+
reachable: true,
|
|
120
|
+
}
|
|
121
|
+
} catch (err) {
|
|
122
|
+
clearTimeout(timeoutId)
|
|
123
|
+
const isTimeout = err.name === 'AbortError'
|
|
124
|
+
return {
|
|
125
|
+
latencyMs: isTimeout ? 3500 : -1,
|
|
126
|
+
quality: isTimeout ? 'timeout' : 'error',
|
|
127
|
+
reachable: false,
|
|
128
|
+
error: isTimeout ? '请求超时 (>3.5s)' : (err.message || '连接失败'),
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function sendJson(res, statusCode, data) {
|
|
134
|
+
res.statusCode = statusCode
|
|
135
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8')
|
|
136
|
+
res.setHeader('Cache-Control', 'no-store')
|
|
137
|
+
res.end(JSON.stringify(data))
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function apply(ctx) {
|
|
141
|
+
ctx.effect(() =>
|
|
142
|
+
ctx.webServer.register({
|
|
143
|
+
kind: 'exact',
|
|
144
|
+
path: '/api/link-pulse/status',
|
|
145
|
+
handler: async (req, res) => {
|
|
146
|
+
if (req.method !== 'GET') {
|
|
147
|
+
return sendJson(res, 405, { error: 'GET only' })
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
const { providers, defaultModelConfig, modelToProviderMap } = loadDynamicProviders()
|
|
152
|
+
|
|
153
|
+
const probePromises = providers.map(async (p) => {
|
|
154
|
+
const probeResult = await probeLatency(p.baseURL)
|
|
155
|
+
return {
|
|
156
|
+
...p,
|
|
157
|
+
probe: probeResult,
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
const probedProviders = await Promise.all(probePromises)
|
|
162
|
+
|
|
163
|
+
sendJson(res, 200, {
|
|
164
|
+
defaultModelConfig,
|
|
165
|
+
modelToProviderMap,
|
|
166
|
+
providers: probedProviders,
|
|
167
|
+
timestamp: Date.now(),
|
|
168
|
+
})
|
|
169
|
+
} catch (err) {
|
|
170
|
+
sendJson(res, 500, { error: String(err && err.message ? err.message : err) })
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
}),
|
|
174
|
+
)
|
|
175
|
+
}
|