dsh-ollama-usage 0.1.12 → 0.1.13
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/README.en.md +12 -2
- package/README.md +12 -2
- package/lib/client.js +152 -87
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -28,7 +28,7 @@ plugin's own detail page, persisted credentials & snapshots, auto-refresh.
|
|
|
28
28
|
| 🎯 **Session usage (per 5 hours)** | Ollama Cloud's 5-hour session quota, pinned at the top showing "used X% · remaining Y%" |
|
|
29
29
|
| 📅 **Weekly usage** | This week's quota progress, shown next to the session usage |
|
|
30
30
|
| 🎨 **Sidebar dual bars** | Minimal, transparent style: session 5h in **light purple** + weekly in **deep purple**, each with a percentage, details on hover, refreshed every 60 seconds (auto-hidden on narrow layouts) |
|
|
31
|
-
| 🖥️ **Full panel on the plugin detail page** | Rendered between the description and component rows of the "Plugin list → dsh-ollama-usage" page: session/week usage bars, session and weekly reset countdowns, and the last 5 session-usage history entries |
|
|
31
|
+
| 🖥️ **Full panel on the plugin detail page** | Rendered between the description and component rows of the "Plugin list → dsh-ollama-usage" page: session/week usage bars, session and weekly reset countdowns, and the last 5 session-usage history entries; card-based sections with loading / error / success states |
|
|
32
32
|
| 💾 **Persistence** | The API Key and usage snapshot are written to `$DSH_HOME/storages/ollama-usage/usage.json` (mode 600, 24 history entries kept), restored automatically across conversations / restarts |
|
|
33
33
|
| 🔄 **Auto-refresh** | The host queries every 10 minutes (even when the page is closed); an invalidated Key (401) is cleared automatically with a prompt |
|
|
34
34
|
| 🔑 **Login guidance** | When not signed in, one click opens [ollama.com/settings](https://ollama.com/settings) to sign in and [settings/keys](https://ollama.com/settings/keys) to create an API Key; compatible with the legacy CLI's `~/.ollama/auth.json` |
|
|
@@ -62,6 +62,16 @@ dsh --profile web
|
|
|
62
62
|
3. On success it is persisted; expand the sidebar to see the dual bars at the bottom, and the panel shows details and history at any time;
|
|
63
63
|
4. When no longer needed, click **Clear stored Key** to remove the local credential (history is kept).
|
|
64
64
|
|
|
65
|
+
## 🖼️ 界面预览 / Screenshots
|
|
66
|
+
|
|
67
|
+
The screenshots below come from a throwaway local preview instance; the example data is for demonstration only:
|
|
68
|
+
|
|
69
|
+

|
|
70
|
+
|
|
71
|
+

|
|
72
|
+
|
|
73
|
+

|
|
74
|
+
|
|
65
75
|
## 🔒 数据与隐私 / Privacy
|
|
66
76
|
|
|
67
77
|
- Only a Bearer-carrying query request is sent to `https://ollama.com/api/balance`;
|
|
@@ -104,7 +114,7 @@ Since DSH 0.2.1 the compatibility gate prefers `engines.dsh`. This plugin declar
|
|
|
104
114
|
|
|
105
115
|
> Only versions that were **actually run** are listed; untested versions are omitted.
|
|
106
116
|
|
|
107
|
-
v0.1.
|
|
117
|
+
v0.1.13 targets DSH **≥0.1.5-rc.1** (the `@deepseek-ai/dsh-*` peer was relaxed to `>=0.1.7-rc.1`), verified on **0.1.5-rc.1 / 0.1.5-rc.2 / 0.1.6-alpha.2 / 0.1.7-rc.1 / 0.1.7-rc.2 / 0.2.0-rc.1** (all RPC envelope probes pass; on 0.1.7-rc.2 the `/ollama-usage/snapshot` endpoint returns as measured; on 0.2.0-rc.1 it passes the new compatibility gate and loads normally; on 0.2.1-rc.1 the gate and RPC envelope probes pass, and 0.2.1-rc.2 passes the gate); for older DSH (0.1.0-rc.5 ~ rc.8) use the last compatible npm version, **0.1.5**.
|
|
108
118
|
|
|
109
119
|
## 🛠️ 开发 / Develop
|
|
110
120
|
|
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ plugin's own detail page, persisted credentials & snapshots, auto-refresh.*
|
|
|
31
31
|
| 🎯 **会话用量(每 5 小时)** | Ollama Cloud 的 5 小时会话配额,置顶展示「已用 X% · 剩余 Y%」 |
|
|
32
32
|
| 📅 **周用量(Weekly)** | 本周配额进度,与会话用量并排展示 |
|
|
33
33
|
| 🎨 **侧边栏双横条** | 极简透明风格:会话 5h **淡紫** + 周用量**深紫**,各带百分比数字,悬停显示详情,每 60 秒自动更新(窄栏自动隐藏) |
|
|
34
|
-
| 🖥️ **插件详情页完整面板** | 渲染在「插件列表 → dsh-ollama-usage」页面的描述与组件行之间:会话/周用量进度条、会话与周重置倒计时、最近 5
|
|
34
|
+
| 🖥️ **插件详情页完整面板** | 渲染在「插件列表 → dsh-ollama-usage」页面的描述与组件行之间:会话/周用量进度条、会话与周重置倒计时、最近 5 条会话用量历史;卡片化分区,带加载 / 错误 / 成功状态提示 |
|
|
35
35
|
| 💾 **持久化** | API Key 与用量快照写入 `$DSH_HOME/storages/ollama-usage/usage.json`(权限 600,保留 24 条历史),跨对话 / 重启自动恢复 |
|
|
36
36
|
| 🔄 **自动刷新** | Host 每 10 分钟自动查询(页面关闭也持续);Key 失效(401)自动清除并提示 |
|
|
37
37
|
| 🔑 **登录引导** | 未登录时一键打开 [ollama.com/settings](https://ollama.com/settings) 登录、到 [settings/keys](https://ollama.com/settings/keys) 创建 API Key;兼容旧版 CLI 的 `~/.ollama/auth.json` |
|
|
@@ -65,6 +65,16 @@ dsh --profile web
|
|
|
65
65
|
3. 检测成功后即持久化,展开侧边栏即可看到底部双横条,面板可随时查看详情与历史;
|
|
66
66
|
4. 不再需要时点 **清除已存 Key** 移除本地凭证(历史保留)。
|
|
67
67
|
|
|
68
|
+
## 🖼️ 界面预览 / Screenshots
|
|
69
|
+
|
|
70
|
+
以下截图来自本地一次性预览实例,示例数据仅用于演示:
|
|
71
|
+
|
|
72
|
+

|
|
73
|
+
|
|
74
|
+

|
|
75
|
+
|
|
76
|
+

|
|
77
|
+
|
|
68
78
|
## 🔒 数据与隐私 / Privacy
|
|
69
79
|
|
|
70
80
|
- 仅向 `https://ollama.com/api/balance` 发送带 Bearer 的查询请求;
|
|
@@ -107,7 +117,7 @@ DSH 0.2.1 起兼容门禁优先读取 `engines.dsh`。本插件声明 **`engines
|
|
|
107
117
|
|
|
108
118
|
> 只列出**实际跑过**的版本;未实测的不列。
|
|
109
119
|
|
|
110
|
-
v0.1.
|
|
120
|
+
v0.1.13 支持 DSH **≥0.1.5-rc.1**(`@deepseek-ai/dsh-*` peer 放宽为 `>=0.1.7-rc.1`),已在 **0.1.5-rc.1 / 0.1.5-rc.2 / 0.1.6-alpha.2 / 0.1.7-rc.1 / 0.1.7-rc.2 / 0.2.0-rc.1** 实测(RPC envelope 探针全过;0.1.7-rc.2 上 `/ollama-usage/snapshot` 实测返回;0.2.0-rc.1 上通过新的兼容性门禁并正常加载;0.2.1-rc.1 上兼容门禁与 RPC envelope 探针通过,0.2.1-rc.2 门禁通过);旧版 DSH(0.1.0-rc.5 ~ rc.8)请使用最后兼容的 npm 版本 **0.1.5**。
|
|
111
121
|
|
|
112
122
|
## 🛠️ 开发 / Develop
|
|
113
123
|
|
package/lib/client.js
CHANGED
|
@@ -6,12 +6,15 @@
|
|
|
6
6
|
* 进度条、会话与周用量重置倒计时、历史记录、API Key 配置、清除 Key)。
|
|
7
7
|
* 渲染在「插件列表 → dsh-ollama-usage」页面的描述与组件行之间 ——
|
|
8
8
|
* 配置不再位于设置面板(settings.section 已退役);
|
|
9
|
-
* - sidebar.footer.action:极简双横条(会话 5h
|
|
9
|
+
* - sidebar.footer.action:极简双横条(会话 5h / 周用量,紫为主的数据可视化强调色);
|
|
10
10
|
* - tool.view.cordis:Run 卡片内的同款面板。
|
|
11
11
|
*
|
|
12
12
|
* 数据通道:Host 在 webServer 注册的 /ollama-usage 前缀路由,经 Connection
|
|
13
|
-
* RPC 信封协议调用(check / snapshot / forget)
|
|
14
|
-
*
|
|
13
|
+
* RPC 信封协议调用(check / snapshot / forget)。
|
|
14
|
+
*
|
|
15
|
+
* 呈现层:手写 <style> 注入,颜色/字体/圆角/阴影/焦点环全部来自官方 --dsw-*
|
|
16
|
+
* 主题变量,亮暗主题自动成立。唯一保留的硬编码颜色是双横条的两档紫色,按规范
|
|
17
|
+
* 只作为「数据可视化强调色」用于横条填充,不扩散到任何通用控件。
|
|
15
18
|
*/
|
|
16
19
|
|
|
17
20
|
window.__ModuleLoader__.load({
|
|
@@ -25,52 +28,87 @@ window.__ModuleLoader__.load({
|
|
|
25
28
|
|
|
26
29
|
const RPC_CHANNEL = '/ollama-usage'
|
|
27
30
|
const CSS_TAG_ID = 'dsh-ollama-usage/client.css'
|
|
31
|
+
// 数据可视化强调色:仅用于侧栏双横条的填充(会话 5h 淡紫 / 周用量深紫),
|
|
32
|
+
// 属于插件品牌识别,不用于按钮、边框、文字等通用控件。
|
|
28
33
|
const SESSION_COLOR = '#b39df7'
|
|
29
34
|
const WEEKLY_COLOR = '#7c66e8'
|
|
30
35
|
|
|
31
36
|
const CSS = [
|
|
32
|
-
|
|
33
|
-
'.olusa-
|
|
34
|
-
'.olusa-
|
|
35
|
-
'.olusa-
|
|
36
|
-
'.olusa-
|
|
37
|
-
'.olusa-
|
|
38
|
-
'.olusa-
|
|
39
|
-
'.olusa-
|
|
40
|
-
'.olusa-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
'.olusa-
|
|
44
|
-
'.olusa-
|
|
45
|
-
'.olusa-
|
|
46
|
-
'.olusa-
|
|
47
|
-
'.olusa-
|
|
48
|
-
'.olusa-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
'.olusa-
|
|
52
|
-
'.olusa-
|
|
53
|
-
'.olusa-
|
|
54
|
-
'.olusa-
|
|
55
|
-
'.olusa-
|
|
56
|
-
'.olusa-
|
|
57
|
-
'.olusa-
|
|
58
|
-
'.olusa-
|
|
59
|
-
'.olusa-
|
|
60
|
-
'.olusa-
|
|
61
|
-
'.olusa-
|
|
62
|
-
'.olusa-
|
|
37
|
+
// ── 面板骨架 ────────────────────────────────────────────────
|
|
38
|
+
'.olusa-panel{display:flex;flex-direction:column;gap:12px;padding:14px 16px;border:1px solid var(--dsw-alias-border-l1);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:var(--dsw-font-xs-13);box-sizing:border-box}',
|
|
39
|
+
'.olusa-panel *{box-sizing:border-box}',
|
|
40
|
+
'.olusa-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;min-width:0}',
|
|
41
|
+
'.olusa-head-main{display:flex;flex-direction:column;gap:2px;min-width:0}',
|
|
42
|
+
'.olusa-title{font:var(--dsw-font-s-14);font-weight:600;color:var(--dsw-alias-label-primary);white-space:nowrap}',
|
|
43
|
+
'.olusa-sub{font:var(--dsw-font-xxxs-11);color:var(--dsw-alias-label-tertiary)}',
|
|
44
|
+
'.olusa-block{display:flex;flex-direction:column;gap:12px;min-width:0}',
|
|
45
|
+
'.olusa-ver{font:var(--dsw-font-xxxs-11);color:var(--dsw-alias-label-caption)}',
|
|
46
|
+
|
|
47
|
+
// ── 用量进度条 ──────────────────────────────────────────────
|
|
48
|
+
'.olusa-barblock{display:flex;flex-direction:column;gap:6px;min-width:0}',
|
|
49
|
+
'.olusa-barhead{display:flex;align-items:baseline;justify-content:space-between;gap:8px;min-width:0}',
|
|
50
|
+
'.olusa-barlabel{font:var(--dsw-font-xxs-strong-12);font-weight:500;color:var(--dsw-alias-label-primary)}',
|
|
51
|
+
'.olusa-barval{font:var(--dsw-font-xxxs-strong-11);font-weight:500;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;white-space:nowrap}',
|
|
52
|
+
'.olusa-bar{height:6px;border-radius:999px;background:color-mix(in srgb,var(--dsw-alias-label-primary) 10%,var(--dsw-alias-bg-layer-2));overflow:hidden}',
|
|
53
|
+
'.olusa-barfill{height:100%;border-radius:999px;transition:width .2s ease}',
|
|
54
|
+
|
|
55
|
+
// ── 说明 / 分区 / 列表 ──────────────────────────────────────
|
|
56
|
+
'.olusa-hint{margin:0;font:var(--dsw-font-xxxs-11);color:var(--dsw-alias-label-tertiary);line-height:16px}',
|
|
57
|
+
'.olusa-sec{display:flex;flex-direction:column;gap:2px;min-width:0}',
|
|
58
|
+
'.olusa-sec-title{margin:0 0 2px;font:var(--dsw-font-xxxs-strong-11);font-weight:600;color:var(--dsw-alias-label-secondary);letter-spacing:.02em}',
|
|
59
|
+
'.olusa-list{display:flex;flex-direction:column;min-width:0}',
|
|
60
|
+
'.olusa-row{display:flex;align-items:baseline;justify-content:space-between;gap:12px;padding:6px 0;border-bottom:1px solid var(--dsw-alias-border-l1);min-width:0;font:var(--dsw-font-xxs-12)}',
|
|
61
|
+
'.olusa-row:last-child{border-bottom:none}',
|
|
62
|
+
'.olusa-rowname{color:var(--dsw-alias-label-secondary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}',
|
|
63
|
+
'.olusa-rowval{color:var(--dsw-alias-label-primary);font-variant-numeric:tabular-nums;white-space:nowrap}',
|
|
64
|
+
'.olusa-link{color:var(--dsw-alias-link);text-decoration:none;border-radius:var(--dsw-radius-xs)}',
|
|
65
|
+
'.olusa-link:hover{text-decoration:underline}',
|
|
66
|
+
'.olusa-link:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}',
|
|
67
|
+
'.olusa-steps{margin:0;padding-left:16px;display:flex;flex-direction:column;gap:4px;font:var(--dsw-font-xxs-12);color:var(--dsw-alias-label-secondary);line-height:18px}',
|
|
68
|
+
|
|
69
|
+
// ── 输入 / 按钮 / 状态 ──────────────────────────────────────
|
|
70
|
+
'.olusa-input{flex:1;min-width:0;height:30px;padding:0 10px;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-base);border:1px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm);font:var(--dsw-font-xs-13);transition:border-color .15s ease}',
|
|
71
|
+
'.olusa-input:hover{border-color:var(--dsw-alias-border-l3)}',
|
|
72
|
+
'.olusa-input:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}',
|
|
73
|
+
'.olusa-input:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}',
|
|
74
|
+
'.olusa-input::placeholder{color:var(--dsw-alias-label-tertiary)}',
|
|
75
|
+
'.olusa-login-title{font:var(--dsw-font-xs-strong-13);font-weight:600;color:var(--dsw-alias-label-primary)}',
|
|
76
|
+
'.olusa-rowbtns{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-top:2px}',
|
|
77
|
+
'.olusa-btn{display:inline-flex;align-items:center;justify-content:center;height:28px;padding:0 12px;color:var(--dsw-alias-label-primary);background:transparent;border:1px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm);font:var(--dsw-font-xxs-strong-12);font-weight:500;cursor:pointer;white-space:nowrap;transition:background-color .15s ease,border-color .15s ease,color .15s ease,opacity .15s ease}',
|
|
78
|
+
'.olusa-btn:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}',
|
|
79
|
+
'.olusa-btn:active:not(:disabled){background:var(--dsw-alias-interactive-bg-active)}',
|
|
80
|
+
'.olusa-btn:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}',
|
|
81
|
+
'.olusa-btn:disabled{opacity:.5;cursor:not-allowed}',
|
|
82
|
+
'.olusa-btn-primary{background:var(--dsw-alias-button-primary-fill);border-color:transparent;color:var(--dsw-alias-label-primary-foreground)}',
|
|
83
|
+
'.olusa-btn-primary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover)}',
|
|
84
|
+
'.olusa-btn-primary:active:not(:disabled){background:var(--dsw-alias-button-primary-hover)}',
|
|
85
|
+
'.olusa-btn-danger{color:var(--dsw-alias-state-error-primary)}',
|
|
86
|
+
'.olusa-btn-danger:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover-danger)}',
|
|
87
|
+
'.olusa-error{margin:0;font:var(--dsw-font-xxs-12);color:var(--dsw-alias-state-error-primary);line-height:18px;word-break:break-word}',
|
|
88
|
+
'.olusa-state{display:inline-flex;align-items:center;align-self:flex-start;padding:2px 8px;border-radius:999px;font:var(--dsw-font-xxxs-strong-11);font-weight:500;max-width:100%}',
|
|
89
|
+
'.olusa-state[data-tone=ok]{background:var(--dsw-alias-state-success-tertiary);color:var(--dsw-alias-state-success-primary);border:1px solid color-mix(in srgb,var(--dsw-alias-state-success-primary) 20%,transparent)}',
|
|
90
|
+
'.olusa-state[data-tone=err]{background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 10%,transparent);color:var(--dsw-alias-state-error-primary);border:1px solid color-mix(in srgb,var(--dsw-alias-state-error-primary) 20%,transparent)}',
|
|
91
|
+
'.olusa-loading{display:flex;flex-direction:column;gap:8px}',
|
|
92
|
+
'.olusa-skeleton{height:10px;border-radius:var(--dsw-radius-xs);background:var(--dsw-alias-bg-skeleton)}',
|
|
93
|
+
'.olusa-skeleton.is-wide{width:56%}',
|
|
94
|
+
|
|
95
|
+
// ── 侧栏双横条 ──────────────────────────────────────────────
|
|
96
|
+
'.olusa-bars{display:flex;flex-direction:column;gap:8px;padding:6px 8px;width:120px;min-width:120px;flex-shrink:0;box-sizing:border-box;background:transparent;border:none}',
|
|
97
|
+
'.olusa-barsrow{display:flex;flex-direction:column;gap:2px;min-width:0}',
|
|
63
98
|
'.olusa-barshead{display:flex;justify-content:space-between;align-items:baseline;gap:6px}',
|
|
64
|
-
'.olusa-barslabel{font-
|
|
65
|
-
'.olusa-barsval{font-
|
|
66
|
-
'.olusa-minibar{height:
|
|
67
|
-
'.olusa-minibarfill{height:100%;border-radius:
|
|
99
|
+
'.olusa-barslabel{font:var(--dsw-font-xxxs-11);color:var(--dsw-alias-label-secondary);white-space:nowrap}',
|
|
100
|
+
'.olusa-barsval{font:var(--dsw-font-xxxs-strong-11);font-weight:600;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary);white-space:nowrap}',
|
|
101
|
+
'.olusa-minibar{height:6px;border-radius:999px;background:color-mix(in srgb,var(--dsw-alias-label-primary) 12%,transparent);overflow:hidden}',
|
|
102
|
+
'.olusa-minibarfill{height:100%;border-radius:999px;transition:width .2s ease}',
|
|
103
|
+
|
|
104
|
+
'@media (prefers-reduced-motion:reduce){.olusa-barfill,.olusa-minibarfill{transition:none}}',
|
|
68
105
|
].join('\n')
|
|
69
106
|
|
|
70
107
|
function injectCss() {
|
|
71
108
|
if (typeof document === 'undefined') return
|
|
72
109
|
if (document.querySelector('style[data-plugin-css="' + CSS_TAG_ID + '"]') !== null) return
|
|
73
110
|
const tag = document.createElement('style')
|
|
111
|
+
tag.dataset.plugin = 'dsh-ollama-usage'
|
|
74
112
|
tag.dataset.pluginCss = CSS_TAG_ID
|
|
75
113
|
tag.textContent = CSS
|
|
76
114
|
;(document.head || document.documentElement).appendChild(tag)
|
|
@@ -78,10 +116,10 @@ window.__ModuleLoader__.load({
|
|
|
78
116
|
|
|
79
117
|
const pct = (v) => (typeof v === 'number' && Number.isFinite(v) ? Math.round(v * 10) / 10 : null)
|
|
80
118
|
const colorFor = (p) => {
|
|
81
|
-
if (p === null) return 'var(--dsw-alias-label-secondary
|
|
82
|
-
if (p < 70) return 'var(--dsw-alias-state-success-primary
|
|
83
|
-
if (p < 90) return 'var(--dsw-alias-state-warn-primary
|
|
84
|
-
return 'var(--dsw-alias-state-error-primary
|
|
119
|
+
if (p === null) return 'var(--dsw-alias-label-secondary)'
|
|
120
|
+
if (p < 70) return 'var(--dsw-alias-state-success-primary)'
|
|
121
|
+
if (p < 90) return 'var(--dsw-alias-state-warn-primary)'
|
|
122
|
+
return 'var(--dsw-alias-state-error-primary)'
|
|
85
123
|
}
|
|
86
124
|
const fmtTime = (iso) => { try {
|
|
87
125
|
const d = new Date(iso)
|
|
@@ -137,7 +175,7 @@ window.__ModuleLoader__.load({
|
|
|
137
175
|
const p = pct(props.percent)
|
|
138
176
|
const width = p === null ? 0 : Math.min(100, Math.max(0, p))
|
|
139
177
|
const remaining = p === null ? null : Math.round((100 - p) * 10) / 10
|
|
140
|
-
return React.createElement('div', { className: 'olusa-
|
|
178
|
+
return React.createElement('div', { className: 'olusa-barblock' },
|
|
141
179
|
React.createElement('div', { className: 'olusa-barhead' },
|
|
142
180
|
React.createElement('span', { className: 'olusa-barlabel' }, props.label),
|
|
143
181
|
React.createElement('span', { className: 'olusa-barval' }, p === null ? '暂无数据' : ('已用 ' + p + '% · 剩余 ' + remaining + '%'))
|
|
@@ -154,7 +192,8 @@ window.__ModuleLoader__.load({
|
|
|
154
192
|
React.createElement('div', { className: 'olusa-login-title' }, '尚未登录 Ollama 账号'),
|
|
155
193
|
React.createElement('ol', { className: 'olusa-steps' },
|
|
156
194
|
React.createElement('li', null,
|
|
157
|
-
|
|
195
|
+
'打开 ',
|
|
196
|
+
React.createElement('a', { className: 'olusa-link', href: 'https://ollama.com/settings', target: '_blank', rel: 'noreferrer' }, 'ollama.com/settings'),
|
|
158
197
|
' 并登录(或注册)Ollama 账号'
|
|
159
198
|
),
|
|
160
199
|
React.createElement('li', null,
|
|
@@ -162,14 +201,14 @@ window.__ModuleLoader__.load({
|
|
|
162
201
|
React.createElement('a', { className: 'olusa-link', href: 'https://ollama.com/settings/keys', target: '_blank', rel: 'noreferrer' }, 'settings/keys'),
|
|
163
202
|
' 创建一个 API Key'
|
|
164
203
|
),
|
|
165
|
-
React.createElement('li', null, '把 Key
|
|
204
|
+
React.createElement('li', null, '把 Key 粘贴到下方点击「检测」;或先在终端运行 ollama signin / ollama login,再点「重新检测本地凭证」')
|
|
166
205
|
),
|
|
167
206
|
React.createElement('input', { className: 'olusa-input', placeholder: '粘贴 API Key', value: props.tokenInput, onChange: (e) => props.onInput(e.target.value), spellCheck: false }),
|
|
168
207
|
React.createElement('div', { className: 'olusa-rowbtns' },
|
|
169
208
|
React.createElement('button', { className: 'olusa-btn olusa-btn-primary', disabled: props.busy || !props.tokenInput.trim(), onClick: () => props.onCheck(props.tokenInput.trim()) }, props.busy ? '检测中…' : '检测'),
|
|
170
209
|
React.createElement('button', { className: 'olusa-btn', disabled: props.busy, onClick: () => props.onRetryLocal() }, '重新检测本地凭证')
|
|
171
210
|
),
|
|
172
|
-
React.createElement('div', { className: 'olusa-hint' }, '
|
|
211
|
+
React.createElement('div', { className: 'olusa-hint' }, '检测成功后,Key 与用量快照会保存到 $DSH_HOME/storages/ollama-usage/usage.json(权限 600),跨对话 / 重启自动恢复并每 10 分钟自动刷新。')
|
|
173
212
|
)
|
|
174
213
|
}
|
|
175
214
|
|
|
@@ -180,34 +219,49 @@ window.__ModuleLoader__.load({
|
|
|
180
219
|
const models = Array.isArray(d.models) ? d.models.slice(0, 5) : []
|
|
181
220
|
const history = Array.isArray(props.history) ? props.history.slice(-5).reverse() : []
|
|
182
221
|
return React.createElement('div', { className: 'olusa-block' },
|
|
183
|
-
React.createElement(BarRow, { label: '会话用量(每 5 小时)', percent: d.sessionPercent,
|
|
222
|
+
React.createElement(BarRow, { label: '会话用量(每 5 小时)', percent: d.sessionPercent, resetText: sessionResetText ? '还有 ' + sessionResetText + ' 重置' : null }),
|
|
184
223
|
React.createElement(BarRow, { label: '本周用量(Weekly)', percent: d.weeklyPercent, resetText: weeklyResetText ? '还有 ' + weeklyResetText + ' 重置' : null }),
|
|
185
224
|
(models.length > 0
|
|
186
|
-
? React.createElement('div', { className: 'olusa-
|
|
187
|
-
React.createElement('div', { className: 'olusa-
|
|
188
|
-
|
|
189
|
-
React.createElement('
|
|
190
|
-
|
|
191
|
-
|
|
225
|
+
? React.createElement('div', { className: 'olusa-sec' },
|
|
226
|
+
React.createElement('div', { className: 'olusa-sec-title' }, '模型请求数(本周)'),
|
|
227
|
+
React.createElement('div', { className: 'olusa-list' },
|
|
228
|
+
models.map((m) => React.createElement('div', { className: 'olusa-row', key: m.name },
|
|
229
|
+
React.createElement('span', { className: 'olusa-rowname', title: m.name }, m.name),
|
|
230
|
+
React.createElement('span', { className: 'olusa-rowval' }, String(m.requestCount) + ' 次')
|
|
231
|
+
)))
|
|
232
|
+
)
|
|
192
233
|
: null),
|
|
193
234
|
(history.length > 0
|
|
194
|
-
? React.createElement('div', { className: 'olusa-
|
|
195
|
-
React.createElement('div', { className: 'olusa-
|
|
196
|
-
|
|
197
|
-
React.createElement('
|
|
198
|
-
|
|
199
|
-
|
|
235
|
+
? React.createElement('div', { className: 'olusa-sec' },
|
|
236
|
+
React.createElement('div', { className: 'olusa-sec-title' }, '最近记录(会话用量)'),
|
|
237
|
+
React.createElement('div', { className: 'olusa-list' },
|
|
238
|
+
history.map((h, i) => React.createElement('div', { className: 'olusa-row', key: String(i) },
|
|
239
|
+
React.createElement('span', { className: 'olusa-rowname' }, fmtTime(h.at)),
|
|
240
|
+
React.createElement('span', { className: 'olusa-rowval' }, (h.sessionPercent === null || h.sessionPercent === undefined) ? '—' : (h.sessionPercent + '%'))
|
|
241
|
+
)))
|
|
242
|
+
)
|
|
200
243
|
: null),
|
|
201
244
|
(props.updatedAt
|
|
202
245
|
? React.createElement('div', { className: 'olusa-hint' }, '上次更新:' + fmtTime(props.updatedAt) + '(每 10 分钟自动刷新)')
|
|
203
246
|
: null),
|
|
204
|
-
React.createElement('div', {
|
|
205
|
-
|
|
247
|
+
React.createElement('div', {
|
|
248
|
+
className: 'olusa-state',
|
|
249
|
+
'data-tone': props.persisted ? 'ok' : 'err',
|
|
250
|
+
title: props.persisted ? '$DSH_HOME/storages/ollama-usage/usage.json' : undefined,
|
|
251
|
+
}, props.persisted ? '✓ 已持久化到本地' : '⚠ 未能写入本地文件')
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** 加载骨架:首屏 snapshot 落定前占位,避免登录表单闪现。 */
|
|
256
|
+
function LoadingBody() {
|
|
257
|
+
return React.createElement('div', { className: 'olusa-loading', role: 'status', 'aria-live': 'polite' },
|
|
258
|
+
React.createElement('div', { className: 'olusa-skeleton is-wide' }),
|
|
259
|
+
React.createElement('div', { className: 'olusa-skeleton' })
|
|
206
260
|
)
|
|
207
261
|
}
|
|
208
262
|
|
|
209
263
|
function OllamaUsagePanel() {
|
|
210
|
-
const [phase, setPhase] = React.useState('
|
|
264
|
+
const [phase, setPhase] = React.useState('loading')
|
|
211
265
|
const [data, setData] = React.useState(null)
|
|
212
266
|
const [history, setHistory] = React.useState(null)
|
|
213
267
|
const [updatedAt, setUpdatedAt] = React.useState(null)
|
|
@@ -224,7 +278,8 @@ window.__ModuleLoader__.load({
|
|
|
224
278
|
setUpdatedAt(v.updatedAt || null)
|
|
225
279
|
if (typeof v.persisted === 'boolean') setPersisted(v.persisted)
|
|
226
280
|
setError('')
|
|
227
|
-
|
|
281
|
+
// 无 usage 快照时留在登录引导,避免“无错误却显示查询失败”的 usage/error 分支。
|
|
282
|
+
setPhase(v.usage ? 'usage' : 'login')
|
|
228
283
|
} else if (res && res.error && (res.error.code === 'no-token' || res.error.code === 'no-data')) {
|
|
229
284
|
setError('')
|
|
230
285
|
setPhase('login')
|
|
@@ -258,44 +313,54 @@ window.__ModuleLoader__.load({
|
|
|
258
313
|
setData(res.value.usage); setHistory(res.value.history || null); setUpdatedAt(res.value.updatedAt || null); setError(''); setPhase('usage')
|
|
259
314
|
// snapshot 数据读自磁盘文件(插件无内存缓存),必然已持久化;服务端字段优先,缺省按不变式置 true
|
|
260
315
|
setPersisted(typeof res.value.persisted === 'boolean' ? res.value.persisted : true)
|
|
316
|
+
} else {
|
|
317
|
+
// 首屏无数据(未登录 / 无快照)落到登录引导;已有数据时保持当前视图。
|
|
318
|
+
setPhase((current) => (current === 'loading' ? 'login' : current))
|
|
261
319
|
}
|
|
262
|
-
}).catch(() => {
|
|
320
|
+
}).catch(() => {
|
|
321
|
+
if (!disposed) setPhase((current) => (current === 'loading' ? 'login' : current))
|
|
322
|
+
})
|
|
263
323
|
refresh()
|
|
264
324
|
const dispose = ctx.interval(refresh, 60000)
|
|
265
325
|
return () => { disposed = true; dispose() }
|
|
266
326
|
}, [])
|
|
267
327
|
|
|
268
|
-
const body = phase === '
|
|
269
|
-
? React.createElement(
|
|
270
|
-
: phase === '
|
|
271
|
-
? React.createElement(
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
React.createElement('
|
|
328
|
+
const body = phase === 'loading'
|
|
329
|
+
? React.createElement(LoadingBody)
|
|
330
|
+
: phase === 'login'
|
|
331
|
+
? React.createElement(LoginBody, { tokenInput: tokenInput, onInput: setTokenInput, onCheck: doCheck, onRetryLocal: () => doCheck(''), busy: busy })
|
|
332
|
+
: phase === 'usage' && data
|
|
333
|
+
? React.createElement('div', { className: 'olusa-block' },
|
|
334
|
+
React.createElement(UsageBody, { data: data, history: history, updatedAt: updatedAt, persisted: persisted }),
|
|
335
|
+
(error ? React.createElement('div', { className: 'olusa-error' }, String(error)) : null),
|
|
336
|
+
React.createElement('div', { className: 'olusa-rowbtns' },
|
|
337
|
+
React.createElement('button', { className: 'olusa-btn olusa-btn-danger', disabled: busy, onClick: () => doForget() }, '清除已存 Key')
|
|
338
|
+
)
|
|
276
339
|
)
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
340
|
+
: React.createElement('div', { className: 'olusa-block' },
|
|
341
|
+
React.createElement('div', { className: 'olusa-error' }, String(error || '查询失败')),
|
|
342
|
+
React.createElement('div', { className: 'olusa-hint' },
|
|
343
|
+
'请确认已登录:',
|
|
344
|
+
React.createElement('a', { className: 'olusa-link', href: 'https://ollama.com/settings', target: '_blank', rel: 'noreferrer' }, 'ollama.com/settings'),
|
|
345
|
+
',或粘贴 API Key 重试。'
|
|
346
|
+
),
|
|
347
|
+
React.createElement('input', { className: 'olusa-input', placeholder: '粘贴 API Key', value: tokenInput, onChange: (e) => setTokenInput(e.target.value), spellCheck: false }),
|
|
348
|
+
React.createElement('div', { className: 'olusa-rowbtns' },
|
|
349
|
+
React.createElement('button', { className: 'olusa-btn olusa-btn-primary', disabled: busy || !tokenInput.trim(), onClick: () => doCheck(tokenInput.trim()) }, busy ? '检测中…' : '检测'),
|
|
350
|
+
React.createElement('button', { className: 'olusa-btn', disabled: busy, onClick: () => doCheck('') }, '重试')
|
|
351
|
+
)
|
|
289
352
|
)
|
|
290
|
-
)
|
|
291
353
|
|
|
292
354
|
return React.createElement('div', { className: 'olusa-panel' },
|
|
293
355
|
React.createElement('div', { className: 'olusa-head' },
|
|
294
|
-
React.createElement('
|
|
356
|
+
React.createElement('div', { className: 'olusa-head-main' },
|
|
357
|
+
React.createElement('span', { className: 'olusa-title' }, '⚡ Ollama 用量'),
|
|
358
|
+
React.createElement('span', { className: 'olusa-sub' }, '会话 5h · 周用量 · 每 10 分钟自动刷新')
|
|
359
|
+
),
|
|
295
360
|
React.createElement('button', { className: 'olusa-btn', disabled: busy, onClick: () => doCheck('') }, busy ? '查询中…' : '刷新')
|
|
296
361
|
),
|
|
297
362
|
body,
|
|
298
|
-
React.createElement('div', { className: 'olusa-ver' }, 'dsh-ollama-usage · v0.1.
|
|
363
|
+
React.createElement('div', { className: 'olusa-ver' }, 'dsh-ollama-usage · v0.1.13')
|
|
299
364
|
)
|
|
300
365
|
}
|
|
301
366
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ollama-usage",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "DeepSeek Harness 插件:可视化 Ollama Cloud 账号用量余量(每 5 小时会话用量 + 周用量),支持侧边栏双横条、插件详情页完整面板、API Key 与用量快照持久化、自动刷新与登录引导。Ollama Pro usage & remaining-quota visualization for DeepSeek Harness: 5-hour session + weekly quota bars in the sidebar footer, a full panel on the plugin's own detail page, persisted API key and usage snapshots, auto-refresh and login guidance.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|