ai-zero-token 2.0.7 → 2.0.8

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.
@@ -1 +1 @@
1
- import{t as e}from"./jsx-runtime-DqpGtLhh.js";import{t}from"./activity-D21-Xrc4.js";import{t as n}from"./server-BrjJPb9D.js";import{t as r}from"./zap-B4_oDbCp.js";import{m as i}from"./profiles-C5SmQvju.js";import{C as a,h as o,v as s,y as c}from"./index-CCiBaGwU.js";import{t as l}from"./InfoRow-0ULI9iI3.js";var u=e(),d=`https://github.com/fchangjun/AI-Zero-Token/releases`;function f(e){return(0,u.jsxs)(`section`,{className:`launch-page`,children:[(0,u.jsxs)(`div`,{className:`launch-copy`,children:[(0,u.jsxs)(`div`,{className:`launch-identity`,children:[(0,u.jsx)(`div`,{className:`launch-app-icon`,children:(0,u.jsx)(`img`,{src:a,alt:``})}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`span`,{className:`badge brand`,children:`Desktop Gateway`}),(0,u.jsx)(`h2`,{children:`AI Zero Token`}),(0,u.jsx)(`p`,{children:`本地 OpenAI 兼容网关、账号池和接口测试工作台。`})]})]}),(0,u.jsxs)(`div`,{className:`launch-metrics`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(o,{size:18}),(0,u.jsx)(`span`,{children:`账号池`}),(0,u.jsx)(`strong`,{children:e.config?.status.profileCount||0})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(n,{size:18}),(0,u.jsx)(`span`,{children:`网关`}),(0,u.jsx)(`strong`,{children:e.config?.status.loggedIn?`运行中`:`待登录`})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(t,{size:18}),(0,u.jsx)(`span`,{children:`模型`}),(0,u.jsx)(`strong`,{children:e.config?.settings.defaultModel||`-`})]})]}),(0,u.jsxs)(`div`,{className:`launch-actions`,children:[(0,u.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>e.onRoute(`accounts`),children:[(0,u.jsx)(o,{size:16}),`管理账号`]}),(0,u.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>e.onRoute(`tester`),children:[(0,u.jsx)(r,{size:16}),`测试接口`]}),(0,u.jsxs)(`a`,{className:`btn-secondary`,href:d,target:`_blank`,rel:`noreferrer`,children:[(0,u.jsx)(c,{size:16}),`桌面版下载`]}),(0,u.jsxs)(`a`,{className:`btn-secondary`,href:d,target:`_blank`,rel:`noreferrer`,title:`桌面版安装包发布后会放在这里`,children:[(0,u.jsx)(s,{size:16}),`发布页`]})]}),(0,u.jsx)(`p`,{className:`launch-download-note`,children:`当前还没有公开安装包时,这里会先打开 GitHub Releases 发布页。`}),(0,u.jsxs)(`div`,{className:`launch-status`,children:[(0,u.jsx)(l,{label:`当前账号`,value:i(e.activeProfile,e.showEmails)}),(0,u.jsx)(l,{label:`服务状态`,value:e.config?.status.loggedIn?`已登录并运行`:`等待登录`}),(0,u.jsx)(l,{label:`Base URL`,value:e.config?.baseUrl||`http://127.0.0.1:8787/v1`,code:!0}),(0,u.jsx)(l,{label:`同步消息`,value:e.status})]})]}),(0,u.jsx)(`div`,{className:`launch-visual`,children:(0,u.jsxs)(`div`,{className:`launch-visual-stage`,children:[(0,u.jsx)(`img`,{className:`launch-visual-mark`,src:a,alt:`AI Zero Token 图标`}),(0,u.jsx)(`img`,{className:`launch-visual-dashboard`,src:e.visualSrc||`data:image/svg+xml,%3csvg%20width='920'%20height='600'%20viewBox='0%200%20920%20600'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3crect%20width='920'%20height='600'%20rx='36'%20fill='%23F8FAFC'/%3e%3crect%20x='56'%20y='54'%20width='808'%20height='492'%20rx='24'%20fill='%23FFFFFF'%20stroke='%23D8E0EA'/%3e%3crect%20x='56'%20y='54'%20width='190'%20height='492'%20rx='24'%20fill='%23111827'/%3e%3cpath%20d='M246%2054h594c13.255%200%2024%2010.745%2024%2024v40H246V54Z'%20fill='%23F8FAFC'/%3e%3ccircle%20cx='88'%20cy='86'%20r='7'%20fill='%23EF4444'/%3e%3ccircle%20cx='112'%20cy='86'%20r='7'%20fill='%23F59E0B'/%3e%3ccircle%20cx='136'%20cy='86'%20r='7'%20fill='%2322C55E'/%3e%3crect%20x='86'%20y='148'%20width='108'%20height='14'%20rx='7'%20fill='%23E5E7EB'%20fill-opacity='.75'/%3e%3crect%20x='86'%20y='194'%20width='128'%20height='34'%20rx='10'%20fill='%232563EB'/%3e%3crect%20x='86'%20y='244'%20width='112'%20height='34'%20rx='10'%20fill='%231F2937'/%3e%3crect%20x='86'%20y='294'%20width='124'%20height='34'%20rx='10'%20fill='%231F2937'/%3e%3crect%20x='86'%20y='344'%20width='98'%20height='34'%20rx='10'%20fill='%231F2937'/%3e%3crect%20x='278'%20y='150'%20width='250'%20height='96'%20rx='18'%20fill='%23EFF6FF'%20stroke='%23BFDBFE'/%3e%3crect%20x='558'%20y='150'%20width='250'%20height='96'%20rx='18'%20fill='%23F0FDF4'%20stroke='%23BBF7D0'/%3e%3crect%20x='278'%20y='280'%20width='530'%20height='210'%20rx='18'%20fill='%23FFFFFF'%20stroke='%23D8E0EA'/%3e%3cpath%20d='M318%20430c43-68%2089-70%20137-8%2039%2049%2081%2037%20126-36%2038-62%2081-79%20129-21'%20stroke='%232563EB'%20stroke-width='8'%20stroke-linecap='round'/%3e%3cpath%20d='M318%20386c42-35%2083-33%20123%206%2045%2045%2092%2040%20141-16%2038-43%2080-49%20126-18'%20stroke='%2322C55E'%20stroke-width='8'%20stroke-linecap='round'/%3e%3crect%20x='318'%20y='316'%20width='118'%20height='13'%20rx='6.5'%20fill='%23111827'/%3e%3crect%20x='318'%20y='342'%20width='194'%20height='10'%20rx='5'%20fill='%23CBD5E1'/%3e%3crect%20x='596'%20y='182'%20width='80'%20height='12'%20rx='6'%20fill='%23111827'/%3e%3crect%20x='596'%20y='207'%20width='150'%20height='10'%20rx='5'%20fill='%2386EFAC'/%3e%3crect%20x='316'%20y='182'%20width='80'%20height='12'%20rx='6'%20fill='%23111827'/%3e%3crect%20x='316'%20y='207'%20width='150'%20height='10'%20rx='5'%20fill='%2393C5FD'/%3e%3ccircle%20cx='776'%20cy='198'%20r='16'%20fill='%2322C55E'/%3e%3cpath%20d='M768%20198l6%206%2011-13'%20stroke='%23FFFFFF'%20stroke-width='5'%20stroke-linecap='round'%20stroke-linejoin='round'/%3e%3cpath%20d='M478%20186l15%2020-15%2020-15-20%2015-20Z'%20fill='%232563EB'/%3e%3c/svg%3e`,alt:`AI Zero Token 桌面端启动页配图`})]})})]})}export{f as LaunchPage};
1
+ import{t as e}from"./jsx-runtime-DqpGtLhh.js";import{t}from"./activity-D21-Xrc4.js";import{t as n}from"./server-BrjJPb9D.js";import{t as r}from"./zap-B4_oDbCp.js";import{m as i}from"./profiles-C5SmQvju.js";import{C as a,h as o,v as s,y as c}from"./index-_5Ny0cZf.js";import{t as l}from"./InfoRow-0ULI9iI3.js";var u=e(),d=`https://github.com/fchangjun/AI-Zero-Token/releases`;function f(e){return(0,u.jsxs)(`section`,{className:`launch-page`,children:[(0,u.jsxs)(`div`,{className:`launch-copy`,children:[(0,u.jsxs)(`div`,{className:`launch-identity`,children:[(0,u.jsx)(`div`,{className:`launch-app-icon`,children:(0,u.jsx)(`img`,{src:a,alt:``})}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`span`,{className:`badge brand`,children:`Desktop Gateway`}),(0,u.jsx)(`h2`,{children:`AI Zero Token`}),(0,u.jsx)(`p`,{children:`本地 OpenAI 兼容网关、账号池和接口测试工作台。`})]})]}),(0,u.jsxs)(`div`,{className:`launch-metrics`,children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(o,{size:18}),(0,u.jsx)(`span`,{children:`账号池`}),(0,u.jsx)(`strong`,{children:e.config?.status.profileCount||0})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(n,{size:18}),(0,u.jsx)(`span`,{children:`网关`}),(0,u.jsx)(`strong`,{children:e.config?.status.loggedIn?`运行中`:`待登录`})]}),(0,u.jsxs)(`div`,{children:[(0,u.jsx)(t,{size:18}),(0,u.jsx)(`span`,{children:`模型`}),(0,u.jsx)(`strong`,{children:e.config?.settings.defaultModel||`-`})]})]}),(0,u.jsxs)(`div`,{className:`launch-actions`,children:[(0,u.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>e.onRoute(`accounts`),children:[(0,u.jsx)(o,{size:16}),`管理账号`]}),(0,u.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>e.onRoute(`tester`),children:[(0,u.jsx)(r,{size:16}),`测试接口`]}),(0,u.jsxs)(`a`,{className:`btn-secondary`,href:d,target:`_blank`,rel:`noreferrer`,children:[(0,u.jsx)(c,{size:16}),`桌面版下载`]}),(0,u.jsxs)(`a`,{className:`btn-secondary`,href:d,target:`_blank`,rel:`noreferrer`,title:`桌面版安装包发布后会放在这里`,children:[(0,u.jsx)(s,{size:16}),`发布页`]})]}),(0,u.jsx)(`p`,{className:`launch-download-note`,children:`当前还没有公开安装包时,这里会先打开 GitHub Releases 发布页。`}),(0,u.jsxs)(`div`,{className:`launch-status`,children:[(0,u.jsx)(l,{label:`当前账号`,value:i(e.activeProfile,e.showEmails)}),(0,u.jsx)(l,{label:`服务状态`,value:e.config?.status.loggedIn?`已登录并运行`:`等待登录`}),(0,u.jsx)(l,{label:`Base URL`,value:e.config?.baseUrl||`http://127.0.0.1:8787/v1`,code:!0}),(0,u.jsx)(l,{label:`同步消息`,value:e.status})]})]}),(0,u.jsx)(`div`,{className:`launch-visual`,children:(0,u.jsxs)(`div`,{className:`launch-visual-stage`,children:[(0,u.jsx)(`img`,{className:`launch-visual-mark`,src:a,alt:`AI Zero Token 图标`}),(0,u.jsx)(`img`,{className:`launch-visual-dashboard`,src:e.visualSrc||`data:image/svg+xml,%3csvg%20width='920'%20height='600'%20viewBox='0%200%20920%20600'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3crect%20width='920'%20height='600'%20rx='36'%20fill='%23F8FAFC'/%3e%3crect%20x='56'%20y='54'%20width='808'%20height='492'%20rx='24'%20fill='%23FFFFFF'%20stroke='%23D8E0EA'/%3e%3crect%20x='56'%20y='54'%20width='190'%20height='492'%20rx='24'%20fill='%23111827'/%3e%3cpath%20d='M246%2054h594c13.255%200%2024%2010.745%2024%2024v40H246V54Z'%20fill='%23F8FAFC'/%3e%3ccircle%20cx='88'%20cy='86'%20r='7'%20fill='%23EF4444'/%3e%3ccircle%20cx='112'%20cy='86'%20r='7'%20fill='%23F59E0B'/%3e%3ccircle%20cx='136'%20cy='86'%20r='7'%20fill='%2322C55E'/%3e%3crect%20x='86'%20y='148'%20width='108'%20height='14'%20rx='7'%20fill='%23E5E7EB'%20fill-opacity='.75'/%3e%3crect%20x='86'%20y='194'%20width='128'%20height='34'%20rx='10'%20fill='%232563EB'/%3e%3crect%20x='86'%20y='244'%20width='112'%20height='34'%20rx='10'%20fill='%231F2937'/%3e%3crect%20x='86'%20y='294'%20width='124'%20height='34'%20rx='10'%20fill='%231F2937'/%3e%3crect%20x='86'%20y='344'%20width='98'%20height='34'%20rx='10'%20fill='%231F2937'/%3e%3crect%20x='278'%20y='150'%20width='250'%20height='96'%20rx='18'%20fill='%23EFF6FF'%20stroke='%23BFDBFE'/%3e%3crect%20x='558'%20y='150'%20width='250'%20height='96'%20rx='18'%20fill='%23F0FDF4'%20stroke='%23BBF7D0'/%3e%3crect%20x='278'%20y='280'%20width='530'%20height='210'%20rx='18'%20fill='%23FFFFFF'%20stroke='%23D8E0EA'/%3e%3cpath%20d='M318%20430c43-68%2089-70%20137-8%2039%2049%2081%2037%20126-36%2038-62%2081-79%20129-21'%20stroke='%232563EB'%20stroke-width='8'%20stroke-linecap='round'/%3e%3cpath%20d='M318%20386c42-35%2083-33%20123%206%2045%2045%2092%2040%20141-16%2038-43%2080-49%20126-18'%20stroke='%2322C55E'%20stroke-width='8'%20stroke-linecap='round'/%3e%3crect%20x='318'%20y='316'%20width='118'%20height='13'%20rx='6.5'%20fill='%23111827'/%3e%3crect%20x='318'%20y='342'%20width='194'%20height='10'%20rx='5'%20fill='%23CBD5E1'/%3e%3crect%20x='596'%20y='182'%20width='80'%20height='12'%20rx='6'%20fill='%23111827'/%3e%3crect%20x='596'%20y='207'%20width='150'%20height='10'%20rx='5'%20fill='%2386EFAC'/%3e%3crect%20x='316'%20y='182'%20width='80'%20height='12'%20rx='6'%20fill='%23111827'/%3e%3crect%20x='316'%20y='207'%20width='150'%20height='10'%20rx='5'%20fill='%2393C5FD'/%3e%3ccircle%20cx='776'%20cy='198'%20r='16'%20fill='%2322C55E'/%3e%3cpath%20d='M768%20198l6%206%2011-13'%20stroke='%23FFFFFF'%20stroke-width='5'%20stroke-linecap='round'%20stroke-linejoin='round'/%3e%3cpath%20d='M478%20186l15%2020-15%2020-15-20%2015-20Z'%20fill='%232563EB'/%3e%3c/svg%3e`,alt:`AI Zero Token 桌面端启动页配图`})]})})]})}export{f as LaunchPage};
@@ -1 +1 @@
1
- import{a as e,n as t,r as n,t as r}from"./jsx-runtime-DqpGtLhh.js";import{t as i}from"./search-B2hz41D3.js";import{T as a,w as o,x as s}from"./profiles-C5SmQvju.js";import{b as c,n as l}from"./index-CCiBaGwU.js";var u=t(`funnel`,[[`path`,{d:`M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z`,key:`sc7q7i`}]]),d=e(n(),1),f=r();function p(e){let[t,n]=(0,d.useState)(``),[r,p]=(0,d.useState)(`all`),[m,h]=(0,d.useState)(`all`),[g,_]=(0,d.useState)(`all`),[v,y]=(0,d.useState)(null);(0,d.useEffect)(()=>{if(e.logs.length===0){y(null);return}(!v||!e.logs.some(e=>e.id===v))&&y(e.logs[0].id)},[e.logs,v]);let b=(0,d.useMemo)(()=>Array.from(new Set(e.logs.map(e=>e.source||`管理页`))),[e.logs]),x=(0,d.useMemo)(()=>Array.from(new Set(e.logs.map(e=>e.method))),[e.logs]),S=(0,d.useMemo)(()=>{let n=t.trim().toLowerCase();return e.logs.filter(e=>{let t=[e.time,e.method,e.endpoint,e.account,e.model,e.statusCode,e.durationMs,e.source].join(` `).toLowerCase();return!(n&&!t.includes(n)||r!==`all`&&e.method!==r||m!==`all`&&(e.source||`管理页`)!==m||g===`ok`&&e.statusCode>=400||g===`error`&&e.statusCode<400)})},[r,e.logs,t,m,g]),C=S.find(e=>e.id===v)||S[0]||null;function w(){C&&l(o(C)).then(e=>{}).catch(()=>void 0)}return(0,f.jsxs)(`section`,{className:`log-table-wrap`,id:`logs`,children:[(0,f.jsx)(`div`,{className:`section-head compact`,children:(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`h2`,{children:`请求日志`}),(0,f.jsx)(`p`,{children:`记录网关最近收到的 API 请求,详情为安全摘要。`})]})}),(0,f.jsxs)(`div`,{className:`log-toolbar`,children:[(0,f.jsxs)(`label`,{className:`search-box log-search`,children:[(0,f.jsx)(i,{size:16}),(0,f.jsx)(`input`,{value:t,onChange:e=>n(e.target.value),placeholder:`搜索时间、接口、账号、模型或状态`})]}),(0,f.jsxs)(`label`,{className:`filter-chip`,children:[(0,f.jsx)(u,{size:14}),(0,f.jsxs)(`select`,{value:r,onChange:e=>p(e.target.value),children:[(0,f.jsx)(`option`,{value:`all`,children:`全部方法`}),x.map(e=>(0,f.jsx)(`option`,{value:e,children:e},e))]})]}),(0,f.jsx)(`label`,{className:`filter-chip`,children:(0,f.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),children:[(0,f.jsx)(`option`,{value:`all`,children:`全部来源`}),b.map(e=>(0,f.jsx)(`option`,{value:e,children:e},e))]})}),(0,f.jsx)(`label`,{className:`filter-chip`,children:(0,f.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),children:[(0,f.jsx)(`option`,{value:`all`,children:`全部状态`}),(0,f.jsx)(`option`,{value:`ok`,children:`成功`}),(0,f.jsx)(`option`,{value:`error`,children:`失败`})]})})]}),(0,f.jsx)(`div`,{className:`table-scroller`,children:(0,f.jsxs)(`table`,{children:[(0,f.jsx)(`thead`,{children:(0,f.jsxs)(`tr`,{children:[(0,f.jsx)(`th`,{children:`时间`}),(0,f.jsx)(`th`,{children:`方法`}),(0,f.jsx)(`th`,{children:`接口`}),(0,f.jsx)(`th`,{children:`账号`}),(0,f.jsx)(`th`,{children:`模型`}),(0,f.jsx)(`th`,{children:`状态`}),(0,f.jsx)(`th`,{children:`耗时`}),(0,f.jsx)(`th`,{children:`来源`})]})}),(0,f.jsx)(`tbody`,{children:S.length===0?(0,f.jsx)(`tr`,{children:(0,f.jsx)(`td`,{colSpan:8,children:`最近 API 请求会在这里显示。`})}):S.map(e=>(0,f.jsxs)(`tr`,{className:e.id===C?.id?`is-selected`:``,onClick:()=>y(e.id),children:[(0,f.jsx)(`td`,{children:a(e.time)}),(0,f.jsx)(`td`,{children:(0,f.jsx)(`span`,{className:`method-pill method-${e.method.toLowerCase()}`,children:e.method})}),(0,f.jsx)(`td`,{children:(0,f.jsx)(`code`,{children:e.endpoint})}),(0,f.jsx)(`td`,{children:e.account}),(0,f.jsx)(`td`,{children:e.model}),(0,f.jsx)(`td`,{children:(0,f.jsx)(`span`,{className:`status-pill ${e.statusCode>=400?`is-error`:`is-ok`}`,children:e.statusCode})}),(0,f.jsx)(`td`,{children:s(e.durationMs)}),(0,f.jsx)(`td`,{children:e.source||`管理页`})]},e.id))})]})}),(0,f.jsxs)(`div`,{className:`table-footer`,children:[`当前展示 `,S.length,` 条请求记录,最近总计 `,e.logs.length,` 条。`]}),C&&(0,f.jsxs)(`div`,{className:`log-detail-panel`,children:[(0,f.jsxs)(`div`,{className:`log-detail-head`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`h3`,{children:`日志详情`}),(0,f.jsxs)(`p`,{children:[a(C.time),` · `,C.method,` `,C.endpoint]})]}),(0,f.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:w,children:[(0,f.jsx)(c,{size:16}),`复制详情`]})]}),(0,f.jsxs)(`div`,{className:`log-detail-grid`,children:[(0,f.jsxs)(`div`,{className:`log-detail-meta`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{children:`账号`}),(0,f.jsx)(`strong`,{children:C.account})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{children:`模型`}),(0,f.jsx)(`strong`,{children:C.model})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{children:`状态`}),(0,f.jsx)(`strong`,{children:C.statusCode})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{children:`耗时`}),(0,f.jsx)(`strong`,{children:s(C.durationMs)})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{children:`来源`}),(0,f.jsx)(`strong`,{children:C.source||`管理页`})]})]}),(0,f.jsx)(`pre`,{className:`pre log-detail-pre`,children:o(C)})]})]})]})}function m(e){return(0,f.jsx)(p,{logs:e.logs})}export{m as LogsPage};
1
+ import{a as e,n as t,r as n,t as r}from"./jsx-runtime-DqpGtLhh.js";import{t as i}from"./search-B2hz41D3.js";import{T as a,w as o,x as s}from"./profiles-C5SmQvju.js";import{b as c,n as l}from"./index-_5Ny0cZf.js";var u=t(`funnel`,[[`path`,{d:`M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z`,key:`sc7q7i`}]]),d=e(n(),1),f=r();function p(e){let[t,n]=(0,d.useState)(``),[r,p]=(0,d.useState)(`all`),[m,h]=(0,d.useState)(`all`),[g,_]=(0,d.useState)(`all`),[v,y]=(0,d.useState)(null);(0,d.useEffect)(()=>{if(e.logs.length===0){y(null);return}(!v||!e.logs.some(e=>e.id===v))&&y(e.logs[0].id)},[e.logs,v]);let b=(0,d.useMemo)(()=>Array.from(new Set(e.logs.map(e=>e.source||`管理页`))),[e.logs]),x=(0,d.useMemo)(()=>Array.from(new Set(e.logs.map(e=>e.method))),[e.logs]),S=(0,d.useMemo)(()=>{let n=t.trim().toLowerCase();return e.logs.filter(e=>{let t=[e.time,e.method,e.endpoint,e.account,e.model,e.statusCode,e.durationMs,e.source].join(` `).toLowerCase();return!(n&&!t.includes(n)||r!==`all`&&e.method!==r||m!==`all`&&(e.source||`管理页`)!==m||g===`ok`&&e.statusCode>=400||g===`error`&&e.statusCode<400)})},[r,e.logs,t,m,g]),C=S.find(e=>e.id===v)||S[0]||null;function w(){C&&l(o(C)).then(e=>{}).catch(()=>void 0)}return(0,f.jsxs)(`section`,{className:`log-table-wrap`,id:`logs`,children:[(0,f.jsx)(`div`,{className:`section-head compact`,children:(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`h2`,{children:`请求日志`}),(0,f.jsx)(`p`,{children:`记录网关最近收到的 API 请求,详情为安全摘要。`})]})}),(0,f.jsxs)(`div`,{className:`log-toolbar`,children:[(0,f.jsxs)(`label`,{className:`search-box log-search`,children:[(0,f.jsx)(i,{size:16}),(0,f.jsx)(`input`,{value:t,onChange:e=>n(e.target.value),placeholder:`搜索时间、接口、账号、模型或状态`})]}),(0,f.jsxs)(`label`,{className:`filter-chip`,children:[(0,f.jsx)(u,{size:14}),(0,f.jsxs)(`select`,{value:r,onChange:e=>p(e.target.value),children:[(0,f.jsx)(`option`,{value:`all`,children:`全部方法`}),x.map(e=>(0,f.jsx)(`option`,{value:e,children:e},e))]})]}),(0,f.jsx)(`label`,{className:`filter-chip`,children:(0,f.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),children:[(0,f.jsx)(`option`,{value:`all`,children:`全部来源`}),b.map(e=>(0,f.jsx)(`option`,{value:e,children:e},e))]})}),(0,f.jsx)(`label`,{className:`filter-chip`,children:(0,f.jsxs)(`select`,{value:g,onChange:e=>_(e.target.value),children:[(0,f.jsx)(`option`,{value:`all`,children:`全部状态`}),(0,f.jsx)(`option`,{value:`ok`,children:`成功`}),(0,f.jsx)(`option`,{value:`error`,children:`失败`})]})})]}),(0,f.jsx)(`div`,{className:`table-scroller`,children:(0,f.jsxs)(`table`,{children:[(0,f.jsx)(`thead`,{children:(0,f.jsxs)(`tr`,{children:[(0,f.jsx)(`th`,{children:`时间`}),(0,f.jsx)(`th`,{children:`方法`}),(0,f.jsx)(`th`,{children:`接口`}),(0,f.jsx)(`th`,{children:`账号`}),(0,f.jsx)(`th`,{children:`模型`}),(0,f.jsx)(`th`,{children:`状态`}),(0,f.jsx)(`th`,{children:`耗时`}),(0,f.jsx)(`th`,{children:`来源`})]})}),(0,f.jsx)(`tbody`,{children:S.length===0?(0,f.jsx)(`tr`,{children:(0,f.jsx)(`td`,{colSpan:8,children:`最近 API 请求会在这里显示。`})}):S.map(e=>(0,f.jsxs)(`tr`,{className:e.id===C?.id?`is-selected`:``,onClick:()=>y(e.id),children:[(0,f.jsx)(`td`,{children:a(e.time)}),(0,f.jsx)(`td`,{children:(0,f.jsx)(`span`,{className:`method-pill method-${e.method.toLowerCase()}`,children:e.method})}),(0,f.jsx)(`td`,{children:(0,f.jsx)(`code`,{children:e.endpoint})}),(0,f.jsx)(`td`,{children:e.account}),(0,f.jsx)(`td`,{children:e.model}),(0,f.jsx)(`td`,{children:(0,f.jsx)(`span`,{className:`status-pill ${e.statusCode>=400?`is-error`:`is-ok`}`,children:e.statusCode})}),(0,f.jsx)(`td`,{children:s(e.durationMs)}),(0,f.jsx)(`td`,{children:e.source||`管理页`})]},e.id))})]})}),(0,f.jsxs)(`div`,{className:`table-footer`,children:[`当前展示 `,S.length,` 条请求记录,最近总计 `,e.logs.length,` 条。`]}),C&&(0,f.jsxs)(`div`,{className:`log-detail-panel`,children:[(0,f.jsxs)(`div`,{className:`log-detail-head`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`h3`,{children:`日志详情`}),(0,f.jsxs)(`p`,{children:[a(C.time),` · `,C.method,` `,C.endpoint]})]}),(0,f.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:w,children:[(0,f.jsx)(c,{size:16}),`复制详情`]})]}),(0,f.jsxs)(`div`,{className:`log-detail-grid`,children:[(0,f.jsxs)(`div`,{className:`log-detail-meta`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{children:`账号`}),(0,f.jsx)(`strong`,{children:C.account})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{children:`模型`}),(0,f.jsx)(`strong`,{children:C.model})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{children:`状态`}),(0,f.jsx)(`strong`,{children:C.statusCode})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{children:`耗时`}),(0,f.jsx)(`strong`,{children:s(C.durationMs)})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`span`,{children:`来源`}),(0,f.jsx)(`strong`,{children:C.source||`管理页`})]})]}),(0,f.jsx)(`pre`,{className:`pre log-detail-pre`,children:o(C)})]})]})]})}function m(e){return(0,f.jsx)(p,{logs:e.logs})}export{m as LogsPage};
@@ -1 +1 @@
1
- import{a as e,n as t,r as n,t as r}from"./jsx-runtime-DqpGtLhh.js";import{t as i}from"./activity-D21-Xrc4.js";import{t as a}from"./circle-check-ZYtn9GqY.js";import{t as o}from"./clock-3-BzDANsVk.js";import{t as s}from"./refresh-cw-CAAH2rqe.js";import{t as c}from"./server-BrjJPb9D.js";import{g as l,m as u,p as ee}from"./index-CCiBaGwU.js";var d=t(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),f=t(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),p=t(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),m=e(n(),1),h=`data:image/svg+xml,%3csvg%20role='img'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eClaude%3c/title%3e%3cpath%20d='m4.7144%2015.9555%204.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608%201.5179.1032%202.2767.1578%201.6514.0972%202.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973%209.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686%201.9064%201.4754%202.4893%201.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335%206.6997%200l.9957.1336.419.3642.6192%201.4147%201.0018%202.2282%201.5543%203.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853%201.8517-.5586%202.9021-.3643%201.9429h.2125l.2429-.2429.9835-1.3053%201.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759%201.1293-.34%201.1657-1.0625%201.3478-.8804%201.1414-1.2628%201.7-.7893%201.36.0729.1093.1882-.0183%202.8535-.607%201.5421-.2794%201.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607%201.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929%201.0686%202.0035%201.8092%202.5075%202.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496%202.3436%203.5214.1214%201.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38%2017.959l-1.1414-1.9428-.1397.079-.674%207.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328%201.9672-2.1796%202.9446-1.7243%201.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889%202.386-3.0357%201.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385%204.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429%201.9064-1.3114Z'/%3e%3c/svg%3e`,g=`data:image/svg+xml,%3csvg%20role='img'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eOpenAI%3c/title%3e%3cpath%20d='M22.2819%209.8211a5.9847%205.9847%200%200%200-.5157-4.9108%206.0462%206.0462%200%200%200-6.5098-2.9A6.0651%206.0651%200%200%200%204.9807%204.1818a5.9847%205.9847%200%200%200-3.9977%202.9%206.0462%206.0462%200%200%200%20.7427%207.0966%205.98%205.98%200%200%200%20.511%204.9107%206.051%206.051%200%200%200%206.5146%202.9001A5.9847%205.9847%200%200%200%2013.2599%2024a6.0557%206.0557%200%200%200%205.7718-4.2058%205.9894%205.9894%200%200%200%203.9977-2.9001%206.0557%206.0557%200%200%200-.7475-7.0729zm-9.022%2012.6081a4.4755%204.4755%200%200%201-2.8764-1.0408l.1419-.0804%204.7783-2.7582a.7948.7948%200%200%200%20.3927-.6813v-6.7369l2.02%201.1686a.071.071%200%200%201%20.038.052v5.5826a4.504%204.504%200%200%201-4.4945%204.4944zm-9.6607-4.1254a4.4708%204.4708%200%200%201-.5346-3.0137l.142.0852%204.783%202.7582a.7712.7712%200%200%200%20.7806%200l5.8428-3.3685v2.3324a.0804.0804%200%200%201-.0332.0615L9.74%2019.9502a4.4992%204.4992%200%200%201-6.1408-1.6464zM2.3408%207.8956a4.485%204.485%200%200%201%202.3655-1.9728V11.6a.7664.7664%200%200%200%20.3879.6765l5.8144%203.3543-2.0201%201.1685a.0757.0757%200%200%201-.071%200l-4.8303-2.7865A4.504%204.504%200%200%201%202.3408%207.872zm16.5963%203.8558L13.1038%208.364%2015.1192%207.2a.0757.0757%200%200%201%20.071%200l4.8303%202.7913a4.4944%204.4944%200%200%201-.6765%208.1042v-5.6772a.79.79%200%200%200-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759%200%200%200-.7854%200L9.409%209.2297V6.8974a.0662.0662%200%200%201%20.0284-.0615l4.8303-2.7866a4.4992%204.4992%200%200%201%206.6802%204.66zM8.3065%2012.863l-2.02-1.1638a.0804.0804%200%200%201-.038-.0567V6.0742a4.4992%204.4992%200%200%201%207.3757-3.4537l-.142.0805L8.704%205.459a.7948.7948%200%200%200-.3927.6813zm1.0976-2.3654l2.602-1.4998%202.6069%201.4998v2.9994l-2.5974%201.4997-2.6067-1.4997Z'/%3e%3c/svg%3e`,_=`data:image/svg+xml,%3csvg%20role='img'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eGoogle%3c/title%3e%3cpath%20d='M12.48%2010.92v3.28h7.84c-.24%201.84-.853%203.187-1.787%204.133-1.147%201.147-2.933%202.4-6.053%202.4-4.827%200-8.6-3.893-8.6-8.72s3.773-8.72%208.6-8.72c2.6%200%204.507%201.027%205.907%202.347l2.307-2.307C18.747%201.44%2016.133%200%2012.48%200%205.867%200%20.307%205.387.307%2012s5.56%2012%2012.173%2012c3.573%200%206.267-1.173%208.373-3.36%202.16-2.16%202.84-5.213%202.84-7.667%200-.76-.053-1.467-.173-2.053H12.48z'/%3e%3c/svg%3e`,v=`data:image/svg+xml,%3csvg%20role='img'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eX%3c/title%3e%3cpath%20d='M14.234%2010.162%2022.977%200h-2.072l-7.591%208.824L7.251%200H.258l9.168%2013.343L.258%2024H2.33l8.016-9.318L16.749%2024h6.993zm-2.837%203.299-.929-1.329L3.076%201.56h3.182l5.965%208.532.929%201.329%207.754%2011.09h-3.182z'/%3e%3c/svg%3e`,y=`data:image/svg+xml,%3csvg%20role='img'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eYouTube%3c/title%3e%3cpath%20d='M23.498%206.186a3.016%203.016%200%200%200-2.122-2.136C19.505%203.545%2012%203.545%2012%203.545s-7.505%200-9.377.505A3.017%203.017%200%200%200%20.502%206.186C0%208.07%200%2012%200%2012s0%203.93.502%205.814a3.016%203.016%200%200%200%202.122%202.136c1.871.505%209.376.505%209.376.505s7.505%200%209.377-.505a3.015%203.015%200%200%200%202.122-2.136C24%2015.93%2024%2012%2024%2012s0-3.93-.502-5.814zM9.545%2015.568V8.432L15.818%2012l-6.273%203.568z'/%3e%3c/svg%3e`,b=r(),x={claude:h,chatgpt:g,google:_,x:v,youtube:y};function S(e){return`tone-${e}`}function C(e){try{return new URL(e).hostname.replace(/^www\./i,``)}catch{return e}}function w(e){return/^(10|127|169\.254|172\.(1[6-9]|2\d|3[0-1])|192\.168)\./.test(e)||/^100\.(6[4-9]|[7-9]\d|1\d\d|2[0-3]\d|24[0-7])\./.test(e)||/^198\.(18|19)\./.test(e)||/^192\.0\.2\./.test(e)||/^198\.51\.100\./.test(e)||/^203\.0\.113\./.test(e)||/^fc00:/i.test(e)||/^fd00:/i.test(e)||/^fe80:/i.test(e)||/^::1$/.test(e)}function T(e){let t=e.match(/Electron\/([\d.]+)/i);if(t)return`Electron ${t[1]}`;let n=e.match(/Chrome\/([\d.]+)/i);if(n&&/Safari\//i.test(e))return`Chrome ${n[1].split(`.`)[0]}`;let r=e.match(/Version\/([\d.]+).*Safari\//i);if(r&&!/Chrome\//i.test(e))return`Safari ${r[1].split(`.`)[0]}`;let i=e.match(/Firefox\/([\d.]+)/i);return i?`Firefox ${i[1].split(`.`)[0]}`:e.slice(0,40)}async function E(){if(typeof RTCPeerConnection>`u`)return{status:`不支持`,detail:`当前环境不支持 WebRTC。`,tone:`orange`,candidates:[]};let e=new Set,t=new RTCPeerConnection({iceServers:[]}),n=!1,r=new Promise(r=>{t.onicecandidate=t=>{t.candidate?.candidate&&e.add(t.candidate.candidate),t.candidate||(n=!0,r())}});try{t.createDataChannel(`probe`);let e=await t.createOffer();await t.setLocalDescription(e),await Promise.race([r,new Promise(e=>window.setTimeout(e,2400))])}catch{}finally{t.close()}let i=[...e],a=i.some(e=>/\btyp srflx\b/.test(e)||/\btyp relay\b/.test(e)),o=i.some(e=>/\btyp host\b/.test(e));return a?{status:`需要留意`,detail:`收集到 ${i.length} 个候选地址,其中包含公网回显特征。`,tone:`red`,candidates:i}:o||n?{status:`本地候选为主`,detail:`收集到 ${i.length} 个候选地址,主要来自本地网段。`,tone:`orange`,candidates:i}:{status:`暂未发现异常`,detail:`未收集到可识别的候选地址。`,tone:`green`,candidates:i}}async function D(){let[e]=await Promise.all([E()]);return{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone||`-`,language:navigator.language||`-`,browser:T(navigator.userAgent||``),webrtc:e}}function O(e){return e.length===0?`slate`:e.some(e=>w(e))?`orange`:`green`}function k(e){return e.length===0?`未读取`:e.some(e=>w(e))?`内网 / 企业 DNS`:`公网 DNS`}function A(e){return{total:e.length,reachable:e.filter(e=>e.status===`可达`).length,limited:e.filter(e=>e.status===`受限`).length,unavailable:e.filter(e=>e.status===`不可用`).length}}function j(e,t){return!e||t.total===0?{label:`正在判断海外访问`,detail:`正在检查 ChatGPT、Claude、Google、YouTube 和 X 的连通性。`,tone:`blue`}:t.unavailable>0?{label:`海外访问受阻`,detail:`${t.unavailable} 个海外应用不可用,优先检查代理出口、DNS 或上游链路。`,tone:`red`}:t.limited>0?{label:`部分应用受限`,detail:`${t.reachable}/${t.total} 个海外应用可达,其余应用返回限制状态。`,tone:`orange`}:{label:`海外应用可访问`,detail:`${t.total} 个目标应用均已连通,当前出口可用于海外反向代理场景。`,tone:`green`}}function te(e,t){if(!e&&!t)return{label:`检测中`,detail:`正在采集公网出口、DNS、WebRTC、代理和平台可达性。`,tone:`blue`};if(!e||!t)return{label:`部分结果`,detail:`已有项目返回,剩余项目会保留失败原因,方便继续排查。`,tone:`orange`};let n=e.publicIpv4.available&&!!e.publicIpv4.ip,r=e.publicIpv6.available&&!!e.publicIpv6.ip,i=[e.platforms.some(e=>e.tone===`red`),t.webrtc.tone===`red`,!n&&!r],a=[e.platforms.some(e=>e.tone===`orange`),t.webrtc.tone===`orange`,O(e.dns.servers)!==`green`,!n,!e.publicIpv6.available];return i.some(Boolean)?{label:`建议先处理`,detail:`有明显阻塞项,先把出口或浏览器回显风险排掉。`,tone:`red`}:a.some(Boolean)?{label:`需要留意`,detail:`结果可用,但有几项信息值得再看一眼。`,tone:`orange`}:{label:`状态正常`,detail:`出口、DNS、WebRTC 和常用平台状态都比较稳定。`,tone:`green`}}function M(e){return(0,b.jsx)(`span`,{className:`network-chip ${e.tone}`,children:e.children})}function N(e){return(0,b.jsxs)(`span`,{className:`access-badge ${e.tone}`,children:[e.tone===`green`?(0,b.jsx)(a,{size:13}):e.tone===`red`?(0,b.jsx)(d,{size:13}):(0,b.jsx)(p,{size:13}),e.children]})}function P(e){let t=e.platformKey.toLowerCase(),n=x[t];return(0,b.jsx)(`span`,{className:`platform-icon ${e.tone} platform-${t}`,children:n?(0,b.jsx)(`img`,{alt:``,src:n}):e.icon})}function F(e){return(0,b.jsxs)(`div`,{className:`network-metric ${S(e.tone)}`,children:[(0,b.jsx)(`span`,{children:e.label}),(0,b.jsx)(`strong`,{children:e.value}),e.detail?(0,b.jsx)(`p`,{children:e.detail}):null]})}function I(e){let t=e.icon;return(0,b.jsxs)(`div`,{className:`signal-card ${S(e.tone)}`,children:[(0,b.jsx)(`div`,{className:`signal-card-icon`,children:(0,b.jsx)(t,{size:17})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`span`,{children:e.label}),(0,b.jsx)(`strong`,{children:e.value}),(0,b.jsx)(`p`,{children:e.detail})]})]})}function L(e){return(0,b.jsxs)(`div`,{className:`network-block ${S(e.tone)}`,children:[(0,b.jsx)(`span`,{children:e.label}),(0,b.jsx)(`strong`,{children:e.value}),(0,b.jsx)(`p`,{children:e.detail})]})}function R(e){let{item:t}=e;return(0,b.jsxs)(`div`,{className:`platform-access-row ${t.tone}`,children:[(0,b.jsxs)(`div`,{className:`platform-access-main`,children:[(0,b.jsx)(P,{icon:t.label.slice(0,1),tone:t.tone,platformKey:t.key}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`strong`,{children:t.label}),(0,b.jsx)(`span`,{children:C(t.url)})]})]}),(0,b.jsxs)(`div`,{className:`platform-access-result`,children:[(0,b.jsx)(N,{tone:t.tone,children:t.status}),(0,b.jsx)(`span`,{children:t.httpStatus?`HTTP ${t.httpStatus}`:`连接结果`})]}),(0,b.jsxs)(`div`,{className:`platform-access-latency`,children:[(0,b.jsx)(`strong`,{children:z(t.elapsedMs)}),(0,b.jsx)(`span`,{children:t.httpStatus?`${t.httpStatus} 响应`:`等待结果`})]}),(0,b.jsx)(`div`,{className:`platform-access-detail`,children:(0,b.jsx)(`span`,{children:t.detail})})]})}function z(e){return typeof e==`number`?`${e} ms`:`-`}function B(e){return e instanceof DOMException&&e.name===`AbortError`?`网络探测超过 18 秒,已停止等待。`:e instanceof Error?e.message:String(e)}function V(){let[e,t]=(0,m.useState)(null),[n,r]=(0,m.useState)(null),[a,d]=(0,m.useState)(!0),[p,h]=(0,m.useState)(`正在采集真实网络状态...`),[g,_]=(0,m.useState)(null);async function v(){d(!0),_(null),h(`正在采集真实网络状态...`);let e=new AbortController,n=window.setTimeout(()=>e.abort(),18e3);try{let[n,i]=await Promise.allSettled([ee(`/_gateway/admin/network-detect`,{signal:e.signal}),D()]);n.status===`fulfilled`&&t(n.value),i.status===`fulfilled`&&r(i.value);let a=[];n.status===`rejected`&&a.push(`网络探测: ${B(n.reason)}`),i.status===`rejected`&&a.push(`本地环境: ${B(i.reason)}`);let o=n.status===`fulfilled`&&i.status===`fulfilled`?`检测完成。`:n.status===`fulfilled`||i.status===`fulfilled`?`部分结果已更新。`:`检测失败。`;_(a.length>0?a.join(` · `):null),h(o)}catch(e){_(B(e)),h(`检测失败。`)}finally{window.clearTimeout(n),d(!1)}}(0,m.useEffect)(()=>{v().catch(()=>void 0)},[]);let y=(0,m.useMemo)(()=>e?new Intl.DateTimeFormat(`zh-CN`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}).format(new Date(e.checkedAt)):`--:--:--`,[e]),x=te(e,n),S=O(e?.dns.servers||[]),C=k(e?.dns.servers||[]),T=e?.dns.servers?.length?e.dns.servers.slice(0,2).join(` / `):`-`,E=e?.dns.detail||`尚未检测到系统 DNS。`,N=A(e?.platforms||[]),P=e?e.publicIpv4.available&&e.publicIpv4.ip?`green`:`orange`:`blue`,V=e?e.publicIpv6.available?`green`:`orange`:`blue`,H=e?e.publicIpv4.available&&e.publicIpv4.ip?e.publicIpv4.ip:`未获取到`:a?`检测中`:`未读取`,U=e?.publicIpv4.detail||`正在采集公网 IPv4 出口。`,W=e?.proxy.enabled?`代理已启用`:e?`直连`:`待检测`,G=e?.proxy.enabled?e.proxy.url||`代理地址未读取`:`检测请求按当前网关配置发起。`,K=e?e.proxy.enabled?`orange`:`green`:`blue`,q=j(e,N),J=N.total>0?Math.round(N.reachable/N.total*100):0,Y=e?`${J}%`:`--`,X=N.total>0?String(N.total):`5`,Z=e?.publicIpv4.countryName?`${e.publicIpv4.countryName}${e.publicIpv4.colo?` · ${e.publicIpv4.colo}`:``}`:e?.publicIpv4.countryCode||`未知出口`,ne=e?.publicIpv4.available?`${e.publicIpv4.source} · ${z(e.publicIpv4.elapsedMs)}`:U,Q=e?.platforms.find(e=>e.tone===`red`)??e?.platforms.find(e=>e.tone===`orange`),re=Q?`${Q.label}: ${Q.detail}`:e?`海外目标应用均有响应。`:`等待海外目标应用响应。`,$=n?.webrtc.tone===`red`?`red`:n?.webrtc.tone===`orange`||S===`orange`?`orange`:S===`slate`||!n?`blue`:`green`;return(0,b.jsxs)(`section`,{className:`network-page`,children:[(0,b.jsxs)(`section`,{className:`network-command-center ${q.tone}`,children:[(0,b.jsxs)(`div`,{className:`network-command-copy`,children:[(0,b.jsxs)(`div`,{className:`network-eyebrow`,children:[(0,b.jsx)(u,{size:14}),(0,b.jsx)(`span`,{children:`海外应用访问诊断`})]}),(0,b.jsx)(`h2`,{children:q.label}),(0,b.jsx)(`p`,{children:q.detail}),(0,b.jsxs)(`div`,{className:`network-command-status`,children:[(0,b.jsx)(M,{tone:x.tone,children:x.label}),(0,b.jsxs)(`span`,{children:[(0,b.jsx)(o,{size:13}),y]}),(0,b.jsx)(`span`,{className:`network-toolbar-status`,children:p})]})]}),(0,b.jsxs)(`div`,{className:`access-score-card`,children:[(0,b.jsx)(`span`,{children:`海外可达率`}),(0,b.jsx)(`strong`,{children:Y}),(0,b.jsx)(`div`,{className:`access-score-bar`,"aria-hidden":`true`,children:(0,b.jsx)(`i`,{style:{width:`${J}%`}})}),(0,b.jsxs)(`p`,{children:[N.reachable,`/`,X,` 个目标应用可达`]}),(0,b.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>v().catch(()=>void 0),disabled:a,children:[(0,b.jsx)(s,{size:16}),a?`检测中`:`重新检测`]})]})]}),g?(0,b.jsxs)(`p`,{className:`network-error`,children:[`检测提示: `,g]}):null,(0,b.jsxs)(`section`,{className:`signal-grid`,children:[(0,b.jsx)(I,{icon:i,label:`海外连通性`,value:`${N.reachable}/${X}`,detail:re,tone:q.tone}),(0,b.jsx)(I,{icon:f,label:`当前出口`,value:e?.publicIpv4.available?Z:H,detail:ne,tone:P}),(0,b.jsx)(I,{icon:c,label:`代理路径`,value:W,detail:G,tone:K}),(0,b.jsx)(I,{icon:l,label:`解析与浏览器`,value:n?`${C} · ${n.webrtc.status}`:`检测中`,detail:n?.webrtc.detail||E,tone:$})]}),(0,b.jsxs)(`section`,{className:`network-workspace`,children:[(0,b.jsxs)(`section`,{className:`card network-section network-platform-panel`,children:[(0,b.jsxs)(`div`,{className:`section-head compact`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h3`,{children:`海外应用矩阵`}),(0,b.jsx)(`p`,{children:`反代链路最常用目标的实时可达性。`})]}),(0,b.jsxs)(`div`,{className:`platform-summary-strip`,children:[(0,b.jsxs)(`div`,{className:`platform-summary-chip green`,children:[(0,b.jsx)(`strong`,{children:N.reachable}),(0,b.jsx)(`span`,{children:`可达`})]}),(0,b.jsxs)(`div`,{className:`platform-summary-chip orange`,children:[(0,b.jsx)(`strong`,{children:N.limited}),(0,b.jsx)(`span`,{children:`受限`})]}),(0,b.jsxs)(`div`,{className:`platform-summary-chip red`,children:[(0,b.jsx)(`strong`,{children:N.unavailable}),(0,b.jsx)(`span`,{children:`阻断`})]})]})]}),e?.platforms.length?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`platform-access-header`,"aria-hidden":`true`,children:[(0,b.jsx)(`span`,{children:`应用`}),(0,b.jsx)(`span`,{children:`状态`}),(0,b.jsx)(`span`,{children:`耗时`}),(0,b.jsx)(`span`,{children:`说明`})]}),(0,b.jsx)(`div`,{className:`platform-access-list`,children:e.platforms.map(e=>(0,b.jsx)(R,{item:e},e.key))})]}):(0,b.jsx)(`div`,{className:`network-empty-state`,children:`平台探测结果还没有返回。`})]}),(0,b.jsxs)(`aside`,{className:`network-side`,children:[(0,b.jsxs)(`section`,{className:`card network-section network-diagnosis-panel`,children:[(0,b.jsx)(`div`,{className:`section-head compact`,children:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h3`,{children:`访问结论`}),(0,b.jsx)(`p`,{children:`用于判断当前环境是否适合海外反向代理。`})]})}),(0,b.jsxs)(`div`,{className:`network-list`,children:[(0,b.jsxs)(`div`,{className:`network-list-item`,children:[(0,b.jsx)(M,{tone:q.tone,children:q.label}),(0,b.jsx)(`p`,{children:q.detail})]}),(0,b.jsxs)(`div`,{className:`network-list-item`,children:[(0,b.jsx)(M,{tone:x.tone,children:x.label}),(0,b.jsx)(`p`,{children:x.detail})]}),(0,b.jsxs)(`div`,{className:`network-list-item`,children:[(0,b.jsx)(M,{tone:n?.webrtc.tone||`blue`,children:n?.webrtc.status||`检测中`}),(0,b.jsx)(`p`,{children:n?.webrtc.detail||`正在采集 WebRTC 候选。`})]})]})]}),(0,b.jsxs)(`section`,{className:`card network-section`,children:[(0,b.jsx)(`div`,{className:`section-head compact`,children:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h3`,{children:`出口与代理`}),(0,b.jsx)(`p`,{children:`反代请求实际经过的公网出口。`})]})}),(0,b.jsxs)(`div`,{className:`network-dual`,children:[(0,b.jsx)(L,{label:`IPv4 出口`,value:H,detail:e?e.publicIpv4.available?`${Z} · ${z(e.publicIpv4.elapsedMs)}`:`${e.publicIpv4.detail} · ${z(e.publicIpv4.elapsedMs)}`:`正在采集公网出口信息。`,tone:P}),(0,b.jsx)(L,{label:`IPv6 出口`,value:e?.publicIpv6.available?e.publicIpv6.ip||`-`:`未检测到`,detail:e?.publicIpv6.detail||`未检测到独立 IPv6 出口。`,tone:V})]}),(0,b.jsx)(`div`,{className:`network-list compact-list`,children:(0,b.jsxs)(`div`,{className:`network-list-item`,children:[(0,b.jsx)(M,{tone:K,children:W}),(0,b.jsx)(`p`,{children:G})]})})]})]})]}),(0,b.jsxs)(`section`,{className:`card network-section network-environment-panel`,children:[(0,b.jsx)(`div`,{className:`section-head compact`,children:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h3`,{children:`解析与本地指纹`}),(0,b.jsx)(`p`,{children:`DNS、WebRTC、时区和语言会影响海外应用的风控判断。`})]})}),(0,b.jsxs)(`div`,{className:`network-three-up`,children:[(0,b.jsx)(F,{label:`DNS`,value:T,detail:`${C} · ${e?.dns.source||`尚未获取`}`,tone:S}),(0,b.jsx)(F,{label:`WebRTC`,value:n?.webrtc.status||(a?`检测中`:`-`),detail:n?.webrtc.detail||`正在采集 WebRTC 候选。`,tone:n?.webrtc.tone||`blue`}),(0,b.jsx)(F,{label:`本地环境`,value:n?.timezone||`-`,detail:`${n?.language||`-`} · ${n?.browser||`-`}`,tone:$})]}),e?.dns.servers.length?(0,b.jsx)(`div`,{className:`dns-chip-row`,children:e.dns.servers.map(e=>(0,b.jsx)(`span`,{className:`dns-chip ${w(e)?`orange`:`green`}`,children:e},e))}):null]})]})}export{V as NetworkDetectPage};
1
+ import{a as e,n as t,r as n,t as r}from"./jsx-runtime-DqpGtLhh.js";import{t as i}from"./activity-D21-Xrc4.js";import{t as a}from"./circle-check-ZYtn9GqY.js";import{t as o}from"./clock-3-BzDANsVk.js";import{t as s}from"./refresh-cw-CAAH2rqe.js";import{t as c}from"./server-BrjJPb9D.js";import{g as l,m as u,p as ee}from"./index-_5Ny0cZf.js";var d=t(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),f=t(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),p=t(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),m=e(n(),1),h=`data:image/svg+xml,%3csvg%20role='img'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eClaude%3c/title%3e%3cpath%20d='m4.7144%2015.9555%204.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608%201.5179.1032%202.2767.1578%201.6514.0972%202.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973%209.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686%201.9064%201.4754%202.4893%201.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335%206.6997%200l.9957.1336.419.3642.6192%201.4147%201.0018%202.2282%201.5543%203.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853%201.8517-.5586%202.9021-.3643%201.9429h.2125l.2429-.2429.9835-1.3053%201.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759%201.1293-.34%201.1657-1.0625%201.3478-.8804%201.1414-1.2628%201.7-.7893%201.36.0729.1093.1882-.0183%202.8535-.607%201.5421-.2794%201.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607%201.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929%201.0686%202.0035%201.8092%202.5075%202.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496%202.3436%203.5214.1214%201.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38%2017.959l-1.1414-1.9428-.1397.079-.674%207.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328%201.9672-2.1796%202.9446-1.7243%201.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889%202.386-3.0357%201.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385%204.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429%201.9064-1.3114Z'/%3e%3c/svg%3e`,g=`data:image/svg+xml,%3csvg%20role='img'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eOpenAI%3c/title%3e%3cpath%20d='M22.2819%209.8211a5.9847%205.9847%200%200%200-.5157-4.9108%206.0462%206.0462%200%200%200-6.5098-2.9A6.0651%206.0651%200%200%200%204.9807%204.1818a5.9847%205.9847%200%200%200-3.9977%202.9%206.0462%206.0462%200%200%200%20.7427%207.0966%205.98%205.98%200%200%200%20.511%204.9107%206.051%206.051%200%200%200%206.5146%202.9001A5.9847%205.9847%200%200%200%2013.2599%2024a6.0557%206.0557%200%200%200%205.7718-4.2058%205.9894%205.9894%200%200%200%203.9977-2.9001%206.0557%206.0557%200%200%200-.7475-7.0729zm-9.022%2012.6081a4.4755%204.4755%200%200%201-2.8764-1.0408l.1419-.0804%204.7783-2.7582a.7948.7948%200%200%200%20.3927-.6813v-6.7369l2.02%201.1686a.071.071%200%200%201%20.038.052v5.5826a4.504%204.504%200%200%201-4.4945%204.4944zm-9.6607-4.1254a4.4708%204.4708%200%200%201-.5346-3.0137l.142.0852%204.783%202.7582a.7712.7712%200%200%200%20.7806%200l5.8428-3.3685v2.3324a.0804.0804%200%200%201-.0332.0615L9.74%2019.9502a4.4992%204.4992%200%200%201-6.1408-1.6464zM2.3408%207.8956a4.485%204.485%200%200%201%202.3655-1.9728V11.6a.7664.7664%200%200%200%20.3879.6765l5.8144%203.3543-2.0201%201.1685a.0757.0757%200%200%201-.071%200l-4.8303-2.7865A4.504%204.504%200%200%201%202.3408%207.872zm16.5963%203.8558L13.1038%208.364%2015.1192%207.2a.0757.0757%200%200%201%20.071%200l4.8303%202.7913a4.4944%204.4944%200%200%201-.6765%208.1042v-5.6772a.79.79%200%200%200-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759%200%200%200-.7854%200L9.409%209.2297V6.8974a.0662.0662%200%200%201%20.0284-.0615l4.8303-2.7866a4.4992%204.4992%200%200%201%206.6802%204.66zM8.3065%2012.863l-2.02-1.1638a.0804.0804%200%200%201-.038-.0567V6.0742a4.4992%204.4992%200%200%201%207.3757-3.4537l-.142.0805L8.704%205.459a.7948.7948%200%200%200-.3927.6813zm1.0976-2.3654l2.602-1.4998%202.6069%201.4998v2.9994l-2.5974%201.4997-2.6067-1.4997Z'/%3e%3c/svg%3e`,_=`data:image/svg+xml,%3csvg%20role='img'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eGoogle%3c/title%3e%3cpath%20d='M12.48%2010.92v3.28h7.84c-.24%201.84-.853%203.187-1.787%204.133-1.147%201.147-2.933%202.4-6.053%202.4-4.827%200-8.6-3.893-8.6-8.72s3.773-8.72%208.6-8.72c2.6%200%204.507%201.027%205.907%202.347l2.307-2.307C18.747%201.44%2016.133%200%2012.48%200%205.867%200%20.307%205.387.307%2012s5.56%2012%2012.173%2012c3.573%200%206.267-1.173%208.373-3.36%202.16-2.16%202.84-5.213%202.84-7.667%200-.76-.053-1.467-.173-2.053H12.48z'/%3e%3c/svg%3e`,v=`data:image/svg+xml,%3csvg%20role='img'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eX%3c/title%3e%3cpath%20d='M14.234%2010.162%2022.977%200h-2.072l-7.591%208.824L7.251%200H.258l9.168%2013.343L.258%2024H2.33l8.016-9.318L16.749%2024h6.993zm-2.837%203.299-.929-1.329L3.076%201.56h3.182l5.965%208.532.929%201.329%207.754%2011.09h-3.182z'/%3e%3c/svg%3e`,y=`data:image/svg+xml,%3csvg%20role='img'%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%3e%3ctitle%3eYouTube%3c/title%3e%3cpath%20d='M23.498%206.186a3.016%203.016%200%200%200-2.122-2.136C19.505%203.545%2012%203.545%2012%203.545s-7.505%200-9.377.505A3.017%203.017%200%200%200%20.502%206.186C0%208.07%200%2012%200%2012s0%203.93.502%205.814a3.016%203.016%200%200%200%202.122%202.136c1.871.505%209.376.505%209.376.505s7.505%200%209.377-.505a3.015%203.015%200%200%200%202.122-2.136C24%2015.93%2024%2012%2024%2012s0-3.93-.502-5.814zM9.545%2015.568V8.432L15.818%2012l-6.273%203.568z'/%3e%3c/svg%3e`,b=r(),x={claude:h,chatgpt:g,google:_,x:v,youtube:y};function S(e){return`tone-${e}`}function C(e){try{return new URL(e).hostname.replace(/^www\./i,``)}catch{return e}}function w(e){return/^(10|127|169\.254|172\.(1[6-9]|2\d|3[0-1])|192\.168)\./.test(e)||/^100\.(6[4-9]|[7-9]\d|1\d\d|2[0-3]\d|24[0-7])\./.test(e)||/^198\.(18|19)\./.test(e)||/^192\.0\.2\./.test(e)||/^198\.51\.100\./.test(e)||/^203\.0\.113\./.test(e)||/^fc00:/i.test(e)||/^fd00:/i.test(e)||/^fe80:/i.test(e)||/^::1$/.test(e)}function T(e){let t=e.match(/Electron\/([\d.]+)/i);if(t)return`Electron ${t[1]}`;let n=e.match(/Chrome\/([\d.]+)/i);if(n&&/Safari\//i.test(e))return`Chrome ${n[1].split(`.`)[0]}`;let r=e.match(/Version\/([\d.]+).*Safari\//i);if(r&&!/Chrome\//i.test(e))return`Safari ${r[1].split(`.`)[0]}`;let i=e.match(/Firefox\/([\d.]+)/i);return i?`Firefox ${i[1].split(`.`)[0]}`:e.slice(0,40)}async function E(){if(typeof RTCPeerConnection>`u`)return{status:`不支持`,detail:`当前环境不支持 WebRTC。`,tone:`orange`,candidates:[]};let e=new Set,t=new RTCPeerConnection({iceServers:[]}),n=!1,r=new Promise(r=>{t.onicecandidate=t=>{t.candidate?.candidate&&e.add(t.candidate.candidate),t.candidate||(n=!0,r())}});try{t.createDataChannel(`probe`);let e=await t.createOffer();await t.setLocalDescription(e),await Promise.race([r,new Promise(e=>window.setTimeout(e,2400))])}catch{}finally{t.close()}let i=[...e],a=i.some(e=>/\btyp srflx\b/.test(e)||/\btyp relay\b/.test(e)),o=i.some(e=>/\btyp host\b/.test(e));return a?{status:`需要留意`,detail:`收集到 ${i.length} 个候选地址,其中包含公网回显特征。`,tone:`red`,candidates:i}:o||n?{status:`本地候选为主`,detail:`收集到 ${i.length} 个候选地址,主要来自本地网段。`,tone:`orange`,candidates:i}:{status:`暂未发现异常`,detail:`未收集到可识别的候选地址。`,tone:`green`,candidates:i}}async function D(){let[e]=await Promise.all([E()]);return{timezone:Intl.DateTimeFormat().resolvedOptions().timeZone||`-`,language:navigator.language||`-`,browser:T(navigator.userAgent||``),webrtc:e}}function O(e){return e.length===0?`slate`:e.some(e=>w(e))?`orange`:`green`}function k(e){return e.length===0?`未读取`:e.some(e=>w(e))?`内网 / 企业 DNS`:`公网 DNS`}function A(e){return{total:e.length,reachable:e.filter(e=>e.status===`可达`).length,limited:e.filter(e=>e.status===`受限`).length,unavailable:e.filter(e=>e.status===`不可用`).length}}function j(e,t){return!e||t.total===0?{label:`正在判断海外访问`,detail:`正在检查 ChatGPT、Claude、Google、YouTube 和 X 的连通性。`,tone:`blue`}:t.unavailable>0?{label:`海外访问受阻`,detail:`${t.unavailable} 个海外应用不可用,优先检查代理出口、DNS 或上游链路。`,tone:`red`}:t.limited>0?{label:`部分应用受限`,detail:`${t.reachable}/${t.total} 个海外应用可达,其余应用返回限制状态。`,tone:`orange`}:{label:`海外应用可访问`,detail:`${t.total} 个目标应用均已连通,当前出口可用于海外反向代理场景。`,tone:`green`}}function te(e,t){if(!e&&!t)return{label:`检测中`,detail:`正在采集公网出口、DNS、WebRTC、代理和平台可达性。`,tone:`blue`};if(!e||!t)return{label:`部分结果`,detail:`已有项目返回,剩余项目会保留失败原因,方便继续排查。`,tone:`orange`};let n=e.publicIpv4.available&&!!e.publicIpv4.ip,r=e.publicIpv6.available&&!!e.publicIpv6.ip,i=[e.platforms.some(e=>e.tone===`red`),t.webrtc.tone===`red`,!n&&!r],a=[e.platforms.some(e=>e.tone===`orange`),t.webrtc.tone===`orange`,O(e.dns.servers)!==`green`,!n,!e.publicIpv6.available];return i.some(Boolean)?{label:`建议先处理`,detail:`有明显阻塞项,先把出口或浏览器回显风险排掉。`,tone:`red`}:a.some(Boolean)?{label:`需要留意`,detail:`结果可用,但有几项信息值得再看一眼。`,tone:`orange`}:{label:`状态正常`,detail:`出口、DNS、WebRTC 和常用平台状态都比较稳定。`,tone:`green`}}function M(e){return(0,b.jsx)(`span`,{className:`network-chip ${e.tone}`,children:e.children})}function N(e){return(0,b.jsxs)(`span`,{className:`access-badge ${e.tone}`,children:[e.tone===`green`?(0,b.jsx)(a,{size:13}):e.tone===`red`?(0,b.jsx)(d,{size:13}):(0,b.jsx)(p,{size:13}),e.children]})}function P(e){let t=e.platformKey.toLowerCase(),n=x[t];return(0,b.jsx)(`span`,{className:`platform-icon ${e.tone} platform-${t}`,children:n?(0,b.jsx)(`img`,{alt:``,src:n}):e.icon})}function F(e){return(0,b.jsxs)(`div`,{className:`network-metric ${S(e.tone)}`,children:[(0,b.jsx)(`span`,{children:e.label}),(0,b.jsx)(`strong`,{children:e.value}),e.detail?(0,b.jsx)(`p`,{children:e.detail}):null]})}function I(e){let t=e.icon;return(0,b.jsxs)(`div`,{className:`signal-card ${S(e.tone)}`,children:[(0,b.jsx)(`div`,{className:`signal-card-icon`,children:(0,b.jsx)(t,{size:17})}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`span`,{children:e.label}),(0,b.jsx)(`strong`,{children:e.value}),(0,b.jsx)(`p`,{children:e.detail})]})]})}function L(e){return(0,b.jsxs)(`div`,{className:`network-block ${S(e.tone)}`,children:[(0,b.jsx)(`span`,{children:e.label}),(0,b.jsx)(`strong`,{children:e.value}),(0,b.jsx)(`p`,{children:e.detail})]})}function R(e){let{item:t}=e;return(0,b.jsxs)(`div`,{className:`platform-access-row ${t.tone}`,children:[(0,b.jsxs)(`div`,{className:`platform-access-main`,children:[(0,b.jsx)(P,{icon:t.label.slice(0,1),tone:t.tone,platformKey:t.key}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`strong`,{children:t.label}),(0,b.jsx)(`span`,{children:C(t.url)})]})]}),(0,b.jsxs)(`div`,{className:`platform-access-result`,children:[(0,b.jsx)(N,{tone:t.tone,children:t.status}),(0,b.jsx)(`span`,{children:t.httpStatus?`HTTP ${t.httpStatus}`:`连接结果`})]}),(0,b.jsxs)(`div`,{className:`platform-access-latency`,children:[(0,b.jsx)(`strong`,{children:z(t.elapsedMs)}),(0,b.jsx)(`span`,{children:t.httpStatus?`${t.httpStatus} 响应`:`等待结果`})]}),(0,b.jsx)(`div`,{className:`platform-access-detail`,children:(0,b.jsx)(`span`,{children:t.detail})})]})}function z(e){return typeof e==`number`?`${e} ms`:`-`}function B(e){return e instanceof DOMException&&e.name===`AbortError`?`网络探测超过 18 秒,已停止等待。`:e instanceof Error?e.message:String(e)}function V(){let[e,t]=(0,m.useState)(null),[n,r]=(0,m.useState)(null),[a,d]=(0,m.useState)(!0),[p,h]=(0,m.useState)(`正在采集真实网络状态...`),[g,_]=(0,m.useState)(null);async function v(){d(!0),_(null),h(`正在采集真实网络状态...`);let e=new AbortController,n=window.setTimeout(()=>e.abort(),18e3);try{let[n,i]=await Promise.allSettled([ee(`/_gateway/admin/network-detect`,{signal:e.signal}),D()]);n.status===`fulfilled`&&t(n.value),i.status===`fulfilled`&&r(i.value);let a=[];n.status===`rejected`&&a.push(`网络探测: ${B(n.reason)}`),i.status===`rejected`&&a.push(`本地环境: ${B(i.reason)}`);let o=n.status===`fulfilled`&&i.status===`fulfilled`?`检测完成。`:n.status===`fulfilled`||i.status===`fulfilled`?`部分结果已更新。`:`检测失败。`;_(a.length>0?a.join(` · `):null),h(o)}catch(e){_(B(e)),h(`检测失败。`)}finally{window.clearTimeout(n),d(!1)}}(0,m.useEffect)(()=>{v().catch(()=>void 0)},[]);let y=(0,m.useMemo)(()=>e?new Intl.DateTimeFormat(`zh-CN`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1}).format(new Date(e.checkedAt)):`--:--:--`,[e]),x=te(e,n),S=O(e?.dns.servers||[]),C=k(e?.dns.servers||[]),T=e?.dns.servers?.length?e.dns.servers.slice(0,2).join(` / `):`-`,E=e?.dns.detail||`尚未检测到系统 DNS。`,N=A(e?.platforms||[]),P=e?e.publicIpv4.available&&e.publicIpv4.ip?`green`:`orange`:`blue`,V=e?e.publicIpv6.available?`green`:`orange`:`blue`,H=e?e.publicIpv4.available&&e.publicIpv4.ip?e.publicIpv4.ip:`未获取到`:a?`检测中`:`未读取`,U=e?.publicIpv4.detail||`正在采集公网 IPv4 出口。`,W=e?.proxy.enabled?`代理已启用`:e?`直连`:`待检测`,G=e?.proxy.enabled?e.proxy.url||`代理地址未读取`:`检测请求按当前网关配置发起。`,K=e?e.proxy.enabled?`orange`:`green`:`blue`,q=j(e,N),J=N.total>0?Math.round(N.reachable/N.total*100):0,Y=e?`${J}%`:`--`,X=N.total>0?String(N.total):`5`,Z=e?.publicIpv4.countryName?`${e.publicIpv4.countryName}${e.publicIpv4.colo?` · ${e.publicIpv4.colo}`:``}`:e?.publicIpv4.countryCode||`未知出口`,ne=e?.publicIpv4.available?`${e.publicIpv4.source} · ${z(e.publicIpv4.elapsedMs)}`:U,Q=e?.platforms.find(e=>e.tone===`red`)??e?.platforms.find(e=>e.tone===`orange`),re=Q?`${Q.label}: ${Q.detail}`:e?`海外目标应用均有响应。`:`等待海外目标应用响应。`,$=n?.webrtc.tone===`red`?`red`:n?.webrtc.tone===`orange`||S===`orange`?`orange`:S===`slate`||!n?`blue`:`green`;return(0,b.jsxs)(`section`,{className:`network-page`,children:[(0,b.jsxs)(`section`,{className:`network-command-center ${q.tone}`,children:[(0,b.jsxs)(`div`,{className:`network-command-copy`,children:[(0,b.jsxs)(`div`,{className:`network-eyebrow`,children:[(0,b.jsx)(u,{size:14}),(0,b.jsx)(`span`,{children:`海外应用访问诊断`})]}),(0,b.jsx)(`h2`,{children:q.label}),(0,b.jsx)(`p`,{children:q.detail}),(0,b.jsxs)(`div`,{className:`network-command-status`,children:[(0,b.jsx)(M,{tone:x.tone,children:x.label}),(0,b.jsxs)(`span`,{children:[(0,b.jsx)(o,{size:13}),y]}),(0,b.jsx)(`span`,{className:`network-toolbar-status`,children:p})]})]}),(0,b.jsxs)(`div`,{className:`access-score-card`,children:[(0,b.jsx)(`span`,{children:`海外可达率`}),(0,b.jsx)(`strong`,{children:Y}),(0,b.jsx)(`div`,{className:`access-score-bar`,"aria-hidden":`true`,children:(0,b.jsx)(`i`,{style:{width:`${J}%`}})}),(0,b.jsxs)(`p`,{children:[N.reachable,`/`,X,` 个目标应用可达`]}),(0,b.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>v().catch(()=>void 0),disabled:a,children:[(0,b.jsx)(s,{size:16}),a?`检测中`:`重新检测`]})]})]}),g?(0,b.jsxs)(`p`,{className:`network-error`,children:[`检测提示: `,g]}):null,(0,b.jsxs)(`section`,{className:`signal-grid`,children:[(0,b.jsx)(I,{icon:i,label:`海外连通性`,value:`${N.reachable}/${X}`,detail:re,tone:q.tone}),(0,b.jsx)(I,{icon:f,label:`当前出口`,value:e?.publicIpv4.available?Z:H,detail:ne,tone:P}),(0,b.jsx)(I,{icon:c,label:`代理路径`,value:W,detail:G,tone:K}),(0,b.jsx)(I,{icon:l,label:`解析与浏览器`,value:n?`${C} · ${n.webrtc.status}`:`检测中`,detail:n?.webrtc.detail||E,tone:$})]}),(0,b.jsxs)(`section`,{className:`network-workspace`,children:[(0,b.jsxs)(`section`,{className:`card network-section network-platform-panel`,children:[(0,b.jsxs)(`div`,{className:`section-head compact`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h3`,{children:`海外应用矩阵`}),(0,b.jsx)(`p`,{children:`反代链路最常用目标的实时可达性。`})]}),(0,b.jsxs)(`div`,{className:`platform-summary-strip`,children:[(0,b.jsxs)(`div`,{className:`platform-summary-chip green`,children:[(0,b.jsx)(`strong`,{children:N.reachable}),(0,b.jsx)(`span`,{children:`可达`})]}),(0,b.jsxs)(`div`,{className:`platform-summary-chip orange`,children:[(0,b.jsx)(`strong`,{children:N.limited}),(0,b.jsx)(`span`,{children:`受限`})]}),(0,b.jsxs)(`div`,{className:`platform-summary-chip red`,children:[(0,b.jsx)(`strong`,{children:N.unavailable}),(0,b.jsx)(`span`,{children:`阻断`})]})]})]}),e?.platforms.length?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`platform-access-header`,"aria-hidden":`true`,children:[(0,b.jsx)(`span`,{children:`应用`}),(0,b.jsx)(`span`,{children:`状态`}),(0,b.jsx)(`span`,{children:`耗时`}),(0,b.jsx)(`span`,{children:`说明`})]}),(0,b.jsx)(`div`,{className:`platform-access-list`,children:e.platforms.map(e=>(0,b.jsx)(R,{item:e},e.key))})]}):(0,b.jsx)(`div`,{className:`network-empty-state`,children:`平台探测结果还没有返回。`})]}),(0,b.jsxs)(`aside`,{className:`network-side`,children:[(0,b.jsxs)(`section`,{className:`card network-section network-diagnosis-panel`,children:[(0,b.jsx)(`div`,{className:`section-head compact`,children:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h3`,{children:`访问结论`}),(0,b.jsx)(`p`,{children:`用于判断当前环境是否适合海外反向代理。`})]})}),(0,b.jsxs)(`div`,{className:`network-list`,children:[(0,b.jsxs)(`div`,{className:`network-list-item`,children:[(0,b.jsx)(M,{tone:q.tone,children:q.label}),(0,b.jsx)(`p`,{children:q.detail})]}),(0,b.jsxs)(`div`,{className:`network-list-item`,children:[(0,b.jsx)(M,{tone:x.tone,children:x.label}),(0,b.jsx)(`p`,{children:x.detail})]}),(0,b.jsxs)(`div`,{className:`network-list-item`,children:[(0,b.jsx)(M,{tone:n?.webrtc.tone||`blue`,children:n?.webrtc.status||`检测中`}),(0,b.jsx)(`p`,{children:n?.webrtc.detail||`正在采集 WebRTC 候选。`})]})]})]}),(0,b.jsxs)(`section`,{className:`card network-section`,children:[(0,b.jsx)(`div`,{className:`section-head compact`,children:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h3`,{children:`出口与代理`}),(0,b.jsx)(`p`,{children:`反代请求实际经过的公网出口。`})]})}),(0,b.jsxs)(`div`,{className:`network-dual`,children:[(0,b.jsx)(L,{label:`IPv4 出口`,value:H,detail:e?e.publicIpv4.available?`${Z} · ${z(e.publicIpv4.elapsedMs)}`:`${e.publicIpv4.detail} · ${z(e.publicIpv4.elapsedMs)}`:`正在采集公网出口信息。`,tone:P}),(0,b.jsx)(L,{label:`IPv6 出口`,value:e?.publicIpv6.available?e.publicIpv6.ip||`-`:`未检测到`,detail:e?.publicIpv6.detail||`未检测到独立 IPv6 出口。`,tone:V})]}),(0,b.jsx)(`div`,{className:`network-list compact-list`,children:(0,b.jsxs)(`div`,{className:`network-list-item`,children:[(0,b.jsx)(M,{tone:K,children:W}),(0,b.jsx)(`p`,{children:G})]})})]})]})]}),(0,b.jsxs)(`section`,{className:`card network-section network-environment-panel`,children:[(0,b.jsx)(`div`,{className:`section-head compact`,children:(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`h3`,{children:`解析与本地指纹`}),(0,b.jsx)(`p`,{children:`DNS、WebRTC、时区和语言会影响海外应用的风控判断。`})]})}),(0,b.jsxs)(`div`,{className:`network-three-up`,children:[(0,b.jsx)(F,{label:`DNS`,value:T,detail:`${C} · ${e?.dns.source||`尚未获取`}`,tone:S}),(0,b.jsx)(F,{label:`WebRTC`,value:n?.webrtc.status||(a?`检测中`:`-`),detail:n?.webrtc.detail||`正在采集 WebRTC 候选。`,tone:n?.webrtc.tone||`blue`}),(0,b.jsx)(F,{label:`本地环境`,value:n?.timezone||`-`,detail:`${n?.language||`-`} · ${n?.browser||`-`}`,tone:$})]}),e?.dns.servers.length?(0,b.jsx)(`div`,{className:`dns-chip-row`,children:e.dns.servers.map(e=>(0,b.jsx)(`span`,{className:`dns-chip ${w(e)?`orange`:`green`}`,children:e},e))}):null]})]})}export{V as NetworkDetectPage};
@@ -1 +1 @@
1
- import{a as e,r as t,t as n}from"./jsx-runtime-DqpGtLhh.js";import{t as r}from"./circle-check-ZYtn9GqY.js";import{t as i}from"./clock-3-BzDANsVk.js";import{t as a}from"./earth-DFdZaQIi.js";import{t as o}from"./zap-B4_oDbCp.js";import{c as s,l as c,m as l,x as u}from"./profiles-C5SmQvju.js";import{g as d,h as f}from"./index-CCiBaGwU.js";import{t as p}from"./InfoRow-0ULI9iI3.js";import{t as m}from"./StatCard-7TEzqn2i.js";var h=e(t(),1),g=n();function _(e){let t=l(e.apiProfile,e.showEmails),n=e.codexProfile?l(e.codexProfile,e.showEmails):e.codexEmail?e.showEmails?e.codexEmail:s(e.codexEmail):e.codexAccountId?e.showEmails?e.codexAccountId:c(e.codexAccountId):`未应用`;return(0,g.jsxs)(`div`,{className:`usage-summary`,children:[(0,g.jsxs)(`div`,{className:`usage-summary-row`,children:[(0,g.jsx)(`span`,{children:`网关:`}),(0,g.jsx)(`strong`,{children:t})]}),(0,g.jsxs)(`div`,{className:`usage-summary-row`,children:[(0,g.jsx)(`span`,{children:`Codex:`}),(0,g.jsx)(`strong`,{children:n})]})]})}function v(e){let t=e?.quota?.primaryUsedPercent;return typeof t!=`number`||!Number.isFinite(t)?0:Math.max(0,Math.min(100,Math.round(t)))}function y(e,t,n,r){let i=Array.isArray(e?.profiles)?e.profiles:[],a=620+(e?.profile?v(e.profile):42)*7+n*90,o=i.reduce((e,t,n)=>e+v(t)*(n+1),0),s=Math.max(1,r/60);return Array.from({length:12},(e,r)=>{let i=Math.sin((r+1+n)*(.65+s*.08))*(120+s*18),c=Math.cos((r+1)*(1.05+s*.06)+n)*(72+s*10),l=t[r]?t[r].durationMs*(n===0?.24:.12):0,u=a+i+c+l+o%280;return Math.max(220,Math.min(2200,Math.round(u)))})}function b(e,t,n,r){return e.map((i,a)=>{let o=t/(e.length-1)*a,s=n-i/r*(n-16)-8;return`${a===0?`M`:`L`}${o.toFixed(2)} ${s.toFixed(2)}`}).join(` `)}function x(e){let t=y(e.config,e.requestLogs,0,e.windowMinutes),n=y(e.config,e.requestLogs,1,e.windowMinutes).map(e=>Math.max(180,e-260)),r=Math.max(...t,...n,2e3),i=b(t,720,210,r),a=b(n,720,210,r),o=Date.now(),s=Math.max(10,Math.round(e.windowMinutes/6)),c=Array.from({length:6},(e,t)=>new Date(o-(5-t)*s*60*1e3).toLocaleTimeString(`zh-CN`,{hour12:!1,hour:`2-digit`,minute:`2-digit`}));return(0,g.jsxs)(`section`,{className:`trend-card`,"aria-label":`请求耗时趋势`,children:[(0,g.jsxs)(`div`,{className:`section-head compact`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`h3`,{children:`请求耗时趋势`}),(0,g.jsx)(`p`,{children:`基于最近调试请求和账号额度状态生成的本地趋势视图。`})]}),(0,g.jsxs)(`select`,{className:`control`,value:e.windowMinutes,onChange:t=>e.onWindow(Number(t.target.value)),children:[(0,g.jsx)(`option`,{value:60,children:`近 1 小时`}),(0,g.jsx)(`option`,{value:180,children:`近 3 小时`}),(0,g.jsx)(`option`,{value:720,children:`近 12 小时`})]})]}),(0,g.jsxs)(`div`,{className:`chart-wrap`,children:[(0,g.jsxs)(`div`,{className:`chart-legend`,children:[(0,g.jsxs)(`span`,{className:`legend-item`,children:[(0,g.jsx)(`span`,{className:`legend-swatch purple`}),`网关响应`]}),(0,g.jsxs)(`span`,{className:`legend-item`,children:[(0,g.jsx)(`span`,{className:`legend-swatch blue`}),`上游响应`]})]}),(0,g.jsxs)(`svg`,{className:`trend-svg`,viewBox:`0 0 720 210`,role:`img`,"aria-label":`请求耗时趋势折线图`,children:[(0,g.jsxs)(`defs`,{children:[(0,g.jsxs)(`linearGradient`,{id:`areaA`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,g.jsx)(`stop`,{offset:`0%`,stopColor:`rgba(99,91,255,0.18)`}),(0,g.jsx)(`stop`,{offset:`100%`,stopColor:`rgba(99,91,255,0.02)`})]}),(0,g.jsxs)(`linearGradient`,{id:`areaB`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,g.jsx)(`stop`,{offset:`0%`,stopColor:`rgba(59,130,246,0.16)`}),(0,g.jsx)(`stop`,{offset:`100%`,stopColor:`rgba(59,130,246,0.02)`})]})]}),[1,2,3,4].map(e=>(0,g.jsx)(`line`,{x1:`0`,y1:e*42,x2:720,y2:e*42,stroke:`#e2e8f0`,strokeWidth:`1`},e)),(0,g.jsx)(`path`,{d:`${i} L 720 210 L 0 210 Z`,fill:`url(#areaA)`,stroke:`none`}),(0,g.jsx)(`path`,{d:`${a} L 720 210 L 0 210 Z`,fill:`url(#areaB)`,stroke:`none`}),(0,g.jsx)(`path`,{d:i,fill:`none`,stroke:`#635bff`,strokeWidth:`2.4`,strokeLinecap:`round`}),(0,g.jsx)(`path`,{d:a,fill:`none`,stroke:`#3b82f6`,strokeWidth:`2.4`,strokeLinecap:`round`})]}),(0,g.jsx)(`div`,{className:`trend-labels`,children:c.map((e,t)=>(0,g.jsx)(`span`,{children:e},`${e}-${t}`))})]})]})}function S(e){return(0,g.jsxs)(`section`,{className:`card service-card endpoint-card`,children:[(0,g.jsx)(`div`,{className:`section-head compact`,children:(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`h3`,{children:`网关信息`}),(0,g.jsx)(`p`,{children:`桌面端与 CLI 共享同一套本地服务。`})]})}),(0,g.jsxs)(`div`,{className:`service-list compact-grid`,children:[(0,g.jsx)(p,{label:`管理页`,value:e.config?.adminUrl||`-`,code:!0}),(0,g.jsx)(p,{label:`Base URL`,value:e.config?.baseUrl||`-`,code:!0}),(0,g.jsx)(p,{label:`默认模型`,value:e.config?.settings.defaultModel||`-`}),(0,g.jsx)(p,{label:`生图模型`,value:`gpt-image-2`}),(0,g.jsx)(p,{label:`兼容接口`,value:e.config?.supportedEndpoints.map(e=>e.path).join(`,`)||`-`}),(0,g.jsx)(p,{label:`令牌预览`,value:e.config?.profile?.accessTokenPreview||`未登录`,code:!0}),(0,g.jsx)(p,{label:`模型来源`,value:e.config?.modelCatalog.source||`-`})]})]})}function C(e){return new Intl.NumberFormat(`zh-CN`).format(Math.round(e||0))}function w(e){let[t,n]=(0,h.useState)(60),s=e.requestLogs.length?e.requestLogs.reduce((e,t)=>e+t.durationMs,0)/e.requestLogs.length:0,c=e.config?.usage?.today,l=c?.failureCount??0;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`section`,{className:`summary-grid desktop-summary-grid overview-summary-grid`,children:[(0,g.jsx)(m,{icon:f,label:`账号总数`,value:String(e.config?.status.profileCount||0),detail:`已保存到本地账号池`,tone:`blue`}),(0,g.jsx)(m,{icon:a,label:`当前账号状态`,value:(0,g.jsx)(_,{apiProfile:e.activeProfile,codexProfile:e.codexProfile,codexEmail:e.codexEmail,codexAccountId:e.codexAccountId,showEmails:e.showEmails}),detail:e.config?.status.loggedIn||e.codexProfile?``:`需要先登录或导入账号`,tone:e.config?.status.loggedIn||e.codexProfile?`green`:`orange`,compact:!0}),(0,g.jsx)(m,{icon:o,label:`今日请求数`,value:C(c?.requestCount??e.requestLogs.length),detail:c?`${C(c.successCount)} 成功 / ${C(c.failureCount)} 失败`:`基于本页最近测试记录`,tone:`blue`}),(0,g.jsx)(m,{icon:i,label:`今日 token`,value:C(c?.totalTokens??0),detail:c?`未返回 token ${C(c.unknownTokenCount)} 次`:`统计最近 ${e.requestLogs.length} 次`,tone:`orange`}),(0,g.jsx)(m,{icon:d,label:`服务状态`,value:e.config?.status.loggedIn?`运行中`:`等待登录`,detail:`网关可转发请求`,tone:e.config?.status.loggedIn?`green`:`orange`}),(0,g.jsx)(m,{icon:r,label:`今日异常`,value:C(l),detail:`平均耗时 ${u(c?c.averageDurationMs:s)}`,tone:l>0?`orange`:`green`})]}),(0,g.jsxs)(`section`,{className:`overview-grid`,children:[(0,g.jsx)(x,{config:e.config,requestLogs:e.requestLogs,windowMinutes:t,onWindow:n}),(0,g.jsx)(S,{config:e.config})]})]})}export{w as OverviewPage};
1
+ import{a as e,r as t,t as n}from"./jsx-runtime-DqpGtLhh.js";import{t as r}from"./circle-check-ZYtn9GqY.js";import{t as i}from"./clock-3-BzDANsVk.js";import{t as a}from"./earth-DFdZaQIi.js";import{t as o}from"./zap-B4_oDbCp.js";import{c as s,l as c,m as l,x as u}from"./profiles-C5SmQvju.js";import{g as d,h as f}from"./index-_5Ny0cZf.js";import{t as p}from"./InfoRow-0ULI9iI3.js";import{t as m}from"./StatCard-7TEzqn2i.js";var h=e(t(),1),g=n();function _(e){let t=l(e.apiProfile,e.showEmails),n=e.codexProfile?l(e.codexProfile,e.showEmails):e.codexEmail?e.showEmails?e.codexEmail:s(e.codexEmail):e.codexAccountId?e.showEmails?e.codexAccountId:c(e.codexAccountId):`未应用`;return(0,g.jsxs)(`div`,{className:`usage-summary`,children:[(0,g.jsxs)(`div`,{className:`usage-summary-row`,children:[(0,g.jsx)(`span`,{children:`网关:`}),(0,g.jsx)(`strong`,{children:t})]}),(0,g.jsxs)(`div`,{className:`usage-summary-row`,children:[(0,g.jsx)(`span`,{children:`Codex:`}),(0,g.jsx)(`strong`,{children:n})]})]})}function v(e){let t=e?.quota?.primaryUsedPercent;return typeof t!=`number`||!Number.isFinite(t)?0:Math.max(0,Math.min(100,Math.round(t)))}function y(e,t,n,r){let i=Array.isArray(e?.profiles)?e.profiles:[],a=620+(e?.profile?v(e.profile):42)*7+n*90,o=i.reduce((e,t,n)=>e+v(t)*(n+1),0),s=Math.max(1,r/60);return Array.from({length:12},(e,r)=>{let i=Math.sin((r+1+n)*(.65+s*.08))*(120+s*18),c=Math.cos((r+1)*(1.05+s*.06)+n)*(72+s*10),l=t[r]?t[r].durationMs*(n===0?.24:.12):0,u=a+i+c+l+o%280;return Math.max(220,Math.min(2200,Math.round(u)))})}function b(e,t,n,r){return e.map((i,a)=>{let o=t/(e.length-1)*a,s=n-i/r*(n-16)-8;return`${a===0?`M`:`L`}${o.toFixed(2)} ${s.toFixed(2)}`}).join(` `)}function x(e){let t=y(e.config,e.requestLogs,0,e.windowMinutes),n=y(e.config,e.requestLogs,1,e.windowMinutes).map(e=>Math.max(180,e-260)),r=Math.max(...t,...n,2e3),i=b(t,720,210,r),a=b(n,720,210,r),o=Date.now(),s=Math.max(10,Math.round(e.windowMinutes/6)),c=Array.from({length:6},(e,t)=>new Date(o-(5-t)*s*60*1e3).toLocaleTimeString(`zh-CN`,{hour12:!1,hour:`2-digit`,minute:`2-digit`}));return(0,g.jsxs)(`section`,{className:`trend-card`,"aria-label":`请求耗时趋势`,children:[(0,g.jsxs)(`div`,{className:`section-head compact`,children:[(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`h3`,{children:`请求耗时趋势`}),(0,g.jsx)(`p`,{children:`基于最近调试请求和账号额度状态生成的本地趋势视图。`})]}),(0,g.jsxs)(`select`,{className:`control`,value:e.windowMinutes,onChange:t=>e.onWindow(Number(t.target.value)),children:[(0,g.jsx)(`option`,{value:60,children:`近 1 小时`}),(0,g.jsx)(`option`,{value:180,children:`近 3 小时`}),(0,g.jsx)(`option`,{value:720,children:`近 12 小时`})]})]}),(0,g.jsxs)(`div`,{className:`chart-wrap`,children:[(0,g.jsxs)(`div`,{className:`chart-legend`,children:[(0,g.jsxs)(`span`,{className:`legend-item`,children:[(0,g.jsx)(`span`,{className:`legend-swatch purple`}),`网关响应`]}),(0,g.jsxs)(`span`,{className:`legend-item`,children:[(0,g.jsx)(`span`,{className:`legend-swatch blue`}),`上游响应`]})]}),(0,g.jsxs)(`svg`,{className:`trend-svg`,viewBox:`0 0 720 210`,role:`img`,"aria-label":`请求耗时趋势折线图`,children:[(0,g.jsxs)(`defs`,{children:[(0,g.jsxs)(`linearGradient`,{id:`areaA`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,g.jsx)(`stop`,{offset:`0%`,stopColor:`rgba(99,91,255,0.18)`}),(0,g.jsx)(`stop`,{offset:`100%`,stopColor:`rgba(99,91,255,0.02)`})]}),(0,g.jsxs)(`linearGradient`,{id:`areaB`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,g.jsx)(`stop`,{offset:`0%`,stopColor:`rgba(59,130,246,0.16)`}),(0,g.jsx)(`stop`,{offset:`100%`,stopColor:`rgba(59,130,246,0.02)`})]})]}),[1,2,3,4].map(e=>(0,g.jsx)(`line`,{x1:`0`,y1:e*42,x2:720,y2:e*42,stroke:`#e2e8f0`,strokeWidth:`1`},e)),(0,g.jsx)(`path`,{d:`${i} L 720 210 L 0 210 Z`,fill:`url(#areaA)`,stroke:`none`}),(0,g.jsx)(`path`,{d:`${a} L 720 210 L 0 210 Z`,fill:`url(#areaB)`,stroke:`none`}),(0,g.jsx)(`path`,{d:i,fill:`none`,stroke:`#635bff`,strokeWidth:`2.4`,strokeLinecap:`round`}),(0,g.jsx)(`path`,{d:a,fill:`none`,stroke:`#3b82f6`,strokeWidth:`2.4`,strokeLinecap:`round`})]}),(0,g.jsx)(`div`,{className:`trend-labels`,children:c.map((e,t)=>(0,g.jsx)(`span`,{children:e},`${e}-${t}`))})]})]})}function S(e){return(0,g.jsxs)(`section`,{className:`card service-card endpoint-card`,children:[(0,g.jsx)(`div`,{className:`section-head compact`,children:(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`h3`,{children:`网关信息`}),(0,g.jsx)(`p`,{children:`桌面端与 CLI 共享同一套本地服务。`})]})}),(0,g.jsxs)(`div`,{className:`service-list compact-grid`,children:[(0,g.jsx)(p,{label:`管理页`,value:e.config?.adminUrl||`-`,code:!0}),(0,g.jsx)(p,{label:`Base URL`,value:e.config?.baseUrl||`-`,code:!0}),(0,g.jsx)(p,{label:`默认模型`,value:e.config?.settings.defaultModel||`-`}),(0,g.jsx)(p,{label:`生图模型`,value:`gpt-image-2`}),(0,g.jsx)(p,{label:`兼容接口`,value:e.config?.supportedEndpoints.map(e=>e.path).join(`,`)||`-`}),(0,g.jsx)(p,{label:`令牌预览`,value:e.config?.profile?.accessTokenPreview||`未登录`,code:!0}),(0,g.jsx)(p,{label:`模型来源`,value:e.config?.modelCatalog.source||`-`})]})]})}function C(e){return new Intl.NumberFormat(`zh-CN`).format(Math.round(e||0))}function w(e){let[t,n]=(0,h.useState)(60),s=e.requestLogs.length?e.requestLogs.reduce((e,t)=>e+t.durationMs,0)/e.requestLogs.length:0,c=e.config?.usage?.today,l=c?.failureCount??0;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`section`,{className:`summary-grid desktop-summary-grid overview-summary-grid`,children:[(0,g.jsx)(m,{icon:f,label:`账号总数`,value:String(e.config?.status.profileCount||0),detail:`已保存到本地账号池`,tone:`blue`}),(0,g.jsx)(m,{icon:a,label:`当前账号状态`,value:(0,g.jsx)(_,{apiProfile:e.activeProfile,codexProfile:e.codexProfile,codexEmail:e.codexEmail,codexAccountId:e.codexAccountId,showEmails:e.showEmails}),detail:e.config?.status.loggedIn||e.codexProfile?``:`需要先登录或导入账号`,tone:e.config?.status.loggedIn||e.codexProfile?`green`:`orange`,compact:!0}),(0,g.jsx)(m,{icon:o,label:`今日请求数`,value:C(c?.requestCount??e.requestLogs.length),detail:c?`${C(c.successCount)} 成功 / ${C(c.failureCount)} 失败`:`基于本页最近测试记录`,tone:`blue`}),(0,g.jsx)(m,{icon:i,label:`今日 token`,value:C(c?.totalTokens??0),detail:c?`未返回 token ${C(c.unknownTokenCount)} 次`:`统计最近 ${e.requestLogs.length} 次`,tone:`orange`}),(0,g.jsx)(m,{icon:d,label:`服务状态`,value:e.config?.status.loggedIn?`运行中`:`等待登录`,detail:`网关可转发请求`,tone:e.config?.status.loggedIn?`green`:`orange`}),(0,g.jsx)(m,{icon:r,label:`今日异常`,value:C(l),detail:`平均耗时 ${u(c?c.averageDurationMs:s)}`,tone:l>0?`orange`:`green`})]}),(0,g.jsxs)(`section`,{className:`overview-grid`,children:[(0,g.jsx)(x,{config:e.config,requestLogs:e.requestLogs,windowMinutes:t,onWindow:n}),(0,g.jsx)(S,{config:e.config})]})]})}export{w as OverviewPage};
@@ -0,0 +1,8 @@
1
+ import{a as e,n as t,r as n,t as r}from"./jsx-runtime-DqpGtLhh.js";import{t as i}from"./earth-DFdZaQIi.js";import{t as a}from"./refresh-cw-CAAH2rqe.js";import{t as o}from"./search-B2hz41D3.js";import{f as s,i as c,m as l,o as u,s as d,w as f}from"./profiles-C5SmQvju.js";import{_ as p,n as ee,p as m,r as h}from"./index-_5Ny0cZf.js";var g=t(`monitor-cog`,[[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`m14.305 7.53.923-.382`,key:`1mlnsw`}],[`path`,{d:`m15.228 4.852-.923-.383`,key:`82mpwg`}],[`path`,{d:`m16.852 3.228-.383-.924`,key:`ln4sir`}],[`path`,{d:`m16.852 8.772-.383.923`,key:`1dejw0`}],[`path`,{d:`m19.148 3.228.383-.924`,key:`192kgf`}],[`path`,{d:`m19.53 9.696-.382-.924`,key:`fiavlr`}],[`path`,{d:`m20.772 4.852.924-.383`,key:`1j8mgp`}],[`path`,{d:`m20.772 7.148.924.383`,key:`zix9be`}],[`path`,{d:`M22 13v2a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7`,key:`1tnzv8`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}]]),te=t(`plug-zap`,[[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m18 3-4 4h6l-4 4`,key:`16psg9`}]]),ne=t(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),re=t(`unplug`,[[`path`,{d:`m19 5 3-3`,key:`yk6iyv`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z`,key:`1snsnr`}]]),_=e(n(),1),v=r();function y(e){return e===`ai-zero-token`?`ai-zero-token`:`openai`}function b(e){return e===`openai`?`openai`:`AI Zero Token`}function ie(e){return e===`openai`?`保留 Codex 原生历史`:`新的 provider 历史`}function ae(e){return e===`openai`?`openai_base_url`:`[model_providers.ai-zero-token]`}function x(e){let t=e.trim();if(!t)throw Error(`请填写 Codex 网关 URL。`);/^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(t)||(t=`http://${t}`);let n;try{n=new URL(t)}catch{throw Error(`Codex 网关 URL 格式错误,请填写 http(s) 地址或 IP:端口。`)}if(n.protocol!==`http:`&&n.protocol!==`https:`)throw Error(`Codex 网关 URL 只支持 http 或 https。`);n.hash=``,n.search=``;let r=n.pathname.replace(/\/+$/g,``);return!r||r===`/`||r===`/v1`?n.pathname=`/codex/v1`:r.endsWith(`/codex`)?n.pathname=`${r}/v1`:n.pathname=r,n.toString().replace(/\/+$/g,``)}function S(e){try{return x(e)}catch{return e.trim().replace(/\/+$/g,``)}}function C(e){return e?.codexBaseUrl||`http://127.0.0.1:8787/codex/v1`}function oe(e){return{defaultModel:e.settings.defaultModel,proxyEnabled:e.settings.networkProxy.enabled,proxyUrl:e.settings.networkProxy.url,proxyNoProxy:e.settings.networkProxy.noProxy||`localhost,127.0.0.1,::1`,autoSwitchEnabled:e.settings.autoSwitch.enabled,autoSwitchExcludedProfileIds:e.settings.autoSwitch.excludedProfileIds||[],quotaSyncConcurrency:String(e.settings.runtime?.quotaSyncConcurrency||3),freeAccountWebGenerationEnabled:!!e.settings.image?.freeAccountWebGenerationEnabled,serverPort:String(e.settings.server.port||8787)}}function se(e){return[l(e,!0),e.email||``,e.accountId,e.profileId,c(e)].join(` `).toLowerCase()}function w(e){let[t,n]=(0,_.useState)({defaultModel:``,proxyEnabled:!1,proxyUrl:``,proxyNoProxy:`localhost,127.0.0.1,::1`,autoSwitchEnabled:!1,autoSwitchExcludedProfileIds:[],quotaSyncConcurrency:`3`,freeAccountWebGenerationEnabled:!1,serverPort:`8787`}),[r,w]=(0,_.useState)(`local`),[T,E]=(0,_.useState)(`http://127.0.0.1:8787/codex/v1`),[D,O]=(0,_.useState)(!1),[ce,le]=(0,_.useState)(()=>new Set),[k,ue]=(0,_.useState)(``),[A,j]=(0,_.useState)(`openai`),[M,de]=(0,_.useState)(!1),[N,P]=(0,_.useState)(null),[fe,F]=(0,_.useState)(!1),I=(0,_.useRef)(null),L=ce.size>0;(0,_.useEffect)(()=>()=>{I.current&&window.clearTimeout(I.current)},[]),(0,_.useEffect)(()=>{!e.config||L||n(oe(e.config))},[e.config,L]),(0,_.useEffect)(()=>{if(!e.config||D)return;let t=C(e.config),n=e.config.codex.gatewayProvider?.baseUrl;E(n||t),w(n&&S(n)!==S(t)?`remote`:`local`)},[e.config,D]),(0,_.useEffect)(()=>{!e.config||M||j(y(e.config.codex.gatewayProvider?.providerId))},[e.config,M]);function R(e){n(t=>({...t,...e})),le(t=>{let n=new Set(t);for(let t of Object.keys(e))n.add(t);return n})}function pe(e,n){let r=new Set(t.autoSwitchExcludedProfileIds);n?r.add(e):r.delete(e),R({autoSwitchExcludedProfileIds:Array.from(r)})}function z(t){let n=C(e.config);O(!0),w(t),t===`local`?E(n):T.trim()||E(n)}function me(){return r===`local`?C(e.config):T}function B(e){de(!0),j(e)}let V=(0,_.useMemo)(()=>new Set(t.autoSwitchExcludedProfileIds),[t.autoSwitchExcludedProfileIds]),H=(0,_.useMemo)(()=>{let t=k.trim().toLowerCase();return(e.config?.profiles||[]).filter(e=>!t||se(e).includes(t))},[k,e.config?.profiles]),he=e.config?.profiles.length||0,U=(e.config?.profiles||[]).filter(e=>V.has(e.profileId)).length,ge=Math.max(0,he-U);async function _e(n){let r=(...e)=>e.some(e=>ce.has(e)),i=Number.parseInt(t.serverPort,10);if(r(`serverPort`)&&(!Number.isInteger(i)||i<1||i>65535)){e.setStatus(`端口必须是 1 到 65535 之间的整数。`);return}let a=Number.parseInt(t.quotaSyncConcurrency,10);if(r(`quotaSyncConcurrency`)&&(!Number.isInteger(a)||a<1||a>32)){e.setStatus(`全局额度刷新并发数必须是 1 到 32 之间的整数。`);return}let o={};r(`defaultModel`)&&(o.defaultModel=t.defaultModel),r(`proxyEnabled`,`proxyUrl`,`proxyNoProxy`)&&(o.networkProxy={enabled:t.proxyEnabled,url:t.proxyUrl,noProxy:t.proxyNoProxy}),r(`autoSwitchEnabled`,`autoSwitchExcludedProfileIds`)&&(o.autoSwitch={},r(`autoSwitchEnabled`)&&(o.autoSwitch.enabled=t.autoSwitchEnabled),r(`autoSwitchExcludedProfileIds`)&&(o.autoSwitch.excludedProfileIds=t.autoSwitchExcludedProfileIds)),r(`quotaSyncConcurrency`)&&(o.runtime={quotaSyncConcurrency:a}),r(`freeAccountWebGenerationEnabled`)&&(o.image={freeAccountWebGenerationEnabled:t.freeAccountWebGenerationEnabled}),r(`serverPort`)&&(o.server={port:i});let s=n?.restart?`restart`:`settings`;e.setBusy(s);try{let t=await m(`/_gateway/admin/settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:f(o)});e.setConfig(t),le(new Set),n?.restart?(e.setStatus(`设置已保存,正在重启本地网关...`),await m(`/_gateway/admin/restart`,{method:`POST`}),e.setStatus(`本地网关正在重启,页面会自动恢复。`)):e.setStatus(`设置已保存。`)}catch(t){e.setStatus(h(t))}finally{e.setBusy(null)}}async function ve(){e.setBusy(`proxy`);try{let n=await m(`/_gateway/admin/settings/proxy-test`,{method:`POST`,headers:{"Content-Type":`application/json`},body:f({networkProxy:{enabled:t.proxyEnabled,url:t.proxyUrl,noProxy:t.proxyNoProxy}})});e.setStatus(`代理测试通过: HTTP ${n.status},耗时 ${n.elapsedMs} ms。`)}catch(t){e.setStatus(`代理测试失败: ${h(t)}`)}finally{e.setBusy(null)}}async function ye(){e.setBusy(`models`);try{let t=await m(`/_gateway/models/refresh`,{method:`POST`});await e.refreshConfig({silent:!0});let n=t.catalog?.modelCount??0;e.setStatus(n>0?`Codex 模型列表已从网络同步,共 ${n} 个。`:`Codex 模型列表已从网络同步。`)}catch(t){e.setStatus(h(t))}finally{e.setBusy(null)}}async function be(){e.setBusy(`codex-share`),F(!1),P(null),I.current&&=(window.clearTimeout(I.current),null);try{let t=await m(`/_gateway/admin/share`);if(!t.primary){let n=t.lanReachable?`没有检测到可分享的局域网地址。请确认设备已连接 Wi-Fi 或局域网。`:`当前网关只允许本机访问,不能分享给局域网设备。请把网关监听地址从 ${t.serverHost} 改为 0.0.0.0 后重启。`;P({tone:`warning`,title:`不能分享代理配置`,detail:n}),e.setStatus(n);return}let n=t.addresses.slice(1).map(e=>`备用 Codex 远程网关 URL:\n${e.codexBaseUrl}`).join(`
2
+
3
+ `),r=[`AI Zero Token 代理配置`,``,`Codex 远程网关 URL:`,t.primary.codexBaseUrl,``,`OpenAI 兼容 Base URL:`,t.primary.baseUrl,``,`API Key:`,`任意值,例如 local`,``,`说明:`,`远程请求会消耗这台网关机器上保存的账号额度。`,`请确认两台设备在同一局域网,且防火墙允许访问该端口。`,...n?[``,n]:[]].join(`
4
+ `),i=await ee(r);i&&(F(!0),I.current=window.setTimeout(()=>{F(!1),I.current=null},2e3)),P({tone:i?`success`:`warning`,title:i?`代理配置已复制`:`复制失败,请手动复制`,detail:i?`把这段配置发给对方。对方在 AI Zero Token 的「远程网关」里填 Codex 地址,OpenAI 兼容客户端填 Base URL。`:`浏览器未允许写入剪贴板,请手动复制下面的代理配置。`,codexUrl:t.primary.codexBaseUrl,baseUrl:t.primary.baseUrl,apiKey:`任意值,例如 local`}),e.setStatus(i?`代理配置已复制:${t.primary.codexBaseUrl}`:r)}catch(t){let n=h(t);P({tone:`warning`,title:`代理配置生成失败`,detail:n}),e.setStatus(n)}finally{e.setBusy(null)}}async function W(t){if(t.config?.codexRestartSupported&&window.confirm(t.confirmMessage)){e.setStatus(t.restartingStatus);try{await m(`/_gateway/admin/desktop/restart-codex`,{method:`POST`}),e.setStatus(t.restartedStatus)}catch(n){e.setStatus(`${t.failedStatusPrefix}: ${h(n)}`)}return}e.setStatus(t.deferStatus)}async function xe(){e.setBusy(`codex-provider`);try{let t=A,n=b(t),r=x(me()),i=e.config?.codex.gatewayProvider?.baseUrl,a=y(e.config?.codex.gatewayProvider?.providerId),o=!!(e.config?.codex.gatewayProvider?.active&&a!==t),s=!!(e.config?.codex.gatewayProvider?.active&&i&&S(i)!==r);if(e.config?.codex.gatewayProvider?.active&&!s&&!o){let r=await m(`/_gateway/admin/codex/remove-provider`,{method:`POST`,headers:{"Content-Type":`application/json`},body:f({providerId:t})});r.config&&e.setConfig(r.config),r.codexProvider.removed?await W({config:r.config??e.config,confirmMessage:`Codex ${n} 接管已解除,是否现在重启 Codex 客户端?\n\nCodex 通常在启动时读取本机 config.toml,重启后会回到原本的 Codex 配置。`,deferStatus:`已解除 ${n} 接管。重启 Codex 后会回到原本的 Codex 配置。`,restartingStatus:`正在重启 Codex 客户端...`,restartedStatus:`已解除 ${n} 接管,并已重启 Codex 客户端。`,failedStatusPrefix:`已解除 ${n} 接管,但重启 Codex 失败`}):e.setStatus(`未发现当前受管的 Codex provider 配置。`);return}let c=!!e.config?.codex.gatewayProvider?.active,l=await m(`/_gateway/admin/codex/configure-provider`,{method:`POST`,headers:{"Content-Type":`application/json`},body:f({baseUrl:r,providerId:t})});l.config&&e.setConfig(l.config);let u=l.codexProvider.historyMigration?.migratedCount||0,d=l.codexProvider.historyMigration?.rolloutPatchedCount||0,p=u>0?`,已迁移 ${u} 条历史记录${d>0?`,已修复 ${d} 个会话索引`:``}`:``;await W({config:l.config??e.config,confirmMessage:t===`openai`?`Codex 接管将使用 openai 历史记录模式,是否现在重启 Codex 客户端?
5
+
6
+ 重启后请求仍会走 AI Zero Token 网关,历史记录会继续归在 Codex 原生 openai provider 下。`:`Codex 接管将切换到 AI Zero Token 新 provider,是否现在重启 Codex 客户端?
7
+
8
+ 重启后请求仍会走 AI Zero Token 网关,历史记录会归在新的 AI Zero Token provider 下。`,deferStatus:`${c?`已更新`:`已写入`} ${n} 接管配置:${l.codexProvider.baseUrl}${p}。重启 Codex 后生效。`,restartingStatus:`正在重启 Codex 客户端...`,restartedStatus:`${c?`已更新`:`已接管`} ${n} 请求,并已重启 Codex 客户端。`,failedStatusPrefix:`${c?`已更新`:`已接管`} ${n} 请求,但重启 Codex 失败`})}catch(t){e.setStatus(h(t))}finally{e.setBusy(null)}}let G=y(e.config?.codex.gatewayProvider?.providerId),K=b(G),q=ae(A),J=!!e.config?.codex.gatewayProvider?.active,Y=e.busy===`codex-provider`,X=e.busy===`codex-share`,Se=C(e.config),Ce=S(r===`local`?Se:T),Z=e.config?.codex.gatewayProvider?.baseUrl||``,Q=!!(J&&Z&&S(Z)!==Ce),$=!!(J&&G!==A),we=[`btn-secondary`,`codex-provider-button`,Y?`is-busy`:J&&!Q&&!$?`is-active`:`is-inactive`].join(` `),Te=Y?`处理中`:J&&!Q&&!$?`解除 Codex 接管`:J?`更新接管配置`:`写入并接管`,Ee=J?K:`未接管`,De=J?`is-included`:`is-excluded`;return(0,v.jsxs)(`section`,{className:`settings-page`,children:[(0,v.jsx)(`div`,{className:`settings-page-head settings-page-head-actions-only`,children:(0,v.jsx)(`div`,{className:`settings-page-actions`,children:(0,v.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:ye,disabled:e.busy===`models`,children:[e.busy===`models`?(0,v.jsx)(p,{className:`spin`,size:16}):(0,v.jsx)(a,{size:16}),`同步 Codex 模型`]})})}),(0,v.jsxs)(`div`,{className:`settings-grid`,children:[(0,v.jsxs)(`section`,{className:`settings-section codex-provider-section`,children:[(0,v.jsxs)(`div`,{className:`codex-provider-head`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{children:`Codex 请求接管`}),(0,v.jsx)(`p`,{className:`hint`,children:`默认使用 openai 保留 Codex 原生历史;也可以切到 AI Zero Token,写入新的 provider 历史分组。接管地址既可以是本机网关,也可以是远程网关 URL。`})]}),(0,v.jsx)(`span`,{className:`count-pill ${De}`,children:Ee})]}),(0,v.jsxs)(`div`,{className:`codex-provider-mode-row`,children:[(0,v.jsxs)(`div`,{className:`codex-provider-mode-copy`,children:[(0,v.jsx)(`div`,{className:`codex-provider-mode-title`,children:`历史记录模式`}),(0,v.jsxs)(`p`,{className:`hint`,children:[b(A),` · `,ie(A)]})]}),(0,v.jsxs)(`div`,{className:`codex-provider-mode-toggle`,role:`group`,"aria-label":`历史记录模式`,children:[(0,v.jsx)(`button`,{className:`codex-provider-mode-option ${A===`openai`?`is-active`:``}`,type:`button`,onClick:()=>B(`openai`),children:`openai`}),(0,v.jsx)(`button`,{className:`codex-provider-mode-option ${A===`ai-zero-token`?`is-active`:``}`,type:`button`,onClick:()=>B(`ai-zero-token`),children:`AI Zero Token`})]})]}),(0,v.jsxs)(`div`,{className:`codex-provider-controls`,children:[(0,v.jsxs)(`div`,{className:`codex-mode-toggle`,role:`group`,"aria-label":`Codex 网关模式`,children:[(0,v.jsxs)(`button`,{className:`codex-mode-option ${r===`local`?`is-active`:``}`,type:`button`,onClick:()=>z(`local`),children:[(0,v.jsx)(g,{size:16}),`本机网关`]}),(0,v.jsxs)(`button`,{className:`codex-mode-option ${r===`remote`?`is-active`:``}`,type:`button`,onClick:()=>z(`remote`),children:[(0,v.jsx)(i,{size:16}),`远程网关`]})]}),(0,v.jsxs)(`label`,{className:`field codex-url-field`,children:[(0,v.jsx)(`span`,{children:`Codex 网关 URL`}),(0,v.jsx)(`input`,{className:`input codex-url-input`,value:r===`local`?Se:T,onChange:e=>{O(!0),w(`remote`),E(e.target.value)},placeholder:`http://192.168.1.10:8787/codex/v1`,readOnly:r===`local`})]}),(0,v.jsxs)(`div`,{className:`codex-provider-actions`,children:[(0,v.jsxs)(`button`,{className:`btn-secondary share-gateway-button`,type:`button`,onClick:be,disabled:X,children:[X?(0,v.jsx)(p,{className:`spin`,size:16}):(0,v.jsx)(ne,{size:16}),X?`生成中`:fe?`已复制`:`复制代理配置`]}),(0,v.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>z(`local`),children:[(0,v.jsx)(g,{size:16}),`使用本机地址`]}),(0,v.jsxs)(`button`,{className:we,type:`button`,onClick:xe,disabled:Y,children:[Y?(0,v.jsx)(p,{className:`spin`,size:16}):J&&!Q?(0,v.jsx)(re,{size:16}):(0,v.jsx)(te,{size:16}),Te]})]})]}),N?(0,v.jsxs)(`div`,{className:`share-gateway-feedback ${N.tone===`success`?`is-success`:`is-warning`}`,role:`status`,"aria-live":`polite`,children:[(0,v.jsx)(`strong`,{children:N.title}),(0,v.jsx)(`span`,{children:N.detail}),(0,v.jsxs)(`div`,{className:`share-gateway-config-list`,children:[N.codexUrl?(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{children:`Codex 远程网关 URL`}),(0,v.jsx)(`code`,{children:N.codexUrl})]}):null,N.baseUrl?(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{children:`OpenAI 兼容 Base URL`}),(0,v.jsx)(`code`,{children:N.baseUrl})]}):null,N.apiKey?(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{children:`API Key`}),(0,v.jsx)(`code`,{children:N.apiKey})]}):null]})]}):null,(0,v.jsxs)(`p`,{className:`hint`,children:[`可直接输入 IP:端口,系统会自动补全为 http://IP:端口/codex/v1。当前将写入 `,(0,v.jsx)(`code`,{children:q}),`:`,(0,v.jsx)(`code`,{children:Ce||`-`})]}),(0,v.jsxs)(`div`,{className:`codex-provider-meta-strip`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{children:`配置文件`}),(0,v.jsx)(`code`,{children:e.config?.codex.gatewayProvider.path||`~/.codex/config.toml`})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{children:`当前状态`}),(0,v.jsx)(`code`,{children:J?`${K} · ${ie(G)}`:`未接管`})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{children:`写入目标`}),(0,v.jsx)(`code`,{children:q})]}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{children:`接管地址`}),(0,v.jsx)(`code`,{children:Z||`未写入受管配置`})]}),(0,v.jsxs)(`div`,{className:`is-warning`,children:[(0,v.jsx)(`span`,{children:`远程网关提示`}),(0,v.jsx)(`strong`,{children:`远程请求会消耗对方网关机器上保存的账号额度。`})]})]})]}),(0,v.jsxs)(`section`,{className:`settings-section`,children:[(0,v.jsx)(`h4`,{children:`模型`}),(0,v.jsxs)(`label`,{className:`field`,children:[(0,v.jsx)(`span`,{children:`默认文本模型`}),(0,v.jsx)(`select`,{className:`control`,value:t.defaultModel,onChange:e=>R({defaultModel:e.target.value}),children:(e.config?.models||[]).map(e=>(0,v.jsx)(`option`,{value:e.id,children:e.id},e.id))})]}),(0,v.jsxs)(`p`,{className:`hint`,children:[`模型列表来源:`,e.config?.modelCatalog.source||`-`,`,共 `,e.config?.modelCatalog.modelCount||0,` 个。`]})]}),(0,v.jsxs)(`section`,{className:`settings-section free-image-section`,children:[(0,v.jsx)(`h4`,{children:`Free 账号生图`}),(0,v.jsxs)(`label`,{className:`switch-line`,children:[(0,v.jsx)(`input`,{type:`checkbox`,checked:t.freeAccountWebGenerationEnabled,onChange:e=>R({freeAccountWebGenerationEnabled:e.target.checked})}),(0,v.jsx)(`span`,{children:`允许 Free 账号使用 ChatGPT 网页链路生图`})]}),(0,v.jsx)(`p`,{className:`hint`,children:`关闭时,Free 账号生图会继续走原先 Codex Responses 图片工具链路,由上游决定是否可用。`}),(0,v.jsxs)(`p`,{className:`free-image-warning`,children:[(0,v.jsx)(`strong`,{children:`封号风险:`}),`该能力不是官方 API 标准流程,使用 Free 账号生图存在账号风控或封号风险。`,(0,v.jsx)(`strong`,{children:`额度较少:`}),`Free 额度通常较少,当前经验值大约 8 张,实际以上游账号为准。`]})]}),(0,v.jsxs)(`section`,{className:`settings-section`,children:[(0,v.jsx)(`h4`,{children:`上游代理`}),(0,v.jsxs)(`label`,{className:`switch-line`,children:[(0,v.jsx)(`input`,{type:`checkbox`,checked:t.proxyEnabled,onChange:e=>R({proxyEnabled:e.target.checked})}),(0,v.jsx)(`span`,{children:`启用 OAuth、模型刷新和接口转发代理`})]}),(0,v.jsxs)(`label`,{className:`field`,children:[(0,v.jsx)(`span`,{children:`代理地址`}),(0,v.jsx)(`input`,{className:`input`,value:t.proxyUrl,onChange:e=>R({proxyUrl:e.target.value}),placeholder:`http://127.0.0.1:7890`})]}),(0,v.jsxs)(`label`,{className:`field`,children:[(0,v.jsx)(`span`,{children:`No Proxy`}),(0,v.jsx)(`input`,{className:`input`,value:t.proxyNoProxy,onChange:e=>R({proxyNoProxy:e.target.value})})]}),(0,v.jsx)(`button`,{className:`btn-secondary`,type:`button`,onClick:ve,disabled:e.busy===`proxy`,children:`测试代理`})]}),(0,v.jsxs)(`section`,{className:`settings-section`,children:[(0,v.jsx)(`h4`,{children:`端口`}),(0,v.jsxs)(`label`,{className:`field`,children:[(0,v.jsx)(`span`,{children:`网关端口`}),(0,v.jsx)(`input`,{className:`input`,inputMode:`numeric`,type:`number`,min:1,max:65535,value:t.serverPort,onChange:e=>R({serverPort:e.target.value})})]}),(0,v.jsx)(`p`,{className:`hint`,children:`修改后重启本地网关生效,桌面窗口不会退出。若端口被占用,启动时会自动顺延到下一个可用端口。`})]}),(0,v.jsxs)(`section`,{className:`settings-section`,children:[(0,v.jsx)(`h4`,{children:`账号运行策略`}),(0,v.jsxs)(`label`,{className:`switch-line`,children:[(0,v.jsx)(`input`,{type:`checkbox`,checked:t.autoSwitchEnabled,onChange:e=>R({autoSwitchEnabled:e.target.checked})}),(0,v.jsx)(`span`,{children:`当前 API 账号额度耗尽后自动切换到下一个仍有额度的账号`})]}),(0,v.jsxs)(`label`,{className:`field`,children:[(0,v.jsx)(`span`,{children:`全局额度刷新并发数`}),(0,v.jsx)(`input`,{className:`input`,inputMode:`numeric`,max:32,min:1,type:`number`,value:t.quotaSyncConcurrency,onChange:e=>R({quotaSyncConcurrency:e.target.value})})]}),(0,v.jsx)(`p`,{className:`hint`,children:`手动刷新全部账号额度时使用,默认 3。账号很多可以调高,遇到限流或失败增多时调低。`}),(0,v.jsx)(`p`,{className:`hint`,children:e.status})]}),(0,v.jsxs)(`section`,{className:`settings-section auto-switch-exclusion-section`,children:[(0,v.jsxs)(`div`,{className:`auto-switch-exclusion-head`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h4`,{children:`不参与自动轮换名单`}),(0,v.jsx)(`p`,{className:`hint`,children:`这些账号不会被自动切换选中,也不会在自己额度耗尽时触发自动切走;仍可在账号页手动应用到网关或 Codex。`})]}),(0,v.jsxs)(`div`,{className:`auto-switch-counts`,"aria-label":`自动轮换账号统计`,children:[(0,v.jsxs)(`span`,{className:`count-pill is-included`,children:[`参与 `,ge,` 个`]}),(0,v.jsxs)(`span`,{className:`count-pill is-excluded`,children:[`不参与 `,U,` 个`]})]})]}),(0,v.jsxs)(`label`,{className:`auto-switch-search`,children:[(0,v.jsx)(o,{size:16}),(0,v.jsx)(`input`,{value:k,onChange:e=>ue(e.target.value),placeholder:`搜索邮箱、账号 ID 或 Profile ID`})]}),(0,v.jsx)(`div`,{className:`auto-switch-profile-list`,children:H.length===0?(0,v.jsx)(`div`,{className:`auto-switch-empty`,children:`还没有匹配的账号。`}):H.map(t=>{let n=V.has(t.profileId),r=s(t),i=!!(e.config?.codex.accountId&&e.config.codex.accountId===t.accountId),a=u(t)?`登录不可用`:d(t)?`额度耗尽`:``;return(0,v.jsxs)(`label`,{className:`auto-switch-profile-row ${n?`is-excluded`:``}`,children:[(0,v.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>pe(t.profileId,e.target.checked)}),(0,v.jsxs)(`span`,{className:`auto-switch-profile-main`,children:[(0,v.jsx)(`strong`,{children:l(t,e.showEmails)}),(0,v.jsxs)(`span`,{children:[c(t),` · `,r.label,t.isActive?` · 当前 API 使用中`:``,i?` · Codex 使用中`:``,a?` · ${a}`:``]})]}),(0,v.jsx)(`span`,{className:`auto-switch-state-pill ${n?`is-excluded`:`is-included`}`,children:n?`不参与轮换`:`参与轮换`})]},t.profileId)})})]}),(0,v.jsxs)(`section`,{className:`settings-section`,children:[(0,v.jsx)(`h4`,{children:`显示`}),(0,v.jsxs)(`label`,{className:`switch-line`,children:[(0,v.jsx)(`input`,{type:`checkbox`,checked:e.showEmails,onChange:t=>e.setShowEmails(t.target.checked)}),(0,v.jsx)(`span`,{children:`脱敏模式`})]}),(0,v.jsx)(`p`,{className:`hint`,children:`开启后账号邮箱将以脱敏形式展示。`})]})]}),(0,v.jsxs)(`div`,{className:`settings-page-actions settings-page-footer-actions`,children:[(0,v.jsx)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>void _e(),disabled:e.busy===`settings`||e.busy===`restart`||!L,children:`保存设置`}),(0,v.jsx)(`button`,{className:`btn-primary`,type:`button`,onClick:()=>void _e({restart:!0}),disabled:e.busy===`settings`||e.busy===`restart`||!L||!e.config?.restartSupported,children:`保存并重启网关`})]})]})}export{w as SettingsPage};
@@ -1,3 +1,3 @@
1
- import{a as e,n as t,r as n,t as r}from"./jsx-runtime-DqpGtLhh.js";import{t as i}from"./upload-CwXb7Q1b.js";import{t as a}from"./zap-B4_oDbCp.js";import{S as o,m as s,w as c,x as l}from"./profiles-C5SmQvju.js";import{_ as u,a as d,b as f,c as p,i as m,l as h,n as g,o as _,p as v,r as y,s as b,t as x,u as S}from"./index-CCiBaGwU.js";var C=t(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),w=e(n(),1),T=r();function E(e){let t=e.endpoint.startsWith(`/v1/images/`);function n(t){let n=t.currentTarget.files?.[0];t.currentTarget.value=``,n&&e.onImageUpload(n,e.imageUploadMode).catch(()=>void 0)}return(0,T.jsxs)(`section`,{className:`card tester-card`,id:`tester`,children:[(0,T.jsxs)(`div`,{className:`section-head compact`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h2`,{children:`快速测试`}),(0,T.jsx)(`p`,{children:`页面直接调用当前网关暴露的 OpenAI 风格接口。`})]}),(0,T.jsx)(`span`,{className:`badge brand`,children:e.busy===`test`?`请求中`:`准备就绪`})]}),(0,T.jsx)(`div`,{className:`tester-tabs`,children:e.endpoints.map(t=>(0,T.jsx)(`button`,{className:`tab-btn ${e.endpoint===t.path?`is-active`:``}`,type:`button`,onClick:()=>e.onEndpoint(t.path),children:S[t.path]||t.path},t.path))}),(0,T.jsxs)(`div`,{className:`tester-workbench`,children:[(0,T.jsxs)(`div`,{className:`tester-pane tester-request-pane`,children:[(0,T.jsxs)(`label`,{className:`field`,children:[(0,T.jsx)(`span`,{children:`接口`}),(0,T.jsx)(`select`,{className:`control`,value:e.endpoint,onChange:t=>e.onEndpoint(t.target.value),children:e.endpoints.map(e=>(0,T.jsxs)(`option`,{value:e.path,children:[e.method,` `,e.path]},e.path))})]}),(0,T.jsxs)(`div`,{className:`tester-copy-row tester-copy-row-top`,children:[(0,T.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:e.onCopyRequest,children:[(0,T.jsx)(f,{size:16}),`复制请求`]}),(0,T.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:e.onCopyResponse,children:[(0,T.jsx)(f,{size:16}),`复制响应`]}),(0,T.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:e.onCopyTiming,children:[(0,T.jsx)(f,{size:16}),`复制日志`]}),(0,T.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:e.onResetExample,children:[(0,T.jsx)(C,{size:16}),`重置示例`]})]}),(0,T.jsxs)(`label`,{className:`field tester-body-field`,children:[(0,T.jsx)(`span`,{children:`请求体 JSON`}),(0,T.jsx)(`textarea`,{className:`textarea tester-textarea`,value:e.requestBody,onChange:t=>e.onRequestBody(t.target.value),disabled:e.activeEndpoint.method===`GET`,spellCheck:!1})]}),e.endpoint===`/v1/images/edits`&&(0,T.jsxs)(`div`,{className:`edit-upload-row`,children:[(0,T.jsxs)(`div`,{className:`edit-upload-mode`,role:`group`,"aria-label":`图片写入方式`,children:[(0,T.jsx)(`span`,{children:`写入方式`}),(0,T.jsxs)(`div`,{className:`edit-upload-toggle`,children:[(0,T.jsx)(`button`,{className:`tab-btn ${e.imageUploadMode===`base64`?`is-active`:``}`,type:`button`,onClick:()=>e.onImageUploadMode(`base64`),children:`Base64`}),(0,T.jsx)(`button`,{className:`tab-btn ${e.imageUploadMode===`image-bed`?`is-active`:``}`,type:`button`,onClick:()=>e.onImageUploadMode(`image-bed`),children:`图床`})]})]}),(0,T.jsxs)(`label`,{className:`btn-secondary upload-btn`,title:e.imageUploadMode===`base64`?`上传图片并写入 base64 data URL`:`上传图片到图床并写入公网链接`,children:[e.imageUploadMode===`image-bed`&&e.busy===`image-bed-upload`?(0,T.jsx)(u,{className:`spin`,size:16}):(0,T.jsx)(i,{size:16}),e.imageUploadMode===`base64`?`上传并写入 Base64`:`上传并写入图床链接`,(0,T.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:n})]}),(0,T.jsxs)(`span`,{children:[`目标字段:images[0].image_url · `,e.imageUploadMode===`base64`?`直接写入 data URL`:`先上传图床再写入公网链接`]})]}),(0,T.jsx)(`p`,{className:`hint`,children:t?e.capability.detail:e.activeEndpoint.description||`GET /v1/models 无需请求体。`}),(0,T.jsxs)(`div`,{className:`tester-actions-bar`,children:[(0,T.jsx)(`div`,{className:`tester-actions-group`,children:(0,T.jsx)(`div`,{className:`example-row`,children:p.map(t=>(0,T.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>e.onEndpoint(t),disabled:!e.endpoints.some(e=>e.path===t),children:[`示例 `,S[t]||t]},t))})}),(0,T.jsxs)(`button`,{className:`btn-primary`,type:`button`,onClick:e.onRun,disabled:e.busy===`test`||t&&!e.config?.profile,children:[e.busy===`test`?(0,T.jsx)(u,{className:`spin`,size:16}):(0,T.jsx)(a,{size:16}),`发送请求`]})]})]}),(0,T.jsxs)(`div`,{className:`tester-pane tester-response-pane`,children:[(0,T.jsxs)(`div`,{className:`tester-result-head`,children:[(0,T.jsxs)(`div`,{className:`tester-result-tabs`,children:[(0,T.jsx)(`button`,{className:`tab-btn ${e.resultTab===`response`?`is-active`:``}`,type:`button`,onClick:()=>e.onResultTab(`response`),children:`响应 JSON`}),(0,T.jsx)(`button`,{className:`tab-btn ${e.resultTab===`timing`?`is-active`:``}`,type:`button`,onClick:()=>e.onResultTab(`timing`),children:`耗时日志`}),(0,T.jsx)(`button`,{className:`tab-btn ${e.resultTab===`preview`?`is-active`:``}`,type:`button`,onClick:()=>e.onResultTab(`preview`),children:`图片预览`})]}),(0,T.jsx)(`p`,{className:`status-inline`,children:e.status})]}),e.resultTab===`response`&&(0,T.jsx)(`pre`,{className:`pre`,children:e.responseBody}),e.resultTab===`timing`&&(0,T.jsx)(`pre`,{className:`pre`,children:e.timingBody}),e.resultTab===`preview`&&(0,T.jsx)(`div`,{className:`preview-panel`,children:e.previewImages.length===0?(0,T.jsx)(`div`,{className:`preview-empty`,children:`图片结果会显示在这里。点击缩略图可查看大图。`}):(0,T.jsx)(`div`,{className:`preview-grid`,children:e.previewImages.map(t=>(0,T.jsxs)(`figure`,{className:`preview-card`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:()=>e.onPreview({src:t.src,meta:t.meta,filename:t.filename}),children:(0,T.jsx)(`img`,{src:t.src,alt:t.meta})}),(0,T.jsx)(`figcaption`,{children:t.meta}),(0,T.jsx)(`div`,{className:`preview-actions`,children:(0,T.jsx)(`a`,{href:t.src,download:t.filename,children:`下载`})})]},t.filename))})})]})]})]})}function D(e){let[t,n]=(0,w.useState)(`/v1/models`),[r,i]=(0,w.useState)(``),[a,u]=(0,w.useState)(`等待请求...`),[f,S]=(0,w.useState)(`等待请求...`),[C,D]=(0,w.useState)(`response`),[O,k]=(0,w.useState)([]),[A,j]=(0,w.useState)(`base64`),M=(0,w.useMemo)(()=>[...e.config?.supportedEndpoints||[]].filter(e=>p.includes(e.path)).sort(h),[e.config?.supportedEndpoints]),N=(0,w.useMemo)(()=>M.find(e=>e.path===t)||M[0]||{method:`GET`,path:`/v1/models`,description:``},[t,M]);(0,w.useEffect)(()=>{if(!e.config)return;let r=p.find(t=>e.config?.supportedEndpoints.some(e=>e.path===t)),a=e.config.supportedEndpoints.some(e=>e.path===t)?t:r||`/v1/models`;n(a),i(x(a,e.config.settings.defaultModel))},[e.config]);function P(t){n(t),i(x(t,e.config?.settings.defaultModel||`gpt-5.4`)),k([])}function F(){P(t)}function I(){g(r||x(t,e.config?.settings.defaultModel||`gpt-5.4`)).then(t=>e.setStatus(t?`请求体已复制。`:`请求体复制失败。`)).catch(()=>e.setStatus(`请求体复制失败。`))}function L(){g(a).then(t=>e.setStatus(t?`响应内容已复制。`:`响应内容复制失败。`)).catch(()=>e.setStatus(`响应内容复制失败。`))}function R(){g(f).then(t=>e.setStatus(t?`耗时日志已复制。`:`耗时日志复制失败。`)).catch(()=>e.setStatus(`耗时日志复制失败。`))}async function z(){let t=N,n=performance.now(),i=[];e.setBusy(`test`),D(`response`),u(`请求发送中...`),S(`请求发送中...`),k([]);try{let a=null,o={method:t.method,headers:{}};if(t.method!==`GET`){let e=performance.now();a=r.trim()?JSON.parse(r):{},i.push(`解析请求体: ${l(performance.now()-e)}`),o.headers[`Content-Type`]=`application/json`,o.body=c(a)}let d=performance.now(),f=await fetch(t.path,o);i.push(`等待响应头: ${l(performance.now()-d)}`);let p=performance.now(),h=await f.text();i.push(`读取响应体: ${l(performance.now()-p)}`);let g=performance.now(),_=h;try{_=h?JSON.parse(h):null}catch{_=h}i.push(`解析响应体: ${l(performance.now()-g)}`);let v=m(_);k(v),v.length>0&&D(`preview`),u(typeof _==`string`?_:c(b(_))),S([`${t.method} ${t.path}`,`HTTP 状态: ${f.status} ${f.statusText}`,...i].join(`
1
+ import{a as e,n as t,r as n,t as r}from"./jsx-runtime-DqpGtLhh.js";import{t as i}from"./upload-CwXb7Q1b.js";import{t as a}from"./zap-B4_oDbCp.js";import{S as o,m as s,w as c,x as l}from"./profiles-C5SmQvju.js";import{_ as u,a as d,b as f,c as p,i as m,l as h,n as g,o as _,p as v,r as y,s as b,t as x,u as S}from"./index-_5Ny0cZf.js";var C=t(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),w=e(n(),1),T=r();function E(e){let t=e.endpoint.startsWith(`/v1/images/`);function n(t){let n=t.currentTarget.files?.[0];t.currentTarget.value=``,n&&e.onImageUpload(n,e.imageUploadMode).catch(()=>void 0)}return(0,T.jsxs)(`section`,{className:`card tester-card`,id:`tester`,children:[(0,T.jsxs)(`div`,{className:`section-head compact`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h2`,{children:`快速测试`}),(0,T.jsx)(`p`,{children:`页面直接调用当前网关暴露的 OpenAI 风格接口。`})]}),(0,T.jsx)(`span`,{className:`badge brand`,children:e.busy===`test`?`请求中`:`准备就绪`})]}),(0,T.jsx)(`div`,{className:`tester-tabs`,children:e.endpoints.map(t=>(0,T.jsx)(`button`,{className:`tab-btn ${e.endpoint===t.path?`is-active`:``}`,type:`button`,onClick:()=>e.onEndpoint(t.path),children:S[t.path]||t.path},t.path))}),(0,T.jsxs)(`div`,{className:`tester-workbench`,children:[(0,T.jsxs)(`div`,{className:`tester-pane tester-request-pane`,children:[(0,T.jsxs)(`label`,{className:`field`,children:[(0,T.jsx)(`span`,{children:`接口`}),(0,T.jsx)(`select`,{className:`control`,value:e.endpoint,onChange:t=>e.onEndpoint(t.target.value),children:e.endpoints.map(e=>(0,T.jsxs)(`option`,{value:e.path,children:[e.method,` `,e.path]},e.path))})]}),(0,T.jsxs)(`div`,{className:`tester-copy-row tester-copy-row-top`,children:[(0,T.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:e.onCopyRequest,children:[(0,T.jsx)(f,{size:16}),`复制请求`]}),(0,T.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:e.onCopyResponse,children:[(0,T.jsx)(f,{size:16}),`复制响应`]}),(0,T.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:e.onCopyTiming,children:[(0,T.jsx)(f,{size:16}),`复制日志`]}),(0,T.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:e.onResetExample,children:[(0,T.jsx)(C,{size:16}),`重置示例`]})]}),(0,T.jsxs)(`label`,{className:`field tester-body-field`,children:[(0,T.jsx)(`span`,{children:`请求体 JSON`}),(0,T.jsx)(`textarea`,{className:`textarea tester-textarea`,value:e.requestBody,onChange:t=>e.onRequestBody(t.target.value),disabled:e.activeEndpoint.method===`GET`,spellCheck:!1})]}),e.endpoint===`/v1/images/edits`&&(0,T.jsxs)(`div`,{className:`edit-upload-row`,children:[(0,T.jsxs)(`div`,{className:`edit-upload-mode`,role:`group`,"aria-label":`图片写入方式`,children:[(0,T.jsx)(`span`,{children:`写入方式`}),(0,T.jsxs)(`div`,{className:`edit-upload-toggle`,children:[(0,T.jsx)(`button`,{className:`tab-btn ${e.imageUploadMode===`base64`?`is-active`:``}`,type:`button`,onClick:()=>e.onImageUploadMode(`base64`),children:`Base64`}),(0,T.jsx)(`button`,{className:`tab-btn ${e.imageUploadMode===`image-bed`?`is-active`:``}`,type:`button`,onClick:()=>e.onImageUploadMode(`image-bed`),children:`图床`})]})]}),(0,T.jsxs)(`label`,{className:`btn-secondary upload-btn`,title:e.imageUploadMode===`base64`?`上传图片并写入 base64 data URL`:`上传图片到图床并写入公网链接`,children:[e.imageUploadMode===`image-bed`&&e.busy===`image-bed-upload`?(0,T.jsx)(u,{className:`spin`,size:16}):(0,T.jsx)(i,{size:16}),e.imageUploadMode===`base64`?`上传并写入 Base64`:`上传并写入图床链接`,(0,T.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:n})]}),(0,T.jsxs)(`span`,{children:[`目标字段:images[0].image_url · `,e.imageUploadMode===`base64`?`直接写入 data URL`:`先上传图床再写入公网链接`]})]}),(0,T.jsx)(`p`,{className:`hint`,children:t?e.capability.detail:e.activeEndpoint.description||`GET /v1/models 无需请求体。`}),(0,T.jsxs)(`div`,{className:`tester-actions-bar`,children:[(0,T.jsx)(`div`,{className:`tester-actions-group`,children:(0,T.jsx)(`div`,{className:`example-row`,children:p.map(t=>(0,T.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>e.onEndpoint(t),disabled:!e.endpoints.some(e=>e.path===t),children:[`示例 `,S[t]||t]},t))})}),(0,T.jsxs)(`button`,{className:`btn-primary`,type:`button`,onClick:e.onRun,disabled:e.busy===`test`||t&&!e.config?.profile,children:[e.busy===`test`?(0,T.jsx)(u,{className:`spin`,size:16}):(0,T.jsx)(a,{size:16}),`发送请求`]})]})]}),(0,T.jsxs)(`div`,{className:`tester-pane tester-response-pane`,children:[(0,T.jsxs)(`div`,{className:`tester-result-head`,children:[(0,T.jsxs)(`div`,{className:`tester-result-tabs`,children:[(0,T.jsx)(`button`,{className:`tab-btn ${e.resultTab===`response`?`is-active`:``}`,type:`button`,onClick:()=>e.onResultTab(`response`),children:`响应 JSON`}),(0,T.jsx)(`button`,{className:`tab-btn ${e.resultTab===`timing`?`is-active`:``}`,type:`button`,onClick:()=>e.onResultTab(`timing`),children:`耗时日志`}),(0,T.jsx)(`button`,{className:`tab-btn ${e.resultTab===`preview`?`is-active`:``}`,type:`button`,onClick:()=>e.onResultTab(`preview`),children:`图片预览`})]}),(0,T.jsx)(`p`,{className:`status-inline`,children:e.status})]}),e.resultTab===`response`&&(0,T.jsx)(`pre`,{className:`pre`,children:e.responseBody}),e.resultTab===`timing`&&(0,T.jsx)(`pre`,{className:`pre`,children:e.timingBody}),e.resultTab===`preview`&&(0,T.jsx)(`div`,{className:`preview-panel`,children:e.previewImages.length===0?(0,T.jsx)(`div`,{className:`preview-empty`,children:`图片结果会显示在这里。点击缩略图可查看大图。`}):(0,T.jsx)(`div`,{className:`preview-grid`,children:e.previewImages.map(t=>(0,T.jsxs)(`figure`,{className:`preview-card`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:()=>e.onPreview({src:t.src,meta:t.meta,filename:t.filename}),children:(0,T.jsx)(`img`,{src:t.src,alt:t.meta})}),(0,T.jsx)(`figcaption`,{children:t.meta}),(0,T.jsx)(`div`,{className:`preview-actions`,children:(0,T.jsx)(`a`,{href:t.src,download:t.filename,children:`下载`})})]},t.filename))})})]})]})]})}function D(e){let[t,n]=(0,w.useState)(`/v1/models`),[r,i]=(0,w.useState)(``),[a,u]=(0,w.useState)(`等待请求...`),[f,S]=(0,w.useState)(`等待请求...`),[C,D]=(0,w.useState)(`response`),[O,k]=(0,w.useState)([]),[A,j]=(0,w.useState)(`base64`),M=(0,w.useMemo)(()=>[...e.config?.supportedEndpoints||[]].filter(e=>p.includes(e.path)).sort(h),[e.config?.supportedEndpoints]),N=(0,w.useMemo)(()=>M.find(e=>e.path===t)||M[0]||{method:`GET`,path:`/v1/models`,description:``},[t,M]);(0,w.useEffect)(()=>{if(!e.config)return;let r=p.find(t=>e.config?.supportedEndpoints.some(e=>e.path===t)),a=e.config.supportedEndpoints.some(e=>e.path===t)?t:r||`/v1/models`;n(a),i(x(a,e.config.settings.defaultModel))},[e.config]);function P(t){n(t),i(x(t,e.config?.settings.defaultModel||`gpt-5.4`)),k([])}function F(){P(t)}function I(){g(r||x(t,e.config?.settings.defaultModel||`gpt-5.4`)).then(t=>e.setStatus(t?`请求体已复制。`:`请求体复制失败。`)).catch(()=>e.setStatus(`请求体复制失败。`))}function L(){g(a).then(t=>e.setStatus(t?`响应内容已复制。`:`响应内容复制失败。`)).catch(()=>e.setStatus(`响应内容复制失败。`))}function R(){g(f).then(t=>e.setStatus(t?`耗时日志已复制。`:`耗时日志复制失败。`)).catch(()=>e.setStatus(`耗时日志复制失败。`))}async function z(){let t=N,n=performance.now(),i=[];e.setBusy(`test`),D(`response`),u(`请求发送中...`),S(`请求发送中...`),k([]);try{let a=null,o={method:t.method,headers:{}};if(t.method!==`GET`){let e=performance.now();a=r.trim()?JSON.parse(r):{},i.push(`解析请求体: ${l(performance.now()-e)}`),o.headers[`Content-Type`]=`application/json`,o.body=c(a)}let d=performance.now(),f=await fetch(t.path,o);i.push(`等待响应头: ${l(performance.now()-d)}`);let p=performance.now(),h=await f.text();i.push(`读取响应体: ${l(performance.now()-p)}`);let g=performance.now(),_=h;try{_=h?JSON.parse(h):null}catch{_=h}i.push(`解析响应体: ${l(performance.now()-g)}`);let v=m(_);k(v),v.length>0&&D(`preview`),u(typeof _==`string`?_:c(b(_))),S([`${t.method} ${t.path}`,`HTTP 状态: ${f.status} ${f.statusText}`,...i].join(`
2
2
  `)),e.setStatus(`${f.ok?`成功`:`失败`}: HTTP ${f.status} ${t.method} ${t.path}`),e.setRequestLogs(r=>[{id:crypto.randomUUID(),time:Date.now(),method:t.method,endpoint:t.path,account:s(e.config?.profile,e.showEmails),model:typeof a==`object`&&a&&`model`in a?String(a.model||e.config?.settings.defaultModel||`-`):e.config?.settings.defaultModel||`-`,statusCode:f.status,durationMs:performance.now()-n,source:`管理台`},...r].slice(0,20)),e.config?.profile&&e.refreshConfig({silent:!0}).catch(()=>void 0)}catch(n){let r=y(n);u(r),S([`${t.method} ${t.path}(失败)`,...i,`错误: ${r}`].join(`
3
3
  `)),e.setStatus(`请求失败。`)}finally{e.setBusy(null)}}async function B(t,n){if(!t.type.startsWith(`image/`)){e.setStatus(`请选择图片文件。`);return}try{if(n===`image-bed`){e.setBusy(`image-bed-upload`);let n=await _(t);i(d(r,(await v(`/_gateway/image-bed/upload`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({filename:t.name,dataUrl:n})})).url,e.config?.settings.defaultModel||`gpt-image-2`)),e.setStatus(`已上传到图床并写入公网链接(${t.name},${o(t.size)})。`);return}i(d(r,await _(t),e.config?.settings.defaultModel||`gpt-image-2`)),e.setStatus(`已将 ${t.name} 转成 base64 data URL,并写入请求体 images[0].image_url(${o(t.size)})。`)}catch(t){e.setStatus(`图片写入失败: ${y(t)}`)}finally{n===`image-bed`&&e.setBusy(null)}}return(0,T.jsx)(E,{config:e.config,endpoints:M,activeEndpoint:N,endpoint:t,requestBody:r,responseBody:a,timingBody:f,resultTab:C,status:e.status,busy:e.busy,previewImages:O,capability:e.capability,imageUploadMode:A,onEndpoint:P,onRequestBody:i,onResultTab:D,onRun:z,onResetExample:F,onCopyRequest:I,onCopyResponse:L,onCopyTiming:R,onImageUploadMode:j,onPreview:e.setPreviewImage,onImageUpload:B})}export{D as TesterPage};
@@ -0,0 +1 @@
1
+ import{a as e,n as t,r as n,t as r}from"./jsx-runtime-DqpGtLhh.js";import{t as i}from"./clock-3-BzDANsVk.js";import{t as a}from"./refresh-cw-CAAH2rqe.js";import{t as o}from"./zap-B4_oDbCp.js";import{C as s,x as c}from"./profiles-C5SmQvju.js";import{S as l,_ as u,p as d,r as f}from"./index-_5Ny0cZf.js";import{t as p}from"./StatCard-7TEzqn2i.js";var m=t(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),h=t(`camera`,[[`path`,{d:`M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z`,key:`18u6gg`}],[`circle`,{cx:`12`,cy:`13`,r:`3`,key:`1vg3eu`}]]),g=t(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),_=t(`dollar-sign`,[[`line`,{x1:`12`,x2:`12`,y1:`2`,y2:`22`,key:`7eqyqh`}],[`path`,{d:`M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6`,key:`1b0p4s`}]]),v=t(`sigma`,[[`path`,{d:`M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2`,key:`wuwx1p`}]]),y=e(n(),1),b=r();function x(){return{requestCount:0,successCount:0,failureCount:0,inputTokens:0,uncachedInputTokens:0,outputTokens:0,totalTokens:0,cacheCreationTokens:0,cacheReadTokens:0,inputCostUsd:0,outputCostUsd:0,cacheCreationCostUsd:0,cacheReadCostUsd:0,estimatedCostUsd:0,unknownTokenCount:0,unknownTokenStatusCounts:{},imageCount:0,totalDurationMs:0,averageDurationMs:0,p95DurationMs:0,durationBuckets:{}}}function S(e){return new Intl.NumberFormat(`zh-CN`).format(Math.round(e||0))}function C(e){return!Number.isFinite(e)||e<=0?`0`:e>=1e6?`${(e/1e6).toFixed(e>=1e7?1:2)}M`:e>=1e4?`${(e/1e3).toFixed(e>=1e5?0:1)}K`:S(e)}function w(e){return!Number.isFinite(e)||e<=0?`$0.00`:e<.01?`$${e.toFixed(5)}`:e<1?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function T(e){return`${S(e.successCount)} 成功 / ${S(e.failureCount)} 失败`}function E(e){let t=e.inputTokens||0,n=e.cacheReadTokens||0;return t<=0||n<=0?`缓存命中 0%`:`缓存命中 ${Math.min(100,n/t*100).toFixed(1)}%`}function D(e){return e===`captured`?`已捕获用量`:e===`missing_terminal`?`缺少终态事件`:e===`terminal_without_usage`?`终态无 usage`:e===`parse_failed`?`SSE 解析失败`:e===`upstream_error`?`上游错误`:`未返回 usage`}function O(e){let t=Object.entries(e.unknownTokenStatusCounts??{}).filter(([,e])=>e>0).sort((e,t)=>t[1]-e[1]);if(t.length===0)return`未返回用量 ${S(e.unknownTokenCount)} 次`;let[n,r]=t[0]??[`not_returned`,0];return`未返回用量 ${S(e.unknownTokenCount)} 次,主要原因:${D(n)} ${S(r)} 次`}function k(e){let t=e.aggregate??x();return(0,b.jsxs)(`article`,{className:`usage-scope-card`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`span`,{children:e.title}),(0,b.jsxs)(`strong`,{children:[C(t.totalTokens),` 已知 token`]}),(0,b.jsx)(`p`,{children:e.detail})]}),(0,b.jsxs)(`dl`,{children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`dt`,{children:`新输入`}),(0,b.jsx)(`dd`,{children:C(t.uncachedInputTokens)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`dt`,{children:`缓存读`}),(0,b.jsx)(`dd`,{children:C(t.cacheReadTokens)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`dt`,{children:`估算费用`}),(0,b.jsx)(`dd`,{children:w(t.estimatedCostUsd)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`dt`,{children:`平均`}),(0,b.jsx)(`dd`,{children:c(t.averageDurationMs)})]}),(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`dt`,{children:`P95`}),(0,b.jsx)(`dd`,{children:c(t.p95DurationMs)})]})]}),(0,b.jsxs)(`p`,{className:`usage-scope-footer`,children:[T(t),` · `,E(t),` · `,O(t)]})]})}function A(e){return(0,b.jsxs)(`section`,{className:`usage-table-card`,children:[(0,b.jsxs)(`div`,{className:`usage-table-head`,children:[(0,b.jsx)(`h3`,{children:e.title}),(0,b.jsxs)(`span`,{children:[e.rows.length,` 项`]})]}),e.rows.length===0?(0,b.jsx)(`div`,{className:`usage-empty`,children:e.empty}):(0,b.jsx)(`div`,{className:`usage-table-scroll`,children:(0,b.jsxs)(`table`,{className:`usage-table`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`th`,{children:`维度`}),(0,b.jsx)(`th`,{children:`请求`}),(0,b.jsx)(`th`,{children:`失败`}),(0,b.jsx)(`th`,{children:`新输入`}),(0,b.jsx)(`th`,{children:`缓存读`}),(0,b.jsx)(`th`,{children:`估算费用`}),(0,b.jsx)(`th`,{children:`已知 token`}),(0,b.jsx)(`th`,{children:`未返回用量`}),(0,b.jsx)(`th`,{children:`图片`}),(0,b.jsx)(`th`,{children:`平均耗时`})]})}),(0,b.jsx)(`tbody`,{children:e.rows.map(e=>(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`td`,{children:e.label}),(0,b.jsx)(`td`,{children:S(e.aggregate.requestCount)}),(0,b.jsx)(`td`,{children:S(e.aggregate.failureCount)}),(0,b.jsx)(`td`,{children:C(e.aggregate.uncachedInputTokens)}),(0,b.jsx)(`td`,{children:C(e.aggregate.cacheReadTokens)}),(0,b.jsx)(`td`,{children:w(e.aggregate.estimatedCostUsd)}),(0,b.jsx)(`td`,{children:C(e.aggregate.totalTokens)}),(0,b.jsx)(`td`,{children:S(e.aggregate.unknownTokenCount)}),(0,b.jsx)(`td`,{children:S(e.aggregate.imageCount)}),(0,b.jsx)(`td`,{children:c(e.aggregate.averageDurationMs)})]},e.key))})]})})]})}function j(e){return(0,b.jsxs)(`section`,{className:`usage-table-card usage-daily-card`,children:[(0,b.jsxs)(`div`,{className:`usage-table-head`,children:[(0,b.jsx)(`h3`,{children:`每日趋势`}),(0,b.jsxs)(`span`,{children:[`最近 `,e.rows.length,` 天`]})]}),e.rows.length===0?(0,b.jsx)(`div`,{className:`usage-empty`,children:`还没有历史用量。`}):(0,b.jsx)(`div`,{className:`usage-table-scroll`,children:(0,b.jsxs)(`table`,{className:`usage-table`,children:[(0,b.jsx)(`thead`,{children:(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`th`,{children:`日期`}),(0,b.jsx)(`th`,{children:`请求`}),(0,b.jsx)(`th`,{children:`成功`}),(0,b.jsx)(`th`,{children:`失败`}),(0,b.jsx)(`th`,{children:`新输入`}),(0,b.jsx)(`th`,{children:`缓存读`}),(0,b.jsx)(`th`,{children:`估算费用`}),(0,b.jsx)(`th`,{children:`已知输入`}),(0,b.jsx)(`th`,{children:`已知输出`}),(0,b.jsx)(`th`,{children:`已知总 token`}),(0,b.jsx)(`th`,{children:`未返回用量`}),(0,b.jsx)(`th`,{children:`图片`}),(0,b.jsx)(`th`,{children:`P95`})]})}),(0,b.jsx)(`tbody`,{children:e.rows.map(e=>(0,b.jsxs)(`tr`,{children:[(0,b.jsx)(`td`,{children:e.date}),(0,b.jsx)(`td`,{children:S(e.aggregate.requestCount)}),(0,b.jsx)(`td`,{children:S(e.aggregate.successCount)}),(0,b.jsx)(`td`,{children:S(e.aggregate.failureCount)}),(0,b.jsx)(`td`,{children:C(e.aggregate.uncachedInputTokens)}),(0,b.jsx)(`td`,{children:C(e.aggregate.cacheReadTokens)}),(0,b.jsx)(`td`,{children:w(e.aggregate.estimatedCostUsd)}),(0,b.jsx)(`td`,{children:C(e.aggregate.inputTokens)}),(0,b.jsx)(`td`,{children:C(e.aggregate.outputTokens)}),(0,b.jsx)(`td`,{children:C(e.aggregate.totalTokens)}),(0,b.jsx)(`td`,{children:S(e.aggregate.unknownTokenCount)}),(0,b.jsx)(`td`,{children:S(e.aggregate.imageCount)}),(0,b.jsx)(`td`,{children:c(e.aggregate.p95DurationMs)})]},e.date))})]})})]})}function M(e){let[t,n]=(0,y.useState)(e.config?.usage??null),[r,T]=(0,y.useState)(!1),[D,O]=(0,y.useState)(!1);(0,y.useEffect)(()=>{n(e.config?.usage??null)},[e.config?.usage]);async function M(){T(!0);try{n(await d(`/_gateway/admin/usage`)),e.setStatus(`用量统计已刷新。`)}catch(t){e.setStatus(`用量统计刷新失败: ${f(t)}`)}finally{T(!1)}}async function N(){if(window.confirm(`会先备份当前统计目录,然后清空用量记录并从 0 重新统计。确认继续?`)){O(!0);try{let t=await d(`/_gateway/admin/usage/reset`,{method:`POST`});n(t.usage),e.setStatus(`用量统计已备份并清空:${t.backupDir}`)}catch(t){e.setStatus(`用量统计清空失败: ${f(t)}`)}finally{O(!1)}}}let P=t,F=P?.lifetime??x(),I=P?.today??x(),L=P?.startup??x(),R=(0,y.useMemo)(()=>F.requestCount===0?`0%`:`${(F.failureCount/F.requestCount*100).toFixed(1)}%`,[F.failureCount,F.requestCount]);return(0,b.jsxs)(`section`,{className:`usage-page`,children:[(0,b.jsxs)(`div`,{className:`usage-actions`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsx)(`span`,{children:`统计文件`}),(0,b.jsx)(`code`,{children:P?.storageDir||`~/.ai-zero-token/.state/usage`})]}),(0,b.jsxs)(`div`,{className:`usage-action-buttons`,children:[(0,b.jsxs)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>void M(),disabled:r||D,children:[r?(0,b.jsx)(u,{className:`spin`,size:16}):(0,b.jsx)(a,{size:16}),`刷新统计`]}),(0,b.jsxs)(`button`,{className:`btn-danger`,type:`button`,onClick:()=>void N(),disabled:r||D,children:[D?(0,b.jsx)(u,{className:`spin`,size:16}):(0,b.jsx)(m,{size:16}),`备份并清空`]})]})]}),(0,b.jsxs)(`section`,{className:`summary-grid desktop-summary-grid usage-summary-grid`,children:[(0,b.jsx)(p,{icon:v,label:`历史已知 token`,value:C(F.totalTokens),detail:`新输入 ${C(F.uncachedInputTokens)},缓存读 ${C(F.cacheReadTokens)}`,tone:`blue`}),(0,b.jsx)(p,{icon:o,label:`今日已知 token`,value:C(I.totalTokens),detail:`${P?.todayDate||`今天`} · ${E(I)}`,tone:`green`}),(0,b.jsx)(p,{icon:l,label:`本次启动已知 token`,value:C(L.totalTokens),detail:`缓存读 ${C(L.cacheReadTokens)} · 启动于 ${s(P?.startedAt)}`,tone:`brand`}),(0,b.jsx)(p,{icon:_,label:`今日估算费用`,value:w(I.estimatedCostUsd),detail:`输入 ${w(I.inputCostUsd+I.cacheCreationCostUsd+I.cacheReadCostUsd)},输出 ${w(I.outputCostUsd)}`,tone:`green`}),(0,b.jsx)(p,{icon:h,label:`图片张数`,value:S(F.imageCount),detail:`历史累计生成或编辑图片`,tone:`orange`}),(0,b.jsx)(p,{icon:i,label:`历史 P95`,value:c(F.p95DurationMs),detail:`平均 ${c(F.averageDurationMs)}`,tone:`orange`}),(0,b.jsx)(p,{icon:g,label:`失败率`,value:R,detail:`${S(F.failureCount)} 次失败`,tone:F.failureCount>0?`orange`:`green`})]}),(0,b.jsxs)(`section`,{className:`usage-scope-grid`,children:[(0,b.jsx)(k,{title:`今日用量`,detail:`当天 00:00 到现在`,aggregate:I}),(0,b.jsx)(k,{title:`本次启动`,detail:`当前网关进程启动后到现在`,aggregate:L}),(0,b.jsx)(k,{title:`历史累计`,detail:`从开始记录以来的全部累计`,aggregate:F})]}),(0,b.jsx)(j,{rows:P?.daily??[]}),(0,b.jsxs)(`section`,{className:`usage-dimension-grid`,children:[(0,b.jsx)(A,{title:`按账号`,rows:P?.byAccount??[],empty:`还没有账号维度数据。`}),(0,b.jsx)(A,{title:`按模型`,rows:P?.byModel??[],empty:`还没有模型维度数据。`}),(0,b.jsx)(A,{title:`按接口`,rows:P?.byEndpoint??[],empty:`还没有接口维度数据。`}),(0,b.jsx)(A,{title:`按用量捕获状态`,rows:P?.byTokenUsageStatus??[],empty:`还没有用量捕获状态数据。`}),(0,b.jsx)(A,{title:`按错误`,rows:P?.byError??[],empty:`还没有错误记录。`}),(0,b.jsx)(A,{title:`按生图链路`,rows:P?.byImageRoute??[],empty:`还没有生图链路数据。`}),(0,b.jsx)(A,{title:`按来源`,rows:P?.bySource??[],empty:`还没有来源维度数据。`})]})]})}export{M as UsagePage};
@@ -5,10 +5,10 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <link rel="icon" type="image/svg+xml" href="/assets/app-mark-nsRs4vo7.svg" />
7
7
  <title>AI Zero Token</title>
8
- <script type="module" crossorigin src="/assets/index-CCiBaGwU.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-_5Ny0cZf.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/assets/jsx-runtime-DqpGtLhh.js">
10
10
  <link rel="modulepreload" crossorigin href="/assets/profiles-C5SmQvju.js">
11
- <link rel="stylesheet" crossorigin href="/assets/index-C22_3Mxq.css">
11
+ <link rel="stylesheet" crossorigin href="/assets/index-BRQrU_AA.css">
12
12
  </head>
13
13
  <body>
14
14
  <div id="root"></div>
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env node
2
+ import { createHash } from "node:crypto";
2
3
  import { DEFAULT_CODEX_MODEL } from "../../models/openai-codex-models.js";
3
4
  import { requestStream, requestText } from "../http-client.js";
4
5
  const CODEX_RESPONSES_URL = "https://chatgpt.com/backend-api/codex/responses";
5
6
  const CODEX_RESPONSES_COMPACT_URL = `${CODEX_RESPONSES_URL}/compact`;
7
+ const COMPAT_PROMPT_CACHE_KEY_PREFIX = "compat_cc_";
8
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
6
9
  const URL_KEY_RE = /(url|uri|href|download|preview|thumbnail|image|asset|file)/i;
7
10
  const REFERENCE_KEY_RE = /(image|asset|file|media|blob|artifact|download|preview|thumbnail)/i;
8
11
  const REFERENCE_VALUE_RE = /^(file|asset|image|img|media|blob)-[\w-]+$/i;
@@ -60,8 +63,125 @@ function parseUpstreamErrorBody(body) {
60
63
  return void 0;
61
64
  }
62
65
  }
63
- function buildCodexRequestHeaders(profile) {
64
- return {
66
+ function hashShort(value) {
67
+ return createHash("sha256").update(value).digest("hex").slice(0, 16);
68
+ }
69
+ function stableStringify(value) {
70
+ if (typeof value === "undefined") {
71
+ return "";
72
+ }
73
+ if (value === null || typeof value !== "object") {
74
+ return JSON.stringify(value) ?? String(value);
75
+ }
76
+ if (Array.isArray(value)) {
77
+ return `[${value.map((item) => stableStringify(item)).join(",")}]`;
78
+ }
79
+ const record = value;
80
+ return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(record[key])}`).join(",")}}`;
81
+ }
82
+ function shouldAutoInjectPromptCacheKeyForCompat(model) {
83
+ const normalized = typeof model === "string" && model.trim() ? model.trim().toLowerCase() : DEFAULT_CODEX_MODEL.toLowerCase();
84
+ return normalized.includes("gpt-5") || normalized.includes("codex");
85
+ }
86
+ function extractInputContentText(content) {
87
+ if (typeof content === "string") {
88
+ return content.trim();
89
+ }
90
+ if (!Array.isArray(content)) {
91
+ const record = asRecord(content);
92
+ return typeof record?.text === "string" ? record.text.trim() : "";
93
+ }
94
+ return content.map((part) => {
95
+ const record = asRecord(part);
96
+ if (!record) {
97
+ return "";
98
+ }
99
+ if (typeof record.text === "string") {
100
+ return record.text.trim();
101
+ }
102
+ if (typeof record.input_text === "string") {
103
+ return record.input_text.trim();
104
+ }
105
+ return "";
106
+ }).filter(Boolean).join("\n").trim();
107
+ }
108
+ function extractFirstInputTextByRole(input, roles) {
109
+ if (typeof input === "string") {
110
+ return roles.has("user") ? input.trim() : "";
111
+ }
112
+ if (!Array.isArray(input)) {
113
+ return "";
114
+ }
115
+ for (const item of input) {
116
+ const record = asRecord(item);
117
+ if (!record) {
118
+ continue;
119
+ }
120
+ const role = typeof record.role === "string" ? record.role.trim().toLowerCase() : "user";
121
+ if (!roles.has(role)) {
122
+ continue;
123
+ }
124
+ const text = extractInputContentText(record.content);
125
+ if (text) {
126
+ return text;
127
+ }
128
+ }
129
+ return "";
130
+ }
131
+ function deriveCompatPromptCacheKey(body) {
132
+ const model = typeof body.model === "string" && body.model.trim() ? body.model.trim() : DEFAULT_CODEX_MODEL;
133
+ if (!shouldAutoInjectPromptCacheKeyForCompat(model)) {
134
+ return "";
135
+ }
136
+ const seedParts = [`model=${model}`];
137
+ const reasoning = asRecord(body.reasoning);
138
+ if (typeof reasoning?.effort === "string" && reasoning.effort.trim()) {
139
+ seedParts.push(`reasoning_effort=${reasoning.effort.trim()}`);
140
+ }
141
+ if (typeof body.tool_choice !== "undefined") {
142
+ seedParts.push(`tool_choice=${stableStringify(body.tool_choice)}`);
143
+ }
144
+ if (Array.isArray(body.tools) && body.tools.length > 0) {
145
+ seedParts.push(`tools=${stableStringify(body.tools)}`);
146
+ }
147
+ if (typeof body.instructions === "string" && body.instructions.trim()) {
148
+ seedParts.push(`instructions=${body.instructions.trim()}`);
149
+ }
150
+ const systemText = extractFirstInputTextByRole(body.input, /* @__PURE__ */ new Set(["system", "developer"]));
151
+ if (systemText) {
152
+ seedParts.push(`system=${systemText}`);
153
+ }
154
+ const firstUserText = extractFirstInputTextByRole(body.input, /* @__PURE__ */ new Set(["user"]));
155
+ if (firstUserText) {
156
+ seedParts.push(`first_user=${firstUserText}`);
157
+ }
158
+ return `${COMPAT_PROMPT_CACHE_KEY_PREFIX}${hashShort(seedParts.join("|"))}`;
159
+ }
160
+ function withCompatPromptCacheKey(body) {
161
+ const existing = typeof body.prompt_cache_key === "string" ? body.prompt_cache_key.trim() : "";
162
+ if (existing) {
163
+ return body;
164
+ }
165
+ const promptCacheKey = deriveCompatPromptCacheKey(body);
166
+ return promptCacheKey ? { ...body, prompt_cache_key: promptCacheKey } : body;
167
+ }
168
+ function deterministicSessionUUID(seed) {
169
+ const hash = Buffer.from(createHash("sha256").update(seed).digest().subarray(0, 16));
170
+ hash[6] = hash[6] & 15 | 64;
171
+ hash[8] = hash[8] & 63 | 128;
172
+ const hex = hash.toString("hex");
173
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
174
+ }
175
+ function normalizeSessionIdentifier(value) {
176
+ const trimmed = value.trim();
177
+ return UUID_RE.test(trimmed) ? trimmed : deterministicSessionUUID(trimmed);
178
+ }
179
+ function requestBodyString(body, key) {
180
+ const value = body?.[key];
181
+ return typeof value === "string" ? value.trim() : "";
182
+ }
183
+ function buildCodexRequestHeaders(profile, requestBody) {
184
+ const headers = {
65
185
  Accept: "text/event-stream",
66
186
  "Content-Type": "application/json",
67
187
  Authorization: `Bearer ${profile.access}`,
@@ -70,6 +190,17 @@ function buildCodexRequestHeaders(profile) {
70
190
  Originator: "pi",
71
191
  "User-Agent": "pi (bun demo)"
72
192
  };
193
+ const explicitSessionId = requestBodyString(requestBody, "session_id");
194
+ const conversationId = requestBodyString(requestBody, "conversation_id");
195
+ const promptCacheKey = requestBodyString(requestBody, "prompt_cache_key");
196
+ const sessionSeed = explicitSessionId || promptCacheKey || conversationId;
197
+ if (sessionSeed) {
198
+ headers.session_id = normalizeSessionIdentifier(sessionSeed);
199
+ }
200
+ if (conversationId) {
201
+ headers.conversation_id = normalizeSessionIdentifier(conversationId);
202
+ }
203
+ return headers;
73
204
  }
74
205
  function createCodexUpstreamError(status, body, transport, quota, requestId) {
75
206
  const upstreamError = parseUpstreamErrorBody(body);
@@ -397,17 +528,17 @@ function extractCodexText(body, requestBody) {
397
528
  };
398
529
  }
399
530
  async function askOpenAICodex(params) {
400
- const requestBody = {
531
+ const requestBody = withCompatPromptCacheKey({
401
532
  ...buildDefaultRequestBody(params),
402
533
  ...params.bodyOverride ?? {}
403
- };
534
+ });
404
535
  if (typeof requestBody.input === "undefined") {
405
536
  throw new Error("Codex \u8BF7\u6C42\u7F3A\u5C11 input\u3002\u8BF7\u63D0\u4F9B prompt \u6216\u5728\u5B9E\u9A8C\u8BF7\u6C42\u4F53\u91CC\u663E\u5F0F\u4F20\u5165 input\u3002");
406
537
  }
407
538
  const response = await requestText({
408
539
  method: "POST",
409
540
  url: CODEX_RESPONSES_URL,
410
- headers: buildCodexRequestHeaders(params.profile),
541
+ headers: buildCodexRequestHeaders(params.profile, requestBody),
411
542
  body: JSON.stringify(requestBody)
412
543
  });
413
544
  const quota = extractCodexQuotaSnapshot(response.headers, response.requestId);
@@ -420,17 +551,17 @@ async function askOpenAICodex(params) {
420
551
  };
421
552
  }
422
553
  async function streamOpenAICodex(params) {
423
- const requestBody = params.passthroughBody ? { ...params.bodyOverride ?? {} } : {
554
+ const requestBody = params.passthroughBody ? { ...params.bodyOverride ?? {} } : withCompatPromptCacheKey({
424
555
  ...buildDefaultRequestBody(params),
425
556
  ...params.bodyOverride ?? {}
426
- };
557
+ });
427
558
  if (!params.passthroughBody && typeof requestBody.input === "undefined") {
428
559
  throw new Error("Codex \u8BF7\u6C42\u7F3A\u5C11 input\u3002\u8BF7\u63D0\u4F9B prompt \u6216\u5728\u5B9E\u9A8C\u8BF7\u6C42\u4F53\u91CC\u663E\u5F0F\u4F20\u5165 input\u3002");
429
560
  }
430
561
  const response = await requestStream({
431
562
  method: "POST",
432
563
  url: params.endpoint === "responses/compact" ? CODEX_RESPONSES_COMPACT_URL : CODEX_RESPONSES_URL,
433
- headers: buildCodexRequestHeaders(params.profile),
564
+ headers: buildCodexRequestHeaders(params.profile, requestBody),
434
565
  body: JSON.stringify(requestBody),
435
566
  signal: params.signal
436
567
  });