dsh-unified-router 0.8.4 → 0.8.5

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.
@@ -30,6 +30,7 @@
30
30
  - 模型一律使用列表行,显示名称与 ID,支持搜索。普通目录分页,Raccoon 的免费与订阅目录各显示在自己的组里。可调模型使用共同的「参数」入口。保存成功或失败后保留当前编辑位置。
31
31
  - 渠道提供方开关和连接都使用相同的设置行。仅提供实际支持的操作。账号或 API Key 未配置时,从相关分区直达对应表单。
32
32
  - 每个分区的主操作放在标题右侧。页头「刷新」负责账号与额度,模型目录的刷新入口位于模型分区。
33
+ - 渠道网格下方、当前渠道工作区上方放置可折叠的「全局设置」,默认收起,切换渠道时保留展开状态。额度上报和智能选号只在此处编辑;全局区同时提供自动签到、自动领取奖励、自动完成任务和思考循环保护的默认值。支持这些功能的渠道用「跟随全局 / 单独开启 / 单独关闭」三选一;跟随时显示当前实际开关状态,已有覆盖不随全局改变。手动领取、执行和查询状态仍可独立操作。小浣熊模型合并仍属于本渠道。回归见 `test/automation-and-ux.test.mjs`。
33
34
 
34
35
  ---
35
36
 
@@ -93,7 +94,7 @@
93
94
 
94
95
  ### 3.4 智能选号模式
95
96
 
96
- - 「渠道」分区提供**全局四档单选**(`routingMode`,默认手动顺序;旧布尔开关 `preferExpiringQuota` 双向兼容:开启=临期优先):**手动**(账号列表顺序)、**免费优先**(先花每日额度与免费赠送,计费额度临期与否不参与)、**临期优先**(每日 → 赠送 → 7 天内到期,同档先到期先用)、**缓存优先**(同一模型沿用最近实际服务的前台账号,直到它用尽或受限才切换;按模型全局粘滞,重启后重新学习)。只有可参与自动选号的渠道显示入口:独立模式下 Raccoon、Qoder 中国版、TRAE,以及 AStudio、CodeArts;共用模式的账号池由原插件选择。
97
+ - 「全局设置」提供**四档单选**(`routingMode`,默认手动顺序;旧布尔开关 `preferExpiringQuota` 双向兼容:开启=临期优先):**手动**(账号列表顺序)、**免费优先**(先花每日额度与免费赠送,计费额度临期与否不参与)、**临期优先**(每日 → 赠送 → 7 天内到期,同档先到期先用)、**缓存优先**(同一模型沿用最近实际服务的前台账号,直到它用尽或受限才切换;按模型全局粘滞,重启后重新学习)。按宿主公布的选号支持范围显示,不取决于当前渠道;共用模式的账号池由原插件选择。
97
98
  - 所有模式只**重排已过滤候选**(限流/停用/黑名单过滤不变),不新增账号、不改写手动顺序、不触发上游查询;证据失效的额度不参与排名。缓存优先在池内生效。统一小浣熊的免费侧优先于粘滞(免费侧恢复可用时回到免费侧)。后台用途(会话标题等)不写粘滞记录。
98
99
 
99
100
  ---
@@ -78,6 +78,7 @@ function readInitialConfig(file, defaults) {
78
78
  routingMode: routingModeOf(saved.routingMode, saved.preferExpiringQuota === true ? 'expiring' : 'manual'),
79
79
  preferExpiringQuota: routingModeOf(saved.routingMode, saved.preferExpiringQuota === true ? 'expiring' : 'manual') === 'expiring',
80
80
  raccoonUnifiedModels: typeof saved.raccoonUnifiedModels === 'boolean' ? saved.raccoonUnifiedModels : base.raccoonUnifiedModels,
81
+ quotaIngest: typeof saved.quotaIngest === 'boolean' ? saved.quotaIngest : base.quotaIngest,
81
82
  providers,
82
83
  }
83
84
  } catch {
package/lib/client.js CHANGED
@@ -1279,6 +1279,7 @@ const number = value => typeof value === 'number' && Number.isFinite(value) ? va
1279
1279
  const initial = provider => ({ provider, accounts: [], models: [], balances: [], statuses: {}, selected: '', loadFailed: false,
1280
1280
  checkin: null,
1281
1281
  automation: null,
1282
+ globalSettingsNotice: '',
1282
1283
  login: null, pendingDelete: null, params: {}, plan: null, planStale: false, planError: false,
1283
1284
  // WorkBuddy 是自管多账号快照:accounts 逐账号、models 全局、loginUrl 属登录窗口。
1284
1285
  workbuddy: { accounts: [], models: [], loginUrl: '' }, workbuddyReady: false, workbuddyStale: false, workbuddyError: false, workbuddyLoginUrl: null,
@@ -2252,7 +2253,7 @@ function createRouterStore(call, provider = PROVIDERS[0].id) {
2252
2253
  ])
2253
2254
  /** 本次读取的结果是否由快照提供(决定要不要推进「最新读取时刻」水位)。 */
2254
2255
  const snapshotServed = new WeakSet()
2255
- const sharedFields = ['statuses', 'checkin', 'automation', ...snapshotProviders.flatMap(item => item.snapshot.keep ?? [])]
2256
+ const sharedFields = ['statuses', 'checkin', 'automation', 'globalSettingsNotice', ...snapshotProviders.flatMap(item => item.snapshot.keep ?? [])]
2256
2257
  let state = restoredRouterState(provider, persisted)
2257
2258
  let disposed = false, readController = null, balanceController = null,
2258
2259
  planController = null, planPollTimer = null, planPollGeneration = 0, planRevision = 0,
@@ -2838,22 +2839,27 @@ function createRouterStore(call, provider = PROVIDERS[0].id) {
2838
2839
  rememberChannel: target => cache.rememberChannel(target, state),
2839
2840
  }))),
2840
2841
  message(notice) { publish({ notice }) },
2841
- async setAutomationConfig(patch) {
2842
+ clearGlobalSettingsNotice() { publish({ globalSettingsNotice: '' }) },
2843
+ async setAutomationConfig(patch, { globalNotice = false } = {}) {
2842
2844
  if (disposed || pending.has('automation')) return false
2845
+ const noticeKey = globalNotice ? 'globalSettingsNotice' : 'notice'
2843
2846
  const controller = new AbortController()
2844
2847
  writes.add(controller)
2845
2848
  const release = pending.enter('automation')
2846
2849
  writeRevision++
2850
+ if (globalNotice) publish({ globalSettingsNotice: '' })
2847
2851
  try {
2848
2852
  const value = await request('automation.setConfig', patch, controller.signal)
2849
2853
  if (!disposed) {
2854
+ // 保存期间开始的读取也可能带着写入前的快照。
2855
+ writeRevision++
2850
2856
  const next = automationFrom(value)
2851
- publish({ ...(next ? { automation: next } : {}), notice: '自动化设置已保存。' })
2857
+ publish({ ...(next ? { automation: next } : {}), [noticeKey]: globalNotice ? '全局设置已保存。' : '自动化设置已保存。' })
2852
2858
  if (sync.hasSnapshots()) void sync.readHostSnapshots()
2853
2859
  }
2854
2860
  return true
2855
2861
  } catch {
2856
- if (!disposed) publish({ notice: '自动化设置保存失败。' })
2862
+ if (!disposed) publish({ [noticeKey]: globalNotice ? '全局设置保存失败,请重试。' : '自动化设置保存失败。' })
2857
2863
  return false
2858
2864
  } finally {
2859
2865
  writes.delete(controller)
@@ -3112,7 +3118,12 @@ const CLIENT_STYLES = `
3112
3118
  .eac-provider-dot[data-tone=success]{background:var(--eac-success)}
3113
3119
  .eac-provider-dot[data-tone=warn]{background:var(--eac-warn)}
3114
3120
 
3115
- /* ---------- 工作区 ---------- */
3121
+ /* ---------- 全局设置与工作区 ---------- */
3122
+ .eac-global-settings{min-width:0;border:1px solid var(--eac-divider);border-radius:var(--eac-r);background:var(--eac-subtle)}
3123
+ .eac-global-summary{padding:var(--eac-s2) var(--eac-s4);border-radius:var(--eac-r);font-size:var(--eac-fs);font-weight:620;cursor:pointer}
3124
+ .eac-global-summary:hover{background:var(--eac-hover)}
3125
+ .eac-global-body{display:flex;flex-direction:column;gap:var(--eac-s3);min-width:0;padding:var(--eac-s1) var(--eac-s4) var(--eac-s4)}
3126
+ .eac-global-body .eac-row-name{white-space:normal;overflow-wrap:anywhere}
3116
3127
  .eac-workspace{display:flex;flex-direction:column;min-width:0;padding:var(--eac-s3) var(--eac-s4) var(--eac-s5);border:1px solid var(--eac-divider);border-radius:var(--eac-r);background:var(--eac-subtle)}
3117
3128
  .eac-panels{display:flex;align-items:center;gap:2px;min-height:36px;border-bottom:1px solid var(--eac-divider)}
3118
3129
  .eac-panel-tab{align-self:stretch;display:inline-flex;align-items:center;gap:6px;margin:0 0 -1px;padding:6px 12px;border:0;border-bottom:2px solid transparent;border-radius:8px 8px 0 0;background:transparent;color:inherit;opacity:.68;cursor:pointer;font-size:var(--eac-fs);font-weight:500;white-space:nowrap;transition:opacity .14s ease,border-color .14s ease,background .14s ease}
@@ -3389,6 +3400,7 @@ html[data-dsh-go-island][data-dsh-go-island-form="panel"] .eac-quota-popover{pos
3389
3400
  }
3390
3401
  @container eac (max-width:640px){
3391
3402
  .eac-header{align-items:center}
3403
+ .eac-global-summary,.eac-global-body{padding-inline:var(--eac-s3)}
3392
3404
  .eac-workspace{padding:var(--eac-s2) var(--eac-s3) var(--eac-s4)}
3393
3405
  .eac-panels{gap:var(--eac-s4)}.eac-panel-body{padding:var(--eac-s3) 0 0}
3394
3406
  .eac-section-head{flex-direction:column}.eac-section-actions{justify-content:flex-start}.eac-group-actions{justify-content:flex-start}
@@ -3904,14 +3916,14 @@ function renderForm(form, ui, key, scope) {
3904
3916
  })
3905
3917
  }
3906
3918
 
3907
- /** 单选分段控件(智能选号模式):复用参数编辑器的 .eac-tier 外观与 aria-pressed。 */
3919
+ /** 单选分段控件:复用参数编辑器的 .eac-tier 外观与 aria-pressed。 */
3908
3920
  function renderOptionTiers({ options, value, name }, ui, disabled) {
3909
3921
  // 返回数组:Row 的 controls 按数组展开(单个元素没有 length 会被丢掉)。
3910
3922
  return [h('div', { className: 'eac-tier-row', role: 'group', 'aria-label': name },
3911
3923
  options.map(option => h('button', {
3912
- key: option.value, type: 'button', className: 'eac-tier',
3924
+ key: String(option.value), type: 'button', className: 'eac-tier',
3913
3925
  'aria-pressed': option.value === value, disabled,
3914
- onClick: () => ui.act(...option.call),
3926
+ onClick: () => { if (option.value !== value) ui.act(...option.call) },
3915
3927
  }, option.label)))]
3916
3928
  }
3917
3929
 
@@ -4119,6 +4131,24 @@ function ModelsPanel({ groups }, ui) {
4119
4131
  })
4120
4132
  }
4121
4133
 
4134
+ const CHANNEL_AUTOMATION_MODES = [
4135
+ { value: null, label: '跟随全局' },
4136
+ { value: true, label: '单独开启' },
4137
+ { value: false, label: '单独关闭' },
4138
+ ]
4139
+
4140
+ function channelAutomationRow(provider, config, { id, name, field, actions }) {
4141
+ const override = config?.providers?.[provider.id]?.[field]
4142
+ const value = config ? override ?? null : undefined
4143
+ return {
4144
+ id, name, value, actions, scope: 'automation', disabled: !config,
4145
+ meta: !config ? '正在读取设置…' : value === null ? `当前按全局${config[field] ? '开启' : '关闭'}` : undefined,
4146
+ options: CHANNEL_AUTOMATION_MODES.map(option => ({
4147
+ ...option, call: ['setAutomationConfig', { provider: provider.id, [field]: option.value }],
4148
+ })),
4149
+ }
4150
+ }
4151
+
4122
4152
  function automationRowsFor(provider, state) {
4123
4153
  const id = provider.id
4124
4154
  // `autoCheckin` 是显式覆盖位:签到(automation 任务)与「一键领取每日额度」
@@ -4131,42 +4161,13 @@ function automationRowsFor(provider, state) {
4131
4161
  const capabilities = state.automation?.tasks?.[id]?.capabilities
4132
4162
  const supportsRewards = capabilities?.claimRewards ?? (provider.caps?.onboarding === true && provider.caps?.completeTasks !== true || provider.caps?.claimRewards === true)
4133
4163
  const supportsTasks = capabilities?.completeTasks ?? (provider.caps?.completeTasks === true)
4134
- const overrides = state.automation?.config?.providers?.[id] ?? {}
4164
+ const config = state.automation?.config
4135
4165
  // 账号列表的位置由渠道自己说(`managed.js` / `workbuddy.js` 各提供 `accountsOf`)。
4136
4166
  const accounts = provider.pack ? state.accounts : (provider.accountsOf?.(state) ?? [])
4137
4167
  const eligible = accounts.some(account => account.enabled !== false && (provider.pack || account.signedIn))
4138
4168
  const query = mode => ({ label: '查询状态', call: ['queryAutomationTask', id, mode], disabled: !eligible, scope: taskScope(id, mode) })
4139
- const inherited = field => !state.automation ? '待读取' : typeof overrides[field] === 'boolean' ? '本渠道单独设置' : '跟随全局设置'
4140
4169
  const scope = 'automation'
4141
4170
  const rows = []
4142
- // 全局开关(只在一个渠道卡渲染,避免每张卡重复):向 subusage 推送额度。
4143
- // 默认关闭——接收端一次会被塞入多张卡,开与不开由用户决定。
4144
- if (provider.caps?.quotaIngestToggle === true) {
4145
- const enabled = state.automation?.config?.quotaIngest === true
4146
- rows.push({ id: 'quota-ingest', name: '向 subusage 推送额度', scope,
4147
- meta: enabled ? '按渠道分卡推送 · 与额度刷新同频(60 秒)' : '关闭 · 不向 subusage 推送',
4148
- value: enabled,
4149
- options: [
4150
- { value: false, label: '关' },
4151
- { value: true, label: '开' },
4152
- ].map(option => ({ ...option, call: ['setAutomationConfig', { quotaIngest: option.value }] })) })
4153
- }
4154
- if (state.automation?.quotaProviders?.includes(id)) {
4155
- // 智能选号模式(全局单选):分段控件代替旧的布尔开关。
4156
- // manual = 手动顺序;free = 免费额度优先;expiring = 临期优先(兼容旧开关);
4157
- // sticky = 缓存优先(同一账号用到额度用尽或受限才切换)。
4158
- const mode = state.automation.config?.routingMode ?? 'manual'
4159
- rows.push({ id: 'routing-mode', name: '智能选号模式', scope,
4160
- meta: { manual: '手动顺序(默认)· 按账号列表顺序', free: '免费额度优先 · 先用每日与赠送额度',
4161
- expiring: '临期额度优先 · 每日 → 赠送 → 7 天内到期', sticky: '缓存优先 · 同一账号用尽或受限才切换' }[mode],
4162
- value: mode,
4163
- options: [
4164
- { value: 'manual', label: '手动' },
4165
- { value: 'free', label: '免费优先' },
4166
- { value: 'expiring', label: '临期优先' },
4167
- { value: 'sticky', label: '缓存优先' },
4168
- ].map(option => ({ ...option, call: ['setAutomationConfig', { routingMode: option.value }] })) })
4169
- }
4170
4171
  // 默认输出上限(分渠道):只在上游没给输出规格时生效(目录 max_output 缺失/为 null
4171
4172
  // 的模型,如云知声 u2-med)。上游有真实规格就用上游值,这里只补缺。
4172
4173
  // 只有自带模型设置文件的三类渠道会消费这个值(API Key、自管、WorkBuddy);
@@ -4185,69 +4186,20 @@ function automationRowsFor(provider, state) {
4185
4186
  { value: 128_000, label: '128K' },
4186
4187
  { value: 256_000, label: '256K' },
4187
4188
  ].map(option => ({ ...option, call: ['setAutomationConfig', { provider: id, defaultMaxOutput: option.value || null }] })) })
4188
- const guardEnabled = automationEffective(state, id, 'cotLoopGuard')
4189
- rows.push({
4190
- id: 'cot-loop-guard', name: '思考循环保护', scope,
4191
- meta: inherited('cotLoopGuard'),
4192
- enabled: guardEnabled,
4193
- toggle: ['setAutomationConfig', { provider: id, cotLoopGuard: !guardEnabled }],
4194
- toggleLabel: `${provider.title} 思考循环保护`,
4195
- actions: typeof overrides.cotLoopGuard === 'boolean'
4196
- ? [{ label: '恢复跟随全局', call: ['setAutomationConfig', { provider: id, cotLoopGuard: null }] }] : undefined,
4197
- })
4198
- if (supportsCheckin) {
4199
- const enabled = automationEffective(state, id, 'autoCheckin')
4200
- rows.push({
4201
- id: 'auto-checkin', name: '自动每日签到', scope,
4202
- meta: inherited('autoCheckin'),
4203
- enabled,
4204
- toggle: ['setAutomationConfig', { provider: id, autoCheckin: !enabled }],
4205
- toggleLabel: `${provider.title} 自动每日签到`,
4206
- actions: [query('checkin'), typeof overrides.autoCheckin === 'boolean'
4207
- ? { label: '恢复跟随全局', call: ['setAutomationConfig', { provider: id, autoCheckin: null }] } : null],
4208
- })
4209
- }
4210
- if (supportsRewards) {
4211
- const enabled = automationEffective(state, id, 'autoClaimRewards')
4212
- rows.push({
4213
- id: 'auto-claim-rewards', name: '自动领取奖励', scope,
4214
- meta: inherited('autoClaimRewards'),
4215
- enabled,
4216
- toggle: ['setAutomationConfig', { provider: id, autoClaimRewards: !enabled }],
4217
- toggleLabel: `${provider.title} 自动领取奖励`,
4218
- actions: [
4219
- { label: '立即领取', call: ['runAutomationTask', id, 'claimRewards'], disabled: !eligible, scope: taskScope(id, 'claimRewards') },
4220
- query('claimRewards'),
4221
- typeof overrides.autoClaimRewards === 'boolean'
4222
- ? { label: '恢复跟随全局', call: ['setAutomationConfig', { provider: id, autoClaimRewards: null }] } : null,
4223
- ],
4224
- })
4225
- }
4226
- if (supportsTasks) {
4227
- const enabled = automationEffective(state, id, 'autoCompleteTasks')
4228
- rows.push({
4229
- id: 'auto-complete-tasks', name: '自动完成任务', scope,
4230
- meta: inherited('autoCompleteTasks'),
4231
- enabled,
4232
- toggle: ['setAutomationConfig', { provider: id, autoCompleteTasks: !enabled }],
4233
- toggleLabel: `${provider.title} 自动完成任务`,
4234
- actions: [
4235
- { label: '立即执行', call: ['runAutomationTask', id, 'completeTasks'], disabled: !eligible, scope: taskScope(id, 'completeTasks') },
4236
- query('completeTasks'),
4237
- typeof overrides.autoCompleteTasks === 'boolean'
4238
- ? { label: '恢复跟随全局', call: ['setAutomationConfig', { provider: id, autoCompleteTasks: null }] } : null,
4239
- ],
4240
- })
4241
- }
4189
+ const add = (id, name, field, actions) => rows.push(channelAutomationRow(provider, config, { id, name, field, actions }))
4190
+ const run = (mode, label) => ({ label, call: ['runAutomationTask', id, mode], disabled: !eligible, scope: taskScope(id, mode) })
4191
+ add('cot-loop-guard', '思考循环保护', 'cotLoopGuard')
4192
+ if (supportsCheckin) add('auto-checkin', '自动每日签到', 'autoCheckin', [query('checkin')])
4193
+ if (supportsRewards) add('auto-claim-rewards', '自动领取奖励', 'autoClaimRewards', [run('claimRewards', '立即领取'), query('claimRewards')])
4194
+ if (supportsTasks) add('auto-complete-tasks', '自动完成任务', 'autoCompleteTasks', [run('completeTasks', '立即执行'), query('completeTasks')])
4242
4195
  return rows
4243
4196
  }
4244
4197
 
4245
- function ChannelPanel(rows, ui, provider, state) {
4246
- const autoRows = provider ? automationRowsFor(provider, state) : []
4247
- const renderRows = list => ListBox({
4198
+ function renderSettingRows(list, ui, keyPrefix, defaultScope) {
4199
+ return ListBox({
4248
4200
  children: list.map(row => {
4249
- const key = `${ui.providerId}:channel:${row.id}`
4250
- const scope = row.scope || `channel:${ui.providerId}`
4201
+ const key = `${keyPrefix}:${row.id}`
4202
+ const scope = row.scope || defaultScope
4251
4203
  const rowDisabled = ui.loading || ui.isPending(scope)
4252
4204
  const expandable = !!(row.form || row.groups?.length)
4253
4205
  return Row({
@@ -4255,8 +4207,11 @@ function ChannelPanel(rows, ui, provider, state) {
4255
4207
  metric: row.metric ? Metric({ ...row.metric, label: row.name }) : undefined,
4256
4208
  switchControl: row.toggle ? Switch({ checked: row.enabled ?? false, disabled: rowDisabled || row.enabled === undefined,
4257
4209
  label: row.toggleLabel || row.name, onChange: () => ui.act(...row.toggle) }) : undefined,
4258
- controls: row.options ? renderOptionTiers(row, ui, rowDisabled)
4259
- : row.href ? [h('a', { className: 'eac-button', href: row.href, target: '_blank', rel: 'noopener noreferrer' }, '打开控制台')] : renderActions(row.actions, ui, scope),
4210
+ controls: [
4211
+ ...(row.options ? renderOptionTiers(row, ui, rowDisabled || row.disabled === true) : []),
4212
+ ...(row.href ? [h('a', { className: 'eac-button', href: row.href, target: '_blank', rel: 'noopener noreferrer' }, '打开控制台')] : []),
4213
+ ...renderActions(row.actions, ui, scope),
4214
+ ],
4260
4215
  moreLabel: expandable ? (row.moreLabel || '配置') : undefined, expanded: ui.more[key] === true,
4261
4216
  onToggle: () => ui.act('toggleMore', key),
4262
4217
  detail: expandable ? [
@@ -4266,6 +4221,11 @@ function ChannelPanel(rows, ui, provider, state) {
4266
4221
  })
4267
4222
  }),
4268
4223
  })
4224
+ }
4225
+
4226
+ function ChannelPanel(rows, ui, provider, state) {
4227
+ const autoRows = provider ? automationRowsFor(provider, state) : []
4228
+ const renderRows = list => renderSettingRows(list, ui, `${ui.providerId}:channel`, `channel:${ui.providerId}`)
4269
4229
  return Section({
4270
4230
  title: '渠道设置',
4271
4231
  children: [
@@ -4285,6 +4245,51 @@ function renderSettingsPanel(panel, provider, state, ui) {
4285
4245
  return ChannelPanel(provider.channel(state), ui, provider, state)
4286
4246
  }
4287
4247
 
4248
+ // ── src/client/global-settings.js ──
4249
+ const GLOBAL_AUTOMATION_OPTIONS = [
4250
+ ['autoCheckin', '自动每日签到'],
4251
+ ['autoClaimRewards', '自动领取奖励'],
4252
+ ['autoCompleteTasks', '自动完成任务'],
4253
+ ['cotLoopGuard', '思考循环保护'],
4254
+ ]
4255
+
4256
+ function GlobalSettingsPanel(state, ui, notice) {
4257
+ const { config, quotaProviders } = state.automation ?? {}
4258
+ const scope = 'automation'
4259
+ const save = patch => ['setAutomationConfig', patch, { globalNotice: true }]
4260
+ const rows = config ? [{
4261
+ id: 'quota-ingest', name: '向 subusage 推送额度',
4262
+ meta: '每 60 秒按渠道推送已采集的额度',
4263
+ enabled: config.quotaIngest, toggle: save({ quotaIngest: !config.quotaIngest }),
4264
+ }] : []
4265
+ if (config && quotaProviders?.length) rows.push({
4266
+ id: 'routing-mode', name: '智能选号模式', value: config.routingMode,
4267
+ meta: { manual: '按账号列表顺序', free: '先用每日与赠送额度',
4268
+ expiring: '每日 → 赠送 → 7 天内到期', sticky: '同一账号用尽或受限才切换' }[config.routingMode],
4269
+ options: [
4270
+ { value: 'manual', label: '手动' }, { value: 'free', label: '免费优先' },
4271
+ { value: 'expiring', label: '临期优先' }, { value: 'sticky', label: '缓存优先' },
4272
+ ].map(option => ({ ...option, call: save({ routingMode: option.value }) })),
4273
+ })
4274
+ const defaults = config ? GLOBAL_AUTOMATION_OPTIONS.map(([field, name]) => ({
4275
+ id: field, name, enabled: config[field], toggle: save({ [field]: !config[field] }),
4276
+ })) : []
4277
+ // 全局区依赖全局快照,不受当前渠道的加载状态影响。
4278
+ const globalUi = { ...ui, loading: false }
4279
+ const settingsList = list => renderSettingRows(list, globalUi, 'global', scope)
4280
+ return h('details', { className: 'eac-global-settings', 'data-section': 'global-settings' },
4281
+ h('summary', { className: 'eac-global-summary' }, '全局设置'),
4282
+ h('div', { className: 'eac-global-body', 'aria-busy': ui.isPending(scope) },
4283
+ notice,
4284
+ config ? settingsList(rows) : h('div', { className: 'eac-empty' },
4285
+ h('span', { role: 'status' }, '等待全局设置数据。'),
4286
+ button('重新读取', () => ui.act('readHostSnapshots'), false, { 'aria-label': '重新读取全局设置' })),
4287
+ config ? h('section', { className: 'eac-group', 'aria-labelledby': 'eac-automation-defaults' },
4288
+ h('h3', { id: 'eac-automation-defaults', className: 'eac-group-title' }, '自动化默认值'),
4289
+ h('p', { className: 'eac-summary' }, '适用于支持该功能且未单独设置的渠道。'),
4290
+ settingsList(defaults)) : null))
4291
+ }
4292
+
4288
4293
  // ── src/client/providers/pack.js ──
4289
4294
  // Channel-pack settings use the same view contract as managed accounts.
4290
4295
  // Optional actions, forms, quota details and model groups are plain data.
@@ -4950,8 +4955,6 @@ const raccoon = {
4950
4955
  familySide: 'free',
4951
4956
  quotaExtraResources: ['automation.status'],
4952
4957
  permanentPackageNames: ['奖励积分'],
4953
- // 全局「向 subusage 推送额度」开关只在本卡渲染(家族卡是设置页第一张)。
4954
- quotaIngestToggle: true,
4955
4958
  },
4956
4959
  }
4957
4960
 
@@ -6900,6 +6903,12 @@ const panelsFor = id => {
6900
6903
  return available ? SETTINGS_PANELS.filter(panel => available.includes(panel.id)) : SETTINGS_PANELS
6901
6904
  }
6902
6905
 
6906
+ function settingsNotice(text, dismiss) {
6907
+ return text ? h('div', { className: 'eac-notice', role: 'status', 'aria-live': 'polite' },
6908
+ h('p', null, text),
6909
+ h('button', { type: 'button', className: 'eac-notice-close', 'aria-label': '关闭提示', onClick: dismiss }, '×')) : null
6910
+ }
6911
+
6903
6912
  function Settings({ ctx }) {
6904
6913
  const storeRef = React.useRef(null)
6905
6914
  const [state, setState] = React.useState(() => restoredRouterState(rememberedProvider()))
@@ -6992,6 +7001,7 @@ function Settings({ ctx }) {
6992
7001
  h('span', { className: 'eac-provider-dot', 'data-tone': toneFor(value) }),
6993
7002
  value ? value.cardMeta ?? (value.closed ? '已关闭' : `${value.totalAccounts ?? value.accounts ?? '—'} 账号 · ${value.models ?? '—'} 模型`) : '待读取'))
6994
7003
  }))))),
7004
+ GlobalSettingsPanel(state, ui, settingsNotice(state.globalSettingsNotice, () => act('clearGlobalSettingsNotice'))),
6995
7005
  h('div', { className: 'eac-workspace', 'data-panel': panel, role: 'tabpanel', id: 'eac-provider-workspace', 'aria-labelledby': `eac-provider-${state.provider}` },
6996
7006
  h('header', { className: 'eac-header' },
6997
7007
  h('h2', { className: 'eac-title' }, provider.title),
@@ -7006,9 +7016,7 @@ function Settings({ ctx }) {
7006
7016
  onKeyDown: event => tabKeys(event, index, panels.map(value => value.id), setPanel),
7007
7017
  onClick: () => setPanel(item.id) }, item.label))),
7008
7018
  h('div', { className: 'eac-panel-body', role: 'tabpanel', id: `eac-panel-${panel}`, 'aria-labelledby': `eac-tab-${panel}` },
7009
- state.notice ? h('div', { className: 'eac-notice', role: 'status', 'aria-live': 'polite' },
7010
- h('p', null, state.notice),
7011
- h('button', { type: 'button', className: 'eac-notice-close', 'aria-label': '关闭提示', onClick: () => act('message', '') }, '×')) : null,
7019
+ settingsNotice(state.notice, () => act('message', '')),
7012
7020
  renderSettingsPanel(panel, provider, state, ui)))
7013
7021
  )
7014
7022
  }
@@ -424,7 +424,7 @@ export function updateSettingsSnapshots(snapshots, method, payload, value) {
424
424
  }
425
425
  if (AUTOMATION_METHODS.has(method)) {
426
426
  return Promise.all([
427
- snapshots.changed(settingsResourceKey('automation.status', 'automation')),
427
+ method !== 'automation.setConfig' && snapshots.changed(settingsResourceKey('automation.status', 'automation')),
428
428
  snapshots.changed(settingsResourceKey('checkin.status', 'daily')),
429
429
  ])
430
430
  }
@@ -101,13 +101,14 @@ export function createSettingsSnapshots(file, resources, { logger, interval = SN
101
101
  const current = instance + ':' + revision
102
102
  return { cursor: current, entries: cursor === current ? null : Object.fromEntries(entries) }
103
103
  },
104
- async changed(key, patch) {
104
+ async changed(key, patch, { create = false } = {}) {
105
105
  await ready
106
106
  if (lifetime.signal.aborted || !resources.has(key)) return
107
107
  if (jobs.has(key)) dirty.add(key)
108
108
  const old = entries.get(key)
109
- if (old?.value && patch) {
110
- publish(key, { ...old, value: resources.get(key).restore(patch(old.value)) })
109
+ if (patch && (old?.value || create)) {
110
+ publish(key, { ...(old?.value ? old : { at: Date.now(), stale: false }),
111
+ value: resources.get(key).restore(patch(old?.value)) })
111
112
  persist()
112
113
  }
113
114
  void collect(key)
package/lib/web-host.js CHANGED
@@ -637,6 +637,10 @@ ${String(error?.stack ?? error)}
637
637
  quotaIngest: config.quotaIngest === true,
638
638
  },
639
639
  allowedProviders: () => [...ALL_PROVIDER_IDS, ...managedIds],
640
+ // 在串行配置写入内同步快照,避免写 RPC 返回后读到旧配置;任务状态继续后台采集。
641
+ onChange: next => snapshots.changed(automationKey, previous => ({
642
+ ...previous, config: next, quotaProviders, unifiedModelProviders,
643
+ }), { create: true }),
640
644
  })
641
645
  const cotLoopGuard = installCotLoopGuard(host, {
642
646
  watch: config.cotLoopGuard,
@@ -719,7 +723,7 @@ ${String(error?.stack ?? error)}
719
723
  return { config: automationSettings.snapshot(), tasks: tasks.providers, quotaProviders, unifiedModelProviders }
720
724
  }
721
725
  if (method === 'automation.setConfig') {
722
- const updated = await automationSettings.update(payload)
726
+ await automationSettings.update(payload)
723
727
  // 打开「向 subusage 推送额度」后立即推一次,不等下一个采集周期。
724
728
  if (payload?.quotaIngest === true) void reportQuota()
725
729
  // 统一模型开关切换后:立即重拉两侧目录并广播(免费面合并目录、
@@ -737,7 +741,7 @@ ${String(error?.stack ?? error)}
737
741
  if (payload.autoClaimRewards === true || payload.autoCompleteTasks === true) void autoTasks.tick()
738
742
  }
739
743
  const tasks = await autoTasks.status()
740
- return { config: updated, tasks: tasks.providers, quotaProviders, unifiedModelProviders }
744
+ return { config: automationSettings.snapshot(), tasks: tasks.providers, quotaProviders, unifiedModelProviders }
741
745
  }
742
746
  if (method === 'automation.run' || method === 'automation.query') {
743
747
  const { mode, provider, accountId } = payload
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-unified-router",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "type": "module",
5
5
  "main": "lib/web-host.js",
6
6
  "license": "MIT",