dsh-volcengine-provider 0.2.15 → 0.2.17

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/lib/client.js CHANGED
@@ -1,5 +1,45 @@
1
1
  window.__ModuleLoader__.load({id:'dsh-volcengine-provider',factory:(require)=>{
2
2
  'use strict';
3
+ // 图片生成的 Host / Client 共享契约;本文件必须保持浏览器安全,不引入 Node 模块。
4
+ const IMAGE_MODEL_OPTIONS = [
5
+ { id: 'doubao-seedream-5-0-pro', label: 'Doubao Seedream 5.0 Pro' },
6
+ { id: 'doubao-seedream-5.5', label: 'Doubao Seedream 5.5' },
7
+ { id: 'doubao-seedream-5.0-flash', label: 'Doubao Seedream 5.0 Flash' }
8
+ ];
9
+ const SUPPORTED_IMAGE_MODELS = IMAGE_MODEL_OPTIONS.map(option => option.id);
10
+ const DEFAULT_IMAGE_MODEL = SUPPORTED_IMAGE_MODELS[0];
11
+ const MEDIA_TOOL_KEYS = ['imageTool'];
12
+
13
+ function defaultMediaState() {
14
+ return { riskAcknowledged: false, imageTool: false, imageModel: DEFAULT_IMAGE_MODEL };
15
+ }
16
+
17
+ function normalizeMediaState(value) {
18
+ const base = defaultMediaState();
19
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return base;
20
+ for (const key of ['riskAcknowledged', ...MEDIA_TOOL_KEYS]) {
21
+ if (value[key] !== undefined && typeof value[key] !== 'boolean') throw new Error('媒体工具开关必须是布尔值');
22
+ if (typeof value[key] === 'boolean') base[key] = value[key];
23
+ }
24
+ if (value.imageModel !== undefined) {
25
+ if (typeof value.imageModel !== 'string' || !SUPPORTED_IMAGE_MODELS.includes(value.imageModel)) {
26
+ throw new Error(`默认图片模型必须是 ${SUPPORTED_IMAGE_MODELS.join(' / ')} 之一`);
27
+ }
28
+ base.imageModel = value.imageModel;
29
+ }
30
+ // 旧版 videoTool 字段在读取时丢弃;撤销风险确认会关闭图片工具。
31
+ if (!base.riskAcknowledged) for (const key of MEDIA_TOOL_KEYS) base[key] = false;
32
+ return base;
33
+ }
34
+
35
+ function mediaToolEnabled(media, key) {
36
+ return media?.riskAcknowledged === true && media?.[key] === true;
37
+ }
38
+
39
+ function assertMediaEnabled(enabled, toolName) {
40
+ if (!enabled()) throw new Error(`${toolName} 未启用:请先在 设置 → 火山方舟 Provider → 图片生成 中开启图片工具`);
41
+ }
42
+
3
43
  const PLUGIN_NAME = 'dsh-volcengine-provider';
4
44
  function wireCodec(type, parse) {
5
45
  return { mode: 'strict', typeSymbol: `${PLUGIN_NAME}#${type}`, schema: { parse }, create: () => ({ parse }) };
@@ -21,11 +61,355 @@ const arkRemote = {
21
61
  }]
22
62
  };
23
63
 
64
+ // 图片工具卡片的数据解析;不访问 DOM、网络或 Node 模块。
65
+ const IMAGE_FILE_PATH = '/plugins/dsh-volcengine-provider/image/file';
66
+ const IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif']);
67
+
68
+ function isRecord(value) {
69
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
70
+ }
71
+
72
+ function mediaViewProps(raw) {
73
+ const owner = isRecord(raw?.owner) ? raw.owner : {};
74
+ return { ...raw, ...owner, block: owner.block ?? raw?.block };
75
+ }
76
+
77
+ function isSettledMediaBlock(props) {
78
+ if (props?.phase === 'result') return true;
79
+ if (props?.phase === 'preparing' || props?.phase === 'start') return false;
80
+ return isRecord(props?.block) && 'kind' in props.block;
81
+ }
82
+
83
+ function argsOf(block) {
84
+ if (!isRecord(block)) return {};
85
+ let args = isRecord(block.call) ? block.call.args : block.args;
86
+ if (typeof args === 'function') {
87
+ try { args = args(); } catch { args = undefined; }
88
+ }
89
+ if (isRecord(args) && typeof args.read === 'function') {
90
+ try { args = args.read(); } catch { args = undefined; }
91
+ }
92
+ if (isRecord(args)) return args;
93
+ const raw = isRecord(block.call) ? block.call.argsRaw : block.argsRaw;
94
+ if (typeof raw !== 'string' || raw === '') return {};
95
+ try { const parsed = JSON.parse(raw); return isRecord(parsed) ? parsed : {}; }
96
+ catch { return {}; }
97
+ }
98
+
99
+ function promptOf(block) {
100
+ const prompt = argsOf(block).prompt;
101
+ return typeof prompt === 'string' ? prompt.trim() : '';
102
+ }
103
+
104
+ function textOf(block) {
105
+ if (!isRecord(block) || !Array.isArray(block.content)) return '';
106
+ return block.content.filter(part => isRecord(part) && part.type === 'text' && typeof part.text === 'string' && part.text.trim())
107
+ .map(part => part.text.trim()).join('\n\n');
108
+ }
109
+
110
+ function normalizedImage(part) {
111
+ const value = part?.attachment;
112
+ if (!isRecord(value) || typeof value.attachmentId !== 'string' || !IMAGE_TYPES.has(value.mediaType)) return undefined;
113
+ return {
114
+ attachmentId: value.attachmentId, mediaType: value.mediaType,
115
+ bytes: Number(value.bytes ?? 0), width: Number(value.width ?? 0), height: Number(value.height ?? 0),
116
+ name: typeof value.name === 'string' && value.name ? value.name : `图片.${value.mediaType === 'image/jpeg' ? 'jpg' : value.mediaType.slice(6)}`
117
+ };
118
+ }
119
+
120
+ function originalItem(value) {
121
+ if (!isRecord(value) || !IMAGE_TYPES.has(value.mediaType)) return undefined;
122
+ const ref = value.attachment;
123
+ if (!isRecord(ref) || typeof ref.attachmentId !== 'string') return undefined;
124
+ const bytes = Number(ref.bytes);
125
+ if (!Number.isSafeInteger(bytes) || bytes <= 0) return undefined;
126
+ return {
127
+ kind: 'original', id: ref.attachmentId, mediaType: value.mediaType, bytes,
128
+ width: Number(value.width ?? 0), height: Number(value.height ?? 0),
129
+ name: typeof ref.name === 'string' && ref.name ? ref.name : `图片.${value.mediaType === 'image/jpeg' ? 'jpg' : 'png'}`,
130
+ attachment: { attachmentId: ref.attachmentId, name: typeof ref.name === 'string' && ref.name ? ref.name : 'image', bytes }
131
+ };
132
+ }
133
+
134
+ function imageFileUrl(item, download = false) {
135
+ if (item?.kind !== 'original') return '';
136
+ const query = new URLSearchParams({
137
+ attachmentId: item.attachment.attachmentId,
138
+ name: item.attachment.name,
139
+ bytes: String(item.attachment.bytes),
140
+ mediaType: item.mediaType,
141
+ ...(download ? { download: '1' } : {})
142
+ });
143
+ return `${IMAGE_FILE_PATH}?${query}`;
144
+ }
145
+
146
+ function mediaItems(block) {
147
+ const meta = isRecord(block?.meta) ? block.meta : {};
148
+ const originalValues = Array.isArray(meta.originals) ? meta.originals : [];
149
+ const content = Array.isArray(block?.content) ? block.content : [];
150
+ const normalizedParts = content.filter(part => isRecord(part) && part.type === 'image');
151
+ if (originalValues.length) {
152
+ const items = [];
153
+ const seen = new Set();
154
+ const count = Math.max(originalValues.length, normalizedParts.length);
155
+ for (let index = 0; index < count; index++) {
156
+ const original = originalItem(originalValues[index]);
157
+ const fallback = normalizedImage(normalizedParts[index]);
158
+ const item = original ?? (fallback ? {
159
+ kind: 'normalized', id: fallback.attachmentId, name: fallback.name, mediaType: fallback.mediaType,
160
+ bytes: fallback.bytes, width: fallback.width, height: fallback.height, attachment: fallback
161
+ } : undefined);
162
+ if (!item || seen.has(item.id)) continue;
163
+ seen.add(item.id);
164
+ items.push(item);
165
+ }
166
+ return items;
167
+ }
168
+ if (!content.length) return [];
169
+ const seen = new Set();
170
+ const images = [];
171
+ for (const part of content) {
172
+ if (!isRecord(part) || part.type !== 'image') continue;
173
+ const ref = normalizedImage(part);
174
+ if (!ref || seen.has(ref.attachmentId)) continue;
175
+ seen.add(ref.attachmentId);
176
+ images.push({
177
+ kind: 'normalized', id: ref.attachmentId, name: ref.name, mediaType: ref.mediaType,
178
+ bytes: ref.bytes, width: ref.width, height: ref.height, attachment: ref
179
+ });
180
+ }
181
+ return images;
182
+ }
183
+
184
+ function mediaFallbackCount(block) {
185
+ const originals = isRecord(block?.meta) && Array.isArray(block.meta.originals) ? block.meta.originals : [];
186
+ return originals.filter(value => originalItem(value) === undefined).length;
187
+ }
188
+
189
+ function mediaModel(block) {
190
+ return isRecord(block?.meta) && typeof block.meta.model === 'string' ? block.meta.model : '';
191
+ }
192
+
193
+ function formatBytes(bytes) {
194
+ if (!Number.isFinite(bytes) || bytes <= 0) return '大小未知';
195
+ if (bytes < 1000) return `${bytes} B`;
196
+ if (bytes < 1000000) return `${(bytes / 1000).toFixed(bytes < 10000 ? 1 : 0)} KB`;
197
+ return `${(bytes / 1000000).toFixed(bytes < 10000000 ? 1 : 0)} MB`;
198
+ }
199
+
200
+ function imageDimensions(item) {
201
+ return item.width > 0 && item.height > 0 ? `${item.width}×${item.height} · ` : '';
202
+ }
203
+
204
+ function triggerMediaDownload(url, name) {
205
+ const anchor = document.createElement('a');
206
+ anchor.href = url;
207
+ anchor.download = name;
208
+ anchor.rel = 'noopener';
209
+ document.body.append(anchor);
210
+ try { anchor.click(); } finally { anchor.remove(); }
211
+ }
212
+
213
+ // 图片大图查看器:原生 dialog、Esc 关闭、缩放与滚动查看。
214
+ function MediaLightbox({ viewer, onClose }) {
215
+ const dialog = react.useRef(null);
216
+ const viewport = react.useRef(null);
217
+ const [zoom, setZoom] = react.useState(1);
218
+ react.useEffect(() => {
219
+ const node = dialog.current;
220
+ if (!node) return undefined;
221
+ if (typeof node.showModal === 'function' && !node.open) node.showModal();
222
+ const cancel = event => { event.preventDefault(); onClose(); };
223
+ node.addEventListener('cancel', cancel);
224
+ return () => {
225
+ node.removeEventListener('cancel', cancel);
226
+ if (node.open) node.close();
227
+ };
228
+ }, [onClose]);
229
+ react.useEffect(() => {
230
+ if (zoom !== 1 || !viewport.current) return;
231
+ viewport.current.scrollLeft = 0;
232
+ viewport.current.scrollTop = 0;
233
+ }, [zoom]);
234
+ return h('dialog', { ref: dialog, className: 'vcp-media-lightbox', 'aria-label': `查看大图:${viewer.label}`, onClose },
235
+ h('div', { className: 'vcp-media-lightbox-toolbar' },
236
+ h('button', { type: 'button', 'aria-disabled': zoom === 1, onClick: () => { if (zoom > 1) setZoom(value => Math.max(1, value - 0.5)); }, 'aria-label': '缩小' }, '−'),
237
+ h('span', { role: 'status' }, `${Math.round(zoom * 100)}%`),
238
+ h('button', { type: 'button', 'aria-disabled': zoom === 4, onClick: () => { if (zoom < 4) setZoom(value => Math.min(4, value + 0.5)); }, 'aria-label': '放大' }, '+'),
239
+ h('button', { type: 'button', 'aria-disabled': zoom === 1, onClick: () => { if (zoom > 1) setZoom(1); } }, '重置'),
240
+ h('a', { className: 'vcp-media-action', href: viewer.src, download: viewer.downloadName ?? viewer.label }, '下载'),
241
+ h('button', { type: 'button', className: 'vcp-media-lightbox-close', onClick: onClose, 'aria-label': '关闭大图' }, '×')),
242
+ h('div', { ref: viewport, className: 'vcp-media-lightbox-viewport' },
243
+ h('div', { style: { width: `${zoom * 100}%`, height: `${zoom * 100}%` } },
244
+ h('img', { src: viewer.src, alt: viewer.label, draggable: false }))));
245
+ }
246
+
247
+ // volc_imagine 的会话图片渲染壳;数据解析与大图组件分别在同域模块中。
248
+ const MEDIA_STYLES = `
249
+ .vcp-media-card{display:grid;gap:12px;width:100%;max-width:720px;min-width:0;box-sizing:border-box;padding:14px;border:1px solid var(--dsw-alias-border-l2,var(--dsw-alias-border-l4));border-radius:12px;background:var(--dsw-alias-bg-module-platform,var(--dsw-alias-bg-layer-1));color:var(--dsw-alias-label-primary);font:inherit}
250
+ .vcp-media-card *{box-sizing:border-box}.vcp-media-card :focus-visible,.vcp-media-lightbox :focus-visible{outline:2px solid var(--dsw-alias-brand-primary,Highlight);outline-offset:2px}
251
+ .vcp-media-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;flex-wrap:wrap}.vcp-media-heading{display:grid;gap:3px;min-width:0}.vcp-media-title{font-size:14px;font-weight:650}.vcp-media-summary,.vcp-media-caption,.vcp-media-detail{display:flex;gap:6px;flex-wrap:wrap;min-width:0;font-size:12px;line-height:1.55;color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere}
252
+ .vcp-media-status{display:inline-flex;align-items:center;gap:5px;padding:2px 8px;border:1px solid var(--dsw-alias-border-l2,var(--dsw-alias-border-l4));border-radius:999px;background:var(--dsw-alias-bg-base,var(--dsw-alias-bg-layer-2));font-size:11px;color:var(--dsw-alias-label-secondary)}.vcp-media-status[data-tone=success]{color:var(--dsw-alias-state-success-primary)}.vcp-media-status[data-tone=error]{color:var(--dsw-alias-state-error-primary)}
253
+ .vcp-media-gallery{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,240px),1fr));gap:10px;min-width:0}.vcp-media-item{display:grid;gap:6px;min-width:0}.vcp-media-preview{display:grid;place-items:center;width:100%;min-height:160px;padding:0;overflow:hidden;border:1px solid var(--dsw-alias-border-l2,var(--dsw-alias-border-l4));border-radius:10px;background:var(--dsw-alias-bg-base,var(--dsw-alias-bg-layer-2));color:var(--dsw-alias-label-secondary);cursor:zoom-in;font:inherit}.vcp-media-preview:disabled{cursor:wait}.vcp-media-preview img{display:block;width:100%;height:auto;max-height:420px;object-fit:contain}
254
+ .vcp-media-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap}.vcp-media-action{display:inline-flex;align-items:center;justify-content:center;min-height:32px;padding:5px 11px;border:1px solid var(--dsw-alias-border-l2,var(--dsw-alias-border-l3));border-radius:7px;background:var(--dsw-alias-bg-base,var(--dsw-alias-bg-layer-2));color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;text-decoration:none;cursor:pointer}.vcp-media-action:hover:not(:disabled){border-color:var(--dsw-alias-brand-primary)}.vcp-media-action:disabled{opacity:.55;cursor:not-allowed}.vcp-media-action[data-primary=true]{background:var(--dsw-alias-button-primary-fill,var(--dsw-alias-brand-primary));color:var(--dsw-alias-label-primary-foreground)}
255
+ .vcp-media-kind{padding:1px 6px;border:1px solid var(--dsw-alias-border-l2,var(--dsw-alias-border-l4));border-radius:999px;color:var(--dsw-alias-label-primary);font-size:10px}
256
+ .vcp-media-progress{width:100%;height:5px}.vcp-media-text{margin:0;max-height:180px;overflow:auto;white-space:pre-wrap;overflow-wrap:anywhere;font:inherit;font-size:12px;line-height:1.6}.vcp-media-details{border-top:1px solid var(--dsw-alias-border-l2,var(--dsw-alias-border-l4));padding-top:8px}.vcp-media-details>summary{cursor:pointer;color:var(--dsw-alias-label-secondary);font-size:12px}.vcp-media-details-body{display:grid;gap:10px;padding-top:10px}.vcp-media-detail{display:grid;gap:4px}.vcp-media-detail strong{font-size:12px;color:var(--dsw-alias-label-primary)}.vcp-media-id{font-family:var(--dsw-font-mono,ui-monospace,monospace);font-size:11px;overflow-wrap:anywhere}
257
+ .vcp-media-lightbox{padding:0;border:0;border-radius:12px;background:var(--dsw-alias-bg-base,var(--dsw-alias-bg-layer-1));color:var(--dsw-alias-label-primary);max-width:96vw;max-height:94vh;overflow:hidden}.vcp-media-lightbox::backdrop{background:var(--dsw-alias-backdrop,rgba(0,0,0,.72))}.vcp-media-lightbox-toolbar{position:absolute;top:8px;left:8px;right:8px;z-index:1;display:flex;align-items:center;gap:6px}.vcp-media-lightbox-toolbar button{min-width:32px;height:32px;padding:0 8px;border:1px solid var(--dsw-alias-border-l2);border-radius:7px;background:var(--dsw-alias-bg-module-platform,var(--dsw-alias-bg-layer-1));color:inherit;cursor:pointer}.vcp-media-lightbox-close{margin-left:auto}.vcp-media-lightbox-viewport{width:min(94vw,1200px);height:min(88vh,800px);overflow:auto}.vcp-media-lightbox-viewport img{display:block;width:100%;height:100%;object-fit:contain}
258
+ @media(max-width:420px){.vcp-media-card{padding:10px;gap:10px}.vcp-media-gallery{grid-template-columns:1fr}.vcp-media-preview{min-height:120px}}
259
+ @media(prefers-reduced-motion:reduce){.vcp-media-card *{scroll-behavior:auto!important;transition:none!important}}
260
+ `;
261
+
262
+ function installMediaStyles() {
263
+ if (typeof document === 'undefined' || !document.head || !document.createElement) return () => {};
264
+ const element = document.createElement('style');
265
+ element.dataset.volcengineMedia = '';
266
+ element.textContent = MEDIA_STYLES;
267
+ document.head.append(element);
268
+ let active = true;
269
+ return () => { if (active) { active = false; element.remove(); } };
270
+ }
271
+
272
+ function useMediaUrlLoader(props) {
273
+ const urls = react.useRef(new Map());
274
+ const pending = react.useRef(new Map());
275
+ const disposed = react.useRef(false);
276
+ react.useEffect(() => {
277
+ disposed.current = false;
278
+ return () => {
279
+ disposed.current = true;
280
+ for (const url of urls.current.values()) URL.revokeObjectURL(url);
281
+ urls.current.clear();
282
+ };
283
+ }, []);
284
+ return react.useCallback(async item => {
285
+ if (item.kind === 'original') return imageFileUrl(item);
286
+ if (typeof props.loadImage === 'function') return props.loadImage(item.attachment);
287
+ const sessionId = props.sessionId;
288
+ const binding = typeof sessionId === 'string' ? props.sessions?.binding?.(sessionId) : undefined;
289
+ if (!binding?.session?.readAttachment) throw new Error('当前会话无法读取图片附件');
290
+ const key = `${sessionId}\0${item.id}`;
291
+ if (urls.current.has(key)) return urls.current.get(key);
292
+ if (pending.current.has(key)) return pending.current.get(key);
293
+ const request = (async () => {
294
+ const result = await binding.session.readAttachment(item.id);
295
+ if (result?.ok !== true || result.value?.attachment?.attachmentId !== item.id) throw new Error('图片附件读取失败');
296
+ if (disposed.current) throw new Error('图片视图已卸载');
297
+ const bytes = result.value.data.slice().buffer;
298
+ const url = URL.createObjectURL(new Blob([bytes], { type: result.value.attachment.mediaType }));
299
+ urls.current.set(key, url);
300
+ return url;
301
+ })().finally(() => pending.current.delete(key));
302
+ pending.current.set(key, request);
303
+ return request;
304
+ }, [props.loadImage, props.sessionId, props.sessions]);
305
+ }
306
+
307
+ function MediaPreview({ item, load, onOpen }) {
308
+ const [state, setState] = react.useState({ src: '', error: false, retry: 0 });
309
+ react.useEffect(() => {
310
+ let live = true;
311
+ setState(previous => ({ ...previous, src: '', error: false }));
312
+ load(item).then(src => { if (live) setState(previous => ({ ...previous, src })); })
313
+ .catch(() => { if (live) setState(previous => ({ ...previous, error: true })); });
314
+ return () => { live = false; };
315
+ }, [item.id, load, state.retry]);
316
+ if (state.error) return h('button', { type: 'button', className: 'vcp-media-preview', onClick: () => setState(previous => ({ ...previous, error: false, retry: previous.retry + 1 })) }, '图片加载失败,点击重试');
317
+ if (!state.src) return h('div', { className: 'vcp-media-preview', role: 'status' }, '正在加载图片…');
318
+ return h('button', { type: 'button', className: 'vcp-media-preview', title: '查看大图', 'aria-label': `查看大图:${item.name}`, onClick: () => onOpen({ src: state.src, label: item.name, downloadName: item.name }) },
319
+ h('img', { src: state.src, alt: item.name, loading: 'lazy', onError: () => setState(previous => ({ ...previous, error: true })) }));
320
+ }
321
+
322
+ function MediaAction({ label, onClick, primary = false }) {
323
+ const [state, setState] = react.useState('idle');
324
+ const alive = react.useRef(true);
325
+ react.useEffect(() => { alive.current = true; return () => { alive.current = false; }; }, []);
326
+ return h('button', {
327
+ type: 'button', className: 'vcp-media-action', 'data-primary': primary || undefined,
328
+ disabled: state === 'pending', 'aria-busy': state === 'pending',
329
+ onClick: () => {
330
+ if (state === 'pending') return;
331
+ setState('pending');
332
+ Promise.resolve().then(onClick).then(() => { if (alive.current) setState('idle'); })
333
+ .catch(() => { if (alive.current) setState('failed'); });
334
+ }
335
+ }, state === 'pending' ? '处理中…' : state === 'failed' ? '操作失败,重试' : label);
336
+ }
337
+
338
+ function MediaDetails({ block, items }) {
339
+ const prompt = promptOf(block);
340
+ const text = textOf(block);
341
+ const model = mediaModel(block);
342
+ return h('details', { className: 'vcp-media-details' },
343
+ h('summary', null, '提示词与技术信息'),
344
+ h('div', { className: 'vcp-media-details-body' },
345
+ prompt ? h('section', { className: 'vcp-media-detail' }, h('strong', null, '提示词'), h('pre', { className: 'vcp-media-text', tabIndex: 0 }, prompt)) : null,
346
+ model ? h('div', { className: 'vcp-media-detail' }, h('strong', null, '模型'), h('span', null, model)) : null,
347
+ items.map(item => h('div', { key: item.id, className: 'vcp-media-detail' },
348
+ h('strong', null, item.kind === 'original' ? '原始文件附件' : '会话图片附件'),
349
+ h('span', null, `${item.name} · ${imageDimensions(item)}${item.mediaType} · ${formatBytes(item.bytes)}`),
350
+ h('span', { className: 'vcp-media-id' }, `attachmentId: ${item.id}`))),
351
+ text ? h('section', { className: 'vcp-media-detail' }, h('strong', null, '工具结果'), h('pre', { className: 'vcp-media-text', tabIndex: 0 }, text)) : null));
352
+ }
353
+
354
+ function VolcImagineToolView(rawProps) {
355
+ const props = mediaViewProps(rawProps);
356
+ const block = props.block;
357
+ const settled = isSettledMediaBlock(props);
358
+ const failed = settled && block?.isError === true;
359
+ const items = settled ? mediaItems(block) : [];
360
+ const fallbackCount = settled ? mediaFallbackCount(block) : 0;
361
+ const prompt = promptOf(block);
362
+ const load = useMediaUrlLoader(props);
363
+ const [viewer, setViewer] = react.useState(null);
364
+ const [copied, setCopied] = react.useState(false);
365
+ const closeViewer = react.useCallback(() => setViewer(null), []);
366
+ react.useEffect(() => {
367
+ if (!copied) return undefined;
368
+ const timer = setTimeout(() => setCopied(false), 2000);
369
+ return () => clearTimeout(timer);
370
+ }, [copied]);
371
+ const tone = failed ? 'error' : !settled ? 'busy' : items.length ? 'success' : 'neutral';
372
+ const title = failed ? '图片生成失败' : settled ? 'Seedream 图片' : prompt ? '正在生成图片…' : '正在接收生图参数…';
373
+ const status = failed ? '失败' : settled ? items.length ? '已完成' : '无图片' : '生成中';
374
+ return h('div', { className: 'vcp-media-root', style: { display: 'contents' } },
375
+ h('section', { className: 'vcp-media-card', 'data-testid': 'volc-imagine-card', 'aria-label': title },
376
+ h('header', { className: 'vcp-media-head' },
377
+ h('div', { className: 'vcp-media-heading' }, h('strong', { className: 'vcp-media-title' }, title),
378
+ h('div', { className: 'vcp-media-summary' }, h('span', null, '火山方舟'), mediaModel(block) ? h('span', null, mediaModel(block)) : null,
379
+ items.length ? h('span', null, items[0].kind === 'original' ? '原始文件' : '会话预览') : null)),
380
+ h('span', { className: 'vcp-media-status', 'data-tone': tone, role: 'status' }, status)),
381
+ !settled ? h('div', null, h('progress', { className: 'vcp-media-progress', 'aria-label': '图片生成进度' })) : null,
382
+ !settled && prompt ? h('pre', { className: 'vcp-media-text', tabIndex: 0 }, prompt) : null,
383
+ settled && failed ? h('pre', { className: 'vcp-media-text', role: 'alert', tabIndex: 0 }, textOf(block) || '图片工具调用失败。') : null,
384
+ fallbackCount ? h('p', { className: 'vcp-media-caption', role: 'status' }, `${fallbackCount} 张原图不可用,已回退到会话预览。`) : null,
385
+ settled && !failed && items.length ? h('div', { className: 'vcp-media-gallery' }, items.map(item => h('div', { key: item.id, className: 'vcp-media-item' },
386
+ h(MediaPreview, { item, load, onOpen: setViewer }),
387
+ h('div', { className: 'vcp-media-caption' }, h('span', { className: 'vcp-media-kind' }, item.kind === 'original' ? '原图' : '预览(规范化)'), h('span', null, `${imageDimensions(item)}${item.mediaType} · ${formatBytes(item.bytes)}`))))) : null,
388
+ settled && !failed && !items.length ? h('pre', { className: 'vcp-media-text', tabIndex: 0 }, textOf(block) || '工具未返回可显示的图片。') : null,
389
+ settled && !failed && items.length ? h('div', { className: 'vcp-media-actions' },
390
+ items.map(item => h(MediaAction, { key: `view:${item.id}`, label: items.length === 1 ? '查看大图' : `查看 ${item.name}`, onClick: async () => setViewer({ src: await load(item), label: item.name, downloadName: item.name }) })),
391
+ items.map(item => item.kind === 'original'
392
+ ? h('a', { key: `download:${item.id}`, className: 'vcp-media-action', 'data-primary': true, href: imageFileUrl(item, true), download: item.attachment.name }, items.length === 1 ? '下载原图' : `下载 ${item.name}`)
393
+ : h(MediaAction, { key: `download:${item.id}`, primary: true, label: '下载预览图', onClick: async () => triggerMediaDownload(await load(item), item.name) })),
394
+ prompt ? h(MediaAction, { label: copied ? '已复制提示词' : '复制提示词', onClick: async () => { await navigator.clipboard.writeText(prompt); setCopied(true); } }) : null) : null,
395
+ settled ? h(MediaDetails, { block, items }) : null),
396
+ viewer ? h(MediaLightbox, { viewer, onClose: closeViewer }) : null);
397
+ }
398
+
399
+ function applyVolcMediaViews(ctx) {
400
+ ctx.effect(installMediaStyles, 'dsh-volcengine-provider: 图片卡片样式');
401
+ ctx.slots.inject('tool.call.toolview', () => ctx.slots.register({
402
+ name: 'tool.call.toolview', key: 'volc_imagine'
403
+ }, VolcImagineToolView));
404
+ }
405
+
24
406
  // dsh-volcengine-provider —— 设置页(Client 侧)
25
407
  //
26
408
  // 页面职责:
27
409
  // 1. 账号管理:新增 / 编辑 / 删除账号。表单只填「凭据引用名」,页面永远拿不到明文密钥。
28
410
  // 2. 双套餐卡片:Agent 套餐与编程套餐各自独立选择账号、拉取模型目录、刷新额度。
411
+ // 额度随设置页可见自动轮询(打开即查、每 60 秒一次、失败退避、隐藏时暂停),
412
+ // 结果在模块作用域留存,重开设置页先显示上次结果。
29
413
  // 3. 网页登录:登录前先讲清副作用,登录中只展示状态与取消入口;
30
414
  // 官方 CLI 在系统默认浏览器里完成授权,页面既不接触授权码,也不接触 token。
31
415
  // 4. 模型管理:套餐启用开关、逐模型启用开关、模型参数编辑与恢复默认。
@@ -66,6 +450,23 @@ const PLAN_HINTS = {
66
450
  'coding-plan': '展示 5 小时 / 周 / 月三个额度窗口,接口只给已用百分比。'
67
451
  };
68
452
 
453
+ const SETTINGS_TABS = [
454
+ { id: 'agent-plan', label: 'Agent 套餐' },
455
+ { id: 'coding-plan', label: '编程套餐' },
456
+ { id: 'accounts', label: '账号与登录' },
457
+ { id: 'media', label: '图片生成' }
458
+ ];
459
+
460
+ function settingsTabAfter(key, current) {
461
+ const index = SETTINGS_TABS.findIndex(tab => tab.id === current);
462
+ if (index < 0) return null;
463
+ if (key === 'Home') return SETTINGS_TABS[0].id;
464
+ if (key === 'End') return SETTINGS_TABS[SETTINGS_TABS.length - 1].id;
465
+ if (key === 'ArrowRight') return SETTINGS_TABS[(index + 1) % SETTINGS_TABS.length].id;
466
+ if (key === 'ArrowLeft') return SETTINGS_TABS[(index - 1 + SETTINGS_TABS.length) % SETTINGS_TABS.length].id;
467
+ return null;
468
+ }
469
+
69
470
  /** 额度窗口名的展示词。 */
70
471
  const WINDOW_KIND_LABELS = { '5h': '5 小时', week: '每周', month: '每月', day: '每日' };
71
472
 
@@ -76,6 +477,13 @@ const WINDOW_GROUP_LABELS = {
76
477
  'daily-capabilities': '每日能力限额'
77
478
  };
78
479
 
480
+ /**
481
+ * 额度中间层:Host 定期采集,Client 只读快照。
482
+ * 这里只负责按固定间隔拉一次轻量视图(内存读取,不触发上游查询),
483
+ * 并据此刷新页面;采集节奏、失败退避和「保留上次成功值」都在 Host 侧完成。
484
+ */
485
+ const QUOTA_POLL_MS = 30000;
486
+
79
487
  /** 处于这三个状态时登录流程仍在进行,页面按秒轮询进度。 */
80
488
  const LOGIN_ACTIVE_STATES = ['launching', 'waiting', 'verifying'];
81
489
  // UI-only sentinel: never sent as an account ID to the host.
@@ -233,7 +641,9 @@ const LOGIN_CONFIRM_NOTES = [
233
641
  '登录使用官方 ArkCli 的无浏览器两段式流程:先生成官方登录链接,你在任意设备的浏览器完成 SSO 后,把页面显示的授权码粘贴回设置页;官方 CLI 负责完成交换与凭据落盘,插件不打开浏览器、不读取网页或授权码内容。',
234
642
  '登录得到的凭据保存在本插件为该账号准备的隔离目录里,不会改变你原有 CLI 的默认身份。',
235
643
  '取消登录或删除账号元数据都不会删除已经保存的凭据;需要清理时请自行处理该账号的隔离目录。',
236
- 'OAuth 登录会绑定该账号可用的个人套餐,模型调用与额度查询使用对应套餐的登录身份,无需另外填写 AK/SK。'
644
+ 'OAuth 登录会绑定该账号可用的个人套餐,模型调用与额度查询使用对应套餐的登录身份,无需另外填写 AK/SK。',
645
+ '官方 SSO 登录态有效期 48 小时:有效期内官方 CLI 自动续期凭据,到期后需要重新网页登录。',
646
+ '授权码 10 分钟内有效;过期请取消本次登录并重新生成登录链接。'
237
647
  ];
238
648
 
239
649
  /** 账号 ID、凭据引用名、Profile 名的取值规则(与 Host 端 state.mjs 保持一致)。 */
@@ -249,41 +659,41 @@ const LOGIN_POLL_MS = 1000;
249
659
  // ── 主题样式(只用设计令牌与继承,兼容深浅色) ───────────────────────────────
250
660
 
251
661
  const style = {
252
- root: { display: 'flex', flexDirection: 'column', gap: 12 },
253
- title: { margin: 0, fontSize: 18, fontWeight: 650, lineHeight: 1.35, letterSpacing: '-.015em' },
662
+ root: { display: 'flex', flexDirection: 'column', gap: 10 },
663
+ title: { margin: 0, fontSize: 15, fontWeight: 650, lineHeight: 1.35, letterSpacing: '-.015em' },
254
664
  card: {
255
665
  minWidth: 0,
256
666
  border: '1px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l2, rgba(128,128,128,.24)))',
257
667
  borderRadius: 12,
258
668
  background: 'var(--dsw-alias-bg-layer-1, rgba(128,128,128,.025))'
259
669
  },
260
- cardTitle: { margin: 0, fontSize: 15, lineHeight: 1.4, fontWeight: 650 },
261
- row: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap', minWidth: 0 },
262
- field: { display: 'flex', flexDirection: 'column', gap: 5, flex: '1 1 180px', minWidth: 0 },
670
+ cardTitle: { margin: 0, fontSize: 13, lineHeight: 1.4, fontWeight: 650 },
671
+ row: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap', minWidth: 0 },
672
+ field: { display: 'flex', flexDirection: 'column', gap: 4, flex: '1 1 180px', minWidth: 0 },
263
673
  label: { fontSize: 12, lineHeight: 1.5, color: 'var(--dsw-alias-label-secondary, inherit)' },
264
674
  input: {
265
- width: '100%', minWidth: 0, minHeight: 32, boxSizing: 'border-box', padding: '6px 9px',
266
- borderRadius: 7, fontSize: 12,
675
+ width: '100%', minWidth: 0, minHeight: 26, boxSizing: 'border-box', padding: '4px 8px',
676
+ borderRadius: 6, fontSize: 12,
267
677
  border: '1px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l2, rgba(128,128,128,.35)))',
268
678
  background: 'var(--dsw-alias-bg-layer-2, Canvas)', color: 'inherit', font: 'inherit'
269
679
  },
270
680
  btn: {
271
- display: 'inline-flex', alignItems: 'center', justifyContent: 'center', minHeight: 32,
272
- padding: '6px 10px', borderRadius: 7, fontSize: 12,
681
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', minHeight: 26,
682
+ padding: '4px 9px', borderRadius: 6, fontSize: 12,
273
683
  border: '1px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l2, rgba(128,128,128,.3)))',
274
684
  background: 'var(--dsw-alias-bg-layer-2, rgba(128,128,128,.06))', color: 'inherit', cursor: 'pointer', font: 'inherit'
275
685
  },
276
686
  primary: {
277
- display: 'inline-flex', alignItems: 'center', justifyContent: 'center', minHeight: 32,
278
- padding: '6px 10px', borderRadius: 7, fontSize: 12, fontWeight: 600,
687
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', minHeight: 26,
688
+ padding: '4px 9px', borderRadius: 6, fontSize: 12, fontWeight: 600,
279
689
  border: '1px solid var(--dsw-alias-brand-primary, #2563eb)',
280
690
  background: 'var(--dsw-alias-button-primary-fill, var(--dsw-alias-brand-primary, #2563eb))',
281
691
  color: 'var(--dsw-alias-label-primary-foreground, #fff)',
282
692
  cursor: 'pointer', font: 'inherit'
283
693
  },
284
694
  danger: {
285
- display: 'inline-flex', alignItems: 'center', justifyContent: 'center', minHeight: 32,
286
- padding: '6px 10px', borderRadius: 7, fontSize: 12,
695
+ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', minHeight: 26,
696
+ padding: '4px 9px', borderRadius: 6, fontSize: 12,
287
697
  border: '1px solid var(--dsw-alias-state-error-primary, rgba(220,38,38,.55))',
288
698
  background: 'transparent', color: 'var(--dsw-alias-label-primary, inherit)',
289
699
  cursor: 'pointer', font: 'inherit'
@@ -299,46 +709,61 @@ const style = {
299
709
  background: 'var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.08))'
300
710
  },
301
711
  subcard: {
302
- display: 'flex', flexDirection: 'column', gap: 10, minWidth: 0, padding: '12px',
303
- borderRadius: 10, background: 'var(--dsw-alias-bg-layer-2, rgba(128,128,128,.04))'
712
+ display: 'flex', flexDirection: 'column', gap: 8, minWidth: 0, padding: '10px',
713
+ borderRadius: 8, background: 'var(--dsw-alias-bg-layer-2, rgba(128,128,128,.04))'
304
714
  },
305
- summary: { cursor: 'pointer', minHeight: 30, padding: '5px 0', fontSize: 12, color: 'var(--dsw-alias-label-secondary, inherit)' }
715
+ summary: { cursor: 'pointer', minHeight: 26, padding: '4px 0', fontSize: 12, color: 'var(--dsw-alias-label-secondary, inherit)' }
306
716
  };
307
717
 
308
718
  // Scoped CSS supplies interaction states and responsive grids which inline styles cannot express.
309
719
  const CLIENT_STYLES = `
310
- .vcp-settings{color:var(--dsw-alias-label-primary,inherit);color-scheme:light;max-width:960px;padding:6px 2px 24px;font-size:13px;line-height:1.5;container-type:inline-size;container-name:vcp}
720
+ .vcp-settings{color:var(--dsw-alias-label-primary,inherit);color-scheme:light;max-width:960px;padding:4px 2px 16px;font-size:12px;line-height:1.5;container-type:inline-size;container-name:vcp}
311
721
  body[data-ds-dark-theme] .vcp-settings{color-scheme:dark}
312
- .vcp-settings *{box-sizing:border-box}.vcp-settings :focus-visible{outline:2px solid var(--dsw-alias-brand-primary,Highlight);outline-offset:3px}.vcp-settings input::placeholder,.vcp-settings textarea::placeholder{color:var(--dsw-alias-label-secondary,GrayText);opacity:1}.vcp-card{padding:12px 14px}
313
- .vcp-content{display:flex;flex-direction:column;gap:14px}.vcp-content[data-empty=true] .vcp-account-panel{order:-1}.vcp-plan-workspace{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,320px),1fr));gap:1px;padding:0;overflow:hidden;background:var(--dsw-alias-border-l4,rgba(128,128,128,.16));align-items:start}.vcp-plan{display:flex;flex-direction:column;gap:12px;min-width:0;padding:16px;background:var(--dsw-alias-bg-layer-1,Canvas)}.vcp-plan-setup{display:flex;align-items:end;gap:10px;flex-wrap:wrap}.vcp-plan-toggle{display:flex;align-items:center;gap:7px;min-height:32px;white-space:nowrap;font-size:12px;font-weight:600}.vcp-plan-account{flex:1 1 170px}.vcp-plan-note{flex-basis:100%}
314
- .vcp-account-body{display:flex;flex-direction:column;gap:12px;padding:12px 0 0}.vcp-accounts-disclosure>summary{display:flex;align-items:center;gap:10px;min-height:32px;cursor:pointer;list-style:none}.vcp-accounts-disclosure>summary::-webkit-details-marker{display:none}.vcp-accounts-disclosure>summary::after{content:'›';margin-left:auto;font-size:18px;line-height:1;transform:rotate(90deg)}.vcp-accounts-disclosure[open]>summary::after{transform:rotate(-90deg)}.vcp-accounts-disclosure[open]>summary{border-bottom:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.14));padding-bottom:10px}
315
- .vcp-header{display:flex;align-items:center;gap:12px;padding:0 2px 2px}.vcp-header-copy{flex:1;min-width:0}.vcp-heading{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}.vcp-heading-copy{flex:1 1 180px;min-width:0}.vcp-heading-copy p{margin-top:4px}.vcp-actions{display:flex;align-items:center;gap:7px;flex-wrap:wrap;min-width:0}
722
+ .vcp-settings *{box-sizing:border-box}.vcp-settings :focus-visible{outline:2px solid var(--dsw-alias-brand-primary,Highlight);outline-offset:2px}.vcp-settings input::placeholder,.vcp-settings textarea::placeholder{color:var(--dsw-alias-label-secondary,GrayText);opacity:1}.vcp-card{padding:10px 12px}
723
+ .vcp-content{display:flex;flex-direction:column;gap:10px}.vcp-content[data-empty=true] .vcp-account-panel{order:-1}.vcp-plan{display:flex;flex-direction:column;gap:10px;min-width:0;padding:12px;background:var(--dsw-alias-bg-layer-1,Canvas)}.vcp-plan-setup{display:flex;align-items:end;gap:8px;flex-wrap:wrap}.vcp-plan-toggle{display:flex;align-items:center;gap:6px;min-height:24px;white-space:nowrap;font-size:12px;font-weight:600}.vcp-plan-account{flex:1 1 170px}.vcp-plan-note{flex-basis:100%}
724
+ .vcp-account-body{display:flex;flex-direction:column;gap:8px;padding:8px 0 0}.vcp-accounts-disclosure>summary{display:flex;align-items:center;gap:8px;min-height:26px;cursor:pointer;list-style:none}.vcp-accounts-disclosure>summary::-webkit-details-marker{display:none}.vcp-accounts-disclosure>summary::after{content:'›';margin-left:auto;font-size:14px;line-height:1;transform:rotate(90deg)}.vcp-accounts-disclosure[open]>summary::after{transform:rotate(-90deg)}.vcp-accounts-disclosure[open]>summary{border-bottom:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.14));padding-bottom:8px}
725
+ .vcp-header{display:flex;align-items:center;gap:8px;padding:0 2px 2px}.vcp-header-copy{flex:1;min-width:0}.vcp-heading{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap}.vcp-heading-copy{flex:1 1 180px;min-width:0}.vcp-heading-copy p{margin-top:3px}.vcp-actions{display:flex;align-items:center;gap:6px;flex-wrap:wrap;min-width:0}
316
726
  .vcp-select{width:100%;min-width:0;max-width:100%;flex:none}.vcp-settings select option{color:var(--dsw-alias-label-primary,CanvasText);background:var(--dsw-alias-bg-layer-1,Canvas)}.vcp-settings select option:disabled{color:var(--dsw-alias-label-secondary,GrayText)}.vcp-chip-row{display:flex;gap:6px;flex-wrap:wrap;min-width:0}.vcp-section{border-top:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.14));padding-top:10px;display:flex;flex-direction:column;gap:6px;min-width:0}
317
- .vcp-notice{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:10px 12px;border-radius:9px;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.18));border-left:3px solid var(--dsw-alias-border-l3,rgba(128,128,128,.4));background:var(--dsw-alias-bg-layer-2,Canvas);overflow-wrap:anywhere}.vcp-notice>p{flex:1 1 180px;min-width:0}.vcp-notice-icon{display:inline-flex;align-items:center;justify-content:center;flex:none;width:22px;height:22px;border-radius:50%;background:var(--dsw-alias-label-secondary,#94a3b8);color:var(--dsw-alias-bg-layer-1,#fff);font-size:13px;font-weight:750;line-height:1}.vcp-notice[data-tone=error]{border-left-color:var(--dsw-alias-state-error-primary,#dc2626)}.vcp-notice[data-tone=warn]{border-left-color:var(--dsw-alias-state-warn-primary,#b45309)}.vcp-notice[data-tone=success]{border-left-color:var(--dsw-alias-state-success-primary,#16a34a)}.vcp-notice[data-tone=error] .vcp-notice-icon{background:var(--dsw-alias-state-error-primary,#dc2626)}.vcp-notice[data-tone=warn] .vcp-notice-icon{background:var(--dsw-alias-state-warn-primary,#b45309)}.vcp-notice[data-tone=success] .vcp-notice-icon{background:var(--dsw-alias-state-success-primary,#16a34a)}
318
- .vcp-account{display:flex;flex-direction:column;gap:8px;min-width:0;padding:14px 0;border-top:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.14))}.vcp-account:first-child{padding-top:0;border-top:0}.vcp-account-title{font-size:13px;font-weight:650;overflow-wrap:anywhere}.vcp-model-list{display:flex;flex-direction:column;margin-top:6px}.vcp-model{display:flex;flex-direction:column;gap:7px;min-width:0;padding:12px 0;border-top:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.14))}.vcp-model:first-child{border-top:0}.vcp-model-name{font-weight:600;min-width:0;overflow-wrap:anywhere}.vcp-model-id{font-family:ui-monospace,'Cascadia Mono',Consolas,monospace;font-size:11px}
727
+ .vcp-notice{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:8px 10px;border-radius:8px;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.18));border-left:3px solid var(--dsw-alias-border-l3,rgba(128,128,128,.4));background:var(--dsw-alias-bg-layer-2,Canvas);overflow-wrap:anywhere}.vcp-notice>p{flex:1 1 180px;min-width:0}.vcp-notice-icon{display:inline-flex;align-items:center;justify-content:center;flex:none;width:18px;height:18px;border-radius:50%;background:var(--dsw-alias-label-secondary,#94a3b8);color:var(--dsw-alias-bg-layer-1,#fff);font-size:11px;font-weight:750;line-height:1}.vcp-notice[data-tone=error]{border-left-color:var(--dsw-alias-state-error-primary,#dc2626)}.vcp-notice[data-tone=warn]{border-left-color:var(--dsw-alias-state-warn-primary,#b45309)}.vcp-notice[data-tone=success]{border-left-color:var(--dsw-alias-state-success-primary,#16a34a)}.vcp-notice[data-tone=error] .vcp-notice-icon{background:var(--dsw-alias-state-error-primary,#dc2626)}.vcp-notice[data-tone=warn] .vcp-notice-icon{background:var(--dsw-alias-state-warn-primary,#b45309)}.vcp-notice[data-tone=success] .vcp-notice-icon{background:var(--dsw-alias-state-success-primary,#16a34a)}
728
+ .vcp-account{display:flex;flex-direction:column;gap:6px;min-width:0;padding:10px 0;border-top:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.14))}.vcp-account:first-child{padding-top:0;border-top:0}.vcp-account-title{font-size:12.5px;font-weight:650;overflow-wrap:anywhere}.vcp-model-list{display:flex;flex-direction:column;margin-top:4px}.vcp-model{display:flex;flex-direction:column;gap:6px;min-width:0;padding:9px 0;border-top:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.14))}.vcp-model:first-child{border-top:0}.vcp-model-name{font-weight:600;min-width:0;overflow-wrap:anywhere}.vcp-model-id{font-family:ui-monospace,'Cascadia Mono',Consolas,monospace;font-size:11px}
319
729
  .vcp-fields{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}.vcp-fields-three{grid-template-columns:repeat(3,minmax(0,1fr))}.vcp-quota-section{display:flex;flex-direction:column;gap:8px;min-width:0}.vcp-quota{display:grid;gap:10px}.vcp-quota-group{display:grid;gap:7px}.vcp-quota-group+.vcp-quota-group{margin-top:3px}.vcp-quota-group-title{font-size:12px;font-weight:600;color:var(--dsw-alias-label-secondary,inherit)}.vcp-quota-window{display:grid;gap:7px;min-width:0;padding:10px 11px;border-radius:9px;background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.07))}.vcp-quota-window[data-tone=error]{background:var(--dsw-alias-state-error-bg,rgba(220,38,38,.08))}.vcp-quota-window[data-tone=warn]{background:var(--dsw-alias-state-warn-bg,rgba(180,83,9,.08))}.vcp-quota-line{display:flex;align-items:center;gap:7px;min-width:0}.vcp-quota-name{font-size:12px;font-weight:600}.vcp-quota-value{display:flex;align-items:baseline;gap:4px;margin-left:auto;text-align:right;white-space:nowrap;font-variant-numeric:tabular-nums}.vcp-quota-percent{font-size:20px;line-height:1.05;font-weight:700;letter-spacing:-.025em;color:var(--dsw-alias-label-primary,inherit)}.vcp-quota-percent small{font-size:12px;font-weight:600}.vcp-quota-remaining{font-size:12px;color:var(--dsw-alias-label-secondary,inherit)}.vcp-quota-track{width:100%;height:8px;border-radius:99px;overflow:hidden;background:var(--dsw-alias-interactive-bg-active,rgba(128,128,128,.2))}.vcp-quota-fill{height:100%;border-radius:99px;background:var(--dsw-alias-brand-primary,#3b82f6)}.vcp-quota-window[data-tone=error] .vcp-quota-fill{background:var(--dsw-alias-state-error-primary,#dc2626)}.vcp-quota-window[data-tone=warn] .vcp-quota-fill{background:var(--dsw-alias-state-warn-primary,#b45309)}.vcp-quota-meta{display:grid;gap:2px;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-secondary,inherit);overflow-wrap:anywhere}.vcp-quota-reset{display:flex;justify-content:space-between;gap:2px 10px;flex-wrap:wrap;font-size:11px;line-height:1.5;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-secondary,inherit)}.vcp-status-chip{display:inline-flex;align-items:center;gap:5px;padding:1px 7px;border-radius:99px;font-size:10.5px;line-height:1.5;white-space:nowrap;background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.09))}.vcp-status-chip::before{content:'';width:6px;height:6px;border-radius:50%;background:var(--dsw-alias-label-secondary,#94a3b8)}.vcp-status-chip[data-tone=warn]{background:var(--dsw-alias-state-warn-bg,rgba(180,83,9,.1))}.vcp-status-chip[data-tone=warn]::before{background:var(--dsw-alias-state-warn-primary,#b45309)}.vcp-status-chip[data-tone=error]{background:var(--dsw-alias-state-error-bg,rgba(220,38,38,.1))}.vcp-status-chip[data-tone=error]::before{background:var(--dsw-alias-state-error-primary,#dc2626)}.vcp-status-chip[data-tone=success]::before{background:var(--dsw-alias-state-success-primary,#16a34a)}
320
- .vcp-details>summary{cursor:pointer}.vcp-details-body{display:flex;flex-direction:column;gap:7px;margin-top:6px;padding-top:10px;border-top:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.14))}.vcp-model-meta{display:flex;flex-direction:column;gap:4px}.vcp-editor,.vcp-confirm,.vcp-login-status{display:flex;flex-direction:column;gap:8px;padding:12px 0;border-top:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.16))}.vcp-confirm,.vcp-login-status{padding:10px 12px;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.18));border-left:3px solid var(--dsw-alias-state-warn-primary,#b45309);border-radius:8px;background:var(--dsw-alias-bg-layer-2,rgba(128,128,128,.04))}.vcp-empty{display:flex;flex-direction:column;gap:9px}
730
+ .vcp-details>summary{cursor:pointer}.vcp-details-body{display:flex;flex-direction:column;gap:6px;margin-top:4px;padding-top:8px;border-top:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.14))}.vcp-model-meta{display:flex;flex-direction:column;gap:4px}.vcp-editor,.vcp-confirm,.vcp-login-status{display:flex;flex-direction:column;gap:6px;padding:8px 0;border-top:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.16))}.vcp-confirm,.vcp-login-status{padding:8px 10px;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.18));border-left:3px solid var(--dsw-alias-state-warn-primary,#b45309);border-radius:8px;background:var(--dsw-alias-bg-layer-2,rgba(128,128,128,.04))}.vcp-empty{display:flex;flex-direction:column;gap:8px}
321
731
  .vcp-button:hover:not(:disabled){box-shadow:0 0 0 1px var(--dsw-alias-brand-primary,Highlight)}.vcp-button:disabled{opacity:.55;cursor:not-allowed}.vcp-settings summary:hover{color:var(--dsw-alias-label-primary,inherit)}
322
732
  @media(max-width:680px){.vcp-fields,.vcp-fields-three{grid-template-columns:1fr}.vcp-select{width:100%;min-width:0}}
323
- @media(max-width:420px){.vcp-settings{padding:2px 0 20px}.vcp-card{padding:12px}.vcp-plan-workspace{padding:0}.vcp-plan{padding:12px}.vcp-header{flex-wrap:wrap}.vcp-header>.vcp-actions{width:100%;justify-content:space-between}.vcp-heading{gap:8px}.vcp-heading>.vcp-actions{width:100%}.vcp-actions .vcp-button{flex:1 1 auto}.vcp-account-body{padding:12px 0 0}.vcp-section{padding-top:12px}.vcp-quota-reset{flex-direction:column}.vcp-plan-account{flex-basis:100%}}
733
+ @media(max-width:420px){.vcp-settings{padding:2px 0 16px}.vcp-card{padding:10px}.vcp-plan{padding:10px}.vcp-header{flex-wrap:wrap}.vcp-header>.vcp-actions{width:100%;justify-content:space-between}.vcp-heading{gap:8px}.vcp-heading>.vcp-actions{width:100%}.vcp-actions .vcp-button{flex:1 1 auto}.vcp-account-body{padding:8px 0 0}.vcp-section{padding-top:8px}.vcp-quota-reset{flex-direction:column}.vcp-plan-account{flex-basis:100%}}
324
734
  @container vcp (max-width:680px){.vcp-fields,.vcp-fields-three{grid-template-columns:1fr}}
325
- @container vcp (max-width:420px){.vcp-settings{padding:2px 0 20px}.vcp-plan{padding:12px}.vcp-header{flex-wrap:wrap}.vcp-header>.vcp-actions{width:100%;justify-content:space-between}.vcp-heading>.vcp-actions{width:100%}.vcp-actions .vcp-button{flex:1 1 auto}.vcp-account-body{padding:12px 0 0}.vcp-quota-reset{flex-direction:column}.vcp-plan-account{flex-basis:100%}}
735
+ @container vcp (max-width:420px){.vcp-settings{padding:2px 0 16px}.vcp-plan{padding:10px}.vcp-header{flex-wrap:wrap}.vcp-header>.vcp-actions{width:100%;justify-content:space-between}.vcp-heading>.vcp-actions{width:100%}.vcp-actions .vcp-button{flex:1 1 auto}.vcp-account-body{padding:8px 0 0}.vcp-quota-reset{flex-direction:column}.vcp-plan-account{flex-basis:100%}}
326
736
 
327
737
  /* Provider workspace: independent plan cards, compact quotas and model badges. */
328
- .vcp-settings{max-width:1080px;padding:4px 2px 32px;gap:16px;-webkit-font-smoothing:antialiased}
329
- .vcp-content{gap:16px}.vcp-hero{position:relative;overflow:hidden;padding:20px 22px;border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.2));border-radius:18px;background:linear-gradient(145deg,color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 8%,var(--dsw-alias-bg-layer-1,#fff)),var(--dsw-alias-bg-layer-1,#fff) 58%);box-shadow:0 8px 28px rgba(15,23,42,.05)}
330
- .vcp-brand-mark{display:flex;align-items:center;justify-content:center;flex:none;width:42px;height:42px;border-radius:13px;background:var(--dsw-alias-brand-primary,#2563eb);color:var(--dsw-alias-label-primary-foreground,#fff);font-size:20px;font-weight:750;box-shadow:0 6px 16px color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 24%,transparent)}
331
- .vcp-hero-subtitle{margin:5px 0 0;max-width:64ch;font-size:12px;line-height:1.6;color:var(--dsw-alias-label-secondary,inherit)}.vcp-eyebrow{margin-bottom:3px;font-size:10px;font-weight:700;letter-spacing:.09em;color:var(--dsw-alias-label-secondary,inherit)}
332
- .vcp-plan-workspace{gap:14px;padding:0;border:0;background:transparent;overflow:visible;align-items:start}.vcp-plan{gap:14px;padding:18px;border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.2));border-radius:16px;background:var(--dsw-alias-bg-layer-1,Canvas);box-shadow:0 3px 14px rgba(15,23,42,.035)}.vcp-plan-setup{align-items:stretch}.vcp-plan-account{flex-basis:100%}.vcp-plan-toggle{display:inline-flex;align-items:center;gap:7px;min-height:28px;font-size:11px;font-weight:600;white-space:nowrap;cursor:pointer}
333
- .vcp-switch-input{appearance:none;-webkit-appearance:none;position:relative;flex:none;width:34px;height:20px;margin:0;border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.35));border-radius:999px;background:var(--dsw-alias-bg-layer-2,rgba(128,128,128,.12));color:var(--dsw-alias-label-primary,#1f2937);cursor:pointer}.vcp-switch-input::after{content:'';position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background:currentColor;box-shadow:0 1px 3px rgba(0,0,0,.2)}.vcp-switch-input:checked{border-color:var(--dsw-alias-brand-primary,#2563eb);background:var(--dsw-alias-brand-primary,#2563eb);color:var(--dsw-alias-label-primary-foreground,#fff)}.vcp-switch-input:checked::after{transform:translateX(14px)}body[data-ds-dark-theme] .vcp-switch-input:checked{color:#11161e}.vcp-switch-input:disabled{opacity:.55;cursor:not-allowed}
738
+ .vcp-settings{max-width:1080px;padding:2px 0 16px;gap:10px;-webkit-font-smoothing:antialiased}
739
+ .vcp-content{gap:10px}.vcp-hero{position:relative;overflow:hidden;padding:12px 14px;border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.2));border-radius:12px;background:linear-gradient(145deg,color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 8%,var(--dsw-alias-bg-layer-1,#fff)),var(--dsw-alias-bg-layer-1,#fff) 58%);box-shadow:0 4px 14px rgba(15,23,42,.04)}
740
+ .vcp-brand-mark{display:flex;align-items:center;justify-content:center;flex:none;width:32px;height:32px;border-radius:10px;background:var(--dsw-alias-brand-primary,#2563eb);color:var(--dsw-alias-label-primary-foreground,#fff);font-size:16px;font-weight:750;box-shadow:0 3px 8px color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 24%,transparent)}
741
+ .vcp-hero-subtitle{margin:3px 0 0;max-width:64ch;font-size:11px;line-height:1.55;color:var(--dsw-alias-label-secondary,inherit)}.vcp-eyebrow{margin-bottom:2px;font-size:10px;font-weight:700;letter-spacing:.09em;color:var(--dsw-alias-label-secondary,inherit)}
742
+ .vcp-plan{gap:10px;padding:12px;border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.2));border-radius:12px;background:var(--dsw-alias-bg-layer-1,Canvas);box-shadow:0 2px 8px rgba(15,23,42,.03)}.vcp-plan-setup{align-items:stretch}.vcp-plan-account{flex-basis:100%}.vcp-plan-toggle{display:inline-flex;align-items:center;gap:6px;min-height:24px;font-size:11px;font-weight:600;white-space:nowrap;cursor:pointer}
743
+ .vcp-switch-input{appearance:none;-webkit-appearance:none;position:relative;flex:none;width:30px;height:18px;margin:0;border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.35));border-radius:999px;background:var(--dsw-alias-bg-layer-2,rgba(128,128,128,.12));color:var(--dsw-alias-label-primary,#1f2937);cursor:pointer}.vcp-switch-input::after{content:'';position:absolute;top:2px;left:2px;width:12px;height:12px;border-radius:50%;background:currentColor;box-shadow:0 1px 3px rgba(0,0,0,.2)}.vcp-switch-input:checked{border-color:var(--dsw-alias-brand-primary,#2563eb);background:var(--dsw-alias-brand-primary,#2563eb);color:var(--dsw-alias-label-primary-foreground,#fff)}.vcp-switch-input:checked::after{transform:translateX(12px)}body[data-ds-dark-theme] .vcp-switch-input:checked{color:#11161e}.vcp-switch-input:disabled{opacity:.55;cursor:not-allowed}
334
744
  .vcp-status-chip{display:inline-flex;align-items:center;gap:5px;padding:2px 8px;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.18));border-radius:999px;font-size:10.5px;line-height:1.6;white-space:nowrap;color:var(--dsw-alias-label-secondary,inherit);background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.06))}.vcp-status-chip::before{content:'';width:6px;height:6px;border-radius:50%;background:currentColor}.vcp-status-chip[data-tone=success]{color:var(--dsw-alias-state-success-primary,#15803d);border-color:color-mix(in srgb,currentColor 30%,transparent);background:color-mix(in srgb,currentColor 8%,transparent)}.vcp-status-chip[data-tone=warn]{color:var(--dsw-alias-state-warn-primary,#b45309);border-color:color-mix(in srgb,currentColor 30%,transparent);background:color-mix(in srgb,currentColor 8%,transparent)}
335
- .vcp-quota{grid-template-columns:1fr;gap:8px}.vcp-quota-group{grid-template-columns:repeat(auto-fit,minmax(min(100%,200px),1fr));gap:8px}.vcp-quota-group-title{grid-column:1/-1}.vcp-quota-window{padding:10px;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.12));background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.045))}.vcp-quota-track{height:6px}.vcp-quota-percent{font-size:18px}.vcp-quota-meta{font-size:11px}.vcp-section{gap:8px;padding-top:12px}
336
- .vcp-model-list{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,280px),1fr));gap:10px;margin-top:10px}.vcp-model{position:relative;display:flex;flex-direction:column;gap:10px;min-width:0;padding:13px;border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.18));border-radius:12px;background:var(--dsw-alias-bg-layer-2,rgba(128,128,128,.035));box-shadow:inset 0 1px 0 rgba(255,255,255,.035)}.vcp-model:first-child{border-top:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.18))}.vcp-model[data-disabled=true]{opacity:.66}.vcp-model-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;min-width:0}.vcp-model-toggle{display:flex;align-items:flex-start;gap:9px;flex:1 1 auto;min-width:0;cursor:pointer}.vcp-model-toggle .vcp-switch-input{margin-top:1px}.vcp-model-heading{display:flex;align-items:center;gap:6px;flex-wrap:wrap;min-width:0;font-size:13px;line-height:1.45}.vcp-model-name{font-size:13.5px;font-weight:650;overflow-wrap:anywhere}.vcp-model-tags{display:flex;gap:5px;flex-wrap:wrap}.vcp-model-tag{display:inline-flex;align-items:center;padding:2px 7px;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.16));border-radius:999px;font-size:10px;line-height:1.55;white-space:nowrap;color:var(--dsw-alias-label-secondary,inherit);background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.04))}.vcp-model-tag[data-tone=accent]{color:var(--dsw-alias-brand-primary,#2563eb);border-color:color-mix(in srgb,currentColor 25%,transparent);background:color-mix(in srgb,currentColor 6%,transparent)}.vcp-model-tag[data-tone=warn]{color:var(--dsw-alias-state-warn-primary,#b45309)}
745
+ .vcp-quota{grid-template-columns:1fr;gap:8px}.vcp-quota-group{grid-template-columns:repeat(auto-fit,minmax(min(100%,200px),1fr));gap:8px}.vcp-quota-group-title{grid-column:1/-1}.vcp-quota-window{padding:8px;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.12));background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.045))}.vcp-quota-track{height:6px}.vcp-quota-percent{font-size:18px}.vcp-quota-meta{font-size:11px}.vcp-section{gap:6px;padding-top:8px}
746
+ .vcp-model-list{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,280px),1fr));gap:8px;margin-top:8px}.vcp-model{position:relative;display:flex;flex-direction:column;gap:8px;min-width:0;padding:10px;border:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.18));border-radius:10px;background:var(--dsw-alias-bg-layer-2,rgba(128,128,128,.035));box-shadow:inset 0 1px 0 rgba(255,255,255,.035)}.vcp-model:first-child{border-top:1px solid var(--dsw-alias-border-l3,rgba(128,128,128,.18))}.vcp-model[data-disabled=true]{opacity:.66}.vcp-model-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;min-width:0}.vcp-model-toggle{display:flex;align-items:flex-start;gap:9px;flex:1 1 auto;min-width:0;cursor:pointer}.vcp-model-toggle .vcp-switch-input{margin-top:1px}.vcp-model-heading{display:flex;align-items:center;gap:6px;flex-wrap:wrap;min-width:0;font-size:13px;line-height:1.45}.vcp-model-name{font-size:13.5px;font-weight:650;overflow-wrap:anywhere}.vcp-model-tags{display:flex;gap:5px;flex-wrap:wrap}.vcp-model-tag{display:inline-flex;align-items:center;padding:2px 7px;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.16));border-radius:999px;font-size:10px;line-height:1.55;white-space:nowrap;color:var(--dsw-alias-label-secondary,inherit);background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.04))}.vcp-model-tag[data-tone=accent]{color:var(--dsw-alias-brand-primary,#2563eb);border-color:color-mix(in srgb,currentColor 25%,transparent);background:color-mix(in srgb,currentColor 6%,transparent)}.vcp-model-tag[data-tone=warn]{color:var(--dsw-alias-state-warn-primary,#b45309)}
337
747
  .vcp-rate-badge{display:inline-flex;align-items:center;gap:4px;padding:1px 7px;border:1px solid color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 35%,transparent);border-radius:999px;background:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 8%,transparent);color:var(--dsw-alias-brand-primary,#2563eb);font-size:10.5px;font-weight:750;line-height:1.6;white-space:nowrap;font-variant-numeric:tabular-nums}.vcp-rate-badge small{font-size:8.5px;font-weight:650;opacity:1}.vcp-rate-badge[data-discount=true]{color:var(--dsw-alias-state-success-primary,#15803d);border-color:color-mix(in srgb,currentColor 35%,transparent);background:color-mix(in srgb,currentColor 9%,transparent)}
338
- .vcp-model-actions{display:flex;justify-content:flex-end;gap:7px;flex-wrap:wrap;margin-top:auto}.vcp-model-actions .vcp-button{min-height:29px;padding:4px 10px;font-size:11px}.vcp-model .vcp-details{padding-top:2px;border-top:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.12))}.vcp-model .vcp-details>summary{min-height:25px;padding:3px 0;font-size:11px}.vcp-account-panel{border-radius:16px;padding:16px 18px}.vcp-button{transition:border-color .15s ease,box-shadow .15s ease}.vcp-button-primary{border-color:var(--dsw-alias-brand-primary,#2563eb)}
339
- @media(max-width:680px){.vcp-hero{padding:16px}.vcp-plan{padding:15px}.vcp-model-list{grid-template-columns:1fr}}
340
- @media(max-width:420px){.vcp-plan{padding:12px}.vcp-brand-mark{width:36px;height:36px;border-radius:11px;font-size:17px}.vcp-hero .vcp-header-copy{flex:1 1 calc(100% - 52px)}.vcp-hero-subtitle{font-size:11px}.vcp-model-head{flex-direction:column}.vcp-model-head>.vcp-chip-row{padding-left:43px}.vcp-quota{grid-template-columns:1fr}}
748
+ .vcp-model-actions{display:flex;justify-content:flex-end;gap:6px;flex-wrap:wrap;margin-top:auto}.vcp-model-actions .vcp-button{min-height:24px;padding:3px 8px;font-size:11px}.vcp-model .vcp-details{padding-top:2px;border-top:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.12))}.vcp-model .vcp-details>summary{min-height:22px;padding:3px 0;font-size:11px}.vcp-account-panel{border-radius:12px;padding:12px 14px}.vcp-button{transition:border-color .15s ease,box-shadow .15s ease}.vcp-button-primary{border-color:var(--dsw-alias-brand-primary,#2563eb)}
749
+ @media(max-width:680px){.vcp-hero{padding:12px}.vcp-plan{padding:12px}.vcp-model-list{grid-template-columns:1fr}}
750
+ @media(max-width:420px){.vcp-plan{padding:10px}.vcp-brand-mark{width:30px;height:30px;border-radius:9px;font-size:15px}.vcp-hero .vcp-header-copy{flex:1 1 calc(100% - 42px)}.vcp-hero-subtitle{font-size:11px}.vcp-model-head{flex-direction:column}.vcp-model-head>.vcp-chip-row{padding-left:39px}.vcp-quota{grid-template-columns:1fr}}
341
751
  @media(prefers-reduced-motion:reduce){.vcp-settings *{scroll-behavior:auto!important;transition:none!important}}
752
+ .vcp-media-billing{margin:0;padding:8px 10px;border-radius:8px;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.18));background:var(--dsw-alias-bg-layer-2,rgba(128,128,128,.04));font-size:12px;line-height:1.5}
753
+ .vcp-media-tool{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap;padding:6px 10px;border-radius:8px;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.14))}
754
+ .vcp-media-tool-copy{flex:1 1 200px;min-width:0}
755
+ .vcp-media-tool-name{font-size:13px;font-weight:650}
756
+ .vcp-media-tool-name code{font-size:11px;font-weight:400;color:var(--dsw-alias-label-secondary,inherit)}
757
+ .vcp-media-tool p{margin:2px 0 0;font-size:12px}
758
+ .vcp-media-model{display:grid;gap:4px;flex:1 1 240px;min-width:0}
759
+ .vcp-media-model>span{font-size:12px;color:var(--dsw-alias-label-secondary,inherit)}
760
+ .vcp-tabs{display:flex;gap:2px;overflow-x:auto;overflow-y:hidden;border-bottom:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.16));scrollbar-width:thin;padding:2px 2px 0}
761
+ .vcp-tab{flex:none;min-height:34px;padding:6px 11px;margin-bottom:-1px;border:0;border-bottom:2px solid transparent;border-radius:7px 7px 0 0;background:transparent;color:var(--dsw-alias-label-secondary,inherit);cursor:pointer;font:inherit;font-size:12px;white-space:nowrap}
762
+ .vcp-tab:focus-visible{outline-offset:-2px}
763
+ .vcp-tab:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.07));color:var(--dsw-alias-label-primary,inherit)}
764
+ .vcp-tab[aria-selected=true]{border-bottom-color:var(--dsw-alias-brand-primary,Highlight);color:var(--dsw-alias-label-primary,inherit);font-weight:650}
765
+ .vcp-tabpanel,.vcp-tab-section{display:flex;flex-direction:column;gap:10px;min-width:0}
766
+ .vcp-tab-section[hidden],.vcp-plan-section[hidden]{display:none!important}
342
767
  `;
343
768
 
344
769
  function installStyles() {
@@ -499,7 +924,8 @@ function resetCountdown(value, now) {
499
924
  const target = resetEpoch(value);
500
925
  if (target === null) return value ? '重置时间不可用' : '重置时间未提供';
501
926
  const seconds = Math.ceil((target - now) / 1000);
502
- if (seconds <= 0) return '已到重置时间,请刷新额度';
927
+ // 轮询会自动更新窗口;到期本身不推断额度已恢复,只提示等待下一次刷新。
928
+ if (seconds <= 0) return '已到重置时间,等待自动刷新';
503
929
  const days = Math.floor(seconds / 86400);
504
930
  const hours = Math.floor(seconds % 86400 / 3600);
505
931
  const minutes = Math.floor(seconds % 3600 / 60);
@@ -509,6 +935,39 @@ function resetCountdown(value, now) {
509
935
  return `距重置 ${minutes ? `${minutes}分 ` : ''}${remainder}秒`;
510
936
  }
511
937
 
938
+ /** 登录态临期提醒阈值:剩余不足 2 小时升级为警告。 */
939
+ const LOGIN_EXPIRY_WARN_MS = 2 * 60 * 60 * 1000;
940
+
941
+ /**
942
+ * OAuth 登录态到期展示:只使用 Host 下发的到期元数据(refresh_token 的 exp),未知时不显示。
943
+ * 到期与临期给出重新登录指引,其余展示绝对时间与剩余时长;剩余时间随页面轮询重算。
944
+ *
945
+ * @param {object} account 账号快照
946
+ * @param {number} [now] 当前毫秒时间戳
947
+ * @returns {{tone: string, text: string}|null} 提示色调与文本;不适用时 null
948
+ */
949
+ function loginExpiryView(account, now = Date.now()) {
950
+ if (!isOAuth(account) || typeof account.oauthExpiresAt !== 'string') return null;
951
+ const at = Date.parse(account.oauthExpiresAt);
952
+ if (!Number.isFinite(at)) return null;
953
+ const remaining = at - now;
954
+ if (remaining <= 0) return { tone: 'error', text: '登录态已到期,请重新网页登录;到期后额度查询与凭据续期不可用。' };
955
+ const minutes = Math.ceil(remaining / 60000);
956
+ const days = Math.floor(minutes / 1440);
957
+ const hours = Math.floor(minutes % 1440 / 60);
958
+ const mins = minutes % 60;
959
+ const label = days ? `${days}天${hours ? ` ${hours}小时` : ''}` : hours ? `${hours}小时${mins ? ` ${mins}分钟` : ''}` : `${mins}分钟`;
960
+ if (remaining <= LOGIN_EXPIRY_WARN_MS) return { tone: 'warn', text: `登录态将在 ${label}后到期(${formatTime(account.oauthExpiresAt)}),请及时重新网页登录。` };
961
+ return { tone: 'muted', text: `登录态有效至 ${formatTime(account.oauthExpiresAt)}(剩余 ${label}),有效期内官方 CLI 自动续期。` };
962
+ }
963
+
964
+ /** 账号卡片上的登录态到期提示。 */
965
+ function LoginExpiryNote({ account }) {
966
+ const view = loginExpiryView(account);
967
+ if (!view) return null;
968
+ return h('p', { style: style[view.tone] || style.muted, role: view.tone === 'error' ? 'alert' : undefined }, view.text);
969
+ }
970
+
512
971
  /**
513
972
  * 百分比保留一位小数。
514
973
  *
@@ -681,7 +1140,7 @@ function busyMessage(key) {
681
1140
  model: `正在更新模型 ${model} 的启用状态…`, settings: `正在保存模型 ${model} 的参数…`,
682
1141
  reset: `正在恢复模型 ${model} 的默认参数…`, login: '正在启动官方网页登录…',
683
1142
  'cancel-login': '正在取消登录…', save: '正在保存账号…', delete: '正在删除账号…',
684
- 'submit-login-code': '正在提交授权码并验证登录…'
1143
+ 'submit-login-code': '正在提交授权码并验证登录…', media: '正在更新图片生成设置…'
685
1144
  };
686
1145
  return messages[operation] || '正在处理…';
687
1146
  }
@@ -996,7 +1455,7 @@ function QuotaWindows({ quota }) {
996
1455
  }, 1000);
997
1456
  return () => clearInterval(timer);
998
1457
  }, [resetSignature]);
999
- if (!quota) return h('p', { style: style.muted }, '尚未查询额度,点击「刷新额度」获取当前账号的数据。');
1458
+ if (!quota) return h('p', { style: style.muted }, '后台正在采集额度,采集完成后会自动显示;也可点击「刷新额度」立即采集。');
1000
1459
  if (quota.state === 'no-key') {
1001
1460
  // no-key 有两种成因:OAuth 账号没绑定该套餐,或引用名账号缺 AK/SK。
1002
1461
  // 先显示后端给的原因,再补一条网页登录的出路。
@@ -1064,15 +1523,17 @@ function QuotaWindows({ quota }) {
1064
1523
  /**
1065
1524
  * 按模型的目录理论上限给稀疏档位(codex 式 standard/extended/maximum 思路):
1066
1525
  * 上下文固定档 128K/256K/512K/1M,输出固定档 32K/64K/128K/256K,
1067
- * 只保留不超过该模型上限的部分;目录声明的上限总是顶档("最大"),
1526
+ * 只保留不超过该模型上限的部分;理论上限本身总是顶档("最大"),
1068
1527
  * 已有自定义值保留为独立凹点,不因改成滑块而吞掉任意整数。
1528
+ * ceiling 为字段的真实上限:上下文取目录 contextWindow,输出取目录 maxTokensCeiling
1529
+ * (未声明时退回默认 maxTokens)——部分模型可协商输出上限高于目录默认值。
1069
1530
  */
1070
1531
  const CAPACITY_LEVELS = {
1071
1532
  contextWindow: [131072, 262144, 524288, 1048576],
1072
1533
  maxTokens: [32768, 65536, 131072, 262144]
1073
1534
  };
1074
- function capacityStops(key, inheritedValue, currentValue) {
1075
- const ceiling = Number.isSafeInteger(inheritedValue) && inheritedValue > 0 ? inheritedValue : undefined;
1535
+ function capacityStops(key, ceilingValue, currentValue) {
1536
+ const ceiling = Number.isSafeInteger(ceilingValue) && ceilingValue > 0 ? ceilingValue : undefined;
1076
1537
  const stops = new Set((CAPACITY_LEVELS[key] ?? []).filter(level => ceiling === undefined || level <= ceiling));
1077
1538
  if (ceiling !== undefined) stops.add(ceiling);
1078
1539
  if (Number.isSafeInteger(currentValue) && currentValue > 0) stops.add(currentValue);
@@ -1209,9 +1670,22 @@ function ModelSettingsEditor({ model, draft, error, fieldErrors, disabled, onCha
1209
1670
  const capacityRow = (key, label) => {
1210
1671
  const inherited = (draft?.[key] ?? '') === '';
1211
1672
  const inheritedValue = model?.defaults?.[key];
1673
+ // 滑块顶档是字段真实上限:输出取目录声明的可协商上限(未声明时即默认值)。
1674
+ // 上游注册目录另有 maxReasoningTokenLength:思考开启时输出上限更低(如 DeepSeek V4 系
1675
+ // 非思考 384K / 思考 128K)。思考映射整体停用(effortsMode 'none')时才放开到非思考上限。
1676
+ let ceiling = key === 'maxTokens' ? (model?.defaults?.maxTokensCeiling ?? inheritedValue) : inheritedValue;
1677
+ let reasoningCapped = false;
1678
+ if (key === 'maxTokens') {
1679
+ const mr = model?.defaults?.maxReasoningTokenLength;
1680
+ const thinkingOn = (draft?.effortsMode ?? 'inherit') !== 'none';
1681
+ if (thinkingOn && Number.isSafeInteger(mr) && mr > 0 && mr < ceiling) {
1682
+ ceiling = mr;
1683
+ reasoningCapped = true;
1684
+ }
1685
+ }
1212
1686
  const draftValue = Number.parseInt(draft?.[key], 10);
1213
1687
  const sliderValue = inherited ? inheritedValue : draftValue;
1214
- const stops = capacityStops(key, inheritedValue, Number.isFinite(sliderValue) ? sliderValue : undefined);
1688
+ const stops = capacityStops(key, ceiling, Number.isFinite(sliderValue) ? sliderValue : undefined);
1215
1689
  return h('div', { style: { display: 'grid', gap: 6 } },
1216
1690
  h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' } },
1217
1691
  h('span', { style: style.label }, label),
@@ -1220,13 +1694,14 @@ function ModelSettingsEditor({ model, draft, error, fieldErrors, disabled, onCha
1220
1694
  type: 'checkbox', checked: inherited, disabled,
1221
1695
  'aria-label': `继承 ${label}`,
1222
1696
  style: { width: 18, height: 18, margin: 0, flex: '0 0 auto', accentColor: 'var(--dsw-alias-brand-primary, Highlight)' },
1223
- onChange: (event) => onChange({ [key]: event.target.checked ? '' : String(stops[stops.length - 1] ?? '') })
1697
+ // 取消继承先落到目录默认值,再由用户向顶档拖;不直接跳到理论上限。
1698
+ onChange: (event) => onChange({ [key]: event.target.checked ? '' : String(inheritedValue ?? stops[stops.length - 1] ?? '') })
1224
1699
  }),
1225
1700
  h('span', { style: { fontSize: 12 } }, '继承目录默认')),
1226
1701
  h('span', { style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary, #64748b)', fontVariantNumeric: 'tabular-nums' } },
1227
1702
  inherited
1228
- ? `目录默认 ${formatTokenCount(inheritedValue)}`
1229
- : `当前 ${formatTokenCount(sliderValue)}(${Number.isFinite(sliderValue) ? sliderValue : '—'} token)`)),
1703
+ ? `目录默认 ${formatTokenCount(inheritedValue)}${ceiling && ceiling !== inheritedValue ? ` · 上限 ${formatTokenCount(ceiling)}${reasoningCapped ? '(思考)' : ''}` : ''}`
1704
+ : `当前 ${formatTokenCount(sliderValue)}(${Number.isFinite(sliderValue) ? sliderValue : '—'} token)${reasoningCapped ? ` · 思考上限 ${formatTokenCount(ceiling)}` : ''}`)),
1230
1705
  h(CapacitySlider, {
1231
1706
  choices: stops,
1232
1707
  value: stops.includes(sliderValue) ? sliderValue : stops[0],
@@ -1423,6 +1898,56 @@ function ModelRow({ plan, model, disabled, routingError, editor, draftError, fie
1423
1898
  * @param {object} props 组件属性
1424
1899
  * @returns {object} 元素树
1425
1900
  */
1901
+ // ── 图片生成:Seedream 默认模型与单开关(启用即确认计费) ────────────────────
1902
+
1903
+ function MediaCard({ snapshot, busy, onToggleImage, onSelectModel, onNavigate }) {
1904
+ const media = snapshot?.media ?? { riskAcknowledged: false, imageTool: false, imageModel: DEFAULT_IMAGE_MODEL };
1905
+ const acknowledged = media.riskAcknowledged === true;
1906
+ const enabled = acknowledged && media.imageTool === true;
1907
+ const activeId = snapshot?.active?.['agent-plan'] ?? null;
1908
+ const account = (Array.isArray(snapshot?.accounts) ? snapshot.accounts : []).find((item) => item?.id === activeId) ?? null;
1909
+ const providerOn = providerEnabledOf(snapshot, 'agent-plan');
1910
+ const disabled = busy !== null;
1911
+ const tone = enabled ? 'success' : 'muted';
1912
+ const state = enabled ? '图片工具已开启' : '图片工具未开启';
1913
+
1914
+ return h('section', { className: 'vcp-plan vcp-card', 'data-section': '04', 'aria-label': '图片生成' },
1915
+ h(SectionHeading, {
1916
+ eyebrow: 'IMAGE GENERATION',
1917
+ title: '图片生成',
1918
+ description: '调用 Agent Plan 内的 Seedream 模型;原图与聊天预览分开保存,下载保留请求的输出格式。',
1919
+ action: h('div', { className: 'vcp-actions' }, h(StatusChip, { tone }, state))
1920
+ }),
1921
+ h('p', { className: 'vcp-media-billing' },
1922
+ h('strong', null, '图片生成按用量计费'),
1923
+ ',图片调用消耗 Agent 套餐 AFP 额度;关闭后已生成的附件保留。'),
1924
+ h('div', { className: 'vcp-media-tool' },
1925
+ h('div', { className: 'vcp-media-tool-copy' },
1926
+ h('span', { className: 'vcp-media-tool-name' }, '生图(Seedream) ', h('code', null, 'volc_imagine')),
1927
+ h('p', { style: style.muted }, '文生图与参考图编辑;原始 PNG/JPEG 文件和会话预览分别入库。')),
1928
+ h('label', { className: 'vcp-plan-toggle', title: '启用即确认图片生成的计费规则' },
1929
+ h('input', {
1930
+ className: 'vcp-switch-input', type: 'checkbox',
1931
+ checked: enabled, disabled,
1932
+ 'aria-label': '启用图片生成',
1933
+ onChange: (event) => onToggleImage(Boolean(event.target.checked))
1934
+ }),
1935
+ h('span', null, '启用'))),
1936
+ h('div', { className: 'vcp-media-tool' },
1937
+ h('label', { className: 'vcp-media-model' },
1938
+ h('span', null, '默认图片模型(启用后可改;单次调用可覆盖)'),
1939
+ h('select', {
1940
+ className: 'vcp-select', style: style.input, value: media.imageModel ?? DEFAULT_IMAGE_MODEL,
1941
+ disabled: disabled || !acknowledged, 'aria-label': '默认图片模型',
1942
+ onChange: event => onSelectModel(event.target.value)
1943
+ }, IMAGE_MODEL_OPTIONS.map(option => h('option', { key: option.id, value: option.id }, option.label))))),
1944
+ enabled && (!providerOn || !account)
1945
+ ? h(Notice, { tone: 'warn', role: 'alert', action: h('button', { type: 'button', style: style.btn, onClick: () => onNavigate('agent-plan') }, '前往 Agent 套餐') }, !providerOn
1946
+ ? 'Agent 套餐当前已停用:媒体工具需要启用 Agent 套餐并选择账号后才能调用。'
1947
+ : 'Agent 套餐尚未选择账号:请先在 Agent 套餐页选择账号,图片工具才能调用。')
1948
+ : null);
1949
+ }
1950
+
1426
1951
  function PlanCard({ plan, snapshot, rawQuota, busy, quotaBusy, onSelect, onModels, onQuota, onToggleProvider, onToggleModel, onSaveModelSettings, onResetModelSettings, onGoLogin, onScrollAccounts }) {
1427
1952
  const accounts = Array.isArray(snapshot?.accounts) ? snapshot.accounts : [];
1428
1953
  const activeId = snapshot?.active?.[plan] ?? null;
@@ -1557,22 +2082,33 @@ function PlanCard({ plan, snapshot, rawQuota, busy, quotaBusy, onSelect, onModel
1557
2082
  account && !auth.oauth && !auth.inference
1558
2083
  ? h(Notice, { tone: 'warn', action: h('button', { type: 'button', style: style.btn, disabled, onClick: onScrollAccounts }, '去账号区编辑') }, '该账号尚未配置此套餐的推理凭据,请在账号高级配置中填写引用名,或使用网页登录。')
1559
2084
  : null,
1560
- h('section', { className: 'vcp-quota-section', 'aria-busy': Boolean(quotaBusy), 'aria-label': `${PLAN_TITLES[plan]}额度` },
2085
+ h('section', { className: 'vcp-quota-section vcp-plan-section', 'aria-busy': Boolean(quotaBusy), 'aria-label': `${PLAN_TITLES[plan]}额度` },
1561
2086
  h('div', { className: 'vcp-heading' },
1562
2087
  h('h4', { style: { margin: 0, fontSize: 13, fontWeight: 650 } }, '套餐额度'),
1563
- h('button', { type: 'button', style: style.btn, disabled: disabled || quotaBusy || !auth.quota, 'aria-busy': quotaBusy || undefined, onClick: () => onQuota(plan) }, quotaBusy ? '正在刷新额度…' : quota?.state === 'error' ? '重试额度查询' : '刷新额度')),
2088
+ h('button', { type: 'button', style: style.btn, disabled: disabled || quotaBusy || !auth.quota, 'aria-busy': quotaBusy || undefined, onClick: () => onQuota(plan) },
2089
+ quotaBusy && !quota ? '正在查询额度…' : quota?.state === 'error' ? '重试额度查询' : '刷新额度')),
1564
2090
  account && !auth.quota && (!auth.oauth || auth.bound)
1565
2091
  ? h(Notice, { tone: 'warn', action: auth.oauth
1566
2092
  ? h('button', { type: 'button', style: style.btn, disabled, onClick: () => onGoLogin(account.id) }, '去账号区重新登录')
1567
2093
  : h('button', { type: 'button', style: style.btn, disabled, onClick: onScrollAccounts }, '去账号区编辑') },
1568
2094
  auth.oauth ? '该套餐的登录身份暂不可查询额度,请重新登录后重试。' : '该账号缺少 AK/SK 凭据引用,额度窗口无法查询。')
1569
2095
  : null,
1570
- quotaBusy ? h('p', { role: 'status', style: style.muted }, `正在查询${PLAN_TITLES[plan]}的额度…`) : null,
2096
+ // 已有数据时轮询静默进行(按钮带 aria-busy),避免每轮都闪一次状态文字。
2097
+ quotaBusy && !quota ? h('p', { role: 'status', style: style.muted }, `正在查询${PLAN_TITLES[plan]}的额度…`) : null,
1571
2098
  !account ? h('p', { style: style.muted }, '请先登录或添加账号,再为此套餐选择账号。')
1572
2099
  : !quota && !auth.quota ? h('p', { style: style.muted }, '完成此套餐的登录绑定或额度鉴权配置后,即可查询额度。')
1573
2100
  : h(QuotaWindows, { quota }),
1574
- quota?.updatedAt ? h('p', { style: style.muted }, `额度更新时间:${formatTime(quota.updatedAt)}`) : null),
1575
- h('section', { className: 'vcp-section', 'aria-label': `${PLAN_TITLES[plan]}模型目录` },
2101
+ // 自动刷新失败不覆盖已有窗口,只在这里说明数据还是上一次的。
2102
+ quota?.refreshError
2103
+ ? h('div', { role: 'status', style: style.warn },
2104
+ h('span', null, `额度更新失败:${describeError(quota.refreshError)};当前显示 ${formatTime(quota.updatedAt)} 的数据,稍后自动重试。`),
2105
+ // 登录/协议失效是唯一能直接修好的类别:给出到账号区重新登录的入口。
2106
+ quota.errorKind === 'auth' && account
2107
+ ? h('button', { type: 'button', style: style.btn, disabled, onClick: () => onGoLogin(account.id) }, '去重新登录')
2108
+ : null)
2109
+ : null,
2110
+ quota?.updatedAt ? h('p', { style: style.muted }, `额度采集于 ${formatTime(quota.updatedAt)} · 后台会定期刷新`) : null),
2111
+ h('section', { className: 'vcp-section vcp-plan-section', 'aria-label': `${PLAN_TITLES[plan]}模型目录` },
1576
2112
  h('div', { className: 'vcp-heading' },
1577
2113
  h('div', { className: 'vcp-heading-copy' },
1578
2114
  h('h4', { style: { margin: 0, fontSize: 13, fontWeight: 650 } }, '模型目录'),
@@ -1606,7 +2142,7 @@ function PlanCard({ plan, snapshot, rawQuota, busy, quotaBusy, onSelect, onModel
1606
2142
  : h('p', { style: style.muted }, catalog
1607
2143
  ? '该目录暂无模型明细(旧缓存可能没有模型列表,重新拉取模型后可用)。'
1608
2144
  : !account ? '选择账号后显示该套餐的模型目录。' : '模型目录:尚未拉取。')),
1609
- h('details', { className: 'vcp-details' },
2145
+ h('details', { className: 'vcp-details vcp-plan-section' },
1610
2146
  h('summary', { style: style.summary }, '套餐高级信息与技术标识'),
1611
2147
  h('div', { className: 'vcp-details-body' },
1612
2148
  h('p', { style: style.muted }, PLAN_HINTS[plan]),
@@ -1667,6 +2203,7 @@ function AccountPanel({ snapshot, editor, confirmDelete, loginConfirm, login, bu
1667
2203
  account.credentialError ? h('p', { role: 'alert', style: style.error }, `凭据状态:${describeError(account.credentialError)}`) : null,
1668
2204
  h('div', { className: 'vcp-chip-row' }, PLANS.map((plan) => h('span', { key: plan, style: style.chip },
1669
2205
  `${plan === 'agent-plan' ? 'Agent' : '编程'}套餐:${snapshot?.active?.[plan] === account.id ? (providerEnabledOf(snapshot, plan) ? '当前使用' : '已选择 · 已停用') : '未选用'}${isOAuth(account) ? ` · ${account.oauthProfiles?.[plan] ? '已绑定' : '未绑定'}` : ''}`))),
2206
+ h(LoginExpiryNote, { account }),
1670
2207
  h('div', { className: 'vcp-actions' }, PLANS.map(plan => {
1671
2208
  const selected = snapshot?.active?.[plan] === account.id;
1672
2209
  if (!planAuth(account, plan).inference || (selected && providerEnabledOf(snapshot, plan))) return null;
@@ -1749,6 +2286,7 @@ function AccountPanel({ snapshot, editor, confirmDelete, loginConfirm, login, bu
1749
2286
  login.message ? h('p', { style: style.muted }, login.message) : null,
1750
2287
  login.url && !loginUrl ? h(Notice, { tone: 'error', role: 'alert' }, '登录链接未通过安全校验,已隐藏;请重新发起登录。') : null,
1751
2288
  loginUrl ? h('a', { href: loginUrl, target: '_blank', rel: 'noopener noreferrer', style: { fontSize: 12, color: 'var(--dsw-alias-link, inherit)' } }, '打开官方登录链接') : null,
2289
+ login.state === 'waiting' ? h('p', { style: style.muted }, '授权码 10 分钟内有效;登录完成后官方 SSO 登录态有效期 48 小时,有效期内由官方 CLI 自动续期。') : null,
1752
2290
  loginUrl && login.state === 'waiting'
1753
2291
  ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } },
1754
2292
  h('label', { style: style.field },
@@ -1843,6 +2381,8 @@ function VolcengineProviderSection({ client }) {
1843
2381
  const [loading, setLoading] = react.useState(true);
1844
2382
  const [busy, setBusy] = react.useState(null);
1845
2383
  const [notice, setNotice] = react.useState(null);
2384
+ // 重开设置页时先用模块里留存的上次额度,首帧不再是「未获取」。
2385
+ // 额度快照由 Host 中间层随 read / snapshots 下发,首屏不再是空的。
1846
2386
  const [quotas, setQuotas] = react.useState({});
1847
2387
  const [quotaBusy, setQuotaBusy] = react.useState({});
1848
2388
  const quotaPendingRef = react.useRef(new Map());
@@ -1850,19 +2390,46 @@ function VolcengineProviderSection({ client }) {
1850
2390
  const [confirmDelete, setConfirmDelete] = react.useState(null);
1851
2391
  const [loginConfirm, setLoginConfirm] = react.useState(null);
1852
2392
  const [login, setLogin] = react.useState({ jobId: null, state: 'idle', message: '', url: null, authMode: null });
2393
+ const [settingsTab, setSettingsTab] = react.useState('agent-plan');
2394
+ const settingsTabPrefix = react.useRef(`vcp-tabs-${Math.random().toString(36).slice(2, 9)}`).current;
2395
+ const tabInitializedRef = react.useRef(false);
2396
+ const pendingNavigationRef = react.useRef(null);
1853
2397
 
1854
2398
  const aliveRef = react.useRef(true);
1855
2399
  const busyRef = react.useRef(null);
1856
2400
  const handledLoginRef = react.useRef(null);
1857
2401
  const readSequenceRef = react.useRef(0);
1858
2402
  const quotaEpochRef = react.useRef(0);
1859
- const accountFingerprintRef = react.useRef(null);
2403
+ const revisionRef = react.useRef(null);
2404
+ const fingerprintRef = react.useRef(null);
1860
2405
 
1861
2406
  react.useEffect(() => {
1862
2407
  aliveRef.current = true;
1863
2408
  return () => { aliveRef.current = false; };
1864
2409
  }, []);
1865
2410
 
2411
+ react.useEffect(() => {
2412
+ if (tabInitializedRef.current || !snapshot) return;
2413
+ tabInitializedRef.current = true;
2414
+ if (!snapshot.accounts?.length) setSettingsTab('accounts');
2415
+ }, [snapshot]);
2416
+
2417
+ react.useEffect(() => {
2418
+ const pending = pendingNavigationRef.current;
2419
+ if (!pending || pending.tab !== settingsTab) return undefined;
2420
+ pendingNavigationRef.current = null;
2421
+ const timer = setTimeout(() => {
2422
+ try {
2423
+ const target = document.getElementById(pending.target) ?? document.getElementById(`${settingsTabPrefix}-panel`);
2424
+ if (!target) return;
2425
+ target.scrollIntoView({ behavior: 'smooth', block: 'start' });
2426
+ target.setAttribute('tabindex', '-1');
2427
+ target.focus({ preventScroll: true });
2428
+ } catch { /* 非浏览器测试环境 */ }
2429
+ }, 0);
2430
+ return () => clearTimeout(timer);
2431
+ }, [settingsTab, settingsTabPrefix]);
2432
+
1866
2433
  /** 把一次 read 返回的整份快照落到状态里。 */
1867
2434
  const applySnapshot = react.useCallback((value) => {
1868
2435
  if (!aliveRef.current || !value) return;
@@ -1873,19 +2440,22 @@ function VolcengineProviderSection({ client }) {
1873
2440
  profiles: account.oauthProfiles, apiKeyRefs: account.apiKeyRefs, accessKeyRef: account.accessKeyRef,
1874
2441
  secretKeyRef: account.secretKeyRef, hasApiKeys: account.hasApiKeys, hasQuotaAccess: account.hasQuotaAccess
1875
2442
  })) });
1876
- if (accountFingerprintRef.current !== fingerprint) {
1877
- accountFingerprintRef.current = fingerprint;
2443
+ if (fingerprintRef.current !== fingerprint) {
2444
+ fingerprintRef.current = fingerprint;
1878
2445
  quotaEpochRef.current += 1;
1879
2446
  setQuotaBusy({});
1880
- setQuotas({});
1881
2447
  }
2448
+ // 额度快照由 Host 中间层下发:打开设置就有数据,不再依赖页面自己发查询。
2449
+ setQuotas(value.quotas ?? {});
1882
2450
  setSnapshot(value);
2451
+ revisionRef.current = value.revision ?? null;
1883
2452
  setEditor(previous => previous?.mode === 'edit' && !(value.accounts ?? []).some(account => account.id === previous.id) ? null : previous);
1884
2453
  setLoading(false);
1885
2454
  const incoming = value.login ? normalizeLogin(value.login) : null;
1886
2455
  if (incoming) setLogin(incoming);
1887
2456
  }, []);
1888
2457
 
2458
+
1889
2459
  /** 重新读取全部状态。 */
1890
2460
  const refresh = react.useCallback(async () => {
1891
2461
  const sequence = ++readSequenceRef.current;
@@ -1991,7 +2561,8 @@ function VolcengineProviderSection({ client }) {
1991
2561
  }
1992
2562
  });
1993
2563
 
1994
- const pullQuota = async (plan) => {
2564
+ /** 手动刷新:Host 立即重采一次并返回结果;自动刷新只读中间层,不经过这里。 */
2565
+ const refreshQuota = async (plan) => {
1995
2566
  const accountId = snapshot?.active?.[plan] ?? null;
1996
2567
  const epoch = quotaEpochRef.current;
1997
2568
  if (!accountId || quotaPendingRef.current.get(plan) === epoch) return;
@@ -2000,10 +2571,10 @@ function VolcengineProviderSection({ client }) {
2000
2571
  try {
2001
2572
  const value = await client.invoke({ op: 'quota', plan, accountId, force: true });
2002
2573
  if (!aliveRef.current || epoch !== quotaEpochRef.current) return;
2003
- setQuotas((previous) => ({ ...previous, [plan]: { ...value, accountId, plan } }));
2574
+ setQuotas(previous => ({ ...previous, [`${accountId}:${plan}`]: { at: Date.now(), value } }));
2004
2575
  } catch (error) {
2005
2576
  if (!aliveRef.current || epoch !== quotaEpochRef.current) return;
2006
- setQuotas((previous) => ({ ...previous, [plan]: { accountId, plan, state: 'error', windows: [], error: describeError(error), updatedAt: new Date().toISOString() } }));
2577
+ setNotice({ ok: false, text: `刷新额度失败:${describeError(error)}` });
2007
2578
  } finally {
2008
2579
  if (quotaPendingRef.current.get(plan) === epoch) {
2009
2580
  quotaPendingRef.current.delete(plan);
@@ -2012,6 +2583,62 @@ function VolcengineProviderSection({ client }) {
2012
2583
  }
2013
2584
  };
2014
2585
 
2586
+ // 页面只读中间层:Host 负责定时采集,这里按固定间隔拉一次内存快照。
2587
+ const quotaTargets = JSON.stringify(PLANS.map(plan => [plan, snapshot?.active?.[plan] ?? null]));
2588
+ react.useEffect(() => {
2589
+ const active = JSON.parse(quotaTargets).filter(([, accountId]) => Boolean(accountId));
2590
+ if (!active.length) return undefined;
2591
+ let stopped = false;
2592
+ let timer = null;
2593
+ const schedule = () => {
2594
+ if (stopped) return;
2595
+ if (timer) clearTimeout(timer);
2596
+ timer = setTimeout(poll, QUOTA_POLL_MS);
2597
+ if (timer && typeof timer.unref === 'function') timer.unref();
2598
+ };
2599
+ const poll = async () => {
2600
+ if (stopped) return;
2601
+ // 页面隐藏时只跳过本轮读取,回前台由 visibilitychange 立即补读。
2602
+ if (typeof document !== 'undefined' && document.hidden === true) { schedule(); return; }
2603
+ let view = null;
2604
+ try {
2605
+ view = await client.invoke({ op: 'snapshots' });
2606
+ if (stopped || !aliveRef.current) return;
2607
+ if (view?.quotas) setQuotas(view.quotas);
2608
+ // Host 采集器更新了模型目录或账号元数据:revision 变化时重读整份快照(含模型列表)。
2609
+ if (view?.revision && revisionRef.current && view.revision !== revisionRef.current) void refresh();
2610
+ } catch { /* 读中间层失败不打扰用户,下一轮再读 */ }
2611
+ // 冷启动时中间层可能还是空的:补一次采集请求,Host 无快照时会等待并回填。
2612
+ for (const [plan, accountId] of active) {
2613
+ if (!aliveRef.current || stopped) return;
2614
+ if (view?.quotas?.[`${accountId}:${plan}`]) continue;
2615
+ try {
2616
+ const value = await client.invoke({ op: 'quota', plan, accountId });
2617
+ if (!aliveRef.current || stopped) return;
2618
+ if (value) setQuotas(previous => ({ ...previous, [`${accountId}:${plan}`]: { at: Date.now(), value } }));
2619
+ } catch { /* 采集失败等下一轮或 Host 退避后再试 */ }
2620
+ }
2621
+ schedule();
2622
+ };
2623
+ void poll();
2624
+ schedule();
2625
+ const onVisible = () => {
2626
+ if (typeof document !== 'undefined' && document.hidden === true) return;
2627
+ if (timer) clearTimeout(timer);
2628
+ void poll();
2629
+ };
2630
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
2631
+ document.addEventListener('visibilitychange', onVisible);
2632
+ }
2633
+ return () => {
2634
+ stopped = true;
2635
+ if (timer) clearTimeout(timer);
2636
+ if (typeof document !== 'undefined' && typeof document.removeEventListener === 'function') {
2637
+ document.removeEventListener('visibilitychange', onVisible);
2638
+ }
2639
+ };
2640
+ }, [quotaTargets, client, refresh]);
2641
+
2015
2642
  // 套餐启停:只改启用状态,不动账号选择,也不动模型参数。
2016
2643
  const toggleProvider = (plan, enabled) => run(`provider:${plan}`, async () => {
2017
2644
  if (!snapshot?.revision) return;
@@ -2060,6 +2687,30 @@ function VolcengineProviderSection({ client }) {
2060
2687
  }
2061
2688
  });
2062
2689
 
2690
+ // 图片工具单开关:开启即确认按用量计费,一次写入确认位与开关位;关闭后服务端会顺带关闭工具。
2691
+ const toggleMediaImage = (enabled) => run('media:image', async () => {
2692
+ if (!snapshot?.revision) return;
2693
+ try {
2694
+ const value = await client.invoke({ op: 'setMedia', riskAcknowledged: enabled, imageTool: enabled, revision: snapshot.revision });
2695
+ applySnapshot(value);
2696
+ setNotice({ ok: true, text: enabled ? '图片工具已开启,按用量消耗 Agent 套餐 AFP 额度。' : '图片工具已关闭,已生成的附件保留。' });
2697
+ } catch (error) {
2698
+ await reportSaveError(error, '更新图片工具失败');
2699
+ }
2700
+ });
2701
+
2702
+ const selectMediaModel = (imageModel) => run('media:model', async () => {
2703
+ if (!snapshot?.revision) return;
2704
+ try {
2705
+ const value = await client.invoke({ op: 'setMedia', imageModel, revision: snapshot.revision });
2706
+ applySnapshot(value);
2707
+ const label = IMAGE_MODEL_OPTIONS.find(option => option.id === imageModel)?.label ?? imageModel;
2708
+ setNotice({ ok: true, text: `默认图片模型已切换为 ${label}。` });
2709
+ } catch (error) {
2710
+ await reportSaveError(error, '更新默认图片模型失败');
2711
+ }
2712
+ });
2713
+
2063
2714
  const startLogin = (accountId) => run('login', async () => {
2064
2715
  if (!snapshot?.revision) return;
2065
2716
  try {
@@ -2114,11 +2765,14 @@ function VolcengineProviderSection({ client }) {
2114
2765
  setNotice(null);
2115
2766
  };
2116
2767
 
2117
- // 从套餐卡片一键回到账号区:滚动到账号面板并为指定账号展开登录确认。
2768
+ const navigateSettings = (tab, target) => {
2769
+ pendingNavigationRef.current = { tab, target };
2770
+ setSettingsTab(tab);
2771
+ };
2772
+
2773
+ // 从套餐卡片一键回到账号区:等目标面板显示后再滚动并聚焦。
2118
2774
  const scrollToAccounts = () => {
2119
- try { document.getElementById('vcp-account-panel')?.scrollIntoView({ behavior: 'smooth', block: 'start' }); } catch {
2120
- // 非浏览器预览环境没有 document:登录确认本身会强制展开账号区。
2121
- }
2775
+ navigateSettings('accounts', 'vcp-account-panel');
2122
2776
  };
2123
2777
  const goAccountLogin = (accountId) => { scrollToAccounts(); requestLogin(accountId); };
2124
2778
 
@@ -2293,6 +2947,8 @@ function VolcengineProviderSection({ client }) {
2293
2947
  };
2294
2948
 
2295
2949
  const busyAccount = busy !== null;
2950
+ // 额度快照按「账号:套餐」存于 Host 中间层,这里只按当前选中账号取值。
2951
+ const quotaOf = (plan) => quotas[`${snapshot?.active?.[plan] ?? ''}:${plan}`]?.value;
2296
2952
  const loginActive = LOGIN_ACTIVE_STATES.includes(login.state);
2297
2953
  const planBusy = busy ?? (loginActive ? 'login-active' : null);
2298
2954
 
@@ -2300,6 +2956,13 @@ function VolcengineProviderSection({ client }) {
2300
2956
  : loginActive ? '登录进行中'
2301
2957
  : loading && !snapshot ? '正在读取设置'
2302
2958
  : snapshot ? `${snapshot.accounts?.length ?? 0} 个账号 · 2 个套餐` : '等待连接';
2959
+ const onSettingsTabKey = (event) => {
2960
+ const next = settingsTabAfter(event.key, settingsTab);
2961
+ if (!next) return;
2962
+ event.preventDefault();
2963
+ setSettingsTab(next);
2964
+ try { document.getElementById(`${settingsTabPrefix}-tab-${next}`)?.focus(); } catch { /* 非浏览器测试环境 */ }
2965
+ };
2303
2966
 
2304
2967
  return h('div', { className: 'vcp-settings', style: style.root },
2305
2968
  h('header', { className: 'vcp-header vcp-hero' },
@@ -2331,21 +2994,28 @@ function VolcengineProviderSection({ client }) {
2331
2994
  !snapshot
2332
2995
  ? (loading ? h('p', { role: 'status', style: style.muted }, '正在读取方舟账号状态…') : null)
2333
2996
  : h('div', { className: 'vcp-content', 'data-empty': !(snapshot.accounts?.length) },
2334
- h('div', { className: 'vcp-plans vcp-plan-workspace' },
2997
+ h('div', { className: 'vcp-tabs', role: 'tablist', 'aria-label': '火山方舟设置分区', onKeyDown: onSettingsTabKey },
2998
+ SETTINGS_TABS.map(tab => h('button', {
2999
+ key: tab.id, type: 'button', role: 'tab', id: `${settingsTabPrefix}-tab-${tab.id}`,
3000
+ className: 'vcp-tab', 'aria-selected': settingsTab === tab.id, 'aria-controls': `${settingsTabPrefix}-panel`,
3001
+ tabIndex: settingsTab === tab.id ? 0 : -1, onClick: () => setSettingsTab(tab.id)
3002
+ }, tab.id === 'accounts' ? `${tab.label} (${snapshot.accounts?.length ?? 0})` : tab.label))),
3003
+ h('div', { className: 'vcp-tabpanel', role: 'tabpanel', id: `${settingsTabPrefix}-panel`, 'aria-labelledby': `${settingsTabPrefix}-tab-${settingsTab}` },
3004
+ PLANS.map(plan => h('div', { key: plan, className: 'vcp-tab-section', hidden: settingsTab !== plan },
2335
3005
  h(PlanCard, {
2336
- plan: 'agent-plan', snapshot, rawQuota: quotas['agent-plan'], busy: planBusy, quotaBusy: Boolean(quotaBusy['agent-plan']),
2337
- onSelect: selectAccount, onModels: pullModels, onQuota: pullQuota,
2338
- onToggleProvider: toggleProvider, onToggleModel: toggleModel,
2339
- onSaveModelSettings: saveModelSettings, onResetModelSettings: resetModelSettings,
2340
- onGoLogin: goAccountLogin, onScrollAccounts: scrollToAccounts
2341
- }),
2342
- h(PlanCard, {
2343
- plan: 'coding-plan', snapshot, rawQuota: quotas['coding-plan'], busy: planBusy, quotaBusy: Boolean(quotaBusy['coding-plan']),
2344
- onSelect: selectAccount, onModels: pullModels, onQuota: pullQuota,
3006
+ plan, snapshot, rawQuota: quotaOf(plan), busy: planBusy, quotaBusy: Boolean(quotaBusy[plan]),
3007
+ onSelect: selectAccount, onModels: pullModels, onQuota: refreshQuota,
2345
3008
  onToggleProvider: toggleProvider, onToggleModel: toggleModel,
2346
3009
  onSaveModelSettings: saveModelSettings, onResetModelSettings: resetModelSettings,
2347
3010
  onGoLogin: goAccountLogin, onScrollAccounts: scrollToAccounts
3011
+ }))),
3012
+ h('div', { className: 'vcp-tab-section', hidden: settingsTab !== 'media' },
3013
+ h(MediaCard, {
3014
+ snapshot, busy: planBusy,
3015
+ onToggleImage: toggleMediaImage, onSelectModel: selectMediaModel,
3016
+ onNavigate: tab => navigateSettings(tab, `${settingsTabPrefix}-panel`)
2348
3017
  })),
3018
+ h('div', { className: 'vcp-tab-section', hidden: settingsTab !== 'accounts' },
2349
3019
  h(AccountPanel, {
2350
3020
  snapshot, editor, confirmDelete, loginConfirm, login, busy,
2351
3021
  onNew: openNew, onEdit: openEdit, onCancelEdit: () => setEditor(null),
@@ -2360,7 +3030,7 @@ function VolcengineProviderSection({ client }) {
2360
3030
  onCancelLoginConfirm: () => setLoginConfirm(null),
2361
3031
  onCancelLogin: () => { void cancelLogin(); },
2362
3032
  onSubmitLoginCode: (code) => { void submitLoginCode(code); }
2363
- })));
3033
+ })))));
2364
3034
  }
2365
3035
 
2366
3036
  // ── 插件装配 ─────────────────────────────────────────────────────────────────
@@ -2465,6 +3135,8 @@ function apply(ctx) {
2465
3135
  console.error('[dsh-volcengine-provider] 设置页注册失败:', error);
2466
3136
  }
2467
3137
 
3138
+ applyVolcMediaViews(ctx);
3139
+
2468
3140
  // 4) 生命周期清理:定时器、远端挂载。
2469
3141
  ctx.effect(() => () => {
2470
3142
  runtime.disposed = true;