bailinghub 0.7.0 → 0.9.0
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.en.md +7 -9
- package/README.md +7 -9
- package/docker-compose.images.yml +2 -2
- package/docs/AGENT_CLIENT_RUNTIME_API.en.md +46 -0
- package/docs/AGENT_CLIENT_RUNTIME_API.md +34 -0
- package/docs/AGENT_TASK_CONTROL.en.md +25 -0
- package/docs/AGENT_TASK_CONTROL.md +94 -0
- package/docs/AGENT_TASK_CONTROL_FOUNDATION.md +134 -0
- package/docs/ARCHITECTURE.md +1 -1
- package/docs/CHANGELOG.en.md +22 -1
- package/docs/CHANGELOG.md +22 -1
- package/docs/COMPATIBILITY.en.md +6 -0
- package/docs/CONTRACT.en.md +2 -0
- package/docs/CONTRACT.md +2 -0
- package/docs/GENERATED_ARTIFACTS.en.md +46 -0
- package/docs/GENERATED_ARTIFACTS.md +108 -0
- package/docs/INDEPENDENT_VALIDATION.en.md +4 -4
- package/docs/INDEPENDENT_VALIDATION.md +4 -4
- package/docs/INVOCATION_RECEIPTS.md +111 -0
- package/docs/MODEL_BILLING.en.md +123 -0
- package/docs/MODEL_BILLING.md +125 -0
- package/docs/PERIOD_ALLOWANCE_UPGRADE.en.md +31 -0
- package/docs/PERIOD_ALLOWANCE_UPGRADE.md +31 -0
- package/docs/README.en.md +7 -0
- package/docs/README.md +7 -0
- package/docs/RELEASE_NOTES_NEXT.en.md +4 -2
- package/docs/RELEASE_NOTES_NEXT.md +4 -2
- package/docs/RELEASE_NOTES_v0.8.0.en.md +40 -0
- package/docs/RELEASE_NOTES_v0.8.0.md +62 -0
- package/docs/RELEASE_NOTES_v0.9.0.en.md +45 -0
- package/docs/RELEASE_NOTES_v0.9.0.md +45 -0
- package/docs/TOOL_RATE_LIMITS.md +50 -0
- package/docs/UPGRADE_v0.8.0.en.md +71 -0
- package/docs/UPGRADE_v0.8.0.md +73 -0
- package/docs/UPGRADE_v0.9.0.en.md +54 -0
- package/docs/UPGRADE_v0.9.0.md +54 -0
- package/docs//345/205/274/345/256/271/346/200/247/344/270/216/345/215/207/347/272/247.md +6 -0
- package/package.json +1 -1
- package/schemas/config/route.schema.json +1 -0
- package/schemas/config/tool-provider.schema.json +2 -1
- package/scripts/check-doc-links.mjs +5 -0
- package/scripts/check-image-tags.sh +1 -1
- package/scripts/check-release-consistency.test.mjs +2 -2
- package/scripts/e2e-console.mjs +32 -2
- package/scripts/install.sh +1 -1
- package/scripts/publish-images.sh +1 -1
- package/scripts/release-audit.mjs +2 -0
- package/scripts/sdk-runtime-test.mjs +6 -0
- package/scripts/verify-billing-install-upgrade.mjs +225 -0
- package/scripts/verify-github-repo.mjs +2 -0
- package/sdk/node/README.md +17 -0
- package/sdk/node/examples/billing.mjs +21 -0
- package/sdk/node/package.json +5 -1
- package/sdk/node/src/index.mjs +2 -0
- package/sdk/node/src/usage.d.mts +74 -0
- package/sdk/node/src/usage.mjs +62 -0
- package/sdk/node/tests/usage-types.mts +23 -0
- package/sdk/node/tests/usage.test.mjs +81 -0
- package/sdk/php7/README.md +19 -2
- package/sdk/php7/examples/billing.php +27 -0
- package/sdk/php7/examples/well-known.php +1 -1
- package/sdk/php7/src/ToolSpec.php +1 -1
- package/sdk/php7/src/UsageClient.php +95 -0
- package/sdk/php7/src/UsageClientException.php +22 -0
- package/sdk/php7/tests/billing-core-http.php +59 -0
- package/sdk/php7/tests/usage-client.php +78 -0
- package/sql/060_agent_artifacts.sql +11 -0
- package/sql/061_tool_rate_limit_policies.sql +3 -0
- package/sql/062_agent_task_control.sql +92 -0
- package/sql/063_usage_model_billing.sql +153 -0
- package/sql/064_period_plan_allowance.sql +25 -0
- package/sql/README.en.md +12 -4
- package/sql/README.md +14 -6
- package/src/adapters/storage/object-storage.ts +15 -3
- package/src/adapters/storage/oss-signature.test.ts +40 -0
- package/src/adapters/storage/oss-signature.ts +21 -0
- package/src/app/agent-artifacts.test.ts +165 -0
- package/src/app/agent-artifacts.ts +85 -0
- package/src/app/agent-client-runtime.test.ts +76 -1
- package/src/app/agent-client-runtime.ts +13 -0
- package/src/app/agent-invocation-snapshot.ts +35 -0
- package/src/app/agent-task-control.ts +187 -0
- package/src/app/agent-task-runtime.ts +68 -0
- package/src/app/agent-tool-invocations.test.ts +329 -1
- package/src/app/agent-tool-invocations.ts +223 -10
- package/src/app/agent-tool-job.test.ts +11 -1
- package/src/app/agent-tool-job.ts +8 -1
- package/src/app/auth.ts +2 -0
- package/src/app/builtin-tools.ts +4 -0
- package/src/app/oss-edition.ts +2 -0
- package/src/app/tool-approvals.ts +4 -0
- package/src/app/tool-assembly.ts +5 -0
- package/src/core/config/artifact-config.ts +15 -0
- package/src/core/config/config-codec.ts +3 -1
- package/src/core/config/config-models.ts +11 -1
- package/src/core/config/route-config.ts +3 -2
- package/src/core/contracts/tool-rate-limits.test.ts +59 -0
- package/src/core/contracts/tool-rate-limits.ts +48 -0
- package/src/core/contracts/tools.ts +122 -43
- package/src/core/contracts/types.ts +3 -1
- package/src/core/runtime/agent-task-control.test.ts +114 -0
- package/src/core/runtime/agent-task-control.ts +227 -0
- package/src/infrastructure/config/config-agent-artifact-repository.ts +32 -0
- package/src/infrastructure/config/config-agent-client-runtime-repository.ts +7 -1
- package/src/infrastructure/config/config-agent-task-control-journal-mysql.test.ts +315 -0
- package/src/infrastructure/config/config-agent-task-control-mysql.test.ts +331 -0
- package/src/infrastructure/config/config-agent-task-control-repository.ts +640 -0
- package/src/infrastructure/config/config-rate-limit-ledger.integration.test.ts +52 -0
- package/src/infrastructure/config/config-rate-limit-ledger.ts +48 -0
- package/src/infrastructure/config/config-storage-bucket-repository.ts +2 -2
- package/src/infrastructure/config/config-tool-provider-repository.ts +4 -4
- package/src/infrastructure/config/configstore.ts +15 -1
- package/src/modules/usage/allowance-reset.mysql.test.ts +122 -0
- package/src/modules/usage/billing-contracts.ts +59 -0
- package/src/modules/usage/billing-decimal.test.ts +22 -0
- package/src/modules/usage/billing-decimal.ts +36 -0
- package/src/modules/usage/billing-external.ts +39 -0
- package/src/modules/usage/billing-gateway.mysql.test.ts +24 -0
- package/src/modules/usage/billing-ledger.test.ts +51 -0
- package/src/modules/usage/billing-ledger.ts +104 -0
- package/src/modules/usage/billing-presentation.mysql.test.ts +95 -0
- package/src/modules/usage/billing-presentation.test.ts +49 -0
- package/src/modules/usage/billing-presentation.ts +34 -0
- package/src/modules/usage/billing-prices.mysql.test.ts +88 -0
- package/src/modules/usage/billing-repository.mysql.test.ts +181 -0
- package/src/modules/usage/billing-repository.ts +463 -0
- package/src/modules/usage/contracts.ts +49 -0
- package/src/modules/usage/dynamic-plan-models.mysql.test.ts +221 -0
- package/src/modules/usage/errors.ts +19 -0
- package/src/modules/usage/http.ts +85 -0
- package/src/modules/usage/identity-revocation.mysql.test.ts +286 -0
- package/src/modules/usage/identity.mysql.test.ts +120 -0
- package/src/modules/usage/identity.ts +303 -0
- package/src/modules/usage/issuer-sdk-billing.mysql.test.ts +92 -0
- package/src/modules/usage/model-gateway.mysql.test.ts +207 -0
- package/src/modules/usage/model-gateway.ts +229 -0
- package/src/modules/usage/model-tool-gateway.mysql.test.ts +137 -0
- package/src/modules/usage/model-tool-provider.test.ts +37 -0
- package/src/modules/usage/model-tool-provider.ts +110 -0
- package/src/modules/usage/model-tools.test.ts +36 -0
- package/src/modules/usage/model-tools.ts +62 -0
- package/src/modules/usage/period-allowance.mysql.test.ts +97 -0
- package/src/modules/usage/period.test.ts +26 -0
- package/src/modules/usage/period.ts +96 -0
- package/src/modules/usage/pricing.test.ts +178 -0
- package/src/modules/usage/pricing.ts +228 -0
- package/src/modules/usage/provider-failure.ts +37 -0
- package/src/modules/usage/provider-stream.test.ts +85 -0
- package/src/modules/usage/provider-stream.ts +77 -0
- package/src/modules/usage/provider.test.ts +67 -0
- package/src/modules/usage/provider.ts +142 -0
- package/src/modules/usage/repository.ts +539 -0
- package/src/modules/usage/service-availability.mysql.test.ts +68 -0
- package/src/modules/usage/service-availability.ts +13 -0
- package/src/modules/usage/service-delete.mysql.test.ts +87 -0
- package/src/modules/usage/stream-http.ts +32 -0
- package/src/modules/usage/test-harness.ts +108 -0
- package/src/modules/usage/usage-deletion.mysql.test.ts +312 -0
- package/src/modules/usage/usage-deletion.ts +119 -0
- package/src/modules/usage/validation.test.ts +18 -0
- package/src/modules/usage/validation.ts +33 -0
- package/src/routes/admin-agent-tasks.ts +32 -0
- package/src/routes/admin-billing-usage.ts +73 -0
- package/src/routes/admin-tool-providers.test.ts +22 -0
- package/src/routes/admin-tool-providers.ts +9 -1
- package/src/routes/admin-usage.ts +147 -0
- package/src/routes/admin.ts +7 -0
- package/src/routes/agent-api.test.ts +76 -0
- package/src/routes/agent-api.ts +42 -1
- package/src/routes/agent-artifacts.ts +29 -0
- package/src/routes/agent-task-control-http-mysql.test.ts +246 -0
- package/src/routes/private.ts +9 -0
- package/src/routes/run.ts +2 -1
- package/src/test-support/agent-task-control-mysql-fixture.ts +75 -0
- package/web/connect/bailing-connect-php7.tgz +0 -0
- package/web/console/assets/Accounts-Bervi5JU.css +1 -0
- package/web/console/assets/Accounts-DnddhY6t.js +3 -0
- package/web/console/assets/AgentClients-VInbD7JS.js +1 -0
- package/web/console/assets/AgentClients-i52AI6YV.css +1 -0
- package/web/console/assets/AgentTasks-B-1XklBg.js +2 -0
- package/web/console/assets/AgentTasks-BsG850Il.css +1 -0
- package/web/console/assets/{Approvals-Bs6FGbp2.js → Approvals-34qUPHf0.js} +1 -1
- package/web/console/assets/{Audit-4WWYhkFM.js → Audit-BbVgkSm2.js} +1 -1
- package/web/console/assets/{BrandLockup-D2GhCipL.js → BrandLockup-DgscF28e.js} +1 -1
- package/web/console/assets/{Channels-CmoGpiCJ.js → Channels-Bp-yuk8d.js} +1 -1
- package/web/console/assets/{ChatEntries-BFRMtwta.js → ChatEntries-C9Ft60TS.js} +1 -1
- package/web/console/assets/{Clients-DGkkSXyA.js → Clients-NPldD-DD.js} +1 -1
- package/web/console/assets/{Cost-BmGt0MfS.js → Cost-DZcuB-EB.js} +1 -1
- package/web/console/assets/{Credentials-CR-sYINT.js → Credentials-RTT7N6zl.js} +1 -1
- package/web/console/assets/{Diagnostics-DAPbKSJp.js → Diagnostics-_LeK8cce.js} +1 -1
- package/web/console/assets/{Executors-CgpiT3o8.js → Executors-Bi7H8rIm.js} +1 -1
- package/web/console/assets/{HelpTip-i-KJhf5s.js → HelpTip-BfyWrxCE.js} +1 -1
- package/web/console/assets/{Kb-Cm9dVSQw.js → Kb-BHamz8NP.js} +2 -2
- package/web/console/assets/{Login-CyUcsTZ_.js → Login-C1rJR-6w.js} +1 -1
- package/web/console/assets/{Projects-DldFPgWg.js → Projects-BRA4a48v.js} +1 -1
- package/web/console/assets/Routes-CTC7U-fQ.js +124 -0
- package/web/console/assets/Routes-CyXV4Pba.css +1 -0
- package/web/console/assets/{Runs-1hxgkuR4.js → Runs-B_fa_BlD.js} +1 -1
- package/web/console/assets/{Setup-DBLOnI2_.js → Setup-C1_d0mFy.js} +1 -1
- package/web/console/assets/Shell-CHEV6RGC.js +1 -0
- package/web/console/assets/Shell-ykb-tUfo.css +1 -0
- package/web/console/assets/StorageBuckets-CVgpZRWY.css +1 -0
- package/web/console/assets/StorageBuckets-DlG3ojhA.js +1 -0
- package/web/console/assets/{SystemSettings-cDkudo2y.js → SystemSettings-DYo2gg6d.js} +1 -1
- package/web/console/assets/{SystemStatus-DZd6s8OX.js → SystemStatus-DKCoUZlq.js} +1 -1
- package/web/console/assets/{Targets-DYNGq1NU.js → Targets-CdkG6BPR.js} +1 -1
- package/web/console/assets/Tools-DU8ei6sd.css +1 -0
- package/web/console/assets/Tools-DVpCt0ox.js +2 -0
- package/web/console/assets/Usage-CAeDGjrb.css +1 -0
- package/web/console/assets/Usage-DWCpLugC.js +1 -0
- package/web/console/assets/UsageAccess-B_Xq7ARW.js +1 -0
- package/web/console/assets/UsageAccess-CGGaWTuj.css +1 -0
- package/web/console/assets/UsageHelp-CSM4xO0K.css +1 -0
- package/web/console/assets/UsageHelp-t5ZG_f-e.js +1 -0
- package/web/console/assets/{index-QnmD7N7F.js → index-C6W4LWVV.js} +1 -1
- package/web/console/assets/{index-Fi9gkGxV.css → index-Cxuc9OCj.css} +1 -1
- package/web/console/assets/index-H1kfa0Mj.js +2 -0
- package/web/console/assets/{request-B7MLvOqo.js → request-DLsP1_ot.js} +1 -1
- package/web/console/assets/{schema-CMuwjYdJ.js → schema-BLOHvAJQ.js} +1 -1
- package/web/console/assets/{util-4bN2dv7B.js → util-CGVh2Jvr.js} +1 -1
- package/web/console/assets/{vendor-element-CZoEjZr8.js → vendor-element-BD089KxE.js} +1 -1
- package/web/console/assets/{vendor-mammoth-BUEEDX6A.js → vendor-mammoth-Bv-CZhmH.js} +1 -1
- package/web/console/index.html +3 -3
- package/web-admin/README.md +17 -0
- package/web-admin/scripts/agent-task-control-smoke.mjs +120 -0
- package/web-admin/src/components/AgentSetupPanel.vue +13 -0
- package/web-admin/src/components/ToolRateLimitEditor.vue +28 -0
- package/web-admin/src/components/UsageDeletionPreview.vue +44 -0
- package/web-admin/src/components/UsageHelp.vue +72 -0
- package/web-admin/src/components/UsageServiceReferences.vue +169 -0
- package/web-admin/src/layout/Shell.vue +23 -6
- package/web-admin/src/pages/Accounts.vue +3 -3
- package/web-admin/src/pages/AgentClients.vue +3 -1
- package/web-admin/src/pages/AgentTasks.vue +281 -0
- package/web-admin/src/pages/Routes.vue +5 -1
- package/web-admin/src/pages/StorageBuckets.vue +6 -6
- package/web-admin/src/pages/Tools.vue +53 -4
- package/web-admin/src/pages/Usage.vue +2470 -0
- package/web-admin/src/pages/UsageAccess.vue +1147 -0
- package/web-admin/src/router.ts +10 -4
- package/web-admin/src/styles/base.css +57 -0
- package/web-admin/src/table-widths.ts +16 -1
- package/web-admin/src/usage-deletion.ts +40 -0
- package/web-admin/src/usage-management.ts +13 -0
- package/web-admin/src/usage-presentation.test.ts +21 -0
- package/web-admin/src/usage-presentation.ts +107 -0
- package/web-admin/src/usage-price-preview.test.ts +60 -0
- package/web-admin/src/usage-price-preview.ts +54 -0
- package/web-admin/tests/token-usage.browser.mjs +773 -0
- package/web-admin/tests/usage-access.browser.mjs +398 -0
- package/web/console/assets/Accounts-B4ePH5jp.css +0 -1
- package/web/console/assets/Accounts-ChL9k-XA.js +0 -3
- package/web/console/assets/AgentClients-Bs7UgVDj.js +0 -1
- package/web/console/assets/AgentClients-DkgPTEbq.css +0 -1
- package/web/console/assets/Routes-DkMIjMQA.css +0 -1
- package/web/console/assets/Routes-DubfjlBD.js +0 -124
- package/web/console/assets/Shell-D9Uw-fsa.css +0 -1
- package/web/console/assets/Shell-gJ5Vz_E7.js +0 -1
- package/web/console/assets/StorageBuckets-DkDW16tj.js +0 -1
- package/web/console/assets/StorageBuckets-GnXnVvF0.css +0 -1
- package/web/console/assets/Tools-A20oaMaQ.css +0 -1
- package/web/console/assets/Tools-DpWM59vV.js +0 -2
- package/web/console/assets/index-DGqs28gI.js +0 -2
|
@@ -0,0 +1,2470 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-card class="billing-page" shadow="never">
|
|
3
|
+
<template #header>
|
|
4
|
+
<div class="page-heading">
|
|
5
|
+
<div class="page-title">
|
|
6
|
+
<b>用户与用量</b>
|
|
7
|
+
<UsageHelp title="用户与用量说明">
|
|
8
|
+
<p v-if="editing">编辑套餐时,左侧配置模型、倍率与额度,右侧预览用户看到的套餐。返回箭头回到套餐列表,保存后配置才会生效。</p>
|
|
9
|
+
<p>套餐售价与周期额度分别填写:额度包一次获得与售价等额的消费额度;周期套餐每次重置为指定周期额度,不按售价自动平分。实际用量按绑定的 OpenRouter 参考价格计算,再乘套餐统一倍率。支付、开通与汇率由业务侧处理。</p>
|
|
10
|
+
<p>计费模型选填:留空按调用模型标识精确匹配 OpenRouter,填写后优先使用指定标识;不改变模型调用地址或凭证。多个参考端点需明确选择。</p>
|
|
11
|
+
<p>周期套餐按每周期额度估算,额度包按整包额度估算。每个模型均假设独占该额度,已计入统一倍率,不平均分配、不可相加。对话按输入∶输出 3∶1、未命中缓存估算,实际按真实用量结算;图片按报价档位展示。</p>
|
|
12
|
+
<p>参考价格不代表实际供应商账单;模型调用仍使用已配置凭证。每笔请求保存价格与倍率快照,不重算历史费用。参考价格未知时不能按免费处理。</p>
|
|
13
|
+
<p>周期按开通时间起算;未用完不累积,最后不足一个周期仍发放完整周期额度,但到套餐到期即失效。售价不代表供应商成本或保证利润。</p>
|
|
14
|
+
<p>额度包显示积分(1 美元额度 = 1,000 积分);周期套餐显示本期剩余百分比。Token 保留为原始用量,不用于余额和百分比。未取得可信用量时显示待计量。</p>
|
|
15
|
+
<p>模型工具由客户端注册和编排。图片适配可执行;未适配的视频、语音等仅可保存声明,不会假装可调用。</p>
|
|
16
|
+
<p>移除套餐只检查启用账户当前有效或待生效的开通;已替换、已到期或已停用的关联不阻止删除。删除后保留历史请求与账本,不恢复原套餐。额度耗尽只阻止新请求,已接纳的回复正常完成。</p>
|
|
17
|
+
</UsageHelp>
|
|
18
|
+
</div>
|
|
19
|
+
<div class="actions">
|
|
20
|
+
<router-link to="/usage-access"
|
|
21
|
+
><el-button>接入设置</el-button></router-link
|
|
22
|
+
><el-button :loading="loading" @click="load">刷新</el-button>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
<el-alert
|
|
27
|
+
v-if="error"
|
|
28
|
+
:title="error"
|
|
29
|
+
type="error"
|
|
30
|
+
:closable="false"
|
|
31
|
+
show-icon
|
|
32
|
+
/>
|
|
33
|
+
<el-alert
|
|
34
|
+
v-if="!loading && !supported"
|
|
35
|
+
title="用量套餐尚未就绪。请检查当前版本与迁移。账户与身份来源可在“接入设置”中管理。"
|
|
36
|
+
type="info"
|
|
37
|
+
:closable="false"
|
|
38
|
+
show-icon
|
|
39
|
+
/>
|
|
40
|
+
<div v-if="pending" class="pending panel">
|
|
41
|
+
<b>上一次保存需要核对</b>
|
|
42
|
+
<p>
|
|
43
|
+
已保留原请求。网络恢复后可核对原结果,避免重复开通;核对完成前暂停其他配置变更。
|
|
44
|
+
</p>
|
|
45
|
+
<el-button
|
|
46
|
+
:loading="saving"
|
|
47
|
+
:disabled="pendingNeedsBilling"
|
|
48
|
+
type="primary"
|
|
49
|
+
@click="retryPending"
|
|
50
|
+
>核对 / 重试原请求</el-button
|
|
51
|
+
>
|
|
52
|
+
</div>
|
|
53
|
+
<div class="console-page-tabs">
|
|
54
|
+
<div class="console-page-tabs-actions">
|
|
55
|
+
<template v-if="tab === 'models'">
|
|
56
|
+
<router-link v-if="me.can('credentials:read')" to="/credentials"><el-button>管理模型凭证</el-button></router-link>
|
|
57
|
+
<el-button v-if="canIssuers" :disabled="blocked" type="primary" @click="openService()">添加模型服务</el-button>
|
|
58
|
+
</template>
|
|
59
|
+
<el-button v-else-if="tab === 'plans' && !editing && canWrite" type="primary" :disabled="blocked" @click="openPlan()">新建套餐</el-button>
|
|
60
|
+
<router-link v-else-if="tab === 'accounts'" to="/usage-access?tab=accounts"><el-button>管理账户与成员</el-button></router-link>
|
|
61
|
+
</div>
|
|
62
|
+
<el-tabs v-model="tab" class="section-tabs">
|
|
63
|
+
<el-tab-pane label="模型服务" name="models">
|
|
64
|
+
<div v-if="services.length" class="model-grid">
|
|
65
|
+
<article
|
|
66
|
+
v-for="service in services"
|
|
67
|
+
:key="service.id"
|
|
68
|
+
class="panel model-card"
|
|
69
|
+
>
|
|
70
|
+
<div class="card-top">
|
|
71
|
+
<h3>{{ service.label }}</h3>
|
|
72
|
+
<el-tag
|
|
73
|
+
:type="serviceReady(service) ? 'success' : service.state === 'suspended' ? 'info' : 'warning'"
|
|
74
|
+
effect="plain"
|
|
75
|
+
>{{ serviceReady(service) ? "可选用" : service.state === "suspended" ? "已停用" : "未就绪" }}</el-tag
|
|
76
|
+
>
|
|
77
|
+
</div>
|
|
78
|
+
<el-tag effect="plain">{{ purposeOf(service) === "tool" ? "模型工具" : "对话模型" }}</el-tag>
|
|
79
|
+
<code>{{ service.config.model }}</code>
|
|
80
|
+
<p class="muted">
|
|
81
|
+
凭证:{{ service.config.credential }}<br />模型服务:{{
|
|
82
|
+
service.id
|
|
83
|
+
}}
|
|
84
|
+
</p>
|
|
85
|
+
<p v-if="!serviceReady(service)" class="service-warning">{{ serviceUnavailableReason(service) }}</p>
|
|
86
|
+
<div class="card-bottom">
|
|
87
|
+
<el-button
|
|
88
|
+
v-if="canIssuers"
|
|
89
|
+
link
|
|
90
|
+
type="primary"
|
|
91
|
+
:disabled="blocked"
|
|
92
|
+
@click="openService(service)"
|
|
93
|
+
>{{ serviceConfigurationLabel(service) }}</el-button
|
|
94
|
+
>
|
|
95
|
+
<el-button
|
|
96
|
+
v-if="canIssuers"
|
|
97
|
+
link
|
|
98
|
+
type="danger"
|
|
99
|
+
:disabled="blocked"
|
|
100
|
+
@click="deleteService(service)"
|
|
101
|
+
>删除</el-button
|
|
102
|
+
>
|
|
103
|
+
</div>
|
|
104
|
+
</article>
|
|
105
|
+
</div>
|
|
106
|
+
<el-empty
|
|
107
|
+
v-else
|
|
108
|
+
description="还没有模型服务。先配置模型凭证,再添加供套餐使用的模型。"
|
|
109
|
+
/>
|
|
110
|
+
</el-tab-pane>
|
|
111
|
+
|
|
112
|
+
<el-tab-pane label="套餐管理" name="plans" :disabled="!supported">
|
|
113
|
+
<template v-if="!editing">
|
|
114
|
+
<el-table :data="plans" row-key="id"
|
|
115
|
+
><el-table-column label="套餐" min-width="205"
|
|
116
|
+
><template #default="{ row }"
|
|
117
|
+
><b>{{ row.label }}</b>
|
|
118
|
+
<div class="muted">
|
|
119
|
+
{{ row.config.mode === "periodic" ? "周期套餐" : "额度包" }} ·
|
|
120
|
+
{{ row.state === "active" ? "可开通" : "暂停开通" }}
|
|
121
|
+
</div></template
|
|
122
|
+
></el-table-column
|
|
123
|
+
>
|
|
124
|
+
<el-table-column label="所见额度" min-width="210">
|
|
125
|
+
<template #default="{ row }">
|
|
126
|
+
<b
|
|
127
|
+
>{{ row.config.mode === "periodic" ? "剩余 " : ""
|
|
128
|
+
}}{{ presentationAmount(previewPresentation(row.config)) }}
|
|
129
|
+
{{ presentationUnit(previewPresentation(row.config)) }}</b
|
|
130
|
+
>
|
|
131
|
+
<div class="muted">
|
|
132
|
+
{{
|
|
133
|
+
row.config.mode === "periodic"
|
|
134
|
+
? periodText(row.config.periodUnit) + "重置"
|
|
135
|
+
: "一次发放,用完为止"
|
|
136
|
+
}}
|
|
137
|
+
</div>
|
|
138
|
+
</template>
|
|
139
|
+
</el-table-column>
|
|
140
|
+
<el-table-column label="套餐售价" min-width="170"
|
|
141
|
+
><template #default="{ row }">{{
|
|
142
|
+
usd(row.config.priceUsd)
|
|
143
|
+
}}<div v-if="row.config.mode === 'periodic'" class="muted">周期额度 {{ row.config.periodAllowanceUsd ? usd(row.config.periodAllowanceUsd) : '待配置' }}</div></template></el-table-column
|
|
144
|
+
><el-table-column label="统一倍率" width="100"><template #default="{row}">{{ row.config.multiplier }}×</template></el-table-column><el-table-column label="有效期" min-width="140"
|
|
145
|
+
><template #default="{ row }">{{
|
|
146
|
+
durationText(row.config)
|
|
147
|
+
}}</template></el-table-column
|
|
148
|
+
><el-table-column label="可用模型" min-width="170"
|
|
149
|
+
><template #default="{ row }"
|
|
150
|
+
><div v-for="id in row.config.serviceIds" :key="id">
|
|
151
|
+
{{ serviceLabel(id) }}
|
|
152
|
+
</div>
|
|
153
|
+
<span v-if="!row.config.serviceIds.length" class="muted"
|
|
154
|
+
>暂无可用模型或工具</span
|
|
155
|
+
></template
|
|
156
|
+
></el-table-column
|
|
157
|
+
><el-table-column label="操作" width="235" align="right" fixed="right"
|
|
158
|
+
><template #default="{ row }"
|
|
159
|
+
><el-button
|
|
160
|
+
v-if="canWrite"
|
|
161
|
+
link
|
|
162
|
+
type="primary"
|
|
163
|
+
:disabled="blocked"
|
|
164
|
+
@click="openPlan(row)"
|
|
165
|
+
>编辑</el-button
|
|
166
|
+
><el-button
|
|
167
|
+
v-if="canAdjust"
|
|
168
|
+
link
|
|
169
|
+
type="primary"
|
|
170
|
+
:disabled="blocked || row.state !== 'active'"
|
|
171
|
+
@click="openGrant(undefined, row.id)"
|
|
172
|
+
>开通给账户</el-button
|
|
173
|
+
><el-button v-if="canWrite" link type="danger" :disabled="blocked" @click="deletePlan(row)">删除</el-button></template
|
|
174
|
+
></el-table-column
|
|
175
|
+
><template #empty
|
|
176
|
+
>还没有 用量套餐。新建套餐后,再为指定账户开通。</template
|
|
177
|
+
></el-table
|
|
178
|
+
>
|
|
179
|
+
</template>
|
|
180
|
+
<template v-else>
|
|
181
|
+
<div class="plan-editor-heading">
|
|
182
|
+
<el-button :icon="ArrowLeft" circle aria-label="返回套餐列表" title="返回套餐列表" @click="editing = false" />
|
|
183
|
+
<h2>{{ form.revision ? "编辑套餐" : "新建套餐" }}</h2>
|
|
184
|
+
</div>
|
|
185
|
+
<div v-if="!billingReady" class="billing-notice">
|
|
186
|
+
<el-alert
|
|
187
|
+
:title="billingWarning"
|
|
188
|
+
type="warning"
|
|
189
|
+
:closable="false"
|
|
190
|
+
/>
|
|
191
|
+
</div>
|
|
192
|
+
<div class="editor-layout">
|
|
193
|
+
<el-form
|
|
194
|
+
novalidate
|
|
195
|
+
class="plan-form" size="default"
|
|
196
|
+
label-position="top"
|
|
197
|
+
:disabled="blocked || !canWrite"
|
|
198
|
+
@submit.prevent="savePlan"
|
|
199
|
+
>
|
|
200
|
+
<section class="panel form-section plan-settings">
|
|
201
|
+
<div class="form-grid plan-settings-grid">
|
|
202
|
+
<el-form-item label="套餐名称"><el-input v-model="form.label" maxlength="120" placeholder="例如:标准套餐" /></el-form-item>
|
|
203
|
+
<el-form-item label="套餐类型"><el-select v-model="form.mode"><el-option value="credits" label="额度包 · 显示积分"/><el-option value="periodic" label="周期套餐 · 显示百分比"/></el-select></el-form-item>
|
|
204
|
+
<el-form-item label="套餐售价(USD)"><el-input-number v-model="form.priceUsd" :min="0.01" :max="1000000" :precision="2" :controls="false" /></el-form-item>
|
|
205
|
+
<el-form-item label="统一计费倍率"><el-input-number v-model="form.multiplier" :min="0.000001" :max="1000" :precision="6" :controls="false" /></el-form-item>
|
|
206
|
+
<el-form-item v-if="form.mode === 'periodic'" label="重置周期"><el-select v-model="form.periodUnit"><el-option label="每天" value="day"/><el-option label="每周" value="week"/><el-option label="每月" value="month"/></el-select></el-form-item>
|
|
207
|
+
<el-form-item v-if="form.mode === 'periodic'" label="周期额度(USD)"><el-input-number v-model="form.periodAllowanceUsd" :min="0.01" :max="1000000" :precision="2" :controls="false" placeholder="每个周期可用的额度" /></el-form-item>
|
|
208
|
+
<el-form-item label="有效期"><div class="duration-field"><el-input-number v-if="form.durationUnit !== 'forever'" v-model="form.durationCount" :min="1" :max="1200" :precision="0" :controls="false"/><el-select v-model="form.durationUnit"><el-option label="个月" value="month"/><el-option label="天" value="day"/><el-option v-if="form.mode === 'credits'" label="持续有效" value="forever"/></el-select></div></el-form-item>
|
|
209
|
+
</div>
|
|
210
|
+
</section>
|
|
211
|
+
<section v-for="group in serviceGroups" :key="group.purpose" class="panel form-section">
|
|
212
|
+
<h3>{{ group.label }}<span class="model-estimate-heading">{{ estimateHeading }}</span></h3>
|
|
213
|
+
<el-checkbox-group v-model="form.serviceIds" class="model-choices">
|
|
214
|
+
<div v-for="service in services.filter(s => purposeOf(s) === group.purpose)" :key="service.id" class="model-choice-row">
|
|
215
|
+
<el-checkbox :value="service.id" :disabled="!serviceReady(service) && !form.serviceIds.includes(service.id)"><span><b>{{ service.label }}</b><small>{{ service.config.model }}</small><small v-if="!serviceReady(service)" class="service-warning">{{ form.serviceIds.includes(service.id) ? '已选服务暂不可用:' : '' }}{{ serviceUnavailableReason(service) }}</small></span></el-checkbox>
|
|
216
|
+
<div class="model-estimate">
|
|
217
|
+
<template v-if="planEstimates(service).length">
|
|
218
|
+
<div v-for="(estimate,i) in planEstimates(service)" :key="i" class="estimate-scenario"><small>{{ estimate.label }} · {{ estimate.prices }}</small><strong>{{ estimate.estimate }}</strong><small>{{ estimate.assumption }}</small></div>
|
|
219
|
+
<small class="quote-source">OpenRouter · {{ service.reference_price?.modelId }} · {{ service.reference_price?.endpointId }} · {{ time(service.reference_price?.fetchedAt || 0) }}{{ quoteStale(service) ? ' · 缓存报价,待更新' : '' }}</small>
|
|
220
|
+
</template>
|
|
221
|
+
<span v-else class="muted">{{ !estimateBudget ? '请先填写有效额度' : service.config.pricing ? '未取得可用参考价格,暂无法估算' : '尚未配置参考价格,暂无法估算' }}</span>
|
|
222
|
+
</div>
|
|
223
|
+
<el-button v-if="!serviceReady(service) && canIssuers" link type="primary" :disabled="blocked" @click="openService(service)">{{ serviceConfigurationLabel(service) }}</el-button>
|
|
224
|
+
</div>
|
|
225
|
+
</el-checkbox-group>
|
|
226
|
+
<p v-if="!services.some(s => purposeOf(s) === group.purpose)" class="muted">尚未添加{{ group.label }}</p>
|
|
227
|
+
</section>
|
|
228
|
+
<el-alert v-if="form.mode === 'periodic' && !periodAllowanceSupported" title="当前为周期额度预览,配套计费版本启用后可保存。" type="info" :closable="false" />
|
|
229
|
+
<el-alert v-if="!form.serviceIds.length" title="未选择服务时,客户端显示暂无可用模型或工具。" type="info" :closable="false" />
|
|
230
|
+
<section class="panel form-section advanced">
|
|
231
|
+
<details>
|
|
232
|
+
<summary>
|
|
233
|
+
更多选项 <span class="muted">开通状态</span>
|
|
234
|
+
</summary>
|
|
235
|
+
<div class="advanced-content">
|
|
236
|
+
<el-form-item label="是否允许新开通"
|
|
237
|
+
><el-switch
|
|
238
|
+
v-model="form.active"
|
|
239
|
+
active-text="允许开通"
|
|
240
|
+
inactive-text="暂停开通"
|
|
241
|
+
/></el-form-item>
|
|
242
|
+
<p class="muted">
|
|
243
|
+
暂停开通不影响已有账户。模型列表更新即时生效,额度与有效期配置只用于以后开通。
|
|
244
|
+
</p>
|
|
245
|
+
</div>
|
|
246
|
+
</details>
|
|
247
|
+
</section>
|
|
248
|
+
<el-alert
|
|
249
|
+
v-if="formError"
|
|
250
|
+
:title="formError"
|
|
251
|
+
type="error"
|
|
252
|
+
:closable="false"
|
|
253
|
+
show-icon
|
|
254
|
+
/>
|
|
255
|
+
<div class="form-footer">
|
|
256
|
+
<span class="muted"
|
|
257
|
+
>保存模型列表后,已有账户刷新即可看到;新账户仍需开通套餐。</span
|
|
258
|
+
><el-button
|
|
259
|
+
type="primary"
|
|
260
|
+
native-type="submit"
|
|
261
|
+
:loading="saving"
|
|
262
|
+
:disabled="!billingReady || (form.mode === 'periodic' && !periodAllowanceSupported)"
|
|
263
|
+
>保存套餐</el-button
|
|
264
|
+
>
|
|
265
|
+
</div>
|
|
266
|
+
</el-form>
|
|
267
|
+
<aside class="preview panel">
|
|
268
|
+
<div class="preview-eyebrow">用户侧说明预览</div>
|
|
269
|
+
<h3>{{ form.label || "未命名套餐" }}</h3>
|
|
270
|
+
<p class="muted">
|
|
271
|
+
{{ form.mode === "periodic" ? "本期剩余" : "可用积分" }}
|
|
272
|
+
</p>
|
|
273
|
+
<div class="preview-amount">
|
|
274
|
+
{{ presentationAmount(planPresentation)
|
|
275
|
+
}}<small>{{ presentationUnit(planPresentation) }}</small>
|
|
276
|
+
</div>
|
|
277
|
+
<p class="preview-unit">
|
|
278
|
+
{{
|
|
279
|
+
planPresentation.state === "unavailable"
|
|
280
|
+
? "请填写有效额度"
|
|
281
|
+
: form.mode === "periodic"
|
|
282
|
+
? "开通后每期恢复至 100%"
|
|
283
|
+
: "开通后一次到账"
|
|
284
|
+
}}
|
|
285
|
+
</p>
|
|
286
|
+
<div class="preview-rule">
|
|
287
|
+
<span>有效期</span><b>{{ durationText(previewConfig) }}</b>
|
|
288
|
+
</div>
|
|
289
|
+
<div class="preview-rule">
|
|
290
|
+
<span>额度更新</span
|
|
291
|
+
><b>{{
|
|
292
|
+
form.mode === "periodic"
|
|
293
|
+
? periodText(form.periodUnit) + "重置"
|
|
294
|
+
: "一次发放"
|
|
295
|
+
}}</b>
|
|
296
|
+
</div>
|
|
297
|
+
<div class="preview-models">
|
|
298
|
+
<span class="muted">可用模型</span>
|
|
299
|
+
<div class="tags">
|
|
300
|
+
<el-tag
|
|
301
|
+
v-for="id in form.serviceIds"
|
|
302
|
+
:key="id"
|
|
303
|
+
effect="plain"
|
|
304
|
+
>{{ serviceLabel(id) }}</el-tag
|
|
305
|
+
><span v-if="!form.serviceIds.length" class="muted"
|
|
306
|
+
>暂无可用模型或工具</span
|
|
307
|
+
>
|
|
308
|
+
</div>
|
|
309
|
+
</div>
|
|
310
|
+
<ul>
|
|
311
|
+
<li>按参考费用乘套餐统一倍率扣除。</li>
|
|
312
|
+
<li>所有对话模型与工具共用一份额度。</li>
|
|
313
|
+
<li>当前模型回复完成后,额度不足再停止新请求。</li>
|
|
314
|
+
</ul>
|
|
315
|
+
<p class="preview-note">
|
|
316
|
+
用量可能稍晚更新,允许少量超出。{{
|
|
317
|
+
form.mode === "periodic"
|
|
318
|
+
? "本期剩余额度不累积到下一期。"
|
|
319
|
+
: "未用积分在套餐有效期内可用。"
|
|
320
|
+
}}
|
|
321
|
+
</p>
|
|
322
|
+
</aside>
|
|
323
|
+
</div>
|
|
324
|
+
</template>
|
|
325
|
+
</el-tab-pane>
|
|
326
|
+
|
|
327
|
+
<el-tab-pane label="账户用量" name="accounts" :disabled="!supported">
|
|
328
|
+
<el-table :data="accounts" row-key="id"
|
|
329
|
+
><el-table-column label="账户" min-width="220"
|
|
330
|
+
><template #default="{ row }"
|
|
331
|
+
><el-button link type="primary" @click="openAccount(row)">{{
|
|
332
|
+
row.label
|
|
333
|
+
}}</el-button>
|
|
334
|
+
<div class="muted mono">{{ row.id }}</div></template
|
|
335
|
+
></el-table-column
|
|
336
|
+
><el-table-column label="类型" width="140"
|
|
337
|
+
><template #default="{ row }">{{
|
|
338
|
+
row.kind === "organization" ? "组织共享" : "个人"
|
|
339
|
+
}}</template></el-table-column
|
|
340
|
+
><el-table-column label="状态" width="120"
|
|
341
|
+
><template #default="{ row }"
|
|
342
|
+
><el-tag :type="row.state === 'active' ? 'success' : 'info'">{{
|
|
343
|
+
row.state === "active" ? "可用" : "已停用"
|
|
344
|
+
}}</el-tag></template
|
|
345
|
+
></el-table-column
|
|
346
|
+
><el-table-column label="操作" width="220" align="right" fixed="right"
|
|
347
|
+
><template #default="{ row }"
|
|
348
|
+
><el-button link type="primary" @click="openAccount(row)"
|
|
349
|
+
>查看用量</el-button
|
|
350
|
+
><el-button
|
|
351
|
+
v-if="canAdjust"
|
|
352
|
+
link
|
|
353
|
+
type="primary"
|
|
354
|
+
:disabled="blocked || row.state !== 'active'"
|
|
355
|
+
@click="openGrant(row)"
|
|
356
|
+
>开通 / 更换套餐</el-button
|
|
357
|
+
></template
|
|
358
|
+
></el-table-column
|
|
359
|
+
><template #empty
|
|
360
|
+
>还没有账户。请先配置身份来源,由业务产品完成一次可信登录。</template
|
|
361
|
+
></el-table
|
|
362
|
+
>
|
|
363
|
+
<div v-if="accountCursor" class="more">
|
|
364
|
+
<el-button :loading="accountsLoading" @click="loadAccounts(true)"
|
|
365
|
+
>加载更多账户</el-button
|
|
366
|
+
>
|
|
367
|
+
</div>
|
|
368
|
+
</el-tab-pane>
|
|
369
|
+
</el-tabs>
|
|
370
|
+
</div>
|
|
371
|
+
</el-card>
|
|
372
|
+
|
|
373
|
+
<UsageDeletionPreview v-model="deletion.open.value" :label="deletion.label.value"
|
|
374
|
+
:report="deletion.report.value" :loading="deletion.loading.value" :busy="blocked"
|
|
375
|
+
:error="deletion.error.value"
|
|
376
|
+
@refresh="deletion.refresh" @delete="confirmDeletePlan" />
|
|
377
|
+
<UsageServiceReferences
|
|
378
|
+
v-model="referencesOpen"
|
|
379
|
+
:label="referenceService?.label || ''"
|
|
380
|
+
:report="serviceReferences"
|
|
381
|
+
:loading="referencesLoading"
|
|
382
|
+
:busy="blocked"
|
|
383
|
+
:error="referencesError"
|
|
384
|
+
:can-edit-plans="canWrite"
|
|
385
|
+
@refresh="loadServiceReferences"
|
|
386
|
+
@delete="confirmDeleteService"
|
|
387
|
+
@plan="openReferencePlan"
|
|
388
|
+
/>
|
|
389
|
+
<el-drawer
|
|
390
|
+
v-model="detailOpen"
|
|
391
|
+
:title="selectedAccount?.label || '账户用量'"
|
|
392
|
+
size="min(960px, 96vw)"
|
|
393
|
+
@closed="openDeferredGrant"
|
|
394
|
+
><div class="account-detail" v-loading="detailLoading">
|
|
395
|
+
<el-alert
|
|
396
|
+
v-if="detailError"
|
|
397
|
+
:title="detailError"
|
|
398
|
+
type="error"
|
|
399
|
+
:closable="false"
|
|
400
|
+
/><template v-if="summary"
|
|
401
|
+
><div class="section-heading">
|
|
402
|
+
<div>
|
|
403
|
+
<h2>{{ summary.grant?.label || "尚未开通套餐" }}</h2>
|
|
404
|
+
<p>
|
|
405
|
+
{{
|
|
406
|
+
summary.grant
|
|
407
|
+
? grantStatus(summary)
|
|
408
|
+
: "开通后即可使用套餐内模型。"
|
|
409
|
+
}}
|
|
410
|
+
</p>
|
|
411
|
+
</div>
|
|
412
|
+
<div class="actions">
|
|
413
|
+
<el-button @click="loadDetail">刷新用量</el-button
|
|
414
|
+
><el-button v-if="canAdjust && summary.grant && !externalGrant"
|
|
415
|
+
:disabled="blocked || !billingReady || !canResetAllowance"
|
|
416
|
+
@click="resetAllowance">重置额度</el-button><el-button
|
|
417
|
+
v-if="canAdjust"
|
|
418
|
+
:disabled="blocked || externalGrant"
|
|
419
|
+
type="primary"
|
|
420
|
+
@click="openGrant(selectedAccount || undefined)"
|
|
421
|
+
>{{ summary.grant ? "更换套餐" : "开通套餐" }}</el-button
|
|
422
|
+
>
|
|
423
|
+
</div>
|
|
424
|
+
</div>
|
|
425
|
+
<el-alert
|
|
426
|
+
v-if="summary.grant"
|
|
427
|
+
:type="accountModelIds.length ? 'info' : 'warning'"
|
|
428
|
+
:closable="false"
|
|
429
|
+
:title="
|
|
430
|
+
accountModelIds.length
|
|
431
|
+
? '可用模型跟随套餐更新,共享本账户的剩余额度。'
|
|
432
|
+
: '该套餐暂无可用模型或工具;原额度、重置和到期时间保持不变。'
|
|
433
|
+
"
|
|
434
|
+
:description="`所属套餐:${summary.plan?.label || summary.grant.label} · ${summary.grant.planId}。当前模型:${accountModelIds.map(serviceLabel).join('、') || '暂无可用模型或工具'}。`"
|
|
435
|
+
/>
|
|
436
|
+
<section class="customer-preview panel" aria-label="账户用户可见预览">
|
|
437
|
+
<div class="preview-eyebrow">用户侧用量预览</div>
|
|
438
|
+
<div class="customer-amount-row">
|
|
439
|
+
<div>
|
|
440
|
+
<p class="muted">
|
|
441
|
+
{{
|
|
442
|
+
accountPresentation.kind === "percentage"
|
|
443
|
+
? "本期剩余"
|
|
444
|
+
: accountPresentation.kind === "credits"
|
|
445
|
+
? "可用积分"
|
|
446
|
+
: "当前额度"
|
|
447
|
+
}}
|
|
448
|
+
</p>
|
|
449
|
+
<div class="preview-amount">
|
|
450
|
+
{{ presentationAmount(accountPresentation)
|
|
451
|
+
}}<small>{{ presentationUnit(accountPresentation) }}</small>
|
|
452
|
+
</div>
|
|
453
|
+
</div>
|
|
454
|
+
<el-tag
|
|
455
|
+
:type="
|
|
456
|
+
accountPresentation.state === 'active' ? 'success' : 'info'
|
|
457
|
+
"
|
|
458
|
+
>{{
|
|
459
|
+
summary.grant
|
|
460
|
+
? accountPresentation.state === "active" &&
|
|
461
|
+
!accountModelIds.length
|
|
462
|
+
? "额度保留"
|
|
463
|
+
: presentationState(accountPresentation)
|
|
464
|
+
: "尚未开通"
|
|
465
|
+
}}</el-tag
|
|
466
|
+
>
|
|
467
|
+
</div>
|
|
468
|
+
<el-progress
|
|
469
|
+
v-if="
|
|
470
|
+
accountPresentation.kind === 'percentage' &&
|
|
471
|
+
accountPresentation.remaining !== null
|
|
472
|
+
"
|
|
473
|
+
:percentage="accountPresentation.remaining"
|
|
474
|
+
:show-text="false"
|
|
475
|
+
/>
|
|
476
|
+
<p v-if="summary.pendingRequests > 0" class="muted">
|
|
477
|
+
{{ number(summary.pendingRequests) }}
|
|
478
|
+
笔用量待更新,已完成的回复不受影响。
|
|
479
|
+
</p>
|
|
480
|
+
<p v-if="summary.grant" class="muted">
|
|
481
|
+
{{
|
|
482
|
+
summary.resetAt
|
|
483
|
+
? "下次重置:" + time(summary.resetAt) + " · "
|
|
484
|
+
: ""
|
|
485
|
+
}}{{
|
|
486
|
+
summary.expiresAt
|
|
487
|
+
? "有效期至:" + time(summary.expiresAt)
|
|
488
|
+
: "持续有效"
|
|
489
|
+
}}
|
|
490
|
+
</p>
|
|
491
|
+
<p v-else class="muted">开通套餐后即可查看用量。</p>
|
|
492
|
+
</section>
|
|
493
|
+
<section class="operator-accounting">
|
|
494
|
+
<div class="section-heading">
|
|
495
|
+
<div>
|
|
496
|
+
<h3>运营计量</h3>
|
|
497
|
+
<p>美元消耗与供应商原始用量分别记录。</p>
|
|
498
|
+
</div>
|
|
499
|
+
</div>
|
|
500
|
+
<template v-if="summary.grant">
|
|
501
|
+
<div class="metrics">
|
|
502
|
+
<div>
|
|
503
|
+
<span>剩余额度</span
|
|
504
|
+
><strong>{{ number(summary.availableUsd) }}</strong
|
|
505
|
+
><small>USD</small>
|
|
506
|
+
</div>
|
|
507
|
+
<div>
|
|
508
|
+
<span>{{
|
|
509
|
+
summary.grant.config.mode === "periodic"
|
|
510
|
+
? "本期已用"
|
|
511
|
+
: "已用额度"
|
|
512
|
+
}}</span
|
|
513
|
+
><strong>{{ number(periodConsumed(summary)) }}</strong
|
|
514
|
+
><small>USD</small>
|
|
515
|
+
</div>
|
|
516
|
+
<div>
|
|
517
|
+
<span>待计量请求</span
|
|
518
|
+
><strong>{{ number(summary.pendingRequests) }}</strong
|
|
519
|
+
><small>用量到账后更新</small>
|
|
520
|
+
</div>
|
|
521
|
+
</div>
|
|
522
|
+
|
|
523
|
+
<el-alert
|
|
524
|
+
v-if="summary.overageUsd > 0"
|
|
525
|
+
:title="`当前额度已超出 ${number(summary.overageUsd)} USD。原回复保留,新请求等待下一期额度或新套餐。`"
|
|
526
|
+
type="warning"
|
|
527
|
+
:closable="false"
|
|
528
|
+
/>
|
|
529
|
+
<div class="panel grant-details">
|
|
530
|
+
<div>
|
|
531
|
+
<span>有效期至</span
|
|
532
|
+
><b>{{ time(summary.expiresAt, "持续有效") }}</b>
|
|
533
|
+
</div>
|
|
534
|
+
<div>
|
|
535
|
+
<span>下次重置</span
|
|
536
|
+
><b>{{ time(summary.resetAt, "不重置") }}</b>
|
|
537
|
+
</div>
|
|
538
|
+
<div>
|
|
539
|
+
<span>可用模型</span>
|
|
540
|
+
<div class="account-models">
|
|
541
|
+
<div v-for="id in accountModelIds" :key="id">
|
|
542
|
+
<b>{{ serviceLabel(id) }}</b
|
|
543
|
+
>
|
|
544
|
+
</div>
|
|
545
|
+
<b v-if="!accountModelIds.length">暂无可用模型或工具</b>
|
|
546
|
+
</div>
|
|
547
|
+
</div>
|
|
548
|
+
<p v-if="externalGrant" class="muted">
|
|
549
|
+
此套餐由业务后端维护,请在原来源调整;这里保留用量与状态查询。
|
|
550
|
+
</p>
|
|
551
|
+
<p v-if="!billingReady" class="muted">
|
|
552
|
+
计费内核尚未就绪,暂不可调整套餐。
|
|
553
|
+
</p>
|
|
554
|
+
<el-button
|
|
555
|
+
v-if="canAdjust && !externalGrant"
|
|
556
|
+
:disabled="blocked || !billingReady"
|
|
557
|
+
@click="controlGrant"
|
|
558
|
+
>{{
|
|
559
|
+
summary.grant.state === "active" ? "暂停新请求" : "恢复使用"
|
|
560
|
+
}}</el-button
|
|
561
|
+
>
|
|
562
|
+
</div></template
|
|
563
|
+
>
|
|
564
|
+
<div class="section-heading">
|
|
565
|
+
<div>
|
|
566
|
+
<h3>最近的模型请求</h3>
|
|
567
|
+
<p>只读取用量和原请求状态,不重新执行模型或业务操作。</p>
|
|
568
|
+
</div>
|
|
569
|
+
</div>
|
|
570
|
+
<el-alert v-if="!billingReady" title="原请求计量明细在配套计费内核更新后可查看。当前套餐余额与有效期保持不变。" type="info" :closable="false" />
|
|
571
|
+
<el-table v-else :data="requests" row-key="operation_id"
|
|
572
|
+
><el-table-column label="原请求" min-width="190"
|
|
573
|
+
><template #default="{ row }"
|
|
574
|
+
><code>{{ row.operation_id }}</code>
|
|
575
|
+
<div class="muted">
|
|
576
|
+
{{ serviceLabel(row.service_id) }}
|
|
577
|
+
</div></template
|
|
578
|
+
></el-table-column
|
|
579
|
+
><el-table-column label="结果" min-width="120"
|
|
580
|
+
><template #default="{ row }"><el-tooltip v-if="row.error" :content="[row.error.message, row.error.http_status ? 'HTTP ' + row.error.http_status : '', row.error.provider_code || '', row.error.provider_request_id ? '请求号:' + row.error.provider_request_id : ''].filter(Boolean).join(' · ')"><span>{{ resultState(row.result_state) }}</span></el-tooltip><span v-else>{{ resultState(row.result_state) }}</span></template></el-table-column
|
|
581
|
+
><el-table-column label="计量" min-width="130"
|
|
582
|
+
><template #default="{ row }">{{
|
|
583
|
+
row.billing_state === "settled" ? "已结算" : "待计量"
|
|
584
|
+
}}</template></el-table-column
|
|
585
|
+
><el-table-column label="套餐消耗(USD)" min-width="180"
|
|
586
|
+
><template #default="{ row }"
|
|
587
|
+
><b>{{
|
|
588
|
+
row.billed_usd === null ||
|
|
589
|
+
row.billed_usd === undefined
|
|
590
|
+
? "待计量"
|
|
591
|
+
: number(row.billed_usd)
|
|
592
|
+
}}</b>
|
|
593
|
+
<div v-if="row.usage?.inputTokens != null && row.usage?.outputTokens != null" class="muted">
|
|
594
|
+
实际 Token:输入 {{ number(row.usage.inputTokens) }} / 输出
|
|
595
|
+
{{ number(row.usage.outputTokens) }}
|
|
596
|
+
</div>
|
|
597
|
+
<div class="muted">参考费用:{{ row.reference_cost_usd == null ? '待计量' : usd(row.reference_cost_usd) }}</div>
|
|
598
|
+
<div v-if="row.billing_rate" class="muted">统一倍率 × {{ row.billing_rate.multiplier }}</div>
|
|
599
|
+
<div v-if="row.usage?.inputTokens == null || row.usage?.outputTokens == null" class="muted">Token:未提供</div><div v-if="row.raw_usage?.outputImageCount != null" class="muted">输出图片:{{ row.raw_usage.outputImageCount }} 张</div>
|
|
600
|
+
</template
|
|
601
|
+
></el-table-column
|
|
602
|
+
><template #empty>尚无 模型请求。</template></el-table
|
|
603
|
+
>
|
|
604
|
+
<div v-if="requestCursor" class="more">
|
|
605
|
+
<el-button :loading="requestsLoading" @click="loadRequests(true)"
|
|
606
|
+
>加载更多请求</el-button
|
|
607
|
+
>
|
|
608
|
+
</div>
|
|
609
|
+
</section></template
|
|
610
|
+
>
|
|
611
|
+
</div></el-drawer
|
|
612
|
+
>
|
|
613
|
+
|
|
614
|
+
<el-drawer
|
|
615
|
+
v-model="grantOpen"
|
|
616
|
+
title="为账户开通套餐"
|
|
617
|
+
size="min(520px, 100vw)"
|
|
618
|
+
class="usage-config-drawer"
|
|
619
|
+
@closed="returnToAccount"
|
|
620
|
+
:close-on-click-modal="false"
|
|
621
|
+
><el-alert
|
|
622
|
+
v-if="!billingReady"
|
|
623
|
+
:title="billingWarning"
|
|
624
|
+
type="warning"
|
|
625
|
+
:closable="false"
|
|
626
|
+
class="template-note"
|
|
627
|
+
/><el-form
|
|
628
|
+
size="default"
|
|
629
|
+
novalidate
|
|
630
|
+
label-position="top"
|
|
631
|
+
:disabled="blocked || grantLoading"
|
|
632
|
+
@submit.prevent="grant"
|
|
633
|
+
><el-form-item label="用量账户"
|
|
634
|
+
><el-select
|
|
635
|
+
v-model="grantAccountId"
|
|
636
|
+
filterable
|
|
637
|
+
placeholder="选择已有账户"
|
|
638
|
+
@change="loadGrantSummary"
|
|
639
|
+
><el-option
|
|
640
|
+
v-for="account in accounts"
|
|
641
|
+
:key="account.id"
|
|
642
|
+
:value="account.id"
|
|
643
|
+
:label="account.label"
|
|
644
|
+
:disabled="account.state !== 'active'" /></el-select
|
|
645
|
+
><el-button
|
|
646
|
+
v-if="accountCursor"
|
|
647
|
+
link
|
|
648
|
+
:loading="accountsLoading"
|
|
649
|
+
@click="loadAccounts(true)"
|
|
650
|
+
>加载更多账户</el-button
|
|
651
|
+
></el-form-item
|
|
652
|
+
><el-form-item label="套餐"
|
|
653
|
+
><el-select v-model="grantPlanId" placeholder="选择套餐"
|
|
654
|
+
><el-option
|
|
655
|
+
v-for="plan in plans.filter((p) => p.state === 'active')"
|
|
656
|
+
:key="plan.id"
|
|
657
|
+
:value="plan.id"
|
|
658
|
+
:label="plan.label" /></el-select
|
|
659
|
+
></el-form-item>
|
|
660
|
+
<div v-if="grantPlan" class="grant-preview panel">
|
|
661
|
+
<b>{{ grantPlan.label }}</b>
|
|
662
|
+
<p>
|
|
663
|
+
{{ grantPlan.config.mode === "periodic" ? "剩余 " : ""
|
|
664
|
+
}}{{ presentationAmount(previewPresentation(grantPlan.config)) }}
|
|
665
|
+
{{ presentationUnit(previewPresentation(grantPlan.config)) }} ·
|
|
666
|
+
{{
|
|
667
|
+
grantPlan.config.mode === "periodic"
|
|
668
|
+
? periodText(grantPlan.config.periodUnit) + "重置"
|
|
669
|
+
: "一次发放"
|
|
670
|
+
}}
|
|
671
|
+
· {{ durationText(grantPlan.config) }}
|
|
672
|
+
</p>
|
|
673
|
+
<p class="muted">
|
|
674
|
+
{{ grantPlan.config.serviceIds.map(serviceLabel).join("、") }}
|
|
675
|
+
</p>
|
|
676
|
+
</div>
|
|
677
|
+
<el-alert
|
|
678
|
+
v-if="grantError"
|
|
679
|
+
:title="grantError"
|
|
680
|
+
type="error"
|
|
681
|
+
:closable="false"
|
|
682
|
+
/><el-alert
|
|
683
|
+
v-else-if="grantSummary?.grant"
|
|
684
|
+
:title="`将替换当前的“${grantSummary.grant.label}”,从现在开始获得一份新额度。原余额不结转;原请求仍归原账。`"
|
|
685
|
+
type="warning"
|
|
686
|
+
:closable="false"
|
|
687
|
+
/>
|
|
688
|
+
<p class="muted">
|
|
689
|
+
本次操作从开通时刻发放一份新额度,不收款,也不改变业务授权。
|
|
690
|
+
</p>
|
|
691
|
+
</el-form>
|
|
692
|
+
<template #footer
|
|
693
|
+
><div class="drawer-actions">
|
|
694
|
+
<el-button @click="grantOpen = false">取消</el-button>
|
|
695
|
+
<el-button
|
|
696
|
+
type="primary"
|
|
697
|
+
:loading="saving"
|
|
698
|
+
:disabled="
|
|
699
|
+
blocked ||
|
|
700
|
+
grantLoading ||
|
|
701
|
+
!canAdjust ||
|
|
702
|
+
!billingReady ||
|
|
703
|
+
!grantSummary ||
|
|
704
|
+
!!grantError ||
|
|
705
|
+
!grantPlan
|
|
706
|
+
"
|
|
707
|
+
@click="grant"
|
|
708
|
+
>确认开通</el-button
|
|
709
|
+
>
|
|
710
|
+
</div></template
|
|
711
|
+
>
|
|
712
|
+
</el-drawer>
|
|
713
|
+
|
|
714
|
+
<el-drawer
|
|
715
|
+
v-model="serviceOpen"
|
|
716
|
+
:title="serviceRevision ? '配置模型服务' : '添加模型服务'"
|
|
717
|
+
size="min(540px, 100vw)"
|
|
718
|
+
class="usage-config-drawer"
|
|
719
|
+
:close-on-click-modal="false"
|
|
720
|
+
><el-form
|
|
721
|
+
size="default"
|
|
722
|
+
novalidate
|
|
723
|
+
label-position="top"
|
|
724
|
+
:disabled="blocked"
|
|
725
|
+
@submit.prevent="saveService"
|
|
726
|
+
><div class="form-grid">
|
|
727
|
+
<el-form-item label="客户端显示名称"
|
|
728
|
+
><el-input
|
|
729
|
+
v-model="serviceForm.label"
|
|
730
|
+
placeholder="例如:快速、深度思考" /></el-form-item
|
|
731
|
+
><el-form-item label="服务标识"
|
|
732
|
+
><el-input
|
|
733
|
+
v-model="serviceForm.id"
|
|
734
|
+
:disabled="serviceRevision > 0"
|
|
735
|
+
placeholder="例如 general-chat" /></el-form-item
|
|
736
|
+
><el-form-item
|
|
737
|
+
><template #label
|
|
738
|
+
>模型凭证</template
|
|
739
|
+
><el-select
|
|
740
|
+
v-model="serviceForm.credential"
|
|
741
|
+
filterable
|
|
742
|
+
:loading="credentialsLoading"
|
|
743
|
+
:disabled="!me.can('credentials:read') || !!credentialsError"
|
|
744
|
+
placeholder="选择已有模型凭证"
|
|
745
|
+
style="width: 100%"
|
|
746
|
+
@change="onServiceCredentialChange"
|
|
747
|
+
>
|
|
748
|
+
<el-option
|
|
749
|
+
v-for="credential in serviceCredentials"
|
|
750
|
+
:key="credential.name"
|
|
751
|
+
:value="credential.name"
|
|
752
|
+
:label="
|
|
753
|
+
credential.name +
|
|
754
|
+
(credential.default_model
|
|
755
|
+
? ' · ' + credential.default_model
|
|
756
|
+
: '')
|
|
757
|
+
"
|
|
758
|
+
/>
|
|
759
|
+
<el-option
|
|
760
|
+
v-if="serviceForm.credential && !selectedServiceCredential"
|
|
761
|
+
:value="serviceForm.credential"
|
|
762
|
+
:label="serviceForm.credential + ' · 当前配置,待核对'"
|
|
763
|
+
disabled
|
|
764
|
+
/>
|
|
765
|
+
<template #footer>
|
|
766
|
+
<router-link to="/credentials" class="credential-create-link">添加模型凭证</router-link>
|
|
767
|
+
</template>
|
|
768
|
+
</el-select>
|
|
769
|
+
<p v-if="credentialsError" class="muted">
|
|
770
|
+
{{ credentialsError }}
|
|
771
|
+
<el-button link @click="loadServiceCredentials">重试</el-button>
|
|
772
|
+
</p>
|
|
773
|
+
<p v-else-if="!me.can('credentials:read')" class="muted">
|
|
774
|
+
当前账号没有模型凭证查看权限,请联系管理员配置。
|
|
775
|
+
</p>
|
|
776
|
+
<p
|
|
777
|
+
v-else-if="!credentialsLoading && !serviceCredentials.length"
|
|
778
|
+
class="muted"
|
|
779
|
+
>
|
|
780
|
+
尚无可用于对话的模型凭证,请先添加。
|
|
781
|
+
</p>
|
|
782
|
+
</el-form-item
|
|
783
|
+
><el-form-item
|
|
784
|
+
><template #label
|
|
785
|
+
>模型标识</template
|
|
786
|
+
><el-select
|
|
787
|
+
v-model="serviceForm.model"
|
|
788
|
+
filterable
|
|
789
|
+
allow-create
|
|
790
|
+
default-first-option
|
|
791
|
+
:disabled="!serviceForm.credential"
|
|
792
|
+
placeholder="选择模型,或输入自定义模型标识"
|
|
793
|
+
style="width: 100%"
|
|
794
|
+
@change="changeCallingModel"
|
|
795
|
+
>
|
|
796
|
+
<el-option
|
|
797
|
+
v-for="model in serviceModelOptions"
|
|
798
|
+
:key="model.value"
|
|
799
|
+
:value="model.value"
|
|
800
|
+
:label="model.label"
|
|
801
|
+
/>
|
|
802
|
+
</el-select>
|
|
803
|
+
</el-form-item>
|
|
804
|
+
</div>
|
|
805
|
+
<el-form-item label="服务用途"><el-radio-group v-model="serviceForm.purpose" @change="changePurpose"><el-radio-button value="chat">对话模型</el-radio-button><el-radio-button value="tool">模型工具</el-radio-button></el-radio-group></el-form-item>
|
|
806
|
+
<div v-if="serviceForm.purpose === 'chat' || serviceForm.tool.capability === 'image_generation'" class="panel form-section">
|
|
807
|
+
<el-form-item label="计费模型(选填)"><el-select v-model="serviceForm.referenceModel" filterable allow-create clearable default-first-option :loading="pricingLoading" :placeholder="serviceForm.model ? `留空使用 ${serviceForm.model}` : '留空使用调用模型标识'" @change="changeReferenceModel"><el-option v-for="m in priceModels" :key="m.id" :value="m.id" :label="`${m.label} · ${m.id}`"/></el-select></el-form-item>
|
|
808
|
+
<div class="reference-match"><span>价格匹配:{{ effectiveReferenceModel || '请先选择调用模型' }}</span><el-button link type="primary" :loading="endpointsLoading" :disabled="!effectiveReferenceModel" @click="loadPriceEndpoints(true)">同步参考价格</el-button></div>
|
|
809
|
+
<el-alert v-if="pricingError || selectedPriceIssue" :title="pricingError || selectedPriceIssue" type="warning" :closable="false"/>
|
|
810
|
+
<details class="service-advanced" :open="!!effectiveReferenceModel && !serviceForm.referenceEndpoint"><summary>参考端点与价格{{ selectedPriceEndpoint ? ` · ${selectedPriceEndpoint.label}` : '' }}</summary>
|
|
811
|
+
<el-form-item label="参考端点"><el-select v-model="serviceForm.referenceEndpoint" filterable :loading="endpointsLoading" :disabled="!effectiveReferenceModel" placeholder="多个报价时,请选择参考端点"><el-option v-for="e in priceEndpoints" :key="e.id" :value="e.id" :label="e.label + (e.unavailable ? ' · 计量规则暂不支持' : !e.pricing?.lines?.length ? ' · 未取得价格' : '')" :disabled="!!endpointPriceIssue(e)"/><el-option v-if="serviceForm.referenceEndpoint && !priceEndpoints.some(e => e.id === serviceForm.referenceEndpoint)" :value="serviceForm.referenceEndpoint" :label="serviceForm.referenceEndpoint + ' · 原绑定,待核对'" disabled/></el-select></el-form-item>
|
|
812
|
+
<p>OpenRouter 参考价,不代表实际供应商账单。仅一个可用端点时自动选中,多个端点需选择;保存后生效。</p><p>最近同步:{{ priceFetchedAt ? time(priceFetchedAt) : '尚未取得' }}{{ pricingStale ? ' · 缓存报价,后台更新中' : '' }}</p><div v-if="selectedPriceEndpoint?.pricing"><div v-for="(line,i) in selectedPriceEndpoint.pricing.lines" :key="i">{{ line.billable }} · {{ line.variant || line.unit }} · ${{ line.costUsd }} / {{ line.unit }}</div></div>
|
|
813
|
+
</details>
|
|
814
|
+
</div>
|
|
815
|
+
<template v-if="serviceForm.purpose === 'tool'">
|
|
816
|
+
<div class="form-grid"><el-form-item label="工具能力"><el-select v-model="serviceForm.tool.capability" filterable allow-create default-first-option @change="changeToolCapability"><el-option label="图片生成" value="image_generation"/><el-option label="视频生成(仅声明)" value="video_generation"/><el-option label="语音生成(仅声明)" value="speech_generation"/></el-select></el-form-item><el-form-item label="调用名称"><el-input v-model="serviceForm.tool.name" placeholder="例如 generate_image"/></el-form-item></div>
|
|
817
|
+
<el-form-item label="给 AI 的使用说明"><el-input v-model="serviceForm.tool.description" type="textarea" :rows="3" maxlength="1200"/></el-form-item>
|
|
818
|
+
<el-form-item label="接口适配"><el-select v-model="serviceForm.tool.adapter"><el-option label="待适配(仅声明,不执行)" value="pending"/><el-option v-if="serviceForm.tool.capability === 'image_generation'" label="阿里云图片(OpenAI 兼容)" value="aliyun-image"/><el-option v-if="serviceForm.tool.capability === 'image_generation'" label="阿里云图片(DashScope 原生)" value="aliyun-image-native"/><el-option v-if="serviceForm.tool.capability === 'image_generation'" label="OpenRouter 图片生成" value="openrouter-image"/></el-select></el-form-item>
|
|
819
|
+
<details class="service-advanced"><summary>参数与输出声明</summary><div v-for="(param,i) in serviceForm.tool.parameters" :key="i" class="tool-parameter"><el-input v-model="param.name" placeholder="参数名"/><el-select v-model="param.type"><el-option value="string" label="文字"/><el-option value="number" label="数字"/><el-option value="boolean" label="开关"/><el-option value="file" label="附件引用"/></el-select><el-checkbox v-model="param.required">必填</el-checkbox><el-button link type="danger" @click="serviceForm.tool.parameters.splice(i,1)">移除</el-button><el-input v-model="param.description" placeholder="参数说明"/></div><el-button link @click="serviceForm.tool.parameters.push({name:'',type:'string',required:false,description:''})">添加参数</el-button><el-form-item label="输出类型"><el-select v-model="serviceForm.tool.outputs" multiple filterable allow-create default-first-option><el-option label="图片" value="image"/><el-option label="视频" value="video"/><el-option label="音频" value="audio"/><el-option label="文件" value="file"/></el-select></el-form-item></details>
|
|
820
|
+
</template>
|
|
821
|
+
<el-switch
|
|
822
|
+
v-model="serviceForm.active"
|
|
823
|
+
active-text="服务启用"
|
|
824
|
+
inactive-text="停止新请求"
|
|
825
|
+
/>
|
|
826
|
+
<details class="service-advanced">
|
|
827
|
+
<summary>模型规格与连接设置</summary>
|
|
828
|
+
|
|
829
|
+
<div class="form-grid">
|
|
830
|
+
<el-form-item label="输出 Token 上限"
|
|
831
|
+
><el-input-number
|
|
832
|
+
v-model="serviceForm.maxOutputTokens"
|
|
833
|
+
:min="1"
|
|
834
|
+
:max="131072" /></el-form-item
|
|
835
|
+
><el-form-item label="上下文窗口(0 = 未登记)"
|
|
836
|
+
><el-input-number
|
|
837
|
+
v-model="serviceForm.contextWindowTokens"
|
|
838
|
+
:min="0"
|
|
839
|
+
:max="10000000" /></el-form-item
|
|
840
|
+
><el-form-item label="模型输入能力"
|
|
841
|
+
><el-select v-model="serviceForm.modalities"
|
|
842
|
+
><el-option value="unknown" label="未登记" /><el-option
|
|
843
|
+
value="text"
|
|
844
|
+
label="文字" /><el-option
|
|
845
|
+
value="text_image"
|
|
846
|
+
label="文字与图片" /></el-select></el-form-item
|
|
847
|
+
><el-form-item label="请求超时(秒)"
|
|
848
|
+
><el-input-number
|
|
849
|
+
v-model="serviceForm.timeoutSeconds"
|
|
850
|
+
:min="1"
|
|
851
|
+
:max="600" /></el-form-item
|
|
852
|
+
><el-form-item label="请求体最大字节数"
|
|
853
|
+
><el-input-number
|
|
854
|
+
v-model="serviceForm.maxInputBytes"
|
|
855
|
+
:min="1"
|
|
856
|
+
:max="16777216" /></el-form-item
|
|
857
|
+
><el-form-item label="供应商账户引用"
|
|
858
|
+
><el-input
|
|
859
|
+
v-model="serviceForm.providerScope"
|
|
860
|
+
placeholder="同一上游账户使用固定引用"
|
|
861
|
+
/></el-form-item>
|
|
862
|
+
</div>
|
|
863
|
+
</details>
|
|
864
|
+
<el-alert
|
|
865
|
+
v-if="serviceError"
|
|
866
|
+
:title="serviceError"
|
|
867
|
+
type="error"
|
|
868
|
+
:closable="false"
|
|
869
|
+
/>
|
|
870
|
+
</el-form>
|
|
871
|
+
<template #footer
|
|
872
|
+
><div class="drawer-actions">
|
|
873
|
+
<el-button @click="serviceOpen = false">取消</el-button>
|
|
874
|
+
<el-button
|
|
875
|
+
type="primary"
|
|
876
|
+
:loading="saving"
|
|
877
|
+
:disabled="blocked || !canIssuers"
|
|
878
|
+
@click="saveService"
|
|
879
|
+
>保存服务</el-button
|
|
880
|
+
>
|
|
881
|
+
</div></template
|
|
882
|
+
>
|
|
883
|
+
</el-drawer>
|
|
884
|
+
</template>
|
|
885
|
+
|
|
886
|
+
<script setup lang="ts">
|
|
887
|
+
import { computed, onMounted, reactive, ref, watch } from "vue";
|
|
888
|
+
import { ArrowLeft } from "@element-plus/icons-vue";
|
|
889
|
+
import { ElCheckboxGroup } from "element-plus/es/components/checkbox/index";
|
|
890
|
+
import { ElMessage } from "element-plus/es/components/message/index";
|
|
891
|
+
import { ElMessageBox } from "element-plus/es/components/message-box/index";
|
|
892
|
+
import { api } from "../request";
|
|
893
|
+
import { useMe } from "../store";
|
|
894
|
+
import { kernelMountPath } from "../runtime-path";
|
|
895
|
+
import UsageDeletionPreview from "../components/UsageDeletionPreview.vue";
|
|
896
|
+
import { useUsageDeletion } from "../usage-deletion";
|
|
897
|
+
import UsageHelp from "../components/UsageHelp.vue";
|
|
898
|
+
import UsageServiceReferences from "../components/UsageServiceReferences.vue";
|
|
899
|
+
import { effectiveBillingModel, estimateModelAllowance, planEstimateBudget, type ReferenceQuote } from "../usage-price-preview";
|
|
900
|
+
import type { ServiceReferenceReport } from "../usage-management";
|
|
901
|
+
import {
|
|
902
|
+
readPresentation,
|
|
903
|
+
previewPresentation,
|
|
904
|
+
presentationAmount,
|
|
905
|
+
presentationUnit,
|
|
906
|
+
presentationState,
|
|
907
|
+
} from "../usage-presentation";
|
|
908
|
+
|
|
909
|
+
type Period = "day" | "week" | "month";
|
|
910
|
+
interface Config {
|
|
911
|
+
mode: "credits" | "periodic";
|
|
912
|
+
serviceIds: string[];
|
|
913
|
+
priceUsd: number;
|
|
914
|
+
periodAllowanceUsd?: number;
|
|
915
|
+
multiplier: number;
|
|
916
|
+
periodUnit?: Period;
|
|
917
|
+
duration: { unit: "day" | "month" | "forever"; count: number };
|
|
918
|
+
}
|
|
919
|
+
interface ToolParameter {name: string; type: 'string'|'number'|'boolean'|'file'; required:boolean; description:string}
|
|
920
|
+
interface ModelTool {name:string;capability:string;description:string;outputs:string[];parameters:ToolParameter[];adapter:'pending'|'aliyun-image'|'aliyun-image-native'|'openrouter-image'}
|
|
921
|
+
type PriceSnapshot = ReferenceQuote;
|
|
922
|
+
interface PriceModel {id:string;label:string;kind:'chat'|'image'}
|
|
923
|
+
interface PriceEndpoint {id:string;label:string;pricing?:PriceSnapshot;unavailable?:boolean;reason?:string}
|
|
924
|
+
interface Plan {
|
|
925
|
+
id: string;
|
|
926
|
+
label: string;
|
|
927
|
+
revision: number;
|
|
928
|
+
state: "active" | "suspended";
|
|
929
|
+
config: Config;
|
|
930
|
+
}
|
|
931
|
+
interface Account {
|
|
932
|
+
id: string;
|
|
933
|
+
label: string;
|
|
934
|
+
kind: "personal" | "organization";
|
|
935
|
+
state: "active" | "suspended";
|
|
936
|
+
}
|
|
937
|
+
interface Service {
|
|
938
|
+
id: string;
|
|
939
|
+
label: string;
|
|
940
|
+
revision: number;
|
|
941
|
+
state: "active" | "suspended";
|
|
942
|
+
availability?: {state: 'ready'|'unavailable'; code: string|null; message: string|null};
|
|
943
|
+
reference_price?: ReferenceQuote | null;
|
|
944
|
+
config: {
|
|
945
|
+
credential: string;
|
|
946
|
+
model: string;
|
|
947
|
+
providerScope: string;
|
|
948
|
+
maxInputBytes: number;
|
|
949
|
+
maxOutputTokens: number;
|
|
950
|
+
timeoutMs: number;
|
|
951
|
+
contextWindowTokens?: number;
|
|
952
|
+
inputModalities?: string[];
|
|
953
|
+
purpose?: "chat"|"tool";
|
|
954
|
+
tool?: ModelTool;
|
|
955
|
+
pricing?: {source:"openrouter";modelId:string;endpointId:string;kind:"chat"|"image"};
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
interface ServiceCredential {
|
|
959
|
+
name: string;
|
|
960
|
+
kind?: string;
|
|
961
|
+
default_model?: string;
|
|
962
|
+
}
|
|
963
|
+
interface Grant {
|
|
964
|
+
id: string;
|
|
965
|
+
planId: string;
|
|
966
|
+
label: string;
|
|
967
|
+
revision: number;
|
|
968
|
+
state: "active" | "suspended";
|
|
969
|
+
sourceOwner: string;
|
|
970
|
+
startsAt: number;
|
|
971
|
+
expiresAt: number | null;
|
|
972
|
+
config: Omit<Config, "serviceIds">;
|
|
973
|
+
}
|
|
974
|
+
interface Summary {
|
|
975
|
+
presentation?: unknown;
|
|
976
|
+
accountId: string;
|
|
977
|
+
grant: Grant | null;
|
|
978
|
+
plan: {
|
|
979
|
+
id: string;
|
|
980
|
+
label: string;
|
|
981
|
+
revision: number;
|
|
982
|
+
serviceIds: string[];
|
|
983
|
+
multiplier: number;
|
|
984
|
+
} | null;
|
|
985
|
+
availableUsd: number;
|
|
986
|
+
consumedUsd: number;
|
|
987
|
+
currentPeriodConsumedUsd: number;
|
|
988
|
+
overageUsd: number;
|
|
989
|
+
pendingRequests: number;
|
|
990
|
+
resetAt: number | null;
|
|
991
|
+
expiresAt: number | null;
|
|
992
|
+
}
|
|
993
|
+
interface RequestView {
|
|
994
|
+
operation_id: string;
|
|
995
|
+
service_id: string;
|
|
996
|
+
result_state: string;
|
|
997
|
+
error?: {message:string;http_status?:number;provider_code?:string;provider_request_id?:string};
|
|
998
|
+
billing_state: string;
|
|
999
|
+
billed_usd: number | null;
|
|
1000
|
+
reference_cost_usd: number | null;
|
|
1001
|
+
usage?: {inputTokens:number;outputTokens:number} | null;
|
|
1002
|
+
raw_usage?: {inputImageCount?:number;outputImageCount?:number} | null;
|
|
1003
|
+
billing_rate?: {
|
|
1004
|
+
planId: string;
|
|
1005
|
+
planRevision: number;
|
|
1006
|
+
multiplier: number;
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
interface Attempt {
|
|
1010
|
+
path: string;
|
|
1011
|
+
body: Record<string, unknown>;
|
|
1012
|
+
kind: "plan" | "grant" | "control" | "reset" | "service" | "service_delete" | "plan_delete";
|
|
1013
|
+
method?: "POST" | "DELETE";
|
|
1014
|
+
}
|
|
1015
|
+
const base = "/admin/api/usage",
|
|
1016
|
+
billing = `${base}/billing`,
|
|
1017
|
+
me = useMe();
|
|
1018
|
+
const canWrite = computed(() => me.can("usage:write")),
|
|
1019
|
+
canAdjust = computed(() => me.can("usage:write") && me.can("usage:adjust")),
|
|
1020
|
+
canIssuers = computed(() => me.can("usage:write") && me.can("usage:issuers"));
|
|
1021
|
+
const tab = ref("plans"),
|
|
1022
|
+
loading = ref(false),
|
|
1023
|
+
saving = ref(false),
|
|
1024
|
+
supported = ref(false),
|
|
1025
|
+
billingReady = ref(false),
|
|
1026
|
+
periodAllowanceSupported = ref(false),
|
|
1027
|
+
error = ref(""),
|
|
1028
|
+
pending = ref<Attempt | null>(null),
|
|
1029
|
+
storageFailed = ref(false);
|
|
1030
|
+
const pendingNeedsBilling = computed(
|
|
1031
|
+
() =>
|
|
1032
|
+
!!pending.value &&
|
|
1033
|
+
["plan", "grant", "control", "reset"].includes(pending.value.kind) &&
|
|
1034
|
+
!billingReady.value,
|
|
1035
|
+
);
|
|
1036
|
+
const blocked = computed(
|
|
1037
|
+
() =>
|
|
1038
|
+
loading.value ||
|
|
1039
|
+
saving.value ||
|
|
1040
|
+
!supported.value ||
|
|
1041
|
+
!!pending.value ||
|
|
1042
|
+
storageFailed.value,
|
|
1043
|
+
);
|
|
1044
|
+
const plans = ref<Plan[]>([]),
|
|
1045
|
+
services = ref<Service[]>([]),
|
|
1046
|
+
accounts = ref<Account[]>([]),
|
|
1047
|
+
accountCursor = ref<string | null>(null),
|
|
1048
|
+
accountsLoading = ref(false);
|
|
1049
|
+
const billingWarning =
|
|
1050
|
+
"美元计费尚未就绪,请核对内核与迁移。";
|
|
1051
|
+
const editing = ref(false),
|
|
1052
|
+
formError = ref("");
|
|
1053
|
+
const defaults = () => ({
|
|
1054
|
+
id: "",
|
|
1055
|
+
revision: 0,
|
|
1056
|
+
label: "",
|
|
1057
|
+
active: true,
|
|
1058
|
+
mode: "periodic" as Config["mode"],
|
|
1059
|
+
serviceIds: [] as string[],
|
|
1060
|
+
priceUsd: 100,
|
|
1061
|
+
periodAllowanceUsd: 20 as number | undefined,
|
|
1062
|
+
multiplier: 1.5,
|
|
1063
|
+
periodUnit: "week" as Period,
|
|
1064
|
+
durationUnit: "month" as Config["duration"]["unit"],
|
|
1065
|
+
durationCount: 1,
|
|
1066
|
+
|
|
1067
|
+
});
|
|
1068
|
+
const form = reactive(defaults());
|
|
1069
|
+
const usd = (value: number) => Number.isFinite(value) ? '$' + value.toLocaleString('en-US', {minimumFractionDigits:2,maximumFractionDigits:6}) : '—';
|
|
1070
|
+
const serviceGroups = [{purpose:'chat',label:'对话模型'},{purpose:'tool',label:'模型工具'}];
|
|
1071
|
+
const purposeOf = (service: Service) => service.config.purpose === 'tool' ? 'tool' : 'chat';
|
|
1072
|
+
const availabilityReasons: Record<string, string> = {
|
|
1073
|
+
USAGE_PRICE_NOT_CONFIGURED: '尚未绑定参考价格,请配置参考模型与端点。',
|
|
1074
|
+
USAGE_PRICE_UNAVAILABLE: '未取得可用参考价格,请检查绑定并同步价格。',
|
|
1075
|
+
USAGE_PRICE_UNSUPPORTED: '参考端点的计量规则暂不支持,请选择其他端点。',
|
|
1076
|
+
USAGE_SERVICE_UNAVAILABLE: '服务已停用,请在配置中启用。',
|
|
1077
|
+
MODEL_TOOL_ADAPTER_NOT_READY: '工具接口尚未适配,当前仅保存声明。',
|
|
1078
|
+
};
|
|
1079
|
+
function serviceAvailability(service: Service) {
|
|
1080
|
+
if (service.availability) return service.availability;
|
|
1081
|
+
return {state: 'unavailable', code: 'USAGE_SERVICE_UNAVAILABLE', message: '尚未取得配置状态,请刷新后重试。'};
|
|
1082
|
+
}
|
|
1083
|
+
const serviceReady = (service: Service) => serviceAvailability(service).state === 'ready';
|
|
1084
|
+
function serviceUnavailableReason(service: Service) {
|
|
1085
|
+
const availability = serviceAvailability(service);
|
|
1086
|
+
return availability.message || availabilityReasons[availability.code || ''] || '服务暂不可用,请检查配置。';
|
|
1087
|
+
}
|
|
1088
|
+
const serviceConfigurationLabel = (service: Service) => serviceAvailability(service).code?.startsWith('USAGE_PRICE_') ? '配置价格' : '配置';
|
|
1089
|
+
const previewConfig = computed<Config>(() => ({
|
|
1090
|
+
mode: form.mode,
|
|
1091
|
+
serviceIds: [...form.serviceIds],
|
|
1092
|
+
priceUsd: Number(form.priceUsd),
|
|
1093
|
+
multiplier: Number(form.multiplier),
|
|
1094
|
+
...(form.mode === "periodic" ? { periodUnit: form.periodUnit, periodAllowanceUsd: Number(form.periodAllowanceUsd) } : {}),
|
|
1095
|
+
duration: {
|
|
1096
|
+
unit: form.durationUnit,
|
|
1097
|
+
count: form.durationUnit === "forever" ? 1 : Number(form.durationCount),
|
|
1098
|
+
},
|
|
1099
|
+
|
|
1100
|
+
}));
|
|
1101
|
+
const planPresentation = computed(() =>
|
|
1102
|
+
previewPresentation(previewConfig.value),
|
|
1103
|
+
);
|
|
1104
|
+
watch(
|
|
1105
|
+
() => form.mode,
|
|
1106
|
+
(mode) => {
|
|
1107
|
+
if (mode === "periodic" && form.durationUnit === "forever")
|
|
1108
|
+
form.durationUnit = "month";
|
|
1109
|
+
},
|
|
1110
|
+
);
|
|
1111
|
+
const number = (n: number) =>
|
|
1112
|
+
Number.isFinite(n)
|
|
1113
|
+
? n.toLocaleString("zh-CN", { maximumFractionDigits: 6 })
|
|
1114
|
+
: "—";
|
|
1115
|
+
const time = (n: number | null, empty = "—") =>
|
|
1116
|
+
n === null ? empty : new Date(n).toLocaleString("zh-CN", { hour12: false });
|
|
1117
|
+
const periodText = (p?: string) =>
|
|
1118
|
+
({ day: "每日", week: "每 7 天", month: "每月按开通日期" })[p || ""] ||
|
|
1119
|
+
"按周期";
|
|
1120
|
+
const durationText = (c: Config) =>
|
|
1121
|
+
c.duration.unit === "forever"
|
|
1122
|
+
? "持续有效"
|
|
1123
|
+
: `开通后 ${c.duration.count} ${c.duration.unit === "month" ? "个月" : "天"}`;
|
|
1124
|
+
const serviceLabel = (id: string) =>
|
|
1125
|
+
services.value.find((s) => s.id === id)?.label || `未找到的模型服务(${id})`;
|
|
1126
|
+
const resultState = (state: string) =>
|
|
1127
|
+
({
|
|
1128
|
+
complete: "已完成",
|
|
1129
|
+
pending: "处理中",
|
|
1130
|
+
unknown: "原结果待核对",
|
|
1131
|
+
cancelled: "已取消",
|
|
1132
|
+
failed: "生成服务已拒绝",
|
|
1133
|
+
})[state] || "状态待核对";
|
|
1134
|
+
function describe(e: unknown) {
|
|
1135
|
+
const code = e instanceof Error ? e.message : "请求失败";
|
|
1136
|
+
const known: Record<string, string> = {
|
|
1137
|
+
USAGE_UNSUPPORTED: "当前实例尚未支持 用量套餐,请核对版本与迁移。",
|
|
1138
|
+
USAGE_BILLING_UNSUPPORTED: "用量套餐尚未就绪,请核对迁移。",
|
|
1139
|
+
USAGE_RESOURCE_IN_USE: "该记录已有使用关联,请查看删除抽屉中的占用原因。",
|
|
1140
|
+
USAGE_RESOURCE_DELETED: "记录已删除,原标识不能重新使用。",
|
|
1141
|
+
USAGE_RESOURCE_NOT_FOUND: "记录已不存在,请刷新列表。",
|
|
1142
|
+
USAGE_FORBIDDEN: "当前管理员没有此操作权限。",
|
|
1143
|
+
USAGE_REVISION_CONFLICT: "记录已被更新,请刷新并核对后重新操作。",
|
|
1144
|
+
USAGE_IDEMPOTENCY_CONFLICT: "原请求与当前内容不一致,请核对原记录。",
|
|
1145
|
+
USAGE_SOURCE_FORBIDDEN: "此套餐由业务后端维护,请回原来源调整。",
|
|
1146
|
+
USAGE_SOURCE_CONFLICT: "此套餐由原来源维护,不能在这里直接替换。",
|
|
1147
|
+
USAGE_PRICE_UNSUPPORTED: "参考端点的计量规则暂不支持,请选择其他端点。",
|
|
1148
|
+
USAGE_PRICE_UNAVAILABLE: "暂时无法取得参考价格,请稍后重试;已有绑定仍保留。",
|
|
1149
|
+
USAGE_PRICING_UNAVAILABLE: "参考价格尚未就绪,请选择有效参考模型和端点。",
|
|
1150
|
+
USAGE_TOOL_ADAPTER_UNSUPPORTED: "工具适配尚未支持,请选择已支持的图片适配或保存为仅声明。",
|
|
1151
|
+
USAGE_INVALID_INPUT: "部分配置不符合要求,请检查填写内容。",
|
|
1152
|
+
USAGE_NOT_FOUND: "记录已不存在,请刷新列表。",
|
|
1153
|
+
USAGE_SERVICE_NOT_FOUND: "模型服务已不存在,请刷新列表。",
|
|
1154
|
+
USAGE_SERVICE_DELETED: "此服务标识已经删除,请为新模型服务填写新的标识。",
|
|
1155
|
+
USAGE_SERVICE_UNAVAILABLE: "选中的模型服务已停用,请刷新并选择可用模型。",
|
|
1156
|
+
USAGE_ACCOUNT_SUSPENDED: "该账户已停用,请先恢复账户。",
|
|
1157
|
+
SERVICE_NOT_ENTITLED:
|
|
1158
|
+
"套餐尚未开通或已经暂停开通,请刷新并选择当前可用套餐。",
|
|
1159
|
+
};
|
|
1160
|
+
return known[code] || `操作未完成:${code}`;
|
|
1161
|
+
}
|
|
1162
|
+
async function load() {
|
|
1163
|
+
if (loading.value) return;
|
|
1164
|
+
loading.value = true;
|
|
1165
|
+
if (!storageFailed.value) error.value = "";
|
|
1166
|
+
try {
|
|
1167
|
+
const results = await Promise.allSettled([
|
|
1168
|
+
api<{ items: Plan[]; billing_ready?: boolean; period_allowance_supported?: boolean }>(`${billing}/plans`)
|
|
1169
|
+
.then((r) => {
|
|
1170
|
+
plans.value = r.items;
|
|
1171
|
+
billingReady.value = r.billing_ready === true;
|
|
1172
|
+
periodAllowanceSupported.value = r.period_allowance_supported === true;
|
|
1173
|
+
supported.value = true;
|
|
1174
|
+
})
|
|
1175
|
+
.catch((e) => {
|
|
1176
|
+
supported.value = false;
|
|
1177
|
+
billingReady.value = false;
|
|
1178
|
+
periodAllowanceSupported.value = false;
|
|
1179
|
+
tab.value = "models";
|
|
1180
|
+
throw e;
|
|
1181
|
+
}),
|
|
1182
|
+
api<{ items: Service[] }>(`${base}/services`).then(
|
|
1183
|
+
(r) => (services.value = r.items),
|
|
1184
|
+
),
|
|
1185
|
+
loadAccounts(),
|
|
1186
|
+
]);
|
|
1187
|
+
const failure = results.find((r) => r.status === "rejected");
|
|
1188
|
+
if (failure?.status === "rejected") throw failure.reason;
|
|
1189
|
+
} catch (e) {
|
|
1190
|
+
error.value = describe(e);
|
|
1191
|
+
} finally {
|
|
1192
|
+
loading.value = false;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
async function loadAccounts(more = false) {
|
|
1196
|
+
if (accountsLoading.value) return;
|
|
1197
|
+
accountsLoading.value = true;
|
|
1198
|
+
try {
|
|
1199
|
+
const query = new URLSearchParams({ limit: "30" });
|
|
1200
|
+
if (more && accountCursor.value) query.set("cursor", accountCursor.value);
|
|
1201
|
+
const r = await api<{ items: Account[]; next_cursor: string | null }>(
|
|
1202
|
+
`${base}/accounts?${query}`,
|
|
1203
|
+
);
|
|
1204
|
+
accounts.value = more ? [...accounts.value, ...r.items] : r.items;
|
|
1205
|
+
accountCursor.value = r.next_cursor;
|
|
1206
|
+
} catch (e) {
|
|
1207
|
+
error.value = describe(e);
|
|
1208
|
+
throw e;
|
|
1209
|
+
} finally {
|
|
1210
|
+
accountsLoading.value = false;
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
const estimateBudget = computed(() => planEstimateBudget(previewConfig.value));
|
|
1214
|
+
const estimateHeading = computed(() => {
|
|
1215
|
+
const cadence = {day:'每天',week:'每周',month:'每月'}[form.periodUnit];
|
|
1216
|
+
const basis = form.mode === 'periodic' ? `${cadence}预计可用量 · 周期额度` : '整包预计可用量 · 套餐额度';
|
|
1217
|
+
return `${basis} ${estimateBudget.value === null ? '待填写' : usd(estimateBudget.value)} · 已计入 ${form.multiplier || 0}×`;
|
|
1218
|
+
});
|
|
1219
|
+
function planEstimates(service: Service) {
|
|
1220
|
+
const quote = service.reference_price, binding = service.config.pricing;
|
|
1221
|
+
if (!quote || !binding || quote.modelId !== binding.modelId || quote.endpointId !== binding.endpointId) return [];
|
|
1222
|
+
return estimateModelAllowance(quote, estimateBudget.value ?? 0, form.multiplier, purposeOf(service) === 'chat' ? 'chat' : 'image');
|
|
1223
|
+
}
|
|
1224
|
+
function quoteStale(service: Service) { return !service.reference_price || Date.now() - service.reference_price.fetchedAt > 6 * 60 * 60 * 1000; }
|
|
1225
|
+
function openPlan(plan?: Plan) {
|
|
1226
|
+
Object.assign(
|
|
1227
|
+
form,
|
|
1228
|
+
defaults(),
|
|
1229
|
+
plan
|
|
1230
|
+
? {
|
|
1231
|
+
id: plan.id,
|
|
1232
|
+
revision: plan.revision,
|
|
1233
|
+
label: plan.label,
|
|
1234
|
+
active: plan.state === "active",
|
|
1235
|
+
mode: plan.config.mode,
|
|
1236
|
+
serviceIds: [...plan.config.serviceIds],
|
|
1237
|
+
priceUsd: plan.config.priceUsd,
|
|
1238
|
+
periodAllowanceUsd: plan.config.periodAllowanceUsd,
|
|
1239
|
+
multiplier: plan.config.multiplier,
|
|
1240
|
+
periodUnit: plan.config.periodUnit || "week",
|
|
1241
|
+
durationUnit: plan.config.duration.unit,
|
|
1242
|
+
durationCount: plan.config.duration.count,
|
|
1243
|
+
|
|
1244
|
+
}
|
|
1245
|
+
: { id: `billing-plan-${crypto.randomUUID()}` },
|
|
1246
|
+
);
|
|
1247
|
+
formError.value = "";
|
|
1248
|
+
editing.value = true;
|
|
1249
|
+
tab.value = "plans";
|
|
1250
|
+
}
|
|
1251
|
+
function validateConfig(c: Config) {
|
|
1252
|
+
if (!form.label.trim()) throw new Error("请填写套餐名称。");
|
|
1253
|
+
if (
|
|
1254
|
+
c.serviceIds.some(
|
|
1255
|
+
(id) => !services.value.some((s) => s.id === id && (serviceReady(s) || plans.value.find(p => p.id === form.id)?.config.serviceIds.includes(id))),
|
|
1256
|
+
)
|
|
1257
|
+
)
|
|
1258
|
+
throw new Error("新增服务尚未就绪或已不存在,请调整选择或先完成服务配置。");
|
|
1259
|
+
if (!Number.isFinite(c.priceUsd) || c.priceUsd < 0.01 || c.priceUsd > 1000000) throw new Error('美元价格须为 0.01 至 1,000,000。');
|
|
1260
|
+
if (c.mode === 'periodic' && (typeof c.periodAllowanceUsd !== 'number' || !Number.isFinite(c.periodAllowanceUsd) || c.periodAllowanceUsd < 0.01 || c.periodAllowanceUsd > 1000000)) throw new Error('请填写 0.01 至 1,000,000 的周期额度。');
|
|
1261
|
+
if (!Number.isFinite(c.multiplier) || c.multiplier < 0.000001 || c.multiplier > 1000) throw new Error('统一倍率须为 0.000001 至 1000。');
|
|
1262
|
+
if (
|
|
1263
|
+
!Number.isSafeInteger(c.duration.count) ||
|
|
1264
|
+
c.duration.count < 1 ||
|
|
1265
|
+
c.duration.count > 1200
|
|
1266
|
+
)
|
|
1267
|
+
throw new Error("请填写有效的使用期限。");
|
|
1268
|
+
|
|
1269
|
+
}
|
|
1270
|
+
async function savePlan() {
|
|
1271
|
+
formError.value = "";
|
|
1272
|
+
if (!billingReady.value) {
|
|
1273
|
+
formError.value = billingWarning;
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
try {
|
|
1277
|
+
if (form.mode === 'periodic' && !periodAllowanceSupported.value) throw new Error('周期额度仅供预览,请先启用配套计费版本。');
|
|
1278
|
+
const config = previewConfig.value;
|
|
1279
|
+
validateConfig(config);
|
|
1280
|
+
await mutate({
|
|
1281
|
+
kind: "plan",
|
|
1282
|
+
path: `${billing}/plans`,
|
|
1283
|
+
body: {
|
|
1284
|
+
id: form.id,
|
|
1285
|
+
label: form.label.trim(),
|
|
1286
|
+
expected_revision: form.revision,
|
|
1287
|
+
state: form.active ? "active" : "suspended",
|
|
1288
|
+
config,
|
|
1289
|
+
},
|
|
1290
|
+
});
|
|
1291
|
+
} catch (e) {
|
|
1292
|
+
formError.value = describe(e);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
const pendingKey = () =>
|
|
1296
|
+
`bailing:billing-config:pending:v1:${kernelMountPath()}:${me.me?.username || ""}`;
|
|
1297
|
+
async function mutate(attempt: Attempt) {
|
|
1298
|
+
if (blocked.value) throw new Error("请先完成上一次操作或等待刷新。");
|
|
1299
|
+
try {
|
|
1300
|
+
sessionStorage.setItem(pendingKey(), JSON.stringify(attempt));
|
|
1301
|
+
} catch {
|
|
1302
|
+
storageFailed.value = true;
|
|
1303
|
+
throw new Error("无法保存原请求,尚未提交。请恢复浏览器会话存储后刷新。");
|
|
1304
|
+
}
|
|
1305
|
+
pending.value = attempt;
|
|
1306
|
+
await retryPending();
|
|
1307
|
+
}
|
|
1308
|
+
const definitive = new Set([
|
|
1309
|
+
"USAGE_RESOURCE_IN_USE",
|
|
1310
|
+
"USAGE_RESOURCE_DELETED",
|
|
1311
|
+
"USAGE_RESOURCE_NOT_FOUND",
|
|
1312
|
+
"USAGE_INVALID_INPUT",
|
|
1313
|
+
"USAGE_FORBIDDEN",
|
|
1314
|
+
"USAGE_REVISION_CONFLICT",
|
|
1315
|
+
"USAGE_SOURCE_FORBIDDEN",
|
|
1316
|
+
"USAGE_SOURCE_CONFLICT",
|
|
1317
|
+
"USAGE_ACCOUNT_NOT_FOUND",
|
|
1318
|
+
"USAGE_ACCOUNT_SUSPENDED",
|
|
1319
|
+
"SERVICE_NOT_ENTITLED",
|
|
1320
|
+
"USAGE_NOT_FOUND",
|
|
1321
|
+
"USAGE_SERVICE_NOT_FOUND",
|
|
1322
|
+
"USAGE_SERVICE_DELETED",
|
|
1323
|
+
"USAGE_SERVICE_UNAVAILABLE",
|
|
1324
|
+
"USAGE_PRICE_NOT_CONFIGURED",
|
|
1325
|
+
"USAGE_PRICE_UNAVAILABLE",
|
|
1326
|
+
"USAGE_PRICE_UNSUPPORTED",
|
|
1327
|
+
"MODEL_TOOL_ADAPTER_NOT_READY",
|
|
1328
|
+
"USAGE_PLAN_NOT_FOUND",
|
|
1329
|
+
"USAGE_IDEMPOTENCY_CONFLICT",
|
|
1330
|
+
"USAGE_UNSUPPORTED",
|
|
1331
|
+
"USAGE_BILLING_UNSUPPORTED",
|
|
1332
|
+
"USAGE_MODEL_NOT_ALLOWED",
|
|
1333
|
+
"USAGE_DISABLED",
|
|
1334
|
+
"USAGE_PLAN_SUSPENDED",
|
|
1335
|
+
]);
|
|
1336
|
+
async function retryPending() {
|
|
1337
|
+
if (!pending.value || saving.value) return;
|
|
1338
|
+
if (pendingNeedsBilling.value) {
|
|
1339
|
+
error.value = billingWarning;
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
const attempt = pending.value;
|
|
1343
|
+
saving.value = true;
|
|
1344
|
+
error.value = "";
|
|
1345
|
+
try {
|
|
1346
|
+
await api(attempt.path, {
|
|
1347
|
+
method: attempt.method ?? "POST",
|
|
1348
|
+
body: JSON.stringify(attempt.body),
|
|
1349
|
+
});
|
|
1350
|
+
sessionStorage.removeItem(pendingKey());
|
|
1351
|
+
pending.value = null;
|
|
1352
|
+
if (attempt.kind === "plan") editing.value = false;
|
|
1353
|
+
if (attempt.kind === "plan_delete") deletion.open.value = false;
|
|
1354
|
+
if (attempt.kind === "grant") grantOpen.value = false;
|
|
1355
|
+
if (attempt.kind === "service") serviceOpen.value = false;
|
|
1356
|
+
if (attempt.kind === "service_delete") {
|
|
1357
|
+
referencesOpen.value = false;
|
|
1358
|
+
tab.value = "models";
|
|
1359
|
+
}
|
|
1360
|
+
ElMessage.success(
|
|
1361
|
+
attempt.kind === "grant"
|
|
1362
|
+
? "套餐已开通,新额度从现在开始生效。"
|
|
1363
|
+
: attempt.kind === "reset" ? "额度已重置,套餐到期时间不变。"
|
|
1364
|
+
: attempt.kind === "service_delete"
|
|
1365
|
+
? "模型服务已删除,历史用量记录已保留。"
|
|
1366
|
+
: attempt.kind === "plan_delete" ? "套餐已删除。" : "已保存。",
|
|
1367
|
+
);
|
|
1368
|
+
await load();
|
|
1369
|
+
if (detailOpen.value) await loadDetail();
|
|
1370
|
+
} catch (e) {
|
|
1371
|
+
const code = e instanceof Error ? e.message : "";
|
|
1372
|
+
error.value = describe(e);
|
|
1373
|
+
formError.value = error.value;
|
|
1374
|
+
grantError.value = error.value;
|
|
1375
|
+
serviceError.value = error.value;
|
|
1376
|
+
if (definitive.has(code)) {
|
|
1377
|
+
sessionStorage.removeItem(pendingKey());
|
|
1378
|
+
pending.value = null;
|
|
1379
|
+
if (code === "USAGE_REVISION_CONFLICT") {
|
|
1380
|
+
editing.value = false;
|
|
1381
|
+
grantOpen.value = false;
|
|
1382
|
+
serviceOpen.value = false;
|
|
1383
|
+
}
|
|
1384
|
+
await load();
|
|
1385
|
+
error.value = describe(e);
|
|
1386
|
+
if (detailOpen.value) await loadDetail();
|
|
1387
|
+
}
|
|
1388
|
+
if (attempt.kind === "plan_delete" && deletion.open.value) {
|
|
1389
|
+
await deletion.refresh();
|
|
1390
|
+
deletion.error.value = describe(e);
|
|
1391
|
+
}
|
|
1392
|
+
if (attempt.kind === "service_delete" && referencesOpen.value) {
|
|
1393
|
+
await loadServiceReferences();
|
|
1394
|
+
referencesError.value = describe(e);
|
|
1395
|
+
}
|
|
1396
|
+
} finally {
|
|
1397
|
+
saving.value = false;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
const detailOpen = ref(false),
|
|
1401
|
+
detailLoading = ref(false),
|
|
1402
|
+
detailError = ref(""),
|
|
1403
|
+
selectedAccount = ref<Account | null>(null),
|
|
1404
|
+
summary = ref<Summary | null>(null),
|
|
1405
|
+
requests = ref<RequestView[]>([]),
|
|
1406
|
+
requestCursor = ref<string | null>(null),
|
|
1407
|
+
requestsLoading = ref(false);
|
|
1408
|
+
const externalGrant = computed(
|
|
1409
|
+
() => !!summary.value?.grant && summary.value.grant.sourceOwner !== "hub",
|
|
1410
|
+
);
|
|
1411
|
+
const canResetAllowance = computed(() => {
|
|
1412
|
+
const g = summary.value?.grant, now = Date.now();
|
|
1413
|
+
return !!g && !!summary.value?.plan && selectedAccount.value?.state === 'active'
|
|
1414
|
+
&& g.state === 'active' && now >= g.startsAt && (g.expiresAt === null || now < g.expiresAt);
|
|
1415
|
+
});
|
|
1416
|
+
const accountModelIds = computed(() =>
|
|
1417
|
+
(summary.value?.plan?.serviceIds || []).filter((id) =>
|
|
1418
|
+
services.value.some(
|
|
1419
|
+
(service) => service.id === id && serviceReady(service),
|
|
1420
|
+
),
|
|
1421
|
+
),
|
|
1422
|
+
);
|
|
1423
|
+
const periodConsumed = (s: Summary) =>
|
|
1424
|
+
s.grant?.config.mode === "periodic"
|
|
1425
|
+
? s.currentPeriodConsumedUsd
|
|
1426
|
+
: s.consumedUsd;
|
|
1427
|
+
const accountPresentation = computed(() =>
|
|
1428
|
+
readPresentation(
|
|
1429
|
+
summary.value?.presentation,
|
|
1430
|
+
summary.value?.grant?.config.mode,
|
|
1431
|
+
),
|
|
1432
|
+
);
|
|
1433
|
+
function grantStatus(s: Summary) {
|
|
1434
|
+
const p = readPresentation(s.presentation, s.grant?.config.mode);
|
|
1435
|
+
if (p.state === "active") return "多个模型共享同一份额度。";
|
|
1436
|
+
if (p.state === "depleted")
|
|
1437
|
+
return s.resetAt
|
|
1438
|
+
? "额度已用完,等待下一周期重置。"
|
|
1439
|
+
: "额度已用完,可开通新的额度包。";
|
|
1440
|
+
return presentationState(p) + ",原记录保留。";
|
|
1441
|
+
}
|
|
1442
|
+
async function openAccount(account: Account) {
|
|
1443
|
+
selectedAccount.value = account;
|
|
1444
|
+
detailOpen.value = true;
|
|
1445
|
+
await loadDetail();
|
|
1446
|
+
}
|
|
1447
|
+
async function loadDetail() {
|
|
1448
|
+
const id = selectedAccount.value?.id;
|
|
1449
|
+
if (!id) return;
|
|
1450
|
+
detailLoading.value = true;
|
|
1451
|
+
detailError.value = "";
|
|
1452
|
+
summary.value = null;
|
|
1453
|
+
requests.value = [];
|
|
1454
|
+
requestCursor.value = null;
|
|
1455
|
+
try {
|
|
1456
|
+
const value = await api<Summary>(
|
|
1457
|
+
`${billing}/accounts/${encodeURIComponent(id)}/summary`,
|
|
1458
|
+
);
|
|
1459
|
+
if (selectedAccount.value?.id !== id) return;
|
|
1460
|
+
summary.value = value;
|
|
1461
|
+
await loadRequests();
|
|
1462
|
+
} catch (e) {
|
|
1463
|
+
detailError.value = describe(e);
|
|
1464
|
+
} finally {
|
|
1465
|
+
detailLoading.value = false;
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
async function loadRequests(more = false) {
|
|
1469
|
+
const id = selectedAccount.value?.id;
|
|
1470
|
+
if (!id || requestsLoading.value || !billingReady.value) return;
|
|
1471
|
+
requestsLoading.value = true;
|
|
1472
|
+
try {
|
|
1473
|
+
const query = new URLSearchParams({ limit: "30" });
|
|
1474
|
+
if (more && requestCursor.value) query.set("cursor", requestCursor.value);
|
|
1475
|
+
const r = await api<{ items: RequestView[]; next_cursor: string | null }>(
|
|
1476
|
+
`${billing}/accounts/${encodeURIComponent(id)}/requests?${query}`,
|
|
1477
|
+
);
|
|
1478
|
+
if (selectedAccount.value?.id !== id) return;
|
|
1479
|
+
requests.value = more ? [...requests.value, ...r.items] : r.items;
|
|
1480
|
+
requestCursor.value = r.next_cursor;
|
|
1481
|
+
} catch (e) {
|
|
1482
|
+
detailError.value = describe(e);
|
|
1483
|
+
} finally {
|
|
1484
|
+
requestsLoading.value = false;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
const grantOpen = ref(false),
|
|
1488
|
+
grantLoading = ref(false),
|
|
1489
|
+
grantError = ref(""),
|
|
1490
|
+
grantAccountId = ref(""),
|
|
1491
|
+
grantPlanId = ref(""),
|
|
1492
|
+
grantSummary = ref<Summary | null>(null);
|
|
1493
|
+
const grantFromAccount = ref(false),
|
|
1494
|
+
deferredGrant = ref(false);
|
|
1495
|
+
function openDeferredGrant() {
|
|
1496
|
+
if (deferredGrant.value) {
|
|
1497
|
+
deferredGrant.value = false;
|
|
1498
|
+
grantOpen.value = true;
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
async function returnToAccount() {
|
|
1502
|
+
if (!grantFromAccount.value || !selectedAccount.value) return;
|
|
1503
|
+
grantFromAccount.value = false;
|
|
1504
|
+
detailOpen.value = true;
|
|
1505
|
+
await loadDetail();
|
|
1506
|
+
}
|
|
1507
|
+
const grantPlan = computed(() =>
|
|
1508
|
+
plans.value.find((p) => p.id === grantPlanId.value),
|
|
1509
|
+
);
|
|
1510
|
+
async function openGrant(account?: Account, planId?: string) {
|
|
1511
|
+
grantAccountId.value = account?.id || "";
|
|
1512
|
+
grantPlanId.value =
|
|
1513
|
+
planId || plans.value.find((p) => p.state === "active")?.id || "";
|
|
1514
|
+
grantSummary.value = null;
|
|
1515
|
+
grantError.value = "";
|
|
1516
|
+
grantFromAccount.value = detailOpen.value;
|
|
1517
|
+
if (detailOpen.value) {
|
|
1518
|
+
deferredGrant.value = true;
|
|
1519
|
+
detailOpen.value = false;
|
|
1520
|
+
} else grantOpen.value = true;
|
|
1521
|
+
if (account) await loadGrantSummary();
|
|
1522
|
+
}
|
|
1523
|
+
async function loadGrantSummary() {
|
|
1524
|
+
const id = grantAccountId.value;
|
|
1525
|
+
grantSummary.value = null;
|
|
1526
|
+
grantError.value = "";
|
|
1527
|
+
if (!id) return;
|
|
1528
|
+
grantLoading.value = true;
|
|
1529
|
+
try {
|
|
1530
|
+
const r = await api<Summary>(
|
|
1531
|
+
`${billing}/accounts/${encodeURIComponent(id)}/summary`,
|
|
1532
|
+
);
|
|
1533
|
+
if (grantAccountId.value !== id) return;
|
|
1534
|
+
grantSummary.value = r;
|
|
1535
|
+
if (r.grant && r.grant.sourceOwner !== "hub")
|
|
1536
|
+
grantError.value = "此套餐由业务后端维护,请在原来源调整。";
|
|
1537
|
+
} catch (e) {
|
|
1538
|
+
grantError.value = describe(e);
|
|
1539
|
+
} finally {
|
|
1540
|
+
grantLoading.value = false;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
async function grant() {
|
|
1544
|
+
if (!billingReady.value) {
|
|
1545
|
+
grantError.value = billingWarning;
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
if (!grantSummary.value || !grantPlan.value || grantError.value) return;
|
|
1549
|
+
try {
|
|
1550
|
+
await mutate({
|
|
1551
|
+
kind: "grant",
|
|
1552
|
+
path: `${billing}/accounts/${encodeURIComponent(grantAccountId.value)}/grant`,
|
|
1553
|
+
body: {
|
|
1554
|
+
request_key: crypto.randomUUID(),
|
|
1555
|
+
plan_id: grantPlanId.value,
|
|
1556
|
+
expected_revision: grantSummary.value.grant?.revision || 0,
|
|
1557
|
+
},
|
|
1558
|
+
});
|
|
1559
|
+
} catch (e) {
|
|
1560
|
+
grantError.value = describe(e);
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
async function resetAllowance() {
|
|
1564
|
+
const g = summary.value?.grant, account = selectedAccount.value;
|
|
1565
|
+
if (!canAdjust.value || !canResetAllowance.value || blocked.value || !billingReady.value || externalGrant.value || !g || !account) return;
|
|
1566
|
+
const terms = g.config.mode === 'periodic'
|
|
1567
|
+
? `本期额度将恢复至 100%(${number(g.config.periodAllowanceUsd!)} USD),重置周期从本次确认时重新起算。`
|
|
1568
|
+
: `可用积分将恢复至初始额度(${number(g.config.priceUsd * 1000)} 积分)。`;
|
|
1569
|
+
try {
|
|
1570
|
+
await ElMessageBox.confirm(`${terms}剩余额度不叠加,套餐到期时间不延长。历史用量保留,重置前已发出的请求继续记入原额度。`, '重置此账户额度',
|
|
1571
|
+
{ confirmButtonText: '确认重置', cancelButtonText: '取消', type: 'warning', closeOnClickModal: false });
|
|
1572
|
+
} catch { return; }
|
|
1573
|
+
try {
|
|
1574
|
+
await mutate({kind: 'reset', path: `${billing}/accounts/${encodeURIComponent(account.id)}/reset`,
|
|
1575
|
+
body: {request_key: crypto.randomUUID(), expected_revision: g.revision}});
|
|
1576
|
+
} catch (e) { detailError.value = describe(e); }
|
|
1577
|
+
}
|
|
1578
|
+
async function controlGrant() {
|
|
1579
|
+
if (!billingReady.value) {
|
|
1580
|
+
detailError.value = billingWarning;
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
const g = summary.value?.grant;
|
|
1584
|
+
if (!g || !selectedAccount.value) return;
|
|
1585
|
+
try {
|
|
1586
|
+
await ElMessageBox.confirm(
|
|
1587
|
+
g.state === "active"
|
|
1588
|
+
? "暂停后不再接纳新请求,已开始的请求仍归原账结算。"
|
|
1589
|
+
: "恢复当前套餐,不发放新额度,也不重新执行原请求。",
|
|
1590
|
+
"确认套餐状态",
|
|
1591
|
+
{ confirmButtonText: "确认", cancelButtonText: "返回", type: "warning" },
|
|
1592
|
+
);
|
|
1593
|
+
} catch {
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
try {
|
|
1597
|
+
await mutate({
|
|
1598
|
+
kind: "control",
|
|
1599
|
+
path: `${billing}/accounts/${encodeURIComponent(selectedAccount.value.id)}/control`,
|
|
1600
|
+
body: {
|
|
1601
|
+
request_key: crypto.randomUUID(),
|
|
1602
|
+
expected_revision: g.revision,
|
|
1603
|
+
state: g.state === "active" ? "suspended" : "active",
|
|
1604
|
+
},
|
|
1605
|
+
});
|
|
1606
|
+
} catch (e) {
|
|
1607
|
+
detailError.value = describe(e);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
const serviceOpen = ref(false),
|
|
1611
|
+
serviceError = ref(""),
|
|
1612
|
+
serviceRevision = ref(0);
|
|
1613
|
+
const serviceDefaults = () => ({
|
|
1614
|
+
id: "",
|
|
1615
|
+
label: "",
|
|
1616
|
+
credential: "",
|
|
1617
|
+
model: "",
|
|
1618
|
+
purpose: 'chat' as 'chat'|'tool',
|
|
1619
|
+
referenceModel: '', referenceEndpoint: '',
|
|
1620
|
+
pricingKind: 'chat' as 'chat'|'image',
|
|
1621
|
+
tool: {name:'generate_image',capability:'image_generation',description:'根据用户的描述生成图片,返回生成结果;不自动修改业务数据。',outputs:['image'],parameters:[{name:'prompt',type:'string',required:true,description:'要生成的画面内容'}],adapter:'pending'} as ModelTool,
|
|
1622
|
+
providerScope: "",
|
|
1623
|
+
active: true,
|
|
1624
|
+
maxOutputTokens: 8192,
|
|
1625
|
+
contextWindowTokens: 0,
|
|
1626
|
+
modalities: "unknown",
|
|
1627
|
+
timeoutSeconds: 120,
|
|
1628
|
+
maxInputBytes: 8388608,
|
|
1629
|
+
});
|
|
1630
|
+
const serviceForm = reactive(serviceDefaults());
|
|
1631
|
+
const priceModels = ref<PriceModel[]>([]), priceEndpoints = ref<PriceEndpoint[]>([]);
|
|
1632
|
+
const pricingLoading = ref(false), endpointsLoading = ref(false), pricingError = ref(''), priceFetchedAt = ref(0), pricingStale = ref(false);
|
|
1633
|
+
let modelPriceSequence = 0, endpointPriceSequence = 0;
|
|
1634
|
+
const effectiveReferenceModel = computed(() => effectiveBillingModel(serviceForm.model, serviceForm.referenceModel));
|
|
1635
|
+
const selectedPriceEndpoint = computed(() => priceEndpoints.value.find(e => e.id === serviceForm.referenceEndpoint));
|
|
1636
|
+
function endpointPriceIssue(endpoint?: PriceEndpoint) {
|
|
1637
|
+
if (!endpoint) return '尚未取得所选参考端点的真实报价,请同步参考价格或重新选择端点。';
|
|
1638
|
+
if (endpoint.unavailable) return '所选端点的计量规则暂不支持,请选择其他端点。';
|
|
1639
|
+
const price = endpoint.pricing;
|
|
1640
|
+
if (!price?.lines?.length) return '所选参考端点未返回价格,不能保存绑定,请同步价格或选择其他端点。';
|
|
1641
|
+
if (price.source !== 'openrouter' || price.currency !== 'USD' || price.modelId !== effectiveReferenceModel.value || price.endpointId !== endpoint.id || price.lines.some(line => !line.costUsd?.trim() || !Number.isFinite(Number(line.costUsd)) || Number(line.costUsd) < 0))
|
|
1642
|
+
return '所选参考端点的价格数据无效,请重新同步价格。';
|
|
1643
|
+
return '';
|
|
1644
|
+
}
|
|
1645
|
+
const selectedPriceIssue = computed(() => !endpointsLoading.value && serviceForm.referenceEndpoint ? endpointPriceIssue(selectedPriceEndpoint.value) : '');
|
|
1646
|
+
async function loadPriceModels() {
|
|
1647
|
+
const sequence = ++modelPriceSequence; pricingLoading.value = true; pricingError.value = ''; priceModels.value = [];
|
|
1648
|
+
try {const r = await api<{items:PriceModel[];fetchedAt:number;stale:boolean}>(`${base}/pricing/models?kind=${serviceForm.pricingKind}`); if(sequence !== modelPriceSequence)return; priceModels.value = r.items; pricingStale.value = r.stale;}
|
|
1649
|
+
catch(e) {if(sequence === modelPriceSequence) pricingError.value = describe(e);}
|
|
1650
|
+
finally {if(sequence === modelPriceSequence) pricingLoading.value = false;}
|
|
1651
|
+
}
|
|
1652
|
+
async function loadPriceEndpoints(sync = false) {
|
|
1653
|
+
const sequence = ++endpointPriceSequence; priceEndpoints.value = []; priceFetchedAt.value = 0;
|
|
1654
|
+
if (!effectiveReferenceModel.value) {endpointsLoading.value = false;return;}
|
|
1655
|
+
endpointsLoading.value = true; pricingError.value = '';
|
|
1656
|
+
try {const body = {model_id:effectiveReferenceModel.value,kind:serviceForm.pricingKind};
|
|
1657
|
+
const r = await api<{items:PriceEndpoint[];fetchedAt:number;stale:boolean}>(sync ? `${base}/pricing/sync` : `${base}/pricing/endpoints?${new URLSearchParams(body)}`, sync ? {method:'POST',body:JSON.stringify(body)} : undefined);
|
|
1658
|
+
if(sequence !== endpointPriceSequence)return; priceEndpoints.value = r.items; priceFetchedAt.value = r.fetchedAt; pricingStale.value = r.stale;
|
|
1659
|
+
const ready = r.items.filter(e => !endpointPriceIssue(e));
|
|
1660
|
+
if (!serviceForm.referenceEndpoint && ready.length === 1) serviceForm.referenceEndpoint = ready[0].id;
|
|
1661
|
+
if (!r.items.length) pricingError.value = '未找到参考价格,请填写 OpenRouter 的计费模型标识。';
|
|
1662
|
+
} catch(e) {if(sequence === endpointPriceSequence) pricingError.value = describe(e);}
|
|
1663
|
+
finally {if(sequence === endpointPriceSequence) endpointsLoading.value = false;}
|
|
1664
|
+
}
|
|
1665
|
+
function changeCallingModel() { if (!serviceForm.referenceModel.trim()) changeReferenceModel(); }
|
|
1666
|
+
function changeReferenceModel() {serviceForm.referenceEndpoint = ''; void loadPriceEndpoints();}
|
|
1667
|
+
function changePurpose() {serviceForm.pricingKind = serviceForm.purpose === 'chat' ? 'chat':'image'; serviceForm.referenceModel = ''; serviceForm.referenceEndpoint = ''; void loadPriceModels(); void loadPriceEndpoints();}
|
|
1668
|
+
function changeToolCapability() {const kind = serviceForm.tool.capability; if(kind !== 'image_generation') {serviceForm.tool.adapter = 'pending';serviceForm.referenceModel = '';serviceForm.referenceEndpoint = '';void loadPriceEndpoints();} serviceForm.tool.outputs = [kind === 'video_generation' ? 'video':kind === 'speech_generation'?'audio':'image'];}
|
|
1669
|
+
const serviceCredentials = ref<ServiceCredential[]>([]),
|
|
1670
|
+
credentialsLoading = ref(false),
|
|
1671
|
+
credentialsError = ref("");
|
|
1672
|
+
const selectedServiceCredential = computed(() =>
|
|
1673
|
+
serviceCredentials.value.find((c) => c.name === serviceForm.credential),
|
|
1674
|
+
);
|
|
1675
|
+
const serviceModelOptions = computed(() => {
|
|
1676
|
+
const options = new Map<string, string>();
|
|
1677
|
+
const defaultModel = selectedServiceCredential.value?.default_model?.trim();
|
|
1678
|
+
if (defaultModel) options.set(defaultModel, `${defaultModel} · 凭证默认`);
|
|
1679
|
+
for (const service of services.value) {
|
|
1680
|
+
if (
|
|
1681
|
+
service.config.credential === serviceForm.credential &&
|
|
1682
|
+
!options.has(service.config.model)
|
|
1683
|
+
)
|
|
1684
|
+
options.set(service.config.model, `${service.config.model} · 已配置`);
|
|
1685
|
+
}
|
|
1686
|
+
if (serviceForm.model && !options.has(serviceForm.model))
|
|
1687
|
+
options.set(serviceForm.model, serviceForm.model);
|
|
1688
|
+
return [...options].map(([value, label]) => ({ value, label }));
|
|
1689
|
+
});
|
|
1690
|
+
async function loadServiceCredentials() {
|
|
1691
|
+
if (!me.can("credentials:read") || credentialsLoading.value) return;
|
|
1692
|
+
credentialsLoading.value = true;
|
|
1693
|
+
credentialsError.value = "";
|
|
1694
|
+
try {
|
|
1695
|
+
const items = await api<ServiceCredential[]>("/admin/api/credentials");
|
|
1696
|
+
serviceCredentials.value = items.filter((c) => c.kind !== "embedding");
|
|
1697
|
+
} catch {
|
|
1698
|
+
credentialsError.value = "模型凭证读取失败,请重试。";
|
|
1699
|
+
} finally {
|
|
1700
|
+
credentialsLoading.value = false;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
function onServiceCredentialChange() {
|
|
1704
|
+
serviceForm.model =
|
|
1705
|
+
selectedServiceCredential.value?.default_model?.trim() || "";
|
|
1706
|
+
// An empty scope follows the newly selected credential on save.
|
|
1707
|
+
serviceForm.providerScope = "";
|
|
1708
|
+
changeCallingModel();
|
|
1709
|
+
}
|
|
1710
|
+
const referencesOpen = ref(false),
|
|
1711
|
+
referencesLoading = ref(false),
|
|
1712
|
+
referencesError = ref("");
|
|
1713
|
+
const referenceService = ref<Service | null>(null),
|
|
1714
|
+
serviceReferences = ref<ServiceReferenceReport | null>(null);
|
|
1715
|
+
let referencesSequence = 0;
|
|
1716
|
+
async function loadServiceReferences() {
|
|
1717
|
+
const service = referenceService.value;
|
|
1718
|
+
if (!service) return;
|
|
1719
|
+
const sequence = ++referencesSequence;
|
|
1720
|
+
referencesLoading.value = true;
|
|
1721
|
+
referencesError.value = "";
|
|
1722
|
+
serviceReferences.value = null;
|
|
1723
|
+
try {
|
|
1724
|
+
const report = await api<ServiceReferenceReport>(
|
|
1725
|
+
`${base}/services/${encodeURIComponent(service.id)}/references`,
|
|
1726
|
+
);
|
|
1727
|
+
if (sequence === referencesSequence) serviceReferences.value = report;
|
|
1728
|
+
} catch (e) {
|
|
1729
|
+
if (sequence === referencesSequence) referencesError.value = describe(e);
|
|
1730
|
+
} finally {
|
|
1731
|
+
if (sequence === referencesSequence) referencesLoading.value = false;
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
async function deleteService(service: Service) {
|
|
1735
|
+
if (blocked.value) return;
|
|
1736
|
+
referenceService.value = service;
|
|
1737
|
+
referencesOpen.value = true;
|
|
1738
|
+
await loadServiceReferences();
|
|
1739
|
+
}
|
|
1740
|
+
const deletion = useUsageDeletion(describe);
|
|
1741
|
+
async function deletePlan(plan: Plan) {
|
|
1742
|
+
if (blocked.value || !canWrite.value) return;
|
|
1743
|
+
await deletion.show(`${billing}/plans/${encodeURIComponent(plan.id)}`, plan.label);
|
|
1744
|
+
}
|
|
1745
|
+
async function confirmDeletePlan() {
|
|
1746
|
+
const report = deletion.report.value;
|
|
1747
|
+
if (!report?.can_delete || deletion.loading.value || blocked.value || !canWrite.value) return;
|
|
1748
|
+
try {
|
|
1749
|
+
await mutate({ kind: "plan_delete", method: "DELETE", path: deletion.path.value,
|
|
1750
|
+
body: { request_key: crypto.randomUUID(), expected_revision: report.revision } });
|
|
1751
|
+
} catch (e) { deletion.error.value = describe(e); }
|
|
1752
|
+
}
|
|
1753
|
+
async function confirmDeleteService() {
|
|
1754
|
+
const report = serviceReferences.value;
|
|
1755
|
+
if (!report?.deletable || referencesLoading.value || blocked.value) return;
|
|
1756
|
+
try {
|
|
1757
|
+
await mutate({
|
|
1758
|
+
kind: "service_delete",
|
|
1759
|
+
method: "DELETE",
|
|
1760
|
+
path: `${base}/services/${encodeURIComponent(report.service.id)}`,
|
|
1761
|
+
body: {
|
|
1762
|
+
expected_revision: report.service.revision,
|
|
1763
|
+
request_key: crypto.randomUUID(),
|
|
1764
|
+
},
|
|
1765
|
+
});
|
|
1766
|
+
} catch (e) {
|
|
1767
|
+
referencesError.value = describe(e);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
function openReferencePlan(id: string) {
|
|
1771
|
+
const plan = plans.value.find((p) => p.id === id);
|
|
1772
|
+
if (!plan) {
|
|
1773
|
+
referencesError.value = "套餐列表已变化,请关闭抽屉并刷新后再试。";
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
referencesOpen.value = false;
|
|
1777
|
+
tab.value = "plans";
|
|
1778
|
+
openPlan(plan);
|
|
1779
|
+
}
|
|
1780
|
+
function openService(service?: Service) {
|
|
1781
|
+
serviceRevision.value = service?.revision || 0;
|
|
1782
|
+
Object.assign(
|
|
1783
|
+
serviceForm,
|
|
1784
|
+
serviceDefaults(),
|
|
1785
|
+
service
|
|
1786
|
+
? {
|
|
1787
|
+
id: service.id,
|
|
1788
|
+
label: service.label,
|
|
1789
|
+
credential: service.config.credential,
|
|
1790
|
+
model: service.config.model,
|
|
1791
|
+
purpose: service.config.purpose || 'chat',
|
|
1792
|
+
referenceModel: service.config.pricing?.modelId === service.config.model ? '' : service.config.pricing?.modelId || '',
|
|
1793
|
+
referenceEndpoint: service.config.pricing?.endpointId || '',
|
|
1794
|
+
pricingKind: service.config.pricing?.kind || (service.config.purpose === 'tool' ? 'image' : 'chat'),
|
|
1795
|
+
...(service.config.tool ? {tool: JSON.parse(JSON.stringify(service.config.tool))} : {}),
|
|
1796
|
+
providerScope: service.config.providerScope,
|
|
1797
|
+
active: service.state === "active",
|
|
1798
|
+
maxOutputTokens: service.config.maxOutputTokens,
|
|
1799
|
+
contextWindowTokens: service.config.contextWindowTokens || 0,
|
|
1800
|
+
modalities: service.config.inputModalities
|
|
1801
|
+
? service.config.inputModalities.includes("image")
|
|
1802
|
+
? "text_image"
|
|
1803
|
+
: "text"
|
|
1804
|
+
: "unknown",
|
|
1805
|
+
timeoutSeconds: service.config.timeoutMs / 1000,
|
|
1806
|
+
maxInputBytes: service.config.maxInputBytes,
|
|
1807
|
+
}
|
|
1808
|
+
: {},
|
|
1809
|
+
);
|
|
1810
|
+
serviceError.value = "";
|
|
1811
|
+
serviceOpen.value = true;
|
|
1812
|
+
void loadServiceCredentials();
|
|
1813
|
+
void loadPriceModels();
|
|
1814
|
+
void loadPriceEndpoints();
|
|
1815
|
+
}
|
|
1816
|
+
async function saveService() {
|
|
1817
|
+
serviceError.value = "";
|
|
1818
|
+
try {
|
|
1819
|
+
if (credentialsLoading.value || credentialsError.value)
|
|
1820
|
+
throw new Error("请先完成模型凭证读取。");
|
|
1821
|
+
if (me.can("credentials:read") && !selectedServiceCredential.value)
|
|
1822
|
+
throw new Error("请选择一个现有的对话模型凭证。");
|
|
1823
|
+
if (
|
|
1824
|
+
!serviceForm.id.trim() ||
|
|
1825
|
+
!serviceForm.label.trim() ||
|
|
1826
|
+
!serviceForm.credential.trim() ||
|
|
1827
|
+
!serviceForm.model.trim()
|
|
1828
|
+
)
|
|
1829
|
+
throw new Error("请填写名称、标识、现有凭证与模型。");
|
|
1830
|
+
const needsPrice = serviceForm.purpose === 'chat' || serviceForm.tool.adapter !== 'pending';
|
|
1831
|
+
if (needsPrice && (!effectiveReferenceModel.value || !serviceForm.referenceEndpoint)) throw new Error('尚未匹配可用参考价格,请检查计费模型并选择参考端点。');
|
|
1832
|
+
if (needsPrice || serviceForm.referenceModel || serviceForm.referenceEndpoint) {
|
|
1833
|
+
if (endpointsLoading.value) throw new Error('参考价格正在读取,请稍后保存。');
|
|
1834
|
+
if (!effectiveReferenceModel.value || !serviceForm.referenceEndpoint) throw new Error('请先匹配参考价格并选择参考端点。');
|
|
1835
|
+
const issue = endpointPriceIssue(selectedPriceEndpoint.value);
|
|
1836
|
+
if (issue) throw new Error(issue);
|
|
1837
|
+
}
|
|
1838
|
+
const config: Service["config"] = {
|
|
1839
|
+
purpose: serviceForm.purpose,
|
|
1840
|
+
...(effectiveReferenceModel.value && serviceForm.referenceEndpoint ? {pricing: {source:'openrouter' as const,modelId:effectiveReferenceModel.value,endpointId:serviceForm.referenceEndpoint,kind:serviceForm.pricingKind}} : {}),
|
|
1841
|
+
...(serviceForm.purpose === 'tool' ? {tool: JSON.parse(JSON.stringify(serviceForm.tool))} : {}),
|
|
1842
|
+
credential: serviceForm.credential.trim(),
|
|
1843
|
+
model: serviceForm.model.trim(),
|
|
1844
|
+
providerScope:
|
|
1845
|
+
serviceForm.providerScope.trim() || serviceForm.credential.trim(),
|
|
1846
|
+
maxOutputTokens: serviceForm.maxOutputTokens,
|
|
1847
|
+
maxInputBytes: serviceForm.maxInputBytes,
|
|
1848
|
+
timeoutMs: serviceForm.timeoutSeconds * 1000,
|
|
1849
|
+
};
|
|
1850
|
+
if (serviceForm.contextWindowTokens > 0)
|
|
1851
|
+
config.contextWindowTokens = serviceForm.contextWindowTokens;
|
|
1852
|
+
if (serviceForm.modalities !== "unknown")
|
|
1853
|
+
config.inputModalities =
|
|
1854
|
+
serviceForm.modalities === "text_image" ? ["text", "image"] : ["text"];
|
|
1855
|
+
await mutate({
|
|
1856
|
+
kind: "service",
|
|
1857
|
+
path: `${base}/services`,
|
|
1858
|
+
body: {
|
|
1859
|
+
id: serviceForm.id.trim(),
|
|
1860
|
+
label: serviceForm.label.trim(),
|
|
1861
|
+
expected_revision: serviceRevision.value,
|
|
1862
|
+
state: serviceForm.active ? "active" : "suspended",
|
|
1863
|
+
config,
|
|
1864
|
+
},
|
|
1865
|
+
});
|
|
1866
|
+
} catch (e) {
|
|
1867
|
+
serviceError.value = describe(e);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
onMounted(() => {
|
|
1871
|
+
try {
|
|
1872
|
+
const stored = JSON.parse(sessionStorage.getItem(pendingKey()) || "null");
|
|
1873
|
+
if (stored) {
|
|
1874
|
+
if (
|
|
1875
|
+
typeof stored.path === "string" &&
|
|
1876
|
+
(stored.kind !== "reset" || ((stored.method === undefined || stored.method === "POST") && /^\/admin\/api\/usage\/billing\/accounts\/[A-Za-z0-9_.:-]+\/reset$/.test(stored.path))) &&
|
|
1877
|
+
(stored.kind !== "plan_delete" || (stored.method === "DELETE" && /^\/admin\/api\/usage\/billing\/plans\/(?:[A-Za-z0-9_.:-]|%3[aA])+$/.test(stored.path))) &&
|
|
1878
|
+
(stored.path.startsWith(billing + "/") ||
|
|
1879
|
+
stored.path === `${base}/services` ||
|
|
1880
|
+
(stored.kind === "service_delete" &&
|
|
1881
|
+
stored.method === "DELETE" &&
|
|
1882
|
+
/^\/admin\/api\/usage\/services\/(?:[A-Za-z0-9_.:-]|%3[aA])+$/.test(
|
|
1883
|
+
stored.path,
|
|
1884
|
+
))) &&
|
|
1885
|
+
stored.body &&
|
|
1886
|
+
["plan", "grant", "control", "reset", "service", "service_delete", "plan_delete"].includes(
|
|
1887
|
+
stored.kind,
|
|
1888
|
+
)
|
|
1889
|
+
)
|
|
1890
|
+
pending.value = stored;
|
|
1891
|
+
else {
|
|
1892
|
+
storageFailed.value = true;
|
|
1893
|
+
error.value = "原保存请求无法识别,请先核对记录。";
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
} catch {
|
|
1897
|
+
storageFailed.value = true;
|
|
1898
|
+
error.value = "无法读取原保存请求,请恢复会话存储后刷新。";
|
|
1899
|
+
}
|
|
1900
|
+
void load();
|
|
1901
|
+
});
|
|
1902
|
+
</script>
|
|
1903
|
+
|
|
1904
|
+
<style scoped>
|
|
1905
|
+
.credential-create-link {
|
|
1906
|
+
display: block;
|
|
1907
|
+
color: var(--el-color-primary);
|
|
1908
|
+
line-height: 32px;
|
|
1909
|
+
text-decoration: none;
|
|
1910
|
+
}
|
|
1911
|
+
.credential-create-link:hover {
|
|
1912
|
+
color: var(--el-color-primary-light-3);
|
|
1913
|
+
}
|
|
1914
|
+
.tool-parameter {display:grid;grid-template-columns:1fr 100px 70px 50px;gap:8px;margin:12px 0;}
|
|
1915
|
+
.tool-parameter > :last-child {grid-column:1 / -1;}
|
|
1916
|
+
.billing-page {
|
|
1917
|
+
min-width: 0;
|
|
1918
|
+
}
|
|
1919
|
+
.billing-page :deep(.el-card__body) {
|
|
1920
|
+
display: grid;
|
|
1921
|
+
grid-template-columns: minmax(0, 1fr);
|
|
1922
|
+
gap: 16px;
|
|
1923
|
+
min-width: 0;
|
|
1924
|
+
}
|
|
1925
|
+
.page-title {
|
|
1926
|
+
display: flex;
|
|
1927
|
+
align-items: center;
|
|
1928
|
+
gap: 5px;
|
|
1929
|
+
}
|
|
1930
|
+
.page-heading,
|
|
1931
|
+
.section-heading,
|
|
1932
|
+
.actions,
|
|
1933
|
+
.card-top,
|
|
1934
|
+
.card-bottom,
|
|
1935
|
+
.form-footer,
|
|
1936
|
+
.dialog-footer {
|
|
1937
|
+
display: flex;
|
|
1938
|
+
align-items: center;
|
|
1939
|
+
justify-content: space-between;
|
|
1940
|
+
gap: 16px;
|
|
1941
|
+
}
|
|
1942
|
+
.preview-eyebrow {
|
|
1943
|
+
font-size: 11px;
|
|
1944
|
+
letter-spacing: 1.6px;
|
|
1945
|
+
color: var(--el-color-primary);
|
|
1946
|
+
}
|
|
1947
|
+
h2 {
|
|
1948
|
+
font-size: 20px;
|
|
1949
|
+
margin: 0 0 7px;
|
|
1950
|
+
}
|
|
1951
|
+
h3 {
|
|
1952
|
+
font-size: 16px;
|
|
1953
|
+
margin: 0 0 8px;
|
|
1954
|
+
}
|
|
1955
|
+
.actions {
|
|
1956
|
+
justify-content: flex-start;
|
|
1957
|
+
flex-wrap: wrap;
|
|
1958
|
+
}
|
|
1959
|
+
.actions :deep(.el-button + .el-button) {
|
|
1960
|
+
margin-left: 0;
|
|
1961
|
+
}
|
|
1962
|
+
.section-heading {
|
|
1963
|
+
margin-bottom: 24px;
|
|
1964
|
+
}
|
|
1965
|
+
.section-tabs :deep(.el-tabs__item) {
|
|
1966
|
+
font-size: 14px;
|
|
1967
|
+
}
|
|
1968
|
+
.panel {
|
|
1969
|
+
border: 1px solid var(--el-border-color-light);
|
|
1970
|
+
background: var(--el-fill-color-blank);
|
|
1971
|
+
}
|
|
1972
|
+
.muted,
|
|
1973
|
+
.footnote {
|
|
1974
|
+
font-size: 12px;
|
|
1975
|
+
line-height: 1.8;
|
|
1976
|
+
color: var(--el-text-color-secondary);
|
|
1977
|
+
}
|
|
1978
|
+
.mono,
|
|
1979
|
+
code {
|
|
1980
|
+
overflow-wrap: anywhere;
|
|
1981
|
+
}
|
|
1982
|
+
.model-grid {
|
|
1983
|
+
display: grid;
|
|
1984
|
+
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
|
1985
|
+
gap: 18px;
|
|
1986
|
+
}
|
|
1987
|
+
.model-card {
|
|
1988
|
+
padding: 24px;
|
|
1989
|
+
min-width: 0;
|
|
1990
|
+
}
|
|
1991
|
+
.model-card .card-top {
|
|
1992
|
+
margin-bottom: 12px;
|
|
1993
|
+
align-items: flex-start;
|
|
1994
|
+
}
|
|
1995
|
+
.model-card h3 {
|
|
1996
|
+
margin: 0;
|
|
1997
|
+
min-width: 0;
|
|
1998
|
+
overflow-wrap: anywhere;
|
|
1999
|
+
}
|
|
2000
|
+
.model-card .card-top :deep(.el-tag) {
|
|
2001
|
+
flex-shrink: 0;
|
|
2002
|
+
}
|
|
2003
|
+
.card-bottom {
|
|
2004
|
+
justify-content: flex-end;
|
|
2005
|
+
border-top: 1px solid var(--el-border-color-lighter);
|
|
2006
|
+
padding-top: 17px;
|
|
2007
|
+
margin-top: 20px;
|
|
2008
|
+
gap: 8px;
|
|
2009
|
+
}
|
|
2010
|
+
.principle {
|
|
2011
|
+
margin-top: 28px;
|
|
2012
|
+
padding: 22px 25px;
|
|
2013
|
+
border-left: 3px solid var(--el-color-primary);
|
|
2014
|
+
}
|
|
2015
|
+
.principle p,
|
|
2016
|
+
.pending p {
|
|
2017
|
+
font-size: 13px;
|
|
2018
|
+
color: var(--el-text-color-secondary);
|
|
2019
|
+
line-height: 1.85;
|
|
2020
|
+
margin: 7px 0 0;
|
|
2021
|
+
}
|
|
2022
|
+
.editor-layout {
|
|
2023
|
+
display: grid;
|
|
2024
|
+
grid-template-columns: minmax(0, 1fr) 315px;
|
|
2025
|
+
align-items: start;
|
|
2026
|
+
gap: 24px;
|
|
2027
|
+
max-width: 1440px;
|
|
2028
|
+
}
|
|
2029
|
+
.plan-editor-heading {
|
|
2030
|
+
display: flex;
|
|
2031
|
+
align-items: center;
|
|
2032
|
+
gap: 12px;
|
|
2033
|
+
margin-bottom: 20px;
|
|
2034
|
+
}
|
|
2035
|
+
.plan-editor-heading h2 {
|
|
2036
|
+
margin: 0;
|
|
2037
|
+
font-size: 18px;
|
|
2038
|
+
line-height: 32px;
|
|
2039
|
+
}
|
|
2040
|
+
.plan-form {
|
|
2041
|
+
display: grid;
|
|
2042
|
+
gap: 17px;
|
|
2043
|
+
min-width: 0;
|
|
2044
|
+
}
|
|
2045
|
+
.form-section {
|
|
2046
|
+
padding: 26px;
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
|
|
2050
|
+
|
|
2051
|
+
|
|
2052
|
+
.form-grid {
|
|
2053
|
+
display: grid;
|
|
2054
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
2055
|
+
gap: 0 20px;
|
|
2056
|
+
}
|
|
2057
|
+
.plan-settings-grid {
|
|
2058
|
+
gap: 22px 24px;
|
|
2059
|
+
}
|
|
2060
|
+
.plan-settings-grid :deep(.el-form-item) {
|
|
2061
|
+
margin-bottom: 0;
|
|
2062
|
+
min-width: 0;
|
|
2063
|
+
}
|
|
2064
|
+
.plan-settings-grid :deep(.el-form-item__content) {
|
|
2065
|
+
min-width: 0;
|
|
2066
|
+
}
|
|
2067
|
+
.plan-settings-grid :deep(.el-input-number),
|
|
2068
|
+
.plan-settings-grid :deep(.el-select) {
|
|
2069
|
+
width: 100%;
|
|
2070
|
+
min-width: 0;
|
|
2071
|
+
}
|
|
2072
|
+
.plan-settings-grid :deep(.el-input__inner) {
|
|
2073
|
+
text-align: left;
|
|
2074
|
+
}
|
|
2075
|
+
.billing-page :deep(.el-select) {
|
|
2076
|
+
width: 100%;
|
|
2077
|
+
}
|
|
2078
|
+
.billing-page :deep(.el-form-item__label) {
|
|
2079
|
+
font-size: 13px;
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
|
|
2083
|
+
|
|
2084
|
+
|
|
2085
|
+
|
|
2086
|
+
.model-choices {
|
|
2087
|
+
display: grid;
|
|
2088
|
+
gap: 8px;
|
|
2089
|
+
margin-bottom: 14px;
|
|
2090
|
+
/* CheckboxGroup resets line-height to zero; quote text needs normal flow. */
|
|
2091
|
+
font-size: 14px;
|
|
2092
|
+
line-height: 1.6;
|
|
2093
|
+
}
|
|
2094
|
+
.model-choices :deep(.el-checkbox) {
|
|
2095
|
+
height: auto;
|
|
2096
|
+
padding: 12px 14px;
|
|
2097
|
+
margin-right: 0;
|
|
2098
|
+
border: 1px solid var(--el-border-color-lighter);
|
|
2099
|
+
}
|
|
2100
|
+
.model-choice-row {
|
|
2101
|
+
display: flex;
|
|
2102
|
+
align-items: flex-start;
|
|
2103
|
+
flex-wrap: wrap;
|
|
2104
|
+
gap: 10px 16px;
|
|
2105
|
+
padding: 12px 14px;
|
|
2106
|
+
border: 1px solid var(--el-border-color-lighter);
|
|
2107
|
+
}
|
|
2108
|
+
.model-choice-row :deep(.el-checkbox) {
|
|
2109
|
+
flex: 1 1 150px;
|
|
2110
|
+
min-width: 0;
|
|
2111
|
+
border: 0;
|
|
2112
|
+
padding: 0;
|
|
2113
|
+
}
|
|
2114
|
+
.model-choice-row > .el-button {
|
|
2115
|
+
flex-shrink: 0;
|
|
2116
|
+
}
|
|
2117
|
+
.model-estimate {
|
|
2118
|
+
flex: 2 1 260px;
|
|
2119
|
+
min-width: 0;
|
|
2120
|
+
display: grid;
|
|
2121
|
+
gap: 10px;
|
|
2122
|
+
font-size: 12px;
|
|
2123
|
+
line-height: 1.6;
|
|
2124
|
+
overflow-wrap: anywhere;
|
|
2125
|
+
}
|
|
2126
|
+
.estimate-scenario { display: grid; gap: 4px; }
|
|
2127
|
+
.model-estimate strong { color: var(--el-color-primary); font-size: 15px; line-height: 1.5; }
|
|
2128
|
+
.model-choices .model-estimate small { margin-top: 0; line-height: 1.6; }
|
|
2129
|
+
.model-estimate-heading { display: block; color: var(--el-text-color-secondary); font-weight: 400; font-size: 12px; margin-top: 5px; }
|
|
2130
|
+
.model-choices .quote-source { font-size: 10px; }
|
|
2131
|
+
.reference-match { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--el-text-color-secondary); font-size: 12px; margin-bottom: 12px; overflow-wrap: anywhere; }
|
|
2132
|
+
.service-warning,
|
|
2133
|
+
.model-choices small.service-warning {
|
|
2134
|
+
color: var(--el-color-warning-dark-2);
|
|
2135
|
+
font-size: 12px;
|
|
2136
|
+
line-height: 1.6;
|
|
2137
|
+
}
|
|
2138
|
+
.reference-endpoint-field :deep(.el-form-item__label) {
|
|
2139
|
+
width: 100%;
|
|
2140
|
+
}
|
|
2141
|
+
.reference-endpoint-label {
|
|
2142
|
+
display: flex;
|
|
2143
|
+
justify-content: space-between;
|
|
2144
|
+
align-items: center;
|
|
2145
|
+
width: 100%;
|
|
2146
|
+
}
|
|
2147
|
+
.model-choices :deep(.el-checkbox__label) {
|
|
2148
|
+
white-space: normal;
|
|
2149
|
+
line-height: 1.5;
|
|
2150
|
+
}
|
|
2151
|
+
.model-choices small {
|
|
2152
|
+
display: block;
|
|
2153
|
+
color: var(--el-text-color-secondary);
|
|
2154
|
+
font-size: 11px;
|
|
2155
|
+
margin-top: 4px;
|
|
2156
|
+
overflow-wrap: anywhere;
|
|
2157
|
+
}
|
|
2158
|
+
.duration-field {
|
|
2159
|
+
display: grid;
|
|
2160
|
+
grid-template-columns: minmax(0, 1fr) 110px;
|
|
2161
|
+
gap: 10px;
|
|
2162
|
+
align-items: center;
|
|
2163
|
+
width: 100%;
|
|
2164
|
+
}
|
|
2165
|
+
.duration-field :deep(.el-input-number) {
|
|
2166
|
+
width: 100%;
|
|
2167
|
+
min-width: 60px;
|
|
2168
|
+
}
|
|
2169
|
+
.duration-field :deep(.el-select) {
|
|
2170
|
+
width: 100%;
|
|
2171
|
+
}
|
|
2172
|
+
.duration-field > :only-child {
|
|
2173
|
+
grid-column: 1 / -1;
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
|
|
2177
|
+
.advanced summary,
|
|
2178
|
+
.service-advanced summary {
|
|
2179
|
+
display: flex;
|
|
2180
|
+
align-items: center;
|
|
2181
|
+
gap: 8px;
|
|
2182
|
+
list-style: none;
|
|
2183
|
+
cursor: pointer;
|
|
2184
|
+
font-size: 13px;
|
|
2185
|
+
}
|
|
2186
|
+
.advanced summary::-webkit-details-marker,
|
|
2187
|
+
.service-advanced summary::-webkit-details-marker {
|
|
2188
|
+
display: none;
|
|
2189
|
+
}
|
|
2190
|
+
.advanced summary::marker,
|
|
2191
|
+
.service-advanced summary::marker {
|
|
2192
|
+
content: "";
|
|
2193
|
+
}
|
|
2194
|
+
.advanced summary::before,
|
|
2195
|
+
.service-advanced summary::before {
|
|
2196
|
+
content: "";
|
|
2197
|
+
flex: 0 0 10px;
|
|
2198
|
+
width: 10px;
|
|
2199
|
+
height: 10px;
|
|
2200
|
+
background: currentColor;
|
|
2201
|
+
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1024 1024'%3E%3Cpath d='M0.085333 239.36L512 784.64l511.914667-545.28z'/%3E%3C/svg%3E") center / contain no-repeat;
|
|
2202
|
+
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1024 1024'%3E%3Cpath d='M0.085333 239.36L512 784.64l511.914667-545.28z'/%3E%3C/svg%3E") center / contain no-repeat;
|
|
2203
|
+
transform: rotate(-90deg);
|
|
2204
|
+
}
|
|
2205
|
+
.advanced details[open] > summary::before,
|
|
2206
|
+
.service-advanced[open] > summary::before {
|
|
2207
|
+
transform: rotate(0);
|
|
2208
|
+
}
|
|
2209
|
+
.advanced summary .muted {
|
|
2210
|
+
margin-left: 0;
|
|
2211
|
+
}
|
|
2212
|
+
.advanced-content {
|
|
2213
|
+
padding-top: 22px;
|
|
2214
|
+
}
|
|
2215
|
+
.preview {
|
|
2216
|
+
position: sticky;
|
|
2217
|
+
top: 22px;
|
|
2218
|
+
padding: 27px 24px;
|
|
2219
|
+
border-top: 3px solid var(--el-color-primary);
|
|
2220
|
+
}
|
|
2221
|
+
.preview h3 {
|
|
2222
|
+
font-size: 19px;
|
|
2223
|
+
margin: 25px 0 20px;
|
|
2224
|
+
}
|
|
2225
|
+
.preview-amount {
|
|
2226
|
+
font-size: 38px;
|
|
2227
|
+
line-height: 1.1;
|
|
2228
|
+
letter-spacing: -1px;
|
|
2229
|
+
font-weight: 650;
|
|
2230
|
+
overflow-wrap: anywhere;
|
|
2231
|
+
}
|
|
2232
|
+
.preview-amount small {
|
|
2233
|
+
font-size: 17px;
|
|
2234
|
+
font-weight: 500;
|
|
2235
|
+
letter-spacing: 0;
|
|
2236
|
+
margin-left: 8px;
|
|
2237
|
+
}
|
|
2238
|
+
.customer-preview {
|
|
2239
|
+
padding: 24px;
|
|
2240
|
+
border-top: 3px solid var(--el-color-primary);
|
|
2241
|
+
}
|
|
2242
|
+
.customer-amount-row {
|
|
2243
|
+
display: flex;
|
|
2244
|
+
gap: 20px;
|
|
2245
|
+
align-items: center;
|
|
2246
|
+
justify-content: space-between;
|
|
2247
|
+
margin: 16px 0 22px;
|
|
2248
|
+
}
|
|
2249
|
+
.operator-accounting {
|
|
2250
|
+
display: grid;
|
|
2251
|
+
gap: 20px;
|
|
2252
|
+
border-top: 1px solid var(--el-border-color-light);
|
|
2253
|
+
padding-top: 24px;
|
|
2254
|
+
}
|
|
2255
|
+
.preview-unit {
|
|
2256
|
+
color: var(--el-text-color-secondary);
|
|
2257
|
+
margin: 10px 0 26px;
|
|
2258
|
+
}
|
|
2259
|
+
.preview-rule {
|
|
2260
|
+
padding: 13px 0;
|
|
2261
|
+
border-top: 1px solid var(--el-border-color-lighter);
|
|
2262
|
+
display: flex;
|
|
2263
|
+
align-items: start;
|
|
2264
|
+
justify-content: space-between;
|
|
2265
|
+
gap: 12px;
|
|
2266
|
+
font-size: 12px;
|
|
2267
|
+
}
|
|
2268
|
+
.preview-rule > span {
|
|
2269
|
+
color: var(--el-text-color-secondary);
|
|
2270
|
+
flex-shrink: 0;
|
|
2271
|
+
}
|
|
2272
|
+
.preview-rule b {
|
|
2273
|
+
font-weight: 500;
|
|
2274
|
+
text-align: right;
|
|
2275
|
+
}
|
|
2276
|
+
.preview-models {
|
|
2277
|
+
padding-top: 19px;
|
|
2278
|
+
}
|
|
2279
|
+
.tags {
|
|
2280
|
+
display: flex;
|
|
2281
|
+
flex-wrap: wrap;
|
|
2282
|
+
gap: 7px;
|
|
2283
|
+
margin-top: 10px;
|
|
2284
|
+
}
|
|
2285
|
+
.preview ul {
|
|
2286
|
+
list-style: none;
|
|
2287
|
+
padding: 18px 0 0;
|
|
2288
|
+
margin: 20px 0 0;
|
|
2289
|
+
border-top: 1px solid var(--el-border-color-lighter);
|
|
2290
|
+
}
|
|
2291
|
+
.preview li {
|
|
2292
|
+
position: relative;
|
|
2293
|
+
padding: 0 0 12px 18px;
|
|
2294
|
+
font-size: 12px;
|
|
2295
|
+
line-height: 1.8;
|
|
2296
|
+
}
|
|
2297
|
+
.preview li::before {
|
|
2298
|
+
content: "✓";
|
|
2299
|
+
position: absolute;
|
|
2300
|
+
left: 0;
|
|
2301
|
+
color: var(--el-color-primary);
|
|
2302
|
+
}
|
|
2303
|
+
.preview-note {
|
|
2304
|
+
font-size: 11px;
|
|
2305
|
+
line-height: 1.8;
|
|
2306
|
+
color: var(--el-text-color-secondary);
|
|
2307
|
+
margin: 6px 0 0;
|
|
2308
|
+
}
|
|
2309
|
+
.form-footer {
|
|
2310
|
+
padding: 5px 0 12px;
|
|
2311
|
+
}
|
|
2312
|
+
.pending {
|
|
2313
|
+
padding: 20px;
|
|
2314
|
+
border-color: var(--el-color-warning);
|
|
2315
|
+
}
|
|
2316
|
+
.pending .el-button {
|
|
2317
|
+
margin-top: 14px;
|
|
2318
|
+
}
|
|
2319
|
+
.more {
|
|
2320
|
+
text-align: center;
|
|
2321
|
+
padding: 18px;
|
|
2322
|
+
}
|
|
2323
|
+
.account-detail {
|
|
2324
|
+
display: grid;
|
|
2325
|
+
gap: 20px;
|
|
2326
|
+
}
|
|
2327
|
+
.account-detail .section-heading {
|
|
2328
|
+
margin: 0;
|
|
2329
|
+
}
|
|
2330
|
+
.metrics {
|
|
2331
|
+
display: grid;
|
|
2332
|
+
grid-template-columns: repeat(3, 1fr);
|
|
2333
|
+
gap: 1px;
|
|
2334
|
+
border: 1px solid var(--el-border-color-light);
|
|
2335
|
+
}
|
|
2336
|
+
.metrics > div {
|
|
2337
|
+
padding: 22px;
|
|
2338
|
+
display: grid;
|
|
2339
|
+
gap: 10px;
|
|
2340
|
+
}
|
|
2341
|
+
.metrics span,
|
|
2342
|
+
.metrics small {
|
|
2343
|
+
font-size: 12px;
|
|
2344
|
+
color: var(--el-text-color-secondary);
|
|
2345
|
+
}
|
|
2346
|
+
.metrics strong {
|
|
2347
|
+
font-size: 27px;
|
|
2348
|
+
letter-spacing: -0.6px;
|
|
2349
|
+
overflow-wrap: anywhere;
|
|
2350
|
+
}
|
|
2351
|
+
.grant-details {
|
|
2352
|
+
padding: 22px;
|
|
2353
|
+
}
|
|
2354
|
+
.grant-details > div {
|
|
2355
|
+
display: flex;
|
|
2356
|
+
justify-content: space-between;
|
|
2357
|
+
gap: 20px;
|
|
2358
|
+
margin-bottom: 14px;
|
|
2359
|
+
font-size: 13px;
|
|
2360
|
+
}
|
|
2361
|
+
.grant-details span {
|
|
2362
|
+
color: var(--el-text-color-secondary);
|
|
2363
|
+
flex-shrink: 0;
|
|
2364
|
+
}
|
|
2365
|
+
.grant-details b {
|
|
2366
|
+
font-weight: 500;
|
|
2367
|
+
text-align: right;
|
|
2368
|
+
overflow-wrap: anywhere;
|
|
2369
|
+
}
|
|
2370
|
+
.grant-preview {
|
|
2371
|
+
padding: 18px;
|
|
2372
|
+
margin: 20px 0;
|
|
2373
|
+
}
|
|
2374
|
+
.grant-preview p {
|
|
2375
|
+
font-size: 13px;
|
|
2376
|
+
line-height: 1.8;
|
|
2377
|
+
margin: 8px 0;
|
|
2378
|
+
}
|
|
2379
|
+
.account-models {
|
|
2380
|
+
display: grid;
|
|
2381
|
+
gap: 6px;
|
|
2382
|
+
text-align: right;
|
|
2383
|
+
}
|
|
2384
|
+
.drawer-actions {
|
|
2385
|
+
display: flex;
|
|
2386
|
+
justify-content: flex-end;
|
|
2387
|
+
gap: 10px;
|
|
2388
|
+
flex-wrap: wrap;
|
|
2389
|
+
}
|
|
2390
|
+
.usage-config-drawer :deep(.el-drawer__footer) {
|
|
2391
|
+
border-top: 1px solid var(--el-border-color-light);
|
|
2392
|
+
padding: 16px 20px;
|
|
2393
|
+
}
|
|
2394
|
+
.usage-config-drawer .form-grid {
|
|
2395
|
+
grid-template-columns: minmax(0, 1fr);
|
|
2396
|
+
}
|
|
2397
|
+
.billing-notice {
|
|
2398
|
+
display: flex;
|
|
2399
|
+
align-items: center;
|
|
2400
|
+
gap: 8px;
|
|
2401
|
+
margin-bottom: 20px;
|
|
2402
|
+
}
|
|
2403
|
+
.billing-notice > .el-alert {
|
|
2404
|
+
flex: 1;
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
.service-advanced {
|
|
2408
|
+
margin: 24px 0;
|
|
2409
|
+
}
|
|
2410
|
+
.service-advanced > .form-grid {
|
|
2411
|
+
margin-top: 16px;
|
|
2412
|
+
}
|
|
2413
|
+
@media (max-width: 1160px) {
|
|
2414
|
+
.editor-layout {
|
|
2415
|
+
grid-template-columns: minmax(0, 1fr) 280px;
|
|
2416
|
+
gap: 18px;
|
|
2417
|
+
}
|
|
2418
|
+
.form-section {
|
|
2419
|
+
padding: 21px;
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
}
|
|
2423
|
+
@media (max-width: 940px) {
|
|
2424
|
+
.editor-layout {
|
|
2425
|
+
grid-template-columns: 1fr;
|
|
2426
|
+
}
|
|
2427
|
+
.preview {
|
|
2428
|
+
position: static;
|
|
2429
|
+
}
|
|
2430
|
+
.page-heading,
|
|
2431
|
+
.section-heading {
|
|
2432
|
+
align-items: flex-start;
|
|
2433
|
+
flex-wrap: wrap;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
@media (max-width: 600px) {
|
|
2437
|
+
.form-grid,
|
|
2438
|
+
.metrics,
|
|
2439
|
+
.model-grid {
|
|
2440
|
+
grid-template-columns: 1fr;
|
|
2441
|
+
}
|
|
2442
|
+
.form-section {
|
|
2443
|
+
padding: 20px 17px;
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
.form-footer {
|
|
2447
|
+
align-items: flex-start;
|
|
2448
|
+
flex-wrap: wrap;
|
|
2449
|
+
}
|
|
2450
|
+
.preview-amount {
|
|
2451
|
+
font-size: 33px;
|
|
2452
|
+
}
|
|
2453
|
+
.grant-details > div {
|
|
2454
|
+
flex-direction: column;
|
|
2455
|
+
gap: 5px;
|
|
2456
|
+
}
|
|
2457
|
+
.account-models {
|
|
2458
|
+
text-align: left;
|
|
2459
|
+
}
|
|
2460
|
+
.grant-details b {
|
|
2461
|
+
text-align: left;
|
|
2462
|
+
}
|
|
2463
|
+
.metrics > div {
|
|
2464
|
+
padding: 15px 20px;
|
|
2465
|
+
}
|
|
2466
|
+
.page-heading .actions {
|
|
2467
|
+
gap: 8px;
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
</style>
|