@bitkyc08/opencodex 2.7.25 → 2.7.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gui/dist/assets/{index-Dq3eZ1cU.css → index-BnrJO9Wz.css} +1 -1
- package/gui/dist/assets/{index-QyUBi3W_.js → index-BvQ5spEX.js} +3 -3
- package/gui/dist/index.html +2 -2
- package/package.json +1 -1
- package/src/cli/index.ts +7 -2
- package/src/config.ts +60 -2
- package/src/lib/errors.ts +51 -12
- package/src/lib/process-control.ts +1 -1
- package/src/lib/redact.ts +8 -0
- package/src/lib/windows-secret-acl.ts +217 -74
- package/src/oauth/github-copilot.ts +427 -0
- package/src/oauth/index.ts +41 -4
- package/src/oauth/kimi.ts +52 -1
- package/src/oauth/store.ts +20 -3
- package/src/oauth/types.ts +5 -0
- package/src/providers/github-copilot-transport.ts +56 -0
- package/src/providers/quota.ts +111 -59
- package/src/providers/registry.ts +56 -2
- package/src/providers/xai-transport.ts +5 -0
- package/src/server/ports.ts +44 -2
- package/src/server/proxy-liveness.ts +26 -4
- package/src/server/request-log.ts +20 -6
- package/src/server/responses.ts +14 -5
- package/src/update/job.ts +59 -11
|
@@ -30,11 +30,11 @@ v1: 经典单线程代理。所有模型使用 v1 协作界面。
|
|
|
30
30
|
base: 上游默认值 — sol/terra 使用 v2,luna 使用 v1,其余跟随 codex 功能标志。
|
|
31
31
|
v2: 多线程代理(spawn_agent)。所有模型使用 v2 协作界面。
|
|
32
32
|
|
|
33
|
-
更改在新会话中生效。`,"models.v2DocsLink":`v1 / v2 是什么?`,"dash.multiAgent":`子代理`,"models.v2Conflict":`[agents] max_threads 仍存在 — codex 将拒绝启动,请从 config.toml 移除`,"models.v2Applied":`multi_agent_v2 已更新 — 新会话生效(重启 Codex 应用以刷新选择器)`,"models.v2ThreadsLabel":`最大线程`,"models.v2ThreadsDefault":`默认 (4)`,"models.v2ThreadsApplied":`线程上限已更新 — 新会话生效`,"models.v2ThreadsInvalid":`线程上限必须为 >= 1 的整数`,"models.v2ThreadsApply":`应用`,"models.capValue":`限制 {value}`,"models.contextCappedValue":`{value} 限制`,"models.setAll":`全部设置`,"models.custom":`自定义…`,"models.customApply":`应用`,"models.customPlaceholder":`令牌 (例如 420000)`,"models.applied":`已应用 — 将在下一个 Codex 回合生效。`,"models.saveFailed":`保存失败`,"models.networkError":`网络错误 — 代理在运行吗?`,"models.loadFail":`加载模型失败 — 代理在运行吗?`,"models.noRouted":`没有已路由的模型`,"models.noRoutedHint":`请先登录提供方或添加一个。`,"models.loading":`加载中…`,"models.search":`搜索模型…`,"models.showMore":`再显示 {n} 个`,"models.allowlistLabel":`仅所选`,"models.allowlistHint":`仅勾选的模型进入目录(留空 = 全部)。适用于暴露成千上万模型的提供商。`,"models.selectedCount":`已选 {n} 个`,"models.orderHint":`选择器顺序:Subagents 中的选择(按所选顺序)→ 其余已路由模型(依次按提供方、模型 ID 字母排序)→ 原生模型。可见性开关仅用于筛选,不会改变此顺序。`,"sub.subtitle":`Codex 的 {cmd} 仅将优先级最高的前 5 个模型作为覆盖项公开。在此最多选择 5 个 — 原生 gpt 或已路由模型 — opencodex 会设置它们的目录优先级,使其正好排在前面。其他模型仍可按确切名称调用;此设置仅控制显示项。`,"sub.featured":`精选`,"sub.orderHint":`此处所选并显示的顺序决定 Codex 模型选择器顶部第 1–5 位,以及 {cmd} 的默认模型候选。`,"sub.noneSelected":`未选择 — 请从下方列表选择。`,"sub.models":`模型`,"sub.search":`搜索模型(原生 gpt + 已路由)…`,"sub.noModels":`没有模型 — 请先登录提供方或添加一个。`,"sub.saved":`已保存 {n} 个模型。启动新的 Codex 会话(或运行 {cmd})以将它们作为 spawn_agent 覆盖项查看。`,"sub.saveFailed":`保存失败`,"sub.networkError":`网络错误 — 代理在运行吗?`,"sub.loadFail":`加载模型失败 — 代理在运行吗?`,"sub.loading":`加载中…`,"sub.moveUp":`上移 {m}`,"sub.moveDown":`下移 {m}`,"sub.removeAria":`移除 {m}`,"logs.title":`请求日志`,"logs.subtitle":`经过本地 opencodex 代理的最近请求,最新在前。`,"logs.autoRefresh":`自动刷新`,"logs.noRequests":`暂无请求。`,"logs.filter.surface.label":`界面`,"logs.filter.surface.all":`全部`,"logs.filter.surface.claude":`Claude`,"logs.filter.surface.codex":`Codex`,"logs.badge.claude":`Claude`,"logs.col.time":`时间`,"logs.col.request":`请求`,"logs.col.model":`模型`,"logs.col.effort":`推理强度`,"logs.col.provider":`提供方`,"logs.col.status":`状态`,"logs.col.tokens":`Token 数`,"logs.col.error":`错误`,"logs.col.upstreamReason":`上游原因`,"logs.col.duration":`耗时`,"logs.tokens.reported":`已上报`,"logs.tokens.unreported":`未上报`,"logs.tokens.unsupported":`不支持`,"logs.tokens.estimated":`估算`,"logs.tokens.input":`输入`,"logs.tokens.output":`输出`,"logs.tokens.cacheRead":`缓存命中 (c)`,"logs.tokens.cacheWrite":`缓存写入 (w)`,"logs.tokens.reasoning":`推理`,"logs.tokens.noCache":`无缓存数据`,"logs.tokens.noCacheNote":`该提供商不报告缓存 token 数`,"logs.tokens.estimatedNote":`估算值(提供商不报告精确用量)`,"logs.details":`查看详情`,"logs.detailTitle":`请求详情`,"logs.detailRaw":`原始日志`,"debug.title":`调试`,"debug.subtitle":`可选的 provider transport 与 usage 提取诊断。请求错误和 502 在 Logs 页面。`,"debug.debug":`Provider debug`,"debug.usage":`Usage 提取`,"debug.injection":`注入日志`,"debug.claude":`Claude 入站`,"debug.claudeInbound.title":`Claude 入站请求`,"debug.claudeInbound.sub":`显示 Claude Code/Desktop 实际发送的内容(thinking、effort、metadata)— 不保存提示词原文。`,"debug.claudeInbound.empty":`尚未捕获任何请求。开启后从 Claude 发送一条消息试试。`,"debug.claudeInbound.time":`时间`,"debug.claudeInbound.endpoint":`端点`,"debug.claudeInbound.model":`模型`,"debug.claudeInbound.none":`无`,"debug.reset":`清除运行时覆盖`,"debug.refresh":`刷新`,"debug.follow":`跟随滚动`,"debug.streamProvider":`Provider`,"debug.streamUsage":`Usage`,"debug.streamInjection":`Injection`,"debug.loading":`正在加载调试设置…`,"debug.emptyTitle":`调试日志已关闭`,"debug.empty":`请在上方卡片中开启 Provider debug 或 Usage extraction。通过代理发送请求后,诊断行会显示在这里。`,"debug.noLinesTitle":`等待诊断行`,"debug.noLines.provider":`提供商调试已开启,但仅记录传输异常(丢弃或格式错误的帧,以及 Cursor dial/retry 事件)。通过 Anthropic 等提供商的正常请求可能不会产生任何行。`,"debug.noLines.usage":`用量提取已开启但尚未捕获任何内容。请通过 Codex 发送请求,随后会显示在此处。`,"debug.noLines.injection":`注入日志已开启但尚未捕获任何内容。它记录协作和子代理回合中的多代理指导注入与 effort-cap 决策。`,"usage.title":`用量`,"usage.subtitle":`代理本地的 Token 用量统计。缺失的用量不会显示为零。`,"usage.loading":`正在加载用量数据…`,"usage.empty":`尚无用量记录。通过代理发送请求后将在此显示。`,"usage.range.all":`全部`,"usage.range.30d":`30 天`,"usage.range.7d":`7 天`,"usage.card.requests":`请求数`,"usage.card.measured":`已计量`,"usage.card.reported":`已上报`,"usage.card.totalTokens":`Token 总数`,"usage.card.cachedTokens":`缓存命中 Token`,"usage.card.cachedTokensHint":`从提供商缓存读取的提示 Token(命中)。缓存写入在下方单独显示。`,"usage.card.cacheWriteTokens":`缓存写入`,"usage.card.coverage":`覆盖率`,"usage.card.activeDays":`活跃天数`,"usage.section.heatmap":`每日活动`,"usage.section.models":`模型`,"usage.section.providers":`提供方`,"usage.section.coverage":`覆盖率明细`,"usage.coverage.measured":`已计量`,"usage.coverage.reported":`提供方上报`,"usage.coverage.estimated":`估算`,"usage.coverage.note":`已计量包含提供方上报和估算的 Token 数。未上报 / 不支持请求仅做计数,不会被算作 0 Token。`,"usage.search.models":`搜索模型…`,"usage.col.requests":`请求数`,"usage.col.measured":`已计量`,"usage.col.reported":`已上报`,"usage.col.tokens":`Token 数`,"usage.col.share":`占比`,"usage.heatmap.less":`少`,"usage.heatmap.more":`多`,"modal.addNamed":`添加:{label}`,"modal.add":`添加提供方`,"modal.search":`搜索提供方…`,"modal.logInWith":`使用 {label} 登录`,"modal.waitingBrowser":`等待浏览器…`,"modal.providerName":`提供方名称`,"modal.adapter":`适配器`,"modal.baseUrl":`Base URL`,"modal.defaultModel":`默认模型(可选)`,"modal.nameRequired":`提供方名称为必填项`,"modal.baseUrlRequired":`Base URL 为必填项`,"modal.networkError":`网络错误 — 代理在运行吗?`,"modal.loginFailStart":`登录启动失败`,"modal.waitingLogin":`等待浏览器登录…`,"modal.loggingIn":`登录中…`,"modal.loginTimeout":`登录超时 — 请重试。`,"nav.api":`API`,"nav.codexAuth":`Codex 认证`,"nav.openMenu":`打开菜单`,"nav.closeMenu":`关闭菜单`,"codexAuth.mainAccount":`主账号`,"codexAuth.appLogin":`应用登录`,"codexAuth.accountPool":`账号池`,"codexAuth.accountModeTitle":`OpenAI 账户模式`,"codexAuth.accountModePool":`账户池模式`,"codexAuth.accountModePoolDesc":`主登录与符合条件的已添加账户会在此轮换。`,"codexAuth.accountModeDirect":`直连模式`,"codexAuth.accountModeDirectDesc":`请求仅使用主登录;已添加账户会继续存储,供账户池模式使用。`,"codexAuth.openaiMissing":`未配置内置 OpenAI 提供方。`,"codexAuth.openaiDisabled":`内置 OpenAI 提供方已禁用。`,"codexAuth.openProviders":`打开提供商`,"codexAuth.add":`添加`,"codexAuth.refreshQuota":`刷新额度`,"codexAuth.refreshingQuota":`刷新中...`,"codexAuth.quotaRefreshed":`额度已刷新`,"codexAuth.quotaRefreshFailed":`额度刷新失败`,"codexAuth.noPool":`尚未添加池账号。`,"codexAuth.fiveHour":`5 小时`,"codexAuth.weekly":`每周`,"codexAuth.monthly":`30天`,"codexAuth.resets":`重置`,"codexAuth.today":`今天`,"codexAuth.current":`当前`,"codexAuth.nextSession":`下次会话`,"codexAuth.poolPrepared":`已为账户池准备`,"codexAuth.preparePoolTitle":`为账户池模式准备此账号?`,"codexAuth.preparePoolDesc":`直连请求仍使用主登录。启用账户池模式后,此账号会成为预先选择的池账号。`,"codexAuth.prepareForPool":`为账户池准备`,"codexAuth.poolPreparedToast":`已为账户池模式准备 {email}`,"codexAuth.switchTitle":`切换活跃账号?`,"codexAuth.switchDesc":`从下次 Codex 会话开始生效。当前会话保持现有账号。`,"codexAuth.cacheWarning":`切换账号会重置提示缓存。新会话从空缓存开始。`,"codexAuth.setAsNext":`设为下次会话`,"codexAuth.cancel":`取消`,"codexAuth.switchBack":`切换回主账号?`,"codexAuth.switchBackDesc":`下次 Codex 会话将使用应用登录账号。`,"codexAuth.autoSwitch":`超过 80% 时自动切换`,"codexAuth.autoSwitchDesc":`新会话会在相关额度窗口达到阈值时切换;Go/Free 只使用 30天`,"codexAuth.switched":`下次会话将使用 {email}`,"codexAuth.loadFailed":`无法加载账户。`,"codexAuth.switchFailed":`无法切换账户。之前的选择保持不变。`,"codexAuth.removeConfirm":`删除 {id}?`,"codexAuth.removeFailed":`无法移除账户。未进行任何更改。`,"codexAuth.addTitle":`添加 Codex 账号`,"codexAuth.addIdLabel":`账号 ID(标识符)`,"codexAuth.addJsonLabel":`auth.json 内容`,"codexAuth.addHelp":`从另一台机器的 ~/.codex/auth.json 复制,或使用 codex-auth export。`,"codexAuth.importBtn":`导入`,"codexAuth.importInvalidJson":`无效的 JSON`,"codexAuth.importMissingTokens":`JSON 中缺少 access_token 或 refresh_token`,"codexAuth.importMissingId":`请输入账号 ID`,"codexAuth.accountAdded":`账号已添加到池中`,"codexAuth.addPickDesc":`使用另一个 ChatGPT 账号登录以添加到池中。`,"codexAuth.oauthLogin":`OAuth 登录`,"codexAuth.oauthDesc":`在浏览器中打开 ChatGPT 登录`,"codexAuth.importAuthJson":`导入 auth.json`,"codexAuth.importAuthJsonDesc":`从另一个 Codex 安装或 codex-auth 导出`,"codexAuth.back":`返回`,"codexAuth.oauthAlreadyInProgress":`登录已在进行中。请在浏览器中完成。`,"codexAuth.oauthWaiting":`等待浏览器中完成 ChatGPT 登录...`,"codexAuth.copyLoginLink":`复制登录链接`,"codexAuth.loginLinkCopied":`登录链接已复制`,"codexAuth.loginLinkCopyFailed":`无法复制登录链接。`,"codexAuth.oauthCancelled":`登录已取消。`,"codexAuth.needsReauth":`重新登录`,"codexAuth.tokenExpired":`令牌已过期 — 重新添加此账号以刷新`,"codexAuth.emailCollision":`此账号与您的主 Codex 登录相同。请使用其他账号。`,"codexAuth.resetCreditsTitle":`重置额度`,"codexAuth.resetCreditsAvailable":`您有 {count} 个可用重置额度。`,"codexAuth.resetCreditsDesc":`每个额度可立即重置您当前的小时和每周使用限制。`,"codexAuth.noResetCredits":`没有可用的重置额度。`,"codexAuth.earnCreditsHint":`额度每月自动发放,也可通过推荐计划获得。`,"codexAuth.creditsExpireNote":`额度在获得后 30 天过期。`,"codexAuth.useOneCredit":`使用 1 个额度`,"codexAuth.confirmResetTitle":`使用重置额度?`,"codexAuth.confirmResetDesc":`这将立即重置您当前的使用限制。剩余额度:{count} 个。`,"codexAuth.irreversible":`此操作不可撤销。`,"codexAuth.useCredit":`使用额度`,"codexAuth.redeeming":`重置中...`,"codexAuth.resetSuccess":`使用限制已重置!剩余额度:{remaining} 个。`,"codexAuth.resetNothingToReset":`当前没有需要重置的使用窗口。`,"codexAuth.resetNoCredit":`没有可用的重置额度。`,"codexAuth.resetError":`重置额度使用失败,请重试。`,"codexAuth.fifoNote":`最早获得的额度优先使用。`,"codexAuth.confirmWhichCredit":`将使用 {date} 获得的额度。`,"codexAuth.creditNext":`即将使用`,"codexAuth.creditLabel":`额度 #{n}`,"codexAuth.creditNextBadge":`NEXT`,"codexAuth.creditGranted":`获得 {date}`,"codexAuth.creditExpires":`过期 {date}(剩余 {days} 天)`,"api.title":`API 访问`,"api.subtitle":`使用生成的 API 密钥从外部应用访问 opencodex 代理。通过 {authHeader} 或 {altHeader} 请求头进行认证。`,"api.endpoint":`端点`,"api.endpointNote":`兼容 OpenAI Responses API 格式。`,"api.newKeyTitle":`已创建新密钥`,"api.newKeyNote":`请立即复制此密钥,它不会再次显示。`,"api.copy":`复制`,"api.copied":`已复制`,"api.dismiss":`关闭`,"api.generateTitle":`生成密钥`,"api.keyNamePlaceholder":`密钥名称(可选)`,"api.generate":`生成`,"api.generating":`创建中…`,"api.activeKeys":`活跃密钥({count})`,"api.noKeys":`还没有 API 密钥。请在上方生成一个。`,"api.colName":`名称`,"api.colKey":`密钥`,"api.colCreated":`创建时间`,"api.confirm":`确认`,"api.deleteAria":`删除 API 密钥`,"api.usageTitle":`使用示例`,"nav.claude":`Claude`,"claude.subtitle":`在 Claude Code 中使用 GPT、Gemini 等其他模型。`,"claude.enabledLabel":`Claude 连接`,"claude.enabledHint":`关闭后 Claude Code 无法使用此代理。`,"claude.authMode":`认证模式`,"claude.authModeHint":`Subscription 需要 Claude 账户,Proxy 无需 Anthropic 账户即可使用`,"claude.authModeSubscription":`Subscription(Claude 账户)`,"claude.authModeProxy":`Proxy(无需账户)`,"claude.systemEnv":`自动连接`,"claude.systemEnvDesc":`开启后,在任意终端运行 claude 会自动通过代理。`,"claude.systemEnvWarn":`⚠ 需要完全退出并重新打开终端应用才能生效。不推荐使用。`,"claude.fastMode":`Fast Mode (OpenAI)`,"claude.fastModeDesc":`控制 OpenAI 模型的推理速度。ON = 优先级(更快)。OFF = 默认速度。Auto = 透传客户端设置。`,"claude.fastAuto":`Auto`,"claude.fastOn":`ON`,"claude.fastOff":`OFF`,"claude.autoContext":`自动利用大上下文`,"claude.autoContextDesc":`决定 1M 标记的范围。开:所有超过 20 万 token 的模型(GPT 系列等)都有大上下文条目;关:仅真正的 1M 模型有。`,"claude.autoContextInert":`配置文件中存在旧式上下文大小值(maxContextTokens),此功能暂不生效。删除该值即可恢复。`,"claude.autoCompactWindow":`自动摘要触发点`,"claude.autoCompactDefault":`350k(默认)`,"claude.autoCompactWindowDesc":`对话达到该点时自动摘要旧内容。不会超过各模型自身上限,因此 200k 模型不受影响。`,"claude.autoCompactWindowWarn":`修改该值可能导致 GPT 模型异常——若超过模型真实上限,会在摘要触发前报错。`,"claude.injectAgents":`自动注册子代理`,"claude.injectAgentsDesc":`将“子代理”页选中的模型(以及当前默认模型)注册为 Claude Code 可派遣的代理(ocx-*)。从下一个会话开始生效。`,"claude.webSearchSidecar":`网页搜索附属服务覆盖`,"claude.webSearchSidecarHint":`仅对 Claude Code 请求覆盖主网页搜索附属服务设置。`,"claude.visionSidecar":`视觉附属服务覆盖`,"claude.visionSidecarHint":`仅对 Claude Code 请求覆盖主视觉附属服务设置。`,"claude.useMainSetting":`使用主设置`,"claude.sidecarModelPlaceholder":`主设置中的模型`,"claude.quickstart":`开始使用`,"claude.quickstartHint":`{cmd} 通过代理打开 Claude Code。你的 claude.ai 登录保持不变。`,"claude.manualEnv":`手动配置(高级)`,"claude.smallFastModel":`后台辅助模型`,"claude.smallFastModelHint":`Claude Code 用于对话摘要、主题识别等后台工作的模型。子代理的 haiku 别名也使用它。留空 = Claude 默认(Haiku)。`,"claude.slotUnset":`使用 Claude 默认值`,"claude.modelMap":`模型拦截`,"claude.modelMapHint":`拦截对特定模型的请求并重定向到你指定的模型。默认为空——添加规则后才生效。`,"claude.mapFrom":`原始模型(如 claude-sonnet-4-5)`,"claude.mapTo":`替换为(如 gemini/gemini-3-pro)`,"claude.addMapping":`添加规则`,"claude.removeMapping":`删除规则`,"claude.aliases":`可用模型`,"claude.aliasesHint":`Claude Code 的 /model 菜单中显示的模型列表。`,"claude.loading":`加载中…`,"claude.loadFail":`加载 Claude 设置失败`,"claude.saved":`已保存。`,"claude.saveFailed":`保存失败`,"claude.networkError":`网络错误 — 代理是否在运行?`,"claude.toggleAria":`切换 Claude 连接`,"claude.none":`无`,"common.close":`关闭`,"common.ok":`确定`,"app.logoAria":`opencodex 徽标`,"app.claudeOn":`Claude 开`,"app.claudeOff":`Claude 关`,"usage.dayMon":`一`,"usage.dayWed":`三`,"usage.dayFri":`五`,"usage.heatmap.tooltipTokens":`{tokens} 令牌`,"usage.heatmap.tooltipRequests":`{requests} 请求`,"modal.back":`返回`,"modal.badge.oauth":`OAuth`,"modal.customProvider":`自定义提供方`,"modal.failedStatus":`失败 ({status})`,"modal.loginError":`登录错误:{error}`,"modal.badge.codexLogin":`Codex 登录`,"modal.badge.local":`本地`,"modal.badge.apiKey":`API 密钥`,"modal.badge.direct":`Direct`,"modal.badge.pool":`账户池`,"modal.badge.free":`免费`,"modal.invalidPreset":`此内置提供方预设不完整。请重启代理后重试。`,"modal.freeTierTitle":`免费层级`,"modal.freeTierDefault":`无需 API 密钥,开箱即用。`,"modal.tab.accounts":`账户`,"modal.tab.free":`免费`,"modal.tab.paid":`付费`,"modal.accountsHint":`Codex 账户提供商会转发你的 ChatGPT 登录。账户管理请前往`,"modal.accountsCodexAuthLink":`Codex 认证`,"modal.browseAll":`浏览全部 {count} 个提供商`,"modal.browseBack":`返回热门提供商`,"modal.notListed":`没有你要的提供商?添加自定义`,"modal.catalogLoading":`正在加载目录…`,"modal.accountLogin":`登录`,"modal.accountLogout":`退出登录`,"modal.accountLoggedIn":`已登录`,"modal.accountLoggedOut":`未登录`,"quota.fiveHourLimit":`5 小时限额`,"quota.weeklyLimit":`每周限额`,"quota.monthlyLimit":`30 天限额`,"quota.cursorFirstParty":`官方模型`,"quota.cursorApiUsage":`API 用量`,"quota.totalSubscriptionCredits":`订阅总额度`,"quota.usedPercent":`已用 {pct}%`,"quota.limitReached":`已达上限`,"quota.resetsToday":`今天 {time} 重置`,"quota.resetsTomorrow":`明天 {time} 重置`,"quota.resetsAt":`{when} 重置`,"quota.resetsRelativeMinutes":`{n} 分钟后重置`,"quota.resetsRelativeHours":`{n} 小时后重置`,"pws.status.ready":`就绪`,"pws.status.needsSetup":`需要设置`,"pws.auth.chatgptPassthrough":`ChatGPT 直通`,"pws.auth.noKey":`无需密钥`,"pws.freeTitle":`免费定价(可能仍需密钥)`,"pws.localTitle":`本地运行时`,"pws.modelCountOne":`1 个模型`,"pws.modelCount":`{count} 个模型`,"pws.rail.suffixDefault":` · 默认`,"pws.rail.suffixLocal":` · 本地`,"pws.rail.suffixFree":` · 免费`,"pws.rail.selectAria":`选择 {name} — {status}{suffix}`,"pws.searchPlaceholder":`搜索提供商…`,"pws.filterAria":`筛选提供商`,"pws.providerFiltersAria":`提供商筛选`,"pws.filters":`筛选`,"pws.filterStatus":`状态`,"pws.pricing":`定价`,"pws.paid":`付费`,"pws.filterType":`类型`,"pws.type.cloud":`云端`,"pws.type.local":`本地`,"pws.type.selfHosted":`自托管`,"pws.type.login":`登录`,"pws.sort":`排序`,"pws.sortProvidersAria":`排序提供商`,"pws.sort.az":`A–Z`,"pws.sort.za":`Z–A`,"pws.sort.freePaid":`免费优先`,"pws.sort.paidFree":`付费优先`,"pws.sort.accountsFirst":`账户优先`,"pws.resetAll":`全部重置`,"pws.providerList":`提供商列表`,"pws.providersAria":`提供商`,"pws.groupReady":`就绪 ({count})`,"pws.groupNeedsSetup":`需要设置 ({count})`,"pws.groupDisabled":`已禁用 ({count})`,"pws.noSearchResults":`没有匹配搜索的提供商。`,"pws.noMatchFilters":`没有匹配筛选的提供商。`,"pws.noProvidersConfigured":`尚未配置提供商。`,"pws.workspaceMainAria":`提供商详情`,"pws.detailComingSoon":`详情视图即将推出 — 请在经典视图中管理。`,"pws.selectPrompt":`从列表中选择一个提供商。`,"pws.connectFirst":`连接你的第一个提供商`,"pws.empty.browseFree":`浏览免费提供商`,"pws.empty.browseFreeDesc":`无需订阅即可开始`,"pws.empty.connectAccount":`连接账户`,"pws.empty.connectAccountDesc":`使用 ChatGPT 或提供商登录`,"pws.empty.addEndpoint":`添加端点`,"pws.empty.addEndpointDesc":`自定义 base URL 和 API 密钥`,"pws.workspaceToggle":`工作区视图`,"pws.classicToggle":`经典视图`,"pws.tab.overview":`概览`,"pws.tab.models":`模型`,"pws.tab.usage":`用量`,"pws.tab.accounts":`账户`,"pws.tab.settings":`设置`,"pws.connection":`连接`,"pws.status.connected":`已连接`,"pws.cell.auth":`认证`,"pws.cell.note":`备注`,"pws.cell.defaultModel":`默认模型`,"pws.statsAria":`提供商统计`,"pws.statsTitle":`统计`,"pws.stats.totalRequests":`请求数(30 天)`,"pws.stats.totalTokens":`令牌(30 天)`,"pws.stats.quotaUpdated":`配额更新`,"pws.stats.quotaTracked":`在用量标签查看限额。`,"pws.stats.source":`来源`,"pws.usageLast30d":`用量(最近 30 天)`,"pws.metricRequests":`请求`,"pws.metricTokens":`令牌`,"pws.usageUnavailable":`尚无用量记录。`,"pws.rateLimits":`速率限制`,"pws.quotaUnavailable":`此提供商暂无配额数据。`,"pws.selected":`已选择`,"pws.copyModelId":`复制 ID`,"pws.modelCopied":`已复制!`,"pws.modelsAvailable":`{count} 个可用`,"pws.modelSearchPlaceholder":`筛选模型…`,"pws.modelsLoading":`正在加载模型…`,"pws.modelsLoadFailed":`无法加载模型。`,"pws.retry":`重试`,"pws.noModels":`未发现此提供商的模型。`,"pws.noModelMatch":`没有匹配筛选的模型。`,"pws.adapterBaseRequired":`适配器和基本 URL 为必填项。`,"pws.addAccount":`添加账户`,"pws.addKey":`添加 API 密钥`,"pws.apiKeys":`API 密钥`,"pws.authMode":`认证方式`,"pws.availableAccounts":`可用账户`,"pws.accountOrdinal":`账户 {count}`,"pws.accountsLoading":`正在加载账户…`,"pws.accountsLoadFailed":`无法加载账户。`,"pws.retryAccounts":`重试`,"pws.noAccounts":`尚未连接任何账户。`,"pws.accountSwitching":`切换中…`,"pws.accountCurrent":`当前账户`,"pws.defaultModelNone":`无(使用提供商默认值)`,"pws.discardSettings":`放弃`,"pws.jsonEditorDesc":`直接编辑提供商 JSON 配置。更改将立即保存。`,"pws.jsonEditorTitle":`JSON 编辑器 — {name}`,"pws.jsonRestore":`恢复`,"pws.jsonSave":`保存`,"pws.loggedInTitle":`已登录`,"pws.notLoggedInTitle":`未登录`,"pws.note":`备注`,"pws.optionalPlaceholder":`可选`,"pws.providerId":`提供商 ID`,"pws.reauth":`需要重新认证`,"pws.removeConfirm":`移除`,"pws.removeConfirmBody":`移除提供商「{name}」?此操作无法撤消。`,"pws.removeConfirmTitle":`移除提供商`,"pws.saveSettings":`保存`,"pws.saving":`保存中…`,"pws.settingsSaved":`设置已保存。`,"pws.settingsUnsavedBar":`有未保存的更改。`,"pws.unsavedLeaveBody":`有未保存的更改。离开前保存吗?`,"pws.unsavedLeaveTitle":`未保存的更改`,"pws.updatesUnavailable":`提供商更新不可用。`,"pws.dashboard.title":`提供商概览`,"pws.dashboard.subtitle":`在一个地方管理所有模型提供商。`,"pws.dashboard.rateLimits":`速率限制`,"pws.dashboard.recentlyUsed":`最近使用`,"pws.dashboard.requests":`{count} 个请求`,"pws.dashboard.checkedAgo":`{time} 前检查`,"pws.dashboard.noQuota":`无配额数据`,"pws.dashboard.noUsage":`暂无使用数据`,"pws.allProviders":`提供商概览`,"pws.enabledLabel":`已启用`,"pws.testConnection":`测试连接`,"pws.testing":`测试中…`,"pws.connectionOk":`连接成功`,"pws.connectionFailed":`连接失败`,"pws.editSettings":`编辑设置`,"pws.viewUsage":`查看详细用量`,"pws.allSystemsOk":`所有系统正常运行`,"pws.apiKeyConfigured":`API 密钥已配置`,"pws.addApiKey":`添加 API 密钥`,"pws.loggedInAs":`已登录为 {email}`,"pws.notLoggedIn":`未登录`,"pws.passthrough":`Codex 透传`,"pws.notes":`备注`,"pws.notePlaceholder":`添加关于此提供商的备注...`,"pws.noteSaved":`备注已保存`,"pws.authSummary":`认证`,"time.justNow":`刚刚`,"time.notChecked":`未检查`,"time.minutesAgo":`{n} 分钟前`,"time.hoursAgo":`{n} 小时前`,"time.daysAgo":`{n} 天前`,"modal.noMatch":`无匹配。`,"modal.oauthDefaultNote":`使用账户登录 — 无需 API 密钥。`,"modal.oauthComingSoon":`{label} 的 OAuth 登录将在下次更新提供。请先使用 API 密钥。`,"modal.oauthComingSoonShort":`此提供方的 OAuth 登录将在下次更新提供 — 请先使用 API 密钥。`,"modal.useApiKeyInstead":`改用 API 密钥`,"modal.setupGuide":`设置指南`,"modal.setupStep1Prefix":`前往`,"modal.setupDashboardLink":`{label} 控制台`,"modal.setupStep1Suffix":`并复制 API 密钥`,"modal.setupStep2":`粘贴到下方的 API 密钥字段`,"modal.setupStep3":`点击添加提供方 — 模型会自动发现`,"modal.namePlaceholder":`例如 openrouter`,"modal.duplicateWarn":`提供方 "{name}" 已存在,将被覆盖。`,"modal.forwardHintPrefix":`无需密钥 — 代理会转发你的`,"modal.forwardCredentials":`codex login`,"modal.forwardHintSuffix":`凭据到此提供方。`,"modal.localHint":`不会存储 API 密钥。这会为 Codex 添加 Cursor 的公开模型目录,但在审计完成前,实时 Cursor 传输与原生文件/Shell 执行仍保持禁用。`,"modal.getApiKey":`获取 {label} API 密钥`,"modal.apiKey":`API 密钥`,"modal.apiKeyPlaceholder":`sk-…(或 $ENV_VAR)`,"modal.defaultModelPlaceholder":`例如 gpt-5.5`,"modal.baseUrlPlaceholder":`https://...`,"modal.adding":`正在添加…`,"modal.useOauthLogin":`← 使用 OAuth 登录`,"codexAuth.addIdPlaceholder":`codex-work, codex-alt, team…`,"codexAuth.resetCreditsAria":`{count} 个重置额度`,"claude.pageTitle":`Claude Code`,"cws.loading":`正在加载组合…`,"cws.loadFailed":`无法加载组合。`,"cws.saveFailed":`无法保存组合。`,"cws.removeFailed":`无法删除组合。`,"cws.saved":`组合已保存。`,"cws.created":`已创建 {model}。`,"cws.removed":`已删除 combo/{id}。`,"cws.add":`添加组合`,"cws.addTitle":`添加组合`,"cws.addSubtitle":`创建可跨多个提供方分发的虚拟模型。客户端请求 combo/<id>。`,"cws.create":`创建组合`,"cws.railAria":`组合列表`,"cws.searchPlaceholder":`搜索组合或目标…`,"cws.noSearchResults":`没有匹配的组合。`,"cws.group.failover":`故障转移`,"cws.group.roundRobin":`轮询`,"cws.targetCount":`{count} 个目标`,"cws.targetCountOne":`1 个目标`,"cws.overviewTitle":`组合`,"cws.overviewBlurb":`可在提供方/模型目标间故障转移,或采用确定性平滑加权轮询的虚拟模型。`,"cws.count.total":`总计`,"cws.count.failover":`故障转移`,"cws.count.roundRobin":`轮询`,"cws.howTitle":`工作原理`,"cws.howBody":`在 Codex 中请求 combo/<id>。OpenCodex 仅在可重试的上游错误时切换目标。若没有可用目标,请求会直接失败,不会回退到全局默认提供方。`,"cws.attentionTitle":`需要关注`,"cws.attention.empty":`未配置目标`,"cws.attention.few":`只有一个目标 — 故障转移无处可跳`,"cws.emptyTitle":`创建第一个组合`,"cws.empty.createDesc":`命名虚拟模型并串联两个或多个后端。`,"cws.backToAll":`返回全部组合`,"cws.allCombos":`全部组合`,"cws.copyModel":`复制 ID`,"cws.copied":`已复制`,"cws.tab.config":`配置`,"cws.tab.about":`关于`,"cws.strategy":`策略`,"cws.strategy.failover":`故障转移`,"cws.strategy.roundRobin":`轮询`,"cws.strategy.failoverHint":`按顺序尝试目标。若出现可重试错误(限流、故障、订阅门控),则跳到下一个。`,"cws.strategy.roundRobinHint":`按权重确定性地分配流量。将所选目标保留一批成功请求后,再推进到下一个目标。`,"cws.field.id":`组合 ID`,"cws.field.idPlaceholder":`free`,"cws.field.idHint":`客户端将请求 {model}`,"cws.field.stickyLimit":`轮换前的粘性成功次数`,"cws.field.stickyLimitHint":`加权选择器推进前,将所选目标保留这么多次成功请求。`,"cws.field.defaultEffort":`默认推理级别`,"cws.field.defaultEffortHint":`仅在客户端未指定推理级别时使用。客户端值优先,每个目标会按自身能力进行处理。`,"cws.targets":`目标`,"cws.targets.failoverHint":`顺序很重要 — 第一个为主。`,"cws.targets.roundRobinHint":`权重控制确定性的相对选择;顺序用于打破轮换环中的平局。`,"cws.target.provider":`提供方`,"cws.target.model":`模型`,"cws.target.weight":`权重`,"cws.target.pickProvider":`选择提供方…`,"cws.target.pickProviderFirst":`请先选择提供方…`,"cws.target.pickModel":`选择模型…`,"cws.target.noModels":`该提供方没有模型`,"cws.target.modelPlaceholder":`模型 ID`,"cws.target.add":`添加目标`,"cws.target.drag":`拖动以重新排序`,"cws.target.moveUp":`上移`,"cws.target.moveDown":`下移`,"cws.aboutTitle":`运行时`,"cws.aboutBody":`失败目标会短暂冷却并遵循 Retry-After。无效请求与上下文错误不会切换。每个目标按自身能力调整推理级别;所有目标耗尽时直接失败。日志与用量会保留有序的实际尝试及每次尝试的用量。`,"cws.removeConfirmTitle":`删除 {model}?`,"cws.removeConfirmDesc":`从配置与 Codex 目录移除该虚拟模型,不会删除任何提供方。`,"cws.unsavedTitle":`未保存的更改`,"cws.unsavedDesc":`丢弃对此组合的编辑并继续?`,"cws.keepEditing":`继续编辑`,"cws.err.missingId":`需要组合 ID。`,"cws.err.invalidId":`ID 须以字母或数字开头,仅含字母、数字、点、下划线或连字符(最多 64)。`,"cws.err.duplicateId":`已存在相同 ID 的组合。`,"cws.err.noTargets":`至少添加一个目标。`,"cws.err.incompleteTarget":`每个目标都需要提供方和模型。`,"cws.target.disabled":`{name}(已禁用)`,"cws.err.reservedNamespace":`创建组合前,请先重命名名为 combo 的实体提供方。`,"cws.err.providerCollision":`组合 ID 与已配置的提供方名称冲突。`,"cws.err.unknownProvider":`每个目标都必须使用已配置的提供方。`,"cws.err.duplicateTarget":`同一提供方/模型目标只能出现一次。`,"cws.err.invalidStickyLimit":`粘性成功次数必须是 1 到 100 的整数。`,"cws.err.invalidWeight":`每个轮询权重必须是 1 到 10000 的整数。`,"cws.err.noEnabledTarget":`至少一个目标必须使用已启用的提供方。`}},ye=[{code:`en`,name:`English`,htmlLang:`en`},{code:`de`,name:`Deutsch`,htmlLang:`de`},{code:`ko`,name:`한국어`,htmlLang:`ko`},{code:`zh`,name:`中文`,htmlLang:`zh-CN`}],be=`ocx-lang`;function xe(){try{let e=localStorage.getItem(be);if(e===`en`||e===`de`||e===`ko`||e===`zh`)return e}catch{}let e=typeof navigator<`u`?navigator.language.toLowerCase():`en`;return e.startsWith(`de`)?`de`:e.startsWith(`ko`)?`ko`:e.startsWith(`zh`)?`zh`:`en`}var Se=(0,_.createContext)(null);function Ce(e,t){if(!t)return e;let n=e;for(let e of Object.keys(t))n=n.split(`{${e}}`).join(String(t[e]));return n}function H(){let e=(0,_.useContext)(Se);if(!e)throw Error(`useI18n must be used within LanguageProvider`);return e}function U(){return H().t}function we({children:e}){let[t,n]=(0,_.useState)(xe);return(0,_.useEffect)(()=>{let e=ye.find(e=>e.code===t)??ye[0];document.documentElement.lang=e.htmlLang;try{localStorage.setItem(`ocx-lang`,t)}catch{}},[t]),(0,S.jsx)(Se.Provider,{value:{locale:t,setLocale:n,t:(e,n)=>Ce(ve[t][e]??_e[e]??e,n)},children:e})}function Te({k:e,cmd:t,vars:n}){let{t:r}=H(),[i,a=``]=r(e,n).split(`{cmd}`);return(0,S.jsxs)(S.Fragment,{children:[i,(0,S.jsx)(`code`,{className:`chip`,children:t}),a]})}var Ee={ko:[{v:0x2386f26fc10000,s:`경`},{v:0xe8d4a51000,s:`조`},{v:1e8,s:`억`},{v:1e4,s:`만`}],zh:[{v:0x2386f26fc10000,s:`京`},{v:0xe8d4a51000,s:`兆`},{v:1e8,s:`亿`},{v:1e4,s:`万`}]};function De(e){return e.replace(/\.0+$/,``).replace(/(\.\d*?)0+$/,`$1`)}function Oe(e,t){let n=Ee[t];if(n){for(let t of n)if(e>=t.v)return`${De((e/t.v).toFixed(1))}${t.s}`;return String(e)}return e<1e4?String(e):e<1e6?`${De((e/1e3).toFixed(1))}K`:e<1e9?`${De((e/1e6).toFixed(1))}M`:e<0xe8d4a51000?`${De((e/1e9).toFixed(1))}B`:`${De((e/0xe8d4a51000).toFixed(1))}T`}function ke({on:e,onClick:t,disabled:n,label:r}){return(0,S.jsx)(`button`,{type:`button`,className:`switch${e?` on`:``}`,onClick:t,disabled:n,"aria-pressed":e,"aria-label":r??(e?`enabled`:`disabled`),children:(0,S.jsx)(`span`,{className:`knob`})})}function W({tone:e,children:t}){return(0,S.jsxs)(`div`,{className:`notice ${e===`ok`?`notice-ok`:`notice-err`}`,role:`status`,children:[e===`ok`?(0,S.jsx)(M,{}):(0,S.jsx)(I,{}),(0,S.jsx)(`span`,{children:t})]})}function G({value:e,options:t,onChange:n,disabled:r,label:i,style:a,align:o,placement:s,dropdownStyle:c}){let[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=t.find(t=>t.value===e);return(0,_.useEffect)(()=>{if(!l)return;let e=e=>{d.current&&!d.current.contains(e.target)&&u(!1)},t=e=>{e.key===`Escape`&&u(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[l]),(0,S.jsxs)(`div`,{ref:d,className:`custom-select`,style:{position:`relative`,display:`inline-block`,...a},children:[(0,S.jsxs)(`button`,{type:`button`,className:`select-trigger`,onClick:()=>!r&&u(e=>!e),disabled:r,"aria-haspopup":`listbox`,"aria-expanded":l,"aria-label":i,children:[(0,S.jsx)(`span`,{children:f?.label??e}),(0,S.jsx)(z,{style:{width:12,height:12,color:`var(--muted)`,transform:l?`rotate(90deg)`:`none`,transition:`transform .12s`}})]}),l&&(0,S.jsx)(`div`,{className:`select-dropdown${o===`right`?` select-dropdown-right`:``}${s===`right`?` select-dropdown-beside`:``}`,role:`listbox`,"aria-label":i,style:c,children:t.map(t=>(0,S.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":t.value===e,className:`select-option${t.value===e?` active`:``}`,onClick:()=>{n(t.value),u(!1)},children:t.label},t.value))})]})}function Ae({icon:e,title:t,children:n,className:r,style:i}){return(0,S.jsxs)(`div`,{className:r?`empty ${r}`:`empty`,style:i,children:[e,(0,S.jsx)(`div`,{className:`title`,children:t}),n&&(0,S.jsx)(`div`,{className:`text-control`,children:n})]})}var je=[`low`,`medium`,`high`,`xhigh`],Me=2,Ne=800;function Pe(e){return e?.includes(`-preview.`)?`preview`:`latest`}function Fe(e,t){switch(e){case`source_checkout`:return t(`dash.updateReason.source_checkout`);case`latest_unavailable`:return t(`dash.updateReason.latest_unavailable`);case`already_latest`:return t(`dash.updateReason.already_latest`);default:return t(`dash.updateReason.unknown`)}}function Ie(e,t){switch(e){case`running`:return t(`dash.updateStatus.running`);case`restarting`:return t(`dash.updateStatus.restarting`);case`succeeded`:return t(`dash.updateStatus.succeeded`);case`failed`:return t(`dash.updateStatus.failed`)}}function Le(e,t){let n={...e};return t?.model!==void 0&&(n.model=t.model),t?.backend===null?delete n.backend:t?.backend!==void 0&&(n.backend=t.backend),n}function Re(e){return e.filter(e=>e.provider===`openai`||e.provider===`anthropic`).map(e=>({value:e.id,label:`${e.provider}/${e.id}`}))}function ze(e,t){return e.find(e=>e.id===t)?.provider===`anthropic`?`anthropic`:`openai`}function Be(e,t){let n=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let r=n.current;if(r){if(e){r.open||r.showModal();return}r.open&&r.close(),t.current?.focus()}},[e,t]),(0,_.useEffect)(()=>()=>{let e=n.current;e?.open&&e.close(),t.current?.focus()},[t]),n}function Ve({apiBase:e}){let{locale:t,t:n}=H(),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(!1),[x,C]=(0,_.useState)(!1),[w,T]=(0,_.useState)(!1),[E,D]=(0,_.useState)(!1),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(`default`),[M,P]=(0,_.useState)(!1),[F,te]=(0,_.useState)(!1),[ne,R]=(0,_.useState)(!1),[z,B]=(0,_.useState)(``),[re,ae]=(0,_.useState)(``),[oe,se]=(0,_.useState)([]),[ce,le]=(0,_.useState)([]),[V,ue]=(0,_.useState)(!1),[de,fe]=(0,_.useState)(``),[pe,me]=(0,_.useState)(``),[he,ge]=(0,_.useState)(!1),[_e,ve]=(0,_.useState)(null),[ye,be]=(0,_.useState)(null),[xe,Se]=(0,_.useState)([]),[Ce,U]=(0,_.useState)(!1),[we,Ee]=(0,_.useState)(`latest`),[De,ke]=(0,_.useState)(!0),[W,Ve]=(0,_.useState)(!1),He=(0,_.useRef)(0),Ue=(0,_.useRef)(null),We=(0,_.useRef)(0),[Ge,Ke]=(0,_.useState)(null),[qe,Je]=(0,_.useState)(null),[Ye,Xe]=(0,_.useState)(null),[Ze,Qe]=(0,_.useState)(!1),[$e,et]=(0,_.useState)(!1),tt=(0,_.useRef)(null),nt=(0,_.useRef)(null),rt=(0,_.useRef)(null),it=Be(ne,tt),at=Be(Ce,nt),ot=Be(F,rt);(0,_.useEffect)(()=>()=>{We.current+=1,Ue.current!==null&&(window.clearTimeout(Ue.current),Ue.current=null)},[]),(0,_.useEffect)(()=>{let t=async()=>{try{let[t,n,r,a,s,c]=await Promise.all([fetch(`${e}/healthz`),fetch(`${e}/api/providers`),fetch(`${e}/api/settings`),fetch(`${e}/api/sidecar-settings`),fetch(`${e}/api/shadow-call-settings`),fetch(`${e}/api/usage?range=30d`)]);i(await t.json()),o(await n.json()),u(await r.json()),f(await a.json());try{s.ok&&m(await s.json())}catch{m(null)}try{g(c.ok?await c.json():null)}catch{g(null)}et(!1);try{let t=await fetch(`${e}/api/v2`);if(t.ok){let e=await t.json();e.multiAgentMode===`v1`||e.multiAgentMode===`v2`?j(e.multiAgentMode):j(`default`)}}catch{}try{let t=await fetch(`${e}/api/injection-model`);if(t.ok){let e=await t.json();B(e.model??``),ae(e.effort??``),se(e.efforts??[]),le(e.available??[])}}catch{}try{let t=await fetch(`${e}/api/effort-caps`);if(t.ok){let e=await t.json();fe(e.effortCap??``),me(e.subagentEffortCap??``)}}catch{}}catch{et(!0)}};t();let n=setInterval(t,5e3);return()=>clearInterval(n)},[e]),(0,_.useEffect)(()=>{let t=async()=>{try{let t=await fetch(`${e}/api/diagnostics/project-config`);Se((t.ok?await t.json():null)?.grouped??[])}catch{Se([])}};t();let n=setInterval(()=>void t(),3e4);return()=>clearInterval(n)},[e]);let st=(0,_.useCallback)(async()=>{T(!0);try{c(await(await fetch(`${e}/api/models`)).json())}catch{}finally{T(!1)}},[e]);(0,_.useEffect)(()=>{if($e)return;let e=window.setTimeout(()=>{st()},0);return()=>window.clearTimeout(e)},[$e,st]),(0,_.useEffect)(()=>{if(!Ye?.id||!Ye.restart)return;let t=!1,n=Ye.latestVersion,r=async()=>{try{let n=await fetch(`${e}/api/update/status?jobId=${encodeURIComponent(Ye.id)}`);if(n.ok){let e=await n.json();if(!t&&e.job&&(Xe(e.job),e.job.status===`failed`)){Qe(!1);return}}}catch{t||Qe(!0)}if(n)try{let r=await fetch(`${e}/healthz`,{cache:`no-store`});if(!r.ok)throw Error(`health failed`);let i=await r.json();!t&&i.version===n&&(Qe(!1),window.location.reload())}catch{t||Qe(!0)}};r();let i=setInterval(r,1500);return()=>{t=!0,clearInterval(i)}},[e,Ye?.id,Ye?.latestVersion,Ye?.restart]);let ct=(0,_.useMemo)(()=>{let e={};for(let t of s)(e[t.provider]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>e.localeCompare(t))},[s]),lt=(0,_.useMemo)(()=>Re(s),[s]);if($e)return(0,S.jsx)(Ae,{style:{marginTop:40},icon:(0,S.jsx)(I,{}),title:(0,S.jsx)(`span`,{style:{color:`var(--red)`},children:n(`dash.cannotConnect`)}),children:(0,S.jsx)(Te,{k:`dash.runStart`,cmd:`ocx start`})});let ut=r?.status===`ok`,dt=async t=>{if(!d||v)return;let n={webSearch:Le(d.webSearch,t.webSearch),vision:Le(d.vision,t.vision)};y(!0),f(n);try{let n=await fetch(`${e}/api/sidecar-settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok)throw Error(`save failed`);let r=await n.json();f({webSearch:r.webSearch,vision:r.vision})}catch{f(d)}finally{y(!1)}};async function ft(t){if(!(!p||x)){C(!0),m({...p,...t});try{await fetch(`${e}/api/shadow-call-settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})}finally{C(!1)}}}let pt=async t=>{if(!(M||A===t)){P(!0);try{(await fetch(`${e}/api/v2`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({multiAgentMode:t})})).ok&&j(t)}catch{}finally{P(!1)}}},mt=async()=>{if(!l||E)return;let t=!l.codexAutoStart;D(!0),u({...l,codexAutoStart:t});try{let n=await fetch(`${e}/api/settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({codexAutoStart:t})});if(!n.ok)throw Error(`save failed`);let r=await n.json();u(e=>e&&{...e,codexAutoStart:r.codexAutoStart})}catch{u(e=>e&&{...e,codexAutoStart:!t}),et(!0)}finally{D(!1)}},ht=async()=>{if(!O){k(!0),ve(null),be(null);try{let t=await fetch(`${e}/api/sync`,{method:`POST`}),n=await t.json();if(!t.ok)throw Error(`error`in n&&n.error?n.error:`sync failed`);ve(n);let r=n.projectConfigGrouped;r&&Se(r)}catch(e){be(e instanceof Error?e.message:String(e))}finally{k(!1)}}},gt=async(t,n=!1)=>{n&&(He.current=0),Ue.current!==null&&(window.clearTimeout(Ue.current),Ue.current=null);let r=++We.current;Ve(!0),Je(null),Ke(null);try{let n=await fetch(`${e}/api/update/check?tag=${t}`),i=await n.json();if(!n.ok)throw Error(`error`in i&&i.error?i.error:`update check failed`);if(r!==We.current)return;let a=i;if(Ke(a),a.reason===`latest_unavailable`&&He.current<Me){let e=++He.current;Ue.current=window.setTimeout(()=>{r===We.current&&(Ue.current=null,gt(t))},Ne*e);return}a.reason!==`latest_unavailable`&&(He.current=0),Ve(!1)}catch(e){if(r!==We.current)return;Je(e instanceof Error?e.message:String(e)),Ve(!1)}},_t=()=>{We.current+=1,Ue.current!==null&&(window.clearTimeout(Ue.current),Ue.current=null),Ve(!1),U(!1)},vt=()=>{let e=Pe(r?.version);Ee(e),ke(!0),U(!0),gt(e,!0)},yt=e=>{Ee(e),gt(e,!0)},bt=async()=>{if(Ge?.canUpdate){Je(null);try{let t=await fetch(`${e}/api/update/run`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({tag:we,restart:De})}),n=await t.json();if(!t.ok||!n.job)throw Error(n.error??`update failed to start`);Xe(n.job),Qe(!1),_t()}catch(e){Je(e instanceof Error?e.message:String(e))}}};return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h2`,{children:n(`nav.dashboard`)})}),(0,S.jsx)(`p`,{className:`page-sub`,children:n(`dash.subtitle`)}),(0,S.jsxs)(`div`,{className:`stat-row`,children:[(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsxs)(`div`,{className:`label`,style:{display:`flex`,alignItems:`center`,gap:6},children:[n(`dash.multiAgent`),(0,S.jsx)(`button`,{ref:rt,type:`button`,className:`btn btn-ghost btn-sm`,style:{width:24,height:24,minWidth:24,flex:`0 0 24px`,padding:0,borderRadius:`var(--radius-pill)`,color:`var(--muted)`},onClick:()=>te(!0),"aria-label":n(`dash.multiAgent`),"aria-haspopup":`dialog`,"aria-controls":`multi-agent-help-dialog`,"aria-expanded":F,children:(0,S.jsx)(L,{width:14,height:14,"aria-hidden":`true`})})]}),(0,S.jsx)(`div`,{className:`value`,style:{display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,S.jsx)(`div`,{role:`radiogroup`,"aria-label":n(`dash.multiAgent`),style:{display:`inline-flex`,borderRadius:`var(--radius-pill)`,background:`var(--surface-soft, var(--raised))`,padding:3,gap:2},children:[`v1`,`default`,`v2`].map(e=>(0,S.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":A===e,className:`btn btn-sm text-caption${A===e?` btn-primary`:` btn-ghost`}`,style:{borderRadius:`var(--radius-pill)`,minWidth:36,padding:`5px 10px`,border:`none`,background:A===e?void 0:`transparent`,color:A===e?void 0:`var(--muted)`},disabled:M,onClick:()=>void pt(e),children:e==="default"?`base`:e},e))})})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`label`,children:n(`dash.status`)}),(0,S.jsxs)(`div`,{className:`value`,style:{display:`flex`,alignItems:`center`,gap:9,color:ut?`var(--green)`:`var(--red)`},children:[(0,S.jsx)(`span`,{className:`dot ${ut?`dot-green`:`dot-red`}`}),n(ut?`dash.online`:`dash.offline`)]})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`label`,children:n(`dash.version`)}),(0,S.jsx)(`div`,{className:`value mono`,children:r?.version??`—`})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`label`,children:n(`dash.uptime`)}),(0,S.jsx)(`div`,{className:`value mono`,children:r?b(r.uptime,t):`—`})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`label`,children:n(`dash.providers`)}),(0,S.jsx)(`div`,{className:`value`,children:a.length})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`label`,children:n(`dash.tokens30d`)}),(0,S.jsx)(`div`,{className:`value mono`,children:h&&h.summary.requests>0?Oe(h.summary.totalTokens,t):`—`}),h&&h.summary.requests>0&&(0,S.jsx)(`div`,{className:`muted text-label`,style:{marginTop:2},children:n(`dash.coverage`).replace(`{pct}`,`${Math.round(h.summary.coverageRatio*100)}%`)})]})]}),xe.length>0&&(0,S.jsxs)(`div`,{className:`notice notice-err maintenance-notice`,style:{marginBottom:24},role:`alert`,children:[(0,S.jsx)(I,{}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.projectConfigTitle`)}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{marginTop:4},children:n(`dash.projectConfigHint`)}),(0,S.jsx)(`ul`,{className:`text-control`,style:{margin:`10px 0 0`,paddingLeft:18},children:xe.map(e=>(0,S.jsxs)(`li`,{style:{marginBottom:8},children:[(0,S.jsx)(`code`,{children:e.path}),` — `,e.issues.join(`, `),(0,S.jsx)(`div`,{className:`muted`,style:{marginTop:2},children:e.bypass})]},e.path))})]})]}),A!==`v1`&&(0,S.jsx)(`div`,{className:`panel`,style:{marginBottom:24},children:(0,S.jsxs)(`div`,{className:`injection-head`,children:[(0,S.jsxs)(`span`,{className:`injection-label`,style:{display:`inline-flex`,alignItems:`center`,gap:6},children:[n(`dash.effortCapLabel`),(0,S.jsxs)(`span`,{style:{position:`relative`,display:`inline-flex`},children:[(0,S.jsx)(`button`,{ref:tt,type:`button`,className:`btn btn-ghost btn-sm`,style:{width:22,height:22,minWidth:22,padding:0,borderRadius:`var(--radius-pill)`,color:`var(--muted)`},onClick:()=>R(e=>!e),"aria-label":n(`dash.effortCapLabel`),"aria-expanded":ne,"aria-haspopup":`dialog`,"aria-controls":`effort-cap-help-dialog`,children:(0,S.jsx)(L,{width:13,height:13,"aria-hidden":`true`})}),(0,S.jsxs)(`dialog`,{ref:it,id:`effort-cap-help-dialog`,className:`help-popup text-control font-regular leading-body`,style:{position:`absolute`,top:`calc(100% + 8px)`,left:0,width:`min(360px, calc(100vw - 48px))`,margin:0,padding:`12px 16px`,border:`1px solid var(--border)`,borderRadius:`var(--radius-sm)`,background:`var(--bg)`,boxShadow:`0 8px 24px rgba(0, 0, 0, 0.14)`,color:`var(--text)`,zIndex:10},"aria-labelledby":`effort-cap-help-text`,onCancel:e=>{e.preventDefault(),R(!1)},children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon`,style:{position:`absolute`,top:4,right:4,width:24,height:24,minWidth:24},onClick:()=>R(!1),"aria-label":n(`common.close`),children:(0,S.jsx)(N,{width:14,height:14})}),(0,S.jsx)(`div`,{id:`effort-cap-help-text`,style:{paddingRight:16},children:n(`dash.effortCapHelp`)})]})]})]}),(0,S.jsx)(G,{value:de,options:[{value:``,label:n(`dash.effortCapNone`)},...je.map(e=>({value:e,label:e}))],onChange:async t=>{if(!he){ge(!0);try{let n=await fetch(`${e}/api/effort-caps`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({effortCap:t||null})});if(n.ok){let e=await n.json();fe(e.effortCap??``),me(e.subagentEffortCap??``)}}catch{}finally{ge(!1)}}},disabled:he,label:n(`dash.effortCapLabel`)}),(0,S.jsx)(G,{value:pe,options:[{value:``,label:n(`dash.effortCapNone`)},...je.map(e=>({value:e,label:e}))],onChange:async t=>{if(!he){ge(!0);try{let n=await fetch(`${e}/api/effort-caps`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({subagentEffortCap:t||null})});if(n.ok){let e=await n.json();fe(e.effortCap??``),me(e.subagentEffortCap??``)}}catch{}finally{ge(!1)}}},disabled:he,label:n(`dash.subagentEffortCapLabel`)})]})}),(0,S.jsxs)(`div`,{className:`panel`,style:{marginBottom:24},children:[(0,S.jsxs)(`div`,{className:`injection-head`,children:[(0,S.jsx)(`span`,{className:`injection-label`,children:n(`dash.injectionLabel`)}),(0,S.jsx)(G,{value:z,options:[{value:``,label:n(`dash.injectionNone`)},...ce.map(e=>({value:e.namespaced,label:`${e.provider} / ${e.model}`}))],onChange:async t=>{if(!V){ue(!0);try{let n=await fetch(`${e}/api/injection-model`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({model:t||null,effort:re||null})});if(n.ok){let e=await n.json();B(e.model??``),ae(e.effort??``)}}catch{}finally{ue(!1)}}},disabled:V,label:n(`dash.injectionLabel`)}),z&&oe.length>0&&(0,S.jsx)(G,{value:re,options:[{value:``,label:n(`dash.injectionEffortNone`)},...oe.map(e=>({value:e,label:e}))],onChange:async t=>{if(!V){ue(!0);try{let n=await fetch(`${e}/api/injection-model`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({model:z||null,effort:t||null})});if(n.ok){let e=await n.json();B(e.model??``),ae(e.effort??``)}}catch{}finally{ue(!1)}}},disabled:V,label:n(`dash.injectionEffortLabel`)}),z&&(0,S.jsx)(`span`,{className:`badge badge-green text-micro`,children:n(`dash.injectionActive`)})]}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{marginTop:6},children:n(`dash.injectionHint`)})]}),(0,S.jsxs)(`div`,{className:`panel maintenance-panel`,style:{marginBottom:24},children:[(0,S.jsxs)(`div`,{className:`spread maintenance-head`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.maintenance`)}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{marginTop:3},children:n(`dash.maintenanceHint`)})]}),(0,S.jsxs)(`div`,{className:`maintenance-actions`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:ht,disabled:O,children:[(0,S.jsx)(ee,{}),` `,n(O?`dash.syncing`:`dash.syncModels`)]}),(0,S.jsxs)(`button`,{ref:nt,type:`button`,className:`btn btn-primary`,onClick:vt,disabled:W,"aria-haspopup":`dialog`,"aria-controls":`dashboard-update-dialog`,"aria-expanded":Ce,children:[(0,S.jsx)(ie,{}),` `,n(`dash.checkUpdate`)]})]})]}),_e&&(0,S.jsxs)(`div`,{className:`notice notice-ok maintenance-notice`,role:`status`,children:[(0,S.jsx)(ee,{}),(0,S.jsxs)(`span`,{children:[n(`dash.syncOk`,{count:_e.added}),_e.warning?` ${_e.warning}`:``,_e.staleAppServerHint?` ${n(`dash.syncStaleHint`)}`:``]})]}),ye&&(0,S.jsxs)(`div`,{className:`notice notice-err maintenance-notice`,role:`status`,children:[(0,S.jsx)(I,{}),(0,S.jsx)(`span`,{children:n(`dash.syncFailed`,{error:ye})})]}),Ye&&(0,S.jsxs)(`div`,{className:`notice ${Ye.status===`failed`?`notice-err`:`notice-ok`} maintenance-notice`,role:`status`,children:[Ye.status===`failed`?(0,S.jsx)(I,{}):(0,S.jsx)(ee,{}),(0,S.jsxs)(`span`,{children:[Ie(Ye.status,n),Ye.latestVersion?` ${Ye.currentVersion} -> ${Ye.latestVersion}.`:``,Ze?` ${n(`dash.updateReconnecting`)}`:``,Ye.error?` ${Ye.error}`:``]})]})]}),(0,S.jsx)(`div`,{className:`panel`,style:{marginBottom:24},children:(0,S.jsxs)(`div`,{className:`spread`,children:[(0,S.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.codexAutoStart`)}),(0,S.jsx)(`div`,{className:`muted setting-hint`,children:n(`dash.codexAutoStartHint`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`switch ${l?.codexAutoStart??!0?`on`:``}`,onClick:mt,disabled:!l||E,"aria-label":n(`dash.codexAutoStart`),"aria-pressed":l?.codexAutoStart??!0,children:(0,S.jsx)(`span`,{className:`knob`})})]})}),(0,S.jsx)(`div`,{className:`panel`,style:{marginBottom:12},children:(0,S.jsxs)(`div`,{className:`spread setting-row`,style:{alignItems:`flex-start`},children:[(0,S.jsxs)(`div`,{className:`setting-copy`,style:{flex:1},children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.webSearchSidecar`)}),(0,S.jsx)(`div`,{className:`muted setting-hint`,children:n(`dash.webSearchSidecarHint`)})]}),(0,S.jsx)(`div`,{className:`setting-controls`,children:(0,S.jsx)(G,{value:d?.webSearch.model??`gpt-5.6-luna`,options:lt,onChange:e=>{dt({webSearch:{model:e,backend:ze(s,e)}})},disabled:!d||v,label:n(`dash.sidecarModel`)})})]})}),(0,S.jsx)(`div`,{className:`panel`,style:{marginBottom:24},children:(0,S.jsxs)(`div`,{className:`spread setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-copy`,style:{flex:1},children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.visionSidecar`)}),(0,S.jsx)(`div`,{className:`muted setting-hint`,children:n(`dash.visionSidecarHint`)})]}),(0,S.jsx)(`div`,{className:`setting-controls`,children:(0,S.jsx)(G,{value:d?.vision.model??`gpt-5.6-luna`,options:lt,onChange:e=>{dt({vision:{model:e,backend:ze(s,e)}})},disabled:!d||v,label:n(`dash.sidecarModel`)})})]})}),(0,S.jsx)(`div`,{className:`panel`,style:{marginBottom:12},children:(0,S.jsxs)(`div`,{className:`spread setting-row`,style:{alignItems:`center`},children:[(0,S.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,S.jsx)(`span`,{className:`font-semibold`,children:n(`dash.shadowCallIntercept`)}),(0,S.jsx)(`span`,{title:n(`dash.shadowCallTooltip`),style:{cursor:`help`,opacity:.5},children:`ⓘ`}),(0,S.jsx)(`code`,{className:`muted text-caption`,children:`⚠ 5.4-mini`})]}),(0,S.jsxs)(`div`,{className:`setting-controls`,style:{display:`flex`,gap:8,alignItems:`center`},children:[(0,S.jsx)(`button`,{type:`button`,className:`switch ${p?.enabled?`on`:``}`,onClick:()=>ft({enabled:!p?.enabled}),disabled:!p||x,"aria-label":n(`dash.shadowCallIntercept`),"aria-pressed":p?.enabled??!1,children:(0,S.jsx)(`span`,{className:`knob`})}),(0,S.jsx)(G,{value:p?.model??``,options:[{value:``,label:`—`},...s.map(e=>({value:e.id,label:`${e.provider}/${e.id}`}))],onChange:e=>{m(t=>t&&{...t,model:e}),ft({model:e})},disabled:!p||x||!p?.enabled,label:n(`dash.shadowCallModel`)})]})]})}),(0,S.jsxs)(`div`,{className:`h-section`,children:[n(`dash.activeProviders`),` `,(0,S.jsx)(`span`,{className:`count`,children:a.length})]}),a.length===0?(0,S.jsx)(Ae,{title:(0,S.jsx)(Te,{k:`dash.noProviders`,cmd:`ocx init`})}):(0,S.jsx)(`div`,{className:`tbl-wrap`,children:(0,S.jsxs)(`table`,{className:`tbl`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:n(`dash.col.name`)}),(0,S.jsx)(`th`,{children:n(`dash.col.adapter`)}),(0,S.jsx)(`th`,{children:n(`dash.col.baseUrl`)}),(0,S.jsx)(`th`,{children:n(`dash.col.model`)})]})}),(0,S.jsx)(`tbody`,{children:a.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{className:`font-semibold`,children:e.name}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`span`,{className:`chip`,children:e.adapter})}),(0,S.jsx)(`td`,{className:`muted mono text-label`,children:e.baseUrl}),(0,S.jsx)(`td`,{className:`muted`,children:e.defaultModel??`—`})]},e.name))})]})}),(0,S.jsxs)(`div`,{className:`h-section`,children:[n(`dash.availableModels`),` `,(0,S.jsx)(`span`,{className:`count`,children:s.length}),w&&(0,S.jsx)(`span`,{className:`spin`,style:{marginLeft:4}})]}),s.length===0&&!w?(0,S.jsx)(Ae,{title:n(`dash.noModels`)}):(0,S.jsx)(`div`,{className:`stack`,style:{gap:16},children:ct.map(([e,t])=>(0,S.jsxs)(`div`,{className:`model-group`,children:[(0,S.jsxs)(`div`,{className:`model-group-head`,children:[e,(0,S.jsx)(`span`,{className:`count`,children:t.length})]}),(0,S.jsx)(`div`,{className:`model-grid`,children:t.map(e=>(0,S.jsx)(`div`,{className:`model-card`,children:(0,S.jsx)(`div`,{className:`id`,children:e.id})},`${e.provider}/${e.id}`))})]},e))}),(0,S.jsx)(`dialog`,{ref:at,id:`dashboard-update-dialog`,className:`modal-overlay`,style:{display:Ce?`flex`:`none`,border:`none`,margin:0,maxWidth:`none`,maxHeight:`none`,width:`100%`,height:`100%`},"aria-labelledby":`update-title`,onCancel:e=>{e.preventDefault(),_t()},children:(0,S.jsxs)(`div`,{className:`modal-card`,children:[(0,S.jsxs)(`div`,{className:`modal-head`,children:[(0,S.jsx)(`h3`,{id:`update-title`,children:n(`dash.updateTitle`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon`,onClick:_t,"aria-label":n(`common.cancel`),children:(0,S.jsx)(N,{})})]}),(0,S.jsx)(`div`,{className:`modal-desc`,children:n(`dash.updateDesc`)}),(0,S.jsxs)(`div`,{className:`update-row`,children:[(0,S.jsx)(`label`,{className:`field-label`,htmlFor:`update-channel`,children:n(`dash.updateChannel`)}),(0,S.jsx)(G,{value:we,options:[{value:`latest`,label:`latest`},{value:`preview`,label:`preview`}],onChange:e=>yt(e),disabled:W,label:n(`dash.updateChannel`)})]}),W&&(0,S.jsx)(Ae,{className:`update-empty`,icon:(0,S.jsx)(`span`,{className:`spin`}),title:n(`dash.updateChecking`)}),qe&&(0,S.jsxs)(`div`,{className:`notice notice-err`,role:`status`,children:[(0,S.jsx)(I,{}),(0,S.jsx)(`span`,{children:qe})]}),Ge&&!W&&(0,S.jsxs)(`div`,{className:`update-box`,children:[(0,S.jsxs)(`div`,{className:`spread`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`muted text-label`,children:n(`dash.updateInstalled`)}),(0,S.jsx)(`div`,{className:`mono`,children:Ge.currentVersion})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`muted text-label`,children:n(`dash.updateLatest`)}),(0,S.jsx)(`div`,{className:`mono`,children:Ge.latestVersion??`—`})]}),(0,S.jsx)(`span`,{className:`badge ${Ge.updateAvailable?`badge-green`:`badge-muted`}`,children:Ge.updateAvailable?n(`dash.updateAvailable`):n(`dash.updateCurrent`)})]}),(0,S.jsxs)(`div`,{className:`muted update-command`,children:[n(`dash.updateCommand`),` `,(0,S.jsx)(`code`,{className:`chip`,children:Ge.command})]}),Ge.reason===`source_checkout`&&(0,S.jsxs)(`div`,{className:`notice-warn`,role:`status`,children:[(0,S.jsx)(I,{}),` `,n(`dash.updateSource`)]}),Ge.reason===`latest_unavailable`&&(0,S.jsxs)(`div`,{className:`notice-warn`,role:`status`,children:[(0,S.jsx)(I,{}),` `,n(`dash.updateUnavailable`),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:W,onClick:()=>{gt(we,!0)},style:{marginLeft:12},children:[(0,S.jsx)(ee,{}),` `,n(`dash.updateRetry`)]})]}),!Ge.canUpdate&&Ge.reason!==`latest_unavailable`&&Ge.reason!==`source_checkout`&&(0,S.jsxs)(`div`,{className:`update-recheck`,children:[(0,S.jsx)(`span`,{className:`muted update-recheck-reason`,children:n(`dash.updateCannotAuto`,{reason:Fe(Ge.reason,n)})}),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:W,onClick:()=>{gt(we,!0)},children:[(0,S.jsx)(ee,{}),` `,n(W?`dash.updateChecking`:`dash.updateRecheck`)]})]}),Ge.canUpdate&&(0,S.jsxs)(`div`,{className:`spread update-restart`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.updateRestart`)}),(0,S.jsx)(`div`,{className:`muted text-label`,children:n(`dash.updateRestartHint`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`switch ${De?`on`:``}`,onClick:()=>ke(e=>!e),"aria-label":n(`dash.updateRestart`),"aria-pressed":De,children:(0,S.jsx)(`span`,{className:`knob`})})]})]}),(0,S.jsxs)(`div`,{className:`modal-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:_t,children:n(`common.cancel`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:bt,disabled:!Ge?.canUpdate||W,children:n(`dash.runUpdate`)})]})]})}),(0,S.jsx)(`dialog`,{ref:ot,id:`multi-agent-help-dialog`,className:`modal-overlay`,style:{display:F?`flex`:`none`,border:`none`,margin:0,maxWidth:`none`,maxHeight:`none`,width:`100%`,height:`100%`},"aria-labelledby":`multi-agent-help-title`,onCancel:e=>{e.preventDefault(),te(!1)},onClick:e=>{e.target===e.currentTarget&&te(!1)},children:(0,S.jsxs)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`modal-head`,children:[(0,S.jsx)(`h3`,{id:`multi-agent-help-title`,children:n(`dash.multiAgent`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon`,onClick:()=>te(!1),"aria-label":n(`common.close`),children:(0,S.jsx)(N,{})})]}),(0,S.jsx)(`div`,{className:`modal-desc leading-relaxed`,style:{whiteSpace:`pre-line`},children:n(`models.v2Help`)}),(0,S.jsx)(`div`,{style:{marginTop:12},children:(0,S.jsx)(`a`,{className:`text-control`,href:`https://lidge-jun.github.io/opencodex/guides/sub-agent-surface/`,target:`_blank`,rel:`noreferrer`,style:{color:`var(--accent)`},children:n(`models.v2DocsLink`)})}),(0,S.jsx)(`div`,{className:`modal-actions`,children:(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>te(!1),children:n(`common.ok`)})})]})})]})}function He(e){return e.id===`openai`}function Ue(e){return e.id===`openai`?e.codexAccountMode===`direct`?`prov.openaiDirectDesc`:`prov.openaiPoolDesc`:null}function We(e){let t={adapter:e.adapter.trim(),baseUrl:e.baseUrl.trim()};return(e.authMode===`key`||e.authMode===`forward`)&&(t.authMode=e.authMode),e.authMode===`key`&&e.apiKey.trim()&&(t.apiKey=e.apiKey.trim()),e.defaultModel.trim()&&(t.defaultModel=e.defaultModel.trim()),t}function Ge(e,t){if(He(e)){if(!e.provider)throw Error(`Missing canonical provider seed for ${e.id}`);return{name:e.id,provider:JSON.parse(JSON.stringify(e.provider))}}return{name:t.name.trim(),provider:We(t)}}var Ke=`https://chatgpt.com/backend-api/codex`,qe=`openai`;function Je(e){try{let t=new URL(e.trim());if(t.username||t.password||t.search||t.hash)return;let n=t.pathname.replace(/\/+$/,``);return`${t.origin}${n}`}catch{return}}function Ye(e){try{let t=new URL(e).hostname.replace(/^\[|\]$/g,``).toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`::1`}catch{return!1}}function Xe(e){return e.keyOptional===!0||e.authMode===`oauth`||e.authMode===`forward`||e.authMode===`local`||Ye(e.baseUrl)||e.hasApiKey===!0}function Ze(e){return e.adapter===`openai-responses`&&e.authMode===`forward`&&Je(e.baseUrl)===Ke}function Qe(e,t){return e===qe&&Ze(t)}function $e(e){return e.freeTier===!0||e.keyOptional===!0||e.authMode===`local`||Ye(e.baseUrl)}function et(e,t){return Qe(e,t)?`accounts`:$e(t)?`free`:`paid`}function tt(e,t){let n=[...e],r=(e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`}),i=e=>e.tier??et(e.name,e);switch(t){case`az`:return n.sort(r);case`za`:return n.sort((e,t)=>r(t,e));case`free-paid`:return n.sort((e,t)=>(i(e)===`free`?0:1)-(i(t)===`free`?0:1)||r(e,t));case`paid-free`:return n.sort((e,t)=>(i(e)===`free`)-+(i(t)===`free`)||r(e,t));case`accounts-first`:return n.sort((e,t)=>{let n=e=>{let t=i(e);return t===`accounts`?0:t===`free`?1:2};return n(e)-n(t)||r(e,t)});default:return n}}function nt(e){let t=[],n=[],r=[];for(let[i,a]of Object.entries(e)){if(a.disabled){r.push({name:i,...a});continue}Xe(a)?t.push({name:i,...a,tier:et(i,a)}):n.push({name:i,...a})}return{ready:t,needsSetup:n,disabled:r}}function rt(e){return e.disabled?`disabled`:Xe(e)?`ready`:`needs-setup`}function it(e){let t=e.openai,n=e.chatgpt;if(!t||!n||!Qe(`openai`,t)||!Ze(n))return e;let r={...e};return delete r.chatgpt,r}function at(e){return{adapter:e.adapter,baseUrl:e.baseUrl,authMode:e.auth,freeTier:!!e.freeTier,keyOptional:!!e.keyOptional}}function ot(e){return et(e.id,at(e))}function st(e){let t={accounts:[],free:[],paid:[]};for(let n of e)t[ot(n)].push(n);return t}function ct(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>e.label.toLowerCase().includes(n)||e.id.toLowerCase().includes(n)):e}var lt=6;function ut({presets:e,usageRank:t={},presetsLoading:n=!1,initialTier:r=`free`,onSelectPreset:i,onSelectCustom:a,accountRows:o=[],accountStatus:s={},busyProvider:c=null,onLogin:l,onCancelLogin:u,onLogout:d}){let f=U(),[p,m]=(0,_.useState)(r),[h,g]=(0,_.useState)(`home`),[v,y]=(0,_.useState)(``),b=(0,_.useRef)(null),x=(0,_.useMemo)(()=>e.filter(e=>e.id!==`custom`),[e]),C=(0,_.useMemo)(()=>[...x].sort((e,n)=>{let r=t[e.id]??0,i=t[n.id]??0;return i===r?e.label.localeCompare(n.label,void 0,{sensitivity:`base`})||e.id.localeCompare(n.id):i-r}),[x,t]),w=(0,_.useMemo)(()=>st(C),[C])[p],T=w.slice(0,lt),E=(0,_.useMemo)(()=>ct(w,v),[w,v]),D=h===`browse`?E:T,O=()=>{g(`browse`),y(``),setTimeout(()=>b.current?.focus(),0)},k=e=>{let t=e.codexAccountMode===`direct`?(0,S.jsx)(`span`,{className:`badge badge-green`,children:f(`modal.badge.direct`)}):e.codexAccountMode===`pool`?(0,S.jsx)(`span`,{className:`badge badge-accent`,children:f(`modal.badge.pool`)}):e.auth===`oauth`?(0,S.jsx)(`span`,{className:`badge badge-accent`,children:f(`modal.badge.oauth`)}):e.auth===`forward`?(0,S.jsx)(`span`,{className:`badge badge-green`,children:f(`modal.badge.codexLogin`)}):e.auth===`local`?(0,S.jsx)(`span`,{className:`badge badge-amber`,children:f(`modal.badge.local`)}):e.keyOptional?null:(0,S.jsx)(`span`,{className:`badge badge-muted`,children:f(`modal.badge.apiKey`)});return(0,S.jsxs)(S.Fragment,{children:[(e.freeTier||e.keyOptional)&&e.auth===`key`?(0,S.jsx)(`span`,{className:`badge badge-green`,children:f(`modal.badge.free`)}):null,t]})};return(0,S.jsxs)(`div`,{className:`provider-catalog`,children:[(0,S.jsx)(`div`,{className:`provider-catalog-tabs`,role:`tablist`,children:[`accounts`,`free`,`paid`].map(e=>(0,S.jsx)(`button`,{role:`tab`,"aria-selected":p===e,className:`provider-catalog-tab${p===e?` active`:``}`,onClick:()=>{m(e),g(`home`),y(``)},children:f(e===`accounts`?`modal.tab.accounts`:e===`free`?`modal.tab.free`:`modal.tab.paid`)},e))}),p===`accounts`&&(0,S.jsxs)(`div`,{className:`provider-catalog-accounts-hint muted text-label`,children:[f(`modal.accountsHint`),` `,(0,S.jsx)(`a`,{href:`#codex-auth`,children:f(`modal.accountsCodexAuthLink`)})]}),h===`browse`&&(0,S.jsx)(`input`,{ref:b,className:`input provider-catalog-search`,value:v,onChange:e=>y(e.target.value),placeholder:f(`modal.search`)}),(0,S.jsxs)(`div`,{className:`provider-catalog-rows`,children:[n&&D.length===0&&(0,S.jsx)(`div`,{className:`muted text-control provider-catalog-empty`,children:f(`modal.catalogLoading`)}),D.map(e=>(0,S.jsxs)(`button`,{className:`list-row`,onClick:()=>i(e),children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`title`,children:e.label}),(0,S.jsxs)(`div`,{className:`sub`,children:[(0,S.jsx)(`code`,{className:`chip`,children:e.adapter}),e.note?` · ${e.note}`:``]})]}),(0,S.jsx)(`div`,{className:`provider-catalog-badges`,children:k(e)})]},e.id)),!n&&D.length===0&&(0,S.jsx)(`div`,{className:`muted text-control provider-catalog-empty`,children:f(`modal.noMatch`)}),p===`accounts`&&o.map(e=>{let t=s[e.id],n=c===e.id;return(0,S.jsxs)(`div`,{className:`list-row provider-catalog-account-row`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`title`,children:e.label}),(0,S.jsx)(`div`,{className:`sub`,children:t?.loggedIn?t.email??e.statusLabel??f(`modal.accountLoggedIn`):t?.error??e.statusLabel??f(`modal.accountLoggedOut`)})]}),(0,S.jsx)(`div`,{className:`provider-catalog-badges`,children:t?.loggedIn?d&&(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>d(e.id),children:f(`modal.accountLogout`)}):n?u&&(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>u(e.id),children:f(`common.cancel`)}):l&&(0,S.jsx)(`button`,{className:`btn btn-primary`,onClick:()=>l(e.id),children:f(`modal.accountLogin`)})})]},e.id)})]}),(0,S.jsxs)(`div`,{className:`provider-catalog-footer`,children:[h===`home`&&w.length>lt&&(0,S.jsx)(`button`,{className:`link-btn`,onClick:O,children:f(`modal.browseAll`,{count:w.length})}),h===`browse`&&(0,S.jsx)(`button`,{className:`link-btn`,onClick:()=>{g(`home`),y(``)},children:f(`modal.browseBack`)}),(0,S.jsx)(`div`,{style:{flex:1}}),p!==`accounts`&&(0,S.jsx)(`button`,{className:`link-btn`,onClick:a,children:f(`modal.notListed`)})]})]})}function dt({apiBase:e,existingNames:t,onClose:n,onAdded:r,initialTier:i,initialCustom:a=!1}){let o=U(),s=(0,_.useMemo)(()=>[{id:`custom`,label:o(`modal.customProvider`),adapter:`openai-chat`,baseUrl:``,auth:`key`}],[o]),[c,l]=(0,_.useState)(a?{id:`custom`,label:o(`modal.customProvider`),adapter:`openai-chat`,baseUrl:``,auth:`key`}:null),[u,d]=(0,_.useState)(a?{name:``,adapter:`openai-chat`,baseUrl:``,authMode:`key`,apiKey:``,defaultModel:``}:null),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)([]),[y,b]=(0,_.useState)(!1),[x,C]=(0,_.useState)(``),[w,T]=(0,_.useState)(`ok`),[E,D]=(0,_.useState)(``),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(``),[M,P]=(0,_.useState)(!0),[ee,F]=(0,_.useState)(s),[I,L]=(0,_.useState)(!0),[te,ne]=(0,_.useState)({}),R=(0,_.useRef)(!0),z=(0,_.useRef)(!1),B=(0,_.useRef)(null),re=(0,_.useRef)(null);(0,_.useEffect)(()=>{R.current=!0,B.current=document.activeElement;let e=re.current;if(e){let t=e.querySelector(`input:not([disabled]), button:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1'])`);t&&t.focus()}return()=>{R.current=!1,B.current?.focus()}},[]),(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,_.useEffect)(()=>{fetch(`${e}/api/oauth/providers`).then(e=>e.json()).then(e=>v(e.providers??[])).catch(()=>{})},[e]),(0,_.useEffect)(()=>{fetch(`${e}/api/provider-presets`).then(e=>e.json()).then(e=>{Array.isArray(e.providers)&&e.providers.length>0&&(z.current=!0,F(e.providers))}).catch(()=>{}).finally(()=>L(!1))},[e]),(0,_.useEffect)(()=>{fetch(`${e}/api/usage?range=30d`).then(e=>e.json()).then(e=>{let t={};for(let n of e.providers??[])t[n.provider]=n.requests;ne(t)}).catch(()=>{})},[e]),(0,_.useEffect)(()=>{z.current||F(s)},[s]);let se=e=>{let t=Ue(e);return t?o(t):e.note},ce=e=>{l(e),d({name:e.id===`custom`?``:e.id,adapter:e.adapter,baseUrl:e.baseUrl,authMode:e.auth,apiKey:``,defaultModel:e.defaultModel??``}),h(``),C(``),T(`ok`),D(``),j(``),P(!0)},le=()=>{l(null),d(null),h(``),C(``),T(`ok`),D(``),j(``),P(!0)},V=async()=>{if(!u)return;let t=c?He(c):!1;if(!t&&!u.name.trim()){h(o(`modal.nameRequired`));return}if(!t&&!u.baseUrl.trim()){h(o(`modal.baseUrlRequired`));return}let n;try{n=Ge(c??{id:`custom`},u)}catch{h(o(`modal.invalidPreset`));return}p(!0),h(``);try{let t=await fetch(`${e}/api/providers`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!t.ok){h((await t.json().catch(()=>({}))).error||o(`modal.failedStatus`,{status:t.status}));return}r(n.name)}catch{h(o(`modal.networkError`))}finally{p(!1)}},ue=async t=>{b(!0),C(``),T(`ok`),D(``),j(``),P(!0);try{let n=await fetch(`${e}/api/oauth/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:t})}),i=await n.json();if(!R.current)return;if(!n.ok){T(`warn`),C(i.error===`unknown oauth provider`?o(`modal.oauthComingSoonShort`):i.error||o(`modal.loginFailStart`));return}i.url?C(o(`modal.waitingLogin`)):C(i.instructions||o(`modal.loggingIn`));for(let n=0;n<100;n++){if(await new Promise(e=>setTimeout(e,2e3)),!R.current)return;let n=await fetch(`${e}/api/oauth/status?provider=${t}`).then(e=>e.json()).catch(()=>null);if(!R.current)return;if(n?.loggedIn){r(t);return}if(n?.error){T(`warn`),C(o(`modal.loginError`,{error:n.error}));return}}T(`warn`),C(o(`modal.loginTimeout`))}catch{R.current&&(T(`warn`),C(o(`modal.networkError`)))}finally{R.current&&b(!1)}},de=async t=>{let n=E.trim();if(!(!n||O)){k(!0),j(``);try{let r=await fetch(`${e}/api/oauth/login/code`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:t,input:n})}),i=await r.json().catch(()=>({}));if(!R.current)return;if(!r.ok){P(!1),j(o(`prov.pasteFail`,{error:i.error||r.statusText}));return}D(``),P(!0),j(o(`prov.pasteOk`))}catch{R.current&&(P(!1),j(o(`modal.networkError`)))}finally{R.current&&k(!1)}}},fe=u?t.includes(u.name.trim())&&u.name.trim()!==``:!1,pe=c?.id===`custom`,me=u?.authMode===`local`,he=c?He(c):!1;return(0,S.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":o(`modal.add`),className:`modal-overlay`,onClick:n,children:(0,S.jsxs)(`div`,{ref:re,className:`modal-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`modal-head`,children:[(0,S.jsx)(`h3`,{children:c?o(`modal.addNamed`,{label:c.label}):o(`modal.add`)}),(0,S.jsx)(`button`,{className:`btn btn-ghost btn-icon`,"aria-label":o(`common.close`),onClick:n,children:(0,S.jsx)(N,{})})]}),c?u&&(c.auth===`oauth`&&u.authMode===`oauth`?(0,S.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:14},children:[(0,S.jsx)(`div`,{className:`muted text-control`,children:c.note??o(`modal.oauthDefaultNote`)}),g.includes(c.oauthProvider??``)?(0,S.jsxs)(`button`,{className:`btn btn-primary`,onClick:()=>ue(c.oauthProvider),disabled:y,style:{width:`100%`,padding:`12px 16px`},children:[(0,S.jsx)(oe,{}),y?o(`modal.waitingBrowser`):o(`modal.logInWith`,{label:c.label})]}):(0,S.jsx)(`div`,{className:`text-control`,style:{color:`var(--amber)`,background:`var(--amber-soft)`,border:`1px solid var(--amber)`,borderRadius:`var(--radius-sm)`,padding:`10px 12px`},children:o(`modal.oauthComingSoon`,{label:c.label})}),x&&(0,S.jsx)(`div`,{className:`text-label`,style:{color:w===`warn`?`var(--amber)`:`var(--accent-hover)`},children:x}),y&&(0,S.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6},children:[(0,S.jsx)(`div`,{className:`muted text-label`,children:o(`prov.pasteRedirectHint`)}),(0,S.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,S.jsx)(`input`,{type:`text`,autoComplete:`off`,spellCheck:!1,value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c.oauthProvider&&(e.preventDefault(),de(c.oauthProvider))},placeholder:o(`prov.pasteRedirect`),"aria-label":o(`prov.pasteRedirect`),disabled:O,className:`input text-label`,style:{flex:1}}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,type:`button`,disabled:O||!E.trim()||!c.oauthProvider,onClick:()=>c.oauthProvider&&void de(c.oauthProvider),children:o(O?`prov.pasteSubmitting`:`prov.pasteSubmit`)})]}),A&&(0,S.jsx)(`div`,{className:`text-label`,style:{color:M?`var(--accent-hover)`:`var(--amber)`},children:A})]}),(0,S.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginTop:2},children:[(0,S.jsx)(`button`,{className:`link-btn`,onClick:()=>{d({...u,authMode:`key`}),C(``),T(`ok`),D(``),j(``)},children:o(`modal.useApiKeyInstead`)}),(0,S.jsx)(`div`,{style:{flex:1}}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:le,children:o(`modal.back`)})]})]}):(0,S.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:[!he&&!pe&&!me&&!c.keyOptional&&c.note&&(0,S.jsxs)(`details`,{className:`setup-guide`,children:[(0,S.jsx)(`summary`,{children:o(`modal.setupGuide`)}),(0,S.jsxs)(`ol`,{className:`text-label leading-relaxed`,style:{margin:`8px 0 0`,paddingLeft:18,color:`var(--muted)`},children:[(0,S.jsxs)(`li`,{children:[o(`modal.setupStep1Prefix`),` `,(0,S.jsx)(`a`,{href:c.dashboardUrl,target:`_blank`,rel:`noreferrer`,children:o(`modal.setupDashboardLink`,{label:c.label})}),` `,o(`modal.setupStep1Suffix`)]}),(0,S.jsx)(`li`,{children:o(`modal.setupStep2`)}),(0,S.jsx)(`li`,{children:o(`modal.setupStep3`)})]}),c.note&&(0,S.jsx)(`div`,{className:`text-label`,style:{color:`var(--muted)`,marginTop:6,fontStyle:`italic`},children:c.note})]}),(0,S.jsx)(ft,{label:o(`modal.providerName`),children:(0,S.jsx)(`input`,{className:`input`,value:u.name,readOnly:he,onChange:e=>d({...u,name:e.target.value}),placeholder:o(`modal.namePlaceholder`)})}),fe&&(0,S.jsx)(`div`,{className:`text-label`,style:{color:`var(--amber)`},children:o(`modal.duplicateWarn`,{name:u.name.trim()})}),!he&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(ft,{label:o(`modal.adapter`),children:(0,S.jsx)(`select`,{className:`input`,value:u.adapter,onChange:e=>d({...u,adapter:e.target.value}),children:[`openai-responses`,`openai-chat`,`anthropic`,`google`,`azure-openai`,`cursor`].map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))})}),(0,S.jsx)(ft,{label:o(`modal.baseUrl`),children:(0,S.jsx)(`input`,{className:`input`,value:u.baseUrl,onChange:e=>d({...u,baseUrl:e.target.value}),placeholder:o(`modal.baseUrlPlaceholder`)})})]}),u.authMode===`forward`?(0,S.jsx)(`div`,{className:`text-label`,style:{color:`var(--green)`,background:`var(--green-soft)`,border:`1px solid var(--green)`,borderRadius:`var(--radius-sm)`,padding:`8px 10px`},children:se(c)}):u.authMode===`local`?(0,S.jsx)(`div`,{className:`text-label leading-relaxed`,style:{color:`var(--amber)`,background:`var(--amber-soft)`,border:`1px solid var(--amber)`,borderRadius:`var(--radius-sm)`,padding:`8px 10px`},children:o(`modal.localHint`)}):c.keyOptional?(0,S.jsxs)(`div`,{className:`text-label leading-relaxed`,style:{color:`var(--green)`,background:`var(--green-soft)`,border:`1px solid var(--green)`,borderRadius:`var(--radius-sm)`,padding:`10px 12px`},children:[(0,S.jsx)(`strong`,{children:o(`modal.freeTierTitle`)}),` — `,c.note??o(`modal.freeTierDefault`)]}):(0,S.jsxs)(S.Fragment,{children:[c.dashboardUrl&&(0,S.jsxs)(`a`,{className:`text-label`,href:c.dashboardUrl,target:`_blank`,rel:`noreferrer`,style:{display:`inline-flex`,alignItems:`center`,gap:5},children:[(0,S.jsx)(ae,{style:{width:14,height:14}}),o(`modal.getApiKey`,{label:c.label}),(0,S.jsx)(ie,{style:{width:13,height:13}})]}),(0,S.jsx)(ft,{label:o(`modal.apiKey`),children:(0,S.jsx)(`input`,{className:`input`,type:`password`,value:u.apiKey,onChange:e=>d({...u,apiKey:e.target.value}),placeholder:o(`modal.apiKeyPlaceholder`)})})]}),!he&&(0,S.jsx)(ft,{label:o(`modal.defaultModel`),children:(0,S.jsx)(`input`,{className:`input`,value:u.defaultModel,onChange:e=>d({...u,defaultModel:e.target.value}),placeholder:o(`modal.defaultModelPlaceholder`)})}),m&&(0,S.jsx)(`div`,{className:`text-control`,role:`alert`,style:{color:`var(--red)`},children:m}),(0,S.jsxs)(`div`,{style:{display:`flex`,gap:8,marginTop:4,alignItems:`center`},children:[(0,S.jsx)(`button`,{className:`btn btn-primary`,onClick:V,disabled:f,children:o(f?`modal.adding`:`modal.add`)}),c.auth===`oauth`&&(0,S.jsx)(`button`,{className:`link-btn`,onClick:()=>{d({...u,authMode:`oauth`}),h(``)},children:o(`modal.useOauthLogin`)}),(0,S.jsx)(`div`,{style:{flex:1}}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:le,children:o(`modal.back`)})]})]})):(0,S.jsx)(ut,{presets:ee,usageRank:te,presetsLoading:I,initialTier:i,onSelectPreset:e=>ce(e),onSelectCustom:()=>ce(s[0])})]})})}function ft({label:e,children:t}){return(0,S.jsxs)(`label`,{style:{display:`block`},children:[(0,S.jsx)(`span`,{className:`field-label`,children:e}),t]})}function pt(e){return e.authMode===`local`||Ye(e.baseUrl)}var mt=[`ollama`,`vllm`,`lm-studio`,`lmstudio`,`litellm`,`localai`];function ht(e){let t=(e.authMode??``).toLowerCase();if(t===`oauth`||t===`forward`)return`login`;if(pt(e))return`local`;let n=`${e.name??``} ${e.adapter} ${e.baseUrl}`.toLowerCase();return mt.some(e=>n.includes(e))?`selfHosted`:`cloud`}function gt(e){if(!e||typeof e!=`object`)return{};let t=e.available;if(!t||typeof t!=`object`||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))Array.isArray(r)&&(n[e]=r.filter(e=>typeof e==`string`));return n}function _t(e){if(!e||typeof e!=`object`)return{};let t=e.selected;if(!t||typeof t!=`object`||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))Array.isArray(r)&&(n[e]=r.filter(e=>typeof e==`string`));return n}function vt(e){let t={};for(let[n,r]of Object.entries(gt(e)))t[n]=r.length;return t}function yt(e){return Object.entries(e).filter(e=>typeof e[1].requests==`number`&&e[1].requests>0).map(([e,t])=>({name:e,...t,requests:t.requests})).sort((e,t)=>t.requests-e.requests||e.name.localeCompare(t.name))}var bt={justNow:`Just now`,notChecked:`Not checked`,minutesAgo:e=>`${e}m ago`,hoursAgo:e=>`${e}h ago`,daysAgo:e=>`${e}d ago`};function xt(e,t,n){let r=typeof t==`object`&&t?t:bt,i=typeof t==`number`?t:n??Date.now();if(e===void 0||!Number.isFinite(e))return r.notChecked;let a=Math.max(0,i-e),o=Math.floor(a/6e4);if(o<1)return r.justNow;if(o<60)return r.minutesAgo(o);let s=Math.floor(o/60);return s<24?r.hoursAgo(s):r.daysAgo(Math.floor(s/24))}function St(e){return{justNow:e(`time.justNow`),notChecked:e(`time.notChecked`),minutesAgo:t=>e(`time.minutesAgo`,{n:t}),hoursAgo:t=>e(`time.hoursAgo`,{n:t}),daysAgo:t=>e(`time.daysAgo`,{n:t})}}function Ct(e,t=`en`){if(e===void 0)return`—`;if(t.toLowerCase().slice(0,2)===`de`){let t=e=>e.replace(/\.0+$/,``).replace(`.`,`,`);return e>=1e9?`${t((e/1e9).toFixed(2))} Mrd.`:e>=1e6?`${t((e/1e6).toFixed(1))} Mio.`:e>=1e3?`${t((e/1e3).toFixed(1))} Tsd.`:String(e)}return e>=1e9?`${(e/1e9).toFixed(2).replace(/\.?0+$/,``)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function wt(e,t=`en`){return Ct(e,t)}var Tt={anthropic:`claude-color.svg`,"anthropic-apikey":`claude-color.svg`,"azure-openai":`openai.svg`,chatgpt:`openai.svg`,"cloudflare-ai-gateway":`cloudflare-ai-gateway-color.svg`,cursor:`cursor-color.svg`,deepseek:`deepseek-color.svg`,firepass:`firepass-color.svg`,fireworks:`fireworks-color.svg`,github:`github-copilot-color.svg`,"github-copilot":`copilot-color.svg`,"gitlab-duo":`gitlab-duo-color.svg`,google:`gemini-color.svg`,"google-antigravity":`antigravity-color.svg`,"google-vertex":`gemini-color.svg`,groq:`groq-color.svg`,huggingface:`huggingface-color.svg`,kimi:`kimi-color.svg`,"kimi-code":`kimi-color.svg`,kiro:`kiro-color.svg`,"lm-studio":`lm-studio-color.svg`,mistral:`mistral-color.svg`,moonshot:`moonshot-color.svg`,nvidia:`nvidia-color.svg`,ollama:`ollama-color.svg`,"ollama-cloud":`ollama-color.svg`,openai:`openai.svg`,"openai-apikey":`openai.svg`,"opencode-free":`opencode.svg`,"opencode-go":`opencode.svg`,"opencode-zen":`opencode.svg`,openrouter:`openrouter-color.svg`,qianfan:`qianfan-color.svg`,"qwen-portal":`qwen-portal-color.svg`,"vercel-ai-gateway":`vercel-ai-gateway-color.svg`,vllm:`vllm-color.svg`,xai:`grok-color.svg`,"mimo-free":`xiaomi-color.svg`,xiaomi:`xiaomi-color.svg`},Et={anthropic:`Anthropic Claude`,"anthropic-apikey":`Anthropic Claude`,chatgpt:`ChatGPT`,openai:`OpenAI (Codex login)`,"openai-apikey":`OpenAI API`,"azure-openai":`Azure OpenAI`,"cloudflare-ai-gateway":`Cloudflare AI Gateway`,nvidia:`NVIDIA NIM`,ollama:`Ollama`,"ollama-cloud":`Ollama Cloud`,xai:`xAI Grok`,"mimo-free":`MiMo Free`,xiaomi:`Xiaomi`,cursor:`Cursor`,deepseek:`DeepSeek`,github:`GitHub`,"github-copilot":`GitHub Copilot`,"gitlab-duo":`GitLab Duo`,openrouter:`OpenRouter`,"opencode-go":`OpenCode Go`,"opencode-free":`OpenCode Free`,"opencode-zen":`OpenCode Zen`,mistral:`Mistral`,groq:`Groq`,kimi:`Kimi`,"kimi-code":`Kimi`,moonshot:`Moonshot`,google:`Google`,"google-vertex":`Google Vertex`,"lm-studio":`LM Studio`,huggingface:`Hugging Face`,"vercel-ai-gateway":`Vercel AI Gateway`,vllm:`vLLM`,litellm:`LiteLLM`};function Dt(e){return Tt[e.toLowerCase()]}function Ot(e,t){let n=Dt(e);return n?`/provider-icons/${n}`:void 0}function kt(e){let t=e.toLowerCase();return Et[t]?Et[t]:e===t&&/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e)?e.split(`-`).map(e=>e&&e[0].toUpperCase()+e.slice(1)).join(` `):e}function At(e){return Object.prototype.hasOwnProperty.call(Et,e.toLowerCase())}function jt(e,t){let n=rt(e);return t(n===`disabled`?`prov.disabledBadge`:n===`ready`?`pws.status.ready`:`pws.status.needsSetup`)}function Mt(e,t){switch(e.authMode){case`oauth`:return t(`modal.badge.oauth`);case`forward`:return t(`pws.auth.chatgptPassthrough`);case`local`:return t(`modal.badge.local`);case`key`:return t(`modal.badge.apiKey`);default:return e.authMode??(e.keyOptional?t(`pws.auth.noKey`):t(`modal.badge.apiKey`))}}function Nt(e){let t=rt(e);return t===`disabled`?`providers-workspace-rail-status providers-workspace-rail-status--inactive`:t===`ready`?`providers-workspace-rail-status providers-workspace-rail-status--active`:`providers-workspace-rail-status providers-workspace-rail-status--warning`}function Pt({name:e,adapter:t,baseUrl:n,cls:r}){let i=Ot(e,{adapter:t,baseUrl:n});return(0,S.jsx)(`span`,{className:r,children:i?(0,S.jsx)(`img`,{src:i,alt:``,"aria-hidden":`true`}):(0,S.jsx)(T,{"aria-hidden":`true`})})}function Ft({item:e,selected:t,tabbable:n,modelCount:r,isDefault:i,showConfigId:a,onClick:o,onFocus:s}){let c=U(),l=$e(e),u=pt(e),d=jt(e,c),f=kt(e.name),p=a?`${f} (${e.name})`:f,m=`${i?c(`pws.rail.suffixDefault`):``}${u?c(`pws.rail.suffixLocal`):l?c(`pws.rail.suffixFree`):``}`,h=r!==void 0&&r>0?r===1?c(`pws.modelCountOne`):c(`pws.modelCount`,{count:r}):``,g=[a?e.name:``,h].filter(Boolean).join(` · `);return(0,S.jsxs)(`button`,{type:`button`,className:`providers-workspace-rail-row${t?` providers-workspace-rail-row--selected`:``}`,onClick:o,role:`option`,"aria-selected":t,tabIndex:n?0:-1,"aria-label":c(`pws.rail.selectAria`,{name:p,status:d,suffix:m}),title:p,onFocus:s,children:[(0,S.jsx)(Pt,{name:e.name,adapter:e.adapter,baseUrl:e.baseUrl,cls:`providers-workspace-rail-icon`}),(0,S.jsxs)(`span`,{className:`providers-workspace-rail-copy`,children:[(0,S.jsxs)(`span`,{className:`providers-workspace-rail-primary`,children:[(0,S.jsx)(`span`,{className:`providers-workspace-rail-name-label`,title:f,children:f}),u?(0,S.jsx)(`span`,{className:`pwi-rail-badge pwi-rail-badge--local`,title:c(`pws.localTitle`),children:c(`modal.badge.local`)}):l?(0,S.jsx)(`span`,{className:`pwi-rail-badge pwi-rail-badge--free`,title:c(`pws.freeTitle`),children:c(`modal.badge.free`)}):null]}),g&&(0,S.jsx)(`span`,{className:`providers-workspace-rail-secondary`,title:g,children:g})]}),(0,S.jsxs)(`span`,{className:`providers-workspace-rail-trail`,children:[i&&(0,S.jsx)(`span`,{className:`pwi-default-star`,title:c(`prov.defaultBadge`),"aria-label":c(`prov.defaultBadge`),children:(0,S.jsx)(he,{width:17,height:17,"aria-hidden":`true`})}),(0,S.jsx)(`span`,{className:Nt(e),title:d,"aria-hidden":`true`})]})]})}function It(e){let t=e?.quota;if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t,r=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,i=Array.isArray(n.customWindows)?n.customWindows.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;return typeof t.label!=`string`||r(t.percent)===void 0?[]:[{label:t.label,percent:t.percent,...r(t.resetAt)===void 0?{}:{resetAt:t.resetAt}}]}):[],a={...r(n.fiveHourPercent)===void 0?{}:{fiveHourPercent:n.fiveHourPercent},...r(n.fiveHourResetAt)===void 0?{}:{fiveHourResetAt:n.fiveHourResetAt},...r(n.weeklyPercent)===void 0?{}:{weeklyPercent:n.weeklyPercent},...r(n.weeklyResetAt)===void 0?{}:{weeklyResetAt:n.weeklyResetAt},...r(n.monthlyPercent)===void 0?{}:{monthlyPercent:n.monthlyPercent},...r(n.monthlyResetAt)===void 0?{}:{monthlyResetAt:n.monthlyResetAt},...i.length>0?{customWindows:i}:{},updatedAt:r(n.updatedAt)??e?.updatedAt??Date.now()};return a.fiveHourPercent!==void 0||a.weeklyPercent!==void 0||a.monthlyPercent!==void 0||(a.customWindows?.length??0)>0?a:null}function Lt(e){if(!e?.trim())return``;let[t,n]=e.split(`:`,2);return n?`${t} · ${n.replace(/-/g,` `)}`:e}function Rt(e,t,n){let r=e.length>0?e:t?[t]:[],i=n.trim().toLowerCase();return i?r.filter(e=>e.toLowerCase().includes(i)):r}function zt(e){let t=e?.trim().toLowerCase();return t===`go`||t===`free`}function Bt(e,t){return!e||!zt(t)?e:{...e.monthlyPercent===void 0?{}:{monthlyPercent:e.monthlyPercent},...e.monthlyResetAt===void 0?{}:{monthlyResetAt:e.monthlyResetAt},...e.resetCredits===void 0?{}:{resetCredits:e.resetCredits},updatedAt:e.updatedAt}}function Vt(e){return e===`5h`?0:e===`First-party models`?2:e===`API usage`?3:5}function Ht(e,t){switch(e){case`First-party models`:return t(`quota.cursorFirstParty`);case`API usage`:return t(`quota.cursorApiUsage`);case`Total subscription credits`:return t(`quota.totalSubscriptionCredits`);default:return e}}function Ut(e,t,n){let r=Bt(e,t);if(!r)return[];let i=[];typeof r.fiveHourPercent==`number`&&i.push({rank:0,row:{label:n(`codexAuth.fiveHour`),limitLabel:n(`quota.fiveHourLimit`),percent:r.fiveHourPercent,resetAt:r.fiveHourResetAt}}),typeof r.weeklyPercent==`number`&&i.push({rank:1,row:{label:n(`codexAuth.weekly`),limitLabel:n(`quota.weeklyLimit`),percent:r.weeklyPercent,resetAt:r.weeklyResetAt}}),typeof r.monthlyPercent==`number`&&i.push({rank:4,row:{label:n(`codexAuth.monthly`),limitLabel:n(`quota.monthlyLimit`),percent:r.monthlyPercent,resetAt:r.monthlyResetAt}});for(let e of r.customWindows??[]){let t=Ht(e.label,n);i.push({rank:Vt(e.label),row:{label:t,limitLabel:t,percent:e.percent,resetAt:e.resetAt}})}return i.sort((e,t)=>e.rank-t.rank).map(e=>e.row)}function Wt(e){switch(e){case`en`:return`en-GB`;case`de`:return`de-DE`;case`ko`:return`ko-KR`;case`zh`:return`zh-CN`;default:return e}}function Gt(e){return e>=99.5}function Kt(e,t){return t>0&&e>=t}function qt(e,t){return Kt(e,t)||Gt(e)?`bar-warn`:`bar-green`}function Jt(e){let t=Math.max(0,Math.min(100,e));return t<=0?0:Math.max(4,Math.round(t))}function Yt({quota:e,plan:t,threshold:n,t:r,className:i,layout:a=`compact`}){let{locale:o}=H(),s=Ut(e,t,r);return s.length===0?null:a===`stacked`?(0,S.jsx)(`div`,{className:`quota-stacked${i?` ${i}`:``}`,children:s.map((e,t)=>(0,S.jsx)(Zt,{row:e,threshold:n,t:r,locale:o},`${e.limitLabel}-${t}`))}):(0,S.jsx)(`div`,{className:`quota-compact${i?` ${i}`:``}`,children:s.map((e,t)=>(0,S.jsx)(Xt,{label:e.label,percent:e.percent,resetAt:e.resetAt,threshold:n,t:r,locale:o},`${e.label}-${t}`))})}function Xt({label:e,percent:t,resetAt:n,threshold:r,t:i,locale:a}){let o=Gt(t),s=Kt(t,r),c=qt(t,r),l=Qt(n,i,a);return(0,S.jsxs)(`div`,{className:`quota-row${s?` quota-row--warn`:``}${o?` quota-row--exhausted`:``}`,children:[(0,S.jsx)(`span`,{className:`quota-label`,children:e}),(0,S.jsx)(`span`,{className:`quota-reset-label`,children:i(`codexAuth.resets`)}),(0,S.jsx)(`span`,{className:`quota-reset-day`,children:l.day}),(0,S.jsx)(`span`,{className:`quota-reset-time`,children:l.time}),(0,S.jsx)(`div`,{className:`bar`,children:(0,S.jsx)(`div`,{className:`bar-fill ${c}`,style:{width:`${Jt(t)}%`}})}),(0,S.jsxs)(`span`,{className:`quota-val${s?` quota-val--warn`:``}`,title:o?i(`quota.limitReached`):void 0,children:[s&&(0,S.jsx)(I,{width:12,height:12,"aria-hidden":`true`}),Math.round(t),`%`,o?` · ${i(`quota.limitReached`)}`:``]})]})}function Zt({row:e,threshold:t,t:n,locale:r}){let i=Gt(e.percent),a=Kt(e.percent,t),o=qt(e.percent,t),s=$t(e.resetAt,n,r);return(0,S.jsxs)(`div`,{className:`quota-stacked-row${a?` quota-stacked-row--warn`:``}${i?` quota-stacked-row--exhausted`:``}`,children:[(0,S.jsxs)(`div`,{className:`quota-stacked-head`,children:[(0,S.jsx)(`span`,{className:`quota-stacked-limit`,children:e.limitLabel}),(0,S.jsx)(`span`,{className:`quota-stacked-reset muted`,children:s})]}),(0,S.jsxs)(`div`,{className:`quota-stacked-bar-row`,children:[(0,S.jsx)(`div`,{className:`bar quota-stacked-bar`,children:(0,S.jsx)(`div`,{className:`bar-fill ${o}`,style:{width:`${Jt(e.percent)}%`}})}),(0,S.jsx)(`span`,{className:`quota-stacked-used${a?` quota-stacked-used--warn`:``}`,children:n(`quota.usedPercent`,{pct:Math.round(e.percent)})})]}),i&&(0,S.jsxs)(`div`,{className:`quota-stacked-limit-reached`,role:`status`,children:[(0,S.jsx)(I,{width:12,height:12,"aria-hidden":`true`}),n(`quota.limitReached`)]})]})}function Qt(e,t,n){if(typeof e!=`number`||!Number.isFinite(e))return{day:``,time:``};let r=e<1e10?e*1e3:e,i=new Date(r),a=new Date,o=Wt(n),s=new Intl.DateTimeFormat(o,{hour:`2-digit`,minute:`2-digit`,hour12:!1}).format(i);return i.getFullYear()===a.getFullYear()&&i.getMonth()===a.getMonth()&&i.getDate()===a.getDate()?{day:t(`codexAuth.today`),time:s}:{day:new Intl.DateTimeFormat(o,{day:`numeric`,month:`short`}).format(i),time:s}}function $t(e,t,n=`en`,r=Date.now()){if(typeof e!=`number`||!Number.isFinite(e))return``;let i=e<1e10?e*1e3:e,a=new Date(i),o=Wt(n),s=new Intl.DateTimeFormat(o,{hour:`2-digit`,minute:`2-digit`,hour12:!1}).format(a),c=new Date(r),l=new Date(c.getFullYear(),c.getMonth(),c.getDate()).getTime(),u=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),d=Math.round((u-l)/864e5);if(d===1)return t(`quota.resetsTomorrow`,{time:s});let f=a.getFullYear()!==c.getFullYear(),p=new Intl.DateTimeFormat(o,{day:`numeric`,month:`short`,...f?{year:`numeric`}:{}}).format(a);if(i<=r)return t(`quota.resetsAt`,{date:p,time:s,when:`${p}, ${s}`});let m=Math.round((i-r)/6e4);if(m<60)return t(`quota.resetsRelativeMinutes`,{n:Math.max(1,m)});let h=Math.round(m/60);return h<12&&d===0?t(`quota.resetsRelativeHours`,{n:Math.max(1,h)}):d===0?t(`quota.resetsToday`,{time:s}):t(`quota.resetsAt`,{date:p,time:s,when:`${p}, ${s}`})}function en({sections:e,quotaReports:t,usageTotals:n,onSelectProvider:r}){let i=U(),{locale:a}=H(),o=St(i),s=(0,_.useMemo)(()=>[...e.ready,...e.needsSetup,...e.disabled],[e]),c=(0,_.useMemo)(()=>new Set(s.map(e=>e.name)),[s]),l=(0,_.useMemo)(()=>{let e=[];for(let n of s){let r=t[n.name];r&&It(r)&&e.push({item:n,report:r})}return e},[s,t]),u=(0,_.useMemo)(()=>{let e={};for(let[t,r]of Object.entries(n))c.has(t)&&(e[t]=r);return yt(e)},[n,c]);return(0,S.jsxs)(`div`,{className:`pws-dashboard`,children:[(0,S.jsxs)(`div`,{className:`pws-dashboard-header`,children:[(0,S.jsx)(`h2`,{className:`pws-dashboard-title`,children:i(`pws.dashboard.title`)}),(0,S.jsx)(`p`,{className:`muted pws-dashboard-subtitle`,children:i(`pws.dashboard.subtitle`)})]}),(0,S.jsxs)(`div`,{className:`pws-dashboard-summary`,children:[(0,S.jsx)(tn,{count:e.ready.length,label:i(`pws.status.ready`),tone:`ok`}),(0,S.jsx)(tn,{count:e.needsSetup.length,label:i(`pws.status.needsSetup`),tone:`warn`}),(0,S.jsx)(tn,{count:e.disabled.length,label:i(`prov.disabledBadge`),tone:`muted`})]}),l.length>0&&(0,S.jsxs)(`section`,{className:`pws-dashboard-section`,"aria-label":i(`pws.dashboard.rateLimits`),children:[(0,S.jsx)(`h3`,{className:`pws-dashboard-section-title`,children:i(`pws.dashboard.rateLimits`)}),(0,S.jsx)(`div`,{className:`pws-dashboard-rows`,children:l.map(({item:e,report:t})=>(0,S.jsxs)(`button`,{type:`button`,className:`pws-dashboard-row`,onClick:()=>r(e.name),children:[(0,S.jsx)(Pt,{name:e.name,adapter:e.adapter,baseUrl:e.baseUrl,cls:`pws-dashboard-row-icon`}),(0,S.jsxs)(`div`,{className:`pws-dashboard-row-info`,children:[(0,S.jsx)(`span`,{className:`pws-dashboard-row-name`,children:kt(e.name)}),(0,S.jsx)(`span`,{className:`pws-dashboard-row-meta muted`,children:i(`pws.dashboard.checkedAgo`,{time:xt(t.updatedAt,o)})})]}),(0,S.jsx)(z,{className:`pws-dashboard-row-chevron`,"aria-hidden":`true`}),(0,S.jsx)(`div`,{className:`pws-dashboard-row-bars`,children:(0,S.jsx)(Yt,{quota:It(t),threshold:80,t:i,layout:`stacked`})})]},e.name))})]}),u.length>0?(0,S.jsxs)(`section`,{className:`pws-dashboard-section`,"aria-label":i(`pws.dashboard.recentlyUsed`),children:[(0,S.jsx)(`h3`,{className:`pws-dashboard-section-title`,children:i(`pws.dashboard.recentlyUsed`)}),(0,S.jsx)(`div`,{className:`pws-dashboard-rows`,children:u.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`pws-dashboard-row`,onClick:()=>r(e.name),children:[(0,S.jsx)(Pt,{name:e.name,adapter:``,baseUrl:``,cls:`pws-dashboard-row-icon`}),(0,S.jsx)(`span`,{className:`pws-dashboard-row-name`,children:kt(e.name)}),(0,S.jsx)(`span`,{className:`pws-dashboard-row-count muted`,children:i(`pws.dashboard.requests`,{count:Ct(e.requests,a)})}),(0,S.jsx)(z,{className:`pws-dashboard-row-chevron`,"aria-hidden":`true`})]},e.name))})]}):(0,S.jsxs)(`section`,{className:`pws-dashboard-section`,children:[(0,S.jsx)(`h3`,{className:`pws-dashboard-section-title`,children:i(`pws.dashboard.recentlyUsed`)}),(0,S.jsx)(`p`,{className:`muted`,children:i(`pws.dashboard.noUsage`)})]})]})}function tn({count:e,label:t,tone:n}){return(0,S.jsxs)(`div`,{className:`pws-dashboard-card pws-dashboard-card--${n}`,children:[(0,S.jsx)(`span`,{className:`pws-dashboard-card-count`,children:e}),(0,S.jsx)(`span`,{className:`pws-dashboard-card-label`,children:t})]})}var nn=[{id:`az`,labelKey:`pws.sort.az`},{id:`za`,labelKey:`pws.sort.za`},{id:`free-paid`,labelKey:`pws.sort.freePaid`},{id:`paid-free`,labelKey:`pws.sort.paidFree`},{id:`accounts-first`,labelKey:`pws.sort.accountsFirst`}];function rn({providers:e,apiBase:t,defaultProvider:n,selectedName:r,onSelect:i,onAddProvider:a,detail:o}){let s=U(),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)({ready:!0,needsSetup:!0,disabled:!0}),[f,p]=(0,_.useState)({free:!0,paid:!0}),[m,h]=(0,_.useState)({cloud:!0,local:!0,selfHosted:!0,login:!0}),[g,v]=(0,_.useState)(`az`),[y,b]=(0,_.useState)(!1),[x,C]=(0,_.useState)(null),[w,T]=(0,_.useState)({}),[E,D]=(0,_.useState)({}),[O,k]=(0,_.useState)({}),[A,j]=(0,_.useState)(!1),[M,N]=(0,_.useState)(!1),[P,ee]=(0,_.useState)({}),[F,I]=(0,_.useState)({}),L=(0,_.useRef)(null),ne=(0,_.useMemo)(()=>nt(it(e)),[e]);(0,_.useEffect)(()=>{let e=!1;return fetch(`${t}/api/selected-models`).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status)))).then(t=>{e||(T(vt(t)),D(gt(t)),k(_t(t)),N(!1),j(!1))}).catch(()=>{e||(N(!0),j(!1))}),()=>{e=!0}},[t]),(0,_.useEffect)(()=>{let e=!1;return fetch(`${t}/api/usage?range=30d`).then(e=>e.ok?e.json():null).then(t=>{if(e||!t)return;let n={};for(let e of t.providers??[])n[e.provider]={requests:e.requests,totalTokens:e.totalTokens};ee(n)}).catch(()=>{}),()=>{e=!0}},[t]),(0,_.useEffect)(()=>{let e=!1;return fetch(`${t}/api/provider-quotas`).then(e=>e.ok?e.json():null).then(t=>{if(e||!t)return;let n={};for(let e of t.reports??[])e?.provider&&(n[e.provider]={label:e.label,source:e.source,updatedAt:typeof e.updatedAt==`number`?e.updatedAt:Date.now(),quota:e.quota});I(n)}).catch(()=>{}),()=>{e=!0}},[t]),(0,_.useEffect)(()=>{if(!y)return;let e=e=>{L.current&&!L.current.contains(e.target)&&b(!1)},t=e=>{e.key===`Escape`&&b(!1)};return document.addEventListener(`mousedown`,e),window.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),window.removeEventListener(`keydown`,t)}},[y]);let R=(0,_.useMemo)(()=>[...ne.ready,...ne.needsSetup,...ne.disabled],[ne]),z=(0,_.useMemo)(()=>R.filter($e).length,[R]),B=R.length-z,re=(0,_.useMemo)(()=>{let e={cloud:0,local:0,selfHosted:0,login:0};for(let t of R)e[ht(t)]+=1;return e},[R]),ie=(0,_.useMemo)(()=>{let e=c.trim().toLowerCase(),t=t=>tt(t.filter(t=>{if(e&&!t.name.toLowerCase().includes(e)&&!t.adapter.toLowerCase().includes(e))return!1;let n=$e(t);return!(n&&!f.free||!n&&!f.paid||!m[ht(t)])}),g);return{ready:u.ready?t(ne.ready):[],needsSetup:u.needsSetup?t(ne.needsSetup):[],disabled:u.disabled?t(ne.disabled):[]}},[ne,c,u,f,m,g]),ae=!u.ready||!u.needsSetup||!u.disabled||!f.free||!f.paid||!m.cloud||!m.local||!m.selfHosted||!m.login||g!==`az`,oe=()=>{d({ready:!0,needsSetup:!0,disabled:!0}),p({free:!0,paid:!0}),h({cloud:!0,local:!0,selfHosted:!0,login:!0}),v(`az`)},se=(0,_.useMemo)(()=>r?R.find(e=>e.name===r)??null:null,[r,R]),ce=(0,_.useMemo)(()=>{let e=new Map;for(let t of R){let n=kt(t.name);e.set(n,(e.get(n)??0)+1)}return new Set([...e.entries()].filter(([,e])=>e>1).map(([e])=>e))},[R]);if(R.length===0)return(0,S.jsx)(an,{onAddProvider:a});let le=[{key:`ready`,label:s(`pws.status.ready`),count:ne.ready.length},{key:`needsSetup`,label:s(`pws.status.needsSetup`),count:ne.needsSetup.length},{key:`disabled`,label:s(`prov.disabledBadge`),count:ne.disabled.length}],V=[{id:`ready`,label:s(`pws.status.ready`),count:ie.ready.length,ariaLabel:s(`pws.groupReady`,{count:ie.ready.length}),items:ie.ready},{id:`needs-setup`,label:s(`pws.status.needsSetup`),count:ie.needsSetup.length,ariaLabel:s(`pws.groupNeedsSetup`,{count:ie.needsSetup.length}),items:ie.needsSetup},{id:`disabled`,label:s(`prov.disabledBadge`),count:ie.disabled.length,ariaLabel:s(`pws.groupDisabled`,{count:ie.disabled.length}),items:ie.disabled}],ue=V.flatMap(e=>e.items.map(e=>e.name)),de=x&&ue.includes(x)?x:r&&ue.includes(r)?r:ue[0]??null;return(0,S.jsx)(`div`,{className:`pws-shell-container`,children:(0,S.jsxs)(`div`,{className:`pws-root`,children:[(0,S.jsxs)(`aside`,{className:`pws-rail`,"aria-label":s(`pws.providerList`),children:[(0,S.jsxs)(`div`,{className:`pws-search-row`,children:[(0,S.jsxs)(`div`,{className:`pws-search-wrap`,children:[(0,S.jsx)(te,{className:`pws-search-icon`,width:14,height:14,"aria-hidden":`true`}),(0,S.jsx)(`input`,{type:`search`,className:`input pws-search-input`,placeholder:s(`pws.searchPlaceholder`),value:c,onChange:e=>l(e.target.value),"aria-label":s(`pws.searchPlaceholder`)})]}),(0,S.jsxs)(`div`,{className:`pws-filter-wrap`,ref:L,children:[(0,S.jsxs)(`button`,{type:`button`,className:`pws-filter-btn${ae||y?` pws-filter-btn--active`:``}`,onClick:()=>b(e=>!e),"aria-label":s(`pws.filterAria`),"aria-haspopup":`menu`,"aria-expanded":y,children:[(0,S.jsx)(ge,{width:18,height:18,"aria-hidden":`true`}),ae&&(0,S.jsx)(`span`,{className:`pws-filter-dot`,"aria-hidden":`true`})]}),y&&(0,S.jsxs)(`div`,{className:`pws-filter-menu`,role:`menu`,"aria-label":s(`pws.providerFiltersAria`),children:[(0,S.jsx)(`div`,{className:`pws-filter-title`,children:s(`pws.filters`)}),(0,S.jsx)(`div`,{className:`pws-filter-head`,children:s(`pws.filterStatus`)}),le.map(({key:e,label:t,count:n})=>(0,S.jsxs)(`label`,{className:`pws-filter-option`,role:`menuitemcheckbox`,"aria-checked":u[e],children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:u[e],onChange:()=>d(t=>({...t,[e]:!t[e]}))}),(0,S.jsx)(`span`,{className:`pws-filter-label`,children:t}),(0,S.jsx)(`span`,{className:`pws-filter-count`,children:n})]},e)),(0,S.jsx)(`div`,{className:`pws-filter-head`,children:s(`pws.pricing`)}),(0,S.jsxs)(`label`,{className:`pws-filter-option`,role:`menuitemcheckbox`,"aria-checked":f.free,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:f.free,onChange:()=>p(e=>({...e,free:!e.free}))}),(0,S.jsx)(`span`,{className:`pws-filter-label`,children:s(`modal.badge.free`)}),(0,S.jsx)(`span`,{className:`pws-filter-count`,children:z})]}),(0,S.jsxs)(`label`,{className:`pws-filter-option`,role:`menuitemcheckbox`,"aria-checked":f.paid,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:f.paid,onChange:()=>p(e=>({...e,paid:!e.paid}))}),(0,S.jsx)(`span`,{className:`pws-filter-label`,children:s(`pws.paid`)}),(0,S.jsx)(`span`,{className:`pws-filter-count`,children:B})]}),(0,S.jsx)(`div`,{className:`pws-filter-head`,children:s(`pws.filterType`)}),[{key:`cloud`,label:s(`pws.type.cloud`),count:re.cloud},{key:`local`,label:s(`pws.type.local`),count:re.local},{key:`selfHosted`,label:s(`pws.type.selfHosted`),count:re.selfHosted},{key:`login`,label:s(`pws.type.login`),count:re.login}].map(({key:e,label:t,count:n})=>(0,S.jsxs)(`label`,{className:`pws-filter-option`,role:`menuitemcheckbox`,"aria-checked":m[e],children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:m[e],onChange:()=>h(t=>({...t,[e]:!t[e]}))}),(0,S.jsx)(`span`,{className:`pws-filter-label`,children:t}),(0,S.jsx)(`span`,{className:`pws-filter-count`,children:n})]},e)),(0,S.jsx)(`div`,{className:`pws-filter-head`,children:s(`pws.sort`)}),(0,S.jsx)(`div`,{className:`pws-sort-grid`,role:`group`,"aria-label":s(`pws.sortProvidersAria`),children:nn.map(e=>(0,S.jsx)(`button`,{type:`button`,className:`pws-sort-btn${g===e.id?` pws-sort-btn--active`:``}`,onClick:()=>v(e.id),"aria-pressed":g===e.id,children:s(e.labelKey)},e.id))}),(0,S.jsx)(`div`,{className:`pws-filter-footer`,children:(0,S.jsx)(`button`,{type:`button`,className:`link-btn`,onClick:oe,disabled:!ae,children:s(`pws.resetAll`)})})]})]})]}),(0,S.jsxs)(`div`,{className:`pws-rail-list`,role:`listbox`,"aria-label":s(`pws.providersAria`),onKeyDown:e=>{let t=Array.from(e.currentTarget.querySelectorAll(`[role="option"]`));if(t.length===0)return;let n=document.activeElement,r=t.findIndex(e=>e===n||e.contains(n));if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let n=e.key===`ArrowDown`?1:-1;t[r<0?n>0?0:t.length-1:(r+n+t.length)%t.length]?.focus();return}if(e.key===`Home`){e.preventDefault(),t[0]?.focus();return}e.key===`End`&&(e.preventDefault(),t[t.length-1]?.focus())},children:[Object.values(ie).every(e=>e.length===0)&&(0,S.jsx)(`span`,{className:`muted pws-rail-empty`,role:`status`,children:s(c?`pws.noSearchResults`:ae?`pws.noMatchFilters`:`pws.noProvidersConfigured`)}),V.map(({id:e,label:t,count:a,ariaLabel:o,items:s})=>s.length===0?null:(0,S.jsxs)(`div`,{className:`pws-rail-group`,role:`group`,"aria-label":o,children:[(0,S.jsxs)(`div`,{className:`pws-rail-group-head`,"aria-hidden":`true`,children:[(0,S.jsx)(`span`,{className:`pws-rail-group-label`,children:t}),(0,S.jsx)(`span`,{className:`pws-rail-group-count`,children:a})]}),s.map(e=>(0,S.jsx)(Ft,{item:e,selected:r===e.name,tabbable:de===e.name,modelCount:w[e.name],isDefault:n===e.name,showConfigId:ce.has(kt(e.name)),onClick:()=>i(e.name),onFocus:()=>C(e.name)},e.name))]},e))]})]}),(0,S.jsx)(`main`,{className:`pws-main`,"aria-label":s(`pws.workspaceMainAria`),children:se?o?.(se,{usageTotals:P[se.name],quotaReport:F[se.name],availableModels:E[se.name]??[],selectedModels:O[se.name]??[],modelsLoading:A,modelsLoadFailed:M})??(0,S.jsxs)(`div`,{className:`pws-detail-placeholder`,children:[(0,S.jsx)(`h3`,{children:kt(se.name)}),(0,S.jsx)(`p`,{className:`muted`,children:s(`pws.detailComingSoon`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>i(null),children:s(`modal.back`)})]}):R.length>0?(0,S.jsx)(en,{sections:ne,quotaReports:F,usageTotals:P,onSelectProvider:e=>i(e)}):null})]})})}function an({onAddProvider:e}){let t=U();return(0,S.jsx)(`div`,{className:`pws-empty-root`,children:(0,S.jsxs)(`div`,{className:`pws-empty-hero`,children:[(0,S.jsx)(`div`,{"aria-hidden":`true`,children:(0,S.jsx)(E,{style:{width:64,height:64}})}),(0,S.jsx)(`h2`,{children:t(`pws.connectFirst`)}),(0,S.jsxs)(`div`,{className:`pws-empty-tiles`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`pws-empty-tile`,onClick:()=>e({tier:`free`}),children:[(0,S.jsx)(`span`,{"aria-hidden":`true`,children:(0,S.jsx)(de,{width:18,height:18})}),(0,S.jsx)(`span`,{className:`pws-empty-tile-label`,children:t(`pws.empty.browseFree`)}),(0,S.jsx)(`span`,{className:`pws-empty-tile-desc muted`,children:t(`pws.empty.browseFreeDesc`)})]}),(0,S.jsxs)(`button`,{type:`button`,className:`pws-empty-tile`,onClick:()=>e({tier:`accounts`}),children:[(0,S.jsx)(`span`,{"aria-hidden":`true`,children:(0,S.jsx)(oe,{width:18,height:18})}),(0,S.jsx)(`span`,{className:`pws-empty-tile-label`,children:t(`pws.empty.connectAccount`)}),(0,S.jsx)(`span`,{className:`pws-empty-tile-desc muted`,children:t(`pws.empty.connectAccountDesc`)})]}),(0,S.jsxs)(`button`,{type:`button`,className:`pws-empty-tile`,onClick:()=>e({custom:!0}),children:[(0,S.jsx)(`span`,{"aria-hidden":`true`,children:(0,S.jsx)(ae,{width:18,height:18})}),(0,S.jsx)(`span`,{className:`pws-empty-tile-label`,children:t(`pws.empty.addEndpoint`)}),(0,S.jsx)(`span`,{className:`pws-empty-tile-desc muted`,children:t(`pws.empty.addEndpointDesc`)})]})]})]})})}function on(e){if(Qe(e.name,e))return`codex-accounts`;let t=(e.authMode??``).toLowerCase();if(t===`forward`||t===`local`||pt(e))return null;if(t===`oauth`)return`oauth-accounts`;let n=e.hasApiKey===!0;return!(t===`key`||n||t===``)||e.keyOptional===!0&&!n?null:`api-keys`}function sn(e,t,n){let r=t.email?.trim();if(r)return r;let i=e.findIndex(e=>e.id===t.id);return n(`pws.accountOrdinal`,{count:String(i>=0?i+1:1)})}function cn({item:e,usageTotals:t,quotaReport:n,oauthEmail:r,onEditSettings:i,onViewUsage:a,onUpdateProvider:o}){let s=U(),{locale:c}=H(),l=St(s),u=rt(e),d=s(u===`ready`?`pws.status.connected`:u===`needs-setup`?`pws.status.needsSetup`:`prov.disabledBadge`),f=t?.requests,p=t?.totalTokens,m=It(n);return(0,S.jsxs)(`div`,{className:`pws-overview-layout`,children:[(0,S.jsxs)(`div`,{className:`pws-overview-main`,children:[(0,S.jsxs)(`section`,{className:`pws-section`,"aria-label":s(`pws.connection`),children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:s(`pws.connection`)}),(0,S.jsxs)(`dl`,{className:`pws-kv`,children:[(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`dash.status`)}),(0,S.jsxs)(`dd`,{className:u===`ready`?`pws-status-ok`:`pws-status-warn`,children:[u===`ready`?(0,S.jsx)(M,{style:{width:13,height:13},"aria-hidden":`true`}):(0,S.jsx)(I,{style:{width:13,height:13},"aria-hidden":`true`}),d]})]}),(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`modal.baseUrl`)}),(0,S.jsx)(`dd`,{children:(0,S.jsx)(`code`,{children:e.baseUrl?.trim()?e.baseUrl:`—`})})]}),(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`pws.cell.auth`)}),(0,S.jsx)(`dd`,{children:r?`${Mt(e,s)} · ${r}`:Mt(e,s)})]}),(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`modal.defaultModel`)}),(0,S.jsx)(`dd`,{children:e.defaultModel??(0,S.jsx)(`span`,{className:`muted`,children:`—`})})]}),e.note&&(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`pws.cell.note`)}),(0,S.jsx)(`dd`,{className:`muted`,children:e.note})]})]}),i&&(0,S.jsx)(`button`,{type:`button`,className:`link-btn pws-edit-settings-link`,onClick:i,children:s(`pws.editSettings`)})]}),(0,S.jsxs)(`section`,{className:`pws-section`,"aria-label":s(`pws.authSummary`),children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:s(`pws.authSummary`)}),(0,S.jsxs)(`div`,{className:`pws-auth-summary`,children:[(0,S.jsx)(`span`,{className:`pws-auth-dot`}),(0,S.jsx)(`span`,{children:e.authMode===`forward`?s(`pws.passthrough`):e.authMode===`oauth`?r?s(`pws.loggedInAs`,{email:r}):s(`pws.notLoggedIn`):e.hasApiKey?s(`pws.apiKeyConfigured`):Mt(e,s)})]})]})]}),(0,S.jsxs)(`aside`,{className:`pws-overview-sidebar`,children:[(0,S.jsxs)(`section`,{className:`pws-section`,"aria-label":s(`pws.statsAria`),children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:s(`pws.statsTitle`)}),(0,S.jsxs)(`dl`,{className:`pws-kv`,children:[typeof f==`number`&&(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`pws.stats.totalRequests`)}),(0,S.jsx)(`dd`,{className:`pws-kv-mono`,children:Ct(f,c)})]}),typeof p==`number`&&(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`pws.stats.totalTokens`)}),(0,S.jsx)(`dd`,{className:`pws-kv-mono`,children:wt(p,c)})]}),n&&(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`pws.stats.quotaUpdated`)}),(0,S.jsx)(`dd`,{className:`pws-kv-mono`,title:n.source?Lt(n.source):void 0,children:xt(n.updatedAt,l)})]}),typeof f!=`number`&&typeof p!=`number`&&!n&&(0,S.jsx)(`div`,{className:`muted`,children:s(`pws.usageUnavailable`)})]}),a&&(0,S.jsxs)(`button`,{type:`button`,className:`link-btn pws-view-usage-link`,onClick:a,children:[s(`pws.viewUsage`),` →`]}),m&&(0,S.jsx)(`div`,{className:`muted pws-stats-note`,children:s(`pws.stats.quotaTracked`)})]}),(0,S.jsx)(ln,{item:e,onUpdateProvider:o})]})]})}function ln({item:e,onUpdateProvider:t}){let n=U(),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(!1),l=(0,_.useCallback)(async()=>{if(s||!t)return;let n=a.trim();if(n===(e.note??``)){i(!1);return}c(!0),await t(e.name,{note:n||void 0}),c(!1),i(!1)},[a,e.name,e.note,t,s]);return r?(0,S.jsxs)(`section`,{className:`pws-section pws-notes-section`,"aria-label":n(`pws.notes`),children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:n(`pws.notes`)}),(0,S.jsx)(`textarea`,{className:`pws-notes-textarea`,value:a,onChange:e=>o(e.target.value),onBlur:()=>void l(),onKeyDown:t=>{t.key===`Escape`&&(o(e.note??``),i(!1))},placeholder:n(`pws.notePlaceholder`),autoFocus:!0,rows:3,disabled:s})]}):(0,S.jsxs)(`section`,{className:`pws-section pws-notes-section`,"aria-label":n(`pws.notes`),children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:n(`pws.notes`)}),(0,S.jsx)(`button`,{type:`button`,className:`pws-notes-display`,onClick:()=>{t&&(o(e.note??``),i(!0))},disabled:!t,children:e.note||(0,S.jsx)(`span`,{className:`muted`,children:n(`pws.notePlaceholder`)})})]})}var un=m();function dn(e,t,n){let r=Array(e);return new Proxy(r,{get(r,i,a){if(typeof i==`string`){let a=i.charCodeAt(0);if(a>=48&&a<=57){let a=+i;if(Number.isInteger(a)&&a>=0&&a<e){let e=r[a];if(!e){let i=t[a*2];e=r[a]={index:a,key:n(a),start:i,size:t[a*2+1],end:i+t[a*2+1],lane:0}}return e}}if(i===`length`)return e}return Reflect.get(r,i,a)}})}function fn(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o=e();return o.length!==r.length||o.some((e,t)=>r[t]!==e)?(r=o,i=t(...o),n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1,i):i}return o.updateDeps=e=>{r=e},o}function pn(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var mn=(e,t)=>Math.abs(e-t)<1.01,hn=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},gn,_n=()=>{if(gn!==void 0)return gn;if(typeof navigator>`u`)return gn=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return gn=!0;let e=navigator.maxTouchPoints;return gn=navigator.platform===`MacIntel`&&e!==void 0&&e>0},vn=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},yn=e=>e,bn=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,r=Array(n);for(let e=0;e<n;e++)r[e]=t+e;return r},xn=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(vn(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(vn(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},Sn={passive:!0},Cn=typeof window>`u`?!0:`onscrollend`in window,wn=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&Cn,o=0,s=a?null:hn(i,()=>t(o,!1),e.options.isScrollingResetDelay),c=e=>()=>{o=n(r),s?.(),t(o,e)},l=c(!0),u=c(!1);return r.addEventListener(`scroll`,l,Sn),a&&r.addEventListener(`scrollend`,u,Sn),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u)}},Tn=(e,t)=>wn(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),En=(e,t,n)=>{if(n.options.useCachedMeasurements){let t=n.indexFromElement(e),r=n.options.getItemKey(t);return n.itemSizeCache.get(r)??n.options.estimateSize(t)}if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}if(!t){let t=n.indexFromElement(e),r=n.options.getItemKey(t),i=n.itemSizeCache.get(r);if(i!==void 0)return i}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},Dn=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:e+t,behavior:n})},On=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{let t=e.target,n=this.indexFromElement(t);if(!t.isConnected){this.observer.unobserve(t);for(let[e,n]of this.elementsCache)if(n===t){this.elementsCache.delete(e);break}return}this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{let t={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:yn,rangeExtractor:bn,onChange:()=>{},measureElement:En,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,anchorTo:`start`,followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`,useCachedMeasurements:!1};for(let n in e){let r=e[n];r!==void 0&&(t[n]=r)}let n=this.options,r=null,i=null,a=!1;if(n!==void 0&&n.enabled&&t.enabled&&t.anchorTo===`end`&&this.scrollElement!==null){let e=n.count,o=t.count,s=this.getMeasurements(),c=e>0?s[0]?.key??n.getItemKey(0):null,l=e>0?s[e-1]?.key??n.getItemKey(e-1):null;if(o!==e||e>0&&o>0&&(t.getItemKey(0)!==c||t.getItemKey(o-1)!==l)){a=!0;let c=e>0?this.getVirtualItemForOffset(this.getScrollOffset())??s[0]:null;c&&(r=[c.key,this.getScrollOffset()-c.start]);let u=t.followOnAppend===!0?`auto`:t.followOnAppend||null;u&&o>e&&this.isAtEnd(n.scrollEndThreshold)&&(e===0||t.getItemKey(o-1)!==l)&&(i=u)}}this.options=t,a&&(this.pendingMin=0,this.itemSizeCacheVersion++);let o=!1,s=0;if(r&&this.scrollOffset!==null){let[e,t]=r,n=this.getMeasurements(),{count:i,getItemKey:a}=this.options,c=0;for(;c<i&&a(c)!==e;)c++;if(c<i){let e=n[c];if(e){let n=e.start+t;n!==this.scrollOffset&&(s=n-this.scrollOffset,this.scrollOffset=n,o=!0)}}}(o||i)&&(this.pendingScrollAnchor=[o?r[0]:null,o?r[1]:0,i,s])},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=fn(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}if(this.scrollElement=e,this.scrollElement&&`ownerDocument`in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{if(t&&this._intendedScrollOffset===null&&e===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(e-this._intendedScrollOffset)<1.5&&(e=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;let n=this.getScrollOffset();this.scrollDirection=t?n===e?this.scrollDirection:n<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement){let e=this.scrollElement,t=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},n=()=>{this._iosTouching=!1,!(!_n()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,Sn),e.addEventListener(`touchend`,n,Sn),this.unsubs.push(()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let t=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,t&&this.scrollElement&&this.options.enabled){let[e,n,r,i]=t;e!==null&&!r&&(_n()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?i!==0&&(this._iosDeferredAdjustment+=i):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),r&&this.scrollToEnd({behavior:r})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let e=this.getScrollOffset(),t=this.getMaxScrollOffset();if(e<0||e>t)return;let n=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=n,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,t)=>{let n=new Map,r=new Map;for(let i=t-1;i>=0;i--){let t=e[i];if(n.has(t.lane))continue;let a=r.get(t.lane);if(a==null||t.end>a.end?r.set(t.lane,t):t.end<a.end&&n.set(t.lane,!0),n.size===this.options.lanes)break}return r.size===this.options.lanes?Array.from(r.values()).sort((e,t)=>e.end===t.end?e.index-t.index:e.end-t.end)[0]:void 0},this.getMeasurementOptions=fn(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(e,t,n,r,i,a,o)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o}),{key:!1}),this.getMeasurements=fn(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o},s)=>{let c=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let l=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),a===1){let i=this.options.gap,a=e*2,o=this._flatMeasurements;if(!o||o.length<a){let e=new Float64Array(a);o&&l>0&&e.set(o.subarray(0,l*2)),o=e,this._flatMeasurements=o}let s;if(l===0)s=t+n;else{let e=l-1;s=o[e*2]+o[e*2+1]+i}for(let t=l;t<e;t++){let e=r(t),n=c.get(e),a=typeof n==`number`?n:this.options.estimateSize(t);o[t*2]=s,o[t*2+1]=a,s+=a+i}let u=dn(e,o,r);return this.measurementsCache=u,u}let u=this.measurementsCache.slice(0,l),d=Array(a).fill(void 0);for(let e=0;e<l;e++){let t=u[e];t&&(d[t.lane]=e)}for(let i=l;i<e;i++){let e=r(i),a=this.laneAssignments.get(i),s,l,f=o===`estimate`||c.has(e);if(a!==void 0&&this.options.lanes>1){s=a;let e=d[s],r=e===void 0?void 0:u[e];l=r?r.end+this.options.gap:t+n}else{let e=this.options.lanes===1?u[i-1]:this.getFurthestMeasurement(u,i);l=e?e.end+this.options.gap:t+n,s=e?e.lane:i%this.options.lanes,this.options.lanes>1&&f&&this.laneAssignments.set(i,s)}let p=c.get(e),m=typeof p==`number`?p:this.options.estimateSize(i),h=l+m;u[i]={index:i,start:l,size:m,end:h,key:e,lane:s},d[s]=i}return this.measurementsCache=u,u},{key:!1,debug:()=>this.options.debug}),this.calculateRange=fn(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=jn(e,t,n,r,r===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=fn(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!this.scrollState||this.scrollState.behavior!==`smooth`)return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e),n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{if(e<0||e>=this.options.count)return;let n,r,i,a=this._flatMeasurements;if(this.options.lanes===1&&a!==null)i=this.options.getItemKey(e),r=a[e*2],n=a[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;i=t.key,r=t.start,n=t.size}let o=t-(this.itemSizeCache.get(i)??n);if(o!==0){let a=this.options.anchorTo===`end`&&this.scrollState?.behavior!==`smooth`&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,s=a?this.getTotalSize():0,c=this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?r<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(i)||this.scrollDirection!==`backward`):this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:i,start:r,size:n,end:r+n,lane:0},o,this));(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(i,t),this.itemSizeCacheVersion++,a?this.applyScrollAdjustment(this.getTotalSize()-s):c&&this.applyScrollAdjustment(o),this.notify(!1)}},this.getVirtualItems=fn(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length===0)return;let n=this._flatMeasurements,r=this.options.lanes===1&&n!=null;return pn(t[kn(0,t.length-1,r?e=>n[e*2]:e=>pn(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(e=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=e,this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`)if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t];if(t===`end`&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{let r=this.getOffsetForAlignment(e,t),i=this.now();this.scrollState={index:null,align:t,behavior:n,startedAt:i,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e,r=this.now();this.scrollState={index:null,align:`start`,behavior:t,startedAt:r,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:e=`auto`}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:`end`,behavior:e});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1){let n=e.length-1,r=this._flatMeasurements;t=r==null?e[n]?.end??0:r[n*2]+r[n*2+1]}else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let e=[];if(this.itemSizeCache.size===0)return e;let t=this.getMeasurements();for(let n of t)n&&this.itemSizeCache.has(n.key)&&e.push({index:n.index,key:n.key,start:n.start,size:n.size,end:n.end,lane:n.lane});return e},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this._intendedScrollOffset=e+(t??0),this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){e!==0&&(_n()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=e:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()})}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&mn(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.getScrollOffset()!==t&&this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let e=this.getSize()||600,n=Math.abs(t-this.getScrollOffset()),r=this.scrollState.behavior===`smooth`&&n>e;this.scrollState.lastTargetOffset=t,r||(this.scrollState.behavior=`auto`),this._scrollToOffset(t,{adjustments:void 0,behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}},kn=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function An(e,t,n){let r=0;for(;r<=t;){let i=(r+t)/2|0,a=e[i*2];if(a<n)r=i+1;else if(a>n)t=i-1;else return i}return r>0?r-1:0}function jn(e,t,n,r,i){let a=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:a};if(r===1&&i!==null){let e=An(i,a,n),r=e,o=n+t;for(;r<a&&i[r*2]+i[r*2+1]<o;)r++;return{startIndex:e,endIndex:r}}let o=kn(0,a,t=>e[t].start,n),s=o;if(r===1)for(;s<a&&e[s].end<n+t;)s++;else if(r>1){let i=Array(r).fill(0);for(;s<a&&i.some(e=>e<n+t);){let t=e[s];i[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(a,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var Mn=typeof document<`u`?_.useLayoutEffect:_.useEffect;function Nn({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n=`transform`,...r}){let i=_.useReducer(e=>e+1,0)[1],a=_.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});a.current.enabled=t,a.current.mode=n;let o=e=>{let t=a.current;if(!t.enabled||!t.container)return;let n=e.getTotalSize();if(n!==t.lastSize){t.lastSize=n;let r=e.options.horizontal?`width`:`height`;t.container.style[r]=`${n}px`}let r=!!e.options.horizontal,i=t.mode===`transform`,o=r?`left`:`top`,s=e.options.scrollMargin,c=e.getVirtualItems();for(let n of c){let a=n.start-s,c=e.elementsCache.get(n.key);c&&t.lastPositions.get(c)!==a&&(t.lastPositions.set(c,a),i?c.style.transform=r?`translate3d(${a}px, 0, 0)`:`translate3d(0, ${a}px, 0)`:c.style[o]=`${a}px`)}},s={...r,onChange:(t,n)=>{var s;let c=a.current,l=!0;if(c.enabled){o(t);let e=t.range,n=c.prevRange;l=!n||n.isScrolling!==t.isScrolling||n.startIndex!==e?.startIndex||n.endIndex!==e?.endIndex,l&&(c.prevRange=e?{startIndex:e.startIndex,endIndex:e.endIndex,isScrolling:t.isScrolling}:null)}l&&(e&&n?(0,un.flushSync)(i):i()),(s=r.onChange)==null||s.call(r,t,n)}},[c]=_.useState(()=>{let e=new On(s);return Object.assign(e,{containerRef:t=>{let n=a.current;if(n.container=t,n.lastSize=null,t&&n.enabled){let r=e.getTotalSize();n.lastSize=r;let i=e.options.horizontal?`width`:`height`;t.style[i]=`${r}px`}}})});return c.setOptions(s),Mn(()=>c._didMount(),[]),Mn(()=>c._willUpdate()),Mn(()=>{o(c)}),c}function Pn(e){return Nn({observeElementRect:xn,observeElementOffset:Tn,scrollToFn:Dn,...e})}function Fn({item:e,availableModels:t,selectedModels:n,modelsLoading:r=!1,modelsLoadFailed:i=!1,onRetryModels:a}){let o=U(),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(null),d=(0,_.useRef)(null),f=(0,_.useMemo)(()=>new Set(n),[n]),p=(0,_.useMemo)(()=>Rt(t,e.defaultModel,s),[t,e.defaultModel,s]),m=p.length>40,h=Pn({count:m?p.length:0,getScrollElement:()=>d.current,estimateSize:()=>36,overscan:12}),g=async e=>{try{await navigator.clipboard.writeText(e),u(e),window.setTimeout(()=>u(t=>t===e?null:t),1200)}catch{}},v=(t,n)=>{let r=t===e.defaultModel,i=f.has(t);return(0,S.jsxs)(`div`,{className:`pws-model-row`,style:n,children:[(0,S.jsx)(`span`,{className:`pws-model-id`,title:t,children:t}),(0,S.jsxs)(`span`,{className:`pws-model-meta`,children:[r?(0,S.jsx)(`span`,{className:`pws-model-flag`,children:o(`prov.defaultBadge`)}):null,i?(0,S.jsx)(`span`,{className:`pws-model-flag pws-model-flag--selected`,children:o(`pws.selected`)}):null,(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>{g(t)},"aria-label":o(`pws.copyModelId`),children:o(l===t?`pws.modelCopied`:`pws.copyModelId`)})]})]},t)},y=t.length===0&&!e.defaultModel;return(0,S.jsxs)(`div`,{className:`pws-section`,children:[(0,S.jsxs)(`div`,{className:`pws-section-head`,children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:o(`pws.tab.models`)}),p.length>0&&(0,S.jsx)(`span`,{className:`muted`,children:o(`pws.modelsAvailable`,{count:p.length})})]}),!y&&(0,S.jsx)(`input`,{type:`search`,className:`input pws-model-search`,placeholder:o(`pws.modelSearchPlaceholder`),value:s,onChange:e=>c(e.target.value),"aria-label":o(`pws.modelSearchPlaceholder`)}),r&&y?(0,S.jsx)(`p`,{className:`muted`,role:`status`,children:o(`pws.modelsLoading`)}):i&&y?(0,S.jsxs)(`div`,{role:`alert`,className:`pws-inline-error`,children:[(0,S.jsx)(`span`,{children:o(`pws.modelsLoadFailed`)}),a&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:a,children:o(`pws.retry`)})]}):y?(0,S.jsx)(`p`,{className:`muted`,children:o(`pws.noModels`)}):p.length===0?(0,S.jsx)(`p`,{className:`muted`,role:`status`,children:o(`pws.noModelMatch`)}):m?(0,S.jsx)(`div`,{ref:d,className:`pws-model-list pws-model-list--virtual`,children:(0,S.jsx)(`div`,{style:{height:h.getTotalSize(),position:`relative`},children:h.getVirtualItems().map(e=>v(p[e.index],{position:`absolute`,top:0,left:0,width:`100%`,height:e.size,transform:`translateY(${String(e.start)}px)`}))})}):(0,S.jsx)(`div`,{className:`pws-model-list`,children:p.map(e=>v(e))})]})}function In({item:e,usageTotals:t,quotaReport:n}){let r=U(),{locale:i}=H(),a=St(r),o=t?.requests!==void 0,s=It(n);return(0,S.jsxs)(`div`,{className:`pws-section`,children:[(0,S.jsxs)(`div`,{className:`pws-usage-block`,children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:r(`pws.usageLast30d`)}),o?(0,S.jsxs)(`div`,{className:`pws-usage-metrics`,role:`group`,"aria-label":r(`pws.usageLast30d`),children:[(0,S.jsxs)(`div`,{className:`pws-usage-metric`,children:[(0,S.jsx)(`span`,{className:`pws-usage-metric-value`,children:Ct(t?.requests,i)}),(0,S.jsx)(`span`,{className:`muted`,children:r(`pws.metricRequests`)})]}),(0,S.jsxs)(`div`,{className:`pws-usage-metric`,children:[(0,S.jsx)(`span`,{className:`pws-usage-metric-value`,children:wt(t?.totalTokens,i)}),(0,S.jsx)(`span`,{className:`muted`,children:r(`pws.metricTokens`)})]})]}):(0,S.jsx)(`p`,{className:`muted`,children:r(`pws.usageUnavailable`)})]}),(0,S.jsxs)(`div`,{className:`pws-usage-block`,children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:r(`pws.rateLimits`)}),s?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Yt,{quota:s,plan:null,threshold:80,t:r,layout:`stacked`}),(0,S.jsxs)(`dl`,{className:`pws-kv pws-usage-meta`,children:[n?.source?.trim()&&(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:r(`pws.stats.source`)}),(0,S.jsx)(`dd`,{children:Lt(n.source)})]}),(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:r(`pws.stats.quotaUpdated`)}),(0,S.jsx)(`dd`,{children:xt(n?.updatedAt,a)})]})]})]}):(0,S.jsx)(`p`,{className:`muted`,children:r(`pws.quotaUnavailable`)})]})]})}function Ln({apiBase:e,onClose:t,onAdded:n}){let r=U(),i=(0,_.useRef)(!0),a=(0,_.useRef)(null),o=(0,_.useRef)(null),s=(0,_.useRef)(null);(0,_.useEffect)(()=>()=>{i.current=!1,a.current&&=(clearInterval(a.current),null),o.current&&=(clearTimeout(o.current),null)},[]);let[c,l]=(0,_.useState)(`pick`),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(!1),y=(0,_.useRef)(null),b=(0,_.useRef)(null),x=(0,_.useCallback)(()=>{a.current&&=(clearInterval(a.current),null),o.current&&=(clearTimeout(o.current),null)},[]),C=(0,_.useCallback)(async()=>{let t=s.current;s.current=null,h(``),x(),t&&await fetch(`${e}/api/codex-auth/login/cancel`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({flowId:t})}).catch(()=>{})},[e,x]),w=(0,_.useCallback)(()=>{c===`oauth-waiting`&&C(),t()},[c,t,C]);return(0,_.useEffect)(()=>{y.current=document.activeElement;let e=b.current;if(e){let t=e.querySelector(`input:not([disabled]), button:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1'])`);t&&t.focus()}return()=>{y.current?.focus()}},[]),(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&w()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w]),(0,S.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":r(`codexAuth.addTitle`),className:`modal-overlay`,onClick:w,children:(0,S.jsxs)(`div`,{ref:b,className:`modal-card`,onClick:e=>e.stopPropagation(),style:{maxWidth:440},children:[c===`pick`&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`h3`,{style:{marginBottom:4},children:r(`codexAuth.addTitle`)}),(0,S.jsx)(`p`,{className:`modal-desc`,children:r(`codexAuth.addPickDesc`)}),(0,S.jsx)(`label`,{className:`field-label`,children:r(`codexAuth.addIdLabel`)}),(0,S.jsx)(`input`,{className:`input`,placeholder:r(`codexAuth.addIdPlaceholder`),value:u,onChange:e=>d(e.target.value),style:{marginBottom:12}}),(0,S.jsx)(`button`,{className:`list-row`,onClick:async()=>{p(``);try{let c=u.trim(),d=await fetch(`${e}/api/codex-auth/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(c?{id:c}:{})}),f=await d.json();if(d.status===409){p(r(`codexAuth.oauthAlreadyInProgress`));return}if(f.url){s.current=f.flowId??null,h(f.url),l(`oauth-waiting`),x();let u=f.flowId??``,d=u?`${e}/api/codex-auth/login-status?flowId=${encodeURIComponent(u)}${c?`&accountId=${encodeURIComponent(c)}`:``}`:`${e}/api/codex-auth/login-status`;a.current=setInterval(async()=>{try{let e=await fetch(d).then(e=>e.json());e.status===`done`?(x(),s.current=null,n(),t()):(e.status===`error`||e.status===`expired`)&&(x(),s.current=null,i.current&&(l(`pick`),p(e.error??`Login failed`)))}catch{}},2e3),o.current=setTimeout(()=>{a.current&&(C(),i.current&&(l(`pick`),p(r(`modal.loginTimeout`))))},3e5)}f.error&&!f.url&&p(f.error)}catch(e){p(String(e))}},style:{marginBottom:8},children:(0,S.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[(0,S.jsx)(de,{width:20}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`title`,children:r(`codexAuth.oauthLogin`)}),(0,S.jsx)(`div`,{className:`sub`,children:r(`codexAuth.oauthDesc`)})]})]})}),f&&(0,S.jsx)(`div`,{className:`notice notice-err`,style:{marginTop:8},children:f}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:w,style:{width:`100%`},children:r(`codexAuth.cancel`)})]}),c===`oauth-waiting`&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`h3`,{style:{marginBottom:4},children:r(`codexAuth.oauthLogin`)}),(0,S.jsx)(`p`,{className:`modal-desc`,children:r(`codexAuth.oauthWaiting`)}),(0,S.jsxs)(`button`,{className:`btn btn-ghost`,onClick:async()=>{if(m)try{if(navigator.clipboard?.writeText)await navigator.clipboard.writeText(m);else{let e=document.createElement(`textarea`);e.value=m,e.style.position=`fixed`,e.style.opacity=`0`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}v(!0),setTimeout(()=>{i.current&&v(!1)},2500)}catch{p(r(`codexAuth.loginLinkCopyFailed`))}},disabled:!m,style:{width:`100%`,justifyContent:`center`,marginTop:12},children:[(0,S.jsx)(ce,{width:14}),` `,r(g?`codexAuth.loginLinkCopied`:`codexAuth.copyLoginLink`)]}),f&&(0,S.jsx)(`div`,{className:`notice notice-err`,style:{marginTop:12},children:f}),(0,S.jsx)(`div`,{style:{textAlign:`center`,padding:`24px 0`},children:(0,S.jsx)(`span`,{className:`spin`,style:{width:24,height:24}})}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:w,style:{width:`100%`},children:r(`codexAuth.cancel`)})]})]})})}function Rn({apiBase:e,accountModeState:t=null,banner:n=null,embedded:r=!1}){let i=U(),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(80),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(!1),[C,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(!1),[D,O]=(0,_.useState)(!1),[k,A]=(0,_.useState)(null),[j,M]=(0,_.useState)(!1),[F,L]=(0,_.useState)(`loading`),[te,ne]=(0,_.useState)(null),R=(0,_.useRef)(0),z=(0,_.useCallback)(async(t=!1)=>{let n=++R.current;t||L(`loading`);try{let[r,i]=await Promise.all([fetch(`${e}/api/codex-auth/accounts${t?`?refresh=1`:``}`),fetch(`${e}/api/codex-auth/active`)]);if(!r.ok||!i.ok)throw Error(`account load failed`);let[a,s]=await Promise.all([r.json(),i.json()]);return R.current===n?(o(a.accounts??[]),c(s.activeCodexAccountId??null),u(s.autoSwitchThreshold??80),L(`ready`),!0):!1}catch{return R.current===n&&L(`error`),!1}},[e]);(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{z()},0),t=window.setInterval(()=>{z()},3e4);return()=>{window.clearTimeout(e),window.clearInterval(t)}},[z]);let B=async n=>{if(!te){ne(n??`__main__`);try{let r=await fetch(`${e}/api/codex-auth/active`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:n})});if(!r.ok)throw Error(`account switch failed`);let o=(await r.json().catch(()=>({}))).activeCodexAccountId??n;c(o),f(null),await z();let s=o&&o!==`__main__`?a.find(e=>e.id===o)?.email??i(`pws.accountOrdinal`,{count:`1`}):i(`codexAuth.mainAccount`);g(i(t===`direct`?`codexAuth.poolPreparedToast`:`codexAuth.switched`,{email:s})),y(!1),setTimeout(()=>g(``),5e3)}catch{g(i(`codexAuth.switchFailed`)),y(!0),setTimeout(()=>g(``),5e3)}finally{ne(null)}}},re=async t=>{let n=a.find(e=>e.id===t)?.email??i(`pws.accountOrdinal`,{count:`1`});if(window.confirm(i(`codexAuth.removeConfirm`,{id:n})))try{let n=await fetch(`${e}/api/codex-auth/accounts?id=${encodeURIComponent(t)}`,{method:`DELETE`});if(!n.ok)throw Error(String(n.status));await z()}catch{g(i(`codexAuth.removeFailed`)),y(!0),setTimeout(()=>g(``),5e3)}},ie=async()=>{let t=l>0?0:80;await fetch(`${e}/api/codex-auth/auto-switch`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({threshold:t})}),u(t)},ae=async()=>{x(!0);try{g(i(await z(!0)?`codexAuth.quotaRefreshed`:`codexAuth.quotaRefreshFailed`)),setTimeout(()=>g(``),5e3)}finally{x(!1)}},ce=async t=>{w(t),E(!1),A(null),M(!0);try{let n=await fetch(`${e}/api/codex-auth/reset-credits?accountId=${encodeURIComponent(t.id)}`);n.ok&&A(((await n.json()).credits??[]).sort((e,t)=>new Date(e.granted_at).getTime()-new Date(t.granted_at).getTime()))}catch{}finally{M(!1)}},le=async t=>{O(!0);try{let n=await fetch(`${e}/api/codex-auth/reset-credits/consume`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:t})});if(!n.ok){alert(i(`codexAuth.resetError`));return}let r=await n.json();if(r.code===`reset`||r.code===`already_redeemed`){let e=C?.quota?.resetCredits??1;w(null),E(!1),await z(!0),g(i(`codexAuth.resetSuccess`,{remaining:String(Math.max(0,e-1))})),setTimeout(()=>g(``),5e3)}else r.code===`nothing_to_reset`?alert(i(`codexAuth.resetNothingToReset`)):r.code===`no_credit`?alert(i(`codexAuth.resetNoCredit`)):alert(i(`codexAuth.resetError`))}catch{alert(i(`codexAuth.resetError`))}finally{O(!1)}},V=a.find(e=>e.isMain),ue=a.filter(e=>!e.isMain),de=e=>s===e,fe=!s||s===`__main__`,pe={id:`__main__`,email:V?.email??`Codex App`,plan:V?.plan,isMain:!0,hasCredential:!0,quota:V?.quota??null},me=i(t===`direct`?`codexAuth.prepareForPool`:`codexAuth.setAsNext`);return(0,S.jsxs)(`div`,{children:[!r&&(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{className:`page-title`,children:i(`nav.codexAuth`)}),(0,S.jsxs)(`button`,{className:`btn btn-sm btn-ghost`,onClick:ae,disabled:b,children:[(0,S.jsx)(ee,{width:14}),` `,i(b?`codexAuth.refreshingQuota`:`codexAuth.refreshQuota`)]})]}),h&&(0,S.jsx)(W,{tone:v?`err`:`ok`,children:h}),F===`loading`&&a.length===0&&(0,S.jsx)(`div`,{className:`pwi-auth-state`,role:`status`,children:i(`pws.accountsLoading`)}),F===`error`&&(0,S.jsxs)(`div`,{className:`pwi-auth-state pwi-auth-state--error`,role:`alert`,children:[(0,S.jsx)(`span`,{children:i(`codexAuth.loadFailed`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>void z(),children:i(`pws.retryAccounts`)})]}),n,(0,S.jsxs)(`div`,{className:`card ${fe?`card-active`:``}`,style:{marginBottom:12},children:[(0,S.jsxs)(`div`,{className:`card-head`,children:[(0,S.jsx)(`span`,{className:`dot dot-green`}),(0,S.jsx)(`strong`,{children:i(`codexAuth.mainAccount`)}),(0,S.jsxs)(`span`,{className:`card-badges`,children:[V&&(0,S.jsx)(Hn,{t:i,account:{...V,id:`__main__`},onClick:()=>ce({...V,id:`__main__`})}),(0,S.jsx)(`span`,{className:`badge ${fe?`badge-primary`:`badge-muted`}`,children:i(fe?t===`direct`?`codexAuth.poolPrepared`:`codexAuth.nextSession`:`codexAuth.current`)})]}),!fe&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-account-switch`,onClick:()=>f(pe),children:me}),(0,S.jsxs)(`span`,{className:`card-right`,children:[(0,S.jsx)(oe,{width:14}),` `,i(`codexAuth.appLogin`)]})]}),(0,S.jsxs)(`div`,{className:`card-sub`,children:[V?.email??`Codex App login`,V?.plan?` · ${V.plan}`:``]}),V?.quota&&(0,S.jsx)(Yt,{quota:V.quota,plan:V.plan,threshold:l,t:i})]}),(0,S.jsxs)(`div`,{className:`section-sep`,children:[(0,S.jsx)(`span`,{className:`section-label`,children:i(`codexAuth.accountPool`)}),(0,S.jsx)(`div`,{className:`sep-line`}),(0,S.jsxs)(`button`,{className:`btn btn-sm btn-ghost`,onClick:()=>m(!0),children:[(0,S.jsx)(P,{width:14}),` `,i(`codexAuth.add`)]})]}),ue.length===0&&(0,S.jsx)(Ae,{title:i(`codexAuth.noPool`)}),ue.map(e=>(0,S.jsxs)(`div`,{className:`card ${de(e.id)?`card-active`:``}`,style:{marginBottom:8},children:[(0,S.jsxs)(`div`,{className:`card-head`,children:[(0,S.jsx)(`span`,{className:`dot ${e.needsReauth?`dot-amber`:de(e.id)?`dot-blue`:`dot-muted`}`}),(0,S.jsx)(`strong`,{children:e.email}),(0,S.jsxs)(`span`,{className:`card-badges`,children:[e.plan&&(0,S.jsx)(`span`,{className:`badge badge-green`,children:e.plan}),(0,S.jsx)(Hn,{t:i,account:e,onClick:()=>ce(e)}),e.needsReauth&&(0,S.jsx)(`span`,{className:`badge badge-amber`,children:i(`codexAuth.needsReauth`)}),de(e.id)&&!e.needsReauth&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:i(t===`direct`?`codexAuth.poolPrepared`:`codexAuth.nextSession`)})]}),!de(e.id)&&!e.needsReauth&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-account-switch`,onClick:()=>f(e),children:me}),(0,S.jsx)(`button`,{className:`btn-icon btn-icon-danger card-right`,"aria-label":`${i(`common.remove`)} — ${e.email}`,title:`${i(`common.remove`)} — ${e.email}`,onClick:t=>{t.stopPropagation(),re(e.id)},children:(0,S.jsx)(N,{width:14})})]}),e.needsReauth?(0,S.jsx)(`div`,{className:`card-sub faint`,children:i(`codexAuth.tokenExpired`)}):(0,S.jsx)(Yt,{quota:e.quota,plan:e.plan,threshold:l,t:i})]},e.id)),(0,S.jsxs)(`div`,{className:`card card-row`,style:{marginTop:16},children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`strong`,{children:i(`codexAuth.autoSwitch`)}),(0,S.jsx)(`div`,{className:`card-sub`,children:i(`codexAuth.autoSwitchDesc`)})]}),(0,S.jsx)(`button`,{className:`toggle ${l>0?`on`:``}`,onClick:ie,"aria-pressed":l>0,"aria-label":i(`codexAuth.autoSwitch`),title:i(`codexAuth.autoSwitch`),children:(0,S.jsx)(`span`,{className:`toggle-knob`})})]}),d&&(0,S.jsx)(`div`,{className:`modal-overlay`,onClick:()=>f(null),children:(0,S.jsxs)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsx)(`h3`,{children:t===`direct`?i(`codexAuth.preparePoolTitle`):d.id===`__main__`?i(`codexAuth.switchBack`):i(`codexAuth.switchTitle`)}),(0,S.jsx)(`p`,{className:`modal-desc`,children:t===`direct`?i(`codexAuth.preparePoolDesc`):d.id===`__main__`?i(`codexAuth.switchBackDesc`):i(`codexAuth.switchDesc`)}),(0,S.jsxs)(`div`,{className:`card`,style:{margin:`12px 0`},children:[(0,S.jsx)(`strong`,{children:d.id===`__main__`?V?.email:d.email}),d.plan&&(0,S.jsx)(`span`,{className:`badge badge-green`,style:{marginLeft:8},children:d.plan})]}),d.id!==`__main__`&&(0,S.jsxs)(`div`,{className:`notice-warn`,children:[(0,S.jsx)(I,{width:14}),` `,i(`codexAuth.cacheWarning`)]}),(0,S.jsxs)(`div`,{className:`modal-actions`,children:[(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>f(null),children:i(`codexAuth.cancel`)}),(0,S.jsx)(`button`,{className:`btn btn-primary`,disabled:!!te,onClick:()=>B(d.id===`__main__`?`__main__`:d.id),children:i(te?`pws.accountSwitching`:t===`direct`?`codexAuth.prepareForPool`:`codexAuth.setAsNext`)})]})]})}),C&&(0,S.jsx)(`div`,{className:`modal-overlay`,onClick:()=>{w(null),E(!1),A(null)},children:(0,S.jsx)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),children:T?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{style:{textAlign:`center`,padding:`12px 0`},children:[(0,S.jsx)(`div`,{className:`confirm-icon`,children:(0,S.jsx)(I,{width:22})}),(0,S.jsx)(`h3`,{children:i(`codexAuth.confirmResetTitle`)}),(0,S.jsx)(`p`,{className:`modal-desc`,children:i(`codexAuth.confirmResetDesc`,{count:String(C.quota?.resetCredits??0)})}),k&&k[0]&&(0,S.jsx)(`p`,{className:`faint text-label`,children:i(`codexAuth.confirmWhichCredit`,{date:zn(k[0].granted_at)})}),(0,S.jsx)(`p`,{className:`faint text-label`,children:i(`codexAuth.irreversible`)})]}),(0,S.jsxs)(`div`,{className:`modal-actions`,children:[(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>E(!1),children:i(`codexAuth.cancel`)}),(0,S.jsx)(`button`,{className:`btn btn-primary`,onClick:()=>le(C.id),disabled:D,children:i(D?`codexAuth.redeeming`:`codexAuth.useCredit`)})]})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`h3`,{children:[(0,S.jsx)(se,{width:16}),` `,i(`codexAuth.resetCreditsTitle`)]}),(0,S.jsxs)(`div`,{className:`card-sub`,children:[C.email,C.plan?` · ${C.plan}`:``]}),(0,S.jsx)(`div`,{style:{margin:`16px 0`},children:(C.quota?.resetCredits??0)>0?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`p`,{style:{marginBottom:12},children:i(`codexAuth.resetCreditsAvailable`,{count:String(C.quota?.resetCredits??0)})}),j&&(0,S.jsx)(`p`,{className:`faint text-label`,children:i(`common.loading`)}),k&&k.length>0&&(0,S.jsx)(`div`,{className:`credit-list`,children:k.map((e,t)=>(0,S.jsx)(Vn,{index:t,grantedAt:e.granted_at,expiresAt:e.expires_at,isNext:t===0,t:i},t))}),(0,S.jsx)(`button`,{className:`btn btn-primary`,style:{marginTop:12,width:`100%`},onClick:()=>E(!0),disabled:D,children:i(`codexAuth.useOneCredit`)}),(0,S.jsx)(`p`,{className:`card-sub text-caption`,style:{marginTop:8,textAlign:`center`},children:i(`codexAuth.fifoNote`)})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`p`,{className:`faint`,children:i(`codexAuth.noResetCredits`)}),(0,S.jsx)(`p`,{className:`modal-desc`,children:i(`codexAuth.earnCreditsHint`)})]})})]})})}),p&&(0,S.jsx)(Ln,{apiBase:e,onClose:()=>m(!1),onAdded:()=>{z(),g(i(`codexAuth.accountAdded`)),setTimeout(()=>g(``),5e3)}})]})}function zn(e){let t=new Date(e);return new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`}).format(t)}function Bn(e){return Math.max(0,Math.ceil((new Date(e).getTime()-Date.now())/864e5))}function Vn({index:e,grantedAt:t,expiresAt:n,isNext:r,t:i}){let a=Bn(n),o=a<=7;return(0,S.jsxs)(`div`,{className:`credit-item${r?` credit-next`:``}`,children:[(0,S.jsxs)(`div`,{className:`credit-item-head`,children:[(0,S.jsx)(se,{width:13}),(0,S.jsx)(`span`,{className:`credit-item-label`,children:r?i(`codexAuth.creditNext`):i(`codexAuth.creditLabel`,{n:String(e+1)})}),r&&(0,S.jsx)(`span`,{className:`badge badge-amber text-micro`,style:{padding:`1px 6px`},children:i(`codexAuth.creditNextBadge`)})]}),(0,S.jsxs)(`div`,{className:`credit-item-dates`,children:[(0,S.jsx)(`span`,{children:i(`codexAuth.creditGranted`,{date:zn(t)})}),(0,S.jsx)(`span`,{className:o?`credit-urgent`:``,children:i(`codexAuth.creditExpires`,{date:zn(n),days:String(a)})})]})]})}function Hn({account:e,onClick:t,t:n}){let r=e.quota?.resetCredits;return r===void 0?null:(0,S.jsxs)(`button`,{type:`button`,className:`badge ${typeof r==`number`&&r>0?`badge-amber`:`badge-muted`} badge-clickable`,onClick:e=>{e.stopPropagation(),t()},"aria-label":n(`codexAuth.resetCreditsAria`,{count:String(r)}),children:[(0,S.jsx)(se,{width:12}),r]})}function Un({item:e,apiBase:t,oauth:n,accounts:r=[],keys:i=[],accountLoadState:a=`ready`,switchingAccountId:o=null,busy:s=!1,loginHint:c,authHandlers:l}){let u=U(),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(``),[h,g]=(0,_.useState)(!1),v=on({...e,hasApiKey:e.hasApiKey||i.length>0}),y=v===`oauth-accounts`,b=v===`api-keys`;if(v===`codex-accounts`)return(0,S.jsxs)(`section`,{className:`pwi-section pwi-auth-section`,"aria-label":u(`pws.availableAccounts`),children:[(0,S.jsx)(`h3`,{className:`pwi-section-title`,children:u(`pws.availableAccounts`)}),(0,S.jsx)(`div`,{className:`pwi-auth-body`,children:(0,S.jsx)(Rn,{apiBase:t,embedded:!0})})]});if(!v||!l)return null;let x=c?.provider===e.name?c:null,C=r.length>0||n?.loggedIn===!0,w=async()=>{let t=p.trim();if(!t)return;g(!0);let n=await l.onAddApiKey(e.name,t);g(!1),n&&(m(``),f(!1))};return(0,S.jsxs)(`section`,{className:`pwi-section pwi-auth-section`,"aria-label":u(y?`pws.availableAccounts`:`pws.apiKeys`),children:[(0,S.jsx)(`h3`,{className:`pwi-section-title`,children:u(y?`pws.availableAccounts`:`pws.apiKeys`)}),(0,S.jsxs)(`div`,{className:`pwi-auth-body`,children:[y&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`pwi-auth-status-row`,children:[(0,S.jsx)(`span`,{className:`pwi-auth-dot ${C?`pwi-auth-dot--ok`:`pwi-auth-dot--off`}`,"aria-hidden":`true`}),(0,S.jsx)(`span`,{className:`pwi-auth-status-text`,children:C?r.length>0?u(`pws.loggedInTitle`):n?.email??u(`pws.loggedInTitle`):n?.error||u(`pws.notLoggedInTitle`)}),(0,S.jsx)(`span`,{className:`pwi-auth-actions`,children:C?(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>void l.onLogout(e.name),children:u(`prov.logout`)}):(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,disabled:s,onClick:()=>void l.onLogin(e.name,!1),children:[s?(0,S.jsx)(`span`,{className:`pwi-spin-inline`,"aria-hidden":`true`}):(0,S.jsx)(oe,{style:{width:13,height:13},"aria-hidden":`true`}),u(s?`prov.waitingBrowser`:`prov.login`)]})})]}),s&&x&&(0,S.jsxs)(`div`,{className:`pwi-auth-wait`,children:[(0,S.jsx)(`span`,{className:`pwi-spin-inline`,"aria-hidden":`true`}),(0,S.jsxs)(`div`,{className:`pwi-auth-wait-copy`,children:[(0,S.jsx)(`div`,{className:`pwi-auth-wait-title`,children:u(`prov.waitingBrowser`)}),x.url&&(0,S.jsxs)(`a`,{href:x.url,target:`_blank`,rel:`noreferrer`,className:`pwi-auth-open-link`,children:[(0,S.jsx)(ie,{style:{width:13,height:13}}),` `,u(`prov.didntOpen`)]})]})]}),a===`loading`&&r.length===0&&(0,S.jsxs)(`div`,{className:`pwi-auth-state`,role:`status`,children:[(0,S.jsx)(`span`,{className:`pwi-spin-inline`,"aria-hidden":`true`}),u(`pws.accountsLoading`)]}),a===`error`&&(0,S.jsxs)(`div`,{className:`pwi-auth-state pwi-auth-state--error`,role:`alert`,children:[(0,S.jsx)(`span`,{children:u(`pws.accountsLoadFailed`)}),l.onRetryAccounts&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>void l.onRetryAccounts?.(e.name),children:u(`pws.retryAccounts`)})]}),r.length>0&&(0,S.jsx)(`div`,{className:`pwi-auth-list`,role:`list`,children:r.map(t=>{let n=sn(r,t,u),i=o===t.id;return(0,S.jsxs)(`div`,{className:`pwi-auth-row${t.active?` pwi-auth-row--active`:``}`,role:`listitem`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`pwi-auth-row-main`,onClick:()=>{!t.active&&!t.needsReauth&&!o&&l.onSwitchAccount(e.name,t)},"aria-current":t.active?`true`:void 0,"aria-label":`${n}${t.active?` — ${u(`pws.accountCurrent`)}`:``}`,disabled:!!(t.needsReauth||o&&!i),children:[(0,S.jsx)(`span`,{className:`pwi-auth-dot ${t.needsReauth?`pwi-auth-dot--warn`:t.active?`pwi-auth-dot--ok`:`pwi-auth-dot--off`}`,"aria-hidden":`true`}),(0,S.jsx)(`span`,{className:`pwi-auth-row-label`,children:n}),t.needsReauth&&(0,S.jsx)(`span`,{className:`badge badge-amber`,children:u(`pws.reauth`)}),t.active&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:u(`prov.accountActive`)}),i&&(0,S.jsx)(`span`,{className:`badge badge-muted`,children:u(`pws.accountSwitching`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm pwi-auth-row-remove`,"aria-label":`${u(`common.remove`)} — ${n}`,title:`${u(`common.remove`)} — ${n}`,disabled:!!o,onClick:()=>void l.onRemoveAccount(e.name,t),children:(0,S.jsx)(F,{style:{width:13,height:13},"aria-hidden":`true`})})]},t.id)})}),a===`ready`&&C&&r.length===0&&(0,S.jsx)(`div`,{className:`pwi-auth-state pwi-auth-state--empty`,children:u(`pws.noAccounts`)}),C&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,style:{marginTop:8},onClick:()=>void l.onLogin(e.name,!0),disabled:s||!!o,children:u(`pws.addAccount`)})]}),b&&(0,S.jsxs)(S.Fragment,{children:[i.length>0&&(0,S.jsx)(`div`,{className:`pwi-auth-list`,role:`list`,children:i.map(t=>(0,S.jsxs)(`div`,{className:`pwi-auth-row${t.active?` pwi-auth-row--active`:``}`,role:`listitem`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`pwi-auth-row-main`,onClick:()=>void l.onSwitchApiKey(e.name,t),disabled:t.active,children:[(0,S.jsx)(`span`,{className:`pwi-auth-dot ${t.active?`pwi-auth-dot--ok`:`pwi-auth-dot--off`}`,"aria-hidden":`true`}),(0,S.jsx)(`code`,{className:`pwi-auth-row-label`,children:t.masked}),t.active&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:u(`prov.accountActive`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm pwi-auth-row-remove`,"aria-label":`${u(`common.remove`)} — ${t.label??t.masked}`,title:`${u(`common.remove`)} — ${t.label??t.masked}`,onClick:()=>void l.onRemoveApiKey(e.name,t),children:(0,S.jsx)(F,{style:{width:13,height:13},"aria-hidden":`true`})})]},t.id))}),d?(0,S.jsxs)(`div`,{className:`pwi-auth-add-key`,children:[(0,S.jsx)(`input`,{className:`input`,type:`password`,value:p,onChange:e=>m(e.target.value),placeholder:u(`modal.apiKeyPlaceholder`),autoComplete:`off`,disabled:h}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:()=>void w(),disabled:h||!p.trim(),children:u(h?`pws.saving`:`pws.addKey`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>{f(!1),m(``)},children:u(`common.cancel`)})]}):(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,style:{marginTop:8},onClick:()=>f(!0),children:u(`pws.addKey`)})]})]})]})}var Wn=[`openai-responses`,`openai-chat`,`anthropic`,`google`,`azure-openai`,`cursor`];function Gn({item:e,availableModels:t=[],onUpdateProvider:n,onDirtyChange:r}){let i=U(),a=String(e.authMode??(e.keyOptional?`local`:`key`)),[o,s]=(0,_.useState)(e.adapter),[c,l]=(0,_.useState)(e.baseUrl),[u,d]=(0,_.useState)(e.defaultModel??``),[f,p]=(0,_.useState)(a),[m,h]=(0,_.useState)(e.note??``),[g,v]=(0,_.useState)(!1),[y,b]=(0,_.useState)(null);(0,_.useEffect)(()=>{s(e.adapter),l(e.baseUrl),d(e.defaultModel??``),p(String(e.authMode??(e.keyOptional?`local`:`key`))),h(e.note??``),b(null)},[e.name,e.adapter,e.baseUrl,e.defaultModel,e.authMode,e.keyOptional,e.note]);let x=o.trim()!==e.adapter||c.trim()!==e.baseUrl||u.trim()!==(e.defaultModel??``)||f!==String(e.authMode??(e.keyOptional?`local`:`key`))||m.trim()!==(e.note??``);(0,_.useEffect)(()=>(r?.(x),()=>r?.(!1)),[x,r]);let C=(0,_.useMemo)(()=>{let n=new Set(t);return u.trim()&&n.add(u.trim()),e.defaultModel&&n.add(e.defaultModel),[...n].sort((e,t)=>e.localeCompare(t))},[t,u,e.defaultModel]),w=(0,_.useMemo)(()=>{let e=[...Wn];return o&&!e.includes(o)&&e.unshift(o),e},[o]),T=At(e.name),E=async()=>{if(!n){b({ok:!1,text:i(`pws.updatesUnavailable`)});return}if(!o.trim()||!c.trim()){b({ok:!1,text:i(`pws.adapterBaseRequired`)});return}v(!0),b(null);let t={adapter:o.trim(),baseUrl:c.trim(),defaultModel:u.trim(),authMode:f,note:m.trim()},r=await n(e.name,t);v(!1),b(r.ok?{ok:!0,text:i(`pws.settingsSaved`)}:{ok:!1,text:r.error||i(`prov.saveFailed`)})};return(0,S.jsxs)(`div`,{className:`pwi-settings-form`,children:[(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsxs)(`span`,{className:`pwi-settings-label`,children:[(0,S.jsx)(oe,{style:{width:12,height:12}}),` `,i(`pws.providerId`)]}),(0,S.jsx)(`input`,{className:`input`,value:e.name,readOnly:!0,disabled:!0})]}),(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsx)(`span`,{className:`pwi-settings-label`,children:i(`modal.adapter`)}),T?(0,S.jsx)(`input`,{className:`input`,value:o,readOnly:!0,disabled:!0}):(0,S.jsx)(`select`,{className:`input`,value:o,onChange:e=>s(e.target.value),children:w.map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))})]}),(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsx)(`span`,{className:`pwi-settings-label`,children:i(`modal.baseUrl`)}),(0,S.jsx)(`input`,{className:`input`,value:c,onChange:e=>l(e.target.value),readOnly:T,disabled:T})]}),(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsx)(`span`,{className:`pwi-settings-label`,children:i(`pws.cell.defaultModel`)}),C.length>0?(0,S.jsxs)(`select`,{className:`input`,value:u,onChange:e=>d(e.target.value),children:[(0,S.jsx)(`option`,{value:``,children:i(`pws.defaultModelNone`)}),C.map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))]}):(0,S.jsx)(`input`,{className:`input`,value:u,onChange:e=>d(e.target.value),placeholder:i(`pws.optionalPlaceholder`)})]}),(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsx)(`span`,{className:`pwi-settings-label`,children:i(`pws.authMode`)}),T?(0,S.jsx)(`input`,{className:`input`,value:Mt(e,i),readOnly:!0,disabled:!0}):(0,S.jsxs)(`select`,{className:`input`,value:f,onChange:e=>p(e.target.value),children:[(0,S.jsx)(`option`,{value:`key`,children:i(`modal.badge.apiKey`)}),(0,S.jsx)(`option`,{value:`forward`,children:i(`pws.auth.chatgptPassthrough`)}),(0,S.jsx)(`option`,{value:`oauth`,children:i(`modal.badge.oauth`)}),(0,S.jsx)(`option`,{value:`local`,children:i(`modal.badge.local`)})]})]}),(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsx)(`span`,{className:`pwi-settings-label`,children:i(`pws.note`)}),(0,S.jsx)(`textarea`,{className:`input pwi-settings-textarea`,value:m,onChange:e=>h(e.target.value),rows:2})]}),x&&(0,S.jsxs)(`div`,{className:`pwi-settings-sticky-bar`,children:[(0,S.jsx)(`span`,{className:`muted`,children:i(`pws.settingsUnsavedBar`)}),(0,S.jsxs)(`div`,{className:`pwi-settings-sticky-bar-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>{s(e.adapter),l(e.baseUrl),d(e.defaultModel??``),p(a),h(e.note??``),b(null)},disabled:g,children:i(`pws.discardSettings`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:()=>void E(),disabled:g,children:i(g?`pws.saving`:`pws.saveSettings`)})]})]}),y&&(0,S.jsx)(`div`,{className:y.ok?`pwi-settings-msg pwi-settings-msg--ok`:`pwi-settings-msg pwi-settings-msg--err`,children:y.text})]})}function Kn({item:e,usageTotals:t,quotaReport:n,availableModels:r,selectedModels:i,modelsLoading:a,modelsLoadFailed:o,onRetryModels:s,oauthEmail:c,onDeselect:l,apiBase:u,oauth:d,accounts:f,accountLoadState:p,switchingAccountId:m,keys:h,busyProvider:g,loginHint:v,authHandlers:y,onUpdateProvider:b,isDefault:x,onRemoveProvider:C,onSetDisabled:w}){let T=U(),[E,D]=(0,_.useState)(`overview`),[O,k]=(0,_.useState)(!1),A=e.disabled===!0,j=(0,_.useMemo)(()=>$e(e),[e]),M=(0,_.useMemo)(()=>pt(e),[e]),N=(0,_.useMemo)(()=>on(e),[e]),P=(0,_.useMemo)(()=>[{id:`overview`,label:T(`pws.tab.overview`)},{id:`models`,label:T(`pws.tab.models`)},{id:`usage`,label:T(`pws.tab.usage`)},...N?[{id:`accounts`,label:T(N===`api-keys`?`pws.apiKeys`:`pws.tab.accounts`)}]:[],{id:`settings`,label:T(`pws.tab.settings`)}],[N,T]),ee=(0,_.useCallback)(e=>{O&&E===`settings`&&e!==`settings`&&!window.confirm(T(`pws.unsavedLeaveBody`))||D(e)},[E,O,T]),I=(0,_.useCallback)((e,t)=>{let n;if(e.key===`ArrowRight`)n=(t+1)%P.length;else if(e.key===`ArrowLeft`)n=(t-1+P.length)%P.length;else if(e.key===`Home`)n=0;else if(e.key===`End`)n=P.length-1;else return;e.preventDefault(),ee(P[n].id),e.currentTarget.parentElement?.querySelectorAll(`[role="tab"]`)[n]?.focus()},[ee,P]),L=`pws-tab-${E}`,te=`pws-panel-${E}`;return(0,S.jsxs)(`div`,{className:`pws-detail`,children:[(0,S.jsx)(`div`,{className:`pws-detail-head`,children:(0,S.jsxs)(`button`,{type:`button`,className:`pws-detail-back-link`,onClick:l,children:[(0,S.jsx)(z,{className:`pws-detail-back-chevron`,"aria-hidden":`true`}),T(`pws.allProviders`)]})}),(0,S.jsxs)(`div`,{className:`pws-detail-head-main`,children:[(0,S.jsx)(Pt,{name:e.name,adapter:e.adapter,baseUrl:e.baseUrl,cls:`pws-detail-icon`}),(0,S.jsx)(`div`,{className:`pws-detail-title-wrap`,children:(0,S.jsxs)(`h2`,{className:`pws-detail-title`,children:[kt(e.name),M&&(0,S.jsx)(`span`,{className:`pwi-rail-badge pwi-rail-badge--local`,children:T(`modal.badge.local`)}),!M&&j&&(0,S.jsx)(`span`,{className:`pwi-rail-badge pwi-rail-badge--free`,children:T(`modal.badge.free`)})]})}),(0,S.jsxs)(`div`,{className:`pws-detail-actions`,children:[C&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm btn-icon-only`,onClick:()=>C(e.name),"aria-label":T(`pws.removeConfirmTitle`),title:T(`pws.removeConfirmTitle`),children:(0,S.jsx)(F,{style:{width:15,height:15},"aria-hidden":`true`})}),w&&(0,S.jsxs)(`div`,{className:`pws-detail-toggle`,children:[(0,S.jsx)(`span`,{className:`pws-detail-toggle-label`,children:T(`pws.enabledLabel`)}),(0,S.jsx)(ke,{on:!A,onClick:()=>w(e.name,!A),disabled:x,label:T(`pws.enabledLabel`)})]})]})]}),(0,S.jsx)(`div`,{className:`pws-detail-tabs`,role:`tablist`,children:P.map((e,t)=>(0,S.jsx)(`button`,{type:`button`,role:`tab`,id:`pws-tab-${e.id}`,"aria-controls":`pws-panel-${e.id}`,"aria-selected":E===e.id,tabIndex:E===e.id?0:-1,className:`pws-detail-tab${E===e.id?` pws-detail-tab--active`:``}`,onClick:()=>ee(e.id),onKeyDown:e=>I(e,t),children:e.label},e.id))}),(0,S.jsxs)(`div`,{className:`pws-detail-panel`,role:`tabpanel`,id:te,"aria-labelledby":L,tabIndex:0,children:[E===`overview`&&(0,S.jsx)(cn,{item:e,usageTotals:t,quotaReport:n,oauthEmail:c,onEditSettings:()=>ee(`settings`),onViewUsage:()=>ee(`usage`),onUpdateProvider:b}),E===`models`&&(0,S.jsx)(Fn,{item:e,availableModels:r,selectedModels:i,modelsLoading:a,modelsLoadFailed:o,onRetryModels:s}),E===`usage`&&(0,S.jsx)(In,{item:e,usageTotals:t,quotaReport:n}),E===`accounts`&&(0,S.jsx)(Un,{item:e,apiBase:u,oauth:d,accounts:f,keys:h,accountLoadState:p,switchingAccountId:m,busy:g===e.name,loginHint:v,authHandlers:y}),E===`settings`&&(0,S.jsx)(Gn,{item:e,availableModels:r,onUpdateProvider:b,onDirtyChange:k})]})]})}function qn(e){return e.codexAccountMode===`direct`?`direct`:`pool`}var Jn={xai:`xAI (Grok)`,anthropic:`Anthropic (Claude)`,kimi:`Kimi (Moonshot)`},Yn=e=>Jn[e]??e;function Xn({apiBase:e}){let t=U(),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)([]),[g,v]=(0,_.useState)({}),[y,b]=(0,_.useState)({}),[x,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(!1),[E,D]=(0,_.useState)(null),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(``),[M,N]=(0,_.useState)(!1),[ee,I]=(0,_.useState)(``),[L,te]=(0,_.useState)({}),[ne,R]=(0,_.useState)({}),[B,ae]=(0,_.useState)(null),[se,le]=(0,_.useState)({}),[V,ue]=(0,_.useState)({}),[de,fe]=(0,_.useState)(null),[pe,me]=(0,_.useState)(``),[he,ge]=(0,_.useState)(()=>location.hash.replace(/^#\/?/,``)===`providers/workspace`),[_e,ve]=(0,_.useState)(null),[ye,be]=(0,_.useState)(null),xe=(0,_.useRef)(!0),Se=(0,_.useRef)({}),Ce=(0,_.useRef)(null),H=(e,t)=>{d(e),p(t)};(0,_.useEffect)(()=>(xe.current=!0,()=>{xe.current=!1}),[]),(0,_.useEffect)(()=>{let e=()=>ge(location.hash.replace(/^#\/?/,``)===`providers/workspace`);return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},[]);let we=()=>{location.hash=he?`#providers`:`#providers/workspace`},Te=(0,_.useCallback)(async()=>{try{let t=await(await fetch(`${e}/api/config`)).json();r(t),l(JSON.stringify(t,null,2))}catch{H(t(`prov.loadConfigFail`),!1)}},[e,t]),Ee=(0,_.useCallback)(async()=>{try{let t=(await fetch(`${e}/api/oauth/providers`).then(e=>e.json())).providers??[];h(t);let n=await Promise.all(t.map(async t=>[t,await fetch(`${e}/api/oauth/status?provider=${t}`).then(e=>e.json()).catch(()=>({loggedIn:!1}))]));v(Object.fromEntries(n))}catch{}},[e]),De=(0,_.useCallback)(async(t=!1)=>{try{let n=await fetch(`${e}/api/provider-quotas${t?`?refresh=1`:``}`).then(e=>e.json());b(Object.fromEntries((n.reports??[]).map(e=>[e.provider,e])))}catch{b({})}},[e]),Oe=(0,_.useCallback)(async t=>{let n=[...new Set(t)];return R(e=>{let t={...e};for(let e of n)t[e]=`loading`;return t}),(await Promise.all(n.map(async t=>{let n=(Se.current[t]??0)+1;Se.current[t]=n;try{let r=await fetch(`${e}/api/oauth/accounts?provider=${encodeURIComponent(t)}`);if(!r.ok)throw Error(String(r.status));let i=await r.json();return!xe.current||Se.current[t]!==n?!0:(te(e=>({...e,[t]:{activeAccountId:i.activeAccountId??null,accounts:i.accounts??[]}})),R(e=>({...e,[t]:`ready`})),!0)}catch{return!xe.current||Se.current[t]!==n?!0:(R(e=>({...e,[t]:`error`})),!1)}}))).every(Boolean)},[e]),ke=async(n,r)=>{if(r.active||r.needsReauth||Ce.current)return;let i={provider:n,accountId:r.id};Ce.current=i,ae(i);let a=sn(L[n]?.accounts??[r],r,t);try{if(!(await fetch(`${e}/api/oauth/accounts/active`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:n,accountId:r.id})})).ok){H(t(`prov.accountSwitchFail`),!1);return}let i=await Oe([n]);if(await Promise.all([Ee(),De(!0)]),!i){H(t(`pws.accountsLoadFailed`),!1);return}H(t(`prov.accountSwitched`,{email:a}),!0)}catch{H(t(`prov.accountSwitchFail`),!1)}finally{Ce.current?.provider===i.provider&&Ce.current.accountId===i.accountId&&(Ce.current=null,xe.current&&ae(null))}},G=(0,_.useCallback)(async t=>{let n=await Promise.all(t.map(async t=>[t,(await fetch(`${e}/api/providers/keys?name=${encodeURIComponent(t)}`).then(e=>e.json()).catch(()=>null))?.keys??[]]));ue(Object.fromEntries(n))},[e]),Ae=async(n,r)=>{if(r.active)return;let i=await fetch(`${e}/api/providers/keys/active`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,id:r.id})});i.ok?(H(t(`prov.keySwitched`,{key:r.label??r.masked}),!0),G(Object.keys(V)),De(!0)):H((await i.json().catch(()=>({}))).error||t(`prov.keySwitchFail`),!1)},je=async(n,r)=>{window.confirm(t(`prov.keyRemoveConfirm`,{key:r.label??r.masked}))&&(await fetch(`${e}/api/providers/keys?name=${encodeURIComponent(n)}&id=${encodeURIComponent(r.id)}`,{method:`DELETE`})).ok&&(H(t(`prov.keyRemoved`,{key:r.label??r.masked}),!0),G(Object.keys(V)),Te(),De(!0))},Me=async(n,r)=>{let i=r.trim();if(!i)return!1;try{let r=await fetch(`${e}/api/providers/keys`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,key:i})});return r.ok?(H(t(`prov.keyAdded`,{name:n}),!0),fe(null),await Promise.all([G(Object.keys(V).includes(n)?Object.keys(V):[...Object.keys(V),n]),Te(),De(!0)]),!0):(H((await r.json().catch(()=>({}))).error||t(`prov.keyAddFail`),!1),!1)}catch{return H(t(`prov.keyAddFail`),!1),!1}},Ne=async e=>{await Me(e,pe)&&me(``)},Pe=async(n,r)=>{let i=sn(L[n]?.accounts??[r],r,t);if(window.confirm(t(`prov.accountRemoveConfirm`,{email:i})))try{if(!(await fetch(`${e}/api/oauth/accounts?provider=${encodeURIComponent(n)}&id=${encodeURIComponent(r.id)}`,{method:`DELETE`})).ok){H(t(`prov.accountRemoveFail`,{email:i}),!1);return}H(t(`prov.accountRemoved`,{email:i}),!0),await Oe([n]),await Promise.all([Ee(),De(!0)])}catch{H(t(`prov.accountRemoveFail`,{email:i}),!1)}};(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{Te(),Ee(),De()},0);return()=>window.clearTimeout(e)},[Te,Ee,De]);let Fe=(0,_.useMemo)(()=>n?Object.entries(n.providers).filter(([,e])=>e.authMode===`oauth`).map(([e])=>e):[],[n]);(0,_.useEffect)(()=>{if(Fe.length===0)return;let e=window.setTimeout(()=>{Oe(Fe)},0);return()=>window.clearTimeout(e)},[Oe,Fe]);let Ie=(0,_.useMemo)(()=>n?Object.entries(n.providers).filter(([,e])=>e.hasApiKey&&e.authMode!==`oauth`&&e.authMode!==`forward`).map(([e])=>e):[],[n]);(0,_.useEffect)(()=>{if(Ie.length===0)return;let e=window.setTimeout(()=>{G(Ie)},0);return()=>window.clearTimeout(e)},[G,Ie]);let Le=async()=>{try{let n=JSON.parse(c);(await fetch(`${e}/api/config`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)})).ok?(H(t(`prov.saved`),!0),a(!1),Te(),De(!0)):H(t(`prov.saveFailed`),!1)}catch{H(t(`prov.invalidJson`),!1)}},Re=async(n,r=!1)=>{C(n),d(``),D(null),j(``),I(``);try{let i=await fetch(`${e}/api/oauth/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r?{provider:n,addAccount:!0}:{provider:n})}),a=await i.json();if(!i.ok){H(a.error||t(`prov.loginFailStart`,{provider:Yn(n)}),!1);return}(a.url||a.instructions)&&D({provider:n,url:a.url,instructions:a.instructions});let o=L[n]?.accounts.length??0;for(let i=0;i<150&&xe.current;i++){await new Promise(e=>setTimeout(e,2e3));let i=await fetch(`${e}/api/oauth/status?provider=${n}`).then(e=>e.json()).catch(()=>null);if(i){if(r?(i.accounts?.length??0)>o||i.done===!0&&!i.error:i.loggedIn){v(e=>({...e,[n]:i})),H(t(`prov.loginOk`,{provider:Yn(n),cmd:`ocx sync`}),!0),D(null),j(``),I(``),Te(),Oe(Object.keys(L).includes(n)?Object.keys(L):[...Object.keys(L),n]),De(!0);break}if(i.error){v(e=>({...e,[n]:i})),H(t(`prov.loginError`,{provider:Yn(n),error:i.error}),!1),D(null);break}}}}catch{H(t(`prov.loginRequestFail`,{provider:Yn(n)}),!1)}finally{xe.current&&C(null)}},ze=async n=>{let r=A.trim();if(!(!r||M)){N(!0),I(``);try{let i=await fetch(`${e}/api/oauth/login/code`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:n,input:r})}),a=await i.json().catch(()=>({}));if(!i.ok){I(t(`prov.pasteFail`,{error:a.error||i.statusText}));return}j(``),I(t(`prov.pasteOk`))}catch{I(t(`prov.pasteFail`,{error:`network error`}))}finally{xe.current&&N(!1)}}},Be=async n=>{try{if(!(await fetch(`${e}/api/oauth/logout?provider=${encodeURIComponent(n)}`,{method:`POST`})).ok){H(t(`prov.logoutFail`,{provider:Yn(n)}),!1);return}await Promise.all([Oe([n]),Ee(),Te(),De(!0)]),H(t(`prov.logoutOk`,{provider:Yn(n)}),!0)}catch{H(t(`prov.logoutFail`,{provider:Yn(n)}),!1)}},Ve=async n=>{window.confirm(t(`prov.removeConfirm`,{name:n}))&&((await fetch(`${e}/api/providers?name=${encodeURIComponent(n)}`,{method:`DELETE`})).ok?(H(t(`prov.removed`,{name:n}),!0),Te(),Ee(),De(!0)):H(t(`prov.removeFail`,{name:n}),!1))},He=async(n,r)=>{let i=await fetch(`${e}/api/providers?name=${encodeURIComponent(n)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({disabled:r})});if(i.ok){H(t(r?`prov.disabled`:`prov.enabled`,{name:n}),!0),Te(),Ee(),De(!0);return}H((await i.json().catch(()=>({}))).error||t(r?`prov.disableFail`:`prov.enableFail`,{name:n}),!1)},Ue=async(t,n)=>{try{let r=await fetch(`${e}/api/providers?name=${encodeURIComponent(t)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});return r.ok?(Te(),{ok:!0}):{ok:!1,error:(await r.json().catch(()=>({}))).error||`Update failed`}}catch{return{ok:!1,error:`Network error`}}},We=async n=>{if(!w){T(!0);try{let i=await fetch(`${e}/api/providers?name=openai`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({codexAccountMode:n})});if(!i.ok){H((await i.json().catch(()=>({}))).error||t(`prov.openaiModeSaveFailed`),!1);return}r(e=>e&&{...e,providers:{...e.providers,openai:{...e.providers.openai,codexAccountMode:n}}}),H(t(`prov.openaiModeSaved`,{mode:t(n===`pool`?`prov.openaiModePool`:`prov.openaiModeDirect`)}),!0),n===`pool`&&De(!0)}catch{H(t(`prov.openaiModeSaveFailed`),!1)}finally{xe.current&&T(!1)}}};if(!n)return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h2`,{children:t(`nav.providers`)})}),u?(0,S.jsx)(W,{tone:`err`,children:u}):(0,S.jsx)(`div`,{className:`muted`,children:t(`prov.loadingConfig`)})]});let Ge=Object.entries(n.providers).filter(([e,t])=>(t.hasApiKey||e===`openai-apikey`)&&t.authMode!==`oauth`&&t.authMode!==`forward`&&!m.includes(e)).map(([e])=>e);return he?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{children:t(`nav.providers`)}),(0,S.jsxs)(`div`,{className:`row`,children:[(0,S.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:we,children:t(`pws.classicToggle`)}),(0,S.jsxs)(`button`,{className:`btn btn-primary`,onClick:()=>s(!0),children:[(0,S.jsx)(P,{}),t(`prov.add`)]})]})]}),u&&(0,S.jsx)(W,{tone:f?`ok`:`err`,children:u}),(0,S.jsx)(rn,{providers:n.providers,apiBase:e,defaultProvider:n.defaultProvider,selectedName:_e,onSelect:ve,onAddProvider:e=>{be(e??null),s(!0)},detail:(t,r)=>(0,S.jsx)(Kn,{item:t,usageTotals:r.usageTotals,quotaReport:r.quotaReport,availableModels:r.availableModels,selectedModels:r.selectedModels,modelsLoading:r.modelsLoading,modelsLoadFailed:r.modelsLoadFailed,oauthEmail:g[t.name]?.email,onDeselect:()=>ve(null),apiBase:e,oauth:g[t.name],accounts:L[t.name]?.accounts??[],keys:V[t.name]??[],accountLoadState:ne[t.name]??(t.authMode===`oauth`?`idle`:`ready`),switchingAccountId:B?.provider===t.name?B.accountId:null,busyProvider:x,loginHint:E,authHandlers:{onLogin:Re,onLogout:Be,onSwitchAccount:ke,onRemoveAccount:Pe,onRetryAccounts:async e=>{await Oe([e])},onAddApiKey:Me,onSwitchApiKey:Ae,onRemoveApiKey:je},isDefault:t.name===n.defaultProvider,onRemoveProvider:Ve,onSetDisabled:He,onUpdateProvider:Ue},t.name)}),o&&(0,S.jsx)(dt,{apiBase:e,existingNames:Object.keys(n.providers),initialTier:ye?.tier,initialCustom:ye?.custom,onClose:()=>{s(!1),be(null)},onAdded:e=>{s(!1),be(null),H(t(`prov.added`,{name:e,cmd:`ocx sync`}),!0),Te(),Ee(),De(!0)}})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{children:t(`nav.providers`)}),(0,S.jsxs)(`div`,{className:`row`,children:[(0,S.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:we,children:t(he?`pws.classicToggle`:`pws.workspaceToggle`)}),i?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`button`,{className:`btn btn-primary`,onClick:Le,children:t(`common.save`)}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>{a(!1),l(JSON.stringify(n,null,2))},children:t(`common.cancel`)})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`btn btn-primary`,onClick:()=>s(!0),children:[(0,S.jsx)(P,{}),t(`prov.add`)]}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>a(!0),children:t(`prov.editJson`)})]})]})]}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`prov.subtitle`)}),u&&(0,S.jsx)(W,{tone:f?`ok`:`err`,children:u}),(0,S.jsxs)(`div`,{className:`panel panel-accent`,style:{marginBottom:18},children:[(0,S.jsxs)(`div`,{className:`row`,style:{marginBottom:14},children:[(0,S.jsx)(oe,{style:{width:16,height:16,color:`var(--accent)`}}),(0,S.jsx)(`span`,{className:`font-semibold`,children:t(`prov.accountLogin`)})]}),(0,S.jsxs)(`div`,{className:`oauth-grid`,children:[m.length===0&&Ge.length===0&&(0,S.jsx)(`span`,{className:`muted text-control`,style:{gridColumn:`1 / -1`},children:t(`prov.noOauth`)}),m.map(e=>{let n=g[e]??{loggedIn:!1},r=x===e,i=Ot(e);return(0,S.jsxs)(`div`,{className:`oauth-row`,children:[(0,S.jsxs)(`span`,{className:`oauth-name`,title:Yn(e),children:[(0,S.jsx)(`span`,{className:`provider-icon provider-icon-sm`,children:i&&(0,S.jsx)(`img`,{src:i,alt:``,"aria-hidden":`true`})}),(0,S.jsx)(`span`,{className:`oauth-name-text`,children:e})]}),(0,S.jsxs)(`span`,{className:`oauth-status`,children:[(0,S.jsx)(`span`,{className:`dot ${n.loggedIn?`dot-green`:`dot-muted`}`}),n.loggedIn?(0,S.jsx)(`span`,{className:`oauth-email`,style:{color:`var(--green)`},children:n.email??t(`prov.loggedIn`)}):(0,S.jsx)(`span`,{className:`oauth-email muted`,children:t(`prov.notLoggedIn`)})]}),(0,S.jsx)(`span`,{className:`oauth-actions`,children:n.loggedIn?(0,S.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>Be(e),children:t(`prov.logout`)}):(0,S.jsx)(`button`,{className:`btn btn-primary btn-sm`,onClick:()=>Re(e),disabled:r,children:r?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`spin`}),t(`prov.waitingBrowser`)]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(oe,{}),t(`prov.login`)]})})}),E?.provider===e&&(E.url||E.instructions||r)&&(0,S.jsxs)(`span`,{className:`oauth-login-hint muted`,children:[(0,S.jsxs)(`span`,{className:`oauth-login-hint-links`,children:[E.url&&(0,S.jsxs)(`a`,{href:E.url,target:`_blank`,rel:`noreferrer`,className:`link-btn`,style:{display:`inline-flex`,alignItems:`center`,gap:5},children:[(0,S.jsx)(ie,{width:14,height:14}),t(`prov.didntOpen`)]}),(0,S.jsxs)(`button`,{className:`link-btn`,onClick:()=>{E?.url&&navigator.clipboard.writeText(E.url).then(()=>{k(!0),setTimeout(()=>k(!1),2500)}).catch(()=>{})},style:{display:`inline-flex`,alignItems:`center`,gap:5},children:[(0,S.jsx)(ce,{width:14,height:14}),t(O?`prov.linkCopied`:`prov.copyLink`)]}),E.instructions&&(0,S.jsx)(`span`,{children:E.instructions})]}),(0,S.jsxs)(`span`,{className:`oauth-login-paste`,children:[(0,S.jsx)(`input`,{className:`input`,type:`text`,autoComplete:`off`,spellCheck:!1,value:A,onChange:e=>j(e.target.value),onKeyDown:t=>{t.key===`Enter`&&(t.preventDefault(),ze(e))},placeholder:t(`prov.pasteRedirect`),"aria-label":t(`prov.pasteRedirect`),disabled:M}),(0,S.jsx)(`button`,{className:`btn btn-ghost btn-sm`,type:`button`,disabled:M||!A.trim(),onClick:()=>void ze(e),children:t(M?`prov.pasteSubmitting`:`prov.pasteSubmit`)})]}),(0,S.jsx)(`span`,{className:`text-caption`,children:ee||t(`prov.pasteRedirectHint`)})]})]},e)}),Ge.map(e=>{let r=n?.providers[e],i=Ot(e),a=r?.keyOptional===!0&&!r?.hasApiKey,o=e===`openai-apikey`&&!r?.hasApiKey;return(0,S.jsxs)(`div`,{className:`oauth-row`,children:[(0,S.jsxs)(`span`,{className:`oauth-name`,title:e,children:[(0,S.jsx)(`span`,{className:`provider-icon provider-icon-sm`,children:i&&(0,S.jsx)(`img`,{src:i,alt:``,"aria-hidden":`true`})}),(0,S.jsx)(`span`,{className:`oauth-name-text`,children:e})]}),(0,S.jsxs)(`span`,{className:`oauth-status`,children:[(0,S.jsx)(`span`,{className:`dot ${o?`dot-amber`:`dot-green`}`}),(0,S.jsx)(`span`,{className:`oauth-email muted`,children:t(o?`prov.openaiApiMissing`:a?`modal.badge.free`:`prov.hasApiKey`)})]}),(0,S.jsx)(`span`,{className:`oauth-actions`,children:o&&(0,S.jsx)(`button`,{className:`btn btn-primary btn-sm`,onClick:()=>s(!0),children:t(`prov.openaiApiSetup`)})})]},e)})]})]}),i?(0,S.jsx)(`textarea`,{className:`input`,value:c,onChange:e=>l(e.target.value),style:{height:400}}):(0,S.jsxs)(`div`,{className:`stack`,style:{gap:8},children:[(0,S.jsxs)(`div`,{className:`muted text-control`,style:{marginBottom:4},children:[t(`prov.port`),`: `,(0,S.jsx)(`code`,{className:`chip`,children:n.port}),` · `,t(`prov.default`),`: `,(0,S.jsx)(`code`,{className:`chip`,children:n.defaultProvider})]}),Object.entries(n.providers).map(([e,r])=>{let i=e===n.defaultProvider,a=r.disabled===!0,o=y[e]?.quota??null,s=Ot(e),c=r.authMode===`oauth`?L[e]:void 0,l=r.authMode!==`oauth`&&r.authMode!==`forward`&&r.hasApiKey?V[e]??[]:[],u=!!c&&c.accounts.length>0||l.length>0,d=se[e]===!0,f=c?.accounts.length??l.length,p=e===`openai`?qn(r):null,m=p===`direct`?t(`prov.openaiDirectDesc`):p===`pool`?t(`prov.openaiPoolDesc`):e===`openai-apikey`?t(`prov.openaiApiDesc`):r.note;return(0,S.jsxs)(`div`,{className:`card prov-card${a?` prov-card-disabled`:``}`,children:[(0,S.jsxs)(`div`,{className:`prov-card-main`,children:[(0,S.jsxs)(`div`,{className:`prov-card-info`,children:[s&&(0,S.jsx)(`span`,{className:`provider-icon`,children:(0,S.jsx)(`img`,{src:s,alt:``,"aria-hidden":`true`})}),(0,S.jsxs)(`div`,{className:`prov-card-copy`,children:[(0,S.jsxs)(`div`,{className:`prov-title`,children:[(0,S.jsx)(`span`,{className:`font-semibold`,children:e}),i&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:t(`prov.defaultBadge`)}),a?(0,S.jsx)(`span`,{className:`badge badge-muted`,children:t(`prov.disabledBadge`)}):(0,S.jsx)(`span`,{className:`badge badge-green`,children:t(`prov.activeBadge`)}),r.authMode===`oauth`&&(0,S.jsx)(`span`,{className:`badge badge-accent`,children:`oauth`}),p===`direct`&&(0,S.jsx)(`span`,{className:`badge badge-green`,children:t(`prov.openaiModeDirect`)}),p===`pool`&&(0,S.jsx)(`span`,{className:`badge badge-accent`,children:t(`prov.openaiModePool`)}),e===`openai-apikey`&&(0,S.jsx)(`span`,{className:`badge badge-muted`,children:t(`modal.badge.apiKey`)}),e!==`openai`&&r.authMode===`forward`&&!r.codexAccountMode&&(0,S.jsx)(`span`,{className:`badge badge-amber`,children:`passthrough`}),r.keyOptional&&(0,S.jsx)(`span`,{className:`badge badge-green`,children:t(`modal.badge.free`)})]}),(0,S.jsxs)(`div`,{className:`muted prov-meta text-control`,children:[(0,S.jsx)(`code`,{className:`chip`,children:r.adapter}),(0,S.jsx)(`span`,{children:r.baseUrl}),r.defaultModel&&(0,S.jsx)(`span`,{children:r.defaultModel}),r.hasApiKey&&(0,S.jsx)(`span`,{children:t(`prov.hasApiKey`)}),r.hasHeaders&&(0,S.jsx)(`span`,{children:t(`prov.hasHeaders`)})]}),m&&(0,S.jsxs)(`div`,{className:`muted text-label leading-body`,style:{marginTop:4},children:[m,p&&(0,S.jsxs)(S.Fragment,{children:[` · `,(0,S.jsx)(`a`,{href:`#codex-auth`,children:t(`prov.manageCodexAccounts`)})]})]}),p&&(0,S.jsxs)(`div`,{className:`openai-mode-row`,children:[(0,S.jsx)(`span`,{id:`openai-account-mode-label`,className:`text-label font-semibold`,children:t(`prov.openaiAccountMode`)}),(0,S.jsx)(`div`,{className:`usage-segmented openai-mode-control`,role:`radiogroup`,"aria-labelledby":`openai-account-mode-label`,children:[`pool`,`direct`].map(e=>(0,S.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":p===e,className:`usage-segmented-btn${p===e?` active`:``}`,disabled:w,onClick:()=>void We(e),children:t(e===`pool`?`prov.openaiModePool`:`prov.openaiModeDirect`)},e))})]})]})]}),(0,S.jsxs)(`div`,{className:`provider-actions`,children:[(0,S.jsxs)(`button`,{className:`btn ${a?`btn-primary`:`btn-ghost`} btn-sm`,onClick:()=>He(e,!a),disabled:i,title:i?t(`prov.defaultCannotDisable`):void 0,"aria-label":t(a?`prov.enableAria`:`prov.disableAria`,{name:e}),children:[i?(0,S.jsx)(oe,{}):(0,S.jsx)(re,{}),t(a?`prov.enable`:`prov.disable`)]}),(0,S.jsxs)(`button`,{className:`btn btn-danger btn-sm`,onClick:()=>Ve(e),"aria-label":t(`sub.removeAria`,{m:e}),children:[(0,S.jsx)(F,{}),t(`common.remove`)]})]})]}),o&&(0,S.jsx)(Yt,{quota:o,threshold:80,t,className:`provider-quota`}),u&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`prov-accounts-toggle${d?` open`:``}`,onClick:()=>le(t=>({...t,[e]:!d})),"aria-expanded":d,"aria-label":t(`prov.accountsAria`,{name:e}),children:[t(`prov.accounts`,{n:String(f)}),(0,S.jsx)(`span`,{className:`chev`,children:(0,S.jsx)(z,{})})]}),d&&(0,S.jsxs)(`div`,{className:`prov-accounts-list`,children:[(c?.accounts??[]).map(n=>{let r=sn(c?.accounts??[n],n,t);return(0,S.jsxs)(`button`,{className:`prov-account-row${n.active?` active`:``}`,onClick:()=>ke(e,n),title:n.active?void 0:t(`prov.accountSwitchTitle`),children:[(0,S.jsx)(`span`,{className:`dot ${n.needsReauth?`dot-amber`:n.active?`dot-green`:`dot-muted`}`}),(0,S.jsx)(`span`,{className:`prov-account-email`,children:r}),n.needsReauth&&(0,S.jsx)(`span`,{className:`badge badge-amber`,children:t(`prov.accountReauth`)}),n.active&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:t(`prov.accountActive`)}),(0,S.jsx)(`span`,{className:`prov-account-remove`,role:`button`,"aria-label":t(`prov.accountRemoveAria`,{email:r}),onClick:t=>{t.stopPropagation(),Pe(e,n)},children:(0,S.jsx)(F,{style:{width:13,height:13}})})]},n.id)}),l.map(n=>(0,S.jsxs)(`button`,{className:`prov-account-row${n.active?` active`:``}`,onClick:()=>Ae(e,n),title:n.active?void 0:t(`prov.keySwitchTitle`),children:[(0,S.jsx)(`span`,{className:`dot ${n.active?`dot-green`:`dot-muted`}`}),(0,S.jsx)(`span`,{className:`prov-account-email mono`,children:n.label?`${n.label} · ${n.masked}`:n.masked}),n.active&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:t(`prov.accountActive`)}),(0,S.jsx)(`span`,{className:`prov-account-remove`,role:`button`,"aria-label":t(`prov.keyRemoveAria`,{key:n.label??n.masked}),onClick:t=>{t.stopPropagation(),je(e,n)},children:(0,S.jsx)(F,{style:{width:13,height:13}})})]},n.id)),c?(0,S.jsx)(`button`,{className:`prov-account-row prov-account-add`,onClick:()=>Re(e,!0),disabled:x===e,children:x===e?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`spin`}),t(`prov.waitingBrowser`)]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(P,{style:{width:13,height:13}}),t(`prov.accountAdd`)]})}):de===e?(0,S.jsxs)(`div`,{className:`prov-account-row prov-account-keyform`,children:[(0,S.jsx)(`input`,{className:`input input-sm mono`,type:`password`,autoFocus:!0,placeholder:t(`prov.keyPlaceholder`),value:pe,onChange:e=>me(e.target.value),onKeyDown:t=>{t.key===`Enter`&&Ne(e),t.key===`Escape`&&(fe(null),me(``))}}),(0,S.jsx)(`button`,{className:`btn btn-primary btn-sm`,onClick:()=>Ne(e),disabled:!pe.trim(),children:t(`common.save`)}),(0,S.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>{fe(null),me(``)},children:t(`common.cancel`)})]}):(0,S.jsxs)(`button`,{className:`prov-account-row prov-account-add`,onClick:()=>{fe(e),me(``)},children:[(0,S.jsx)(P,{style:{width:13,height:13}}),t(`prov.keyAdd`)]})]})]})]},e)})]}),o&&(0,S.jsx)(dt,{apiBase:e,existingNames:Object.keys(n.providers),onClose:()=>s(!1),onAdded:e=>{s(!1),H(t(`prov.added`,{name:e,cmd:`ocx sync`}),!0),Te(),Ee(),De(!0)}})]})}var Zn={"gpt-5.6-sol":le,"gpt-5.6-terra":de,"gpt-5.6-luna":V},Qn={width:14,height:14,flexShrink:0,verticalAlign:`text-bottom`,marginRight:4};function $n(e){return e.slice(e.lastIndexOf(`/`)+1)}function er(e){return Zn[e]??Zn[$n(e)]??null}function tr(e){let t=er(e);return t?(0,_.createElement)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:4}},(0,_.createElement)(t,{style:Qn}),e):e}var nr=Array.from({length:18},(e,t)=>1e5+t*5e4),rr=new Set(nr),ir=`custom`,ar=[4,8,16,32,64,128,256,500,1e3],or=new Set(ar),sr=60;function cr(e){return!Number.isFinite(e)||e<=0?String(e):e%1e3==0?`${e/1e3}k`:e.toLocaleString()}function lr(e){let t=new Set;for(let n of e)n.disabled&&t.add(n.namespaced);return t}function ur(e,t){let n=[];for(let r of e)!t.has(r.id)&&!t.has(r.namespaced)&&n.push({value:r.namespaced,label:r.namespaced});return n}function dr({apiBase:e}){let t=U(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(new Set),[o,s]=(0,_.useState)({}),[c,l]=(0,_.useState)({}),[u,d]=(0,_.useState)({}),[f,p]=(0,_.useState)(35e4),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(!1),[y,b]=(0,_.useState)(()=>{try{let e=localStorage.getItem(`ocx-models-collapsed`);return e?new Set(JSON.parse(e)):new Set}catch{return new Set}}),[x,C]=(0,_.useState)(``),[w,T]=(0,_.useState)(!1),[D,O]=(0,_.useState)(!0),[k,A]=(0,_.useState)(!1),j=(0,_.useRef)(!1),[M,N]=(0,_.useState)(null),[P,ee]=(0,_.useState)(!1),[F,I]=(0,_.useState)(``),te=(0,_.useRef)(!1),[ne,R]=(0,_.useState)(``),[B,re]=(0,_.useState)(!1),[ie,ae]=(0,_.useState)(!1),[oe,se]=(0,_.useState)(null),[ce,le]=(0,_.useState)(!1),V=(0,_.useMemo)(()=>ur(n,i),[n,i]),ue=(0,_.useCallback)(async()=>{try{let t=await fetch(`${e}/api/shadow-call-settings`);t.ok&&se(await t.json())}catch{}},[e]),de=(0,_.useCallback)(async()=>{if(!te.current)try{let t=await fetch(`${e}/api/v2`);if(!t.ok||!(t.headers.get(`content-type`)??``).includes(`application/json`)){N(null);return}let n=await t.json();typeof n.enabled==`boolean`&&N({enabled:n.enabled,agentsMaxThreadsConflict:n.agentsMaxThreadsConflict===!0,maxConcurrentThreadsPerSession:typeof n.maxConcurrentThreadsPerSession==`number`?n.maxConcurrentThreadsPerSession:null,multiAgentMode:n.multiAgentMode===`v1`||n.multiAgentMode===`v2`?n.multiAgentMode:`default`})}catch{N(null)}},[e]),fe=(0,_.useCallback)(async()=>{try{let[t,n]=await Promise.all([fetch(`${e}/api/models`).then(e=>e.json()),fetch(`${e}/api/provider-context-caps`).then(e=>e.json())]);de(),ue(),r(t),a(lr(t));let i=typeof n.value==`number`&&Number.isFinite(n.value)&&n.value>0?n.value:typeof n.cap==`number`&&Number.isFinite(n.cap)&&n.cap>0?n.cap:void 0;i!==void 0&&p(i),d(n.caps??{})}catch{T(!1),C(t(`models.loadFail`))}finally{O(!1)}},[e,ue,de,t]);(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{fe()},0),t=window.setInterval(()=>{j.current||fe()},1e4);return()=>{window.clearTimeout(e),window.clearInterval(t)}},[fe]);let pe=(0,_.useMemo)(()=>{let e={};for(let t of n)(e[t.provider]??=[]).push(t);return Object.entries(e).sort(([e,t],[n,r])=>{let i=t.every(e=>e.native);return i===r.every(e=>e.native)?e.localeCompare(n):i?-1:1})},[n]),me=async n=>{A(!0),j.current=!0,C(``);try{(await fetch(`${e}/api/disabled-models`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({models:[...n]})})).ok?(a(n),T(!0),C(t(`models.applied`))):(T(!1),C(t(`models.saveFailed`)))}catch{T(!1),C(t(`models.networkError`))}finally{A(!1),j.current=!1}},he=e=>{let t=new Set(i);t.has(e)?t.delete(e):t.add(e),me(t)},ge=async n=>{A(!0),j.current=!0,C(``);let r=u[n]!==f;try{let i=await fetch(`${e}/api/provider-context-caps`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:n,enabled:r})});i.ok?(d((await i.json()).caps??{}),T(!0),C(t(`models.capApplied`)),await fe()):(T(!1),C(t(`models.capSaveFailed`)))}catch{T(!1),C(t(`models.networkError`))}finally{A(!1),j.current=!1}},_e=e=>{b(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{localStorage.setItem(`ocx-models-collapsed`,JSON.stringify([...n]))}catch{}return n})},ve=async n=>{A(!0),j.current=!0,C(``);try{let r=await fetch(`${e}/api/provider-context-caps`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(r.ok){let e=await r.json();typeof e.value==`number`&&Number.isFinite(e.value)&&e.value>0&&p(e.value),d(e.caps??{}),T(!0),C(t(`models.capApplied`)),await fe()}else T(!1),C(t(`models.capSaveFailed`))}catch{T(!1),C(t(`models.networkError`))}finally{A(!1),j.current=!1}},ye=e=>{!Number.isFinite(e)||e<=0||ve({value:Math.floor(e)})},be=e=>{if(e===ir){v(!0),h(String(f));return}v(!1);let t=Number(e);Number.isFinite(t)&&t>0&&t!==f&&ye(t)},xe=()=>{let e=Number(m.replace(/[_,\s]/g,``));if(!Number.isFinite(e)||e<=0){T(!1),C(t(`models.capSaveFailed`));return}v(!1),ye(e)},Se=(0,_.useMemo)(()=>{let e=pe.filter(([,e])=>!e.every(e=>e.native));return e.length>0&&e.every(([e])=>u[e]===f)},[pe,u,f]),Ce=()=>{ve({setAll:!Se})},H=async t=>{if(!(!oe||ce)){le(!0),se({...oe,...t});try{await fetch(`${e}/api/shadow-call-settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})}finally{le(!1)}}},we=async n=>{if(!(!M||te.current)&&M.multiAgentMode!==n){ee(!0),te.current=!0,I(``),C(``);try{let r=await fetch(`${e}/api/v2`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({multiAgentMode:n})}),i=await r.json().catch(()=>null);r.ok&&i?(de(),T(!0),C(t(`models.v2Applied`)),I((i.warnings??[]).join(` `))):(T(!1),C(i?.error??t(`models.saveFailed`)))}catch{T(!1),C(t(`models.networkError`))}finally{ee(!1),te.current=!1}}},Te=async n=>{if(!(!M||te.current)){if(!Number.isInteger(n)||n<1){T(!1),C(t(`models.v2ThreadsInvalid`));return}if(M.maxConcurrentThreadsPerSession!==n){ee(!0),te.current=!0,I(``),C(``);try{let r=await fetch(`${e}/api/v2`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({maxConcurrentThreadsPerSession:n})}),i=await r.json().catch(()=>null);r.ok&&i&&typeof i.enabled==`boolean`?(N({enabled:i.enabled,agentsMaxThreadsConflict:i.agentsMaxThreadsConflict===!0,maxConcurrentThreadsPerSession:typeof i.maxConcurrentThreadsPerSession==`number`?i.maxConcurrentThreadsPerSession:null,multiAgentMode:i.multiAgentMode===`v1`||i.multiAgentMode===`v2`?i.multiAgentMode:`default`}),T(!0),C(t(`models.v2ThreadsApplied`)),re(!1)):(T(!1),C(i?.error??t(`models.saveFailed`)))}catch{T(!1),C(t(`models.networkError`))}finally{ee(!1),te.current=!1}}}},Ee=e=>{if(e===ir){re(!0),R(String(M?.maxConcurrentThreadsPerSession??``));return}re(!1),Te(Number(e))};return D?(0,S.jsxs)(`div`,{className:`row muted`,children:[(0,S.jsx)(`span`,{className:`spin`}),` `,t(`models.loading`)]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{children:t(`nav.models`)}),(0,S.jsx)(`span`,{className:`muted mono text-label`,children:t(`models.active`,{active:n.length-i.size,total:n.length})})]}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`models.subtitle`)}),x&&(0,S.jsx)(W,{tone:w?`ok`:`err`,children:x}),(0,S.jsxs)(`div`,{className:`row muted text-control`,style:{gap:6,marginBottom:8,alignItems:`center`},children:[(0,S.jsxs)(`span`,{title:t(`models.shadowCallInterceptHint`),style:{cursor:`help`},children:[t(`models.shadowCallIntercept`),` ⓘ`]}),(0,S.jsx)(`code`,{className:`text-caption`,style:{opacity:.6},children:`⚠ 5.4-mini →`}),(0,S.jsx)(ke,{on:oe?.enabled??!1,onClick:()=>void H({enabled:!oe?.enabled}),disabled:!oe||ce,label:t(`models.shadowCallIntercept`)}),(0,S.jsx)(G,{value:oe?.model??``,options:[{value:``,label:`—`},...V],onChange:e=>{se(t=>t&&{...t,model:e}),H({model:e})},disabled:!oe||ce||!oe.enabled,label:t(`models.shadowCallIntercept`)})]}),M&&(0,S.jsxs)(`div`,{className:`row`,style:{gap:8,marginBottom:8,flexWrap:`wrap`,alignItems:`center`},children:[(0,S.jsx)(`span`,{className:`muted text-control`,children:t(`models.v2Label`)}),(0,S.jsx)(`div`,{className:`segmented`,role:`radiogroup`,"aria-label":t(`models.v2Label`),style:{display:`inline-flex`,borderRadius:`var(--radius-pill)`,background:`var(--surface-soft, var(--raised))`,padding:3,gap:2},children:[`v1`,`default`,`v2`].map(e=>(0,S.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":(M.multiAgentMode??`default`)===e,className:`btn btn-sm${(M.multiAgentMode??`default`)===e?` btn-primary`:` btn-ghost`}`,style:{borderRadius:`var(--radius-pill)`,minWidth:64,padding:`5px 12px`,border:`none`,background:(M.multiAgentMode??`default`)===e?void 0:`transparent`,color:(M.multiAgentMode??`default`)===e?void 0:`var(--muted)`},disabled:P,onClick:()=>void we(e),children:t(`models.v2Mode_${e}`)},e))}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,style:{width:24,height:24,minWidth:24,flex:`0 0 24px`,padding:0,borderRadius:`var(--radius-pill)`,color:`var(--muted)`},onClick:()=>ae(!0),"aria-label":t(`models.v2Label`),"aria-haspopup":`dialog`,children:(0,S.jsx)(L,{width:14,height:14,"aria-hidden":`true`})}),M.enabled&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`muted text-control`,style:{marginLeft:8},children:t(`models.v2ThreadsLabel`)}),(0,S.jsx)(G,{value:B?ir:M.maxConcurrentThreadsPerSession!==null&&M.maxConcurrentThreadsPerSession!==void 0?or.has(M.maxConcurrentThreadsPerSession)?String(M.maxConcurrentThreadsPerSession):ir:``,options:[...M.maxConcurrentThreadsPerSession===null||M.maxConcurrentThreadsPerSession===void 0?[{value:``,label:t(`models.v2ThreadsDefault`)}]:[],...M.maxConcurrentThreadsPerSession!==null&&M.maxConcurrentThreadsPerSession!==void 0&&!or.has(M.maxConcurrentThreadsPerSession)&&!B?[{value:ir,label:String(M.maxConcurrentThreadsPerSession)}]:[],...ar.map(e=>({value:String(e),label:String(e)})),{value:ir,label:t(`models.custom`)}],onChange:e=>Ee(e),disabled:P,label:t(`models.v2ThreadsLabel`)}),B&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`input`,{className:`input`,style:{width:100},inputMode:`numeric`,value:ne,onChange:e=>R(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Te(Number(ne.replace(/[_,\s]/g,``)))},disabled:P,"aria-label":t(`models.v2ThreadsLabel`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm`,disabled:P,onClick:()=>{Te(Number(ne.replace(/[_,\s]/g,``)))},children:t(`models.v2ThreadsApply`)})]})]}),M.enabled&&M.agentsMaxThreadsConflict&&(0,S.jsx)(`span`,{className:`mono text-label`,style:{color:`var(--err, #e5484d)`},children:t(`models.v2Conflict`)}),F&&(0,S.jsx)(`span`,{className:`muted text-label`,children:F})]}),(0,S.jsxs)(`div`,{className:`row`,style:{gap:8,marginBottom:8,flexWrap:`wrap`},children:[(0,S.jsx)(`span`,{className:`muted text-control`,children:t(`models.contextCapLabel`)}),(0,S.jsx)(G,{value:g?ir:rr.has(f)?String(f):ir,options:[...!rr.has(f)&&!g?[{value:String(f),label:cr(f)}]:[],...nr.map(e=>({value:String(e),label:cr(e)})),{value:ir,label:t(`models.custom`)}],onChange:e=>be(e),disabled:k,label:t(`models.contextCapLabel`)}),g&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`input`,{className:`input`,style:{width:160},inputMode:`numeric`,placeholder:t(`models.customPlaceholder`),value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&xe()},disabled:k,"aria-label":t(`models.customPlaceholder`)}),(0,S.jsx)(`button`,{type:`button`,onClick:xe,disabled:k,className:`btn btn-ghost btn-sm`,children:t(`models.customApply`)})]}),(0,S.jsx)(`div`,{style:{flex:1}}),(0,S.jsx)(ke,{on:Se,onClick:Ce,disabled:k,label:t(`models.setAll`)}),(0,S.jsx)(`span`,{className:`muted mono text-label`,children:t(`models.setAll`)})]}),(0,S.jsxs)(`div`,{className:`row muted text-label leading-body`,style:{alignItems:`flex-start`,gap:8,marginBottom:12,maxWidth:`80ch`},children:[(0,S.jsx)(L,{width:15,height:15,"aria-hidden":`true`,style:{flexShrink:0,marginTop:2}}),(0,S.jsx)(`span`,{children:t(`models.orderHint`)})]}),pe.map(([e,n])=>{let r=y.has(e),a=n.filter(e=>!i.has(e.namespaced)).length,d=u[e]===f,p=n.every(e=>e.native),m=(o[e]??``).trim().toLowerCase(),h=m?n.filter(e=>e.id.toLowerCase().includes(m)):n,g=c[e]??sr,_=h.slice(0,g),v=h.length-_.length,b=n.every(e=>!i.has(e.namespaced)),x=n.every(e=>i.has(e.namespaced)),C=e=>{let t=new Set(i);for(let r of n)e?t.delete(r.namespaced):t.add(r.namespaced);me(t)};return(0,S.jsxs)(`div`,{className:`card`,style:{marginBottom:8,overflow:`hidden`},children:[(0,S.jsxs)(`div`,{onClick:()=>_e(e),className:`row group-head${r?``:` open`}`,children:[(0,S.jsx)(z,{style:{width:14,height:14,color:`var(--muted)`,transform:r?`none`:`rotate(90deg)`,transition:`transform .12s`}}),(0,S.jsx)(`span`,{className:`text-body font-semibold`,children:e}),p&&(0,S.jsx)(`span`,{className:`muted mono text-caption`,style:{padding:`1px 6px`,border:`1px solid var(--border)`,borderRadius:`var(--radius-pill)`},children:t(`models.nativeGroupLabel`)}),(0,S.jsx)(`span`,{className:`muted mono text-label`,children:t(`models.active`,{active:a,total:n.length})}),(0,S.jsx)(`div`,{style:{flex:1}}),(0,S.jsxs)(`div`,{className:`row`,onClick:e=>e.stopPropagation(),style:{gap:6},children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm text-caption`,disabled:k||b,onClick:()=>C(!0),style:{padding:`2px 8px`},children:t(`models.allOn`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm text-caption`,disabled:k||x,onClick:()=>C(!1),style:{padding:`2px 8px`},children:t(`models.allOff`)}),!p&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(ke,{on:d,onClick:()=>ge(e),disabled:k,label:t(`models.capValue`,{value:cr(f)})}),(0,S.jsx)(`span`,{className:`muted mono text-label`,children:t(`models.capValue`,{value:cr(f)})})]})]})]}),!r&&(0,S.jsxs)(`div`,{style:{padding:`6px 12px`},children:[p&&(0,S.jsx)(`p`,{className:`muted text-label`,style:{margin:`2px 0 6px`},children:t(`models.nativeHint`)}),n.length>sr/2&&(0,S.jsx)(`input`,{className:`input`,style:{width:`100%`,marginBottom:6},placeholder:t(`models.search`),value:o[e]??``,onChange:t=>s(n=>({...n,[e]:t.target.value})),"aria-label":t(`models.search`)}),_.map(e=>{let n=i.has(e.namespaced);return(0,S.jsxs)(`div`,{className:`row`,style:{padding:`5px 0`},children:[(0,S.jsx)(ke,{on:!n,onClick:()=>he(e.namespaced),disabled:k,label:e.native?e.id:e.namespaced}),(0,S.jsx)(`code`,{className:`mono text-control`,style:{color:n?`var(--faint)`:`var(--text)`,textDecoration:n?`line-through`:`none`},children:e.native?tr(e.id):e.namespaced}),e.contextCapped&&(0,S.jsx)(`span`,{className:`muted mono text-caption`,style:{padding:`1px 6px`,border:`1px solid var(--border)`,borderRadius:`var(--radius-pill)`},children:t(`models.contextCappedValue`,{value:cr(e.contextCap??f)})})]},e.namespaced)}),v>0&&(0,S.jsx)(`button`,{type:`button`,onClick:()=>l(t=>({...t,[e]:g+sr})),className:`btn btn-ghost btn-sm`,style:{marginTop:4},children:t(`models.showMore`,{n:v})})]})]},e)}),pe.length===0&&(0,S.jsx)(Ae,{icon:(0,S.jsx)(E,{}),title:t(`models.noRouted`),children:t(`models.noRoutedHint`)}),ie&&(0,S.jsx)(`div`,{className:`modal-overlay`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`models.v2Label`),onClick:()=>ae(!1),onKeyDown:e=>{e.key===`Escape`&&ae(!1)},children:(0,S.jsxs)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`modal-head`,children:[(0,S.jsx)(`h3`,{children:t(`models.v2Label`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>ae(!1),"aria-label":t(`common.close`),children:`×`})]}),(0,S.jsx)(`div`,{className:`modal-desc leading-relaxed`,style:{whiteSpace:`pre-line`},children:t(`models.v2Help`)}),(0,S.jsx)(`div`,{style:{marginTop:12},children:(0,S.jsx)(`a`,{className:`text-control`,href:`https://lidge-jun.github.io/opencodex/guides/sub-agent-surface/`,target:`_blank`,rel:`noreferrer`,style:{color:`var(--accent)`},children:t(`models.v2DocsLink`)})}),(0,S.jsx)(`div`,{className:`modal-actions`,children:(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>ae(!1),children:t(`common.ok`)})})]})})]})}var fr=[`low`,`medium`,`high`,`xhigh`,`max`,`ultra`],pr=`medium`,mr=/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;function hr(e){return mr.test(e.trim())}function gr(e){return`combo/${e.trim()}`}function _r(e){return e===`round-robin`?`round-robin`:`failover`}function vr(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1&&e<=100?e:1}function yr(e){return typeof e==`string`&&fr.includes(e)?e:pr}function br(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1&&e<=1e4?e:void 0}function xr(e){if(!e||typeof e!=`object`)return[];let t=e.combos;if(!Array.isArray(t))return[];let n=[];for(let e of t){if(!e||typeof e!=`object`)continue;let t=e,r=typeof t.id==`string`?t.id.trim():``;if(!r)continue;let i=Array.isArray(t.targets)?t.targets:[],a=[];for(let e of i){if(!e||typeof e!=`object`)continue;let t=e,n=typeof t.provider==`string`?t.provider.trim():``,r=typeof t.model==`string`?t.model.trim():``;if(!n||!r)continue;let i=br(t.weight);a.push(i===void 0?{provider:n,model:r}:{provider:n,model:r,weight:i})}n.push({id:r,model:typeof t.model==`string`&&t.model.trim()?t.model.trim():gr(r),strategy:_r(t.strategy),stickyLimit:vr(t.stickyLimit),defaultEffort:yr(t.defaultEffort),targets:a})}return n.sort((e,t)=>e.id.localeCompare(t.id,void 0,{sensitivity:`base`}))}function Sr(e){let t=[],n=[];for(let r of e)r.strategy===`round-robin`?n.push(r):t.push(r);return{failover:t,roundRobin:n}}function Cr(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>e.id.toLowerCase().includes(n)||e.model.toLowerCase().includes(n)?!0:e.targets.some(e=>e.provider.toLowerCase().includes(n)||e.model.toLowerCase().includes(n))):e}function wr(e){let t=[];for(let n of e)n.targets.length===0?t.push({id:n.id,model:n.model,reason:`empty-targets`}):n.targets.length<2&&t.push({id:n.id,model:n.model,reason:`few-targets`});return t}function Tr(e,t){return e.id!==t.id||e.strategy!==t.strategy||e.stickyLimit!==t.stickyLimit||e.defaultEffort!==t.defaultEffort||e.targets.length!==t.targets.length?!1:e.targets.every((e,n)=>{let r=t.targets[n];return e.provider===r.provider&&e.model===r.model&&(e.weight??1)===(r.weight??1)})}function Er(e){return{id:e.id.trim(),combo:{targets:e.targets.map(t=>e.strategy===`round-robin`?{provider:t.provider.trim(),model:t.model.trim(),weight:t.weight??1}:{provider:t.provider.trim(),model:t.model.trim()}),strategy:e.strategy,defaultEffort:e.defaultEffort,...e.strategy===`round-robin`?{stickyLimit:e.stickyLimit}:{}}}}function Dr(e,t){let n=e.id.trim();if(!n)return`missingId`;if(!hr(n))return`invalidId`;if(t.isCreate&&t.existingIds.includes(n))return`duplicateId`;if(Object.hasOwn(t.providers,`combo`))return`reservedNamespace`;if(Object.hasOwn(t.providers,n))return`providerCollision`;if(e.targets.length<1)return`noTargets`;for(let n of e.targets){if(!n.provider.trim()||!n.model.trim())return`incompleteTarget`;if(!Object.hasOwn(t.providers,n.provider.trim()))return`unknownProvider`}let r=new Set;for(let t of e.targets){let e=`${t.provider.trim()}/${t.model.trim()}`;if(r.has(e))return`duplicateTarget`;r.add(e)}if(e.strategy===`round-robin`){if(!Number.isInteger(e.stickyLimit)||e.stickyLimit<1||e.stickyLimit>100)return`invalidStickyLimit`;for(let t of e.targets){let e=t.weight??1;if(!Number.isInteger(e)||e<1||e>1e4)return`invalidWeight`}}return e.targets.some(e=>t.providers[e.provider.trim()]?.disabled!==!0)?null:`noEnabledTarget`}function Or(e=``){return{id:e,model:e?gr(e):`combo/`,strategy:`failover`,stickyLimit:1,defaultEffort:pr,targets:[{provider:``,model:``}]}}function kr(e){return e.filter(e=>!e.disabled&&!e.hiddenFromPicker).sort((e,t)=>e.name.localeCompare(t.name))}function Ar(e){if(!e)return!1;let t=e.name.toLowerCase();if(t!==`openai`&&t!==`chatgpt`||(e.authMode??``).toLowerCase()!==`forward`||(e.adapter??``).toLowerCase()!==`openai-responses`)return!1;let n=(e.baseUrl??``).replace(/\/+$/,``);return!n||n.includes(`chatgpt.com/backend-api/codex`)}function jr(e,t,n){let r=new Set([t]),i=n.find(e=>e.name===t);(t.toLowerCase()===`chatgpt`||Ar(i))&&r.add(`openai`);let a=e.filter(e=>r.has(e.provider)).map(e=>e.id).filter(Boolean);return[...new Set(a)].sort((e,t)=>e.localeCompare(t))}function Mr({value:e,onChange:t,disabled:n}){let r=U();return(0,S.jsx)(`div`,{className:`cwi-strategy-seg`,role:`radiogroup`,"aria-label":r(`cws.strategy`),children:[[`failover`,`cws.strategy.failover`],[`round-robin`,`cws.strategy.roundRobin`]].map(([i,a])=>(0,S.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":e===i,className:`btn btn-sm${e===i?` btn-primary`:` btn-ghost`}`,disabled:n,onClick:()=>t(i),children:r(a)},i))})}function Nr({id:e,value:t,onChange:n,disabled:r}){return(0,S.jsx)(`select`,{id:e,className:`input`,value:t,disabled:r,"aria-label":U()(`cws.field.defaultEffort`),onChange:e=>n(e.target.value),children:fr.map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))})}function Pr({targets:e,strategy:t,providers:n,models:r,onChange:i}){let a=U(),o=kr(n),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(null),d=(t,n)=>{i(e.map((e,r)=>r===t?{...e,...n}:e))},f=(t,n)=>{if(t===n||t<0||n<0||t>=e.length||n>=e.length)return;let r=[...e],[a]=r.splice(t,1);r.splice(n,0,a),i(r)};return(0,S.jsxs)(`div`,{className:`cwi-target-list`,children:[e.map((p,m)=>{let h=n.find(e=>e.name===p.provider),g=h&&!o.some(e=>e.name===p.provider)?[...o,h]:o,_=jr(r,p.provider,n),v=p.model&&!_.includes(p.model)?[p.model,..._]:_,y=!p.provider;return(0,S.jsxs)(`div`,{className:[`cwi-target-row`,t===`failover`?`cwi-target-row--failover`:``,s===m?`cwi-target-row--dragging`:``,l===m&&s!==null&&s!==m?`cwi-target-row--drop`:``].filter(Boolean).join(` `),onDragOver:e=>{s!==null&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,l!==m&&u(m))},onDrop:e=>{e.preventDefault(),s!==null&&f(s,m),c(null),u(null)},onDragEnd:()=>{c(null),u(null)},children:[(0,S.jsx)(`button`,{type:`button`,className:`cwi-target-grip`,draggable:!0,"aria-label":a(`cws.target.drag`),title:a(`cws.target.drag`),onDragStart:e=>{c(m),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,String(m))},children:(0,S.jsx)(me,{width:14,height:14,"aria-hidden":`true`})}),(0,S.jsxs)(`select`,{className:`input`,value:p.provider,"aria-label":a(`cws.target.provider`),onChange:e=>{let t=e.target.value;d(m,{provider:t,model:jr(r,t,n)[0]??``})},children:[(0,S.jsx)(`option`,{value:``,children:a(`cws.target.pickProvider`)}),g.map(e=>(0,S.jsx)(`option`,{value:e.name,children:e.disabled?a(`cws.target.disabled`,{name:e.name}):e.name},e.name))]}),(0,S.jsxs)(`select`,{className:`input`,value:p.model,disabled:y,"aria-label":a(`cws.target.model`),onChange:e=>d(m,{model:e.target.value}),children:[(0,S.jsx)(`option`,{value:``,children:y?a(`cws.target.pickProviderFirst`):v.length===0?a(`cws.target.noModels`):a(`cws.target.pickModel`)}),v.map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))]}),t===`round-robin`&&(0,S.jsx)(`input`,{className:`input mono`,type:`number`,min:1,max:1e4,value:p.weight??1,"aria-label":a(`cws.target.weight`),onChange:e=>d(m,{weight:Number(e.target.value)})}),(0,S.jsx)(`div`,{className:`cwi-target-actions`,children:(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:e.length<=1,onClick:()=>i(e.filter((e,t)=>t!==m)),"aria-label":a(`common.remove`),children:(0,S.jsx)(F,{width:14,height:14})})})]},m)}),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,style:{alignSelf:`flex-start`},onClick:()=>i([...e,{provider:``,model:``}]),children:[(0,S.jsx)(P,{width:14,height:14}),` `,a(`cws.target.add`)]})]})}function Fr({model:e,onCancel:t,onConfirm:n}){let r=U();return(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),t())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,S.jsx)(`div`,{className:`modal-overlay`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`cwi-remove-title`,onClick:t,children:(0,S.jsxs)(`div`,{className:`modal-card pwi-remove-confirm-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsx)(`h3`,{id:`cwi-remove-title`,className:`pwi-remove-confirm-title`,children:r(`cws.removeConfirmTitle`,{model:e})}),(0,S.jsx)(`p`,{className:`muted pwi-remove-confirm-desc`,children:r(`cws.removeConfirmDesc`)}),(0,S.jsxs)(`div`,{className:`pwi-remove-confirm-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:t,children:r(`common.cancel`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn pwi-remove-confirm-danger`,onClick:n,children:r(`common.remove`)})]})]})})}function Ir({onKeep:e,onDiscard:t}){let n=U();return(0,S.jsx)(`div`,{className:`modal-overlay`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`cwi-unsaved-title`,onClick:e,children:(0,S.jsxs)(`div`,{className:`modal-card pwi-json-unsaved-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsx)(`h3`,{id:`cwi-unsaved-title`,className:`pwi-json-unsaved-title`,children:n(`cws.unsavedTitle`)}),(0,S.jsx)(`p`,{className:`muted pwi-json-unsaved-desc`,children:n(`cws.unsavedDesc`)}),(0,S.jsxs)(`div`,{className:`pwi-json-unsaved-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:e,children:n(`cws.keepEditing`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-danger`,onClick:t,children:n(`common.discard`)})]})]})})}function Lr({existingIds:e,providerMap:t,providers:n,models:r,onClose:i,onSubmit:a}){let o=U(),[s,c]=(0,_.useState)(()=>Or()),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(``);(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!l&&(e.preventDefault(),i())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l,i]);let p=async()=>{let n=Dr(s,{existingIds:e,isCreate:!0,providers:t});if(n){f(o(`cws.err.${n}`));return}u(!0),f(``);let r=await a({...s,id:s.id.trim(),model:gr(s.id.trim())});if(u(!1),!r.ok){f(r.error||o(`cws.saveFailed`));return}};return(0,S.jsx)(`div`,{className:`modal-overlay`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`cwi-add-title`,onClick:()=>{l||i()},children:(0,S.jsxs)(`div`,{className:`modal-card`,style:{width:`min(560px, 94vw)`},onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`row`,style:{justifyContent:`space-between`,marginBottom:8},children:[(0,S.jsx)(`h3`,{id:`cwi-add-title`,style:{margin:0},children:o(`cws.addTitle`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:i,disabled:l,"aria-label":o(`common.close`),children:(0,S.jsx)(N,{width:16,height:16})})]}),(0,S.jsx)(`p`,{className:`muted`,style:{marginTop:0},children:o(`cws.addSubtitle`)}),d&&(0,S.jsx)(W,{tone:`err`,children:d}),(0,S.jsxs)(`div`,{className:`cwi-modal-form`,children:[(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{htmlFor:`cwi-new-id`,children:o(`cws.field.id`)}),(0,S.jsx)(`input`,{id:`cwi-new-id`,className:`input mono`,value:s.id,placeholder:o(`cws.field.idPlaceholder`),disabled:l,onChange:e=>c(t=>({...t,id:e.target.value,model:gr(e.target.value)}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`4px 0 0`},children:o(`cws.field.idHint`,{model:s.id.trim()?gr(s.id.trim()):`combo/…`})})]}),(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{children:o(`cws.strategy`)}),(0,S.jsx)(Mr,{value:s.strategy,disabled:l,onChange:e=>c(t=>({...t,strategy:e}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`6px 0 0`},children:s.strategy===`failover`?o(`cws.strategy.failoverHint`):o(`cws.strategy.roundRobinHint`)})]}),(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{htmlFor:`cwi-new-effort`,children:o(`cws.field.defaultEffort`)}),(0,S.jsx)(Nr,{id:`cwi-new-effort`,value:s.defaultEffort,disabled:l,onChange:e=>c(t=>({...t,defaultEffort:e}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`4px 0 0`},children:o(`cws.field.defaultEffortHint`)})]}),s.strategy===`round-robin`&&(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{htmlFor:`cwi-new-sticky`,children:o(`cws.field.stickyLimit`)}),(0,S.jsx)(`input`,{id:`cwi-new-sticky`,className:`input mono`,type:`number`,min:1,max:100,value:s.stickyLimit,disabled:l,onChange:e=>c(t=>({...t,stickyLimit:Number(e.target.value)}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`4px 0 0`},children:o(`cws.field.stickyLimitHint`)})]}),(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{children:o(`cws.targets`)}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`0 0 8px`},children:s.strategy===`failover`?o(`cws.targets.failoverHint`):o(`cws.targets.roundRobinHint`)}),(0,S.jsx)(Pr,{targets:s.targets,strategy:s.strategy,providers:n,models:r,onChange:e=>c(t=>({...t,targets:e}))})]})]}),(0,S.jsxs)(`div`,{className:`cwi-modal-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:i,disabled:l,children:o(`common.cancel`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>{p()},disabled:l,children:o(l?`common.saving`:`cws.create`)})]})]})})}function Rr({combos:e,onSelect:t,onAdd:n}){let r=U(),i=Sr(e),a=wr(e);return(0,S.jsxs)(`div`,{className:`combos-workspace-overview`,children:[(0,S.jsxs)(`div`,{className:`combos-workspace-overview-head`,children:[(0,S.jsx)(`h2`,{className:`combos-workspace-overview-title`,children:r(`cws.overviewTitle`)}),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:n,children:[(0,S.jsx)(P,{width:14,height:14}),` `,r(`cws.add`)]})]}),(0,S.jsx)(`p`,{className:`muted`,style:{marginTop:0,maxWidth:`62ch`},children:r(`cws.overviewBlurb`)}),(0,S.jsxs)(`div`,{className:`cwi-count-strip`,children:[(0,S.jsxs)(`div`,{className:`cwi-count-pill`,children:[(0,S.jsx)(`strong`,{children:e.length}),(0,S.jsx)(`span`,{children:r(`cws.count.total`)})]}),(0,S.jsxs)(`div`,{className:`cwi-count-pill`,children:[(0,S.jsx)(`strong`,{children:i.failover.length}),(0,S.jsx)(`span`,{children:r(`cws.count.failover`)})]}),(0,S.jsxs)(`div`,{className:`cwi-count-pill`,children:[(0,S.jsx)(`strong`,{children:i.roundRobin.length}),(0,S.jsx)(`span`,{children:r(`cws.count.roundRobin`)})]})]}),(0,S.jsxs)(`section`,{className:`pwi-section`,"aria-label":r(`cws.howTitle`),children:[(0,S.jsx)(`h3`,{className:`pwi-section-title`,children:r(`cws.howTitle`)}),(0,S.jsx)(`p`,{className:`muted`,style:{margin:0},children:r(`cws.howBody`)})]}),a.length>0&&(0,S.jsxs)(`section`,{className:`pwi-section`,"aria-label":r(`cws.attentionTitle`),children:[(0,S.jsx)(`h3`,{className:`pwi-section-title`,children:r(`cws.attentionTitle`)}),(0,S.jsx)(`div`,{className:`cwi-attention-list`,children:a.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`cwi-attention-row`,onClick:()=>t(e.id),children:[(0,S.jsx)(I,{width:14,height:14,"aria-hidden":`true`}),(0,S.jsx)(`code`,{className:`chip`,children:e.model}),(0,S.jsx)(`span`,{className:`muted`,children:e.reason===`empty-targets`?r(`cws.attention.empty`):r(`cws.attention.few`)}),(0,S.jsx)(z,{width:14,height:14,style:{marginLeft:`auto`},"aria-hidden":`true`})]},e.id))})]})]})}function zr({onAdd:e}){let t=U();return(0,S.jsx)(`div`,{className:`combos-workspace-empty-root`,children:(0,S.jsxs)(`button`,{type:`button`,className:`cwi-empty-cta`,onClick:e,children:[(0,S.jsx)(`span`,{className:`pwi-empty-right-icon`,"aria-hidden":`true`,children:(0,S.jsx)(pe,{style:{width:64,height:64}})}),(0,S.jsx)(`span`,{className:`cwi-empty-cta-title`,children:t(`cws.emptyTitle`)}),(0,S.jsx)(`span`,{className:`pwi-empty-right-sub`,children:t(`cws.empty.createDesc`)})]})})}function Br({baseline:e,providerMap:t,providers:n,models:r,onBack:i,onSaved:a,onRequestRemove:o,onSave:s,onDirtyChange:c}){let l=U(),[u,d]=(0,_.useState)(`config`),[f,p]=(0,_.useState)(e),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(!1),x=!Tr(f,e);(0,_.useEffect)(()=>{let t=window.setTimeout(()=>{p(e),v(null),d(`config`)},0);return()=>window.clearTimeout(t)},[`${e.id}:${e.strategy}:${e.stickyLimit}:${e.defaultEffort}:${e.targets.map(e=>`${e.provider}/${e.model}:${e.weight??1}`).join(`,`)}`]),(0,_.useEffect)(()=>{c(x)},[x,c]);let C=async()=>{try{await navigator.clipboard.writeText(e.model),b(!0),window.setTimeout(()=>b(!1),1200)}catch{}},w=async()=>{let e=Dr(f,{existingIds:[],isCreate:!1,providers:t});if(e){v({ok:!1,text:l(`cws.err.${e}`)});return}h(!0);let n=await s(f,!1);if(h(!1),!n.ok){v({ok:!1,text:n.error||l(`cws.saveFailed`)});return}v({ok:!0,text:l(`cws.saved`)}),a(f)};return(0,S.jsxs)(`div`,{className:`combos-workspace-detail`,children:[(0,S.jsxs)(`div`,{className:`combos-workspace-detail-head`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm pwi-back-overview`,onClick:i,"aria-label":l(`cws.backToAll`),children:[(0,S.jsx)(z,{style:{width:14,height:14,transform:`rotate(180deg)`},"aria-hidden":`true`}),l(`cws.allCombos`)]}),(0,S.jsx)(`h2`,{className:`combos-workspace-detail-title`,children:e.model}),(0,S.jsx)(`button`,{type:`button`,className:`chip cwi-copy-chip`,onClick:()=>{C()},title:l(`cws.copyModel`),children:l(y?`cws.copied`:`cws.copyModel`)}),(0,S.jsxs)(`div`,{className:`combos-workspace-detail-actions`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:o,children:[(0,S.jsx)(F,{width:14,height:14}),` `,l(`common.remove`)]}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,disabled:!x||m,onClick:()=>{w()},children:l(m?`common.saving`:`common.save`)})]})]}),g&&(0,S.jsx)(W,{tone:g.ok?`ok`:`err`,children:g.text}),(0,S.jsxs)(`div`,{className:`combos-workspace-tabs`,role:`tablist`,children:[(0,S.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`config`,className:`combos-workspace-tab${u===`config`?` combos-workspace-tab--active`:``}`,onClick:()=>d(`config`),children:l(`cws.tab.config`)}),(0,S.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`about`,className:`combos-workspace-tab${u===`about`?` combos-workspace-tab--active`:``}`,onClick:()=>d(`about`),children:l(`cws.tab.about`)})]}),(0,S.jsx)(`div`,{className:`combos-workspace-tab-content`,role:`tabpanel`,children:u===`config`?(0,S.jsxs)(`div`,{className:`cwi-form-grid`,children:[(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{children:l(`cws.strategy`)}),(0,S.jsx)(Mr,{value:f.strategy,disabled:m,onChange:e=>p(t=>({...t,strategy:e}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`6px 0 0`},children:f.strategy===`failover`?l(`cws.strategy.failoverHint`):l(`cws.strategy.roundRobinHint`)})]}),(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{htmlFor:`cwi-effort`,children:l(`cws.field.defaultEffort`)}),(0,S.jsx)(Nr,{id:`cwi-effort`,value:f.defaultEffort,disabled:m,onChange:e=>p(t=>({...t,defaultEffort:e}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`4px 0 0`},children:l(`cws.field.defaultEffortHint`)})]}),f.strategy===`round-robin`&&(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{htmlFor:`cwi-sticky`,children:l(`cws.field.stickyLimit`)}),(0,S.jsx)(`input`,{id:`cwi-sticky`,className:`input mono`,type:`number`,min:1,max:100,value:f.stickyLimit,disabled:m,onChange:e=>p(t=>({...t,stickyLimit:Number(e.target.value)}))})]}),(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{children:l(`cws.targets`)}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`0 0 8px`},children:f.strategy===`failover`?l(`cws.targets.failoverHint`):l(`cws.targets.roundRobinHint`)}),(0,S.jsx)(Pr,{targets:f.targets,strategy:f.strategy,providers:n,models:r,onChange:e=>p(t=>({...t,targets:e}))})]})]}):(0,S.jsxs)(`section`,{className:`pwi-section`,children:[(0,S.jsx)(`h3`,{className:`pwi-section-title`,children:l(`cws.aboutTitle`)}),(0,S.jsx)(`p`,{className:`muted`,style:{margin:0},children:l(`cws.aboutBody`)})]})})]})}function Vr({combos:e,providers:t,models:n,loading:r,onRefresh:i,onSave:a,onRemove:o,onAdd:s,adding:c,onCloseAdd:l,onCreated:u}){let d=U(),f=(0,_.useMemo)(()=>Object.fromEntries(t.map(e=>[e.name,{disabled:e.disabled}])),[t]),[p,m]=(0,_.useState)(``),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(void 0),[b,x]=(0,_.useState)(null),[C,w]=(0,_.useState)(null),T=(0,_.useMemo)(()=>Cr(e,p),[e,p]),E=(0,_.useMemo)(()=>Sr(T),[T]),D=h&&e.some(e=>e.id===h)?h:null,O=e.find(e=>e.id===D)??null,k=O&&C?.id===O.id?C:O,[A,j]=(0,_.useState)(!1),M=(0,_.useCallback)(e=>{if(e!==D){if(!A){g(e),w(null);return}y(e)}},[D,A]),N=()=>{v!==void 0&&(g(v),w(null),j(!1),y(void 0))},ee=()=>y(void 0),F=v!==void 0&&A;return!r&&e.length===0?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(zr,{onAdd:s}),c&&(0,S.jsx)(Lr,{existingIds:e.map(e=>e.id),providerMap:f,providers:t,models:n,onClose:l,onSubmit:async e=>{let t=await a(e,!0);return t.ok&&(l(),u(e.id),g(e.id)),t}})]}):(0,S.jsxs)(`div`,{className:`combos-workspace-root`,children:[(0,S.jsxs)(`aside`,{className:`combos-workspace-rail`,"aria-label":d(`cws.railAria`),children:[(0,S.jsxs)(`div`,{className:`combos-workspace-rail-header`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`combos-workspace-rail-title`,children:d(`nav.combos`)}),(0,S.jsx)(`div`,{className:`combos-workspace-rail-count`,children:e.length})]}),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:s,"aria-label":d(`cws.add`),children:[(0,S.jsx)(P,{width:14,height:14}),` `,d(`cws.add`)]})]}),(0,S.jsx)(`div`,{className:`cwi-search-row`,children:(0,S.jsxs)(`div`,{className:`cwi-search-wrap`,children:[(0,S.jsx)(te,{className:`cwi-search-icon`,"aria-hidden":`true`}),(0,S.jsx)(`input`,{className:`input cwi-search-input`,value:p,onChange:e=>m(e.target.value),placeholder:d(`cws.searchPlaceholder`),"aria-label":d(`cws.searchPlaceholder`)})]})}),(0,S.jsx)(`div`,{className:`combos-workspace-rail-list`,children:T.length===0?(0,S.jsx)(`p`,{className:`muted`,style:{padding:`16px`},children:d(`cws.noSearchResults`)}):(0,S.jsx)(S.Fragment,{children:[[`failover`,E.failover,`cws.group.failover`],[`round-robin`,E.roundRobin,`cws.group.roundRobin`]].map(([e,t,n])=>t.length>0?(0,S.jsxs)(`div`,{className:`combos-workspace-rail-group`,children:[(0,S.jsxs)(`div`,{className:`combos-workspace-rail-group-head`,children:[(0,S.jsx)(`span`,{className:`pwi-dot`,"aria-hidden":`true`}),d(n),(0,S.jsx)(`span`,{className:`combos-workspace-rail-count`,children:t.length})]}),t.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`combos-workspace-rail-row${D===e.id?` combos-workspace-rail-row--selected`:``}`,onClick:()=>M(e.id),"aria-current":D===e.id?`true`:void 0,children:[(0,S.jsx)(`span`,{className:`combos-workspace-rail-icon`,"aria-hidden":`true`,children:(0,S.jsx)(pe,{width:16,height:16})}),(0,S.jsx)(`span`,{className:`combos-workspace-rail-name`,children:e.model}),(0,S.jsx)(`span`,{className:`combos-workspace-rail-meta`,children:e.targets.length===1?d(`cws.targetCountOne`):d(`cws.targetCount`,{count:e.targets.length})}),(0,S.jsx)(z,{className:`combos-workspace-rail-chevron`,"aria-hidden":`true`})]},e.id))]},e):null)})})]}),(0,S.jsx)(`div`,{className:`combos-workspace-main`,children:k?(0,S.jsx)(Br,{baseline:k,providerMap:f,providers:t,models:n,onBack:()=>M(null),onSaved:e=>{w(e),j(!1),i()},onRequestRemove:()=>x(k.id),onSave:a,onDirtyChange:j},k.id):(0,S.jsx)(Rr,{combos:e,onSelect:e=>M(e),onAdd:s})}),c&&(0,S.jsx)(Lr,{existingIds:e.map(e=>e.id),providerMap:f,providers:t,models:n,onClose:l,onSubmit:async e=>{let t=await a(e,!0);return t.ok&&(l(),u(e.id),g(e.id),w(null)),t}}),b&&(0,S.jsx)(Fr,{model:gr(b),onCancel:()=>x(null),onConfirm:()=>{(async()=>{let e=await o(b);x(null),e.ok&&(D===b&&(g(null),w(null)),i())})()}}),F&&(0,S.jsx)(Ir,{onKeep:ee,onDiscard:N})]})}function Hr(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e.error;return typeof t==`string`&&t.trim()?t:void 0}function Ur(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&e.success===!0}function Wr({apiBase:e}){let t=U(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(!0),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),g=(e,t)=>{d(e),p(t)};(0,_.useEffect)(()=>{if(!u||!f)return;let e=window.setTimeout(()=>{d(``),p(!1)},5e3);return()=>window.clearTimeout(e)},[u,f]);let v=(0,_.useCallback)(async()=>{try{let[t,n,i]=await Promise.all([fetch(`${e}/api/combos`),fetch(`${e}/api/config`),fetch(`${e}/api/models`)]);if(!t.ok||!n.ok||!i.ok)throw Error(`combo workspace load failed`);let o=await t.json(),c=await n.json(),l=await i.json(),u=Array.isArray(l)?l:Array.isArray(l?.models)?l.models:[];r(xr(o));let d=c.providers??{},f=it(d);a(Object.entries(d).map(([e,t])=>({name:e,disabled:!!t.disabled,hiddenFromPicker:!Object.hasOwn(f,e),authMode:t.authMode,adapter:t.adapter,baseUrl:t.baseUrl})));let p=[];for(let e of u){if(!e||typeof e!=`object`)continue;let t=e;if(typeof t.provider!=`string`||typeof t.id!=`string`)continue;let n=t.provider.trim(),r=t.id.trim();!n||!r||n===`combo`||t.disabled!==!0&&p.push({provider:n,id:r,namespaced:typeof t.namespaced==`string`?t.namespaced:void 0})}for(let[e,t]of Object.entries(c.providers??{})){let n=typeof t.defaultModel==`string`?t.defaultModel.trim():``;!n||t.disabled||p.some(t=>t.provider===e&&t.id===n)||p.push({provider:e,id:n,namespaced:`${e}/${n}`})}s(p)}catch{g(t(`cws.loadFailed`),!1)}finally{l(!1)}},[e,t]);return(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{v()},0);return()=>window.clearTimeout(e)},[v]),c&&n.length===0?(0,S.jsxs)(`div`,{className:`combos-workspace-shell`,children:[u&&(0,S.jsx)(`div`,{className:`combos-workspace-shell-banner`,children:(0,S.jsx)(W,{tone:f?`ok`:`err`,children:u})}),(0,S.jsx)(`div`,{className:`muted`,style:{padding:`24px 20px`},role:`status`,children:u?null:t(`cws.loading`)})]}):(0,S.jsxs)(`div`,{className:`combos-workspace-shell`,children:[u&&(0,S.jsx)(`div`,{className:`combos-workspace-shell-banner`,children:(0,S.jsx)(W,{tone:f?`ok`:`err`,children:u})}),(0,S.jsx)(`div`,{className:`combos-workspace-shell-body`,children:(0,S.jsx)(Vr,{combos:n,providers:i,models:o,loading:c,onRefresh:()=>{v()},onSave:async(n,r)=>{try{let i=await fetch(`${e}/api/combos`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(Er(n))}),a=await i.json(),o=Hr(a);if(!i.ok||o||!Ur(a)){let e=o||t(`cws.saveFailed`);return g(e,!1),{ok:!1,error:e}}return await v(),g(r?t(`cws.created`,{model:n.model}):t(`cws.saved`),!0),{ok:!0}}catch{let e=t(`cws.saveFailed`);return g(e,!1),{ok:!1,error:e}}},onRemove:async n=>{try{let r=await fetch(`${e}/api/combos?id=${encodeURIComponent(n)}`,{method:`DELETE`}),i=await r.json(),a=Hr(i);if(!r.ok||a||!Ur(i)){let e=a||t(`cws.removeFailed`);return g(e,!1),{ok:!1,error:e}}return await v(),g(t(`cws.removed`,{id:n}),!0),{ok:!0}}catch{let e=t(`cws.removeFailed`);return g(e,!1),{ok:!1,error:e}}},onAdd:()=>h(!0),adding:m,onCloseAdd:()=>h(!1),onCreated:()=>{v()}})})]})}function Gr({apiBase:e}){let t=U(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!0),m=(0,_.useMemo)(()=>new Set(i),[i]),h=(0,_.useCallback)(async()=>{try{let t=await fetch(`${e}/api/subagent-models`).then(e=>e.json()),n=t.available??[],i=new Set(n);r(n),a((t.chosen??[]).filter(e=>i.has(e)))}catch{d(!1),l(t(`sub.loadFail`))}finally{p(!1)}},[e,t]);(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{h()},0);return()=>window.clearTimeout(e)},[h]);let g=e=>{l(``),a(t=>t.includes(e)?t.filter(t=>t!==e):t.length>=5?t:[...t,e])},v=(e,t)=>{a(n=>{let r=[...n],i=e+t;return i<0||i>=r.length?n:([r[e],r[i]]=[r[i],r[e]],r)})},y=async()=>{l(``);try{let n=await fetch(`${e}/api/subagent-models`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({models:i})}),r=await n.json();d(n.ok),l(n.ok?t(`sub.saved`,{n:r.applied?.length??0,cmd:`ocx sync`}):r.error||t(`sub.saveFailed`))}catch{d(!1),l(t(`sub.networkError`))}},b=(0,_.useMemo)(()=>{let e=o.trim().toLowerCase();return n.filter(t=>!e||t.toLowerCase().includes(e))},[n,o]);return f?(0,S.jsx)(`div`,{className:`muted`,style:{padding:8},children:t(`sub.loading`)}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h2`,{children:t(`nav.subagents`)})}),(0,S.jsx)(`p`,{className:`page-sub`,children:(0,S.jsx)(Te,{k:`sub.subtitle`,cmd:`spawn_agent`})}),c&&(0,S.jsx)(W,{tone:u?`ok`:`err`,children:c}),(0,S.jsxs)(`div`,{className:`h-section`,children:[t(`sub.featured`),` `,(0,S.jsxs)(`span`,{className:`count`,children:[i.length,`/5`]})]}),(0,S.jsxs)(`div`,{className:`row muted text-label leading-body`,style:{alignItems:`flex-start`,gap:8,margin:`-2px 0 10px`,maxWidth:`80ch`},children:[(0,S.jsx)(L,{width:15,height:15,"aria-hidden":`true`,style:{flexShrink:0,marginTop:2}}),(0,S.jsx)(`span`,{children:(0,S.jsx)(Te,{k:`sub.orderHint`,cmd:`spawn_agent`})})]}),i.length===0?(0,S.jsx)(Ae,{title:t(`sub.noneSelected`)}):(0,S.jsx)(`div`,{className:`stack`,style:{gap:8},children:i.map((e,n)=>(0,S.jsxs)(`div`,{className:`card panel-accent row`,style:{padding:`8px 12px`,gap:10},children:[(0,S.jsx)(`span`,{className:`mono font-bold`,style:{width:18,color:`var(--accent)`},children:n+1}),(0,S.jsx)(`code`,{className:`mono`,style:{flex:1,color:`var(--text)`},children:tr(e)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon btn-sm`,onClick:()=>v(n,-1),disabled:n===0,"aria-label":t(`sub.moveUp`,{m:e}),children:(0,S.jsx)(ne,{})}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon btn-sm`,onClick:()=>v(n,1),disabled:n===i.length-1,"aria-label":t(`sub.moveDown`,{m:e}),children:(0,S.jsx)(R,{})}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon btn-sm`,onClick:()=>g(e),"aria-label":t(`sub.removeAria`,{m:e}),style:{color:`var(--red)`},children:(0,S.jsx)(N,{})})]},e))}),(0,S.jsx)(`div`,{style:{marginTop:14},children:(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:y,children:t(`common.save`)})}),(0,S.jsxs)(`div`,{className:`h-section`,children:[t(`sub.models`),` `,(0,S.jsx)(`span`,{className:`count`,children:b.length})]}),(0,S.jsxs)(`div`,{className:`row`,style:{marginBottom:10,gap:8},children:[(0,S.jsx)(te,{width:15,height:15,"aria-hidden":`true`,style:{color:`var(--faint)`,flexShrink:0}}),(0,S.jsx)(`input`,{className:`input`,value:o,onChange:e=>s(e.target.value),placeholder:t(`sub.search`),"aria-label":t(`sub.search`),style:{flex:1}})]}),(0,S.jsxs)(`div`,{className:`stack`,style:{gap:6,maxHeight:360,overflowY:`auto`},children:[b.map(e=>{let t=m.has(e),n=!t&&i.length>=5;return(0,S.jsxs)(`button`,{type:`button`,className:`card row${t?` panel-accent`:``}`,onClick:()=>g(e),disabled:n,"aria-pressed":t,style:{width:`100%`,opacity:n?.45:1,cursor:n?`not-allowed`:`pointer`},children:[(0,S.jsx)(`span`,{style:{width:16,height:16,flexShrink:0,color:`var(--accent)`,display:`inline-flex`},children:t&&(0,S.jsx)(M,{style:{width:16,height:16}})}),(0,S.jsx)(D,{style:{width:15,height:15,color:`var(--faint)`,flexShrink:0}}),(0,S.jsx)(`code`,{className:`mono`,style:{color:`var(--text)`},children:tr(e)})]},e)}),b.length===0&&(0,S.jsx)(Ae,{title:t(`sub.noModels`)})]})]})}var Kr={400:{en:{label:`Bad request`,description:`The proxy could not understand the request. Check the model, message shape, headers, and JSON body before retrying.`},ko:{label:`잘못된 요청`,description:`프록시가 요청을 이해할 수 없습니다. 재시도 전에 모델, 메시지 형식, 헤더, JSON 본문을 확인해야 합니다.`},zh:{label:`错误请求`,description:`代理无法理解该请求。重试前请检查模型、消息结构、标头和 JSON 正文。`},de:{label:`Ungültige Anfrage`,description:`Der Proxy konnte die Anfrage nicht verstehen. Prüfe Modell, Nachrichtenformat, Header und JSON-Body vor einem erneuten Versuch.`}},401:{en:{label:`Unauthorized`,description:`Credentials are missing, expired, or invalid. Re-login or refresh the account/provider credentials used by opencodex.`},ko:{label:`인증 필요`,description:`자격 증명이 없거나 만료되었거나 유효하지 않습니다. opencodex에서 사용하는 계정 또는 제공자 자격 증명을 다시 로그인하거나 갱신해야 합니다.`},zh:{label:`未授权`,description:`凭据缺失、已过期或无效。请重新登录,或刷新 opencodex 使用的账号/提供商凭据。`},de:{label:`Nicht autorisiert`,description:`Anmeldedaten fehlen, sind abgelaufen oder ungültig. Melde dich erneut an oder aktualisiere die von opencodex genutzten Konto-/Anbieter-Zugangsdaten.`}},402:{en:{label:`Payment required`,description:`The upstream provider rejected the request because billing, credits, or plan access is not available. Add credits, update billing, or switch provider.`},ko:{label:`결제 필요`,description:`청구, 크레딧, 플랜 접근 권한 문제로 업스트림 제공자가 요청을 거부했습니다. 크레딧 추가, 결제 정보 갱신, 제공자 전환이 필요합니다.`},zh:{label:`需要付款`,description:`上游提供商因账单、额度或套餐权限不可用而拒绝了请求。请充值、更新账单信息或切换提供商。`},de:{label:`Zahlung erforderlich`,description:`Der Upstream-Anbieter hat die Anfrage abgelehnt, weil Abrechnung, Guthaben oder Planzugriff nicht verfügbar ist. Guthaben aufladen, Abrechnung aktualisieren oder Anbieter wechseln.`}},403:{en:{label:`Forbidden`,description:`The account is authenticated but not allowed to use this model or operation. Often a plan/subscription gate (e.g. Ollama Cloud Pro), org policy, or model permission — not necessarily a bad API key.`},ko:{label:`권한 없음`,description:`계정 인증은 되었지만 이 모델 또는 작업을 사용할 권한이 없습니다. 플랜/구독 제한(예: Ollama Cloud Pro), 조직 정책, 모델 권한 문제인 경우가 많으며 API 키가 잘못된 것은 아닐 수 있습니다.`},zh:{label:`禁止访问`,description:`账号已认证,但无权使用此模型或操作。常见原因是套餐/订阅限制(例如 Ollama Cloud Pro)、组织策略或模型权限——不一定是 API 密钥无效。`},de:{label:`Verboten`,description:`Das Konto ist authentifiziert, darf dieses Modell oder diese Operation aber nicht nutzen. Oft Plan-/Abo-Sperre (z. B. Ollama Cloud Pro), Organisationsrichtlinie oder Modellrecht — nicht zwingend ein ungültiger API-Key.`}},404:{en:{label:`Not found`,description:`The requested route, model, account, or upstream resource was not found. Verify the model name and opencodex provider configuration.`},ko:{label:`찾을 수 없음`,description:`요청한 경로, 모델, 계정 또는 업스트림 리소스를 찾을 수 없습니다. 모델 이름과 opencodex 제공자 설정을 확인해야 합니다.`},zh:{label:`未找到`,description:`找不到请求的路由、模型、账号或上游资源。请确认模型名称和 opencodex 提供商配置。`},de:{label:`Nicht gefunden`,description:`Die angeforderte Route, das Modell, das Konto oder die Upstream-Ressource wurde nicht gefunden. Prüfe Modellname und opencodex-Anbieterkonfiguration.`}},408:{en:{label:`Request timeout`,description:`The request took too long before the proxy or upstream provider could complete it. Retry with a smaller request or a different provider.`},ko:{label:`요청 시간 초과`,description:`프록시 또는 업스트림 제공자가 요청을 완료하기 전에 시간이 초과되었습니다. 더 작은 요청으로 재시도하거나 다른 제공자로 전환해야 합니다.`},zh:{label:`请求超时`,description:`代理或上游提供商未能在限定时间内完成请求。请缩小请求后重试,或切换提供商。`},de:{label:`Anfrage-Timeout`,description:`Die Anfrage dauerte zu lange, bevor Proxy oder Upstream-Anbieter sie abschließen konnten. Mit kleinerer Anfrage oder anderem Anbieter erneut versuchen.`}},409:{en:{label:`Conflict`,description:`The request conflicts with the current account, session, or provider state. Refresh the session or retry after the active operation finishes.`},ko:{label:`상태 충돌`,description:`요청이 현재 계정, 세션 또는 제공자 상태와 충돌합니다. 세션을 갱신하거나 진행 중인 작업이 끝난 뒤 재시도해야 합니다.`},zh:{label:`状态冲突`,description:`请求与当前账号、会话或提供商状态冲突。请刷新会话,或等待当前操作完成后重试。`},de:{label:`Konflikt`,description:`Die Anfrage kollidiert mit dem aktuellen Konto-, Sitzungs- oder Anbieterstatus. Sitzung aktualisieren oder nach Abschluss der laufenden Operation erneut versuchen.`}},413:{en:{label:`Request too large`,description:`The prompt, attachments, or generated payload exceeds a proxy or upstream limit. Reduce tokens, file size, or conversation history.`},ko:{label:`요청 과대`,description:`프롬프트, 첨부 파일 또는 생성 페이로드가 프록시나 업스트림 한도를 초과했습니다. 토큰, 파일 크기, 대화 기록을 줄여야 합니다.`},zh:{label:`请求过大`,description:`提示、附件或生成的负载超过了代理或上游限制。请减少 token、文件大小或对话历史。`},de:{label:`Anfrage zu groß`,description:`Prompt, Anhänge oder generierte Nutzlast überschreiten ein Proxy- oder Upstream-Limit. Tokens, Dateigröße oder Verlauf reduzieren.`}},422:{en:{label:`Invalid content`,description:`The provider accepted the request format but rejected its contents. Check model options, tool definitions, message roles, and unsupported fields.`},ko:{label:`내용 검증 실패`,description:`제공자가 요청 형식은 받았지만 내용을 거부했습니다. 모델 옵션, 도구 정의, 메시지 역할, 지원되지 않는 필드를 확인해야 합니다.`},zh:{label:`内容无效`,description:`提供商接受了请求格式,但拒绝了其中的内容。请检查模型选项、工具定义、消息角色和不支持的字段。`},de:{label:`Ungültiger Inhalt`,description:`Der Anbieter akzeptierte das Anfrageformat, lehnte den Inhalt aber ab. Prüfe Modelloptionen, Tool-Definitionen, Nachrichtenrollen und nicht unterstützte Felder.`}},424:{en:{label:`Provider dependency failed`,description:`A required upstream dependency failed while opencodex was routing the request. Retry later or switch to another configured provider.`},ko:{label:`제공자 의존성 실패`,description:`opencodex가 요청을 라우팅하는 동안 필요한 업스트림 의존성이 실패했습니다. 나중에 재시도하거나 다른 설정된 제공자로 전환해야 합니다.`},zh:{label:`提供商依赖失败`,description:`opencodex 路由请求时,必需的上游依赖失败。请稍后重试,或切换到另一个已配置的提供商。`},de:{label:`Anbieter-Abhängigkeit fehlgeschlagen`,description:`Eine erforderliche Upstream-Abhängigkeit ist fehlgeschlagen, während opencodex die Anfrage geroutet hat. Später erneut versuchen oder zu einem anderen Anbieter wechseln.`}},429:{en:{label:`Rate limited`,description:`The upstream provider rate or quota limit has been reached. Wait for the quota window to reset or switch account/provider.`},ko:{label:`한도 초과`,description:`업스트림 제공자의 속도 또는 할당량 한도에 도달했습니다. 한도 창이 초기화될 때까지 기다리거나 계정/제공자를 전환해야 합니다.`},zh:{label:`限流`,description:`已达到上游提供商的速率或额度限制。请等待额度窗口重置,或切换账号/提供商。`},de:{label:`Ratenlimit erreicht`,description:`Das Raten- oder Kontingentlimit des Upstream-Anbieters ist erreicht. Auf Reset des Kontingentfensters warten oder Konto/Anbieter wechseln.`}},499:{en:{label:`Client closed request`,description:`The client disconnected or canceled the request before opencodex finished routing it. Retry if the cancellation was accidental.`},ko:{label:`클라이언트 취소`,description:`opencodex가 라우팅을 끝내기 전에 클라이언트 연결이 끊기거나 요청이 취소되었습니다. 의도한 취소가 아니면 다시 시도해야 합니다.`},zh:{label:`客户端已取消`,description:`opencodex 完成路由前,客户端已断开连接或取消请求。如果不是有意取消,请重试。`},de:{label:`Client hat Anfrage geschlossen`,description:`Der Client hat die Verbindung getrennt oder die Anfrage abgebrochen, bevor opencodex das Routing abgeschlossen hat. Bei versehentlichem Abbruch erneut versuchen.`}},500:{en:{label:`Proxy error`,description:`opencodex hit an internal error while handling the request. Retry once, then check proxy logs if it repeats.`},ko:{label:`프록시 오류`,description:`opencodex가 요청을 처리하는 동안 내부 오류가 발생했습니다. 한 번 재시도하고 반복되면 프록시 로그를 확인해야 합니다.`},zh:{label:`代理错误`,description:`opencodex 处理请求时发生内部错误。请先重试一次;如果重复出现,请检查代理日志。`},de:{label:`Proxy-Fehler`,description:`opencodex ist bei der Anfragebearbeitung auf einen internen Fehler gestoßen. Einmal erneut versuchen, bei Wiederholung Proxy-Logs prüfen.`}},502:{en:{label:`Bad upstream response`,description:`The upstream provider returned an invalid or failed response through the proxy. Retry or route the request to another provider.`},ko:{label:`업스트림 응답 오류`,description:`업스트림 제공자가 프록시를 통해 유효하지 않거나 실패한 응답을 반환했습니다. 재시도하거나 다른 제공자로 라우팅해야 합니다.`},zh:{label:`上游响应错误`,description:`上游提供商通过代理返回了无效或失败的响应。请重试,或将请求路由到其他提供商。`},de:{label:`Ungültige Upstream-Antwort`,description:`Der Upstream-Anbieter lieferte über den Proxy eine ungültige oder fehlgeschlagene Antwort. Erneut versuchen oder zu einem anderen Anbieter routen.`}},503:{en:{label:`Provider unavailable`,description:`The proxy or upstream provider is temporarily unavailable or overloaded. Wait briefly, then retry or switch provider.`},ko:{label:`제공자 사용 불가`,description:`프록시 또는 업스트림 제공자가 일시적으로 사용할 수 없거나 과부하 상태입니다. 잠시 기다린 뒤 재시도하거나 제공자를 전환해야 합니다.`},zh:{label:`提供商不可用`,description:`代理或上游提供商暂时不可用或过载。请稍后重试,或切换提供商。`},de:{label:`Anbieter nicht verfügbar`,description:`Proxy oder Upstream-Anbieter ist vorübergehend nicht verfügbar oder überlastet. Kurz warten, dann erneut versuchen oder Anbieter wechseln.`}},504:{en:{label:`Upstream timeout`,description:`The upstream provider did not respond before the proxy timeout. Retry with a smaller request or choose a faster provider.`},ko:{label:`업스트림 시간 초과`,description:`프록시 시간 제한 전에 업스트림 제공자가 응답하지 않았습니다. 더 작은 요청으로 재시도하거나 더 빠른 제공자를 선택해야 합니다.`},zh:{label:`上游超时`,description:`上游提供商未在代理超时前响应。请缩小请求后重试,或选择响应更快的提供商。`},de:{label:`Upstream-Timeout`,description:`Der Upstream-Anbieter antwortete nicht vor dem Proxy-Timeout. Mit kleinerer Anfrage erneut versuchen oder schnelleren Anbieter wählen.`}},529:{en:{label:`Provider overloaded`,description:`The upstream provider is overloaded or capacity-limited. Wait and retry, or switch to another account/provider.`},ko:{label:`제공자 과부하`,description:`업스트림 제공자가 과부하 상태이거나 처리 용량이 제한되었습니다. 기다렸다가 재시도하거나 다른 계정/제공자로 전환해야 합니다.`},zh:{label:`提供商过载`,description:`上游提供商过载或容量受限。请等待后重试,或切换到其他账号/提供商。`},de:{label:`Anbieter überlastet`,description:`Der Upstream-Anbieter ist überlastet oder kapazitätsbegrenzt. Warten und erneut versuchen oder anderes Konto/Anbieter nutzen.`}}},qr={client:{en:{label:`Request error`,description:`The proxy or upstream provider rejected the request. Check the request shape, credentials, model name, and provider configuration.`},ko:{label:`요청 오류`,description:`프록시 또는 업스트림 제공자가 요청을 거부했습니다. 요청 형식, 자격 증명, 모델 이름, 제공자 설정을 확인해야 합니다.`},zh:{label:`请求错误`,description:`代理或上游提供商拒绝了该请求。请检查请求结构、凭据、模型名称和提供商配置。`},de:{label:`Anfragefehler`,description:`Der Proxy oder Upstream-Anbieter hat die Anfrage abgelehnt. Prüfe Anfrageformat, Anmeldedaten, Modellname und Anbieterkonfiguration.`}},server:{en:{label:`Server or upstream error`,description:`opencodex or an upstream provider failed while processing the request. Retry later or route the request to another provider.`},ko:{label:`서버 또는 업스트림 오류`,description:`opencodex 또는 업스트림 제공자가 요청 처리 중 실패했습니다. 나중에 재시도하거나 다른 제공자로 라우팅해야 합니다.`},zh:{label:`服务器或上游错误`,description:`opencodex 或上游提供商处理请求时失败。请稍后重试,或将请求路由到其他提供商。`},de:{label:`Server- oder Upstream-Fehler`,description:`opencodex oder ein Upstream-Anbieter ist bei der Anfragebearbeitung fehlgeschlagen. Später erneut versuchen oder zu einem anderen Anbieter routen.`}}};function Jr(e){return e===`de`||e===`ko`||e===`zh`?e:`en`}function Yr(e,t){if(e<400)return null;let n=Jr(t);return(Kr[Math.trunc(e)]??(e<500?qr.client:qr.server))[n]}function Xr(e,t){if(!e.usage)return;let n=Qr(e),r=[`${t(`logs.tokens.input`)}=${e.usage.inputTokens}`,`${t(`logs.tokens.output`)}=${e.usage.outputTokens}`];return n.read!==void 0&&r.push(`${t(`logs.tokens.cacheRead`)}=${n.read}`),n.write!==void 0&&r.push(`${t(`logs.tokens.cacheWrite`)}=${n.write}`),typeof e.usage.reasoningOutputTokens==`number`&&r.push(`${t(`logs.tokens.reasoning`)}=${e.usage.reasoningOutputTokens}`),e.usageStatus===`estimated`&&r.push(t(`logs.tokens.estimatedNote`)),e.usageStatus===`estimated`&&n.read===void 0&&n.write===void 0&&r.push(t(`logs.tokens.noCacheNote`)),r.join(` · `)}function Zr(e){if(!e.usage)return typeof e.totalTokens==`number`?e.totalTokens:void 0;let t=e.usage.inputTokens+e.usage.outputTokens,n=e.usage.totalTokens??e.totalTokens;return typeof n==`number`?Math.max(n,t):t}function Qr(e){let t=e.usage;if(!t)return{};let n=typeof t.cacheCreationInputTokens==`number`?t.cacheCreationInputTokens:void 0;return{read:typeof t.cacheReadInputTokens==`number`?t.cacheReadInputTokens:typeof t.cachedInputTokens==`number`&&n!==void 0?Math.max(0,t.cachedInputTokens-n):t.cachedInputTokens,write:n}}function $r(e){if(e.requestedSpeedLabel)return e.requestedSpeedLabel;if(e.modelSupportsServiceTier&&e.configuredSpeedLabel)return e.configuredSpeedLabel}function ei(e){return e>=200&&e<300?`var(--green)`:e>=400?`var(--red)`:`var(--amber)`}function ti(e,t){return new Date(e).toLocaleTimeString(t)}function ni(e,t){return new Date(e).toLocaleString(t)}function ri(e){return[`model=${e.model}`,e.resolvedModel?`resolved=${e.resolvedModel}`:void 0,e.requestedServiceTier?`requestedTier=${e.requestedServiceTier}`:void 0,e.configuredServiceTier?`configuredTier=${e.configuredServiceTier}`:void 0,e.responseServiceTier?`responseTier=${e.responseServiceTier}`:void 0,e.modelSupportsServiceTier===void 0?void 0:`supportsTier=${e.modelSupportsServiceTier}`].filter(Boolean).join(` · `)}function ii({apiBase:e}){let{t,locale:n}=H(),[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)(!0),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(`all`),d=(0,_.useRef)(null),f=ye.find(e=>e.code===n)?.htmlLang;(0,_.useEffect)(()=>{let t=async()=>{try{i(await(await fetch(`${e}/api/logs`)).json())}catch{}};if(t(),!a)return;let n=setInterval(t,2e3);return()=>clearInterval(n)},[e,a]);let p=s?Yr(s.status,n):null,m=r.filter(e=>l===`all`||(l===`claude`?e.surface===`claude`:e.surface!==`claude`)),h=Pn({count:m.length,getScrollElement:()=>d.current,estimateSize:()=>44,overscan:15}),g=h.getVirtualItems(),v=g.length>0?g[0].start:0,y=g.length>0?h.getTotalSize()-g[g.length-1].end:0;return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{children:t(`logs.title`)}),(0,S.jsxs)(`label`,{className:`muted text-control`,style:{cursor:`pointer`,display:`inline-flex`,alignItems:`center`,gap:6},children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(e.target.checked)}),t(`logs.autoRefresh`)]})]}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`logs.subtitle`)}),(0,S.jsxs)(`div`,{className:`row`,style:{gap:8,marginBottom:12,alignItems:`center`},children:[(0,S.jsx)(`span`,{className:`muted text-control`,children:t(`logs.filter.surface.label`)}),(0,S.jsx)(`div`,{className:`segmented`,role:`radiogroup`,"aria-label":t(`logs.filter.surface.label`),style:{display:`inline-flex`,borderRadius:`var(--radius-pill)`,background:`var(--surface-soft, var(--raised))`,padding:3,gap:2},children:[`all`,`claude`,`codex`].map(e=>(0,S.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":l===e,className:`btn btn-sm${l===e?` btn-primary`:` btn-ghost`}`,style:{borderRadius:`var(--radius-pill)`,minWidth:64,padding:`5px 12px`,border:`none`,background:l===e?void 0:`transparent`,color:l===e?void 0:`var(--muted)`},onClick:()=>u(e),children:t(`logs.filter.surface.${e}`)},e))})]}),m.length===0?(0,S.jsx)(Ae,{title:t(`logs.noRequests`)}):(0,S.jsx)(`div`,{ref:d,className:`tbl-wrap`,style:{overflowY:`auto`,maxHeight:`calc(100vh - 260px)`},children:(0,S.jsxs)(`table`,{className:`tbl`,children:[(0,S.jsx)(`thead`,{style:{position:`sticky`,top:0,zIndex:1,background:`var(--surface)`},children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:t(`logs.col.time`)}),(0,S.jsx)(`th`,{className:`num log-col-tokens`,children:t(`logs.col.tokens`)}),(0,S.jsx)(`th`,{className:`log-col-model`,children:t(`logs.col.model`)}),(0,S.jsx)(`th`,{children:t(`logs.col.effort`)}),(0,S.jsx)(`th`,{children:t(`logs.col.provider`)}),(0,S.jsx)(`th`,{children:t(`logs.col.status`)}),(0,S.jsx)(`th`,{children:t(`logs.col.request`)}),(0,S.jsx)(`th`,{className:`num`,children:t(`logs.col.duration`)})]})}),(0,S.jsxs)(`tbody`,{children:[v>0&&(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:8,style:{height:v,padding:0,border:0}})}),g.map(e=>{let r=m[m.length-1-e.index];return(0,S.jsxs)(`tr`,{"data-index":e.index,ref:h.measureElement,children:[(0,S.jsx)(`td`,{className:`muted mono`,children:ti(r.timestamp,f)}),(0,S.jsx)(`td`,{className:`num mono log-col-tokens`,title:Xr(r,t),children:(()=>{let e=Zr(r),{read:i,write:a}=Qr(r);return e===void 0?(0,S.jsx)(`span`,{className:`muted`,children:t(`logs.tokens.${r.usageStatus??`unreported`}`)}):(0,S.jsxs)(`span`,{style:{display:`inline-flex`,flexDirection:`column`,alignItems:`flex-end`,gap:2},children:[(0,S.jsxs)(`span`,{children:[r.usageStatus===`estimated`?`~`:``,Oe(e,n)]}),i!==void 0&&i>0&&(0,S.jsxs)(`span`,{className:`muted text-caption leading-tight`,children:[`c `,Oe(i,n)]}),a!==void 0&&a>0&&(0,S.jsxs)(`span`,{className:`muted text-caption leading-tight`,children:[`w `,Oe(a,n)]}),r.usageStatus===`estimated`&&i===void 0&&a===void 0&&(0,S.jsx)(`span`,{className:`muted text-caption leading-tight`,children:t(`logs.tokens.noCache`)})]})})()}),(0,S.jsx)(`td`,{className:`mono log-col-model`,title:ri(r),children:(0,S.jsxs)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:6,flexWrap:`wrap`},children:[(0,S.jsx)(`span`,{children:tr(r.resolvedModel??r.model)}),r.surface===`claude`&&(0,S.jsx)(`span`,{className:`badge badge-accent`,children:t(`logs.badge.claude`)}),$r(r)&&(0,S.jsx)(`span`,{className:`badge badge-amber`,children:$r(r)})]})}),(0,S.jsx)(`td`,{className:`mono`,children:r.requestedEffort??`-`}),(0,S.jsx)(`td`,{className:`muted`,children:r.provider}),(0,S.jsx)(`td`,{children:(0,S.jsxs)(`span`,{className:`log-status-cell`,children:[(0,S.jsx)(`span`,{className:`mono font-semibold`,style:{color:ei(r.status)},children:r.status}),r.status>=400&&(0,S.jsx)(`button`,{type:`button`,className:`log-detail-btn`,onClick:()=>c(r),children:t(`logs.details`)})]})}),(0,S.jsx)(`td`,{className:`muted mono`,children:(0,S.jsx)(`span`,{className:`log-reqid`,title:r.requestId,children:r.requestId??`-`})}),(0,S.jsxs)(`td`,{className:`num`,children:[r.durationMs,`ms`]})]},r.requestId??`${r.timestamp}-${e.index}`)}),y>0&&(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:8,style:{height:y,padding:0,border:0}})})]})]})}),s&&(0,S.jsx)(oi,{detail:s,detailInfo:p,localeTag:f,t,onClose:()=>c(null)})]})}function ai(e){let t=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let n=t.current;n&&(e&&!n.open?n.showModal():!e&&n.open&&n.close())},[e]),t}function oi({detail:e,detailInfo:t,localeTag:n,t:r,onClose:i}){return(0,S.jsx)(`dialog`,{ref:ai(!0),className:`modal-overlay`,"aria-labelledby":`log-detail-title`,onCancel:e=>{e.preventDefault(),i()},children:(0,S.jsxs)(`div`,{className:`modal-card`,children:[(0,S.jsxs)(`div`,{className:`modal-head`,children:[(0,S.jsxs)(`h3`,{id:`log-detail-title`,children:[(0,S.jsx)(`span`,{className:`mono`,style:{color:ei(e.status)},children:e.status}),t&&(0,S.jsx)(`span`,{style:{marginLeft:8},children:t.label})]}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:i,"aria-label":r(`common.cancel`),children:(0,S.jsx)(N,{})})]}),t&&(0,S.jsx)(`p`,{className:`modal-desc`,children:t.description}),(0,S.jsxs)(`div`,{className:`log-detail-grid`,children:[(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.time`)}),(0,S.jsx)(`span`,{className:`mono`,children:ni(e.timestamp,n)}),(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.request`)}),(0,S.jsx)(`span`,{className:`mono log-detail-break`,children:e.requestId??`-`}),(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.model`)}),(0,S.jsx)(`span`,{className:`mono`,children:tr(e.resolvedModel??e.model)}),(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.provider`)}),(0,S.jsx)(`span`,{children:e.provider}),e.errorCode&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.error`)}),(0,S.jsx)(`span`,{className:`mono`,children:e.errorCode})]}),e.upstreamError&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.upstreamReason`)}),(0,S.jsx)(`span`,{className:`mono log-detail-break`,children:e.upstreamError})]}),(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.duration`)}),(0,S.jsxs)(`span`,{className:`mono`,children:[e.durationMs,`ms`]})]}),(0,S.jsx)(`div`,{className:`muted text-label`,style:{margin:`12px 0 6px`},children:r(`logs.detailRaw`)}),(0,S.jsx)(`pre`,{className:`log-detail-json`,children:JSON.stringify(e,null,2)})]})})}var si=[`provider`,`usage`,`injection`];function ci(e){return e>0?`[${new Date(e).toLocaleTimeString()}] `:``}function li(e){return new Date(e).toLocaleTimeString()}function ui(e,t){return t===`provider`?!!e?.enabled:t===`usage`?!!e?.usage:!!e?.injection}function di(e,t){return t===`debug`?e.enabled:t===`usage`?e.usage:t===`injection`?e.injection:e.claude}function fi({apiBase:e}){let{t}=H(),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(`provider`),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)(!0),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)([]),g=(0,_.useRef)(0),v=(0,_.useRef)(null),y=Pn({count:c.length,getScrollElement:()=>v.current,estimateSize:()=>20,overscan:30,getItemKey:e=>c[e].seq});(0,_.useEffect)(()=>{let t=async()=>{try{let t=await fetch(`${e}/api/debug`);t.ok&&r(await t.json())}catch{}};t();let n=setInterval(()=>void t(),2e3);return()=>clearInterval(n)},[e]);let b=(0,_.useCallback)(e=>ui(n,e),[n]);(0,_.useEffect)(()=>{if(!n||b(o))return;let e=si.find(b);if(!e)return;let t=window.setTimeout(()=>s(e),0);return()=>window.clearTimeout(t)},[n,o,b]);let x=b(o),C=o===`provider`?`${e}/api/debug/logs`:o===`usage`?`${e}/api/debug/usage-logs`:`${e}/api/debug/injection-logs`,w=(0,_.useCallback)(async e=>{if(!x){l([]),g.current=0;return}p(!0);try{let t=new URLSearchParams({limit:`500`});!e&&g.current>0&&t.set(`after`,String(g.current));let n=await fetch(`${C}?${t}`);if(!n.ok)return;let r=await n.json();if(r.length===0)return;l(t=>(e?r:[...t,...r]).slice(-2e3)),g.current=r[r.length-1].seq}catch{}finally{p(!1)}},[C,x]);(0,_.useEffect)(()=>{g.current=0;let e=window.setTimeout(()=>{l([]),w(!0)},0);return()=>window.clearTimeout(e)},[o,x,w]),(0,_.useEffect)(()=>{if(!u||!x)return;let e=setInterval(()=>void w(!1),1e3);return()=>clearInterval(e)},[u,x,w]),(0,_.useEffect)(()=>{u&&c.length>0&&y.scrollToIndex(c.length-1,{align:`end`})},[c,u,y]),(0,_.useEffect)(()=>{if(!n?.claude){h([]);return}let t=async()=>{try{let t=await fetch(`${e}/api/claude/inbound-debug`);if(t.ok){let e=await t.json();h(Array.isArray(e.entries)?e.entries:[])}}catch{}};t();let r=setInterval(()=>void t(),2e3);return()=>clearInterval(r)},[e,n?.claude]);let T=async(t,n)=>{a(!0);try{let i=await fetch(`${e}/api/debug`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({[t]:n})});i.ok&&r(await i.json())}catch{}finally{a(!1)}},E=async()=>{a(!0);try{let t=await fetch(`${e}/api/debug`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({reset:!0})});t.ok&&r(await t.json())}catch{}finally{a(!1)}};return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{children:t(`debug.title`)}),(0,S.jsxs)(`div`,{style:{display:`inline-flex`,alignItems:`center`,gap:12},children:[(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:f||!x,onClick:()=>void w(!0),children:[(0,S.jsx)(ee,{}),` `,t(`debug.refresh`)]}),(0,S.jsxs)(`label`,{className:`muted text-control`,style:{cursor:`pointer`,display:`inline-flex`,alignItems:`center`,gap:6},children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked)}),t(`debug.follow`)]})]})]}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`debug.subtitle`)}),n?(0,S.jsxs)(`div`,{className:`card`,style:{marginBottom:16,padding:`12px 14px`},children:[(0,S.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:12,flexWrap:`wrap`},children:[(0,S.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:16},children:[`debug`,`usage`,`injection`,`claude`].map(e=>{let r=di(n,e);return(0,S.jsxs)(`div`,{style:{display:`inline-flex`,alignItems:`center`,gap:10,minWidth:220},children:[(0,S.jsx)(ke,{on:r,disabled:i,label:t(`debug.${e}`),onClick:()=>void T(e,!r)}),(0,S.jsx)(`span`,{className:`text-control`,children:t(`debug.${e}`)})]},e)})}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:i,onClick:()=>void E(),children:t(`debug.reset`)})]}),(n.enabled||n.usage||n.injection)&&(0,S.jsxs)(`div`,{style:{display:`inline-flex`,gap:6,marginTop:12},children:[n.enabled&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm${o===`provider`?` btn-primary`:` btn-ghost`}`,onClick:()=>s(`provider`),children:t(`debug.streamProvider`)}),n.usage&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm${o===`usage`?` btn-primary`:` btn-ghost`}`,onClick:()=>s(`usage`),children:t(`debug.streamUsage`)}),n.injection&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm${o===`injection`?` btn-primary`:` btn-ghost`}`,onClick:()=>s(`injection`),children:t(`debug.streamInjection`)})]})]}):(0,S.jsx)(`div`,{className:`empty`,children:t(`debug.loading`)}),n?.claude&&(0,S.jsxs)(`div`,{className:`card`,style:{marginBottom:16,padding:`12px 14px`},children:[(0,S.jsx)(`div`,{className:`font-semibold`,style:{marginBottom:4},children:t(`debug.claudeInbound.title`)}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{marginBottom:10},children:t(`debug.claudeInbound.sub`)}),m.length===0?(0,S.jsx)(`div`,{className:`muted text-control`,children:t(`debug.claudeInbound.empty`)}):(0,S.jsx)(`div`,{style:{overflowX:`auto`},children:(0,S.jsxs)(`table`,{className:`table text-label`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:t(`debug.claudeInbound.time`)}),(0,S.jsx)(`th`,{children:t(`debug.claudeInbound.endpoint`)}),(0,S.jsx)(`th`,{children:t(`debug.claudeInbound.model`)}),(0,S.jsx)(`th`,{children:`thinking`}),(0,S.jsx)(`th`,{children:`effort`}),(0,S.jsx)(`th`,{children:`beta`}),(0,S.jsx)(`th`,{children:`metadata`}),(0,S.jsx)(`th`,{children:`system`})]})}),(0,S.jsx)(`tbody`,{children:m.map((e,n)=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{className:`muted mono`,children:li(e.at)}),(0,S.jsx)(`td`,{className:`mono`,children:e.endpoint}),(0,S.jsxs)(`td`,{className:`mono`,title:e.resolvedModel,children:[e.model,e.resolvedModel&&e.resolvedModel!==e.model&&(0,S.jsxs)(`span`,{className:`muted`,children:[` → `,e.resolvedModel]})]}),(0,S.jsxs)(`td`,{className:`mono`,children:[e.thinkingType??`-`,e.thinkingBudgetTokens!==void 0&&(0,S.jsxs)(`span`,{className:`muted`,children:[` (`,e.thinkingBudgetTokens,`)`]})]}),(0,S.jsx)(`td`,{className:`mono`,children:e.outputConfigEffort??`-`}),(0,S.jsx)(`td`,{className:`mono`,title:e.anthropicBeta,style:{maxWidth:160,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.anthropicBeta??`-`}),(0,S.jsx)(`td`,{className:`mono`,title:e.metadataKeys?.join(`, `),children:e.hasMetadataUserId?`user_id ${e.userIdTag??``}`:t(`debug.claudeInbound.none`)}),(0,S.jsx)(`td`,{className:`mono`,children:e.hasSystem?e.systemTag??`yes`:t(`debug.claudeInbound.none`)})]},`${e.at}-${n}`))})]})})]}),n&&!x?(0,S.jsxs)(`div`,{className:`empty`,children:[(0,S.jsx)(`div`,{className:`font-semibold`,style:{marginBottom:6},children:t(`debug.emptyTitle`)}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{maxWidth:560,marginInline:`auto`},children:t(`debug.empty`)})]}):n&&x&&c.length===0?(0,S.jsxs)(`div`,{className:`empty`,children:[(0,S.jsx)(`div`,{className:`font-semibold`,style:{marginBottom:6},children:t(`debug.noLinesTitle`)}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{maxWidth:560,marginInline:`auto`},children:t(`debug.noLines.${o}`)})]}):n&&x?(0,S.jsx)(`div`,{ref:v,className:`log-detail-json`,style:{maxHeight:`calc(100vh - 280px)`,overflow:`auto`},children:(0,S.jsx)(`div`,{style:{position:`relative`,height:y.getTotalSize(),width:`100%`},children:y.getVirtualItems().map(e=>(0,S.jsx)(`div`,{ref:y.measureElement,"data-index":e.index,style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start}px)`},children:`${ci(c[e.index].at)}${c[e.index].line}`},e.key))})}):null]})}function pi(e){return`${Math.round(e*100)}%`}function mi(e,t){let n=`${t}/${e}`,r=0;for(let e=0;e<n.length;e++)r=r*31+n.charCodeAt(e)>>>0;return`hsl(${r%360} 55% 55%)`}function hi(e){let t=new Map(e.map(e=>[e.date,e])),n=[],r=new Date;r.setHours(0,0,0,0),r.setDate(r.getDate()-6);for(let e=0;e<7;e++){let e=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`,i=t.get(e);n.push({date:e,requests:i?.requests??0,measuredRequests:i?.measuredRequests??0,reportedRequests:i?.reportedRequests??0,totalTokens:i?.totalTokens??0,models:i?.models??[]}),r.setDate(r.getDate()+1)}return n}function gi(e){let t=e.filter(e=>e>0).sort((e,t)=>e-t);if(t.length===0)return[0,0,0,0];let n=e=>t[Math.min(t.length-1,Math.floor(e*t.length))];return[n(.25),n(.5),n(.75),n(.95)]}function _i(e,t){return e<=0?0:e<=t[0]?1:e<=t[1]?2:e<=t[2]?3:4}function vi(e){let t=gi(e.map(e=>e.totalTokens)),n=new Map(e.map(e=>[e.date,e])),r=new Date;r.setHours(0,0,0,0);let i=new Date(r);i.setDate(i.getDate()-364),i.setDate(i.getDate()-i.getDay());let a=[],o=[],s=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],c=-4,l=-1,u=[],d=new Date(i);for(;d<=r;){let e=`${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,`0`)}-${String(d.getDate()).padStart(2,`0`)}`,r=d.getMonth();d.getDay()===0&&r!==l&&a.length-c>=4&&(o.push({label:s[r],col:a.length}),c=a.length,l=r);let i=n.get(e);u.push({date:e,requests:i?.requests??0,totalTokens:i?.totalTokens??0,level:i?_i(i.totalTokens,t):0,dayOfWeek:d.getDay()}),d.getDay()===6&&(a.push(u),u=[]),d.setDate(d.getDate()+1)}if(u.length>0){for(;u.length<7;)u.push({date:``,requests:0,totalTokens:0,level:0,dayOfWeek:u.length});a.push(u)}return{weeks:a,months:o,buckets:t}}function yi({surface:e,range:t,onSurface:n,onRange:r,t:i}){return(0,S.jsxs)(`div`,{className:`usage-filters`,children:[(0,S.jsx)(`div`,{className:`usage-segmented`,role:`group`,"aria-label":i(`logs.filter.surface.label`),children:[`all`,`codex`,`claude`].map(t=>{let r=i(`logs.filter.surface.${t}`);return(0,S.jsxs)(`button`,{type:`button`,className:`usage-segmented-btn usage-source-btn${e===t?` active`:``}`,"aria-label":r,"aria-pressed":e===t,onClick:()=>n(t),children:[t===`codex`&&(0,S.jsx)(`img`,{className:`usage-source-mark`,src:`/provider-icons/openai.svg`,alt:``,"aria-hidden":`true`}),t===`claude`&&(0,S.jsx)(`img`,{className:`usage-source-mark`,src:`/provider-icons/claude.svg`,alt:``,"aria-hidden":`true`}),(0,S.jsx)(`span`,{className:t===`all`?`usage-source-label`:`usage-source-label usage-source-label-collapsible`,children:r})]},t)})}),(0,S.jsx)(`div`,{className:`usage-segmented`,role:`group`,"aria-label":i(`usage.title`),children:[`all`,`30d`,`7d`].map(e=>{let n=i(`usage.range.${e}`);return(0,S.jsx)(`button`,{type:`button`,className:`usage-segmented-btn${t===e?` active`:``}`,"aria-label":n,"aria-pressed":t===e,onClick:()=>r(e),children:n},e)})})]})}function bi({summary:e,activeDays:t,locale:n,t:r}){return(0,S.jsxs)(`div`,{className:`usage-cards usage-cards-3x2`,role:`group`,"aria-label":r(`usage.title`),children:[(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.requests`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.requests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.measured`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.measuredRequests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.totalTokens`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:Oe(e.totalTokens,n)})]}),(0,S.jsxs)(`div`,{className:`stat`,title:r(`usage.card.cachedTokensHint`),children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.cachedTokens`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:Oe(e.cacheReadInputTokens??e.cachedInputTokens,n)}),(e.cacheCreationInputTokens??0)>0&&(0,S.jsxs)(`div`,{className:`muted text-caption`,children:[r(`usage.card.cacheWriteTokens`),`: `,Oe(e.cacheCreationInputTokens??0,n)]})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.coverage`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:pi(e.coverageRatio)})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.activeDays`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:t})]})]})}function xi({weekBars:e,locale:t,t:n}){let[r,i]=(0,_.useState)(null),a=Math.max(1,...e.map(e=>e.totalTokens));return(0,S.jsx)(`div`,{className:`daybars`,role:`img`,"aria-label":n(`usage.section.heatmap`),children:e.map(e=>{let n=Math.round(e.totalTokens/a*100),o=e.date.slice(5);return(0,S.jsxs)(`div`,{className:`daybar`,onMouseEnter:()=>i(e.date),onMouseLeave:()=>i(t=>t===e.date?null:t),children:[(0,S.jsx)(`div`,{className:`daybar-track`,children:(0,S.jsxs)(`div`,{className:`daybar-stack`,style:{height:`${n}%`},children:[e.models.map(e=>(0,S.jsx)(`div`,{className:`daybar-seg`,style:{flexGrow:e.totalTokens,background:mi(e.model,e.provider)}},`${e.provider}/${e.model}`)),e.models.length===0&&e.totalTokens>0&&(0,S.jsx)(`div`,{className:`daybar-seg`,style:{flexGrow:1,background:`var(--green)`}})]})}),r===e.date&&e.totalTokens>0&&(0,S.jsxs)(`div`,{className:`daybar-tip`,role:`tooltip`,children:[(0,S.jsx)(`div`,{className:`daybar-tip-date`,children:e.date}),e.models.slice(0,8).map(e=>(0,S.jsxs)(`div`,{className:`daybar-tip-row`,children:[(0,S.jsx)(`span`,{className:`daybar-tip-swatch`,style:{background:mi(e.model,e.provider)}}),(0,S.jsx)(`span`,{className:`daybar-tip-name`,children:tr(e.model)}),(0,S.jsx)(`span`,{className:`daybar-tip-val`,children:Oe(e.totalTokens,t)})]},`${e.provider}/${e.model}`))]}),(0,S.jsx)(`span`,{className:`daybar-count`,children:Oe(e.totalTokens,t)}),(0,S.jsx)(`span`,{className:`daybar-label muted`,children:o})]},e.date)})})}function Si({range:e,heatmap:t,weekBars:n,locale:r,t:i}){let a=(0,_.useRef)(null),[o,s]=(0,_.useState)(null);return(0,_.useEffect)(()=>{let e=a.current;if(!e)return;let t=()=>{e.scrollLeft=e.scrollWidth};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[t,e]),(0,S.jsxs)(`section`,{className:`panel`,style:{marginTop:16},"aria-labelledby":`usage-heatmap-title`,children:[(0,S.jsx)(`h3`,{id:`usage-heatmap-title`,className:`panel-title`,children:i(`usage.section.heatmap`)}),e===`7d`?(0,S.jsx)(xi,{weekBars:n,locale:r,t:i}):(0,S.jsxs)(`div`,{className:`heatmap`,ref:a,role:`img`,"aria-labelledby":`usage-heatmap-title`,children:[(0,S.jsxs)(`div`,{className:`heatmap-months`,style:{gridTemplateColumns:`28px repeat(${t.weeks.length}, calc(var(--hm-cell) + var(--hm-gap)))`},children:[(0,S.jsx)(`span`,{className:`heatmap-day-spacer`}),t.months.map(e=>(0,S.jsx)(`span`,{className:`heatmap-month`,style:{gridColumn:e.col+2},children:e.label},`${e.label}-${e.col}`))]}),(0,S.jsxs)(`div`,{className:`heatmap-body`,children:[(0,S.jsxs)(`div`,{className:`heatmap-days`,children:[(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{children:i(`usage.dayMon`)}),(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{children:i(`usage.dayWed`)}),(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{children:i(`usage.dayFri`)}),(0,S.jsx)(`span`,{})]}),(0,S.jsx)(`div`,{className:`heatmap-grid`,style:{gridTemplateColumns:`repeat(${t.weeks.length}, var(--hm-cell))`},children:t.weeks.map((e,t)=>(0,S.jsx)(`div`,{className:`heatmap-week`,children:e.map((e,n)=>(0,S.jsx)(`div`,{className:`heatmap-cell heatmap-cell-${e.level}`,onMouseEnter:r=>{if(!e.date)return;let i=r.currentTarget.getBoundingClientRect();s({weekIndex:t,dayIndex:n,x:i.left+i.width/2,y:i.top})},onMouseLeave:()=>s(e=>e?.weekIndex===t&&e.dayIndex===n?null:e)},e.date||`pad-${t}-${n}`))},e[0]?.date||`week-${t}`))})]}),o&&(()=>{let e=t.weeks[o.weekIndex]?.[o.dayIndex];return e?.date?(0,S.jsxs)(`div`,{className:`heatmap-tip`,role:`tooltip`,style:{left:o.x,top:o.y},children:[(0,S.jsx)(`div`,{className:`heatmap-tip-date`,children:e.date}),(0,S.jsx)(`div`,{className:`heatmap-tip-val`,children:i(`usage.heatmap.tooltipTokens`,{tokens:Oe(e.totalTokens,r)})}),(0,S.jsx)(`div`,{className:`heatmap-tip-req muted`,children:i(`usage.heatmap.tooltipRequests`,{requests:e.requests})})]}):null})(),(0,S.jsxs)(`div`,{className:`heatmap-legend muted`,children:[(0,S.jsx)(`span`,{children:i(`usage.heatmap.less`)}),[0,1,2,3,4].map(e=>(0,S.jsx)(`span`,{className:`heatmap-cell heatmap-cell-${e}`},e)),(0,S.jsx)(`span`,{children:i(`usage.heatmap.more`)})]})]})]})}function Ci({models:e,modelQuery:t,onModelQuery:n,locale:r,t:i}){let a=i(`usage.search.models`);return(0,S.jsxs)(`section`,{className:`panel`,style:{marginTop:16},"aria-labelledby":`usage-models-title`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`h3`,{id:`usage-models-title`,className:`panel-title`,children:i(`usage.section.models`)}),(0,S.jsx)(`input`,{className:`input`,"aria-label":a,placeholder:a,value:t,onChange:e=>n(e.target.value)})]}),(0,S.jsx)(`div`,{className:`tbl-wrap usage-scroll`,children:(0,S.jsxs)(`table`,{className:`tbl`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:i(`logs.col.model`)}),(0,S.jsx)(`th`,{children:i(`logs.col.provider`)}),(0,S.jsx)(`th`,{className:`num`,children:i(`usage.col.requests`)}),(0,S.jsx)(`th`,{className:`num`,children:i(`usage.col.measured`)}),(0,S.jsx)(`th`,{className:`num`,children:i(`usage.col.tokens`)}),(0,S.jsx)(`th`,{children:i(`usage.col.share`)})]})}),(0,S.jsx)(`tbody`,{children:e.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{className:`mono`,children:tr(e.resolvedModel??e.model)}),(0,S.jsx)(`td`,{className:`muted`,children:e.provider}),(0,S.jsx)(`td`,{className:`num`,children:e.requests}),(0,S.jsx)(`td`,{className:`num`,children:e.measuredRequests}),(0,S.jsx)(`td`,{className:`num mono`,children:Oe(e.totalTokens,r)}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`div`,{className:`usage-bar`,children:(0,S.jsx)(`div`,{className:`usage-bar-fill`,style:{width:`${Math.round(e.shareRatio*100)}%`}})})})]},`${e.provider}/${e.model}/${e.resolvedModel??``}`))})]})})]})}function wi({providers:e,locale:t,t:n}){return(0,S.jsxs)(`section`,{className:`panel`,style:{marginTop:16},"aria-labelledby":`usage-providers-title`,children:[(0,S.jsx)(`h3`,{id:`usage-providers-title`,className:`panel-title`,children:n(`usage.section.providers`)}),(0,S.jsx)(`div`,{className:`tbl-wrap usage-scroll`,children:(0,S.jsxs)(`table`,{className:`tbl`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:n(`logs.col.provider`)}),(0,S.jsx)(`th`,{className:`num`,children:n(`usage.col.requests`)}),(0,S.jsx)(`th`,{className:`num`,children:n(`usage.col.measured`)}),(0,S.jsx)(`th`,{className:`num`,children:n(`usage.col.tokens`)}),(0,S.jsx)(`th`,{children:n(`usage.col.share`)})]})}),(0,S.jsx)(`tbody`,{children:e.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{className:`mono`,children:e.provider}),(0,S.jsx)(`td`,{className:`num`,children:e.requests}),(0,S.jsx)(`td`,{className:`num`,children:e.measuredRequests}),(0,S.jsx)(`td`,{className:`num mono`,children:Oe(e.totalTokens,t)}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`div`,{className:`usage-bar`,children:(0,S.jsx)(`div`,{className:`usage-bar-fill`,style:{width:`${Math.round(e.shareRatio*100)}%`}})})})]},e.provider))})]})})]})}function Ti({summary:e,t}){return(0,S.jsxs)(`section`,{className:`panel`,style:{marginTop:16},"aria-labelledby":`usage-coverage-title`,children:[(0,S.jsx)(`h3`,{id:`usage-coverage-title`,className:`panel-title`,children:t(`usage.section.coverage`)}),(0,S.jsxs)(`div`,{className:`usage-cards usage-cards-3x2`,children:[(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:t(`usage.coverage.measured`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.measuredRequests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:t(`usage.coverage.reported`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.reportedRequests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:t(`usage.coverage.estimated`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.estimatedRequests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:t(`logs.tokens.unreported`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.unreportedRequests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:t(`logs.tokens.unsupported`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.unsupportedRequests})]})]}),(0,S.jsx)(`p`,{className:`muted text-control`,style:{marginTop:12},children:t(`usage.coverage.note`)})]})}function Ei({apiBase:e}){let{t,locale:n}=H(),[r,i]=(0,_.useState)(`30d`),[a,o]=(0,_.useState)(`all`),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(!0),[d,f]=(0,_.useState)(``),p=(0,_.useCallback)(async(t,n,r)=>{u(!0);try{let i=await fetch(`${e}/api/usage?range=${t}&surface=${n}`,{signal:r});if(!i.ok)throw Error(`fetch failed`);let a=await i.json();if(r.aborted)return;c(a)}catch{if(r.aborted)return;c(null)}finally{r.aborted||u(!1)}},[e]);(0,_.useEffect)(()=>{let e=new AbortController,t=window.setTimeout(()=>{p(r,a,e.signal)},0);return()=>{window.clearTimeout(t),e.abort()}},[p,r,a]);let m=(0,_.useMemo)(()=>vi(s?.days??[]),[s?.days]),h=(0,_.useMemo)(()=>hi(s?.days??[]),[s?.days]),g=(0,_.useMemo)(()=>(s?.days??[]).filter(e=>e.requests>0).length,[s?.days]),v=(0,_.useMemo)(()=>{let e=d.trim().toLowerCase(),t=[...s?.models??[]].sort((e,t)=>t.totalTokens-e.totalTokens);return e?t.filter(t=>t.model.toLowerCase().includes(e)||t.provider.toLowerCase().includes(e)||(t.resolvedModel??``).toLowerCase().includes(e)).slice(0,100):t.slice(0,100)},[s?.models,d]),y=(0,_.useMemo)(()=>[...s?.providers??[]].sort((e,t)=>t.totalTokens-e.totalTokens),[s?.providers]);return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head usage-head`,children:[(0,S.jsx)(`h2`,{id:`usage-page-title`,children:t(`usage.title`)}),(0,S.jsx)(yi,{surface:a,range:r,onSurface:o,onRange:i,t})]}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`usage.subtitle`)}),l&&!s?(0,S.jsx)(Ae,{title:t(`usage.loading`)}):!s||s.summary.requests===0?(0,S.jsx)(Ae,{title:t(`usage.empty`)}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(bi,{summary:s.summary,activeDays:g,locale:n,t}),(0,S.jsx)(Si,{range:r,heatmap:m,weekBars:h,locale:n,t}),(0,S.jsx)(Ci,{models:v,modelQuery:d,onModelQuery:f,locale:n,t}),(0,S.jsx)(wi,{providers:y,locale:n,t}),(0,S.jsx)(Ti,{summary:s.summary,t})]})]})}function Di(e){if(!e||typeof e!=`object`)return`absent`;let t=e.providers;if(!t||typeof t!=`object`||Array.isArray(t)||!Object.hasOwn(t,`openai`))return`absent`;let n=t.openai;if(!n||typeof n!=`object`||Array.isArray(n))return`absent`;let r=n;return r.disabled===!0?`disabled`:r.codexAccountMode===`direct`?`direct`:r.codexAccountMode===void 0||r.codexAccountMode===`pool`?`pool`:`absent`}function K({apiBase:e}){let t=U(),[n,r]=(0,_.useState)(null),i=(0,_.useCallback)(async()=>{try{r(Di(await fetch(`${e}/api/config`).then(e=>e.json())))}catch{}},[e]);return(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{i()},0),t=window.setInterval(()=>{i()},3e4);return()=>{window.clearTimeout(e),window.clearInterval(t)}},[i]),(0,S.jsx)(Rn,{apiBase:e,accountModeState:n,banner:(0,S.jsxs)(`div`,{className:`panel`,style:{marginBottom:16},children:[(0,S.jsxs)(`div`,{className:`row`,children:[(0,S.jsx)(`strong`,{children:t(`codexAuth.accountModeTitle`)}),n===`pool`&&(0,S.jsx)(`span`,{className:`badge badge-accent`,children:t(`codexAuth.accountModePool`)}),n===`direct`&&(0,S.jsx)(`span`,{className:`badge badge-green`,children:t(`codexAuth.accountModeDirect`)})]}),n===`pool`&&(0,S.jsx)(`p`,{className:`card-sub`,style:{margin:`6px 0 0`},children:t(`codexAuth.accountModePoolDesc`)}),n===`direct`&&(0,S.jsxs)(`p`,{className:`card-sub`,style:{margin:`6px 0 0`},children:[t(`codexAuth.accountModeDirectDesc`),` `,(0,S.jsx)(`a`,{href:`#providers`,children:t(`codexAuth.openProviders`)})]}),n===`absent`&&(0,S.jsxs)(`p`,{className:`card-sub`,style:{margin:`8px 0 0`},children:[t(`codexAuth.openaiMissing`),` `,(0,S.jsx)(`a`,{href:`#providers`,children:t(`codexAuth.openProviders`)})]}),n===`disabled`&&(0,S.jsxs)(`p`,{className:`card-sub`,style:{margin:`8px 0 0`},children:[t(`codexAuth.openaiDisabled`),` `,(0,S.jsx)(`a`,{href:`#providers`,children:t(`codexAuth.openProviders`)})]})]})})}function Oi(e,t){return new Date(e).toLocaleDateString(t)}function ki({apiBase:e}){let{t,locale:n}=H(),r=ye.find(e=>e.code===n)?.htmlLang,[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=(0,_.useCallback)(async()=>{try{let t=await fetch(`${e}/api/keys`);if(t.ok){let e=await t.json();a(e.keys??[]),s(e.endpoint??``)}}catch{}},[e]);(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{y()},0);return()=>window.clearTimeout(e)},[y]);let b=o||`http://127.0.0.1:10100/v1/responses`,x=async()=>{d(!0);try{let t=await fetch(`${e}/api/keys`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:c||`default`})});t.ok&&(p((await t.json()).key),l(``),y())}finally{d(!1)}},C=async t=>{await fetch(`${e}/api/keys`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:t})}),v(null),y()},w=()=>{f&&(navigator.clipboard.writeText(f),h(!0),setTimeout(()=>h(!1),2e3))},T=t(`api.subtitle`).split(/\{authHeader\}|\{altHeader\}/);return(0,S.jsxs)(`section`,{className:`api-page`,children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h2`,{children:t(`api.title`)})}),(0,S.jsxs)(`p`,{className:`page-sub`,children:[T[0],(0,S.jsx)(`code`,{children:`Authorization: Bearer ocx_...`}),T[1],(0,S.jsx)(`code`,{children:`x-opencodex-api-key`}),T[2]]}),(0,S.jsxs)(`div`,{className:`panel api-panel`,children:[(0,S.jsx)(`h3`,{className:`panel-title`,children:t(`api.endpoint`)}),(0,S.jsx)(`code`,{className:`api-code api-code-inline`,children:b}),(0,S.jsx)(`p`,{className:`muted small`,children:t(`api.endpointNote`)})]}),f&&(0,S.jsxs)(`div`,{className:`panel api-panel panel-accent`,style:{marginTop:`1rem`},children:[(0,S.jsx)(`h3`,{className:`panel-title`,children:t(`api.newKeyTitle`)}),(0,S.jsx)(`p`,{className:`muted small`,children:t(`api.newKeyNote`)}),(0,S.jsxs)(`div`,{className:`api-form-row`,children:[(0,S.jsx)(`code`,{className:`api-code`,style:{flex:1,wordBreak:`break-all`},children:f}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,onClick:w,children:m?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(M,{}),` `,t(`api.copied`)]}):t(`api.copy`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,style:{alignSelf:`flex-start`},onClick:()=>p(null),children:t(`api.dismiss`)})]}),(0,S.jsxs)(`div`,{className:`panel api-panel`,style:{marginTop:`1rem`},children:[(0,S.jsx)(`h3`,{className:`panel-title`,children:t(`api.generateTitle`)}),(0,S.jsxs)(`div`,{className:`api-form-row`,children:[(0,S.jsx)(`input`,{id:`api-key-name`,type:`text`,placeholder:t(`api.keyNamePlaceholder`),"aria-label":t(`api.keyNamePlaceholder`),value:c,onChange:e=>l(e.target.value),className:`input`}),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-primary`,onClick:x,disabled:u,children:[(0,S.jsx)(P,{}),` `,t(u?`api.generating`:`api.generate`)]})]})]}),(0,S.jsxs)(`div`,{className:`panel api-panel`,style:{marginTop:`1rem`},children:[(0,S.jsx)(`h3`,{className:`panel-title`,children:t(`api.activeKeys`,{count:i.length})}),i.length===0?(0,S.jsx)(`p`,{className:`muted`,children:t(`api.noKeys`)}):(0,S.jsx)(`div`,{className:`tbl-wrap`,children:(0,S.jsxs)(`table`,{className:`tbl`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:t(`api.colName`)}),(0,S.jsx)(`th`,{children:t(`api.colKey`)}),(0,S.jsx)(`th`,{children:t(`api.colCreated`)}),(0,S.jsx)(`th`,{})]})}),(0,S.jsx)(`tbody`,{children:i.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{children:e.name}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`code`,{children:e.prefix})}),(0,S.jsx)(`td`,{children:Oi(e.createdAt,r)}),(0,S.jsx)(`td`,{children:g===e.id?(0,S.jsxs)(`span`,{className:`api-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-danger`,onClick:()=>C(e.id),children:t(`api.confirm`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,onClick:()=>v(null),children:t(`common.cancel`)})]}):(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,"aria-label":t(`api.deleteAria`),onClick:()=>v(e.id),children:(0,S.jsx)(N,{})})})]},e.id))})]})})]}),(0,S.jsxs)(`div`,{className:`panel api-panel`,style:{marginTop:`1rem`},children:[(0,S.jsx)(`h3`,{className:`panel-title`,children:t(`api.usageTitle`)}),(0,S.jsx)(`pre`,{className:`api-code`,children:`curl ${b} \\
|
|
33
|
+
更改在新会话中生效。`,"models.v2DocsLink":`v1 / v2 是什么?`,"dash.multiAgent":`子代理`,"models.v2Conflict":`[agents] max_threads 仍存在 — codex 将拒绝启动,请从 config.toml 移除`,"models.v2Applied":`multi_agent_v2 已更新 — 新会话生效(重启 Codex 应用以刷新选择器)`,"models.v2ThreadsLabel":`最大线程`,"models.v2ThreadsDefault":`默认 (4)`,"models.v2ThreadsApplied":`线程上限已更新 — 新会话生效`,"models.v2ThreadsInvalid":`线程上限必须为 >= 1 的整数`,"models.v2ThreadsApply":`应用`,"models.capValue":`限制 {value}`,"models.contextCappedValue":`{value} 限制`,"models.setAll":`全部设置`,"models.custom":`自定义…`,"models.customApply":`应用`,"models.customPlaceholder":`令牌 (例如 420000)`,"models.applied":`已应用 — 将在下一个 Codex 回合生效。`,"models.saveFailed":`保存失败`,"models.networkError":`网络错误 — 代理在运行吗?`,"models.loadFail":`加载模型失败 — 代理在运行吗?`,"models.noRouted":`没有已路由的模型`,"models.noRoutedHint":`请先登录提供方或添加一个。`,"models.loading":`加载中…`,"models.search":`搜索模型…`,"models.showMore":`再显示 {n} 个`,"models.allowlistLabel":`仅所选`,"models.allowlistHint":`仅勾选的模型进入目录(留空 = 全部)。适用于暴露成千上万模型的提供商。`,"models.selectedCount":`已选 {n} 个`,"models.orderHint":`选择器顺序:Subagents 中的选择(按所选顺序)→ 其余已路由模型(依次按提供方、模型 ID 字母排序)→ 原生模型。可见性开关仅用于筛选,不会改变此顺序。`,"sub.subtitle":`Codex 的 {cmd} 仅将优先级最高的前 5 个模型作为覆盖项公开。在此最多选择 5 个 — 原生 gpt 或已路由模型 — opencodex 会设置它们的目录优先级,使其正好排在前面。其他模型仍可按确切名称调用;此设置仅控制显示项。`,"sub.featured":`精选`,"sub.orderHint":`此处所选并显示的顺序决定 Codex 模型选择器顶部第 1–5 位,以及 {cmd} 的默认模型候选。`,"sub.noneSelected":`未选择 — 请从下方列表选择。`,"sub.models":`模型`,"sub.search":`搜索模型(原生 gpt + 已路由)…`,"sub.noModels":`没有模型 — 请先登录提供方或添加一个。`,"sub.saved":`已保存 {n} 个模型。启动新的 Codex 会话(或运行 {cmd})以将它们作为 spawn_agent 覆盖项查看。`,"sub.saveFailed":`保存失败`,"sub.networkError":`网络错误 — 代理在运行吗?`,"sub.loadFail":`加载模型失败 — 代理在运行吗?`,"sub.loading":`加载中…`,"sub.moveUp":`上移 {m}`,"sub.moveDown":`下移 {m}`,"sub.removeAria":`移除 {m}`,"logs.title":`请求日志`,"logs.subtitle":`经过本地 opencodex 代理的最近请求,最新在前。`,"logs.autoRefresh":`自动刷新`,"logs.noRequests":`暂无请求。`,"logs.filter.surface.label":`界面`,"logs.filter.surface.all":`全部`,"logs.filter.surface.claude":`Claude`,"logs.filter.surface.codex":`Codex`,"logs.badge.claude":`Claude`,"logs.col.time":`时间`,"logs.col.request":`请求`,"logs.col.model":`模型`,"logs.col.effort":`推理强度`,"logs.col.provider":`提供方`,"logs.col.status":`状态`,"logs.col.tokens":`Token 数`,"logs.col.error":`错误`,"logs.col.upstreamReason":`上游原因`,"logs.col.duration":`耗时`,"logs.tokens.reported":`已上报`,"logs.tokens.unreported":`未上报`,"logs.tokens.unsupported":`不支持`,"logs.tokens.estimated":`估算`,"logs.tokens.input":`输入`,"logs.tokens.output":`输出`,"logs.tokens.cacheRead":`缓存命中 (c)`,"logs.tokens.cacheWrite":`缓存写入 (w)`,"logs.tokens.reasoning":`推理`,"logs.tokens.noCache":`无缓存数据`,"logs.tokens.noCacheNote":`该提供商不报告缓存 token 数`,"logs.tokens.estimatedNote":`估算值(提供商不报告精确用量)`,"logs.details":`查看详情`,"logs.detailTitle":`请求详情`,"logs.detailRaw":`原始日志`,"debug.title":`调试`,"debug.subtitle":`可选的 provider transport 与 usage 提取诊断。请求错误和 502 在 Logs 页面。`,"debug.debug":`Provider debug`,"debug.usage":`Usage 提取`,"debug.injection":`注入日志`,"debug.claude":`Claude 入站`,"debug.claudeInbound.title":`Claude 入站请求`,"debug.claudeInbound.sub":`显示 Claude Code/Desktop 实际发送的内容(thinking、effort、metadata)— 不保存提示词原文。`,"debug.claudeInbound.empty":`尚未捕获任何请求。开启后从 Claude 发送一条消息试试。`,"debug.claudeInbound.time":`时间`,"debug.claudeInbound.endpoint":`端点`,"debug.claudeInbound.model":`模型`,"debug.claudeInbound.none":`无`,"debug.reset":`清除运行时覆盖`,"debug.refresh":`刷新`,"debug.follow":`跟随滚动`,"debug.streamProvider":`Provider`,"debug.streamUsage":`Usage`,"debug.streamInjection":`Injection`,"debug.loading":`正在加载调试设置…`,"debug.emptyTitle":`调试日志已关闭`,"debug.empty":`请在上方卡片中开启 Provider debug 或 Usage extraction。通过代理发送请求后,诊断行会显示在这里。`,"debug.noLinesTitle":`等待诊断行`,"debug.noLines.provider":`提供商调试已开启,但仅记录传输异常(丢弃或格式错误的帧,以及 Cursor dial/retry 事件)。通过 Anthropic 等提供商的正常请求可能不会产生任何行。`,"debug.noLines.usage":`用量提取已开启但尚未捕获任何内容。请通过 Codex 发送请求,随后会显示在此处。`,"debug.noLines.injection":`注入日志已开启但尚未捕获任何内容。它记录协作和子代理回合中的多代理指导注入与 effort-cap 决策。`,"usage.title":`用量`,"usage.subtitle":`代理本地的 Token 用量统计。缺失的用量不会显示为零。`,"usage.loading":`正在加载用量数据…`,"usage.empty":`尚无用量记录。通过代理发送请求后将在此显示。`,"usage.range.all":`全部`,"usage.range.30d":`30 天`,"usage.range.7d":`7 天`,"usage.card.requests":`请求数`,"usage.card.measured":`已计量`,"usage.card.reported":`已上报`,"usage.card.totalTokens":`Token 总数`,"usage.card.cachedTokens":`缓存命中 Token`,"usage.card.cachedTokensHint":`从提供商缓存读取的提示 Token(命中)。缓存写入在下方单独显示。`,"usage.card.cacheWriteTokens":`缓存写入`,"usage.card.coverage":`覆盖率`,"usage.card.activeDays":`活跃天数`,"usage.section.heatmap":`每日活动`,"usage.section.models":`模型`,"usage.section.providers":`提供方`,"usage.section.coverage":`覆盖率明细`,"usage.coverage.measured":`已计量`,"usage.coverage.reported":`提供方上报`,"usage.coverage.estimated":`估算`,"usage.coverage.note":`已计量包含提供方上报和估算的 Token 数。未上报 / 不支持请求仅做计数,不会被算作 0 Token。`,"usage.search.models":`搜索模型…`,"usage.col.requests":`请求数`,"usage.col.measured":`已计量`,"usage.col.reported":`已上报`,"usage.col.tokens":`Token 数`,"usage.col.share":`占比`,"usage.heatmap.less":`少`,"usage.heatmap.more":`多`,"modal.addNamed":`添加:{label}`,"modal.add":`添加提供方`,"modal.search":`搜索提供方…`,"modal.logInWith":`使用 {label} 登录`,"modal.waitingBrowser":`等待浏览器…`,"modal.providerName":`提供方名称`,"modal.adapter":`适配器`,"modal.baseUrl":`Base URL`,"modal.defaultModel":`默认模型(可选)`,"modal.nameRequired":`提供方名称为必填项`,"modal.baseUrlRequired":`Base URL 为必填项`,"modal.networkError":`网络错误 — 代理在运行吗?`,"modal.loginFailStart":`登录启动失败`,"modal.waitingLogin":`等待浏览器登录…`,"modal.loggingIn":`登录中…`,"modal.loginTimeout":`登录超时 — 请重试。`,"nav.api":`API`,"nav.codexAuth":`Codex 认证`,"nav.openMenu":`打开菜单`,"nav.closeMenu":`关闭菜单`,"codexAuth.mainAccount":`主账号`,"codexAuth.appLogin":`应用登录`,"codexAuth.accountPool":`账号池`,"codexAuth.accountModeTitle":`OpenAI 账户模式`,"codexAuth.accountModePool":`账户池模式`,"codexAuth.accountModePoolDesc":`主登录与符合条件的已添加账户会在此轮换。`,"codexAuth.accountModeDirect":`直连模式`,"codexAuth.accountModeDirectDesc":`请求仅使用主登录;已添加账户会继续存储,供账户池模式使用。`,"codexAuth.openaiMissing":`未配置内置 OpenAI 提供方。`,"codexAuth.openaiDisabled":`内置 OpenAI 提供方已禁用。`,"codexAuth.openProviders":`打开提供商`,"codexAuth.add":`添加`,"codexAuth.refreshQuota":`刷新额度`,"codexAuth.refreshingQuota":`刷新中...`,"codexAuth.quotaRefreshed":`额度已刷新`,"codexAuth.quotaRefreshFailed":`额度刷新失败`,"codexAuth.noPool":`尚未添加池账号。`,"codexAuth.fiveHour":`5 小时`,"codexAuth.weekly":`每周`,"codexAuth.monthly":`30天`,"codexAuth.resets":`重置`,"codexAuth.today":`今天`,"codexAuth.current":`当前`,"codexAuth.nextSession":`下次会话`,"codexAuth.poolPrepared":`已为账户池准备`,"codexAuth.preparePoolTitle":`为账户池模式准备此账号?`,"codexAuth.preparePoolDesc":`直连请求仍使用主登录。启用账户池模式后,此账号会成为预先选择的池账号。`,"codexAuth.prepareForPool":`为账户池准备`,"codexAuth.poolPreparedToast":`已为账户池模式准备 {email}`,"codexAuth.switchTitle":`切换活跃账号?`,"codexAuth.switchDesc":`从下次 Codex 会话开始生效。当前会话保持现有账号。`,"codexAuth.cacheWarning":`切换账号会重置提示缓存。新会话从空缓存开始。`,"codexAuth.setAsNext":`设为下次会话`,"codexAuth.cancel":`取消`,"codexAuth.switchBack":`切换回主账号?`,"codexAuth.switchBackDesc":`下次 Codex 会话将使用应用登录账号。`,"codexAuth.autoSwitch":`超过 80% 时自动切换`,"codexAuth.autoSwitchDesc":`新会话会在相关额度窗口达到阈值时切换;Go/Free 只使用 30天`,"codexAuth.switched":`下次会话将使用 {email}`,"codexAuth.loadFailed":`无法加载账户。`,"codexAuth.switchFailed":`无法切换账户。之前的选择保持不变。`,"codexAuth.removeConfirm":`删除 {id}?`,"codexAuth.removeFailed":`无法移除账户。未进行任何更改。`,"codexAuth.addTitle":`添加 Codex 账号`,"codexAuth.addIdLabel":`账号 ID(标识符)`,"codexAuth.addJsonLabel":`auth.json 内容`,"codexAuth.addHelp":`从另一台机器的 ~/.codex/auth.json 复制,或使用 codex-auth export。`,"codexAuth.importBtn":`导入`,"codexAuth.importInvalidJson":`无效的 JSON`,"codexAuth.importMissingTokens":`JSON 中缺少 access_token 或 refresh_token`,"codexAuth.importMissingId":`请输入账号 ID`,"codexAuth.accountAdded":`账号已添加到池中`,"codexAuth.addPickDesc":`使用另一个 ChatGPT 账号登录以添加到池中。`,"codexAuth.oauthLogin":`OAuth 登录`,"codexAuth.oauthDesc":`在浏览器中打开 ChatGPT 登录`,"codexAuth.importAuthJson":`导入 auth.json`,"codexAuth.importAuthJsonDesc":`从另一个 Codex 安装或 codex-auth 导出`,"codexAuth.back":`返回`,"codexAuth.oauthAlreadyInProgress":`登录已在进行中。请在浏览器中完成。`,"codexAuth.oauthWaiting":`等待浏览器中完成 ChatGPT 登录...`,"codexAuth.copyLoginLink":`复制登录链接`,"codexAuth.loginLinkCopied":`登录链接已复制`,"codexAuth.loginLinkCopyFailed":`无法复制登录链接。`,"codexAuth.oauthCancelled":`登录已取消。`,"codexAuth.needsReauth":`重新登录`,"codexAuth.tokenExpired":`令牌已过期 — 重新添加此账号以刷新`,"codexAuth.emailCollision":`此账号与您的主 Codex 登录相同。请使用其他账号。`,"codexAuth.resetCreditsTitle":`重置额度`,"codexAuth.resetCreditsAvailable":`您有 {count} 个可用重置额度。`,"codexAuth.resetCreditsDesc":`每个额度可立即重置您当前的小时和每周使用限制。`,"codexAuth.noResetCredits":`没有可用的重置额度。`,"codexAuth.earnCreditsHint":`额度每月自动发放,也可通过推荐计划获得。`,"codexAuth.creditsExpireNote":`额度在获得后 30 天过期。`,"codexAuth.useOneCredit":`使用 1 个额度`,"codexAuth.confirmResetTitle":`使用重置额度?`,"codexAuth.confirmResetDesc":`这将立即重置您当前的使用限制。剩余额度:{count} 个。`,"codexAuth.irreversible":`此操作不可撤销。`,"codexAuth.useCredit":`使用额度`,"codexAuth.redeeming":`重置中...`,"codexAuth.resetSuccess":`使用限制已重置!剩余额度:{remaining} 个。`,"codexAuth.resetNothingToReset":`当前没有需要重置的使用窗口。`,"codexAuth.resetNoCredit":`没有可用的重置额度。`,"codexAuth.resetError":`重置额度使用失败,请重试。`,"codexAuth.fifoNote":`最早获得的额度优先使用。`,"codexAuth.confirmWhichCredit":`将使用 {date} 获得的额度。`,"codexAuth.creditNext":`即将使用`,"codexAuth.creditLabel":`额度 #{n}`,"codexAuth.creditNextBadge":`NEXT`,"codexAuth.creditGranted":`获得 {date}`,"codexAuth.creditExpires":`过期 {date}(剩余 {days} 天)`,"api.title":`API 访问`,"api.subtitle":`使用生成的 API 密钥从外部应用访问 opencodex 代理。通过 {authHeader} 或 {altHeader} 请求头进行认证。`,"api.endpoint":`端点`,"api.endpointNote":`兼容 OpenAI Responses API 格式。`,"api.newKeyTitle":`已创建新密钥`,"api.newKeyNote":`请立即复制此密钥,它不会再次显示。`,"api.copy":`复制`,"api.copied":`已复制`,"api.dismiss":`关闭`,"api.generateTitle":`生成密钥`,"api.keyNamePlaceholder":`密钥名称(可选)`,"api.generate":`生成`,"api.generating":`创建中…`,"api.activeKeys":`活跃密钥({count})`,"api.noKeys":`还没有 API 密钥。请在上方生成一个。`,"api.colName":`名称`,"api.colKey":`密钥`,"api.colCreated":`创建时间`,"api.confirm":`确认`,"api.deleteAria":`删除 API 密钥`,"api.usageTitle":`使用示例`,"nav.claude":`Claude`,"claude.subtitle":`在 Claude Code 中使用 GPT、Gemini 等其他模型。`,"claude.enabledLabel":`Claude 连接`,"claude.enabledHint":`关闭后 Claude Code 无法使用此代理。`,"claude.authMode":`认证模式`,"claude.authModeHint":`Subscription 需要 Claude 账户,Proxy 无需 Anthropic 账户即可使用`,"claude.authModeSubscription":`Subscription(Claude 账户)`,"claude.authModeProxy":`Proxy(无需账户)`,"claude.systemEnv":`自动连接`,"claude.systemEnvDesc":`开启后,在任意终端运行 claude 会自动通过代理。`,"claude.systemEnvWarn":`⚠ 需要完全退出并重新打开终端应用才能生效。不推荐使用。`,"claude.fastMode":`Fast Mode (OpenAI)`,"claude.fastModeDesc":`控制 OpenAI 模型的推理速度。ON = 优先级(更快)。OFF = 默认速度。Auto = 透传客户端设置。`,"claude.fastAuto":`Auto`,"claude.fastOn":`ON`,"claude.fastOff":`OFF`,"claude.autoContext":`自动利用大上下文`,"claude.autoContextDesc":`决定 1M 标记的范围。开:所有超过 20 万 token 的模型(GPT 系列等)都有大上下文条目;关:仅真正的 1M 模型有。`,"claude.autoContextInert":`配置文件中存在旧式上下文大小值(maxContextTokens),此功能暂不生效。删除该值即可恢复。`,"claude.autoCompactWindow":`自动摘要触发点`,"claude.autoCompactDefault":`350k(默认)`,"claude.autoCompactWindowDesc":`对话达到该点时自动摘要旧内容。不会超过各模型自身上限,因此 200k 模型不受影响。`,"claude.autoCompactWindowWarn":`修改该值可能导致 GPT 模型异常——若超过模型真实上限,会在摘要触发前报错。`,"claude.injectAgents":`自动注册子代理`,"claude.injectAgentsDesc":`将“子代理”页选中的模型(以及当前默认模型)注册为 Claude Code 可派遣的代理(ocx-*)。从下一个会话开始生效。`,"claude.webSearchSidecar":`网页搜索附属服务覆盖`,"claude.webSearchSidecarHint":`仅对 Claude Code 请求覆盖主网页搜索附属服务设置。`,"claude.visionSidecar":`视觉附属服务覆盖`,"claude.visionSidecarHint":`仅对 Claude Code 请求覆盖主视觉附属服务设置。`,"claude.useMainSetting":`使用主设置`,"claude.sidecarModelPlaceholder":`主设置中的模型`,"claude.quickstart":`开始使用`,"claude.quickstartHint":`{cmd} 通过代理打开 Claude Code。你的 claude.ai 登录保持不变。`,"claude.manualEnv":`手动配置(高级)`,"claude.smallFastModel":`后台辅助模型`,"claude.smallFastModelHint":`Claude Code 用于对话摘要、主题识别等后台工作的模型。子代理的 haiku 别名也使用它。留空 = Claude 默认(Haiku)。`,"claude.slotUnset":`使用 Claude 默认值`,"claude.modelMap":`模型拦截`,"claude.modelMapHint":`拦截对特定模型的请求并重定向到你指定的模型。默认为空——添加规则后才生效。`,"claude.mapFrom":`原始模型(如 claude-sonnet-4-5)`,"claude.mapTo":`替换为(如 gemini/gemini-3-pro)`,"claude.addMapping":`添加规则`,"claude.removeMapping":`删除规则`,"claude.aliases":`可用模型`,"claude.aliasesHint":`Claude Code 的 /model 菜单中显示的模型列表。`,"claude.loading":`加载中…`,"claude.loadFail":`加载 Claude 设置失败`,"claude.saved":`已保存。`,"claude.saveFailed":`保存失败`,"claude.networkError":`网络错误 — 代理是否在运行?`,"claude.toggleAria":`切换 Claude 连接`,"claude.none":`无`,"common.close":`关闭`,"common.ok":`确定`,"app.logoAria":`opencodex 徽标`,"app.claudeOn":`Claude 开`,"app.claudeOff":`Claude 关`,"usage.dayMon":`一`,"usage.dayWed":`三`,"usage.dayFri":`五`,"usage.heatmap.tooltipTokens":`{tokens} 令牌`,"usage.heatmap.tooltipRequests":`{requests} 请求`,"modal.back":`返回`,"modal.badge.oauth":`OAuth`,"modal.customProvider":`自定义提供方`,"modal.failedStatus":`失败 ({status})`,"modal.loginError":`登录错误:{error}`,"modal.badge.codexLogin":`Codex 登录`,"modal.badge.local":`本地`,"modal.badge.apiKey":`API 密钥`,"modal.badge.direct":`Direct`,"modal.badge.pool":`账户池`,"modal.badge.free":`免费`,"modal.invalidPreset":`此内置提供方预设不完整。请重启代理后重试。`,"modal.freeTierTitle":`免费层级`,"modal.freeTierDefault":`无需 API 密钥,开箱即用。`,"modal.tab.accounts":`账户`,"modal.tab.free":`免费`,"modal.tab.paid":`付费`,"modal.accountsHint":`Codex 账户提供商会转发你的 ChatGPT 登录。账户管理请前往`,"modal.accountsCodexAuthLink":`Codex 认证`,"modal.browseAll":`浏览全部 {count} 个提供商`,"modal.browseBack":`返回热门提供商`,"modal.notListed":`没有你要的提供商?添加自定义`,"modal.catalogLoading":`正在加载目录…`,"modal.accountLogin":`登录`,"modal.accountLogout":`退出登录`,"modal.accountLoggedIn":`已登录`,"modal.accountLoggedOut":`未登录`,"quota.fiveHourLimit":`5 小时限额`,"quota.weeklyLimit":`每周限额`,"quota.monthlyLimit":`30 天限额`,"quota.cursorFirstParty":`官方模型`,"quota.cursorApiUsage":`API 用量`,"quota.totalSubscriptionCredits":`订阅总额度`,"quota.usedPercent":`已用 {pct}%`,"quota.limitReached":`已达上限`,"quota.resetsToday":`今天 {time} 重置`,"quota.resetsTomorrow":`明天 {time} 重置`,"quota.resetsAt":`{when} 重置`,"quota.resetsRelativeMinutes":`{n} 分钟后重置`,"quota.resetsRelativeHours":`{n} 小时后重置`,"pws.status.ready":`就绪`,"pws.status.needsSetup":`需要设置`,"pws.auth.chatgptPassthrough":`ChatGPT 直通`,"pws.auth.noKey":`无需密钥`,"pws.freeTitle":`免费定价(可能仍需密钥)`,"pws.localTitle":`本地运行时`,"pws.modelCountOne":`1 个模型`,"pws.modelCount":`{count} 个模型`,"pws.rail.suffixDefault":` · 默认`,"pws.rail.suffixLocal":` · 本地`,"pws.rail.suffixFree":` · 免费`,"pws.rail.selectAria":`选择 {name} — {status}{suffix}`,"pws.searchPlaceholder":`搜索提供商…`,"pws.filterAria":`筛选提供商`,"pws.providerFiltersAria":`提供商筛选`,"pws.filters":`筛选`,"pws.filterStatus":`状态`,"pws.pricing":`定价`,"pws.paid":`付费`,"pws.filterType":`类型`,"pws.type.cloud":`云端`,"pws.type.local":`本地`,"pws.type.selfHosted":`自托管`,"pws.type.login":`登录`,"pws.sort":`排序`,"pws.sortProvidersAria":`排序提供商`,"pws.sort.az":`A–Z`,"pws.sort.za":`Z–A`,"pws.sort.freePaid":`免费优先`,"pws.sort.paidFree":`付费优先`,"pws.sort.accountsFirst":`账户优先`,"pws.resetAll":`全部重置`,"pws.providerList":`提供商列表`,"pws.providersAria":`提供商`,"pws.groupReady":`就绪 ({count})`,"pws.groupNeedsSetup":`需要设置 ({count})`,"pws.groupDisabled":`已禁用 ({count})`,"pws.noSearchResults":`没有匹配搜索的提供商。`,"pws.noMatchFilters":`没有匹配筛选的提供商。`,"pws.noProvidersConfigured":`尚未配置提供商。`,"pws.workspaceMainAria":`提供商详情`,"pws.detailComingSoon":`详情视图即将推出 — 请在经典视图中管理。`,"pws.selectPrompt":`从列表中选择一个提供商。`,"pws.connectFirst":`连接你的第一个提供商`,"pws.empty.browseFree":`浏览免费提供商`,"pws.empty.browseFreeDesc":`无需订阅即可开始`,"pws.empty.connectAccount":`连接账户`,"pws.empty.connectAccountDesc":`使用 ChatGPT 或提供商登录`,"pws.empty.addEndpoint":`添加端点`,"pws.empty.addEndpointDesc":`自定义 base URL 和 API 密钥`,"pws.workspaceToggle":`工作区视图`,"pws.classicToggle":`经典视图`,"pws.tab.overview":`概览`,"pws.tab.models":`模型`,"pws.tab.usage":`用量`,"pws.tab.accounts":`账户`,"pws.tab.settings":`设置`,"pws.connection":`连接`,"pws.status.connected":`已连接`,"pws.cell.auth":`认证`,"pws.cell.note":`备注`,"pws.cell.defaultModel":`默认模型`,"pws.statsAria":`提供商统计`,"pws.statsTitle":`统计`,"pws.stats.totalRequests":`请求数(30 天)`,"pws.stats.totalTokens":`令牌(30 天)`,"pws.stats.quotaUpdated":`配额更新`,"pws.stats.quotaTracked":`在用量标签查看限额。`,"pws.stats.source":`来源`,"pws.usageLast30d":`用量(最近 30 天)`,"pws.metricRequests":`请求`,"pws.metricTokens":`令牌`,"pws.usageUnavailable":`尚无用量记录。`,"pws.rateLimits":`速率限制`,"pws.quotaUnavailable":`此提供商暂无配额数据。`,"pws.selected":`已选择`,"pws.copyModelId":`复制 ID`,"pws.modelCopied":`已复制!`,"pws.modelsAvailable":`{count} 个可用`,"pws.modelSearchPlaceholder":`筛选模型…`,"pws.modelsLoading":`正在加载模型…`,"pws.modelsLoadFailed":`无法加载模型。`,"pws.retry":`重试`,"pws.noModels":`未发现此提供商的模型。`,"pws.noModelMatch":`没有匹配筛选的模型。`,"pws.adapterBaseRequired":`适配器和基本 URL 为必填项。`,"pws.addAccount":`添加账户`,"pws.addKey":`添加 API 密钥`,"pws.apiKeys":`API 密钥`,"pws.authMode":`认证方式`,"pws.availableAccounts":`可用账户`,"pws.accountOrdinal":`账户 {count}`,"pws.accountsLoading":`正在加载账户…`,"pws.accountsLoadFailed":`无法加载账户。`,"pws.retryAccounts":`重试`,"pws.noAccounts":`尚未连接任何账户。`,"pws.accountSwitching":`切换中…`,"pws.accountCurrent":`当前账户`,"pws.defaultModelNone":`无(使用提供商默认值)`,"pws.discardSettings":`放弃`,"pws.jsonEditorDesc":`直接编辑提供商 JSON 配置。更改将立即保存。`,"pws.jsonEditorTitle":`JSON 编辑器 — {name}`,"pws.jsonRestore":`恢复`,"pws.jsonSave":`保存`,"pws.loggedInTitle":`已登录`,"pws.notLoggedInTitle":`未登录`,"pws.note":`备注`,"pws.optionalPlaceholder":`可选`,"pws.providerId":`提供商 ID`,"pws.reauth":`需要重新认证`,"pws.removeConfirm":`移除`,"pws.removeConfirmBody":`移除提供商「{name}」?此操作无法撤消。`,"pws.removeConfirmTitle":`移除提供商`,"pws.saveSettings":`保存`,"pws.saving":`保存中…`,"pws.settingsSaved":`设置已保存。`,"pws.settingsUnsavedBar":`有未保存的更改。`,"pws.unsavedLeaveBody":`有未保存的更改。离开前保存吗?`,"pws.unsavedLeaveTitle":`未保存的更改`,"pws.updatesUnavailable":`提供商更新不可用。`,"pws.dashboard.title":`提供商概览`,"pws.dashboard.subtitle":`在一个地方管理所有模型提供商。`,"pws.dashboard.rateLimits":`速率限制`,"pws.dashboard.recentlyUsed":`最近使用`,"pws.dashboard.requests":`{count} 个请求`,"pws.dashboard.checkedAgo":`{time} 前检查`,"pws.dashboard.noQuota":`无配额数据`,"pws.dashboard.noUsage":`暂无使用数据`,"pws.allProviders":`提供商概览`,"pws.enabledLabel":`已启用`,"pws.testConnection":`测试连接`,"pws.testing":`测试中…`,"pws.connectionOk":`连接成功`,"pws.connectionFailed":`连接失败`,"pws.editSettings":`编辑设置`,"pws.viewUsage":`查看详细用量`,"pws.allSystemsOk":`所有系统正常运行`,"pws.apiKeyConfigured":`API 密钥已配置`,"pws.addApiKey":`添加 API 密钥`,"pws.loggedInAs":`已登录为 {email}`,"pws.notLoggedIn":`未登录`,"pws.passthrough":`Codex 透传`,"pws.notes":`备注`,"pws.notePlaceholder":`添加关于此提供商的备注...`,"pws.noteSaved":`备注已保存`,"pws.authSummary":`认证`,"time.justNow":`刚刚`,"time.notChecked":`未检查`,"time.minutesAgo":`{n} 分钟前`,"time.hoursAgo":`{n} 小时前`,"time.daysAgo":`{n} 天前`,"modal.noMatch":`无匹配。`,"modal.oauthDefaultNote":`使用账户登录 — 无需 API 密钥。`,"modal.oauthComingSoon":`{label} 的 OAuth 登录将在下次更新提供。请先使用 API 密钥。`,"modal.oauthComingSoonShort":`此提供方的 OAuth 登录将在下次更新提供 — 请先使用 API 密钥。`,"modal.useApiKeyInstead":`改用 API 密钥`,"modal.setupGuide":`设置指南`,"modal.setupStep1Prefix":`前往`,"modal.setupDashboardLink":`{label} 控制台`,"modal.setupStep1Suffix":`并复制 API 密钥`,"modal.setupStep2":`粘贴到下方的 API 密钥字段`,"modal.setupStep3":`点击添加提供方 — 模型会自动发现`,"modal.namePlaceholder":`例如 openrouter`,"modal.duplicateWarn":`提供方 "{name}" 已存在,将被覆盖。`,"modal.forwardHintPrefix":`无需密钥 — 代理会转发你的`,"modal.forwardCredentials":`codex login`,"modal.forwardHintSuffix":`凭据到此提供方。`,"modal.localHint":`不会存储 API 密钥。这会为 Codex 添加 Cursor 的公开模型目录,但在审计完成前,实时 Cursor 传输与原生文件/Shell 执行仍保持禁用。`,"modal.getApiKey":`获取 {label} API 密钥`,"modal.apiKey":`API 密钥`,"modal.apiKeyPlaceholder":`sk-…(或 $ENV_VAR)`,"modal.defaultModelPlaceholder":`例如 gpt-5.5`,"modal.baseUrlPlaceholder":`https://...`,"modal.adding":`正在添加…`,"modal.useOauthLogin":`← 使用 OAuth 登录`,"codexAuth.addIdPlaceholder":`codex-work, codex-alt, team…`,"codexAuth.resetCreditsAria":`{count} 个重置额度`,"claude.pageTitle":`Claude Code`,"cws.loading":`正在加载组合…`,"cws.loadFailed":`无法加载组合。`,"cws.saveFailed":`无法保存组合。`,"cws.removeFailed":`无法删除组合。`,"cws.saved":`组合已保存。`,"cws.created":`已创建 {model}。`,"cws.removed":`已删除 combo/{id}。`,"cws.add":`添加组合`,"cws.addTitle":`添加组合`,"cws.addSubtitle":`创建可跨多个提供方分发的虚拟模型。客户端请求 combo/<id>。`,"cws.create":`创建组合`,"cws.railAria":`组合列表`,"cws.searchPlaceholder":`搜索组合或目标…`,"cws.noSearchResults":`没有匹配的组合。`,"cws.group.failover":`故障转移`,"cws.group.roundRobin":`轮询`,"cws.targetCount":`{count} 个目标`,"cws.targetCountOne":`1 个目标`,"cws.overviewTitle":`组合`,"cws.overviewBlurb":`可在提供方/模型目标间故障转移,或采用确定性平滑加权轮询的虚拟模型。`,"cws.count.total":`总计`,"cws.count.failover":`故障转移`,"cws.count.roundRobin":`轮询`,"cws.howTitle":`工作原理`,"cws.howBody":`在 Codex 中请求 combo/<id>。OpenCodex 仅在可重试的上游错误时切换目标。若没有可用目标,请求会直接失败,不会回退到全局默认提供方。`,"cws.attentionTitle":`需要关注`,"cws.attention.empty":`未配置目标`,"cws.attention.few":`只有一个目标 — 故障转移无处可跳`,"cws.emptyTitle":`创建第一个组合`,"cws.empty.createDesc":`命名虚拟模型并串联两个或多个后端。`,"cws.backToAll":`返回全部组合`,"cws.allCombos":`全部组合`,"cws.copyModel":`复制 ID`,"cws.copied":`已复制`,"cws.tab.config":`配置`,"cws.tab.about":`关于`,"cws.strategy":`策略`,"cws.strategy.failover":`故障转移`,"cws.strategy.roundRobin":`轮询`,"cws.strategy.failoverHint":`按顺序尝试目标。若出现可重试错误(限流、故障、订阅门控),则跳到下一个。`,"cws.strategy.roundRobinHint":`按权重确定性地分配流量。将所选目标保留一批成功请求后,再推进到下一个目标。`,"cws.field.id":`组合 ID`,"cws.field.idPlaceholder":`free`,"cws.field.idHint":`客户端将请求 {model}`,"cws.field.stickyLimit":`轮换前的粘性成功次数`,"cws.field.stickyLimitHint":`加权选择器推进前,将所选目标保留这么多次成功请求。`,"cws.field.defaultEffort":`默认推理级别`,"cws.field.defaultEffortHint":`仅在客户端未指定推理级别时使用。客户端值优先,每个目标会按自身能力进行处理。`,"cws.targets":`目标`,"cws.targets.failoverHint":`顺序很重要 — 第一个为主。`,"cws.targets.roundRobinHint":`权重控制确定性的相对选择;顺序用于打破轮换环中的平局。`,"cws.target.provider":`提供方`,"cws.target.model":`模型`,"cws.target.weight":`权重`,"cws.target.pickProvider":`选择提供方…`,"cws.target.pickProviderFirst":`请先选择提供方…`,"cws.target.pickModel":`选择模型…`,"cws.target.noModels":`该提供方没有模型`,"cws.target.modelPlaceholder":`模型 ID`,"cws.target.add":`添加目标`,"cws.target.drag":`拖动以重新排序`,"cws.target.moveUp":`上移`,"cws.target.moveDown":`下移`,"cws.aboutTitle":`运行时`,"cws.aboutBody":`失败目标会短暂冷却并遵循 Retry-After。无效请求与上下文错误不会切换。每个目标按自身能力调整推理级别;所有目标耗尽时直接失败。日志与用量会保留有序的实际尝试及每次尝试的用量。`,"cws.removeConfirmTitle":`删除 {model}?`,"cws.removeConfirmDesc":`从配置与 Codex 目录移除该虚拟模型,不会删除任何提供方。`,"cws.unsavedTitle":`未保存的更改`,"cws.unsavedDesc":`丢弃对此组合的编辑并继续?`,"cws.keepEditing":`继续编辑`,"cws.err.missingId":`需要组合 ID。`,"cws.err.invalidId":`ID 须以字母或数字开头,仅含字母、数字、点、下划线或连字符(最多 64)。`,"cws.err.duplicateId":`已存在相同 ID 的组合。`,"cws.err.noTargets":`至少添加一个目标。`,"cws.err.incompleteTarget":`每个目标都需要提供方和模型。`,"cws.target.disabled":`{name}(已禁用)`,"cws.err.reservedNamespace":`创建组合前,请先重命名名为 combo 的实体提供方。`,"cws.err.providerCollision":`组合 ID 与已配置的提供方名称冲突。`,"cws.err.unknownProvider":`每个目标都必须使用已配置的提供方。`,"cws.err.duplicateTarget":`同一提供方/模型目标只能出现一次。`,"cws.err.invalidStickyLimit":`粘性成功次数必须是 1 到 100 的整数。`,"cws.err.invalidWeight":`每个轮询权重必须是 1 到 10000 的整数。`,"cws.err.noEnabledTarget":`至少一个目标必须使用已启用的提供方。`}},ye=[{code:`en`,name:`English`,htmlLang:`en`},{code:`de`,name:`Deutsch`,htmlLang:`de`},{code:`ko`,name:`한국어`,htmlLang:`ko`},{code:`zh`,name:`中文`,htmlLang:`zh-CN`}],be=`ocx-lang`;function xe(){try{let e=localStorage.getItem(be);if(e===`en`||e===`de`||e===`ko`||e===`zh`)return e}catch{}let e=typeof navigator<`u`?navigator.language.toLowerCase():`en`;return e.startsWith(`de`)?`de`:e.startsWith(`ko`)?`ko`:e.startsWith(`zh`)?`zh`:`en`}var Se=(0,_.createContext)(null);function Ce(e,t){if(!t)return e;let n=e;for(let e of Object.keys(t))n=n.split(`{${e}}`).join(String(t[e]));return n}function H(){let e=(0,_.useContext)(Se);if(!e)throw Error(`useI18n must be used within LanguageProvider`);return e}function U(){return H().t}function we({children:e}){let[t,n]=(0,_.useState)(xe);return(0,_.useEffect)(()=>{let e=ye.find(e=>e.code===t)??ye[0];document.documentElement.lang=e.htmlLang;try{localStorage.setItem(`ocx-lang`,t)}catch{}},[t]),(0,S.jsx)(Se.Provider,{value:{locale:t,setLocale:n,t:(e,n)=>Ce(ve[t][e]??_e[e]??e,n)},children:e})}function Te({k:e,cmd:t,vars:n}){let{t:r}=H(),[i,a=``]=r(e,n).split(`{cmd}`);return(0,S.jsxs)(S.Fragment,{children:[i,(0,S.jsx)(`code`,{className:`chip`,children:t}),a]})}var Ee={ko:[{v:0x2386f26fc10000,s:`경`},{v:0xe8d4a51000,s:`조`},{v:1e8,s:`억`},{v:1e4,s:`만`}],zh:[{v:0x2386f26fc10000,s:`京`},{v:0xe8d4a51000,s:`兆`},{v:1e8,s:`亿`},{v:1e4,s:`万`}]};function De(e){return e.replace(/\.0+$/,``).replace(/(\.\d*?)0+$/,`$1`)}function Oe(e,t){let n=Ee[t];if(n){for(let t of n)if(e>=t.v)return`${De((e/t.v).toFixed(1))}${t.s}`;return String(e)}return e<1e4?String(e):e<1e6?`${De((e/1e3).toFixed(1))}K`:e<1e9?`${De((e/1e6).toFixed(1))}M`:e<0xe8d4a51000?`${De((e/1e9).toFixed(1))}B`:`${De((e/0xe8d4a51000).toFixed(1))}T`}function ke({on:e,onClick:t,disabled:n,label:r}){return(0,S.jsx)(`button`,{type:`button`,className:`switch${e?` on`:``}`,onClick:t,disabled:n,"aria-pressed":e,"aria-label":r??(e?`enabled`:`disabled`),children:(0,S.jsx)(`span`,{className:`knob`})})}function W({tone:e,children:t}){return(0,S.jsxs)(`div`,{className:`notice ${e===`ok`?`notice-ok`:`notice-err`}`,role:`status`,children:[e===`ok`?(0,S.jsx)(M,{}):(0,S.jsx)(I,{}),(0,S.jsx)(`span`,{children:t})]})}function G({value:e,options:t,onChange:n,disabled:r,label:i,style:a,align:o,placement:s,dropdownStyle:c}){let[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=t.find(t=>t.value===e);return(0,_.useEffect)(()=>{if(!l)return;let e=e=>{d.current&&!d.current.contains(e.target)&&u(!1)},t=e=>{e.key===`Escape`&&u(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[l]),(0,S.jsxs)(`div`,{ref:d,className:`custom-select`,style:{position:`relative`,display:`inline-block`,...a},children:[(0,S.jsxs)(`button`,{type:`button`,className:`select-trigger`,onClick:()=>!r&&u(e=>!e),disabled:r,"aria-haspopup":`listbox`,"aria-expanded":l,"aria-label":i,children:[(0,S.jsx)(`span`,{children:f?.label??e}),(0,S.jsx)(z,{style:{width:12,height:12,color:`var(--muted)`,transform:l?`rotate(90deg)`:`none`,transition:`transform .12s`}})]}),l&&(0,S.jsx)(`div`,{className:`select-dropdown${o===`right`?` select-dropdown-right`:``}${s===`right`?` select-dropdown-beside`:``}`,role:`listbox`,"aria-label":i,style:c,children:t.map(t=>(0,S.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":t.value===e,className:`select-option${t.value===e?` active`:``}`,onClick:()=>{n(t.value),u(!1)},children:t.label},t.value))})]})}function Ae({icon:e,title:t,children:n,className:r,style:i}){return(0,S.jsxs)(`div`,{className:r?`empty ${r}`:`empty`,style:i,children:[e,(0,S.jsx)(`div`,{className:`title`,children:t}),n&&(0,S.jsx)(`div`,{className:`text-control`,children:n})]})}var je=[`low`,`medium`,`high`,`xhigh`],Me=2,Ne=800;function Pe(e){return e?.includes(`-preview.`)?`preview`:`latest`}function Fe(e,t){switch(e){case`source_checkout`:return t(`dash.updateReason.source_checkout`);case`latest_unavailable`:return t(`dash.updateReason.latest_unavailable`);case`already_latest`:return t(`dash.updateReason.already_latest`);default:return t(`dash.updateReason.unknown`)}}function Ie(e,t){switch(e){case`running`:return t(`dash.updateStatus.running`);case`restarting`:return t(`dash.updateStatus.restarting`);case`succeeded`:return t(`dash.updateStatus.succeeded`);case`failed`:return t(`dash.updateStatus.failed`)}}function Le(e,t){let n={...e};return t?.model!==void 0&&(n.model=t.model),t?.backend===null?delete n.backend:t?.backend!==void 0&&(n.backend=t.backend),n}function Re(e){return e.filter(e=>e.provider===`openai`||e.provider===`anthropic`).map(e=>({value:e.id,label:`${e.provider}/${e.id}`}))}function ze(e,t){return e.find(e=>e.id===t)?.provider===`anthropic`?`anthropic`:`openai`}var Be=!1;typeof window<`u`&&(window.addEventListener(`keydown`,()=>{Be=!0},{capture:!0,passive:!0}),window.addEventListener(`pointerdown`,()=>{Be=!1},{capture:!0,passive:!0}));function Ve(e){if(e){if(Be){e.focus({preventScroll:!0});return}try{e.focus({preventScroll:!0,focusVisible:!1})}catch{e.focus({preventScroll:!0})}}}function He(e,t){let n=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let r=n.current;if(r){if(e){r.open||r.showModal();return}r.open&&r.close(),Ve(t.current)}},[e,t]),(0,_.useEffect)(()=>()=>{let e=n.current;e?.open&&e.close(),Ve(t.current)},[t]),n}function Ue({apiBase:e}){let{locale:t,t:n}=H(),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(!1),[x,C]=(0,_.useState)(!1),[w,T]=(0,_.useState)(!1),[E,D]=(0,_.useState)(!1),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(`default`),[M,P]=(0,_.useState)(!1),[F,te]=(0,_.useState)(!1),[ne,R]=(0,_.useState)(!1),[z,B]=(0,_.useState)(``),[re,ae]=(0,_.useState)(``),[oe,se]=(0,_.useState)([]),[ce,le]=(0,_.useState)([]),[V,ue]=(0,_.useState)(!1),[de,fe]=(0,_.useState)(``),[pe,me]=(0,_.useState)(``),[he,ge]=(0,_.useState)(!1),[_e,ve]=(0,_.useState)(null),[ye,be]=(0,_.useState)(null),[xe,Se]=(0,_.useState)([]),[Ce,U]=(0,_.useState)(!1),[we,Ee]=(0,_.useState)(`latest`),[De,ke]=(0,_.useState)(!0),[W,Be]=(0,_.useState)(!1),Ve=(0,_.useRef)(0),Ue=(0,_.useRef)(null),We=(0,_.useRef)(0),[Ge,Ke]=(0,_.useState)(null),[qe,Je]=(0,_.useState)(null),[Ye,Xe]=(0,_.useState)(null),[Ze,Qe]=(0,_.useState)(!1),[$e,et]=(0,_.useState)(!1),tt=(0,_.useRef)(null),nt=(0,_.useRef)(null),rt=(0,_.useRef)(null),it=He(ne,tt),at=He(Ce,nt),ot=He(F,rt);(0,_.useEffect)(()=>()=>{We.current+=1,Ue.current!==null&&(window.clearTimeout(Ue.current),Ue.current=null)},[]),(0,_.useEffect)(()=>{let t=async()=>{try{let[t,n,r,a,s,c]=await Promise.all([fetch(`${e}/healthz`),fetch(`${e}/api/providers`),fetch(`${e}/api/settings`),fetch(`${e}/api/sidecar-settings`),fetch(`${e}/api/shadow-call-settings`),fetch(`${e}/api/usage?range=30d`)]);i(await t.json()),o(await n.json()),u(await r.json()),f(await a.json());try{s.ok&&m(await s.json())}catch{m(null)}try{g(c.ok?await c.json():null)}catch{g(null)}et(!1);try{let t=await fetch(`${e}/api/v2`);if(t.ok){let e=await t.json();e.multiAgentMode===`v1`||e.multiAgentMode===`v2`?j(e.multiAgentMode):j(`default`)}}catch{}try{let t=await fetch(`${e}/api/injection-model`);if(t.ok){let e=await t.json();B(e.model??``),ae(e.effort??``),se(e.efforts??[]),le(e.available??[])}}catch{}try{let t=await fetch(`${e}/api/effort-caps`);if(t.ok){let e=await t.json();fe(e.effortCap??``),me(e.subagentEffortCap??``)}}catch{}}catch{et(!0)}};t();let n=setInterval(t,5e3);return()=>clearInterval(n)},[e]),(0,_.useEffect)(()=>{let t=async()=>{try{let t=await fetch(`${e}/api/diagnostics/project-config`);Se((t.ok?await t.json():null)?.grouped??[])}catch{Se([])}};t();let n=setInterval(()=>void t(),3e4);return()=>clearInterval(n)},[e]);let st=(0,_.useCallback)(async()=>{T(!0);try{c(await(await fetch(`${e}/api/models`)).json())}catch{}finally{T(!1)}},[e]);(0,_.useEffect)(()=>{if($e)return;let e=window.setTimeout(()=>{st()},0);return()=>window.clearTimeout(e)},[$e,st]),(0,_.useEffect)(()=>{if(!Ye?.id||!Ye.restart)return;let t=!1,n=Ye.latestVersion,r=async()=>{try{let n=await fetch(`${e}/api/update/status?jobId=${encodeURIComponent(Ye.id)}`);if(n.ok){let e=await n.json();if(!t&&e.job&&(Xe(e.job),e.job.status===`failed`)){Qe(!1);return}}}catch{t||Qe(!0)}if(n)try{let r=await fetch(`${e}/healthz`,{cache:`no-store`});if(!r.ok)throw Error(`health failed`);let i=await r.json();!t&&i.version===n&&(Qe(!1),window.location.reload())}catch{t||Qe(!0)}};r();let i=setInterval(r,1500);return()=>{t=!0,clearInterval(i)}},[e,Ye?.id,Ye?.latestVersion,Ye?.restart]);let ct=(0,_.useMemo)(()=>{let e={};for(let t of s)(e[t.provider]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>e.localeCompare(t))},[s]),lt=(0,_.useMemo)(()=>Re(s),[s]);if($e)return(0,S.jsx)(Ae,{style:{marginTop:40},icon:(0,S.jsx)(I,{}),title:(0,S.jsx)(`span`,{style:{color:`var(--red)`},children:n(`dash.cannotConnect`)}),children:(0,S.jsx)(Te,{k:`dash.runStart`,cmd:`ocx start`})});let ut=r?.status===`ok`,dt=async t=>{if(!d||v)return;let n={webSearch:Le(d.webSearch,t.webSearch),vision:Le(d.vision,t.vision)};y(!0),f(n);try{let n=await fetch(`${e}/api/sidecar-settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok)throw Error(`save failed`);let r=await n.json();f({webSearch:r.webSearch,vision:r.vision})}catch{f(d)}finally{y(!1)}};async function ft(t){if(!(!p||x)){C(!0),m({...p,...t});try{await fetch(`${e}/api/shadow-call-settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})}finally{C(!1)}}}let pt=async t=>{if(!(M||A===t)){P(!0);try{(await fetch(`${e}/api/v2`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({multiAgentMode:t})})).ok&&j(t)}catch{}finally{P(!1)}}},mt=async()=>{if(!l||E)return;let t=!l.codexAutoStart;D(!0),u({...l,codexAutoStart:t});try{let n=await fetch(`${e}/api/settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({codexAutoStart:t})});if(!n.ok)throw Error(`save failed`);let r=await n.json();u(e=>e&&{...e,codexAutoStart:r.codexAutoStart})}catch{u(e=>e&&{...e,codexAutoStart:!t}),et(!0)}finally{D(!1)}},ht=async()=>{if(!O){k(!0),ve(null),be(null);try{let t=await fetch(`${e}/api/sync`,{method:`POST`}),n=await t.json();if(!t.ok)throw Error(`error`in n&&n.error?n.error:`sync failed`);ve(n);let r=n.projectConfigGrouped;r&&Se(r)}catch(e){be(e instanceof Error?e.message:String(e))}finally{k(!1)}}},gt=async(t,n=!1)=>{n&&(Ve.current=0),Ue.current!==null&&(window.clearTimeout(Ue.current),Ue.current=null);let r=++We.current;Be(!0),Je(null),Ke(null);try{let n=await fetch(`${e}/api/update/check?tag=${t}`),i=await n.json();if(!n.ok)throw Error(`error`in i&&i.error?i.error:`update check failed`);if(r!==We.current)return;let a=i;if(Ke(a),a.reason===`latest_unavailable`&&Ve.current<Me){let e=++Ve.current;Ue.current=window.setTimeout(()=>{r===We.current&&(Ue.current=null,gt(t))},Ne*e);return}a.reason!==`latest_unavailable`&&(Ve.current=0),Be(!1)}catch(e){if(r!==We.current)return;Je(e instanceof Error?e.message:String(e)),Be(!1)}},_t=()=>{We.current+=1,Ue.current!==null&&(window.clearTimeout(Ue.current),Ue.current=null),Be(!1),U(!1)},vt=()=>{let e=Pe(r?.version);Ee(e),ke(!0),U(!0),gt(e,!0)},yt=e=>{Ee(e),gt(e,!0)},bt=async()=>{if(Ge?.canUpdate){Je(null);try{let t=await fetch(`${e}/api/update/run`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({tag:we,restart:De})}),n=await t.json();if(!t.ok||!n.job)throw Error(n.error??`update failed to start`);Xe(n.job),Qe(!1),_t()}catch(e){Je(e instanceof Error?e.message:String(e))}}};return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h2`,{children:n(`nav.dashboard`)})}),(0,S.jsx)(`p`,{className:`page-sub`,children:n(`dash.subtitle`)}),(0,S.jsxs)(`div`,{className:`stat-row`,children:[(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsxs)(`div`,{className:`label`,style:{display:`flex`,alignItems:`center`,gap:6},children:[n(`dash.multiAgent`),(0,S.jsx)(`button`,{ref:rt,type:`button`,className:`btn btn-ghost btn-sm`,style:{width:24,height:24,minWidth:24,flex:`0 0 24px`,padding:0,borderRadius:`var(--radius-pill)`,color:`var(--muted)`},onClick:()=>te(!0),"aria-label":n(`dash.multiAgent`),"aria-haspopup":`dialog`,"aria-controls":`multi-agent-help-dialog`,"aria-expanded":F,children:(0,S.jsx)(L,{width:14,height:14,"aria-hidden":`true`})})]}),(0,S.jsx)(`div`,{className:`value`,style:{display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,S.jsx)(`div`,{role:`radiogroup`,"aria-label":n(`dash.multiAgent`),style:{display:`inline-flex`,borderRadius:`var(--radius-pill)`,background:`var(--surface-soft, var(--raised))`,padding:3,gap:2},children:[`v1`,`default`,`v2`].map(e=>(0,S.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":A===e,className:`btn btn-sm text-caption${A===e?` btn-primary`:` btn-ghost`}`,style:{borderRadius:`var(--radius-pill)`,minWidth:36,padding:`5px 10px`,border:`none`,background:A===e?void 0:`transparent`,color:A===e?void 0:`var(--muted)`},disabled:M,onClick:()=>void pt(e),children:e==="default"?`base`:e},e))})})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`label`,children:n(`dash.status`)}),(0,S.jsxs)(`div`,{className:`value`,style:{display:`flex`,alignItems:`center`,gap:9,color:ut?`var(--green)`:`var(--red)`},children:[(0,S.jsx)(`span`,{className:`dot ${ut?`dot-green`:`dot-red`}`}),n(ut?`dash.online`:`dash.offline`)]})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`label`,children:n(`dash.version`)}),(0,S.jsx)(`div`,{className:`value mono`,children:r?.version??`—`})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`label`,children:n(`dash.uptime`)}),(0,S.jsx)(`div`,{className:`value mono`,children:r?b(r.uptime,t):`—`})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`label`,children:n(`dash.providers`)}),(0,S.jsx)(`div`,{className:`value`,children:a.length})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`label`,children:n(`dash.tokens30d`)}),(0,S.jsx)(`div`,{className:`value mono`,children:h&&h.summary.requests>0?Oe(h.summary.totalTokens,t):`—`}),h&&h.summary.requests>0&&(0,S.jsx)(`div`,{className:`muted text-label`,style:{marginTop:2},children:n(`dash.coverage`).replace(`{pct}`,`${Math.round(h.summary.coverageRatio*100)}%`)})]})]}),xe.length>0&&(0,S.jsxs)(`div`,{className:`notice notice-err maintenance-notice`,style:{marginBottom:24},role:`alert`,children:[(0,S.jsx)(I,{}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.projectConfigTitle`)}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{marginTop:4},children:n(`dash.projectConfigHint`)}),(0,S.jsx)(`ul`,{className:`text-control`,style:{margin:`10px 0 0`,paddingLeft:18},children:xe.map(e=>(0,S.jsxs)(`li`,{style:{marginBottom:8},children:[(0,S.jsx)(`code`,{children:e.path}),` — `,e.issues.join(`, `),(0,S.jsx)(`div`,{className:`muted`,style:{marginTop:2},children:e.bypass})]},e.path))})]})]}),A!==`v1`&&(0,S.jsx)(`div`,{className:`panel`,style:{marginBottom:24},children:(0,S.jsxs)(`div`,{className:`injection-head`,children:[(0,S.jsxs)(`span`,{className:`injection-label`,style:{display:`inline-flex`,alignItems:`center`,gap:6},children:[n(`dash.effortCapLabel`),(0,S.jsxs)(`span`,{style:{position:`relative`,display:`inline-flex`},children:[(0,S.jsx)(`button`,{ref:tt,type:`button`,className:`btn btn-ghost btn-sm`,style:{width:22,height:22,minWidth:22,padding:0,borderRadius:`var(--radius-pill)`,color:`var(--muted)`},onClick:()=>R(e=>!e),"aria-label":n(`dash.effortCapLabel`),"aria-expanded":ne,"aria-haspopup":`dialog`,"aria-controls":`effort-cap-help-dialog`,children:(0,S.jsx)(L,{width:13,height:13,"aria-hidden":`true`})}),(0,S.jsxs)(`dialog`,{ref:it,id:`effort-cap-help-dialog`,className:`help-popup text-control font-regular leading-body`,style:{position:`absolute`,top:`calc(100% + 8px)`,left:0,width:`min(360px, calc(100vw - 48px))`,margin:0,padding:`12px 16px`,border:`1px solid var(--border)`,borderRadius:`var(--radius-sm)`,background:`var(--bg)`,boxShadow:`0 8px 24px rgba(0, 0, 0, 0.14)`,color:`var(--text)`,zIndex:10},"aria-labelledby":`effort-cap-help-text`,onCancel:e=>{e.preventDefault(),R(!1)},children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon`,style:{position:`absolute`,top:4,right:4,width:24,height:24,minWidth:24},onClick:()=>R(!1),"aria-label":n(`common.close`),children:(0,S.jsx)(N,{width:14,height:14})}),(0,S.jsx)(`div`,{id:`effort-cap-help-text`,style:{paddingRight:16},children:n(`dash.effortCapHelp`)})]})]})]}),(0,S.jsx)(G,{value:de,options:[{value:``,label:n(`dash.effortCapNone`)},...je.map(e=>({value:e,label:e}))],onChange:async t=>{if(!he){ge(!0);try{let n=await fetch(`${e}/api/effort-caps`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({effortCap:t||null})});if(n.ok){let e=await n.json();fe(e.effortCap??``),me(e.subagentEffortCap??``)}}catch{}finally{ge(!1)}}},disabled:he,label:n(`dash.effortCapLabel`)}),(0,S.jsx)(G,{value:pe,options:[{value:``,label:n(`dash.effortCapNone`)},...je.map(e=>({value:e,label:e}))],onChange:async t=>{if(!he){ge(!0);try{let n=await fetch(`${e}/api/effort-caps`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({subagentEffortCap:t||null})});if(n.ok){let e=await n.json();fe(e.effortCap??``),me(e.subagentEffortCap??``)}}catch{}finally{ge(!1)}}},disabled:he,label:n(`dash.subagentEffortCapLabel`)})]})}),(0,S.jsxs)(`div`,{className:`panel`,style:{marginBottom:24},children:[(0,S.jsxs)(`div`,{className:`injection-head`,children:[(0,S.jsx)(`span`,{className:`injection-label`,children:n(`dash.injectionLabel`)}),(0,S.jsx)(G,{value:z,options:[{value:``,label:n(`dash.injectionNone`)},...ce.map(e=>({value:e.namespaced,label:`${e.provider} / ${e.model}`}))],onChange:async t=>{if(!V){ue(!0);try{let n=await fetch(`${e}/api/injection-model`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({model:t||null,effort:re||null})});if(n.ok){let e=await n.json();B(e.model??``),ae(e.effort??``)}}catch{}finally{ue(!1)}}},disabled:V,label:n(`dash.injectionLabel`)}),z&&oe.length>0&&(0,S.jsx)(G,{value:re,options:[{value:``,label:n(`dash.injectionEffortNone`)},...oe.map(e=>({value:e,label:e}))],onChange:async t=>{if(!V){ue(!0);try{let n=await fetch(`${e}/api/injection-model`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({model:z||null,effort:t||null})});if(n.ok){let e=await n.json();B(e.model??``),ae(e.effort??``)}}catch{}finally{ue(!1)}}},disabled:V,label:n(`dash.injectionEffortLabel`)}),z&&(0,S.jsx)(`span`,{className:`badge badge-green text-micro`,children:n(`dash.injectionActive`)})]}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{marginTop:6},children:n(`dash.injectionHint`)})]}),(0,S.jsxs)(`div`,{className:`panel maintenance-panel`,style:{marginBottom:24},children:[(0,S.jsxs)(`div`,{className:`spread maintenance-head`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.maintenance`)}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{marginTop:3},children:n(`dash.maintenanceHint`)})]}),(0,S.jsxs)(`div`,{className:`maintenance-actions`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:ht,disabled:O,children:[(0,S.jsx)(ee,{}),` `,n(O?`dash.syncing`:`dash.syncModels`)]}),(0,S.jsxs)(`button`,{ref:nt,type:`button`,className:`btn btn-primary`,onClick:vt,disabled:W,"aria-haspopup":`dialog`,"aria-controls":`dashboard-update-dialog`,"aria-expanded":Ce,children:[(0,S.jsx)(ie,{}),` `,n(`dash.checkUpdate`)]})]})]}),_e&&(0,S.jsxs)(`div`,{className:`notice notice-ok maintenance-notice`,role:`status`,children:[(0,S.jsx)(ee,{}),(0,S.jsxs)(`span`,{children:[n(`dash.syncOk`,{count:_e.added}),_e.warning?` ${_e.warning}`:``,_e.staleAppServerHint?` ${n(`dash.syncStaleHint`)}`:``]})]}),ye&&(0,S.jsxs)(`div`,{className:`notice notice-err maintenance-notice`,role:`status`,children:[(0,S.jsx)(I,{}),(0,S.jsx)(`span`,{children:n(`dash.syncFailed`,{error:ye})})]}),Ye&&(0,S.jsxs)(`div`,{className:`notice ${Ye.status===`failed`?`notice-err`:`notice-ok`} maintenance-notice`,role:`status`,children:[Ye.status===`failed`?(0,S.jsx)(I,{}):(0,S.jsx)(ee,{}),(0,S.jsxs)(`span`,{children:[Ie(Ye.status,n),Ye.latestVersion?` ${Ye.currentVersion} -> ${Ye.latestVersion}.`:``,Ze?` ${n(`dash.updateReconnecting`)}`:``,Ye.error?` ${Ye.error}`:``]})]})]}),(0,S.jsx)(`div`,{className:`panel`,style:{marginBottom:24},children:(0,S.jsxs)(`div`,{className:`spread`,children:[(0,S.jsxs)(`div`,{style:{flex:1,minWidth:0},children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.codexAutoStart`)}),(0,S.jsx)(`div`,{className:`muted setting-hint`,children:n(`dash.codexAutoStartHint`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`switch ${l?.codexAutoStart??!0?`on`:``}`,onClick:mt,disabled:!l||E,"aria-label":n(`dash.codexAutoStart`),"aria-pressed":l?.codexAutoStart??!0,children:(0,S.jsx)(`span`,{className:`knob`})})]})}),(0,S.jsx)(`div`,{className:`panel`,style:{marginBottom:12},children:(0,S.jsxs)(`div`,{className:`spread setting-row`,style:{alignItems:`flex-start`},children:[(0,S.jsxs)(`div`,{className:`setting-copy`,style:{flex:1},children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.webSearchSidecar`)}),(0,S.jsx)(`div`,{className:`muted setting-hint`,children:n(`dash.webSearchSidecarHint`)})]}),(0,S.jsx)(`div`,{className:`setting-controls`,children:(0,S.jsx)(G,{value:d?.webSearch.model??`gpt-5.6-luna`,options:lt,onChange:e=>{dt({webSearch:{model:e,backend:ze(s,e)}})},disabled:!d||v,label:n(`dash.sidecarModel`)})})]})}),(0,S.jsx)(`div`,{className:`panel`,style:{marginBottom:24},children:(0,S.jsxs)(`div`,{className:`spread setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-copy`,style:{flex:1},children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.visionSidecar`)}),(0,S.jsx)(`div`,{className:`muted setting-hint`,children:n(`dash.visionSidecarHint`)})]}),(0,S.jsx)(`div`,{className:`setting-controls`,children:(0,S.jsx)(G,{value:d?.vision.model??`gpt-5.6-luna`,options:lt,onChange:e=>{dt({vision:{model:e,backend:ze(s,e)}})},disabled:!d||v,label:n(`dash.sidecarModel`)})})]})}),(0,S.jsx)(`div`,{className:`panel`,style:{marginBottom:12},children:(0,S.jsxs)(`div`,{className:`spread setting-row`,style:{alignItems:`center`},children:[(0,S.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[(0,S.jsx)(`span`,{className:`font-semibold`,children:n(`dash.shadowCallIntercept`)}),(0,S.jsx)(`span`,{title:n(`dash.shadowCallTooltip`),style:{cursor:`help`,opacity:.5},children:`ⓘ`}),(0,S.jsx)(`code`,{className:`muted text-caption`,children:`⚠ 5.4-mini`})]}),(0,S.jsxs)(`div`,{className:`setting-controls`,style:{display:`flex`,gap:8,alignItems:`center`},children:[(0,S.jsx)(`button`,{type:`button`,className:`switch ${p?.enabled?`on`:``}`,onClick:()=>ft({enabled:!p?.enabled}),disabled:!p||x,"aria-label":n(`dash.shadowCallIntercept`),"aria-pressed":p?.enabled??!1,children:(0,S.jsx)(`span`,{className:`knob`})}),(0,S.jsx)(G,{value:p?.model??``,options:[{value:``,label:`—`},...s.map(e=>({value:e.id,label:`${e.provider}/${e.id}`}))],onChange:e=>{m(t=>t&&{...t,model:e}),ft({model:e})},disabled:!p||x||!p?.enabled,label:n(`dash.shadowCallModel`)})]})]})}),(0,S.jsxs)(`div`,{className:`h-section`,children:[n(`dash.activeProviders`),` `,(0,S.jsx)(`span`,{className:`count`,children:a.length})]}),a.length===0?(0,S.jsx)(Ae,{title:(0,S.jsx)(Te,{k:`dash.noProviders`,cmd:`ocx init`})}):(0,S.jsx)(`div`,{className:`tbl-wrap`,children:(0,S.jsxs)(`table`,{className:`tbl`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:n(`dash.col.name`)}),(0,S.jsx)(`th`,{children:n(`dash.col.adapter`)}),(0,S.jsx)(`th`,{children:n(`dash.col.baseUrl`)}),(0,S.jsx)(`th`,{children:n(`dash.col.model`)})]})}),(0,S.jsx)(`tbody`,{children:a.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{className:`font-semibold`,children:e.name}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`span`,{className:`chip`,children:e.adapter})}),(0,S.jsx)(`td`,{className:`muted mono text-label`,children:e.baseUrl}),(0,S.jsx)(`td`,{className:`muted`,children:e.defaultModel??`—`})]},e.name))})]})}),(0,S.jsxs)(`div`,{className:`h-section`,children:[n(`dash.availableModels`),` `,(0,S.jsx)(`span`,{className:`count`,children:s.length}),w&&(0,S.jsx)(`span`,{className:`spin`,style:{marginLeft:4}})]}),s.length===0&&!w?(0,S.jsx)(Ae,{title:n(`dash.noModels`)}):(0,S.jsx)(`div`,{className:`stack`,style:{gap:16},children:ct.map(([e,t])=>(0,S.jsxs)(`div`,{className:`model-group`,children:[(0,S.jsxs)(`div`,{className:`model-group-head`,children:[e,(0,S.jsx)(`span`,{className:`count`,children:t.length})]}),(0,S.jsx)(`div`,{className:`model-grid`,children:t.map(e=>(0,S.jsx)(`div`,{className:`model-card`,children:(0,S.jsx)(`div`,{className:`id`,children:e.id})},`${e.provider}/${e.id}`))})]},e))}),(0,S.jsx)(`dialog`,{ref:at,id:`dashboard-update-dialog`,className:`modal-overlay`,style:{display:Ce?`flex`:`none`,border:`none`,margin:0,maxWidth:`none`,maxHeight:`none`,width:`100%`,height:`100%`},"aria-labelledby":`update-title`,onCancel:e=>{e.preventDefault(),_t()},children:(0,S.jsxs)(`div`,{className:`modal-card`,children:[(0,S.jsxs)(`div`,{className:`modal-head`,children:[(0,S.jsx)(`h3`,{id:`update-title`,children:n(`dash.updateTitle`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon`,onClick:_t,"aria-label":n(`common.cancel`),children:(0,S.jsx)(N,{})})]}),(0,S.jsx)(`div`,{className:`modal-desc`,children:n(`dash.updateDesc`)}),(0,S.jsxs)(`div`,{className:`update-row`,children:[(0,S.jsx)(`label`,{className:`field-label`,htmlFor:`update-channel`,children:n(`dash.updateChannel`)}),(0,S.jsx)(G,{value:we,options:[{value:`latest`,label:`latest`},{value:`preview`,label:`preview`}],onChange:e=>yt(e),disabled:W,label:n(`dash.updateChannel`)})]}),W&&(0,S.jsx)(Ae,{className:`update-empty`,icon:(0,S.jsx)(`span`,{className:`spin`}),title:n(`dash.updateChecking`)}),qe&&(0,S.jsxs)(`div`,{className:`notice notice-err`,role:`status`,children:[(0,S.jsx)(I,{}),(0,S.jsx)(`span`,{children:qe})]}),Ge&&!W&&(0,S.jsxs)(`div`,{className:`update-box`,children:[(0,S.jsxs)(`div`,{className:`spread`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`muted text-label`,children:n(`dash.updateInstalled`)}),(0,S.jsx)(`div`,{className:`mono`,children:Ge.currentVersion})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`muted text-label`,children:n(`dash.updateLatest`)}),(0,S.jsx)(`div`,{className:`mono`,children:Ge.latestVersion??`—`})]}),(0,S.jsx)(`span`,{className:`badge ${Ge.updateAvailable?`badge-green`:`badge-muted`}`,children:Ge.updateAvailable?n(`dash.updateAvailable`):n(`dash.updateCurrent`)})]}),(0,S.jsxs)(`div`,{className:`muted update-command`,children:[n(`dash.updateCommand`),` `,(0,S.jsx)(`code`,{className:`chip`,children:Ge.command})]}),Ge.reason===`source_checkout`&&(0,S.jsxs)(`div`,{className:`notice-warn`,role:`status`,children:[(0,S.jsx)(I,{}),` `,n(`dash.updateSource`)]}),Ge.reason===`latest_unavailable`&&(0,S.jsxs)(`div`,{className:`notice-warn`,role:`status`,children:[(0,S.jsx)(I,{}),` `,n(`dash.updateUnavailable`),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:W,onClick:()=>{gt(we,!0)},style:{marginLeft:12},children:[(0,S.jsx)(ee,{}),` `,n(`dash.updateRetry`)]})]}),!Ge.canUpdate&&Ge.reason!==`latest_unavailable`&&Ge.reason!==`source_checkout`&&(0,S.jsxs)(`div`,{className:`update-recheck`,children:[(0,S.jsx)(`span`,{className:`muted update-recheck-reason`,children:n(`dash.updateCannotAuto`,{reason:Fe(Ge.reason,n)})}),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:W,onClick:()=>{gt(we,!0)},children:[(0,S.jsx)(ee,{}),` `,n(W?`dash.updateChecking`:`dash.updateRecheck`)]})]}),Ge.canUpdate&&(0,S.jsxs)(`div`,{className:`spread update-restart`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`font-semibold`,children:n(`dash.updateRestart`)}),(0,S.jsx)(`div`,{className:`muted text-label`,children:n(`dash.updateRestartHint`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`switch ${De?`on`:``}`,onClick:()=>ke(e=>!e),"aria-label":n(`dash.updateRestart`),"aria-pressed":De,children:(0,S.jsx)(`span`,{className:`knob`})})]})]}),(0,S.jsxs)(`div`,{className:`modal-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:_t,children:n(`common.cancel`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:bt,disabled:!Ge?.canUpdate||W,children:n(`dash.runUpdate`)})]})]})}),(0,S.jsx)(`dialog`,{ref:ot,id:`multi-agent-help-dialog`,className:`modal-overlay`,style:{display:F?`flex`:`none`,border:`none`,margin:0,maxWidth:`none`,maxHeight:`none`,width:`100%`,height:`100%`},"aria-labelledby":`multi-agent-help-title`,onCancel:e=>{e.preventDefault(),te(!1)},onClick:e=>{e.target===e.currentTarget&&te(!1)},children:(0,S.jsxs)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`modal-head`,children:[(0,S.jsx)(`h3`,{id:`multi-agent-help-title`,children:n(`dash.multiAgent`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon`,onClick:()=>te(!1),"aria-label":n(`common.close`),children:(0,S.jsx)(N,{})})]}),(0,S.jsx)(`div`,{className:`modal-desc leading-relaxed`,style:{whiteSpace:`pre-line`},children:n(`models.v2Help`)}),(0,S.jsx)(`div`,{style:{marginTop:12},children:(0,S.jsx)(`a`,{className:`text-control`,href:`https://lidge-jun.github.io/opencodex/guides/sub-agent-surface/`,target:`_blank`,rel:`noreferrer`,style:{color:`var(--accent)`},children:n(`models.v2DocsLink`)})}),(0,S.jsx)(`div`,{className:`modal-actions`,children:(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>te(!1),children:n(`common.ok`)})})]})})]})}function We(e){return e.id===`openai`}function Ge(e){return e.id===`openai`?e.codexAccountMode===`direct`?`prov.openaiDirectDesc`:`prov.openaiPoolDesc`:null}function Ke(e){let t={adapter:e.adapter.trim(),baseUrl:e.baseUrl.trim()};return(e.authMode===`key`||e.authMode===`forward`)&&(t.authMode=e.authMode),e.authMode===`key`&&e.apiKey.trim()&&(t.apiKey=e.apiKey.trim()),e.defaultModel.trim()&&(t.defaultModel=e.defaultModel.trim()),t}function qe(e,t){if(We(e)){if(!e.provider)throw Error(`Missing canonical provider seed for ${e.id}`);return{name:e.id,provider:JSON.parse(JSON.stringify(e.provider))}}return{name:t.name.trim(),provider:Ke(t)}}var Je=`https://chatgpt.com/backend-api/codex`,Ye=`openai`;function Xe(e){try{let t=new URL(e.trim());if(t.username||t.password||t.search||t.hash)return;let n=t.pathname.replace(/\/+$/,``);return`${t.origin}${n}`}catch{return}}function Ze(e){try{let t=new URL(e).hostname.replace(/^\[|\]$/g,``).toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`::1`}catch{return!1}}function Qe(e){return e.keyOptional===!0||e.authMode===`oauth`||e.authMode===`forward`||e.authMode===`local`||Ze(e.baseUrl)||e.hasApiKey===!0}function $e(e){return e.adapter===`openai-responses`&&e.authMode===`forward`&&Xe(e.baseUrl)===Je}function et(e,t){return e===Ye&&$e(t)}function tt(e){return e.freeTier===!0||e.keyOptional===!0||e.authMode===`local`||Ze(e.baseUrl)}function nt(e,t){return et(e,t)?`accounts`:tt(t)?`free`:`paid`}function rt(e,t){let n=[...e],r=(e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`}),i=e=>e.tier??nt(e.name,e);switch(t){case`az`:return n.sort(r);case`za`:return n.sort((e,t)=>r(t,e));case`free-paid`:return n.sort((e,t)=>(i(e)===`free`?0:1)-(i(t)===`free`?0:1)||r(e,t));case`paid-free`:return n.sort((e,t)=>(i(e)===`free`)-+(i(t)===`free`)||r(e,t));case`accounts-first`:return n.sort((e,t)=>{let n=e=>{let t=i(e);return t===`accounts`?0:t===`free`?1:2};return n(e)-n(t)||r(e,t)});default:return n}}function it(e){let t=[],n=[],r=[];for(let[i,a]of Object.entries(e)){if(a.disabled){r.push({name:i,...a});continue}Qe(a)?t.push({name:i,...a,tier:nt(i,a)}):n.push({name:i,...a})}return{ready:t,needsSetup:n,disabled:r}}function at(e){return e.disabled?`disabled`:Qe(e)?`ready`:`needs-setup`}function ot(e){let t=e.openai,n=e.chatgpt;if(!t||!n||!et(`openai`,t)||!$e(n))return e;let r={...e};return delete r.chatgpt,r}function st(e){return{adapter:e.adapter,baseUrl:e.baseUrl,authMode:e.auth,freeTier:!!e.freeTier,keyOptional:!!e.keyOptional}}function ct(e){return nt(e.id,st(e))}function lt(e){let t={accounts:[],free:[],paid:[]};for(let n of e)t[ct(n)].push(n);return t}function ut(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>e.label.toLowerCase().includes(n)||e.id.toLowerCase().includes(n)):e}var dt=6;function ft({presets:e,usageRank:t={},presetsLoading:n=!1,initialTier:r=`free`,onSelectPreset:i,onSelectCustom:a,accountRows:o=[],accountStatus:s={},busyProvider:c=null,onLogin:l,onCancelLogin:u,onLogout:d}){let f=U(),[p,m]=(0,_.useState)(r),[h,g]=(0,_.useState)(`home`),[v,y]=(0,_.useState)(``),b=(0,_.useRef)(null),x=(0,_.useMemo)(()=>e.filter(e=>e.id!==`custom`),[e]),C=(0,_.useMemo)(()=>[...x].sort((e,n)=>{let r=t[e.id]??0,i=t[n.id]??0;return i===r?e.label.localeCompare(n.label,void 0,{sensitivity:`base`})||e.id.localeCompare(n.id):i-r}),[x,t]),w=(0,_.useMemo)(()=>lt(C),[C])[p],T=w.slice(0,dt),E=(0,_.useMemo)(()=>ut(w,v),[w,v]),D=h===`browse`?E:T,O=()=>{g(`browse`),y(``),setTimeout(()=>b.current?.focus(),0)},k=e=>{let t=e.codexAccountMode===`direct`?(0,S.jsx)(`span`,{className:`badge badge-green`,children:f(`modal.badge.direct`)}):e.codexAccountMode===`pool`?(0,S.jsx)(`span`,{className:`badge badge-accent`,children:f(`modal.badge.pool`)}):e.auth===`oauth`?(0,S.jsx)(`span`,{className:`badge badge-accent`,children:f(`modal.badge.oauth`)}):e.auth===`forward`?(0,S.jsx)(`span`,{className:`badge badge-green`,children:f(`modal.badge.codexLogin`)}):e.auth===`local`?(0,S.jsx)(`span`,{className:`badge badge-amber`,children:f(`modal.badge.local`)}):e.keyOptional?null:(0,S.jsx)(`span`,{className:`badge badge-muted`,children:f(`modal.badge.apiKey`)});return(0,S.jsxs)(S.Fragment,{children:[(e.freeTier||e.keyOptional)&&e.auth===`key`?(0,S.jsx)(`span`,{className:`badge badge-green`,children:f(`modal.badge.free`)}):null,t]})};return(0,S.jsxs)(`div`,{className:`provider-catalog`,children:[(0,S.jsx)(`div`,{className:`provider-catalog-tabs`,role:`tablist`,children:[`accounts`,`free`,`paid`].map(e=>(0,S.jsx)(`button`,{role:`tab`,"aria-selected":p===e,className:`provider-catalog-tab${p===e?` active`:``}`,onClick:()=>{m(e),g(`home`),y(``)},children:f(e===`accounts`?`modal.tab.accounts`:e===`free`?`modal.tab.free`:`modal.tab.paid`)},e))}),p===`accounts`&&(0,S.jsxs)(`div`,{className:`provider-catalog-accounts-hint muted text-label`,children:[f(`modal.accountsHint`),` `,(0,S.jsx)(`a`,{href:`#codex-auth`,children:f(`modal.accountsCodexAuthLink`)})]}),h===`browse`&&(0,S.jsx)(`input`,{ref:b,className:`input provider-catalog-search`,value:v,onChange:e=>y(e.target.value),placeholder:f(`modal.search`)}),(0,S.jsxs)(`div`,{className:`provider-catalog-rows`,children:[n&&D.length===0&&(0,S.jsx)(`div`,{className:`muted text-control provider-catalog-empty`,children:f(`modal.catalogLoading`)}),D.map(e=>(0,S.jsxs)(`button`,{className:`list-row`,onClick:()=>i(e),children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`title`,children:e.label}),(0,S.jsxs)(`div`,{className:`sub`,children:[(0,S.jsx)(`code`,{className:`chip`,children:e.adapter}),e.note?` · ${e.note}`:``]})]}),(0,S.jsx)(`div`,{className:`provider-catalog-badges`,children:k(e)})]},e.id)),!n&&D.length===0&&(0,S.jsx)(`div`,{className:`muted text-control provider-catalog-empty`,children:f(`modal.noMatch`)}),p===`accounts`&&o.map(e=>{let t=s[e.id],n=c===e.id;return(0,S.jsxs)(`div`,{className:`list-row provider-catalog-account-row`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`title`,children:e.label}),(0,S.jsx)(`div`,{className:`sub`,children:t?.loggedIn?t.email??e.statusLabel??f(`modal.accountLoggedIn`):t?.error??e.statusLabel??f(`modal.accountLoggedOut`)})]}),(0,S.jsx)(`div`,{className:`provider-catalog-badges`,children:t?.loggedIn?d&&(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>d(e.id),children:f(`modal.accountLogout`)}):n?u&&(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>u(e.id),children:f(`common.cancel`)}):l&&(0,S.jsx)(`button`,{className:`btn btn-primary`,onClick:()=>l(e.id),children:f(`modal.accountLogin`)})})]},e.id)})]}),(0,S.jsxs)(`div`,{className:`provider-catalog-footer`,children:[h===`home`&&w.length>dt&&(0,S.jsx)(`button`,{className:`link-btn`,onClick:O,children:f(`modal.browseAll`,{count:w.length})}),h===`browse`&&(0,S.jsx)(`button`,{className:`link-btn`,onClick:()=>{g(`home`),y(``)},children:f(`modal.browseBack`)}),(0,S.jsx)(`div`,{style:{flex:1}}),p!==`accounts`&&(0,S.jsx)(`button`,{className:`link-btn`,onClick:a,children:f(`modal.notListed`)})]})]})}function pt({apiBase:e,existingNames:t,onClose:n,onAdded:r,initialTier:i,initialCustom:a=!1}){let o=U(),s=(0,_.useMemo)(()=>[{id:`custom`,label:o(`modal.customProvider`),adapter:`openai-chat`,baseUrl:``,auth:`key`}],[o]),[c,l]=(0,_.useState)(a?{id:`custom`,label:o(`modal.customProvider`),adapter:`openai-chat`,baseUrl:``,auth:`key`}:null),[u,d]=(0,_.useState)(a?{name:``,adapter:`openai-chat`,baseUrl:``,authMode:`key`,apiKey:``,defaultModel:``}:null),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)([]),[y,b]=(0,_.useState)(!1),[x,C]=(0,_.useState)(``),[w,T]=(0,_.useState)(`ok`),[E,D]=(0,_.useState)(``),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(``),[M,P]=(0,_.useState)(!0),[ee,F]=(0,_.useState)(s),[I,L]=(0,_.useState)(!0),[te,ne]=(0,_.useState)({}),R=(0,_.useRef)(!0),z=(0,_.useRef)(!1),B=(0,_.useRef)(null),re=(0,_.useRef)(null);(0,_.useEffect)(()=>{R.current=!0,B.current=document.activeElement;let e=re.current;if(e){let t=e.querySelector(`input:not([disabled]), button:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1'])`);t&&t.focus()}return()=>{R.current=!1,B.current?.focus()}},[]),(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,_.useEffect)(()=>{fetch(`${e}/api/oauth/providers`).then(e=>e.json()).then(e=>v(e.providers??[])).catch(()=>{})},[e]),(0,_.useEffect)(()=>{fetch(`${e}/api/provider-presets`).then(e=>e.json()).then(e=>{Array.isArray(e.providers)&&e.providers.length>0&&(z.current=!0,F(e.providers))}).catch(()=>{}).finally(()=>L(!1))},[e]),(0,_.useEffect)(()=>{fetch(`${e}/api/usage?range=30d`).then(e=>e.json()).then(e=>{let t={};for(let n of e.providers??[])t[n.provider]=n.requests;ne(t)}).catch(()=>{})},[e]),(0,_.useEffect)(()=>{z.current||F(s)},[s]);let se=e=>{let t=Ge(e);return t?o(t):e.note},ce=e=>{l(e),d({name:e.id===`custom`?``:e.id,adapter:e.adapter,baseUrl:e.baseUrl,authMode:e.auth,apiKey:``,defaultModel:e.defaultModel??``}),h(``),C(``),T(`ok`),D(``),j(``),P(!0)},le=()=>{l(null),d(null),h(``),C(``),T(`ok`),D(``),j(``),P(!0)},V=async()=>{if(!u)return;let t=c?We(c):!1;if(!t&&!u.name.trim()){h(o(`modal.nameRequired`));return}if(!t&&!u.baseUrl.trim()){h(o(`modal.baseUrlRequired`));return}let n;try{n=qe(c??{id:`custom`},u)}catch{h(o(`modal.invalidPreset`));return}p(!0),h(``);try{let t=await fetch(`${e}/api/providers`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!t.ok){h((await t.json().catch(()=>({}))).error||o(`modal.failedStatus`,{status:t.status}));return}r(n.name)}catch{h(o(`modal.networkError`))}finally{p(!1)}},ue=async t=>{b(!0),C(``),T(`ok`),D(``),j(``),P(!0);try{let n=await fetch(`${e}/api/oauth/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:t})}),i=await n.json();if(!R.current)return;if(!n.ok){T(`warn`),C(i.error===`unknown oauth provider`?o(`modal.oauthComingSoonShort`):i.error||o(`modal.loginFailStart`));return}i.url?C(o(`modal.waitingLogin`)):C(i.instructions||o(`modal.loggingIn`));for(let n=0;n<100;n++){if(await new Promise(e=>setTimeout(e,2e3)),!R.current)return;let n=await fetch(`${e}/api/oauth/status?provider=${t}`).then(e=>e.json()).catch(()=>null);if(!R.current)return;if(n?.loggedIn){r(t);return}if(n?.error){T(`warn`),C(o(`modal.loginError`,{error:n.error}));return}}T(`warn`),C(o(`modal.loginTimeout`))}catch{R.current&&(T(`warn`),C(o(`modal.networkError`)))}finally{R.current&&b(!1)}},de=async t=>{let n=E.trim();if(!(!n||O)){k(!0),j(``);try{let r=await fetch(`${e}/api/oauth/login/code`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:t,input:n})}),i=await r.json().catch(()=>({}));if(!R.current)return;if(!r.ok){P(!1),j(o(`prov.pasteFail`,{error:i.error||r.statusText}));return}D(``),P(!0),j(o(`prov.pasteOk`))}catch{R.current&&(P(!1),j(o(`modal.networkError`)))}finally{R.current&&k(!1)}}},fe=u?t.includes(u.name.trim())&&u.name.trim()!==``:!1,pe=c?.id===`custom`,me=u?.authMode===`local`,he=c?We(c):!1;return(0,S.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":o(`modal.add`),className:`modal-overlay`,onClick:n,children:(0,S.jsxs)(`div`,{ref:re,className:`modal-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`modal-head`,children:[(0,S.jsx)(`h3`,{children:c?o(`modal.addNamed`,{label:c.label}):o(`modal.add`)}),(0,S.jsx)(`button`,{className:`btn btn-ghost btn-icon`,"aria-label":o(`common.close`),onClick:n,children:(0,S.jsx)(N,{})})]}),c?u&&(c.auth===`oauth`&&u.authMode===`oauth`?(0,S.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:14},children:[(0,S.jsx)(`div`,{className:`muted text-control`,children:c.note??o(`modal.oauthDefaultNote`)}),g.includes(c.oauthProvider??``)?(0,S.jsxs)(`button`,{className:`btn btn-primary`,onClick:()=>ue(c.oauthProvider),disabled:y,style:{width:`100%`,padding:`12px 16px`},children:[(0,S.jsx)(oe,{}),y?o(`modal.waitingBrowser`):o(`modal.logInWith`,{label:c.label})]}):(0,S.jsx)(`div`,{className:`text-control`,style:{color:`var(--amber)`,background:`var(--amber-soft)`,border:`1px solid var(--amber)`,borderRadius:`var(--radius-sm)`,padding:`10px 12px`},children:o(`modal.oauthComingSoon`,{label:c.label})}),x&&(0,S.jsx)(`div`,{className:`text-label`,style:{color:w===`warn`?`var(--amber)`:`var(--accent-hover)`},children:x}),y&&(0,S.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:6},children:[(0,S.jsx)(`div`,{className:`muted text-label`,children:o(`prov.pasteRedirectHint`)}),(0,S.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,S.jsx)(`input`,{type:`text`,autoComplete:`off`,spellCheck:!1,value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c.oauthProvider&&(e.preventDefault(),de(c.oauthProvider))},placeholder:o(`prov.pasteRedirect`),"aria-label":o(`prov.pasteRedirect`),disabled:O,className:`input text-label`,style:{flex:1}}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,type:`button`,disabled:O||!E.trim()||!c.oauthProvider,onClick:()=>c.oauthProvider&&void de(c.oauthProvider),children:o(O?`prov.pasteSubmitting`:`prov.pasteSubmit`)})]}),A&&(0,S.jsx)(`div`,{className:`text-label`,style:{color:M?`var(--accent-hover)`:`var(--amber)`},children:A})]}),(0,S.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginTop:2},children:[(0,S.jsx)(`button`,{className:`link-btn`,onClick:()=>{d({...u,authMode:`key`}),C(``),T(`ok`),D(``),j(``)},children:o(`modal.useApiKeyInstead`)}),(0,S.jsx)(`div`,{style:{flex:1}}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:le,children:o(`modal.back`)})]})]}):(0,S.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:10},children:[!he&&!pe&&!me&&!c.keyOptional&&c.note&&(0,S.jsxs)(`details`,{className:`setup-guide`,children:[(0,S.jsx)(`summary`,{children:o(`modal.setupGuide`)}),(0,S.jsxs)(`ol`,{className:`text-label leading-relaxed`,style:{margin:`8px 0 0`,paddingLeft:18,color:`var(--muted)`},children:[(0,S.jsxs)(`li`,{children:[o(`modal.setupStep1Prefix`),` `,(0,S.jsx)(`a`,{href:c.dashboardUrl,target:`_blank`,rel:`noreferrer`,children:o(`modal.setupDashboardLink`,{label:c.label})}),` `,o(`modal.setupStep1Suffix`)]}),(0,S.jsx)(`li`,{children:o(`modal.setupStep2`)}),(0,S.jsx)(`li`,{children:o(`modal.setupStep3`)})]}),c.note&&(0,S.jsx)(`div`,{className:`text-label`,style:{color:`var(--muted)`,marginTop:6,fontStyle:`italic`},children:c.note})]}),(0,S.jsx)(mt,{label:o(`modal.providerName`),children:(0,S.jsx)(`input`,{className:`input`,value:u.name,readOnly:he,onChange:e=>d({...u,name:e.target.value}),placeholder:o(`modal.namePlaceholder`)})}),fe&&(0,S.jsx)(`div`,{className:`text-label`,style:{color:`var(--amber)`},children:o(`modal.duplicateWarn`,{name:u.name.trim()})}),!he&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(mt,{label:o(`modal.adapter`),children:(0,S.jsx)(`select`,{className:`input`,value:u.adapter,onChange:e=>d({...u,adapter:e.target.value}),children:[`openai-responses`,`openai-chat`,`anthropic`,`google`,`azure-openai`,`cursor`].map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))})}),(0,S.jsx)(mt,{label:o(`modal.baseUrl`),children:(0,S.jsx)(`input`,{className:`input`,value:u.baseUrl,onChange:e=>d({...u,baseUrl:e.target.value}),placeholder:o(`modal.baseUrlPlaceholder`)})})]}),u.authMode===`forward`?(0,S.jsx)(`div`,{className:`text-label`,style:{color:`var(--green)`,background:`var(--green-soft)`,border:`1px solid var(--green)`,borderRadius:`var(--radius-sm)`,padding:`8px 10px`},children:se(c)}):u.authMode===`local`?(0,S.jsx)(`div`,{className:`text-label leading-relaxed`,style:{color:`var(--amber)`,background:`var(--amber-soft)`,border:`1px solid var(--amber)`,borderRadius:`var(--radius-sm)`,padding:`8px 10px`},children:o(`modal.localHint`)}):c.keyOptional?(0,S.jsxs)(`div`,{className:`text-label leading-relaxed`,style:{color:`var(--green)`,background:`var(--green-soft)`,border:`1px solid var(--green)`,borderRadius:`var(--radius-sm)`,padding:`10px 12px`},children:[(0,S.jsx)(`strong`,{children:o(`modal.freeTierTitle`)}),` — `,c.note??o(`modal.freeTierDefault`)]}):(0,S.jsxs)(S.Fragment,{children:[c.dashboardUrl&&(0,S.jsxs)(`a`,{className:`text-label`,href:c.dashboardUrl,target:`_blank`,rel:`noreferrer`,style:{display:`inline-flex`,alignItems:`center`,gap:5},children:[(0,S.jsx)(ae,{style:{width:14,height:14}}),o(`modal.getApiKey`,{label:c.label}),(0,S.jsx)(ie,{style:{width:13,height:13}})]}),(0,S.jsx)(mt,{label:o(`modal.apiKey`),children:(0,S.jsx)(`input`,{className:`input`,type:`password`,value:u.apiKey,onChange:e=>d({...u,apiKey:e.target.value}),placeholder:o(`modal.apiKeyPlaceholder`)})})]}),!he&&(0,S.jsx)(mt,{label:o(`modal.defaultModel`),children:(0,S.jsx)(`input`,{className:`input`,value:u.defaultModel,onChange:e=>d({...u,defaultModel:e.target.value}),placeholder:o(`modal.defaultModelPlaceholder`)})}),m&&(0,S.jsx)(`div`,{className:`text-control`,role:`alert`,style:{color:`var(--red)`},children:m}),(0,S.jsxs)(`div`,{style:{display:`flex`,gap:8,marginTop:4,alignItems:`center`},children:[(0,S.jsx)(`button`,{className:`btn btn-primary`,onClick:V,disabled:f,children:o(f?`modal.adding`:`modal.add`)}),c.auth===`oauth`&&(0,S.jsx)(`button`,{className:`link-btn`,onClick:()=>{d({...u,authMode:`oauth`}),h(``)},children:o(`modal.useOauthLogin`)}),(0,S.jsx)(`div`,{style:{flex:1}}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:le,children:o(`modal.back`)})]})]})):(0,S.jsx)(ft,{presets:ee,usageRank:te,presetsLoading:I,initialTier:i,onSelectPreset:e=>ce(e),onSelectCustom:()=>ce(s[0])})]})})}function mt({label:e,children:t}){return(0,S.jsxs)(`label`,{style:{display:`block`},children:[(0,S.jsx)(`span`,{className:`field-label`,children:e}),t]})}function ht(e){return e.authMode===`local`||Ze(e.baseUrl)}var gt=[`ollama`,`vllm`,`lm-studio`,`lmstudio`,`litellm`,`localai`];function _t(e){let t=(e.authMode??``).toLowerCase();if(t===`oauth`||t===`forward`)return`login`;if(ht(e))return`local`;let n=`${e.name??``} ${e.adapter} ${e.baseUrl}`.toLowerCase();return gt.some(e=>n.includes(e))?`selfHosted`:`cloud`}function vt(e){if(!e||typeof e!=`object`)return{};let t=e.available;if(!t||typeof t!=`object`||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))Array.isArray(r)&&(n[e]=r.filter(e=>typeof e==`string`));return n}function yt(e){if(!e||typeof e!=`object`)return{};let t=e.selected;if(!t||typeof t!=`object`||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))Array.isArray(r)&&(n[e]=r.filter(e=>typeof e==`string`));return n}function bt(e){let t={};for(let[n,r]of Object.entries(vt(e)))t[n]=r.length;return t}function xt(e){return Object.entries(e).filter(e=>typeof e[1].requests==`number`&&e[1].requests>0).map(([e,t])=>({name:e,...t,requests:t.requests})).sort((e,t)=>t.requests-e.requests||e.name.localeCompare(t.name))}var St={justNow:`Just now`,notChecked:`Not checked`,minutesAgo:e=>`${e}m ago`,hoursAgo:e=>`${e}h ago`,daysAgo:e=>`${e}d ago`};function Ct(e,t,n){let r=typeof t==`object`&&t?t:St,i=typeof t==`number`?t:n??Date.now();if(e===void 0||!Number.isFinite(e))return r.notChecked;let a=Math.max(0,i-e),o=Math.floor(a/6e4);if(o<1)return r.justNow;if(o<60)return r.minutesAgo(o);let s=Math.floor(o/60);return s<24?r.hoursAgo(s):r.daysAgo(Math.floor(s/24))}function wt(e){return{justNow:e(`time.justNow`),notChecked:e(`time.notChecked`),minutesAgo:t=>e(`time.minutesAgo`,{n:t}),hoursAgo:t=>e(`time.hoursAgo`,{n:t}),daysAgo:t=>e(`time.daysAgo`,{n:t})}}function Tt(e,t=`en`){if(e===void 0)return`—`;if(t.toLowerCase().slice(0,2)===`de`){let t=e=>e.replace(/\.0+$/,``).replace(`.`,`,`);return e>=1e9?`${t((e/1e9).toFixed(2))} Mrd.`:e>=1e6?`${t((e/1e6).toFixed(1))} Mio.`:e>=1e3?`${t((e/1e3).toFixed(1))} Tsd.`:String(e)}return e>=1e9?`${(e/1e9).toFixed(2).replace(/\.?0+$/,``)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Et(e,t=`en`){return Tt(e,t)}var Dt={anthropic:`claude-color.svg`,"anthropic-apikey":`claude-color.svg`,"azure-openai":`openai.svg`,chatgpt:`openai.svg`,"cloudflare-ai-gateway":`cloudflare-ai-gateway-color.svg`,cursor:`cursor-color.svg`,deepseek:`deepseek-color.svg`,firepass:`firepass-color.svg`,fireworks:`fireworks-color.svg`,github:`github-copilot-color.svg`,"github-copilot":`copilot-color.svg`,"gitlab-duo":`gitlab-duo-color.svg`,google:`gemini-color.svg`,"google-antigravity":`antigravity-color.svg`,"google-vertex":`gemini-color.svg`,groq:`groq-color.svg`,huggingface:`huggingface-color.svg`,kimi:`kimi-color.svg`,"kimi-code":`kimi-color.svg`,kiro:`kiro-color.svg`,"lm-studio":`lm-studio-color.svg`,mistral:`mistral-color.svg`,moonshot:`moonshot-color.svg`,nvidia:`nvidia-color.svg`,ollama:`ollama-color.svg`,"ollama-cloud":`ollama-color.svg`,openai:`openai.svg`,"openai-apikey":`openai.svg`,"opencode-free":`opencode.svg`,"opencode-go":`opencode.svg`,"opencode-zen":`opencode.svg`,openrouter:`openrouter-color.svg`,qianfan:`qianfan-color.svg`,"qwen-portal":`qwen-portal-color.svg`,"vercel-ai-gateway":`vercel-ai-gateway-color.svg`,vllm:`vllm-color.svg`,xai:`grok-color.svg`,"mimo-free":`xiaomi-color.svg`,xiaomi:`xiaomi-color.svg`},Ot={anthropic:`Anthropic Claude`,"anthropic-apikey":`Anthropic Claude`,chatgpt:`ChatGPT`,openai:`OpenAI (Codex login)`,"openai-apikey":`OpenAI API`,"azure-openai":`Azure OpenAI`,"cloudflare-ai-gateway":`Cloudflare AI Gateway`,nvidia:`NVIDIA NIM`,ollama:`Ollama`,"ollama-cloud":`Ollama Cloud`,xai:`xAI Grok`,"mimo-free":`MiMo Free`,xiaomi:`Xiaomi`,cursor:`Cursor`,deepseek:`DeepSeek`,github:`GitHub`,"github-copilot":`GitHub Copilot`,"gitlab-duo":`GitLab Duo`,openrouter:`OpenRouter`,"opencode-go":`OpenCode Go`,"opencode-free":`OpenCode Free`,"opencode-zen":`OpenCode Zen`,mistral:`Mistral`,groq:`Groq`,kimi:`Kimi`,"kimi-code":`Kimi`,moonshot:`Moonshot`,google:`Google`,"google-vertex":`Google Vertex`,"lm-studio":`LM Studio`,huggingface:`Hugging Face`,"vercel-ai-gateway":`Vercel AI Gateway`,vllm:`vLLM`,litellm:`LiteLLM`};function kt(e){return Dt[e.toLowerCase()]}function At(e,t){let n=kt(e);return n?`/provider-icons/${n}`:void 0}function jt(e){let t=e.toLowerCase();return Ot[t]?Ot[t]:e===t&&/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e)?e.split(`-`).map(e=>e&&e[0].toUpperCase()+e.slice(1)).join(` `):e}function Mt(e){return Object.prototype.hasOwnProperty.call(Ot,e.toLowerCase())}function Nt(e,t){let n=at(e);return t(n===`disabled`?`prov.disabledBadge`:n===`ready`?`pws.status.ready`:`pws.status.needsSetup`)}function Pt(e,t){switch(e.authMode){case`oauth`:return t(`modal.badge.oauth`);case`forward`:return t(`pws.auth.chatgptPassthrough`);case`local`:return t(`modal.badge.local`);case`key`:return t(`modal.badge.apiKey`);default:return e.authMode??(e.keyOptional?t(`pws.auth.noKey`):t(`modal.badge.apiKey`))}}function Ft(e){let t=at(e);return t===`disabled`?`providers-workspace-rail-status providers-workspace-rail-status--inactive`:t===`ready`?`providers-workspace-rail-status providers-workspace-rail-status--active`:`providers-workspace-rail-status providers-workspace-rail-status--warning`}function It({name:e,adapter:t,baseUrl:n,cls:r}){let i=At(e,{adapter:t,baseUrl:n});return(0,S.jsx)(`span`,{className:r,children:i?(0,S.jsx)(`img`,{src:i,alt:``,"aria-hidden":`true`}):(0,S.jsx)(T,{"aria-hidden":`true`})})}function Lt({item:e,selected:t,tabbable:n,modelCount:r,isDefault:i,showConfigId:a,onClick:o,onFocus:s}){let c=U(),l=tt(e),u=ht(e),d=Nt(e,c),f=jt(e.name),p=a?`${f} (${e.name})`:f,m=`${i?c(`pws.rail.suffixDefault`):``}${u?c(`pws.rail.suffixLocal`):l?c(`pws.rail.suffixFree`):``}`,h=r!==void 0&&r>0?r===1?c(`pws.modelCountOne`):c(`pws.modelCount`,{count:r}):``,g=[a?e.name:``,h].filter(Boolean).join(` · `);return(0,S.jsxs)(`button`,{type:`button`,className:`providers-workspace-rail-row${t?` providers-workspace-rail-row--selected`:``}`,onClick:o,role:`option`,"aria-selected":t,tabIndex:n?0:-1,"aria-label":c(`pws.rail.selectAria`,{name:p,status:d,suffix:m}),title:p,onFocus:s,children:[(0,S.jsx)(It,{name:e.name,adapter:e.adapter,baseUrl:e.baseUrl,cls:`providers-workspace-rail-icon`}),(0,S.jsxs)(`span`,{className:`providers-workspace-rail-copy`,children:[(0,S.jsxs)(`span`,{className:`providers-workspace-rail-primary`,children:[(0,S.jsx)(`span`,{className:`providers-workspace-rail-name-label`,title:f,children:f}),u?(0,S.jsx)(`span`,{className:`pwi-rail-badge pwi-rail-badge--local`,title:c(`pws.localTitle`),children:c(`modal.badge.local`)}):l?(0,S.jsx)(`span`,{className:`pwi-rail-badge pwi-rail-badge--free`,title:c(`pws.freeTitle`),children:c(`modal.badge.free`)}):null]}),g&&(0,S.jsx)(`span`,{className:`providers-workspace-rail-secondary`,title:g,children:g})]}),(0,S.jsxs)(`span`,{className:`providers-workspace-rail-trail`,children:[i&&(0,S.jsx)(`span`,{className:`pwi-default-star`,title:c(`prov.defaultBadge`),"aria-label":c(`prov.defaultBadge`),children:(0,S.jsx)(he,{width:17,height:17,"aria-hidden":`true`})}),(0,S.jsx)(`span`,{className:Ft(e),title:d,"aria-hidden":`true`})]})]})}function Rt(e){let t=e?.quota;if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t,r=e=>typeof e==`number`&&Number.isFinite(e)?e:void 0,i=Array.isArray(n.customWindows)?n.customWindows.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;return typeof t.label!=`string`||r(t.percent)===void 0?[]:[{label:t.label,percent:t.percent,...r(t.resetAt)===void 0?{}:{resetAt:t.resetAt}}]}):[],a={...r(n.fiveHourPercent)===void 0?{}:{fiveHourPercent:n.fiveHourPercent},...r(n.fiveHourResetAt)===void 0?{}:{fiveHourResetAt:n.fiveHourResetAt},...r(n.weeklyPercent)===void 0?{}:{weeklyPercent:n.weeklyPercent},...r(n.weeklyResetAt)===void 0?{}:{weeklyResetAt:n.weeklyResetAt},...r(n.monthlyPercent)===void 0?{}:{monthlyPercent:n.monthlyPercent},...r(n.monthlyResetAt)===void 0?{}:{monthlyResetAt:n.monthlyResetAt},...i.length>0?{customWindows:i}:{},updatedAt:r(n.updatedAt)??e?.updatedAt??Date.now()};return a.fiveHourPercent!==void 0||a.weeklyPercent!==void 0||a.monthlyPercent!==void 0||(a.customWindows?.length??0)>0?a:null}function zt(e){if(!e?.trim())return``;let[t,n]=e.split(`:`,2);return n?`${t} · ${n.replace(/-/g,` `)}`:e}function Bt(e,t,n){let r=e.length>0?e:t?[t]:[],i=n.trim().toLowerCase();return i?r.filter(e=>e.toLowerCase().includes(i)):r}function Vt(e){let t=e?.trim().toLowerCase();return t===`go`||t===`free`}function Ht(e,t){return!e||!Vt(t)?e:{...e.monthlyPercent===void 0?{}:{monthlyPercent:e.monthlyPercent},...e.monthlyResetAt===void 0?{}:{monthlyResetAt:e.monthlyResetAt},...e.resetCredits===void 0?{}:{resetCredits:e.resetCredits},updatedAt:e.updatedAt}}function Ut(e){return e===`5h`?0:e===`First-party models`?2:e===`API usage`?3:5}function Wt(e,t){switch(e){case`First-party models`:return t(`quota.cursorFirstParty`);case`API usage`:return t(`quota.cursorApiUsage`);case`Total subscription credits`:return t(`quota.totalSubscriptionCredits`);default:return e}}function Gt(e,t,n){let r=Ht(e,t);if(!r)return[];let i=[];typeof r.fiveHourPercent==`number`&&i.push({rank:0,row:{label:n(`codexAuth.fiveHour`),limitLabel:n(`quota.fiveHourLimit`),percent:r.fiveHourPercent,resetAt:r.fiveHourResetAt}}),typeof r.weeklyPercent==`number`&&i.push({rank:1,row:{label:n(`codexAuth.weekly`),limitLabel:n(`quota.weeklyLimit`),percent:r.weeklyPercent,resetAt:r.weeklyResetAt}}),typeof r.monthlyPercent==`number`&&i.push({rank:4,row:{label:n(`codexAuth.monthly`),limitLabel:n(`quota.monthlyLimit`),percent:r.monthlyPercent,resetAt:r.monthlyResetAt}});for(let e of r.customWindows??[]){let t=Wt(e.label,n);i.push({rank:Ut(e.label),row:{label:t,limitLabel:t,percent:e.percent,resetAt:e.resetAt}})}return i.sort((e,t)=>e.rank-t.rank).map(e=>e.row)}function Kt(e){switch(e){case`en`:return`en-GB`;case`de`:return`de-DE`;case`ko`:return`ko-KR`;case`zh`:return`zh-CN`;default:return e}}function qt(e){return e>=99.5}function Jt(e,t){return t>0&&e>=t}function Yt(e,t){return Jt(e,t)||qt(e)?`bar-warn`:`bar-green`}function Xt(e){let t=Math.max(0,Math.min(100,e));return t<=0?0:Math.max(4,Math.round(t))}function Zt({quota:e,plan:t,threshold:n,t:r,className:i,layout:a=`compact`}){let{locale:o}=H(),s=Gt(e,t,r);return s.length===0?null:a===`stacked`?(0,S.jsx)(`div`,{className:`quota-stacked${i?` ${i}`:``}`,children:s.map((e,t)=>(0,S.jsx)($t,{row:e,threshold:n,t:r,locale:o},`${e.limitLabel}-${t}`))}):(0,S.jsx)(`div`,{className:`quota-compact${i?` ${i}`:``}`,children:s.map((e,t)=>(0,S.jsx)(Qt,{label:e.label,percent:e.percent,resetAt:e.resetAt,threshold:n,t:r,locale:o},`${e.label}-${t}`))})}function Qt({label:e,percent:t,resetAt:n,threshold:r,t:i,locale:a}){let o=qt(t),s=Jt(t,r),c=Yt(t,r),l=en(n,i,a);return(0,S.jsxs)(`div`,{className:`quota-row${s?` quota-row--warn`:``}${o?` quota-row--exhausted`:``}`,children:[(0,S.jsx)(`span`,{className:`quota-label`,children:e}),(0,S.jsx)(`span`,{className:`quota-reset-label`,children:i(`codexAuth.resets`)}),(0,S.jsx)(`span`,{className:`quota-reset-day`,children:l.day}),(0,S.jsx)(`span`,{className:`quota-reset-time`,children:l.time}),(0,S.jsx)(`div`,{className:`bar`,children:(0,S.jsx)(`div`,{className:`bar-fill ${c}`,style:{width:`${Xt(t)}%`}})}),(0,S.jsxs)(`span`,{className:`quota-val${s?` quota-val--warn`:``}`,title:o?i(`quota.limitReached`):void 0,children:[s&&(0,S.jsx)(I,{width:12,height:12,"aria-hidden":`true`}),Math.round(t),`%`,o?` · ${i(`quota.limitReached`)}`:``]})]})}function $t({row:e,threshold:t,t:n,locale:r}){let i=qt(e.percent),a=Jt(e.percent,t),o=Yt(e.percent,t),s=tn(e.resetAt,n,r);return(0,S.jsxs)(`div`,{className:`quota-stacked-row${a?` quota-stacked-row--warn`:``}${i?` quota-stacked-row--exhausted`:``}`,children:[(0,S.jsxs)(`div`,{className:`quota-stacked-head`,children:[(0,S.jsx)(`span`,{className:`quota-stacked-limit`,children:e.limitLabel}),(0,S.jsx)(`span`,{className:`quota-stacked-reset muted`,children:s})]}),(0,S.jsxs)(`div`,{className:`quota-stacked-bar-row`,children:[(0,S.jsx)(`div`,{className:`bar quota-stacked-bar`,children:(0,S.jsx)(`div`,{className:`bar-fill ${o}`,style:{width:`${Xt(e.percent)}%`}})}),(0,S.jsx)(`span`,{className:`quota-stacked-used${a?` quota-stacked-used--warn`:``}`,children:n(`quota.usedPercent`,{pct:Math.round(e.percent)})})]}),i&&(0,S.jsxs)(`div`,{className:`quota-stacked-limit-reached`,role:`status`,children:[(0,S.jsx)(I,{width:12,height:12,"aria-hidden":`true`}),n(`quota.limitReached`)]})]})}function en(e,t,n){if(typeof e!=`number`||!Number.isFinite(e))return{day:``,time:``};let r=e<1e10?e*1e3:e,i=new Date(r),a=new Date,o=Kt(n),s=new Intl.DateTimeFormat(o,{hour:`2-digit`,minute:`2-digit`,hour12:!1}).format(i);return i.getFullYear()===a.getFullYear()&&i.getMonth()===a.getMonth()&&i.getDate()===a.getDate()?{day:t(`codexAuth.today`),time:s}:{day:new Intl.DateTimeFormat(o,{day:`numeric`,month:`short`}).format(i),time:s}}function tn(e,t,n=`en`,r=Date.now()){if(typeof e!=`number`||!Number.isFinite(e))return``;let i=e<1e10?e*1e3:e,a=new Date(i),o=Kt(n),s=new Intl.DateTimeFormat(o,{hour:`2-digit`,minute:`2-digit`,hour12:!1}).format(a),c=new Date(r),l=new Date(c.getFullYear(),c.getMonth(),c.getDate()).getTime(),u=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),d=Math.round((u-l)/864e5);if(d===1)return t(`quota.resetsTomorrow`,{time:s});let f=a.getFullYear()!==c.getFullYear(),p=new Intl.DateTimeFormat(o,{day:`numeric`,month:`short`,...f?{year:`numeric`}:{}}).format(a);if(i<=r)return t(`quota.resetsAt`,{date:p,time:s,when:`${p}, ${s}`});let m=Math.round((i-r)/6e4);if(m<60)return t(`quota.resetsRelativeMinutes`,{n:Math.max(1,m)});let h=Math.round(m/60);return h<12&&d===0?t(`quota.resetsRelativeHours`,{n:Math.max(1,h)}):d===0?t(`quota.resetsToday`,{time:s}):t(`quota.resetsAt`,{date:p,time:s,when:`${p}, ${s}`})}function nn({sections:e,quotaReports:t,usageTotals:n,onSelectProvider:r}){let i=U(),{locale:a}=H(),o=wt(i),s=(0,_.useMemo)(()=>[...e.ready,...e.needsSetup,...e.disabled],[e]),c=(0,_.useMemo)(()=>new Set(s.map(e=>e.name)),[s]),l=(0,_.useMemo)(()=>{let e=[];for(let n of s){let r=t[n.name];r&&Rt(r)&&e.push({item:n,report:r})}return e},[s,t]),u=(0,_.useMemo)(()=>{let e={};for(let[t,r]of Object.entries(n))c.has(t)&&(e[t]=r);return xt(e)},[n,c]);return(0,S.jsxs)(`div`,{className:`pws-dashboard`,children:[(0,S.jsxs)(`div`,{className:`pws-dashboard-header`,children:[(0,S.jsx)(`h2`,{className:`pws-dashboard-title`,children:i(`pws.dashboard.title`)}),(0,S.jsx)(`p`,{className:`muted pws-dashboard-subtitle`,children:i(`pws.dashboard.subtitle`)})]}),(0,S.jsxs)(`div`,{className:`pws-dashboard-summary`,children:[(0,S.jsx)(rn,{count:e.ready.length,label:i(`pws.status.ready`),tone:`ok`}),(0,S.jsx)(rn,{count:e.needsSetup.length,label:i(`pws.status.needsSetup`),tone:`warn`}),(0,S.jsx)(rn,{count:e.disabled.length,label:i(`prov.disabledBadge`),tone:`muted`})]}),l.length>0&&(0,S.jsxs)(`section`,{className:`pws-dashboard-section`,"aria-label":i(`pws.dashboard.rateLimits`),children:[(0,S.jsx)(`h3`,{className:`pws-dashboard-section-title`,children:i(`pws.dashboard.rateLimits`)}),(0,S.jsx)(`div`,{className:`pws-dashboard-rows`,children:l.map(({item:e,report:t})=>(0,S.jsxs)(`button`,{type:`button`,className:`pws-dashboard-row`,onClick:()=>r(e.name),children:[(0,S.jsx)(It,{name:e.name,adapter:e.adapter,baseUrl:e.baseUrl,cls:`pws-dashboard-row-icon`}),(0,S.jsxs)(`div`,{className:`pws-dashboard-row-info`,children:[(0,S.jsx)(`span`,{className:`pws-dashboard-row-name`,children:jt(e.name)}),(0,S.jsx)(`span`,{className:`pws-dashboard-row-meta muted`,children:i(`pws.dashboard.checkedAgo`,{time:Ct(t.updatedAt,o)})})]}),(0,S.jsx)(z,{className:`pws-dashboard-row-chevron`,"aria-hidden":`true`}),(0,S.jsx)(`div`,{className:`pws-dashboard-row-bars`,children:(0,S.jsx)(Zt,{quota:Rt(t),threshold:80,t:i,layout:`stacked`})})]},e.name))})]}),u.length>0?(0,S.jsxs)(`section`,{className:`pws-dashboard-section`,"aria-label":i(`pws.dashboard.recentlyUsed`),children:[(0,S.jsx)(`h3`,{className:`pws-dashboard-section-title`,children:i(`pws.dashboard.recentlyUsed`)}),(0,S.jsx)(`div`,{className:`pws-dashboard-rows`,children:u.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`pws-dashboard-row`,onClick:()=>r(e.name),children:[(0,S.jsx)(It,{name:e.name,adapter:``,baseUrl:``,cls:`pws-dashboard-row-icon`}),(0,S.jsx)(`span`,{className:`pws-dashboard-row-name`,children:jt(e.name)}),(0,S.jsx)(`span`,{className:`pws-dashboard-row-count muted`,children:i(`pws.dashboard.requests`,{count:Tt(e.requests,a)})}),(0,S.jsx)(z,{className:`pws-dashboard-row-chevron`,"aria-hidden":`true`})]},e.name))})]}):(0,S.jsxs)(`section`,{className:`pws-dashboard-section`,children:[(0,S.jsx)(`h3`,{className:`pws-dashboard-section-title`,children:i(`pws.dashboard.recentlyUsed`)}),(0,S.jsx)(`p`,{className:`muted`,children:i(`pws.dashboard.noUsage`)})]})]})}function rn({count:e,label:t,tone:n}){return(0,S.jsxs)(`div`,{className:`pws-dashboard-card pws-dashboard-card--${n}`,children:[(0,S.jsx)(`span`,{className:`pws-dashboard-card-count`,children:e}),(0,S.jsx)(`span`,{className:`pws-dashboard-card-label`,children:t})]})}var an=[{id:`az`,labelKey:`pws.sort.az`},{id:`za`,labelKey:`pws.sort.za`},{id:`free-paid`,labelKey:`pws.sort.freePaid`},{id:`paid-free`,labelKey:`pws.sort.paidFree`},{id:`accounts-first`,labelKey:`pws.sort.accountsFirst`}];function on({providers:e,apiBase:t,defaultProvider:n,selectedName:r,onSelect:i,onAddProvider:a,detail:o}){let s=U(),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)({ready:!0,needsSetup:!0,disabled:!0}),[f,p]=(0,_.useState)({free:!0,paid:!0}),[m,h]=(0,_.useState)({cloud:!0,local:!0,selfHosted:!0,login:!0}),[g,v]=(0,_.useState)(`az`),[y,b]=(0,_.useState)(!1),[x,C]=(0,_.useState)(null),[w,T]=(0,_.useState)({}),[E,D]=(0,_.useState)({}),[O,k]=(0,_.useState)({}),[A,j]=(0,_.useState)(!1),[M,N]=(0,_.useState)(!1),[P,ee]=(0,_.useState)({}),[F,I]=(0,_.useState)({}),L=(0,_.useRef)(null),ne=(0,_.useMemo)(()=>it(ot(e)),[e]);(0,_.useEffect)(()=>{let e=!1;return fetch(`${t}/api/selected-models`).then(e=>e.ok?e.json():Promise.reject(Error(String(e.status)))).then(t=>{e||(T(bt(t)),D(vt(t)),k(yt(t)),N(!1),j(!1))}).catch(()=>{e||(N(!0),j(!1))}),()=>{e=!0}},[t]),(0,_.useEffect)(()=>{let e=!1;return fetch(`${t}/api/usage?range=30d`).then(e=>e.ok?e.json():null).then(t=>{if(e||!t)return;let n={};for(let e of t.providers??[])n[e.provider]={requests:e.requests,totalTokens:e.totalTokens};ee(n)}).catch(()=>{}),()=>{e=!0}},[t]),(0,_.useEffect)(()=>{let e=!1;return fetch(`${t}/api/provider-quotas`).then(e=>e.ok?e.json():null).then(t=>{if(e||!t)return;let n={};for(let e of t.reports??[])e?.provider&&(n[e.provider]={label:e.label,source:e.source,updatedAt:typeof e.updatedAt==`number`?e.updatedAt:Date.now(),quota:e.quota});I(n)}).catch(()=>{}),()=>{e=!0}},[t]),(0,_.useEffect)(()=>{if(!y)return;let e=e=>{L.current&&!L.current.contains(e.target)&&b(!1)},t=e=>{e.key===`Escape`&&b(!1)};return document.addEventListener(`mousedown`,e),window.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),window.removeEventListener(`keydown`,t)}},[y]);let R=(0,_.useMemo)(()=>[...ne.ready,...ne.needsSetup,...ne.disabled],[ne]),z=(0,_.useMemo)(()=>R.filter(tt).length,[R]),B=R.length-z,re=(0,_.useMemo)(()=>{let e={cloud:0,local:0,selfHosted:0,login:0};for(let t of R)e[_t(t)]+=1;return e},[R]),ie=(0,_.useMemo)(()=>{let e=c.trim().toLowerCase(),t=t=>rt(t.filter(t=>{if(e&&!t.name.toLowerCase().includes(e)&&!t.adapter.toLowerCase().includes(e))return!1;let n=tt(t);return!(n&&!f.free||!n&&!f.paid||!m[_t(t)])}),g);return{ready:u.ready?t(ne.ready):[],needsSetup:u.needsSetup?t(ne.needsSetup):[],disabled:u.disabled?t(ne.disabled):[]}},[ne,c,u,f,m,g]),ae=!u.ready||!u.needsSetup||!u.disabled||!f.free||!f.paid||!m.cloud||!m.local||!m.selfHosted||!m.login||g!==`az`,oe=()=>{d({ready:!0,needsSetup:!0,disabled:!0}),p({free:!0,paid:!0}),h({cloud:!0,local:!0,selfHosted:!0,login:!0}),v(`az`)},se=(0,_.useMemo)(()=>r?R.find(e=>e.name===r)??null:null,[r,R]),ce=(0,_.useMemo)(()=>{let e=new Map;for(let t of R){let n=jt(t.name);e.set(n,(e.get(n)??0)+1)}return new Set([...e.entries()].filter(([,e])=>e>1).map(([e])=>e))},[R]);if(R.length===0)return(0,S.jsx)(sn,{onAddProvider:a});let le=[{key:`ready`,label:s(`pws.status.ready`),count:ne.ready.length},{key:`needsSetup`,label:s(`pws.status.needsSetup`),count:ne.needsSetup.length},{key:`disabled`,label:s(`prov.disabledBadge`),count:ne.disabled.length}],V=[{id:`ready`,label:s(`pws.status.ready`),count:ie.ready.length,ariaLabel:s(`pws.groupReady`,{count:ie.ready.length}),items:ie.ready},{id:`needs-setup`,label:s(`pws.status.needsSetup`),count:ie.needsSetup.length,ariaLabel:s(`pws.groupNeedsSetup`,{count:ie.needsSetup.length}),items:ie.needsSetup},{id:`disabled`,label:s(`prov.disabledBadge`),count:ie.disabled.length,ariaLabel:s(`pws.groupDisabled`,{count:ie.disabled.length}),items:ie.disabled}],ue=V.flatMap(e=>e.items.map(e=>e.name)),de=x&&ue.includes(x)?x:r&&ue.includes(r)?r:ue[0]??null;return(0,S.jsx)(`div`,{className:`pws-shell-container`,children:(0,S.jsxs)(`div`,{className:`pws-root`,children:[(0,S.jsxs)(`aside`,{className:`pws-rail`,"aria-label":s(`pws.providerList`),children:[(0,S.jsxs)(`div`,{className:`pws-search-row`,children:[(0,S.jsxs)(`div`,{className:`pws-search-wrap`,children:[(0,S.jsx)(te,{className:`pws-search-icon`,width:14,height:14,"aria-hidden":`true`}),(0,S.jsx)(`input`,{type:`search`,className:`input pws-search-input`,placeholder:s(`pws.searchPlaceholder`),value:c,onChange:e=>l(e.target.value),"aria-label":s(`pws.searchPlaceholder`)})]}),(0,S.jsxs)(`div`,{className:`pws-filter-wrap`,ref:L,children:[(0,S.jsxs)(`button`,{type:`button`,className:`pws-filter-btn${ae||y?` pws-filter-btn--active`:``}`,onClick:()=>b(e=>!e),"aria-label":s(`pws.filterAria`),"aria-haspopup":`menu`,"aria-expanded":y,children:[(0,S.jsx)(ge,{width:18,height:18,"aria-hidden":`true`}),ae&&(0,S.jsx)(`span`,{className:`pws-filter-dot`,"aria-hidden":`true`})]}),y&&(0,S.jsxs)(`div`,{className:`pws-filter-menu`,role:`menu`,"aria-label":s(`pws.providerFiltersAria`),children:[(0,S.jsx)(`div`,{className:`pws-filter-title`,children:s(`pws.filters`)}),(0,S.jsx)(`div`,{className:`pws-filter-head`,children:s(`pws.filterStatus`)}),le.map(({key:e,label:t,count:n})=>(0,S.jsxs)(`label`,{className:`pws-filter-option`,role:`menuitemcheckbox`,"aria-checked":u[e],children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:u[e],onChange:()=>d(t=>({...t,[e]:!t[e]}))}),(0,S.jsx)(`span`,{className:`pws-filter-label`,children:t}),(0,S.jsx)(`span`,{className:`pws-filter-count`,children:n})]},e)),(0,S.jsx)(`div`,{className:`pws-filter-head`,children:s(`pws.pricing`)}),(0,S.jsxs)(`label`,{className:`pws-filter-option`,role:`menuitemcheckbox`,"aria-checked":f.free,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:f.free,onChange:()=>p(e=>({...e,free:!e.free}))}),(0,S.jsx)(`span`,{className:`pws-filter-label`,children:s(`modal.badge.free`)}),(0,S.jsx)(`span`,{className:`pws-filter-count`,children:z})]}),(0,S.jsxs)(`label`,{className:`pws-filter-option`,role:`menuitemcheckbox`,"aria-checked":f.paid,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:f.paid,onChange:()=>p(e=>({...e,paid:!e.paid}))}),(0,S.jsx)(`span`,{className:`pws-filter-label`,children:s(`pws.paid`)}),(0,S.jsx)(`span`,{className:`pws-filter-count`,children:B})]}),(0,S.jsx)(`div`,{className:`pws-filter-head`,children:s(`pws.filterType`)}),[{key:`cloud`,label:s(`pws.type.cloud`),count:re.cloud},{key:`local`,label:s(`pws.type.local`),count:re.local},{key:`selfHosted`,label:s(`pws.type.selfHosted`),count:re.selfHosted},{key:`login`,label:s(`pws.type.login`),count:re.login}].map(({key:e,label:t,count:n})=>(0,S.jsxs)(`label`,{className:`pws-filter-option`,role:`menuitemcheckbox`,"aria-checked":m[e],children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:m[e],onChange:()=>h(t=>({...t,[e]:!t[e]}))}),(0,S.jsx)(`span`,{className:`pws-filter-label`,children:t}),(0,S.jsx)(`span`,{className:`pws-filter-count`,children:n})]},e)),(0,S.jsx)(`div`,{className:`pws-filter-head`,children:s(`pws.sort`)}),(0,S.jsx)(`div`,{className:`pws-sort-grid`,role:`group`,"aria-label":s(`pws.sortProvidersAria`),children:an.map(e=>(0,S.jsx)(`button`,{type:`button`,className:`pws-sort-btn${g===e.id?` pws-sort-btn--active`:``}`,onClick:()=>v(e.id),"aria-pressed":g===e.id,children:s(e.labelKey)},e.id))}),(0,S.jsx)(`div`,{className:`pws-filter-footer`,children:(0,S.jsx)(`button`,{type:`button`,className:`link-btn`,onClick:oe,disabled:!ae,children:s(`pws.resetAll`)})})]})]})]}),(0,S.jsxs)(`div`,{className:`pws-rail-list`,role:`listbox`,"aria-label":s(`pws.providersAria`),onKeyDown:e=>{let t=Array.from(e.currentTarget.querySelectorAll(`[role="option"]`));if(t.length===0)return;let n=document.activeElement,r=t.findIndex(e=>e===n||e.contains(n));if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let n=e.key===`ArrowDown`?1:-1;t[r<0?n>0?0:t.length-1:(r+n+t.length)%t.length]?.focus();return}if(e.key===`Home`){e.preventDefault(),t[0]?.focus();return}e.key===`End`&&(e.preventDefault(),t[t.length-1]?.focus())},children:[Object.values(ie).every(e=>e.length===0)&&(0,S.jsx)(`span`,{className:`muted pws-rail-empty`,role:`status`,children:s(c?`pws.noSearchResults`:ae?`pws.noMatchFilters`:`pws.noProvidersConfigured`)}),V.map(({id:e,label:t,count:a,ariaLabel:o,items:s})=>s.length===0?null:(0,S.jsxs)(`div`,{className:`pws-rail-group`,role:`group`,"aria-label":o,children:[(0,S.jsxs)(`div`,{className:`pws-rail-group-head`,"aria-hidden":`true`,children:[(0,S.jsx)(`span`,{className:`pws-rail-group-label`,children:t}),(0,S.jsx)(`span`,{className:`pws-rail-group-count`,children:a})]}),s.map(e=>(0,S.jsx)(Lt,{item:e,selected:r===e.name,tabbable:de===e.name,modelCount:w[e.name],isDefault:n===e.name,showConfigId:ce.has(jt(e.name)),onClick:()=>i(e.name),onFocus:()=>C(e.name)},e.name))]},e))]})]}),(0,S.jsx)(`main`,{className:`pws-main`,"aria-label":s(`pws.workspaceMainAria`),children:se?o?.(se,{usageTotals:P[se.name],quotaReport:F[se.name],availableModels:E[se.name]??[],selectedModels:O[se.name]??[],modelsLoading:A,modelsLoadFailed:M})??(0,S.jsxs)(`div`,{className:`pws-detail-placeholder`,children:[(0,S.jsx)(`h3`,{children:jt(se.name)}),(0,S.jsx)(`p`,{className:`muted`,children:s(`pws.detailComingSoon`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>i(null),children:s(`modal.back`)})]}):R.length>0?(0,S.jsx)(nn,{sections:ne,quotaReports:F,usageTotals:P,onSelectProvider:e=>i(e)}):null})]})})}function sn({onAddProvider:e}){let t=U();return(0,S.jsx)(`div`,{className:`pws-empty-root`,children:(0,S.jsxs)(`div`,{className:`pws-empty-hero`,children:[(0,S.jsx)(`div`,{"aria-hidden":`true`,children:(0,S.jsx)(E,{style:{width:64,height:64}})}),(0,S.jsx)(`h2`,{children:t(`pws.connectFirst`)}),(0,S.jsxs)(`div`,{className:`pws-empty-tiles`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`pws-empty-tile`,onClick:()=>e({tier:`free`}),children:[(0,S.jsx)(`span`,{"aria-hidden":`true`,children:(0,S.jsx)(de,{width:18,height:18})}),(0,S.jsx)(`span`,{className:`pws-empty-tile-label`,children:t(`pws.empty.browseFree`)}),(0,S.jsx)(`span`,{className:`pws-empty-tile-desc muted`,children:t(`pws.empty.browseFreeDesc`)})]}),(0,S.jsxs)(`button`,{type:`button`,className:`pws-empty-tile`,onClick:()=>e({tier:`accounts`}),children:[(0,S.jsx)(`span`,{"aria-hidden":`true`,children:(0,S.jsx)(oe,{width:18,height:18})}),(0,S.jsx)(`span`,{className:`pws-empty-tile-label`,children:t(`pws.empty.connectAccount`)}),(0,S.jsx)(`span`,{className:`pws-empty-tile-desc muted`,children:t(`pws.empty.connectAccountDesc`)})]}),(0,S.jsxs)(`button`,{type:`button`,className:`pws-empty-tile`,onClick:()=>e({custom:!0}),children:[(0,S.jsx)(`span`,{"aria-hidden":`true`,children:(0,S.jsx)(ae,{width:18,height:18})}),(0,S.jsx)(`span`,{className:`pws-empty-tile-label`,children:t(`pws.empty.addEndpoint`)}),(0,S.jsx)(`span`,{className:`pws-empty-tile-desc muted`,children:t(`pws.empty.addEndpointDesc`)})]})]})]})})}function cn(e){if(et(e.name,e))return`codex-accounts`;let t=(e.authMode??``).toLowerCase();if(t===`forward`||t===`local`||ht(e))return null;if(t===`oauth`)return`oauth-accounts`;let n=e.hasApiKey===!0;return!(t===`key`||n||t===``)||e.keyOptional===!0&&!n?null:`api-keys`}function ln(e,t,n){let r=t.email?.trim();if(r)return r;let i=e.findIndex(e=>e.id===t.id);return n(`pws.accountOrdinal`,{count:String(i>=0?i+1:1)})}function un({item:e,usageTotals:t,quotaReport:n,oauthEmail:r,onEditSettings:i,onViewUsage:a,onUpdateProvider:o}){let s=U(),{locale:c}=H(),l=wt(s),u=at(e),d=s(u===`ready`?`pws.status.connected`:u===`needs-setup`?`pws.status.needsSetup`:`prov.disabledBadge`),f=t?.requests,p=t?.totalTokens,m=Rt(n);return(0,S.jsxs)(`div`,{className:`pws-overview-layout`,children:[(0,S.jsxs)(`div`,{className:`pws-overview-main`,children:[(0,S.jsxs)(`section`,{className:`pws-section`,"aria-label":s(`pws.connection`),children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:s(`pws.connection`)}),(0,S.jsxs)(`dl`,{className:`pws-kv`,children:[(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`dash.status`)}),(0,S.jsxs)(`dd`,{className:u===`ready`?`pws-status-ok`:`pws-status-warn`,children:[u===`ready`?(0,S.jsx)(M,{style:{width:13,height:13},"aria-hidden":`true`}):(0,S.jsx)(I,{style:{width:13,height:13},"aria-hidden":`true`}),d]})]}),(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`modal.baseUrl`)}),(0,S.jsx)(`dd`,{children:(0,S.jsx)(`code`,{children:e.baseUrl?.trim()?e.baseUrl:`—`})})]}),(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`pws.cell.auth`)}),(0,S.jsx)(`dd`,{children:r?`${Pt(e,s)} · ${r}`:Pt(e,s)})]}),(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`modal.defaultModel`)}),(0,S.jsx)(`dd`,{children:e.defaultModel??(0,S.jsx)(`span`,{className:`muted`,children:`—`})})]}),e.note&&(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`pws.cell.note`)}),(0,S.jsx)(`dd`,{className:`muted`,children:e.note})]})]}),i&&(0,S.jsx)(`button`,{type:`button`,className:`link-btn pws-edit-settings-link`,onClick:i,children:s(`pws.editSettings`)})]}),(0,S.jsxs)(`section`,{className:`pws-section`,"aria-label":s(`pws.authSummary`),children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:s(`pws.authSummary`)}),(0,S.jsxs)(`div`,{className:`pws-auth-summary`,children:[(0,S.jsx)(`span`,{className:`pws-auth-dot`}),(0,S.jsx)(`span`,{children:e.authMode===`forward`?s(`pws.passthrough`):e.authMode===`oauth`?r?s(`pws.loggedInAs`,{email:r}):s(`pws.notLoggedIn`):e.hasApiKey?s(`pws.apiKeyConfigured`):Pt(e,s)})]})]})]}),(0,S.jsxs)(`aside`,{className:`pws-overview-sidebar`,children:[(0,S.jsxs)(`section`,{className:`pws-section`,"aria-label":s(`pws.statsAria`),children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:s(`pws.statsTitle`)}),(0,S.jsxs)(`dl`,{className:`pws-kv`,children:[typeof f==`number`&&(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`pws.stats.totalRequests`)}),(0,S.jsx)(`dd`,{className:`pws-kv-mono`,children:Tt(f,c)})]}),typeof p==`number`&&(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`pws.stats.totalTokens`)}),(0,S.jsx)(`dd`,{className:`pws-kv-mono`,children:Et(p,c)})]}),n&&(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:s(`pws.stats.quotaUpdated`)}),(0,S.jsx)(`dd`,{className:`pws-kv-mono`,title:n.source?zt(n.source):void 0,children:Ct(n.updatedAt,l)})]}),typeof f!=`number`&&typeof p!=`number`&&!n&&(0,S.jsx)(`div`,{className:`muted`,children:s(`pws.usageUnavailable`)})]}),a&&(0,S.jsxs)(`button`,{type:`button`,className:`link-btn pws-view-usage-link`,onClick:a,children:[s(`pws.viewUsage`),` →`]}),m&&(0,S.jsx)(`div`,{className:`muted pws-stats-note`,children:s(`pws.stats.quotaTracked`)})]}),(0,S.jsx)(dn,{item:e,onUpdateProvider:o})]})]})}function dn({item:e,onUpdateProvider:t}){let n=U(),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(!1),l=(0,_.useCallback)(async()=>{if(s||!t)return;let n=a.trim();if(n===(e.note??``)){i(!1);return}c(!0),await t(e.name,{note:n||void 0}),c(!1),i(!1)},[a,e.name,e.note,t,s]);return r?(0,S.jsxs)(`section`,{className:`pws-section pws-notes-section`,"aria-label":n(`pws.notes`),children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:n(`pws.notes`)}),(0,S.jsx)(`textarea`,{className:`pws-notes-textarea`,value:a,onChange:e=>o(e.target.value),onBlur:()=>void l(),onKeyDown:t=>{t.key===`Escape`&&(o(e.note??``),i(!1))},placeholder:n(`pws.notePlaceholder`),autoFocus:!0,rows:3,disabled:s})]}):(0,S.jsxs)(`section`,{className:`pws-section pws-notes-section`,"aria-label":n(`pws.notes`),children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:n(`pws.notes`)}),(0,S.jsx)(`button`,{type:`button`,className:`pws-notes-display`,onClick:()=>{t&&(o(e.note??``),i(!0))},disabled:!t,children:e.note||(0,S.jsx)(`span`,{className:`muted`,children:n(`pws.notePlaceholder`)})})]})}var fn=m();function pn(e,t,n){let r=Array(e);return new Proxy(r,{get(r,i,a){if(typeof i==`string`){let a=i.charCodeAt(0);if(a>=48&&a<=57){let a=+i;if(Number.isInteger(a)&&a>=0&&a<e){let e=r[a];if(!e){let i=t[a*2];e=r[a]={index:a,key:n(a),start:i,size:t[a*2+1],end:i+t[a*2+1],lane:0}}return e}}if(i===`length`)return e}return Reflect.get(r,i,a)}})}function mn(e,t,n){let r=n.initialDeps??[],i,a=!0;function o(){let o=e();return o.length!==r.length||o.some((e,t)=>r[t]!==e)?(r=o,i=t(...o),n?.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1,i):i}return o.updateDeps=e=>{r=e},o}function hn(e,t){if(e===void 0)throw Error(`Unexpected undefined${t?`: ${t}`:``}`);return e}var gn=(e,t)=>Math.abs(e-t)<1.01,_n=(e,t,n)=>{let r;return function(...i){e.clearTimeout(r),r=e.setTimeout(()=>t.apply(this,i),n)}},vn,yn=()=>{if(vn!==void 0)return vn;if(typeof navigator>`u`)return vn=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return vn=!0;let e=navigator.maxTouchPoints;return vn=navigator.platform===`MacIntel`&&e!==void 0&&e>0},bn=e=>{let{offsetWidth:t,offsetHeight:n}=e;return{width:t,height:n}},xn=e=>e,Sn=e=>{let t=Math.max(e.startIndex-e.overscan,0),n=Math.min(e.endIndex+e.overscan,e.count-1)-t+1,r=Array(n);for(let e=0;e<n;e++)r[e]=t+e;return r},Cn=(e,t)=>{let n=e.scrollElement;if(!n)return;let r=e.targetWindow;if(!r)return;let i=e=>{let{width:n,height:r}=e;t({width:Math.round(n),height:Math.round(r)})};if(i(bn(n)),!r.ResizeObserver)return()=>{};let a=new r.ResizeObserver(t=>{let r=()=>{let e=t[0];if(e?.borderBoxSize){let t=e.borderBoxSize[0];if(t){i({width:t.inlineSize,height:t.blockSize});return}}i(bn(n))};e.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(r):r()});return a.observe(n,{box:`border-box`}),()=>{a.unobserve(n)}},wn={passive:!0},Tn=typeof window>`u`?!0:`onscrollend`in window,En=(e,t,n)=>{let r=e.scrollElement;if(!r)return;let i=e.targetWindow;if(!i)return;let a=e.options.useScrollendEvent&&Tn,o=0,s=a?null:_n(i,()=>t(o,!1),e.options.isScrollingResetDelay),c=e=>()=>{o=n(r),s?.(),t(o,e)},l=c(!0),u=c(!1);return r.addEventListener(`scroll`,l,wn),a&&r.addEventListener(`scrollend`,u,wn),()=>{r.removeEventListener(`scroll`,l),a&&r.removeEventListener(`scrollend`,u)}},Dn=(e,t)=>En(e,t,t=>{let{horizontal:n,isRtl:r}=e.options;return n?t.scrollLeft*(r&&-1||1):t.scrollTop}),On=(e,t,n)=>{if(n.options.useCachedMeasurements){let t=n.indexFromElement(e),r=n.options.getItemKey(t);return n.itemSizeCache.get(r)??n.options.estimateSize(t)}if(t?.borderBoxSize){let e=t.borderBoxSize[0];if(e)return Math.round(e[n.options.horizontal?`inlineSize`:`blockSize`])}if(!t){let t=n.indexFromElement(e),r=n.options.getItemKey(t),i=n.itemSizeCache.get(r);if(i!==void 0)return i}return e[n.options.horizontal?`offsetWidth`:`offsetHeight`]},kn=(e,{adjustments:t=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)?.scrollTo)==null||a.call(i,{[r.options.horizontal?`left`:`top`]:e+t,behavior:n})},An=class{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var e;return((e=this.targetWindow?.performance)?.now)?.call(e)??Date.now()},this.observer=(()=>{let e=null,t=()=>e||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:e=new this.targetWindow.ResizeObserver(e=>{e.forEach(e=>{let t=()=>{let t=e.target,n=this.indexFromElement(t);if(!t.isConnected){this.observer.unobserve(t);for(let[e,n]of this.elementsCache)if(n===t){this.elementsCache.delete(e);break}return}this.shouldMeasureDuringScroll(n)&&this.resizeItem(n,this.options.measureElement(t,e,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(t):t()})}));return{disconnect:()=>{var n;(n=t())==null||n.disconnect(),e=null},observe:e=>t()?.observe(e,{box:`border-box`}),unobserve:e=>t()?.unobserve(e)}})(),this.range=null,this.setOptions=e=>{let t={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:xn,rangeExtractor:Sn,onChange:()=>{},measureElement:On,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:`data-index`,initialMeasurementsCache:[],lanes:1,anchorTo:`start`,followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:`estimate`,useCachedMeasurements:!1};for(let n in e){let r=e[n];r!==void 0&&(t[n]=r)}let n=this.options,r=null,i=null,a=!1;if(n!==void 0&&n.enabled&&t.enabled&&t.anchorTo===`end`&&this.scrollElement!==null){let e=n.count,o=t.count,s=this.getMeasurements(),c=e>0?s[0]?.key??n.getItemKey(0):null,l=e>0?s[e-1]?.key??n.getItemKey(e-1):null;if(o!==e||e>0&&o>0&&(t.getItemKey(0)!==c||t.getItemKey(o-1)!==l)){a=!0;let c=e>0?this.getVirtualItemForOffset(this.getScrollOffset())??s[0]:null;c&&(r=[c.key,this.getScrollOffset()-c.start]);let u=t.followOnAppend===!0?`auto`:t.followOnAppend||null;u&&o>e&&this.isAtEnd(n.scrollEndThreshold)&&(e===0||t.getItemKey(o-1)!==l)&&(i=u)}}this.options=t,a&&(this.pendingMin=0,this.itemSizeCacheVersion++);let o=!1,s=0;if(r&&this.scrollOffset!==null){let[e,t]=r,n=this.getMeasurements(),{count:i,getItemKey:a}=this.options,c=0;for(;c<i&&a(c)!==e;)c++;if(c<i){let e=n[c];if(e){let n=e.start+t;n!==this.scrollOffset&&(s=n-this.scrollOffset,this.scrollOffset=n,o=!0)}}}(o||i)&&(this.pendingScrollAnchor=[o?r[0]:null,o?r[1]:0,i,s])},this.notify=e=>{var t,n;(n=(t=this.options).onChange)==null||n.call(t,this,e)},this.maybeNotify=mn(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),e=>{this.notify(e)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(e=>e()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{let e=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==e){if(this.cleanup(),!e){this.maybeNotify();return}if(this.scrollElement=e,this.scrollElement&&`ownerDocument`in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=this.scrollElement?.window??null,this.elementsCache.forEach(e=>{this.observer.observe(e)}),this.unsubs.push(this.options.observeElementRect(this,e=>{this.scrollRect=e,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(e,t)=>{if(t&&this._intendedScrollOffset===null&&e===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(e-this._intendedScrollOffset)<1.5&&(e=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;let n=this.getScrollOffset();this.scrollDirection=t?n===e?this.scrollDirection:n<e?`forward`:`backward`:null,this.scrollOffset=e,this.isScrolling=t,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),`addEventListener`in this.scrollElement){let e=this.scrollElement,t=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},n=()=>{this._iosTouching=!1,!(!yn()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};e.addEventListener(`touchstart`,t,wn),e.addEventListener(`touchend`,n,wn),this.unsubs.push(()=>{e.removeEventListener(`touchstart`,t),e.removeEventListener(`touchend`,n),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}let t=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,t&&this.scrollElement&&this.options.enabled){let[e,n,r,i]=t;e!==null&&!r&&(yn()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?i!==0&&(this._iosDeferredAdjustment+=i):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),r&&this.scrollToEnd({behavior:r})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;let e=this.getScrollOffset(),t=this.getMaxScrollOffset();if(e<0||e>t)return;let n=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(e,{adjustments:this.scrollAdjustments+=n,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?`width`:`height`]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset==`function`?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(e,t)=>{let n=new Map,r=new Map;for(let i=t-1;i>=0;i--){let t=e[i];if(n.has(t.lane))continue;let a=r.get(t.lane);if(a==null||t.end>a.end?r.set(t.lane,t):t.end<a.end&&n.set(t.lane,!0),n.size===this.options.lanes)break}return r.size===this.options.lanes?Array.from(r.values()).sort((e,t)=>e.end===t.end?e.index-t.index:e.end-t.end)[0]:void 0},this.getMeasurementOptions=mn(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(e,t,n,r,i,a,o)=>(this.prevLanes!==void 0&&this.prevLanes!==a&&(this.lanesChangedFlag=!0),this.prevLanes=a,this.pendingMin=null,{count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o}),{key:!1}),this.getMeasurements=mn(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:e,paddingStart:t,scrollMargin:n,getItemKey:r,enabled:i,lanes:a,laneAssignmentMode:o},s)=>{let c=this.itemSizeCache;if(!i)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>e)for(let t of this.laneAssignments.keys())t>=e&&this.laneAssignments.delete(t);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(e=>{this.itemSizeCache.set(e.key,e.size)}));let l=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===e&&(this.lanesSettling=!1),a===1){let i=this.options.gap,a=e*2,o=this._flatMeasurements;if(!o||o.length<a){let e=new Float64Array(a);o&&l>0&&e.set(o.subarray(0,l*2)),o=e,this._flatMeasurements=o}let s;if(l===0)s=t+n;else{let e=l-1;s=o[e*2]+o[e*2+1]+i}for(let t=l;t<e;t++){let e=r(t),n=c.get(e),a=typeof n==`number`?n:this.options.estimateSize(t);o[t*2]=s,o[t*2+1]=a,s+=a+i}let u=pn(e,o,r);return this.measurementsCache=u,u}let u=this.measurementsCache.slice(0,l),d=Array(a).fill(void 0);for(let e=0;e<l;e++){let t=u[e];t&&(d[t.lane]=e)}for(let i=l;i<e;i++){let e=r(i),a=this.laneAssignments.get(i),s,l,f=o===`estimate`||c.has(e);if(a!==void 0&&this.options.lanes>1){s=a;let e=d[s],r=e===void 0?void 0:u[e];l=r?r.end+this.options.gap:t+n}else{let e=this.options.lanes===1?u[i-1]:this.getFurthestMeasurement(u,i);l=e?e.end+this.options.gap:t+n,s=e?e.lane:i%this.options.lanes,this.options.lanes>1&&f&&this.laneAssignments.set(i,s)}let p=c.get(e),m=typeof p==`number`?p:this.options.estimateSize(i),h=l+m;u[i]={index:i,start:l,size:m,end:h,key:e,lane:s},d[s]=i}return this.measurementsCache=u,u},{key:!1,debug:()=>this.options.debug}),this.calculateRange=mn(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(e,t,n,r)=>e.length===0||t===0?(this.range=null,null):(this.range=Nn(e,t,n,r,r===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=mn(()=>{let e=null,t=null,n=this.calculateRange();return n&&(e=n.startIndex,t=n.endIndex),this.maybeNotify.updateDeps([this.isScrolling,e,t]),[this.options.rangeExtractor,this.options.overscan,this.options.count,e,t]},(e,t,n,r,i)=>r===null||i===null?[]:e({startIndex:r,endIndex:i,overscan:t,count:n}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=e=>{let t=this.options.indexAttribute,n=e.getAttribute(t);return n?parseInt(n,10):(console.warn(`Missing attribute name '${t}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=e=>{if(!this.scrollState||this.scrollState.behavior!==`smooth`)return!0;let t=this.scrollState.index??this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)?.index;if(t!==void 0&&this.range){let n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),r=Math.max(0,t-n),i=Math.min(this.options.count-1,t+n);return e>=r&&e<=i}return!0},this.measureElement=e=>{if(!e){this.elementsCache.forEach((e,t)=>{e.isConnected||(this.observer.unobserve(e),this.elementsCache.delete(t))});return}let t=this.indexFromElement(e),n=this.options.getItemKey(t),r=this.elementsCache.get(n);r!==e&&(r&&this.observer.unobserve(r),this.observer.observe(e),this.elementsCache.set(n,e)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(t)&&this.resizeItem(t,this.options.measureElement(e,void 0,this))},this.resizeItem=(e,t)=>{if(e<0||e>=this.options.count)return;let n,r,i,a=this._flatMeasurements;if(this.options.lanes===1&&a!==null)i=this.options.getItemKey(e),r=a[e*2],n=a[e*2+1];else{let t=this.measurementsCache[e];if(!t)return;i=t.key,r=t.start,n=t.size}let o=t-(this.itemSizeCache.get(i)??n);if(o!==0){let a=this.options.anchorTo===`end`&&this.scrollState?.behavior!==`smooth`&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,s=a?this.getTotalSize():0,c=this.scrollState?.behavior!==`smooth`&&(this.shouldAdjustScrollPositionOnItemSizeChange===void 0?r<this.getScrollOffset()+this.scrollAdjustments&&(!this.itemSizeCache.has(i)||this.scrollDirection!==`backward`):this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[e]??{index:e,key:i,start:r,size:n,end:r+n,lane:0},o,this));(this.pendingMin===null||e<this.pendingMin)&&(this.pendingMin=e),this.itemSizeCache.set(i,t),this.itemSizeCacheVersion++,a?this.applyScrollAdjustment(this.getTotalSize()-s):c&&this.applyScrollAdjustment(o),this.notify(!1)}},this.getVirtualItems=mn(()=>[this.getVirtualIndexes(),this.getMeasurements()],(e,t)=>{let n=[];for(let r=0,i=e.length;r<i;r++){let i=t[e[r]];n.push(i)}return n},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=e=>{let t=this.getMeasurements();if(t.length===0)return;let n=this._flatMeasurements,r=this.options.lanes===1&&n!=null;return hn(t[jn(0,t.length-1,r?e=>n[e*2]:e=>hn(t[e]).start,e)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if(`scrollHeight`in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{let e=this.scrollElement.document.documentElement;return this.options.horizontal?e.scrollWidth-this.scrollElement.innerWidth:e.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(e=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=e,this.getOffsetForAlignment=(e,t,n=0)=>{if(!this.scrollElement)return 0;let r=this.getSize(),i=this.getScrollOffset();t===`auto`&&(t=e>=i+r?`end`:`start`),t===`center`?e+=(n-r)/2:t===`end`&&(e-=r);let a=this.getMaxScrollOffset();return Math.max(Math.min(a,e),0)},this.getOffsetForIndex=(e,t=`auto`)=>{e=Math.max(0,Math.min(e,this.options.count-1));let n=this.getSize(),r=this.getScrollOffset(),i=this.measurementsCache[e];if(!i)return;if(t===`auto`)if(i.end>=r+n-this.options.scrollPaddingEnd)t=`end`;else if(i.start<=r+this.options.scrollPaddingStart)t=`start`;else return[r,t];if(t===`end`&&e===this.options.count-1)return[this.getMaxScrollOffset(),t];let a=t===`end`?i.end+this.options.scrollPaddingEnd:i.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(a,t,i.size),t]},this.scrollToOffset=(e,{align:t=`start`,behavior:n=`auto`}={})=>{let r=this.getOffsetForAlignment(e,t),i=this.now();this.scrollState={index:null,align:t,behavior:n,startedAt:i,lastTargetOffset:r,stableFrames:0},this._scrollToOffset(r,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollToIndex=(e,{align:t=`auto`,behavior:n=`auto`}={})=>{e=Math.max(0,Math.min(e,this.options.count-1));let r=this.getOffsetForIndex(e,t);if(!r)return;let[i,a]=r,o=this.now();this.scrollState={index:e,align:a,behavior:n,startedAt:o,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:n}),this.scheduleScrollReconcile()},this.scrollBy=(e,{behavior:t=`auto`}={})=>{let n=this.getScrollOffset()+e,r=this.now();this.scrollState={index:null,align:`start`,behavior:t,startedAt:r,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:t}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:e=`auto`}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:`end`,behavior:e});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:e})},this.getTotalSize=()=>{let e=this.getMeasurements(),t;if(e.length===0)t=this.options.paddingStart;else if(this.options.lanes===1){let n=e.length-1,r=this._flatMeasurements;t=r==null?e[n]?.end??0:r[n*2]+r[n*2+1]}else{let n=Array(this.options.lanes).fill(null),r=e.length-1;for(;r>=0&&n.some(e=>e===null);){let t=e[r];n[t.lane]===null&&(n[t.lane]=t.end),r--}t=Math.max(...n.filter(e=>e!==null))}return Math.max(t-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{let e=[];if(this.itemSizeCache.size===0)return e;let t=this.getMeasurements();for(let n of t)n&&this.itemSizeCache.has(n.key)&&e.push({index:n.index,key:n.key,start:n.start,size:n.size,end:n.end,lane:n.lane});return e},this._scrollToOffset=(e,{adjustments:t,behavior:n})=>{this._intendedScrollOffset=e+(t??0),this.options.scrollToFn(e,{behavior:n,adjustments:t},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(e)}applyScrollAdjustment(e,t){e!==0&&(yn()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?this._iosDeferredAdjustment+=e:(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=e,behavior:t}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollAdjustments=0)))}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId??=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()})}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}let e=this.scrollState.index==null?void 0:this.getOffsetForIndex(this.scrollState.index,this.scrollState.align),t=e?e[0]:this.scrollState.lastTargetOffset,n=t!==this.scrollState.lastTargetOffset;if(!n&&gn(t,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=1){this.getScrollOffset()!==t&&this._scrollToOffset(t,{adjustments:void 0,behavior:`auto`}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,n){let e=this.getSize()||600,n=Math.abs(t-this.getScrollOffset()),r=this.scrollState.behavior===`smooth`&&n>e;this.scrollState.lastTargetOffset=t,r||(this.scrollState.behavior=`auto`),this._scrollToOffset(t,{adjustments:void 0,behavior:r?`smooth`:`auto`})}this.scheduleScrollReconcile()}},jn=(e,t,n,r)=>{for(;e<=t;){let i=(e+t)/2|0,a=n(i);if(a<r)e=i+1;else if(a>r)t=i-1;else return i}return e>0?e-1:0};function Mn(e,t,n){let r=0;for(;r<=t;){let i=(r+t)/2|0,a=e[i*2];if(a<n)r=i+1;else if(a>n)t=i-1;else return i}return r>0?r-1:0}function Nn(e,t,n,r,i){let a=e.length-1;if(e.length<=r)return{startIndex:0,endIndex:a};if(r===1&&i!==null){let e=Mn(i,a,n),r=e,o=n+t;for(;r<a&&i[r*2]+i[r*2+1]<o;)r++;return{startIndex:e,endIndex:r}}let o=jn(0,a,t=>e[t].start,n),s=o;if(r===1)for(;s<a&&e[s].end<n+t;)s++;else if(r>1){let i=Array(r).fill(0);for(;s<a&&i.some(e=>e<n+t);){let t=e[s];i[t.lane]=t.end,s++}let c=Array(r).fill(n+t);for(;o>=0&&c.some(e=>e>=n);){let t=e[o];c[t.lane]=t.start,o--}o=Math.max(0,o-o%r),s=Math.min(a,s+(r-1-s%r))}return{startIndex:o,endIndex:s}}var Pn=typeof document<`u`?_.useLayoutEffect:_.useEffect;function Fn({useFlushSync:e=!0,directDomUpdates:t=!1,directDomUpdatesMode:n=`transform`,...r}){let i=_.useReducer(e=>e+1,0)[1],a=_.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});a.current.enabled=t,a.current.mode=n;let o=e=>{let t=a.current;if(!t.enabled||!t.container)return;let n=e.getTotalSize();if(n!==t.lastSize){t.lastSize=n;let r=e.options.horizontal?`width`:`height`;t.container.style[r]=`${n}px`}let r=!!e.options.horizontal,i=t.mode===`transform`,o=r?`left`:`top`,s=e.options.scrollMargin,c=e.getVirtualItems();for(let n of c){let a=n.start-s,c=e.elementsCache.get(n.key);c&&t.lastPositions.get(c)!==a&&(t.lastPositions.set(c,a),i?c.style.transform=r?`translate3d(${a}px, 0, 0)`:`translate3d(0, ${a}px, 0)`:c.style[o]=`${a}px`)}},s={...r,onChange:(t,n)=>{var s;let c=a.current,l=!0;if(c.enabled){o(t);let e=t.range,n=c.prevRange;l=!n||n.isScrolling!==t.isScrolling||n.startIndex!==e?.startIndex||n.endIndex!==e?.endIndex,l&&(c.prevRange=e?{startIndex:e.startIndex,endIndex:e.endIndex,isScrolling:t.isScrolling}:null)}l&&(e&&n?(0,fn.flushSync)(i):i()),(s=r.onChange)==null||s.call(r,t,n)}},[c]=_.useState(()=>{let e=new An(s);return Object.assign(e,{containerRef:t=>{let n=a.current;if(n.container=t,n.lastSize=null,t&&n.enabled){let r=e.getTotalSize();n.lastSize=r;let i=e.options.horizontal?`width`:`height`;t.style[i]=`${r}px`}}})});return c.setOptions(s),Pn(()=>c._didMount(),[]),Pn(()=>c._willUpdate()),Pn(()=>{o(c)}),c}function In(e){return Fn({observeElementRect:Cn,observeElementOffset:Dn,scrollToFn:kn,...e})}function Ln({item:e,availableModels:t,selectedModels:n,modelsLoading:r=!1,modelsLoadFailed:i=!1,onRetryModels:a}){let o=U(),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(null),d=(0,_.useRef)(null),f=(0,_.useMemo)(()=>new Set(n),[n]),p=(0,_.useMemo)(()=>Bt(t,e.defaultModel,s),[t,e.defaultModel,s]),m=p.length>40,h=In({count:m?p.length:0,getScrollElement:()=>d.current,estimateSize:()=>36,overscan:12}),g=async e=>{try{await navigator.clipboard.writeText(e),u(e),window.setTimeout(()=>u(t=>t===e?null:t),1200)}catch{}},v=(t,n)=>{let r=t===e.defaultModel,i=f.has(t);return(0,S.jsxs)(`div`,{className:`pws-model-row`,style:n,children:[(0,S.jsx)(`span`,{className:`pws-model-id`,title:t,children:t}),(0,S.jsxs)(`span`,{className:`pws-model-meta`,children:[r?(0,S.jsx)(`span`,{className:`pws-model-flag`,children:o(`prov.defaultBadge`)}):null,i?(0,S.jsx)(`span`,{className:`pws-model-flag pws-model-flag--selected`,children:o(`pws.selected`)}):null,(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>{g(t)},"aria-label":o(`pws.copyModelId`),children:o(l===t?`pws.modelCopied`:`pws.copyModelId`)})]})]},t)},y=t.length===0&&!e.defaultModel;return(0,S.jsxs)(`div`,{className:`pws-section`,children:[(0,S.jsxs)(`div`,{className:`pws-section-head`,children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:o(`pws.tab.models`)}),p.length>0&&(0,S.jsx)(`span`,{className:`muted`,children:o(`pws.modelsAvailable`,{count:p.length})})]}),!y&&(0,S.jsx)(`input`,{type:`search`,className:`input pws-model-search`,placeholder:o(`pws.modelSearchPlaceholder`),value:s,onChange:e=>c(e.target.value),"aria-label":o(`pws.modelSearchPlaceholder`)}),r&&y?(0,S.jsx)(`p`,{className:`muted`,role:`status`,children:o(`pws.modelsLoading`)}):i&&y?(0,S.jsxs)(`div`,{role:`alert`,className:`pws-inline-error`,children:[(0,S.jsx)(`span`,{children:o(`pws.modelsLoadFailed`)}),a&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:a,children:o(`pws.retry`)})]}):y?(0,S.jsx)(`p`,{className:`muted`,children:o(`pws.noModels`)}):p.length===0?(0,S.jsx)(`p`,{className:`muted`,role:`status`,children:o(`pws.noModelMatch`)}):m?(0,S.jsx)(`div`,{ref:d,className:`pws-model-list pws-model-list--virtual`,children:(0,S.jsx)(`div`,{style:{height:h.getTotalSize(),position:`relative`},children:h.getVirtualItems().map(e=>v(p[e.index],{position:`absolute`,top:0,left:0,width:`100%`,height:e.size,transform:`translateY(${String(e.start)}px)`}))})}):(0,S.jsx)(`div`,{className:`pws-model-list`,children:p.map(e=>v(e))})]})}function Rn({item:e,usageTotals:t,quotaReport:n}){let r=U(),{locale:i}=H(),a=wt(r),o=t?.requests!==void 0,s=Rt(n);return(0,S.jsxs)(`div`,{className:`pws-section`,children:[(0,S.jsxs)(`div`,{className:`pws-usage-block`,children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:r(`pws.usageLast30d`)}),o?(0,S.jsxs)(`div`,{className:`pws-usage-metrics`,role:`group`,"aria-label":r(`pws.usageLast30d`),children:[(0,S.jsxs)(`div`,{className:`pws-usage-metric`,children:[(0,S.jsx)(`span`,{className:`pws-usage-metric-value`,children:Tt(t?.requests,i)}),(0,S.jsx)(`span`,{className:`muted`,children:r(`pws.metricRequests`)})]}),(0,S.jsxs)(`div`,{className:`pws-usage-metric`,children:[(0,S.jsx)(`span`,{className:`pws-usage-metric-value`,children:Et(t?.totalTokens,i)}),(0,S.jsx)(`span`,{className:`muted`,children:r(`pws.metricTokens`)})]})]}):(0,S.jsx)(`p`,{className:`muted`,children:r(`pws.usageUnavailable`)})]}),(0,S.jsxs)(`div`,{className:`pws-usage-block`,children:[(0,S.jsx)(`h3`,{className:`pws-section-title`,children:r(`pws.rateLimits`)}),s?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Zt,{quota:s,plan:null,threshold:80,t:r,layout:`stacked`}),(0,S.jsxs)(`dl`,{className:`pws-kv pws-usage-meta`,children:[n?.source?.trim()&&(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:r(`pws.stats.source`)}),(0,S.jsx)(`dd`,{children:zt(n.source)})]}),(0,S.jsxs)(`div`,{className:`pws-kv-row`,children:[(0,S.jsx)(`dt`,{children:r(`pws.stats.quotaUpdated`)}),(0,S.jsx)(`dd`,{children:Ct(n?.updatedAt,a)})]})]})]}):(0,S.jsx)(`p`,{className:`muted`,children:r(`pws.quotaUnavailable`)})]})]})}function zn({apiBase:e,onClose:t,onAdded:n}){let r=U(),i=(0,_.useRef)(!0),a=(0,_.useRef)(null),o=(0,_.useRef)(null),s=(0,_.useRef)(null);(0,_.useEffect)(()=>()=>{i.current=!1,a.current&&=(clearInterval(a.current),null),o.current&&=(clearTimeout(o.current),null)},[]);let[c,l]=(0,_.useState)(`pick`),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(!1),y=(0,_.useRef)(null),b=(0,_.useRef)(null),x=(0,_.useCallback)(()=>{a.current&&=(clearInterval(a.current),null),o.current&&=(clearTimeout(o.current),null)},[]),C=(0,_.useCallback)(async()=>{let t=s.current;s.current=null,h(``),x(),t&&await fetch(`${e}/api/codex-auth/login/cancel`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({flowId:t})}).catch(()=>{})},[e,x]),w=(0,_.useCallback)(()=>{c===`oauth-waiting`&&C(),t()},[c,t,C]);return(0,_.useEffect)(()=>{y.current=document.activeElement;let e=b.current;if(e){let t=e.querySelector(`input:not([disabled]), button:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1'])`);t&&t.focus()}return()=>{y.current?.focus()}},[]),(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&w()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w]),(0,S.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":r(`codexAuth.addTitle`),className:`modal-overlay`,onClick:w,children:(0,S.jsxs)(`div`,{ref:b,className:`modal-card`,onClick:e=>e.stopPropagation(),style:{maxWidth:440},children:[c===`pick`&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`h3`,{style:{marginBottom:4},children:r(`codexAuth.addTitle`)}),(0,S.jsx)(`p`,{className:`modal-desc`,children:r(`codexAuth.addPickDesc`)}),(0,S.jsx)(`label`,{className:`field-label`,children:r(`codexAuth.addIdLabel`)}),(0,S.jsx)(`input`,{className:`input`,placeholder:r(`codexAuth.addIdPlaceholder`),value:u,onChange:e=>d(e.target.value),style:{marginBottom:12}}),(0,S.jsx)(`button`,{className:`list-row`,onClick:async()=>{p(``);try{let c=u.trim(),d=await fetch(`${e}/api/codex-auth/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(c?{id:c}:{})}),f=await d.json();if(d.status===409){p(r(`codexAuth.oauthAlreadyInProgress`));return}if(f.url){s.current=f.flowId??null,h(f.url),l(`oauth-waiting`),x();let u=f.flowId??``,d=u?`${e}/api/codex-auth/login-status?flowId=${encodeURIComponent(u)}${c?`&accountId=${encodeURIComponent(c)}`:``}`:`${e}/api/codex-auth/login-status`;a.current=setInterval(async()=>{try{let e=await fetch(d).then(e=>e.json());e.status===`done`?(x(),s.current=null,n(),t()):(e.status===`error`||e.status===`expired`)&&(x(),s.current=null,i.current&&(l(`pick`),p(e.error??`Login failed`)))}catch{}},2e3),o.current=setTimeout(()=>{a.current&&(C(),i.current&&(l(`pick`),p(r(`modal.loginTimeout`))))},3e5)}f.error&&!f.url&&p(f.error)}catch(e){p(String(e))}},style:{marginBottom:8},children:(0,S.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[(0,S.jsx)(de,{width:20}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`title`,children:r(`codexAuth.oauthLogin`)}),(0,S.jsx)(`div`,{className:`sub`,children:r(`codexAuth.oauthDesc`)})]})]})}),f&&(0,S.jsx)(`div`,{className:`notice notice-err`,style:{marginTop:8},children:f}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:w,style:{width:`100%`},children:r(`codexAuth.cancel`)})]}),c===`oauth-waiting`&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`h3`,{style:{marginBottom:4},children:r(`codexAuth.oauthLogin`)}),(0,S.jsx)(`p`,{className:`modal-desc`,children:r(`codexAuth.oauthWaiting`)}),(0,S.jsxs)(`button`,{className:`btn btn-ghost`,onClick:async()=>{if(m)try{if(navigator.clipboard?.writeText)await navigator.clipboard.writeText(m);else{let e=document.createElement(`textarea`);e.value=m,e.style.position=`fixed`,e.style.opacity=`0`,document.body.appendChild(e),e.select(),document.execCommand(`copy`),document.body.removeChild(e)}v(!0),setTimeout(()=>{i.current&&v(!1)},2500)}catch{p(r(`codexAuth.loginLinkCopyFailed`))}},disabled:!m,style:{width:`100%`,justifyContent:`center`,marginTop:12},children:[(0,S.jsx)(ce,{width:14}),` `,r(g?`codexAuth.loginLinkCopied`:`codexAuth.copyLoginLink`)]}),f&&(0,S.jsx)(`div`,{className:`notice notice-err`,style:{marginTop:12},children:f}),(0,S.jsx)(`div`,{style:{textAlign:`center`,padding:`24px 0`},children:(0,S.jsx)(`span`,{className:`spin`,style:{width:24,height:24}})}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:w,style:{width:`100%`},children:r(`codexAuth.cancel`)})]})]})})}function Bn({apiBase:e,accountModeState:t=null,banner:n=null,embedded:r=!1}){let i=U(),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(80),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(!1),[C,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(!1),[D,O]=(0,_.useState)(!1),[k,A]=(0,_.useState)(null),[j,M]=(0,_.useState)(!1),[F,L]=(0,_.useState)(`loading`),[te,ne]=(0,_.useState)(null),R=(0,_.useRef)(0),z=(0,_.useCallback)(async(t=!1)=>{let n=++R.current;t||L(`loading`);try{let[r,i]=await Promise.all([fetch(`${e}/api/codex-auth/accounts${t?`?refresh=1`:``}`),fetch(`${e}/api/codex-auth/active`)]);if(!r.ok||!i.ok)throw Error(`account load failed`);let[a,s]=await Promise.all([r.json(),i.json()]);return R.current===n?(o(a.accounts??[]),c(s.activeCodexAccountId??null),u(s.autoSwitchThreshold??80),L(`ready`),!0):!1}catch{return R.current===n&&L(`error`),!1}},[e]);(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{z()},0),t=window.setInterval(()=>{z()},3e4);return()=>{window.clearTimeout(e),window.clearInterval(t)}},[z]);let B=async n=>{if(!te){ne(n??`__main__`);try{let r=await fetch(`${e}/api/codex-auth/active`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:n})});if(!r.ok)throw Error(`account switch failed`);let o=(await r.json().catch(()=>({}))).activeCodexAccountId??n;c(o),f(null),await z();let s=o&&o!==`__main__`?a.find(e=>e.id===o)?.email??i(`pws.accountOrdinal`,{count:`1`}):i(`codexAuth.mainAccount`);g(i(t===`direct`?`codexAuth.poolPreparedToast`:`codexAuth.switched`,{email:s})),y(!1),setTimeout(()=>g(``),5e3)}catch{g(i(`codexAuth.switchFailed`)),y(!0),setTimeout(()=>g(``),5e3)}finally{ne(null)}}},re=async t=>{let n=a.find(e=>e.id===t)?.email??i(`pws.accountOrdinal`,{count:`1`});if(window.confirm(i(`codexAuth.removeConfirm`,{id:n})))try{let n=await fetch(`${e}/api/codex-auth/accounts?id=${encodeURIComponent(t)}`,{method:`DELETE`});if(!n.ok)throw Error(String(n.status));await z()}catch{g(i(`codexAuth.removeFailed`)),y(!0),setTimeout(()=>g(``),5e3)}},ie=async()=>{let t=l>0?0:80;await fetch(`${e}/api/codex-auth/auto-switch`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({threshold:t})}),u(t)},ae=async()=>{x(!0);try{g(i(await z(!0)?`codexAuth.quotaRefreshed`:`codexAuth.quotaRefreshFailed`)),setTimeout(()=>g(``),5e3)}finally{x(!1)}},ce=async t=>{w(t),E(!1),A(null),M(!0);try{let n=await fetch(`${e}/api/codex-auth/reset-credits?accountId=${encodeURIComponent(t.id)}`);n.ok&&A(((await n.json()).credits??[]).sort((e,t)=>new Date(e.granted_at).getTime()-new Date(t.granted_at).getTime()))}catch{}finally{M(!1)}},le=async t=>{O(!0);try{let n=await fetch(`${e}/api/codex-auth/reset-credits/consume`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:t})});if(!n.ok){alert(i(`codexAuth.resetError`));return}let r=await n.json();if(r.code===`reset`||r.code===`already_redeemed`){let e=C?.quota?.resetCredits??1;w(null),E(!1),await z(!0),g(i(`codexAuth.resetSuccess`,{remaining:String(Math.max(0,e-1))})),setTimeout(()=>g(``),5e3)}else r.code===`nothing_to_reset`?alert(i(`codexAuth.resetNothingToReset`)):r.code===`no_credit`?alert(i(`codexAuth.resetNoCredit`)):alert(i(`codexAuth.resetError`))}catch{alert(i(`codexAuth.resetError`))}finally{O(!1)}},V=a.find(e=>e.isMain),ue=a.filter(e=>!e.isMain),de=e=>s===e,fe=!s||s===`__main__`,pe={id:`__main__`,email:V?.email??`Codex App`,plan:V?.plan,isMain:!0,hasCredential:!0,quota:V?.quota??null},me=i(t===`direct`?`codexAuth.prepareForPool`:`codexAuth.setAsNext`);return(0,S.jsxs)(`div`,{children:[!r&&(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{className:`page-title`,children:i(`nav.codexAuth`)}),(0,S.jsxs)(`button`,{className:`btn btn-sm btn-ghost`,onClick:ae,disabled:b,children:[(0,S.jsx)(ee,{width:14}),` `,i(b?`codexAuth.refreshingQuota`:`codexAuth.refreshQuota`)]})]}),h&&(0,S.jsx)(W,{tone:v?`err`:`ok`,children:h}),F===`loading`&&a.length===0&&(0,S.jsx)(`div`,{className:`pwi-auth-state`,role:`status`,children:i(`pws.accountsLoading`)}),F===`error`&&(0,S.jsxs)(`div`,{className:`pwi-auth-state pwi-auth-state--error`,role:`alert`,children:[(0,S.jsx)(`span`,{children:i(`codexAuth.loadFailed`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>void z(),children:i(`pws.retryAccounts`)})]}),n,(0,S.jsxs)(`div`,{className:`card ${fe?`card-active`:``}`,style:{marginBottom:12},children:[(0,S.jsxs)(`div`,{className:`card-head`,children:[(0,S.jsx)(`span`,{className:`dot dot-green`}),(0,S.jsx)(`strong`,{children:i(`codexAuth.mainAccount`)}),(0,S.jsxs)(`span`,{className:`card-badges`,children:[V&&(0,S.jsx)(Wn,{t:i,account:{...V,id:`__main__`},onClick:()=>ce({...V,id:`__main__`})}),(0,S.jsx)(`span`,{className:`badge ${fe?`badge-primary`:`badge-muted`}`,children:i(fe?t===`direct`?`codexAuth.poolPrepared`:`codexAuth.nextSession`:`codexAuth.current`)})]}),!fe&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-account-switch`,onClick:()=>f(pe),children:me}),(0,S.jsxs)(`span`,{className:`card-right`,children:[(0,S.jsx)(oe,{width:14}),` `,i(`codexAuth.appLogin`)]})]}),(0,S.jsxs)(`div`,{className:`card-sub`,children:[V?.email??`Codex App login`,V?.plan?` · ${V.plan}`:``]}),V?.quota&&(0,S.jsx)(Zt,{quota:V.quota,plan:V.plan,threshold:l,t:i})]}),(0,S.jsxs)(`div`,{className:`section-sep`,children:[(0,S.jsx)(`span`,{className:`section-label`,children:i(`codexAuth.accountPool`)}),(0,S.jsx)(`div`,{className:`sep-line`}),(0,S.jsxs)(`button`,{className:`btn btn-sm btn-ghost`,onClick:()=>m(!0),children:[(0,S.jsx)(P,{width:14}),` `,i(`codexAuth.add`)]})]}),ue.length===0&&(0,S.jsx)(Ae,{title:i(`codexAuth.noPool`)}),ue.map(e=>(0,S.jsxs)(`div`,{className:`card ${de(e.id)?`card-active`:``}`,style:{marginBottom:8},children:[(0,S.jsxs)(`div`,{className:`card-head`,children:[(0,S.jsx)(`span`,{className:`dot ${e.needsReauth?`dot-amber`:de(e.id)?`dot-blue`:`dot-muted`}`}),(0,S.jsx)(`strong`,{children:e.email}),(0,S.jsxs)(`span`,{className:`card-badges`,children:[e.plan&&(0,S.jsx)(`span`,{className:`badge badge-green`,children:e.plan}),(0,S.jsx)(Wn,{t:i,account:e,onClick:()=>ce(e)}),e.needsReauth&&(0,S.jsx)(`span`,{className:`badge badge-amber`,children:i(`codexAuth.needsReauth`)}),de(e.id)&&!e.needsReauth&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:i(t===`direct`?`codexAuth.poolPrepared`:`codexAuth.nextSession`)})]}),!de(e.id)&&!e.needsReauth&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-account-switch`,onClick:()=>f(e),children:me}),(0,S.jsx)(`button`,{className:`btn-icon btn-icon-danger card-right`,"aria-label":`${i(`common.remove`)} — ${e.email}`,title:`${i(`common.remove`)} — ${e.email}`,onClick:t=>{t.stopPropagation(),re(e.id)},children:(0,S.jsx)(N,{width:14})})]}),e.needsReauth?(0,S.jsx)(`div`,{className:`card-sub faint`,children:i(`codexAuth.tokenExpired`)}):(0,S.jsx)(Zt,{quota:e.quota,plan:e.plan,threshold:l,t:i})]},e.id)),(0,S.jsxs)(`div`,{className:`card card-row`,style:{marginTop:16},children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`strong`,{children:i(`codexAuth.autoSwitch`)}),(0,S.jsx)(`div`,{className:`card-sub`,children:i(`codexAuth.autoSwitchDesc`)})]}),(0,S.jsx)(`button`,{className:`toggle ${l>0?`on`:``}`,onClick:ie,"aria-pressed":l>0,"aria-label":i(`codexAuth.autoSwitch`),title:i(`codexAuth.autoSwitch`),children:(0,S.jsx)(`span`,{className:`toggle-knob`})})]}),d&&(0,S.jsx)(`div`,{className:`modal-overlay`,onClick:()=>f(null),children:(0,S.jsxs)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsx)(`h3`,{children:t===`direct`?i(`codexAuth.preparePoolTitle`):d.id===`__main__`?i(`codexAuth.switchBack`):i(`codexAuth.switchTitle`)}),(0,S.jsx)(`p`,{className:`modal-desc`,children:t===`direct`?i(`codexAuth.preparePoolDesc`):d.id===`__main__`?i(`codexAuth.switchBackDesc`):i(`codexAuth.switchDesc`)}),(0,S.jsxs)(`div`,{className:`card`,style:{margin:`12px 0`},children:[(0,S.jsx)(`strong`,{children:d.id===`__main__`?V?.email:d.email}),d.plan&&(0,S.jsx)(`span`,{className:`badge badge-green`,style:{marginLeft:8},children:d.plan})]}),d.id!==`__main__`&&(0,S.jsxs)(`div`,{className:`notice-warn`,children:[(0,S.jsx)(I,{width:14}),` `,i(`codexAuth.cacheWarning`)]}),(0,S.jsxs)(`div`,{className:`modal-actions`,children:[(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>f(null),children:i(`codexAuth.cancel`)}),(0,S.jsx)(`button`,{className:`btn btn-primary`,disabled:!!te,onClick:()=>B(d.id===`__main__`?`__main__`:d.id),children:i(te?`pws.accountSwitching`:t===`direct`?`codexAuth.prepareForPool`:`codexAuth.setAsNext`)})]})]})}),C&&(0,S.jsx)(`div`,{className:`modal-overlay`,onClick:()=>{w(null),E(!1),A(null)},children:(0,S.jsx)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),children:T?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{style:{textAlign:`center`,padding:`12px 0`},children:[(0,S.jsx)(`div`,{className:`confirm-icon`,children:(0,S.jsx)(I,{width:22})}),(0,S.jsx)(`h3`,{children:i(`codexAuth.confirmResetTitle`)}),(0,S.jsx)(`p`,{className:`modal-desc`,children:i(`codexAuth.confirmResetDesc`,{count:String(C.quota?.resetCredits??0)})}),k&&k[0]&&(0,S.jsx)(`p`,{className:`faint text-label`,children:i(`codexAuth.confirmWhichCredit`,{date:Vn(k[0].granted_at)})}),(0,S.jsx)(`p`,{className:`faint text-label`,children:i(`codexAuth.irreversible`)})]}),(0,S.jsxs)(`div`,{className:`modal-actions`,children:[(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>E(!1),children:i(`codexAuth.cancel`)}),(0,S.jsx)(`button`,{className:`btn btn-primary`,onClick:()=>le(C.id),disabled:D,children:i(D?`codexAuth.redeeming`:`codexAuth.useCredit`)})]})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`h3`,{children:[(0,S.jsx)(se,{width:16}),` `,i(`codexAuth.resetCreditsTitle`)]}),(0,S.jsxs)(`div`,{className:`card-sub`,children:[C.email,C.plan?` · ${C.plan}`:``]}),(0,S.jsx)(`div`,{style:{margin:`16px 0`},children:(C.quota?.resetCredits??0)>0?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`p`,{style:{marginBottom:12},children:i(`codexAuth.resetCreditsAvailable`,{count:String(C.quota?.resetCredits??0)})}),j&&(0,S.jsx)(`p`,{className:`faint text-label`,children:i(`common.loading`)}),k&&k.length>0&&(0,S.jsx)(`div`,{className:`credit-list`,children:k.map((e,t)=>(0,S.jsx)(Un,{index:t,grantedAt:e.granted_at,expiresAt:e.expires_at,isNext:t===0,t:i},t))}),(0,S.jsx)(`button`,{className:`btn btn-primary`,style:{marginTop:12,width:`100%`},onClick:()=>E(!0),disabled:D,children:i(`codexAuth.useOneCredit`)}),(0,S.jsx)(`p`,{className:`card-sub text-caption`,style:{marginTop:8,textAlign:`center`},children:i(`codexAuth.fifoNote`)})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`p`,{className:`faint`,children:i(`codexAuth.noResetCredits`)}),(0,S.jsx)(`p`,{className:`modal-desc`,children:i(`codexAuth.earnCreditsHint`)})]})})]})})}),p&&(0,S.jsx)(zn,{apiBase:e,onClose:()=>m(!1),onAdded:()=>{z(),g(i(`codexAuth.accountAdded`)),setTimeout(()=>g(``),5e3)}})]})}function Vn(e){let t=new Date(e);return new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`}).format(t)}function Hn(e){return Math.max(0,Math.ceil((new Date(e).getTime()-Date.now())/864e5))}function Un({index:e,grantedAt:t,expiresAt:n,isNext:r,t:i}){let a=Hn(n),o=a<=7;return(0,S.jsxs)(`div`,{className:`credit-item${r?` credit-next`:``}`,children:[(0,S.jsxs)(`div`,{className:`credit-item-head`,children:[(0,S.jsx)(se,{width:13}),(0,S.jsx)(`span`,{className:`credit-item-label`,children:r?i(`codexAuth.creditNext`):i(`codexAuth.creditLabel`,{n:String(e+1)})}),r&&(0,S.jsx)(`span`,{className:`badge badge-amber text-micro`,style:{padding:`1px 6px`},children:i(`codexAuth.creditNextBadge`)})]}),(0,S.jsxs)(`div`,{className:`credit-item-dates`,children:[(0,S.jsx)(`span`,{children:i(`codexAuth.creditGranted`,{date:Vn(t)})}),(0,S.jsx)(`span`,{className:o?`credit-urgent`:``,children:i(`codexAuth.creditExpires`,{date:Vn(n),days:String(a)})})]})]})}function Wn({account:e,onClick:t,t:n}){let r=e.quota?.resetCredits;return r===void 0?null:(0,S.jsxs)(`button`,{type:`button`,className:`badge ${typeof r==`number`&&r>0?`badge-amber`:`badge-muted`} badge-clickable`,onClick:e=>{e.stopPropagation(),t()},"aria-label":n(`codexAuth.resetCreditsAria`,{count:String(r)}),children:[(0,S.jsx)(se,{width:12}),r]})}function Gn({item:e,apiBase:t,oauth:n,accounts:r=[],keys:i=[],accountLoadState:a=`ready`,switchingAccountId:o=null,busy:s=!1,loginHint:c,authHandlers:l}){let u=U(),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(``),[h,g]=(0,_.useState)(!1),v=cn({...e,hasApiKey:e.hasApiKey||i.length>0}),y=v===`oauth-accounts`,b=v===`api-keys`;if(v===`codex-accounts`)return(0,S.jsxs)(`section`,{className:`pwi-section pwi-auth-section`,"aria-label":u(`pws.availableAccounts`),children:[(0,S.jsx)(`h3`,{className:`pwi-section-title`,children:u(`pws.availableAccounts`)}),(0,S.jsx)(`div`,{className:`pwi-auth-body`,children:(0,S.jsx)(Bn,{apiBase:t,embedded:!0})})]});if(!v||!l)return null;let x=c?.provider===e.name?c:null,C=r.length>0||n?.loggedIn===!0,w=async()=>{let t=p.trim();if(!t)return;g(!0);let n=await l.onAddApiKey(e.name,t);g(!1),n&&(m(``),f(!1))};return(0,S.jsxs)(`section`,{className:`pwi-section pwi-auth-section`,"aria-label":u(y?`pws.availableAccounts`:`pws.apiKeys`),children:[(0,S.jsx)(`h3`,{className:`pwi-section-title`,children:u(y?`pws.availableAccounts`:`pws.apiKeys`)}),(0,S.jsxs)(`div`,{className:`pwi-auth-body`,children:[y&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`pwi-auth-status-row`,children:[(0,S.jsx)(`span`,{className:`pwi-auth-dot ${C?`pwi-auth-dot--ok`:`pwi-auth-dot--off`}`,"aria-hidden":`true`}),(0,S.jsx)(`span`,{className:`pwi-auth-status-text`,children:C?r.length>0?u(`pws.loggedInTitle`):n?.email??u(`pws.loggedInTitle`):n?.error||u(`pws.notLoggedInTitle`)}),(0,S.jsx)(`span`,{className:`pwi-auth-actions`,children:C?(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>void l.onLogout(e.name),children:u(`prov.logout`)}):(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,disabled:s,onClick:()=>void l.onLogin(e.name,!1),children:[s?(0,S.jsx)(`span`,{className:`pwi-spin-inline`,"aria-hidden":`true`}):(0,S.jsx)(oe,{style:{width:13,height:13},"aria-hidden":`true`}),u(s?`prov.waitingBrowser`:`prov.login`)]})})]}),s&&x&&(0,S.jsxs)(`div`,{className:`pwi-auth-wait`,children:[(0,S.jsx)(`span`,{className:`pwi-spin-inline`,"aria-hidden":`true`}),(0,S.jsxs)(`div`,{className:`pwi-auth-wait-copy`,children:[(0,S.jsx)(`div`,{className:`pwi-auth-wait-title`,children:u(`prov.waitingBrowser`)}),x.url&&(0,S.jsxs)(`a`,{href:x.url,target:`_blank`,rel:`noreferrer`,className:`pwi-auth-open-link`,children:[(0,S.jsx)(ie,{style:{width:13,height:13}}),` `,u(`prov.didntOpen`)]})]})]}),a===`loading`&&r.length===0&&(0,S.jsxs)(`div`,{className:`pwi-auth-state`,role:`status`,children:[(0,S.jsx)(`span`,{className:`pwi-spin-inline`,"aria-hidden":`true`}),u(`pws.accountsLoading`)]}),a===`error`&&(0,S.jsxs)(`div`,{className:`pwi-auth-state pwi-auth-state--error`,role:`alert`,children:[(0,S.jsx)(`span`,{children:u(`pws.accountsLoadFailed`)}),l.onRetryAccounts&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>void l.onRetryAccounts?.(e.name),children:u(`pws.retryAccounts`)})]}),r.length>0&&(0,S.jsx)(`div`,{className:`pwi-auth-list`,role:`list`,children:r.map(t=>{let n=ln(r,t,u),i=o===t.id;return(0,S.jsxs)(`div`,{className:`pwi-auth-row${t.active?` pwi-auth-row--active`:``}`,role:`listitem`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`pwi-auth-row-main`,onClick:()=>{!t.active&&!t.needsReauth&&!o&&l.onSwitchAccount(e.name,t)},"aria-current":t.active?`true`:void 0,"aria-label":`${n}${t.active?` — ${u(`pws.accountCurrent`)}`:``}`,disabled:!!(t.needsReauth||o&&!i),children:[(0,S.jsx)(`span`,{className:`pwi-auth-dot ${t.needsReauth?`pwi-auth-dot--warn`:t.active?`pwi-auth-dot--ok`:`pwi-auth-dot--off`}`,"aria-hidden":`true`}),(0,S.jsx)(`span`,{className:`pwi-auth-row-label`,children:n}),t.needsReauth&&(0,S.jsx)(`span`,{className:`badge badge-amber`,children:u(`pws.reauth`)}),t.active&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:u(`prov.accountActive`)}),i&&(0,S.jsx)(`span`,{className:`badge badge-muted`,children:u(`pws.accountSwitching`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm pwi-auth-row-remove`,"aria-label":`${u(`common.remove`)} — ${n}`,title:`${u(`common.remove`)} — ${n}`,disabled:!!o,onClick:()=>void l.onRemoveAccount(e.name,t),children:(0,S.jsx)(F,{style:{width:13,height:13},"aria-hidden":`true`})})]},t.id)})}),a===`ready`&&C&&r.length===0&&(0,S.jsx)(`div`,{className:`pwi-auth-state pwi-auth-state--empty`,children:u(`pws.noAccounts`)}),C&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,style:{marginTop:8},onClick:()=>void l.onLogin(e.name,!0),disabled:s||!!o,children:u(`pws.addAccount`)})]}),b&&(0,S.jsxs)(S.Fragment,{children:[i.length>0&&(0,S.jsx)(`div`,{className:`pwi-auth-list`,role:`list`,children:i.map(t=>(0,S.jsxs)(`div`,{className:`pwi-auth-row${t.active?` pwi-auth-row--active`:``}`,role:`listitem`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`pwi-auth-row-main`,onClick:()=>void l.onSwitchApiKey(e.name,t),disabled:t.active,children:[(0,S.jsx)(`span`,{className:`pwi-auth-dot ${t.active?`pwi-auth-dot--ok`:`pwi-auth-dot--off`}`,"aria-hidden":`true`}),(0,S.jsx)(`code`,{className:`pwi-auth-row-label`,children:t.masked}),t.active&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:u(`prov.accountActive`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm pwi-auth-row-remove`,"aria-label":`${u(`common.remove`)} — ${t.label??t.masked}`,title:`${u(`common.remove`)} — ${t.label??t.masked}`,onClick:()=>void l.onRemoveApiKey(e.name,t),children:(0,S.jsx)(F,{style:{width:13,height:13},"aria-hidden":`true`})})]},t.id))}),d?(0,S.jsxs)(`div`,{className:`pwi-auth-add-key`,children:[(0,S.jsx)(`input`,{className:`input`,type:`password`,value:p,onChange:e=>m(e.target.value),placeholder:u(`modal.apiKeyPlaceholder`),autoComplete:`off`,disabled:h}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:()=>void w(),disabled:h||!p.trim(),children:u(h?`pws.saving`:`pws.addKey`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>{f(!1),m(``)},children:u(`common.cancel`)})]}):(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,style:{marginTop:8},onClick:()=>f(!0),children:u(`pws.addKey`)})]})]})]})}var Kn=[`openai-responses`,`openai-chat`,`anthropic`,`google`,`azure-openai`,`cursor`];function qn({item:e,availableModels:t=[],onUpdateProvider:n,onDirtyChange:r}){let i=U(),a=String(e.authMode??(e.keyOptional?`local`:`key`)),[o,s]=(0,_.useState)(e.adapter),[c,l]=(0,_.useState)(e.baseUrl),[u,d]=(0,_.useState)(e.defaultModel??``),[f,p]=(0,_.useState)(a),[m,h]=(0,_.useState)(e.note??``),[g,v]=(0,_.useState)(!1),[y,b]=(0,_.useState)(null);(0,_.useEffect)(()=>{s(e.adapter),l(e.baseUrl),d(e.defaultModel??``),p(String(e.authMode??(e.keyOptional?`local`:`key`))),h(e.note??``),b(null)},[e.name,e.adapter,e.baseUrl,e.defaultModel,e.authMode,e.keyOptional,e.note]);let x=o.trim()!==e.adapter||c.trim()!==e.baseUrl||u.trim()!==(e.defaultModel??``)||f!==String(e.authMode??(e.keyOptional?`local`:`key`))||m.trim()!==(e.note??``);(0,_.useEffect)(()=>(r?.(x),()=>r?.(!1)),[x,r]);let C=(0,_.useMemo)(()=>{let n=new Set(t);return u.trim()&&n.add(u.trim()),e.defaultModel&&n.add(e.defaultModel),[...n].sort((e,t)=>e.localeCompare(t))},[t,u,e.defaultModel]),w=(0,_.useMemo)(()=>{let e=[...Kn];return o&&!e.includes(o)&&e.unshift(o),e},[o]),T=Mt(e.name),E=async()=>{if(!n){b({ok:!1,text:i(`pws.updatesUnavailable`)});return}if(!o.trim()||!c.trim()){b({ok:!1,text:i(`pws.adapterBaseRequired`)});return}v(!0),b(null);let t={adapter:o.trim(),baseUrl:c.trim(),defaultModel:u.trim(),authMode:f,note:m.trim()},r=await n(e.name,t);v(!1),b(r.ok?{ok:!0,text:i(`pws.settingsSaved`)}:{ok:!1,text:r.error||i(`prov.saveFailed`)})};return(0,S.jsxs)(`div`,{className:`pwi-settings-form`,children:[(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsxs)(`span`,{className:`pwi-settings-label`,children:[(0,S.jsx)(oe,{style:{width:12,height:12}}),` `,i(`pws.providerId`)]}),(0,S.jsx)(`input`,{className:`input`,value:e.name,readOnly:!0,disabled:!0})]}),(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsx)(`span`,{className:`pwi-settings-label`,children:i(`modal.adapter`)}),T?(0,S.jsx)(`input`,{className:`input`,value:o,readOnly:!0,disabled:!0}):(0,S.jsx)(`select`,{className:`input`,value:o,onChange:e=>s(e.target.value),children:w.map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))})]}),(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsx)(`span`,{className:`pwi-settings-label`,children:i(`modal.baseUrl`)}),(0,S.jsx)(`input`,{className:`input`,value:c,onChange:e=>l(e.target.value),readOnly:T,disabled:T})]}),(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsx)(`span`,{className:`pwi-settings-label`,children:i(`pws.cell.defaultModel`)}),C.length>0?(0,S.jsxs)(`select`,{className:`input`,value:u,onChange:e=>d(e.target.value),children:[(0,S.jsx)(`option`,{value:``,children:i(`pws.defaultModelNone`)}),C.map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))]}):(0,S.jsx)(`input`,{className:`input`,value:u,onChange:e=>d(e.target.value),placeholder:i(`pws.optionalPlaceholder`)})]}),(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsx)(`span`,{className:`pwi-settings-label`,children:i(`pws.authMode`)}),T?(0,S.jsx)(`input`,{className:`input`,value:Pt(e,i),readOnly:!0,disabled:!0}):(0,S.jsxs)(`select`,{className:`input`,value:f,onChange:e=>p(e.target.value),children:[(0,S.jsx)(`option`,{value:`key`,children:i(`modal.badge.apiKey`)}),(0,S.jsx)(`option`,{value:`forward`,children:i(`pws.auth.chatgptPassthrough`)}),(0,S.jsx)(`option`,{value:`oauth`,children:i(`modal.badge.oauth`)}),(0,S.jsx)(`option`,{value:`local`,children:i(`modal.badge.local`)})]})]}),(0,S.jsxs)(`label`,{className:`pwi-settings-field`,children:[(0,S.jsx)(`span`,{className:`pwi-settings-label`,children:i(`pws.note`)}),(0,S.jsx)(`textarea`,{className:`input pwi-settings-textarea`,value:m,onChange:e=>h(e.target.value),rows:2})]}),x&&(0,S.jsxs)(`div`,{className:`pwi-settings-sticky-bar`,children:[(0,S.jsx)(`span`,{className:`muted`,children:i(`pws.settingsUnsavedBar`)}),(0,S.jsxs)(`div`,{className:`pwi-settings-sticky-bar-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>{s(e.adapter),l(e.baseUrl),d(e.defaultModel??``),p(a),h(e.note??``),b(null)},disabled:g,children:i(`pws.discardSettings`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:()=>void E(),disabled:g,children:i(g?`pws.saving`:`pws.saveSettings`)})]})]}),y&&(0,S.jsx)(`div`,{className:y.ok?`pwi-settings-msg pwi-settings-msg--ok`:`pwi-settings-msg pwi-settings-msg--err`,children:y.text})]})}function Jn({item:e,usageTotals:t,quotaReport:n,availableModels:r,selectedModels:i,modelsLoading:a,modelsLoadFailed:o,onRetryModels:s,oauthEmail:c,onDeselect:l,apiBase:u,oauth:d,accounts:f,accountLoadState:p,switchingAccountId:m,keys:h,busyProvider:g,loginHint:v,authHandlers:y,onUpdateProvider:b,isDefault:x,onRemoveProvider:C,onSetDisabled:w}){let T=U(),[E,D]=(0,_.useState)(`overview`),[O,k]=(0,_.useState)(!1),A=e.disabled===!0,j=(0,_.useMemo)(()=>tt(e),[e]),M=(0,_.useMemo)(()=>ht(e),[e]),N=(0,_.useMemo)(()=>cn(e),[e]),P=(0,_.useMemo)(()=>[{id:`overview`,label:T(`pws.tab.overview`)},{id:`models`,label:T(`pws.tab.models`)},{id:`usage`,label:T(`pws.tab.usage`)},...N?[{id:`accounts`,label:T(N===`api-keys`?`pws.apiKeys`:`pws.tab.accounts`)}]:[],{id:`settings`,label:T(`pws.tab.settings`)}],[N,T]),ee=(0,_.useCallback)(e=>{O&&E===`settings`&&e!==`settings`&&!window.confirm(T(`pws.unsavedLeaveBody`))||D(e)},[E,O,T]),I=(0,_.useCallback)((e,t)=>{let n;if(e.key===`ArrowRight`)n=(t+1)%P.length;else if(e.key===`ArrowLeft`)n=(t-1+P.length)%P.length;else if(e.key===`Home`)n=0;else if(e.key===`End`)n=P.length-1;else return;e.preventDefault(),ee(P[n].id),e.currentTarget.parentElement?.querySelectorAll(`[role="tab"]`)[n]?.focus()},[ee,P]),L=`pws-tab-${E}`,te=`pws-panel-${E}`;return(0,S.jsxs)(`div`,{className:`pws-detail`,children:[(0,S.jsx)(`div`,{className:`pws-detail-head`,children:(0,S.jsxs)(`button`,{type:`button`,className:`pws-detail-back-link`,onClick:l,children:[(0,S.jsx)(z,{className:`pws-detail-back-chevron`,"aria-hidden":`true`}),T(`pws.allProviders`)]})}),(0,S.jsxs)(`div`,{className:`pws-detail-head-main`,children:[(0,S.jsx)(It,{name:e.name,adapter:e.adapter,baseUrl:e.baseUrl,cls:`pws-detail-icon`}),(0,S.jsx)(`div`,{className:`pws-detail-title-wrap`,children:(0,S.jsxs)(`h2`,{className:`pws-detail-title`,children:[jt(e.name),M&&(0,S.jsx)(`span`,{className:`pwi-rail-badge pwi-rail-badge--local`,children:T(`modal.badge.local`)}),!M&&j&&(0,S.jsx)(`span`,{className:`pwi-rail-badge pwi-rail-badge--free`,children:T(`modal.badge.free`)})]})}),(0,S.jsxs)(`div`,{className:`pws-detail-actions`,children:[C&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm btn-icon-only`,onClick:()=>C(e.name),"aria-label":T(`pws.removeConfirmTitle`),title:T(`pws.removeConfirmTitle`),children:(0,S.jsx)(F,{style:{width:15,height:15},"aria-hidden":`true`})}),w&&(0,S.jsxs)(`div`,{className:`pws-detail-toggle`,children:[(0,S.jsx)(`span`,{className:`pws-detail-toggle-label`,children:T(`pws.enabledLabel`)}),(0,S.jsx)(ke,{on:!A,onClick:()=>w(e.name,!A),disabled:x,label:T(`pws.enabledLabel`)})]})]})]}),(0,S.jsx)(`div`,{className:`pws-detail-tabs`,role:`tablist`,children:P.map((e,t)=>(0,S.jsx)(`button`,{type:`button`,role:`tab`,id:`pws-tab-${e.id}`,"aria-controls":`pws-panel-${e.id}`,"aria-selected":E===e.id,tabIndex:E===e.id?0:-1,className:`pws-detail-tab${E===e.id?` pws-detail-tab--active`:``}`,onClick:()=>ee(e.id),onKeyDown:e=>I(e,t),children:e.label},e.id))}),(0,S.jsxs)(`div`,{className:`pws-detail-panel`,role:`tabpanel`,id:te,"aria-labelledby":L,tabIndex:0,children:[E===`overview`&&(0,S.jsx)(un,{item:e,usageTotals:t,quotaReport:n,oauthEmail:c,onEditSettings:()=>ee(`settings`),onViewUsage:()=>ee(`usage`),onUpdateProvider:b}),E===`models`&&(0,S.jsx)(Ln,{item:e,availableModels:r,selectedModels:i,modelsLoading:a,modelsLoadFailed:o,onRetryModels:s}),E===`usage`&&(0,S.jsx)(Rn,{item:e,usageTotals:t,quotaReport:n}),E===`accounts`&&(0,S.jsx)(Gn,{item:e,apiBase:u,oauth:d,accounts:f,keys:h,accountLoadState:p,switchingAccountId:m,busy:g===e.name,loginHint:v,authHandlers:y}),E===`settings`&&(0,S.jsx)(qn,{item:e,availableModels:r,onUpdateProvider:b,onDirtyChange:k})]})]})}function Yn(e){return e.codexAccountMode===`direct`?`direct`:`pool`}var Xn={xai:`xAI (Grok)`,anthropic:`Anthropic (Claude)`,kimi:`Kimi (Moonshot)`},Zn=e=>Xn[e]??e;function Qn({apiBase:e}){let t=U(),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(!1),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)([]),[g,v]=(0,_.useState)({}),[y,b]=(0,_.useState)({}),[x,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(!1),[E,D]=(0,_.useState)(null),[O,k]=(0,_.useState)(!1),[A,j]=(0,_.useState)(``),[M,N]=(0,_.useState)(!1),[ee,I]=(0,_.useState)(``),[L,te]=(0,_.useState)({}),[ne,R]=(0,_.useState)({}),[B,ae]=(0,_.useState)(null),[se,le]=(0,_.useState)({}),[V,ue]=(0,_.useState)({}),[de,fe]=(0,_.useState)(null),[pe,me]=(0,_.useState)(``),[he,ge]=(0,_.useState)(()=>location.hash.replace(/^#\/?/,``)===`providers/workspace`),[_e,ve]=(0,_.useState)(null),[ye,be]=(0,_.useState)(null),xe=(0,_.useRef)(!0),Se=(0,_.useRef)({}),Ce=(0,_.useRef)(null),H=(e,t)=>{d(e),p(t)};(0,_.useEffect)(()=>(xe.current=!0,()=>{xe.current=!1}),[]),(0,_.useEffect)(()=>{let e=()=>ge(location.hash.replace(/^#\/?/,``)===`providers/workspace`);return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},[]);let we=()=>{location.hash=he?`#providers`:`#providers/workspace`},Te=(0,_.useCallback)(async()=>{try{let t=await(await fetch(`${e}/api/config`)).json();r(t),l(JSON.stringify(t,null,2))}catch{H(t(`prov.loadConfigFail`),!1)}},[e,t]),Ee=(0,_.useCallback)(async()=>{try{let t=(await fetch(`${e}/api/oauth/providers`).then(e=>e.json())).providers??[];h(t);let n=await Promise.all(t.map(async t=>[t,await fetch(`${e}/api/oauth/status?provider=${t}`).then(e=>e.json()).catch(()=>({loggedIn:!1}))]));v(Object.fromEntries(n))}catch{}},[e]),De=(0,_.useCallback)(async(t=!1)=>{try{let n=await fetch(`${e}/api/provider-quotas${t?`?refresh=1`:``}`).then(e=>e.json());b(Object.fromEntries((n.reports??[]).map(e=>[e.provider,e])))}catch{b({})}},[e]),Oe=(0,_.useCallback)(async t=>{let n=[...new Set(t)];return R(e=>{let t={...e};for(let e of n)t[e]=`loading`;return t}),(await Promise.all(n.map(async t=>{let n=(Se.current[t]??0)+1;Se.current[t]=n;try{let r=await fetch(`${e}/api/oauth/accounts?provider=${encodeURIComponent(t)}`);if(!r.ok)throw Error(String(r.status));let i=await r.json();return!xe.current||Se.current[t]!==n?!0:(te(e=>({...e,[t]:{activeAccountId:i.activeAccountId??null,accounts:i.accounts??[]}})),R(e=>({...e,[t]:`ready`})),!0)}catch{return!xe.current||Se.current[t]!==n?!0:(R(e=>({...e,[t]:`error`})),!1)}}))).every(Boolean)},[e]),ke=async(n,r)=>{if(r.active||r.needsReauth||Ce.current)return;let i={provider:n,accountId:r.id};Ce.current=i,ae(i);let a=ln(L[n]?.accounts??[r],r,t);try{if(!(await fetch(`${e}/api/oauth/accounts/active`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:n,accountId:r.id})})).ok){H(t(`prov.accountSwitchFail`),!1);return}let i=await Oe([n]);if(await Promise.all([Ee(),De(!0)]),!i){H(t(`pws.accountsLoadFailed`),!1);return}H(t(`prov.accountSwitched`,{email:a}),!0)}catch{H(t(`prov.accountSwitchFail`),!1)}finally{Ce.current?.provider===i.provider&&Ce.current.accountId===i.accountId&&(Ce.current=null,xe.current&&ae(null))}},G=(0,_.useCallback)(async t=>{let n=await Promise.all(t.map(async t=>[t,(await fetch(`${e}/api/providers/keys?name=${encodeURIComponent(t)}`).then(e=>e.json()).catch(()=>null))?.keys??[]]));ue(Object.fromEntries(n))},[e]),Ae=async(n,r)=>{if(r.active)return;let i=await fetch(`${e}/api/providers/keys/active`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,id:r.id})});i.ok?(H(t(`prov.keySwitched`,{key:r.label??r.masked}),!0),G(Object.keys(V)),De(!0)):H((await i.json().catch(()=>({}))).error||t(`prov.keySwitchFail`),!1)},je=async(n,r)=>{window.confirm(t(`prov.keyRemoveConfirm`,{key:r.label??r.masked}))&&(await fetch(`${e}/api/providers/keys?name=${encodeURIComponent(n)}&id=${encodeURIComponent(r.id)}`,{method:`DELETE`})).ok&&(H(t(`prov.keyRemoved`,{key:r.label??r.masked}),!0),G(Object.keys(V)),Te(),De(!0))},Me=async(n,r)=>{let i=r.trim();if(!i)return!1;try{let r=await fetch(`${e}/api/providers/keys`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,key:i})});return r.ok?(H(t(`prov.keyAdded`,{name:n}),!0),fe(null),await Promise.all([G(Object.keys(V).includes(n)?Object.keys(V):[...Object.keys(V),n]),Te(),De(!0)]),!0):(H((await r.json().catch(()=>({}))).error||t(`prov.keyAddFail`),!1),!1)}catch{return H(t(`prov.keyAddFail`),!1),!1}},Ne=async e=>{await Me(e,pe)&&me(``)},Pe=async(n,r)=>{let i=ln(L[n]?.accounts??[r],r,t);if(window.confirm(t(`prov.accountRemoveConfirm`,{email:i})))try{if(!(await fetch(`${e}/api/oauth/accounts?provider=${encodeURIComponent(n)}&id=${encodeURIComponent(r.id)}`,{method:`DELETE`})).ok){H(t(`prov.accountRemoveFail`,{email:i}),!1);return}H(t(`prov.accountRemoved`,{email:i}),!0),await Oe([n]),await Promise.all([Ee(),De(!0)])}catch{H(t(`prov.accountRemoveFail`,{email:i}),!1)}};(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{Te(),Ee(),De()},0);return()=>window.clearTimeout(e)},[Te,Ee,De]);let Fe=(0,_.useMemo)(()=>n?Object.entries(n.providers).filter(([,e])=>e.authMode===`oauth`).map(([e])=>e):[],[n]);(0,_.useEffect)(()=>{if(Fe.length===0)return;let e=window.setTimeout(()=>{Oe(Fe)},0);return()=>window.clearTimeout(e)},[Oe,Fe]);let Ie=(0,_.useMemo)(()=>n?Object.entries(n.providers).filter(([,e])=>e.hasApiKey&&e.authMode!==`oauth`&&e.authMode!==`forward`).map(([e])=>e):[],[n]);(0,_.useEffect)(()=>{if(Ie.length===0)return;let e=window.setTimeout(()=>{G(Ie)},0);return()=>window.clearTimeout(e)},[G,Ie]);let Le=async()=>{try{let n=JSON.parse(c);(await fetch(`${e}/api/config`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)})).ok?(H(t(`prov.saved`),!0),a(!1),Te(),De(!0)):H(t(`prov.saveFailed`),!1)}catch{H(t(`prov.invalidJson`),!1)}},Re=async(n,r=!1)=>{C(n),d(``),D(null),j(``),I(``);try{let i=await fetch(`${e}/api/oauth/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r?{provider:n,addAccount:!0}:{provider:n})}),a=await i.json();if(!i.ok){H(a.error||t(`prov.loginFailStart`,{provider:Zn(n)}),!1);return}(a.url||a.instructions)&&D({provider:n,url:a.url,instructions:a.instructions});let o=L[n]?.accounts.length??0;for(let i=0;i<150&&xe.current;i++){await new Promise(e=>setTimeout(e,2e3));let i=await fetch(`${e}/api/oauth/status?provider=${n}`).then(e=>e.json()).catch(()=>null);if(i){if(r?(i.accounts?.length??0)>o||i.done===!0&&!i.error:i.loggedIn){v(e=>({...e,[n]:i})),H(t(`prov.loginOk`,{provider:Zn(n),cmd:`ocx sync`}),!0),D(null),j(``),I(``),Te(),Oe(Object.keys(L).includes(n)?Object.keys(L):[...Object.keys(L),n]),De(!0);break}if(i.error){v(e=>({...e,[n]:i})),H(t(`prov.loginError`,{provider:Zn(n),error:i.error}),!1),D(null);break}}}}catch{H(t(`prov.loginRequestFail`,{provider:Zn(n)}),!1)}finally{xe.current&&C(null)}},ze=async n=>{let r=A.trim();if(!(!r||M)){N(!0),I(``);try{let i=await fetch(`${e}/api/oauth/login/code`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:n,input:r})}),a=await i.json().catch(()=>({}));if(!i.ok){I(t(`prov.pasteFail`,{error:a.error||i.statusText}));return}j(``),I(t(`prov.pasteOk`))}catch{I(t(`prov.pasteFail`,{error:`network error`}))}finally{xe.current&&N(!1)}}},Be=async n=>{try{if(!(await fetch(`${e}/api/oauth/logout?provider=${encodeURIComponent(n)}`,{method:`POST`})).ok){H(t(`prov.logoutFail`,{provider:Zn(n)}),!1);return}await Promise.all([Oe([n]),Ee(),Te(),De(!0)]),H(t(`prov.logoutOk`,{provider:Zn(n)}),!0)}catch{H(t(`prov.logoutFail`,{provider:Zn(n)}),!1)}},Ve=async n=>{window.confirm(t(`prov.removeConfirm`,{name:n}))&&((await fetch(`${e}/api/providers?name=${encodeURIComponent(n)}`,{method:`DELETE`})).ok?(H(t(`prov.removed`,{name:n}),!0),Te(),Ee(),De(!0)):H(t(`prov.removeFail`,{name:n}),!1))},He=async(n,r)=>{let i=await fetch(`${e}/api/providers?name=${encodeURIComponent(n)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({disabled:r})});if(i.ok){H(t(r?`prov.disabled`:`prov.enabled`,{name:n}),!0),Te(),Ee(),De(!0);return}H((await i.json().catch(()=>({}))).error||t(r?`prov.disableFail`:`prov.enableFail`,{name:n}),!1)},Ue=async(t,n)=>{try{let r=await fetch(`${e}/api/providers?name=${encodeURIComponent(t)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});return r.ok?(Te(),{ok:!0}):{ok:!1,error:(await r.json().catch(()=>({}))).error||`Update failed`}}catch{return{ok:!1,error:`Network error`}}},We=async n=>{if(!w){T(!0);try{let i=await fetch(`${e}/api/providers?name=openai`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({codexAccountMode:n})});if(!i.ok){H((await i.json().catch(()=>({}))).error||t(`prov.openaiModeSaveFailed`),!1);return}r(e=>e&&{...e,providers:{...e.providers,openai:{...e.providers.openai,codexAccountMode:n}}}),H(t(`prov.openaiModeSaved`,{mode:t(n===`pool`?`prov.openaiModePool`:`prov.openaiModeDirect`)}),!0),n===`pool`&&De(!0)}catch{H(t(`prov.openaiModeSaveFailed`),!1)}finally{xe.current&&T(!1)}}};if(!n)return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h2`,{children:t(`nav.providers`)})}),u?(0,S.jsx)(W,{tone:`err`,children:u}):(0,S.jsx)(`div`,{className:`muted`,children:t(`prov.loadingConfig`)})]});let Ge=Object.entries(n.providers).filter(([e,t])=>(t.hasApiKey||e===`openai-apikey`)&&t.authMode!==`oauth`&&t.authMode!==`forward`&&!m.includes(e)).map(([e])=>e);return he?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{children:t(`nav.providers`)}),(0,S.jsxs)(`div`,{className:`row`,children:[(0,S.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:we,children:t(`pws.classicToggle`)}),(0,S.jsxs)(`button`,{className:`btn btn-primary`,onClick:()=>s(!0),children:[(0,S.jsx)(P,{}),t(`prov.add`)]})]})]}),u&&(0,S.jsx)(W,{tone:f?`ok`:`err`,children:u}),(0,S.jsx)(on,{providers:n.providers,apiBase:e,defaultProvider:n.defaultProvider,selectedName:_e,onSelect:ve,onAddProvider:e=>{be(e??null),s(!0)},detail:(t,r)=>(0,S.jsx)(Jn,{item:t,usageTotals:r.usageTotals,quotaReport:r.quotaReport,availableModels:r.availableModels,selectedModels:r.selectedModels,modelsLoading:r.modelsLoading,modelsLoadFailed:r.modelsLoadFailed,oauthEmail:g[t.name]?.email,onDeselect:()=>ve(null),apiBase:e,oauth:g[t.name],accounts:L[t.name]?.accounts??[],keys:V[t.name]??[],accountLoadState:ne[t.name]??(t.authMode===`oauth`?`idle`:`ready`),switchingAccountId:B?.provider===t.name?B.accountId:null,busyProvider:x,loginHint:E,authHandlers:{onLogin:Re,onLogout:Be,onSwitchAccount:ke,onRemoveAccount:Pe,onRetryAccounts:async e=>{await Oe([e])},onAddApiKey:Me,onSwitchApiKey:Ae,onRemoveApiKey:je},isDefault:t.name===n.defaultProvider,onRemoveProvider:Ve,onSetDisabled:He,onUpdateProvider:Ue},t.name)}),o&&(0,S.jsx)(pt,{apiBase:e,existingNames:Object.keys(n.providers),initialTier:ye?.tier,initialCustom:ye?.custom,onClose:()=>{s(!1),be(null)},onAdded:e=>{s(!1),be(null),H(t(`prov.added`,{name:e,cmd:`ocx sync`}),!0),Te(),Ee(),De(!0)}})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{children:t(`nav.providers`)}),(0,S.jsxs)(`div`,{className:`row`,children:[(0,S.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:we,children:t(he?`pws.classicToggle`:`pws.workspaceToggle`)}),i?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`button`,{className:`btn btn-primary`,onClick:Le,children:t(`common.save`)}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>{a(!1),l(JSON.stringify(n,null,2))},children:t(`common.cancel`)})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`btn btn-primary`,onClick:()=>s(!0),children:[(0,S.jsx)(P,{}),t(`prov.add`)]}),(0,S.jsx)(`button`,{className:`btn btn-ghost`,onClick:()=>a(!0),children:t(`prov.editJson`)})]})]})]}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`prov.subtitle`)}),u&&(0,S.jsx)(W,{tone:f?`ok`:`err`,children:u}),(0,S.jsxs)(`div`,{className:`panel panel-accent`,style:{marginBottom:18},children:[(0,S.jsxs)(`div`,{className:`row`,style:{marginBottom:14},children:[(0,S.jsx)(oe,{style:{width:16,height:16,color:`var(--accent)`}}),(0,S.jsx)(`span`,{className:`font-semibold`,children:t(`prov.accountLogin`)})]}),(0,S.jsxs)(`div`,{className:`oauth-grid`,children:[m.length===0&&Ge.length===0&&(0,S.jsx)(`span`,{className:`muted text-control`,style:{gridColumn:`1 / -1`},children:t(`prov.noOauth`)}),m.map(e=>{let n=g[e]??{loggedIn:!1},r=x===e,i=At(e);return(0,S.jsxs)(`div`,{className:`oauth-row`,children:[(0,S.jsxs)(`span`,{className:`oauth-name`,title:Zn(e),children:[(0,S.jsx)(`span`,{className:`provider-icon provider-icon-sm`,children:i&&(0,S.jsx)(`img`,{src:i,alt:``,"aria-hidden":`true`})}),(0,S.jsx)(`span`,{className:`oauth-name-text`,children:e})]}),(0,S.jsxs)(`span`,{className:`oauth-status`,children:[(0,S.jsx)(`span`,{className:`dot ${n.loggedIn?`dot-green`:`dot-muted`}`}),n.loggedIn?(0,S.jsx)(`span`,{className:`oauth-email`,style:{color:`var(--green)`},children:n.email??t(`prov.loggedIn`)}):(0,S.jsx)(`span`,{className:`oauth-email muted`,children:t(`prov.notLoggedIn`)})]}),(0,S.jsx)(`span`,{className:`oauth-actions`,children:n.loggedIn?(0,S.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>Be(e),children:t(`prov.logout`)}):(0,S.jsx)(`button`,{className:`btn btn-primary btn-sm`,onClick:()=>Re(e),disabled:r,children:r?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`spin`}),t(`prov.waitingBrowser`)]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(oe,{}),t(`prov.login`)]})})}),E?.provider===e&&(E.url||E.instructions||r)&&(0,S.jsxs)(`span`,{className:`oauth-login-hint muted`,children:[(0,S.jsxs)(`span`,{className:`oauth-login-hint-links`,children:[E.url&&(0,S.jsxs)(`a`,{href:E.url,target:`_blank`,rel:`noreferrer`,className:`link-btn`,style:{display:`inline-flex`,alignItems:`center`,gap:5},children:[(0,S.jsx)(ie,{width:14,height:14}),t(`prov.didntOpen`)]}),(0,S.jsxs)(`button`,{className:`link-btn`,onClick:()=>{E?.url&&navigator.clipboard.writeText(E.url).then(()=>{k(!0),setTimeout(()=>k(!1),2500)}).catch(()=>{})},style:{display:`inline-flex`,alignItems:`center`,gap:5},children:[(0,S.jsx)(ce,{width:14,height:14}),t(O?`prov.linkCopied`:`prov.copyLink`)]}),E.instructions&&(0,S.jsx)(`span`,{children:E.instructions})]}),(0,S.jsxs)(`span`,{className:`oauth-login-paste`,children:[(0,S.jsx)(`input`,{className:`input`,type:`text`,autoComplete:`off`,spellCheck:!1,value:A,onChange:e=>j(e.target.value),onKeyDown:t=>{t.key===`Enter`&&(t.preventDefault(),ze(e))},placeholder:t(`prov.pasteRedirect`),"aria-label":t(`prov.pasteRedirect`),disabled:M}),(0,S.jsx)(`button`,{className:`btn btn-ghost btn-sm`,type:`button`,disabled:M||!A.trim(),onClick:()=>void ze(e),children:t(M?`prov.pasteSubmitting`:`prov.pasteSubmit`)})]}),(0,S.jsx)(`span`,{className:`text-caption`,children:ee||t(`prov.pasteRedirectHint`)})]})]},e)}),Ge.map(e=>{let r=n?.providers[e],i=At(e),a=r?.keyOptional===!0&&!r?.hasApiKey,o=e===`openai-apikey`&&!r?.hasApiKey;return(0,S.jsxs)(`div`,{className:`oauth-row`,children:[(0,S.jsxs)(`span`,{className:`oauth-name`,title:e,children:[(0,S.jsx)(`span`,{className:`provider-icon provider-icon-sm`,children:i&&(0,S.jsx)(`img`,{src:i,alt:``,"aria-hidden":`true`})}),(0,S.jsx)(`span`,{className:`oauth-name-text`,children:e})]}),(0,S.jsxs)(`span`,{className:`oauth-status`,children:[(0,S.jsx)(`span`,{className:`dot ${o?`dot-amber`:`dot-green`}`}),(0,S.jsx)(`span`,{className:`oauth-email muted`,children:t(o?`prov.openaiApiMissing`:a?`modal.badge.free`:`prov.hasApiKey`)})]}),(0,S.jsx)(`span`,{className:`oauth-actions`,children:o&&(0,S.jsx)(`button`,{className:`btn btn-primary btn-sm`,onClick:()=>s(!0),children:t(`prov.openaiApiSetup`)})})]},e)})]})]}),i?(0,S.jsx)(`textarea`,{className:`input`,value:c,onChange:e=>l(e.target.value),style:{height:400}}):(0,S.jsxs)(`div`,{className:`stack`,style:{gap:8},children:[(0,S.jsxs)(`div`,{className:`muted text-control`,style:{marginBottom:4},children:[t(`prov.port`),`: `,(0,S.jsx)(`code`,{className:`chip`,children:n.port}),` · `,t(`prov.default`),`: `,(0,S.jsx)(`code`,{className:`chip`,children:n.defaultProvider})]}),Object.entries(n.providers).map(([e,r])=>{let i=e===n.defaultProvider,a=r.disabled===!0,o=y[e]?.quota??null,s=At(e),c=r.authMode===`oauth`?L[e]:void 0,l=r.authMode!==`oauth`&&r.authMode!==`forward`&&r.hasApiKey?V[e]??[]:[],u=!!c&&c.accounts.length>0||l.length>0,d=se[e]===!0,f=c?.accounts.length??l.length,p=e===`openai`?Yn(r):null,m=p===`direct`?t(`prov.openaiDirectDesc`):p===`pool`?t(`prov.openaiPoolDesc`):e===`openai-apikey`?t(`prov.openaiApiDesc`):r.note;return(0,S.jsxs)(`div`,{className:`card prov-card${a?` prov-card-disabled`:``}`,children:[(0,S.jsxs)(`div`,{className:`prov-card-main`,children:[(0,S.jsxs)(`div`,{className:`prov-card-info`,children:[s&&(0,S.jsx)(`span`,{className:`provider-icon`,children:(0,S.jsx)(`img`,{src:s,alt:``,"aria-hidden":`true`})}),(0,S.jsxs)(`div`,{className:`prov-card-copy`,children:[(0,S.jsxs)(`div`,{className:`prov-title`,children:[(0,S.jsx)(`span`,{className:`font-semibold`,children:e}),i&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:t(`prov.defaultBadge`)}),a?(0,S.jsx)(`span`,{className:`badge badge-muted`,children:t(`prov.disabledBadge`)}):(0,S.jsx)(`span`,{className:`badge badge-green`,children:t(`prov.activeBadge`)}),r.authMode===`oauth`&&(0,S.jsx)(`span`,{className:`badge badge-accent`,children:`oauth`}),p===`direct`&&(0,S.jsx)(`span`,{className:`badge badge-green`,children:t(`prov.openaiModeDirect`)}),p===`pool`&&(0,S.jsx)(`span`,{className:`badge badge-accent`,children:t(`prov.openaiModePool`)}),e===`openai-apikey`&&(0,S.jsx)(`span`,{className:`badge badge-muted`,children:t(`modal.badge.apiKey`)}),e!==`openai`&&r.authMode===`forward`&&!r.codexAccountMode&&(0,S.jsx)(`span`,{className:`badge badge-amber`,children:`passthrough`}),r.keyOptional&&(0,S.jsx)(`span`,{className:`badge badge-green`,children:t(`modal.badge.free`)})]}),(0,S.jsxs)(`div`,{className:`muted prov-meta text-control`,children:[(0,S.jsx)(`code`,{className:`chip`,children:r.adapter}),(0,S.jsx)(`span`,{children:r.baseUrl}),r.defaultModel&&(0,S.jsx)(`span`,{children:r.defaultModel}),r.hasApiKey&&(0,S.jsx)(`span`,{children:t(`prov.hasApiKey`)}),r.hasHeaders&&(0,S.jsx)(`span`,{children:t(`prov.hasHeaders`)})]}),m&&(0,S.jsxs)(`div`,{className:`muted text-label leading-body`,style:{marginTop:4},children:[m,p&&(0,S.jsxs)(S.Fragment,{children:[` · `,(0,S.jsx)(`a`,{href:`#codex-auth`,children:t(`prov.manageCodexAccounts`)})]})]}),p&&(0,S.jsxs)(`div`,{className:`openai-mode-row`,children:[(0,S.jsx)(`span`,{id:`openai-account-mode-label`,className:`text-label font-semibold`,children:t(`prov.openaiAccountMode`)}),(0,S.jsx)(`div`,{className:`usage-segmented openai-mode-control`,role:`radiogroup`,"aria-labelledby":`openai-account-mode-label`,children:[`pool`,`direct`].map(e=>(0,S.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":p===e,className:`usage-segmented-btn${p===e?` active`:``}`,disabled:w,onClick:()=>void We(e),children:t(e===`pool`?`prov.openaiModePool`:`prov.openaiModeDirect`)},e))})]})]})]}),(0,S.jsxs)(`div`,{className:`provider-actions`,children:[(0,S.jsxs)(`button`,{className:`btn ${a?`btn-primary`:`btn-ghost`} btn-sm`,onClick:()=>He(e,!a),disabled:i,title:i?t(`prov.defaultCannotDisable`):void 0,"aria-label":t(a?`prov.enableAria`:`prov.disableAria`,{name:e}),children:[i?(0,S.jsx)(oe,{}):(0,S.jsx)(re,{}),t(a?`prov.enable`:`prov.disable`)]}),(0,S.jsxs)(`button`,{className:`btn btn-danger btn-sm`,onClick:()=>Ve(e),"aria-label":t(`sub.removeAria`,{m:e}),children:[(0,S.jsx)(F,{}),t(`common.remove`)]})]})]}),o&&(0,S.jsx)(Zt,{quota:o,threshold:80,t,className:`provider-quota`}),u&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{className:`prov-accounts-toggle${d?` open`:``}`,onClick:()=>le(t=>({...t,[e]:!d})),"aria-expanded":d,"aria-label":t(`prov.accountsAria`,{name:e}),children:[t(`prov.accounts`,{n:String(f)}),(0,S.jsx)(`span`,{className:`chev`,children:(0,S.jsx)(z,{})})]}),d&&(0,S.jsxs)(`div`,{className:`prov-accounts-list`,children:[(c?.accounts??[]).map(n=>{let r=ln(c?.accounts??[n],n,t);return(0,S.jsxs)(`button`,{className:`prov-account-row${n.active?` active`:``}`,onClick:()=>ke(e,n),title:n.active?void 0:t(`prov.accountSwitchTitle`),children:[(0,S.jsx)(`span`,{className:`dot ${n.needsReauth?`dot-amber`:n.active?`dot-green`:`dot-muted`}`}),(0,S.jsx)(`span`,{className:`prov-account-email`,children:r}),n.needsReauth&&(0,S.jsx)(`span`,{className:`badge badge-amber`,children:t(`prov.accountReauth`)}),n.active&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:t(`prov.accountActive`)}),(0,S.jsx)(`span`,{className:`prov-account-remove`,role:`button`,"aria-label":t(`prov.accountRemoveAria`,{email:r}),onClick:t=>{t.stopPropagation(),Pe(e,n)},children:(0,S.jsx)(F,{style:{width:13,height:13}})})]},n.id)}),l.map(n=>(0,S.jsxs)(`button`,{className:`prov-account-row${n.active?` active`:``}`,onClick:()=>Ae(e,n),title:n.active?void 0:t(`prov.keySwitchTitle`),children:[(0,S.jsx)(`span`,{className:`dot ${n.active?`dot-green`:`dot-muted`}`}),(0,S.jsx)(`span`,{className:`prov-account-email mono`,children:n.label?`${n.label} · ${n.masked}`:n.masked}),n.active&&(0,S.jsx)(`span`,{className:`badge badge-primary`,children:t(`prov.accountActive`)}),(0,S.jsx)(`span`,{className:`prov-account-remove`,role:`button`,"aria-label":t(`prov.keyRemoveAria`,{key:n.label??n.masked}),onClick:t=>{t.stopPropagation(),je(e,n)},children:(0,S.jsx)(F,{style:{width:13,height:13}})})]},n.id)),c?(0,S.jsx)(`button`,{className:`prov-account-row prov-account-add`,onClick:()=>Re(e,!0),disabled:x===e,children:x===e?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`spin`}),t(`prov.waitingBrowser`)]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(P,{style:{width:13,height:13}}),t(`prov.accountAdd`)]})}):de===e?(0,S.jsxs)(`div`,{className:`prov-account-row prov-account-keyform`,children:[(0,S.jsx)(`input`,{className:`input input-sm mono`,type:`password`,autoFocus:!0,placeholder:t(`prov.keyPlaceholder`),value:pe,onChange:e=>me(e.target.value),onKeyDown:t=>{t.key===`Enter`&&Ne(e),t.key===`Escape`&&(fe(null),me(``))}}),(0,S.jsx)(`button`,{className:`btn btn-primary btn-sm`,onClick:()=>Ne(e),disabled:!pe.trim(),children:t(`common.save`)}),(0,S.jsx)(`button`,{className:`btn btn-ghost btn-sm`,onClick:()=>{fe(null),me(``)},children:t(`common.cancel`)})]}):(0,S.jsxs)(`button`,{className:`prov-account-row prov-account-add`,onClick:()=>{fe(e),me(``)},children:[(0,S.jsx)(P,{style:{width:13,height:13}}),t(`prov.keyAdd`)]})]})]})]},e)})]}),o&&(0,S.jsx)(pt,{apiBase:e,existingNames:Object.keys(n.providers),onClose:()=>s(!1),onAdded:e=>{s(!1),H(t(`prov.added`,{name:e,cmd:`ocx sync`}),!0),Te(),Ee(),De(!0)}})]})}var $n={"gpt-5.6-sol":le,"gpt-5.6-terra":de,"gpt-5.6-luna":V},er={width:14,height:14,flexShrink:0,verticalAlign:`text-bottom`,marginRight:4};function tr(e){return e.slice(e.lastIndexOf(`/`)+1)}function nr(e){return $n[e]??$n[tr(e)]??null}function rr(e){let t=nr(e);return t?(0,_.createElement)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:4}},(0,_.createElement)(t,{style:er}),e):e}var ir=Array.from({length:18},(e,t)=>1e5+t*5e4),ar=new Set(ir),or=`custom`,sr=[4,8,16,32,64,128,256,500,1e3],cr=new Set(sr),lr=60;function ur(e){return!Number.isFinite(e)||e<=0?String(e):e%1e3==0?`${e/1e3}k`:e.toLocaleString()}function dr(e){let t=new Set;for(let n of e)n.disabled&&t.add(n.namespaced);return t}function fr(e,t){let n=[];for(let r of e)!t.has(r.id)&&!t.has(r.namespaced)&&n.push({value:r.namespaced,label:r.namespaced});return n}function pr({apiBase:e}){let t=U(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(new Set),[o,s]=(0,_.useState)({}),[c,l]=(0,_.useState)({}),[u,d]=(0,_.useState)({}),[f,p]=(0,_.useState)(35e4),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(!1),[y,b]=(0,_.useState)(()=>{try{let e=localStorage.getItem(`ocx-models-collapsed`);return e?new Set(JSON.parse(e)):new Set}catch{return new Set}}),[x,C]=(0,_.useState)(``),[w,T]=(0,_.useState)(!1),[D,O]=(0,_.useState)(!0),[k,A]=(0,_.useState)(!1),j=(0,_.useRef)(!1),[M,N]=(0,_.useState)(null),[P,ee]=(0,_.useState)(!1),[F,I]=(0,_.useState)(``),te=(0,_.useRef)(!1),[ne,R]=(0,_.useState)(``),[B,re]=(0,_.useState)(!1),[ie,ae]=(0,_.useState)(!1),[oe,se]=(0,_.useState)(null),[ce,le]=(0,_.useState)(!1),V=(0,_.useMemo)(()=>fr(n,i),[n,i]),ue=(0,_.useCallback)(async()=>{try{let t=await fetch(`${e}/api/shadow-call-settings`);t.ok&&se(await t.json())}catch{}},[e]),de=(0,_.useCallback)(async()=>{if(!te.current)try{let t=await fetch(`${e}/api/v2`);if(!t.ok||!(t.headers.get(`content-type`)??``).includes(`application/json`)){N(null);return}let n=await t.json();typeof n.enabled==`boolean`&&N({enabled:n.enabled,agentsMaxThreadsConflict:n.agentsMaxThreadsConflict===!0,maxConcurrentThreadsPerSession:typeof n.maxConcurrentThreadsPerSession==`number`?n.maxConcurrentThreadsPerSession:null,multiAgentMode:n.multiAgentMode===`v1`||n.multiAgentMode===`v2`?n.multiAgentMode:`default`})}catch{N(null)}},[e]),fe=(0,_.useCallback)(async()=>{try{let[t,n]=await Promise.all([fetch(`${e}/api/models`).then(e=>e.json()),fetch(`${e}/api/provider-context-caps`).then(e=>e.json())]);de(),ue(),r(t),a(dr(t));let i=typeof n.value==`number`&&Number.isFinite(n.value)&&n.value>0?n.value:typeof n.cap==`number`&&Number.isFinite(n.cap)&&n.cap>0?n.cap:void 0;i!==void 0&&p(i),d(n.caps??{})}catch{T(!1),C(t(`models.loadFail`))}finally{O(!1)}},[e,ue,de,t]);(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{fe()},0),t=window.setInterval(()=>{j.current||fe()},1e4);return()=>{window.clearTimeout(e),window.clearInterval(t)}},[fe]);let pe=(0,_.useMemo)(()=>{let e={};for(let t of n)(e[t.provider]??=[]).push(t);return Object.entries(e).sort(([e,t],[n,r])=>{let i=t.every(e=>e.native);return i===r.every(e=>e.native)?e.localeCompare(n):i?-1:1})},[n]),me=async n=>{A(!0),j.current=!0,C(``);try{(await fetch(`${e}/api/disabled-models`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({models:[...n]})})).ok?(a(n),T(!0),C(t(`models.applied`))):(T(!1),C(t(`models.saveFailed`)))}catch{T(!1),C(t(`models.networkError`))}finally{A(!1),j.current=!1}},he=e=>{let t=new Set(i);t.has(e)?t.delete(e):t.add(e),me(t)},ge=async n=>{A(!0),j.current=!0,C(``);let r=u[n]!==f;try{let i=await fetch(`${e}/api/provider-context-caps`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:n,enabled:r})});i.ok?(d((await i.json()).caps??{}),T(!0),C(t(`models.capApplied`)),await fe()):(T(!1),C(t(`models.capSaveFailed`)))}catch{T(!1),C(t(`models.networkError`))}finally{A(!1),j.current=!1}},_e=e=>{b(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{localStorage.setItem(`ocx-models-collapsed`,JSON.stringify([...n]))}catch{}return n})},ve=async n=>{A(!0),j.current=!0,C(``);try{let r=await fetch(`${e}/api/provider-context-caps`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(r.ok){let e=await r.json();typeof e.value==`number`&&Number.isFinite(e.value)&&e.value>0&&p(e.value),d(e.caps??{}),T(!0),C(t(`models.capApplied`)),await fe()}else T(!1),C(t(`models.capSaveFailed`))}catch{T(!1),C(t(`models.networkError`))}finally{A(!1),j.current=!1}},ye=e=>{!Number.isFinite(e)||e<=0||ve({value:Math.floor(e)})},be=e=>{if(e===or){v(!0),h(String(f));return}v(!1);let t=Number(e);Number.isFinite(t)&&t>0&&t!==f&&ye(t)},xe=()=>{let e=Number(m.replace(/[_,\s]/g,``));if(!Number.isFinite(e)||e<=0){T(!1),C(t(`models.capSaveFailed`));return}v(!1),ye(e)},Se=(0,_.useMemo)(()=>{let e=pe.filter(([,e])=>!e.every(e=>e.native));return e.length>0&&e.every(([e])=>u[e]===f)},[pe,u,f]),Ce=()=>{ve({setAll:!Se})},H=async t=>{if(!(!oe||ce)){le(!0),se({...oe,...t});try{await fetch(`${e}/api/shadow-call-settings`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})}finally{le(!1)}}},we=async n=>{if(!(!M||te.current)&&M.multiAgentMode!==n){ee(!0),te.current=!0,I(``),C(``);try{let r=await fetch(`${e}/api/v2`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({multiAgentMode:n})}),i=await r.json().catch(()=>null);r.ok&&i?(de(),T(!0),C(t(`models.v2Applied`)),I((i.warnings??[]).join(` `))):(T(!1),C(i?.error??t(`models.saveFailed`)))}catch{T(!1),C(t(`models.networkError`))}finally{ee(!1),te.current=!1}}},Te=async n=>{if(!(!M||te.current)){if(!Number.isInteger(n)||n<1){T(!1),C(t(`models.v2ThreadsInvalid`));return}if(M.maxConcurrentThreadsPerSession!==n){ee(!0),te.current=!0,I(``),C(``);try{let r=await fetch(`${e}/api/v2`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({maxConcurrentThreadsPerSession:n})}),i=await r.json().catch(()=>null);r.ok&&i&&typeof i.enabled==`boolean`?(N({enabled:i.enabled,agentsMaxThreadsConflict:i.agentsMaxThreadsConflict===!0,maxConcurrentThreadsPerSession:typeof i.maxConcurrentThreadsPerSession==`number`?i.maxConcurrentThreadsPerSession:null,multiAgentMode:i.multiAgentMode===`v1`||i.multiAgentMode===`v2`?i.multiAgentMode:`default`}),T(!0),C(t(`models.v2ThreadsApplied`)),re(!1)):(T(!1),C(i?.error??t(`models.saveFailed`)))}catch{T(!1),C(t(`models.networkError`))}finally{ee(!1),te.current=!1}}}},Ee=e=>{if(e===or){re(!0),R(String(M?.maxConcurrentThreadsPerSession??``));return}re(!1),Te(Number(e))};return D?(0,S.jsxs)(`div`,{className:`row muted`,children:[(0,S.jsx)(`span`,{className:`spin`}),` `,t(`models.loading`)]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{children:t(`nav.models`)}),(0,S.jsx)(`span`,{className:`muted mono text-label`,children:t(`models.active`,{active:n.length-i.size,total:n.length})})]}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`models.subtitle`)}),x&&(0,S.jsx)(W,{tone:w?`ok`:`err`,children:x}),(0,S.jsxs)(`div`,{className:`row muted text-control`,style:{gap:6,marginBottom:8,alignItems:`center`},children:[(0,S.jsxs)(`span`,{title:t(`models.shadowCallInterceptHint`),style:{cursor:`help`},children:[t(`models.shadowCallIntercept`),` ⓘ`]}),(0,S.jsx)(`code`,{className:`text-caption`,style:{opacity:.6},children:`⚠ 5.4-mini →`}),(0,S.jsx)(ke,{on:oe?.enabled??!1,onClick:()=>void H({enabled:!oe?.enabled}),disabled:!oe||ce,label:t(`models.shadowCallIntercept`)}),(0,S.jsx)(G,{value:oe?.model??``,options:[{value:``,label:`—`},...V],onChange:e=>{se(t=>t&&{...t,model:e}),H({model:e})},disabled:!oe||ce||!oe.enabled,label:t(`models.shadowCallIntercept`)})]}),M&&(0,S.jsxs)(`div`,{className:`row`,style:{gap:8,marginBottom:8,flexWrap:`wrap`,alignItems:`center`},children:[(0,S.jsx)(`span`,{className:`muted text-control`,children:t(`models.v2Label`)}),(0,S.jsx)(`div`,{className:`segmented`,role:`radiogroup`,"aria-label":t(`models.v2Label`),style:{display:`inline-flex`,borderRadius:`var(--radius-pill)`,background:`var(--surface-soft, var(--raised))`,padding:3,gap:2},children:[`v1`,`default`,`v2`].map(e=>(0,S.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":(M.multiAgentMode??`default`)===e,className:`btn btn-sm${(M.multiAgentMode??`default`)===e?` btn-primary`:` btn-ghost`}`,style:{borderRadius:`var(--radius-pill)`,minWidth:64,padding:`5px 12px`,border:`none`,background:(M.multiAgentMode??`default`)===e?void 0:`transparent`,color:(M.multiAgentMode??`default`)===e?void 0:`var(--muted)`},disabled:P,onClick:()=>void we(e),children:t(`models.v2Mode_${e}`)},e))}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,style:{width:24,height:24,minWidth:24,flex:`0 0 24px`,padding:0,borderRadius:`var(--radius-pill)`,color:`var(--muted)`},onClick:()=>ae(!0),"aria-label":t(`models.v2Label`),"aria-haspopup":`dialog`,children:(0,S.jsx)(L,{width:14,height:14,"aria-hidden":`true`})}),M.enabled&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`muted text-control`,style:{marginLeft:8},children:t(`models.v2ThreadsLabel`)}),(0,S.jsx)(G,{value:B?or:M.maxConcurrentThreadsPerSession!==null&&M.maxConcurrentThreadsPerSession!==void 0?cr.has(M.maxConcurrentThreadsPerSession)?String(M.maxConcurrentThreadsPerSession):or:``,options:[...M.maxConcurrentThreadsPerSession===null||M.maxConcurrentThreadsPerSession===void 0?[{value:``,label:t(`models.v2ThreadsDefault`)}]:[],...M.maxConcurrentThreadsPerSession!==null&&M.maxConcurrentThreadsPerSession!==void 0&&!cr.has(M.maxConcurrentThreadsPerSession)&&!B?[{value:or,label:String(M.maxConcurrentThreadsPerSession)}]:[],...sr.map(e=>({value:String(e),label:String(e)})),{value:or,label:t(`models.custom`)}],onChange:e=>Ee(e),disabled:P,label:t(`models.v2ThreadsLabel`)}),B&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`input`,{className:`input`,style:{width:100},inputMode:`numeric`,value:ne,onChange:e=>R(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Te(Number(ne.replace(/[_,\s]/g,``)))},disabled:P,"aria-label":t(`models.v2ThreadsLabel`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm`,disabled:P,onClick:()=>{Te(Number(ne.replace(/[_,\s]/g,``)))},children:t(`models.v2ThreadsApply`)})]})]}),M.enabled&&M.agentsMaxThreadsConflict&&(0,S.jsx)(`span`,{className:`mono text-label`,style:{color:`var(--err, #e5484d)`},children:t(`models.v2Conflict`)}),F&&(0,S.jsx)(`span`,{className:`muted text-label`,children:F})]}),(0,S.jsxs)(`div`,{className:`row`,style:{gap:8,marginBottom:8,flexWrap:`wrap`},children:[(0,S.jsx)(`span`,{className:`muted text-control`,children:t(`models.contextCapLabel`)}),(0,S.jsx)(G,{value:g?or:ar.has(f)?String(f):or,options:[...!ar.has(f)&&!g?[{value:String(f),label:ur(f)}]:[],...ir.map(e=>({value:String(e),label:ur(e)})),{value:or,label:t(`models.custom`)}],onChange:e=>be(e),disabled:k,label:t(`models.contextCapLabel`)}),g&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`input`,{className:`input`,style:{width:160},inputMode:`numeric`,placeholder:t(`models.customPlaceholder`),value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&xe()},disabled:k,"aria-label":t(`models.customPlaceholder`)}),(0,S.jsx)(`button`,{type:`button`,onClick:xe,disabled:k,className:`btn btn-ghost btn-sm`,children:t(`models.customApply`)})]}),(0,S.jsx)(`div`,{style:{flex:1}}),(0,S.jsx)(ke,{on:Se,onClick:Ce,disabled:k,label:t(`models.setAll`)}),(0,S.jsx)(`span`,{className:`muted mono text-label`,children:t(`models.setAll`)})]}),(0,S.jsxs)(`div`,{className:`row muted text-label leading-body`,style:{alignItems:`flex-start`,gap:8,marginBottom:12,maxWidth:`80ch`},children:[(0,S.jsx)(L,{width:15,height:15,"aria-hidden":`true`,style:{flexShrink:0,marginTop:2}}),(0,S.jsx)(`span`,{children:t(`models.orderHint`)})]}),pe.map(([e,n])=>{let r=y.has(e),a=n.filter(e=>!i.has(e.namespaced)).length,d=u[e]===f,p=n.every(e=>e.native),m=(o[e]??``).trim().toLowerCase(),h=m?n.filter(e=>e.id.toLowerCase().includes(m)):n,g=c[e]??lr,_=h.slice(0,g),v=h.length-_.length,b=n.every(e=>!i.has(e.namespaced)),x=n.every(e=>i.has(e.namespaced)),C=e=>{let t=new Set(i);for(let r of n)e?t.delete(r.namespaced):t.add(r.namespaced);me(t)};return(0,S.jsxs)(`div`,{className:`card`,style:{marginBottom:8,overflow:`hidden`},children:[(0,S.jsxs)(`div`,{onClick:()=>_e(e),className:`row group-head${r?``:` open`}`,children:[(0,S.jsx)(z,{style:{width:14,height:14,color:`var(--muted)`,transform:r?`none`:`rotate(90deg)`,transition:`transform .12s`}}),(0,S.jsx)(`span`,{className:`text-body font-semibold`,children:e}),p&&(0,S.jsx)(`span`,{className:`muted mono text-caption`,style:{padding:`1px 6px`,border:`1px solid var(--border)`,borderRadius:`var(--radius-pill)`},children:t(`models.nativeGroupLabel`)}),(0,S.jsx)(`span`,{className:`muted mono text-label`,children:t(`models.active`,{active:a,total:n.length})}),(0,S.jsx)(`div`,{style:{flex:1}}),(0,S.jsxs)(`div`,{className:`row`,onClick:e=>e.stopPropagation(),style:{gap:6},children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm text-caption`,disabled:k||b,onClick:()=>C(!0),style:{padding:`2px 8px`},children:t(`models.allOn`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm text-caption`,disabled:k||x,onClick:()=>C(!1),style:{padding:`2px 8px`},children:t(`models.allOff`)}),!p&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(ke,{on:d,onClick:()=>ge(e),disabled:k,label:t(`models.capValue`,{value:ur(f)})}),(0,S.jsx)(`span`,{className:`muted mono text-label`,children:t(`models.capValue`,{value:ur(f)})})]})]})]}),!r&&(0,S.jsxs)(`div`,{style:{padding:`6px 12px`},children:[p&&(0,S.jsx)(`p`,{className:`muted text-label`,style:{margin:`2px 0 6px`},children:t(`models.nativeHint`)}),n.length>lr/2&&(0,S.jsx)(`input`,{className:`input`,style:{width:`100%`,marginBottom:6},placeholder:t(`models.search`),value:o[e]??``,onChange:t=>s(n=>({...n,[e]:t.target.value})),"aria-label":t(`models.search`)}),_.map(e=>{let n=i.has(e.namespaced);return(0,S.jsxs)(`div`,{className:`row`,style:{padding:`5px 0`},children:[(0,S.jsx)(ke,{on:!n,onClick:()=>he(e.namespaced),disabled:k,label:e.native?e.id:e.namespaced}),(0,S.jsx)(`code`,{className:`mono text-control`,style:{color:n?`var(--faint)`:`var(--text)`,textDecoration:n?`line-through`:`none`},children:e.native?rr(e.id):e.namespaced}),e.contextCapped&&(0,S.jsx)(`span`,{className:`muted mono text-caption`,style:{padding:`1px 6px`,border:`1px solid var(--border)`,borderRadius:`var(--radius-pill)`},children:t(`models.contextCappedValue`,{value:ur(e.contextCap??f)})})]},e.namespaced)}),v>0&&(0,S.jsx)(`button`,{type:`button`,onClick:()=>l(t=>({...t,[e]:g+lr})),className:`btn btn-ghost btn-sm`,style:{marginTop:4},children:t(`models.showMore`,{n:v})})]})]},e)}),pe.length===0&&(0,S.jsx)(Ae,{icon:(0,S.jsx)(E,{}),title:t(`models.noRouted`),children:t(`models.noRoutedHint`)}),ie&&(0,S.jsx)(`div`,{className:`modal-overlay`,role:`dialog`,"aria-modal":`true`,"aria-label":t(`models.v2Label`),onClick:()=>ae(!1),onKeyDown:e=>{e.key===`Escape`&&ae(!1)},children:(0,S.jsxs)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`modal-head`,children:[(0,S.jsx)(`h3`,{children:t(`models.v2Label`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>ae(!1),"aria-label":t(`common.close`),children:`×`})]}),(0,S.jsx)(`div`,{className:`modal-desc leading-relaxed`,style:{whiteSpace:`pre-line`},children:t(`models.v2Help`)}),(0,S.jsx)(`div`,{style:{marginTop:12},children:(0,S.jsx)(`a`,{className:`text-control`,href:`https://lidge-jun.github.io/opencodex/guides/sub-agent-surface/`,target:`_blank`,rel:`noreferrer`,style:{color:`var(--accent)`},children:t(`models.v2DocsLink`)})}),(0,S.jsx)(`div`,{className:`modal-actions`,children:(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>ae(!1),children:t(`common.ok`)})})]})})]})}var mr=[`low`,`medium`,`high`,`xhigh`,`max`,`ultra`],hr=`medium`,gr=/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;function _r(e){return gr.test(e.trim())}function vr(e){return`combo/${e.trim()}`}function yr(e){return e===`round-robin`?`round-robin`:`failover`}function br(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1&&e<=100?e:1}function xr(e){return typeof e==`string`&&mr.includes(e)?e:hr}function Sr(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1&&e<=1e4?e:void 0}function Cr(e){if(!e||typeof e!=`object`)return[];let t=e.combos;if(!Array.isArray(t))return[];let n=[];for(let e of t){if(!e||typeof e!=`object`)continue;let t=e,r=typeof t.id==`string`?t.id.trim():``;if(!r)continue;let i=Array.isArray(t.targets)?t.targets:[],a=[];for(let e of i){if(!e||typeof e!=`object`)continue;let t=e,n=typeof t.provider==`string`?t.provider.trim():``,r=typeof t.model==`string`?t.model.trim():``;if(!n||!r)continue;let i=Sr(t.weight);a.push(i===void 0?{provider:n,model:r}:{provider:n,model:r,weight:i})}n.push({id:r,model:typeof t.model==`string`&&t.model.trim()?t.model.trim():vr(r),strategy:yr(t.strategy),stickyLimit:br(t.stickyLimit),defaultEffort:xr(t.defaultEffort),targets:a})}return n.sort((e,t)=>e.id.localeCompare(t.id,void 0,{sensitivity:`base`}))}function wr(e){let t=[],n=[];for(let r of e)r.strategy===`round-robin`?n.push(r):t.push(r);return{failover:t,roundRobin:n}}function Tr(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>e.id.toLowerCase().includes(n)||e.model.toLowerCase().includes(n)?!0:e.targets.some(e=>e.provider.toLowerCase().includes(n)||e.model.toLowerCase().includes(n))):e}function Er(e){let t=[];for(let n of e)n.targets.length===0?t.push({id:n.id,model:n.model,reason:`empty-targets`}):n.targets.length<2&&t.push({id:n.id,model:n.model,reason:`few-targets`});return t}function Dr(e,t){return e.id!==t.id||e.strategy!==t.strategy||e.stickyLimit!==t.stickyLimit||e.defaultEffort!==t.defaultEffort||e.targets.length!==t.targets.length?!1:e.targets.every((e,n)=>{let r=t.targets[n];return e.provider===r.provider&&e.model===r.model&&(e.weight??1)===(r.weight??1)})}function Or(e){return{id:e.id.trim(),combo:{targets:e.targets.map(t=>e.strategy===`round-robin`?{provider:t.provider.trim(),model:t.model.trim(),weight:t.weight??1}:{provider:t.provider.trim(),model:t.model.trim()}),strategy:e.strategy,defaultEffort:e.defaultEffort,...e.strategy===`round-robin`?{stickyLimit:e.stickyLimit}:{}}}}function kr(e,t){let n=e.id.trim();if(!n)return`missingId`;if(!_r(n))return`invalidId`;if(t.isCreate&&t.existingIds.includes(n))return`duplicateId`;if(Object.hasOwn(t.providers,`combo`))return`reservedNamespace`;if(Object.hasOwn(t.providers,n))return`providerCollision`;if(e.targets.length<1)return`noTargets`;for(let n of e.targets){if(!n.provider.trim()||!n.model.trim())return`incompleteTarget`;if(!Object.hasOwn(t.providers,n.provider.trim()))return`unknownProvider`}let r=new Set;for(let t of e.targets){let e=`${t.provider.trim()}/${t.model.trim()}`;if(r.has(e))return`duplicateTarget`;r.add(e)}if(e.strategy===`round-robin`){if(!Number.isInteger(e.stickyLimit)||e.stickyLimit<1||e.stickyLimit>100)return`invalidStickyLimit`;for(let t of e.targets){let e=t.weight??1;if(!Number.isInteger(e)||e<1||e>1e4)return`invalidWeight`}}return e.targets.some(e=>t.providers[e.provider.trim()]?.disabled!==!0)?null:`noEnabledTarget`}function Ar(e=``){return{id:e,model:e?vr(e):`combo/`,strategy:`failover`,stickyLimit:1,defaultEffort:hr,targets:[{provider:``,model:``}]}}function jr(e){return e.filter(e=>!e.disabled&&!e.hiddenFromPicker).sort((e,t)=>e.name.localeCompare(t.name))}function Mr(e){if(!e)return!1;let t=e.name.toLowerCase();if(t!==`openai`&&t!==`chatgpt`||(e.authMode??``).toLowerCase()!==`forward`||(e.adapter??``).toLowerCase()!==`openai-responses`)return!1;let n=(e.baseUrl??``).replace(/\/+$/,``);return!n||n.includes(`chatgpt.com/backend-api/codex`)}function Nr(e,t,n){let r=new Set([t]),i=n.find(e=>e.name===t);(t.toLowerCase()===`chatgpt`||Mr(i))&&r.add(`openai`);let a=e.filter(e=>r.has(e.provider)).map(e=>e.id).filter(Boolean);return[...new Set(a)].sort((e,t)=>e.localeCompare(t))}function Pr({value:e,onChange:t,disabled:n}){let r=U();return(0,S.jsx)(`div`,{className:`cwi-strategy-seg`,role:`radiogroup`,"aria-label":r(`cws.strategy`),children:[[`failover`,`cws.strategy.failover`],[`round-robin`,`cws.strategy.roundRobin`]].map(([i,a])=>(0,S.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":e===i,className:`btn btn-sm${e===i?` btn-primary`:` btn-ghost`}`,disabled:n,onClick:()=>t(i),children:r(a)},i))})}function Fr({id:e,value:t,onChange:n,disabled:r}){return(0,S.jsx)(`select`,{id:e,className:`input`,value:t,disabled:r,"aria-label":U()(`cws.field.defaultEffort`),onChange:e=>n(e.target.value),children:mr.map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))})}function Ir({targets:e,strategy:t,providers:n,models:r,onChange:i}){let a=U(),o=jr(n),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(null),d=(t,n)=>{i(e.map((e,r)=>r===t?{...e,...n}:e))},f=(t,n)=>{if(t===n||t<0||n<0||t>=e.length||n>=e.length)return;let r=[...e],[a]=r.splice(t,1);r.splice(n,0,a),i(r)};return(0,S.jsxs)(`div`,{className:`cwi-target-list`,children:[e.map((p,m)=>{let h=n.find(e=>e.name===p.provider),g=h&&!o.some(e=>e.name===p.provider)?[...o,h]:o,_=Nr(r,p.provider,n),v=p.model&&!_.includes(p.model)?[p.model,..._]:_,y=!p.provider;return(0,S.jsxs)(`div`,{className:[`cwi-target-row`,t===`failover`?`cwi-target-row--failover`:``,s===m?`cwi-target-row--dragging`:``,l===m&&s!==null&&s!==m?`cwi-target-row--drop`:``].filter(Boolean).join(` `),onDragOver:e=>{s!==null&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,l!==m&&u(m))},onDrop:e=>{e.preventDefault(),s!==null&&f(s,m),c(null),u(null)},onDragEnd:()=>{c(null),u(null)},children:[(0,S.jsx)(`button`,{type:`button`,className:`cwi-target-grip`,draggable:!0,"aria-label":a(`cws.target.drag`),title:a(`cws.target.drag`),onDragStart:e=>{c(m),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,String(m))},children:(0,S.jsx)(me,{width:14,height:14,"aria-hidden":`true`})}),(0,S.jsxs)(`select`,{className:`input`,value:p.provider,"aria-label":a(`cws.target.provider`),onChange:e=>{let t=e.target.value;d(m,{provider:t,model:Nr(r,t,n)[0]??``})},children:[(0,S.jsx)(`option`,{value:``,children:a(`cws.target.pickProvider`)}),g.map(e=>(0,S.jsx)(`option`,{value:e.name,children:e.disabled?a(`cws.target.disabled`,{name:e.name}):e.name},e.name))]}),(0,S.jsxs)(`select`,{className:`input`,value:p.model,disabled:y,"aria-label":a(`cws.target.model`),onChange:e=>d(m,{model:e.target.value}),children:[(0,S.jsx)(`option`,{value:``,children:y?a(`cws.target.pickProviderFirst`):v.length===0?a(`cws.target.noModels`):a(`cws.target.pickModel`)}),v.map(e=>(0,S.jsx)(`option`,{value:e,children:e},e))]}),t===`round-robin`&&(0,S.jsx)(`input`,{className:`input mono`,type:`number`,min:1,max:1e4,value:p.weight??1,"aria-label":a(`cws.target.weight`),onChange:e=>d(m,{weight:Number(e.target.value)})}),(0,S.jsx)(`div`,{className:`cwi-target-actions`,children:(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:e.length<=1,onClick:()=>i(e.filter((e,t)=>t!==m)),"aria-label":a(`common.remove`),children:(0,S.jsx)(F,{width:14,height:14})})})]},m)}),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,style:{alignSelf:`flex-start`},onClick:()=>i([...e,{provider:``,model:``}]),children:[(0,S.jsx)(P,{width:14,height:14}),` `,a(`cws.target.add`)]})]})}function Lr({model:e,onCancel:t,onConfirm:n}){let r=U();return(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),t())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,S.jsx)(`div`,{className:`modal-overlay`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`cwi-remove-title`,onClick:t,children:(0,S.jsxs)(`div`,{className:`modal-card pwi-remove-confirm-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsx)(`h3`,{id:`cwi-remove-title`,className:`pwi-remove-confirm-title`,children:r(`cws.removeConfirmTitle`,{model:e})}),(0,S.jsx)(`p`,{className:`muted pwi-remove-confirm-desc`,children:r(`cws.removeConfirmDesc`)}),(0,S.jsxs)(`div`,{className:`pwi-remove-confirm-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:t,children:r(`common.cancel`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn pwi-remove-confirm-danger`,onClick:n,children:r(`common.remove`)})]})]})})}function Rr({onKeep:e,onDiscard:t}){let n=U();return(0,S.jsx)(`div`,{className:`modal-overlay`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`cwi-unsaved-title`,onClick:e,children:(0,S.jsxs)(`div`,{className:`modal-card pwi-json-unsaved-card`,onClick:e=>e.stopPropagation(),children:[(0,S.jsx)(`h3`,{id:`cwi-unsaved-title`,className:`pwi-json-unsaved-title`,children:n(`cws.unsavedTitle`)}),(0,S.jsx)(`p`,{className:`muted pwi-json-unsaved-desc`,children:n(`cws.unsavedDesc`)}),(0,S.jsxs)(`div`,{className:`pwi-json-unsaved-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:e,children:n(`cws.keepEditing`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-danger`,onClick:t,children:n(`common.discard`)})]})]})})}function zr({existingIds:e,providerMap:t,providers:n,models:r,onClose:i,onSubmit:a}){let o=U(),[s,c]=(0,_.useState)(()=>Ar()),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(``);(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!l&&(e.preventDefault(),i())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l,i]);let p=async()=>{let n=kr(s,{existingIds:e,isCreate:!0,providers:t});if(n){f(o(`cws.err.${n}`));return}u(!0),f(``);let r=await a({...s,id:s.id.trim(),model:vr(s.id.trim())});if(u(!1),!r.ok){f(r.error||o(`cws.saveFailed`));return}};return(0,S.jsx)(`div`,{className:`modal-overlay`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`cwi-add-title`,onClick:()=>{l||i()},children:(0,S.jsxs)(`div`,{className:`modal-card`,style:{width:`min(560px, 94vw)`},onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`row`,style:{justifyContent:`space-between`,marginBottom:8},children:[(0,S.jsx)(`h3`,{id:`cwi-add-title`,style:{margin:0},children:o(`cws.addTitle`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:i,disabled:l,"aria-label":o(`common.close`),children:(0,S.jsx)(N,{width:16,height:16})})]}),(0,S.jsx)(`p`,{className:`muted`,style:{marginTop:0},children:o(`cws.addSubtitle`)}),d&&(0,S.jsx)(W,{tone:`err`,children:d}),(0,S.jsxs)(`div`,{className:`cwi-modal-form`,children:[(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{htmlFor:`cwi-new-id`,children:o(`cws.field.id`)}),(0,S.jsx)(`input`,{id:`cwi-new-id`,className:`input mono`,value:s.id,placeholder:o(`cws.field.idPlaceholder`),disabled:l,onChange:e=>c(t=>({...t,id:e.target.value,model:vr(e.target.value)}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`4px 0 0`},children:o(`cws.field.idHint`,{model:s.id.trim()?vr(s.id.trim()):`combo/…`})})]}),(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{children:o(`cws.strategy`)}),(0,S.jsx)(Pr,{value:s.strategy,disabled:l,onChange:e=>c(t=>({...t,strategy:e}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`6px 0 0`},children:s.strategy===`failover`?o(`cws.strategy.failoverHint`):o(`cws.strategy.roundRobinHint`)})]}),(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{htmlFor:`cwi-new-effort`,children:o(`cws.field.defaultEffort`)}),(0,S.jsx)(Fr,{id:`cwi-new-effort`,value:s.defaultEffort,disabled:l,onChange:e=>c(t=>({...t,defaultEffort:e}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`4px 0 0`},children:o(`cws.field.defaultEffortHint`)})]}),s.strategy===`round-robin`&&(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{htmlFor:`cwi-new-sticky`,children:o(`cws.field.stickyLimit`)}),(0,S.jsx)(`input`,{id:`cwi-new-sticky`,className:`input mono`,type:`number`,min:1,max:100,value:s.stickyLimit,disabled:l,onChange:e=>c(t=>({...t,stickyLimit:Number(e.target.value)}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`4px 0 0`},children:o(`cws.field.stickyLimitHint`)})]}),(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{children:o(`cws.targets`)}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`0 0 8px`},children:s.strategy===`failover`?o(`cws.targets.failoverHint`):o(`cws.targets.roundRobinHint`)}),(0,S.jsx)(Ir,{targets:s.targets,strategy:s.strategy,providers:n,models:r,onChange:e=>c(t=>({...t,targets:e}))})]})]}),(0,S.jsxs)(`div`,{className:`cwi-modal-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:i,disabled:l,children:o(`common.cancel`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:()=>{p()},disabled:l,children:o(l?`common.saving`:`cws.create`)})]})]})})}function Br({combos:e,onSelect:t,onAdd:n}){let r=U(),i=wr(e),a=Er(e);return(0,S.jsxs)(`div`,{className:`combos-workspace-overview`,children:[(0,S.jsxs)(`div`,{className:`combos-workspace-overview-head`,children:[(0,S.jsx)(`h2`,{className:`combos-workspace-overview-title`,children:r(`cws.overviewTitle`)}),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:n,children:[(0,S.jsx)(P,{width:14,height:14}),` `,r(`cws.add`)]})]}),(0,S.jsx)(`p`,{className:`muted`,style:{marginTop:0,maxWidth:`62ch`},children:r(`cws.overviewBlurb`)}),(0,S.jsxs)(`div`,{className:`cwi-count-strip`,children:[(0,S.jsxs)(`div`,{className:`cwi-count-pill`,children:[(0,S.jsx)(`strong`,{children:e.length}),(0,S.jsx)(`span`,{children:r(`cws.count.total`)})]}),(0,S.jsxs)(`div`,{className:`cwi-count-pill`,children:[(0,S.jsx)(`strong`,{children:i.failover.length}),(0,S.jsx)(`span`,{children:r(`cws.count.failover`)})]}),(0,S.jsxs)(`div`,{className:`cwi-count-pill`,children:[(0,S.jsx)(`strong`,{children:i.roundRobin.length}),(0,S.jsx)(`span`,{children:r(`cws.count.roundRobin`)})]})]}),(0,S.jsxs)(`section`,{className:`pwi-section`,"aria-label":r(`cws.howTitle`),children:[(0,S.jsx)(`h3`,{className:`pwi-section-title`,children:r(`cws.howTitle`)}),(0,S.jsx)(`p`,{className:`muted`,style:{margin:0},children:r(`cws.howBody`)})]}),a.length>0&&(0,S.jsxs)(`section`,{className:`pwi-section`,"aria-label":r(`cws.attentionTitle`),children:[(0,S.jsx)(`h3`,{className:`pwi-section-title`,children:r(`cws.attentionTitle`)}),(0,S.jsx)(`div`,{className:`cwi-attention-list`,children:a.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`cwi-attention-row`,onClick:()=>t(e.id),children:[(0,S.jsx)(I,{width:14,height:14,"aria-hidden":`true`}),(0,S.jsx)(`code`,{className:`chip`,children:e.model}),(0,S.jsx)(`span`,{className:`muted`,children:e.reason===`empty-targets`?r(`cws.attention.empty`):r(`cws.attention.few`)}),(0,S.jsx)(z,{width:14,height:14,style:{marginLeft:`auto`},"aria-hidden":`true`})]},e.id))})]})]})}function Vr({onAdd:e}){let t=U();return(0,S.jsx)(`div`,{className:`combos-workspace-empty-root`,children:(0,S.jsxs)(`button`,{type:`button`,className:`cwi-empty-cta`,onClick:e,children:[(0,S.jsx)(`span`,{className:`pwi-empty-right-icon`,"aria-hidden":`true`,children:(0,S.jsx)(pe,{style:{width:64,height:64}})}),(0,S.jsx)(`span`,{className:`cwi-empty-cta-title`,children:t(`cws.emptyTitle`)}),(0,S.jsx)(`span`,{className:`pwi-empty-right-sub`,children:t(`cws.empty.createDesc`)})]})})}function Hr({baseline:e,providerMap:t,providers:n,models:r,onBack:i,onSaved:a,onRequestRemove:o,onSave:s,onDirtyChange:c}){let l=U(),[u,d]=(0,_.useState)(`config`),[f,p]=(0,_.useState)(e),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(!1),x=!Dr(f,e);(0,_.useEffect)(()=>{let t=window.setTimeout(()=>{p(e),v(null),d(`config`)},0);return()=>window.clearTimeout(t)},[`${e.id}:${e.strategy}:${e.stickyLimit}:${e.defaultEffort}:${e.targets.map(e=>`${e.provider}/${e.model}:${e.weight??1}`).join(`,`)}`]),(0,_.useEffect)(()=>{c(x)},[x,c]);let C=async()=>{try{await navigator.clipboard.writeText(e.model),b(!0),window.setTimeout(()=>b(!1),1200)}catch{}},w=async()=>{let e=kr(f,{existingIds:[],isCreate:!1,providers:t});if(e){v({ok:!1,text:l(`cws.err.${e}`)});return}h(!0);let n=await s(f,!1);if(h(!1),!n.ok){v({ok:!1,text:n.error||l(`cws.saveFailed`)});return}v({ok:!0,text:l(`cws.saved`)}),a(f)};return(0,S.jsxs)(`div`,{className:`combos-workspace-detail`,children:[(0,S.jsxs)(`div`,{className:`combos-workspace-detail-head`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm pwi-back-overview`,onClick:i,"aria-label":l(`cws.backToAll`),children:[(0,S.jsx)(z,{style:{width:14,height:14,transform:`rotate(180deg)`},"aria-hidden":`true`}),l(`cws.allCombos`)]}),(0,S.jsx)(`h2`,{className:`combos-workspace-detail-title`,children:e.model}),(0,S.jsx)(`button`,{type:`button`,className:`chip cwi-copy-chip`,onClick:()=>{C()},title:l(`cws.copyModel`),children:l(y?`cws.copied`:`cws.copyModel`)}),(0,S.jsxs)(`div`,{className:`combos-workspace-detail-actions`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:o,children:[(0,S.jsx)(F,{width:14,height:14}),` `,l(`common.remove`)]}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,disabled:!x||m,onClick:()=>{w()},children:l(m?`common.saving`:`common.save`)})]})]}),g&&(0,S.jsx)(W,{tone:g.ok?`ok`:`err`,children:g.text}),(0,S.jsxs)(`div`,{className:`combos-workspace-tabs`,role:`tablist`,children:[(0,S.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`config`,className:`combos-workspace-tab${u===`config`?` combos-workspace-tab--active`:``}`,onClick:()=>d(`config`),children:l(`cws.tab.config`)}),(0,S.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":u===`about`,className:`combos-workspace-tab${u===`about`?` combos-workspace-tab--active`:``}`,onClick:()=>d(`about`),children:l(`cws.tab.about`)})]}),(0,S.jsx)(`div`,{className:`combos-workspace-tab-content`,role:`tabpanel`,children:u===`config`?(0,S.jsxs)(`div`,{className:`cwi-form-grid`,children:[(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{children:l(`cws.strategy`)}),(0,S.jsx)(Pr,{value:f.strategy,disabled:m,onChange:e=>p(t=>({...t,strategy:e}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`6px 0 0`},children:f.strategy===`failover`?l(`cws.strategy.failoverHint`):l(`cws.strategy.roundRobinHint`)})]}),(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{htmlFor:`cwi-effort`,children:l(`cws.field.defaultEffort`)}),(0,S.jsx)(Fr,{id:`cwi-effort`,value:f.defaultEffort,disabled:m,onChange:e=>p(t=>({...t,defaultEffort:e}))}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`4px 0 0`},children:l(`cws.field.defaultEffortHint`)})]}),f.strategy===`round-robin`&&(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{htmlFor:`cwi-sticky`,children:l(`cws.field.stickyLimit`)}),(0,S.jsx)(`input`,{id:`cwi-sticky`,className:`input mono`,type:`number`,min:1,max:100,value:f.stickyLimit,disabled:m,onChange:e=>p(t=>({...t,stickyLimit:Number(e.target.value)}))})]}),(0,S.jsxs)(`div`,{className:`cwi-field`,children:[(0,S.jsx)(`label`,{children:l(`cws.targets`)}),(0,S.jsx)(`p`,{className:`muted`,style:{fontSize:12,margin:`0 0 8px`},children:f.strategy===`failover`?l(`cws.targets.failoverHint`):l(`cws.targets.roundRobinHint`)}),(0,S.jsx)(Ir,{targets:f.targets,strategy:f.strategy,providers:n,models:r,onChange:e=>p(t=>({...t,targets:e}))})]})]}):(0,S.jsxs)(`section`,{className:`pwi-section`,children:[(0,S.jsx)(`h3`,{className:`pwi-section-title`,children:l(`cws.aboutTitle`)}),(0,S.jsx)(`p`,{className:`muted`,style:{margin:0},children:l(`cws.aboutBody`)})]})})]})}function Ur({combos:e,providers:t,models:n,loading:r,onRefresh:i,onSave:a,onRemove:o,onAdd:s,adding:c,onCloseAdd:l,onCreated:u}){let d=U(),f=(0,_.useMemo)(()=>Object.fromEntries(t.map(e=>[e.name,{disabled:e.disabled}])),[t]),[p,m]=(0,_.useState)(``),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(void 0),[b,x]=(0,_.useState)(null),[C,w]=(0,_.useState)(null),T=(0,_.useMemo)(()=>Tr(e,p),[e,p]),E=(0,_.useMemo)(()=>wr(T),[T]),D=h&&e.some(e=>e.id===h)?h:null,O=e.find(e=>e.id===D)??null,k=O&&C?.id===O.id?C:O,[A,j]=(0,_.useState)(!1),M=(0,_.useCallback)(e=>{if(e!==D){if(!A){g(e),w(null);return}y(e)}},[D,A]),N=()=>{v!==void 0&&(g(v),w(null),j(!1),y(void 0))},ee=()=>y(void 0),F=v!==void 0&&A;return!r&&e.length===0?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Vr,{onAdd:s}),c&&(0,S.jsx)(zr,{existingIds:e.map(e=>e.id),providerMap:f,providers:t,models:n,onClose:l,onSubmit:async e=>{let t=await a(e,!0);return t.ok&&(l(),u(e.id),g(e.id)),t}})]}):(0,S.jsxs)(`div`,{className:`combos-workspace-root`,children:[(0,S.jsxs)(`aside`,{className:`combos-workspace-rail`,"aria-label":d(`cws.railAria`),children:[(0,S.jsxs)(`div`,{className:`combos-workspace-rail-header`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`div`,{className:`combos-workspace-rail-title`,children:d(`nav.combos`)}),(0,S.jsx)(`div`,{className:`combos-workspace-rail-count`,children:e.length})]}),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:s,"aria-label":d(`cws.add`),children:[(0,S.jsx)(P,{width:14,height:14}),` `,d(`cws.add`)]})]}),(0,S.jsx)(`div`,{className:`cwi-search-row`,children:(0,S.jsxs)(`div`,{className:`cwi-search-wrap`,children:[(0,S.jsx)(te,{className:`cwi-search-icon`,"aria-hidden":`true`}),(0,S.jsx)(`input`,{className:`input cwi-search-input`,value:p,onChange:e=>m(e.target.value),placeholder:d(`cws.searchPlaceholder`),"aria-label":d(`cws.searchPlaceholder`)})]})}),(0,S.jsx)(`div`,{className:`combos-workspace-rail-list`,children:T.length===0?(0,S.jsx)(`p`,{className:`muted`,style:{padding:`16px`},children:d(`cws.noSearchResults`)}):(0,S.jsx)(S.Fragment,{children:[[`failover`,E.failover,`cws.group.failover`],[`round-robin`,E.roundRobin,`cws.group.roundRobin`]].map(([e,t,n])=>t.length>0?(0,S.jsxs)(`div`,{className:`combos-workspace-rail-group`,children:[(0,S.jsxs)(`div`,{className:`combos-workspace-rail-group-head`,children:[(0,S.jsx)(`span`,{className:`pwi-dot`,"aria-hidden":`true`}),d(n),(0,S.jsx)(`span`,{className:`combos-workspace-rail-count`,children:t.length})]}),t.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`combos-workspace-rail-row${D===e.id?` combos-workspace-rail-row--selected`:``}`,onClick:()=>M(e.id),"aria-current":D===e.id?`true`:void 0,children:[(0,S.jsx)(`span`,{className:`combos-workspace-rail-icon`,"aria-hidden":`true`,children:(0,S.jsx)(pe,{width:16,height:16})}),(0,S.jsx)(`span`,{className:`combos-workspace-rail-name`,children:e.model}),(0,S.jsx)(`span`,{className:`combos-workspace-rail-meta`,children:e.targets.length===1?d(`cws.targetCountOne`):d(`cws.targetCount`,{count:e.targets.length})}),(0,S.jsx)(z,{className:`combos-workspace-rail-chevron`,"aria-hidden":`true`})]},e.id))]},e):null)})})]}),(0,S.jsx)(`div`,{className:`combos-workspace-main`,children:k?(0,S.jsx)(Hr,{baseline:k,providerMap:f,providers:t,models:n,onBack:()=>M(null),onSaved:e=>{w(e),j(!1),i()},onRequestRemove:()=>x(k.id),onSave:a,onDirtyChange:j},k.id):(0,S.jsx)(Br,{combos:e,onSelect:e=>M(e),onAdd:s})}),c&&(0,S.jsx)(zr,{existingIds:e.map(e=>e.id),providerMap:f,providers:t,models:n,onClose:l,onSubmit:async e=>{let t=await a(e,!0);return t.ok&&(l(),u(e.id),g(e.id),w(null)),t}}),b&&(0,S.jsx)(Lr,{model:vr(b),onCancel:()=>x(null),onConfirm:()=>{(async()=>{let e=await o(b);x(null),e.ok&&(D===b&&(g(null),w(null)),i())})()}}),F&&(0,S.jsx)(Rr,{onKeep:ee,onDiscard:N})]})}function Wr(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e.error;return typeof t==`string`&&t.trim()?t:void 0}function Gr(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&e.success===!0}function Kr({apiBase:e}){let t=U(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(!0),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(!1),g=(e,t)=>{d(e),p(t)};(0,_.useEffect)(()=>{if(!u||!f)return;let e=window.setTimeout(()=>{d(``),p(!1)},5e3);return()=>window.clearTimeout(e)},[u,f]);let v=(0,_.useCallback)(async()=>{try{let[t,n,i]=await Promise.all([fetch(`${e}/api/combos`),fetch(`${e}/api/config`),fetch(`${e}/api/models`)]);if(!t.ok||!n.ok||!i.ok)throw Error(`combo workspace load failed`);let o=await t.json(),c=await n.json(),l=await i.json(),u=Array.isArray(l)?l:Array.isArray(l?.models)?l.models:[];r(Cr(o));let d=c.providers??{},f=ot(d);a(Object.entries(d).map(([e,t])=>({name:e,disabled:!!t.disabled,hiddenFromPicker:!Object.hasOwn(f,e),authMode:t.authMode,adapter:t.adapter,baseUrl:t.baseUrl})));let p=[];for(let e of u){if(!e||typeof e!=`object`)continue;let t=e;if(typeof t.provider!=`string`||typeof t.id!=`string`)continue;let n=t.provider.trim(),r=t.id.trim();!n||!r||n===`combo`||t.disabled!==!0&&p.push({provider:n,id:r,namespaced:typeof t.namespaced==`string`?t.namespaced:void 0})}for(let[e,t]of Object.entries(c.providers??{})){let n=typeof t.defaultModel==`string`?t.defaultModel.trim():``;!n||t.disabled||p.some(t=>t.provider===e&&t.id===n)||p.push({provider:e,id:n,namespaced:`${e}/${n}`})}s(p)}catch{g(t(`cws.loadFailed`),!1)}finally{l(!1)}},[e,t]);return(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{v()},0);return()=>window.clearTimeout(e)},[v]),c&&n.length===0?(0,S.jsxs)(`div`,{className:`combos-workspace-shell`,children:[u&&(0,S.jsx)(`div`,{className:`combos-workspace-shell-banner`,children:(0,S.jsx)(W,{tone:f?`ok`:`err`,children:u})}),(0,S.jsx)(`div`,{className:`muted`,style:{padding:`24px 20px`},role:`status`,children:u?null:t(`cws.loading`)})]}):(0,S.jsxs)(`div`,{className:`combos-workspace-shell`,children:[u&&(0,S.jsx)(`div`,{className:`combos-workspace-shell-banner`,children:(0,S.jsx)(W,{tone:f?`ok`:`err`,children:u})}),(0,S.jsx)(`div`,{className:`combos-workspace-shell-body`,children:(0,S.jsx)(Ur,{combos:n,providers:i,models:o,loading:c,onRefresh:()=>{v()},onSave:async(n,r)=>{try{let i=await fetch(`${e}/api/combos`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify(Or(n))}),a=await i.json(),o=Wr(a);if(!i.ok||o||!Gr(a)){let e=o||t(`cws.saveFailed`);return g(e,!1),{ok:!1,error:e}}return await v(),g(r?t(`cws.created`,{model:n.model}):t(`cws.saved`),!0),{ok:!0}}catch{let e=t(`cws.saveFailed`);return g(e,!1),{ok:!1,error:e}}},onRemove:async n=>{try{let r=await fetch(`${e}/api/combos?id=${encodeURIComponent(n)}`,{method:`DELETE`}),i=await r.json(),a=Wr(i);if(!r.ok||a||!Gr(i)){let e=a||t(`cws.removeFailed`);return g(e,!1),{ok:!1,error:e}}return await v(),g(t(`cws.removed`,{id:n}),!0),{ok:!0}}catch{let e=t(`cws.removeFailed`);return g(e,!1),{ok:!1,error:e}}},onAdd:()=>h(!0),adding:m,onCloseAdd:()=>h(!1),onCreated:()=>{v()}})})]})}function qr({apiBase:e}){let t=U(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(!0),m=(0,_.useMemo)(()=>new Set(i),[i]),h=(0,_.useCallback)(async()=>{try{let t=await fetch(`${e}/api/subagent-models`).then(e=>e.json()),n=t.available??[],i=new Set(n);r(n),a((t.chosen??[]).filter(e=>i.has(e)))}catch{d(!1),l(t(`sub.loadFail`))}finally{p(!1)}},[e,t]);(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{h()},0);return()=>window.clearTimeout(e)},[h]);let g=e=>{l(``),a(t=>t.includes(e)?t.filter(t=>t!==e):t.length>=5?t:[...t,e])},v=(e,t)=>{a(n=>{let r=[...n],i=e+t;return i<0||i>=r.length?n:([r[e],r[i]]=[r[i],r[e]],r)})},y=async()=>{l(``);try{let n=await fetch(`${e}/api/subagent-models`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({models:i})}),r=await n.json();d(n.ok),l(n.ok?t(`sub.saved`,{n:r.applied?.length??0,cmd:`ocx sync`}):r.error||t(`sub.saveFailed`))}catch{d(!1),l(t(`sub.networkError`))}},b=(0,_.useMemo)(()=>{let e=o.trim().toLowerCase();return n.filter(t=>!e||t.toLowerCase().includes(e))},[n,o]);return f?(0,S.jsx)(`div`,{className:`muted`,style:{padding:8},children:t(`sub.loading`)}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h2`,{children:t(`nav.subagents`)})}),(0,S.jsx)(`p`,{className:`page-sub`,children:(0,S.jsx)(Te,{k:`sub.subtitle`,cmd:`spawn_agent`})}),c&&(0,S.jsx)(W,{tone:u?`ok`:`err`,children:c}),(0,S.jsxs)(`div`,{className:`h-section`,children:[t(`sub.featured`),` `,(0,S.jsxs)(`span`,{className:`count`,children:[i.length,`/5`]})]}),(0,S.jsxs)(`div`,{className:`row muted text-label leading-body`,style:{alignItems:`flex-start`,gap:8,margin:`-2px 0 10px`,maxWidth:`80ch`},children:[(0,S.jsx)(L,{width:15,height:15,"aria-hidden":`true`,style:{flexShrink:0,marginTop:2}}),(0,S.jsx)(`span`,{children:(0,S.jsx)(Te,{k:`sub.orderHint`,cmd:`spawn_agent`})})]}),i.length===0?(0,S.jsx)(Ae,{title:t(`sub.noneSelected`)}):(0,S.jsx)(`div`,{className:`stack`,style:{gap:8},children:i.map((e,n)=>(0,S.jsxs)(`div`,{className:`card panel-accent row`,style:{padding:`8px 12px`,gap:10},children:[(0,S.jsx)(`span`,{className:`mono font-bold`,style:{width:18,color:`var(--accent)`},children:n+1}),(0,S.jsx)(`code`,{className:`mono`,style:{flex:1,color:`var(--text)`},children:rr(e)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon btn-sm`,onClick:()=>v(n,-1),disabled:n===0,"aria-label":t(`sub.moveUp`,{m:e}),children:(0,S.jsx)(ne,{})}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon btn-sm`,onClick:()=>v(n,1),disabled:n===i.length-1,"aria-label":t(`sub.moveDown`,{m:e}),children:(0,S.jsx)(R,{})}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon btn-sm`,onClick:()=>g(e),"aria-label":t(`sub.removeAria`,{m:e}),style:{color:`var(--red)`},children:(0,S.jsx)(N,{})})]},e))}),(0,S.jsx)(`div`,{style:{marginTop:14},children:(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:y,children:t(`common.save`)})}),(0,S.jsxs)(`div`,{className:`h-section`,children:[t(`sub.models`),` `,(0,S.jsx)(`span`,{className:`count`,children:b.length})]}),(0,S.jsxs)(`div`,{className:`row`,style:{marginBottom:10,gap:8},children:[(0,S.jsx)(te,{width:15,height:15,"aria-hidden":`true`,style:{color:`var(--faint)`,flexShrink:0}}),(0,S.jsx)(`input`,{className:`input`,value:o,onChange:e=>s(e.target.value),placeholder:t(`sub.search`),"aria-label":t(`sub.search`),style:{flex:1}})]}),(0,S.jsxs)(`div`,{className:`stack`,style:{gap:6,maxHeight:360,overflowY:`auto`},children:[b.map(e=>{let t=m.has(e),n=!t&&i.length>=5;return(0,S.jsxs)(`button`,{type:`button`,className:`card row${t?` panel-accent`:``}`,onClick:()=>g(e),disabled:n,"aria-pressed":t,style:{width:`100%`,opacity:n?.45:1,cursor:n?`not-allowed`:`pointer`},children:[(0,S.jsx)(`span`,{style:{width:16,height:16,flexShrink:0,color:`var(--accent)`,display:`inline-flex`},children:t&&(0,S.jsx)(M,{style:{width:16,height:16}})}),(0,S.jsx)(D,{style:{width:15,height:15,color:`var(--faint)`,flexShrink:0}}),(0,S.jsx)(`code`,{className:`mono`,style:{color:`var(--text)`},children:rr(e)})]},e)}),b.length===0&&(0,S.jsx)(Ae,{title:t(`sub.noModels`)})]})]})}var Jr={400:{en:{label:`Bad request`,description:`The proxy could not understand the request. Check the model, message shape, headers, and JSON body before retrying.`},ko:{label:`잘못된 요청`,description:`프록시가 요청을 이해할 수 없습니다. 재시도 전에 모델, 메시지 형식, 헤더, JSON 본문을 확인해야 합니다.`},zh:{label:`错误请求`,description:`代理无法理解该请求。重试前请检查模型、消息结构、标头和 JSON 正文。`},de:{label:`Ungültige Anfrage`,description:`Der Proxy konnte die Anfrage nicht verstehen. Prüfe Modell, Nachrichtenformat, Header und JSON-Body vor einem erneuten Versuch.`}},401:{en:{label:`Unauthorized`,description:`Credentials are missing, expired, or invalid. Re-login or refresh the account/provider credentials used by opencodex.`},ko:{label:`인증 필요`,description:`자격 증명이 없거나 만료되었거나 유효하지 않습니다. opencodex에서 사용하는 계정 또는 제공자 자격 증명을 다시 로그인하거나 갱신해야 합니다.`},zh:{label:`未授权`,description:`凭据缺失、已过期或无效。请重新登录,或刷新 opencodex 使用的账号/提供商凭据。`},de:{label:`Nicht autorisiert`,description:`Anmeldedaten fehlen, sind abgelaufen oder ungültig. Melde dich erneut an oder aktualisiere die von opencodex genutzten Konto-/Anbieter-Zugangsdaten.`}},402:{en:{label:`Payment required`,description:`The upstream provider rejected the request because billing, credits, or plan access is not available. Add credits, update billing, or switch provider.`},ko:{label:`결제 필요`,description:`청구, 크레딧, 플랜 접근 권한 문제로 업스트림 제공자가 요청을 거부했습니다. 크레딧 추가, 결제 정보 갱신, 제공자 전환이 필요합니다.`},zh:{label:`需要付款`,description:`上游提供商因账单、额度或套餐权限不可用而拒绝了请求。请充值、更新账单信息或切换提供商。`},de:{label:`Zahlung erforderlich`,description:`Der Upstream-Anbieter hat die Anfrage abgelehnt, weil Abrechnung, Guthaben oder Planzugriff nicht verfügbar ist. Guthaben aufladen, Abrechnung aktualisieren oder Anbieter wechseln.`}},403:{en:{label:`Forbidden`,description:`The account is authenticated but not allowed to use this model or operation. Often a plan/subscription gate (e.g. Ollama Cloud Pro), org policy, or model permission — not necessarily a bad API key.`},ko:{label:`권한 없음`,description:`계정 인증은 되었지만 이 모델 또는 작업을 사용할 권한이 없습니다. 플랜/구독 제한(예: Ollama Cloud Pro), 조직 정책, 모델 권한 문제인 경우가 많으며 API 키가 잘못된 것은 아닐 수 있습니다.`},zh:{label:`禁止访问`,description:`账号已认证,但无权使用此模型或操作。常见原因是套餐/订阅限制(例如 Ollama Cloud Pro)、组织策略或模型权限——不一定是 API 密钥无效。`},de:{label:`Verboten`,description:`Das Konto ist authentifiziert, darf dieses Modell oder diese Operation aber nicht nutzen. Oft Plan-/Abo-Sperre (z. B. Ollama Cloud Pro), Organisationsrichtlinie oder Modellrecht — nicht zwingend ein ungültiger API-Key.`}},404:{en:{label:`Not found`,description:`The requested route, model, account, or upstream resource was not found. Verify the model name and opencodex provider configuration.`},ko:{label:`찾을 수 없음`,description:`요청한 경로, 모델, 계정 또는 업스트림 리소스를 찾을 수 없습니다. 모델 이름과 opencodex 제공자 설정을 확인해야 합니다.`},zh:{label:`未找到`,description:`找不到请求的路由、模型、账号或上游资源。请确认模型名称和 opencodex 提供商配置。`},de:{label:`Nicht gefunden`,description:`Die angeforderte Route, das Modell, das Konto oder die Upstream-Ressource wurde nicht gefunden. Prüfe Modellname und opencodex-Anbieterkonfiguration.`}},408:{en:{label:`Request timeout`,description:`The request took too long before the proxy or upstream provider could complete it. Retry with a smaller request or a different provider.`},ko:{label:`요청 시간 초과`,description:`프록시 또는 업스트림 제공자가 요청을 완료하기 전에 시간이 초과되었습니다. 더 작은 요청으로 재시도하거나 다른 제공자로 전환해야 합니다.`},zh:{label:`请求超时`,description:`代理或上游提供商未能在限定时间内完成请求。请缩小请求后重试,或切换提供商。`},de:{label:`Anfrage-Timeout`,description:`Die Anfrage dauerte zu lange, bevor Proxy oder Upstream-Anbieter sie abschließen konnten. Mit kleinerer Anfrage oder anderem Anbieter erneut versuchen.`}},409:{en:{label:`Conflict`,description:`The request conflicts with the current account, session, or provider state. Refresh the session or retry after the active operation finishes.`},ko:{label:`상태 충돌`,description:`요청이 현재 계정, 세션 또는 제공자 상태와 충돌합니다. 세션을 갱신하거나 진행 중인 작업이 끝난 뒤 재시도해야 합니다.`},zh:{label:`状态冲突`,description:`请求与当前账号、会话或提供商状态冲突。请刷新会话,或等待当前操作完成后重试。`},de:{label:`Konflikt`,description:`Die Anfrage kollidiert mit dem aktuellen Konto-, Sitzungs- oder Anbieterstatus. Sitzung aktualisieren oder nach Abschluss der laufenden Operation erneut versuchen.`}},413:{en:{label:`Request too large`,description:`The prompt, attachments, or generated payload exceeds a proxy or upstream limit. Reduce tokens, file size, or conversation history.`},ko:{label:`요청 과대`,description:`프롬프트, 첨부 파일 또는 생성 페이로드가 프록시나 업스트림 한도를 초과했습니다. 토큰, 파일 크기, 대화 기록을 줄여야 합니다.`},zh:{label:`请求过大`,description:`提示、附件或生成的负载超过了代理或上游限制。请减少 token、文件大小或对话历史。`},de:{label:`Anfrage zu groß`,description:`Prompt, Anhänge oder generierte Nutzlast überschreiten ein Proxy- oder Upstream-Limit. Tokens, Dateigröße oder Verlauf reduzieren.`}},422:{en:{label:`Invalid content`,description:`The provider accepted the request format but rejected its contents. Check model options, tool definitions, message roles, and unsupported fields.`},ko:{label:`내용 검증 실패`,description:`제공자가 요청 형식은 받았지만 내용을 거부했습니다. 모델 옵션, 도구 정의, 메시지 역할, 지원되지 않는 필드를 확인해야 합니다.`},zh:{label:`内容无效`,description:`提供商接受了请求格式,但拒绝了其中的内容。请检查模型选项、工具定义、消息角色和不支持的字段。`},de:{label:`Ungültiger Inhalt`,description:`Der Anbieter akzeptierte das Anfrageformat, lehnte den Inhalt aber ab. Prüfe Modelloptionen, Tool-Definitionen, Nachrichtenrollen und nicht unterstützte Felder.`}},424:{en:{label:`Provider dependency failed`,description:`A required upstream dependency failed while opencodex was routing the request. Retry later or switch to another configured provider.`},ko:{label:`제공자 의존성 실패`,description:`opencodex가 요청을 라우팅하는 동안 필요한 업스트림 의존성이 실패했습니다. 나중에 재시도하거나 다른 설정된 제공자로 전환해야 합니다.`},zh:{label:`提供商依赖失败`,description:`opencodex 路由请求时,必需的上游依赖失败。请稍后重试,或切换到另一个已配置的提供商。`},de:{label:`Anbieter-Abhängigkeit fehlgeschlagen`,description:`Eine erforderliche Upstream-Abhängigkeit ist fehlgeschlagen, während opencodex die Anfrage geroutet hat. Später erneut versuchen oder zu einem anderen Anbieter wechseln.`}},429:{en:{label:`Rate limited`,description:`The upstream provider rate or quota limit has been reached. Wait for the quota window to reset or switch account/provider.`},ko:{label:`한도 초과`,description:`업스트림 제공자의 속도 또는 할당량 한도에 도달했습니다. 한도 창이 초기화될 때까지 기다리거나 계정/제공자를 전환해야 합니다.`},zh:{label:`限流`,description:`已达到上游提供商的速率或额度限制。请等待额度窗口重置,或切换账号/提供商。`},de:{label:`Ratenlimit erreicht`,description:`Das Raten- oder Kontingentlimit des Upstream-Anbieters ist erreicht. Auf Reset des Kontingentfensters warten oder Konto/Anbieter wechseln.`}},499:{en:{label:`Client closed request`,description:`The client disconnected or canceled the request before opencodex finished routing it. Retry if the cancellation was accidental.`},ko:{label:`클라이언트 취소`,description:`opencodex가 라우팅을 끝내기 전에 클라이언트 연결이 끊기거나 요청이 취소되었습니다. 의도한 취소가 아니면 다시 시도해야 합니다.`},zh:{label:`客户端已取消`,description:`opencodex 完成路由前,客户端已断开连接或取消请求。如果不是有意取消,请重试。`},de:{label:`Client hat Anfrage geschlossen`,description:`Der Client hat die Verbindung getrennt oder die Anfrage abgebrochen, bevor opencodex das Routing abgeschlossen hat. Bei versehentlichem Abbruch erneut versuchen.`}},500:{en:{label:`Proxy error`,description:`opencodex hit an internal error while handling the request. Retry once, then check proxy logs if it repeats.`},ko:{label:`프록시 오류`,description:`opencodex가 요청을 처리하는 동안 내부 오류가 발생했습니다. 한 번 재시도하고 반복되면 프록시 로그를 확인해야 합니다.`},zh:{label:`代理错误`,description:`opencodex 处理请求时发生内部错误。请先重试一次;如果重复出现,请检查代理日志。`},de:{label:`Proxy-Fehler`,description:`opencodex ist bei der Anfragebearbeitung auf einen internen Fehler gestoßen. Einmal erneut versuchen, bei Wiederholung Proxy-Logs prüfen.`}},502:{en:{label:`Bad upstream response`,description:`The upstream provider returned an invalid or failed response through the proxy. Retry or route the request to another provider.`},ko:{label:`업스트림 응답 오류`,description:`업스트림 제공자가 프록시를 통해 유효하지 않거나 실패한 응답을 반환했습니다. 재시도하거나 다른 제공자로 라우팅해야 합니다.`},zh:{label:`上游响应错误`,description:`上游提供商通过代理返回了无效或失败的响应。请重试,或将请求路由到其他提供商。`},de:{label:`Ungültige Upstream-Antwort`,description:`Der Upstream-Anbieter lieferte über den Proxy eine ungültige oder fehlgeschlagene Antwort. Erneut versuchen oder zu einem anderen Anbieter routen.`}},503:{en:{label:`Provider unavailable`,description:`The proxy or upstream provider is temporarily unavailable or overloaded. Wait briefly, then retry or switch provider.`},ko:{label:`제공자 사용 불가`,description:`프록시 또는 업스트림 제공자가 일시적으로 사용할 수 없거나 과부하 상태입니다. 잠시 기다린 뒤 재시도하거나 제공자를 전환해야 합니다.`},zh:{label:`提供商不可用`,description:`代理或上游提供商暂时不可用或过载。请稍后重试,或切换提供商。`},de:{label:`Anbieter nicht verfügbar`,description:`Proxy oder Upstream-Anbieter ist vorübergehend nicht verfügbar oder überlastet. Kurz warten, dann erneut versuchen oder Anbieter wechseln.`}},504:{en:{label:`Upstream timeout`,description:`The upstream provider did not respond before the proxy timeout. Retry with a smaller request or choose a faster provider.`},ko:{label:`업스트림 시간 초과`,description:`프록시 시간 제한 전에 업스트림 제공자가 응답하지 않았습니다. 더 작은 요청으로 재시도하거나 더 빠른 제공자를 선택해야 합니다.`},zh:{label:`上游超时`,description:`上游提供商未在代理超时前响应。请缩小请求后重试,或选择响应更快的提供商。`},de:{label:`Upstream-Timeout`,description:`Der Upstream-Anbieter antwortete nicht vor dem Proxy-Timeout. Mit kleinerer Anfrage erneut versuchen oder schnelleren Anbieter wählen.`}},529:{en:{label:`Provider overloaded`,description:`The upstream provider is overloaded or capacity-limited. Wait and retry, or switch to another account/provider.`},ko:{label:`제공자 과부하`,description:`업스트림 제공자가 과부하 상태이거나 처리 용량이 제한되었습니다. 기다렸다가 재시도하거나 다른 계정/제공자로 전환해야 합니다.`},zh:{label:`提供商过载`,description:`上游提供商过载或容量受限。请等待后重试,或切换到其他账号/提供商。`},de:{label:`Anbieter überlastet`,description:`Der Upstream-Anbieter ist überlastet oder kapazitätsbegrenzt. Warten und erneut versuchen oder anderes Konto/Anbieter nutzen.`}}},Yr={client:{en:{label:`Request error`,description:`The proxy or upstream provider rejected the request. Check the request shape, credentials, model name, and provider configuration.`},ko:{label:`요청 오류`,description:`프록시 또는 업스트림 제공자가 요청을 거부했습니다. 요청 형식, 자격 증명, 모델 이름, 제공자 설정을 확인해야 합니다.`},zh:{label:`请求错误`,description:`代理或上游提供商拒绝了该请求。请检查请求结构、凭据、模型名称和提供商配置。`},de:{label:`Anfragefehler`,description:`Der Proxy oder Upstream-Anbieter hat die Anfrage abgelehnt. Prüfe Anfrageformat, Anmeldedaten, Modellname und Anbieterkonfiguration.`}},server:{en:{label:`Server or upstream error`,description:`opencodex or an upstream provider failed while processing the request. Retry later or route the request to another provider.`},ko:{label:`서버 또는 업스트림 오류`,description:`opencodex 또는 업스트림 제공자가 요청 처리 중 실패했습니다. 나중에 재시도하거나 다른 제공자로 라우팅해야 합니다.`},zh:{label:`服务器或上游错误`,description:`opencodex 或上游提供商处理请求时失败。请稍后重试,或将请求路由到其他提供商。`},de:{label:`Server- oder Upstream-Fehler`,description:`opencodex oder ein Upstream-Anbieter ist bei der Anfragebearbeitung fehlgeschlagen. Später erneut versuchen oder zu einem anderen Anbieter routen.`}}};function Xr(e){return e===`de`||e===`ko`||e===`zh`?e:`en`}function Zr(e,t){if(e<400)return null;let n=Xr(t);return(Jr[Math.trunc(e)]??(e<500?Yr.client:Yr.server))[n]}function Qr(e,t){if(!e.usage)return;let n=ei(e),r=[`${t(`logs.tokens.input`)}=${e.usage.inputTokens}`,`${t(`logs.tokens.output`)}=${e.usage.outputTokens}`];return n.read!==void 0&&r.push(`${t(`logs.tokens.cacheRead`)}=${n.read}`),n.write!==void 0&&r.push(`${t(`logs.tokens.cacheWrite`)}=${n.write}`),typeof e.usage.reasoningOutputTokens==`number`&&r.push(`${t(`logs.tokens.reasoning`)}=${e.usage.reasoningOutputTokens}`),e.usageStatus===`estimated`&&r.push(t(`logs.tokens.estimatedNote`)),e.usageStatus===`estimated`&&n.read===void 0&&n.write===void 0&&r.push(t(`logs.tokens.noCacheNote`)),r.join(` · `)}function $r(e){if(!e.usage)return typeof e.totalTokens==`number`?e.totalTokens:void 0;let t=e.usage.inputTokens+e.usage.outputTokens,n=e.usage.totalTokens??e.totalTokens;return typeof n==`number`?Math.max(n,t):t}function ei(e){let t=e.usage;if(!t)return{};let n=typeof t.cacheCreationInputTokens==`number`?t.cacheCreationInputTokens:void 0;return{read:typeof t.cacheReadInputTokens==`number`?t.cacheReadInputTokens:typeof t.cachedInputTokens==`number`&&n!==void 0?Math.max(0,t.cachedInputTokens-n):t.cachedInputTokens,write:n}}function ti(e){if(e.requestedSpeedLabel)return e.requestedSpeedLabel;if(e.modelSupportsServiceTier&&e.configuredSpeedLabel)return e.configuredSpeedLabel}function ni(e){return e>=200&&e<300?`var(--green)`:e>=400?`var(--red)`:`var(--amber)`}function ri(e,t){return new Date(e).toLocaleTimeString(t)}function ii(e,t){return new Date(e).toLocaleString(t)}function ai(e){return[`model=${e.model}`,e.resolvedModel?`resolved=${e.resolvedModel}`:void 0,e.requestedServiceTier?`requestedTier=${e.requestedServiceTier}`:void 0,e.configuredServiceTier?`configuredTier=${e.configuredServiceTier}`:void 0,e.responseServiceTier?`responseTier=${e.responseServiceTier}`:void 0,e.modelSupportsServiceTier===void 0?void 0:`supportsTier=${e.modelSupportsServiceTier}`].filter(Boolean).join(` · `)}function oi({apiBase:e}){let{t,locale:n}=H(),[r,i]=(0,_.useState)([]),[a,o]=(0,_.useState)(!0),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(`all`),d=(0,_.useRef)(null),f=ye.find(e=>e.code===n)?.htmlLang;(0,_.useEffect)(()=>{let t=async()=>{try{i(await(await fetch(`${e}/api/logs`)).json())}catch{}};if(t(),!a)return;let n=setInterval(t,2e3);return()=>clearInterval(n)},[e,a]);let p=s?Zr(s.status,n):null,m=r.filter(e=>l===`all`||(l===`claude`?e.surface===`claude`:e.surface!==`claude`)),h=In({count:m.length,getScrollElement:()=>d.current,estimateSize:()=>44,overscan:15}),g=h.getVirtualItems(),v=g.length>0?g[0].start:0,y=g.length>0?h.getTotalSize()-g[g.length-1].end:0;return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{children:t(`logs.title`)}),(0,S.jsxs)(`label`,{className:`muted text-control`,style:{cursor:`pointer`,display:`inline-flex`,alignItems:`center`,gap:6},children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(e.target.checked)}),t(`logs.autoRefresh`)]})]}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`logs.subtitle`)}),(0,S.jsxs)(`div`,{className:`row`,style:{gap:8,marginBottom:12,alignItems:`center`},children:[(0,S.jsx)(`span`,{className:`muted text-control`,children:t(`logs.filter.surface.label`)}),(0,S.jsx)(`div`,{className:`segmented`,role:`radiogroup`,"aria-label":t(`logs.filter.surface.label`),style:{display:`inline-flex`,borderRadius:`var(--radius-pill)`,background:`var(--surface-soft, var(--raised))`,padding:3,gap:2},children:[`all`,`claude`,`codex`].map(e=>(0,S.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":l===e,className:`btn btn-sm${l===e?` btn-primary`:` btn-ghost`}`,style:{borderRadius:`var(--radius-pill)`,minWidth:64,padding:`5px 12px`,border:`none`,background:l===e?void 0:`transparent`,color:l===e?void 0:`var(--muted)`},onClick:()=>u(e),children:t(`logs.filter.surface.${e}`)},e))})]}),m.length===0?(0,S.jsx)(Ae,{title:t(`logs.noRequests`)}):(0,S.jsx)(`div`,{ref:d,className:`tbl-wrap`,style:{overflowY:`auto`,maxHeight:`calc(100vh - 260px)`},children:(0,S.jsxs)(`table`,{className:`tbl`,children:[(0,S.jsx)(`thead`,{style:{position:`sticky`,top:0,zIndex:1,background:`var(--surface)`},children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:t(`logs.col.time`)}),(0,S.jsx)(`th`,{className:`num log-col-tokens`,children:t(`logs.col.tokens`)}),(0,S.jsx)(`th`,{className:`log-col-model`,children:t(`logs.col.model`)}),(0,S.jsx)(`th`,{children:t(`logs.col.effort`)}),(0,S.jsx)(`th`,{children:t(`logs.col.provider`)}),(0,S.jsx)(`th`,{children:t(`logs.col.status`)}),(0,S.jsx)(`th`,{children:t(`logs.col.request`)}),(0,S.jsx)(`th`,{className:`num`,children:t(`logs.col.duration`)})]})}),(0,S.jsxs)(`tbody`,{children:[v>0&&(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:8,style:{height:v,padding:0,border:0}})}),g.map(e=>{let r=m[m.length-1-e.index];return(0,S.jsxs)(`tr`,{"data-index":e.index,ref:h.measureElement,children:[(0,S.jsx)(`td`,{className:`muted mono`,children:ri(r.timestamp,f)}),(0,S.jsx)(`td`,{className:`num mono log-col-tokens`,title:Qr(r,t),children:(()=>{let e=$r(r),{read:i,write:a}=ei(r);return e===void 0?(0,S.jsx)(`span`,{className:`muted`,children:t(`logs.tokens.${r.usageStatus??`unreported`}`)}):(0,S.jsxs)(`span`,{style:{display:`inline-flex`,flexDirection:`column`,alignItems:`flex-end`,gap:2},children:[(0,S.jsxs)(`span`,{children:[r.usageStatus===`estimated`?`~`:``,Oe(e,n)]}),i!==void 0&&i>0&&(0,S.jsxs)(`span`,{className:`muted text-caption leading-tight`,children:[`c `,Oe(i,n)]}),a!==void 0&&a>0&&(0,S.jsxs)(`span`,{className:`muted text-caption leading-tight`,children:[`w `,Oe(a,n)]}),r.usageStatus===`estimated`&&i===void 0&&a===void 0&&(0,S.jsx)(`span`,{className:`muted text-caption leading-tight`,children:t(`logs.tokens.noCache`)})]})})()}),(0,S.jsx)(`td`,{className:`mono log-col-model`,title:ai(r),children:(0,S.jsxs)(`span`,{style:{display:`inline-flex`,alignItems:`center`,gap:6,flexWrap:`wrap`},children:[(0,S.jsx)(`span`,{children:rr(r.resolvedModel??r.model)}),r.surface===`claude`&&(0,S.jsx)(`span`,{className:`badge badge-accent`,children:t(`logs.badge.claude`)}),ti(r)&&(0,S.jsx)(`span`,{className:`badge badge-amber`,children:ti(r)})]})}),(0,S.jsx)(`td`,{className:`mono`,children:r.requestedEffort??`-`}),(0,S.jsx)(`td`,{className:`muted`,children:r.provider}),(0,S.jsx)(`td`,{children:(0,S.jsxs)(`span`,{className:`log-status-cell`,children:[(0,S.jsx)(`span`,{className:`mono font-semibold`,style:{color:ni(r.status)},children:r.status}),r.status>=400&&(0,S.jsx)(`button`,{type:`button`,className:`log-detail-btn`,onClick:()=>c(r),children:t(`logs.details`)})]})}),(0,S.jsx)(`td`,{className:`muted mono`,children:(0,S.jsx)(`span`,{className:`log-reqid`,title:r.requestId,children:r.requestId??`-`})}),(0,S.jsxs)(`td`,{className:`num`,children:[r.durationMs,`ms`]})]},r.requestId??`${r.timestamp}-${e.index}`)}),y>0&&(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:8,style:{height:y,padding:0,border:0}})})]})]})}),s&&(0,S.jsx)(ci,{detail:s,detailInfo:p,localeTag:f,t,onClose:()=>c(null)})]})}function si(e){let t=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let n=t.current;n&&(e&&!n.open?n.showModal():!e&&n.open&&n.close())},[e]),t}function ci({detail:e,detailInfo:t,localeTag:n,t:r,onClose:i}){return(0,S.jsx)(`dialog`,{ref:si(!0),className:`modal-overlay`,"aria-labelledby":`log-detail-title`,onCancel:e=>{e.preventDefault(),i()},children:(0,S.jsxs)(`div`,{className:`modal-card`,children:[(0,S.jsxs)(`div`,{className:`modal-head`,children:[(0,S.jsxs)(`h3`,{id:`log-detail-title`,children:[(0,S.jsx)(`span`,{className:`mono`,style:{color:ni(e.status)},children:e.status}),t&&(0,S.jsx)(`span`,{style:{marginLeft:8},children:t.label})]}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:i,"aria-label":r(`common.cancel`),children:(0,S.jsx)(N,{})})]}),t&&(0,S.jsx)(`p`,{className:`modal-desc`,children:t.description}),(0,S.jsxs)(`div`,{className:`log-detail-grid`,children:[(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.time`)}),(0,S.jsx)(`span`,{className:`mono`,children:ii(e.timestamp,n)}),(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.request`)}),(0,S.jsx)(`span`,{className:`mono log-detail-break`,children:e.requestId??`-`}),(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.model`)}),(0,S.jsx)(`span`,{className:`mono`,children:rr(e.resolvedModel??e.model)}),(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.provider`)}),(0,S.jsx)(`span`,{children:e.provider}),e.errorCode&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.error`)}),(0,S.jsx)(`span`,{className:`mono`,children:e.errorCode})]}),e.upstreamError&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.upstreamReason`)}),(0,S.jsx)(`span`,{className:`mono log-detail-break`,children:e.upstreamError})]}),(0,S.jsx)(`span`,{className:`muted`,children:r(`logs.col.duration`)}),(0,S.jsxs)(`span`,{className:`mono`,children:[e.durationMs,`ms`]})]}),(0,S.jsx)(`div`,{className:`muted text-label`,style:{margin:`12px 0 6px`},children:r(`logs.detailRaw`)}),(0,S.jsx)(`pre`,{className:`log-detail-json`,children:JSON.stringify(e,null,2)})]})})}var li=[`provider`,`usage`,`injection`];function ui(e){return e>0?`[${new Date(e).toLocaleTimeString()}] `:``}function di(e){return new Date(e).toLocaleTimeString()}function fi(e,t){return t===`provider`?!!e?.enabled:t===`usage`?!!e?.usage:!!e?.injection}function pi(e,t){return t===`debug`?e.enabled:t===`usage`?e.usage:t===`injection`?e.injection:e.claude}function mi({apiBase:e}){let{t}=H(),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(`provider`),[c,l]=(0,_.useState)([]),[u,d]=(0,_.useState)(!0),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)([]),g=(0,_.useRef)(0),v=(0,_.useRef)(null),y=In({count:c.length,getScrollElement:()=>v.current,estimateSize:()=>20,overscan:30,getItemKey:e=>c[e].seq});(0,_.useEffect)(()=>{let t=async()=>{try{let t=await fetch(`${e}/api/debug`);t.ok&&r(await t.json())}catch{}};t();let n=setInterval(()=>void t(),2e3);return()=>clearInterval(n)},[e]);let b=(0,_.useCallback)(e=>fi(n,e),[n]);(0,_.useEffect)(()=>{if(!n||b(o))return;let e=li.find(b);if(!e)return;let t=window.setTimeout(()=>s(e),0);return()=>window.clearTimeout(t)},[n,o,b]);let x=b(o),C=o===`provider`?`${e}/api/debug/logs`:o===`usage`?`${e}/api/debug/usage-logs`:`${e}/api/debug/injection-logs`,w=(0,_.useCallback)(async e=>{if(!x){l([]),g.current=0;return}p(!0);try{let t=new URLSearchParams({limit:`500`});!e&&g.current>0&&t.set(`after`,String(g.current));let n=await fetch(`${C}?${t}`);if(!n.ok)return;let r=await n.json();if(r.length===0)return;l(t=>(e?r:[...t,...r]).slice(-2e3)),g.current=r[r.length-1].seq}catch{}finally{p(!1)}},[C,x]);(0,_.useEffect)(()=>{g.current=0;let e=window.setTimeout(()=>{l([]),w(!0)},0);return()=>window.clearTimeout(e)},[o,x,w]),(0,_.useEffect)(()=>{if(!u||!x)return;let e=setInterval(()=>void w(!1),1e3);return()=>clearInterval(e)},[u,x,w]),(0,_.useEffect)(()=>{u&&c.length>0&&y.scrollToIndex(c.length-1,{align:`end`})},[c,u,y]),(0,_.useEffect)(()=>{if(!n?.claude){h([]);return}let t=async()=>{try{let t=await fetch(`${e}/api/claude/inbound-debug`);if(t.ok){let e=await t.json();h(Array.isArray(e.entries)?e.entries:[])}}catch{}};t();let r=setInterval(()=>void t(),2e3);return()=>clearInterval(r)},[e,n?.claude]);let T=async(t,n)=>{a(!0);try{let i=await fetch(`${e}/api/debug`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({[t]:n})});i.ok&&r(await i.json())}catch{}finally{a(!1)}},E=async()=>{a(!0);try{let t=await fetch(`${e}/api/debug`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({reset:!0})});t.ok&&r(await t.json())}catch{}finally{a(!1)}};return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head`,children:[(0,S.jsx)(`h2`,{children:t(`debug.title`)}),(0,S.jsxs)(`div`,{style:{display:`inline-flex`,alignItems:`center`,gap:12},children:[(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:f||!x,onClick:()=>void w(!0),children:[(0,S.jsx)(ee,{}),` `,t(`debug.refresh`)]}),(0,S.jsxs)(`label`,{className:`muted text-control`,style:{cursor:`pointer`,display:`inline-flex`,alignItems:`center`,gap:6},children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked)}),t(`debug.follow`)]})]})]}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`debug.subtitle`)}),n?(0,S.jsxs)(`div`,{className:`card`,style:{marginBottom:16,padding:`12px 14px`},children:[(0,S.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:12,flexWrap:`wrap`},children:[(0,S.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:16},children:[`debug`,`usage`,`injection`,`claude`].map(e=>{let r=pi(n,e);return(0,S.jsxs)(`div`,{style:{display:`inline-flex`,alignItems:`center`,gap:10,minWidth:220},children:[(0,S.jsx)(ke,{on:r,disabled:i,label:t(`debug.${e}`),onClick:()=>void T(e,!r)}),(0,S.jsx)(`span`,{className:`text-control`,children:t(`debug.${e}`)})]},e)})}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:i,onClick:()=>void E(),children:t(`debug.reset`)})]}),(n.enabled||n.usage||n.injection)&&(0,S.jsxs)(`div`,{style:{display:`inline-flex`,gap:6,marginTop:12},children:[n.enabled&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm${o===`provider`?` btn-primary`:` btn-ghost`}`,onClick:()=>s(`provider`),children:t(`debug.streamProvider`)}),n.usage&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm${o===`usage`?` btn-primary`:` btn-ghost`}`,onClick:()=>s(`usage`),children:t(`debug.streamUsage`)}),n.injection&&(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm${o===`injection`?` btn-primary`:` btn-ghost`}`,onClick:()=>s(`injection`),children:t(`debug.streamInjection`)})]})]}):(0,S.jsx)(`div`,{className:`empty`,children:t(`debug.loading`)}),n?.claude&&(0,S.jsxs)(`div`,{className:`card`,style:{marginBottom:16,padding:`12px 14px`},children:[(0,S.jsx)(`div`,{className:`font-semibold`,style:{marginBottom:4},children:t(`debug.claudeInbound.title`)}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{marginBottom:10},children:t(`debug.claudeInbound.sub`)}),m.length===0?(0,S.jsx)(`div`,{className:`muted text-control`,children:t(`debug.claudeInbound.empty`)}):(0,S.jsx)(`div`,{style:{overflowX:`auto`},children:(0,S.jsxs)(`table`,{className:`table text-label`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:t(`debug.claudeInbound.time`)}),(0,S.jsx)(`th`,{children:t(`debug.claudeInbound.endpoint`)}),(0,S.jsx)(`th`,{children:t(`debug.claudeInbound.model`)}),(0,S.jsx)(`th`,{children:`thinking`}),(0,S.jsx)(`th`,{children:`effort`}),(0,S.jsx)(`th`,{children:`beta`}),(0,S.jsx)(`th`,{children:`metadata`}),(0,S.jsx)(`th`,{children:`system`})]})}),(0,S.jsx)(`tbody`,{children:m.map((e,n)=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{className:`muted mono`,children:di(e.at)}),(0,S.jsx)(`td`,{className:`mono`,children:e.endpoint}),(0,S.jsxs)(`td`,{className:`mono`,title:e.resolvedModel,children:[e.model,e.resolvedModel&&e.resolvedModel!==e.model&&(0,S.jsxs)(`span`,{className:`muted`,children:[` → `,e.resolvedModel]})]}),(0,S.jsxs)(`td`,{className:`mono`,children:[e.thinkingType??`-`,e.thinkingBudgetTokens!==void 0&&(0,S.jsxs)(`span`,{className:`muted`,children:[` (`,e.thinkingBudgetTokens,`)`]})]}),(0,S.jsx)(`td`,{className:`mono`,children:e.outputConfigEffort??`-`}),(0,S.jsx)(`td`,{className:`mono`,title:e.anthropicBeta,style:{maxWidth:160,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.anthropicBeta??`-`}),(0,S.jsx)(`td`,{className:`mono`,title:e.metadataKeys?.join(`, `),children:e.hasMetadataUserId?`user_id ${e.userIdTag??``}`:t(`debug.claudeInbound.none`)}),(0,S.jsx)(`td`,{className:`mono`,children:e.hasSystem?e.systemTag??`yes`:t(`debug.claudeInbound.none`)})]},`${e.at}-${n}`))})]})})]}),n&&!x?(0,S.jsxs)(`div`,{className:`empty`,children:[(0,S.jsx)(`div`,{className:`font-semibold`,style:{marginBottom:6},children:t(`debug.emptyTitle`)}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{maxWidth:560,marginInline:`auto`},children:t(`debug.empty`)})]}):n&&x&&c.length===0?(0,S.jsxs)(`div`,{className:`empty`,children:[(0,S.jsx)(`div`,{className:`font-semibold`,style:{marginBottom:6},children:t(`debug.noLinesTitle`)}),(0,S.jsx)(`div`,{className:`muted text-control`,style:{maxWidth:560,marginInline:`auto`},children:t(`debug.noLines.${o}`)})]}):n&&x?(0,S.jsx)(`div`,{ref:v,className:`log-detail-json`,style:{maxHeight:`calc(100vh - 280px)`,overflow:`auto`},children:(0,S.jsx)(`div`,{style:{position:`relative`,height:y.getTotalSize(),width:`100%`},children:y.getVirtualItems().map(e=>(0,S.jsx)(`div`,{ref:y.measureElement,"data-index":e.index,style:{position:`absolute`,top:0,left:0,width:`100%`,transform:`translateY(${e.start}px)`},children:`${ui(c[e.index].at)}${c[e.index].line}`},e.key))})}):null]})}function hi(e){return`${Math.round(e*100)}%`}function gi(e,t){let n=`${t}/${e}`,r=0;for(let e=0;e<n.length;e++)r=r*31+n.charCodeAt(e)>>>0;return`hsl(${r%360} 55% 55%)`}function _i(e){let t=new Map(e.map(e=>[e.date,e])),n=[],r=new Date;r.setHours(0,0,0,0),r.setDate(r.getDate()-6);for(let e=0;e<7;e++){let e=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`,i=t.get(e);n.push({date:e,requests:i?.requests??0,measuredRequests:i?.measuredRequests??0,reportedRequests:i?.reportedRequests??0,totalTokens:i?.totalTokens??0,models:i?.models??[]}),r.setDate(r.getDate()+1)}return n}function vi(e){let t=e.filter(e=>e>0).sort((e,t)=>e-t);if(t.length===0)return[0,0,0,0];let n=e=>t[Math.min(t.length-1,Math.floor(e*t.length))];return[n(.25),n(.5),n(.75),n(.95)]}function yi(e,t){return e<=0?0:e<=t[0]?1:e<=t[1]?2:e<=t[2]?3:4}function bi(e){let t=vi(e.map(e=>e.totalTokens)),n=new Map(e.map(e=>[e.date,e])),r=new Date;r.setHours(0,0,0,0);let i=new Date(r);i.setDate(i.getDate()-364),i.setDate(i.getDate()-i.getDay());let a=[],o=[],s=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],c=-4,l=-1,u=[],d=new Date(i);for(;d<=r;){let e=`${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,`0`)}-${String(d.getDate()).padStart(2,`0`)}`,r=d.getMonth();d.getDay()===0&&r!==l&&a.length-c>=4&&(o.push({label:s[r],col:a.length}),c=a.length,l=r);let i=n.get(e);u.push({date:e,requests:i?.requests??0,totalTokens:i?.totalTokens??0,level:i?yi(i.totalTokens,t):0,dayOfWeek:d.getDay()}),d.getDay()===6&&(a.push(u),u=[]),d.setDate(d.getDate()+1)}if(u.length>0){for(;u.length<7;)u.push({date:``,requests:0,totalTokens:0,level:0,dayOfWeek:u.length});a.push(u)}return{weeks:a,months:o,buckets:t}}function xi({surface:e,range:t,onSurface:n,onRange:r,t:i}){return(0,S.jsxs)(`div`,{className:`usage-filters`,children:[(0,S.jsx)(`div`,{className:`usage-segmented`,role:`group`,"aria-label":i(`logs.filter.surface.label`),children:[`all`,`codex`,`claude`].map(t=>{let r=i(`logs.filter.surface.${t}`);return(0,S.jsxs)(`button`,{type:`button`,className:`usage-segmented-btn usage-source-btn${e===t?` active`:``}`,"aria-label":r,"aria-pressed":e===t,onClick:()=>n(t),children:[t===`codex`&&(0,S.jsx)(`img`,{className:`usage-source-mark`,src:`/provider-icons/openai.svg`,alt:``,"aria-hidden":`true`}),t===`claude`&&(0,S.jsx)(`img`,{className:`usage-source-mark`,src:`/provider-icons/claude.svg`,alt:``,"aria-hidden":`true`}),(0,S.jsx)(`span`,{className:t===`all`?`usage-source-label`:`usage-source-label usage-source-label-collapsible`,children:r})]},t)})}),(0,S.jsx)(`div`,{className:`usage-segmented`,role:`group`,"aria-label":i(`usage.title`),children:[`all`,`30d`,`7d`].map(e=>{let n=i(`usage.range.${e}`);return(0,S.jsx)(`button`,{type:`button`,className:`usage-segmented-btn${t===e?` active`:``}`,"aria-label":n,"aria-pressed":t===e,onClick:()=>r(e),children:n},e)})})]})}function Si({summary:e,activeDays:t,locale:n,t:r}){return(0,S.jsxs)(`div`,{className:`usage-cards usage-cards-3x2`,role:`group`,"aria-label":r(`usage.title`),children:[(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.requests`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.requests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.measured`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.measuredRequests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.totalTokens`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:Oe(e.totalTokens,n)})]}),(0,S.jsxs)(`div`,{className:`stat`,title:r(`usage.card.cachedTokensHint`),children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.cachedTokens`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:Oe(e.cacheReadInputTokens??e.cachedInputTokens,n)}),(e.cacheCreationInputTokens??0)>0&&(0,S.jsxs)(`div`,{className:`muted text-caption`,children:[r(`usage.card.cacheWriteTokens`),`: `,Oe(e.cacheCreationInputTokens??0,n)]})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.coverage`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:hi(e.coverageRatio)})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:r(`usage.card.activeDays`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:t})]})]})}function Ci({weekBars:e,locale:t,t:n}){let[r,i]=(0,_.useState)(null),a=Math.max(1,...e.map(e=>e.totalTokens));return(0,S.jsx)(`div`,{className:`daybars`,role:`img`,"aria-label":n(`usage.section.heatmap`),children:e.map(e=>{let n=Math.round(e.totalTokens/a*100),o=e.date.slice(5);return(0,S.jsxs)(`div`,{className:`daybar`,onMouseEnter:()=>i(e.date),onMouseLeave:()=>i(t=>t===e.date?null:t),children:[(0,S.jsx)(`div`,{className:`daybar-track`,children:(0,S.jsxs)(`div`,{className:`daybar-stack`,style:{height:`${n}%`},children:[e.models.map(e=>(0,S.jsx)(`div`,{className:`daybar-seg`,style:{flexGrow:e.totalTokens,background:gi(e.model,e.provider)}},`${e.provider}/${e.model}`)),e.models.length===0&&e.totalTokens>0&&(0,S.jsx)(`div`,{className:`daybar-seg`,style:{flexGrow:1,background:`var(--green)`}})]})}),r===e.date&&e.totalTokens>0&&(0,S.jsxs)(`div`,{className:`daybar-tip`,role:`tooltip`,children:[(0,S.jsx)(`div`,{className:`daybar-tip-date`,children:e.date}),e.models.slice(0,8).map(e=>(0,S.jsxs)(`div`,{className:`daybar-tip-row`,children:[(0,S.jsx)(`span`,{className:`daybar-tip-swatch`,style:{background:gi(e.model,e.provider)}}),(0,S.jsx)(`span`,{className:`daybar-tip-name`,children:rr(e.model)}),(0,S.jsx)(`span`,{className:`daybar-tip-val`,children:Oe(e.totalTokens,t)})]},`${e.provider}/${e.model}`))]}),(0,S.jsx)(`span`,{className:`daybar-count`,children:Oe(e.totalTokens,t)}),(0,S.jsx)(`span`,{className:`daybar-label muted`,children:o})]},e.date)})})}function wi({range:e,heatmap:t,weekBars:n,locale:r,t:i}){let a=(0,_.useRef)(null),[o,s]=(0,_.useState)(null);return(0,_.useEffect)(()=>{let e=a.current;if(!e)return;let t=()=>{e.scrollLeft=e.scrollWidth};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[t,e]),(0,S.jsxs)(`section`,{className:`panel`,style:{marginTop:16},"aria-labelledby":`usage-heatmap-title`,children:[(0,S.jsx)(`h3`,{id:`usage-heatmap-title`,className:`panel-title`,children:i(`usage.section.heatmap`)}),e===`7d`?(0,S.jsx)(Ci,{weekBars:n,locale:r,t:i}):(0,S.jsxs)(`div`,{className:`heatmap`,ref:a,role:`img`,"aria-labelledby":`usage-heatmap-title`,children:[(0,S.jsxs)(`div`,{className:`heatmap-months`,style:{gridTemplateColumns:`28px repeat(${t.weeks.length}, calc(var(--hm-cell) + var(--hm-gap)))`},children:[(0,S.jsx)(`span`,{className:`heatmap-day-spacer`}),t.months.map(e=>(0,S.jsx)(`span`,{className:`heatmap-month`,style:{gridColumn:e.col+2},children:e.label},`${e.label}-${e.col}`))]}),(0,S.jsxs)(`div`,{className:`heatmap-body`,children:[(0,S.jsxs)(`div`,{className:`heatmap-days`,children:[(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{children:i(`usage.dayMon`)}),(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{children:i(`usage.dayWed`)}),(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{children:i(`usage.dayFri`)}),(0,S.jsx)(`span`,{})]}),(0,S.jsx)(`div`,{className:`heatmap-grid`,style:{gridTemplateColumns:`repeat(${t.weeks.length}, var(--hm-cell))`},children:t.weeks.map((e,t)=>(0,S.jsx)(`div`,{className:`heatmap-week`,children:e.map((e,n)=>(0,S.jsx)(`div`,{className:`heatmap-cell heatmap-cell-${e.level}`,onMouseEnter:r=>{if(!e.date)return;let i=r.currentTarget.getBoundingClientRect();s({weekIndex:t,dayIndex:n,x:i.left+i.width/2,y:i.top})},onMouseLeave:()=>s(e=>e?.weekIndex===t&&e.dayIndex===n?null:e)},e.date||`pad-${t}-${n}`))},e[0]?.date||`week-${t}`))})]}),o&&(()=>{let e=t.weeks[o.weekIndex]?.[o.dayIndex];return e?.date?(0,S.jsxs)(`div`,{className:`heatmap-tip`,role:`tooltip`,style:{left:o.x,top:o.y},children:[(0,S.jsx)(`div`,{className:`heatmap-tip-date`,children:e.date}),(0,S.jsx)(`div`,{className:`heatmap-tip-val`,children:i(`usage.heatmap.tooltipTokens`,{tokens:Oe(e.totalTokens,r)})}),(0,S.jsx)(`div`,{className:`heatmap-tip-req muted`,children:i(`usage.heatmap.tooltipRequests`,{requests:e.requests})})]}):null})(),(0,S.jsxs)(`div`,{className:`heatmap-legend muted`,children:[(0,S.jsx)(`span`,{children:i(`usage.heatmap.less`)}),[0,1,2,3,4].map(e=>(0,S.jsx)(`span`,{className:`heatmap-cell heatmap-cell-${e}`},e)),(0,S.jsx)(`span`,{children:i(`usage.heatmap.more`)})]})]})]})}function Ti({models:e,modelQuery:t,onModelQuery:n,locale:r,t:i}){let a=i(`usage.search.models`);return(0,S.jsxs)(`section`,{className:`panel`,style:{marginTop:16},"aria-labelledby":`usage-models-title`,children:[(0,S.jsxs)(`div`,{className:`panel-head`,children:[(0,S.jsx)(`h3`,{id:`usage-models-title`,className:`panel-title`,children:i(`usage.section.models`)}),(0,S.jsx)(`input`,{className:`input`,"aria-label":a,placeholder:a,value:t,onChange:e=>n(e.target.value)})]}),(0,S.jsx)(`div`,{className:`tbl-wrap usage-scroll`,children:(0,S.jsxs)(`table`,{className:`tbl`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:i(`logs.col.model`)}),(0,S.jsx)(`th`,{children:i(`logs.col.provider`)}),(0,S.jsx)(`th`,{className:`num`,children:i(`usage.col.requests`)}),(0,S.jsx)(`th`,{className:`num`,children:i(`usage.col.measured`)}),(0,S.jsx)(`th`,{className:`num`,children:i(`usage.col.tokens`)}),(0,S.jsx)(`th`,{children:i(`usage.col.share`)})]})}),(0,S.jsx)(`tbody`,{children:e.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{className:`mono`,children:rr(e.resolvedModel??e.model)}),(0,S.jsx)(`td`,{className:`muted`,children:e.provider}),(0,S.jsx)(`td`,{className:`num`,children:e.requests}),(0,S.jsx)(`td`,{className:`num`,children:e.measuredRequests}),(0,S.jsx)(`td`,{className:`num mono`,children:Oe(e.totalTokens,r)}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`div`,{className:`usage-bar`,children:(0,S.jsx)(`div`,{className:`usage-bar-fill`,style:{width:`${Math.round(e.shareRatio*100)}%`}})})})]},`${e.provider}/${e.model}/${e.resolvedModel??``}`))})]})})]})}function Ei({providers:e,locale:t,t:n}){return(0,S.jsxs)(`section`,{className:`panel`,style:{marginTop:16},"aria-labelledby":`usage-providers-title`,children:[(0,S.jsx)(`h3`,{id:`usage-providers-title`,className:`panel-title`,children:n(`usage.section.providers`)}),(0,S.jsx)(`div`,{className:`tbl-wrap usage-scroll`,children:(0,S.jsxs)(`table`,{className:`tbl`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:n(`logs.col.provider`)}),(0,S.jsx)(`th`,{className:`num`,children:n(`usage.col.requests`)}),(0,S.jsx)(`th`,{className:`num`,children:n(`usage.col.measured`)}),(0,S.jsx)(`th`,{className:`num`,children:n(`usage.col.tokens`)}),(0,S.jsx)(`th`,{children:n(`usage.col.share`)})]})}),(0,S.jsx)(`tbody`,{children:e.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{className:`mono`,children:e.provider}),(0,S.jsx)(`td`,{className:`num`,children:e.requests}),(0,S.jsx)(`td`,{className:`num`,children:e.measuredRequests}),(0,S.jsx)(`td`,{className:`num mono`,children:Oe(e.totalTokens,t)}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`div`,{className:`usage-bar`,children:(0,S.jsx)(`div`,{className:`usage-bar-fill`,style:{width:`${Math.round(e.shareRatio*100)}%`}})})})]},e.provider))})]})})]})}function Di({summary:e,t}){return(0,S.jsxs)(`section`,{className:`panel`,style:{marginTop:16},"aria-labelledby":`usage-coverage-title`,children:[(0,S.jsx)(`h3`,{id:`usage-coverage-title`,className:`panel-title`,children:t(`usage.section.coverage`)}),(0,S.jsxs)(`div`,{className:`usage-cards usage-cards-3x2`,children:[(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:t(`usage.coverage.measured`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.measuredRequests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:t(`usage.coverage.reported`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.reportedRequests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:t(`usage.coverage.estimated`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.estimatedRequests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:t(`logs.tokens.unreported`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.unreportedRequests})]}),(0,S.jsxs)(`div`,{className:`stat`,children:[(0,S.jsx)(`div`,{className:`muted`,children:t(`logs.tokens.unsupported`)}),(0,S.jsx)(`div`,{className:`stat-value`,children:e.unsupportedRequests})]})]}),(0,S.jsx)(`p`,{className:`muted text-control`,style:{marginTop:12},children:t(`usage.coverage.note`)})]})}function K({apiBase:e}){let{t,locale:n}=H(),[r,i]=(0,_.useState)(`30d`),[a,o]=(0,_.useState)(`all`),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(!0),[d,f]=(0,_.useState)(``),p=(0,_.useCallback)(async(t,n,r)=>{u(!0);try{let i=await fetch(`${e}/api/usage?range=${t}&surface=${n}`,{signal:r});if(!i.ok)throw Error(`fetch failed`);let a=await i.json();if(r.aborted)return;c(a)}catch{if(r.aborted)return;c(null)}finally{r.aborted||u(!1)}},[e]);(0,_.useEffect)(()=>{let e=new AbortController,t=window.setTimeout(()=>{p(r,a,e.signal)},0);return()=>{window.clearTimeout(t),e.abort()}},[p,r,a]);let m=(0,_.useMemo)(()=>bi(s?.days??[]),[s?.days]),h=(0,_.useMemo)(()=>_i(s?.days??[]),[s?.days]),g=(0,_.useMemo)(()=>(s?.days??[]).filter(e=>e.requests>0).length,[s?.days]),v=(0,_.useMemo)(()=>{let e=d.trim().toLowerCase(),t=[...s?.models??[]].sort((e,t)=>t.totalTokens-e.totalTokens);return e?t.filter(t=>t.model.toLowerCase().includes(e)||t.provider.toLowerCase().includes(e)||(t.resolvedModel??``).toLowerCase().includes(e)).slice(0,100):t.slice(0,100)},[s?.models,d]),y=(0,_.useMemo)(()=>[...s?.providers??[]].sort((e,t)=>t.totalTokens-e.totalTokens),[s?.providers]);return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`page-head usage-head`,children:[(0,S.jsx)(`h2`,{id:`usage-page-title`,children:t(`usage.title`)}),(0,S.jsx)(xi,{surface:a,range:r,onSurface:o,onRange:i,t})]}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`usage.subtitle`)}),l&&!s?(0,S.jsx)(Ae,{title:t(`usage.loading`)}):!s||s.summary.requests===0?(0,S.jsx)(Ae,{title:t(`usage.empty`)}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Si,{summary:s.summary,activeDays:g,locale:n,t}),(0,S.jsx)(wi,{range:r,heatmap:m,weekBars:h,locale:n,t}),(0,S.jsx)(Ti,{models:v,modelQuery:d,onModelQuery:f,locale:n,t}),(0,S.jsx)(Ei,{providers:y,locale:n,t}),(0,S.jsx)(Di,{summary:s.summary,t})]})]})}function Oi(e){if(!e||typeof e!=`object`)return`absent`;let t=e.providers;if(!t||typeof t!=`object`||Array.isArray(t)||!Object.hasOwn(t,`openai`))return`absent`;let n=t.openai;if(!n||typeof n!=`object`||Array.isArray(n))return`absent`;let r=n;return r.disabled===!0?`disabled`:r.codexAccountMode===`direct`?`direct`:r.codexAccountMode===void 0||r.codexAccountMode===`pool`?`pool`:`absent`}function ki({apiBase:e}){let t=U(),[n,r]=(0,_.useState)(null),i=(0,_.useCallback)(async()=>{try{r(Oi(await fetch(`${e}/api/config`).then(e=>e.json())))}catch{}},[e]);return(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{i()},0),t=window.setInterval(()=>{i()},3e4);return()=>{window.clearTimeout(e),window.clearInterval(t)}},[i]),(0,S.jsx)(Bn,{apiBase:e,accountModeState:n,banner:(0,S.jsxs)(`div`,{className:`panel`,style:{marginBottom:16},children:[(0,S.jsxs)(`div`,{className:`row`,children:[(0,S.jsx)(`strong`,{children:t(`codexAuth.accountModeTitle`)}),n===`pool`&&(0,S.jsx)(`span`,{className:`badge badge-accent`,children:t(`codexAuth.accountModePool`)}),n===`direct`&&(0,S.jsx)(`span`,{className:`badge badge-green`,children:t(`codexAuth.accountModeDirect`)})]}),n===`pool`&&(0,S.jsx)(`p`,{className:`card-sub`,style:{margin:`6px 0 0`},children:t(`codexAuth.accountModePoolDesc`)}),n===`direct`&&(0,S.jsxs)(`p`,{className:`card-sub`,style:{margin:`6px 0 0`},children:[t(`codexAuth.accountModeDirectDesc`),` `,(0,S.jsx)(`a`,{href:`#providers`,children:t(`codexAuth.openProviders`)})]}),n===`absent`&&(0,S.jsxs)(`p`,{className:`card-sub`,style:{margin:`8px 0 0`},children:[t(`codexAuth.openaiMissing`),` `,(0,S.jsx)(`a`,{href:`#providers`,children:t(`codexAuth.openProviders`)})]}),n===`disabled`&&(0,S.jsxs)(`p`,{className:`card-sub`,style:{margin:`8px 0 0`},children:[t(`codexAuth.openaiDisabled`),` `,(0,S.jsx)(`a`,{href:`#providers`,children:t(`codexAuth.openProviders`)})]})]})})}function Ai(e,t){return new Date(e).toLocaleDateString(t)}function ji({apiBase:e}){let{t,locale:n}=H(),r=ye.find(e=>e.code===n)?.htmlLang,[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(!1),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(null),y=(0,_.useCallback)(async()=>{try{let t=await fetch(`${e}/api/keys`);if(t.ok){let e=await t.json();a(e.keys??[]),s(e.endpoint??``)}}catch{}},[e]);(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{y()},0);return()=>window.clearTimeout(e)},[y]);let b=o||`http://127.0.0.1:10100/v1/responses`,x=async()=>{d(!0);try{let t=await fetch(`${e}/api/keys`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:c||`default`})});t.ok&&(p((await t.json()).key),l(``),y())}finally{d(!1)}},C=async t=>{await fetch(`${e}/api/keys`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:t})}),v(null),y()},w=()=>{f&&(navigator.clipboard.writeText(f),h(!0),setTimeout(()=>h(!1),2e3))},T=t(`api.subtitle`).split(/\{authHeader\}|\{altHeader\}/);return(0,S.jsxs)(`section`,{className:`api-page`,children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h2`,{children:t(`api.title`)})}),(0,S.jsxs)(`p`,{className:`page-sub`,children:[T[0],(0,S.jsx)(`code`,{children:`Authorization: Bearer ocx_...`}),T[1],(0,S.jsx)(`code`,{children:`x-opencodex-api-key`}),T[2]]}),(0,S.jsxs)(`div`,{className:`panel api-panel`,children:[(0,S.jsx)(`h3`,{className:`panel-title`,children:t(`api.endpoint`)}),(0,S.jsx)(`code`,{className:`api-code api-code-inline`,children:b}),(0,S.jsx)(`p`,{className:`muted small`,children:t(`api.endpointNote`)})]}),f&&(0,S.jsxs)(`div`,{className:`panel api-panel panel-accent`,style:{marginTop:`1rem`},children:[(0,S.jsx)(`h3`,{className:`panel-title`,children:t(`api.newKeyTitle`)}),(0,S.jsx)(`p`,{className:`muted small`,children:t(`api.newKeyNote`)}),(0,S.jsxs)(`div`,{className:`api-form-row`,children:[(0,S.jsx)(`code`,{className:`api-code`,style:{flex:1,wordBreak:`break-all`},children:f}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,onClick:w,children:m?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(M,{}),` `,t(`api.copied`)]}):t(`api.copy`)})]}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,style:{alignSelf:`flex-start`},onClick:()=>p(null),children:t(`api.dismiss`)})]}),(0,S.jsxs)(`div`,{className:`panel api-panel`,style:{marginTop:`1rem`},children:[(0,S.jsx)(`h3`,{className:`panel-title`,children:t(`api.generateTitle`)}),(0,S.jsxs)(`div`,{className:`api-form-row`,children:[(0,S.jsx)(`input`,{id:`api-key-name`,type:`text`,placeholder:t(`api.keyNamePlaceholder`),"aria-label":t(`api.keyNamePlaceholder`),value:c,onChange:e=>l(e.target.value),className:`input`}),(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-primary`,onClick:x,disabled:u,children:[(0,S.jsx)(P,{}),` `,t(u?`api.generating`:`api.generate`)]})]})]}),(0,S.jsxs)(`div`,{className:`panel api-panel`,style:{marginTop:`1rem`},children:[(0,S.jsx)(`h3`,{className:`panel-title`,children:t(`api.activeKeys`,{count:i.length})}),i.length===0?(0,S.jsx)(`p`,{className:`muted`,children:t(`api.noKeys`)}):(0,S.jsx)(`div`,{className:`tbl-wrap`,children:(0,S.jsxs)(`table`,{className:`tbl`,children:[(0,S.jsx)(`thead`,{children:(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`th`,{children:t(`api.colName`)}),(0,S.jsx)(`th`,{children:t(`api.colKey`)}),(0,S.jsx)(`th`,{children:t(`api.colCreated`)}),(0,S.jsx)(`th`,{})]})}),(0,S.jsx)(`tbody`,{children:i.map(e=>(0,S.jsxs)(`tr`,{children:[(0,S.jsx)(`td`,{children:e.name}),(0,S.jsx)(`td`,{children:(0,S.jsx)(`code`,{children:e.prefix})}),(0,S.jsx)(`td`,{children:Ai(e.createdAt,r)}),(0,S.jsx)(`td`,{children:g===e.id?(0,S.jsxs)(`span`,{className:`api-actions`,children:[(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-danger`,onClick:()=>C(e.id),children:t(`api.confirm`)}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,onClick:()=>v(null),children:t(`common.cancel`)})]}):(0,S.jsx)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,"aria-label":t(`api.deleteAria`),onClick:()=>v(e.id),children:(0,S.jsx)(N,{})})})]},e.id))})]})})]}),(0,S.jsxs)(`div`,{className:`panel api-panel`,style:{marginTop:`1rem`},children:[(0,S.jsx)(`h3`,{className:`panel-title`,children:t(`api.usageTitle`)}),(0,S.jsx)(`pre`,{className:`api-code`,children:`curl ${b} \\
|
|
34
34
|
-H "Authorization: Bearer ocx_YOUR_KEY_HERE" \\
|
|
35
35
|
-H "Content-Type: application/json" \\
|
|
36
36
|
-d '{
|
|
37
37
|
"model": "gpt-5.4",
|
|
38
38
|
"input": "Hello, world!"
|
|
39
|
-
}'`})]})]})}var
|
|
40
|
-
`)}function Ni({label:e,checked:t,onChange:n}){return(0,S.jsxs)(`label`,{className:`toggle`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>n(e.target.checked),"aria-label":e}),(0,S.jsx)(`span`,{className:`slider`,"aria-hidden":`true`})]})}function Pi({apiBase:e}){let t=U(),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(!0),f=(0,_.useCallback)(async()=>{try{let t=await fetch(`${e}/api/claude-code`).then(e=>e.json());r({...t,authMode:t.authMode===`proxy`?`proxy`:`subscription`,systemEnv:t.systemEnv!==!1,fastMode:t.fastMode??null,maxContextTokens:t.maxContextTokens??null,autoContext:t.autoContext!==!1,autoCompactWindow:t.autoCompactWindow??null,injectAgents:t.injectAgents!==!1,effectiveModelEnv:t.effectiveModelEnv??{}}),a(Object.entries(t.modelMap??{}).map(([e,t])=>({from:e,to:String(t)})))}catch{l(!1),s(t(`claude.loadFail`))}finally{d(!1)}},[e,t]);(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{f()},0);return()=>window.clearTimeout(e)},[f]);let p=(0,_.useMemo)(()=>{let e=(n?.available??[]).map(e=>({value:e,label:String(tr(e))}));return[{value:``,label:t(`claude.slotUnset`)},...e]},[n?.available,t]),m=(0,_.useMemo)(()=>{let e=[1e5,2e5,25e4,3e5,35e4,4e5,5e5,6e5,75e4,9e5,1e6],r=n?.autoCompactWindow??null,i=r!==null&&!e.includes(r)?[...e,r].sort((e,t)=>e-t):e;return[{value:``,label:t(`claude.autoCompactDefault`)},...i.map(e=>({value:String(e),label:ji(e)}))]},[n?.autoCompactWindow,t]),h=async()=>{if(!n)return;s(``);let r={};for(let e of i)e.from.trim()&&e.to.trim()&&(r[e.from.trim()]=e.to.trim());try{let i=await fetch(`${e}/api/claude-code`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:n.enabled,authMode:n.authMode,systemEnv:n.systemEnv,fastMode:n.fastMode,autoContext:n.autoContext,autoCompactWindow:n.autoCompactWindow,injectAgents:n.injectAgents,smallFastModel:n.smallFastModel,modelMap:r,webSearchSidecar:n.webSearchSidecar?{backend:n.webSearchSidecar.backend??null,model:n.webSearchSidecar.model??``}:null,visionSidecar:n.visionSidecar?{backend:n.visionSidecar.backend??null,model:n.visionSidecar.model??``}:null})}),a=await i.json();l(i.ok),s(i.ok?t(`claude.saved`):a.error||t(`claude.saveFailed`)),i.ok&&await f()}catch{l(!1),s(t(`claude.networkError`))}};if(u)return(0,S.jsx)(`div`,{className:`muted`,style:{padding:8},children:t(`claude.loading`)});if(!n)return(0,S.jsx)(W,{tone:`err`,children:o||t(`claude.loadFail`)});let g=Mi(n);return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h2`,{children:t(`claude.pageTitle`)})}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`claude.subtitle`)}),o&&(0,S.jsx)(W,{tone:c?`ok`:`err`,children:o}),(0,S.jsxs)(`div`,{className:`card`,style:{overflow:`hidden`},children:[(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.enabledLabel`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.enabledHint`)})]}),(0,S.jsx)(Ni,{label:t(`claude.enabledLabel`),checked:n.enabled,onChange:e=>r({...n,enabled:e})})]}),(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.authMode`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.authModeHint`)})]}),(0,S.jsx)(G,{value:n.authMode,options:[{value:`subscription`,label:t(`claude.authModeSubscription`)},{value:`proxy`,label:t(`claude.authModeProxy`)}],onChange:e=>r({...n,authMode:e}),label:t(`claude.authMode`),style:{minWidth:220}})]}),(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.systemEnv`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.systemEnvDesc`)}),n.systemEnv&&(0,S.jsx)(`span`,{className:`desc`,style:{color:`var(--red)`},children:t(`claude.systemEnvWarn`)})]}),(0,S.jsx)(Ni,{label:t(`claude.systemEnv`),checked:n.systemEnv,onChange:e=>r({...n,systemEnv:e})})]}),(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.fastMode`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.fastModeDesc`)})]}),(0,S.jsxs)(`select`,{value:n.fastMode===null?`auto`:n.fastMode?`on`:`off`,onChange:e=>{let t=e.target.value;r({...n,fastMode:t===`auto`?null:t===`on`})},className:`text-label font-medium`,"aria-label":t(`claude.fastMode`),style:{padding:`5px 10px`,borderRadius:`var(--radius-xs)`,border:`1px solid var(--border)`,background:`var(--surface)`,color:`var(--text)`},children:[(0,S.jsx)(`option`,{value:`auto`,children:t(`claude.fastAuto`)}),(0,S.jsx)(`option`,{value:`on`,children:t(`claude.fastOn`)}),(0,S.jsx)(`option`,{value:`off`,children:t(`claude.fastOff`)})]})]}),(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.autoContext`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.autoContextDesc`)}),n.maxContextTokens!==null&&(0,S.jsx)(`span`,{className:`desc`,style:{color:`var(--muted)`},children:t(`claude.autoContextInert`)})]}),(0,S.jsx)(Ni,{label:t(`claude.autoContext`),checked:n.autoContext,onChange:e=>r({...n,autoContext:e})})]}),n.autoContext&&(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.autoCompactWindow`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.autoCompactWindowDesc`)}),n.autoCompactWindow!==null&&(0,S.jsx)(`span`,{className:`desc`,style:{color:`var(--red)`},children:t(`claude.autoCompactWindowWarn`)})]}),(0,S.jsx)(G,{value:n.autoCompactWindow===null?``:String(n.autoCompactWindow),options:m,onChange:e=>r({...n,autoCompactWindow:e===``?null:Number(e)}),label:t(`claude.autoCompactWindow`),style:{minWidth:130}})]}),(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.injectAgents`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.injectAgentsDesc`)})]}),(0,S.jsx)(Ni,{label:t(`claude.injectAgents`),checked:n.injectAgents,onChange:e=>r({...n,injectAgents:e})})]}),[`webSearchSidecar`,`visionSidecar`].map(e=>{let i=n[e],a=e===`webSearchSidecar`?`claude.webSearchSidecar`:`claude.visionSidecar`,o=e===`webSearchSidecar`?`claude.webSearchSidecarHint`:`claude.visionSidecarHint`;return(0,S.jsxs)(`div`,{className:`setting-row`,style:{alignItems:`flex-start`},children:[(0,S.jsxs)(`div`,{className:`setting-label setting-copy`,style:{flex:1},children:[(0,S.jsx)(`span`,{className:`title`,children:t(a)}),(0,S.jsx)(`span`,{className:`desc`,children:t(o)})]}),(0,S.jsxs)(`div`,{className:`setting-controls`,style:{display:`flex`,gap:8},children:[(0,S.jsx)(G,{value:i?i.backend??`auto`:`inherit`,options:[{value:`inherit`,label:t(`claude.useMainSetting`)},{value:`auto`,label:t(`dash.backendAuto`)},{value:`openai`,label:t(`dash.backendOpenAI`)},{value:`anthropic`,label:t(`dash.backendAnthropic`)}],onChange:t=>r({...n,[e]:t===`inherit`?void 0:{...i,backend:t===`auto`?void 0:t}}),label:t(`dash.sidecarBackend`)}),(0,S.jsx)(`input`,{className:`input mono`,value:i?.model??``,onChange:t=>r({...n,[e]:{...i,model:t.target.value}}),placeholder:t(`claude.sidecarModelPlaceholder`),disabled:!i,"aria-label":t(`dash.sidecarModel`),style:{minWidth:210}})]})]},e)})]}),(0,S.jsx)(`div`,{className:`h-section`,children:t(`claude.quickstart`)}),(0,S.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:(0,S.jsx)(Te,{k:`claude.quickstartHint`,cmd:`ocx claude`})}),(0,S.jsx)(`pre`,{className:`mono card`,style:{padding:`10px 14px`,overflowX:`auto`,margin:0},children:`ocx claude`}),(0,S.jsxs)(`details`,{style:{margin:`10px 0 0`},children:[(0,S.jsx)(`summary`,{className:`muted text-label`,style:{cursor:`pointer`,padding:`2px 2px`},children:t(`claude.manualEnv`)}),(0,S.jsx)(`pre`,{className:`mono card text-label`,style:{padding:`10px 14px`,overflowX:`auto`,margin:`6px 0 0`},children:g})]}),(0,S.jsx)(`div`,{className:`h-section`,children:t(`claude.smallFastModel`)}),(0,S.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:t(`claude.smallFastModelHint`)}),(0,S.jsx)(G,{value:n.smallFastModel,options:p,onChange:e=>r({...n,smallFastModel:e}),label:t(`claude.smallFastModel`),style:{maxWidth:420}}),(0,S.jsxs)(`div`,{className:`h-section`,children:[t(`claude.modelMap`),` `,(0,S.jsx)(`span`,{className:`count`,children:i.length})]}),(0,S.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:t(`claude.modelMapHint`)}),(0,S.jsx)(`div`,{className:`stack`,style:{gap:8},children:i.map((e,n)=>(0,S.jsxs)(`div`,{className:`row`,style:{gap:8},children:[(0,S.jsx)(`input`,{className:`input mono`,value:e.from,placeholder:t(`claude.mapFrom`),"aria-label":t(`claude.mapFrom`),onChange:e=>a(t=>t.map((t,r)=>r===n?{...t,from:e.target.value}:t)),style:{flex:1}}),(0,S.jsx)(`span`,{className:`muted`,"aria-hidden":!0,children:`→`}),(0,S.jsx)(`input`,{className:`input mono`,value:e.to,placeholder:t(`claude.mapTo`),"aria-label":t(`claude.mapTo`),onChange:e=>a(t=>t.map((t,r)=>r===n?{...t,to:e.target.value}:t)),style:{flex:1}}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon btn-sm`,onClick:()=>a(e=>e.filter((e,t)=>t!==n)),"aria-label":t(`claude.removeMapping`),style:{color:`var(--red)`},children:(0,S.jsx)(N,{})})]},n))}),(0,S.jsx)(`div`,{style:{marginTop:8},children:(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>a(e=>[...e,{from:``,to:``}]),children:[(0,S.jsx)(P,{}),` `,t(`claude.addMapping`)]})}),(0,S.jsx)(`div`,{style:{marginTop:14},children:(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:h,children:t(`common.save`)})}),(0,S.jsxs)(`div`,{className:`h-section`,children:[t(`claude.aliases`),` `,(0,S.jsx)(`span`,{className:`count`,children:n.aliases.length})]}),(0,S.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:t(`claude.aliasesHint`)}),n.aliases.length===0?(0,S.jsx)(`div`,{className:`muted text-label`,children:t(`claude.none`)}):(0,S.jsx)(`div`,{className:`stack`,style:{gap:6,maxHeight:320,overflowY:`auto`},children:Array.from(n.aliases.reduce((e,t)=>{let n=/\(([^)]+)\)\s*$/.exec(t.display_name),r=n?n[1]:`etc`;return(e.get(r)??e.set(r,[]).get(r)).push(t),e},new Map)).map(([e,t])=>(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`div`,{className:`muted text-caption font-semibold`,style:{textTransform:`uppercase`,letterSpacing:`var(--tracking-wide)`,margin:`6px 2px 4px`},children:[e,` · `,t.length]}),(0,S.jsx)(`div`,{className:`stack`,style:{gap:4},children:t.map(e=>(0,S.jsxs)(`div`,{className:`card row`,style:{padding:`6px 12px`,gap:10},children:[(0,S.jsx)(`code`,{className:`mono text-label`,style:{flex:1},children:e.id}),(0,S.jsx)(`span`,{className:`muted text-label`,children:e.display_name})]},e.id))})]},e))})]})}var Fi=`opencodex-api-token`,Ii=!1,Li=null;function Ri(e){try{let t=e instanceof Request?e.url:String(e);return new URL(t,window.location.href).pathname}catch{return null}}function zi(e){let t=Ri(e);return!!t&&(t.startsWith(`/api/`)||t.startsWith(`/v1/`))}function Bi(){try{return sessionStorage.getItem(Fi)?.trim()||null}catch{return null}}function Vi(e){try{sessionStorage.setItem(Fi,e)}catch{}}function Hi(){try{sessionStorage.removeItem(Fi)}catch{}}function Ui(e,t,n){let r=new Headers(t?.headers??(e instanceof Request?e.headers:void 0));return r.set(`X-OpenCodex-API-Key`,n),e instanceof Request?[new Request(e,{headers:r}),t?{...t,headers:r}:void 0]:[e,{...t,headers:r}]}async function Wi(){return Li||(Li=Promise.resolve().then(()=>window.prompt(`OpenCodex API token`)?.trim()||null).finally(()=>{Li=null}),Li)}function Gi(){if(Ii)return;Ii=!0;let e=window.fetch.bind(window);window.fetch=async(t,n)=>{if(!zi(t))return e(t,n);let r=Bi(),[i,a]=r?Ui(t,n,r):[t,n],o=await e(i,a);if(o.status!==401)return o;r&&Hi();let s=await Wi();if(!s)return o;Vi(s);let[c,l]=Ui(t,n,s),u=await e(c,l);return u.status===401&&Hi(),u}}Gi();var Ki=new Set([`dashboard`,`providers`,`models`,`combos`,`subagents`,`logs`,`debug`,`usage`,`codex-auth`,`api`,`claude`]);function qi(){let e=location.hash.replace(/^#\/?/,``).split(`/`)[0];return Ki.has(e)?e:`dashboard`}function Ji(e,t){return e===t||t===`providers`&&e===`providers/workspace`}var Yi=``,Xi=`ocx-theme`,Zi=[{id:`dashboard`,tkey:`nav.dashboard`,Icon:w},{id:`providers`,tkey:`nav.providers`,Icon:T},{id:`models`,tkey:`nav.models`,Icon:E},{id:`combos`,tkey:`nav.combos`,Icon:pe},{id:`subagents`,tkey:`nav.subagents`,Icon:D},{id:`logs`,tkey:`nav.logs`,Icon:O},{id:`debug`,tkey:`nav.debug`,Icon:A},{id:`usage`,tkey:`nav.usage`,Icon:j},{id:`codex-auth`,tkey:`nav.codexAuth`,Icon:ae},{id:`api`,tkey:`nav.api`,Icon:de},{id:`claude`,tkey:`nav.claude`,Icon:fe}],Qi={light:le,dark:V,system:ue},$i={light:`theme.light`,dark:`theme.dark`,system:`theme.system`};function ea(e){if(!e||typeof e!=`object`||!(`version`in e))return null;let t=e.version;return typeof t==`string`&&t.length>0?t:null}function ta(){let e=localStorage.getItem(Xi);return e===`light`||e===`dark`?e:`system`}function na(){let[e,t]=(0,_.useState)(qi),[n,r]=(0,_.useState)(ta),[i,a]=(0,_.useState)(null),{locale:o,setLocale:s}=H(),c=U(),[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=(0,_.useRef)(null),p=(0,_.useRef)(!1);(0,_.useEffect)(()=>{let e=()=>{let e=qi(),n=window.location.hash.replace(/^#\/?/,``);if(u(!1),!Ji(n,e)){window.location.hash=e;return}t(e)};return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},[]),(0,_.useEffect)(()=>{Ji(window.location.hash.replace(/^#\/?/,``),e)||(window.location.hash=e)},[e]),(0,_.useEffect)(()=>{let e=document.documentElement;n===`system`?(e.removeAttribute(`data-theme`),localStorage.removeItem(Xi)):(e.setAttribute(`data-theme`,n),localStorage.setItem(Xi,n))},[n]),(0,_.useEffect)(()=>{let e=!1,t=async()=>{try{let t=await fetch(`${Yi}/healthz`);if(!t.ok)return;let n=ea(await t.json());!e&&n&&a(n)}catch{}};t();let n=setInterval(t,3e4);return()=>{e=!0,clearInterval(n)}},[]);let m=()=>r(e=>e===`light`?`dark`:e===`dark`?`system`:`light`),h=Qi[n],g=i??`2.7.25`,[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(null);(0,_.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&u(!1)};window.addEventListener(`keydown`,e);let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{window.removeEventListener(`keydown`,e),document.body.style.overflow=t}},[l]),(0,_.useEffect)(()=>{if(l){p.current=!0;let e=setTimeout(()=>f.current?.focus(),200);return()=>clearTimeout(e)}p.current&&(p.current=!1,d.current?.focus())},[l]),(0,_.useEffect)(()=>{let e=window.matchMedia(`(min-width: 761px)`),t=()=>{e.matches&&u(!1)};return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,_.useEffect)(()=>{let e=!1;return fetch(`${Yi}/api/claude-code`).then(e=>e.json()).then(t=>{!e&&typeof t.enabled==`boolean`&&x(t.enabled)}).catch(()=>{}),()=>{e=!0}},[]);let C=async()=>{if(b===null)return;let e=!b;x(e);try{(await fetch(`${Yi}/api/claude-code`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:e})})).ok||x(!e)}catch{x(!e)}},w=async()=>{if(confirm(c(`dash.stopConfirm`))){y(!0);try{await fetch(`${Yi}/api/stop`,{method:`POST`})}catch{}}},T=(0,S.jsxs)(`div`,{className:`brand`,children:[(0,S.jsx)(`span`,{className:`brand-logo`,role:`img`,"aria-label":c(`app.logoAria`)}),(0,S.jsx)(`span`,{className:`name`,children:`opencodex`}),(0,S.jsxs)(`span`,{className:`ver`,children:[`v`,g]})]});return(0,S.jsxs)(`div`,{className:`app`,children:[(0,S.jsxs)(`header`,{className:`mobile-topbar`,inert:l,children:[(0,S.jsx)(`button`,{ref:d,type:`button`,className:`menu-toggle`,onClick:()=>u(e=>!e),"aria-expanded":l,"aria-controls":`app-sidebar`,"aria-label":c(l?`nav.closeMenu`:`nav.openMenu`),title:c(l?`nav.closeMenu`:`nav.openMenu`),children:(0,S.jsx)(k,{})}),T,(0,S.jsx)(`button`,{type:`button`,className:`theme-toggle stop-toggle`,onClick:w,disabled:v,"aria-label":c(`dash.stop`),title:c(`dash.stop`),children:(0,S.jsx)(re,{})})]}),l&&(0,S.jsx)(`div`,{className:`drawer-scrim`,onClick:()=>u(!1),"aria-hidden":`true`}),(0,S.jsxs)(`aside`,{id:`app-sidebar`,className:`sidebar${l?` open`:``}`,ref:f,tabIndex:-1,children:[(0,S.jsxs)(`div`,{className:`drawer-head`,children:[T,(0,S.jsx)(`button`,{type:`button`,className:`menu-toggle drawer-close`,onClick:()=>u(!1),"aria-label":c(`nav.closeMenu`),title:c(`nav.closeMenu`),children:(0,S.jsx)(N,{})})]}),(0,S.jsx)(`nav`,{children:Zi.map(({id:n,tkey:r,Icon:i})=>(0,S.jsxs)(`button`,{className:`nav-item${e===n?` active`:``}`,"data-page":n,onClick:()=>{t(n),u(!1)},"aria-current":e===n?`page`:void 0,children:[(0,S.jsx)(i,{}),` `,c(r)]},n))}),(0,S.jsxs)(`div`,{className:`sidebar-foot`,children:[b!==null&&(0,S.jsxs)(`button`,{type:`button`,className:`theme-toggle`,onClick:C,"aria-pressed":b,"aria-label":c(`claude.toggleAria`),title:c(`claude.toggleAria`),style:b?{color:`var(--accent)`}:void 0,children:[(0,S.jsx)(fe,{}),` `,(0,S.jsx)(`span`,{className:`mode`,children:c(b?`app.claudeOn`:`app.claudeOff`)})]}),(0,S.jsxs)(`div`,{className:`lang-toggle`,children:[(0,S.jsx)(de,{"aria-hidden":!0}),(0,S.jsx)(G,{value:o,options:ye.map(e=>({value:e.code,label:e.name})),onChange:e=>s(e),label:c(`lang.label`),placement:`right`,style:{flex:1,minWidth:0,width:`100%`}})]}),(0,S.jsxs)(`button`,{type:`button`,className:`theme-toggle`,onClick:m,"aria-label":`${c(`theme.label`)}: ${c($i[n])}`,title:`${c(`theme.label`)}: ${c($i[n])}`,children:[(0,S.jsx)(h,{}),` `,(0,S.jsx)(`span`,{className:`mode`,children:c($i[n])})]}),(0,S.jsxs)(`button`,{type:`button`,className:`theme-toggle stop-toggle`,onClick:w,disabled:v,"aria-label":c(`dash.stop`),title:c(`dash.stop`),children:[(0,S.jsx)(re,{}),` `,(0,S.jsx)(`span`,{className:`mode`,children:c(v?`dash.stopping`:`dash.stop`)})]}),(0,S.jsxs)(`a`,{className:`sidebar-link`,href:`https://github.com/lidge-jun/opencodex`,target:`_blank`,rel:`noreferrer`,children:[(0,S.jsx)(B,{}),` `,c(`common.github`)]})]})]}),(0,S.jsx)(`main`,{className:`main`,inert:l,children:(0,S.jsxs)(`div`,{className:`main-inner${e===`combos`?` main-inner--combos`:``}`,children:[e===`dashboard`&&(0,S.jsx)(Ve,{apiBase:Yi}),e===`providers`&&(0,S.jsx)(Xn,{apiBase:Yi}),e===`models`&&(0,S.jsx)(dr,{apiBase:Yi}),e===`combos`&&(0,S.jsx)(Wr,{apiBase:Yi}),e===`subagents`&&(0,S.jsx)(Gr,{apiBase:Yi}),e===`logs`&&(0,S.jsx)(ii,{apiBase:Yi}),e===`debug`&&(0,S.jsx)(fi,{apiBase:Yi}),e===`usage`&&(0,S.jsx)(Ei,{apiBase:Yi}),e===`codex-auth`&&(0,S.jsx)(K,{apiBase:Yi}),e===`api`&&(0,S.jsx)(ki,{apiBase:Yi}),e===`claude`&&(0,S.jsx)(Pi,{apiBase:Yi})]})})]})}v.createRoot(document.getElementById(`root`)).render((0,S.jsx)(_.StrictMode,{children:(0,S.jsx)(we,{children:(0,S.jsx)(na,{})})}));
|
|
39
|
+
}'`})]})]})}var Mi=[`ANTHROPIC_MODEL`,`ANTHROPIC_DEFAULT_OPUS_MODEL`,`ANTHROPIC_DEFAULT_SONNET_MODEL`,`ANTHROPIC_DEFAULT_HAIKU_MODEL`,`ANTHROPIC_DEFAULT_FABLE_MODEL`];function Ni(e){return e>=1e6?`1M`:`${Math.round(e/1e3)}k`}function Pi(e){let t=`http://127.0.0.1:${e.port}`,n=e.autoContext&&e.maxContextTokens===null,r=Mi.filter(t=>e.effectiveModelEnv[t]).map(t=>`export ${t}=${e.effectiveModelEnv[t]}`);return[`export ANTHROPIC_BASE_URL=${t}`,...e.authMode===`proxy`?[`export ANTHROPIC_AUTH_TOKEN=opencodex-proxy`]:[`# no ANTHROPIC_AUTH_TOKEN: your claude.ai login (and connectors) stay active`],`export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`,...n?[`export CLAUDE_CODE_AUTO_COMPACT_WINDOW=${e.autoCompactWindow??35e4}`]:[],...r,`claude`].join(`
|
|
40
|
+
`)}function Fi({label:e,checked:t,onChange:n}){return(0,S.jsxs)(`label`,{className:`toggle`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t,onChange:e=>n(e.target.checked),"aria-label":e}),(0,S.jsx)(`span`,{className:`slider`,"aria-hidden":`true`})]})}function Ii({apiBase:e}){let t=U(),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(!0),f=(0,_.useCallback)(async()=>{try{let t=await fetch(`${e}/api/claude-code`).then(e=>e.json());r({...t,authMode:t.authMode===`proxy`?`proxy`:`subscription`,systemEnv:t.systemEnv!==!1,fastMode:t.fastMode??null,maxContextTokens:t.maxContextTokens??null,autoContext:t.autoContext!==!1,autoCompactWindow:t.autoCompactWindow??null,injectAgents:t.injectAgents!==!1,effectiveModelEnv:t.effectiveModelEnv??{}}),a(Object.entries(t.modelMap??{}).map(([e,t])=>({from:e,to:String(t)})))}catch{l(!1),s(t(`claude.loadFail`))}finally{d(!1)}},[e,t]);(0,_.useEffect)(()=>{let e=window.setTimeout(()=>{f()},0);return()=>window.clearTimeout(e)},[f]);let p=(0,_.useMemo)(()=>{let e=(n?.available??[]).map(e=>({value:e,label:String(rr(e))}));return[{value:``,label:t(`claude.slotUnset`)},...e]},[n?.available,t]),m=(0,_.useMemo)(()=>{let e=[1e5,2e5,25e4,3e5,35e4,4e5,5e5,6e5,75e4,9e5,1e6],r=n?.autoCompactWindow??null,i=r!==null&&!e.includes(r)?[...e,r].sort((e,t)=>e-t):e;return[{value:``,label:t(`claude.autoCompactDefault`)},...i.map(e=>({value:String(e),label:Ni(e)}))]},[n?.autoCompactWindow,t]),h=async()=>{if(!n)return;s(``);let r={};for(let e of i)e.from.trim()&&e.to.trim()&&(r[e.from.trim()]=e.to.trim());try{let i=await fetch(`${e}/api/claude-code`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:n.enabled,authMode:n.authMode,systemEnv:n.systemEnv,fastMode:n.fastMode,autoContext:n.autoContext,autoCompactWindow:n.autoCompactWindow,injectAgents:n.injectAgents,smallFastModel:n.smallFastModel,modelMap:r,webSearchSidecar:n.webSearchSidecar?{backend:n.webSearchSidecar.backend??null,model:n.webSearchSidecar.model??``}:null,visionSidecar:n.visionSidecar?{backend:n.visionSidecar.backend??null,model:n.visionSidecar.model??``}:null})}),a=await i.json();l(i.ok),s(i.ok?t(`claude.saved`):a.error||t(`claude.saveFailed`)),i.ok&&await f()}catch{l(!1),s(t(`claude.networkError`))}};if(u)return(0,S.jsx)(`div`,{className:`muted`,style:{padding:8},children:t(`claude.loading`)});if(!n)return(0,S.jsx)(W,{tone:`err`,children:o||t(`claude.loadFail`)});let g=Pi(n);return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`page-head`,children:(0,S.jsx)(`h2`,{children:t(`claude.pageTitle`)})}),(0,S.jsx)(`p`,{className:`page-sub`,children:t(`claude.subtitle`)}),o&&(0,S.jsx)(W,{tone:c?`ok`:`err`,children:o}),(0,S.jsxs)(`div`,{className:`card`,style:{overflow:`hidden`},children:[(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.enabledLabel`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.enabledHint`)})]}),(0,S.jsx)(Fi,{label:t(`claude.enabledLabel`),checked:n.enabled,onChange:e=>r({...n,enabled:e})})]}),(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.authMode`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.authModeHint`)})]}),(0,S.jsx)(G,{value:n.authMode,options:[{value:`subscription`,label:t(`claude.authModeSubscription`)},{value:`proxy`,label:t(`claude.authModeProxy`)}],onChange:e=>r({...n,authMode:e}),label:t(`claude.authMode`),style:{minWidth:220}})]}),(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.systemEnv`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.systemEnvDesc`)}),n.systemEnv&&(0,S.jsx)(`span`,{className:`desc`,style:{color:`var(--red)`},children:t(`claude.systemEnvWarn`)})]}),(0,S.jsx)(Fi,{label:t(`claude.systemEnv`),checked:n.systemEnv,onChange:e=>r({...n,systemEnv:e})})]}),(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.fastMode`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.fastModeDesc`)})]}),(0,S.jsxs)(`select`,{value:n.fastMode===null?`auto`:n.fastMode?`on`:`off`,onChange:e=>{let t=e.target.value;r({...n,fastMode:t===`auto`?null:t===`on`})},className:`text-label font-medium`,"aria-label":t(`claude.fastMode`),style:{padding:`5px 10px`,borderRadius:`var(--radius-xs)`,border:`1px solid var(--border)`,background:`var(--surface)`,color:`var(--text)`},children:[(0,S.jsx)(`option`,{value:`auto`,children:t(`claude.fastAuto`)}),(0,S.jsx)(`option`,{value:`on`,children:t(`claude.fastOn`)}),(0,S.jsx)(`option`,{value:`off`,children:t(`claude.fastOff`)})]})]}),(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.autoContext`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.autoContextDesc`)}),n.maxContextTokens!==null&&(0,S.jsx)(`span`,{className:`desc`,style:{color:`var(--muted)`},children:t(`claude.autoContextInert`)})]}),(0,S.jsx)(Fi,{label:t(`claude.autoContext`),checked:n.autoContext,onChange:e=>r({...n,autoContext:e})})]}),n.autoContext&&(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.autoCompactWindow`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.autoCompactWindowDesc`)}),n.autoCompactWindow!==null&&(0,S.jsx)(`span`,{className:`desc`,style:{color:`var(--red)`},children:t(`claude.autoCompactWindowWarn`)})]}),(0,S.jsx)(G,{value:n.autoCompactWindow===null?``:String(n.autoCompactWindow),options:m,onChange:e=>r({...n,autoCompactWindow:e===``?null:Number(e)}),label:t(`claude.autoCompactWindow`),style:{minWidth:130}})]}),(0,S.jsxs)(`div`,{className:`setting-row`,children:[(0,S.jsxs)(`div`,{className:`setting-label`,children:[(0,S.jsx)(`span`,{className:`title`,children:t(`claude.injectAgents`)}),(0,S.jsx)(`span`,{className:`desc`,children:t(`claude.injectAgentsDesc`)})]}),(0,S.jsx)(Fi,{label:t(`claude.injectAgents`),checked:n.injectAgents,onChange:e=>r({...n,injectAgents:e})})]}),[`webSearchSidecar`,`visionSidecar`].map(e=>{let i=n[e],a=e===`webSearchSidecar`?`claude.webSearchSidecar`:`claude.visionSidecar`,o=e===`webSearchSidecar`?`claude.webSearchSidecarHint`:`claude.visionSidecarHint`;return(0,S.jsxs)(`div`,{className:`setting-row`,style:{alignItems:`flex-start`},children:[(0,S.jsxs)(`div`,{className:`setting-label setting-copy`,style:{flex:1},children:[(0,S.jsx)(`span`,{className:`title`,children:t(a)}),(0,S.jsx)(`span`,{className:`desc`,children:t(o)})]}),(0,S.jsxs)(`div`,{className:`setting-controls`,style:{display:`flex`,gap:8},children:[(0,S.jsx)(G,{value:i?i.backend??`auto`:`inherit`,options:[{value:`inherit`,label:t(`claude.useMainSetting`)},{value:`auto`,label:t(`dash.backendAuto`)},{value:`openai`,label:t(`dash.backendOpenAI`)},{value:`anthropic`,label:t(`dash.backendAnthropic`)}],onChange:t=>r({...n,[e]:t===`inherit`?void 0:{...i,backend:t===`auto`?void 0:t}}),label:t(`dash.sidecarBackend`)}),(0,S.jsx)(`input`,{className:`input mono`,value:i?.model??``,onChange:t=>r({...n,[e]:{...i,model:t.target.value}}),placeholder:t(`claude.sidecarModelPlaceholder`),disabled:!i,"aria-label":t(`dash.sidecarModel`),style:{minWidth:210}})]})]},e)})]}),(0,S.jsx)(`div`,{className:`h-section`,children:t(`claude.quickstart`)}),(0,S.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:(0,S.jsx)(Te,{k:`claude.quickstartHint`,cmd:`ocx claude`})}),(0,S.jsx)(`pre`,{className:`mono card`,style:{padding:`10px 14px`,overflowX:`auto`,margin:0},children:`ocx claude`}),(0,S.jsxs)(`details`,{style:{margin:`10px 0 0`},children:[(0,S.jsx)(`summary`,{className:`muted text-label`,style:{cursor:`pointer`,padding:`2px 2px`},children:t(`claude.manualEnv`)}),(0,S.jsx)(`pre`,{className:`mono card text-label`,style:{padding:`10px 14px`,overflowX:`auto`,margin:`6px 0 0`},children:g})]}),(0,S.jsx)(`div`,{className:`h-section`,children:t(`claude.smallFastModel`)}),(0,S.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:t(`claude.smallFastModelHint`)}),(0,S.jsx)(G,{value:n.smallFastModel,options:p,onChange:e=>r({...n,smallFastModel:e}),label:t(`claude.smallFastModel`),style:{maxWidth:420}}),(0,S.jsxs)(`div`,{className:`h-section`,children:[t(`claude.modelMap`),` `,(0,S.jsx)(`span`,{className:`count`,children:i.length})]}),(0,S.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:t(`claude.modelMapHint`)}),(0,S.jsx)(`div`,{className:`stack`,style:{gap:8},children:i.map((e,n)=>(0,S.jsxs)(`div`,{className:`row`,style:{gap:8},children:[(0,S.jsx)(`input`,{className:`input mono`,value:e.from,placeholder:t(`claude.mapFrom`),"aria-label":t(`claude.mapFrom`),onChange:e=>a(t=>t.map((t,r)=>r===n?{...t,from:e.target.value}:t)),style:{flex:1}}),(0,S.jsx)(`span`,{className:`muted`,"aria-hidden":!0,children:`→`}),(0,S.jsx)(`input`,{className:`input mono`,value:e.to,placeholder:t(`claude.mapTo`),"aria-label":t(`claude.mapTo`),onChange:e=>a(t=>t.map((t,r)=>r===n?{...t,to:e.target.value}:t)),style:{flex:1}}),(0,S.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon btn-sm`,onClick:()=>a(e=>e.filter((e,t)=>t!==n)),"aria-label":t(`claude.removeMapping`),style:{color:`var(--red)`},children:(0,S.jsx)(N,{})})]},n))}),(0,S.jsx)(`div`,{style:{marginTop:8},children:(0,S.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>a(e=>[...e,{from:``,to:``}]),children:[(0,S.jsx)(P,{}),` `,t(`claude.addMapping`)]})}),(0,S.jsx)(`div`,{style:{marginTop:14},children:(0,S.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:h,children:t(`common.save`)})}),(0,S.jsxs)(`div`,{className:`h-section`,children:[t(`claude.aliases`),` `,(0,S.jsx)(`span`,{className:`count`,children:n.aliases.length})]}),(0,S.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:t(`claude.aliasesHint`)}),n.aliases.length===0?(0,S.jsx)(`div`,{className:`muted text-label`,children:t(`claude.none`)}):(0,S.jsx)(`div`,{className:`stack`,style:{gap:6,maxHeight:320,overflowY:`auto`},children:Array.from(n.aliases.reduce((e,t)=>{let n=/\(([^)]+)\)\s*$/.exec(t.display_name),r=n?n[1]:`etc`;return(e.get(r)??e.set(r,[]).get(r)).push(t),e},new Map)).map(([e,t])=>(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`div`,{className:`muted text-caption font-semibold`,style:{textTransform:`uppercase`,letterSpacing:`var(--tracking-wide)`,margin:`6px 2px 4px`},children:[e,` · `,t.length]}),(0,S.jsx)(`div`,{className:`stack`,style:{gap:4},children:t.map(e=>(0,S.jsxs)(`div`,{className:`card row`,style:{padding:`6px 12px`,gap:10},children:[(0,S.jsx)(`code`,{className:`mono text-label`,style:{flex:1},children:e.id}),(0,S.jsx)(`span`,{className:`muted text-label`,children:e.display_name})]},e.id))})]},e))})]})}var Li=`opencodex-api-token`,Ri=!1,zi=null;function Bi(e){try{let t=e instanceof Request?e.url:String(e);return new URL(t,window.location.href).pathname}catch{return null}}function Vi(e){let t=Bi(e);return!!t&&(t.startsWith(`/api/`)||t.startsWith(`/v1/`))}function Hi(){try{return sessionStorage.getItem(Li)?.trim()||null}catch{return null}}function Ui(e){try{sessionStorage.setItem(Li,e)}catch{}}function Wi(){try{sessionStorage.removeItem(Li)}catch{}}function Gi(e,t,n){let r=new Headers(t?.headers??(e instanceof Request?e.headers:void 0));return r.set(`X-OpenCodex-API-Key`,n),e instanceof Request?[new Request(e,{headers:r}),t?{...t,headers:r}:void 0]:[e,{...t,headers:r}]}async function Ki(){return zi||(zi=Promise.resolve().then(()=>window.prompt(`OpenCodex API token`)?.trim()||null).finally(()=>{zi=null}),zi)}function qi(){if(Ri)return;Ri=!0;let e=window.fetch.bind(window);window.fetch=async(t,n)=>{if(!Vi(t))return e(t,n);let r=Hi(),[i,a]=r?Gi(t,n,r):[t,n],o=await e(i,a);if(o.status!==401)return o;r&&Wi();let s=await Ki();if(!s)return o;Ui(s);let[c,l]=Gi(t,n,s),u=await e(c,l);return u.status===401&&Wi(),u}}qi();var Ji=new Set([`dashboard`,`providers`,`models`,`combos`,`subagents`,`logs`,`debug`,`usage`,`codex-auth`,`api`,`claude`]);function Yi(){let e=location.hash.replace(/^#\/?/,``).split(`/`)[0];return Ji.has(e)?e:`dashboard`}function Xi(e,t){return e===t||t===`providers`&&e===`providers/workspace`}var Zi=``,Qi=`ocx-theme`,$i=[{id:`dashboard`,tkey:`nav.dashboard`,Icon:w},{id:`providers`,tkey:`nav.providers`,Icon:T},{id:`models`,tkey:`nav.models`,Icon:E},{id:`combos`,tkey:`nav.combos`,Icon:pe},{id:`subagents`,tkey:`nav.subagents`,Icon:D},{id:`logs`,tkey:`nav.logs`,Icon:O},{id:`debug`,tkey:`nav.debug`,Icon:A},{id:`usage`,tkey:`nav.usage`,Icon:j},{id:`codex-auth`,tkey:`nav.codexAuth`,Icon:ae},{id:`api`,tkey:`nav.api`,Icon:de},{id:`claude`,tkey:`nav.claude`,Icon:fe}],ea={light:le,dark:V,system:ue},ta={light:`theme.light`,dark:`theme.dark`,system:`theme.system`};function na(e){if(!e||typeof e!=`object`||!(`version`in e))return null;let t=e.version;return typeof t==`string`&&t.length>0?t:null}function ra(){let e=localStorage.getItem(Qi);return e===`light`||e===`dark`?e:`system`}function ia(){let[e,t]=(0,_.useState)(Yi),[n,r]=(0,_.useState)(ra),[i,a]=(0,_.useState)(null),{locale:o,setLocale:s}=H(),c=U(),[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=(0,_.useRef)(null),p=(0,_.useRef)(!1);(0,_.useEffect)(()=>{let e=()=>{let e=Yi(),n=window.location.hash.replace(/^#\/?/,``);if(u(!1),!Xi(n,e)){window.location.hash=e;return}t(e)};return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},[]),(0,_.useEffect)(()=>{Xi(window.location.hash.replace(/^#\/?/,``),e)||(window.location.hash=e)},[e]),(0,_.useEffect)(()=>{let e=document.documentElement;n===`system`?(e.removeAttribute(`data-theme`),localStorage.removeItem(Qi)):(e.setAttribute(`data-theme`,n),localStorage.setItem(Qi,n))},[n]),(0,_.useEffect)(()=>{let e=!1,t=async()=>{try{let t=await fetch(`${Zi}/healthz`);if(!t.ok)return;let n=na(await t.json());!e&&n&&a(n)}catch{}};t();let n=setInterval(t,3e4);return()=>{e=!0,clearInterval(n)}},[]);let m=()=>r(e=>e===`light`?`dark`:e===`dark`?`system`:`light`),h=ea[n],g=i??`2.7.26`,[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(null);(0,_.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&u(!1)};window.addEventListener(`keydown`,e);let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{window.removeEventListener(`keydown`,e),document.body.style.overflow=t}},[l]),(0,_.useEffect)(()=>{if(l){p.current=!0;let e=setTimeout(()=>f.current?.focus(),200);return()=>clearTimeout(e)}p.current&&(p.current=!1,d.current?.focus())},[l]),(0,_.useEffect)(()=>{let e=window.matchMedia(`(min-width: 761px)`),t=()=>{e.matches&&u(!1)};return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,_.useEffect)(()=>{let e=!1;return fetch(`${Zi}/api/claude-code`).then(e=>e.json()).then(t=>{!e&&typeof t.enabled==`boolean`&&x(t.enabled)}).catch(()=>{}),()=>{e=!0}},[]);let C=async()=>{if(b===null)return;let e=!b;x(e);try{(await fetch(`${Zi}/api/claude-code`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:e})})).ok||x(!e)}catch{x(!e)}},w=async()=>{if(confirm(c(`dash.stopConfirm`))){y(!0);try{await fetch(`${Zi}/api/stop`,{method:`POST`})}catch{}}},T=(0,S.jsxs)(`div`,{className:`brand`,children:[(0,S.jsx)(`span`,{className:`brand-logo`,role:`img`,"aria-label":c(`app.logoAria`)}),(0,S.jsx)(`span`,{className:`name`,children:`opencodex`}),(0,S.jsxs)(`span`,{className:`ver`,children:[`v`,g]})]});return(0,S.jsxs)(`div`,{className:`app`,children:[(0,S.jsxs)(`header`,{className:`mobile-topbar`,inert:l,children:[(0,S.jsx)(`button`,{ref:d,type:`button`,className:`menu-toggle`,onClick:()=>u(e=>!e),"aria-expanded":l,"aria-controls":`app-sidebar`,"aria-label":c(l?`nav.closeMenu`:`nav.openMenu`),title:c(l?`nav.closeMenu`:`nav.openMenu`),children:(0,S.jsx)(k,{})}),T,(0,S.jsx)(`button`,{type:`button`,className:`theme-toggle stop-toggle`,onClick:w,disabled:v,"aria-label":c(`dash.stop`),title:c(`dash.stop`),children:(0,S.jsx)(re,{})})]}),l&&(0,S.jsx)(`div`,{className:`drawer-scrim`,onClick:()=>u(!1),"aria-hidden":`true`}),(0,S.jsxs)(`aside`,{id:`app-sidebar`,className:`sidebar${l?` open`:``}`,ref:f,tabIndex:-1,children:[(0,S.jsxs)(`div`,{className:`drawer-head`,children:[T,(0,S.jsx)(`button`,{type:`button`,className:`menu-toggle drawer-close`,onClick:()=>u(!1),"aria-label":c(`nav.closeMenu`),title:c(`nav.closeMenu`),children:(0,S.jsx)(N,{})})]}),(0,S.jsx)(`nav`,{children:$i.map(({id:n,tkey:r,Icon:i})=>(0,S.jsxs)(`button`,{className:`nav-item${e===n?` active`:``}`,"data-page":n,onClick:()=>{t(n),u(!1)},"aria-current":e===n?`page`:void 0,children:[(0,S.jsx)(i,{}),` `,c(r)]},n))}),(0,S.jsxs)(`div`,{className:`sidebar-foot`,children:[b!==null&&(0,S.jsxs)(`button`,{type:`button`,className:`theme-toggle`,onClick:C,"aria-pressed":b,"aria-label":c(`claude.toggleAria`),title:c(`claude.toggleAria`),style:b?{color:`var(--accent)`}:void 0,children:[(0,S.jsx)(fe,{}),` `,(0,S.jsx)(`span`,{className:`mode`,children:c(b?`app.claudeOn`:`app.claudeOff`)})]}),(0,S.jsxs)(`div`,{className:`lang-toggle`,children:[(0,S.jsx)(de,{"aria-hidden":!0}),(0,S.jsx)(G,{value:o,options:ye.map(e=>({value:e.code,label:e.name})),onChange:e=>s(e),label:c(`lang.label`),placement:`right`,style:{flex:1,minWidth:0,width:`100%`}})]}),(0,S.jsxs)(`button`,{type:`button`,className:`theme-toggle`,onClick:m,"aria-label":`${c(`theme.label`)}: ${c(ta[n])}`,title:`${c(`theme.label`)}: ${c(ta[n])}`,children:[(0,S.jsx)(h,{}),` `,(0,S.jsx)(`span`,{className:`mode`,children:c(ta[n])})]}),(0,S.jsxs)(`button`,{type:`button`,className:`theme-toggle stop-toggle`,onClick:w,disabled:v,"aria-label":c(`dash.stop`),title:c(`dash.stop`),children:[(0,S.jsx)(re,{}),` `,(0,S.jsx)(`span`,{className:`mode`,children:c(v?`dash.stopping`:`dash.stop`)})]}),(0,S.jsxs)(`a`,{className:`sidebar-link`,href:`https://github.com/lidge-jun/opencodex`,target:`_blank`,rel:`noreferrer`,children:[(0,S.jsx)(B,{}),` `,c(`common.github`)]})]})]}),(0,S.jsx)(`main`,{className:`main`,inert:l,children:(0,S.jsxs)(`div`,{className:`main-inner${e===`combos`?` main-inner--combos`:``}`,children:[e===`dashboard`&&(0,S.jsx)(Ue,{apiBase:Zi}),e===`providers`&&(0,S.jsx)(Qn,{apiBase:Zi}),e===`models`&&(0,S.jsx)(pr,{apiBase:Zi}),e===`combos`&&(0,S.jsx)(Kr,{apiBase:Zi}),e===`subagents`&&(0,S.jsx)(qr,{apiBase:Zi}),e===`logs`&&(0,S.jsx)(oi,{apiBase:Zi}),e===`debug`&&(0,S.jsx)(mi,{apiBase:Zi}),e===`usage`&&(0,S.jsx)(K,{apiBase:Zi}),e===`codex-auth`&&(0,S.jsx)(ki,{apiBase:Zi}),e===`api`&&(0,S.jsx)(ji,{apiBase:Zi}),e===`claude`&&(0,S.jsx)(Ii,{apiBase:Zi})]})})]})}v.createRoot(document.getElementById(`root`)).render((0,S.jsx)(_.StrictMode,{children:(0,S.jsx)(we,{children:(0,S.jsx)(ia,{})})}));
|