dsh-connect-madao 0.9.3 → 0.10.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 +40 -0
- package/README.md +4 -3
- package/lib/bin.js +97 -5
- package/lib/client.js +351 -49
- package/lib/index.js +210 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,46 @@
|
|
|
2
2
|
|
|
3
3
|
本项目遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
4
4
|
|
|
5
|
+
## 0.10.0 — 2026-12-01
|
|
6
|
+
|
|
7
|
+
本版功能来自 **[@KaenFelix](https://github.com/KaenFelix)** 的
|
|
8
|
+
[PR #4](https://github.com/XLNC-L/dsh-connect-madao/pull/4)(原提交 `0.10.0`:
|
|
9
|
+
设置页侧栏入口、界面开关、自动签到,并修浅色模式配色)。按其正文描述的「四件事」
|
|
10
|
+
摘取,**未包含**该分支后续引入的 native adapter 改架(0.12+)、图片 attachment、
|
|
11
|
+
包名迁移等与本次无关的改动;所有源码均已重放到当前代码并以本仓库重新构建。
|
|
12
|
+
|
|
13
|
+
### 新增
|
|
14
|
+
|
|
15
|
+
- **设置页侧栏入口** —— 面板注册到 `settings.section`(`id = dsh-connect-madao`,
|
|
16
|
+
`order = 55`),设置页左侧导航出现「码道连接器」一页,与其它连接器并列。
|
|
17
|
+
图标走 `settings.section.icon`(同一 id);该槽位在部分宿主版本可能缺失,
|
|
18
|
+
单独 `try/catch`,缺了只退回默认齿轮,页面本身不受影响。原来的
|
|
19
|
+
`plugins.bundle.config` 卡片保留,插件详情页照旧。
|
|
20
|
+
- **自动签到(默认关闭 + 显式开关)** —— 新增 `auto-checkin.ts`。只有用户在
|
|
21
|
+
「账号 → 每日签到」下打开开关才运行,不打开一个请求都不发。
|
|
22
|
+
- 每分钟 tick 比对(不联网),睡眠 / 跨天 / 手动改时间最多 60 秒自纠正;
|
|
23
|
+
启动时先跑一轮,避免「10:05 关机、10:30 开机要等到明天」。
|
|
24
|
+
- 两次真实请求之间至少间隔 15 分钟,避免撞签到接口频率限制。
|
|
25
|
+
- 开关从关变开时立刻跑一轮,不让人等 15 分钟窗口。
|
|
26
|
+
- 失败不放大:任何异常吞掉并记录;凭据没就绪时安静跳过等下一轮。
|
|
27
|
+
- 复用桥接那一份客户端与 STS 续期(`borrowClient()`),不另起一套,避免两条
|
|
28
|
+
链路各自换 STS 撞 IAM 频率限制。
|
|
29
|
+
- **`GET` / `POST /settings`** —— 两个开关(`composerChip` 胶囊显隐、`autoCheckin`)
|
|
30
|
+
的读写端点,GET 顺带返回自动签到运行状态。状态落在
|
|
31
|
+
`$DSH_HOME/dsh-connect-madao-state.json`(`DSH_HOME` 未设时 `~/.dsh`),权限 `0600`,
|
|
32
|
+
写入走「临时文件 + rename」,逐字段回落。**走桥接而不写 DSH 插件 config**,
|
|
33
|
+
因为开关要求「点一下立刻生效」,写 config 会触发插件重载把桥接与在途对话一起掀掉。
|
|
34
|
+
- 客户端经 DSH 同源转发访问该端点(`/settings` 已加入 PR #2 的转发白名单),
|
|
35
|
+
因此 NAS / 远程访问时同样可用。
|
|
36
|
+
|
|
37
|
+
### 修复
|
|
38
|
+
|
|
39
|
+
- **浅色模式下设置面板几乎看不清** —— 面板原先用的 `--dsh-fg` / `--dsh-border` /
|
|
40
|
+
`--dsh-muted` / `--dsh-input-bg` 在当前 DSH 里并不存在,`var()` 全部回退到写死的
|
|
41
|
+
暗色值,导致浅色主题下「账号」标签白字白底、说明文字浅灰、输入框一块黑。
|
|
42
|
+
全部换成真实的 `--dsw-alias-*` 主题令牌;叠加 `opacity` 的文字改成语义色,
|
|
43
|
+
避免对比度被二次削弱。
|
|
44
|
+
|
|
5
45
|
## 0.9.3 — 2026-12-01
|
|
6
46
|
|
|
7
47
|
本版聚焦「远程可用」与「签到链路补漏」,来自两份社区贡献:
|
package/README.md
CHANGED
|
@@ -245,9 +245,10 @@ lib/ 构建产物
|
|
|
245
245
|
[PR #2](https://github.com/XLNC-L/dsh-connect-madao/pull/2):设置面板改走 DSH 同源转发
|
|
246
246
|
(修复 NAS/远程访问时连不上本地桥接)、模型渠道经 `configEditor` 运行时合并
|
|
247
247
|
(修复码道模型被其它渠道配置覆盖)。
|
|
248
|
-
- **[@KaenFelix](https://github.com/KaenFelix)** —— 0.
|
|
249
|
-
`
|
|
250
|
-
|
|
248
|
+
- **[@KaenFelix](https://github.com/KaenFelix)** —— 0.10.0 的设置页侧栏入口、
|
|
249
|
+
自动签到(默认关闭)、`/settings` 界面开关与浅色模式配色修复,以及 0.9.3 修复的
|
|
250
|
+
`claimCheckin` 在 `CLAIMED` 状态下没真正补 `confirm` 的缺陷,均来自他的
|
|
251
|
+
[PR #4](https://github.com/XLNC-L/dsh-connect-madao/pull/4)。
|
|
251
252
|
- **[@vzhentian1-design](https://github.com/vzhentian1-design)** —— 0.9.2 的
|
|
252
253
|
`POST /v1/ops/confirm` 补全、多活动扫描 + `type`/`triggerEvent` 白名单、
|
|
253
254
|
积分到期预警,以及 `LICENSE`,均来自他的
|
package/lib/bin.js
CHANGED
|
@@ -1489,7 +1489,7 @@ init_sts_provider();
|
|
|
1489
1489
|
import { createHash as createHash5 } from "node:crypto";
|
|
1490
1490
|
import { createServer } from "node:http";
|
|
1491
1491
|
import { writeFileSync } from "node:fs";
|
|
1492
|
-
import { join as
|
|
1492
|
+
import { join as join5 } from "node:path";
|
|
1493
1493
|
|
|
1494
1494
|
// src/protocol/body.ts
|
|
1495
1495
|
var DEFAULT_MAX_TOKENS = 65536;
|
|
@@ -1967,6 +1967,59 @@ async function claimAllCheckins(client) {
|
|
|
1967
1967
|
return { ok: true, claimed, skipped, campaigns };
|
|
1968
1968
|
}
|
|
1969
1969
|
|
|
1970
|
+
// src/settings.ts
|
|
1971
|
+
import { mkdir as mkdir2, readFile as readFile2, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
|
|
1972
|
+
import { homedir as homedir4 } from "node:os";
|
|
1973
|
+
import { join as join4 } from "node:path";
|
|
1974
|
+
var SETTINGS_FILENAME = "dsh-connect-madao-state.json";
|
|
1975
|
+
var DEFAULT_SETTINGS = Object.freeze({
|
|
1976
|
+
schemaVersion: 1,
|
|
1977
|
+
composerChip: true,
|
|
1978
|
+
autoCheckin: false
|
|
1979
|
+
});
|
|
1980
|
+
function settingsPath(env = process.env) {
|
|
1981
|
+
const home = typeof env.DSH_HOME === "string" && env.DSH_HOME.length > 0 ? env.DSH_HOME : join4(homedir4(), ".dsh");
|
|
1982
|
+
return join4(home, SETTINGS_FILENAME);
|
|
1983
|
+
}
|
|
1984
|
+
function normalizeSettings(raw) {
|
|
1985
|
+
if (typeof raw !== "object" || raw === null) return { ...DEFAULT_SETTINGS };
|
|
1986
|
+
const record = raw;
|
|
1987
|
+
return {
|
|
1988
|
+
schemaVersion: 1,
|
|
1989
|
+
composerChip: typeof record.composerChip === "boolean" ? record.composerChip : DEFAULT_SETTINGS.composerChip,
|
|
1990
|
+
autoCheckin: typeof record.autoCheckin === "boolean" ? record.autoCheckin : DEFAULT_SETTINGS.autoCheckin
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
async function readSettings(env = process.env) {
|
|
1994
|
+
let text;
|
|
1995
|
+
try {
|
|
1996
|
+
text = await readFile2(settingsPath(env), "utf8");
|
|
1997
|
+
} catch {
|
|
1998
|
+
return { ...DEFAULT_SETTINGS };
|
|
1999
|
+
}
|
|
2000
|
+
try {
|
|
2001
|
+
return normalizeSettings(JSON.parse(text));
|
|
2002
|
+
} catch {
|
|
2003
|
+
return { ...DEFAULT_SETTINGS };
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
async function writeSettings(next, env = process.env) {
|
|
2007
|
+
const target = settingsPath(env);
|
|
2008
|
+
await mkdir2(join4(target, ".."), { recursive: true });
|
|
2009
|
+
const tmp = `${target}.${process.pid}.tmp`;
|
|
2010
|
+
await writeFile2(tmp, `${JSON.stringify(next, null, 2)}
|
|
2011
|
+
`, { encoding: "utf8", mode: 384 });
|
|
2012
|
+
await rename2(tmp, target);
|
|
2013
|
+
return next;
|
|
2014
|
+
}
|
|
2015
|
+
async function patchSettings(patch, env = process.env) {
|
|
2016
|
+
const current = await readSettings(env);
|
|
2017
|
+
const next = normalizeSettings({ ...current, ...patch });
|
|
2018
|
+
await writeSettings(next, env);
|
|
2019
|
+
chatLog(`settings updated: composerChip=${next.composerChip} autoCheckin=${next.autoCheckin}`);
|
|
2020
|
+
return next;
|
|
2021
|
+
}
|
|
2022
|
+
|
|
1970
2023
|
// src/server.ts
|
|
1971
2024
|
async function ensureFreshClient(ctx) {
|
|
1972
2025
|
if (!ctx.sts || !ctx.loaded) return;
|
|
@@ -2052,7 +2105,8 @@ ${failures.map((f) => ` ${f}`).join("\n")}`);
|
|
|
2052
2105
|
server,
|
|
2053
2106
|
port: actualPort,
|
|
2054
2107
|
url: `http://${host}:${actualPort}`,
|
|
2055
|
-
close: () => new Promise((resolve, reject) => server.close((e) => e ? reject(e) : resolve()))
|
|
2108
|
+
close: () => new Promise((resolve, reject) => server.close((e) => e ? reject(e) : resolve())),
|
|
2109
|
+
ctx
|
|
2056
2110
|
};
|
|
2057
2111
|
}
|
|
2058
2112
|
async function handle(req, res, ctx) {
|
|
@@ -2069,6 +2123,44 @@ async function handle(req, res, ctx) {
|
|
|
2069
2123
|
if (req.method === "GET" && url.pathname === "/healthz") {
|
|
2070
2124
|
return json(res, 200, await healthz(ctx));
|
|
2071
2125
|
}
|
|
2126
|
+
if (url.pathname === "/settings" && (req.method === "GET" || req.method === "POST")) {
|
|
2127
|
+
if (req.method === "GET") {
|
|
2128
|
+
const settings = await readSettings();
|
|
2129
|
+
return json(res, 200, {
|
|
2130
|
+
ok: true,
|
|
2131
|
+
settings,
|
|
2132
|
+
autoCheckin: ctx.autoCheckin ? ctx.autoCheckin.state() : null
|
|
2133
|
+
});
|
|
2134
|
+
}
|
|
2135
|
+
let payload = {};
|
|
2136
|
+
try {
|
|
2137
|
+
payload = JSON.parse(await readBody(req));
|
|
2138
|
+
} catch {
|
|
2139
|
+
return json(res, 400, { error: { message: "\u8BF7\u6C42\u4F53\u4E0D\u662F\u5408\u6CD5 JSON" } });
|
|
2140
|
+
}
|
|
2141
|
+
const patch = {};
|
|
2142
|
+
if (typeof payload.composerChip === "boolean") patch.composerChip = payload.composerChip;
|
|
2143
|
+
if (typeof payload.autoCheckin === "boolean") patch.autoCheckin = payload.autoCheckin;
|
|
2144
|
+
if (Object.keys(patch).length === 0) {
|
|
2145
|
+
return json(res, 400, { error: { message: "\u6CA1\u6709\u53EF\u66F4\u65B0\u7684\u5B57\u6BB5" } });
|
|
2146
|
+
}
|
|
2147
|
+
try {
|
|
2148
|
+
const settings = await patchSettings(patch);
|
|
2149
|
+
if (ctx.autoCheckin) {
|
|
2150
|
+
try {
|
|
2151
|
+
await ctx.autoCheckin.tick();
|
|
2152
|
+
} catch {
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
return json(res, 200, {
|
|
2156
|
+
ok: true,
|
|
2157
|
+
settings,
|
|
2158
|
+
autoCheckin: ctx.autoCheckin ? ctx.autoCheckin.state() : null
|
|
2159
|
+
});
|
|
2160
|
+
} catch (e) {
|
|
2161
|
+
return json(res, 500, { error: { message: `\u4FDD\u5B58\u8BBE\u7F6E\u5931\u8D25\uFF1A${String(e?.message ?? e)}` } });
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2072
2164
|
if (req.method === "GET" && (url.pathname === "/diag/account" || url.pathname === "/diag/credit")) {
|
|
2073
2165
|
return json(res, 200, await accountInfo(ctx));
|
|
2074
2166
|
}
|
|
@@ -2336,7 +2428,7 @@ async function chatCompletion(res, client, rawBody, ctxModels) {
|
|
|
2336
2428
|
`chat REJECT context ${estTokens} (msgs ${estMessages} + tools ${estTools}/${toolCount}) > ${limit} for ${model}`
|
|
2337
2429
|
);
|
|
2338
2430
|
try {
|
|
2339
|
-
writeFileSync(
|
|
2431
|
+
writeFileSync(join5(logDir(), "last-rejected.json"), JSON.stringify(rawBody), "utf8");
|
|
2340
2432
|
chatLog("chat REJECT \u8BF7\u6C42\u4F53\u5DF2\u5B58\u81F3 ~/.dsh-connect-madao/last-rejected.json");
|
|
2341
2433
|
} catch {
|
|
2342
2434
|
}
|
|
@@ -2790,7 +2882,7 @@ async function cmdModels() {
|
|
|
2790
2882
|
const { MadaoClient: MadaoClient2 } = await Promise.resolve().then(() => (init_client(), client_exports));
|
|
2791
2883
|
const { discoverModels: discoverModels2 } = await Promise.resolve().then(() => (init_models(), models_exports));
|
|
2792
2884
|
const { syncPatch: syncPatch2 } = await Promise.resolve().then(() => (init_host_patch(), host_patch_exports));
|
|
2793
|
-
const { dirname: dirname2, join:
|
|
2885
|
+
const { dirname: dirname2, join: join6 } = await import("node:path");
|
|
2794
2886
|
const { fileURLToPath } = await import("node:url");
|
|
2795
2887
|
try {
|
|
2796
2888
|
const loaded = await loadCredentials2();
|
|
@@ -2809,7 +2901,7 @@ async function cmdModels() {
|
|
|
2809
2901
|
}
|
|
2810
2902
|
if (write) {
|
|
2811
2903
|
const here = dirname2(fileURLToPath(import.meta.url));
|
|
2812
|
-
const target =
|
|
2904
|
+
const target = join6(here, "..", "cordis.patch.yml");
|
|
2813
2905
|
const r = syncPatch2(target, found.models);
|
|
2814
2906
|
console.log(r.error ? `
|
|
2815
2907
|
\u5199\u56DE\u5931\u8D25\uFF1A${r.error}` : `
|
package/lib/client.js
CHANGED
|
@@ -44,6 +44,78 @@ async function request(method, path, body, timeoutMs) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// src/client/settings.ts
|
|
48
|
+
var CHIP_CACHE_KEY = "dsh-connect-madao:composerChip";
|
|
49
|
+
var AUTO_CACHE_KEY = "dsh-connect-madao:autoCheckin";
|
|
50
|
+
function readCachedBool(key) {
|
|
51
|
+
try {
|
|
52
|
+
const raw = window.localStorage.getItem(key);
|
|
53
|
+
if (raw === "0") return false;
|
|
54
|
+
if (raw === "1") return true;
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
function writeCachedBool(key, value) {
|
|
60
|
+
try {
|
|
61
|
+
window.localStorage.setItem(key, value ? "1" : "0");
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
var current = {
|
|
66
|
+
composerChip: readCachedBool(CHIP_CACHE_KEY) ?? true,
|
|
67
|
+
autoCheckin: readCachedBool(AUTO_CACHE_KEY) ?? false
|
|
68
|
+
};
|
|
69
|
+
var autoState = null;
|
|
70
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
71
|
+
function getSettings() {
|
|
72
|
+
return current;
|
|
73
|
+
}
|
|
74
|
+
function getAutoCheckinState() {
|
|
75
|
+
return autoState;
|
|
76
|
+
}
|
|
77
|
+
function subscribeSettings(listener) {
|
|
78
|
+
listeners.add(listener);
|
|
79
|
+
return () => {
|
|
80
|
+
listeners.delete(listener);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function emit(next) {
|
|
84
|
+
current = next;
|
|
85
|
+
writeCachedBool(CHIP_CACHE_KEY, next.composerChip);
|
|
86
|
+
writeCachedBool(AUTO_CACHE_KEY, next.autoCheckin);
|
|
87
|
+
for (const listener of [...listeners]) {
|
|
88
|
+
try {
|
|
89
|
+
listener(next);
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function applyPayload(payload) {
|
|
95
|
+
if (!payload) return;
|
|
96
|
+
const next = { ...current };
|
|
97
|
+
const settings = payload.settings;
|
|
98
|
+
if (settings) {
|
|
99
|
+
if (typeof settings.composerChip === "boolean") next.composerChip = settings.composerChip;
|
|
100
|
+
if (typeof settings.autoCheckin === "boolean") next.autoCheckin = settings.autoCheckin;
|
|
101
|
+
}
|
|
102
|
+
if (payload.autoCheckin && typeof payload.autoCheckin === "object") {
|
|
103
|
+
autoState = payload.autoCheckin;
|
|
104
|
+
}
|
|
105
|
+
emit(next);
|
|
106
|
+
}
|
|
107
|
+
async function loadSettings() {
|
|
108
|
+
try {
|
|
109
|
+
applyPayload(await bridgeJson("/settings", 8e3));
|
|
110
|
+
} catch {
|
|
111
|
+
}
|
|
112
|
+
return current;
|
|
113
|
+
}
|
|
114
|
+
async function saveSettings(patch) {
|
|
115
|
+
applyPayload(await bridgePost("/settings", patch, 15e3));
|
|
116
|
+
return current;
|
|
117
|
+
}
|
|
118
|
+
|
|
47
119
|
// src/client/Panel.tsx
|
|
48
120
|
const { Fragment, jsx, jsxs } = require("react/jsx-runtime");
|
|
49
121
|
var FALLBACK_MODELS = [
|
|
@@ -61,18 +133,18 @@ var FALLBACK_MODELS = [
|
|
|
61
133
|
];
|
|
62
134
|
var S = {
|
|
63
135
|
root: {
|
|
64
|
-
border: "1px solid var(--
|
|
136
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))",
|
|
65
137
|
borderRadius: 10,
|
|
66
138
|
padding: 16,
|
|
67
139
|
fontFamily: "inherit",
|
|
68
140
|
fontSize: 13,
|
|
69
|
-
color: "var(--
|
|
141
|
+
color: "var(--dsw-alias-label-primary, #0f1115)"
|
|
70
142
|
},
|
|
71
143
|
// 账号详情区块
|
|
72
144
|
section: {
|
|
73
145
|
marginTop: 16,
|
|
74
146
|
paddingTop: 14,
|
|
75
|
-
borderTop: "1px solid var(--
|
|
147
|
+
borderTop: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))"
|
|
76
148
|
},
|
|
77
149
|
sectionTitle: {
|
|
78
150
|
display: "flex",
|
|
@@ -88,13 +160,13 @@ var S = {
|
|
|
88
160
|
gap: "5px 14px",
|
|
89
161
|
alignItems: "center"
|
|
90
162
|
},
|
|
91
|
-
detailKey: { fontSize: 11,
|
|
163
|
+
detailKey: { fontSize: 11, color: "var(--dsw-alias-label-secondary, #61666b)" },
|
|
92
164
|
detailVal: { fontFamily: "monospace", fontSize: 11, wordBreak: "break-all" },
|
|
93
165
|
miniBtn: {
|
|
94
166
|
background: "none",
|
|
95
|
-
border: "1px solid var(--
|
|
167
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))",
|
|
96
168
|
borderRadius: 5,
|
|
97
|
-
color: "
|
|
169
|
+
color: "var(--dsw-alias-label-primary, #0f1115)",
|
|
98
170
|
fontSize: 11,
|
|
99
171
|
padding: "1px 8px",
|
|
100
172
|
cursor: "pointer"
|
|
@@ -113,29 +185,29 @@ var S = {
|
|
|
113
185
|
fontWeight: 700,
|
|
114
186
|
fontSize: 15
|
|
115
187
|
},
|
|
116
|
-
title: { fontSize: 15, fontWeight: 600, margin: 0 },
|
|
117
|
-
sub: { fontSize: 12,
|
|
118
|
-
tabs: { display: "flex", gap: 4, borderBottom: "1px solid var(--
|
|
188
|
+
title: { fontSize: 15, fontWeight: 600, margin: 0, color: "var(--dsw-alias-label-primary, #0f1115)" },
|
|
189
|
+
sub: { fontSize: 12, color: "var(--dsw-alias-label-secondary, #61666b)", margin: "3px 0 0" },
|
|
190
|
+
tabs: { display: "flex", gap: 4, borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))", marginBottom: 14 },
|
|
119
191
|
tab: (active) => ({
|
|
120
192
|
padding: "7px 12px",
|
|
121
193
|
cursor: "pointer",
|
|
122
194
|
background: "transparent",
|
|
123
195
|
border: "none",
|
|
124
196
|
borderBottom: active ? "2px solid #c7000b" : "2px solid transparent",
|
|
125
|
-
color: active ? "var(--
|
|
197
|
+
color: active ? "var(--dsw-alias-label-primary, #0f1115)" : "var(--dsw-alias-label-secondary, #61666b)",
|
|
126
198
|
fontWeight: active ? 600 : 400,
|
|
127
199
|
fontSize: 13,
|
|
128
200
|
fontFamily: "inherit"
|
|
129
201
|
}),
|
|
130
202
|
field: { marginBottom: 12 },
|
|
131
|
-
label: { display: "block", marginBottom: 5, fontSize: 12,
|
|
203
|
+
label: { display: "block", marginBottom: 5, fontSize: 12, color: "var(--dsw-alias-label-secondary, #61666b)" },
|
|
132
204
|
input: {
|
|
133
205
|
width: "100%",
|
|
134
206
|
padding: "7px 9px",
|
|
135
207
|
borderRadius: 6,
|
|
136
|
-
border: "1px solid var(--
|
|
137
|
-
background: "var(--
|
|
138
|
-
color: "
|
|
208
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))",
|
|
209
|
+
background: "var(--dsw-alias-bg-layer-2, #f4f5f7)",
|
|
210
|
+
color: "var(--dsw-alias-label-primary, #0f1115)",
|
|
139
211
|
fontFamily: "monospace",
|
|
140
212
|
fontSize: 12,
|
|
141
213
|
boxSizing: "border-box"
|
|
@@ -145,16 +217,16 @@ var S = {
|
|
|
145
217
|
padding: "7px 14px",
|
|
146
218
|
borderRadius: 6,
|
|
147
219
|
cursor: "pointer",
|
|
148
|
-
border: primary ? "none" : "1px solid var(--
|
|
220
|
+
border: primary ? "none" : "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))",
|
|
149
221
|
background: primary ? "#c7000b" : "transparent",
|
|
150
|
-
color: primary ? "#fff" : "
|
|
222
|
+
color: primary ? "#fff" : "var(--dsw-alias-label-primary, #0f1115)",
|
|
151
223
|
fontSize: 12,
|
|
152
224
|
fontFamily: "inherit"
|
|
153
225
|
}),
|
|
154
|
-
hint: { fontSize: 12,
|
|
226
|
+
hint: { fontSize: 12, color: "var(--dsw-alias-label-secondary, #61666b)", lineHeight: 1.6, margin: "0 0 14px" },
|
|
155
227
|
table: { width: "100%", borderCollapse: "collapse", fontSize: 12 },
|
|
156
|
-
th: { textAlign: "left", padding: "7px 8px", borderBottom: "1px solid var(--
|
|
157
|
-
td: { padding: "7px 8px", borderBottom: "1px solid var(--
|
|
228
|
+
th: { textAlign: "left", padding: "7px 8px", borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))", color: "var(--dsw-alias-label-secondary, #61666b)", fontWeight: 500 },
|
|
229
|
+
td: { padding: "7px 8px", borderBottom: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))" },
|
|
158
230
|
step: (state) => ({
|
|
159
231
|
display: "flex",
|
|
160
232
|
alignItems: "center",
|
|
@@ -167,10 +239,36 @@ var S = {
|
|
|
167
239
|
height: 7,
|
|
168
240
|
borderRadius: "50%",
|
|
169
241
|
flex: "0 0 auto",
|
|
170
|
-
background: state === "ok" ? "#2ea043" : state === "fail" ? "#d1242f" : state === "run" ? "#d29922" : "#
|
|
242
|
+
background: state === "ok" ? "var(--dsw-alias-state-success-primary, #2ea043)" : state === "fail" ? "var(--dsw-alias-state-error-primary, #d1242f)" : state === "run" ? "var(--dsw-alias-state-warn-primary, #d29922)" : "var(--dsw-alias-label-tertiary, #81858c)"
|
|
171
243
|
}),
|
|
172
244
|
kv: { display: "grid", gridTemplateColumns: "110px 1fr", gap: "6px 12px", fontSize: 12, lineHeight: 1.7 },
|
|
173
|
-
kvk: {
|
|
245
|
+
kvk: { color: "var(--dsw-alias-label-secondary, #61666b)" },
|
|
246
|
+
// 开关行:文字在左、开关在右
|
|
247
|
+
uiRow: { display: "flex", alignItems: "center", gap: 12 },
|
|
248
|
+
switch: (on, busy) => ({
|
|
249
|
+
flex: "0 0 auto",
|
|
250
|
+
position: "relative",
|
|
251
|
+
width: 38,
|
|
252
|
+
height: 22,
|
|
253
|
+
padding: 0,
|
|
254
|
+
borderRadius: 11,
|
|
255
|
+
border: "none",
|
|
256
|
+
cursor: busy ? "default" : "pointer",
|
|
257
|
+
opacity: busy ? 0.6 : 1,
|
|
258
|
+
background: on ? "var(--dsw-alias-state-success-primary, #2ea043)" : "var(--dsw-alias-label-tertiary, #81858c)",
|
|
259
|
+
transition: "background .15s ease"
|
|
260
|
+
}),
|
|
261
|
+
knob: (on) => ({
|
|
262
|
+
position: "absolute",
|
|
263
|
+
top: 3,
|
|
264
|
+
left: on ? 19 : 3,
|
|
265
|
+
width: 16,
|
|
266
|
+
height: 16,
|
|
267
|
+
borderRadius: "50%",
|
|
268
|
+
background: "#fff",
|
|
269
|
+
boxShadow: "0 1px 3px rgba(0,0,0,.35)",
|
|
270
|
+
transition: "left .15s ease"
|
|
271
|
+
})
|
|
174
272
|
};
|
|
175
273
|
function CodeArtsPanel({ t }) {
|
|
176
274
|
const [tab, setTab] = useState("account");
|
|
@@ -186,6 +284,58 @@ function CodeArtsPanel({ t }) {
|
|
|
186
284
|
const [acct, setAcct] = useState(null);
|
|
187
285
|
const [checkin, setCheckin] = useState(null);
|
|
188
286
|
const [checkinBusy, setCheckinBusy] = useState(false);
|
|
287
|
+
const [uiSettings, setUiSettings] = useState(getSettings());
|
|
288
|
+
const [uiSaving, setUiSaving] = useState(false);
|
|
289
|
+
const [uiError, setUiError] = useState(null);
|
|
290
|
+
const [autoState2, setAutoState] = useState(getAutoCheckinState());
|
|
291
|
+
const [autoBusy, setAutoBusy] = useState(false);
|
|
292
|
+
useEffect(() => {
|
|
293
|
+
const stop = subscribeSettings((next) => {
|
|
294
|
+
setUiSettings(next);
|
|
295
|
+
setAutoState(getAutoCheckinState());
|
|
296
|
+
});
|
|
297
|
+
void loadSettings();
|
|
298
|
+
return stop;
|
|
299
|
+
}, []);
|
|
300
|
+
useEffect(() => {
|
|
301
|
+
if (!uiSettings.autoCheckin) return;
|
|
302
|
+
const timer = setInterval(() => {
|
|
303
|
+
void loadSettings();
|
|
304
|
+
}, 3e4);
|
|
305
|
+
return () => clearInterval(timer);
|
|
306
|
+
}, [uiSettings.autoCheckin]);
|
|
307
|
+
const toggleComposerChip = useCallback(async (next) => {
|
|
308
|
+
setUiSaving(true);
|
|
309
|
+
setUiError(null);
|
|
310
|
+
setUiSettings({ ...getSettings(), composerChip: next });
|
|
311
|
+
try {
|
|
312
|
+
await saveSettings({ composerChip: next });
|
|
313
|
+
} catch (e) {
|
|
314
|
+
setUiSettings({ ...getSettings(), composerChip: !next });
|
|
315
|
+
setUiError(String(e?.message ?? e));
|
|
316
|
+
} finally {
|
|
317
|
+
setUiSaving(false);
|
|
318
|
+
}
|
|
319
|
+
}, []);
|
|
320
|
+
const toggleAutoCheckin = useCallback(async (next) => {
|
|
321
|
+
setAutoBusy(true);
|
|
322
|
+
setUiError(null);
|
|
323
|
+
setUiSettings({ ...getSettings(), autoCheckin: next });
|
|
324
|
+
try {
|
|
325
|
+
await saveSettings({ autoCheckin: next });
|
|
326
|
+
setAutoState(getAutoCheckinState());
|
|
327
|
+
if (next) {
|
|
328
|
+
setTimeout(() => {
|
|
329
|
+
void loadSettings();
|
|
330
|
+
}, 1500);
|
|
331
|
+
}
|
|
332
|
+
} catch (e) {
|
|
333
|
+
setUiSettings({ ...getSettings(), autoCheckin: !next });
|
|
334
|
+
setUiError(String(e?.message ?? e));
|
|
335
|
+
} finally {
|
|
336
|
+
setAutoBusy(false);
|
|
337
|
+
}
|
|
338
|
+
}, []);
|
|
189
339
|
const loadCheckin = useCallback(async () => {
|
|
190
340
|
try {
|
|
191
341
|
setCheckin(await bridgeJson("/diag/checkin", 3e4));
|
|
@@ -351,6 +501,7 @@ function CodeArtsPanel({ t }) {
|
|
|
351
501
|
] }),
|
|
352
502
|
/* @__PURE__ */ jsxs("div", { style: S.tabs, children: [
|
|
353
503
|
tabBtn("account", t("tab.account")),
|
|
504
|
+
tabBtn("interface", t("tab.interface")),
|
|
354
505
|
tabBtn("models", t("tab.models")),
|
|
355
506
|
tabBtn("diagnostics", t("tab.diagnostics")),
|
|
356
507
|
tabBtn("about", t("tab.about"))
|
|
@@ -389,10 +540,10 @@ function CodeArtsPanel({ t }) {
|
|
|
389
540
|
borderRadius: 6,
|
|
390
541
|
background: r.active ? "rgba(46,160,67,0.10)" : "transparent",
|
|
391
542
|
border: r.active ? "1px solid rgba(46,160,67,0.35)" : "1px solid transparent",
|
|
392
|
-
color: r.active ? "
|
|
543
|
+
color: r.active ? "var(--dsw-alias-label-primary, #0f1115)" : "var(--dsw-alias-label-secondary, #61666b)"
|
|
393
544
|
},
|
|
394
545
|
children: [
|
|
395
|
-
/* @__PURE__ */ jsxs("span", { style: {
|
|
546
|
+
/* @__PURE__ */ jsxs("span", { style: { color: "var(--dsw-alias-label-secondary, #61666b)", minWidth: 14 }, children: [
|
|
396
547
|
i + 1,
|
|
397
548
|
"."
|
|
398
549
|
] }),
|
|
@@ -403,12 +554,12 @@ function CodeArtsPanel({ t }) {
|
|
|
403
554
|
style: {
|
|
404
555
|
fontSize: 11,
|
|
405
556
|
fontWeight: expired || urgent ? 600 : 400,
|
|
406
|
-
color: expired
|
|
557
|
+
color: expired || urgent ? "var(--dsw-alias-state-error-primary, #d1242f)" : "var(--dsw-alias-state-warn-primary, #d29922)"
|
|
407
558
|
},
|
|
408
559
|
children: r.extra
|
|
409
560
|
}
|
|
410
561
|
),
|
|
411
|
-
r.active && /* @__PURE__ */ jsx("span", { style: { fontSize: 11, color: "#2ea043", fontWeight: 600 }, children: t("account.sourceActive") })
|
|
562
|
+
r.active && /* @__PURE__ */ jsx("span", { style: { fontSize: 11, color: "var(--dsw-alias-state-success-primary, #2ea043)", fontWeight: 600 }, children: t("account.sourceActive") })
|
|
412
563
|
]
|
|
413
564
|
},
|
|
414
565
|
r.key
|
|
@@ -416,11 +567,11 @@ function CodeArtsPanel({ t }) {
|
|
|
416
567
|
})(),
|
|
417
568
|
/* @__PURE__ */ jsx("p", { style: { ...S.hint, marginBottom: 0 }, children: acct?.temporary === true ? t("account.sourceTempNote") : t("account.sourcePermNote") }),
|
|
418
569
|
/* @__PURE__ */ jsxs("details", { style: { marginTop: 10 }, children: [
|
|
419
|
-
/* @__PURE__ */ jsx("summary", { style: { fontSize: 12, cursor: "pointer",
|
|
570
|
+
/* @__PURE__ */ jsx("summary", { style: { fontSize: 12, cursor: "pointer", color: "var(--dsw-alias-label-secondary, #61666b)" }, children: t("account.howToGetAk") }),
|
|
420
571
|
/* @__PURE__ */ jsx("p", { style: { ...S.hint, marginTop: 6, marginBottom: 0 }, children: t("account.howToGetAkSteps") })
|
|
421
572
|
] }),
|
|
422
573
|
/* @__PURE__ */ jsxs("details", { style: { marginTop: 6 }, children: [
|
|
423
|
-
/* @__PURE__ */ jsx("summary", { style: { fontSize: 12, cursor: "pointer",
|
|
574
|
+
/* @__PURE__ */ jsx("summary", { style: { fontSize: 12, cursor: "pointer", color: "var(--dsw-alias-label-secondary, #61666b)" }, children: t("account.howCodeartsWorks") }),
|
|
424
575
|
/* @__PURE__ */ jsx("p", { style: { ...S.hint, marginTop: 6, marginBottom: 0 }, children: t("account.howCodeartsWorksDesc") })
|
|
425
576
|
] })
|
|
426
577
|
] }),
|
|
@@ -455,7 +606,16 @@ function CodeArtsPanel({ t }) {
|
|
|
455
606
|
/* @__PURE__ */ jsxs("div", { style: S.row, children: [
|
|
456
607
|
/* @__PURE__ */ jsx("button", { style: S.btn(true), onClick: saveCredentials, disabled: saving, children: saving ? t("account.saving") : saved ? t("account.saved") : t("account.save") }),
|
|
457
608
|
/* @__PURE__ */ jsx("button", { style: S.btn(false), onClick: testConnection, disabled: testing, children: testing ? t("account.testing") : t("account.test") }),
|
|
458
|
-
testResult && /* @__PURE__ */ jsx(
|
|
609
|
+
testResult && /* @__PURE__ */ jsx(
|
|
610
|
+
"span",
|
|
611
|
+
{
|
|
612
|
+
style: {
|
|
613
|
+
fontSize: 12,
|
|
614
|
+
color: testResult.ok ? "var(--dsw-alias-state-success-primary, #2ea043)" : "var(--dsw-alias-state-error-primary, #d1242f)"
|
|
615
|
+
},
|
|
616
|
+
children: testResult.message
|
|
617
|
+
}
|
|
618
|
+
)
|
|
459
619
|
] }),
|
|
460
620
|
/* @__PURE__ */ jsxs("div", { style: S.section, children: [
|
|
461
621
|
/* @__PURE__ */ jsxs("div", { style: S.sectionTitle, children: [
|
|
@@ -493,7 +653,7 @@ function CodeArtsPanel({ t }) {
|
|
|
493
653
|
{
|
|
494
654
|
style: {
|
|
495
655
|
...S.detailVal,
|
|
496
|
-
color: acct.creditExpiry.level === "urgent" || acct.creditExpiry.level === "warn" ? "#d1242f" : "#d29922"
|
|
656
|
+
color: acct.creditExpiry.level === "urgent" || acct.creditExpiry.level === "warn" ? "var(--dsw-alias-state-error-primary, #d1242f)" : "var(--dsw-alias-state-warn-primary, #d29922)"
|
|
497
657
|
},
|
|
498
658
|
children: acct.creditExpiry.message
|
|
499
659
|
}
|
|
@@ -507,7 +667,68 @@ function CodeArtsPanel({ t }) {
|
|
|
507
667
|
/* @__PURE__ */ jsx("span", { style: { flex: 1, fontSize: 12 }, children: checkin.status === "CLAIMED" || checkin.status === "CONFIRMED" || checkin.status === "CONSUMED" ? t("checkin.done", { n: checkin.amount ?? 100 }) : checkin.claimable ? t("checkin.available", { n: checkin.pendingAmount ?? 100 }) : t("checkin.idle") }),
|
|
508
668
|
checkin.claimable ? /* @__PURE__ */ jsx("button", { style: S.btn(true), onClick: () => void doCheckin(), disabled: checkinBusy, children: checkinBusy ? t("checkin.doing") : t("checkin.claim") }) : null,
|
|
509
669
|
/* @__PURE__ */ jsx("button", { style: S.btn(false), onClick: () => void doClaimAll(), disabled: checkinBusy, children: checkinBusy ? t("checkin.allDoing") : t("checkin.all") })
|
|
510
|
-
] }) : /* @__PURE__ */ jsx("div", { style: S.hint, children: checkin?.reason ?? t("checkin.unavailable") })
|
|
670
|
+
] }) : /* @__PURE__ */ jsx("div", { style: S.hint, children: checkin?.reason ?? t("checkin.unavailable") }),
|
|
671
|
+
/* @__PURE__ */ jsxs(
|
|
672
|
+
"div",
|
|
673
|
+
{
|
|
674
|
+
style: {
|
|
675
|
+
...S.uiRow,
|
|
676
|
+
marginTop: 12,
|
|
677
|
+
paddingTop: 12,
|
|
678
|
+
borderTop: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))"
|
|
679
|
+
},
|
|
680
|
+
children: [
|
|
681
|
+
/* @__PURE__ */ jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
682
|
+
/* @__PURE__ */ jsx("div", { style: { fontSize: 12 }, children: t("checkin.auto") }),
|
|
683
|
+
/* @__PURE__ */ jsx("div", { style: { ...S.hint, margin: "2px 0 0", fontSize: 11 }, children: t("checkin.autoHint") })
|
|
684
|
+
] }),
|
|
685
|
+
/* @__PURE__ */ jsx(
|
|
686
|
+
"button",
|
|
687
|
+
{
|
|
688
|
+
type: "button",
|
|
689
|
+
role: "switch",
|
|
690
|
+
"aria-checked": uiSettings.autoCheckin ? "true" : "false",
|
|
691
|
+
"aria-label": t("checkin.auto"),
|
|
692
|
+
style: S.switch(uiSettings.autoCheckin, autoBusy),
|
|
693
|
+
disabled: autoBusy,
|
|
694
|
+
onClick: () => void toggleAutoCheckin(!uiSettings.autoCheckin),
|
|
695
|
+
children: /* @__PURE__ */ jsx("span", { style: S.knob(uiSettings.autoCheckin) })
|
|
696
|
+
}
|
|
697
|
+
)
|
|
698
|
+
]
|
|
699
|
+
}
|
|
700
|
+
),
|
|
701
|
+
uiSettings.autoCheckin && /* @__PURE__ */ jsx("div", { style: { ...S.hint, margin: "8px 0 0", fontSize: 11 }, children: autoState2?.lastMessage ? `${t("checkin.autoLast")}${autoState2.lastMessage}` : t("checkin.autoIdle") })
|
|
702
|
+
] })
|
|
703
|
+
] }),
|
|
704
|
+
tab === "interface" && /* @__PURE__ */ jsxs("div", { children: [
|
|
705
|
+
/* @__PURE__ */ jsx("p", { style: { ...S.hint, marginTop: 0 }, children: t("ui.hint") }),
|
|
706
|
+
/* @__PURE__ */ jsxs("div", { style: S.section, children: [
|
|
707
|
+
/* @__PURE__ */ jsx("div", { style: S.sectionTitle, children: t("ui.chipSection") }),
|
|
708
|
+
/* @__PURE__ */ jsxs("div", { style: S.uiRow, children: [
|
|
709
|
+
/* @__PURE__ */ jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
710
|
+
/* @__PURE__ */ jsx("div", { style: { fontSize: 12 }, children: t("ui.composerChip") }),
|
|
711
|
+
/* @__PURE__ */ jsx("div", { style: { ...S.hint, margin: "2px 0 0", fontSize: 11 }, children: t("ui.composerChipHint") })
|
|
712
|
+
] }),
|
|
713
|
+
/* @__PURE__ */ jsx(
|
|
714
|
+
"button",
|
|
715
|
+
{
|
|
716
|
+
type: "button",
|
|
717
|
+
role: "switch",
|
|
718
|
+
"aria-checked": uiSettings.composerChip ? "true" : "false",
|
|
719
|
+
"aria-label": t("ui.composerChip"),
|
|
720
|
+
style: S.switch(uiSettings.composerChip, uiSaving),
|
|
721
|
+
disabled: uiSaving,
|
|
722
|
+
onClick: () => void toggleComposerChip(!uiSettings.composerChip),
|
|
723
|
+
children: /* @__PURE__ */ jsx("span", { style: S.knob(uiSettings.composerChip) })
|
|
724
|
+
}
|
|
725
|
+
)
|
|
726
|
+
] }),
|
|
727
|
+
uiError && /* @__PURE__ */ jsxs("div", { style: { marginTop: 8, fontSize: 11, color: "var(--dsw-alias-state-error-primary, #d1242f)" }, children: [
|
|
728
|
+
t("ui.saveFail"),
|
|
729
|
+
" \xB7 ",
|
|
730
|
+
uiError
|
|
731
|
+
] })
|
|
511
732
|
] })
|
|
512
733
|
] }),
|
|
513
734
|
tab === "models" && /* @__PURE__ */ jsxs("div", { children: [
|
|
@@ -524,11 +745,11 @@ function CodeArtsPanel({ t }) {
|
|
|
524
745
|
] }) }),
|
|
525
746
|
/* @__PURE__ */ jsx("tbody", { children: models.map((m) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
526
747
|
/* @__PURE__ */ jsx("td", { style: S.td, title: m.description ?? void 0, children: m.name }),
|
|
527
|
-
/* @__PURE__ */ jsx("td", { style: { ...S.td, fontFamily: "monospace",
|
|
748
|
+
/* @__PURE__ */ jsx("td", { style: { ...S.td, fontFamily: "monospace", color: "var(--dsw-alias-label-secondary, #61666b)", fontSize: 11 }, children: m.id }),
|
|
528
749
|
/* @__PURE__ */ jsx("td", { style: S.td, children: (m.context ?? m.context_window ?? 0).toLocaleString() }),
|
|
529
750
|
/* @__PURE__ */ jsx("td", { style: S.td, children: (m.maxOutput ?? m.max_output_tokens ?? 0).toLocaleString() }),
|
|
530
751
|
/* @__PURE__ */ jsx("td", { style: { ...S.td, fontFamily: "monospace" }, children: m.ratio ?? "\u2014" }),
|
|
531
|
-
/* @__PURE__ */ jsx("td", { style: S.td, title: m.supportsImages ?? m.supports_images ? t("models.visionYes") : t("models.visionNo"), children: m.supportsImages ?? m.supports_images ? "\u{1F441}" : /* @__PURE__ */ jsx("span", { style: {
|
|
752
|
+
/* @__PURE__ */ jsx("td", { style: S.td, title: m.supportsImages ?? m.supports_images ? t("models.visionYes") : t("models.visionNo"), children: m.supportsImages ?? m.supports_images ? "\u{1F441}" : /* @__PURE__ */ jsx("span", { style: { color: "var(--dsw-alias-label-secondary, #61666b)" }, children: "\u2014" }) }),
|
|
532
753
|
/* @__PURE__ */ jsx("td", { style: { ...S.td, fontSize: 11, opacity: m.strengths?.length ? 1 : 0.25 }, children: m.strengths?.length ? m.strengths.join(" / ") : "\u2014" })
|
|
533
754
|
] }, m.id)) })
|
|
534
755
|
] })
|
|
@@ -544,7 +765,7 @@ function CodeArtsPanel({ t }) {
|
|
|
544
765
|
].map(([key, label]) => /* @__PURE__ */ jsxs("div", { style: S.step(diag[key] ?? "idle"), children: [
|
|
545
766
|
/* @__PURE__ */ jsx("span", { style: S.dot(diag[key] ?? "idle") }),
|
|
546
767
|
/* @__PURE__ */ jsx("span", { style: { flex: 1 }, children: label }),
|
|
547
|
-
/* @__PURE__ */ jsx("span", { style: {
|
|
768
|
+
/* @__PURE__ */ jsx("span", { style: { color: "var(--dsw-alias-label-secondary, #61666b)", fontSize: 11 }, children: diag[key] === "ok" ? "\u2713" : diag[key] === "fail" ? "\u2717" : diag[key] === "run" ? "\u2026" : "\u2014" })
|
|
548
769
|
] }, key)) })
|
|
549
770
|
] }),
|
|
550
771
|
tab === "about" && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs("div", { style: S.kv, children: [
|
|
@@ -568,6 +789,12 @@ function fmt(n) {
|
|
|
568
789
|
return n.toLocaleString("zh-CN", { maximumFractionDigits: 2 });
|
|
569
790
|
}
|
|
570
791
|
function ComposerChip({ t }) {
|
|
792
|
+
const [visible, setVisible] = useState2(getSettings().composerChip);
|
|
793
|
+
useEffect2(() => {
|
|
794
|
+
const stop = subscribeSettings((next) => setVisible(next.composerChip));
|
|
795
|
+
void loadSettings();
|
|
796
|
+
return stop;
|
|
797
|
+
}, []);
|
|
571
798
|
const [health, setHealth] = useState2(null);
|
|
572
799
|
const [account, setAccount] = useState2(null);
|
|
573
800
|
const [open, setOpen] = useState2(false);
|
|
@@ -627,6 +854,7 @@ function ComposerChip({ t }) {
|
|
|
627
854
|
const state = health?.ok ? "ready" : health ? "fail" : "idle";
|
|
628
855
|
const label = state === "ready" ? t("chip.ready") : t("chip.idle");
|
|
629
856
|
const credit = account?.credit;
|
|
857
|
+
if (!visible) return null;
|
|
630
858
|
return /* @__PURE__ */ jsxs2("div", { ref: boxRef, style: { position: "relative", display: "inline-flex" }, children: [
|
|
631
859
|
/* @__PURE__ */ jsxs2("button", { style: S2.chip(state), onClick: () => setOpen((v) => !v), title: t("meta.title"), children: [
|
|
632
860
|
/* @__PURE__ */ jsx2("span", { style: S2.dot(state) }),
|
|
@@ -671,7 +899,7 @@ function ComposerChip({ t }) {
|
|
|
671
899
|
/* @__PURE__ */ jsx2("div", { style: S2.sep }),
|
|
672
900
|
/* @__PURE__ */ jsx2("button", { style: S2.testBtn(busy), disabled: busy, onClick: () => void testAndRefresh(), children: busy ? t("chip.testing") : t("chip.testRefresh") }),
|
|
673
901
|
steps && /* @__PURE__ */ jsx2("div", { style: S2.steps, children: steps.map((s) => /* @__PURE__ */ jsxs2("div", { style: S2.stepRow, children: [
|
|
674
|
-
/* @__PURE__ */ jsx2("span", { style: { color: s.ok ? "var(--
|
|
902
|
+
/* @__PURE__ */ jsx2("span", { style: { color: s.ok ? "var(--dsw-alias-state-success-primary, #2ea043)" : "var(--dsw-alias-state-error-primary, #d1242f)" }, children: s.ok ? "\u2713" : "\u2717" }),
|
|
675
903
|
/* @__PURE__ */ jsx2("span", { style: { flex: 1 }, children: s.name }),
|
|
676
904
|
/* @__PURE__ */ jsx2("span", { style: S2.stepDetail, title: s.detail, children: s.detail ?? (s.ms ? `${s.ms}ms` : "") })
|
|
677
905
|
] }, s.name)) })
|
|
@@ -686,9 +914,9 @@ var S2 = {
|
|
|
686
914
|
height: 26,
|
|
687
915
|
padding: "0 9px",
|
|
688
916
|
borderRadius: 13,
|
|
689
|
-
border: "1px solid var(--
|
|
917
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))",
|
|
690
918
|
background: "transparent",
|
|
691
|
-
color: "
|
|
919
|
+
color: "var(--dsw-alias-label-primary, #0f1115)",
|
|
692
920
|
fontSize: 12,
|
|
693
921
|
cursor: "pointer",
|
|
694
922
|
opacity: state === "idle" ? 0.6 : 1
|
|
@@ -697,15 +925,15 @@ var S2 = {
|
|
|
697
925
|
width: 6,
|
|
698
926
|
height: 6,
|
|
699
927
|
borderRadius: "50%",
|
|
700
|
-
background: state === "ready" ? "var(--
|
|
928
|
+
background: state === "ready" ? "var(--dsw-alias-state-success-primary, #2ea043)" : state === "fail" ? "var(--dsw-alias-state-error-primary, #d1242f)" : "var(--dsw-alias-label-tertiary, #81858c)"
|
|
701
929
|
}),
|
|
702
930
|
mini: {
|
|
703
931
|
marginLeft: 2,
|
|
704
932
|
paddingLeft: 6,
|
|
705
|
-
borderLeft: "1px solid var(--
|
|
933
|
+
borderLeft: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))",
|
|
706
934
|
fontFamily: "monospace",
|
|
707
935
|
fontSize: 11,
|
|
708
|
-
|
|
936
|
+
color: "var(--dsw-alias-label-secondary, #61666b)"
|
|
709
937
|
},
|
|
710
938
|
pop: {
|
|
711
939
|
position: "absolute",
|
|
@@ -714,10 +942,10 @@ var S2 = {
|
|
|
714
942
|
width: 288,
|
|
715
943
|
padding: 12,
|
|
716
944
|
borderRadius: 10,
|
|
717
|
-
border: "1px solid var(--
|
|
718
|
-
background: "var(--
|
|
945
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))",
|
|
946
|
+
background: "var(--dsw-alias-bg-layer-3, #ffffff)",
|
|
719
947
|
boxShadow: "0 8px 28px rgba(0,0,0,.45)",
|
|
720
|
-
color: "var(--
|
|
948
|
+
color: "var(--dsw-alias-label-primary, #0f1115)",
|
|
721
949
|
fontSize: 12,
|
|
722
950
|
zIndex: 50
|
|
723
951
|
},
|
|
@@ -726,8 +954,8 @@ var S2 = {
|
|
|
726
954
|
fontSize: 10,
|
|
727
955
|
padding: "1px 6px",
|
|
728
956
|
borderRadius: 8,
|
|
729
|
-
background: ok ? "
|
|
730
|
-
color: ok ? "var(--
|
|
957
|
+
background: ok ? "color-mix(in srgb, var(--dsw-alias-state-success-primary, #2ea043) 16%, transparent)" : "color-mix(in srgb, var(--dsw-alias-state-error-primary, #d1242f) 16%, transparent)",
|
|
958
|
+
color: ok ? "var(--dsw-alias-state-success-primary, #2ea043)" : "var(--dsw-alias-state-error-primary, #d1242f)"
|
|
731
959
|
}),
|
|
732
960
|
account: { display: "flex", alignItems: "center", gap: 8 },
|
|
733
961
|
avatar: {
|
|
@@ -737,7 +965,7 @@ var S2 = {
|
|
|
737
965
|
display: "inline-flex",
|
|
738
966
|
alignItems: "center",
|
|
739
967
|
justifyContent: "center",
|
|
740
|
-
background: "
|
|
968
|
+
background: "var(--dsw-alias-bg-layer-2, #f4f5f7)",
|
|
741
969
|
fontSize: 12,
|
|
742
970
|
fontWeight: 600,
|
|
743
971
|
flexShrink: 0
|
|
@@ -748,15 +976,15 @@ var S2 = {
|
|
|
748
976
|
mono: { fontFamily: "monospace", fontSize: 11 },
|
|
749
977
|
big: { fontSize: 22, fontWeight: 600, fontVariantNumeric: "tabular-nums", marginBottom: 5 },
|
|
750
978
|
bigUnit: { fontSize: 12, fontWeight: 400, opacity: 0.55 },
|
|
751
|
-
sep: { height: 1, background: "var(--
|
|
979
|
+
sep: { height: 1, background: "var(--dsw-alias-border-l2, rgba(0,0,0,.1))", margin: "10px 0" },
|
|
752
980
|
hint: { fontSize: 11, opacity: 0.6, lineHeight: 1.5 },
|
|
753
981
|
testBtn: (busy) => ({
|
|
754
982
|
width: "100%",
|
|
755
983
|
height: 30,
|
|
756
984
|
borderRadius: 7,
|
|
757
|
-
border: "1px solid var(--
|
|
758
|
-
background: "var(--
|
|
759
|
-
color: "
|
|
985
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(0,0,0,.1))",
|
|
986
|
+
background: "var(--dsw-alias-bg-layer-2, #f4f5f7)",
|
|
987
|
+
color: "var(--dsw-alias-label-primary, #0f1115)",
|
|
760
988
|
fontSize: 12,
|
|
761
989
|
cursor: busy ? "default" : "pointer",
|
|
762
990
|
opacity: busy ? 0.6 : 1
|
|
@@ -766,6 +994,30 @@ var S2 = {
|
|
|
766
994
|
stepDetail: { opacity: 0.55, fontFamily: "monospace", fontSize: 10, maxWidth: 140, textAlign: "right", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }
|
|
767
995
|
};
|
|
768
996
|
|
|
997
|
+
// src/client/SectionIcon.tsx
|
|
998
|
+
const { jsx: jsx3 } = require("react/jsx-runtime");
|
|
999
|
+
function SettingsSectionIcon(props) {
|
|
1000
|
+
const size = typeof props?.size === "number" ? props.size : 16;
|
|
1001
|
+
return jsx3("span", {
|
|
1002
|
+
style: {
|
|
1003
|
+
display: "inline-flex",
|
|
1004
|
+
alignItems: "center",
|
|
1005
|
+
justifyContent: "center",
|
|
1006
|
+
width: size,
|
|
1007
|
+
height: size,
|
|
1008
|
+
borderRadius: Math.max(3, Math.round(size * 0.25)),
|
|
1009
|
+
background: "linear-gradient(135deg,#c7000b,#ff6a00)",
|
|
1010
|
+
color: "#fff",
|
|
1011
|
+
fontSize: Math.max(9, Math.round(size * 0.68)),
|
|
1012
|
+
fontWeight: 700,
|
|
1013
|
+
lineHeight: 1,
|
|
1014
|
+
opacity: props?.active === false ? 0.55 : 1,
|
|
1015
|
+
flex: "0 0 auto"
|
|
1016
|
+
},
|
|
1017
|
+
children: "\u7801"
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
|
|
769
1021
|
// src/client/index.ts
|
|
770
1022
|
var name = "dsh-connect-madao-client";
|
|
771
1023
|
var inject = ["slots", "locale"];
|
|
@@ -773,6 +1025,7 @@ var zh = {
|
|
|
773
1025
|
"meta.title": "\u7801\u9053\u8FDE\u63A5\u5668",
|
|
774
1026
|
"meta.desc": "\u628A\u534E\u4E3A\u4E91\u7801\u9053\uFF08CodeArts Agent\uFF09\u6A21\u578B\u63A5\u5165 DSH",
|
|
775
1027
|
"tab.account": "\u8D26\u53F7",
|
|
1028
|
+
"tab.interface": "\u754C\u9762",
|
|
776
1029
|
"tab.models": "\u6A21\u578B",
|
|
777
1030
|
"tab.diagnostics": "\u8BCA\u65AD",
|
|
778
1031
|
"tab.about": "\u5173\u4E8E",
|
|
@@ -825,6 +1078,15 @@ var zh = {
|
|
|
825
1078
|
"checkin.allGot": "\u5DF2\u9886\u53D6 {n} \u9879\u6D3B\u52A8",
|
|
826
1079
|
"checkin.allNone": "\u6CA1\u6709\u53EF\u9886\u7684\u6D3B\u52A8",
|
|
827
1080
|
"checkin.expiring": "\u79EF\u5206\u5373\u5C06\u5230\u671F",
|
|
1081
|
+
"checkin.auto": "\u81EA\u52A8\u7B7E\u5230",
|
|
1082
|
+
"checkin.autoHint": "\u5F00\u542F\u540E\uFF0C\u63D2\u4EF6\u6BCF\u5206\u949F\u68C0\u67E5\u4E00\u6B21\uFF0C\u53D1\u73B0\u5F53\u5929\u53EF\u9886\u5C31\u81EA\u52A8\u9886\u53D6\uFF08\u6BCF 15 \u5206\u949F\u6700\u591A\u5C1D\u8BD5\u4E00\u6B21\uFF09\u3002\u9ED8\u8BA4\u5173\u95ED\u3002",
|
|
1083
|
+
"checkin.autoLast": "\u4E0A\u6B21\uFF1A",
|
|
1084
|
+
"checkin.autoIdle": "\u8FD8\u6CA1\u6709\u8FD0\u884C\u8FC7\uFF0C\u7A0D\u540E\u81EA\u52A8\u68C0\u67E5\u3002",
|
|
1085
|
+
"ui.hint": "\u8FD9\u91CC\u7684\u5F00\u5173\u70B9\u4E00\u4E0B\u5C31\u751F\u6548\uFF0C\u4E0D\u9700\u8981\u91CD\u542F DSH\u3002",
|
|
1086
|
+
"ui.chipSection": "\u8F93\u5165\u6846\u72B6\u6001\u80F6\u56CA",
|
|
1087
|
+
"ui.composerChip": "\u663E\u793A\u8F93\u5165\u6846\u300C\u7801\u9053\u300D\u72B6\u6001\u80F6\u56CA",
|
|
1088
|
+
"ui.composerChipHint": "\u5173\u6389\u540E\uFF0C\u8F93\u5165\u6846\u53F3\u4FA7\u90A3\u4E2A\u300C\u25CF \u7801\u9053\u300D\u5C0F\u80F6\u56CA\u4E0D\u518D\u51FA\u73B0\uFF1B\u8D26\u53F7\u4E0E\u79EF\u5206\u4ECD\u53EF\u5728\u672C\u9875\u67E5\u770B\u3002",
|
|
1089
|
+
"ui.saveFail": "\u4FDD\u5B58\u5931\u8D25",
|
|
828
1090
|
"models.title": "\u53EF\u7528\u6A21\u578B",
|
|
829
1091
|
"models.hint": "\u4EE5\u4E0B\u6A21\u578B\u53D6\u81EA\u7801\u9053\u7F51\u5173\uFF0C\u5171 {n} \u4E2A\u3002",
|
|
830
1092
|
"models.name": "\u540D\u79F0",
|
|
@@ -871,6 +1133,7 @@ var en = {
|
|
|
871
1133
|
"meta.title": "CodeArts Connector",
|
|
872
1134
|
"meta.desc": "Bring Huawei Cloud CodeArts Agent models into DSH",
|
|
873
1135
|
"tab.account": "Account",
|
|
1136
|
+
"tab.interface": "Interface",
|
|
874
1137
|
"tab.models": "Models",
|
|
875
1138
|
"tab.diagnostics": "Diagnostics",
|
|
876
1139
|
"tab.about": "About",
|
|
@@ -923,6 +1186,15 @@ var en = {
|
|
|
923
1186
|
"checkin.allGot": "Claimed {n} campaign(s)",
|
|
924
1187
|
"checkin.allNone": "Nothing to claim",
|
|
925
1188
|
"checkin.expiring": "Credits expiring soon",
|
|
1189
|
+
"checkin.auto": "Auto check-in",
|
|
1190
|
+
"checkin.autoHint": "When on, the plugin checks once a minute and claims the daily reward as soon as it is available (at most one attempt every 15 minutes). Off by default.",
|
|
1191
|
+
"checkin.autoLast": "Last: ",
|
|
1192
|
+
"checkin.autoIdle": "Has not run yet; it will check shortly.",
|
|
1193
|
+
"ui.hint": "These switches take effect immediately \u2014 no DSH restart needed.",
|
|
1194
|
+
"ui.chipSection": "Composer status chip",
|
|
1195
|
+
"ui.composerChip": "Show the CodeArts status chip in the composer",
|
|
1196
|
+
"ui.composerChipHint": "When off, the small \u201C\u25CF CodeArts\u201D chip beside the composer is hidden. Account and credits stay available on this page.",
|
|
1197
|
+
"ui.saveFail": "Save failed",
|
|
926
1198
|
"models.title": "Available models",
|
|
927
1199
|
"models.hint": "{n} models from the CodeArts gateway.",
|
|
928
1200
|
"models.name": "Name",
|
|
@@ -996,6 +1268,36 @@ function apply(ctx) {
|
|
|
996
1268
|
}
|
|
997
1269
|
};
|
|
998
1270
|
registerCard("plugins.bundle.config");
|
|
1271
|
+
const SETTINGS_SECTION_ID = "dsh-connect-madao";
|
|
1272
|
+
try {
|
|
1273
|
+
ctx.slots.inject(
|
|
1274
|
+
"settings.section",
|
|
1275
|
+
() => ctx.slots.register(
|
|
1276
|
+
{
|
|
1277
|
+
name: "settings.section",
|
|
1278
|
+
id: SETTINGS_SECTION_ID,
|
|
1279
|
+
order: 55,
|
|
1280
|
+
label: () => t("meta.title"),
|
|
1281
|
+
locale: namespace,
|
|
1282
|
+
inject: () => ({ t, surface: "settings" })
|
|
1283
|
+
},
|
|
1284
|
+
CodeArtsPanel
|
|
1285
|
+
)
|
|
1286
|
+
);
|
|
1287
|
+
} catch (err) {
|
|
1288
|
+
console.error("[dsh-connect-madao] settings.section register failed:", err);
|
|
1289
|
+
}
|
|
1290
|
+
try {
|
|
1291
|
+
ctx.slots.inject(
|
|
1292
|
+
"settings.section.icon",
|
|
1293
|
+
() => ctx.slots.register(
|
|
1294
|
+
{ name: "settings.section.icon", id: SETTINGS_SECTION_ID, locale: namespace },
|
|
1295
|
+
SettingsSectionIcon
|
|
1296
|
+
)
|
|
1297
|
+
);
|
|
1298
|
+
} catch (err) {
|
|
1299
|
+
console.warn("[dsh-connect-madao] settings nav icon register failed (page unaffected):", err);
|
|
1300
|
+
}
|
|
999
1301
|
try {
|
|
1000
1302
|
ctx.slots.inject(
|
|
1001
1303
|
"conversation.input.right",
|
package/lib/index.js
CHANGED
|
@@ -85,7 +85,7 @@ var init_models = __esm({
|
|
|
85
85
|
import { createHash as createHash5 } from "node:crypto";
|
|
86
86
|
import { createServer } from "node:http";
|
|
87
87
|
import { writeFileSync } from "node:fs";
|
|
88
|
-
import { join as
|
|
88
|
+
import { join as join5 } from "node:path";
|
|
89
89
|
|
|
90
90
|
// src/client.ts
|
|
91
91
|
import { createHash as createHash3, randomUUID } from "node:crypto";
|
|
@@ -1856,6 +1856,59 @@ async function claimAllCheckins(client) {
|
|
|
1856
1856
|
return { ok: true, claimed, skipped, campaigns };
|
|
1857
1857
|
}
|
|
1858
1858
|
|
|
1859
|
+
// src/settings.ts
|
|
1860
|
+
import { mkdir as mkdir2, readFile as readFile2, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
|
|
1861
|
+
import { homedir as homedir4 } from "node:os";
|
|
1862
|
+
import { join as join4 } from "node:path";
|
|
1863
|
+
var SETTINGS_FILENAME = "dsh-connect-madao-state.json";
|
|
1864
|
+
var DEFAULT_SETTINGS = Object.freeze({
|
|
1865
|
+
schemaVersion: 1,
|
|
1866
|
+
composerChip: true,
|
|
1867
|
+
autoCheckin: false
|
|
1868
|
+
});
|
|
1869
|
+
function settingsPath(env = process.env) {
|
|
1870
|
+
const home = typeof env.DSH_HOME === "string" && env.DSH_HOME.length > 0 ? env.DSH_HOME : join4(homedir4(), ".dsh");
|
|
1871
|
+
return join4(home, SETTINGS_FILENAME);
|
|
1872
|
+
}
|
|
1873
|
+
function normalizeSettings(raw) {
|
|
1874
|
+
if (typeof raw !== "object" || raw === null) return { ...DEFAULT_SETTINGS };
|
|
1875
|
+
const record = raw;
|
|
1876
|
+
return {
|
|
1877
|
+
schemaVersion: 1,
|
|
1878
|
+
composerChip: typeof record.composerChip === "boolean" ? record.composerChip : DEFAULT_SETTINGS.composerChip,
|
|
1879
|
+
autoCheckin: typeof record.autoCheckin === "boolean" ? record.autoCheckin : DEFAULT_SETTINGS.autoCheckin
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
async function readSettings(env = process.env) {
|
|
1883
|
+
let text;
|
|
1884
|
+
try {
|
|
1885
|
+
text = await readFile2(settingsPath(env), "utf8");
|
|
1886
|
+
} catch {
|
|
1887
|
+
return { ...DEFAULT_SETTINGS };
|
|
1888
|
+
}
|
|
1889
|
+
try {
|
|
1890
|
+
return normalizeSettings(JSON.parse(text));
|
|
1891
|
+
} catch {
|
|
1892
|
+
return { ...DEFAULT_SETTINGS };
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
async function writeSettings(next, env = process.env) {
|
|
1896
|
+
const target = settingsPath(env);
|
|
1897
|
+
await mkdir2(join4(target, ".."), { recursive: true });
|
|
1898
|
+
const tmp = `${target}.${process.pid}.tmp`;
|
|
1899
|
+
await writeFile2(tmp, `${JSON.stringify(next, null, 2)}
|
|
1900
|
+
`, { encoding: "utf8", mode: 384 });
|
|
1901
|
+
await rename2(tmp, target);
|
|
1902
|
+
return next;
|
|
1903
|
+
}
|
|
1904
|
+
async function patchSettings(patch, env = process.env) {
|
|
1905
|
+
const current = await readSettings(env);
|
|
1906
|
+
const next = normalizeSettings({ ...current, ...patch });
|
|
1907
|
+
await writeSettings(next, env);
|
|
1908
|
+
chatLog(`settings updated: composerChip=${next.composerChip} autoCheckin=${next.autoCheckin}`);
|
|
1909
|
+
return next;
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1859
1912
|
// src/server.ts
|
|
1860
1913
|
async function ensureFreshClient(ctx) {
|
|
1861
1914
|
if (!ctx.sts || !ctx.loaded) return;
|
|
@@ -1871,6 +1924,10 @@ async function ensureFreshClient(ctx) {
|
|
|
1871
1924
|
chatLog(`STS refresh failed: ${String(e?.message ?? e).slice(0, 160)}`);
|
|
1872
1925
|
}
|
|
1873
1926
|
}
|
|
1927
|
+
async function borrowClient(ctx) {
|
|
1928
|
+
await ensureFreshClient(ctx);
|
|
1929
|
+
return ctx.client;
|
|
1930
|
+
}
|
|
1874
1931
|
async function startServer(opts = {}) {
|
|
1875
1932
|
const port = opts.port ?? 8765;
|
|
1876
1933
|
const host = opts.host ?? "127.0.0.1";
|
|
@@ -1941,7 +1998,8 @@ ${failures.map((f) => ` ${f}`).join("\n")}`);
|
|
|
1941
1998
|
server,
|
|
1942
1999
|
port: actualPort,
|
|
1943
2000
|
url: `http://${host}:${actualPort}`,
|
|
1944
|
-
close: () => new Promise((resolve, reject) => server.close((e) => e ? reject(e) : resolve()))
|
|
2001
|
+
close: () => new Promise((resolve, reject) => server.close((e) => e ? reject(e) : resolve())),
|
|
2002
|
+
ctx
|
|
1945
2003
|
};
|
|
1946
2004
|
}
|
|
1947
2005
|
async function handle(req, res, ctx) {
|
|
@@ -1958,6 +2016,44 @@ async function handle(req, res, ctx) {
|
|
|
1958
2016
|
if (req.method === "GET" && url.pathname === "/healthz") {
|
|
1959
2017
|
return json(res, 200, await healthz(ctx));
|
|
1960
2018
|
}
|
|
2019
|
+
if (url.pathname === "/settings" && (req.method === "GET" || req.method === "POST")) {
|
|
2020
|
+
if (req.method === "GET") {
|
|
2021
|
+
const settings = await readSettings();
|
|
2022
|
+
return json(res, 200, {
|
|
2023
|
+
ok: true,
|
|
2024
|
+
settings,
|
|
2025
|
+
autoCheckin: ctx.autoCheckin ? ctx.autoCheckin.state() : null
|
|
2026
|
+
});
|
|
2027
|
+
}
|
|
2028
|
+
let payload = {};
|
|
2029
|
+
try {
|
|
2030
|
+
payload = JSON.parse(await readBody(req));
|
|
2031
|
+
} catch {
|
|
2032
|
+
return json(res, 400, { error: { message: "\u8BF7\u6C42\u4F53\u4E0D\u662F\u5408\u6CD5 JSON" } });
|
|
2033
|
+
}
|
|
2034
|
+
const patch = {};
|
|
2035
|
+
if (typeof payload.composerChip === "boolean") patch.composerChip = payload.composerChip;
|
|
2036
|
+
if (typeof payload.autoCheckin === "boolean") patch.autoCheckin = payload.autoCheckin;
|
|
2037
|
+
if (Object.keys(patch).length === 0) {
|
|
2038
|
+
return json(res, 400, { error: { message: "\u6CA1\u6709\u53EF\u66F4\u65B0\u7684\u5B57\u6BB5" } });
|
|
2039
|
+
}
|
|
2040
|
+
try {
|
|
2041
|
+
const settings = await patchSettings(patch);
|
|
2042
|
+
if (ctx.autoCheckin) {
|
|
2043
|
+
try {
|
|
2044
|
+
await ctx.autoCheckin.tick();
|
|
2045
|
+
} catch {
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
return json(res, 200, {
|
|
2049
|
+
ok: true,
|
|
2050
|
+
settings,
|
|
2051
|
+
autoCheckin: ctx.autoCheckin ? ctx.autoCheckin.state() : null
|
|
2052
|
+
});
|
|
2053
|
+
} catch (e) {
|
|
2054
|
+
return json(res, 500, { error: { message: `\u4FDD\u5B58\u8BBE\u7F6E\u5931\u8D25\uFF1A${String(e?.message ?? e)}` } });
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
1961
2057
|
if (req.method === "GET" && (url.pathname === "/diag/account" || url.pathname === "/diag/credit")) {
|
|
1962
2058
|
return json(res, 200, await accountInfo(ctx));
|
|
1963
2059
|
}
|
|
@@ -2225,7 +2321,7 @@ async function chatCompletion(res, client, rawBody, ctxModels) {
|
|
|
2225
2321
|
`chat REJECT context ${estTokens} (msgs ${estMessages} + tools ${estTools}/${toolCount}) > ${limit} for ${model}`
|
|
2226
2322
|
);
|
|
2227
2323
|
try {
|
|
2228
|
-
writeFileSync(
|
|
2324
|
+
writeFileSync(join5(logDir(), "last-rejected.json"), JSON.stringify(rawBody), "utf8");
|
|
2229
2325
|
chatLog("chat REJECT \u8BF7\u6C42\u4F53\u5DF2\u5B58\u81F3 ~/.dsh-connect-madao/last-rejected.json");
|
|
2230
2326
|
} catch {
|
|
2231
2327
|
}
|
|
@@ -2588,6 +2684,98 @@ function json(res, status, payload) {
|
|
|
2588
2684
|
res.end(body);
|
|
2589
2685
|
}
|
|
2590
2686
|
|
|
2687
|
+
// src/auto-checkin.ts
|
|
2688
|
+
var TICK_MS = 6e4;
|
|
2689
|
+
var CLAIM_INTERVAL_MS = 15 * 6e4;
|
|
2690
|
+
function emptyAutoCheckinState() {
|
|
2691
|
+
return {
|
|
2692
|
+
enabled: false,
|
|
2693
|
+
lastRunAt: null,
|
|
2694
|
+
lastResultAt: null,
|
|
2695
|
+
lastResult: null,
|
|
2696
|
+
lastMessage: null,
|
|
2697
|
+
lastAmount: null,
|
|
2698
|
+
runs: 0,
|
|
2699
|
+
claims: 0
|
|
2700
|
+
};
|
|
2701
|
+
}
|
|
2702
|
+
function createAutoCheckinScheduler(host) {
|
|
2703
|
+
let timer = null;
|
|
2704
|
+
let disposed = false;
|
|
2705
|
+
let running = false;
|
|
2706
|
+
let lastAttemptAt = 0;
|
|
2707
|
+
let wasEnabled = false;
|
|
2708
|
+
const state = () => host.state;
|
|
2709
|
+
async function tick() {
|
|
2710
|
+
if (disposed || running) return state();
|
|
2711
|
+
running = true;
|
|
2712
|
+
try {
|
|
2713
|
+
const settings = await readSettings();
|
|
2714
|
+
const enabled = settings.autoCheckin === true;
|
|
2715
|
+
host.state.enabled = enabled;
|
|
2716
|
+
if (!enabled) {
|
|
2717
|
+
wasEnabled = false;
|
|
2718
|
+
host.state.lastMessage = "\u81EA\u52A8\u7B7E\u5230\u5DF2\u5173\u95ED";
|
|
2719
|
+
return state();
|
|
2720
|
+
}
|
|
2721
|
+
const justEnabled = !wasEnabled;
|
|
2722
|
+
wasEnabled = true;
|
|
2723
|
+
const now = Date.now();
|
|
2724
|
+
if (!justEnabled && now - lastAttemptAt < CLAIM_INTERVAL_MS) return state();
|
|
2725
|
+
lastAttemptAt = now;
|
|
2726
|
+
host.state.runs += 1;
|
|
2727
|
+
const client = await host.getClient();
|
|
2728
|
+
if (client === null) {
|
|
2729
|
+
host.state.lastResult = "skip";
|
|
2730
|
+
host.state.lastMessage = "\u6865\u63A5\u672A\u5C31\u7EEA\uFF08\u51ED\u636E\u672A\u52A0\u8F7D\uFF09\uFF0C\u7A0D\u540E\u518D\u8BD5";
|
|
2731
|
+
return state();
|
|
2732
|
+
}
|
|
2733
|
+
const r = await claimCheckin(client);
|
|
2734
|
+
host.state.lastRunAt = Date.now();
|
|
2735
|
+
host.state.lastResultAt = Date.now();
|
|
2736
|
+
if (r.available === false) {
|
|
2737
|
+
host.state.lastResult = "skip";
|
|
2738
|
+
host.state.lastMessage = "\u798F\u5229\u5217\u8868\u91CC\u6CA1\u6709\u6BCF\u65E5\u7B7E\u5230\u6D3B\u52A8";
|
|
2739
|
+
} else if (r.claimed === true) {
|
|
2740
|
+
host.state.lastResult = "claimed";
|
|
2741
|
+
host.state.lastAmount = typeof r.amount === "number" ? r.amount : null;
|
|
2742
|
+
host.state.lastMessage = `\u5DF2\u81EA\u52A8\u7B7E\u5230\uFF0C+${r.amount ?? 100} \u79EF\u5206`;
|
|
2743
|
+
host.state.claims += 1;
|
|
2744
|
+
chatLog(`auto-checkin OK amount=${r.amount ?? "-"}`);
|
|
2745
|
+
} else {
|
|
2746
|
+
host.state.lastResult = "already";
|
|
2747
|
+
host.state.lastMessage = r.reason ?? "\u4ECA\u65E5\u65E0\u9700\u7B7E\u5230";
|
|
2748
|
+
}
|
|
2749
|
+
} catch (e) {
|
|
2750
|
+
host.state.lastRunAt = Date.now();
|
|
2751
|
+
host.state.lastResultAt = Date.now();
|
|
2752
|
+
host.state.lastResult = "error";
|
|
2753
|
+
host.state.lastMessage = String(e?.message ?? e).slice(0, 200);
|
|
2754
|
+
chatLog(`auto-checkin ERROR ${host.state.lastMessage}`);
|
|
2755
|
+
} finally {
|
|
2756
|
+
running = false;
|
|
2757
|
+
}
|
|
2758
|
+
return state();
|
|
2759
|
+
}
|
|
2760
|
+
return {
|
|
2761
|
+
tick,
|
|
2762
|
+
state,
|
|
2763
|
+
start() {
|
|
2764
|
+
if (timer !== null) return;
|
|
2765
|
+
timer = setInterval(() => {
|
|
2766
|
+
void tick().catch(() => {
|
|
2767
|
+
});
|
|
2768
|
+
}, TICK_MS);
|
|
2769
|
+
if (typeof timer.unref === "function") timer.unref();
|
|
2770
|
+
},
|
|
2771
|
+
dispose() {
|
|
2772
|
+
disposed = true;
|
|
2773
|
+
if (timer !== null) clearInterval(timer);
|
|
2774
|
+
timer = null;
|
|
2775
|
+
}
|
|
2776
|
+
};
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2591
2779
|
// src/index.ts
|
|
2592
2780
|
init_models();
|
|
2593
2781
|
|
|
@@ -2675,10 +2863,12 @@ var ALLOWED = /* @__PURE__ */ new Set([
|
|
|
2675
2863
|
"GET /diag/checkin",
|
|
2676
2864
|
"GET /diag/test",
|
|
2677
2865
|
"GET /v1/models",
|
|
2866
|
+
"GET /settings",
|
|
2678
2867
|
"POST /diag/checkin",
|
|
2679
2868
|
"POST /diag/checkin/all",
|
|
2680
2869
|
"POST /diag/credentials",
|
|
2681
|
-
"POST /diag/test"
|
|
2870
|
+
"POST /diag/test",
|
|
2871
|
+
"POST /settings"
|
|
2682
2872
|
]);
|
|
2683
2873
|
function jsonError(message, status) {
|
|
2684
2874
|
return Response.json({ error: { message } }, { status, headers: { "cache-control": "no-store" } });
|
|
@@ -2779,16 +2969,16 @@ function registerRemoteBridge(ctx, port = 8765, isReady) {
|
|
|
2779
2969
|
|
|
2780
2970
|
// src/index.ts
|
|
2781
2971
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync2 } from "node:fs";
|
|
2782
|
-
import { join as
|
|
2783
|
-
import { homedir as
|
|
2972
|
+
import { join as join6 } from "node:path";
|
|
2973
|
+
import { homedir as homedir5 } from "node:os";
|
|
2784
2974
|
var name = "dsh-connect-madao";
|
|
2785
2975
|
var inject = ["connection", "configEditor"];
|
|
2786
2976
|
var PROVIDER = "madao";
|
|
2787
2977
|
function diag(line) {
|
|
2788
|
-
const dir =
|
|
2978
|
+
const dir = join6(homedir5(), ".dsh-connect-madao");
|
|
2789
2979
|
try {
|
|
2790
2980
|
mkdirSync2(dir, { recursive: true });
|
|
2791
|
-
appendFileSync2(
|
|
2981
|
+
appendFileSync2(join6(dir, "host.log"), `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
2792
2982
|
`, "utf8");
|
|
2793
2983
|
} catch {
|
|
2794
2984
|
}
|
|
@@ -2814,6 +3004,10 @@ function apply(ctx, config = {}) {
|
|
|
2814
3004
|
ctx.effect(
|
|
2815
3005
|
() => async () => {
|
|
2816
3006
|
disposed = true;
|
|
3007
|
+
try {
|
|
3008
|
+
server?.ctx.autoCheckin?.dispose();
|
|
3009
|
+
} catch {
|
|
3010
|
+
}
|
|
2817
3011
|
const running = server;
|
|
2818
3012
|
server = void 0;
|
|
2819
3013
|
await running?.close().catch(() => {
|
|
@@ -2867,6 +3061,14 @@ function apply(ctx, config = {}) {
|
|
|
2867
3061
|
}
|
|
2868
3062
|
server = started;
|
|
2869
3063
|
diag(`bridge ready at ${server.url}/v1 (models=${models.length}, credentials: ${hint})`);
|
|
3064
|
+
const scheduler = createAutoCheckinScheduler({
|
|
3065
|
+
state: emptyAutoCheckinState(),
|
|
3066
|
+
getClient: () => borrowClient(server.ctx)
|
|
3067
|
+
});
|
|
3068
|
+
server.ctx.autoCheckin = scheduler;
|
|
3069
|
+
scheduler.start();
|
|
3070
|
+
void scheduler.tick().catch(() => {
|
|
3071
|
+
});
|
|
2870
3072
|
} catch (err) {
|
|
2871
3073
|
diag(`bridge failed to start: ${String(err?.stack ?? err)}`);
|
|
2872
3074
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "dsh-connect-madao",
|
|
3
3
|
"displayName": "DSH Connect 码道",
|
|
4
4
|
"description": "把华为云码道(CodeArts Agent)的模型接入 DeepSeek Harness:自签 SDK-HMAC-SHA256、P-256 密钥协商与 SM4-GCM 载荷加密,对外提供 OpenAI 兼容接口,并带设置面板与状态胶囊。",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.10.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|