diff --git a/backend/src/api/admin/router.rs b/backend/src/api/admin/router.rs index fcb31bc6f..fd69b3ae0 100644 --- a/backend/src/api/admin/router.rs +++ b/backend/src/api/admin/router.rs @@ -46,7 +46,7 @@ pub fn router() -> Router { .route("/api/admin/settings", get(settings).post(update_settings)) .route( "/api/admin/settings/admin-api-key", - get(admin_api_key_status).delete(delete_admin_api_key), + get(admin_api_key_status).post(delete_admin_api_key), ) .route( "/api/admin/settings/admin-api-key/regenerate", diff --git a/backend/src/api/admin/settings_routes.rs b/backend/src/api/admin/settings_routes.rs index c313419ca..67f9ab5f6 100644 --- a/backend/src/api/admin/settings_routes.rs +++ b/backend/src/api/admin/settings_routes.rs @@ -115,7 +115,7 @@ pub(crate) async fn regenerate_admin_api_key( )) } -/// `DELETE /api/admin/settings/admin-api-key` +/// `POST /api/admin/settings/admin-api-key` pub(crate) async fn delete_admin_api_key( State(state): State, _auth: AdminAuth, diff --git a/backend/tests/api/admin/settings_routes/routes.rs b/backend/tests/api/admin/settings_routes/routes.rs index 1ec3e1d84..864ac58ba 100644 --- a/backend/tests/api/admin/settings_routes/routes.rs +++ b/backend/tests/api/admin/settings_routes/routes.rs @@ -209,7 +209,7 @@ async fn admin_settings_admin_api_key_should_delete_and_revoke_access() { .clone() .oneshot( Request::builder() - .method("DELETE") + .method("POST") .uri("/api/admin/settings/admin-api-key") .header("cookie", "cpr_admin_session=session_1") .header("x-request-id", "req_settings_admin_key_delete") diff --git a/docs/architecture.md b/docs/architecture.md index 04e1ea7a6..97806bd3c 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -513,13 +513,13 @@ Vue 管理端位于 `frontend/src`,使用 Vue Router、Pinia 和按领域划 ```text view / component -> feature composable / explicit Pinia store - -> api module / api stream adapter - -> request transport + -> api module -> request transport + -> VueUse SSE ``` -- `api/request.ts` 返回 `unknown`,endpoint module 使用 Zod 在 HTTP 边界解析;不使用类型断言代替运行时校验。 +- `api/request.ts` 只负责请求与管理端 envelope 解包;endpoint module 不声明响应 DTO,直接透传 `data` / `params`,管理端写操作统一使用 `POST`。 - 401 处理由 `main.ts` 注入,request transport 不依赖 router 或 store。 -- EventSource、URL 和事件解析只存在于 `api/streams`;feature 只消费 typed event 和可关闭 stream handle。 +- SSE 由对应 feature composable / Pinia store 使用 VueUse `useEventSource` 管理,连接随 feature 生命周期关闭,不保留手写 `api/streams` transport。 - 账号、API Key、usage 列表使用 latest-request-wins 的 `usePagedQuery`,页内选择统一由 `usePageSelection` 管理。 - system update 是 layout 持有的单例 Pinia 状态;桌面和移动 Sidebar 只发出打开意图,不挂载或清理共享 stream。 - API 结果、composable 返回值和局部 view model 默认依赖 TypeScript 推导;显式类型只用于 Props/Emits、领域判别联合和可复用泛型边界。 diff --git a/frontend/eslint.config.mjs b/frontend/eslint.config.mjs deleted file mode 100644 index 3ecc107d5..000000000 --- a/frontend/eslint.config.mjs +++ /dev/null @@ -1,65 +0,0 @@ -import antfu from '@antfu/eslint-config' - -export default antfu( - { - type: 'app', - ignores: ['dist', 'coverage', 'pnpm-workspace.yaml'], - formatters: { - css: true, - html: true, - markdown: 'prettier', - }, - stylistic: { - indent: 2, - quotes: 'single', - }, - typescript: true, - vue: { - a11y: true, - }, - }, - { - rules: { - 'ts/no-use-before-define': 'off', - 'vue/custom-event-name-casing': 'off', - 'vue/no-unused-refs': 'off', - 'vue-a11y/click-events-have-key-events': 'off', - 'vue-a11y/label-has-for': 'off', - 'vue-a11y/mouse-events-have-key-events': 'off', - 'vue-a11y/no-redundant-roles': 'off', - 'vue-a11y/no-static-element-interactions': 'off', - }, - }, - { - files: ['src/api/**/*.ts'], - rules: { - 'no-restricted-imports': [ - 'error', - { - patterns: [ - { - group: ['@/layout/**', '@/router/**', '@/stores/**', '@/views/**'], - message: 'API transport 和 adapter 不能反向依赖 UI、路由或状态层。', - }, - ], - }, - ], - }, - }, - { - files: ['src/composables/**/*.ts', 'src/layout/**/*.vue', 'src/stores/**/*.ts', 'src/views/**'], - rules: { - 'no-restricted-imports': [ - 'error', - { - paths: [ - { - name: 'axios', - message: 'HTTP transport 只能由 src/api 持有。', - }, - ], - }, - ], - }, - }, -) diff --git a/frontend/eslint.config.ts b/frontend/eslint.config.ts new file mode 100644 index 000000000..b35d3fbbe --- /dev/null +++ b/frontend/eslint.config.ts @@ -0,0 +1,21 @@ +import antfu from '@antfu/eslint-config' + +export default antfu( + { + type: 'app', + ignores: ['dist', 'coverage', 'pnpm-workspace.yaml'], + formatters: { + css: true, + html: true, + markdown: 'prettier', + }, + stylistic: { + indent: 2, + quotes: 'single', + }, + typescript: true, + vue: { + a11y: true, + }, + }, +) diff --git a/frontend/package.json b/frontend/package.json index d4fe819cd..3e3833183 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,8 +10,7 @@ "lint": "eslint .", "lint:fix": "eslint . --fix", "format": "pnpm run lint:fix", - "format:check": "pnpm run lint", - "test": "vitest run" + "format:check": "pnpm run lint" }, "dependencies": { "@fontsource-variable/inter": "^5.2.8", @@ -28,8 +27,7 @@ "pinia": "^3.0.4", "pinia-plugin-persistedstate": "^4.7.1", "vue": "^3.5.39", - "vue-router": "^5.1.0", - "zod": "^4.4.3" + "vue-router": "^5.1.0" }, "devDependencies": { "@antfu/eslint-config": "^9.1.0", @@ -43,7 +41,6 @@ "tailwindcss": "^4.3.2", "typescript": "^6.0.3", "vite": "^8.1.4", - "vitest": "^4.1.10", "vue-tsc": "^3.3.7" } } diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index f7e65f845..a021dd357 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -1,7 +1,7 @@ lockfileVersion: '9.0' settings: - autoInstallPeers: true + autoInstallPeers: false excludeLinksFromLockfile: false importers: @@ -53,13 +53,10 @@ importers: vue-router: specifier: ^5.1.0 version: 5.1.0(@vue/compiler-sfc@3.5.39)(pinia@3.0.4(typescript@6.0.3)(vue@3.5.39(typescript@6.0.3)))(rolldown@1.1.5)(vite@8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0))(vue@3.5.39(typescript@6.0.3)) - zod: - specifier: ^4.4.3 - version: 4.4.3 devDependencies: '@antfu/eslint-config': specifier: ^9.1.0 - version: 9.1.0(@typescript-eslint/typescript-estree@8.64.0(typescript@6.0.3))(@typescript-eslint/utils@8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(@vue/compiler-sfc@3.5.39)(eslint-plugin-format@2.0.1(eslint@10.7.0(jiti@2.7.0)))(eslint-plugin-vuejs-accessibility@2.5.0(eslint@10.7.0(jiti@2.7.0))(globals@17.7.0))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3)(vitest@4.1.10(@types/node@26.1.1)(vite@8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0))) + version: 9.1.0(@typescript-eslint/typescript-estree@8.64.0(typescript@6.0.3))(@typescript-eslint/utils@8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(@vue/compiler-sfc@3.5.39)(eslint-plugin-format@2.0.1(eslint@10.7.0(jiti@2.7.0)))(eslint-plugin-vuejs-accessibility@2.5.0(eslint@10.7.0(jiti@2.7.0))(globals@17.7.0))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3) '@tailwindcss/vite': specifier: ^4.3.2 version: 4.3.2(vite@8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0)) @@ -90,9 +87,6 @@ importers: vite: specifier: ^8.1.4 version: 8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0) - vitest: - specifier: ^4.1.10 - version: 4.1.10(@types/node@26.1.1)(vite@8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0)) vue-tsc: specifier: ^3.3.7 version: 3.3.7(typescript@6.0.3) @@ -587,9 +581,6 @@ packages: resolution: {integrity: sha512-TeheYy0ILzBEI/CO55CP6zJCSdSWeRtGnHy8U8dWSUH4I68iqTsy7HkMktR4xakThc9jotkPQUXT4ITdbV7cHA==} engines: {node: '>=18'} - '@standard-schema/spec@1.1.0': - resolution: {integrity: sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==} - '@stylistic/eslint-plugin@5.10.0': resolution: {integrity: sha512-nPK52ZHvot8Ju/0A4ucSX1dcPV2/1clx0kLcH5wDmrE4naKso7TUC/voUyU1O9OTKTrR6MYip6LP0ogEMQ9jPQ==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -693,15 +684,9 @@ packages: '@tybys/wasm-util@0.10.3': resolution: {integrity: sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg==} - '@types/chai@5.2.3': - resolution: {integrity: sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==} - '@types/debug@4.1.13': resolution: {integrity: sha512-KSVgmQmzMwPlmtljOomayoR89W4FynCAi3E8PPs7vmDVPe84hT+vGPKkJfThkmXs0x0jAaa9U8uW8bbfyS2fWw==} - '@types/deep-eql@4.0.2': - resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==} - '@types/esrecurse@4.3.1': resolution: {integrity: sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==} @@ -820,35 +805,6 @@ packages: vitest: optional: true - '@vitest/expect@4.1.10': - resolution: {integrity: sha512-YsCn+qAk1GWjQOWFEsEcL2gNQ0zmVmQu3T03qP6UyjhtmdtwtbuI+DASn/7iQB3HGTXkdBwGddzxPlmiql5vlA==} - - '@vitest/mocker@4.1.10': - resolution: {integrity: sha512-v0xaezt+DKEmKfaxg133ldzADrwLGd7Ze1MfQQTYfvs8OqZIwbxyxaYURivwV7sWy5fqn3rH5uOrSp07bp44Ow==} - peerDependencies: - msw: ^2.4.9 - vite: ^6.0.0 || ^7.0.0 || ^8.0.0 - peerDependenciesMeta: - msw: - optional: true - vite: - optional: true - - '@vitest/pretty-format@4.1.10': - resolution: {integrity: sha512-W1HsjSH4MXQ9YfmmhLAoIYf1HRfekQCGngeIgcei6MP5QQGWUe0gkopdZQaVCFO+JDJMrAJGwa5pRpNpvy4P8Q==} - - '@vitest/runner@4.1.10': - resolution: {integrity: sha512-IKI6kpIH+LmpROplyLwBBaCfMgOZOMsygVa6BARD6ahA04VRuJSa6OaVG7kRvSEMD870Vd91rSSw0eegtWyLGg==} - - '@vitest/snapshot@4.1.10': - resolution: {integrity: sha512-xRkfOT1qpTAi/Ti4Y1LtfRc3kEuqxGw59eN2jN9pRWMtS/XDevekhcFSqvQqjUNGksfjMJu3Y+oJ+4Ypn2OaJw==} - - '@vitest/spy@4.1.10': - resolution: {integrity: sha512-PLf/Ugvoq5wO/b4rwYCR1h2PSIdXz7wnkQFMiUpLdtM7l6pqVFcQIBEHyT1+l+cj7mNwAfZHzqXqDyjvOuwbDw==} - - '@vitest/utils@4.1.10': - resolution: {integrity: sha512-fy9am/HWxbaGt/Sawrp90vt6Y6jQwf1RX77cz3uwoJwJVMli/e1IEwRPnMNJ7vKfPTwo0diXifkpPvwH9v7nGA==} - '@volar/language-core@2.4.28': resolution: {integrity: sha512-w4qhIJ8ZSitgLAkVay6AbcnC7gP3glYM3fYwKV3srj8m494E3xtrCv6E+bWviiK/8hs6e6t1ij1s2Endql7vzQ==} @@ -973,10 +929,6 @@ packages: resolution: {integrity: sha512-COROpnaoap1E2F000S62r6A60uHZnmlvomhfyT2DlTcrY1OrBKn2UhH7qn5wTC9zMvD0AY7csdPSNwKP+7WiQw==} engines: {node: '>= 0.4'} - assertion-error@2.0.1: - resolution: {integrity: sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==} - engines: {node: '>=12'} - ast-kit@2.2.0: resolution: {integrity: sha512-m1Q/RaVOnTp9JxPX+F+Zn7IcLYMzM8kZofDImfsKZd8MbR+ikdOzTeztStWqfrqIxZnYWryyI9ePm3NGjnZgGw==} engines: {node: '>=20.19.0'} @@ -1033,10 +985,6 @@ packages: ccount@2.0.1: resolution: {integrity: sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==} - chai@6.2.2: - resolution: {integrity: sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==} - engines: {node: '>=18'} - change-case@5.4.4: resolution: {integrity: sha512-HRQyTk2/YPEkt9TnUPbOpr64Uw3KOicFWPVBb+xiHvd6eBx/qPr9xqfBFDT8P2vWsvvz4jbEkfDe71W3VyNu2w==} @@ -1069,9 +1017,6 @@ packages: confbox@0.2.4: resolution: {integrity: sha512-ysOGlgTFbN2/Y6Cg3Iye8YKulHw+R2fNXHrgSmXISQdMnomY6eNDprVdW9R5xBguEqI954+S6709UyiO7B+6OQ==} - convert-source-map@2.0.0: - resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} - copy-anything@4.0.5: resolution: {integrity: sha512-7Vv6asjS4gMOuILabD3l739tsaxFQmC+a7pLZm02zyvs8p977bL3zEgq3yDk5rn9B0PbYgIv++jmHcuUab4RhA==} engines: {node: '>=18'} @@ -1168,9 +1113,6 @@ packages: resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==} engines: {node: '>= 0.4'} - es-module-lexer@2.3.1: - resolution: {integrity: sha512-shc1dbU90Yl/xq1QrC7QRtfcwURZuVRfPhZbDoldJ1cn1gzDvBaBWlv0eFolj5+0znnPJz5TXLxsN77X/12KTA==} - es-object-atoms@1.1.2: resolution: {integrity: sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==} engines: {node: '>= 0.4'} @@ -1410,17 +1352,10 @@ packages: estree-walker@2.0.2: resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} - estree-walker@3.0.3: - resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} - esutils@2.0.3: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} engines: {node: '>=0.10.0'} - expect-type@1.4.0: - resolution: {integrity: sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==} - engines: {node: '>=12.0.0'} - exsolve@1.1.0: resolution: {integrity: sha512-D+42+T12DdIlJM3uepa55qGiL3sYdLBOxIl2ifQCzCHz4c7eiolaHsi3BIqEr7JxBzxv2pYZQX9kw16ziMcEmw==} @@ -1921,10 +1856,6 @@ packages: object-deep-merge@2.0.1: resolution: {integrity: sha512-aKttDKcU3pyZqKcCkDhsMn70WmZFG2JGDQLP9EcLyTSIFQRCPWLAmBZRLJnrVUrhPG1jETEEbfdgbNtJf1LyMg==} - obug@2.1.3: - resolution: {integrity: sha512-9miFgM2OFba7hB+pRgvtV84pYTBaoTHohvmIgiRt6dRIzbwEOIaNaP+dIlGs2fNFoB0SeISs0Jz5WFVRid6Xyg==} - engines: {node: '>=12.20.0'} - ohash@2.0.11: resolution: {integrity: sha512-RdR9FQrFwNBNXAr4GixM8YaRZRJ5PUWbKYbE5eOsrwAjJW0q2REGcf79oYPsLyskQCZG1PLN+S/K1V00joZAoQ==} @@ -2108,9 +2039,6 @@ packages: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} - siginfo@2.0.0: - resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==} - sisteransi@1.0.5: resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} @@ -2131,12 +2059,6 @@ packages: resolution: {integrity: sha512-1POYv7uv2gXoyGFpBCmpDVSNV74IfsWlDW216UPjbWufNf+bSU6GdbDsxdcxtfwb4xlI3yxzOTKClUosxARYrQ==} engines: {node: '>=0.10.0'} - stackback@0.0.2: - resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==} - - std-env@4.2.0: - resolution: {integrity: sha512-oCUKSupKTHX53EyjDtuZQ64pjLJ6yYCtpmEw0goYxtjG9KpbRe8KAsl2tBUGU9DyMcJ0RwJ8GqJAFzMXcXW1Rw==} - strip-indent@4.1.1: resolution: {integrity: sha512-SlyRoSkdh1dYP0PzclLE7r0M9sgbFKKMFXpFRUMNuKhQSbC6VQIGzq3E0qsfvGJaUFJPGv6Ws1NZ/haTAjfbMA==} engines: {node: '>=12'} @@ -2156,9 +2078,6 @@ packages: resolution: {integrity: sha512-uxc/zpqFg6x7C8vOE7lh6Lbda8eEL9zmVm/PLeTPBRhh1xCgdWaQ+J1CUieGpIfm2HdtsUpRv+HshiasBMcc6A==} engines: {node: '>=6'} - tinybench@2.9.0: - resolution: {integrity: sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==} - tinyexec@1.2.4: resolution: {integrity: sha512-SHf/r48b7vOrjve9PxJo3MN5v5yuyjHvdUcrQffT3WXMUfnGmHDVbC4k3sHJaJTgZCwpUplIaAo5ANtMyp3YHg==} engines: {node: '>=18'} @@ -2171,10 +2090,6 @@ packages: resolution: {integrity: sha512-Pugqs6M0m7Lv1I7FtxN4aoyToKg1C4tu+/381vH35y8oENM/Ai7f7C4StcoK4/+BSw9ebcS8jRiVrORFKCALLw==} engines: {node: ^20.0.0 || >=22.0.0} - tinyrainbow@3.1.0: - resolution: {integrity: sha512-Bf+ILmBgretUrdJxzXM0SgXLZ3XfiaUuOj/IKQHuTXip+05Xn+uyEYdVg0kYDipTBcLrCVyUzAPz7QmArb0mmw==} - engines: {node: '>=14.0.0'} - to-valid-identifier@1.0.0: resolution: {integrity: sha512-41wJyvKep3yT2tyPqX/4blcfybknGB4D+oETKLs7Q76UiPqRpUJK3hr1nxelyYO0PHKVzJwlu0aCeEAsGI6rpw==} engines: {node: '>=20'} @@ -2317,47 +2232,6 @@ packages: yaml: optional: true - vitest@4.1.10: - resolution: {integrity: sha512-R9jUTe5S4Qb0HCd4TNqpC7oGcrMssMRGXLW80ubjWsW9VH5GF8y1Y0SFLY9AbqSk6nt0PnOx4H4WNJYZ13GUPw==} - engines: {node: ^20.0.0 || ^22.0.0 || >=24.0.0} - hasBin: true - peerDependencies: - '@edge-runtime/vm': '*' - '@opentelemetry/api': ^1.9.0 - '@types/node': ^20.0.0 || ^22.0.0 || >=24.0.0 - '@vitest/browser-playwright': 4.1.10 - '@vitest/browser-preview': 4.1.10 - '@vitest/browser-webdriverio': 4.1.10 - '@vitest/coverage-istanbul': 4.1.10 - '@vitest/coverage-v8': 4.1.10 - '@vitest/ui': 4.1.10 - happy-dom: '*' - jsdom: '*' - vite: ^6.0.0 || ^7.0.0 || ^8.0.0 - peerDependenciesMeta: - '@edge-runtime/vm': - optional: true - '@opentelemetry/api': - optional: true - '@types/node': - optional: true - '@vitest/browser-playwright': - optional: true - '@vitest/browser-preview': - optional: true - '@vitest/browser-webdriverio': - optional: true - '@vitest/coverage-istanbul': - optional: true - '@vitest/coverage-v8': - optional: true - '@vitest/ui': - optional: true - happy-dom: - optional: true - jsdom: - optional: true - vscode-uri@3.1.0: resolution: {integrity: sha512-/BpdSx+yCQGnCvecbyXdxHDkuk55/G3xwnC0GqY4gmQ3j+A+g8kzzgB4Nk/SINjqn6+waqw3EgbVF2QKExkRxQ==} @@ -2407,11 +2281,6 @@ packages: engines: {node: '>= 8'} hasBin: true - why-is-node-running@2.3.0: - resolution: {integrity: sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==} - engines: {node: '>=8'} - hasBin: true - word-wrap@1.2.5: resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} engines: {node: '>=0.10.0'} @@ -2433,9 +2302,6 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} - zod@4.4.3: - resolution: {integrity: sha512-ytENFjIJFl2UwYglde2jchW2Hwm4GJFLDiSXWdTrJQBIN9Fcyp7n4DhxJEiWNAJMV1/BqWfW/kkg71UDcHJyTQ==} - zrender@6.1.0: resolution: {integrity: sha512-oEGMDB6pOP2S6OwRR4PdVv610zrjnA3Bh+JnSG12fYJlBKjtNAoEb5fSUoCOOINlH96I2fU38/A2UpRKs67xYQ==} @@ -2444,7 +2310,7 @@ packages: snapshots: - '@antfu/eslint-config@9.1.0(@typescript-eslint/typescript-estree@8.64.0(typescript@6.0.3))(@typescript-eslint/utils@8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(@vue/compiler-sfc@3.5.39)(eslint-plugin-format@2.0.1(eslint@10.7.0(jiti@2.7.0)))(eslint-plugin-vuejs-accessibility@2.5.0(eslint@10.7.0(jiti@2.7.0))(globals@17.7.0))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3)(vitest@4.1.10(@types/node@26.1.1)(vite@8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0)))': + '@antfu/eslint-config@9.1.0(@typescript-eslint/typescript-estree@8.64.0(typescript@6.0.3))(@typescript-eslint/utils@8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(@vue/compiler-sfc@3.5.39)(eslint-plugin-format@2.0.1(eslint@10.7.0(jiti@2.7.0)))(eslint-plugin-vuejs-accessibility@2.5.0(eslint@10.7.0(jiti@2.7.0))(globals@17.7.0))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3)': dependencies: '@antfu/install-pkg': 1.1.0 '@clack/prompts': 1.7.0 @@ -2454,7 +2320,7 @@ snapshots: '@stylistic/eslint-plugin': 5.10.0(eslint@10.7.0(jiti@2.7.0)) '@typescript-eslint/eslint-plugin': 8.64.0(@typescript-eslint/parser@8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3) '@typescript-eslint/parser': 8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3) - '@vitest/eslint-plugin': 1.6.23(@typescript-eslint/eslint-plugin@8.64.0(@typescript-eslint/parser@8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3)(vitest@4.1.10(@types/node@26.1.1)(vite@8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0))) + '@vitest/eslint-plugin': 1.6.23(@typescript-eslint/eslint-plugin@8.64.0(@typescript-eslint/parser@8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3) ansis: 4.3.1 cac: 7.0.0 eslint: 10.7.0(jiti@2.7.0) @@ -2817,8 +2683,6 @@ snapshots: '@sindresorhus/base62@1.0.0': {} - '@standard-schema/spec@1.1.0': {} - '@stylistic/eslint-plugin@5.10.0(eslint@10.7.0(jiti@2.7.0))': dependencies: '@eslint-community/eslint-utils': 4.9.1(eslint@10.7.0(jiti@2.7.0)) @@ -2902,17 +2766,10 @@ snapshots: tslib: 2.8.1 optional: true - '@types/chai@5.2.3': - dependencies: - '@types/deep-eql': 4.0.2 - assertion-error: 2.0.1 - '@types/debug@4.1.13': dependencies: '@types/ms': 2.1.0 - '@types/deep-eql@4.0.2': {} - '@types/esrecurse@4.3.1': {} '@types/estree@1.0.9': {} @@ -3041,7 +2898,7 @@ snapshots: vite: 8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0) vue: 3.5.39(typescript@6.0.3) - '@vitest/eslint-plugin@1.6.23(@typescript-eslint/eslint-plugin@8.64.0(@typescript-eslint/parser@8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3)(vitest@4.1.10(@types/node@26.1.1)(vite@8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0)))': + '@vitest/eslint-plugin@1.6.23(@typescript-eslint/eslint-plugin@8.64.0(@typescript-eslint/parser@8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3)': dependencies: '@typescript-eslint/scope-manager': 8.64.0 '@typescript-eslint/utils': 8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3) @@ -3049,51 +2906,9 @@ snapshots: optionalDependencies: '@typescript-eslint/eslint-plugin': 8.64.0(@typescript-eslint/parser@8.64.0(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3))(eslint@10.7.0(jiti@2.7.0))(typescript@6.0.3) typescript: 6.0.3 - vitest: 4.1.10(@types/node@26.1.1)(vite@8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0)) transitivePeerDependencies: - supports-color - '@vitest/expect@4.1.10': - dependencies: - '@standard-schema/spec': 1.1.0 - '@types/chai': 5.2.3 - '@vitest/spy': 4.1.10 - '@vitest/utils': 4.1.10 - chai: 6.2.2 - tinyrainbow: 3.1.0 - - '@vitest/mocker@4.1.10(vite@8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0))': - dependencies: - '@vitest/spy': 4.1.10 - estree-walker: 3.0.3 - magic-string: 0.30.21 - optionalDependencies: - vite: 8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0) - - '@vitest/pretty-format@4.1.10': - dependencies: - tinyrainbow: 3.1.0 - - '@vitest/runner@4.1.10': - dependencies: - '@vitest/utils': 4.1.10 - pathe: 2.0.3 - - '@vitest/snapshot@4.1.10': - dependencies: - '@vitest/pretty-format': 4.1.10 - '@vitest/utils': 4.1.10 - magic-string: 0.30.21 - pathe: 2.0.3 - - '@vitest/spy@4.1.10': {} - - '@vitest/utils@4.1.10': - dependencies: - '@vitest/pretty-format': 4.1.10 - convert-source-map: 2.0.0 - tinyrainbow: 3.1.0 - '@volar/language-core@2.4.28': dependencies: '@volar/source-map': 2.4.28 @@ -3256,8 +3071,6 @@ snapshots: aria-query@5.3.2: {} - assertion-error@2.0.1: {} - ast-kit@2.2.0: dependencies: '@babel/parser': 7.29.7 @@ -3314,8 +3127,6 @@ snapshots: ccount@2.0.1: {} - chai@6.2.2: {} - change-case@5.4.4: {} character-entities@2.0.2: {} @@ -3338,8 +3149,6 @@ snapshots: confbox@0.2.4: {} - convert-source-map@2.0.0: {} - copy-anything@4.0.5: dependencies: is-what: 5.5.0 @@ -3416,8 +3225,6 @@ snapshots: es-errors@1.3.0: {} - es-module-lexer@2.3.1: {} - es-object-atoms@1.1.2: dependencies: es-errors: 1.3.0 @@ -3736,14 +3543,8 @@ snapshots: estree-walker@2.0.2: {} - estree-walker@3.0.3: - dependencies: - '@types/estree': 1.0.9 - esutils@2.0.3: {} - expect-type@1.4.0: {} - exsolve@1.1.0: {} fast-deep-equal@3.1.3: {} @@ -4370,8 +4171,6 @@ snapshots: object-deep-merge@2.0.1: {} - obug@2.1.3: {} - ohash@2.0.11: {} optionator@0.9.4: @@ -4557,8 +4356,6 @@ snapshots: shebang-regex@3.0.0: {} - siginfo@2.0.0: {} - sisteransi@1.0.5: {} source-map-js@1.2.1: {} @@ -4574,10 +4371,6 @@ snapshots: speakingurl@14.0.1: {} - stackback@0.0.2: {} - - std-env@4.2.0: {} - strip-indent@4.1.1: {} superjson@2.2.6: @@ -4592,8 +4385,6 @@ snapshots: tapable@2.3.3: {} - tinybench@2.9.0: {} - tinyexec@1.2.4: {} tinyglobby@0.2.17: @@ -4603,8 +4394,6 @@ snapshots: tinypool@2.1.0: {} - tinyrainbow@3.1.0: {} - to-valid-identifier@1.0.0: dependencies: '@sindresorhus/base62': 1.0.0 @@ -4696,33 +4485,6 @@ snapshots: jiti: 2.7.0 yaml: 2.9.0 - vitest@4.1.10(@types/node@26.1.1)(vite@8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0)): - dependencies: - '@vitest/expect': 4.1.10 - '@vitest/mocker': 4.1.10(vite@8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0)) - '@vitest/pretty-format': 4.1.10 - '@vitest/runner': 4.1.10 - '@vitest/snapshot': 4.1.10 - '@vitest/spy': 4.1.10 - '@vitest/utils': 4.1.10 - es-module-lexer: 2.3.1 - expect-type: 1.4.0 - magic-string: 0.30.21 - obug: 2.1.3 - pathe: 2.0.3 - picomatch: 4.0.5 - std-env: 4.2.0 - tinybench: 2.9.0 - tinyexec: 1.2.4 - tinyglobby: 0.2.17 - tinyrainbow: 3.1.0 - vite: 8.1.4(@types/node@26.1.1)(jiti@2.7.0)(yaml@2.9.0) - why-is-node-running: 2.3.0 - optionalDependencies: - '@types/node': 26.1.1 - transitivePeerDependencies: - - msw - vscode-uri@3.1.0: {} vue-eslint-parser@10.4.1(eslint@10.7.0(jiti@2.7.0)): @@ -4793,11 +4555,6 @@ snapshots: dependencies: isexe: 2.0.0 - why-is-node-running@2.3.0: - dependencies: - siginfo: 2.0.0 - stackback: 0.0.2 - word-wrap@1.2.5: {} xml-name-validator@4.0.0: {} @@ -4811,8 +4568,6 @@ snapshots: yocto-queue@0.1.0: {} - zod@4.4.3: {} - zrender@6.1.0: dependencies: tslib: 2.3.0 diff --git a/frontend/pnpm-workspace.yaml b/frontend/pnpm-workspace.yaml index caafd5e46..0dde9bd9d 100644 --- a/frontend/pnpm-workspace.yaml +++ b/frontend/pnpm-workspace.yaml @@ -1,2 +1,4 @@ +autoInstallPeers: false + minimumReleaseAgeExclude: - vite@8.1.3 diff --git a/frontend/src/api/modules/accounts.ts b/frontend/src/api/modules/accounts.ts index 258795578..2d244f3a1 100644 --- a/frontend/src/api/modules/accounts.ts +++ b/frontend/src/api/modules/accounts.ts @@ -1,207 +1,46 @@ -import { z } from 'zod' +import request from '../request' -import request, { requestParsed } from '../request' - -const ACCOUNT_EXPORT_CONFIRMATION = 'export_sensitive_accounts' - -const quotaWindowLocalUsageSchema = z.object({ - requestCount: z.number(), - requestCountDisplay: z.string(), - inputTokens: z.number(), - inputTokensDisplay: z.string(), - outputTokens: z.number(), - outputTokensDisplay: z.string(), - cachedTokens: z.number(), - cachedTokensDisplay: z.string(), - totalTokens: z.number(), - totalTokensDisplay: z.string(), -}) - -const quotaWindowSchema = z.object({ - key: z.string(), - group: z.enum(['monthly', 'shortTerm', 'other']), - windowSeconds: z.number().nullable(), - labelDisplay: z.string(), - usedPercent: z.number().nullable(), - usedPercentDisplay: z.string(), - localUsage: quotaWindowLocalUsageSchema.optional(), - resetAtDisplay: z.string(), - windowUsedDisplay: z.string(), -}) - -const accountQuotaSchema = z.object({ - refreshedAtDisplay: z.string(), - windows: z.array(quotaWindowSchema), -}) - -const accountModelUsageSchema = z - .object({ - model: z.string(), - requestCount: z.number(), - requestCountDisplay: z.string(), - successRate: z.number(), - successRateDisplay: z.string(), - inputTokens: z.number(), - inputTokensDisplay: z.string(), - outputTokens: z.number(), - outputTokensDisplay: z.string(), - cachedTokens: z.number(), - cachedTokensDisplay: z.string(), - totalTokens: z.number(), - totalTokensDisplay: z.string(), - billingAmountUsd: z.number(), - billingAmountUsdDisplay: z.string(), - lastUsedAt: z.string().nullable(), - lastUsedAtDisplay: z.string(), - }) - .passthrough() - -const accountUsageSchema = z - .object({ - inputTokensDisplay: z.string(), - outputTokensDisplay: z.string(), - cachedTokensDisplay: z.string(), - createdTokensDisplay: z.string(), - readTokensDisplay: z.string(), - models: z.array(accountModelUsageSchema), - }) - .passthrough() - -const accountSchema = z - .object({ - id: z.string(), - email: z.string().nullable(), - accountId: z.string().nullable(), - userId: z.string().nullable(), - label: z.string().nullable(), - planType: z.string().nullable(), - hasRefreshToken: z.boolean(), - status: z.string(), - displayStatus: z.string(), - tokenRefreshing: z.boolean(), - accessTokenExpiresAt: z.string().nullable(), - accessTokenExpiresAtDisplay: z.string().nullable(), - addedAt: z.string(), - addedAtDisplay: z.string(), - updatedAt: z.string(), - updatedAtDisplay: z.string(), - quota: accountQuotaSchema, - usage: accountUsageSchema, - }) - .passthrough() - -const accountPageSchema = z.object({ - items: z.array(accountSchema), - page: z.object({ - page: z.number(), - pageSize: z.number(), - total: z.number(), - totalPages: z.number(), - }), - summary: z.object({ - total: z.number(), - active: z.number(), - quotaExhausted: z.number(), - attention: z.number(), - }), -}) - -const _accountQuerySchema = z.object({ - page: z.number().optional(), - pageSize: z.number().optional(), - search: z.string().optional(), - status: z.string().optional(), - sortBy: z.string().optional(), - sortDirection: z.enum(['asc', 'desc']).optional(), -}) - -const importResultSchema = z.object({ - imported: z.number(), - skipped: z.number(), - sourceFormat: z.string(), -}) - -const oauthAuthorizeSchema = z.object({ - sessionId: z.string(), - authUrl: z.string(), - expiresAt: z.string(), - expiresAtDisplay: z.string(), -}) - -const accountRefreshSchema = z.object({ - id: z.string(), - email: z.string().nullable(), - previousStatus: z.string(), - result: z.enum(['alive', 'dead', 'skipped']), - error: z.string().nullable(), - durationMs: z.number(), -}) - -const accountQuotaRefreshSchema = z - .object({ - quota: z.unknown(), - raw: z.unknown(), - quotaData: accountQuotaSchema, - planType: z.string().nullable(), - account: accountSchema, - }) - .passthrough() - -const accountModelsSchema = z.object({ - models: z.array( - z.object({ - id: z.string(), - label: z.string(), - }), - ), -}) - -type JsonObject = Record - -export function getAccounts(params?: z.input) { - return requestParsed({ +export function getAccounts(data: object) { + return request({ url: '/api/admin/accounts', method: 'GET', - params, - }, accountPageSchema) + params: data, + }) } -export function importAccounts(data: JsonObject) { - return requestParsed({ +export function importAccounts(data: object) { + return request({ url: '/api/admin/accounts/import', method: 'POST', data, - }, importResultSchema) -} - -export function exportAccounts(params?: { ids?: string }) { - return request({ - url: '/api/admin/accounts/export', - method: 'GET', - params: { - ...params, - confirm: ACCOUNT_EXPORT_CONFIRMATION, - }, }) } -export function authorizeAccountOAuth(data = {}) { - return requestParsed({ +export function exportAccounts(data: object) { + return request({ + url: '/api/admin/accounts/export', + method: 'GET', + params: data, + }) +} + +export function authorizeAccountOAuth(data?: object) { + return request({ url: '/api/admin/accounts/oauth/authorize', method: 'POST', data, - }, oauthAuthorizeSchema) + }) } -export function exchangeAccountOAuth(data: JsonObject) { - return requestParsed({ +export function exchangeAccountOAuth(data: object) { + return request({ url: '/api/admin/accounts/oauth/exchange', method: 'POST', data, - }, importResultSchema) + }) } -export function deleteAccounts(data: { ids: string[] }) { +export function deleteAccounts(data: object) { return request({ url: '/api/admin/accounts/delete', method: 'POST', @@ -209,15 +48,15 @@ export function deleteAccounts(data: { ids: string[] }) { }) } -export function refreshAccount(data: { id: string }) { - return requestParsed({ +export function refreshAccount(data: object) { + return request({ url: '/api/admin/accounts/refresh', method: 'POST', data, - }, accountRefreshSchema) + }) } -export function updateAccount(data: { id: string, status?: string, label?: string | null }) { +export function updateAccount(data: object) { return request({ url: '/api/admin/accounts/update', method: 'POST', @@ -225,28 +64,26 @@ export function updateAccount(data: { id: string, status?: string, label?: strin }) } -export function getAccountQuota(params: { id: string }) { - return requestParsed({ +export function getAccountQuota(data: object) { + return request({ url: '/api/admin/accounts/quota', method: 'GET', - params, - }, accountQuotaRefreshSchema) + params: data, + }) } -export function getAccountModels(data: { id: string }) { - return requestParsed({ +export function getAccountModels(data: object) { + return request({ url: '/api/admin/accounts/models', method: 'GET', - params: { - id: data.id, - }, - }, accountModelsSchema) + params: data, + }) } -export function refreshAccountModels(data: { id: string }) { - return requestParsed({ +export function refreshAccountModels(data: object) { + return request({ url: '/api/admin/accounts/models', method: 'POST', data, - }, accountModelsSchema) + }) } diff --git a/frontend/src/api/modules/api-keys.ts b/frontend/src/api/modules/api-keys.ts index 979cb8c63..a8c1386c5 100644 --- a/frontend/src/api/modules/api-keys.ts +++ b/frontend/src/api/modules/api-keys.ts @@ -1,85 +1,33 @@ -import { z } from 'zod' +import request from '../request' -import { requestParsed } from '../request' - -const apiKeySchema = z.object({ - id: z.string(), - name: z.string(), - label: z.string().nullable(), - prefix: z.string(), - key: z.string(), - enabled: z.boolean(), - createdAt: z.string(), - createdAtDisplay: z.string(), - lastUsedAt: z.string().nullable(), - lastUsedAtDisplay: z.string(), -}) - -const pageSchema = z.object({ - page: z.number(), - pageSize: z.number(), - total: z.number(), - totalPages: z.number(), -}) - -const apiKeyPageSchema = z.object({ - items: z.array(apiKeySchema), - page: pageSchema, -}) - -const _apiKeyQuerySchema = z.object({ - page: z.number().optional(), - pageSize: z.number().optional(), - search: z.string().optional(), - sortBy: z.string().optional(), - sortDirection: z.enum(['asc', 'desc']).optional(), -}) - -const _createApiKeySchema = z.object({ - name: z.string(), - label: z.string().optional(), -}) -const _deleteApiKeysSchema = z.object({ ids: z.array(z.string()) }) -const _updateApiKeySchema = z - .object({ - id: z.string(), - label: z.string().nullable().optional(), - status: z.enum(['active', 'disabled']).optional(), - }) - .refine(value => value.label !== undefined || value.status !== undefined) - -const batchDeleteResultSchema = z.object({ - deleted: z.number(), -}) - -export function getApiKeys(params: z.input) { - return requestParsed({ +export function getApiKeys(data: object) { + return request({ url: '/api/admin/keys', method: 'GET', - params, - }, apiKeyPageSchema) + params: data, + }) } -export function createApiKey(data: z.input) { - return requestParsed({ +export function createApiKey(data: object) { + return request({ url: '/api/admin/keys', method: 'POST', data, - }, apiKeySchema) + }) } -export function deleteApiKeys(data: z.input) { - return requestParsed({ +export function deleteApiKeys(data: object) { + return request({ url: '/api/admin/keys/delete', method: 'POST', data, - }, batchDeleteResultSchema) + }) } -export function updateApiKey(data: z.input) { - return requestParsed({ +export function updateApiKey(data: object) { + return request({ url: '/api/admin/keys/update', method: 'POST', data, - }, apiKeySchema) + }) } diff --git a/frontend/src/api/modules/auth.ts b/frontend/src/api/modules/auth.ts index d7f99674f..56a487cc1 100644 --- a/frontend/src/api/modules/auth.ts +++ b/frontend/src/api/modules/auth.ts @@ -1,42 +1,23 @@ -import { z } from 'zod' +import request from '../request' -import { requestParsed } from '../request' - -const _loginPayloadSchema = z.object({ - username: z.string().optional(), - password: z.string(), -}) - -const loginResultSchema = z.object({ - expiresAt: z.string(), -}) - -const authStatusSchema = z.object({ - authenticated: z.boolean(), -}) - -const logoutResultSchema = z.object({ - message: z.string(), -}) - -export function login(data: z.input) { - return requestParsed({ +export function login(data: object) { + return request({ url: '/api/admin/login', method: 'POST', data, - }, loginResultSchema) + }) } export function getAuthStatus() { - return requestParsed({ + return request({ url: '/api/admin/auth/status', method: 'GET', - }, authStatusSchema) + }) } export function logout() { - return requestParsed({ + return request({ url: '/api/admin/logout', method: 'POST', - }, logoutResultSchema) + }) } diff --git a/frontend/src/api/modules/dashboard.ts b/frontend/src/api/modules/dashboard.ts index e5ec2a081..bdda1b8c8 100644 --- a/frontend/src/api/modules/dashboard.ts +++ b/frontend/src/api/modules/dashboard.ts @@ -1,235 +1,17 @@ -import { z } from 'zod' +import request from '../request' -import { requestParsed } from '../request' - -const trendKindSchema = z.enum(['usage', 'latency', 'errors']) - -const trendPointSchema = z - .object({ - time: z.string(), - requests: z.string(), - requestsValue: z.number(), - inputTokens: z.string(), - inputTokensValue: z.number(), - outputTokens: z.string(), - outputTokensValue: z.number(), - cachedTokens: z.string(), - cachedTokensValue: z.number(), - cacheHitRateValue: z.number(), - tokensValue: z.number(), - errors: z.string(), - errorsValue: z.number(), - latency: z.string(), - latencyValue: z.number().nullable(), - maxLatency: z.string(), - maxLatencyValue: z.number().nullable(), - minLatency: z.string(), - minLatencyValue: z.number().nullable(), - successRate: z.string(), - successRateValue: z.number().nullable(), - }) - .passthrough() - -const dashboardTrendSchema = z.object({ - kind: trendKindSchema, - points: z.array(trendPointSchema), - summary: z.array( - z.object({ - label: z.string(), - value: z.string(), - ratio: z.string().nullable(), - }), - ), -}) - -const healthPointSchema = z.object({ - time: z.string(), - status: z.enum(['future', 'no_data', 'unavailable', 'unstable', 'low_sample', 'stable']), - reliabilityDisplay: z.string(), - successRequests: z.number(), - failedRequests: z.number(), - cancelledRequests: z.number(), - callerErrorRequests: z.number(), -}) - -const healthTimelineSchema = z.object({ - title: z.string(), - description: z.string(), - reliabilityDisplay: z.string(), - status: healthPointSchema.shape.status, - successRequests: z.number(), - failedRequests: z.number(), - cancelledRequests: z.number(), - callerErrorRequests: z.number(), - points: z.array(healthPointSchema), -}) - -const tokenDetailsSchema = z - .object({ - inputTokens: z.number(), - outputTokens: z.number(), - cachedTokens: z.number(), - cacheWriteTokens: z.number(), - reasoningTokens: z.number(), - totalTokens: z.number(), - }) - .passthrough() - -const billingSchema = z - .object({ - totalAmount: z.number(), - totalAmountDisplay: z.string(), - }) - .passthrough() - -const dashboardUsageRecordSchema = z - .object({ - id: z.string(), - route: z.string().nullable(), - model: z.string(), - statusCode: z.number(), - transport: z.string().nullable(), - createdAtDisplay: z.string(), - accountEmail: z.string().nullable(), - requestedModel: z.string().nullable(), - upstreamModel: z.string().nullable(), - clientIp: z.string().nullable(), - userAgent: z.string().nullable(), - reasoningEffort: z.string().nullable(), - reasoningPreset: z.string().nullable(), - compact: z.boolean(), - requestKind: z.string().nullable(), - subagentKind: z.string().nullable(), - tokenDetails: tokenDetailsSchema, - billing: billingSchema.nullable(), - firstTokenLatencyMs: z.number().nullable(), - latencyMs: z.number().nullable(), - latencyDetails: z.object({ - firstReasoningMs: z.number().nullable(), - firstTextMs: z.number().nullable(), - transportDecisionWaitMs: z.number().nullable(), - wsConnectMs: z.number().nullable(), - upstreamHeadersMs: z.number().nullable(), - firstEventMs: z.number().nullable(), - openaiProcessingMs: z.number().nullable(), - }), - firstTokenLatencyMsDisplay: z.string(), - latencyMsDisplay: z.string(), - }) - .passthrough() - -const wireProfileSchema = z - .object({ - originator: z.string(), - codexVersion: z.string(), - desktopVersion: z.string(), - desktopBuild: z.string(), - target: z.object({ - osType: z.string(), - osVersion: z.string(), - arch: z.string(), - terminal: z.string(), - }), - userAgent: z.string(), - verifiedAt: z.string(), - release: z - .object({ - status: z.string(), - checkedAt: z.string().optional(), - latestVersion: z.string().optional(), - latestBuild: z.string().optional(), - publishedAt: z.string().optional(), - minimumSystemVersion: z.string().optional(), - hardwareRequirements: z.string().optional(), - downloadUrl: z.string().optional(), - downloadSize: z.number().optional(), - signaturePresent: z.boolean().optional(), - error: z.string().optional(), - }) - .passthrough(), - }) - .passthrough() - -const dashboardSummarySchema = z.object({ - cards: z.object({ - accounts: z.object({ - total: z.string(), - totalValue: z.number(), - enabled: z.string(), - enabledValue: z.number(), - abnormal: z.string(), - abnormalValue: z.number(), - }), - traffic: z.object({ - todayRequests: z.string(), - todayRequestsValue: z.number(), - yesterdayRequestsValue: z.number(), - totalRequests: z.string(), - }), - tokens: z.object({ - todayTokens: z.string(), - todayTokensValue: z.number(), - yesterdayTokensValue: z.number(), - totalTokens: z.string(), - totalBillingAmountUsd: z.string(), - }), - cache: z.object({ - todayHitRate: z.string(), - todayHitRateValue: z.number().nullable(), - yesterdayHitRateValue: z.number().nullable(), - totalHitRate: z.string(), - totalCachedTokens: z.string(), - averageFirstTokenLatencyMs: z.string(), - }), - }), - trend: dashboardTrendSchema, - healthTimeline: healthTimelineSchema, - accountUsage: z.array( - z.object({ - id: z.string(), - email: z.string(), - planType: z.string().nullable(), - tokens: z.string(), - quotaUsedPercent: z.number().nullable(), - lastUsed: z.string(), - }), - ), - wireProfile: wireProfileSchema, - usageRecords: z.array(dashboardUsageRecordSchema), - poolSummary: z.object({ - total: z.number(), - active: z.number(), - expired: z.number(), - quotaExhausted: z.number(), - refreshing: z.number(), - disabled: z.number(), - banned: z.number(), - }), - capacityInfo: z.object({ - maxConcurrentPerAccount: z.number(), - totalSlots: z.number(), - usedSlots: z.number(), - availableSlots: z.number(), - }), - rotationStrategy: z.string().nullable(), -}) - -const _dashboardQuerySchema = z.object({ - kind: trendKindSchema.optional(), -}) - -export function getDashboardSummary(params?: z.input) { - return requestParsed({ +export function getDashboardSummary(data: object) { + return request({ url: '/api/admin/dashboard/summary', method: 'GET', - params, - }, dashboardSummarySchema) + params: data, + }) } -export function getDashboardTrend(params: z.input) { - return requestParsed({ +export function getDashboardTrend(data: object) { + return request({ url: '/api/admin/dashboard/trend', method: 'GET', - params, - }, dashboardTrendSchema) + params: data, + }) } diff --git a/frontend/src/api/modules/settings.ts b/frontend/src/api/modules/settings.ts index b2a18c265..859692372 100644 --- a/frontend/src/api/modules/settings.ts +++ b/frontend/src/api/modules/settings.ts @@ -1,67 +1,37 @@ -import { z } from 'zod' - -import { requestParsed } from '../request' - -const rotationStrategySchema = z.enum([ - 'smart', - 'quota_reset_priority', - 'round_robin', - 'sticky', -]) - -const settingsSchema = z.object({ - modelAliases: z.record(z.string(), z.string()), - refreshMarginSeconds: z.number(), - refreshConcurrency: z.number(), - maxConcurrentPerAccount: z.number(), - requestIntervalMs: z.number(), - rotationStrategy: rotationStrategySchema, -}) - -const adminApiKeyStatusSchema = z.object({ - exists: z.boolean(), -}) - -const generatedAdminApiKeySchema = z.object({ - key: z.string(), -}) - -const messageSchema = z.object({ - message: z.string(), -}) +import request from '../request' export function getSettings() { - return requestParsed({ + return request({ url: '/api/admin/settings', method: 'GET', - }, settingsSchema) + }) } -export function updateSettings(data: z.input) { - return requestParsed({ +export function updateSettings(data: object) { + return request({ url: '/api/admin/settings', method: 'POST', data, - }, settingsSchema) + }) } export function getAdminApiKeyStatus() { - return requestParsed({ + return request({ url: '/api/admin/settings/admin-api-key', method: 'GET', - }, adminApiKeyStatusSchema) + }) } export function regenerateAdminApiKey() { - return requestParsed({ + return request({ url: '/api/admin/settings/admin-api-key/regenerate', method: 'POST', - }, generatedAdminApiKeySchema) + }) } export function deleteAdminApiKey() { - return requestParsed({ + return request({ url: '/api/admin/settings/admin-api-key', - method: 'DELETE', - }, messageSchema) + method: 'POST', + }) } diff --git a/frontend/src/api/modules/system.ts b/frontend/src/api/modules/system.ts index 76d516c8b..2de96575c 100644 --- a/frontend/src/api/modules/system.ts +++ b/frontend/src/api/modules/system.ts @@ -1,76 +1,32 @@ -import { z } from 'zod' +import request from '../request' -import { requestParsed } from '../request' - -const versionSchema = z.object({ - version: z.string(), - gitSha: z.string(), - buildTime: z.string(), - deploymentMode: z.string(), - deploymentModeLabel: z.string(), - updateChannel: z.string(), - latestVersion: z.string(), - hasUpdate: z.boolean(), - updateCached: z.boolean(), - updateWarning: z.string().nullable(), -}) - -const updateDetailSchema = z.object({ - currentVersion: z.string(), - latestVersion: z.string(), - hasUpdate: z.boolean(), - deploymentMode: z.string(), - deploymentModeLabel: z.string(), - buildType: z.string(), - buildTypeLabel: z.string(), - releaseUrl: z.string().nullable(), - notes: z.string().nullable(), - cached: z.boolean(), - updateSupported: z.boolean(), - unsupportedReason: z.string().nullable(), - warning: z.string().nullable(), -}) - -const updateStartedSchema = z.object({ - operationId: z.string(), - deploymentMode: z.string(), - message: z.string(), - needRestart: z.boolean(), - targetVersion: z.string(), -}) - -const restartResultSchema = z.object({ - message: z.string(), - operationId: z.string(), -}) - -export function getSystemVersion(options: { timeoutMs?: number } = {}) { - return requestParsed({ +export function getSystemVersion(timeout = 0) { + return request({ url: '/api/admin/system/version', method: 'GET', - ...(options.timeoutMs ? { timeout: options.timeoutMs } : {}), - }, versionSchema) + ...(timeout ? { timeout } : {}), + }) } -export function getSystemUpdateDetail(refresh = false) { - return requestParsed({ +export function getSystemUpdateDetail(data: object) { + return request({ url: '/api/admin/system/update-detail', method: 'GET', - params: { refresh }, - }, updateDetailSchema) + params: data, + }) } -export function performSystemUpdate(targetVersion: string) { - return requestParsed({ +export function performSystemUpdate(data: object) { + return request({ url: '/api/admin/system/update', method: 'POST', - data: { targetVersion }, - }, updateStartedSchema) + data, + }) } export function restartSystem() { - return requestParsed({ + return request({ url: '/api/admin/system/restart', method: 'POST', - }, restartResultSchema) + }) } diff --git a/frontend/src/api/modules/usage.ts b/frontend/src/api/modules/usage.ts index 6ee5cc1bc..d09667fa5 100644 --- a/frontend/src/api/modules/usage.ts +++ b/frontend/src/api/modules/usage.ts @@ -1,308 +1,49 @@ -import { z } from 'zod' +import request from '../request' -import { requestParsed } from '../request' - -const pageSchema = z.object({ - page: z.number(), - pageSize: z.number(), - total: z.number(), - totalPages: z.number(), -}) - -const usageQuerySchema = z.object({ - page: z.number().optional(), - pageSize: z.number().optional(), - kind: z.string().optional(), - clientApiKeyId: z.string().optional(), - provider: z.string().optional(), - requestId: z.string().optional(), - accountId: z.string().optional(), - route: z.string().optional(), - model: z.string().optional(), - statusCode: z.number().optional(), - transport: z.string().optional(), - attemptIndex: z.number().optional(), - responseId: z.string().optional(), - upstreamRequestId: z.string().optional(), - search: z.string().optional(), - startTime: z.string().optional(), - endTime: z.string().optional(), -}) - -const tokenDetailsSchema = z.object({ - inputTokens: z.number(), - outputTokens: z.number(), - cachedTokens: z.number(), - cacheWriteTokens: z.number(), - reasoningTokens: z.number(), - totalTokens: z.number(), - inputTokensDisplay: z.string(), - outputTokensDisplay: z.string(), - cachedTokensDisplay: z.string(), - cacheWriteTokensDisplay: z.string(), - reasoningTokensDisplay: z.string(), - totalTokensDisplay: z.string(), -}) - -const billingSchema = z.object({ - inputAmount: z.number(), - outputAmount: z.number(), - cacheReadAmount: z.number(), - cacheWriteAmount: z.number(), - standardAmount: z.number(), - totalAmount: z.number(), - inputPricePerMtoken: z.number(), - outputPricePerMtoken: z.number(), - cacheReadPricePerMtoken: z.number(), - cacheWritePricePerMtoken: z.number(), - serviceTier: z.string().nullable(), - serviceTierDisplay: z.string(), - multiplier: z.number(), - inputAmountDisplay: z.string(), - outputAmountDisplay: z.string(), - cacheReadAmountDisplay: z.string(), - cacheWriteAmountDisplay: z.string(), - standardAmountDisplay: z.string(), - totalAmountDisplay: z.string(), - inputPriceDisplay: z.string(), - outputPriceDisplay: z.string(), - cacheReadPriceDisplay: z.string(), - cacheWritePriceDisplay: z.string(), - multiplierDisplay: z.string(), -}) - -const usageRecordSchema = z - .object({ - id: z.string(), - requestId: z.string().nullable(), - clientApiKeyId: z.string().nullable(), - kind: z.string(), - provider: z.string(), - accountId: z.string(), - route: z.string().nullable(), - model: z.string(), - requestedModel: z.string().nullable(), - upstreamModel: z.string().nullable(), - serviceTier: z.string().nullable(), - statusCode: z.number(), - transport: z.string().nullable(), - attemptIndex: z.number().nullable(), - responseId: z.string().nullable(), - upstreamRequestId: z.string().nullable(), - latencyMs: z.number().nullable(), - firstTokenMs: z.number().nullable(), - inputTokens: z.number().nullable(), - outputTokens: z.number().nullable(), - cachedTokens: z.number().nullable(), - cacheWriteTokens: z.number().nullable(), - reasoningTokens: z.number().nullable(), - message: z.string(), - metadata: z.unknown(), - createdAt: z.string(), - createdAtDisplay: z.string(), - accountEmail: z.string().nullable(), - clientIp: z.string().nullable(), - userAgent: z.string().nullable(), - reasoningEffort: z.string().nullable(), - reasoningPreset: z.string().nullable(), - compact: z.boolean(), - requestKind: z.string().nullable(), - subagentKind: z.string().nullable(), - tokenDetails: tokenDetailsSchema, - billing: billingSchema.nullable(), - firstTokenLatencyMs: z.number().nullable(), - firstTokenLatencyMsDisplay: z.string(), - latencyMsDisplay: z.string(), - }) - .passthrough() - -const usagePageSchema = z.object({ - items: z.array(usageRecordSchema), - page: pageSchema, -}) - -const usageSummarySchema = z.object({ - totalRequests: z.string(), - inputTokens: z.string(), - outputTokens: z.string(), - cachedTokens: z.string(), - cacheWriteTokens: z.string(), - totalTokens: z.string(), - averageLatencyMs: z.string(), -}) - -const healthPointSchema = z.object({ - bucket: z.string(), - label: z.string(), - successRequests: z.number(), - failedRequests: z.number(), - cancelledRequests: z.number(), - callerErrorRequests: z.number(), - errorRate: z.number(), -}) - -const performancePointSchema = z.object({ - bucket: z.string(), - label: z.string(), - latencyP50Ms: z.number().nullable(), - latencyP95Ms: z.number().nullable(), - latencyP99Ms: z.number().nullable(), - firstTokenP50Ms: z.number().nullable(), - firstTokenP95Ms: z.number().nullable(), - firstTokenP99Ms: z.number().nullable(), -}) - -const costPointSchema = z.object({ - bucket: z.string(), - label: z.string(), - inputTokens: z.number(), - outputTokens: z.number(), - cachedTokens: z.number(), - totalTokens: z.number(), - estimatedCost: z.number(), - standardCost: z.number(), - cachedTokenRate: z.number(), - cacheHitRequestRate: z.number(), -}) - -const usageOverviewSchema = z.object({ - granularity: z.string(), - health: z.object({ - totalRequests: z.number(), - successRequests: z.number(), - failedRequests: z.number(), - cancelledRequests: z.number(), - callerErrorRequests: z.number(), - successRate: z.number(), - requestChangeRate: z.number().nullable(), - successRateChange: z.number().nullable(), - points: z.array(healthPointSchema), - }), - performance: z.object({ - latencyP50Ms: z.number().nullable(), - latencyP95Ms: z.number().nullable(), - latencyP99Ms: z.number().nullable(), - firstTokenP50Ms: z.number().nullable(), - firstTokenP95Ms: z.number().nullable(), - firstTokenP99Ms: z.number().nullable(), - latencyCoverage: z.number(), - firstTokenCoverage: z.number(), - points: z.array(performancePointSchema), - }), - cost: z.object({ - estimatedCost: z.number(), - standardCost: z.number(), - costPerRequest: z.number(), - tokensPerRequest: z.number(), - cachedTokenRate: z.number(), - cacheHitRequestRate: z.number(), - inputTokens: z.number(), - outputTokens: z.number(), - cachedTokens: z.number(), - totalTokens: z.number(), - points: z.array(costPointSchema), - }), -}) - -const diagnosticsSchema = z.object({ - dimension: z.string(), - items: z.array( - z.object({ - name: z.string(), - requestCount: z.number(), - successCount: z.number(), - errorCount: z.number(), - errorRate: z.number(), - requestShare: z.number(), - latencyP95Ms: z.number().nullable(), - estimatedCost: z.number(), - }), - ), -}) - -const opsErrorSchema = z - .object({ - id: z.string(), - requestId: z.string().nullable(), - clientApiKeyId: z.string().nullable(), - kind: z.string(), - provider: z.string().nullable(), - accountId: z.string().nullable(), - route: z.string().nullable(), - model: z.string().nullable(), - statusCode: z.number().nullable(), - clientStatusCode: z.number().nullable(), - upstreamStatusCode: z.number().nullable(), - transport: z.string().nullable(), - attemptIndex: z.number().nullable(), - failureClass: z.string().nullable(), - responseId: z.string().nullable(), - upstreamRequestId: z.string().nullable(), - latencyMs: z.number().nullable(), - message: z.string(), - metadata: z.unknown(), - createdAt: z.string(), - createdAtDisplay: z.string(), - }) - .passthrough() - -const _opsQuerySchema = usageQuerySchema.extend({ - clientStatusCode: z.number().optional(), - upstreamStatusCode: z.number().optional(), - failureClass: z.string().optional(), -}) - -const _rangeSchema = z.object({ - startTime: z.string().optional(), - endTime: z.string().optional(), -}) - -export function getUsageRecords(params?: z.input) { - return requestParsed({ +export function getUsageRecords(data: object) { + return request({ url: '/api/admin/usage/records', method: 'GET', - params, - }, usagePageSchema) + params: data, + }) } -export function getOpsErrors(params?: z.input) { - return requestParsed({ +export function getOpsErrors(data: object) { + return request({ url: '/api/admin/ops/errors', method: 'GET', - params, - }, z.object({ items: z.array(opsErrorSchema), page: pageSchema })) + params: data, + }) } -export function getUsageRecordDetail(params: { id: string }) { - return requestParsed({ +export function getUsageRecordDetail(data: object) { + return request({ url: '/api/admin/usage/records/detail', method: 'GET', - params, - }, usageRecordSchema) + params: data, + }) } -export function getUsageRecordSummary(params?: z.input) { - return requestParsed({ +export function getUsageRecordSummary(data: object) { + return request({ url: '/api/admin/usage/records/summary', method: 'GET', - params, - }, usageSummarySchema) + params: data, + }) } -export function getUsageRecordInsightsOverview(params?: z.input) { - return requestParsed({ +export function getUsageRecordInsightsOverview(data: object) { + return request({ url: '/api/admin/usage/records/insights/overview', method: 'GET', - params, - }, usageOverviewSchema) + params: data, + }) } -export function getUsageRecordInsightsDiagnostics( - params: z.input & { dimension: string }, -) { - return requestParsed({ +export function getUsageRecordInsightsDiagnostics(data: object) { + return request({ url: '/api/admin/usage/records/insights/diagnostics', method: 'GET', - params, - }, diagnosticsSchema) + params: data, + }) } diff --git a/frontend/src/api/request.ts b/frontend/src/api/request.ts index 278c31347..41598c044 100644 --- a/frontend/src/api/request.ts +++ b/frontend/src/api/request.ts @@ -4,25 +4,10 @@ import type { AxiosRequestConfig, AxiosResponse, } from 'axios' -import type { ZodType } from 'zod' import axios from 'axios' import { API_BASE_URL, API_TIMEOUT_MS } from './constants' -interface ApiEnvelope { - code: number - message: string - data: T -} - -interface ApiErrorBody { - code?: number - message?: string - data?: unknown -} - -type UnauthorizedHandler = () => void | Promise - export class ApiError extends Error { constructor( message: string, @@ -42,9 +27,9 @@ const http: AxiosInstance = axios.create({ }) let unauthorizedHandled = false -let unauthorizedHandler: UnauthorizedHandler | undefined +let unauthorizedHandler: (() => void | Promise) | undefined -export function setUnauthorizedHandler(handler: UnauthorizedHandler) { +export function setUnauthorizedHandler(handler: () => void | Promise) { unauthorizedHandler = handler } @@ -69,7 +54,7 @@ http.interceptors.response.use( (response: AxiosResponse) => { return response }, - (error: AxiosError) => { + (error: AxiosError) => { const { response } = error const status = response?.status || 0 @@ -85,7 +70,7 @@ http.interceptors.response.use( }, ) -function isApiEnvelope(value: unknown): value is ApiEnvelope { +function isApiEnvelope(value: any) { return ( typeof value === 'object' && value !== null @@ -96,7 +81,7 @@ function isApiEnvelope(value: unknown): value is ApiEnvelope { } export default async function request(config: AxiosRequestConfig) { - const response = await http.request>({ + const response = await http.request({ ...config, }) @@ -106,10 +91,3 @@ export default async function request(config: AxiosRequestConfig) { return response.data } - -export async function requestParsed( - config: AxiosRequestConfig, - schema: Schema, -) { - return schema.parse(await request(config)) -} diff --git a/frontend/src/api/streams/account-connection.ts b/frontend/src/api/streams/account-connection.ts deleted file mode 100644 index 9a995f3ca..000000000 --- a/frontend/src/api/streams/account-connection.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { z } from 'zod' - -import { API_BASE_URL } from '../constants' - -const requestPayloadSchema = z - .object({ - input: z - .array( - z - .object({ - content: z - .array( - z - .object({ - type: z.string().optional(), - text: z.string().optional(), - }) - .passthrough(), - ) - .optional(), - }) - .passthrough(), - ) - .optional(), - }) - .passthrough() - -const accountConnectionEventSchema = z.discriminatedUnion('type', [ - z.object({ type: z.literal('test_start'), model: z.string().optional() }), - z.object({ type: z.literal('request'), payload: requestPayloadSchema.optional() }), - z.object({ type: z.literal('status'), text: z.string().optional() }), - z.object({ type: z.literal('content'), text: z.string().optional() }), - z.object({ - type: z.literal('test_complete'), - success: z.boolean().optional(), - error: z.string().optional(), - accountStatus: z.string().optional(), - }), - z.object({ - type: z.literal('error'), - error: z.string().optional(), - accountStatus: z.string().optional(), - }), -]) - -export type AccountConnectionEvent = z.infer - -export function openAccountConnectionStream(options: { - accountId: string - modelId: string - onEvent: (event: AccountConnectionEvent) => void - onError: () => void -}) { - const params = new URLSearchParams({ - id: options.accountId, - modelId: options.modelId, - }) - const source = new EventSource(`${API_BASE_URL}/api/admin/accounts/test?${params}`, { - withCredentials: true, - }) - source.onmessage = (event) => { - try { - options.onEvent(accountConnectionEventSchema.parse(JSON.parse(event.data))) - } - catch { - options.onError() - } - } - source.onerror = options.onError - return source -} diff --git a/frontend/src/api/streams/system-update.ts b/frontend/src/api/streams/system-update.ts deleted file mode 100644 index 3dd273a81..000000000 --- a/frontend/src/api/streams/system-update.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { z } from 'zod' - -import { API_BASE_URL } from '../constants' - -const systemUpdateEventSchema = z.object({ - id: z.string(), - operationId: z.string().nullable().optional(), - level: z.enum(['info', 'success', 'warning', 'error']), - step: z.string().nullable().optional(), - message: z.string(), - terminal: z.boolean().optional(), - at: z.string(), -}) - -export type SystemUpdateEvent = z.infer - -export function openSystemUpdateStream(options: { - onOpen: () => void - onEvent: (event: SystemUpdateEvent) => void - onError: (closed: boolean) => void - onParseError: () => void -}) { - if (typeof EventSource === 'undefined') - return null - - const source = new EventSource(`${API_BASE_URL}/api/admin/system/update-events`, { - withCredentials: true, - }) - source.onopen = options.onOpen - source.addEventListener('update', (event) => { - try { - options.onEvent(systemUpdateEventSchema.parse(JSON.parse((event as MessageEvent).data))) - } - catch { - options.onParseError() - } - }) - source.onerror = () => { - options.onError(source.readyState === EventSource.CLOSED) - } - return source -} diff --git a/frontend/src/components/base/BaseForm/FormItem.vue b/frontend/src/components/base/BaseForm/FormItem.vue index e7529d3da..574e066d5 100644 --- a/frontend/src/components/base/BaseForm/FormItem.vue +++ b/frontend/src/components/base/BaseForm/FormItem.vue @@ -23,9 +23,12 @@ withDefaults( >
- + * diff --git a/frontend/src/components/base/BaseInput.vue b/frontend/src/components/base/BaseInput.vue index 56ceed470..5bf859599 100644 --- a/frontend/src/components/base/BaseInput.vue +++ b/frontend/src/components/base/BaseInput.vue @@ -8,6 +8,8 @@ const props = withDefaults( disabled?: boolean error?: string autocomplete?: string + name?: string + ariaLabel?: string }>(), { placeholder: '', @@ -15,6 +17,8 @@ const props = withDefaults( disabled: false, error: undefined, autocomplete: undefined, + name: undefined, + ariaLabel: undefined, }, ) @@ -54,7 +58,7 @@ const inputClasses = computed(() => [