dsh-opendesign-corouter 0.1.8 → 0.1.10
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 +3 -3
- package/lib/catalog.d.ts +7 -2
- package/lib/client.d.ts +22 -4
- package/lib/client.js +254 -47
- package/lib/device-auth.d.ts +1 -1
- package/lib/generated/typert.host.js +36 -0
- package/lib/generated/typert.remote-client.d.ts +2 -1
- package/lib/generated/typert.remote-client.js +36 -0
- package/lib/index.d.ts +7 -1
- package/lib/index.js +377 -6
- package/lib/index.js.map +4 -4
- package/lib/pricing.d.ts +149 -0
- package/lib/remote.d.ts +21 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -39,9 +39,12 @@ __export(client_exports, {
|
|
|
39
39
|
QuotaView: () => QuotaView,
|
|
40
40
|
SettingsPage: () => SettingsPage,
|
|
41
41
|
apply: () => apply,
|
|
42
|
+
formatRefreshCountdown: () => formatRefreshCountdown,
|
|
43
|
+
formatRelativeDeadline: () => formatRelativeDeadline,
|
|
42
44
|
formatTime: () => formatTime,
|
|
43
45
|
formatTokens: () => formatTokens,
|
|
44
46
|
formatUsd: () => formatUsd,
|
|
47
|
+
formatWindowCredits: () => formatWindowCredits,
|
|
45
48
|
inject: () => inject,
|
|
46
49
|
modelEnabled: () => modelEnabled,
|
|
47
50
|
modelSettingsEntry: () => modelSettingsEntry,
|
|
@@ -51,6 +54,7 @@ __export(client_exports, {
|
|
|
51
54
|
parseNumberInput: () => parseNumberInput,
|
|
52
55
|
protocolEndpoint: () => protocolEndpoint,
|
|
53
56
|
quotaAutoRefresh: () => quotaAutoRefresh,
|
|
57
|
+
quotaStatusView: () => quotaStatusView,
|
|
54
58
|
tabAfter: () => tabAfter,
|
|
55
59
|
writeModelSettings: () => writeModelSettings
|
|
56
60
|
});
|
|
@@ -20068,6 +20072,40 @@ function member(value, allowed, label) {
|
|
|
20068
20072
|
if (hit === void 0) throw new Error(`${label} \u4E0D\u5728\u5141\u8BB8\u7684\u53D6\u503C\u5185`);
|
|
20069
20073
|
return hit;
|
|
20070
20074
|
}
|
|
20075
|
+
function parsePriceCatalog(value) {
|
|
20076
|
+
if (!record2(value) || !Array.isArray(value.models) || value.models.length > MAX_MODELS) throw new Error("\u4EF7\u683C\u76EE\u5F55\u683C\u5F0F\u65E0\u6548");
|
|
20077
|
+
const state = member(value.state, ["ok", "partial", "error"], "\u4EF7\u683C\u76EE\u5F55\u72B6\u6001");
|
|
20078
|
+
const stale = flag(value.stale, "\u4EF7\u683C\u7F13\u5B58\u72B6\u6001");
|
|
20079
|
+
const fetchedAt = value.fetchedAt === void 0 ? void 0 : isoTime(value.fetchedAt, "\u4EF7\u683C\u66F4\u65B0\u65F6\u95F4");
|
|
20080
|
+
if (stale && fetchedAt === void 0) throw new Error("\u8FC7\u671F\u4EF7\u683C\u5FC5\u987B\u6807\u6CE8\u66F4\u65B0\u65F6\u95F4");
|
|
20081
|
+
const ids = /* @__PURE__ */ new Set();
|
|
20082
|
+
const nullableAmount = (item) => {
|
|
20083
|
+
if (item === null) return null;
|
|
20084
|
+
const result = amount(item, "\u4EF7\u683C");
|
|
20085
|
+
if (result > 1e6) throw new Error("\u4EF7\u683C\u8D85\u51FA\u8303\u56F4");
|
|
20086
|
+
return result;
|
|
20087
|
+
};
|
|
20088
|
+
const models = value.models.map((model) => {
|
|
20089
|
+
if (!record2(model) || !Array.isArray(model.tiers) || model.tiers.length === 0 || model.tiers.length > 8) throw new Error("\u6A21\u578B\u4EF7\u683C\u683C\u5F0F\u65E0\u6548");
|
|
20090
|
+
const id = text(model.id, "\u6A21\u578B id", 128);
|
|
20091
|
+
if (!MODEL_ID.test(id) || ids.has(id)) throw new Error("\u6A21\u578B\u4EF7\u683C id \u65E0\u6548\u6216\u91CD\u590D");
|
|
20092
|
+
ids.add(id);
|
|
20093
|
+
const tiers = model.tiers.map((tier) => {
|
|
20094
|
+
if (!record2(tier)) throw new Error("\u4EF7\u683C\u6863\u4F4D\u683C\u5F0F\u65E0\u6548");
|
|
20095
|
+
return {
|
|
20096
|
+
label: text(tier.label, "\u4EF7\u683C\u6863\u4F4D", 128),
|
|
20097
|
+
currency: tier.currency === null ? null : member(tier.currency, ["USD"], "\u4EF7\u683C\u5E01\u79CD"),
|
|
20098
|
+
unit: tier.unit === null ? null : member(tier.unit, ["per_1m_tokens", "per_1k_tokens"], "\u4EF7\u683C\u5355\u4F4D"),
|
|
20099
|
+
input: nullableAmount(tier.input),
|
|
20100
|
+
output: nullableAmount(tier.output),
|
|
20101
|
+
cacheRead: nullableAmount(tier.cacheRead),
|
|
20102
|
+
cacheWrite: nullableAmount(tier.cacheWrite)
|
|
20103
|
+
};
|
|
20104
|
+
});
|
|
20105
|
+
return { id, tiers };
|
|
20106
|
+
});
|
|
20107
|
+
return { state, stale, ...fetchedAt === void 0 ? {} : { fetchedAt }, models };
|
|
20108
|
+
}
|
|
20071
20109
|
function parseQuotaWindow(value) {
|
|
20072
20110
|
if (!record2(value)) throw new Error("\u989D\u5EA6\u7A97\u53E3\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
20073
20111
|
const durationSeconds = amount(value.durationSeconds, "\u989D\u5EA6\u7A97\u53E3\u65F6\u957F");
|
|
@@ -20215,6 +20253,7 @@ function parseActivationOpenState(value) {
|
|
|
20215
20253
|
|
|
20216
20254
|
// src/generated/typert.remote-client.ts
|
|
20217
20255
|
var StatusCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#Status", create: () => external_exports.unknown().transform((value) => parseStatus(value)) };
|
|
20256
|
+
var PriceCatalogCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#PriceCatalog", create: () => external_exports.unknown().transform((value) => parsePriceCatalog(value)) };
|
|
20218
20257
|
var QuotaSnapshotCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#QuotaSnapshot", create: () => external_exports.unknown().transform((value) => parseQuotaSnapshot(value)) };
|
|
20219
20258
|
var LoginStateCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#LoginState", create: () => external_exports.unknown().transform((value) => parseLoginState(value)) };
|
|
20220
20259
|
var StartLoginRequestCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#StartLoginRequest", create: () => external_exports.unknown().transform((value) => parseStartLoginRequest(value)) };
|
|
@@ -20224,6 +20263,7 @@ var SaveApiKeyRequestCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corou
|
|
|
20224
20263
|
var TYPERT_REMOTE = createTypertRemoteInfo({ package: "dsh-opendesign-corouter", methods: {
|
|
20225
20264
|
"openDesignCoRouter/status": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: StatusCodec },
|
|
20226
20265
|
"openDesignCoRouter/refreshModels": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: StatusCodec },
|
|
20266
|
+
"openDesignCoRouter/refreshPrices": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: PriceCatalogCodec },
|
|
20227
20267
|
"openDesignCoRouter/refreshQuota": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: QuotaSnapshotCodec },
|
|
20228
20268
|
"openDesignCoRouter/refreshQuotaNow": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: QuotaSnapshotCodec },
|
|
20229
20269
|
"openDesignCoRouter/startLogin": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [{ name: "input", source: "json", codec: StartLoginRequestCodec, strictCodec: StartLoginRequestCodec }], result: LoginStateCodec },
|
|
@@ -20290,6 +20330,7 @@ function installStyles() {
|
|
|
20290
20330
|
style.dataset.opendesignCorouter = "";
|
|
20291
20331
|
style.textContent = `
|
|
20292
20332
|
.odc-settings{color:var(--dsw-alias-label-primary,inherit);max-width:860px;padding:6px 2px 24px;font-size:13px;line-height:1.5}
|
|
20333
|
+
.odc-settings{color-scheme:light;container-type:inline-size}body[data-ds-dark-theme] .odc-settings{color-scheme:dark}
|
|
20293
20334
|
.odc-settings *{box-sizing:border-box}.odc-settings h2{margin:0;font-size:21px;line-height:1.35;font-weight:650;letter-spacing:-.02em}.odc-settings h3{margin:0;font-size:14px;font-weight:650}.odc-settings p{margin:0}
|
|
20294
20335
|
.odc-intro{margin:6px 0 18px!important;color:var(--dsw-alias-label-secondary,inherit);font-size:12px}.odc-tabs{display:flex;gap:4px;overflow-x:auto;margin:0 0 16px;padding:0 0 8px;border-bottom:1px solid var(--dsw-alias-border-l4,transparent)}
|
|
20295
20336
|
.odc-tab{flex:none;border:1px solid transparent;border-radius:8px;padding:7px 13px;background:transparent;color:var(--dsw-alias-label-secondary,inherit);font:inherit;cursor:pointer}.odc-tab:hover{background:var(--dsw-alias-bg-layer-1,transparent)}.odc-tab[aria-selected=true]{color:var(--dsw-alias-label-primary,inherit);border-color:var(--dsw-alias-border-l3,transparent);background:var(--dsw-alias-bg-layer-1,transparent)}
|
|
@@ -20303,11 +20344,27 @@ function installStyles() {
|
|
|
20303
20344
|
.odc-model-groups{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;margin-top:12px}.odc-model-list{display:grid;gap:6px;margin:10px 0 0;padding:0;list-style:none}.odc-model-item{padding:9px 10px;border-radius:8px;background:var(--dsw-alias-bg-layer-2,transparent);min-width:0}.odc-model-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;flex-wrap:wrap}.odc-model-switch{min-width:0;flex:1 1 190px}.odc-model-item strong,.odc-model-item code{display:block;overflow-wrap:anywhere}.odc-model-item strong{font-size:12px;font-weight:600}.odc-model-item code{margin-top:2px;color:var(--dsw-alias-label-secondary,inherit);font-size:11px}.odc-model-meta{margin-top:6px!important;color:var(--dsw-alias-label-secondary,inherit);font-size:11px;overflow-wrap:anywhere}.odc-model-count{color:var(--dsw-alias-label-secondary,inherit);font-size:11px;font-weight:400}.odc-chip{display:inline-flex;align-items:center;padding:1px 7px;border:1px solid var(--dsw-alias-border-l3,transparent);border-radius:999px;color:var(--dsw-alias-label-secondary,inherit);font-size:10px;line-height:1.6}
|
|
20304
20345
|
.odc-model-details{margin-top:8px}.odc-model-details>summary{cursor:pointer;color:var(--dsw-alias-label-secondary,inherit);font-size:11px;line-height:1.7}.odc-model-editor{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:2px 10px;margin-top:8px}
|
|
20305
20346
|
.odc-field{display:grid;gap:6px;margin-top:14px}.odc-field-compact{margin-top:8px}.odc-field label,.odc-switch-text{font-size:12px;font-weight:550}.odc-input{width:100%;min-width:0;min-height:34px;padding:7px 9px;border:1px solid var(--dsw-alias-border-l3,transparent);border-radius:8px;background:var(--dsw-alias-bg-layer-2,transparent);color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:12px}.odc-field-compact .odc-input{min-height:30px;padding:5px 8px;font-size:11px}.odc-input::placeholder{color:var(--dsw-alias-label-secondary,inherit);opacity:1}.odc-input:disabled{opacity:.55}
|
|
20347
|
+
.odc-input option{background:var(--dsw-alias-bg-layer-2,Canvas);color:var(--dsw-alias-label-primary,CanvasText)}
|
|
20348
|
+
.odc-input,.odc-button:not(.odc-button-primary),.odc-tab[aria-selected=true]{border-color:var(--dsw-alias-border-l3,CanvasText);border-color:color-mix(in srgb,var(--dsw-alias-label-primary,CanvasText) 55%,var(--dsw-alias-bg-layer-2,Canvas))}
|
|
20306
20349
|
.odc-switch{display:flex;align-items:center;gap:12px;min-height:44px;padding:6px 2px;cursor:pointer}.odc-switch input{appearance:auto;width:20px;height:20px;flex:none;margin:0;cursor:inherit;accent-color:var(--dsw-alias-brand-primary,Highlight)}.odc-switch>span{display:grid;gap:4px;min-width:0}.odc-switch:has(input:disabled){cursor:not-allowed;opacity:.6}.odc-divider{height:1px;border:0;background:var(--dsw-alias-border-l4,transparent);margin:2px 0}.odc-link{color:var(--dsw-alias-brand-primary,inherit);text-underline-offset:3px}
|
|
20307
20350
|
.odc-readonly{display:grid;gap:10px;margin-top:14px;padding:10px 12px;border-radius:8px;background:var(--dsw-alias-bg-layer-2,transparent)}.odc-code{display:block;min-width:0;color:var(--dsw-alias-label-primary,inherit);font-family:ui-monospace,'Cascadia Mono',Consolas,monospace;font-size:11px;line-height:1.6;overflow-wrap:anywhere}
|
|
20308
20351
|
.odc-timing{padding:12px 0;border-top:1px solid var(--dsw-alias-border-l4,transparent)}.odc-timing .odc-metric{min-height:0}.odc-settings>.odc-notice{margin-bottom:14px}.odc-model-details>summary{min-height:32px;padding:6px 0}
|
|
20309
20352
|
.odc-field-error{color:var(--dsw-alias-state-error-primary,inherit);color:color-mix(in srgb,var(--dsw-alias-state-error-primary,CanvasText) 85%,var(--dsw-alias-label-primary,CanvasText))}
|
|
20353
|
+
.odc-model-groups{align-items:start}.odc-label,.odc-hint,.odc-meta,.odc-window dt,.odc-quota-footer dt,.odc-quota-footer dd,.odc-window-details>summary,.odc-model-details>summary,.odc-model-item code,.odc-model-meta,.odc-model-count,.odc-code{font-size:12px}.odc-field-compact .odc-input,.odc-button-small{font-size:12px}.odc-button-small{min-height:32px}.odc-chip{font-size:11px}
|
|
20354
|
+
.odc-settings{--odc-accent:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);max-width:720px;padding:16px;line-height:1.6}
|
|
20355
|
+
.odc-settings h2{font-size:16px;letter-spacing:0}.odc-intro{margin:4px 0 12px!important}.odc-tabs{flex-wrap:wrap;overflow:visible;gap:4px;padding:0;border:0;margin-bottom:14px}
|
|
20356
|
+
.odc-tab{border:1px solid transparent;border-radius:999px;padding:6px 12px;font-size:12px}.odc-tab[aria-selected=true]{border-color:transparent;background:color-mix(in srgb,var(--odc-accent) 16%,transparent);font-weight:600}
|
|
20357
|
+
.odc-card{border-radius:10px;background:transparent;padding:14px}.odc-panel{gap:12px}.odc-card-head{margin-bottom:10px}.odc-button-primary{background:color-mix(in srgb,var(--odc-accent) 12%,transparent);border-color:color-mix(in srgb,var(--odc-accent) 65%,transparent);color:var(--dsw-alias-label-primary,CanvasText)}.odc-button-primary:hover:not(:disabled){background:color-mix(in srgb,var(--odc-accent) 18%,transparent)}
|
|
20358
|
+
.odc-quota-panel{display:grid;gap:8px;min-width:0}.odc-quota-panel>.odc-card-head{margin:0}.odc-quota-status{--odc-state:var(--odc-accent);display:flex;align-items:center;gap:10px;padding:10px 12px;border:1px solid color-mix(in srgb,var(--odc-state) 28%,transparent);border-radius:10px;background:color-mix(in srgb,var(--odc-state) 10%,transparent);font-size:13px;font-weight:600}.odc-quota-status[data-tone=good]{--odc-state:var(--dsw-alias-state-success-primary,Highlight)}.odc-quota-status[data-tone=warn]{--odc-state:var(--dsw-alias-state-warn-primary,Highlight)}.odc-quota-status[data-tone=critical]{--odc-state:var(--dsw-alias-state-error-primary,Highlight)}.odc-state-mark{display:grid;place-items:center;width:28px;height:28px;border:1px solid color-mix(in srgb,var(--odc-state) 65%,transparent);border-radius:8px;flex:none;font-size:15px;font-weight:700}.odc-state-copy{display:grid;gap:1px;min-width:0}.odc-state-copy .odc-hint{font-weight:400}
|
|
20359
|
+
.odc-window{--odc-window-color:var(--dsw-alias-label-secondary,CanvasText);gap:5px;margin:0;padding:10px 12px;border:0;border-radius:8px;background:color-mix(in srgb,var(--dsw-alias-label-primary,CanvasText) 5%,transparent)}.odc-window[data-tone=good]{--odc-window-color:color-mix(in srgb,var(--dsw-alias-state-success-primary,Highlight) 70%,var(--dsw-alias-label-primary,CanvasText))}.odc-window[data-tone=warn]{--odc-window-color:color-mix(in srgb,var(--dsw-alias-state-warn-primary,Highlight) 70%,var(--dsw-alias-label-primary,CanvasText))}.odc-window[data-tone=critical]{--odc-window-color:var(--dsw-alias-state-error-primary,Highlight)}.odc-window-remaining strong{font-size:18px}.odc-window progress{appearance:none;height:7px;border:0;border-radius:999px;overflow:hidden;background:color-mix(in srgb,var(--dsw-alias-label-primary,CanvasText) 18%,transparent);accent-color:var(--odc-window-color)}.odc-window progress::-webkit-progress-bar{background:color-mix(in srgb,var(--dsw-alias-label-primary,CanvasText) 18%,transparent);border-radius:999px}.odc-window progress::-webkit-progress-value{background:var(--odc-window-color);border-radius:999px}
|
|
20360
|
+
.odc-window-usage{display:block;margin:0;color:var(--dsw-alias-label-secondary,inherit);font-size:12px;overflow-wrap:anywhere}.odc-window-bottom{display:flex;align-items:baseline;justify-content:space-between;gap:4px 12px;flex-wrap:wrap}.odc-window-reset{display:flex;align-items:baseline;justify-content:flex-start;flex-wrap:wrap;gap:4px 6px;padding:0;border:0}.odc-window-details>summary{min-height:28px;padding:4px 0}.odc-window-details[open]{flex-basis:100%}.odc-window-details dl>div{display:flex;justify-content:space-between;gap:12px}
|
|
20361
|
+
@media(forced-colors:active){.odc-window progress{appearance:auto;accent-color:Highlight;forced-color-adjust:auto}.odc-window progress::-webkit-progress-value{background:Highlight}}
|
|
20362
|
+
.odc-balance-list,.odc-timing{display:grid;gap:0;margin:0}.odc-balance-row,.odc-timing-row{display:flex;justify-content:space-between;align-items:baseline;gap:12px;min-width:0;min-height:0;padding:6px 0;border-top:1px solid var(--dsw-alias-border-l4,transparent)}.odc-balance-row:first-child,.odc-timing-row:first-child{border-top:0}.odc-balance-row>div,.odc-timing-row>div{min-width:0}.odc-balance-row dt,.odc-timing-row dt{font-size:12px;font-weight:600}.odc-balance-row dd,.odc-timing-row dd{margin:0;min-width:0;text-align:right}.odc-balance-row .odc-metric-value{font-size:13px}.odc-timing-row .odc-metric-text{font-size:13px;white-space:nowrap}.odc-timing-row .odc-hint{display:block}.odc-timing{padding:4px 14px}
|
|
20363
|
+
.odc-model-item{background:transparent;border:1px solid var(--dsw-alias-border-l4,transparent)}.odc-model-item:has(details[open]){border-color:color-mix(in srgb,var(--odc-accent) 55%,transparent);background:color-mix(in srgb,var(--odc-accent) 5%,transparent)}
|
|
20364
|
+
.odc-price-summary{margin:5px 0 0!important;font-size:12px;color:var(--dsw-alias-label-secondary,inherit);overflow-wrap:anywhere}.odc-pricing-head{display:flex;justify-content:space-between;align-items:center;gap:10px;flex-wrap:wrap}.odc-price-tier{padding:8px 0;border-top:1px solid var(--dsw-alias-border-l4,transparent)}.odc-price-tier dl{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px 12px;margin:6px 0 0}.odc-price-tier dl>div{display:flex;justify-content:space-between;gap:8px}.odc-price-tier dt{color:var(--dsw-alias-label-secondary,inherit)}.odc-price-tier dd{margin:0;font-variant-numeric:tabular-nums}
|
|
20310
20365
|
.odc-settings :focus-visible{outline:2px solid var(--dsw-alias-brand-primary,Highlight);outline-offset:3px}@media(max-width:680px){.odc-quota-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.odc-model-groups{grid-template-columns:1fr}.odc-model-editor{grid-template-columns:1fr}}@media(max-width:380px){.odc-quota-grid{grid-template-columns:1fr}.odc-card{padding:12px}}
|
|
20366
|
+
@container(max-width:680px){.odc-quota-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.odc-model-groups,.odc-model-editor{grid-template-columns:1fr}}@container(max-width:380px){.odc-quota-grid{grid-template-columns:1fr}.odc-card{padding:12px}}
|
|
20367
|
+
@container(max-width:480px){.odc-timing-row{align-items:flex-start}.odc-timing-row>div{flex:1 1 0}.odc-timing-row dd{flex:0 0 auto;max-width:50%;overflow-wrap:anywhere}.odc-timing-row .odc-metric-text{white-space:normal}}
|
|
20311
20368
|
`;
|
|
20312
20369
|
document.head.append(style);
|
|
20313
20370
|
return () => style.remove();
|
|
@@ -20405,6 +20462,37 @@ function formatTime(value) {
|
|
|
20405
20462
|
const date5 = new Date(value);
|
|
20406
20463
|
return Number.isFinite(date5.getTime()) ? date5.toLocaleString("zh-CN", { hour12: false }) : "\u2014";
|
|
20407
20464
|
}
|
|
20465
|
+
function formatRelativeDeadline(value, now, dueText) {
|
|
20466
|
+
const at = value === void 0 ? Number.NaN : Date.parse(value);
|
|
20467
|
+
if (!Number.isFinite(at) || !Number.isFinite(now)) return "\u2014";
|
|
20468
|
+
const seconds = Math.ceil((at - now) / 1e3);
|
|
20469
|
+
if (seconds <= 0) return dueText;
|
|
20470
|
+
if (seconds >= 86400) return `${Math.floor(seconds / 86400)}\u5929${Math.floor(seconds % 86400 / 3600)}\u5C0F\u65F6\u540E`;
|
|
20471
|
+
if (seconds >= 3600) return `${Math.floor(seconds / 3600)}\u5C0F\u65F6${Math.floor(seconds % 3600 / 60)}\u5206\u949F\u540E`;
|
|
20472
|
+
if (seconds >= 60) return `${Math.floor(seconds / 60)}\u5206${seconds % 60}\u79D2\u540E`;
|
|
20473
|
+
return `${seconds}\u79D2\u540E`;
|
|
20474
|
+
}
|
|
20475
|
+
function formatRefreshCountdown(value, now) {
|
|
20476
|
+
return formatRelativeDeadline(value, now, "\u5373\u5C06\u5237\u65B0");
|
|
20477
|
+
}
|
|
20478
|
+
function RelativeDeadline({ at, busy = false, dueText, titleLabel, futureSuffix = "" }) {
|
|
20479
|
+
const [now, setNow] = React.useState(() => Date.now());
|
|
20480
|
+
React.useEffect(() => {
|
|
20481
|
+
if (at === void 0 || !Number.isFinite(Date.parse(at))) return;
|
|
20482
|
+
const update = () => setNow(Date.now());
|
|
20483
|
+
update();
|
|
20484
|
+
const timer = setInterval(update, 1e3);
|
|
20485
|
+
document.addEventListener("visibilitychange", update);
|
|
20486
|
+
return () => {
|
|
20487
|
+
clearInterval(timer);
|
|
20488
|
+
document.removeEventListener("visibilitychange", update);
|
|
20489
|
+
};
|
|
20490
|
+
}, [at]);
|
|
20491
|
+
if (busy) return h("span", null, "\u5237\u65B0\u4E2D\u2026");
|
|
20492
|
+
if (at === void 0 || !Number.isFinite(Date.parse(at))) return h("span", null, "\u2014");
|
|
20493
|
+
const relative = formatRelativeDeadline(at, now, dueText) + (Date.parse(at) > now ? futureSuffix : "");
|
|
20494
|
+
return h("time", { dateTime: at, title: `${titleLabel}\uFF1A${formatTime(at)}`, "aria-label": `${relative}\uFF0C${titleLabel}\uFF1A${formatTime(at)}` }, relative);
|
|
20495
|
+
}
|
|
20408
20496
|
function formatTokens(value) {
|
|
20409
20497
|
if (value === void 0 || !Number.isFinite(value)) return "\u2014";
|
|
20410
20498
|
return new Intl.NumberFormat("zh-CN").format(value);
|
|
@@ -20415,6 +20503,34 @@ function windowLabel(seconds) {
|
|
|
20415
20503
|
if (seconds % 60 === 0) return `${seconds / 60} \u5206\u949F\u8D60\u9001\u7A97\u53E3`;
|
|
20416
20504
|
return `${seconds} \u79D2\u8D60\u9001\u7A97\u53E3`;
|
|
20417
20505
|
}
|
|
20506
|
+
function formatWindowCredits(value) {
|
|
20507
|
+
if (value >= 1e9) return `${(value / 1e9).toFixed(2)}B`;
|
|
20508
|
+
if (value >= 1e6) return `${(value / 1e6).toFixed(2)}M`;
|
|
20509
|
+
if (value >= 1e3) return `${(value / 1e3).toFixed(1)}K`;
|
|
20510
|
+
return String(value);
|
|
20511
|
+
}
|
|
20512
|
+
function windowTone(window) {
|
|
20513
|
+
return window.percent >= 100 ? "critical" : window.percent >= 71 ? "warn" : "good";
|
|
20514
|
+
}
|
|
20515
|
+
function windowDue(window, now) {
|
|
20516
|
+
if (window.resetsAt === void 0) return false;
|
|
20517
|
+
const at = Date.parse(window.resetsAt);
|
|
20518
|
+
return Number.isFinite(at) && at <= now;
|
|
20519
|
+
}
|
|
20520
|
+
function quotaStatusView(quota, now) {
|
|
20521
|
+
if (quota.state === "error") return { title: QUOTA_LABELS.error, tone: "critical", icon: "!" };
|
|
20522
|
+
if (quota.state === "need-login") return { title: QUOTA_LABELS["need-login"], tone: "neutral", icon: "i" };
|
|
20523
|
+
if (quota.stale) return { title: "\u663E\u793A\u4E0A\u6B21\u6210\u529F\u8BFB\u6570", tone: "warn", icon: "?" };
|
|
20524
|
+
if (quota.state === "partial") return { title: QUOTA_LABELS.partial, tone: "warn", icon: "?" };
|
|
20525
|
+
if (quota.eligible === false) return { title: "\u672A\u5F00\u901A Design Plan", tone: "neutral", icon: "i" };
|
|
20526
|
+
const windows = quota.windows.filter((window2) => Number.isFinite(window2.percent));
|
|
20527
|
+
if (!windows.length) return { title: "\u6682\u65E0\u8D60\u9001\u7A97\u53E3\u6570\u636E", tone: "neutral", icon: "i" };
|
|
20528
|
+
if (windows.some((window2) => windowDue(window2, now))) return { title: "\u7B49\u5F85\u66F4\u65B0\u7A97\u53E3\u989D\u5EA6", tone: "neutral", icon: "\u2026" };
|
|
20529
|
+
const window = windows.reduce((worst, next) => next.percent > worst.percent ? next : worst);
|
|
20530
|
+
const tone = windowTone(window);
|
|
20531
|
+
const title = tone === "critical" ? "\u8D60\u9001\u7A97\u53E3\u989D\u5EA6\u5DF2\u7528\u5C3D" : window.percent >= 91 ? "\u8D60\u9001\u7A97\u53E3\u989D\u5EA6\u5373\u5C06\u7528\u5C3D" : tone === "warn" ? "\u8D60\u9001\u7A97\u53E3\u989D\u5EA6\u504F\u5C11" : "\u8D60\u9001\u7A97\u53E3\u989D\u5EA6\u5145\u8DB3";
|
|
20532
|
+
return { title, tone, icon: tone === "good" ? "\u2713" : tone === "warn" ? "!" : "\xD7", window };
|
|
20533
|
+
}
|
|
20418
20534
|
function nextWindowResetAt(windows, now) {
|
|
20419
20535
|
let earliest;
|
|
20420
20536
|
let earliestMs = Number.POSITIVE_INFINITY;
|
|
@@ -20436,7 +20552,21 @@ var RESET_MODE_LABELS = {
|
|
|
20436
20552
|
activity_triggered: "\u6309\u4F7F\u7528\u89E6\u53D1",
|
|
20437
20553
|
anchored_recurring: "\u56FA\u5B9A\u5468\u671F"
|
|
20438
20554
|
};
|
|
20439
|
-
function QuotaView({ quota, nextAutoRefreshAt, refreshIntervalSeconds }) {
|
|
20555
|
+
function QuotaView({ quota, nextAutoRefreshAt, refreshIntervalSeconds, busy = false }) {
|
|
20556
|
+
const [now, setNow] = React.useState(() => Date.now());
|
|
20557
|
+
React.useEffect(() => {
|
|
20558
|
+
setNow(Date.now());
|
|
20559
|
+
}, [quota?.windows]);
|
|
20560
|
+
React.useEffect(() => {
|
|
20561
|
+
const future = (quota?.windows ?? []).map((window) => Date.parse(window.resetsAt ?? "")).filter((at) => Number.isFinite(at) && at > now);
|
|
20562
|
+
const update = () => setNow(Date.now());
|
|
20563
|
+
const timer = future.length ? setTimeout(update, Math.min(2147483647, Math.max(1, Math.min(...future) - now + 10))) : void 0;
|
|
20564
|
+
document.addEventListener("visibilitychange", update);
|
|
20565
|
+
return () => {
|
|
20566
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
20567
|
+
document.removeEventListener("visibilitychange", update);
|
|
20568
|
+
};
|
|
20569
|
+
}, [quota?.windows, now]);
|
|
20440
20570
|
if (quota === void 0) return h("p", { className: "odc-hint", role: "status" }, "\u6B63\u5728\u8BFB\u53D6\u989D\u5EA6\u2026");
|
|
20441
20571
|
const metrics = [
|
|
20442
20572
|
{ label: "\u5957\u9910\u4F59\u989D", value: formatUsd(quota.balances.subscriptionUsd), hint: "\u8BA2\u9605\u5269\u4F59\u53EF\u7528\u91D1\u989D" },
|
|
@@ -20446,17 +20576,17 @@ function QuotaView({ quota, nextAutoRefreshAt, refreshIntervalSeconds }) {
|
|
|
20446
20576
|
const timing = [
|
|
20447
20577
|
{
|
|
20448
20578
|
label: "\u8BA2\u9605\u8D26\u671F\u7ED3\u675F",
|
|
20449
|
-
value:
|
|
20579
|
+
value: h(RelativeDeadline, { at: quota.subscriptionPeriodEnd, dueText: "\u5DF2\u5230\u7ED3\u675F\u65F6\u95F4", titleLabel: "\u8D26\u671F\u7ED3\u675F\u65F6\u95F4" }),
|
|
20450
20580
|
hint: `\u8D26\u671F\u5F00\u59CB\uFF1A${formatTime(quota.subscriptionPeriodStart)}`
|
|
20451
20581
|
},
|
|
20452
20582
|
{
|
|
20453
20583
|
label: "\u4E0B\u6B21\u989D\u5EA6\u6062\u590D",
|
|
20454
|
-
value:
|
|
20584
|
+
value: h(RelativeDeadline, { at: nextWindowResetAt(quota.windows, Date.now()), dueText: "\u7B49\u5F85\u66F4\u65B0", titleLabel: "\u989D\u5EA6\u6062\u590D\u65F6\u95F4" }),
|
|
20455
20585
|
hint: "\u6700\u65E9\u6062\u590D\u7684\u8D60\u9001\u7A97\u53E3\uFF1B\u4E0D\u4EE3\u8868\u94B1\u5305\u5230\u8D26\u65F6\u95F4"
|
|
20456
20586
|
},
|
|
20457
20587
|
{
|
|
20458
20588
|
label: "\u4E0B\u6B21\u81EA\u52A8\u5237\u65B0",
|
|
20459
|
-
value:
|
|
20589
|
+
value: h(RelativeDeadline, { at: quota.state === "need-login" || quota.autoRefreshPaused ? void 0 : nextAutoRefreshAt, busy: busy && quota.state !== "need-login" && !quota.autoRefreshPaused, dueText: "\u5373\u5C06\u5237\u65B0", titleLabel: "\u8BA1\u5212\u5237\u65B0\u65F6\u95F4" }),
|
|
20460
20590
|
hint: quota.state === "need-login" ? "\u767B\u5F55\u540E\u81EA\u52A8\u5237\u65B0" : quota.autoRefreshPaused ? "\u8FDE\u7EED\u5931\u8D25\uFF0C\u81EA\u52A8\u91CD\u8BD5\u5DF2\u6682\u505C\uFF1B\u70B9\u51FB\u5237\u65B0\u989D\u5EA6\u91CD\u8BD5" : refreshIntervalSeconds === void 0 ? "\u672A\u542F\u7528\u81EA\u52A8\u5237\u65B0" : quota.refreshFailures ? `\u5237\u65B0\u5931\u8D25 ${quota.refreshFailures} \u6B21\uFF0C\u6B63\u5728\u5EF6\u8FDF\u91CD\u8BD5` : `\u6BCF ${refreshIntervalSeconds} \u79D2\u81EA\u52A8\u5237\u65B0`
|
|
20461
20591
|
}
|
|
20462
20592
|
];
|
|
@@ -20464,12 +20594,13 @@ function QuotaView({ quota, nextAutoRefreshAt, refreshIntervalSeconds }) {
|
|
|
20464
20594
|
quota.tier === void 0 ? void 0 : `\u5F53\u524D\u5957\u9910\uFF1A${quota.tier}`,
|
|
20465
20595
|
quota.eligible === void 0 ? void 0 : `\u5957\u9910\u8D44\u683C\uFF1A${quota.eligible ? "\u5DF2\u5F00\u901A" : "\u672A\u5F00\u901A"}`
|
|
20466
20596
|
].filter((value) => value !== void 0).join(" \xB7 ");
|
|
20597
|
+
const quotaStatus = quotaStatusView(quota, now);
|
|
20467
20598
|
return h(
|
|
20468
20599
|
React.Fragment,
|
|
20469
20600
|
null,
|
|
20470
20601
|
h(
|
|
20471
20602
|
"div",
|
|
20472
|
-
{ className: "odc-
|
|
20603
|
+
{ className: "odc-quota-panel" },
|
|
20473
20604
|
h(
|
|
20474
20605
|
"div",
|
|
20475
20606
|
{ className: "odc-card-head" },
|
|
@@ -20479,11 +20610,22 @@ function QuotaView({ quota, nextAutoRefreshAt, refreshIntervalSeconds }) {
|
|
|
20479
20610
|
h("h3", null, "\u5957\u9910\u8D60\u9001\u7A97\u53E3"),
|
|
20480
20611
|
tierLine === "" ? null : h("p", { className: "odc-hint" }, tierLine)
|
|
20481
20612
|
),
|
|
20613
|
+
quota.stale ? h("span", { className: "odc-chip" }, "\u4E0A\u6B21\u6210\u529F\u8BFB\u6570") : null
|
|
20614
|
+
),
|
|
20615
|
+
h(
|
|
20616
|
+
"div",
|
|
20617
|
+
{ className: "odc-quota-status", "data-state": quota.state, "data-tone": quotaStatus.tone },
|
|
20618
|
+
h("span", { className: "odc-state-mark", "aria-hidden": true }, quotaStatus.icon),
|
|
20482
20619
|
h(
|
|
20483
20620
|
"div",
|
|
20484
|
-
{ className: "odc-
|
|
20485
|
-
h("
|
|
20486
|
-
|
|
20621
|
+
{ className: "odc-state-copy" },
|
|
20622
|
+
h("strong", null, quotaStatus.title),
|
|
20623
|
+
quotaStatus.window === void 0 ? null : h(
|
|
20624
|
+
"span",
|
|
20625
|
+
{ className: "odc-hint" },
|
|
20626
|
+
`${windowLabel(quotaStatus.window.durationSeconds).replace("\u8D60\u9001\u7A97\u53E3", "")} \xB7 \u5269\u4F59 ${Math.max(0, Math.min(100, 100 - quotaStatus.window.percent)).toFixed(1)}%`,
|
|
20627
|
+
quotaStatus.window.resetsAt === void 0 ? null : h(React.Fragment, null, " \xB7 ", h(RelativeDeadline, { at: quotaStatus.window.resetsAt, dueText: "\u7B49\u5F85\u66F4\u65B0", titleLabel: "\u9884\u8BA1\u6062\u590D\u65F6\u95F4", futureSuffix: "\u6062\u590D" }))
|
|
20628
|
+
)
|
|
20487
20629
|
)
|
|
20488
20630
|
),
|
|
20489
20631
|
quota.windows.length === 0 ? quota.eligible === false ? h("p", { className: "odc-hint", role: "status" }, "\u5F53\u524D\u8D26\u53F7\u672A\u5F00\u901A Design Plan\uFF0C\u6CA1\u6709\u8D60\u9001\u989D\u5EA6\u7A97\u53E3\u3002") : h(
|
|
@@ -20494,9 +20636,10 @@ function QuotaView({ quota, nextAutoRefreshAt, refreshIntervalSeconds }) {
|
|
|
20494
20636
|
) : quota.windows.map((window, index) => {
|
|
20495
20637
|
const label = windowLabel(window.durationSeconds);
|
|
20496
20638
|
const remainingPercent = Math.max(0, Math.min(100, 100 - window.percent));
|
|
20639
|
+
const tone = quota.state === "ok" && !quota.stale && !windowDue(window, now) ? windowTone(window) : "neutral";
|
|
20497
20640
|
return h(
|
|
20498
20641
|
"section",
|
|
20499
|
-
{ className: "odc-window", key: `${window.durationSeconds}-${index}`, "aria-label": label },
|
|
20642
|
+
{ className: "odc-window", key: `${window.durationSeconds}-${index}`, "aria-label": label, "data-tone": tone },
|
|
20500
20643
|
h(
|
|
20501
20644
|
"div",
|
|
20502
20645
|
{ className: "odc-window-head" },
|
|
@@ -20505,48 +20648,52 @@ function QuotaView({ quota, nextAutoRefreshAt, refreshIntervalSeconds }) {
|
|
|
20505
20648
|
"div",
|
|
20506
20649
|
{ className: "odc-window-remaining" },
|
|
20507
20650
|
h("strong", null, `${remainingPercent.toFixed(1)}%`),
|
|
20508
|
-
h("span", { className: "odc-label" }, "\u5269\u4F59")
|
|
20651
|
+
h("span", { className: "odc-label" }, "\u5269\u4F59\u6BD4\u4F8B")
|
|
20509
20652
|
)
|
|
20510
20653
|
),
|
|
20511
20654
|
h("progress", { max: 100, value: remainingPercent, "aria-label": `${label}\u5269\u4F59\u989D\u5EA6` }),
|
|
20512
|
-
h(
|
|
20513
|
-
"dl",
|
|
20514
|
-
{ className: "odc-window-usage", "aria-label": "\u7A97\u53E3\u7528\u91CF\u660E\u7EC6" },
|
|
20515
|
-
[{ label: "\u5DF2\u7528", value: window.used }, { label: "\u4E0A\u9650", value: window.limit }, { label: "\u5269\u4F59", value: window.remaining ?? "\u2014" }].map((item) => h("div", { key: item.label }, h("dt", null, item.label), h("dd", null, item.value)))
|
|
20516
|
-
),
|
|
20655
|
+
h("p", { className: "odc-window-usage", title: `\u5DF2\u7528 ${window.used} / \u603B\u8BA1 ${window.limit} \u79EF\u5206`, "aria-label": `\u7A97\u53E3\u79EF\u5206\uFF1A\u5DF2\u7528 ${window.used}\uFF0C\u603B\u8BA1 ${window.limit}` }, `\u5DF2\u7528 ${formatWindowCredits(window.used)} / \u603B\u8BA1 ${formatWindowCredits(window.limit)} \u79EF\u5206`),
|
|
20517
20656
|
h(
|
|
20518
20657
|
"div",
|
|
20519
|
-
{ className: "odc-window-
|
|
20520
|
-
h("span", { className: "odc-label" }, "\u4E0B\u6B21\u6062\u590D"),
|
|
20521
|
-
window.resetsAt === void 0 ? h("span", null, "\u2014") : h("time", { dateTime: window.resetsAt }, formatTime(window.resetsAt))
|
|
20522
|
-
),
|
|
20523
|
-
window.windowStart === void 0 && window.resetMode === void 0 ? null : h(
|
|
20524
|
-
"details",
|
|
20525
|
-
{ className: "odc-window-details" },
|
|
20526
|
-
h("summary", null, "\u7A97\u53E3\u8BE6\u60C5"),
|
|
20658
|
+
{ className: "odc-window-bottom" },
|
|
20527
20659
|
h(
|
|
20528
|
-
"
|
|
20529
|
-
|
|
20530
|
-
|
|
20531
|
-
|
|
20660
|
+
"div",
|
|
20661
|
+
{ className: "odc-window-reset" },
|
|
20662
|
+
h("span", { className: "odc-label" }, "\u4E0B\u6B21\u6062\u590D"),
|
|
20663
|
+
h(RelativeDeadline, { at: window.resetsAt, dueText: "\u5DF2\u5230\u6062\u590D\u65F6\u95F4\uFF0C\u7B49\u5F85\u66F4\u65B0", titleLabel: "\u9884\u8BA1\u6062\u590D\u65F6\u95F4" })
|
|
20664
|
+
),
|
|
20665
|
+
h(
|
|
20666
|
+
"details",
|
|
20667
|
+
{ className: "odc-window-details" },
|
|
20668
|
+
h("summary", null, "\u7A97\u53E3\u8BE6\u60C5"),
|
|
20669
|
+
h(
|
|
20670
|
+
"dl",
|
|
20671
|
+
null,
|
|
20672
|
+
h("div", null, h("dt", null, "\u63A5\u53E3\u5269\u4F59\u79EF\u5206"), h("dd", null, window.remaining === void 0 ? "\u2014" : window.remaining)),
|
|
20673
|
+
window.windowStart === void 0 ? null : h("div", null, h("dt", null, "\u7A97\u53E3\u5F00\u59CB"), h("dd", null, h("time", { dateTime: window.windowStart }, formatTime(window.windowStart)))),
|
|
20674
|
+
window.resetMode === void 0 ? null : h("div", null, h("dt", null, "\u91CD\u7F6E\u65B9\u5F0F"), h("dd", null, RESET_MODE_LABELS[window.resetMode] ?? window.resetMode))
|
|
20675
|
+
)
|
|
20532
20676
|
)
|
|
20533
20677
|
)
|
|
20534
20678
|
);
|
|
20535
20679
|
})
|
|
20536
20680
|
),
|
|
20537
|
-
h(
|
|
20538
|
-
"
|
|
20539
|
-
{ className: "odc-card
|
|
20540
|
-
h("
|
|
20541
|
-
h("
|
|
20542
|
-
|
|
20543
|
-
|
|
20544
|
-
|
|
20681
|
+
h(
|
|
20682
|
+
"section",
|
|
20683
|
+
{ className: "odc-card", "aria-label": "\u94B1\u5305\u4F59\u989D" },
|
|
20684
|
+
h("h3", null, "\u94B1\u5305\u4F59\u989D"),
|
|
20685
|
+
h("dl", { className: "odc-balance-list" }, metrics.map((metric) => h(
|
|
20686
|
+
"div",
|
|
20687
|
+
{ className: "odc-balance-row odc-metric", key: metric.label },
|
|
20688
|
+
h("div", null, h("dt", { title: metric.hint }, metric.label)),
|
|
20689
|
+
h("dd", null, h("strong", { className: "odc-metric-value" }, metric.value))
|
|
20690
|
+
)))
|
|
20691
|
+
),
|
|
20692
|
+
h("dl", { className: "odc-card odc-timing", "aria-label": "\u989D\u5EA6\u65F6\u95F4\u5B89\u6392" }, timing.map((metric) => h(
|
|
20545
20693
|
"div",
|
|
20546
|
-
{ className: "odc-metric", key: metric.label },
|
|
20547
|
-
h("span", { className: "odc-
|
|
20548
|
-
h("strong", { className: "odc-metric-value odc-metric-text" }, metric.value)
|
|
20549
|
-
h("span", { className: "odc-hint" }, metric.hint)
|
|
20694
|
+
{ className: "odc-timing-row odc-metric", key: metric.label },
|
|
20695
|
+
h("div", null, h("dt", null, metric.label), h("span", { className: "odc-hint" }, metric.hint)),
|
|
20696
|
+
h("dd", null, h("strong", { className: "odc-metric-value odc-metric-text" }, metric.value))
|
|
20550
20697
|
))),
|
|
20551
20698
|
h(
|
|
20552
20699
|
"dl",
|
|
@@ -20642,7 +20789,7 @@ function Overview({ status, busy, onRefresh, nextAutoRefreshAt, refreshIntervalS
|
|
|
20642
20789
|
h("div", null, h("h3", null, "\u989D\u5EA6\u6982\u89C8"), h("p", { className: "odc-hint" }, "\u67E5\u770B\u5957\u9910\u7528\u91CF\u3001\u8BA2\u9605\u4F59\u989D\u548C\u5145\u503C\u4F59\u989D\u3002")),
|
|
20643
20790
|
h("button", { className: "odc-button", type: "button", disabled: busy, onClick: onRefresh }, busy ? "\u5237\u65B0\u4E2D\u2026" : "\u5237\u65B0\u989D\u5EA6")
|
|
20644
20791
|
),
|
|
20645
|
-
h(QuotaView, { quota: status?.quota, nextAutoRefreshAt, refreshIntervalSeconds })
|
|
20792
|
+
h(QuotaView, { quota: status?.quota, nextAutoRefreshAt, refreshIntervalSeconds, busy })
|
|
20646
20793
|
);
|
|
20647
20794
|
}
|
|
20648
20795
|
var NUMERIC_FIELDS = {
|
|
@@ -20750,7 +20897,23 @@ function EffortField({ id, model, value, disabled, onChange }) {
|
|
|
20750
20897
|
}, error62 ?? (invalidDefault ? "\u5DF2\u4FDD\u5B58\u7684\u6863\u4F4D\u4E0D\u9002\u7528\u4E8E\u5F53\u524D\u6A21\u578B\u6216\u534F\u8BAE\uFF0C\u8BF7\u9009\u62E9\u5176\u4ED6\u6863\u4F4D\u6216\u7EE7\u627F\u9ED8\u8BA4\u3002" : unavailable ? "\u5F53\u524D\u6A21\u578B\u6216\u534F\u8BAE\u672A\u63D0\u4F9B\u53EF\u8C03\u6574\u7684\u601D\u8003\u6863\u4F4D\u3002" : "\u7559\u7A7A\u4F7F\u7528\u670D\u52A1\u7AEF\u9ED8\u8BA4\u6863\u4F4D\u3002"))
|
|
20751
20898
|
);
|
|
20752
20899
|
}
|
|
20753
|
-
|
|
20900
|
+
var PRICE_SITE = "https://corouter.open-design.ai/zh/models/";
|
|
20901
|
+
function priceUnit(tier) {
|
|
20902
|
+
return tier.unit === "per_1m_tokens" ? "\u6BCF\u767E\u4E07 Token" : tier.unit === "per_1k_tokens" ? "\u6BCF\u5343 Token" : "\u8BA1\u4EF7\u5355\u4F4D\u672A\u6807\u660E";
|
|
20903
|
+
}
|
|
20904
|
+
function priceAmount(amount2, currency) {
|
|
20905
|
+
if (amount2 === null) return "\u672A\u5217\u51FA";
|
|
20906
|
+
return currency === "USD" ? `$${amount2}` : `${amount2}\uFF08\u5E01\u79CD\u672A\u6807\u660E\uFF09`;
|
|
20907
|
+
}
|
|
20908
|
+
function PriceDetails({ tiers }) {
|
|
20909
|
+
return h("div", { className: "odc-price-details", "aria-label": "\u5B98\u7F51\u4EF7\u683C\u8BE6\u60C5" }, tiers.map((tier, index) => h(
|
|
20910
|
+
"section",
|
|
20911
|
+
{ className: "odc-price-tier", key: `${index}-${tier.label}` },
|
|
20912
|
+
h("strong", null, `${tier.label} \xB7 ${priceUnit(tier)}`),
|
|
20913
|
+
h("dl", null, [["\u8F93\u5165", tier.input], ["\u8F93\u51FA", tier.output], ["\u7F13\u5B58\u8BFB\u53D6", tier.cacheRead], ["\u7F13\u5B58\u5199\u5165", tier.cacheWrite]].map(([label, value]) => h("div", { key: label }, h("dt", null, label), h("dd", null, priceAmount(value, tier.currency)))))
|
|
20914
|
+
)));
|
|
20915
|
+
}
|
|
20916
|
+
function ModelRow({ model, settings, authoritative, writable, pending, price, priceKnown = false, onCommit }) {
|
|
20754
20917
|
const id = React.useId();
|
|
20755
20918
|
const mounted = useMounted();
|
|
20756
20919
|
const [error62, setError] = React.useState(void 0);
|
|
@@ -20813,11 +20976,13 @@ function ModelRow({ model, settings, authoritative, writable, pending, onCommit
|
|
|
20813
20976
|
} }, "\u91CD\u7F6E")
|
|
20814
20977
|
)
|
|
20815
20978
|
),
|
|
20979
|
+
price !== void 0 ? h("p", { className: "odc-price-summary" }, `\u5B98\u7F51\u53C2\u8003 \xB7 ${price.tiers[0].label} \xB7 \u8F93\u5165 ${priceAmount(price.tiers[0].input, price.tiers[0].currency)} / \u8F93\u51FA ${priceAmount(price.tiers[0].output, price.tiers[0].currency)} \xB7 ${priceUnit(price.tiers[0])}${price.tiers.length > 1 ? ` \xB7 \u5171 ${price.tiers.length} \u6863` : ""}`) : priceKnown ? h("p", { className: "odc-price-summary" }, "\u5B98\u7F51\u6682\u672A\u5217\u51FA\u6B64\u6A21\u578B\u4EF7\u683C") : null,
|
|
20816
20980
|
h(
|
|
20817
20981
|
"details",
|
|
20818
20982
|
{ className: "odc-model-details" },
|
|
20819
|
-
h("summary", { "aria-label": `${model.name} \u53C2\u6570\u8BBE\u7F6E` },
|
|
20983
|
+
h("summary", { "aria-label": `${model.name} \u53C2\u6570\u8BBE\u7F6E${price === void 0 ? "" : "\u4E0E\u4EF7\u683C"}` }, `${price === void 0 ? "\u53C2\u6570\u8BBE\u7F6E" : "\u53C2\u6570\u4E0E\u4EF7\u683C"} \xB7 ${hasOverrides ? "\u5DF2\u81EA\u5B9A\u4E49" : "\u4F7F\u7528\u9ED8\u8BA4\u503C"}`),
|
|
20820
20984
|
h("p", { className: "odc-model-meta" }, facts),
|
|
20985
|
+
price === void 0 ? null : h(PriceDetails, { tiers: price.tiers }),
|
|
20821
20986
|
h("p", { className: "odc-hint" }, "\u6570\u503C\u79BB\u5F00\u8F93\u5165\u6846\u540E\u4FDD\u5B58\uFF0C\u7559\u7A7A\u7EE7\u627F\u9ED8\u8BA4\u3002"),
|
|
20822
20987
|
h(
|
|
20823
20988
|
"div",
|
|
@@ -20849,7 +21014,7 @@ function ModelRow({ model, settings, authoritative, writable, pending, onCommit
|
|
|
20849
21014
|
error62 !== void 0 ? h("p", { className: "odc-hint odc-field-error", role: "alert" }, error62) : null
|
|
20850
21015
|
);
|
|
20851
21016
|
}
|
|
20852
|
-
function ModelGroup({ title, group, models, settingsMap, authoritative, writable, pending, onCommit }) {
|
|
21017
|
+
function ModelGroup({ title, group, models, settingsMap, authoritative, writable, pending, onCommit, prices }) {
|
|
20853
21018
|
const [query, setQuery] = React.useState("");
|
|
20854
21019
|
const [expanded, setExpanded] = React.useState(false);
|
|
20855
21020
|
const id = React.useId();
|
|
@@ -20883,6 +21048,8 @@ function ModelGroup({ title, group, models, settingsMap, authoritative, writable
|
|
|
20883
21048
|
authoritative,
|
|
20884
21049
|
writable,
|
|
20885
21050
|
pending,
|
|
21051
|
+
price: prices?.models.find((entry) => entry.id === model.id),
|
|
21052
|
+
priceKnown: prices !== void 0 && (prices.state !== "error" || prices.stale),
|
|
20886
21053
|
onCommit: (next) => onCommit(model.id, next)
|
|
20887
21054
|
}))),
|
|
20888
21055
|
normalized === "" && filtered.length > 6 ? h("button", {
|
|
@@ -20895,7 +21062,7 @@ function ModelGroup({ title, group, models, settingsMap, authoritative, writable
|
|
|
20895
21062
|
}, expanded ? "\u6536\u8D77\u6A21\u578B\u5217\u8868" : `\u663E\u793A\u5168\u90E8 ${filtered.length} \u4E2A\u6A21\u578B`) : null
|
|
20896
21063
|
);
|
|
20897
21064
|
}
|
|
20898
|
-
function Models({ status, formSnapshot, setFormField, pendingField, onRefreshModels, refreshingModels, notice }) {
|
|
21065
|
+
function Models({ status, formSnapshot, setFormField, pendingField, onRefreshModels, refreshingModels, notice, prices, refreshingPrices = false, onRefreshPrices }) {
|
|
20899
21066
|
const formReady = formSnapshot.status === "ready" && formSnapshot.value !== void 0;
|
|
20900
21067
|
const settingsMap = formReady ? formSnapshot.value?.modelSettings ?? {} : status?.config.modelSettings ?? {};
|
|
20901
21068
|
const authoritative = formReady || status?.config.modelSettings !== void 0;
|
|
@@ -20950,11 +21117,23 @@ function Models({ status, formSnapshot, setFormField, pendingField, onRefreshMod
|
|
|
20950
21117
|
status?.apiKeyConfigured === false ? h("p", { className: "odc-hint" }, "\u5237\u65B0\u6A21\u578B\u9700\u8981\u53EF\u7528\u7684 API Key\uFF1B\u4FDD\u5B58 Key \u540E\u91CD\u8BD5\u3002") : null,
|
|
20951
21118
|
status?.modelsError !== void 0 ? h("p", { className: "odc-notice", "data-kind": "error", role: "alert" }, status.modelsError) : null,
|
|
20952
21119
|
h(NoticeView, { notice }),
|
|
21120
|
+
h(
|
|
21121
|
+
"section",
|
|
21122
|
+
{ className: "odc-card", "aria-label": "\u5B98\u7F51\u6A21\u578B\u4EF7\u683C" },
|
|
21123
|
+
h(
|
|
21124
|
+
"div",
|
|
21125
|
+
{ className: "odc-pricing-head" },
|
|
21126
|
+
h("h3", null, "\u5B98\u7F51\u53C2\u8003\u4EF7\u683C"),
|
|
21127
|
+
h("button", { className: "odc-button", type: "button", disabled: refreshingPrices || onRefreshPrices === void 0, onClick: onRefreshPrices }, refreshingPrices ? "\u6B63\u5728\u66F4\u65B0\u4EF7\u683C\u2026" : "\u66F4\u65B0\u4EF7\u683C")
|
|
21128
|
+
),
|
|
21129
|
+
h("p", { className: "odc-hint", role: "status" }, refreshingPrices ? "\u6B63\u5728\u8BFB\u53D6\u5B98\u7F51\u4EF7\u683C\u2026" : prices === void 0 ? "\u7B49\u5F85\u8BFB\u53D6\u5B98\u7F51\u4EF7\u683C\u3002" : prices.state === "error" ? prices.stale ? `\u8BFB\u53D6\u5931\u8D25\uFF0C\u663E\u793A\u4E0A\u6B21\u4EF7\u683C\uFF08${formatTime(prices.fetchedAt)}\uFF09\u3002` : "\u5B98\u7F51\u4EF7\u683C\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002" : `\u5DF2\u66F4\u65B0\uFF1A${formatTime(prices.fetchedAt)}${prices.state === "partial" ? "\uFF1B\u90E8\u5206\u4EF7\u683C\u672A\u80FD\u8BFB\u53D6" : ""}`),
|
|
21130
|
+
h("p", { className: "odc-hint" }, "\u5B98\u7F51\u5206\u6863\u4EF7\u683C\u4EC5\u4F9B\u53C2\u8003\uFF1B\u5B9E\u9645\u8D39\u7528\u4EE5\u8D26\u6237\u8D26\u5355\u4E3A\u51C6\u3002", " ", h("a", { className: "odc-link", href: PRICE_SITE, target: "_blank", rel: "noreferrer noopener" }, "\u67E5\u770B\u5B98\u7F51\u4EF7\u683C"))
|
|
21131
|
+
),
|
|
20953
21132
|
models.length === 0 ? h("p", { className: "odc-hint", role: "status" }, "\u6682\u65E0\u53EF\u7528\u6A21\u578B\uFF1B\u53EF\u5237\u65B0\u6A21\u578B\u5217\u8868\u540E\u91CD\u8BD5\u3002") : h(
|
|
20954
21133
|
"div",
|
|
20955
21134
|
{ className: "odc-model-groups" },
|
|
20956
|
-
h(ModelGroup, { title: "\u5957\u9910\u8D60\u9001\u6A21\u578B", group: "plan", models, settingsMap, authoritative, writable, pending, onCommit: commit }),
|
|
20957
|
-
h(ModelGroup, { title: "\u4ED8\u8D39\u6A21\u578B", group: "paid", models, settingsMap, authoritative, writable, pending, onCommit: commit })
|
|
21135
|
+
h(ModelGroup, { title: "\u5957\u9910\u8D60\u9001\u6A21\u578B", group: "plan", models, settingsMap, authoritative, writable, pending, onCommit: commit, prices }),
|
|
21136
|
+
h(ModelGroup, { title: "\u4ED8\u8D39\u6A21\u578B", group: "paid", models, settingsMap, authoritative, writable, pending, onCommit: commit, prices })
|
|
20958
21137
|
)
|
|
20959
21138
|
);
|
|
20960
21139
|
}
|
|
@@ -21450,6 +21629,10 @@ function SettingsPage({ caller, form }) {
|
|
|
21450
21629
|
const [loading, setLoading] = React.useState(true);
|
|
21451
21630
|
const [refreshing, setRefreshing] = React.useState(false);
|
|
21452
21631
|
const [refreshingModels, setRefreshingModels] = React.useState(false);
|
|
21632
|
+
const [prices, setPrices] = React.useState();
|
|
21633
|
+
const [refreshingPrices, setRefreshingPrices] = React.useState(false);
|
|
21634
|
+
const pricesBusy = React.useRef(false);
|
|
21635
|
+
const pricesRequested = React.useRef(false);
|
|
21453
21636
|
const [modelsNotice, setModelsNotice] = React.useState(null);
|
|
21454
21637
|
const [pendingField, setPendingField] = React.useState([]);
|
|
21455
21638
|
const writeTail = React.useRef(Promise.resolve());
|
|
@@ -21595,6 +21778,25 @@ function SettingsPage({ caller, form }) {
|
|
|
21595
21778
|
}
|
|
21596
21779
|
}
|
|
21597
21780
|
}, [caller, mounted]);
|
|
21781
|
+
const refreshPrices = React.useCallback(async () => {
|
|
21782
|
+
if (pricesBusy.current) return;
|
|
21783
|
+
pricesBusy.current = true;
|
|
21784
|
+
setRefreshingPrices(true);
|
|
21785
|
+
try {
|
|
21786
|
+
const next = await caller("refreshPrices");
|
|
21787
|
+
if (mounted.current) setPrices(next);
|
|
21788
|
+
} catch {
|
|
21789
|
+
if (mounted.current) setPrices((previous) => previous?.fetchedAt === void 0 ? { state: "error", stale: false, models: [] } : { ...previous, state: "error", stale: true });
|
|
21790
|
+
} finally {
|
|
21791
|
+
pricesBusy.current = false;
|
|
21792
|
+
if (mounted.current) setRefreshingPrices(false);
|
|
21793
|
+
}
|
|
21794
|
+
}, [caller, mounted]);
|
|
21795
|
+
React.useEffect(() => {
|
|
21796
|
+
if (tab !== "models" || pricesRequested.current) return;
|
|
21797
|
+
pricesRequested.current = true;
|
|
21798
|
+
void refreshPrices();
|
|
21799
|
+
}, [tab, refreshPrices]);
|
|
21598
21800
|
const loginState = status?.login.state;
|
|
21599
21801
|
const loginActive = loginState !== void 0 && loginInFlight(loginState);
|
|
21600
21802
|
React.useEffect(() => {
|
|
@@ -21667,7 +21869,12 @@ function SettingsPage({ caller, form }) {
|
|
|
21667
21869
|
void refreshModels();
|
|
21668
21870
|
},
|
|
21669
21871
|
refreshingModels,
|
|
21670
|
-
notice: modelsNotice
|
|
21872
|
+
notice: modelsNotice,
|
|
21873
|
+
prices,
|
|
21874
|
+
refreshingPrices,
|
|
21875
|
+
onRefreshPrices: () => {
|
|
21876
|
+
void refreshPrices();
|
|
21877
|
+
}
|
|
21671
21878
|
});
|
|
21672
21879
|
} else if (tab === "connection") {
|
|
21673
21880
|
content = h(Connection, { status, formSnapshot, setFormField, pendingField, caller, onLoginStatus: acceptLoginStatus, onStatus: acceptStatus });
|
package/lib/device-auth.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export interface DeviceTokens {
|
|
|
3
3
|
runtimeKey: string;
|
|
4
4
|
}
|
|
5
5
|
export declare const DEVICE_AUTH_ENDPOINT = "https://amr-api.open-design.ai/api/v1/cli/device-authorizations";
|
|
6
|
-
export declare const DEVICE_AUTH_PLUGIN_VERSION = "0.1.
|
|
6
|
+
export declare const DEVICE_AUTH_PLUGIN_VERSION = "0.1.10";
|
|
7
7
|
export declare const DEVICE_REQUEST_TIMEOUT_MS = 20000;
|
|
8
8
|
/** One bounded launch step of the temporary activation window. */
|
|
9
9
|
export declare const DEVICE_OPEN_TIMEOUT_MS = 30000;
|
|
@@ -136,6 +136,40 @@ function member(value, allowed, label) {
|
|
|
136
136
|
if (hit === void 0) throw new Error(`${label} \u4E0D\u5728\u5141\u8BB8\u7684\u53D6\u503C\u5185`);
|
|
137
137
|
return hit;
|
|
138
138
|
}
|
|
139
|
+
function parsePriceCatalog(value) {
|
|
140
|
+
if (!record(value) || !Array.isArray(value.models) || value.models.length > MAX_MODELS) throw new Error("\u4EF7\u683C\u76EE\u5F55\u683C\u5F0F\u65E0\u6548");
|
|
141
|
+
const state = member(value.state, ["ok", "partial", "error"], "\u4EF7\u683C\u76EE\u5F55\u72B6\u6001");
|
|
142
|
+
const stale = flag(value.stale, "\u4EF7\u683C\u7F13\u5B58\u72B6\u6001");
|
|
143
|
+
const fetchedAt = value.fetchedAt === void 0 ? void 0 : isoTime(value.fetchedAt, "\u4EF7\u683C\u66F4\u65B0\u65F6\u95F4");
|
|
144
|
+
if (stale && fetchedAt === void 0) throw new Error("\u8FC7\u671F\u4EF7\u683C\u5FC5\u987B\u6807\u6CE8\u66F4\u65B0\u65F6\u95F4");
|
|
145
|
+
const ids = /* @__PURE__ */ new Set();
|
|
146
|
+
const nullableAmount = (item) => {
|
|
147
|
+
if (item === null) return null;
|
|
148
|
+
const result = amount(item, "\u4EF7\u683C");
|
|
149
|
+
if (result > 1e6) throw new Error("\u4EF7\u683C\u8D85\u51FA\u8303\u56F4");
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
const models = value.models.map((model) => {
|
|
153
|
+
if (!record(model) || !Array.isArray(model.tiers) || model.tiers.length === 0 || model.tiers.length > 8) throw new Error("\u6A21\u578B\u4EF7\u683C\u683C\u5F0F\u65E0\u6548");
|
|
154
|
+
const id = text(model.id, "\u6A21\u578B id", 128);
|
|
155
|
+
if (!MODEL_ID.test(id) || ids.has(id)) throw new Error("\u6A21\u578B\u4EF7\u683C id \u65E0\u6548\u6216\u91CD\u590D");
|
|
156
|
+
ids.add(id);
|
|
157
|
+
const tiers = model.tiers.map((tier) => {
|
|
158
|
+
if (!record(tier)) throw new Error("\u4EF7\u683C\u6863\u4F4D\u683C\u5F0F\u65E0\u6548");
|
|
159
|
+
return {
|
|
160
|
+
label: text(tier.label, "\u4EF7\u683C\u6863\u4F4D", 128),
|
|
161
|
+
currency: tier.currency === null ? null : member(tier.currency, ["USD"], "\u4EF7\u683C\u5E01\u79CD"),
|
|
162
|
+
unit: tier.unit === null ? null : member(tier.unit, ["per_1m_tokens", "per_1k_tokens"], "\u4EF7\u683C\u5355\u4F4D"),
|
|
163
|
+
input: nullableAmount(tier.input),
|
|
164
|
+
output: nullableAmount(tier.output),
|
|
165
|
+
cacheRead: nullableAmount(tier.cacheRead),
|
|
166
|
+
cacheWrite: nullableAmount(tier.cacheWrite)
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
return { id, tiers };
|
|
170
|
+
});
|
|
171
|
+
return { state, stale, ...fetchedAt === void 0 ? {} : { fetchedAt }, models };
|
|
172
|
+
}
|
|
139
173
|
function parseQuotaWindow(value) {
|
|
140
174
|
if (!record(value)) throw new Error("\u989D\u5EA6\u7A97\u53E3\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
141
175
|
const durationSeconds = amount(value.durationSeconds, "\u989D\u5EA6\u7A97\u53E3\u65F6\u957F");
|
|
@@ -283,6 +317,7 @@ function parseActivationOpenState(value) {
|
|
|
283
317
|
|
|
284
318
|
// src/generated/typert.remote-client.ts
|
|
285
319
|
var StatusCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#Status", create: () => z.unknown().transform((value) => parseStatus(value)) };
|
|
320
|
+
var PriceCatalogCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#PriceCatalog", create: () => z.unknown().transform((value) => parsePriceCatalog(value)) };
|
|
286
321
|
var QuotaSnapshotCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#QuotaSnapshot", create: () => z.unknown().transform((value) => parseQuotaSnapshot(value)) };
|
|
287
322
|
var LoginStateCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#LoginState", create: () => z.unknown().transform((value) => parseLoginState(value)) };
|
|
288
323
|
var StartLoginRequestCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corouter#StartLoginRequest", create: () => z.unknown().transform((value) => parseStartLoginRequest(value)) };
|
|
@@ -292,6 +327,7 @@ var SaveApiKeyRequestCodec = { mode: "strict", typeSymbol: "dsh-opendesign-corou
|
|
|
292
327
|
var TYPERT_REMOTE = createTypertRemoteInfo({ package: "dsh-opendesign-corouter", methods: {
|
|
293
328
|
"openDesignCoRouter/status": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: StatusCodec },
|
|
294
329
|
"openDesignCoRouter/refreshModels": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: StatusCodec },
|
|
330
|
+
"openDesignCoRouter/refreshPrices": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: PriceCatalogCodec },
|
|
295
331
|
"openDesignCoRouter/refreshQuota": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: QuotaSnapshotCodec },
|
|
296
332
|
"openDesignCoRouter/refreshQuotaNow": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [], result: QuotaSnapshotCodec },
|
|
297
333
|
"openDesignCoRouter/startLogin": { service: "openDesignCoRouter", invocation: { kind: "direct" }, parameters: [{ name: "input", source: "json", codec: StartLoginRequestCodec, strictCodec: StartLoginRequestCodec }], result: LoginStateCodec },
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol';
|
|
2
|
-
import type { Status, QuotaSnapshot, LoginState, StartLoginRequest, CancelLoginRequest, ActivationOpenState, SaveApiKeyRequest } from '../remote.js';
|
|
2
|
+
import type { Status, PriceCatalog, QuotaSnapshot, LoginState, StartLoginRequest, CancelLoginRequest, ActivationOpenState, SaveApiKeyRequest } from '../remote.js';
|
|
3
3
|
export type CoRouterRemote = {
|
|
4
4
|
status: () => Promise<RemoteResult<Status>>;
|
|
5
5
|
refreshModels: () => Promise<RemoteResult<Status>>;
|
|
6
|
+
refreshPrices: () => Promise<RemoteResult<PriceCatalog>>;
|
|
6
7
|
refreshQuota: () => Promise<RemoteResult<QuotaSnapshot>>;
|
|
7
8
|
refreshQuotaNow: () => Promise<RemoteResult<QuotaSnapshot>>;
|
|
8
9
|
startLogin: (input: StartLoginRequest) => Promise<RemoteResult<LoginState>>;
|