dsh-codearts-dock 1.0.0 → 1.0.1

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/docs/DETAIL.md CHANGED
@@ -8,11 +8,10 @@ An unofficial third-party plugin, unaffiliated with Huawei and DeepSeek / Harnes
8
8
 
9
9
  - Native adapter for streaming text, reasoning, tool calls and model-supported image input.
10
10
  - Multiple accounts, import/export, manual switching and actionable health checks.
11
- - Composer credit chip, configurable low-balance alerts and backup account overview.
12
- - Model search, capability filters, multiplier sorting, drafts and configuration presets.
13
- - Up to 200 local request metadata records, with recording and clear controls.
11
+ - Composer credit chip and multi-account balance overview, retaining clearly marked last results when refreshes fail.
12
+ - Model search, pinned favorites, capability filters, multiplier sorting, drafts and configuration presets.
14
13
  - Configuration migration with mandatory password encryption when credentials are included, and a restore preview.
15
- - Optional daily check-in, disabled by default and attempted only while the plugin is running.
14
+ - Manual check-in for eligible accounts; availability and results depend on the upstream service.
16
15
 
17
16
  ## Get started
18
17
 
@@ -20,6 +19,6 @@ Install and enable the bundle, open Settings → CodeArts → Accounts, add your
20
19
 
21
20
  ## Data and costs
22
21
 
23
- Requests and authentication information are sent to the configured services. Local credentials and ordinary account exports are plaintext; prefer encrypted backups for migration. Balances, multipliers and local usage records are not official billing records.
22
+ Requests and authentication information are sent to the configured services. Local credentials and ordinary account exports are plaintext; prefer encrypted backups for migration. Balances and multipliers are not official billing records.
24
23
 
25
24
  [Documentation](https://github.com/Jensen0925/dsh-codearts-dock#readme) · [Disclaimer](https://github.com/Jensen0925/dsh-codearts-dock/blob/main/DISCLAIMER.md) · [Security](https://github.com/Jensen0925/dsh-codearts-dock/blob/main/SECURITY.md)
package/docs/DETAIL.zh.md CHANGED
@@ -8,11 +8,10 @@
8
8
 
9
9
  - 原生模型适配:流式文本、推理、工具调用,以及模型支持的图片输入。
10
10
  - 多账号管理、导入导出、手动切换和健康检查。
11
- - 输入框积分胶囊、自定义低余额提醒及备用账号概览。
12
- - 模型搜索、能力筛选、倍率排序、配置草稿和预设。
13
- - 本机最近 200 条请求元数据,可关闭记录并清空。
11
+ - 输入框积分胶囊及多账号余额概览,刷新失败时保留并标注上次结果。
12
+ - 模型搜索、常用置顶、能力筛选、倍率排序、配置草稿和预设。
14
13
  - 配置迁移;包含账号凭证时必须密码加密,恢复前预览。
15
- - 可选每日自动签到,默认关闭,仅在插件运行时尝试。
14
+ - 手动一键签到,领取结果以上游返回为准。
16
15
 
17
16
  ## 开始使用
18
17
 
@@ -20,6 +19,6 @@
20
19
 
21
20
  ## 数据与费用
22
21
 
23
- 请求内容及认证信息会发送给配置的服务;本机凭证以明文保存。普通账号导出包含密钥,换机优先使用加密备份。余额、倍率和本机用量不是官方账单,实际计费以上游为准。
22
+ 请求内容及认证信息会发送给配置的服务;本机凭证以明文保存。普通账号导出包含密钥,换机优先使用加密备份。余额和倍率不是官方账单,实际计费以上游为准。
24
23
 
25
24
  [完整文档](https://github.com/Jensen0925/dsh-codearts-dock#readme) · [免责声明](https://github.com/Jensen0925/dsh-codearts-dock/blob/main/DISCLAIMER.md) · [安全说明](https://github.com/Jensen0925/dsh-codearts-dock/blob/main/SECURITY.md)
package/locale/en.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "CodeArts Dock",
4
- "description": "Unofficial Huawei Cloud CodeArts model connector for DeepSeek Harness. Multi-account management, credit alerts, health checks, model presets, local usage metadata and encrypted configuration backups. Requires your own authorized account; upstream charges may apply.",
4
+ "description": "Unofficial Huawei Cloud CodeArts model connector for DeepSeek Harness. Multi-account management, credit overview, health checks, model presets and encrypted configuration backups. Requires your own authorized account; upstream charges may apply.",
5
5
  "detail": "docs/DETAIL.md"
6
6
  }
7
7
  }
package/locale/zh.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "CodeArts Dock · 码道驿站",
4
- "description": "为 DeepSeek Harness 接入华为云码道模型的第三方非官方插件。支持多账号、积分与余额提醒、账号健康检查、模型搜索与配置预设、本机用量记录及加密配置备份。需要自己的有效账号与权限,调用可能产生费用。",
4
+ "description": "为 DeepSeek Harness 接入华为云码道模型的第三方非官方插件。支持多账号、积分概览、账号健康检查、模型搜索与配置预设、及加密配置备份。需要自己的有效账号与权限,调用可能产生费用。",
5
5
  "detail": "docs/DETAIL.zh.md"
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "dsh-codearts-dock",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "displayName": "CodeArts Dock · 码道驿站",
5
- "description": "为 DeepSeek Harness 接入华为云码道模型的非官方插件,提供多账号、积分提醒、模型预设、本机用量与加密配置备份。",
5
+ "description": "为 DeepSeek Harness 接入华为云码道模型的非官方插件,提供多账号、积分概览、模型预设与加密配置备份。",
6
6
  "type": "module",
7
7
  "main": "src/index.js",
8
8
  "icon": "icons/dsh-connect-codearts-128.png",
package/src/adapter.js CHANGED
@@ -209,33 +209,6 @@ class CodeArtsAdapter extends LlmAdapter {
209
209
  * @returns {AsyncGenerator<any>} Host stream chunks.
210
210
  */
211
211
  async *stream(options) {
212
- const startedAt = Date.now()
213
- const generation = this.deps.usage?.generation()
214
- let status = 'aborted'
215
- let inputTokens = null, outputTokens = null
216
- try {
217
- for await (const chunk of this.#stream(options)) {
218
- if (chunk.type === 'usage') {
219
- inputTokens = chunk.usage?.inputTokens ?? inputTokens
220
- outputTokens = chunk.usage?.outputTokens ?? outputTokens
221
- }
222
- if (chunk.type === 'finish') status = chunk.reason?.kind === 'error' ? 'error' : chunk.reason?.kind === 'aborted' ? 'aborted' : 'success'
223
- yield chunk
224
- }
225
- } catch (error) {
226
- status = error?.name === 'AbortError' ? 'aborted' : 'error'
227
- throw error
228
- } finally {
229
- try {
230
- await this.deps.usage?.record({
231
- at: startedAt, model: this.deps.catalog.resolveId?.(options.model) ?? options.model,
232
- durationMs: Date.now() - startedAt, inputTokens, outputTokens, status,
233
- }, generation)
234
- } catch { /* A local history write must never fail a model request. */ }
235
- }
236
- }
237
-
238
- async *#stream(options) {
239
212
  const model = this.#effective(this.deps.catalog.find(options.model))
240
213
  const client = await this.#client()
241
214
 
package/src/checkin.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * (`POST /v1/ops/claim`) that spends the day's one entitlement, so everything
8
8
  * here is built around never doing it twice and never doing it unasked.
9
9
  *
10
- * Auto check-in is therefore opt-in, off by default, and guarded three ways:
10
+ * Manual check-in is guarded three ways:
11
11
  *
12
12
  * 1. it re-reads campaign state immediately before claiming, so an account
13
13
  * already claimed today by any client is skipped, not retried;
@@ -154,7 +154,7 @@ export async function readCheckin(client, options = {}) {
154
154
  * @param {object} options claim options.
155
155
  * @param {string} options.accountId whose record to update.
156
156
  * @param {Date} [options.now] clock, for tests.
157
- * @param {boolean} [options.force] claim even when the local record says it was attempted today (never used by auto mode).
157
+ * @param {boolean} [options.force] claim even when the local record says it was attempted today (never used by the batch action).
158
158
  * @returns {Promise<{claimed: boolean, amount?: number, reason?: string}>} the outcome.
159
159
  */
160
160
  export async function claimDaily(client, options) {
@@ -205,7 +205,7 @@ async function recordAttempt(state, accountId, now, claimed, amount, error) {
205
205
  }
206
206
 
207
207
  /**
208
- * Run auto check-in across the accounts that should be checked.
208
+ * Claim once across the selected accounts after an explicit user action.
209
209
  *
210
210
  * Sequential on purpose: the gateway counts concurrent sessions with a small
211
211
  * ceiling, and a burst of parallel claims on one account is the fastest way to
@@ -216,7 +216,7 @@ async function recordAttempt(state, accountId, now, claimed, amount, error) {
216
216
  * @param {Date} [options.now] clock, for tests.
217
217
  * @returns {Promise<{attempted: number, claimed: number, skipped: number, failures: Array<{id: string, reason: string}>}>} the summary.
218
218
  */
219
- export async function runAutoCheckin({ targets, now = new Date() }) {
219
+ export async function claimAllDaily({ targets, now = new Date() }) {
220
220
  const summary = { attempted: 0, claimed: 0, skipped: 0, failures: [] }
221
221
  const state = readCheckinState()
222
222
 
@@ -244,7 +244,7 @@ export async function runAutoCheckin({ targets, now = new Date() }) {
244
244
  }
245
245
 
246
246
  /**
247
- * What auto check-in has done today, for the settings page.
247
+ * What check-in has done today, for the settings page.
248
248
  * @param {Array<{id: string, label: string}>} accounts the pool, in display order.
249
249
  * @param {Date} [now] clock, for tests.
250
250
  * @returns {{total: number, done: number, pending: number, lastError?: string}} today's progress.
package/src/features.js CHANGED
@@ -9,8 +9,10 @@ export async function applyPreferences(deps, patch) {
9
9
  await persistPreferences(validated)
10
10
  Object.assign(deps.settings, validated)
11
11
  if ('refreshIntervalMs' in validated) deps.rescheduleCatalog?.()
12
- deps.catalog.configure({ enabledIds: deps.settings.enabledModelIds, overrides: deps.settings.modelOverrides })
13
- deps.ctx.emit('llm/models-updated', 'codearts')
12
+ if ('enabledModelIds' in validated || 'modelOverrides' in validated) {
13
+ deps.catalog.configure({ enabledIds: deps.settings.enabledModelIds, overrides: deps.settings.modelOverrides })
14
+ deps.ctx.emit('llm/models-updated', 'codearts')
15
+ }
14
16
  return { ok: true, preferences: portablePreferences(deps.settings) }
15
17
  }
16
18
  export function registerFeatureRoutes(route, deps, readBody) {
@@ -25,8 +27,6 @@ export function registerFeatureRoutes(route, deps, readBody) {
25
27
  const body = await readBody(req)
26
28
  return serial(() => applyPreferences(deps, body))
27
29
  })
28
- route('/usage', () => deps.usage.list())
29
- route('/usage/clear', async () => { await deps.usage.clear(); return deps.usage.list() })
30
30
  route('/presets', async (req) => {
31
31
  const body = await readBody(req)
32
32
  return serial(async () => {
package/src/health.js CHANGED
@@ -13,6 +13,3 @@ export function accountHealth({ error, credit, checkedAt = Date.now() } = {}) {
13
13
  } else if (Number.isFinite(credit?.remain)) state = credit.remain <= 0 ? 'insufficient' : 'available'
14
14
  return { state, checkedAt, action: state === 'credentials' ? 'credentials' : state === 'insufficient' ? 'switch' : 'recheck' }
15
15
  }
16
- export function isLowBalance(credit, settings) {
17
- return settings.lowBalanceEnabled !== false && Number.isFinite(credit?.remain) && credit.remain < settings.lowBalanceThreshold
18
- }
package/src/index.js CHANGED
@@ -56,15 +56,14 @@ import {
56
56
  claimDaily,
57
57
  readCheckin,
58
58
  readCheckinState,
59
- runAutoCheckin,
59
+ claimAllDaily,
60
60
  todaySummary,
61
61
  } from './checkin.js'
62
62
  import { getSts } from './sts.js'
63
63
  import { CONFIG_DIR } from './paths.js'
64
- import { FEATURE_DEFAULTS, InputError, readPreferences, persistPreferences, validatePreferences } from './preferences.js'
64
+ import { FEATURE_DEFAULTS, InputError, readPreferences, validatePreferences } from './preferences.js'
65
65
  import { registerFeatureRoutes, applyPreferences } from './features.js'
66
- import { createUsageStore } from './usage.js'
67
- import { accountHealth, isLowBalance } from './health.js'
66
+ import { accountHealth } from './health.js'
68
67
 
69
68
  /** Plugin name; also the client module id. */
70
69
  export const name = 'dsh-connect-codearts'
@@ -93,11 +92,8 @@ export const Config = z.object({
93
92
  refreshIntervalMs: z.number().description('模型目录与积分的刷新间隔(毫秒)'),
94
93
  composerChip: z.boolean().default(true).description('在输入框旁显示积分'),
95
94
  registerProvider: z.boolean().default(true).description('是否注册码道这个 provider 路由'),
96
- autoCheckin: z.boolean().default(false).description('每天自动签到一次'),
97
- lowBalanceEnabled: z.boolean().default(true).description('低余额提醒'),
98
- lowBalanceThreshold: z.number().default(500).description('低余额提醒阈值'),
99
- usageEnabled: z.boolean().default(true).description('在本机保留最近 200 条请求元数据'),
100
95
  enabledModelIds: z.array(z.string()).description('启用的模型;留空表示全部'),
96
+ favoriteModelIds: z.array(z.string()).default([]).description('模型设置页中置顶的常用模型'),
101
97
  modelOverrides: z.dict(z.object({
102
98
  images: z.boolean(),
103
99
  allowOff: z.boolean(),
@@ -128,8 +124,6 @@ export const DEFAULTS = {
128
124
  ...FEATURE_DEFAULTS,
129
125
  /** Turn the provider off without uninstalling the bundle. */
130
126
  enabled: true,
131
- /** Claim the daily bonus in the background, once a day. Off by default. */
132
- autoCheckin: false,
133
127
  /**
134
128
  * The user's model selection.
135
129
  *
@@ -177,7 +171,6 @@ export function apply(ctx, config = {}) {
177
171
  const settings = { ...DEFAULTS, ...config }
178
172
  // Restore before timers and adapters start; preferences never include credentials.
179
173
  try { Object.assign(settings, validatePreferences(readPreferences())) } catch {}
180
- const usage = createUsageStore({ enabled: () => settings.usageEnabled !== false })
181
174
  const healthChecks = new Map()
182
175
  const healthCache = new Map()
183
176
  let rescheduleCatalog = () => {}
@@ -215,7 +208,6 @@ export function apply(ctx, config = {}) {
215
208
  const adapter = createCodeArtsAdapter({
216
209
  credentials,
217
210
  catalog,
218
- usage,
219
211
  gateway: () => settings.gateway,
220
212
  attachments: () => ctx.get('attachments'),
221
213
  log: logger,
@@ -290,43 +282,6 @@ export function apply(ctx, config = {}) {
290
282
  // serves its settings page, which is where the user fixes the credential.
291
283
  void refresh()
292
284
 
293
- // Auto check-in runs from the Host, not the page: the settings panel is not
294
- // open at the hour a daily claim usually becomes available, and a timer in the
295
- // browser would simply never fire. It reads the saved switch each time, so
296
- // turning it off takes effect without a restart.
297
- ctx.effect(() => {
298
- const sweep = async () => {
299
- if (settings.autoCheckin !== true) return
300
- try {
301
- const store = readStore()
302
- const targets = []
303
- for (const account of store.accounts) {
304
- try {
305
- targets.push({
306
- id: account.id,
307
- client: new MadaoClient({ credentials: await tripleOf(account), gateway: settings.gateway }),
308
- })
309
- } catch {
310
- // An account whose key cannot be exchanged is skipped.
311
- }
312
- }
313
- if (targets.length > 0) {
314
- await runAutoCheckin({ targets })
315
- healthCache.clear()
316
- healthChecks.clear()
317
- }
318
- } catch (error) {
319
- logger(`自动签到失败:${error?.message ?? error}`)
320
- }
321
- }
322
- // Hourly is enough for a once-a-day entitlement, and the day guard makes a
323
- // frequent timer harmless: it can skip, never double-claim.
324
- const timer = setInterval(() => void sweep(), 60 * 60 * 1000)
325
- timer.unref?.()
326
- void sweep()
327
- return () => clearInterval(timer)
328
- }, 'codearts: auto check-in')
329
-
330
285
  ctx.effect(() => {
331
286
  let timer
332
287
  let disposed = false
@@ -362,7 +317,7 @@ export function apply(ctx, config = {}) {
362
317
  )
363
318
  }
364
319
 
365
- const deps = { credentials, catalog, client, refresh, logger, settings, ctx, settingsNs, usage, healthChecks, healthCache, rescheduleCatalog: () => rescheduleCatalog(), invalidateAccounts: () => { healthCache.clear(); healthChecks.clear(); tripleCache.clear() } }
320
+ const deps = { credentials, catalog, client, refresh, logger, settings, ctx, settingsNs, healthChecks, healthCache, rescheduleCatalog: () => rescheduleCatalog(), invalidateAccounts: () => { healthCache.clear(); healthChecks.clear(); tripleCache.clear() } }
366
321
 
367
322
  registerFeatureRoutes(route, deps, readJsonBody)
368
323
 
@@ -391,7 +346,7 @@ export function apply(ctx, config = {}) {
391
346
  route('/models/select', (req) => handleModelSelection(req, deps))
392
347
  route('/checkin', () => handleCheckinStatus(deps))
393
348
  route('/checkin/claim', (req) => handleCheckinClaim(req, deps))
394
- route('/checkin/auto', (req) => handleAutoCheckin(req, deps))
349
+ route('/checkin/claim-all', (req) => handleCheckinClaimAll(req, deps))
395
350
  })
396
351
 
397
352
  // Release the renewal timer when the plugin unloads.
@@ -453,9 +408,6 @@ async function buildStatus(deps) {
453
408
  settingsPath: [],
454
409
  },
455
410
  settings: {
456
- lowBalanceEnabled: deps.settings.lowBalanceEnabled,
457
- lowBalanceThreshold: deps.settings.lowBalanceThreshold,
458
- usageEnabled: deps.settings.usageEnabled,
459
411
  composerChip: deps.settings.composerChip !== false,
460
412
  refreshIntervalMs: deps.settings.refreshIntervalMs ?? DEFAULT_REFRESH_MS,
461
413
  gateway: deps.settings.gateway ?? null,
@@ -479,6 +431,7 @@ async function buildModels(deps) {
479
431
  enabledIds: selectionIsDefault ? null : deps.catalog.visible().map((model) => model.id),
480
432
  total: all.length,
481
433
  presets: deps.settings.modelPresets,
434
+ favoriteModelIds: deps.settings.favoriteModelIds ?? [],
482
435
  models: all.map((model) => ({
483
436
  enabled: deps.catalog.isEnabled(model.id),
484
437
  overrides: overrides[model.id] ?? null,
@@ -515,9 +468,9 @@ async function buildAccount(deps) {
515
468
  temporary: resolved.source === 'codearts',
516
469
  expiresAt: resolved.expiresAtMs ?? null,
517
470
  credit,
471
+ creditCheckedAt: credit ? Date.now() : null,
472
+ creditIdentity: createHash('sha256').update(JSON.stringify([resolved.source, deps.credentials.accountId ?? identity.userId ?? resolved.key.ak, deps.settings.gateway ?? ''])).digest('hex'),
518
473
  roles,
519
- lowBalance: isLowBalance(credit, deps.settings),
520
- lowBalanceThreshold: deps.settings.lowBalanceThreshold,
521
474
  composerChip: deps.settings.composerChip !== false,
522
475
  health: accountHealth({ credit }),
523
476
  }
@@ -565,12 +518,15 @@ async function inspectAccount(account, deps, force = false) {
565
518
  if (existing?.signature === signature) return existing.promise
566
519
  const operation = (async () => {
567
520
  if (force) tripleCache.delete(account.id)
568
- const entry = { ...publicAccount(account, readStore()), credit: null, checkin: null, error: null }
521
+ const entry = { ...publicAccount(account, readStore()), credit: null, creditCheckedAt: null, creditIdentity: signature, checkin: null, error: null }
569
522
  let failure
570
523
  try {
571
524
  const client = new MadaoClient({ credentials: await tripleOf(account), gateway: deps.settings.gateway })
572
525
  const credit = await readCredit(client, { strict: true })
573
- if (credit) entry.credit = { remain: credit.remain, total: credit.total, plan: credit.plan ?? null, expiring: credit.expiringTotal ?? 0 }
526
+ if (credit) {
527
+ entry.credit = { remain: credit.remain, total: credit.total, plan: credit.plan ?? null, expiring: credit.expiringTotal ?? 0 }
528
+ entry.creditCheckedAt = Date.now()
529
+ }
574
530
  const checkin = await readCheckin(client, { now: new Date(), state: readCheckinState(), accountId: account.id })
575
531
  entry.checkin = { available: checkin.available, claimable: checkin.claimable, claimedToday: checkin.claimedToday, amount: checkin.amount, title: checkin.title, reason: checkin.reason ?? null }
576
532
  const identity = parseIdentity(tripleCache.get(account.id)?.securityToken)
@@ -583,7 +539,6 @@ async function inspectAccount(account, deps, force = false) {
583
539
  entry.error = message(error)
584
540
  }
585
541
  entry.health = accountHealth({ error: failure, credit: entry.credit })
586
- entry.lowBalance = isLowBalance(entry.credit, deps.settings)
587
542
  const current = readStore().accounts.find((item) => item.id === account.id)
588
543
  if (current?.sk === account.sk && deps.healthChecks.get(account.id)?.promise === operation) deps.healthCache.set(account.id, entry)
589
544
  return entry
@@ -599,14 +554,11 @@ async function handleAccounts(deps) {
599
554
  for (const account of store.accounts) {
600
555
  const cached = deps.healthCache.get(account.id)
601
556
  const entry = cached && Date.now() - cached.health.checkedAt < 60000 ? { ...cached, ...publicAccount(account, store) } : await inspectAccount(account, deps)
602
- accounts.push({ ...entry, lowBalance: isLowBalance(entry.credit, deps.settings) })
557
+ accounts.push(entry)
603
558
  }
604
559
  return {
605
560
  ok: true, version: STORE_VERSION, activeId: store.activeId, accounts,
606
561
  today: todaySummary(accounts.map(({ id, label }) => ({ id, label })), new Date()),
607
- autoCheckin: deps.settings.autoCheckin === true,
608
- lowBalanceEnabled: deps.settings.lowBalanceEnabled !== false,
609
- lowBalanceThreshold: deps.settings.lowBalanceThreshold,
610
562
  }
611
563
  }
612
564
  async function handleAccountCheck(req, deps) {
@@ -809,7 +761,6 @@ async function handleCheckinStatus(deps) {
809
761
  ok: true,
810
762
  accounts,
811
763
  today: todaySummary(accounts, now),
812
- autoCheckin: deps.settings.autoCheckin === true,
813
764
  }
814
765
  }
815
766
 
@@ -831,28 +782,9 @@ async function handleCheckinClaim(req, deps) {
831
782
  }
832
783
  }
833
784
 
834
- /**
835
- * Run auto check-in now.
836
- *
837
- * `enabled` reflects the saved switch; turning it on is a separate, explicit
838
- * action, and this handler only runs the sweep. It never becomes a timer here —
839
- * the timer is the plugin's, so a page that is closed still checks in.
840
- */
841
- async function handleAutoCheckin(req, deps) {
842
- const body = await readJsonBody(req)
843
- deps.healthCache.clear()
844
- deps.healthChecks.clear()
845
- // `enabled` changes the standing preference. The one-off button sends
846
- // `now: true` instead, so pressing it never opts a user into daily
847
- // automation — an action and a preference are different things.
848
- const oneOff = body.now === true
849
- if (!oneOff && typeof body.enabled === 'boolean' && body.enabled !== deps.settings.autoCheckin) {
850
- deps.settings.autoCheckin = body.enabled
851
- // Remember the choice across restarts without editing the profile patch.
852
- await persistAutoCheckin(body.enabled)
853
- }
854
- if (!oneOff && body.enabled === false) return { ok: true, enabled: false, summary: null }
855
-
785
+ /** Claim the daily bonus for the pool, only on an explicit click. */
786
+ async function handleCheckinClaimAll(req, deps) {
787
+ await readJsonBody(req)
856
788
  const store = readStore()
857
789
  const targets = []
858
790
  for (const account of store.accounts) {
@@ -865,21 +797,10 @@ async function handleAutoCheckin(req, deps) {
865
797
  // An account whose key cannot be exchanged is skipped, not fatal.
866
798
  }
867
799
  }
868
- const summary = await runAutoCheckin({ targets })
800
+ const summary = await claimAllDaily({ targets })
869
801
  deps.healthCache.clear()
870
802
  deps.healthChecks.clear()
871
- return { ok: true, enabled: deps.settings.autoCheckin === true, summary }
872
- }
873
-
874
- /**
875
- * Persist a preference beside the account store.
876
- *
877
- * One writer for every switch: the preferences file is small and shared, and a
878
- * second writer would eventually read-modify-write over the first's key.
879
- */
880
- /** Persist the auto check-in switch. */
881
- async function persistAutoCheckin(enabled) {
882
- await persistPreferences({ autoCheckin: enabled })
803
+ return { ok: true, summary }
883
804
  }
884
805
 
885
806
  async function handleTest(deps) {
@@ -1012,7 +933,7 @@ async function handleRoute(req, res, handler) {
1012
933
 
1013
934
  /** Routes that change state and therefore accept POST only. */
1014
935
  const MUTATING_PATHS = new Set([
1015
- '/preferences/save', '/presets', '/usage/clear', '/accounts/check',
936
+ '/preferences/save', '/presets', '/accounts/check',
1016
937
  '/backup/export', '/backup/preview', '/backup/restore',
1017
938
  '/models/select',
1018
939
  '/save',
@@ -1024,7 +945,7 @@ const MUTATING_PATHS = new Set([
1024
945
  '/accounts/activate',
1025
946
  '/accounts/rename',
1026
947
  '/checkin/claim',
1027
- '/checkin/auto',
948
+ '/checkin/claim-all',
1028
949
  ])
1029
950
 
1030
951
  /** The exact sub-path of a plugin route, or null when it is not one. */
@@ -6,7 +6,7 @@ import { randomUUID } from 'node:crypto'
6
6
  import { CONFIG_DIR } from './paths.js'
7
7
 
8
8
  export class InputError extends Error {}
9
- export const FEATURE_DEFAULTS = Object.freeze({ lowBalanceEnabled: true, lowBalanceThreshold: 500, usageEnabled: true, modelPresets: [] })
9
+ export const FEATURE_DEFAULTS = Object.freeze({ modelPresets: [], favoriteModelIds: [] })
10
10
  const plain = (value) => value !== null && typeof value === 'object' && !Array.isArray(value)
11
11
  const fail = (message) => { throw new InputError(message) }
12
12
  const safeId = (id) => typeof id === 'string' && id.length > 0 && id.length <= 200 && !['__proto__', 'constructor', 'prototype'].includes(id)
@@ -36,15 +36,13 @@ export function validateSelection(value) {
36
36
  export function validatePreferences(input) {
37
37
  if (!plain(input)) fail('偏好设置格式不正确')
38
38
  const out = {}
39
- for (const key of ['autoCheckin', 'composerChip', 'lowBalanceEnabled', 'usageEnabled']) {
40
- if (key in input) {
41
- if (typeof input[key] !== 'boolean') fail(`${key} 必须为布尔值`)
42
- out[key] = input[key]
43
- }
39
+ if ('composerChip' in input) {
40
+ if (typeof input.composerChip !== 'boolean') fail('composerChip 必须为布尔值')
41
+ out.composerChip = input.composerChip
44
42
  }
45
- if ('lowBalanceThreshold' in input) {
46
- if (!Number.isFinite(input.lowBalanceThreshold) || input.lowBalanceThreshold < 0 || input.lowBalanceThreshold > 1e9) fail('余额阈值必须在 0 到 10 亿之间')
47
- out.lowBalanceThreshold = input.lowBalanceThreshold
43
+ if ('favoriteModelIds' in input) {
44
+ if (!Array.isArray(input.favoriteModelIds) || input.favoriteModelIds.length > 500 || !input.favoriteModelIds.every(safeId)) fail('常用模型列表格式不正确')
45
+ out.favoriteModelIds = [...new Set(input.favoriteModelIds)]
48
46
  }
49
47
  if ('refreshIntervalMs' in input) {
50
48
  if (!Number.isInteger(input.refreshIntervalMs) || input.refreshIntervalMs < 60000 || input.refreshIntervalMs > 86400000) fail('刷新间隔必须在 1 分钟到 24 小时之间')
@@ -81,9 +79,8 @@ export function persistPreferences(patch) {
81
79
  }
82
80
  export function portablePreferences(settings) {
83
81
  return validatePreferences({
84
- autoCheckin: settings.autoCheckin === true, composerChip: settings.composerChip !== false,
85
- lowBalanceEnabled: settings.lowBalanceEnabled !== false, lowBalanceThreshold: settings.lowBalanceThreshold ?? 500,
86
- usageEnabled: settings.usageEnabled !== false, modelPresets: settings.modelPresets ?? [],
82
+ composerChip: settings.composerChip !== false,
83
+ modelPresets: settings.modelPresets ?? [], favoriteModelIds: settings.favoriteModelIds ?? [],
87
84
  enabledModelIds: settings.enabledModelIds ?? null, modelOverrides: settings.modelOverrides ?? {},
88
85
  refreshIntervalMs: Math.max(60000, Math.min(86400000, Number(settings.refreshIntervalMs) || 300000)),
89
86
  })
@@ -244,6 +244,28 @@ await check('the today summary counts only claimed accounts', async () => {
244
244
  assert.equal(summary.pending, 1)
245
245
  })
246
246
 
247
+ await check('manual batch claims each eligible account once and continues after a failure', async () => {
248
+ const first = fakeGateway()
249
+ const second = fakeGateway()
250
+ const now = new Date('2026-11-18T10:00:00+08:00')
251
+ const targets = [
252
+ { id: 'batch-first', client: first.client },
253
+ { id: 'batch-error', client: { getJson: async () => { throw new Error('offline mock error') } } },
254
+ { id: 'batch-second', client: second.client },
255
+ ]
256
+ const result = await checkin.claimAllDaily({ targets, now })
257
+ assert.equal(result.claimed, 2)
258
+ assert.equal(result.failures.length, 1)
259
+ assert.equal(result.failures[0].id, 'batch-error')
260
+ assert.equal(first.state.claims, 1)
261
+ assert.equal(second.state.claims, 1)
262
+ const retry = await checkin.claimAllDaily({ targets: [targets[0], targets[2]], now })
263
+ assert.equal(retry.skipped, 2)
264
+ assert.equal(retry.claimed, 0)
265
+ assert.equal(first.state.claims, 1)
266
+ assert.equal(second.state.claims, 1)
267
+ })
268
+
247
269
  await check('the day key follows the local calendar, not UTC', () => {
248
270
  // 23:30 in +08:00 is still the 18th locally even though UTC has rolled over.
249
271
  assert.equal(checkin.todayKey(new Date('2026-11-18T23:30:00+08:00')), '2026-11-18')