dsh-volcengine-provider 0.2.16 → 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/README.md +6 -2
- package/docs/changelog.md +9 -0
- package/docs/client-media-preview.png +0 -0
- package/docs/client-media-settings-preview.png +0 -0
- package/docs/client-settings-preview-dark.png +0 -0
- package/docs/client-settings-preview-empty.png +0 -0
- package/docs/client-settings-preview-mobile-dark.png +0 -0
- package/docs/client-settings-preview-models.png +0 -0
- package/docs/client-settings-preview.png +0 -0
- package/docs/development.md +3 -1
- package/docs/media-generation.md +71 -0
- package/docs/usage.md +25 -4
- package/docs/validation.md +40 -0
- package/lib/cli.mjs +44 -1
- package/lib/client.js +725 -69
- package/lib/index.mjs +38 -5
- package/lib/manager.mjs +288 -35
- package/lib/media-config.mjs +39 -0
- package/lib/media-image-route.mjs +110 -0
- package/lib/media-image.mjs +212 -0
- package/lib/media.mjs +263 -0
- package/lib/oauth-expiry.mjs +47 -0
- package/lib/snapshot.mjs +105 -0
- package/lib/state.mjs +5 -2
- package/package.json +18 -2
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:
|
|
253
|
-
title: { margin: 0, fontSize:
|
|
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:
|
|
261
|
-
row: { display: 'flex', alignItems: 'center', gap:
|
|
262
|
-
field: { display: 'flex', flexDirection: 'column', gap:
|
|
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:
|
|
266
|
-
borderRadius:
|
|
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:
|
|
272
|
-
padding: '
|
|
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:
|
|
278
|
-
padding: '
|
|
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:
|
|
286
|
-
padding: '
|
|
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:
|
|
303
|
-
borderRadius:
|
|
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:
|
|
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:
|
|
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:
|
|
313
|
-
.vcp-content{display:flex;flex-direction:column;gap:
|
|
314
|
-
.vcp-account-body{display:flex;flex-direction:column;gap:
|
|
315
|
-
.vcp-header{display:flex;align-items:center;gap:
|
|
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:
|
|
318
|
-
.vcp-account{display:flex;flex-direction:column;gap:
|
|
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:
|
|
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
|
|
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
|
|
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:
|
|
329
|
-
.vcp-content{gap:
|
|
330
|
-
.vcp-brand-mark{display:flex;align-items:center;justify-content:center;flex:none;width:
|
|
331
|
-
.vcp-hero-subtitle{margin:
|
|
332
|
-
.vcp-plan
|
|
333
|
-
.vcp-switch-input{appearance:none;-webkit-appearance:none;position:relative;flex:none;width:
|
|
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:
|
|
336
|
-
.vcp-model-list{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,280px),1fr));gap:
|
|
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:
|
|
339
|
-
@media(max-width:680px){.vcp-hero{padding:
|
|
340
|
-
@media(max-width:420px){.vcp-plan{padding:
|
|
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
|
-
|
|
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
|
// 先显示后端给的原因,再补一条网页登录的出路。
|
|
@@ -1439,6 +1898,56 @@ function ModelRow({ plan, model, disabled, routingError, editor, draftError, fie
|
|
|
1439
1898
|
* @param {object} props 组件属性
|
|
1440
1899
|
* @returns {object} 元素树
|
|
1441
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
|
+
|
|
1442
1951
|
function PlanCard({ plan, snapshot, rawQuota, busy, quotaBusy, onSelect, onModels, onQuota, onToggleProvider, onToggleModel, onSaveModelSettings, onResetModelSettings, onGoLogin, onScrollAccounts }) {
|
|
1443
1952
|
const accounts = Array.isArray(snapshot?.accounts) ? snapshot.accounts : [];
|
|
1444
1953
|
const activeId = snapshot?.active?.[plan] ?? null;
|
|
@@ -1573,22 +2082,33 @@ function PlanCard({ plan, snapshot, rawQuota, busy, quotaBusy, onSelect, onModel
|
|
|
1573
2082
|
account && !auth.oauth && !auth.inference
|
|
1574
2083
|
? h(Notice, { tone: 'warn', action: h('button', { type: 'button', style: style.btn, disabled, onClick: onScrollAccounts }, '去账号区编辑') }, '该账号尚未配置此套餐的推理凭据,请在账号高级配置中填写引用名,或使用网页登录。')
|
|
1575
2084
|
: null,
|
|
1576
|
-
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]}额度` },
|
|
1577
2086
|
h('div', { className: 'vcp-heading' },
|
|
1578
2087
|
h('h4', { style: { margin: 0, fontSize: 13, fontWeight: 650 } }, '套餐额度'),
|
|
1579
|
-
h('button', { type: 'button', style: style.btn, disabled: disabled || quotaBusy || !auth.quota, 'aria-busy': quotaBusy || undefined, onClick: () => onQuota(plan) },
|
|
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' ? '重试额度查询' : '刷新额度')),
|
|
1580
2090
|
account && !auth.quota && (!auth.oauth || auth.bound)
|
|
1581
2091
|
? h(Notice, { tone: 'warn', action: auth.oauth
|
|
1582
2092
|
? h('button', { type: 'button', style: style.btn, disabled, onClick: () => onGoLogin(account.id) }, '去账号区重新登录')
|
|
1583
2093
|
: h('button', { type: 'button', style: style.btn, disabled, onClick: onScrollAccounts }, '去账号区编辑') },
|
|
1584
2094
|
auth.oauth ? '该套餐的登录身份暂不可查询额度,请重新登录后重试。' : '该账号缺少 AK/SK 凭据引用,额度窗口无法查询。')
|
|
1585
2095
|
: null,
|
|
1586
|
-
|
|
2096
|
+
// 已有数据时轮询静默进行(按钮带 aria-busy),避免每轮都闪一次状态文字。
|
|
2097
|
+
quotaBusy && !quota ? h('p', { role: 'status', style: style.muted }, `正在查询${PLAN_TITLES[plan]}的额度…`) : null,
|
|
1587
2098
|
!account ? h('p', { style: style.muted }, '请先登录或添加账号,再为此套餐选择账号。')
|
|
1588
2099
|
: !quota && !auth.quota ? h('p', { style: style.muted }, '完成此套餐的登录绑定或额度鉴权配置后,即可查询额度。')
|
|
1589
2100
|
: h(QuotaWindows, { quota }),
|
|
1590
|
-
|
|
1591
|
-
|
|
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]}模型目录` },
|
|
1592
2112
|
h('div', { className: 'vcp-heading' },
|
|
1593
2113
|
h('div', { className: 'vcp-heading-copy' },
|
|
1594
2114
|
h('h4', { style: { margin: 0, fontSize: 13, fontWeight: 650 } }, '模型目录'),
|
|
@@ -1622,7 +2142,7 @@ function PlanCard({ plan, snapshot, rawQuota, busy, quotaBusy, onSelect, onModel
|
|
|
1622
2142
|
: h('p', { style: style.muted }, catalog
|
|
1623
2143
|
? '该目录暂无模型明细(旧缓存可能没有模型列表,重新拉取模型后可用)。'
|
|
1624
2144
|
: !account ? '选择账号后显示该套餐的模型目录。' : '模型目录:尚未拉取。')),
|
|
1625
|
-
h('details', { className: 'vcp-details' },
|
|
2145
|
+
h('details', { className: 'vcp-details vcp-plan-section' },
|
|
1626
2146
|
h('summary', { style: style.summary }, '套餐高级信息与技术标识'),
|
|
1627
2147
|
h('div', { className: 'vcp-details-body' },
|
|
1628
2148
|
h('p', { style: style.muted }, PLAN_HINTS[plan]),
|
|
@@ -1683,6 +2203,7 @@ function AccountPanel({ snapshot, editor, confirmDelete, loginConfirm, login, bu
|
|
|
1683
2203
|
account.credentialError ? h('p', { role: 'alert', style: style.error }, `凭据状态:${describeError(account.credentialError)}`) : null,
|
|
1684
2204
|
h('div', { className: 'vcp-chip-row' }, PLANS.map((plan) => h('span', { key: plan, style: style.chip },
|
|
1685
2205
|
`${plan === 'agent-plan' ? 'Agent' : '编程'}套餐:${snapshot?.active?.[plan] === account.id ? (providerEnabledOf(snapshot, plan) ? '当前使用' : '已选择 · 已停用') : '未选用'}${isOAuth(account) ? ` · ${account.oauthProfiles?.[plan] ? '已绑定' : '未绑定'}` : ''}`))),
|
|
2206
|
+
h(LoginExpiryNote, { account }),
|
|
1686
2207
|
h('div', { className: 'vcp-actions' }, PLANS.map(plan => {
|
|
1687
2208
|
const selected = snapshot?.active?.[plan] === account.id;
|
|
1688
2209
|
if (!planAuth(account, plan).inference || (selected && providerEnabledOf(snapshot, plan))) return null;
|
|
@@ -1765,6 +2286,7 @@ function AccountPanel({ snapshot, editor, confirmDelete, loginConfirm, login, bu
|
|
|
1765
2286
|
login.message ? h('p', { style: style.muted }, login.message) : null,
|
|
1766
2287
|
login.url && !loginUrl ? h(Notice, { tone: 'error', role: 'alert' }, '登录链接未通过安全校验,已隐藏;请重新发起登录。') : null,
|
|
1767
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,
|
|
1768
2290
|
loginUrl && login.state === 'waiting'
|
|
1769
2291
|
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
|
1770
2292
|
h('label', { style: style.field },
|
|
@@ -1859,6 +2381,8 @@ function VolcengineProviderSection({ client }) {
|
|
|
1859
2381
|
const [loading, setLoading] = react.useState(true);
|
|
1860
2382
|
const [busy, setBusy] = react.useState(null);
|
|
1861
2383
|
const [notice, setNotice] = react.useState(null);
|
|
2384
|
+
// 重开设置页时先用模块里留存的上次额度,首帧不再是「未获取」。
|
|
2385
|
+
// 额度快照由 Host 中间层随 read / snapshots 下发,首屏不再是空的。
|
|
1862
2386
|
const [quotas, setQuotas] = react.useState({});
|
|
1863
2387
|
const [quotaBusy, setQuotaBusy] = react.useState({});
|
|
1864
2388
|
const quotaPendingRef = react.useRef(new Map());
|
|
@@ -1866,19 +2390,46 @@ function VolcengineProviderSection({ client }) {
|
|
|
1866
2390
|
const [confirmDelete, setConfirmDelete] = react.useState(null);
|
|
1867
2391
|
const [loginConfirm, setLoginConfirm] = react.useState(null);
|
|
1868
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);
|
|
1869
2397
|
|
|
1870
2398
|
const aliveRef = react.useRef(true);
|
|
1871
2399
|
const busyRef = react.useRef(null);
|
|
1872
2400
|
const handledLoginRef = react.useRef(null);
|
|
1873
2401
|
const readSequenceRef = react.useRef(0);
|
|
1874
2402
|
const quotaEpochRef = react.useRef(0);
|
|
1875
|
-
const
|
|
2403
|
+
const revisionRef = react.useRef(null);
|
|
2404
|
+
const fingerprintRef = react.useRef(null);
|
|
1876
2405
|
|
|
1877
2406
|
react.useEffect(() => {
|
|
1878
2407
|
aliveRef.current = true;
|
|
1879
2408
|
return () => { aliveRef.current = false; };
|
|
1880
2409
|
}, []);
|
|
1881
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
|
+
|
|
1882
2433
|
/** 把一次 read 返回的整份快照落到状态里。 */
|
|
1883
2434
|
const applySnapshot = react.useCallback((value) => {
|
|
1884
2435
|
if (!aliveRef.current || !value) return;
|
|
@@ -1889,19 +2440,22 @@ function VolcengineProviderSection({ client }) {
|
|
|
1889
2440
|
profiles: account.oauthProfiles, apiKeyRefs: account.apiKeyRefs, accessKeyRef: account.accessKeyRef,
|
|
1890
2441
|
secretKeyRef: account.secretKeyRef, hasApiKeys: account.hasApiKeys, hasQuotaAccess: account.hasQuotaAccess
|
|
1891
2442
|
})) });
|
|
1892
|
-
if (
|
|
1893
|
-
|
|
2443
|
+
if (fingerprintRef.current !== fingerprint) {
|
|
2444
|
+
fingerprintRef.current = fingerprint;
|
|
1894
2445
|
quotaEpochRef.current += 1;
|
|
1895
2446
|
setQuotaBusy({});
|
|
1896
|
-
setQuotas({});
|
|
1897
2447
|
}
|
|
2448
|
+
// 额度快照由 Host 中间层下发:打开设置就有数据,不再依赖页面自己发查询。
|
|
2449
|
+
setQuotas(value.quotas ?? {});
|
|
1898
2450
|
setSnapshot(value);
|
|
2451
|
+
revisionRef.current = value.revision ?? null;
|
|
1899
2452
|
setEditor(previous => previous?.mode === 'edit' && !(value.accounts ?? []).some(account => account.id === previous.id) ? null : previous);
|
|
1900
2453
|
setLoading(false);
|
|
1901
2454
|
const incoming = value.login ? normalizeLogin(value.login) : null;
|
|
1902
2455
|
if (incoming) setLogin(incoming);
|
|
1903
2456
|
}, []);
|
|
1904
2457
|
|
|
2458
|
+
|
|
1905
2459
|
/** 重新读取全部状态。 */
|
|
1906
2460
|
const refresh = react.useCallback(async () => {
|
|
1907
2461
|
const sequence = ++readSequenceRef.current;
|
|
@@ -2007,7 +2561,8 @@ function VolcengineProviderSection({ client }) {
|
|
|
2007
2561
|
}
|
|
2008
2562
|
});
|
|
2009
2563
|
|
|
2010
|
-
|
|
2564
|
+
/** 手动刷新:Host 立即重采一次并返回结果;自动刷新只读中间层,不经过这里。 */
|
|
2565
|
+
const refreshQuota = async (plan) => {
|
|
2011
2566
|
const accountId = snapshot?.active?.[plan] ?? null;
|
|
2012
2567
|
const epoch = quotaEpochRef.current;
|
|
2013
2568
|
if (!accountId || quotaPendingRef.current.get(plan) === epoch) return;
|
|
@@ -2016,10 +2571,10 @@ function VolcengineProviderSection({ client }) {
|
|
|
2016
2571
|
try {
|
|
2017
2572
|
const value = await client.invoke({ op: 'quota', plan, accountId, force: true });
|
|
2018
2573
|
if (!aliveRef.current || epoch !== quotaEpochRef.current) return;
|
|
2019
|
-
setQuotas(
|
|
2574
|
+
setQuotas(previous => ({ ...previous, [`${accountId}:${plan}`]: { at: Date.now(), value } }));
|
|
2020
2575
|
} catch (error) {
|
|
2021
2576
|
if (!aliveRef.current || epoch !== quotaEpochRef.current) return;
|
|
2022
|
-
|
|
2577
|
+
setNotice({ ok: false, text: `刷新额度失败:${describeError(error)}` });
|
|
2023
2578
|
} finally {
|
|
2024
2579
|
if (quotaPendingRef.current.get(plan) === epoch) {
|
|
2025
2580
|
quotaPendingRef.current.delete(plan);
|
|
@@ -2028,6 +2583,62 @@ function VolcengineProviderSection({ client }) {
|
|
|
2028
2583
|
}
|
|
2029
2584
|
};
|
|
2030
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
|
+
|
|
2031
2642
|
// 套餐启停:只改启用状态,不动账号选择,也不动模型参数。
|
|
2032
2643
|
const toggleProvider = (plan, enabled) => run(`provider:${plan}`, async () => {
|
|
2033
2644
|
if (!snapshot?.revision) return;
|
|
@@ -2076,6 +2687,30 @@ function VolcengineProviderSection({ client }) {
|
|
|
2076
2687
|
}
|
|
2077
2688
|
});
|
|
2078
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
|
+
|
|
2079
2714
|
const startLogin = (accountId) => run('login', async () => {
|
|
2080
2715
|
if (!snapshot?.revision) return;
|
|
2081
2716
|
try {
|
|
@@ -2130,11 +2765,14 @@ function VolcengineProviderSection({ client }) {
|
|
|
2130
2765
|
setNotice(null);
|
|
2131
2766
|
};
|
|
2132
2767
|
|
|
2133
|
-
|
|
2768
|
+
const navigateSettings = (tab, target) => {
|
|
2769
|
+
pendingNavigationRef.current = { tab, target };
|
|
2770
|
+
setSettingsTab(tab);
|
|
2771
|
+
};
|
|
2772
|
+
|
|
2773
|
+
// 从套餐卡片一键回到账号区:等目标面板显示后再滚动并聚焦。
|
|
2134
2774
|
const scrollToAccounts = () => {
|
|
2135
|
-
|
|
2136
|
-
// 非浏览器预览环境没有 document:登录确认本身会强制展开账号区。
|
|
2137
|
-
}
|
|
2775
|
+
navigateSettings('accounts', 'vcp-account-panel');
|
|
2138
2776
|
};
|
|
2139
2777
|
const goAccountLogin = (accountId) => { scrollToAccounts(); requestLogin(accountId); };
|
|
2140
2778
|
|
|
@@ -2309,6 +2947,8 @@ function VolcengineProviderSection({ client }) {
|
|
|
2309
2947
|
};
|
|
2310
2948
|
|
|
2311
2949
|
const busyAccount = busy !== null;
|
|
2950
|
+
// 额度快照按「账号:套餐」存于 Host 中间层,这里只按当前选中账号取值。
|
|
2951
|
+
const quotaOf = (plan) => quotas[`${snapshot?.active?.[plan] ?? ''}:${plan}`]?.value;
|
|
2312
2952
|
const loginActive = LOGIN_ACTIVE_STATES.includes(login.state);
|
|
2313
2953
|
const planBusy = busy ?? (loginActive ? 'login-active' : null);
|
|
2314
2954
|
|
|
@@ -2316,6 +2956,13 @@ function VolcengineProviderSection({ client }) {
|
|
|
2316
2956
|
: loginActive ? '登录进行中'
|
|
2317
2957
|
: loading && !snapshot ? '正在读取设置'
|
|
2318
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
|
+
};
|
|
2319
2966
|
|
|
2320
2967
|
return h('div', { className: 'vcp-settings', style: style.root },
|
|
2321
2968
|
h('header', { className: 'vcp-header vcp-hero' },
|
|
@@ -2347,21 +2994,28 @@ function VolcengineProviderSection({ client }) {
|
|
|
2347
2994
|
!snapshot
|
|
2348
2995
|
? (loading ? h('p', { role: 'status', style: style.muted }, '正在读取方舟账号状态…') : null)
|
|
2349
2996
|
: h('div', { className: 'vcp-content', 'data-empty': !(snapshot.accounts?.length) },
|
|
2350
|
-
h('div', { className: 'vcp-
|
|
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 },
|
|
2351
3005
|
h(PlanCard, {
|
|
2352
|
-
plan
|
|
2353
|
-
onSelect: selectAccount, onModels: pullModels, onQuota:
|
|
2354
|
-
onToggleProvider: toggleProvider, onToggleModel: toggleModel,
|
|
2355
|
-
onSaveModelSettings: saveModelSettings, onResetModelSettings: resetModelSettings,
|
|
2356
|
-
onGoLogin: goAccountLogin, onScrollAccounts: scrollToAccounts
|
|
2357
|
-
}),
|
|
2358
|
-
h(PlanCard, {
|
|
2359
|
-
plan: 'coding-plan', snapshot, rawQuota: quotas['coding-plan'], busy: planBusy, quotaBusy: Boolean(quotaBusy['coding-plan']),
|
|
2360
|
-
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,
|
|
2361
3008
|
onToggleProvider: toggleProvider, onToggleModel: toggleModel,
|
|
2362
3009
|
onSaveModelSettings: saveModelSettings, onResetModelSettings: resetModelSettings,
|
|
2363
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`)
|
|
2364
3017
|
})),
|
|
3018
|
+
h('div', { className: 'vcp-tab-section', hidden: settingsTab !== 'accounts' },
|
|
2365
3019
|
h(AccountPanel, {
|
|
2366
3020
|
snapshot, editor, confirmDelete, loginConfirm, login, busy,
|
|
2367
3021
|
onNew: openNew, onEdit: openEdit, onCancelEdit: () => setEditor(null),
|
|
@@ -2376,7 +3030,7 @@ function VolcengineProviderSection({ client }) {
|
|
|
2376
3030
|
onCancelLoginConfirm: () => setLoginConfirm(null),
|
|
2377
3031
|
onCancelLogin: () => { void cancelLogin(); },
|
|
2378
3032
|
onSubmitLoginCode: (code) => { void submitLoginCode(code); }
|
|
2379
|
-
})));
|
|
3033
|
+
})))));
|
|
2380
3034
|
}
|
|
2381
3035
|
|
|
2382
3036
|
// ── 插件装配 ─────────────────────────────────────────────────────────────────
|
|
@@ -2481,6 +3135,8 @@ function apply(ctx) {
|
|
|
2481
3135
|
console.error('[dsh-volcengine-provider] 设置页注册失败:', error);
|
|
2482
3136
|
}
|
|
2483
3137
|
|
|
3138
|
+
applyVolcMediaViews(ctx);
|
|
3139
|
+
|
|
2484
3140
|
// 4) 生命周期清理:定时器、远端挂载。
|
|
2485
3141
|
ctx.effect(() => () => {
|
|
2486
3142
|
runtime.disposed = true;
|