@goodandready/dsh-model-sync 0.3.12 → 0.3.14
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 +34 -0
- package/README.ru.md +34 -0
- package/README.zh.md +34 -0
- package/lib/adapter-registry.js +20 -3
- package/lib/client.js +994 -81
- package/lib/generic-adapter.js +23 -5
- package/lib/http.js +298 -237
- package/lib/index.js +172 -163
- package/lib/models.js +300 -282
- package/lib/policy.js +25 -2
- package/lib/reliability.js +6 -2
- package/lib/synchronizer.js +157 -3
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -5,13 +5,23 @@ window.__ModuleLoader__.load({
|
|
|
5
5
|
var exports = module.exports
|
|
6
6
|
const React = require('react')
|
|
7
7
|
|
|
8
|
-
const CSS = '.dms-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;margin:0;padding:0;overflow:hidden;box-sizing:border-box}' +
|
|
8
|
+
const CSS = '.dms-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;margin:0;padding:0;overflow:hidden;box-sizing:border-box}' +
|
|
9
|
+
'.dms-card-open{background:var(--dsw-alias-bg-layer-3);border-color:var(--dsw-alias-border-l2)}' +
|
|
10
|
+
'.dms-card-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:12px;display:flex;align-items:center;gap:12px;padding:14px 16px}' +
|
|
11
|
+
'.dms-card-header:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.05))}' +
|
|
12
|
+
'.dms-card-header:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-2px}' +
|
|
13
|
+
'.dms-card-head-text{display:flex;flex-direction:column;gap:2px;flex:1;min-width:0}' +
|
|
14
|
+
'.dms-card-name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}' +
|
|
15
|
+
'.dms-card-description{color:var(--dsw-alias-label-secondary);font-size:13px;line-height:1.45}' +
|
|
16
|
+
'.dms-card-chevron{color:var(--dsw-alias-label-tertiary);flex:0 0 auto;transition:transform .12s}.dms-card-chevron-open{transform:rotate(180deg)}' +
|
|
17
|
+
'.dms-card-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding-bottom:8px;display:flex;flex-direction:column;gap:10px;box-sizing:border-box}' +
|
|
18
|
+
'.dms-wrap{display:flex;flex-direction:column;gap:14px;max-width:760px;box-sizing:border-box;color:var(--dsw-alias-label-primary,inherit)}' +
|
|
9
19
|
'.dms-wrap>p{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:1.55}' +
|
|
10
20
|
'.dms-toolbar,.dms-section{display:flex;flex-direction:row;align-items:center;flex-wrap:wrap;gap:10px;padding:13px 14px;border:1px solid var(--dsw-alias-border-l2,var(--dsw-alias-border-primary,rgba(255,255,255,.14)));border-radius:10px;background:var(--dsw-alias-bg-layer-1,transparent);box-sizing:border-box}' +
|
|
11
21
|
'.dms-toolbar>select{flex:1 1 190px;min-width:190px}' +
|
|
12
22
|
'.dms-toolbar>.dms-actions{flex-basis:100%}' +
|
|
13
23
|
'.dms-toolbar>label{display:inline-flex;align-items:flex-start;gap:7px;font-size:12px;line-height:1.35;color:var(--dsw-alias-label-secondary)}' +
|
|
14
|
-
'.dms-toolbar>select,.dms-editor input,.dms-editor textarea{box-sizing:border-box;min-width:0;background:var(--dsw-specific-input-major,var(--dsw-alias-bg-layer-2,transparent));border:1px solid var(--dsw-alias-border-l1,var(--dsw-alias-border-l2));border-radius:6px;color:var(--dsw-alias-label-primary);font:inherit;padding:7px 9px}' +
|
|
24
|
+
'.dms-toolbar>select,.dms-editor input,.dms-editor textarea,.dms-input{box-sizing:border-box;min-width:0;background:var(--dsw-specific-input-major,var(--dsw-alias-bg-layer-2,transparent));border:1px solid var(--dsw-alias-border-l1,var(--dsw-alias-border-l2));border-radius:6px;color:var(--dsw-alias-label-primary);font:inherit;padding:7px 9px}' +
|
|
15
25
|
'.dms-toolbar>label input{accent-color:var(--dsw-alias-brand-primary,var(--dsw-alias-button-info-fill))}' +
|
|
16
26
|
'.dms-actions{display:flex;align-items:center;flex-wrap:wrap;gap:7px}' +
|
|
17
27
|
'.dms-wrap>.dms-actions{padding:10px 14px;border:1px solid var(--dsw-alias-border-l2,var(--dsw-alias-border-primary,rgba(255,255,255,.14)));border-radius:10px;background:var(--dsw-alias-bg-layer-1,transparent)}' +
|
|
@@ -28,7 +38,26 @@ window.__ModuleLoader__.load({
|
|
|
28
38
|
'.dms-editor label{display:block;gap:5px;margin-top:8px;color:var(--dsw-alias-label-secondary);font-size:12px}' +
|
|
29
39
|
'.dms-editor label input,.dms-editor label textarea{width:100%}' +
|
|
30
40
|
'.dms-editor input[type="checkbox"]{width:auto;accent-color:var(--dsw-alias-brand-primary)}' +
|
|
31
|
-
'.dms-section-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;padding:16px 18px;display:flex;flex-direction:column;gap:12px;box-sizing:border-box}' +
|
|
41
|
+
'.dms-section-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;padding:16px 18px;display:flex;flex-direction:column;gap:12px;box-sizing:border-box}' +
|
|
42
|
+
'.dms-section-title{font-size:15px;font-weight:600;color:var(--dsw-alias-label-primary);display:flex;align-items:center;justify-content:space-between;line-height:1.4}' +
|
|
43
|
+
'.dms-section-desc{font-size:13px;color:var(--dsw-alias-label-secondary);margin-top:-6px;line-height:1.4}' +
|
|
44
|
+
'.dms-row{display:flex;flex-wrap:wrap;gap:8px;align-items:center}' +
|
|
45
|
+
'.dms-grid-2{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:12px}' +
|
|
46
|
+
'.dms-badge{font-size:11px;padding:2px 8px;border-radius:999px;border:1px solid var(--dsw-alias-border-l2);display:inline-flex;align-items:center;gap:4px;font-weight:500}' +
|
|
47
|
+
'.dms-badge-ok{border-color:var(--dsw-alias-state-success-primary);color:var(--dsw-alias-state-success-primary);background:rgba(16,185,129,0.08)}' +
|
|
48
|
+
'.dms-badge-warn{border-color:var(--dsw-alias-state-warning-primary);color:var(--dsw-alias-state-warning-primary);background:rgba(245,158,11,0.08)}' +
|
|
49
|
+
'.dms-badge-bad{border-color:var(--dsw-alias-state-error-primary);color:var(--dsw-alias-state-error-primary);background:rgba(239,68,68,0.08)}' +
|
|
50
|
+
'.dms-input{height:34px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);border-radius:6px;padding:0 10px;font-size:13px;box-sizing:border-box}' +
|
|
51
|
+
'.dms-input:focus{outline:none;border-color:var(--dsw-alias-state-brand-primary)}' +
|
|
52
|
+
'.dms-btn-primary{background:var(--dsw-alias-label-primary)!important;color:var(--dsw-alias-bg-layer-3)!important;border-color:transparent!important;font-weight:600}' +
|
|
53
|
+
'.dms-btn-primary:hover:not(:disabled){opacity:0.88}' +
|
|
54
|
+
'.dms-btn-danger{color:var(--dsw-alias-state-error-primary)!important;border-color:rgba(239,68,68,0.3)!important}' +
|
|
55
|
+
'.dms-btn-danger:hover:not(:disabled){background:rgba(239,68,68,0.12)!important;border-color:rgba(239,68,68,0.5)!important}' +
|
|
56
|
+
'.dms-alert{padding:10px 14px;border-radius:8px;font-size:13px}' +
|
|
57
|
+
'.dms-alert-ok{background:rgba(16,185,129,0.1);color:var(--dsw-alias-state-success-primary)}' +
|
|
58
|
+
'.dms-alert-bad{background:rgba(239,68,68,0.1);color:var(--dsw-alias-state-error-primary)}' +
|
|
59
|
+
'.dms-probe-result{padding:2px 6px;border-radius:4px;font-family:monospace;font-size:11px;border:1px solid var(--dsw-alias-border-l2);display:inline-flex;align-items:center;gap:4px}' +
|
|
60
|
+
'@media (max-width:540px){.dms-provider{grid-template-columns:1fr!important}.dms-provider .dms-btn{justify-self:start}.dms-toolbar>div:first-child{align-items:stretch;flex-direction:column}.dms-toolbar>div:first-child select{width:100%}.dms-toolbar,.dms-section,.dms-section-card,.dms-editor{padding:11px 12px}}'
|
|
32
61
|
|
|
33
62
|
function createErrorBoundary() {
|
|
34
63
|
if (!React || typeof React.Component !== 'function') {
|
|
@@ -80,62 +109,607 @@ window.__ModuleLoader__.load({
|
|
|
80
109
|
tag.setAttribute('data-plugin-css', cssId)
|
|
81
110
|
document.head.appendChild(tag)
|
|
82
111
|
}
|
|
112
|
+
|
|
83
113
|
const en = {
|
|
84
|
-
title: 'Model synchronization',
|
|
114
|
+
title: 'Model synchronization',
|
|
115
|
+
showSettings: 'Show settings', hideSettings: 'Hide settings',
|
|
116
|
+
desc: 'Refresh model catalogs for API-key providers. A dry-run is the default; applying changes is explicit.',
|
|
117
|
+
loading: 'Loading…',
|
|
118
|
+
refresh: 'Refresh status',
|
|
119
|
+
refreshAll: 'Refresh all',
|
|
120
|
+
run: 'Discover',
|
|
121
|
+
apply: 'Apply changes',
|
|
122
|
+
dryRun: 'Preview only (dry-run)',
|
|
123
|
+
all: 'All API-key providers',
|
|
124
|
+
ok: 'ready',
|
|
125
|
+
dormant: 'not configured',
|
|
126
|
+
running: 'running…',
|
|
127
|
+
noProviders: 'No API-key providers found.',
|
|
128
|
+
lastRun: 'Last run',
|
|
129
|
+
previewTitle: 'Changes preview',
|
|
130
|
+
previewNone: 'No changes detected.',
|
|
131
|
+
previewAdded: 'Added',
|
|
132
|
+
previewRemoved: 'Removed',
|
|
133
|
+
previewChanged: 'Changed',
|
|
134
|
+
previewApply: 'Apply preview',
|
|
135
|
+
previewDismiss: 'Close preview',
|
|
136
|
+
selectModels: 'Choose models',
|
|
137
|
+
saveSelection: 'Save and apply selection',
|
|
138
|
+
selectAtLeastOne: 'Select at least one model or use All models.',
|
|
139
|
+
cancel: 'Cancel',
|
|
140
|
+
selected: 'selected',
|
|
141
|
+
allModels: 'All models',
|
|
142
|
+
noModels: 'No models in the current catalog.',
|
|
143
|
+
capabilityFilter: 'Filter by capabilities',
|
|
144
|
+
capabilityCount: 'shown',
|
|
145
|
+
noCapabilities: 'No capability metadata in this catalog.',
|
|
146
|
+
pickerNote: 'The selection is applied to the DSH model picker immediately.',
|
|
147
|
+
health: 'Check availability',
|
|
148
|
+
healthOk: 'available',
|
|
149
|
+
healthError: 'unavailable',
|
|
150
|
+
healthDormant: 'not configured',
|
|
151
|
+
policy: 'Manual model selection',
|
|
152
|
+
savePolicy: 'Save policy',
|
|
153
|
+
policyInclude: 'Include patterns (one per line)',
|
|
154
|
+
policyExclude: 'Exclude patterns (one per line)',
|
|
155
|
+
policyRequire: 'Required capabilities (comma-separated)',
|
|
156
|
+
policyDeny: 'Denied capabilities (comma-separated)',
|
|
157
|
+
policyNote: 'Patterns match model id, name, and tags. Apply changes to update the DSH picker.',
|
|
158
|
+
scheduler: 'Scheduler',
|
|
159
|
+
nextRun: 'next run',
|
|
160
|
+
schedulerOff: 'off',
|
|
161
|
+
schedulerOn: 'on',
|
|
162
|
+
removeMissing: 'Confirm stale removal',
|
|
163
|
+
stale: 'stale',
|
|
164
|
+
deprecated: 'deprecated',
|
|
165
|
+
history: 'Synchronization history',
|
|
166
|
+
historyRun: 'Run',
|
|
167
|
+
diffAdded: 'added',
|
|
168
|
+
diffRemoved: 'removed',
|
|
169
|
+
diffRenamed: 'renamed',
|
|
170
|
+
diffChanged: 'metadata changed',
|
|
171
|
+
rollback: 'Rollback catalog',
|
|
172
|
+
rollbackConfirm: 'Rollback this provider catalog to the selected snapshot?',
|
|
173
|
+
credentials: 'Credential diagnostics',
|
|
174
|
+
checkCredentials: 'Check credentials',
|
|
175
|
+
missingCredential: 'not configured',
|
|
176
|
+
credentialReady: 'configured',
|
|
177
|
+
report: 'Run report',
|
|
178
|
+
success: 'success',
|
|
179
|
+
partial: 'partial success',
|
|
180
|
+
failure: 'failed',
|
|
181
|
+
empty: 'no configured providers',
|
|
182
|
+
notifications: 'Notifications',
|
|
183
|
+
markRead: 'Mark read',
|
|
184
|
+
acknowledge: 'Acknowledge',
|
|
185
|
+
noNotifications: 'No notifications.',
|
|
186
|
+
selectAllFiltered: 'Select all shown',
|
|
187
|
+
deselectAllFiltered: 'Deselect all shown',
|
|
188
|
+
invertFiltered: 'Invert selection',
|
|
189
|
+
filterContext100k: 'Context ≥ 100k',
|
|
190
|
+
filterCheap: 'Cheap ≤ $1/1M',
|
|
191
|
+
showMore: 'Show more (%d)',
|
|
192
|
+
showingCount: 'Showing %d of %d models',
|
|
193
|
+
deprecatesIn: 'Deprecates in %dd',
|
|
194
|
+
cacheHoursAgo: 'cache %dh ago',
|
|
195
|
+
noHistory: 'No synchronization history.',
|
|
196
|
+
searchPlaceholder: 'Search id/name/tag',
|
|
197
|
+
sortName: 'Name A→Z',
|
|
198
|
+
sortPrice: 'Price ↑',
|
|
199
|
+
sortContext: 'Context ↓',
|
|
200
|
+
sortDate: 'Newest ↓',
|
|
201
|
+
schedulerSettings: 'Scheduler configuration',
|
|
202
|
+
scheduleEnabled: 'Enable background schedule',
|
|
203
|
+
intervalMinutes: 'Interval (minutes)',
|
|
204
|
+
autoApplySchedule: 'Auto-apply changes',
|
|
205
|
+
saveScheduler: 'Save scheduler',
|
|
206
|
+
schedulerSaved: 'Saved',
|
|
207
|
+
scopeUnavailable: 'Settings service unavailable.',
|
|
208
|
+
invalidPattern: 'Invalid regex pattern: %s',
|
|
209
|
+
batchTry: 'Test Selected',
|
|
210
|
+
batchTryRunning: 'Testing...',
|
|
211
|
+
batchTryDeselectUnreachable: 'Deselect unreachable',
|
|
212
|
+
batchTryResults: 'Batch test: %d/%d reached',
|
|
213
|
+
filterCostContext: 'Cost & Context limits',
|
|
214
|
+
enableCostFilter: 'Filter by maximum price',
|
|
215
|
+
maxPricePerMillion: 'Max price ($ / 1M tokens)',
|
|
216
|
+
enableContextFilter: 'Filter by minimum context',
|
|
217
|
+
minContextTokens: 'Min context window (tokens)',
|
|
218
|
+
exportConfig: 'Export configuration',
|
|
219
|
+
importConfig: 'Import configuration',
|
|
220
|
+
exportImportTitle: 'Configuration Backup & Restore',
|
|
221
|
+
importSuccess: 'Configuration imported successfully',
|
|
222
|
+
importError: 'Import failed: %s',
|
|
223
|
+
importPlaceholder: 'Paste JSON configuration here…',
|
|
224
|
+
modelAliases: 'Model Aliases',
|
|
225
|
+
aliasPlaceholder: 'Alias (e.g. gpt-4o-latest)',
|
|
226
|
+
targetModel: 'Target model',
|
|
227
|
+
addAlias: 'Save alias',
|
|
228
|
+
removeAlias: 'Delete alias',
|
|
229
|
+
noAliases: 'No model aliases defined.',
|
|
230
|
+
targetProvider: 'Provider',
|
|
85
231
|
}
|
|
86
|
-
|
|
87
|
-
|
|
232
|
+
|
|
233
|
+
const zh = {
|
|
234
|
+
title: '模型同步',
|
|
235
|
+
showSettings: '展开设置', hideSettings: '收起设置',
|
|
236
|
+
desc: '为配置了 API 密钥的服务商刷新模型目录。默认仅预览变更(dry-run);需显式确认以应用更改。',
|
|
237
|
+
loading: '加载中…',
|
|
238
|
+
refresh: '刷新状态',
|
|
239
|
+
refreshAll: '全部刷新',
|
|
240
|
+
run: '发现模型',
|
|
241
|
+
apply: '应用变更',
|
|
242
|
+
dryRun: '仅预览(dry-run)',
|
|
243
|
+
all: '所有 API 密钥服务商',
|
|
244
|
+
ok: '就绪',
|
|
245
|
+
dormant: '未配置',
|
|
246
|
+
running: '运行中…',
|
|
247
|
+
noProviders: '未找到任何已配置的服务商。',
|
|
248
|
+
lastRun: '上次运行',
|
|
249
|
+
previewTitle: '变更预览',
|
|
250
|
+
previewNone: '未检测到任何变更。',
|
|
251
|
+
previewAdded: '新增',
|
|
252
|
+
previewRemoved: '已移除',
|
|
253
|
+
previewChanged: '已更改',
|
|
254
|
+
previewApply: '应用预览中的变更',
|
|
255
|
+
previewDismiss: '关闭预览',
|
|
256
|
+
selectModels: '选择模型',
|
|
257
|
+
saveSelection: '保存并应用选择',
|
|
258
|
+
selectAtLeastOne: '请至少选择一个模型,或使用“全部模型”。',
|
|
259
|
+
cancel: '取消',
|
|
260
|
+
selected: '已选',
|
|
261
|
+
allModels: '全部模型',
|
|
262
|
+
noModels: '当前目录中没有模型。',
|
|
263
|
+
capabilityFilter: '按能力筛选',
|
|
264
|
+
capabilityCount: '已显示',
|
|
265
|
+
noCapabilities: '此目录中没有能力元数据。',
|
|
266
|
+
pickerNote: '所选模型将立即生效至 DSH 模型选择器。',
|
|
267
|
+
health: '检查可用性',
|
|
268
|
+
healthOk: '可用',
|
|
269
|
+
healthError: '不可用',
|
|
270
|
+
healthDormant: '未配置',
|
|
271
|
+
policy: '手动模型选择',
|
|
272
|
+
savePolicy: '保存策略',
|
|
273
|
+
policyInclude: '包含规则(每行一个正则表达式)',
|
|
274
|
+
policyExclude: '排除规则(每行一个正则表达式)',
|
|
275
|
+
policyRequire: '必需能力(逗号分隔)',
|
|
276
|
+
policyDeny: '禁止能力(逗号分隔)',
|
|
277
|
+
policyNote: '规则将匹配模型 ID、名称和标签。点击应用变更后更新 DSH 选择器。',
|
|
278
|
+
scheduler: '定时同步',
|
|
279
|
+
nextRun: '下次运行',
|
|
280
|
+
schedulerOff: '已关闭',
|
|
281
|
+
schedulerOn: '已开启',
|
|
282
|
+
removeMissing: '确认移除失效模型',
|
|
283
|
+
stale: '过期',
|
|
284
|
+
deprecated: '已弃用',
|
|
285
|
+
history: '同步历史',
|
|
286
|
+
historyRun: '运行记录',
|
|
287
|
+
diffAdded: '新增',
|
|
288
|
+
diffRemoved: '移除',
|
|
289
|
+
diffRenamed: '重命名',
|
|
290
|
+
diffChanged: '元数据变更',
|
|
291
|
+
rollback: '回滚目录',
|
|
292
|
+
rollbackConfirm: '确定要将该服务商目录回滚至所选快照吗?',
|
|
293
|
+
credentials: '凭据诊断',
|
|
294
|
+
checkCredentials: '检查凭据',
|
|
295
|
+
missingCredential: '未配置',
|
|
296
|
+
credentialReady: '已配置',
|
|
297
|
+
report: '运行报告',
|
|
298
|
+
success: '成功',
|
|
299
|
+
partial: '部分成功',
|
|
300
|
+
failure: '失败',
|
|
301
|
+
empty: '无配置的服务商',
|
|
302
|
+
notifications: '系统通知',
|
|
303
|
+
markRead: '标记已读',
|
|
304
|
+
acknowledge: '确认知晓',
|
|
305
|
+
noNotifications: '暂无通知。',
|
|
306
|
+
selectAllFiltered: '全选已筛选',
|
|
307
|
+
deselectAllFiltered: '取消全选已筛选',
|
|
308
|
+
invertFiltered: '反向选择',
|
|
309
|
+
filterContext100k: '上下文 ≥ 100k',
|
|
310
|
+
filterCheap: '经济型 ≤ $1/1M',
|
|
311
|
+
showMore: '加载更多 (%d)',
|
|
312
|
+
showingCount: '正在显示 %d / %d 个模型',
|
|
313
|
+
deprecatesIn: '将在 %d 天后弃用',
|
|
314
|
+
cacheHoursAgo: '缓存于 %d 小时前',
|
|
315
|
+
noHistory: '暂无同步历史。',
|
|
316
|
+
searchPlaceholder: '搜索 ID / 名称 / 标签',
|
|
317
|
+
sortName: '名称 A→Z',
|
|
318
|
+
sortPrice: '价格 ↑',
|
|
319
|
+
sortContext: '上下文 ↓',
|
|
320
|
+
sortDate: '最新 ↓',
|
|
321
|
+
schedulerSettings: '定时计划设置',
|
|
322
|
+
scheduleEnabled: '开启后台定时同步',
|
|
323
|
+
intervalMinutes: '间隔时间(分钟)',
|
|
324
|
+
autoApplySchedule: '自动应用变更',
|
|
325
|
+
saveScheduler: '保存计划',
|
|
326
|
+
schedulerSaved: '已保存',
|
|
327
|
+
scopeUnavailable: '设置服务不可用。',
|
|
328
|
+
invalidPattern: '正则表达式无效:%s',
|
|
329
|
+
batchTry: '批量测试选中模型',
|
|
330
|
+
batchTryRunning: '测试中...',
|
|
331
|
+
batchTryDeselectUnreachable: '取消选中不可用模型',
|
|
332
|
+
batchTryResults: '批量测试:%d/%d 成功',
|
|
333
|
+
filterCostContext: '价格与上下文限制',
|
|
334
|
+
enableCostFilter: '启用最高价格过滤',
|
|
335
|
+
maxPricePerMillion: '最高价格($/百万Token)',
|
|
336
|
+
enableContextFilter: '启用最小上下文过滤',
|
|
337
|
+
minContextTokens: '最小上下文窗口(Token)',
|
|
338
|
+
exportConfig: '导出配置',
|
|
339
|
+
importConfig: '导入配置',
|
|
340
|
+
exportImportTitle: '配置备份与恢复',
|
|
341
|
+
importSuccess: '配置导入成功',
|
|
342
|
+
importError: '导入失败:%s',
|
|
343
|
+
importPlaceholder: '在此粘贴 JSON 配置内容…',
|
|
344
|
+
modelAliases: '模型别名映射',
|
|
345
|
+
aliasPlaceholder: '别名(例如 gpt-4o-latest)',
|
|
346
|
+
targetModel: '目标模型',
|
|
347
|
+
addAlias: '保存别名',
|
|
348
|
+
removeAlias: '删除别名',
|
|
349
|
+
noAliases: '未定义任何模型别名。',
|
|
350
|
+
targetProvider: '服务商',
|
|
88
351
|
}
|
|
352
|
+
|
|
89
353
|
const API = '/dsh-model-sync'
|
|
90
|
-
const CAPABILITY_LABELS = {
|
|
91
|
-
|
|
354
|
+
const CAPABILITY_LABELS = {
|
|
355
|
+
vision: { en: 'Vision', zh: '视觉' },
|
|
356
|
+
tools: { en: 'Tools', zh: '工具调用' },
|
|
357
|
+
reasoning: { en: 'Reasoning', zh: '深度思考' },
|
|
358
|
+
embeddings: { en: 'Embeddings', zh: '嵌入向量' },
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function filterModelsByCapabilities(models, selected) {
|
|
362
|
+
const required = [...new Set((selected ?? []).filter((key) => typeof key === 'string' && key))]
|
|
363
|
+
return (models ?? []).filter((model) => required.every((key) => model?.capabilities?.[key] === true))
|
|
364
|
+
}
|
|
365
|
+
|
|
92
366
|
const NS = 'dsh-model-sync'
|
|
367
|
+
|
|
93
368
|
function useLocale(ctx) {
|
|
94
|
-
return React.useSyncExternalStore(
|
|
369
|
+
return React.useSyncExternalStore(
|
|
370
|
+
React.useMemo(() => (cb) => ctx.locale?.subscribe?.(cb) ?? (() => {}), [ctx]),
|
|
371
|
+
React.useCallback(() => ctx.locale?.getSnapshot?.().active ?? 'en', [ctx])
|
|
372
|
+
)
|
|
95
373
|
}
|
|
374
|
+
|
|
96
375
|
function ModelSyncSection({ ctx, includeIntro = true }) {
|
|
97
|
-
const locale = useLocale(ctx)
|
|
98
|
-
const
|
|
99
|
-
const [
|
|
100
|
-
const [
|
|
376
|
+
const locale = useLocale(ctx)
|
|
377
|
+
const t = locale === 'zh' ? zh : en
|
|
378
|
+
const [status, setStatus] = React.useState(null)
|
|
379
|
+
const [provider, setProvider] = React.useState('')
|
|
380
|
+
const [dryRun, setDryRun] = React.useState(true)
|
|
381
|
+
const [removeMissing, setRemoveMissing] = React.useState(false)
|
|
382
|
+
const [busy, setBusy] = React.useState(false)
|
|
383
|
+
const [error, setError] = React.useState('')
|
|
384
|
+
const [credentialStatus, setCredentialStatus] = React.useState(null)
|
|
385
|
+
const [selectionProvider, setSelectionProvider] = React.useState('')
|
|
386
|
+
const [selectionDraft, setSelectionDraft] = React.useState([])
|
|
387
|
+
const [capabilityFilter, setCapabilityFilter] = React.useState([])
|
|
388
|
+
const [searchQuery, setSearchQuery] = React.useState('')
|
|
389
|
+
const [debouncedSearchQuery, setDebouncedSearchQuery] = React.useState('')
|
|
390
|
+
const [sortBy, setSortBy] = React.useState('name')
|
|
391
|
+
|
|
392
|
+
React.useEffect(() => {
|
|
393
|
+
const timer = setTimeout(() => { setDebouncedSearchQuery(searchQuery) }, 150)
|
|
394
|
+
return () => clearTimeout(timer)
|
|
395
|
+
}, [searchQuery])
|
|
396
|
+
|
|
397
|
+
const [preview, setPreview] = React.useState(null)
|
|
398
|
+
const [policyProvider, setPolicyProvider] = React.useState('')
|
|
399
|
+
const [policyDraft, setPolicyDraft] = React.useState({
|
|
400
|
+
include: '',
|
|
401
|
+
exclude: '',
|
|
402
|
+
requireCapabilities: '',
|
|
403
|
+
denyCapabilities: '',
|
|
404
|
+
enableCostFilter: false,
|
|
405
|
+
maxPricePerMillion: '',
|
|
406
|
+
enableContextFilter: false,
|
|
407
|
+
minContextTokens: '',
|
|
408
|
+
})
|
|
409
|
+
const [pageSize, setPageSize] = React.useState(50)
|
|
410
|
+
const [quickFilter, setQuickFilter] = React.useState({ context100k: false, cheap: false })
|
|
411
|
+
const [tryState, setTryState] = React.useState({})
|
|
412
|
+
const [batchTrying, setBatchTrying] = React.useState(false)
|
|
413
|
+
const [batchSummary, setBatchSummary] = React.useState(null)
|
|
414
|
+
|
|
415
|
+
const [aliasDraft, setAliasDraft] = React.useState({ alias: '', provider: '', model: '' })
|
|
416
|
+
const [aliasMsg, setAliasMsg] = React.useState('')
|
|
417
|
+
const [aliasErr, setAliasErr] = React.useState('')
|
|
418
|
+
|
|
419
|
+
const [importText, setImportText] = React.useState('')
|
|
420
|
+
const [importMsg, setImportMsg] = React.useState('')
|
|
421
|
+
const [importErr, setImportErr] = React.useState('')
|
|
422
|
+
const [showImportBox, setShowImportBox] = React.useState(false)
|
|
423
|
+
|
|
101
424
|
const scope = React.useMemo(() => (ctx && ctx.settingsScope ? ctx.settingsScope.bind({ namespace: NS }) : undefined), [ctx])
|
|
102
|
-
const snapshot = React.useSyncExternalStore(
|
|
425
|
+
const snapshot = React.useSyncExternalStore(
|
|
426
|
+
React.useMemo(() => (cb) => (scope ? scope.subscribe(cb) : () => {}), [scope]),
|
|
427
|
+
React.useCallback(() => (scope ? scope.getSnapshot() : { status: 'loading' }), [scope]),
|
|
428
|
+
React.useCallback(() => ({ status: 'loading' }), [])
|
|
429
|
+
)
|
|
103
430
|
const snapStatus = snapshot?.status || 'loading'
|
|
104
431
|
const stored = snapshot?.value || {}
|
|
105
432
|
const [schedDraft, setSchedDraft] = React.useState(null)
|
|
106
433
|
const [schedMsg, setSchedMsg] = React.useState('')
|
|
107
434
|
const [schedErr, setSchedErr] = React.useState('')
|
|
435
|
+
|
|
108
436
|
React.useEffect(() => {
|
|
109
437
|
if (snapStatus === 'ready' && schedDraft === null) {
|
|
110
438
|
setSchedDraft({ scheduleEnabled: stored.scheduleEnabled ?? false, intervalMinutes: stored.intervalMinutes ?? 60, autoApply: stored.autoApply ?? false })
|
|
111
439
|
}
|
|
112
440
|
}, [snapStatus, stored, schedDraft])
|
|
441
|
+
|
|
113
442
|
const saveScheduler = async () => {
|
|
114
443
|
if (!scope || !schedDraft) return
|
|
115
444
|
setBusy(true); setSchedErr(''); setSchedMsg('')
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
445
|
+
try {
|
|
446
|
+
await scope.set('scheduleEnabled', !!schedDraft.scheduleEnabled)
|
|
447
|
+
await scope.set('intervalMinutes', Number(schedDraft.intervalMinutes) || 60)
|
|
448
|
+
await scope.set('autoApply', !!schedDraft.autoApply)
|
|
449
|
+
setSchedMsg(t.schedulerSaved)
|
|
450
|
+
load()
|
|
451
|
+
} catch (e) {
|
|
452
|
+
setSchedErr(String(e?.message ?? e))
|
|
453
|
+
} finally {
|
|
454
|
+
setBusy(false)
|
|
455
|
+
}
|
|
122
456
|
}
|
|
123
|
-
|
|
124
|
-
const doTry = (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
457
|
+
|
|
458
|
+
const doTry = (targetProvider, targetModel) => {
|
|
459
|
+
const key = `${targetProvider}:${targetModel}`
|
|
460
|
+
setTryState((current) => ({ ...current, [key]: { loading: true } }))
|
|
461
|
+
fetch(`${API}/try`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ provider: targetProvider, model: targetModel }) })
|
|
462
|
+
.then(async (r) => { const b = await r.json(); return { ok: r.ok && b.ok !== false, latency: b.latencyMs, status: b.status, error: b.error } })
|
|
463
|
+
.then((res) => { setTryState((current) => ({ ...current, [key]: { loading: false, ok: res.ok, latency: res.latency, status: res.status, error: res.error } })) })
|
|
464
|
+
.catch((err) => { setTryState((current) => ({ ...current, [key]: { loading: false, ok: false, error: String(err?.message ?? err) } })) })
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const runBatchTry = () => {
|
|
468
|
+
if (!selectionProvider || !selectionDraft.length) return
|
|
469
|
+
setBatchTrying(true)
|
|
470
|
+
setError('')
|
|
471
|
+
fetch(`${API}/batch-try`, {
|
|
472
|
+
method: 'POST',
|
|
473
|
+
headers: { 'content-type': 'application/json' },
|
|
474
|
+
body: JSON.stringify({ provider: selectionProvider, models: selectionDraft }),
|
|
475
|
+
})
|
|
476
|
+
.then(async (r) => {
|
|
477
|
+
const data = await r.json()
|
|
478
|
+
if (!r.ok || data.error) throw new Error(data?.error?.message ?? `HTTP ${r.status}`)
|
|
479
|
+
return data
|
|
480
|
+
})
|
|
481
|
+
.then((data) => {
|
|
482
|
+
const next = { ...tryState }
|
|
483
|
+
for (const res of data.results ?? []) {
|
|
484
|
+
next[`${selectionProvider}:${res.model}`] = {
|
|
485
|
+
ok: res.ok,
|
|
486
|
+
latency: res.latencyMs,
|
|
487
|
+
status: res.status,
|
|
488
|
+
error: res.error,
|
|
489
|
+
loading: false,
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
setTryState(next)
|
|
493
|
+
setBatchSummary(data.summary)
|
|
494
|
+
})
|
|
495
|
+
.catch((e) => setError(String(e?.message ?? e)))
|
|
496
|
+
.finally(() => setBatchTrying(false))
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const deselectUnreachable = () => {
|
|
500
|
+
if (!selectionProvider) return
|
|
501
|
+
setSelectionDraft((current) => current.filter((m) => {
|
|
502
|
+
const probe = tryState[`${selectionProvider}:${m}`]
|
|
503
|
+
return !probe || probe.ok !== false
|
|
504
|
+
}))
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const handleExport = () => {
|
|
508
|
+
fetch(`${API}/export`)
|
|
509
|
+
.then((r) => r.json())
|
|
510
|
+
.then((data) => {
|
|
511
|
+
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' })
|
|
512
|
+
const url = URL.createObjectURL(blob)
|
|
513
|
+
const a = document.createElement('a')
|
|
514
|
+
a.href = url
|
|
515
|
+
a.download = `dsh-model-sync-config-${new Date().toISOString().slice(0, 10)}.json`
|
|
516
|
+
a.click()
|
|
517
|
+
URL.revokeObjectURL(url)
|
|
518
|
+
})
|
|
519
|
+
.catch((e) => setError(String(e?.message ?? e)))
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const handleImport = () => {
|
|
523
|
+
if (!importText.trim()) return
|
|
524
|
+
setBusy(true); setImportErr(''); setImportMsg('')
|
|
525
|
+
try {
|
|
526
|
+
const parsed = JSON.parse(importText)
|
|
527
|
+
fetch(`${API}/import`, {
|
|
528
|
+
method: 'POST',
|
|
529
|
+
headers: { 'content-type': 'application/json' },
|
|
530
|
+
body: JSON.stringify(parsed),
|
|
531
|
+
})
|
|
532
|
+
.then(async (r) => {
|
|
533
|
+
const res = await r.json()
|
|
534
|
+
if (!r.ok) throw new Error(res.error?.message ?? `HTTP ${r.status}`)
|
|
535
|
+
return res
|
|
536
|
+
})
|
|
537
|
+
.then(() => {
|
|
538
|
+
setImportMsg(t.importSuccess)
|
|
539
|
+
setImportText('')
|
|
540
|
+
setShowImportBox(false)
|
|
541
|
+
load()
|
|
542
|
+
})
|
|
543
|
+
.catch((e) => setImportErr(t.importError.replace('%s', String(e?.message ?? e))))
|
|
544
|
+
.finally(() => setBusy(false))
|
|
545
|
+
} catch {
|
|
546
|
+
setImportErr(t.importError.replace('%s', 'Invalid JSON syntax'))
|
|
547
|
+
setBusy(false)
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const saveAlias = () => {
|
|
552
|
+
if (!aliasDraft.alias.trim() || !aliasDraft.provider || !aliasDraft.model.trim()) return
|
|
553
|
+
setBusy(true); setAliasErr(''); setAliasMsg('')
|
|
554
|
+
fetch(`${API}/aliases`, {
|
|
555
|
+
method: 'POST',
|
|
556
|
+
headers: { 'content-type': 'application/json' },
|
|
557
|
+
body: JSON.stringify({ alias: aliasDraft.alias.trim(), provider: aliasDraft.provider, model: aliasDraft.model.trim() }),
|
|
558
|
+
})
|
|
559
|
+
.then(async (r) => {
|
|
560
|
+
const res = await r.json()
|
|
561
|
+
if (!r.ok) throw new Error(res.error?.message ?? `HTTP ${r.status}`)
|
|
562
|
+
return res
|
|
563
|
+
})
|
|
564
|
+
.then(() => {
|
|
565
|
+
setAliasDraft({ alias: '', provider: '', model: '' })
|
|
566
|
+
setAliasMsg(t.schedulerSaved)
|
|
567
|
+
load()
|
|
568
|
+
})
|
|
569
|
+
.catch((e) => setAliasErr(String(e?.message ?? e)))
|
|
570
|
+
.finally(() => setBusy(false))
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
const deleteAlias = (aliasName) => {
|
|
574
|
+
setBusy(true)
|
|
575
|
+
fetch(`${API}/aliases`, {
|
|
576
|
+
method: 'POST',
|
|
577
|
+
headers: { 'content-type': 'application/json' },
|
|
578
|
+
body: JSON.stringify({ alias: aliasName, action: 'delete' }),
|
|
579
|
+
})
|
|
580
|
+
.then(async (r) => {
|
|
581
|
+
const res = await r.json()
|
|
582
|
+
if (!r.ok) throw new Error(res.error?.message ?? `HTTP ${r.status}`)
|
|
583
|
+
return res
|
|
584
|
+
})
|
|
585
|
+
.then(() => load())
|
|
586
|
+
.catch((e) => setError(String(e?.message ?? e)))
|
|
587
|
+
.finally(() => setBusy(false))
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const load = () => {
|
|
591
|
+
if (typeof document !== 'undefined' && document.hidden) return
|
|
592
|
+
setError('')
|
|
593
|
+
fetch(`${API}/status`)
|
|
594
|
+
.then((r) => r.json())
|
|
595
|
+
.then(setStatus)
|
|
596
|
+
.catch((e) => setError(String(e?.message ?? e)))
|
|
597
|
+
loadCredentials()
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const loadCredentials = () => {
|
|
601
|
+
fetch(`${API}/credentials`)
|
|
602
|
+
.then((r) => r.json())
|
|
603
|
+
.then(setCredentialStatus)
|
|
604
|
+
.catch(() => {})
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
React.useEffect(() => { ensureStyles(); load() }, [])
|
|
608
|
+
|
|
609
|
+
const execute = (targetProvider) => {
|
|
610
|
+
setBusy(true); setError(''); setPreview(null)
|
|
611
|
+
fetch(`${API}/run`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ provider: targetProvider, dryRun, removeMissing }) })
|
|
612
|
+
.then(async (r) => { const body = await r.json(); if (!r.ok) throw new Error(body?.error?.message ?? `HTTP ${r.status}`); return body })
|
|
613
|
+
.then((body) => {
|
|
614
|
+
setStatus(body)
|
|
615
|
+
if (dryRun && body.results) setPreview(body.results)
|
|
616
|
+
else setPreview(null)
|
|
617
|
+
})
|
|
618
|
+
.catch((e) => setError(String(e?.message ?? e)))
|
|
619
|
+
.finally(() => setBusy(false))
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const checkHealth = (targetProvider) => {
|
|
623
|
+
setBusy(true); setError('')
|
|
624
|
+
fetch(`${API}/health`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ provider: targetProvider }) })
|
|
625
|
+
.then(async (r) => { const body = await r.json(); if (!r.ok) throw new Error(body?.error?.message ?? `HTTP ${r.status}`); return body })
|
|
626
|
+
.then(setStatus)
|
|
627
|
+
.catch((e) => setError(String(e?.message ?? e)))
|
|
628
|
+
.finally(() => setBusy(false))
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
const checkCredentials = (targetProvider) => {
|
|
632
|
+
setBusy(true); setError('')
|
|
633
|
+
fetch(`${API}/credentials/check`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ provider: targetProvider }) })
|
|
634
|
+
.then(async (r) => { const body = await r.json(); if (!r.ok) throw new Error(body?.error?.message ?? `HTTP ${r.status}`); return body })
|
|
635
|
+
.then((body) => { if (body.credentials) setCredentialStatus(body.credentials); load() })
|
|
636
|
+
.catch((e) => setError(String(e?.message ?? e)))
|
|
637
|
+
.finally(() => setBusy(false))
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
const updateNotification = (id, action) => {
|
|
641
|
+
setBusy(true); setError('')
|
|
642
|
+
fetch(`${API}/notifications/${action}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ id }) })
|
|
643
|
+
.then(async (r) => { const body = await r.json(); if (!r.ok) throw new Error(body?.error?.message ?? `HTTP ${r.status}`); return body })
|
|
644
|
+
.then(() => load())
|
|
645
|
+
.catch((e) => setError(String(e?.message ?? e)))
|
|
646
|
+
.finally(() => setBusy(false))
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
const openSelection = (row) => {
|
|
650
|
+
const available = row.availableModels ?? row.models ?? []
|
|
651
|
+
const defaults = row.selectableModels ?? available
|
|
652
|
+
closePolicy()
|
|
653
|
+
setSelectionProvider(row.provider)
|
|
654
|
+
setSelectionDraft(row.selectedModels?.length ? row.selectedModels : defaults.map((model) => model.id))
|
|
655
|
+
setCapabilityFilter([])
|
|
656
|
+
setSearchQuery('')
|
|
657
|
+
setSortBy('name')
|
|
658
|
+
setPageSize(50)
|
|
659
|
+
setQuickFilter({ context100k: false, cheap: false })
|
|
660
|
+
setBatchSummary(null)
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const closeSelection = () => {
|
|
664
|
+
setSelectionProvider('')
|
|
665
|
+
setSelectionDraft([])
|
|
666
|
+
setCapabilityFilter([])
|
|
667
|
+
setSearchQuery('')
|
|
668
|
+
setSortBy('name')
|
|
669
|
+
setPageSize(50)
|
|
670
|
+
setQuickFilter({ context100k: false, cheap: false })
|
|
671
|
+
setBatchSummary(null)
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const openPolicy = (row) => {
|
|
675
|
+
const policy = status?.policies?.[row.provider] ?? row.policy ?? {}
|
|
676
|
+
closeSelection()
|
|
677
|
+
setPolicyProvider(row.provider)
|
|
678
|
+
setPolicyDraft({
|
|
679
|
+
include: (policy.include ?? []).join('\n'),
|
|
680
|
+
exclude: (policy.exclude ?? []).join('\n'),
|
|
681
|
+
requireCapabilities: Object.keys(policy.requireCapabilities ?? {}).join(', '),
|
|
682
|
+
denyCapabilities: Object.keys(policy.denyCapabilities ?? {}).join(', '),
|
|
683
|
+
enableCostFilter: !!policy.enableCostFilter,
|
|
684
|
+
maxPricePerMillion: policy.maxPricePerMillion !== undefined ? String(policy.maxPricePerMillion) : '',
|
|
685
|
+
enableContextFilter: !!policy.enableContextFilter,
|
|
686
|
+
minContextTokens: policy.minContextTokens !== undefined ? String(policy.minContextTokens) : '',
|
|
687
|
+
})
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
const closePolicy = () => {
|
|
691
|
+
setPolicyProvider('')
|
|
692
|
+
setPolicyDraft({
|
|
693
|
+
include: '',
|
|
694
|
+
exclude: '',
|
|
695
|
+
requireCapabilities: '',
|
|
696
|
+
denyCapabilities: '',
|
|
697
|
+
enableCostFilter: false,
|
|
698
|
+
maxPricePerMillion: '',
|
|
699
|
+
enableContextFilter: false,
|
|
700
|
+
minContextTokens: '',
|
|
701
|
+
})
|
|
702
|
+
}
|
|
703
|
+
|
|
136
704
|
const splitValues = (value) => [...new Set(String(value ?? '').split(/[,\n]+/).map((item) => item.trim()).filter(Boolean))]
|
|
137
705
|
const capabilityValues = (value) => Object.fromEntries(splitValues(value).map((key) => [key, true]))
|
|
138
|
-
const validatePatterns = (patterns) => {
|
|
706
|
+
const validatePatterns = (patterns) => {
|
|
707
|
+
for (const p of patterns) {
|
|
708
|
+
try { new RegExp(p, 'i') } catch { return p }
|
|
709
|
+
}
|
|
710
|
+
return null
|
|
711
|
+
}
|
|
712
|
+
|
|
139
713
|
const savePolicy = () => {
|
|
140
714
|
const includeList = splitValues(policyDraft.include)
|
|
141
715
|
const excludeList = splitValues(policyDraft.exclude)
|
|
@@ -143,16 +717,103 @@ window.__ModuleLoader__.load({
|
|
|
143
717
|
if (badInclude) { setError((t.invalidPattern || 'Invalid regex pattern: %s').replace('%s', badInclude)); return }
|
|
144
718
|
const badExclude = validatePatterns(excludeList)
|
|
145
719
|
if (badExclude) { setError((t.invalidPattern || 'Invalid regex pattern: %s').replace('%s', badExclude)); return }
|
|
146
|
-
setBusy(true); setError('')
|
|
720
|
+
setBusy(true); setError('')
|
|
721
|
+
const payload = {
|
|
722
|
+
provider: policyProvider,
|
|
723
|
+
include: includeList,
|
|
724
|
+
exclude: excludeList,
|
|
725
|
+
requireCapabilities: capabilityValues(policyDraft.requireCapabilities),
|
|
726
|
+
denyCapabilities: capabilityValues(policyDraft.denyCapabilities),
|
|
727
|
+
enableCostFilter: !!policyDraft.enableCostFilter,
|
|
728
|
+
...(policyDraft.enableCostFilter && policyDraft.maxPricePerMillion !== '' ? { maxPricePerMillion: Number(policyDraft.maxPricePerMillion) } : {}),
|
|
729
|
+
enableContextFilter: !!policyDraft.enableContextFilter,
|
|
730
|
+
...(policyDraft.enableContextFilter && policyDraft.minContextTokens !== '' ? { minContextTokens: Number(policyDraft.minContextTokens) } : {}),
|
|
731
|
+
}
|
|
732
|
+
fetch(`${API}/policy`, {
|
|
733
|
+
method: 'POST',
|
|
734
|
+
headers: { 'content-type': 'application/json' },
|
|
735
|
+
body: JSON.stringify(payload),
|
|
736
|
+
})
|
|
737
|
+
.then(async (r) => { const body = await r.json(); if (!r.ok) throw new Error(body?.error?.message ?? `HTTP ${r.status}`); return body })
|
|
738
|
+
.then(() => { closePolicy(); return load() })
|
|
739
|
+
.catch((e) => setError(String(e?.message ?? e)))
|
|
740
|
+
.finally(() => setBusy(false))
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
const saveSelection = () => {
|
|
744
|
+
const row = rows.find((item) => item.provider === selectionProvider)
|
|
745
|
+
const available = row?.availableModels ?? row?.models ?? []
|
|
746
|
+
if (available.length > 0 && selectionDraft.length === 0) { setError(t.selectAtLeastOne); return }
|
|
747
|
+
const models = selectionDraft.length === available.length ? [] : selectionDraft
|
|
748
|
+
setBusy(true); setError('')
|
|
749
|
+
fetch(`${API}/selection`, {
|
|
750
|
+
method: 'POST',
|
|
751
|
+
headers: { 'content-type': 'application/json' },
|
|
752
|
+
body: JSON.stringify({ provider: selectionProvider, models }),
|
|
753
|
+
})
|
|
754
|
+
.then(async (r) => { const body = await r.json(); if (!r.ok) throw new Error(body?.error?.message ?? `HTTP ${r.status}`); return body })
|
|
755
|
+
.then((body) => { setStatus(body); closeSelection() })
|
|
756
|
+
.catch((e) => setError(String(e?.message ?? e)))
|
|
757
|
+
.finally(() => setBusy(false))
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
const rollback = (entry, targetProvider) => {
|
|
761
|
+
if (!window.confirm(t.rollbackConfirm)) return
|
|
762
|
+
setBusy(true); setError('')
|
|
763
|
+
fetch(`${API}/history/rollback`, {
|
|
764
|
+
method: 'POST',
|
|
765
|
+
headers: { 'content-type': 'application/json' },
|
|
766
|
+
body: JSON.stringify({ historyId: entry.id, provider: targetProvider }),
|
|
767
|
+
})
|
|
768
|
+
.then(async (r) => { const body = await r.json(); if (!r.ok) throw new Error(body?.error?.message ?? `HTTP ${r.status}`); return body })
|
|
769
|
+
.then(() => load())
|
|
770
|
+
.catch((e) => setError(String(e?.message ?? e)))
|
|
771
|
+
.finally(() => setBusy(false))
|
|
147
772
|
}
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
773
|
+
|
|
774
|
+
const isNewModel = (model, row) => {
|
|
775
|
+
const added = status?.lastRun?.results?.find((r) => r.provider === row.provider)?.diff?.added || []
|
|
776
|
+
const isAdded = added.some((m) => m.id === model.id)
|
|
777
|
+
if (!isAdded) return false
|
|
778
|
+
const finishedAt = status?.lastRun?.finishedAt
|
|
779
|
+
if (!finishedAt) return false
|
|
780
|
+
return (Date.now() - new Date(finishedAt).getTime()) < 7 * 24 * 60 * 60 * 1000
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
const rows = (status?.providers ?? []).filter((row) => row.configured)
|
|
784
|
+
const selectedRow = rows.find((row) => row.provider === selectionProvider)
|
|
785
|
+
const choices = selectedRow?.availableModels ?? selectedRow?.models ?? []
|
|
786
|
+
|
|
787
|
+
const filteredChoices = React.useMemo(() => {
|
|
788
|
+
const filteredChoicesBase = filterModelsByCapabilities(choices, capabilityFilter)
|
|
789
|
+
const tokens = debouncedSearchQuery.trim().toLowerCase().split(/\s+/).filter(Boolean)
|
|
790
|
+
const searchedChoices = tokens.length ? filteredChoicesBase.filter((m) => {
|
|
791
|
+
const haystack = (m.id + ' ' + (m.name || '') + ' ' + (m.aliases || []).join(' ') + ' ' + (m.tags || []).join(' ') + ' ' + (m.description || '')).toLowerCase()
|
|
792
|
+
return tokens.every((tok) => haystack.includes(tok))
|
|
793
|
+
}) : filteredChoicesBase
|
|
794
|
+
const quickFilteredChoices = searchedChoices.filter((m) => {
|
|
795
|
+
if (quickFilter.context100k && (!m.contextWindow || m.contextWindow < 100000)) return false
|
|
796
|
+
if (quickFilter.cheap && (!m.pricing?.inputPerToken || (m.pricing.inputPerToken * 1000000) > 1.0)) return false
|
|
797
|
+
return true
|
|
798
|
+
})
|
|
799
|
+
return [...quickFilteredChoices].sort((a, b) => {
|
|
800
|
+
if (sortBy === 'price') {
|
|
801
|
+
const pa = a.pricing?.inputPerToken ?? Infinity
|
|
802
|
+
const pb = b.pricing?.inputPerToken ?? Infinity
|
|
803
|
+
return pa - pb
|
|
804
|
+
}
|
|
805
|
+
if (sortBy === 'context') return (b.contextWindow ?? 0) - (a.contextWindow ?? 0)
|
|
806
|
+
if (sortBy === 'date') return (b.firstSeenAt ?? 0) - (a.firstSeenAt ?? 0)
|
|
807
|
+
return (a.name || a.id || '').localeCompare(b.name || b.id || '')
|
|
808
|
+
})
|
|
809
|
+
}, [choices, capabilityFilter, debouncedSearchQuery, quickFilter, sortBy])
|
|
810
|
+
|
|
811
|
+
const maxContext = React.useMemo(() => filteredChoices.reduce((max, m) => Math.max(max, m.contextWindow || 0), 0), [filteredChoices])
|
|
812
|
+
const minPrice = React.useMemo(() => filteredChoices.reduce((min, m) => m.pricing?.inputPerToken !== undefined ? Math.min(min, m.pricing.inputPerToken) : min, Infinity), [filteredChoices])
|
|
813
|
+
const availableCapabilities = [...new Set(choices.flatMap((model) => Object.entries(model?.capabilities ?? {}).filter(([, enabled]) => enabled === true).map(([key]) => key)))].sort()
|
|
814
|
+
const visibleChoices = filteredChoices.slice(0, pageSize)
|
|
815
|
+
const button = (label, onClick, variant) => React.createElement('button', { type: 'button', disabled: busy, onClick, className: 'dms-btn' + (variant ? ' dms-btn-' + variant : '') }, label)
|
|
816
|
+
|
|
156
817
|
const renderNotifications = () => {
|
|
157
818
|
const entries = status?.notifications ?? []
|
|
158
819
|
if (entries.length === 0) return React.createElement('small', { style: { display: 'block', marginTop: 6 } }, t.noNotifications)
|
|
@@ -162,6 +823,7 @@ window.__ModuleLoader__.load({
|
|
|
162
823
|
item.acknowledgedAt ? null : button(t.acknowledge, () => updateNotification(item.id, 'acknowledge')),
|
|
163
824
|
React.createElement('small', { style: { display: 'block', marginLeft: 12 } }, (item.providers ?? []).map((row) => row.provider + ': ' + row.status + (row.message ? ' · ' + row.message : '')).join('; '))))
|
|
164
825
|
}
|
|
826
|
+
|
|
165
827
|
const renderScheduler = () => {
|
|
166
828
|
return React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 8, width: '100%' } },
|
|
167
829
|
status?.scheduler ? React.createElement('small', { style: { display: 'block' } }, `${t.scheduler}: ${status.scheduler.active ? t.schedulerOn : t.schedulerOff}${status.scheduler.nextRunAt ? ` · ${t.nextRun}: ${new Date(status.scheduler.nextRunAt).toLocaleString()}` : ''}`) : null,
|
|
@@ -175,6 +837,75 @@ window.__ModuleLoader__.load({
|
|
|
175
837
|
) : null
|
|
176
838
|
)
|
|
177
839
|
}
|
|
840
|
+
|
|
841
|
+
const renderAliases = () => {
|
|
842
|
+
const aliasMap = status?.aliases ?? {}
|
|
843
|
+
const entries = Object.entries(aliasMap)
|
|
844
|
+
return React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 8, width: '100%' } },
|
|
845
|
+
entries.length === 0 ? React.createElement('small', { style: { display: 'block', marginTop: 4 } }, t.noAliases) : entries.map(([aliasName, data]) => {
|
|
846
|
+
return React.createElement('div', { key: aliasName, className: 'dms-row', style: { justifyContent: 'space-between', padding: '6px 10px', border: '1px solid var(--dsw-alias-border-l2)', borderRadius: 6, background: 'var(--dsw-alias-bg-layer-2)' } },
|
|
847
|
+
React.createElement('div', { style: { display: 'flex', gap: 8, alignItems: 'center' } },
|
|
848
|
+
React.createElement('strong', { style: { fontFamily: 'monospace', fontSize: 13 } }, aliasName),
|
|
849
|
+
React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 12 } }, `→ ${data.provider} / ${data.model}`)
|
|
850
|
+
),
|
|
851
|
+
button(t.removeAlias, () => deleteAlias(aliasName), 'danger')
|
|
852
|
+
)
|
|
853
|
+
}),
|
|
854
|
+
React.createElement('div', { className: 'dms-row', style: { marginTop: 8, gap: 8 } },
|
|
855
|
+
React.createElement('input', {
|
|
856
|
+
className: 'dms-input',
|
|
857
|
+
placeholder: t.aliasPlaceholder,
|
|
858
|
+
value: aliasDraft.alias,
|
|
859
|
+
onChange: (e) => setAliasDraft((d) => ({ ...d, alias: e.target.value })),
|
|
860
|
+
style: { flex: '1 1 140px' }
|
|
861
|
+
}),
|
|
862
|
+
React.createElement('select', {
|
|
863
|
+
className: 'dms-input',
|
|
864
|
+
value: aliasDraft.provider,
|
|
865
|
+
onChange: (e) => setAliasDraft((d) => ({ ...d, provider: e.target.value, model: '' })),
|
|
866
|
+
style: { flex: '1 1 120px' }
|
|
867
|
+
},
|
|
868
|
+
React.createElement('option', { value: '' }, `-- ${t.targetProvider} --`),
|
|
869
|
+
rows.map((r) => React.createElement('option', { key: r.provider, value: r.provider }, r.provider))
|
|
870
|
+
),
|
|
871
|
+
React.createElement('input', {
|
|
872
|
+
className: 'dms-input',
|
|
873
|
+
placeholder: t.targetModel,
|
|
874
|
+
value: aliasDraft.model,
|
|
875
|
+
onChange: (e) => setAliasDraft((d) => ({ ...d, model: e.target.value })),
|
|
876
|
+
style: { flex: '1 1 140px' }
|
|
877
|
+
}),
|
|
878
|
+
button(t.addAlias, saveAlias, 'primary')
|
|
879
|
+
),
|
|
880
|
+
aliasMsg ? React.createElement('small', { style: { color: 'var(--dsw-alias-state-success-primary)' } }, aliasMsg) : null,
|
|
881
|
+
aliasErr ? React.createElement('small', { style: { color: 'var(--dsw-alias-state-error-primary)' } }, aliasErr) : null
|
|
882
|
+
)
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
const renderExportImport = () => {
|
|
886
|
+
return React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 8, width: '100%' } },
|
|
887
|
+
React.createElement('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap', alignItems: 'center' } },
|
|
888
|
+
button(t.exportConfig, handleExport),
|
|
889
|
+
button(t.importConfig, () => setShowImportBox((v) => !v)),
|
|
890
|
+
importMsg ? React.createElement('small', { style: { color: 'var(--dsw-alias-state-success-primary)' } }, importMsg) : null,
|
|
891
|
+
importErr ? React.createElement('small', { style: { color: 'var(--dsw-alias-state-error-primary)' } }, importErr) : null
|
|
892
|
+
),
|
|
893
|
+
showImportBox ? React.createElement('div', { className: 'dms-editor', style: { marginTop: 6 } },
|
|
894
|
+
React.createElement('textarea', {
|
|
895
|
+
rows: 4,
|
|
896
|
+
value: importText,
|
|
897
|
+
onChange: (e) => setImportText(e.target.value),
|
|
898
|
+
placeholder: t.importPlaceholder,
|
|
899
|
+
style: { width: '100%', fontFamily: 'monospace', fontSize: 12 }
|
|
900
|
+
}),
|
|
901
|
+
React.createElement('div', { style: { display: 'flex', gap: 8, marginTop: 6 } },
|
|
902
|
+
button(t.apply, handleImport, 'primary'),
|
|
903
|
+
button(t.cancel, () => { setShowImportBox(false); setImportErr('') })
|
|
904
|
+
)
|
|
905
|
+
) : null
|
|
906
|
+
)
|
|
907
|
+
}
|
|
908
|
+
|
|
178
909
|
const renderHistory = () => {
|
|
179
910
|
const entries = status?.history ?? []
|
|
180
911
|
if (entries.length === 0) return React.createElement('small', { style: { display: 'block', marginTop: 6 } }, t.noHistory)
|
|
@@ -190,69 +921,251 @@ window.__ModuleLoader__.load({
|
|
|
190
921
|
React.createElement('small', { style: { display: 'block', marginTop: 4 } }, details))
|
|
191
922
|
})))
|
|
192
923
|
}
|
|
924
|
+
|
|
193
925
|
return React.createElement('div', { className: 'dms-wrap' },
|
|
194
926
|
includeIntro ? React.createElement('p', null, t.desc) : null,
|
|
195
|
-
React.createElement('div', { className: 'dms-toolbar' },
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
927
|
+
React.createElement('div', { className: 'dms-toolbar' },
|
|
928
|
+
React.createElement('select', { value: provider, onChange: (e) => setProvider(e.target.value) },
|
|
929
|
+
React.createElement('option', { value: '' }, t.all),
|
|
930
|
+
rows.map((row) => React.createElement('option', { key: row.provider, value: row.provider }, row.provider))
|
|
931
|
+
),
|
|
932
|
+
React.createElement('label', { style: { marginLeft: 12 } }, React.createElement('input', { type: 'checkbox', checked: dryRun, onChange: (e) => setDryRun(e.target.checked) }), ` ${t.dryRun}`),
|
|
933
|
+
React.createElement('label', { style: { marginLeft: 12 } }, React.createElement('input', { type: 'checkbox', checked: removeMissing, onChange: (e) => setRemoveMissing(e.target.checked) }), ` ${t.removeMissing}`)
|
|
934
|
+
),
|
|
935
|
+
React.createElement('div', { className: 'dms-actions' },
|
|
936
|
+
button(t.refresh, load),
|
|
937
|
+
button(t.refreshAll, () => execute(undefined)),
|
|
938
|
+
button(dryRun ? t.run : t.apply, () => execute(provider || undefined), dryRun ? undefined : 'primary'),
|
|
939
|
+
button(t.health, () => checkHealth(provider || undefined)),
|
|
940
|
+
button(t.checkCredentials, () => checkCredentials(provider || undefined))
|
|
941
|
+
),
|
|
942
|
+
busy ? React.createElement('span', null, t.running) : null,
|
|
943
|
+
error ? React.createElement('div', { className: 'dms-alert dms-alert-bad' }, error) : null,
|
|
944
|
+
preview ? React.createElement('div', { className: 'dms-editor' },
|
|
945
|
+
React.createElement('strong', null, t.previewTitle),
|
|
946
|
+
preview.length === 0 ? React.createElement('small', null, t.previewNone) : preview.map((item) => {
|
|
947
|
+
const counts = item.counts ?? {}
|
|
948
|
+
const names = (items) => (items ?? []).map((model) => model?.after?.id ?? model?.id).filter(Boolean).join(', ')
|
|
949
|
+
const details = `+ ${names(item.diff?.added)}; - ${names(item.diff?.removed)}; ⇄ ${(item.diff?.renamed ?? []).map((pair) => `${pair.before?.id} → ${pair.after?.id}`).join(', ')}; ~ ${(item.diff?.changed ?? []).map((pair) => pair.after?.id).join(', ')}`
|
|
950
|
+
return React.createElement('div', { key: item.provider, style: { margin: '4px 0' } },
|
|
951
|
+
React.createElement('span', null, `${item.provider}: ${item.status} · +${counts.added ?? 0} ${t.previewAdded}, -${counts.removed ?? 0} ${t.previewRemoved}, ${counts.changed ?? 0} ${t.previewChanged}`),
|
|
952
|
+
React.createElement('small', { style: { display: 'block', marginLeft: 8 } }, details)
|
|
953
|
+
)
|
|
954
|
+
}),
|
|
955
|
+
React.createElement('div', { style: { marginTop: 8 } },
|
|
956
|
+
button(t.previewApply, () => execute(provider || undefined), 'primary'),
|
|
957
|
+
button(t.previewDismiss, () => setPreview(null))
|
|
958
|
+
)
|
|
959
|
+
) : null,
|
|
960
|
+
status?.lastRun ? React.createElement('small', null, `${t.lastRun}: ${new Date(status.lastRun.finishedAt).toLocaleString()}`) : null,
|
|
961
|
+
rows.length === 0 ? React.createElement('p', null, t.noProviders) : rows.map((row) => {
|
|
204
962
|
const latestRun = status?.lastRun?.results?.find((item) => item.provider === row.provider)
|
|
205
963
|
const addedCount = latestRun?.status === 'ok' ? (latestRun.diff?.added?.length ?? 0) : 0
|
|
206
|
-
const
|
|
207
|
-
const
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
const
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
964
|
+
const count = row.models?.length ?? 0
|
|
965
|
+
const availableCount = row.availableModels?.length ?? count
|
|
966
|
+
const staleCount = row.staleModels?.length ?? 0
|
|
967
|
+
const deprecatedCount = row.deprecatedModels?.length ?? 0
|
|
968
|
+
const cachedHours = row.cachedAt ? Math.round((Date.now() - new Date(row.cachedAt).getTime()) / 3600000) : null
|
|
969
|
+
const isStaleDiscovery = row.staleDiscovery === true
|
|
970
|
+
const metaBadges = []
|
|
971
|
+
if (cachedHours !== null) metaBadges.push(t.cacheHoursAgo.replace('%d', cachedHours))
|
|
972
|
+
if (staleCount > 0) metaBadges.push(`${staleCount} ${t.stale}`)
|
|
973
|
+
if (deprecatedCount > 0) metaBadges.push(`${deprecatedCount} ${t.deprecated}`)
|
|
974
|
+
const modelSummary = count === availableCount ? `${count} ${t.selected}` : `${count}/${availableCount} ${t.selected}`
|
|
975
|
+
const healthBadge = row.health?.status ? React.createElement('span', { className: 'dms-badge ' + (row.health.status === 'ok' ? 'dms-badge-ok' : row.health.status === 'dormant' ? 'dms-badge-warn' : 'dms-badge-bad') }, row.health.status === 'ok' ? t.healthOk : row.health.status === 'dormant' ? t.healthDormant : t.healthError) : null
|
|
976
|
+
const staleBadge = isStaleDiscovery ? React.createElement('span', { className: 'dms-badge dms-badge-warn' }, t.stale) : null
|
|
977
|
+
const providerCard = React.createElement('div', { key: row.provider, className: 'dms-provider' },
|
|
978
|
+
React.createElement('span', null,
|
|
979
|
+
React.createElement('strong', null, row.provider),
|
|
980
|
+
` · ${row.configured ? t.ok : t.dormant} · ${modelSummary}`,
|
|
981
|
+
metaBadges.length ? ` · ${metaBadges.join(' · ')}` : '',
|
|
982
|
+
' ', healthBadge, ' ', staleBadge
|
|
221
983
|
),
|
|
222
984
|
button(t.selectModels, () => openSelection(row)),
|
|
223
985
|
button(t.policy, () => openPolicy(row))
|
|
224
986
|
)
|
|
225
|
-
|
|
226
|
-
const
|
|
987
|
+
|
|
988
|
+
const selectionEditor = selectionProvider === row.provider ? React.createElement('div', { className: 'dms-editor' },
|
|
989
|
+
React.createElement('strong', null, `${t.selectModels}: ${selectionProvider}`),
|
|
990
|
+
React.createElement('div', { style: { display: 'flex', gap: 8, margin: '8px 0', flexWrap: 'wrap' } },
|
|
991
|
+
React.createElement('input', { placeholder: t.searchPlaceholder, value: searchQuery, onChange: (e) => setSearchQuery(e.target.value), style: { flex: '1 1 160px', padding: '6px 8px', borderRadius: 6, border: '1px solid var(--dsw-alias-border-l2)', background: 'var(--dsw-alias-bg-layer-2)' } }),
|
|
992
|
+
React.createElement('select', { value: sortBy, onChange: (e) => setSortBy(e.target.value), style: { padding: '6px 8px', borderRadius: 6 } },
|
|
993
|
+
React.createElement('option', { value: 'name' }, t.sortName),
|
|
994
|
+
React.createElement('option', { value: 'price' }, t.sortPrice),
|
|
995
|
+
React.createElement('option', { value: 'context' }, t.sortContext),
|
|
996
|
+
React.createElement('option', { value: 'date' }, t.sortDate)
|
|
997
|
+
)
|
|
998
|
+
),
|
|
999
|
+
React.createElement('div', { style: { display: 'flex', gap: 6, margin: '6px 0', flexWrap: 'wrap' } },
|
|
1000
|
+
React.createElement('button', { type: 'button', className: 'dms-btn', style: quickFilter.context100k ? { borderColor: 'var(--dsw-alias-brand-primary)', background: 'var(--dsw-alias-bg-layer-2)' } : {}, onClick: () => setQuickFilter((f) => ({ ...f, context100k: !f.context100k })) }, (quickFilter.context100k ? '✓ ' : '') + t.filterContext100k),
|
|
1001
|
+
React.createElement('button', { type: 'button', className: 'dms-btn', style: quickFilter.cheap ? { borderColor: 'var(--dsw-alias-brand-primary)', background: 'var(--dsw-alias-bg-layer-2)' } : {}, onClick: () => setQuickFilter((f) => ({ ...f, cheap: !f.cheap })) }, (quickFilter.cheap ? '✓ ' : '') + t.filterCheap)
|
|
1002
|
+
),
|
|
1003
|
+
React.createElement('div', { style: { margin: '8px 0' } },
|
|
1004
|
+
choices.length === 0 ? React.createElement('small', null, t.noModels) : React.createElement(React.Fragment, null,
|
|
1005
|
+
availableCapabilities.length > 0 ? React.createElement('div', { style: { marginBottom: 8 } },
|
|
1006
|
+
React.createElement('strong', null, t.capabilityFilter),
|
|
1007
|
+
availableCapabilities.map((capability) => React.createElement('label', { key: capability, style: { display: 'inline-block', marginLeft: 8 } },
|
|
1008
|
+
React.createElement('input', { type: 'checkbox', checked: capabilityFilter.includes(capability), onChange: (e) => setCapabilityFilter((current) => e.target.checked ? [...current, capability] : current.filter((item) => item !== capability)) }),
|
|
1009
|
+
' ' + (CAPABILITY_LABELS[capability]?.[locale] ?? capability)
|
|
1010
|
+
))
|
|
1011
|
+
) : React.createElement('small', { style: { display: 'block', marginBottom: 8 } }, t.noCapabilities),
|
|
1012
|
+
React.createElement('div', { style: { display: 'flex', gap: 6, margin: '6px 0', flexWrap: 'wrap' } },
|
|
1013
|
+
button(t.selectAllFiltered, () => { const ids = new Set(selectionDraft); for (const m of filteredChoices) ids.add(m.id); setSelectionDraft([...ids]) }),
|
|
1014
|
+
button(t.deselectAllFiltered, () => { const filterSet = new Set(filteredChoices.map((m) => m.id)); setSelectionDraft(selectionDraft.filter((id) => !filterSet.has(id))) }),
|
|
1015
|
+
button(t.invertFiltered, () => { const current = new Set(selectionDraft); for (const m of filteredChoices) { if (current.has(m.id)) current.delete(m.id); else current.add(m.id); } setSelectionDraft([...current]) })
|
|
1016
|
+
),
|
|
1017
|
+
React.createElement('div', { style: { display: 'flex', gap: 6, margin: '6px 0', flexWrap: 'wrap', alignItems: 'center' } },
|
|
1018
|
+
button(batchTrying ? t.batchTryRunning : t.batchTry, runBatchTry),
|
|
1019
|
+
batchSummary && batchSummary.unreachable > 0 ? button(t.batchTryDeselectUnreachable, deselectUnreachable, 'danger') : null,
|
|
1020
|
+
batchSummary ? React.createElement('small', { style: { color: 'var(--dsw-alias-label-secondary)' } }, t.batchTryResults.replace('%d', batchSummary.reachable).replace('%d', batchSummary.total)) : null
|
|
1021
|
+
),
|
|
1022
|
+
React.createElement('small', { style: { display: 'block', marginBottom: 8 } }, `${filteredChoices.length}/${choices.length} ${t.capabilityCount}`),
|
|
1023
|
+
visibleChoices.map((model) => {
|
|
1024
|
+
const deprecationDays = (() => {
|
|
1025
|
+
const d = model.lifecycle?.deprecationDate
|
|
1026
|
+
if (!d) return null
|
|
1027
|
+
const diff = new Date(d).getTime() - Date.now()
|
|
1028
|
+
return diff > 0 ? Math.ceil(diff / (1000 * 60 * 60 * 24)) : 0
|
|
1029
|
+
})()
|
|
1030
|
+
const probe = tryState[`${row.provider}:${model.id}`]
|
|
1031
|
+
return React.createElement('label', { key: model.id, style: { display: 'block', margin: '4px 0', padding: '4px 6px', borderRadius: 6, background: isNewModel(model, row) ? 'var(--dsw-alias-bg-layer-2)' : 'transparent' } },
|
|
1032
|
+
React.createElement('input', { type: 'checkbox', checked: selectionDraft.includes(model.id), onChange: (e) => setSelectionDraft((current) => e.target.checked ? [...current, model.id] : current.filter((id) => id !== model.id)) }),
|
|
1033
|
+
` ${model.name ?? model.id} (${model.id})`,
|
|
1034
|
+
isNewModel(model, row) ? React.createElement('span', { style: { marginLeft: 6, fontSize: 11, padding: '1px 5px', borderRadius: 4, background: 'var(--dsw-alias-state-business-primary)', color: 'white' } }, 'NEW') : null,
|
|
1035
|
+
deprecationDays !== null ? React.createElement('span', { style: { marginLeft: 6, fontSize: 10, padding: '1px 5px', borderRadius: 4, background: 'var(--dsw-alias-state-warning-primary)', color: 'white' } }, deprecationDays > 0 ? t.deprecatesIn.replace('%d', deprecationDays) : t.deprecated) : null,
|
|
1036
|
+
(model.contextWindow && maxContext > 0 && model.contextWindow >= maxContext) ? React.createElement('span', { style: { marginLeft: 4, fontSize: 10, padding: '1px 4px', borderRadius: 3, background: 'var(--dsw-alias-state-warning-primary)', color: 'white' } }, '★') : null,
|
|
1037
|
+
(model.pricing && minPrice !== Infinity && model.pricing.inputPerToken === minPrice) ? React.createElement('span', { style: { marginLeft: 4, fontSize: 10, padding: '1px 4px', borderRadius: 3, background: 'var(--dsw-alias-state-success-primary)', color: 'white' } }, '$') : null,
|
|
1038
|
+
model.tags && model.tags.length ? React.createElement('small', { style: { marginLeft: 6, color: 'var(--dsw-alias-label-secondary)' } }, model.tags.join(', ')) : null,
|
|
1039
|
+
model.pricing ? React.createElement('small', { style: { marginLeft: 6, color: 'var(--dsw-alias-label-secondary)', fontSize: 11 } }, `in $${(model.pricing.inputPerToken * 1000000).toFixed(2)}/1M` + (model.pricing.cacheReadPerToken !== undefined ? ` / cache $${(model.pricing.cacheReadPerToken * 1000000).toFixed(2)}` : '') + (model.pricing.outputPerToken !== undefined ? ` / out $${(model.pricing.outputPerToken * 1000000).toFixed(2)}` : '')) : null,
|
|
1040
|
+
model.description ? React.createElement('small', { title: model.description, style: { display: 'block', marginLeft: 22, color: 'var(--dsw-alias-label-secondary)', fontSize: 11 } }, model.description.slice(0, 120)) : null,
|
|
1041
|
+
row.baseURL || row.api ? React.createElement('a', { href: (row.baseURL || '') + '/models/' + encodeURIComponent(model.id), target: '_blank', rel: 'noopener', style: { marginLeft: 8, fontSize: 11 } }, 'docs') : null,
|
|
1042
|
+
React.createElement('button', { type: 'button', onClick: (e) => { e.preventDefault(); doTry(row.provider, model.id) }, style: { marginLeft: 8, fontSize: 11, padding: '1px 6px', borderRadius: 4 } }, (probe && probe.loading) ? '…' : '▶'),
|
|
1043
|
+
probe && !probe.loading ? React.createElement('span', { className: 'dms-badge ' + (probe.ok ? 'dms-badge-ok' : 'dms-badge-bad'), style: { marginLeft: 6 } }, probe.ok ? `${probe.latency}ms` : (probe.error || probe.status || 'offline')) : null
|
|
1044
|
+
)
|
|
1045
|
+
}),
|
|
1046
|
+
filteredChoices.length > pageSize ? React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 8, margin: '8px 0' } },
|
|
1047
|
+
button(t.showMore.replace('%d', Math.min(50, filteredChoices.length - pageSize)), () => setPageSize((s) => s + 50)),
|
|
1048
|
+
React.createElement('small', { style: { color: 'var(--dsw-alias-label-secondary)' } }, t.showingCount.replace('%d', visibleChoices.length).replace('%d', filteredChoices.length))
|
|
1049
|
+
) : null
|
|
1050
|
+
)
|
|
1051
|
+
),
|
|
1052
|
+
React.createElement('small', null, t.pickerNote),
|
|
1053
|
+
React.createElement('div', { style: { marginTop: 8 } },
|
|
1054
|
+
button(t.allModels, () => setSelectionDraft(choices.map((model) => model.id))),
|
|
1055
|
+
button(t.saveSelection, saveSelection, 'primary'),
|
|
1056
|
+
button(t.cancel, closeSelection)
|
|
1057
|
+
)
|
|
1058
|
+
) : null
|
|
1059
|
+
|
|
1060
|
+
const policyEditor = policyProvider === row.provider ? React.createElement('div', { className: 'dms-editor' },
|
|
1061
|
+
React.createElement('strong', null, `${t.policy}: ${policyProvider}`),
|
|
1062
|
+
React.createElement('label', { style: { display: 'block', marginTop: 8 } }, t.policyInclude,
|
|
1063
|
+
React.createElement('textarea', { rows: 3, value: policyDraft.include, onChange: (e) => setPolicyDraft((current) => ({ ...current, include: e.target.value })), style: { display: 'block', width: '100%' } })
|
|
1064
|
+
),
|
|
1065
|
+
React.createElement('label', { style: { display: 'block', marginTop: 8 } }, t.policyExclude,
|
|
1066
|
+
React.createElement('textarea', { rows: 3, value: policyDraft.exclude, onChange: (e) => setPolicyDraft((current) => ({ ...current, exclude: e.target.value })), style: { display: 'block', width: '100%' } })
|
|
1067
|
+
),
|
|
1068
|
+
React.createElement('label', { style: { display: 'block', marginTop: 8 } }, t.policyRequire,
|
|
1069
|
+
React.createElement('input', { value: policyDraft.requireCapabilities, onChange: (e) => setPolicyDraft((current) => ({ ...current, requireCapabilities: e.target.value })), style: { display: 'block', width: '100%' } })
|
|
1070
|
+
),
|
|
1071
|
+
React.createElement('label', { style: { display: 'block', marginTop: 8 } }, t.policyDeny,
|
|
1072
|
+
React.createElement('input', { value: policyDraft.denyCapabilities, onChange: (e) => setPolicyDraft((current) => ({ ...current, denyCapabilities: e.target.value })), style: { display: 'block', width: '100%' } })
|
|
1073
|
+
),
|
|
1074
|
+
React.createElement('label', { style: { display: 'flex', alignItems: 'center', gap: 7, marginTop: 8, cursor: 'pointer' } },
|
|
1075
|
+
React.createElement('input', { type: 'checkbox', checked: !!policyDraft.enableCostFilter, onChange: (e) => setPolicyDraft((c) => ({ ...c, enableCostFilter: e.target.checked })) }),
|
|
1076
|
+
t.enableCostFilter
|
|
1077
|
+
),
|
|
1078
|
+
policyDraft.enableCostFilter ? React.createElement('label', { style: { display: 'block', marginTop: 4, marginLeft: 22 } },
|
|
1079
|
+
t.maxPricePerMillion,
|
|
1080
|
+
React.createElement('input', { type: 'number', step: '0.1', min: '0', value: policyDraft.maxPricePerMillion ?? '', onChange: (e) => setPolicyDraft((c) => ({ ...c, maxPricePerMillion: e.target.value })), style: { display: 'block', width: 140, marginTop: 4 } })
|
|
1081
|
+
) : null,
|
|
1082
|
+
React.createElement('label', { style: { display: 'flex', alignItems: 'center', gap: 7, marginTop: 8, cursor: 'pointer' } },
|
|
1083
|
+
React.createElement('input', { type: 'checkbox', checked: !!policyDraft.enableContextFilter, onChange: (e) => setPolicyDraft((c) => ({ ...c, enableContextFilter: e.target.checked })) }),
|
|
1084
|
+
t.enableContextFilter
|
|
1085
|
+
),
|
|
1086
|
+
policyDraft.enableContextFilter ? React.createElement('label', { style: { display: 'block', marginTop: 4, marginLeft: 22 } },
|
|
1087
|
+
t.minContextTokens,
|
|
1088
|
+
React.createElement('input', { type: 'number', step: '1000', min: '0', value: policyDraft.minContextTokens ?? '', onChange: (e) => setPolicyDraft((c) => ({ ...c, minContextTokens: e.target.value })), style: { display: 'block', width: 140, marginTop: 4 } })
|
|
1089
|
+
) : null,
|
|
1090
|
+
React.createElement('small', null, t.policyNote),
|
|
1091
|
+
React.createElement('div', { style: { marginTop: 8 } },
|
|
1092
|
+
button(t.savePolicy, savePolicy, 'primary'),
|
|
1093
|
+
button(t.cancel, closePolicy)
|
|
1094
|
+
)
|
|
1095
|
+
) : null
|
|
1096
|
+
|
|
227
1097
|
return React.createElement('div', { key: row.provider, className: 'dms-provider-wrap' }, providerCard, selectionEditor, policyEditor)
|
|
228
1098
|
}),
|
|
229
|
-
React.createElement('div', { className: 'dms-section-card dms-section' },
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
1099
|
+
React.createElement('div', { className: 'dms-section-card dms-section' },
|
|
1100
|
+
React.createElement('div', { className: 'dms-section-title' }, React.createElement('strong', null, t.modelAliases)),
|
|
1101
|
+
renderAliases()
|
|
1102
|
+
),
|
|
1103
|
+
React.createElement('div', { className: 'dms-section-card dms-section' },
|
|
1104
|
+
React.createElement('div', { className: 'dms-section-title' }, React.createElement('strong', null, t.exportImportTitle)),
|
|
1105
|
+
renderExportImport()
|
|
1106
|
+
),
|
|
1107
|
+
React.createElement('div', { className: 'dms-section-card dms-section' },
|
|
1108
|
+
React.createElement('div', { className: 'dms-section-title' }, React.createElement('strong', null, t.notifications)),
|
|
1109
|
+
renderNotifications()
|
|
1110
|
+
),
|
|
1111
|
+
React.createElement('div', { className: 'dms-section-card dms-section' },
|
|
1112
|
+
React.createElement('div', { className: 'dms-section-title' }, React.createElement('strong', null, t.credentials)),
|
|
1113
|
+
credentialStatus === null ? React.createElement('small', { style: { display: 'block', marginTop: 6 } }, t.loading) : (credentialStatus.results ?? []).length === 0 ? React.createElement('small', { style: { display: 'block', marginTop: 6 } }, t.noProviders) : (credentialStatus.results ?? []).map((item) => React.createElement('div', { key: item.provider, style: { marginTop: 6 } }, React.createElement('span', null, `${item.provider}: ${item.rotation?.configured ? `${item.rotation.keyCount} refs` : 'single ref'}${item.lastRequest ? ` · ${item.lastRequest.status}` : ''}`), (item.refs ?? []).map((ref) => React.createElement('small', { key: ref.ref || ref.label, style: { display: 'block', marginLeft: 12 } }, `${ref.order}. ${ref.label} · ${ref.configured === true ? t.credentialReady : t.missingCredential}${ref.source && ref.source !== 'unknown' ? ` · ${ref.source}` : ''}${ref.lastResolution?.status ? ` · ${ref.lastResolution.status}` : ''}`))))
|
|
1114
|
+
),
|
|
1115
|
+
React.createElement('div', { className: 'dms-section-card dms-section' },
|
|
1116
|
+
React.createElement('div', { className: 'dms-section-title' }, React.createElement('strong', null, t.schedulerSettings)),
|
|
1117
|
+
renderScheduler()
|
|
1118
|
+
),
|
|
1119
|
+
React.createElement('div', { className: 'dms-section-card dms-section' },
|
|
1120
|
+
React.createElement('div', { className: 'dms-section-title' }, React.createElement('strong', null, t.history)),
|
|
1121
|
+
renderHistory()
|
|
1122
|
+
)
|
|
233
1123
|
)
|
|
234
1124
|
}
|
|
1125
|
+
|
|
235
1126
|
function ModelSyncCard({ ctx }) {
|
|
236
|
-
const locale = useLocale(ctx)
|
|
1127
|
+
const locale = useLocale(ctx)
|
|
1128
|
+
const t = locale === 'zh' ? zh : en
|
|
1129
|
+
const [open, setOpen] = React.useState(false)
|
|
237
1130
|
const [cardStatus, setCardStatus] = React.useState(null)
|
|
238
|
-
React.useEffect(() => {
|
|
239
|
-
|
|
1131
|
+
React.useEffect(() => {
|
|
1132
|
+
ensureStyles()
|
|
1133
|
+
const load = () => {
|
|
1134
|
+
if (typeof document !== 'undefined' && document.hidden) return
|
|
1135
|
+
fetch(`${API}/status`).then((r) => r.json()).then(setCardStatus).catch(() => {})
|
|
1136
|
+
}
|
|
1137
|
+
load()
|
|
1138
|
+
if (open) return
|
|
1139
|
+
const id = setInterval(load, 15000)
|
|
1140
|
+
return () => clearInterval(id)
|
|
1141
|
+
}, [open])
|
|
1142
|
+
const cardBadge = (cardStatus?.lastRun?.results?.reduce((s, r) => s + (r.diff?.added?.length || 0), 0) || 0)
|
|
240
1143
|
return React.createElement('li', { className: 'dms-card' + (open ? ' dms-card-open' : '') },
|
|
241
1144
|
React.createElement('button', { type: 'button', className: 'dms-card-header', 'aria-expanded': open, 'aria-label': `${t[open ? 'hideSettings' : 'showSettings']}: ${t.title}`, onClick: () => setOpen((value) => !value) },
|
|
242
|
-
React.createElement('span', { className: 'dms-card-head-text' },
|
|
1145
|
+
React.createElement('span', { className: 'dms-card-head-text' },
|
|
1146
|
+
React.createElement('span', { className: 'dms-card-name' }, t.title),
|
|
1147
|
+
React.createElement('span', { className: 'dms-card-description' }, t.desc)
|
|
1148
|
+
),
|
|
243
1149
|
cardBadge ? React.createElement('span', { style: { background: 'var(--dsw-alias-state-business-primary)', color: 'white', padding: '2px 6px', borderRadius: 6, fontSize: 11, marginLeft: 8 } }, `+${cardBadge}`) : null,
|
|
244
|
-
React.createElement('svg', { width: 14, height: 14, className: 'dms-card-chevron' + (open ? ' dms-card-chevron-open' : ''), viewBox: '0 0 14 14', fill: 'none', 'aria-hidden': 'true' },
|
|
245
|
-
|
|
1150
|
+
React.createElement('svg', { width: 14, height: 14, className: 'dms-card-chevron' + (open ? ' dms-card-chevron-open' : ''), viewBox: '0 0 14 14', fill: 'none', 'aria-hidden': 'true' },
|
|
1151
|
+
React.createElement('path', { d: 'M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 8.90706 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5', fill: 'currentColor' })
|
|
1152
|
+
)
|
|
1153
|
+
),
|
|
1154
|
+
open ? React.createElement('div', { className: 'dms-card-body' }, React.createElement(ErrorBoundary, null, React.createElement(ModelSyncSection, { ctx, includeIntro: false }))) : null
|
|
1155
|
+
)
|
|
246
1156
|
}
|
|
1157
|
+
|
|
247
1158
|
function apply(ctx) {
|
|
248
1159
|
ctx.effect(() => {
|
|
249
|
-
try { ctx.locale?.register?.(NS, { en,
|
|
1160
|
+
try { ctx.locale?.register?.(NS, { en, zh }) } catch {}
|
|
250
1161
|
return () => {}
|
|
251
1162
|
}, 'dsh-model-sync: dictionaries')
|
|
252
1163
|
try {
|
|
253
1164
|
ctx.slots.inject('settings.plugin.item', () => ctx.slots.register({ name: 'settings.plugin.item', key: NS, locale: NS, inject: () => ({ ctx }) }, (props) => React.createElement(ErrorBoundary, null, React.createElement(ModelSyncCard, { ...props, ctx }))))
|
|
254
1165
|
} catch {}
|
|
255
1166
|
}
|
|
256
|
-
|
|
1167
|
+
|
|
1168
|
+
module.exports = { apply, inject: ['slots', 'locale', 'settingsScope'], filterModelsByCapabilities }
|
|
1169
|
+
return module.exports
|
|
257
1170
|
},
|
|
258
1171
|
})
|