-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvision-config.html
More file actions
404 lines (358 loc) · 14.2 KB
/
Copy pathvision-config.html
File metadata and controls
404 lines (358 loc) · 14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="dark">
<title>Riven Analyst · 视觉模型配置</title>
<style>
:root {
--ink: #f7f2ff;
--muted: #b8abc9;
--panel: rgba(20, 13, 31, .82);
--line: rgba(218, 181, 255, .18);
--violet: #b56cff;
--cyan: #69e5ff;
--good: #7af7c0;
--danger: #ff8db0;
--shadow: 0 24px 80px rgba(5, 0, 14, .52);
}
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
color: var(--ink);
font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", "Microsoft YaHei", sans-serif;
background:
radial-gradient(circle at 16% 12%, rgba(145, 67, 255, .30), transparent 31rem),
radial-gradient(circle at 88% 82%, rgba(48, 167, 255, .17), transparent 34rem),
linear-gradient(145deg, #09060f 0%, #10091b 48%, #07050c 100%);
}
body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
opacity: .32;
background-image:
linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
background-size: 44px 44px;
mask-image: linear-gradient(to bottom, black, transparent 82%);
}
.shell {
width: min(1080px, calc(100% - 32px));
margin: 0 auto;
padding: 48px 0 64px;
position: relative;
}
header {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
align-items: end;
gap: 28px;
margin-bottom: 26px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
color: var(--cyan);
font-size: 12px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
.pulse {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--good);
box-shadow: 0 0 18px var(--good);
}
h1 {
margin: 10px 0 8px;
font-size: clamp(38px, 6vw, 68px);
line-height: 1;
letter-spacing: -.055em;
font-weight: 780;
color: transparent;
background: linear-gradient(100deg, #fff 5%, #d7afff 50%, #78e9ff 100%);
background-clip: text;
-webkit-background-clip: text;
}
.lede { max-width: 680px; margin: 0; color: var(--muted); font-size: 16px; }
.sigil { width: 112px; aspect-ratio: 1; filter: drop-shadow(0 0 30px rgba(181, 108, 255, .38)); }
.layout {
display: grid;
grid-template-columns: minmax(0, 1.08fr) minmax(300px, .78fr);
gap: 18px;
align-items: start;
}
.card {
border: 1px solid var(--line);
border-radius: 24px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(22px);
-webkit-backdrop-filter: blur(22px);
}
.form-card { padding: clamp(22px, 4vw, 36px); }
.info-card { padding: 27px; position: sticky; top: 18px; }
.section-title { margin: 0 0 5px; font-size: 18px; letter-spacing: -.01em; }
.section-note { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
label { color: #d8cce6; font-size: 12px; font-weight: 700; letter-spacing: .025em; }
input {
width: 100%;
min-height: 48px;
border: 1px solid var(--line);
border-radius: 13px;
padding: 0 14px;
color: var(--ink);
background: rgba(7, 4, 12, .64);
outline: none;
transition: border-color .18s, box-shadow .18s;
font: inherit;
}
input:focus { border-color: var(--violet); box-shadow: 0 0 0 4px rgba(181,108,255,.12); }
input::placeholder { color: #766987; }
.secret-wrap { position: relative; }
.secret-wrap input { padding-right: 62px; }
.reveal {
position: absolute;
right: 8px;
top: 50%;
translate: 0 -50%;
border: 0;
border-radius: 8px;
padding: 7px 8px;
color: var(--muted);
background: transparent;
cursor: pointer;
}
.primary {
width: 100%;
margin-top: 20px;
min-height: 54px;
border: 0;
border-radius: 14px;
color: white;
background: linear-gradient(110deg, #6f2bdd, #a24cff 55%, #6759ff);
box-shadow: 0 14px 36px rgba(116, 45, 224, .34);
font: 800 14px/1 inherit;
cursor: pointer;
transition: transform .18s, filter .18s;
}
.primary:hover { transform: translateY(-2px); filter: brightness(1.08); }
.primary:disabled { cursor: wait; opacity: .7; transform: none; }
.error-text { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 12px; }
.status {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 17px;
color: var(--muted);
font-size: 12px;
font-weight: 750;
}
.status::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.status.saved { color: var(--good); }
.status.error { color: var(--danger); }
.steps { display: grid; gap: 14px; margin: 22px 0; }
.step { display: grid; grid-template-columns: 30px 1fr; gap: 11px; align-items: start; }
.step b {
display: grid;
place-items: center;
width: 30px;
height: 30px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--cyan);
background: rgba(255,255,255,.035);
font-size: 12px;
}
.step p { margin: 2px 0 0; color: #d8cce6; font-size: 13px; }
.step small { display: block; margin-top: 3px; color: var(--muted); }
.path {
padding: 13px 14px;
border: 1px solid rgba(255,255,255,.08);
border-radius: 13px;
background: #08050d;
color: #d8c7e9;
font: 11px/1.65 "Cascadia Code", Consolas, monospace;
overflow-wrap: anywhere;
}
.privacy { margin: 17px 0 0; color: var(--muted); font-size: 11px; }
.privacy b { color: var(--good); }
@media (max-width: 820px) {
header { grid-template-columns: 1fr; }
.sigil { display: none; }
.layout { grid-template-columns: 1fr; }
.info-card { position: static; }
}
@media (max-width: 600px) {
.shell { width: min(100% - 20px, 1080px); padding-top: 32px; }
.grid { grid-template-columns: 1fr; }
.field.full { grid-column: auto; }
.card { border-radius: 19px; }
}
</style>
</head>
<body>
<main class="shell">
<header>
<div>
<div class="eyebrow"><span class="pulse"></span> Vision MCP Configurator</div>
<h1>配置视觉模型。</h1>
<p class="lede">这里配置 Riven Analyst 中视觉 MCP 的外部模型供应商。</p>
</div>
<svg class="sigil" viewBox="0 0 120 120" aria-hidden="true">
<defs><linearGradient id="crystal" x1="0" y1="0" x2="1" y2="1"><stop stop-color="#e3bbff"/><stop offset=".45" stop-color="#933cff"/><stop offset="1" stop-color="#43ccea"/></linearGradient></defs>
<path d="M60 5 101 34 90 92 60 115 28 91 18 34Z" fill="none" stroke="url(#crystal)" stroke-width="2"/>
<path d="m60 5 13 43 28-14M60 5 45 49 18 34M45 49l15 66 13-67M28 91l17-42 45 43-17-44" fill="none" stroke="url(#crystal)" stroke-width="1.3" opacity=".8"/>
<circle cx="60" cy="62" r="7" fill="#fff" opacity=".9"/>
</svg>
</header>
<div class="layout">
<section class="card form-card" aria-labelledby="config-title">
<h2 class="section-title" id="config-title">视觉供应商</h2>
<p class="section-note">当前只支持 OpenAI-compatible 外部端点。</p>
<div class="grid">
<div class="field">
<label for="provider">Provider 标识</label>
<input id="provider" placeholder="供应商标识" autocomplete="off">
</div>
<div class="field">
<label for="model">视觉模型 ID</label>
<input id="model" placeholder="供应商提供的视觉模型 ID" spellcheck="false" autocomplete="off">
</div>
<div class="field full">
<label for="baseUrl">API Base URL</label>
<input id="baseUrl" type="url" placeholder="https://api.example.com/v1" spellcheck="false" autocomplete="url">
</div>
<div class="field full">
<label for="apiKey">API Key</label>
<div class="secret-wrap">
<input id="apiKey" type="password" placeholder="只写入 Claude Code 的本机敏感配置" autocomplete="off">
<button class="reveal" id="reveal" type="button">显示</button>
</div>
</div>
</div>
<button class="primary" id="save" type="button">保存到 Claude Code</button>
<p class="error-text" id="error" role="alert"></p>
</section>
<aside class="card info-card" aria-labelledby="save-title">
<div class="status" id="status">等待保存</div>
<h2 class="section-title" id="save-title">完成配置</h2>
<p class="section-note">填写供应商控制台提供的信息,然后保存到 Claude Code。</p>
<div class="steps">
<div class="step"><b>1</b><p>填写左侧四项信息。<small>这些内容都可以在模型供应商的控制台中找到。</small></p></div>
<div class="step"><b>2</b><p>点击“保存到 Claude Code”。<small>按提示选择 Claude Code 的 <strong>.claude</strong> 目录。</small></p></div>
<div class="step"><b>3</b><p>保存成功后重启 Claude Code。<small>Riven Analyst 随即使用新的视觉模型配置。</small></p></div>
</div>
<div class="path">Windows: C:\Users\你的用户名\.claude<br>macOS / Linux: ~/.claude</div>
<p class="privacy"><b>● 本地保存</b> API Key 不会经由本页面发送到网络。</p>
</aside>
</div>
</main>
<script>
(() => {
"use strict";
const pluginId = "riven-analyst@riven-analyst";
const $ = (id) => document.getElementById(id);
const fields = { provider: $("provider"), baseUrl: $("baseUrl"), model: $("model"), apiKey: $("apiKey") };
$("reveal").addEventListener("click", () => {
const visible = fields.apiKey.type === "text";
fields.apiKey.type = visible ? "password" : "text";
$("reveal").textContent = visible ? "显示" : "隐藏";
});
const readJson = async (directory, name) => {
try {
const handle = await directory.getFileHandle(name);
const text = await (await handle.getFile()).text();
return text.trim() ? JSON.parse(text) : {};
} catch (error) {
if (error.name === "NotFoundError") return {};
throw error;
}
};
const writeJson = async (directory, name, value) => {
const handle = await directory.getFileHandle(name, { create: true });
const writable = await handle.createWritable();
await writable.write(`${JSON.stringify(value, null, 2)}\n`);
await writable.close();
};
const resolveClaudeDirectory = async (selected) => {
if (selected.name === ".claude") return selected;
try {
return await selected.getDirectoryHandle(".claude");
} catch {
throw new Error("请选择 .claude 目录,或选择包含 .claude 的用户主目录。");
}
};
$("save").addEventListener("click", async () => {
const provider = fields.provider.value.trim();
const baseUrl = fields.baseUrl.value.trim().replace(/\/+$/, "");
const model = fields.model.value.trim();
const apiKey = fields.apiKey.value.trim();
try {
if (!("showDirectoryPicker" in window)) throw new Error("当前浏览器不支持本地目录写入,请用最新版 Chrome 或 Edge 打开本页。");
const parsed = new URL(baseUrl);
if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.search || parsed.hash) {
throw new Error("API Base URL 必须是没有账号、查询参数和锚点的 HTTPS 地址。");
}
if (!/^[A-Za-z0-9_-]+$/.test(provider)) throw new Error("Provider 标识只能包含字母、数字、下划线和连字符。");
if (!model) throw new Error("请填写视觉模型 ID。");
if (!apiKey) throw new Error("请填写 API Key。");
$("save").disabled = true;
$("status").textContent = "等待选择目录";
$("status").className = "status";
$("error").textContent = "";
const selected = await window.showDirectoryPicker({ mode: "readwrite", startIn: "documents" });
const directory = await resolveClaudeDirectory(selected);
const settings = await readJson(directory, "settings.json");
const credentials = await readJson(directory, ".credentials.json");
settings.pluginConfigs ??= {};
settings.pluginConfigs[pluginId] ??= {};
settings.pluginConfigs[pluginId].options ??= {};
Object.assign(settings.pluginConfigs[pluginId].options, {
vision_provider: provider,
vision_base_url: baseUrl,
vision_model: model
});
credentials.pluginSecrets ??= {};
credentials.pluginSecrets[pluginId] ??= {};
credentials.pluginSecrets[pluginId].vision_api_key = apiKey;
await writeJson(directory, "settings.json", settings);
await writeJson(directory, ".credentials.json", credentials);
fields.apiKey.value = "";
$("status").textContent = "视觉配置已保存";
$("status").className = "status saved";
} catch (error) {
if (error.name === "AbortError") {
$("status").textContent = "已取消";
$("status").className = "status";
} else {
$("status").textContent = "保存失败";
$("status").className = "status error";
$("error").textContent = error.message;
}
} finally {
$("save").disabled = false;
}
});
})();
</script>
</body>
</html>