dsh-cliproxyapi-pro 1.8.0 → 1.9.1
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/CHANGELOG.md +23 -0
- package/README.en.md +38 -409
- package/README.md +38 -409
- package/lib/client.js +131 -28
- package/lib/host/accounts.js +176 -0
- package/lib/host/apply/agent-tool.js +406 -0
- package/lib/host/apply/commands.js +122 -0
- package/lib/host/apply/controller.js +105 -0
- package/lib/host/apply/http-routes.js +273 -0
- package/lib/host/apply/image-jobs.js +171 -0
- package/lib/host/apply/index.js +41 -0
- package/lib/host/apply/interpret.js +72 -0
- package/lib/host/apply/lifecycle.js +34 -0
- package/lib/host/apply/media-failures.js +68 -0
- package/lib/host/apply/media-service.js +202 -0
- package/lib/host/apply/quota-service.js +42 -0
- package/lib/host/apply/references.js +43 -0
- package/lib/host/apply/session-status.js +104 -0
- package/lib/host/apply/state.js +78 -0
- package/lib/host/apply/updates.js +55 -0
- package/lib/host/apply/video-command.js +152 -0
- package/lib/host/apply/video-edit.js +253 -0
- package/lib/host/apply/video-jobs.js +206 -0
- package/lib/host/apply-utils.js +39 -0
- package/lib/host/config.js +205 -0
- package/lib/host/controller.js +435 -0
- package/lib/host/discovery.js +295 -0
- package/lib/host/http-gate.js +144 -0
- package/lib/host/models.js +102 -0
- package/lib/host/mount-guard.js +56 -0
- package/lib/host/routes.js +165 -0
- package/lib/host/runtime.js +445 -0
- package/lib/host/state-store.js +39 -0
- package/lib/host/status-text.js +93 -0
- package/lib/index.js +17 -4330
- package/lib/media/agent-tool.js +255 -0
- package/lib/media/choice.js +83 -0
- package/lib/media/classify.js +65 -0
- package/lib/media/codec/fit.js +76 -0
- package/lib/media/codec/jpeg.js +158 -0
- package/lib/media/codec/png.js +102 -0
- package/lib/media/commands/parsing.js +269 -0
- package/lib/media/constants.js +46 -0
- package/lib/media/diagnose.js +134 -0
- package/lib/media/images.js +165 -0
- package/lib/media/index.js +29 -0
- package/lib/media/interpret.js +126 -0
- package/lib/media/job-store.js +99 -0
- package/lib/media/mp4.js +44 -0
- package/lib/media/output-files.js +59 -0
- package/lib/media/session-store.js +293 -0
- package/lib/media/settings.js +255 -0
- package/lib/media/util.js +45 -0
- package/lib/media/video.js +326 -0
- package/lib/quota/auth-state.js +33 -0
- package/lib/quota/constants.js +86 -0
- package/lib/quota/controller.js +467 -0
- package/lib/quota/helpers.js +325 -0
- package/lib/quota/index.js +19 -0
- package/lib/quota/management.js +216 -0
- package/lib/quota/matching.js +143 -0
- package/lib/quota/parsers.js +352 -0
- package/lib/quota/probes/billing.js +80 -0
- package/lib/quota/probes/google.js +120 -0
- package/lib/quota/probes/oauth.js +27 -0
- package/lib/quota/probes/plugin.js +18 -0
- package/lib/updater/constants.js +23 -0
- package/lib/updater/errors.js +8 -0
- package/lib/updater/index.js +11 -0
- package/lib/updater/registry.js +83 -0
- package/lib/updater/settings.js +45 -0
- package/lib/updater/store.js +23 -0
- package/lib/updater/updater.js +148 -0
- package/lib/updater/verify.js +110 -0
- package/lib/updater/version.js +31 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +6 -9
- package/lib/media.js +0 -2528
- package/lib/quota.js +0 -1646
- package/lib/updater.js +0 -443
package/lib/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
window.__ModuleLoader__.load({
|
|
2
2
|
id: "dsh-cliproxyapi-pro",
|
|
3
3
|
factory: (require) => {
|
|
4
|
+
// GENERATED from src/client by scripts/build-client.mjs - edit the sources, then run npm run build:client
|
|
4
5
|
var module = { exports: {} };
|
|
5
6
|
var exports = module.exports;
|
|
6
7
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -267,6 +268,9 @@ window.__ModuleLoader__.load({
|
|
|
267
268
|
qKeyStatusSet: "已配置",
|
|
268
269
|
qKeyStatusUnset: "未配置",
|
|
269
270
|
qDataLabel: "额度数据",
|
|
271
|
+
qRefreshPolicy: "默认每 30 分钟自动刷新。账号刷新失败会暂停整个账号;单个凭证额度查询失败只暂停该凭证。手动刷新账号或保存管理密钥可重试。暂停仅保存在插件内存中,插件重启后清除,刷新页面不会清除。",
|
|
272
|
+
qAccountPaused: "此账号自动刷新已暂停。请手动刷新账号或保存管理密钥以重试;暂停保存在插件内存中,插件重启后清除,刷新页面不会清除。",
|
|
273
|
+
qCredentialPaused: "此凭证自动刷新已暂停,其他凭证不受影响。请手动刷新账号以重试;暂停保存在插件内存中,插件重启后清除,刷新页面不会清除。",
|
|
270
274
|
qTotalCreds: "{n} 个凭证",
|
|
271
275
|
qKeySaved: "管理密钥已保存",
|
|
272
276
|
qKeyCleared: "管理密钥已清除",
|
|
@@ -309,8 +313,10 @@ window.__ModuleLoader__.load({
|
|
|
309
313
|
qDurDH: "{d}天{h}小时",
|
|
310
314
|
qDurHM: "{h}小时{m}分",
|
|
311
315
|
qDurM: "{m}分钟",
|
|
312
|
-
qErrUnauthorized: "管理密钥无效(401
|
|
316
|
+
qErrUnauthorized: "管理密钥无效(401),请检查后重新保存。",
|
|
313
317
|
qErrForbidden: "CPA 拒绝了管理请求(403):请确认 CPA 已开启 remote-management.allow-remote,且密钥正确。",
|
|
318
|
+
qAuthRetrying: "已连续被拒绝 {n}/{max} 次;连续 {max} 次后停止自动查询。",
|
|
319
|
+
qAuthPaused: "已连续被拒绝 {n} 次,自动查询已停止,以免 CPA 因错误密钥封禁本机地址。保存新的管理密钥后恢复;手动刷新只会再试一次。",
|
|
314
320
|
qErrNetwork: "无法连接 CPA 管理接口,请检查服务地址与网络。",
|
|
315
321
|
qErrTimeout: "CPA 管理接口响应超时,请稍后重试。",
|
|
316
322
|
qErrHttp: "CPA 管理接口返回错误(HTTP {status})。",
|
|
@@ -484,6 +490,10 @@ window.__ModuleLoader__.load({
|
|
|
484
490
|
mediaConfirmAllowed: "已允许,开始生成",
|
|
485
491
|
mediaConfirmDeclined: "已拒绝",
|
|
486
492
|
mediaConfirmFailed: "没有送达:{error}",
|
|
493
|
+
mediaMasterTitle: "启用图片和视频生成",
|
|
494
|
+
mediaMasterHint: "对所有账号生效。关闭时输入框旁不显示生成按钮,没有 /cpa-image、/cpa-video 等生成命令,也不注册 agent 生成工具;已提交的视频会继续完成,聊天记录里已生成的结果仍可查看。",
|
|
495
|
+
mediaMasterOnNote: "已开启:可以用输入框旁的按钮、斜杠命令生成图片和视频。",
|
|
496
|
+
mediaMasterOffNote: "已关闭:界面上不显示生成功能,也没有生成命令。打开后才会出现下面的模型和设置。",
|
|
487
497
|
mediaAgentTitle: "允许 agent 生成图片 / 视频",
|
|
488
498
|
mediaAgentHint: "打开后,对话里的 agent 可以调用 generate_media 工具,用上面启用的生成模型生图、生视频、编辑或延长视频,文件保存到会话工作目录下的保存位置。关闭时不注册这个工具,不占用上下文。斜杠命令和输入框旁的按钮不受影响。",
|
|
489
499
|
mediaAgentOnNote: "已开启:agent 可以调用 generate_media。确认方式和秒数上限可在输入框旁的生成按钮里按会话单独修改。",
|
|
@@ -763,6 +773,9 @@ window.__ModuleLoader__.load({
|
|
|
763
773
|
qKeyStatusSet: "Set",
|
|
764
774
|
qKeyStatusUnset: "Not set",
|
|
765
775
|
qDataLabel: "Quota data",
|
|
776
|
+
qRefreshPolicy: "Automatic refresh defaults to every 30 minutes. An account refresh failure pauses the whole account; a credential quota failure pauses only that credential. Refresh the account manually or save its management key to retry. Pauses live only in plugin memory until plugin restart; reloading the page does not clear them.",
|
|
777
|
+
qAccountPaused: "Automatic refresh is paused for this account. Refresh the account manually or save its management key to retry. The pause lives in plugin memory until plugin restart; reloading the page does not clear it.",
|
|
778
|
+
qCredentialPaused: "Automatic refresh is paused for this credential; other credentials are unaffected. Refresh the account manually to retry. The pause lives in plugin memory until plugin restart; reloading the page does not clear it.",
|
|
766
779
|
qTotalCreds: "{n} credentials",
|
|
767
780
|
qKeySaved: "Management key saved",
|
|
768
781
|
qKeyCleared: "Management key cleared",
|
|
@@ -805,8 +818,10 @@ window.__ModuleLoader__.load({
|
|
|
805
818
|
qDurDH: "{d}d {h}h",
|
|
806
819
|
qDurHM: "{h}h {m}m",
|
|
807
820
|
qDurM: "{m}m",
|
|
808
|
-
qErrUnauthorized: "The management key was rejected (401).
|
|
821
|
+
qErrUnauthorized: "The management key was rejected (401). Check it and save it again.",
|
|
809
822
|
qErrForbidden: "CPA refused the management request (403). Make sure remote-management.allow-remote is on and the key is correct.",
|
|
823
|
+
qAuthRetrying: "Rejected {n}/{max} times in a row; automatic checks stop after {max}.",
|
|
824
|
+
qAuthPaused: "Rejected {n} times in a row, so automatic checks have stopped to keep CPA from banning this address for bad keys. Saving a new management key resumes them; a manual refresh tries only once.",
|
|
810
825
|
qErrNetwork: "Could not reach the CPA management API. Check the server address and network.",
|
|
811
826
|
qErrTimeout: "The CPA management API timed out. Retry shortly.",
|
|
812
827
|
qErrHttp: "The CPA management API returned an error (HTTP {status}).",
|
|
@@ -980,6 +995,10 @@ window.__ModuleLoader__.load({
|
|
|
980
995
|
mediaConfirmAllowed: "Allowed; generating",
|
|
981
996
|
mediaConfirmDeclined: "Declined",
|
|
982
997
|
mediaConfirmFailed: "Not delivered: {error}",
|
|
998
|
+
mediaMasterTitle: "Enable image and video generation",
|
|
999
|
+
mediaMasterHint: "Applies to every account. While off, the composer shows no generation buttons, /cpa-image, /cpa-video and the other generation commands do not exist, and no agent generation tool is registered. Videos already submitted still finish, and past results in the chat stay viewable.",
|
|
1000
|
+
mediaMasterOnNote: "On: generate images and videos with the composer buttons and slash commands.",
|
|
1001
|
+
mediaMasterOffNote: "Off: no generation features appear and no generation commands exist. Turn it on to see the models and settings below.",
|
|
983
1002
|
mediaAgentTitle: "Let the agent generate images / videos",
|
|
984
1003
|
mediaAgentHint: "When on, the chat agent can call the generate_media tool to generate images and videos, or edit / extend videos, with the generation models enabled above; files go to the save location under the session's working directory. When off the tool is not registered and takes no context. Slash commands and the composer button work either way.",
|
|
985
1004
|
mediaAgentOnNote: "On: the agent can call generate_media. Confirmation and the seconds limit can be changed per session in the generation button next to the composer.",
|
|
@@ -4745,6 +4764,7 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
4745
4764
|
if (!mounted.current) return;
|
|
4746
4765
|
setData(body.media ?? null);
|
|
4747
4766
|
after?.();
|
|
4767
|
+
if ("enabled" in patch) announceMediaGeneration();
|
|
4748
4768
|
setNotice({ tone: "ok", text: t("mediaSaved") });
|
|
4749
4769
|
} catch (err) {
|
|
4750
4770
|
if (mounted.current) setNotice({ tone: "error", text: mediaErrorText(t, err) });
|
|
@@ -5005,13 +5025,47 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5005
5025
|
return h("div", { className: "dcpa-tabbody dcpa-models dcpa-media" }, h("p", { className: "dcpa-q-sub" }, t("mediaLoading")));
|
|
5006
5026
|
}
|
|
5007
5027
|
|
|
5028
|
+
// The master switch (all accounts): off hides every generation feature.
|
|
5029
|
+
const generationOn = data?.settings?.enabled === true;
|
|
5030
|
+
const masterCard = h(
|
|
5031
|
+
"div",
|
|
5032
|
+
{ className: "dcpa-media-card", "data-generation": generationOn ? "on" : "off" },
|
|
5033
|
+
h(
|
|
5034
|
+
"div",
|
|
5035
|
+
{ className: "dcpa-media-agent-head" },
|
|
5036
|
+
h("span", { className: "dcpa-frow-label" }, t("mediaMasterTitle"), h(InfoTip, { t, text: t("mediaMasterHint") })),
|
|
5037
|
+
h(
|
|
5038
|
+
"button",
|
|
5039
|
+
{
|
|
5040
|
+
type: "button",
|
|
5041
|
+
role: "switch",
|
|
5042
|
+
className: "dcpa-switch",
|
|
5043
|
+
"aria-checked": generationOn,
|
|
5044
|
+
"aria-label": t("mediaMasterTitle"),
|
|
5045
|
+
disabled: busy !== null || data === null,
|
|
5046
|
+
onClick: () => void saveGlobal({ enabled: !generationOn }),
|
|
5047
|
+
},
|
|
5048
|
+
h("span", { className: "dcpa-switch-thumb" })
|
|
5049
|
+
)
|
|
5050
|
+
),
|
|
5051
|
+
h("p", { className: "dcpa-q-sub" }, t(generationOn ? "mediaMasterOnNote" : "mediaMasterOffNote"))
|
|
5052
|
+
);
|
|
5053
|
+
const messages = [
|
|
5054
|
+
error ? h("p", { key: "err", className: "dcpa-q-msg", "data-tone": "error", role: "alert" }, fmt(t, "mediaLoadError", { error })) : null,
|
|
5055
|
+
data?.settingsError ? h("p", { key: "invalid", className: "dcpa-q-msg", "data-tone": "error", role: "alert" }, t("mediaSettingsInvalid")) : null,
|
|
5056
|
+
notice ? h("p", { key: "notice", className: "dcpa-q-msg", "data-tone": notice.tone, role: notice.tone === "error" ? "alert" : "status" }, notice.text) : null,
|
|
5057
|
+
];
|
|
5058
|
+
|
|
5059
|
+
if (!generationOn) {
|
|
5060
|
+
return h("div", { className: "dcpa-tabbody dcpa-models dcpa-media" }, masterCard, ...messages);
|
|
5061
|
+
}
|
|
5062
|
+
|
|
5008
5063
|
return h(
|
|
5009
5064
|
"div",
|
|
5010
5065
|
{ className: "dcpa-tabbody dcpa-models dcpa-media" },
|
|
5066
|
+
masterCard,
|
|
5011
5067
|
h("p", { className: "dcpa-q-sub" }, t("mediaIntro")),
|
|
5012
|
-
|
|
5013
|
-
data?.settingsError ? h("p", { className: "dcpa-q-msg", "data-tone": "error", role: "alert" }, t("mediaSettingsInvalid")) : null,
|
|
5014
|
-
notice ? h("p", { className: "dcpa-q-msg", "data-tone": notice.tone, role: notice.tone === "error" ? "alert" : "status" }, notice.text) : null,
|
|
5068
|
+
...messages,
|
|
5015
5069
|
mine && models.length === 0
|
|
5016
5070
|
? h("p", { className: "dcpa-hint" }, t(catalogRead ? "mediaNone" : "mediaNoCatalog"))
|
|
5017
5071
|
: null,
|
|
@@ -5215,7 +5269,12 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5215
5269
|
function quotaErrorText(t, account) {
|
|
5216
5270
|
const key = QUOTA_ERROR_KEYS[account?.errorCode];
|
|
5217
5271
|
if (key === undefined) return null;
|
|
5218
|
-
|
|
5272
|
+
const text = fmt(t, key, { status: account.errorStatus ?? "?" });
|
|
5273
|
+
// Consecutive management-key rejections: the count, or that background checks stopped.
|
|
5274
|
+
const n = account.authFailures;
|
|
5275
|
+
if ((account.errorCode !== "unauthorized" && account.errorCode !== "forbidden") || !Number.isInteger(n) || n <= 0) return text;
|
|
5276
|
+
const max = account.authFailureLimit ?? 3;
|
|
5277
|
+
return `${text} ${fmt(t, account.authPaused ? "qAuthPaused" : "qAuthRetrying", { n, max })}`;
|
|
5219
5278
|
}
|
|
5220
5279
|
|
|
5221
5280
|
function windowLabel(t, w) {
|
|
@@ -5370,6 +5429,7 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5370
5429
|
let timer = null;
|
|
5371
5430
|
let disposed = false;
|
|
5372
5431
|
let seq = 0;
|
|
5432
|
+
let retryDelay = 0;
|
|
5373
5433
|
const inflight = new Set();
|
|
5374
5434
|
|
|
5375
5435
|
const emit = (patch) => {
|
|
@@ -5400,7 +5460,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5400
5460
|
if (timer !== null) clearT(timer);
|
|
5401
5461
|
timer = null;
|
|
5402
5462
|
if (disposed || listeners.size === 0) return;
|
|
5403
|
-
|
|
5463
|
+
// A stale "refreshing" snapshot must not turn failed status reads into a 4 s loop.
|
|
5464
|
+
const delay = retryDelay || (state.data?.refreshing ? QUOTA_BUSY_POLL_MS : QUOTA_POLL_MS);
|
|
5404
5465
|
timer = setT(() => {
|
|
5405
5466
|
timer = null;
|
|
5406
5467
|
void load().finally(schedule);
|
|
@@ -5408,18 +5469,26 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5408
5469
|
};
|
|
5409
5470
|
|
|
5410
5471
|
const load = async () => {
|
|
5472
|
+
if (disposed) return;
|
|
5411
5473
|
const mine = ++seq;
|
|
5412
5474
|
emit({ loading: true });
|
|
5413
5475
|
try {
|
|
5414
5476
|
const body = await request(API.quotaStatus);
|
|
5415
|
-
if (mine === seq)
|
|
5477
|
+
if (!disposed && mine === seq) {
|
|
5478
|
+
retryDelay = 0;
|
|
5479
|
+
emit({ data: body.quota ?? null, error: null, loading: false, loadedAt: Date.now() });
|
|
5480
|
+
}
|
|
5416
5481
|
} catch (error) {
|
|
5417
5482
|
if (disposed) return;
|
|
5418
|
-
if (mine === seq)
|
|
5483
|
+
if (mine === seq) {
|
|
5484
|
+
retryDelay = retryDelay ? Math.min(retryDelay * 2, 300 * 1000) : QUOTA_POLL_MS;
|
|
5485
|
+
emit({ error: error instanceof Error ? error.message : String(error), loading: false });
|
|
5486
|
+
}
|
|
5419
5487
|
}
|
|
5420
5488
|
};
|
|
5421
5489
|
|
|
5422
5490
|
const mutate = async (kind, url, payload) => {
|
|
5491
|
+
if (disposed) return { ok: false };
|
|
5423
5492
|
const mine = ++seq;
|
|
5424
5493
|
emit({ busy: kind, busyAccount: payload?.accountId ?? null, error: null });
|
|
5425
5494
|
try {
|
|
@@ -5428,7 +5497,10 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5428
5497
|
headers: { "content-type": "application/json" },
|
|
5429
5498
|
body: JSON.stringify(payload ?? {}),
|
|
5430
5499
|
});
|
|
5431
|
-
if (mine === seq)
|
|
5500
|
+
if (!disposed && mine === seq) {
|
|
5501
|
+
retryDelay = 0;
|
|
5502
|
+
emit({ data: body.quota ?? state.data, error: null, loading: false, loadedAt: Date.now() });
|
|
5503
|
+
}
|
|
5432
5504
|
emit({ busy: null, busyAccount: null });
|
|
5433
5505
|
schedule();
|
|
5434
5506
|
return { ok: true };
|
|
@@ -5442,6 +5514,7 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5442
5514
|
return {
|
|
5443
5515
|
getSnapshot: () => state,
|
|
5444
5516
|
subscribe(fn) {
|
|
5517
|
+
if (disposed) return () => {};
|
|
5445
5518
|
listeners.add(fn);
|
|
5446
5519
|
if (listeners.size === 1) {
|
|
5447
5520
|
if (state.data === null || Date.now() - state.loadedAt > QUOTA_POLL_MS) void load().finally(schedule);
|
|
@@ -5527,6 +5600,16 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5527
5600
|
const composerBadges = createBadgePresence();
|
|
5528
5601
|
// The generation-model button has its own composer/hero presence.
|
|
5529
5602
|
const mediaChips = createBadgePresence();
|
|
5603
|
+
// The Generation tab tells the composer buttons when the master switch
|
|
5604
|
+
// changed, so they appear / disappear without waiting for a retry.
|
|
5605
|
+
const mediaGenerationListeners = new Set();
|
|
5606
|
+
const announceMediaGeneration = () => {
|
|
5607
|
+
for (const fn of [...mediaGenerationListeners]) {
|
|
5608
|
+
try {
|
|
5609
|
+
fn();
|
|
5610
|
+
} catch {}
|
|
5611
|
+
}
|
|
5612
|
+
};
|
|
5530
5613
|
|
|
5531
5614
|
/**
|
|
5532
5615
|
* Composer placement announces itself for its session; hero placement
|
|
@@ -5643,20 +5726,21 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5643
5726
|
}
|
|
5644
5727
|
|
|
5645
5728
|
function CredentialWindows({ t, cred, windows, now }) {
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
"div",
|
|
5649
|
-
{ className: "dcpa-q-meters" },
|
|
5650
|
-
windows.map((w, i) => h(QuotaMeter, { key: w.id ?? i, t, w, now }))
|
|
5651
|
-
);
|
|
5652
|
-
}
|
|
5729
|
+
const failed = cred.quotaState === "error";
|
|
5730
|
+
const paused = cred.autoRefreshPaused === true;
|
|
5653
5731
|
const lines = [
|
|
5654
|
-
|
|
5655
|
-
? h("p", { key: "q", className: "dcpa-q-note", "data-tone": "error" },
|
|
5656
|
-
|
|
5657
|
-
|
|
5732
|
+
failed || paused
|
|
5733
|
+
? h("p", { key: "q", className: "dcpa-q-note", "data-tone": "error" },
|
|
5734
|
+
failed ? t("qQuotaError") : null,
|
|
5735
|
+
paused ? `${failed ? " · " : ""}${t("qCredentialPaused")}` : null)
|
|
5736
|
+
: windows.length === 0
|
|
5737
|
+
? h("p", { key: "q", className: "dcpa-q-note" }, t(cred.quotaState === "unsupported" ? "qQuotaUnsupported" : "qQuotaNone"))
|
|
5738
|
+
: null,
|
|
5739
|
+
windows.length === 0 && cred.recent ? h("p", { key: "r", className: "dcpa-q-note" }, fmt(t, "qRecent", cred.recent)) : null,
|
|
5658
5740
|
];
|
|
5659
|
-
return h("div", { className: "dcpa-q-meters" },
|
|
5741
|
+
return h("div", { className: "dcpa-q-meters" },
|
|
5742
|
+
windows.map((w, i) => h(QuotaMeter, { key: w.id ?? i, t, w, now })),
|
|
5743
|
+
lines.some(Boolean) ? h("div", null, lines) : null);
|
|
5660
5744
|
}
|
|
5661
5745
|
|
|
5662
5746
|
function CredentialRow({ t, cred, now, pickerIds }) {
|
|
@@ -5941,7 +6025,7 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5941
6025
|
h(
|
|
5942
6026
|
"div",
|
|
5943
6027
|
{ className: "dcpa-q-row-main" },
|
|
5944
|
-
h("div", { className: "dcpa-q-title" }, t("qDataLabel")),
|
|
6028
|
+
h("div", { className: "dcpa-q-title" }, t("qDataLabel"), h(InfoTip, { t, text: t("qRefreshPolicy") })),
|
|
5945
6029
|
h(
|
|
5946
6030
|
"div",
|
|
5947
6031
|
{ className: "dcpa-q-sub" },
|
|
@@ -5950,7 +6034,8 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
5950
6034
|
: account.fetchedAt
|
|
5951
6035
|
? fmt(t, "qUpdated", { time: agoText(t, account.fetchedAt, now) })
|
|
5952
6036
|
: t("qNeverUpdated"),
|
|
5953
|
-
account.enabled === false ? ` · ${t("qAccountDisabled")}` : ""
|
|
6037
|
+
account.enabled === false ? ` · ${t("qAccountDisabled")}` : "",
|
|
6038
|
+
account.autoRefreshPaused === true ? ` · ${t("qAccountPaused")}` : ""
|
|
5954
6039
|
)
|
|
5955
6040
|
),
|
|
5956
6041
|
h(
|
|
@@ -6141,7 +6226,9 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
6141
6226
|
h(
|
|
6142
6227
|
"div",
|
|
6143
6228
|
{ className: "dcpa-q-pop-foot" },
|
|
6144
|
-
h("span", null,
|
|
6229
|
+
h("span", null,
|
|
6230
|
+
account.fetchedAt ? fmt(t, "qUpdated", { time: agoText(t, account.fetchedAt, now) }) : t("qPeekFooter"),
|
|
6231
|
+
account.autoRefreshPaused === true ? ` · ${t("qAccountPaused")}` : ""),
|
|
6145
6232
|
h(
|
|
6146
6233
|
"button",
|
|
6147
6234
|
{
|
|
@@ -6293,8 +6380,10 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
6293
6380
|
if (controller.signal.aborted) return;
|
|
6294
6381
|
if (!res.ok || body.ok === false) throw new Error(body.error || `HTTP ${res.status}`);
|
|
6295
6382
|
setData(body.session ?? null);
|
|
6296
|
-
|
|
6297
|
-
|
|
6383
|
+
// Generation switched off: nothing to show and nothing to wait for
|
|
6384
|
+
// (the Generation tab announces when it is switched on again).
|
|
6385
|
+
needsRetry = body.session?.generation !== false && (body.session?.catalogIncomplete === true ||
|
|
6386
|
+
!["image", "video"].some((kind) => Array.isArray(body.session?.options?.[kind]) && body.session.options[kind].length > 0));
|
|
6298
6387
|
} catch (err) {
|
|
6299
6388
|
if (!controller.signal.aborted) setError(err instanceof Error ? err.message : String(err));
|
|
6300
6389
|
} finally {
|
|
@@ -6309,6 +6398,19 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
6309
6398
|
};
|
|
6310
6399
|
}, [sessionId, shadowed, openKind, retry]);
|
|
6311
6400
|
|
|
6401
|
+
// The master switch changed on the Generation tab: load again now.
|
|
6402
|
+
useEffect(() => {
|
|
6403
|
+
const reload = () => {
|
|
6404
|
+
if (!mounted.current) return;
|
|
6405
|
+
closeMenu();
|
|
6406
|
+
setRetry((n) => n + 1);
|
|
6407
|
+
};
|
|
6408
|
+
mediaGenerationListeners.add(reload);
|
|
6409
|
+
return () => {
|
|
6410
|
+
mediaGenerationListeners.delete(reload);
|
|
6411
|
+
};
|
|
6412
|
+
}, []);
|
|
6413
|
+
|
|
6312
6414
|
useEffect(() => {
|
|
6313
6415
|
if (openKind === null) return undefined;
|
|
6314
6416
|
const place = () => {
|
|
@@ -6567,7 +6669,7 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
6567
6669
|
|
|
6568
6670
|
// #region generate_media tool rows (tool.call.toolview, key "generate_media")
|
|
6569
6671
|
|
|
6570
|
-
/** The run id the host derives from a tool call id (mirrors lib/media.js
|
|
6672
|
+
/** The run id the host derives from a tool call id (mirrors toolRunId in lib/media/agent-tool.js). */
|
|
6571
6673
|
function toolRunId(callId) {
|
|
6572
6674
|
const raw = String(callId ?? "").replace(/[^A-Za-z0-9._:-]/g, "_").replace(/^[^A-Za-z0-9]+/, "").slice(0, 119);
|
|
6573
6675
|
return /^[A-Za-z0-9][A-Za-z0-9._:-]{0,119}$/.test(raw) ? raw : null;
|
|
@@ -7398,6 +7500,7 @@ select.dcpa-q-input.dcpa-media-kind { flex: none; width: auto; height: 28px; fon
|
|
|
7398
7500
|
);
|
|
7399
7501
|
}
|
|
7400
7502
|
// #endregion
|
|
7503
|
+
|
|
7401
7504
|
const inject = ["slots", "locale"];
|
|
7402
7505
|
|
|
7403
7506
|
function apply(ctx) {
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// Persisted account normalization, migration, conflicts and account patches.
|
|
2
|
+
|
|
3
|
+
import { DEFAULT_ACCOUNT_ID, DEFAULT_PROVIDER, DEFAULT_DISPLAY_NAME, DEFAULT_API_KEY_ENV, STATE_VERSION, ACCOUNT_FIELDS, GLOBAL_FIELDS, normalizeStringList, normalizeModelOverrides, resolveConfig, normalizeAccountId } from "./config.js";
|
|
4
|
+
import { managedRouteKeys } from "./routes.js";
|
|
5
|
+
|
|
6
|
+
/** The persisted shape of one account: its settings without the globals. */
|
|
7
|
+
export function pickAccount(resolved) {
|
|
8
|
+
return {
|
|
9
|
+
id: resolved.id,
|
|
10
|
+
enabled: resolved.enabled,
|
|
11
|
+
provider: resolved.provider,
|
|
12
|
+
displayName: resolved.displayName,
|
|
13
|
+
baseURL: resolved.baseURL,
|
|
14
|
+
apiKeyEnv: resolved.apiKeyEnv,
|
|
15
|
+
protocol: resolved.protocol,
|
|
16
|
+
protocolMode: resolved.protocolMode,
|
|
17
|
+
includePrefix: resolved.includePrefix,
|
|
18
|
+
excludePrefix: resolved.excludePrefix,
|
|
19
|
+
...(resolved.selectedModels === undefined ? {} : { selectedModels: resolved.selectedModels }),
|
|
20
|
+
modelOverrides: resolved.modelOverrides,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function pickFields(source, fields) {
|
|
25
|
+
const out = {};
|
|
26
|
+
if (typeof source !== "object" || source === null) return out;
|
|
27
|
+
for (const field of fields) if (source[field] !== undefined) out[field] = source[field];
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function plainObject(value) {
|
|
32
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Normalize the state file into `{ version, refreshIntervalSeconds,
|
|
37
|
+
* probeTimeoutMs, accounts[] }`. A legacy single-account file (flat fields,
|
|
38
|
+
* no `accounts` array) becomes one account with id `default`, so its
|
|
39
|
+
* provider route, key reference and model selection carry over unchanged.
|
|
40
|
+
* Invalid or duplicate account ids are replaced with generated ones.
|
|
41
|
+
*/
|
|
42
|
+
export function normalizeState(raw = {}) {
|
|
43
|
+
const source = plainObject(raw) ?? {};
|
|
44
|
+
const globals = resolveConfig(pickFields(source, GLOBAL_FIELDS));
|
|
45
|
+
const rawAccounts = Array.isArray(source.accounts)
|
|
46
|
+
? source.accounts
|
|
47
|
+
: [{ ...pickFields(source, ACCOUNT_FIELDS), id: DEFAULT_ACCOUNT_ID }];
|
|
48
|
+
const accounts = [];
|
|
49
|
+
const ids = new Set();
|
|
50
|
+
for (const entry of rawAccounts) {
|
|
51
|
+
if (plainObject(entry) === undefined) continue;
|
|
52
|
+
let id = normalizeAccountId(entry.id);
|
|
53
|
+
if (id === undefined || ids.has(id)) {
|
|
54
|
+
let n = accounts.length + 1;
|
|
55
|
+
while (ids.has(`account-${n}`)) n += 1;
|
|
56
|
+
id = `account-${n}`;
|
|
57
|
+
}
|
|
58
|
+
ids.add(id);
|
|
59
|
+
accounts.push(pickAccount(resolveConfig({ ...pickFields(entry, ACCOUNT_FIELDS), id })));
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
version: STATE_VERSION,
|
|
63
|
+
refreshIntervalSeconds: globals.refreshIntervalSeconds,
|
|
64
|
+
probeTimeoutMs: globals.probeTimeoutMs,
|
|
65
|
+
accounts,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Overlay the host-supplied plugin config on the persisted state. A config
|
|
71
|
+
* with `accounts` replaces the account list; flat legacy fields apply to the
|
|
72
|
+
* first account, as they did when only one account existed.
|
|
73
|
+
*/
|
|
74
|
+
export function mergeHostConfig(persisted, config) {
|
|
75
|
+
const host = plainObject(config) ?? {};
|
|
76
|
+
const base = plainObject(persisted) ?? {};
|
|
77
|
+
if (!Array.isArray(base.accounts) || Array.isArray(host.accounts)) return { ...base, ...host };
|
|
78
|
+
const flat = pickFields(host, ACCOUNT_FIELDS);
|
|
79
|
+
const accounts = [...base.accounts];
|
|
80
|
+
if (Object.keys(flat).length > 0 && accounts.length > 0) accounts[0] = { ...accounts[0], ...flat };
|
|
81
|
+
return { ...base, ...pickFields(host, GLOBAL_FIELDS), accounts };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Accounts whose managed route keys overlap an earlier account's. Each one
|
|
86
|
+
* maps to the id of the account that already owns the keys.
|
|
87
|
+
*/
|
|
88
|
+
export function accountConflicts(accounts) {
|
|
89
|
+
const owners = new Map();
|
|
90
|
+
const conflicts = new Map();
|
|
91
|
+
for (const account of accounts) {
|
|
92
|
+
const keys = managedRouteKeys(account.provider);
|
|
93
|
+
const clash = keys.map((key) => owners.get(key)).find((owner) => owner !== undefined);
|
|
94
|
+
if (clash !== undefined) {
|
|
95
|
+
conflicts.set(account.id, clash);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
for (const key of keys) owners.set(key, account.id);
|
|
99
|
+
}
|
|
100
|
+
return conflicts;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function assertNoConflicts(accounts) {
|
|
104
|
+
const conflicts = accountConflicts(accounts);
|
|
105
|
+
for (const [id, ownerId] of conflicts) {
|
|
106
|
+
const account = accounts.find((a) => a.id === id);
|
|
107
|
+
const owner = accounts.find((a) => a.id === ownerId);
|
|
108
|
+
throw new Error(
|
|
109
|
+
`dsh-cliproxyapi: provider route "${account?.provider}" of account "${account?.displayName ?? id}" overlaps the routes of account "${owner?.displayName ?? ownerId}". Every account needs its own Provider Route ID.`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Defaults for a newly added account: the first free `cli-proxy-N` route,
|
|
116
|
+
* its own credential reference, and disabled until the user fills it in.
|
|
117
|
+
* When no account owns `cli-proxy`, the new account takes the classic names.
|
|
118
|
+
*/
|
|
119
|
+
export function newAccountDefaults(accounts) {
|
|
120
|
+
const usedIds = new Set(accounts.map((a) => a.id));
|
|
121
|
+
const usedKeys = new Set(accounts.flatMap((a) => managedRouteKeys(a.provider)));
|
|
122
|
+
const usedRefs = new Set(accounts.map((a) => a.apiKeyEnv));
|
|
123
|
+
const free = (provider) => managedRouteKeys(provider).every((key) => !usedKeys.has(key));
|
|
124
|
+
const base = {
|
|
125
|
+
enabled: false,
|
|
126
|
+
baseURL: "",
|
|
127
|
+
protocol: "openai-completions",
|
|
128
|
+
protocolMode: "auto",
|
|
129
|
+
includePrefix: "",
|
|
130
|
+
excludePrefix: "",
|
|
131
|
+
// No selectedModels: the first successful probe seeds recommendModels().
|
|
132
|
+
modelOverrides: {},
|
|
133
|
+
};
|
|
134
|
+
if (!usedIds.has(DEFAULT_ACCOUNT_ID) && free(DEFAULT_PROVIDER) && !usedRefs.has(DEFAULT_API_KEY_ENV)) {
|
|
135
|
+
return {
|
|
136
|
+
...base,
|
|
137
|
+
id: DEFAULT_ACCOUNT_ID,
|
|
138
|
+
provider: DEFAULT_PROVIDER,
|
|
139
|
+
displayName: DEFAULT_DISPLAY_NAME,
|
|
140
|
+
apiKeyEnv: DEFAULT_API_KEY_ENV,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
let n = Math.max(2, accounts.length + 1);
|
|
144
|
+
while (
|
|
145
|
+
usedIds.has(`account-${n}`) ||
|
|
146
|
+
!free(`${DEFAULT_PROVIDER}-${n}`) ||
|
|
147
|
+
usedRefs.has(`${DEFAULT_API_KEY_ENV}_${n}`)
|
|
148
|
+
) {
|
|
149
|
+
n += 1;
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
...base,
|
|
153
|
+
id: `account-${n}`,
|
|
154
|
+
provider: `${DEFAULT_PROVIDER}-${n}`,
|
|
155
|
+
displayName: `${DEFAULT_DISPLAY_NAME} ${n}`,
|
|
156
|
+
apiKeyEnv: `${DEFAULT_API_KEY_ENV}_${n}`,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Apply an account patch from the UI. `selectedModels` and
|
|
162
|
+
* `modelOverrides` replace the stored value when present; the id never changes.
|
|
163
|
+
*/
|
|
164
|
+
export function patchAccount(account, patch) {
|
|
165
|
+
const fields = pickFields(patch, ACCOUNT_FIELDS);
|
|
166
|
+
const next = { ...account, ...fields, id: account.id };
|
|
167
|
+
if (patch !== null && typeof patch === "object" && "selectedModels" in patch) {
|
|
168
|
+
next.selectedModels = Array.isArray(patch.selectedModels)
|
|
169
|
+
? normalizeStringList(patch.selectedModels) ?? []
|
|
170
|
+
: [];
|
|
171
|
+
}
|
|
172
|
+
if (patch !== null && typeof patch === "object" && "modelOverrides" in patch) {
|
|
173
|
+
next.modelOverrides = normalizeModelOverrides(patch.modelOverrides);
|
|
174
|
+
}
|
|
175
|
+
return pickAccount(resolveConfig(next));
|
|
176
|
+
}
|