@xopcai/xopc 0.0.88 → 0.0.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/README.zh-CN.md +8 -1
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/feishu/src/outbound/media-load.js +1 -1
- package/dist/extensions/feishu/src/workflow-progress.js +1 -1
- package/dist/extensions/telegram/src/plugin.js +1 -1
- package/dist/extensions/telegram/src/routing-integration.js +2 -2
- package/dist/extensions/telegram/src/workflow-progress.js +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/extensions/weixin/src/api/api.js +2 -2
- package/dist/extensions/weixin/src/auth/accounts.js +1 -1
- package/dist/extensions/weixin/src/cdn/upload.js +1 -1
- package/dist/extensions/weixin/src/media/data-url.js +1 -1
- package/dist/extensions/weixin/src/messaging/debug-mode.js +1 -1
- package/dist/extensions/weixin/src/messaging/inbound.js +1 -1
- package/dist/extensions/weixin/src/messaging/process-message.js +1 -1
- package/dist/extensions/weixin/src/plugin.js +1 -1
- package/dist/extensions/weixin/src/storage/sync-buf.js +1 -1
- package/dist/extensions/weixin/src/workflow-progress.js +1 -1
- package/dist/gateway/static/root/assets/agents-B6PJB07W.js +222 -0
- package/dist/gateway/static/root/assets/apps-page-BOr0B1wv.js +1 -0
- package/dist/gateway/static/root/assets/channels-settings-BelUKggl.js +1 -0
- package/dist/gateway/static/root/assets/{channels-status-swr-DIsl75Y3.js → channels-status-swr-DaHGkRF1.js} +1 -1
- package/dist/gateway/static/root/assets/cron-api-CjOg-BIj.js +1 -0
- package/dist/gateway/static/root/assets/cron-page-DhoZmZXb.js +1 -0
- package/dist/gateway/static/root/assets/{dist-CJwfHYvT.js → dist-6LecgDx5.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-BVJohZoZ.js → extension-debug-page-CtuKJ9tE.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-BT2tmElC.js → extension-page-ykzjOkR5.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BSS47c2j.js → extension-settings-page-Ce2qrdpO.js} +1 -1
- package/dist/gateway/static/root/assets/{fetch-BaFNUtkE.js → fetch-C9FFJjuH.js} +1 -1
- package/dist/gateway/static/root/assets/{field-primitives-QwYEq6Hz.js → field-primitives-BFcrNeTU.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-config-api-BVSidEDJ.js → heartbeat-config-api-CEg4Vr9R.js} +1 -1
- package/dist/gateway/static/root/assets/{index-qNrVJp-y.js → index-CZfy9oxs.js} +97 -97
- package/dist/gateway/static/root/assets/index-CiN1cQiQ.css +1 -0
- package/dist/gateway/static/root/assets/logs-page-BwWLfqvd.js +1 -0
- package/dist/gateway/static/root/assets/sessions-page-DV5WN8uk.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-B8N3A3Zo.js → settings-form-section-BqdzA28u.js} +1 -1
- package/dist/gateway/static/root/assets/settings-page-CfOBRbPX.js +3 -0
- package/dist/gateway/static/root/assets/{share-preview-page-Q7KqkO-u.js → share-preview-page-Di5Bzh4g.js} +1 -1
- package/dist/gateway/static/root/assets/skills-page-D0H5Kaxg.js +2 -0
- package/dist/gateway/static/root/assets/{theme-store-BbRc5ugR.js → theme-store-CNqbmTNV.js} +1 -1
- package/dist/gateway/static/root/assets/url-aYn-Rj1C.js +7 -0
- package/dist/gateway/static/root/assets/{utils-CxDGduqK.js → utils-BWm2tG2w.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-CTyHz7L_.js → voice-api-key-field-X2UfnHeq.js} +1 -1
- package/dist/gateway/static/root/assets/workflows-page-BOPpO3NG.js +27 -0
- package/dist/gateway/static/root/index.html +5 -6
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-manager.d.ts +2 -0
- package/dist/src/agent/agent-manager.js +8 -7
- package/dist/src/agent/agent-manager.js.map +1 -1
- package/dist/src/agent/agent-scope.js +1 -1
- package/dist/src/agent/bootstrap/load-bootstrap-files.js +1 -1
- package/dist/src/agent/context/workspace-seed.js +2 -2
- package/dist/src/agent/goals/goal-run-store.js +4 -4
- package/dist/src/agent/goals/persistent-goal-service.js +1 -1
- package/dist/src/agent/goals/post-turn.js +2 -2
- package/dist/src/agent/image/load-image-media.js +2 -2
- package/dist/src/agent/ipc/bus.js +1 -1
- package/dist/src/agent/ipc/inbox.js +2 -2
- package/dist/src/agent/ipc/socket.js +1 -1
- package/dist/src/agent/mcp/bundle-mcp-materialize.js +1 -1
- package/dist/src/agent/mcp/bundle-mcp-runtime.js +1 -1
- package/dist/src/agent/mcp/mcp-transport-config.js +1 -1
- package/dist/src/agent/mcp/mcp-transport.js +1 -1
- package/dist/src/agent/memory/builtin-memory-store.js +1 -1
- package/dist/src/agent/memory/dreaming/deep-promotion.js +1 -1
- package/dist/src/agent/memory/dreaming/events.js +1 -1
- package/dist/src/agent/memory/dreaming/last-run.js +1 -1
- package/dist/src/agent/memory/dreaming/light-sweep.js +1 -1
- package/dist/src/agent/memory/dreaming/preview.js +1 -1
- package/dist/src/agent/memory/dreaming/rem-patterns.js +1 -1
- package/dist/src/agent/memory/dreaming/short-term-store.js +1 -1
- package/dist/src/agent/memory/dreaming/utils.js +1 -1
- package/dist/src/agent/memory/plugin-discovery.js +1 -1
- package/dist/src/agent/models/manager.js +1 -1
- package/dist/src/agent/prompt/service-prompt-builder.js +2 -2
- package/dist/src/agent/reply/post-compaction-context.js +1 -1
- package/dist/src/agent/reply/workspace-boundary-read.js +1 -1
- package/dist/src/agent/sandbox/path-policy.js +2 -2
- package/dist/src/agent/service/build-direct-message-content.js +1 -1
- package/dist/src/agent/service.js +6 -5
- package/dist/src/agent/service.js.map +1 -1
- package/dist/src/agent/service.types.d.ts +3 -1
- package/dist/src/agent/session/session-inspector.js +1 -1
- package/dist/src/agent/skills/config.js +1 -1
- package/dist/src/agent/skills/hub-hash.js +2 -2
- package/dist/src/agent/skills/hub-lock.js +1 -1
- package/dist/src/agent/skills/hub-pull.js +2 -2
- package/dist/src/agent/skills/index.js +1 -1
- package/dist/src/agent/skills/managed-store.js +1 -1
- package/dist/src/agent/skills/scanner.js +1 -1
- package/dist/src/agent/skills/skill-manage-ops.js +1 -1
- package/dist/src/agent/skills/skill-manager.js +1 -1
- package/dist/src/agent/tools/cronjob-tool.js +2 -1
- package/dist/src/agent/tools/cronjob-tool.js.map +1 -1
- package/dist/src/agent/tools/dreaming-tool.js +1 -1
- package/dist/src/agent/tools/factory.d.ts +3 -0
- package/dist/src/agent/tools/factory.js +3 -24
- package/dist/src/agent/tools/factory.js.map +1 -1
- package/dist/src/agent/tools/image-generate-tool.js +1 -1
- package/dist/src/agent/tools/send-media.js +1 -1
- package/dist/src/agent/tools/skill-manage-tool.js +1 -1
- package/dist/src/agent/tools/workflow-tool.d.ts +6 -28
- package/dist/src/agent/tools/workflow-tool.js +61 -261
- package/dist/src/agent/tools/workflow-tool.js.map +1 -1
- package/dist/src/agent/tools/write.js +1 -1
- package/dist/src/agent/workflow/catalog.js +1 -1
- package/dist/src/agent/workflow/workflow-child-tools.d.ts +4 -0
- package/dist/src/agent/workflow/workflow-child-tools.js +21 -0
- package/dist/src/agent/workflow/workflow-child-tools.js.map +1 -0
- package/dist/src/auth/credentials.d.ts +14 -2
- package/dist/src/auth/credentials.js +40 -15
- package/dist/src/auth/credentials.js.map +1 -1
- package/dist/src/auth/oauth/types.d.ts +16 -0
- package/dist/src/auth/profiles/store.js +1 -1
- package/dist/src/auth/sync-provider-auth.js +1 -1
- package/dist/src/browser/cache-dir-policy.js +1 -1
- package/dist/src/browser/cdp-local-launcher.js +2 -2
- package/dist/src/browser/providers/browser-ext-install.js +3 -3
- package/dist/src/browser/providers/cloakbrowser.js +4 -4
- package/dist/src/browser/providers/playwright-doctor.js +1 -1
- package/dist/src/browser/stealth.js +1 -1
- package/dist/src/channels/attachments/inbound-persist.js +1 -1
- package/dist/src/channels/attachments/outbound-tts-persist.js +1 -1
- package/dist/src/channels/outbound/persist-store.js +1 -1
- package/dist/src/channels/pairing/allow-from-file.js +1 -1
- package/dist/src/channels/pairing/pairing-store.js +2 -2
- package/dist/src/chat-commands/builtins/config.js +2 -2
- package/dist/src/chat-commands/context.js +1 -1
- package/dist/src/cli/commands/auth.js +6 -0
- package/dist/src/cli/commands/auth.js.map +1 -1
- package/dist/src/cli/commands/config.js +1 -1
- package/dist/src/cli/commands/doctor/checks/config-health.js +1 -1
- package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
- package/dist/src/cli/commands/doctor/checks/session-integrity.js +1 -1
- package/dist/src/cli/commands/doctor/checks/state-integrity.js +1 -1
- package/dist/src/cli/commands/doctor/checks/workspace-status.js +1 -1
- package/dist/src/cli/commands/extension-dev.js +1 -1
- package/dist/src/cli/commands/extension-marketplace.js +1 -1
- package/dist/src/cli/commands/extension-pack.js +1 -1
- package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
- package/dist/src/cli/commands/gateway/logs.js +1 -1
- package/dist/src/cli/commands/image.js +1 -1
- package/dist/src/cli/commands/init.js +4 -4
- package/dist/src/cli/commands/onboard/model.js +6 -0
- package/dist/src/cli/commands/onboard/model.js.map +1 -1
- package/dist/src/cli/commands/onboard.js +1 -1
- package/dist/src/cli/utils/init-workspace-core.js +2 -2
- package/dist/src/config/agent-profile.js +1 -1
- package/dist/src/config/agent-typed-models.js +1 -1
- package/dist/src/config/gateway-bind.js +1 -1
- package/dist/src/config/index.js +5 -5
- package/dist/src/config/loader.js +2 -2
- package/dist/src/config/models-json.js +2 -2
- package/dist/src/config/paths-state.js +1 -1
- package/dist/src/config/profile.js +2 -2
- package/dist/src/config/workspace-path.js +1 -1
- package/dist/src/cron/executor.d.ts +2 -0
- package/dist/src/cron/executor.js +61 -7
- package/dist/src/cron/executor.js.map +1 -1
- package/dist/src/cron/job-content.js +2 -1
- package/dist/src/cron/job-content.js.map +1 -1
- package/dist/src/cron/persistence.js +1 -1
- package/dist/src/cron/run-log-store.js +1 -1
- package/dist/src/cron/types.d.ts +21 -1
- package/dist/src/cron/validation.d.ts +76 -0
- package/dist/src/cron/validation.js +26 -1
- package/dist/src/cron/validation.js.map +1 -1
- package/dist/src/daemon/constants.js +1 -1
- package/dist/src/daemon/install-plan.js +2 -2
- package/dist/src/daemon/launchd.js +2 -2
- package/dist/src/daemon/schtasks.js +2 -2
- package/dist/src/daemon/systemd.js +2 -2
- package/dist/src/extensions/bundle-mcp.js +1 -1
- package/dist/src/extensions/discover-extensions.js +1 -1
- package/dist/src/extensions/health.js +1 -1
- package/dist/src/extensions/loader.js +1 -1
- package/dist/src/extensions/lockfile.js +2 -2
- package/dist/src/gateway/agents-admin.js +3 -3
- package/dist/src/gateway/file-path-classifier.js +2 -2
- package/dist/src/gateway/gateway-workflow-host.types.d.ts +17 -0
- package/dist/src/gateway/gateway-workflow-host.types.js +1 -0
- package/dist/src/gateway/hono/lib/config-payload.js +1 -1
- package/dist/src/gateway/hono/lib/extension-store.js +2 -2
- package/dist/src/gateway/hono/lib/static-ui.js +2 -2
- package/dist/src/gateway/hono/oauth-async.js +40 -15
- package/dist/src/gateway/hono/oauth-async.js.map +1 -1
- package/dist/src/gateway/hono/oauth.js +31 -6
- package/dist/src/gateway/hono/oauth.js.map +1 -1
- package/dist/src/gateway/hono/routes/agents.js +1 -1
- package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +1 -1
- package/dist/src/gateway/hono/routes/dreaming.js +1 -1
- package/dist/src/gateway/hono/routes/host-fs.js +2 -2
- package/dist/src/gateway/hono/routes/models.js +12 -6
- package/dist/src/gateway/hono/routes/models.js.map +1 -1
- package/dist/src/gateway/hono/routes/shares.js +1 -1
- package/dist/src/gateway/hono/routes/workflows.js +69 -190
- package/dist/src/gateway/hono/routes/workflows.js.map +1 -1
- package/dist/src/gateway/hono/routes/workspace.js +4 -4
- package/dist/src/gateway/lock.js +3 -3
- package/dist/src/gateway/ports.js +1 -1
- package/dist/src/gateway/service/agent-runner.js +2 -2
- package/dist/src/gateway/service/marketplace-service.js +2 -2
- package/dist/src/gateway/service.d.ts +5 -0
- package/dist/src/gateway/service.js +23 -3
- package/dist/src/gateway/service.js.map +1 -1
- package/dist/src/gateway/workspace-fs-file-list.js +1 -1
- package/dist/src/infra/restart.js +2 -2
- package/dist/src/infra/update-check.js +1 -1
- package/dist/src/infra/update-global.js +1 -1
- package/dist/src/infra/update-lock.js +3 -3
- package/dist/src/infra/update-runner.js +1 -1
- package/dist/src/infra/update-startup.js +2 -2
- package/dist/src/infra/write-file-atomic.js +2 -2
- package/dist/src/providers/auth-runtime/auth-profile-store.js +1 -1
- package/dist/src/providers/index.d.ts +8 -0
- package/dist/src/providers/index.js +53 -14
- package/dist/src/providers/index.js.map +1 -1
- package/dist/src/providers/model-registry.js +1 -1
- package/dist/src/session/config-store.js +2 -2
- package/dist/src/session/init-session-turn.js +2 -2
- package/dist/src/session/parity/jsonl-transcript-io.js +2 -2
- package/dist/src/session/parity/sessions-json-file.js +1 -1
- package/dist/src/session/parity/transcript-file-lock.js +2 -2
- package/dist/src/session/parity/transcript-paths.js +1 -1
- package/dist/src/session/resolve-session.js +4 -4
- package/dist/src/session/search-index-cache.js +1 -1
- package/dist/src/session/search-index.js +1 -1
- package/dist/src/session/session-title.js +2 -2
- package/dist/src/session/store.js +5 -5
- package/dist/src/share/share-auto.js +2 -2
- package/dist/src/share/share-store.js +3 -3
- package/dist/src/share/share-thumbnail.js +2 -2
- package/dist/src/share/share-zip.js +1 -1
- package/dist/src/share/site-share-config.d.ts +3 -2
- package/dist/src/share/site-share-config.js.map +1 -1
- package/dist/src/share/site-share-store.js +3 -3
- package/dist/src/share/site-static-serve.js +1 -1
- package/dist/src/tui/clipboard-image.js +3 -3
- package/dist/src/tui/theme-manager.js +1 -1
- package/dist/src/tui/tui-keybindings-file.js +1 -1
- package/dist/src/tui/tui-scoped-models.js +2 -2
- package/dist/src/tui/tui-settings.js +1 -1
- package/dist/src/tui/tui.js +3 -3
- package/dist/src/tunnel/frpc-binary.js +3 -3
- package/dist/src/tunnel/frpc-config.js +1 -1
- package/dist/src/tunnel/frpc-extract.js +1 -1
- package/dist/src/tunnel/tunnel-state.js +1 -1
- package/dist/src/utils/logger/audit.js +1 -1
- package/dist/src/utils/logger/log-store.js +1 -1
- package/dist/src/utils/logger/rotation.js +1 -1
- package/dist/src/voice/tts/audio.js +1 -1
- package/dist/src/voice/tts/providers/edge-speech.js +2 -2
- package/dist/src/workflows/domain/command.d.ts +2 -1
- package/dist/src/workflows/domain/definition-utils.d.ts +14 -0
- package/dist/src/workflows/domain/definition-utils.js +50 -0
- package/dist/src/workflows/domain/definition-utils.js.map +1 -0
- package/dist/src/workflows/domain/index.d.ts +2 -0
- package/dist/src/workflows/domain/index.js +3 -1
- package/dist/src/workflows/domain/run.d.ts +57 -0
- package/dist/src/workflows/domain/run.js.map +1 -1
- package/dist/src/workflows/domain/validation.d.ts +19 -0
- package/dist/src/workflows/domain/validation.js +66 -0
- package/dist/src/workflows/domain/validation.js.map +1 -0
- package/dist/src/workflows/engine/workflow-engine.d.ts +2 -1
- package/dist/src/workflows/engine/workflow-engine.js +1 -0
- package/dist/src/workflows/engine/workflow-engine.js.map +1 -1
- package/dist/src/workflows/index.d.ts +4 -0
- package/dist/src/workflows/index.js +9 -2
- package/dist/src/workflows/service/run-view-to-snapshot.d.ts +4 -0
- package/dist/src/workflows/service/run-view-to-snapshot.js +61 -0
- package/dist/src/workflows/service/run-view-to-snapshot.js.map +1 -0
- package/dist/src/workflows/service/workflow-run-service.d.ts +36 -0
- package/dist/src/workflows/service/workflow-run-service.js +279 -0
- package/dist/src/workflows/service/workflow-run-service.js.map +1 -0
- package/dist/src/workflows/service/workflow-run-service.types.d.ts +47 -0
- package/dist/src/workflows/service/workflow-run-service.types.js +1 -0
- package/dist/src/workflows/service/workflow-session-bridge.d.ts +29 -0
- package/dist/src/workflows/service/workflow-session-bridge.js +177 -0
- package/dist/src/workflows/service/workflow-session-bridge.js.map +1 -0
- package/dist/src/workflows/service/workflow-session-key.d.ts +3 -0
- package/dist/src/workflows/service/workflow-session-key.js +21 -0
- package/dist/src/workflows/service/workflow-session-key.js.map +1 -0
- package/dist/src/workflows/store/event-store.js +1 -1
- package/dist/src/workflows/store/run-store.js +2 -1
- package/dist/src/workflows/store/run-store.js.map +1 -1
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/agents-CRxETUZx.js +0 -222
- package/dist/gateway/static/root/assets/apps-page-wKWf3l57.js +0 -1
- package/dist/gateway/static/root/assets/channels-settings-DDbqVNkx.js +0 -1
- package/dist/gateway/static/root/assets/copy-SxMW6Xpc.js +0 -1
- package/dist/gateway/static/root/assets/cron-api-N9hvuRrn.js +0 -1
- package/dist/gateway/static/root/assets/cron-page-tlNGNxhP.js +0 -1
- package/dist/gateway/static/root/assets/index-CqZzHNEg.css +0 -1
- package/dist/gateway/static/root/assets/logs-page-DDonPVLn.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-DKt-Wmib.js +0 -1
- package/dist/gateway/static/root/assets/settings-page-DcJjvvw4.js +0 -3
- package/dist/gateway/static/root/assets/skills-page-DuJ4BTO3.js +0 -2
- package/dist/gateway/static/root/assets/url-D6jvVYIA.js +0 -7
- package/dist/gateway/static/root/assets/workflows-page-GacJ41Fv.js +0 -27
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{a as i,i as a,n as o,o as s,r as c,t as l}from"./url-D6jvVYIA.js";import{a as u,i as d,o as f}from"./vendor-swr-BIWyz7Rc.js";import{n as p,t as m}from"./copy-SxMW6Xpc.js";import{a as h,i as g,n as _,o as v,r as y,s as b,t as x}from"./dist-BTWC-BTN.js";import{i as S}from"./theme-store-BbRc5ugR.js";import{a as C,n as w,t as T}from"./fetch-BaFNUtkE.js";import{$n as E,$r as D,A as O,At as k,B as A,Bt as j,C as M,Ct as N,D as P,Di as F,Dr as I,Dt as L,E as R,Ei as z,Et as B,F as V,Fn as ee,Fr as H,Ft as U,Gi as W,Gt as te,Hr as G,Ht as ne,I as re,In as ie,Ir as ae,It as oe,Ji as se,Jn as ce,Jr as le,Ki as ue,L as de,Li as fe,Ln as pe,Lt as me,M as he,Mi as ge,Mt as _e,N as ve,Ni as ye,Nn as be,Nt as xe,O as Se,Oi as Ce,Or as we,Ot as Te,P as Ee,Pn as De,Pr as Oe,Pt as ke,Qn as Ae,R as je,Rr as Me,Rt as Ne,S as Pe,Sn as Fe,St as Ie,Ti as Le,Tr as Re,Tt as ze,Ur as Be,Ut as Ve,Vt as He,Wn as Ue,Wr as We,Wt as Ge,X as Ke,Xn as qe,Yn as Je,Yr as Ye,Zn as Xe,Zr as Ze,Zt as Qe,_a as $e,_r as et,aa as tt,ar as K,ba as nt,bt as rt,ci as it,cr as at,d as ot,di as st,dr as ct,dt as lt,ea as ut,ei as dt,er as ft,f as pt,fi as mt,fr as ht,g as gt,ga as _t,gr as vt,ha as yt,hi as q,hr as bt,ia as xt,j as St,jt as Ct,k as wt,kn as Tt,kr as Et,kt as Dt,l as Ot,la as kt,li as At,lr as jt,mi as Mt,mr as J,na as Nt,ni as Pt,nr as Ft,oa as It,p as Lt,pr as Y,qn as Rt,qr as zt,si as Bt,sr as Vt,t as Ht,ta as Ut,ti as Wt,tr as Gt,ur as Kt,wi as qt,wr as Jt,wt as Yt,x as Xt,xa as Zt,xn as Qt,xt as $t,yr as en,z as tn,zr as nn,zt as rn}from"./index-qNrVJp-y.js";import{a as an,c as on,d as sn,l as cn,n as ln,o as un,r as dn,s as fn,t as pn,u as mn}from"./voice-api-key-field-CTyHz7L_.js";import{a as hn,i as gn,r as _n}from"./utils-CxDGduqK.js";import{n as vn,r as yn,t as X}from"./settings-form-section-B8N3A3Zo.js";import{c as bn,f as xn,r as Sn}from"./cron-dreaming-jobs-DueM3rBz.js";import{l as Cn}from"./cron-api-N9hvuRrn.js";import{a as wn,c as Tn,d as En,f as Dn,i as On,l as kn,n as An,o as jn,p as Mn,r as Nn,s as Pn,t as Fn,u as In}from"./agents-CRxETUZx.js";import{m as Ln,n as Rn,r as zn,t as Bn}from"./channels-status-swr-DIsl75Y3.js";import{a as Vn,i as Hn,n as Un,o as Wn,r as Gn,s as Kn,t as qn}from"./heartbeat-config-api-BVSidEDJ.js";var Z=e(t(),1),Q=n(),Jn=[{id:`lightChat`,steps:[{path:`/settings/credentials?tab=providers`,labelKey:`stepProviders`},{path:`/settings/agent-defaults`,labelKey:`stepDefaultModel`}]},{id:`multiChannel`,steps:[{path:`/settings/credentials?tab=providers`,labelKey:`stepProviders`},{path:`/settings/agent-defaults`,labelKey:`stepDefaultModel`},{path:`/channels`,labelKey:`stepChannel`},{path:`/agents`,labelKey:`stepPresets`}]},{id:`automation`,steps:[{path:`/settings/credentials?tab=providers`,labelKey:`stepProviders`},{path:`/skills`,labelKey:`stepSkills`},{path:`/cron`,labelKey:`stepCron`}]}],Yn=`xopc-scenario-presets-dismissed`;function Xn(){try{return localStorage.getItem(Yn)===`true`}catch{return!1}}function Zn(){try{localStorage.setItem(Yn,`true`)}catch{}}var $=r();function Qn(e,t){return t[e.labelKey]??e.labelKey}function $n(){let e=(0,Q.c)(5),t=s(a(er)).setupStatus.scenarios,[n,r]=(0,Z.useState)(Xn);if(n)return null;let i,o,c;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=J(`inline-flex shrink-0 items-center gap-1 rounded-lg px-2 py-1.5 text-xs font-medium text-fg-muted`,`hover:bg-surface-hover hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.press),o=()=>{Zn(),r(!0)},c=(0,$.jsx)(vt,{className:`size-3.5`,"aria-hidden":!0}),e[0]=i,e[1]=o,e[2]=c):(i=e[0],o=e[1],c=e[2]);let l=Jn.map(e=>{let n=t.presets[e.id];return(0,$.jsxs)(`article`,{className:`flex flex-col rounded-xl border border-edge-subtle bg-surface-panel p-4`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.title}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:n.description}),(0,$.jsx)(`ol`,{className:`mt-3 flex flex-col gap-1`,children:e.steps.map((n,r)=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(_t,{to:n.path,className:J(`text-xs font-medium text-accent-fg hover:underline`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent rounded`),children:[r+1,`. `,Qn(n,t.steps)]})},`${e.id}-${n.labelKey}`))})]},e.id)}),u;return e[3]===l?u=e[4]:(u=(0,$.jsx)(`div`,{className:`mt-4 grid gap-3 sm:grid-cols-3`,children:l}),e[3]=l,e[4]=u),(0,$.jsxs)(X,{children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,$.jsx)(vn,{icon:Oe,title:t.title,subtitle:t.subtitle}),(0,$.jsxs)(`button`,{type:`button`,className:i,onClick:o,children:[c,t.dismiss]})]}),u]})}function er(e){return e.language}function tr(e){if(!e||typeof e!=`object`)return 0;let t=e.providers;return!t||typeof t!=`object`||Array.isArray(t)?0:Object.values(t).filter(e=>e===`***`).length}function nr(e){if(!e||typeof e!=`object`)return``;let t=e.agents;if(!t||typeof t!=`object`||Array.isArray(t))return``;let n=t.defaults;if(!n||typeof n!=`object`||Array.isArray(n))return``;let r=n.model;return typeof r==`string`?r.trim():``}function rr(e){let t=Ln(e);return t.telegram.enabled&&gn(t.telegram)||t.weixin.enabled&&hn(t.weixin)||t.feishu.enabled&&_n(t.feishu)||gn(t.telegram)||hn(t.weixin)||_n(t.feishu)}function ir(e){let t=tr(e.config),n=e.providerMeta?.configured??t,r=e.providerMeta?.total??0,i=n>0||t>0,a=nr(e.config),o=a.length>0,s=e.hasToken&&e.sseConnected,c=rr(e.config),l=e.skillCount>0,u=[{id:`gateway`,done:s,detail:s?e.labels.gatewayOnline:e.labels.gatewayOffline},{id:`provider`,done:i,detail:i?e.providerMeta&&e.providerMeta.total>0?e.labels.providersMetaReady(n,r):e.labels.providersConfigured(t):e.labels.providersMissing},{id:`defaultModel`,done:o,detail:o?e.labels.modelConfigured(a):e.labels.modelMissing},{id:`channel`,done:c,optional:!0,detail:c?e.labels.channelConfigured:e.labels.channelMissing},{id:`skill`,done:l,optional:!0,detail:l?e.labels.skillsConfigured(e.skillCount):e.labels.skillsMissing},{id:`presets`,done:e.presetsDone,optional:!0,detail:e.presetsDone?e.labels.presetsConfigured:e.labels.presetsMissing}],d=u.filter(e=>!e.optional).every(e=>e.done),f=u.every(e=>e.done);return{gatewayConnected:s,providerConfigured:i,providerCount:t,providerMetaConfigured:n,providerMetaTotal:r,defaultModel:a,defaultModelConfigured:o,channelConfigured:c,skillInstalled:l,skillCount:e.skillCount,presetsDone:e.presetsDone,agentCount:e.agentCount,checklist:u,requiredComplete:d,allComplete:f}}function ar(){try{return localStorage.getItem(Dn)===`true`}catch{return!1}}function or(e,t){return ar()?!0:!e||e.length===0?!1:!(e.length<=1&&e.every(e=>e.id===t))}function sr(){let e=(0,Q.c)(50),t=C(dr),n=a(ur),r;e[0]===n?r=e[1]:(r=s(n),e[0]=n,e[1]=r);let i=r.setupStatus.labels,o=A(lr),{data:c,error:l,isLoading:u,mutate:f}=Fe(!!t),p;e[2]!==n||e[3]!==t?(p=t?[`setup-checklist-skills`,n]:null,e[2]=n,e[3]=t,e[4]=p):p=e[4];let m;e[5]===n?m=e[6]:(m=()=>lt(n),e[5]=n,e[6]=m);let h;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(h={revalidateOnFocus:!1},e[7]=h):h=e[7];let{data:g,error:_,isLoading:v,mutate:y}=d(p,m,h),b;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(b={revalidateOnFocus:!1},e[8]=b):b=e[8];let{data:x,error:S,isLoading:w,mutate:T}=d(t?`setup-checklist-provider-meta`:null,P,b),E;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(E={revalidateOnFocus:!1},e[9]=E):E=e[9];let{data:D,error:O,isLoading:k,mutate:j}=d(t?`setup-checklist-agents`:null,Ke,E),M;e[10]===Symbol.for(`react.memo_cache_sentinel`)?(M={revalidateOnFocus:!1},e[10]=M):M=e[10],d(t?je:null,tn,M);let N=!t||!u&&!v&&!w&&!k,F=!!(l||_||S||O),I;bb0:{if(!t||!N){I=null;break bb0}let n=g?.catalog?.length??0,r;if(e[11]!==D?.agents||e[12]!==D?.defaultId||e[13]!==c?.payload?.config||e[14]!==i.channelConfigured||e[15]!==i.channelMissing||e[16]!==i.gatewayOffline||e[17]!==i.gatewayOnline||e[18]!==i.modelConfigured||e[19]!==i.modelMissing||e[20]!==i.presetsConfigured||e[21]!==i.presetsMissing||e[22]!==i.providersConfigured||e[23]!==i.providersMetaReady||e[24]!==i.providersMissing||e[25]!==i.skillsConfigured||e[26]!==i.skillsMissing||e[27]!==x||e[28]!==n||e[29]!==o||e[30]!==t){let a=x?.filter(cr).length??0,s=x?.length??0,l=D?.agents.length??0,u=or(D?.agents,D?.defaultId),d;e[32]===i.providersConfigured?d=e[33]:(d=e=>i.providersConfigured.replace(`{{count}}`,String(e)),e[32]=i.providersConfigured,e[33]=d);let f;e[34]===i.providersMetaReady?f=e[35]:(f=(e,t)=>i.providersMetaReady.replace(`{{configured}}`,String(e)).replace(`{{total}}`,String(t)),e[34]=i.providersMetaReady,e[35]=f);let p;e[36]===i.modelConfigured?p=e[37]:(p=e=>i.modelConfigured.replace(`{{model}}`,e),e[36]=i.modelConfigured,e[37]=p);let m;e[38]===i.skillsConfigured?m=e[39]:(m=e=>i.skillsConfigured.replace(`{{count}}`,String(e)),e[38]=i.skillsConfigured,e[39]=m),r=ir({hasToken:!!t,sseConnected:o,config:c?.payload?.config,skillCount:n,providerMeta:s>0?{configured:a,total:s}:null,presetsDone:u,agentCount:l,labels:{gatewayOnline:i.gatewayOnline,gatewayOffline:i.gatewayOffline,providersConfigured:d,providersMetaReady:f,providersMissing:i.providersMissing,modelConfigured:p,modelMissing:i.modelMissing,channelConfigured:i.channelConfigured,channelMissing:i.channelMissing,skillsConfigured:m,skillsMissing:i.skillsMissing,presetsConfigured:i.presetsConfigured.replace(`{{count}}`,String(l)),presetsMissing:i.presetsMissing}}),e[11]=D?.agents,e[12]=D?.defaultId,e[13]=c?.payload?.config,e[14]=i.channelConfigured,e[15]=i.channelMissing,e[16]=i.gatewayOffline,e[17]=i.gatewayOnline,e[18]=i.modelConfigured,e[19]=i.modelMissing,e[20]=i.presetsConfigured,e[21]=i.presetsMissing,e[22]=i.providersConfigured,e[23]=i.providersMetaReady,e[24]=i.providersMissing,e[25]=i.skillsConfigured,e[26]=i.skillsMissing,e[27]=x,e[28]=n,e[29]=o,e[30]=t,e[31]=r}else r=e[31];I=r}let L=I,R;e[40]!==j||e[41]!==f||e[42]!==T||e[43]!==y?(R=async()=>{await Promise.all([f(),y(),T(),j()])},e[40]=j,e[41]=f,e[42]=T,e[43]=y,e[44]=R):R=e[44];let z=R,B;return e[45]!==F||e[46]!==N||e[47]!==z||e[48]!==L?(B={ready:N,error:F,snapshot:L,refresh:z},e[45]=F,e[46]=N,e[47]=z,e[48]=L,e[49]=B):B=e[49],B}function cr(e){return e.configured}function lr(e){return e.connectionState===`connected`}function ur(e){return e.language}function dr(e){return e.token}var fr={gateway:`/settings/gateway`,provider:`/settings/credentials`,defaultModel:`/settings/agent-defaults`,channel:`/channels`,skill:`/skills`,presets:`/agents`};function pr(e){let t=(0,Q.c)(5),{ok:n,label:r}=e,i=n?`bg-success-soft text-success`:`bg-surface-hover text-fg-muted`,a;t[0]===i?a=t[1]:(a=J(`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium`,i),t[0]=i,t[1]=a);let o;return t[2]!==r||t[3]!==a?(o=(0,$.jsx)(`span`,{className:a,children:r}),t[2]=r,t[3]=a,t[4]=o):o=t[4],o}function mr(){let e=(0,Q.c)(7),t=s(a(hr)).setupStatus,{ready:n,error:r,snapshot:i,refresh:o}=sr(),c;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=J(`inline-flex shrink-0 items-center gap-2 rounded-lg border border-edge px-3 py-2 text-sm font-medium text-fg`,`hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.press),e[0]=c):c=e[0];let l;e[1]===o?l=e[2]:(l=()=>void o(),e[1]=o,e[2]=l);let u=!n&&`animate-spin`,d;e[3]===u?d=e[4]:(d=J(`size-4`,u),e[3]=u,e[4]=d);let f;return e[5]===d?f=e[6]:(f=(0,$.jsx)(Ze,{className:d,"aria-hidden":!0}),e[5]=d,e[6]=f),(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,$.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.title}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.subtitle})]}),(0,$.jsxs)(`button`,{type:`button`,className:c,onClick:l,disabled:!n,children:[f,t.refresh]})]}),r?(0,$.jsx)(`p`,{className:`rounded-xl border border-red-300/40 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-900/40 dark:bg-red-950/30 dark:text-red-300`,children:t.loadError}):null,!n||!i?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,"aria-busy":!0,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}),t.loading]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(X,{children:[(0,$.jsx)(vn,{icon:tt,title:t.summaryTitle,subtitle:t.summarySubtitle}),(0,$.jsxs)(`div`,{className:`mt-4 grid gap-3 sm:grid-cols-3`,children:[(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.summaryGateway}),(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(pr,{ok:i.gatewayConnected,label:i.gatewayConnected?t.statusOnline:t.statusOffline})})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.summaryProviders}),(0,$.jsx)(`p`,{className:`mt-2 truncate text-sm font-medium text-fg`,children:i.providerConfigured?i.providerMetaTotal>0?t.labels.providersMetaReady.replace(`{{configured}}`,String(i.providerMetaConfigured)).replace(`{{total}}`,String(i.providerMetaTotal)):t.labels.providersConfigured.replace(`{{count}}`,String(i.providerCount)):t.labels.providersMissing})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.summaryModel}),(0,$.jsx)(`p`,{className:`mt-2 truncate text-sm font-medium text-fg`,children:i.defaultModelConfigured?i.defaultModel:t.labels.modelMissing})]})]}),i.requiredComplete?(0,$.jsx)(`p`,{className:`mt-4 text-sm text-success`,children:t.requiredCompleteMessage}):(0,$.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:t.requiredIncompleteMessage})]}),(0,$.jsx)($n,{}),(0,$.jsxs)(X,{children:[(0,$.jsx)(vn,{icon:se,title:t.checklistTitle,subtitle:t.checklistSubtitle}),(0,$.jsx)(`ul`,{className:`mt-4 flex flex-col gap-1`,children:i.checklist.map(e=>{let n=t.items[e.id];return(0,$.jsx)(`li`,{children:(0,$.jsxs)(_t,{to:fr[e.id],className:J(`flex items-center gap-3 rounded-xl px-3 py-3 transition-colors`,`hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),children:[(0,$.jsx)(`span`,{className:J(`flex size-6 shrink-0 items-center justify-center rounded-full border`,e.done?`border-success/40 bg-success-soft text-success`:`border-edge bg-surface-panel text-fg-subtle`),"aria-hidden":!0,children:e.done?(0,$.jsx)(tt,{className:`size-3.5`,strokeWidth:2.5}):null}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.title}),e.optional?(0,$.jsx)(`span`,{className:`rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:t.optionalBadge}):null]}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-muted`,children:n.description}),e.detail?(0,$.jsx)(`span`,{className:`mt-1 block truncate text-xs text-fg-subtle`,children:e.detail}):null]}),(0,$.jsx)(Nt,{className:`size-4 shrink-0 text-fg-subtle`,"aria-hidden":!0})]})},e.id)})})]})]})]})}function hr(e){return e.language}function gr(e,t){let n=!1,r=0,i=t;for(let t of e.values())t.dirty&&(n=!0,r+=1),t.saving&&(i=!0);return{anyDirty:n,dirtyCount:r,anySaving:i}}var _r=i((e,t)=>({sections:new Map,saveAllInFlight:!1,anyDirty:!1,dirtyCount:0,anySaving:!1,registerSection:t=>{e(e=>{let n=new Map(e.sections);return n.set(t.id,t),{sections:n,...gr(n,e.saveAllInFlight)}})},unregisterSection:t=>{e(e=>{if(!e.sections.has(t))return e;let n=new Map(e.sections);return n.delete(t),{sections:n,...gr(n,e.saveAllInFlight)}})},saveAll:async()=>{let n=Array.from(t().sections.values()).filter(e=>e.dirty);if(n.length===0)return{ok:!0,saved:0,failures:[]};e(e=>({saveAllInFlight:!0,...gr(e.sections,!0)}));let r=[],i=0;try{let e=await Promise.all(n.map(async e=>{try{let t=await e.save();return{id:e.id,result:t}}catch(t){return{id:e.id,result:{ok:!1,error:t instanceof Error?t.message:String(t)}}}}));for(let{id:t,result:n}of e)n.ok?i+=1:r.push({id:t,error:n.error??`Save failed`})}finally{e(e=>({saveAllInFlight:!1,...gr(e.sections,!1)}))}return{ok:r.length===0,saved:i,failures:r}},discardAll:()=>{for(let e of t().sections.values())e.dirty&&e.discard()}}));function vr({id:e,dirty:t,saving:n,save:r,discard:i}){let a=(0,Z.useRef)(r),o=(0,Z.useRef)(i);a.current=r,o.current=i;let s=_r(e=>e.registerSection),c=_r(e=>e.unregisterSection);(0,Z.useEffect)(()=>(s({id:e,dirty:t,saving:n,save:async()=>{try{return await a.current(),{ok:!0}}catch(e){return{ok:!1,error:e instanceof Error?e.message:String(e)}}},discard:()=>o.current()}),()=>c(e)),[e,t,n,s,c])}function yr(e){let t=(0,Q.c)(24),{showLabel:n,hideLabel:r,icon:i,hint:a,children:o,className:s,defaultOpen:c}=e,[l,u]=(0,Z.useState)(c??!1),d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=e=>u(e.currentTarget.open),t[0]=d):d=t[0];let f;t[1]===s?f=t[2]:(f=J(`group rounded-2xl bg-surface-base open:pb-1`,s),t[1]=s,t[2]=f);let p;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(xt,{className:`size-4 shrink-0 text-fg-muted transition-transform group-open:rotate-180`,"aria-hidden":!0}),t[3]=p):p=t[3];let m;t[4]===i?m=t[5]:(m=i?(0,$.jsx)(i,{className:`size-4 shrink-0 text-accent`,strokeWidth:1.75,"aria-hidden":!0}):null,t[4]=i,t[5]=m);let h;t[6]===n?h=t[7]:(h=(0,$.jsx)(`span`,{className:`group-open:hidden`,children:n}),t[6]=n,t[7]=h);let g;t[8]===r?g=t[9]:(g=(0,$.jsx)(`span`,{className:`hidden group-open:inline`,children:r}),t[8]=r,t[9]=g);let _;t[10]!==m||t[11]!==h||t[12]!==g?(_=(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 rounded-2xl px-4 py-3.5 text-sm font-medium text-fg transition-colors hover:text-fg group-open:rounded-b-none [&::-webkit-details-marker]:hidden`,children:[p,m,h,g]}),t[10]=m,t[11]=h,t[12]=g,t[13]=_):_=t[13];let v;t[14]===a?v=t[15]:(v=a?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:a}):null,t[14]=a,t[15]=v);let y;t[16]!==o||t[17]!==v?(y=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 px-4 pb-4 pt-1`,children:[v,o]}),t[16]=o,t[17]=v,t[18]=y):y=t[18];let b;return t[19]!==l||t[20]!==f||t[21]!==_||t[22]!==y?(b=(0,$.jsxs)(`details`,{open:l,onToggle:d,className:f,children:[_,y]}),t[19]=l,t[20]=f,t[21]=_,t[22]=y,t[23]=b):b=t[23],b}async function br(){let e=await T(l(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function xr(e){let t=new Set,n=[];for(let r of e){let e=r.models.length>0?r.models:r.defaultModel?[r.defaultModel]:[];for(let i of e){let e=`${r.id}/${i}`;t.has(e)||(t.add(e),n.push(e))}}return n}function Sr(e,t){let n=xr(e.filter(e=>e.configured===!0));return!t||n.includes(t)?n:[t,...n]}function Cr(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=n.split(/[/\s]+/).filter(Boolean);return e.filter(e=>{let t=e.toLowerCase();return r.every(e=>t.includes(e))})}var wr=`image-generation-providers`;function Tr(e){let t=(0,Q.c)(80),{value:n,disabled:r,placeholder:i,searchPlaceholder:a,noMatches:o,registryEmptyHint:s,outOfFilterNote:c,className:l,onChange:u}=e,[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(``),g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g={revalidateOnFocus:!1},t[0]=g):g=t[0];let{data:_,isLoading:v,error:y}=d(wr,br,g),b;t[1]===n?b=t[2]:(b=n.trim(),t[1]=n,t[2]=b);let x=b,S;t[3]===_?S=t[4]:(S=xr((_??[]).filter(Or)),t[3]=_,t[4]=S);let C=S,w;t[5]===_?w=t[6]:(w=_??[],t[5]=_,t[6]=w);let T;t[7]!==w||t[8]!==x?(T=Sr(w,x),t[7]=w,t[8]=x,t[9]=T):T=t[9];let E=T,D;t[10]!==E||t[11]!==m?(D=Cr(E,m),t[10]=E,t[11]=m,t[12]=D):D=t[12];let O=D,k;t[13]!==C||t[14]!==c||t[15]!==x?(k=!!c&&!!x&&!C.includes(x),t[13]=C,t[14]=c,t[15]=x,t[16]=k):k=t[16];let A=k,j;t[17]!==i||t[18]!==n?(j=n.trim()?n:i,t[17]=i,t[18]=n,t[19]=j):j=t[19];let N=j,P;t[20]!==i||t[21]!==n?(P=n.trim()||i,t[20]=i,t[21]=n,t[22]=P):P=t[22];let F=P,I;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(I=e=>{p(e),e||h(``)},t[23]=I):I=t[23];let L=I,R=r||v,z=v?`…`:F,B;t[24]===l?B=t[25]:(B=J(Vt,`items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-left text-sm font-normal text-fg`,K.transition,K.press,`hover:border-edge hover:bg-surface-hover/45`,Kt,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,l),t[24]=l,t[25]=B);let V=v?`…`:N,H;t[26]===V?H=t[27]:(H=(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:V}),t[26]=V,t[27]=H);let U;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(U=(0,$.jsx)(Ut,{className:`size-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0}),t[28]=U):U=t[28];let W;t[29]!==f||t[30]!==R||t[31]!==z||t[32]!==B||t[33]!==H?(W=(0,$.jsx)(pe,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,disabled:R,title:z,className:B,"aria-haspopup":`listbox`,"aria-expanded":f,children:[H,U]})}),t[29]=f,t[30]=R,t[31]=z,t[32]=B,t[33]=H,t[34]=W):W=t[34];let te;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(te=J(`w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-edge-subtle bg-surface-panel p-1 shadow-elevated dark:border-edge-subtle`,M),t[35]=te):te=t[35];let G;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(G=J(`mb-1 w-full rounded-lg border border-edge-subtle bg-surface-base px-2.5 py-1.5 text-sm text-fg placeholder:text-fg-disabled dark:bg-surface-hover/40`,at),t[36]=G):G=t[36];let ne;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>h(e.target.value),t[37]=ne):ne=t[37];let re;t[38]!==m||t[39]!==a?(re=(0,$.jsx)(`input`,{type:`search`,className:G,placeholder:a,value:m,onChange:ne,onKeyDown:Er}),t[38]=m,t[39]=a,t[40]=re):re=t[40];let ae;t[41]===y?ae=t[42]:(ae=y?(0,$.jsx)(`div`,{className:`p-2 text-xs text-red-600 dark:text-red-400`,children:y instanceof Error?y.message:`Failed to load image providers`}):null,t[41]=y,t[42]=ae);let oe;t[43]!==E||t[44]!==y||t[45]!==v||t[46]!==o||t[47]!==s?(oe=!y&&E.length===0&&!v?(0,$.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:s??o}):null,t[43]=E,t[44]=y,t[45]=v,t[46]=o,t[47]=s,t[48]=oe):oe=t[48];let se;t[49]!==E||t[50]!==y||t[51]!==O.length||t[52]!==o?(se=!y&&E.length>0&&O.length===0?(0,$.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o}):null,t[49]=E,t[50]=y,t[51]=O.length,t[52]=o,t[53]=se):se=t[53];let ce;if(t[54]!==O||t[55]!==u||t[56]!==n){let e;t[58]!==u||t[59]!==n?(e=e=>(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":e===n,className:J(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-fg hover:bg-surface-hover`,K.press,e===n&&`bg-surface-hover/90 font-medium dark:bg-surface-hover/70`),onClick:()=>{u(e),p(!1),h(``)},children:[(0,$.jsx)(tt,{className:J(`size-4 shrink-0`,e!==n&&`invisible`),"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:e})]},e),t[58]=u,t[59]=n,t[60]=e):e=t[60],ce=O.map(e),t[54]=O,t[55]=u,t[56]=n,t[57]=ce}else ce=t[57];let le;t[61]!==a||t[62]!==ae||t[63]!==oe||t[64]!==se||t[65]!==ce?(le=(0,$.jsxs)(`div`,{className:`max-h-60 overflow-auto`,role:`listbox`,"aria-label":a,children:[ae,oe,se,ce]}),t[61]=a,t[62]=ae,t[63]=oe,t[64]=se,t[65]=ce,t[66]=le):le=t[66];let ue;t[67]!==re||t[68]!==le?(ue=(0,$.jsx)(ee,{children:(0,$.jsxs)(De,{className:te,side:`bottom`,sideOffset:4,align:`end`,onOpenAutoFocus:Dr,children:[re,le]})}),t[67]=re,t[68]=le,t[69]=ue):ue=t[69];let de;t[70]!==f||t[71]!==W||t[72]!==ue?(de=(0,$.jsxs)(ie,{open:f,onOpenChange:L,modal:!1,children:[W,ue]}),t[70]=f,t[71]=W,t[72]=ue,t[73]=de):de=t[73];let fe;t[74]!==c||t[75]!==A?(fe=A?(0,$.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400/90`,children:c}):null,t[74]=c,t[75]=A,t[76]=fe):fe=t[76];let me;return t[77]!==de||t[78]!==fe?(me=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[de,fe]}),t[77]=de,t[78]=fe,t[79]=me):me=t[79],me}function Er(e){return e.stopPropagation()}function Dr(e){return e.preventDefault()}function Or(e){return e.configured===!0}function kr(e,t,n){let r=e.trim();return r?`model:${r}`:`empty:${n.slice(0,t).filter(e=>!e.trim()).length}`}function Ar(e){let t=(0,Q.c)(37),{a:n,chat:r,form:i,update:a}=e,o;t[0]!==n.cardModelsSubtitle||t[1]!==n.cardModelsTitle?(o=(0,$.jsx)(vn,{icon:z,title:n.cardModelsTitle,subtitle:n.cardModelsSubtitle}),t[0]=n.cardModelsSubtitle,t[1]=n.cardModelsTitle,t[2]=o):o=t[2];let s;t[3]===a?s=t[4]:(s=e=>a({imageModel:e}),t[3]=a,t[4]=s);let c;t[5]!==n.visionOutOfFilterNote||t[6]!==n.visionRegistryEmpty||t[7]!==r.modelNoMatches||t[8]!==r.modelPlaceholder||t[9]!==r.modelSearchPlaceholder||t[10]!==i.imageModel||t[11]!==s?(c=(0,$.jsx)(gt,{value:i.imageModel,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:n.visionRegistryEmpty,outOfFilterNote:n.visionOutOfFilterNote,onChange:s}),t[5]=n.visionOutOfFilterNote,t[6]=n.visionRegistryEmpty,t[7]=r.modelNoMatches,t[8]=r.modelPlaceholder,t[9]=r.modelSearchPlaceholder,t[10]=i.imageModel,t[11]=s,t[12]=c):c=t[12];let l;t[13]!==n.desc.imageModel||t[14]!==n.label.imageModel||t[15]!==c?(l=(0,$.jsx)(Tn,{label:n.label.imageModel,description:n.desc.imageModel,children:c}),t[13]=n.desc.imageModel,t[14]=n.label.imageModel,t[15]=c,t[16]=l):l=t[16];let u;t[17]===a?u=t[18]:(u=e=>a({imageGenerationModel:e}),t[17]=a,t[18]=u);let d;t[19]!==n.imageGenOutOfFilterNote||t[20]!==n.imageGenRegistryEmpty||t[21]!==r.modelNoMatches||t[22]!==r.modelPlaceholder||t[23]!==r.modelSearchPlaceholder||t[24]!==i.imageGenerationModel||t[25]!==u?(d=(0,$.jsx)(Tr,{value:i.imageGenerationModel,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,registryEmptyHint:n.imageGenRegistryEmpty,outOfFilterNote:n.imageGenOutOfFilterNote,onChange:u}),t[19]=n.imageGenOutOfFilterNote,t[20]=n.imageGenRegistryEmpty,t[21]=r.modelNoMatches,t[22]=r.modelPlaceholder,t[23]=r.modelSearchPlaceholder,t[24]=i.imageGenerationModel,t[25]=u,t[26]=d):d=t[26];let f;t[27]!==n.desc.imageGenerationModel||t[28]!==n.label.imageGenerationModel||t[29]!==d?(f=(0,$.jsx)(Tn,{label:n.label.imageGenerationModel,description:n.desc.imageGenerationModel,children:d}),t[27]=n.desc.imageGenerationModel,t[28]=n.label.imageGenerationModel,t[29]=d,t[30]=f):f=t[30];let p;t[31]!==l||t[32]!==f?(p=(0,$.jsxs)(`div`,{className:`mt-4 flex flex-col gap-5`,children:[l,f]}),t[31]=l,t[32]=f,t[33]=p):p=t[33];let m;return t[34]!==o||t[35]!==p?(m=(0,$.jsxs)(X,{children:[o,p]}),t[34]=o,t[35]=p,t[36]=m):m=t[36],m}function jr(e){let t=(0,Q.c)(45),{a:n,chat:r,form:i,update:a}=e,o=n.label.imageModelFallbacks,s=n.desc.imageModelFallbacks,c;t[0]!==n.removeModelFallback||t[1]!==n.visionOutOfFilterNote||t[2]!==n.visionRegistryEmpty||t[3]!==r||t[4]!==i.imageModelFallbacks||t[5]!==a?(c=i.imageModelFallbacks.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(gt,{value:e,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:n.visionRegistryEmpty,outOfFilterNote:n.visionOutOfFilterNote,onChange:e=>{let n=[...i.imageModelFallbacks];n[t]=e,a({imageModelFallbacks:n})}})}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":n.removeModelFallback,onClick:()=>a({imageModelFallbacks:i.imageModelFallbacks.filter((e,n)=>n!==t)}),children:(0,$.jsx)(Re,{className:`size-4`,strokeWidth:1.75})})]},kr(e,t,i.imageModelFallbacks))),t[0]=n.removeModelFallback,t[1]=n.visionOutOfFilterNote,t[2]=n.visionRegistryEmpty,t[3]=r,t[4]=i.imageModelFallbacks,t[5]=a,t[6]=c):c=t[6];let l;t[7]!==i.imageModelFallbacks||t[8]!==a?(l=()=>a({imageModelFallbacks:[...i.imageModelFallbacks,``]}),t[7]=i.imageModelFallbacks,t[8]=a,t[9]=l):l=t[9];let u;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(dt,{className:`size-4 shrink-0`,strokeWidth:1.75}),t[10]=u):u=t[10];let d;t[11]!==n.addModelFallback||t[12]!==l?(d=(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:l,children:[u,n.addModelFallback]}),t[11]=n.addModelFallback,t[12]=l,t[13]=d):d=t[13];let f;t[14]!==c||t[15]!==d?(f=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[c,d]}),t[14]=c,t[15]=d,t[16]=f):f=t[16];let p;t[17]!==n.desc.imageModelFallbacks||t[18]!==n.label.imageModelFallbacks||t[19]!==f?(p=(0,$.jsx)(Tn,{label:o,description:s,children:f}),t[17]=n.desc.imageModelFallbacks,t[18]=n.label.imageModelFallbacks,t[19]=f,t[20]=p):p=t[20];let m=n.label.imageGenerationModelFallbacks,h=n.desc.imageGenerationModelFallbacks,g;t[21]!==n.imageGenOutOfFilterNote||t[22]!==n.imageGenRegistryEmpty||t[23]!==n.removeModelFallback||t[24]!==r||t[25]!==i.imageGenerationModelFallbacks||t[26]!==a?(g=i.imageGenerationModelFallbacks.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(Tr,{value:e,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,registryEmptyHint:n.imageGenRegistryEmpty,outOfFilterNote:n.imageGenOutOfFilterNote,onChange:e=>{let n=[...i.imageGenerationModelFallbacks];n[t]=e,a({imageGenerationModelFallbacks:n})}})}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":n.removeModelFallback,onClick:()=>a({imageGenerationModelFallbacks:i.imageGenerationModelFallbacks.filter((e,n)=>n!==t)}),children:(0,$.jsx)(Re,{className:`size-4`,strokeWidth:1.75})})]},kr(e,t,i.imageGenerationModelFallbacks))),t[21]=n.imageGenOutOfFilterNote,t[22]=n.imageGenRegistryEmpty,t[23]=n.removeModelFallback,t[24]=r,t[25]=i.imageGenerationModelFallbacks,t[26]=a,t[27]=g):g=t[27];let _;t[28]!==i.imageGenerationModelFallbacks||t[29]!==a?(_=()=>a({imageGenerationModelFallbacks:[...i.imageGenerationModelFallbacks,``]}),t[28]=i.imageGenerationModelFallbacks,t[29]=a,t[30]=_):_=t[30];let v;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(dt,{className:`size-4 shrink-0`,strokeWidth:1.75}),t[31]=v):v=t[31];let y;t[32]!==n.addModelFallback||t[33]!==_?(y=(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:_,children:[v,n.addModelFallback]}),t[32]=n.addModelFallback,t[33]=_,t[34]=y):y=t[34];let b;t[35]!==g||t[36]!==y?(b=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[g,y]}),t[35]=g,t[36]=y,t[37]=b):b=t[37];let x;t[38]!==n.desc.imageGenerationModelFallbacks||t[39]!==n.label.imageGenerationModelFallbacks||t[40]!==b?(x=(0,$.jsx)(Tn,{label:m,description:h,children:b}),t[38]=n.desc.imageGenerationModelFallbacks,t[39]=n.label.imageGenerationModelFallbacks,t[40]=b,t[41]=x):x=t[41];let S;return t[42]!==x||t[43]!==p?(S=(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[p,x]}),t[42]=x,t[43]=p,t[44]=S):S=t[44],S}function Mr(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ht)}var Nr=()=>l(sn);function Pr(e){return{imageModel:e.imageModel,imageModelFallbacks:e.imageModelFallbacks,imageGenerationModel:e.imageGenerationModel,imageGenerationModelFallbacks:e.imageGenerationModelFallbacks,imageGenerationModelTimeoutMs:e.imageGenerationModelTimeoutMs,imageGenerationModelAutoProviderFallback:e.imageGenerationModelAutoProviderFallback}}function Fr(e){return{credentialsIntro:e.credentialsIntro,regionHint:e.regionHint,endpointPresetsHint:e.endpointPresetsHint,apiKeyLabel:e.apiKeyLabel,optionalPlaceholder:e.optionalPlaceholder,regionLabel:e.regionLabel,baseUrlLabel:e.baseUrlLabel,imageBaseUrlLabel:e.imageBaseUrlLabel,saveCredentials:e.saveCredentials,savingCredentials:e.savingCredentials,credentialsSaved:e.credentialsSaved,discardCredentials:e.discardCredentials,credentialsNothingToSave:e.credentialsNothingToSave,credentialsSaveError:e.credentialsSaveError,regionPresetDefault:e.regionPresetDefault,regionPresetCustom:e.regionPresetCustom,baseUrlPresetDefault:e.baseUrlPresetDefault,baseUrlPresetCustom:e.baseUrlPresetCustom,openExtensionSettings:e.openExtensionSettings,openImageModelsPage:e.openImageModelsPage,extensionSettingsLinkTitle:e.extensionSettingsLinkTitle,imageModelsLinkTitle:e.imageModelsLinkTitle,configured:e.configured,missingKey:e.missingKey,unsavedChanges:e.unsavedChanges,expandProvider:e.expandProvider,collapseProvider:e.collapseProvider,defaultModel:e.defaultModel,modelsLabel:e.modelsLabel,modelCountOne:e.modelCountOne,modelCountMany:e.modelCountMany,imageBaseUrlPresetHint:e.imageBaseUrlPresetHint,dashscopeRegion_beijing:e.dashscopeRegion_beijing,dashscopeRegion_singapore:e.dashscopeRegion_singapore,dashscopeRegion_us:e.dashscopeRegion_us,apiKeyMaskedHelp:e.apiKeyMaskedHelp,apiKeyCopy:e.apiKeyCopy,apiKeyCopied:e.apiKeyCopied,apiKeyShow:e.apiKeyShow,apiKeyHide:e.apiKeyHide,apiKeyNotInConfigFile:e.apiKeyNotInConfigFile,apiKeyRevealFailed:e.apiKeyRevealFailed,minimaxClusterLabel:e.minimaxClusterLabel,minimaxClusterHint:e.minimaxClusterHint,falQueueBaseLabel:e.falQueueBaseLabel,falQueueBaseHint:e.falQueueBaseHint}}var Ir=ot(),Lr={loading:!0,saving:!1,savedFlash:!1,error:void 0};function Rr({embedded:e=!1}={}){let t=a(e=>e.language),n=s(t),r=n.imageModelsSettings,i=!!C(e=>e.token),[o,c]=(0,Z.useReducer)(Ir,{form:null,baseline:null}),l=o.form,u=o.baseline,[f,p]=(0,Z.useReducer)(Lt,Lr),{loading:m,saving:h,savedFlash:g,error:_}=f,v=Tt(),y=(0,Z.useMemo)(()=>new Set(v.map(e=>e.id)),[v]),b=(0,Z.useCallback)(async()=>{if(i){p({type:`patch`,patch:{loading:!0,error:void 0}});try{let e=await kn();c({type:`sync`,value:structuredClone(e)})}catch(e){p({type:`patch`,patch:{error:e instanceof Error?e.message:String(e)}})}finally{p({type:`patch`,patch:{loading:!1}})}}},[i]);(0,Z.useEffect)(()=>{b()},[b]);let x=(0,Z.useCallback)(e=>{c({type:`patch`,patch:e})},[]),{data:S=[]}=d(i?Nr():null,mn,{revalidateOnFocus:!1}),w=S.some(e=>e.configured),T=Fe(i),E=on(S),D=(0,Z.useMemo)(()=>!l||!u?!1:JSON.stringify(Pr(l))!==JSON.stringify(Pr(u)),[l,u]),O=D||E.credDirty;(0,Z.useEffect)(()=>{if(!O)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[O]);let k=(0,Z.useCallback)(async()=>{if(l){p({type:`patch`,patch:{saving:!0,error:void 0}});try{try{In(l.paramsJson)}catch(e){p({type:`patch`,patch:{error:e instanceof SyntaxError?n.agentSettings.advanced.paramsInvalidJson:e instanceof Error?e.message:n.agentSettings.advanced.paramsInvalidJson}});return}let e=[];D&&e.push(En(l).then(()=>{c({type:`saved`,value:structuredClone(l)}),T.mutate?.()})),E.credDirty&&e.push(E.saveCredentials(r.credentialsSaveError)),await Promise.all(e),p({type:`patch`,patch:{savedFlash:!0}}),window.setTimeout(()=>p({type:`patch`,patch:{savedFlash:!1}}),1500)}catch(e){p({type:`patch`,patch:{error:e instanceof Error?e.message:String(e)}})}finally{p({type:`patch`,patch:{saving:!1}})}}},[l,D,T,n.agentSettings,E,r.credentialsSaveError]),A=(0,Z.useCallback)(()=>{u&&(c({type:`discard`}),E.credDirty&&E.onDiscardCredentials(),p({type:`patch`,patch:{error:void 0,savedFlash:!1}}))},[u,E]);vr({id:`image-models`,dirty:O,saving:h,save:k,discard:A});let j=(0,Z.useMemo)(()=>Fr(r),[r]),M=(0,Z.useMemo)(()=>({getApiKey:n.providersSettings.getApiKey,getApiKeyIntl:n.providersSettings.getApiKeyIntl,getApiKeyCn:n.providersSettings.getApiKeyCn}),[n.providersSettings]),N=e?`flex flex-col gap-4`:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,P=e?`w-full text-sm text-fg-muted`:`mx-auto w-full max-w-app-main px-4 py-8 text-sm text-fg-muted`,F=e?`flex w-full items-center gap-2 text-sm text-fg-muted`:`mx-auto flex w-full max-w-app-main items-center gap-2 px-4 py-8 text-sm text-fg-muted`;return i?m||!l?(0,$.jsxs)(`div`,{className:F,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),` Loading…`]}):(0,$.jsxs)(`div`,{className:N,children:[e?null:(0,$.jsxs)(`header`,{className:`flex items-start justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:r.title}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.subtitle})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[g?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:r.saved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:A,disabled:!O||h,children:r.discard}),(0,$.jsxs)(Y,{type:`button`,variant:`primary`,onClick:()=>void k(),disabled:!O||h,children:[h?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):(0,$.jsx)(le,{className:`size-3.5`}),(0,$.jsx)(`span`,{className:`ml-1.5`,children:h?r.saving:r.save})]})]})]}),_?(0,$.jsx)(`div`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-300`,children:_}):null,(0,$.jsx)(Ar,{form:l,update:x,a:n.agentSettings,chat:n.chat}),(0,$.jsx)(yr,{showLabel:r.fallbackChainsTitle,hideLabel:r.fallbackChainsTitle,children:(0,$.jsx)(jr,{form:l,update:x,a:n.agentSettings,chat:n.chat})}),(0,$.jsx)(yr,{showLabel:r.runtimeTuningTitle,hideLabel:r.runtimeTuningTitle,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,children:r.timeoutLabel}),(0,$.jsx)(`input`,{type:`number`,min:0,step:1e3,className:J(Mr(),`max-w-48`),value:l.imageGenerationModelTimeoutMs??``,placeholder:`120000`,onChange:e=>{let t=e.target.value.trim(),n=t===``?null:Math.max(0,Math.floor(Number(t)));x({imageGenerationModelTimeoutMs:n&&n>0?n:null})}}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.timeoutHint})]}),(0,$.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:l.imageGenerationModelAutoProviderFallback,onChange:e=>x({imageGenerationModelAutoProviderFallback:e.target.checked}),"aria-label":r.autoFallbackLabel}),(0,$.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:r.autoFallbackLabel}),(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:r.autoFallbackHint})]})]})]})}),(0,$.jsx)(yr,{icon:Be,showLabel:r.providersTitle,hideLabel:r.providersTitle,defaultOpen:w,children:S.length===0?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.providersEmpty}):(0,$.jsx)(cn,{summaries:S,credDraft:E.credDraft,credBaseline:E.credBaseline,credDirty:E.credDirty,credSaving:E.credSaving,credError:E.credError,credSavedFlash:E.credSavedFlash,credNoopFlash:E.credNoopFlash,updateCredRow:E.updateCredRow,onDiscardCredentials:E.onDiscardCredentials,onSaveCredentials:()=>void E.saveCredentials(r.credentialsSaveError),extensionIds:y,showExtensionLinks:!0,showImageModelsLink:!1,hideActions:!0,language:t,apiKeyLinkLabels:M,messages:j})})]}):(0,$.jsx)(`div`,{className:P,children:t===`zh`?`请先登录网关。`:`Connect to a gateway to continue.`})}var zr=jt;function Br(e){switch(e){case`alibaba`:return`(DASHSCOPE_API_KEY)`;case`openai`:return`(OPENAI_API_KEY)`;case`groq`:return`(GROQ_API_KEY)`;default:return``}}function Vr(e){switch(e){case`alibaba`:return`(DASHSCOPE_API_KEY)`;case`openai`:return`(OPENAI_API_KEY)`;case`minimax`:return`(MINIMAX_API_KEY)`;default:return``}}function Hr(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ht,`dark:border-edge`)}function Ur(){return J(ct,jt)}var Wr=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Gr=[{id:`whisper-1`,name:`Whisper-1`}],Kr=[{id:`whisper-large-v3-turbo`,name:`Whisper Large v3 Turbo`},{id:`whisper-large-v3`,name:`Whisper Large v3`}],qr=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],Jr=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Yr=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Xr=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Zr=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],Qr=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],$r=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}],ei=[{id:`openai`,capability:`tts`,displayName:`OpenAI`,aliases:[],configured:!1,fields:[],diagnostics:{requiresApiKey:!0,configPath:`messages.tts.providers.openai`}},{id:`alibaba`,capability:`tts`,displayName:`Alibaba DashScope`,aliases:[],configured:!1,fields:[],diagnostics:{requiresApiKey:!0,configPath:`messages.tts.providers.alibaba`}},{id:`minimax`,capability:`tts`,displayName:`MiniMax`,aliases:[],configured:!1,fields:[],diagnostics:{requiresApiKey:!0,configPath:`messages.tts.providers.minimax`}},{id:`edge`,capability:`tts`,displayName:`Microsoft Edge`,aliases:[],configured:!1,fields:[],diagnostics:{requiresApiKey:!1,configPath:`messages.tts.providers.edge`}},{id:`tts-local-cli`,capability:`tts`,displayName:`Local CLI`,aliases:[`cli`,`local-cli`],configured:!1,fields:[],diagnostics:{requiresApiKey:!1,configPath:`messages.tts.providers.tts-local-cli`}}],ti=[{id:`alibaba`,capability:`stt`,displayName:`Alibaba DashScope`,aliases:[`dashscope`,`paraformer`],configured:!1,fields:[],diagnostics:{requiresApiKey:!0,configPath:`tools.media.audio.providers.alibaba`}},{id:`openai`,capability:`stt`,displayName:`OpenAI Whisper`,aliases:[],configured:!1,fields:[],diagnostics:{requiresApiKey:!0,configPath:`tools.media.audio.providers.openai`}}];function ni(e,t){switch(e){case`openai`:return t.stt.openai;case`alibaba`:return t.stt.alibaba;case`groq`:return`Groq`;default:return e}}function ri(e,t){switch(e){case`openai`:return t.tts.providerOpenai;case`alibaba`:return t.stt.alibaba;case`edge`:return t.tts.providerEdge;case`tts-local-cli`:return t.tts.providerLocalCli;case`minimax`:return`MiniMax`;default:return e}}function ii(e){return{maskedHelp:e.apiKeyMaskedHelp,copy:e.apiKeyCopy,copied:e.apiKeyCopied,show:e.apiKeyShow,hide:e.apiKeyHide,notInConfigFile:e.apiKeyNotInConfigFile,loadFailed:e.apiKeyRevealFailed}}function ai(e,t){let n=e[t.key];return typeof n==`string`||typeof n==`number`||typeof n==`boolean`?n:t.defaultValue===void 0?t.type===`boolean`?!1:``:t.defaultValue}function oi(e,t){if(e.type===`boolean`)return!!t;if(e.type!==`number`)return t;let n=String(t).trim();if(!n)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function si(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`update`:return{...e,form:t.updater(e.form)};case`discard`:return e.baseline?{form:structuredClone(e.baseline),baseline:e.baseline}:e;case`saved`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}}}function ci({embedded:e=!1}={}){let t=a(e=>e.language),n=s(t),r=n.voiceSettings,i=!!C(e=>e.token),[o,c]=(0,Z.useReducer)(si,{form:null,baseline:null}),u=o.form,f=o.baseline,[p,m]=(0,Z.useState)(null),[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),x=(0,Z.useRef)(!1),S=(0,Z.useRef)({parsed:null,models:void 0}),{data:w,error:T,isLoading:E,mutate:D}=Fe(i),{data:O,error:k,isLoading:A,mutate:j}=d(i?l(`/api/voice/models`):null,ln,{revalidateOnFocus:!1}),{data:M,error:N,isLoading:P}=d(i?l(`/api/voice/providers`):null,dn,{revalidateOnFocus:!1}),{data:F,error:I,isLoading:L}=d(i?l(`/api/voice/stt-providers`):null,an,{revalidateOnFocus:!1}),R=(0,Z.useMemo)(()=>M?.providers??ei,[M]),z=(0,Z.useMemo)(()=>F?.providers??ti,[F]),B=(0,Z.useMemo)(()=>w?.payload?.config===void 0?null:un(w.payload.config),[w]),V=(0,Z.useMemo)(()=>!u||!f?!1:JSON.stringify(u)!==JSON.stringify(f),[u,f]);i?B!==null&&O!==void 0&&!x.current&&(S.current.parsed!==B||S.current.models!==O)&&(S.current={parsed:B,models:O},c({type:`sync`,value:B}),m(O),b(!1)):(S.current.parsed!==null||S.current.models!==void 0)&&(S.current={parsed:null,models:void 0},c({type:`reset`}),m(null),x.current=!1);let ee=!!(i&&(B===null||O===void 0||M===void 0||F===void 0)&&(E||A||P||L)),H=T instanceof Error?T.message:T?String(T):k instanceof Error?k.message:k?String(k):N instanceof Error?N.message:N?String(N):I instanceof Error?I.message:I?String(I):null,U=(0,Z.useCallback)(e=>{x.current=!0,c({type:`update`,updater:t=>t?{...t,stt:{...t.stt,...e}}:null})},[]),W=(0,Z.useCallback)(e=>{x.current=!0,c({type:`update`,updater:t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null})},[]),te=(0,Z.useCallback)(e=>{x.current=!0,c({type:`update`,updater:t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null})},[]),G=(0,Z.useCallback)(e=>{x.current=!0,c({type:`update`,updater:t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!0,order:[`alibaba`,`openai`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}}})},[]),ne=(0,Z.useCallback)(e=>{x.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,...e}}:null})},[]),re=(0,Z.useCallback)(e=>{x.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null})},[]),ie=(0,Z.useCallback)(e=>{x.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null})},[]),ae=(0,Z.useCallback)(e=>{x.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null})},[]),oe=(0,Z.useCallback)(e=>{x.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null})},[]),se=(0,Z.useCallback)(e=>{x.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null})},[]),ce=(0,Z.useCallback)(async()=>{if(!(!u||h)){g(!0),v(null),b(!1);try{await fn(u),c({type:`saved`,value:u}),x.current=!1,b(!0),window.setTimeout(()=>b(!1),2500)}catch(e){v(e instanceof Error?e.message:r.saveError)}finally{g(!1)}}},[u,h,r.saveError]),le=(0,Z.useCallback)(()=>{f&&(x.current=!1,c({type:`discard`}),v(null),b(!1))},[f]);vr({id:`voice`,dirty:V,saving:h,save:ce,discard:le});let ue=e?`flex flex-col gap-4`:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,de=e?`flex flex-col gap-3`:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`;if(!i)return(0,$.jsxs)(`div`,{className:de,children:[e?null:(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.settingsSections.voice}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.needToken})]});if(ee)return(0,$.jsx)(`div`,{className:de,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),r.loading]})});if(!u||p===null)return(0,$.jsxs)(`div`,{className:de,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:_??H??r.loadError}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:()=>{D(),j()},children:r.retry})]});let pe=u.stt,me=u.tts,he=ii(r);return(0,$.jsxs)(`div`,{className:ue,children:[(0,$.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[e?(0,$.jsx)(`div`,{className:`min-w-0`,"aria-hidden":!0}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.settingsSections.voice}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.subtitle}),(0,$.jsxs)(`a`,{href:Rt(t,`voice`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[r.docsLink,(0,$.jsx)(fe,{className:`size-3.5`})]})]}),e?null:(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[y?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:r.saved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!V||h,onClick:le,children:r.discard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!V||h,onClick:()=>void ce(),children:h?r.saving:r.save})]})]}),V&&!e?(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:r.unsavedHint}):null,_?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:_}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(li,{v:r,apiKeyLabels:he,stt:pe,models:p,sttProviders:z,updateStt:U,updateSttAlibaba:W,updateSttOpenai:te,updateSttFallback:G}),(0,$.jsx)(mi,{v:r,apiKeyLabels:he,tts:me,models:p,ttsProviders:R,updateTts:ne,updateTtsAlibaba:re,updateTtsOpenai:ie,updateTtsEdge:ae,updateTtsMinimax:oe,updateTtsLocalCli:se})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-accent/25 bg-accent/5 px-4 py-3 dark:border-accent/30 dark:bg-accent/10`,children:[(0,$.jsxs)(`p`,{className:`text-sm text-fg`,children:[(0,$.jsx)(`strong`,{className:`text-accent`,children:r.notes.title}),` `,r.notes.duration]}),(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:r.notes.envVars})]})]})}function li(e){let t=(0,Q.c)(60),{v:n,apiKeyLabels:r,stt:i,models:a,sttProviders:o,updateStt:s,updateSttAlibaba:c,updateSttOpenai:l,updateSttFallback:u}=e,d=a?.stt?.alibaba?.length?a.stt.alibaba:Wr,f=a?.stt?.openai?.length?a.stt.openai:Gr,p;if(t[0]!==i.provider||t[1]!==o){let e=new Set;p=[];for(let t of o)e.has(t.id)||(e.add(t.id),p.push(t));if(i.provider&&!e.has(i.provider)){let e;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[3]=e):e=t[3];let n;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(n=[{key:`apiKey`,label:`API Key`,type:`password`,secret:!0},{key:`model`,label:`Model`,type:`string`}],t[4]=n):n=t[4];let r=`tools.media.audio.providers.${i.provider}`,a;t[5]===r?a=t[6]:(a={requiresApiKey:!0,configPath:r},t[5]=r,t[6]=a);let o;t[7]!==i.provider||t[8]!==a?(o={id:i.provider,capability:`stt`,displayName:i.provider,aliases:e,configured:!1,fields:n,diagnostics:a},t[7]=i.provider,t[8]=a,t[9]=o):o=t[9],p.push(o)}t[0]=i.provider,t[1]=o,t[2]=p}else p=t[2];let m=p,h,g,_,v,y;if(t[10]!==d||t[11]!==r||t[12]!==f||t[13]!==m||t[14]!==i||t[15]!==s||t[16]!==c||t[17]!==u||t[18]!==l||t[19]!==n){let e=m.find(e=>e.id===i.provider),a=i.providers?.[i.provider],o=typeof a?.apiKey==`string`?a.apiKey:``,p=typeof a?.model==`string`?a.model:``,b={...i.provider===`alibaba`?i.alibaba??{}:{},...i.provider===`openai`?i.openai??{}:{},...a??{}},x=(e?.fields??[]).filter(pi),S;t[25]!==i.provider||t[26]!==i.providers||t[27]!==s?(S=e=>{s({providers:{...i.providers??{},[i.provider]:{...i.providers?.[i.provider]??{},...e}}})},t[25]=i.provider,t[26]=i.providers,t[27]=s,t[28]=S):S=t[28];let C=S;v=`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`;let w;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(st,{className:`size-4 text-accent`,strokeWidth:1.75}),t[29]=w):w=t[29];let T;t[30]===n.stt.title?T=t[31]:(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[w,n.stt.title]}),t[30]=n.stt.title,t[31]=T);let E;t[32]===n.stt.description?E=t[33]:(E=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.stt.description}),t[32]=n.stt.description,t[33]=E),t[34]!==T||t[35]!==E?(y=(0,$.jsxs)(`div`,{className:`mb-4`,children:[T,E]}),t[34]=T,t[35]=E,t[36]=y):y=t[36],h=`space-y-4`;let D;t[37]===n.stt.enable?D=t[38]:(D=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.enable}),t[37]=n.stt.enable,t[38]=D);let O;t[39]===n.stt.enableDesc?O=t[40]:(O=(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.enableDesc}),t[39]=n.stt.enableDesc,t[40]=O);let k;t[41]!==D||t[42]!==O?(k=(0,$.jsxs)(`div`,{children:[D,O]}),t[41]=D,t[42]=O,t[43]=k):k=t[43];let A;t[44]===s?A=t[45]:(A=e=>s({enabled:e.target.checked}),t[44]=s,t[45]=A);let j;t[46]!==i.enabled||t[47]!==A?(j=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i.enabled,onChange:A}),t[46]=i.enabled,t[47]=A,t[48]=j):j=t[48],t[49]!==k||t[50]!==j?(g=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[k,j]}),t[49]=k,t[50]=j,t[51]=g):g=t[51],_=i.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,zr),children:[(0,$.jsx)(xi,{children:n.stt.provider}),(0,$.jsx)(`select`,{className:Ur(),value:i.provider,onChange:e=>s({provider:e.target.value}),children:m.map(e=>(0,$.jsxs)(`option`,{value:e.id,children:[ni(e.id,n),e.configured?``:` *`]},e.id))})]}),(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,zr),children:[(0,$.jsx)(xi,{children:n.stt.model}),i.provider===`alibaba`?(0,$.jsx)(`select`,{className:Ur(),value:i.alibaba?.model??``,onChange:e=>c({model:e.target.value}),children:d.map(fi)}):i.provider===`openai`?(0,$.jsx)(`select`,{className:Ur(),value:i.openai?.model??``,onChange:e=>l({model:e.target.value}),children:f.map(di)}):i.provider===`groq`?(0,$.jsx)(`select`,{className:Ur(),value:p||Kr[0].id,onChange:e=>C({model:e.target.value}),children:Kr.map(ui)}):(0,$.jsx)(`input`,{className:Hr(),value:p,onChange:e=>C({model:e.target.value}),placeholder:i.provider})]}),(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,zr),children:[(0,$.jsx)(xi,{children:n.stt.apiKey}),(0,$.jsx)(pn,{kind:`stt`,providerId:i.provider,fieldId:`voice-stt-${i.provider}-api-key`,value:i.provider===`alibaba`?i.alibaba?.apiKey??``:i.provider===`openai`?i.openai?.apiKey??``:o,onChange:e=>{i.provider===`alibaba`?c({apiKey:e}):i.provider===`openai`?l({apiKey:e}):C({apiKey:e})},labels:r,placeholder:i.provider===`groq`?`gsk_...`:`sk-...`}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,Br(i.provider)?` ${Br(i.provider)}`:``]})]})]}),x.length>0?(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:x.map(e=>(0,$.jsx)(yi,{field:e,value:ai(b,e),onChange:t=>C({[e.key]:t}),className:e.type===`textarea`?`sm:col-span-2`:zr},e.key))}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.fallback}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.fallbackDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i.fallback?.enabled??!0,onChange:e=>u({enabled:e.target.checked})})]})]}):null,t[10]=d,t[11]=r,t[12]=f,t[13]=m,t[14]=i,t[15]=s,t[16]=c,t[17]=u,t[18]=l,t[19]=n,t[20]=h,t[21]=g,t[22]=_,t[23]=v,t[24]=y}else h=t[20],g=t[21],_=t[22],v=t[23],y=t[24];let b;t[52]!==h||t[53]!==g||t[54]!==_?(b=(0,$.jsxs)(`div`,{className:h,children:[g,_]}),t[52]=h,t[53]=g,t[54]=_,t[55]=b):b=t[55];let x;return t[56]!==v||t[57]!==y||t[58]!==b?(x=(0,$.jsxs)(`section`,{className:v,children:[y,b]}),t[56]=v,t[57]=y,t[58]=b,t[59]=x):x=t[59],x}function ui(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function di(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function fi(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function pi(e){return e.key!==`apiKey`&&e.key!==`model`}function mi(e){let t=(0,Q.c)(76),{v:n,apiKeyLabels:r,tts:i,models:a,ttsProviders:o,updateTts:s,updateTtsAlibaba:c,updateTtsOpenai:l,updateTtsEdge:u,updateTtsMinimax:d,updateTtsLocalCli:f}=e,p;t[0]===n?p=t[1]:(p=e=>e===`off`?n.tts.triggerDescOff:e===`always`?n.tts.triggerDescAlways:e===`inbound`?n.tts.triggerDescInbound:e===`tagged`?n.tts.triggerDescTagged:``,t[0]=n,t[1]=p);let m=p,h=a?.tts?.openai?.length?a.tts.openai:qr,g=a?.ttsVoices?.openai?.length?a.ttsVoices.openai:Jr,_=a?.tts?.alibaba?.length?a.tts.alibaba:Yr,v=a?.ttsVoices?.alibaba?.length?a.ttsVoices.alibaba:Xr,y=a?.ttsVoices?.edge?.length?a.ttsVoices.edge:Zr,b=a?.tts?.minimax?.length?a.tts.minimax:Qr,x=a?.ttsVoices?.minimax?.length?a.ttsVoices.minimax:$r,S;if(t[2]!==i.provider||t[3]!==o){let e=new Set;S=[];for(let t of o)e.has(t.id)||(e.add(t.id),S.push(t));if(i.provider&&!e.has(i.provider)){let e;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=[],t[5]=e):e=t[5];let n;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(n=[{key:`apiKey`,label:`API Key`,type:`password`,secret:!0},{key:`model`,label:`Model`,type:`string`},{key:`voice`,label:`Voice`,type:`string`}],t[6]=n):n=t[6];let r=`messages.tts.providers.${i.provider}`,a;t[7]===r?a=t[8]:(a={requiresApiKey:!0,configPath:r},t[7]=r,t[8]=a);let o;t[9]!==a||t[10]!==i.provider?(o={id:i.provider,capability:`tts`,displayName:i.provider,aliases:e,configured:!1,fields:n,diagnostics:a},t[9]=a,t[10]=i.provider,t[11]=o):o=t[11],S.push(o)}t[2]=i.provider,t[3]=o,t[4]=S}else S=t[4];let C=S,w,T,E,D,O;if(t[12]!==r||t[13]!==C||t[14]!==m||t[15]!==i||t[16]!==_||t[17]!==b||t[18]!==h||t[19]!==v||t[20]!==y||t[21]!==x||t[22]!==g||t[23]!==s||t[24]!==c||t[25]!==u||t[26]!==f||t[27]!==d||t[28]!==l||t[29]!==n){let e=C.find(e=>e.id===i.provider),a=i.providers?.[i.provider],o={...i.provider===`openai`?i.openai??{}:{},...i.provider===`alibaba`?i.alibaba??{}:{},...i.provider===`edge`?i.edge??{}:{},...i.provider===`minimax`?i.minimax??{}:{},...i.provider===`tts-local-cli`?i[`tts-local-cli`]??{}:{},...a??{}},p=(e?.fields??[]).filter(vi),S;t[35]!==i.provider||t[36]!==i.providers||t[37]!==s?(S=e=>{s({providers:{...i.providers??{},[i.provider]:{...i.providers?.[i.provider]??{},...e}}})},t[35]=i.provider,t[36]=i.providers,t[37]=s,t[38]=S):S=t[38];let k=S,A;t[39]!==i.provider||t[40]!==k||t[41]!==u||t[42]!==d||t[43]!==l?(A=(e,t)=>{let n={[e.key]:t};k(n),i.provider===`openai`&&e.key===`baseUrl`?l(n):i.provider===`minimax`&&(e.key===`baseUrl`||e.key===`groupId`)?d(n):i.provider===`edge`&&e.key===`lang`&&u(n)},t[39]=i.provider,t[40]=k,t[41]=u,t[42]=d,t[43]=l,t[44]=A):A=t[44];let j=A;D=`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`;let M;t[45]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(en,{className:`size-4 text-accent`,strokeWidth:1.75}),t[45]=M):M=t[45];let N;t[46]===n.tts.title?N=t[47]:(N=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[M,n.tts.title]}),t[46]=n.tts.title,t[47]=N);let P;t[48]===n.tts.description?P=t[49]:(P=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.tts.description}),t[48]=n.tts.description,t[49]=P),t[50]!==N||t[51]!==P?(O=(0,$.jsxs)(`div`,{className:`mb-4`,children:[N,P]}),t[50]=N,t[51]=P,t[52]=O):O=t[52],w=`space-y-4`;let F;t[53]===n.tts.enable?F=t[54]:(F=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.tts.enable}),t[53]=n.tts.enable,t[54]=F);let I;t[55]===n.tts.enableDesc?I=t[56]:(I=(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.tts.enableDesc}),t[55]=n.tts.enableDesc,t[56]=I);let L;t[57]!==F||t[58]!==I?(L=(0,$.jsxs)(`div`,{children:[F,I]}),t[57]=F,t[58]=I,t[59]=L):L=t[59];let R;t[60]===s?R=t[61]:(R=e=>s({enabled:e.target.checked}),t[60]=s,t[61]=R);let z;t[62]!==R||t[63]!==i.enabled?(z=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i.enabled,onChange:R}),t[62]=R,t[63]=i.enabled,t[64]=z):z=t[64],t[65]!==L||t[66]!==z?(T=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[L,z]}),t[65]=L,t[66]=z,t[67]=T):T=t[67],E=i.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,zr),children:[(0,$.jsx)(xi,{children:n.tts.trigger}),(0,$.jsxs)(`select`,{className:Ur(),value:i.trigger,onChange:e=>s({trigger:e.target.value}),children:[(0,$.jsx)(`option`,{value:`off`,children:n.tts.triggerOff}),(0,$.jsx)(`option`,{value:`always`,children:n.tts.triggerAlways}),(0,$.jsx)(`option`,{value:`inbound`,children:n.tts.triggerInbound}),(0,$.jsx)(`option`,{value:`tagged`,children:n.tts.triggerTagged})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:m(i.trigger)})]}),(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,zr),children:[(0,$.jsx)(xi,{children:n.tts.provider}),(0,$.jsx)(`select`,{className:Ur(),value:i.provider,onChange:e=>s({provider:e.target.value}),children:C.map(e=>(0,$.jsx)(`option`,{value:e.id,children:ri(e.id,n)},e.id))})]})]}),i.provider===`openai`||i.provider===`alibaba`||i.provider===`minimax`?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,zr),children:[(0,$.jsx)(xi,{children:n.stt.apiKey}),(0,$.jsx)(pn,{kind:`tts`,providerId:i.provider,fieldId:`voice-tts-${i.provider}-api-key`,value:i.provider===`openai`?i.openai?.apiKey??``:i.provider===`alibaba`?i.alibaba?.apiKey??``:i.minimax?.apiKey??``,onChange:e=>{i.provider===`openai`?l({apiKey:e}):i.provider===`alibaba`?c({apiKey:e}):d({apiKey:e})},labels:r,placeholder:i.provider===`minimax`?`eyJ...`:`sk-...`}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,Vr(i.provider)?` ${Vr(i.provider)}`:``]})]}),(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,zr),children:[(0,$.jsx)(xi,{children:n.stt.model}),(0,$.jsx)(`select`,{className:Ur(),value:i.provider===`openai`?i.openai?.model??``:i.provider===`alibaba`?i.alibaba?.model??``:i.minimax?.model??``,onChange:e=>{i.provider===`openai`?l({model:e.target.value}):i.provider===`alibaba`?c({model:e.target.value}):d({model:e.target.value})},children:(i.provider===`openai`?h:i.provider===`alibaba`?_:b).map(_i)})]}),(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,zr),children:[(0,$.jsx)(xi,{children:n.tts.voice}),(0,$.jsx)(`select`,{className:Ur(),value:i.provider===`openai`?i.openai?.voice??``:i.provider===`alibaba`?i.alibaba?.voice??``:i.minimax?.voice??``,onChange:e=>{i.provider===`openai`?l({voice:e.target.value}):i.provider===`alibaba`?c({voice:e.target.value}):d({voice:e.target.value})},children:(i.provider===`openai`?g:i.provider===`alibaba`?v:x).map(gi)})]})]}):null,i.provider===`edge`?(0,$.jsxs)(`div`,{className:J(`flex flex-col gap-1.5`,zr),children:[(0,$.jsx)(xi,{children:n.tts.voice}),(0,$.jsx)(`select`,{className:Ur(),value:i.edge?.voice??``,onChange:e=>u({voice:e.target.value}),children:y.map(hi)}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.edgeHint})]}):null,i.provider===`tts-local-cli`?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(xi,{children:n.tts.localCli.command}),(0,$.jsx)(`input`,{className:J(Hr(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:i[`tts-local-cli`]?.command??``,onChange:e=>f({command:e.target.value}),placeholder:n.tts.localCli.commandPlaceholder}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.commandDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(xi,{children:n.tts.localCli.cwd}),(0,$.jsx)(`input`,{className:J(Hr(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:i[`tts-local-cli`]?.cwd??``,onChange:e=>f({cwd:e.target.value}),placeholder:`/path/to/cwd`}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.cwdDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(xi,{children:n.tts.localCli.outputFormat}),(0,$.jsxs)(`select`,{className:Ur(),value:i[`tts-local-cli`]?.outputFormat??`wav`,onChange:e=>f({outputFormat:e.target.value}),children:[(0,$.jsx)(`option`,{value:`wav`,children:`wav`}),(0,$.jsx)(`option`,{value:`mp3`,children:`mp3`}),(0,$.jsx)(`option`,{value:`opus`,children:`opus`})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.outputFormatDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(xi,{children:n.tts.localCli.timeoutMs}),(0,$.jsx)(`input`,{className:Hr(),type:`number`,min:0,step:1e3,value:typeof i[`tts-local-cli`]?.timeoutMs==`number`?String(i[`tts-local-cli`].timeoutMs):``,onChange:e=>{let t=e.target.value.trim();if(t===``){f({timeoutMs:void 0});return}let n=Number(t);Number.isFinite(n)&&n>=0&&f({timeoutMs:n})},placeholder:`30000`}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.timeoutMsDesc})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:n.tts.localCli.hint})]}):null,p.length>0?(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:p.map(e=>(0,$.jsx)(yi,{field:e,value:ai(o,e),onChange:t=>j(e,t),className:e.type===`textarea`?`sm:col-span-2`:zr},e.key))}):null]}):null,t[12]=r,t[13]=C,t[14]=m,t[15]=i,t[16]=_,t[17]=b,t[18]=h,t[19]=v,t[20]=y,t[21]=x,t[22]=g,t[23]=s,t[24]=c,t[25]=u,t[26]=f,t[27]=d,t[28]=l,t[29]=n,t[30]=w,t[31]=T,t[32]=E,t[33]=D,t[34]=O}else w=t[30],T=t[31],E=t[32],D=t[33],O=t[34];let k;t[68]!==w||t[69]!==T||t[70]!==E?(k=(0,$.jsxs)(`div`,{className:w,children:[T,E]}),t[68]=w,t[69]=T,t[70]=E,t[71]=k):k=t[71];let A;return t[72]!==D||t[73]!==O||t[74]!==k?(A=(0,$.jsxs)(`section`,{className:D,children:[O,k]}),t[72]=D,t[73]=O,t[74]=k,t[75]=A):A=t[75],A}function hi(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function gi(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function _i(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function vi(e){return![`apiKey`,`model`,`voice`].includes(e.key)}function yi(e){let t=(0,Q.c)(36),{field:n,value:r,onChange:i,className:a}=e,o=`voice-schema-field-${n.key}`,s=n.description;if(n.type===`boolean`){let e;t[0]===a?e=t[1]:(e=J(`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,a),t[0]=a,t[1]=e);let o;t[2]===n.label?o=t[3]:(o=(0,$.jsx)(`span`,{className:`block text-sm font-medium text-fg`,children:n.label}),t[2]=n.label,t[3]=o);let c;t[4]===s?c=t[5]:(c=s?(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:s}):null,t[4]=s,t[5]=c);let l;t[6]!==o||t[7]!==c?(l=(0,$.jsxs)(`span`,{children:[o,c]}),t[6]=o,t[7]=c,t[8]=l):l=t[8];let u=!!r,d;t[9]!==n||t[10]!==i?(d=e=>i(oi(n,e.target.checked)),t[9]=n,t[10]=i,t[11]=d):d=t[11];let f;t[12]!==u||t[13]!==d?(f=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:u,onChange:d}),t[12]=u,t[13]=d,t[14]=f):f=t[14];let p;return t[15]!==e||t[16]!==l||t[17]!==f?(p=(0,$.jsxs)(`label`,{className:e,children:[l,f]}),t[15]=e,t[16]=l,t[17]=f,t[18]=p):p=t[18],p}let c=typeof r==`boolean`?``:String(r),l;t[19]===a?l=t[20]:(l=J(`flex flex-col gap-1.5`,a),t[19]=a,t[20]=l);let u;t[21]===n.label?u=t[22]:(u=(0,$.jsx)(xi,{children:n.label}),t[21]=n.label,t[22]=u);let d;t[23]!==a||t[24]!==n||t[25]!==c||t[26]!==o||t[27]!==i?(d=n.type===`select`?(0,$.jsx)(`select`,{id:o,className:Ur(),value:c,required:n.required,onChange:e=>i(oi(n,e.target.value)),children:(n.options??[]).map(bi)}):n.type===`textarea`?(0,$.jsx)(`textarea`,{id:o,className:J(Hr(),`min-h-24 resize-y`),value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(oi(n,e.target.value))}):n.type===`password`?(0,$.jsx)(ft,{id:o,className:a,value:c,onChange:e=>i(oi(n,e)),placeholder:n.placeholder,labels:Xe}):(0,$.jsx)(`input`,{id:o,className:Hr(),type:n.type===`number`?`number`:`text`,autoComplete:n.secret?`new-password`:`off`,spellCheck:!1,value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(oi(n,e.target.value))}),t[23]=a,t[24]=n,t[25]=c,t[26]=o,t[27]=i,t[28]=d):d=t[28];let f;t[29]===s?f=t[30]:(f=s?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:s}):null,t[29]=s,t[30]=f);let p;return t[31]!==l||t[32]!==u||t[33]!==d||t[34]!==f?(p=(0,$.jsxs)(`div`,{className:l,children:[u,d,f]}),t[31]=l,t[32]=u,t[33]=d,t[34]=f,t[35]=p):p=t[35],p}function bi(e){return(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id)}function xi(e){let t=(0,Q.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=r),r}function Si(e){let t=e&&typeof e==`object`&&`tools`in e?e.tools:void 0,n=t&&typeof t==`object`&&`web`in t?t.web:void 0,r=n&&typeof n==`object`&&`region`in n?n.region:void 0,i=r===`cn`||r===`global`?r:`auto`,a=n&&typeof n==`object`&&`search`in n?n.search:void 0,o=a&&typeof a==`object`?a:{},s=typeof o.maxResults==`number`&&Number.isFinite(o.maxResults)?Math.floor(o.maxResults):5,c=n&&typeof n==`object`&&`blocklist`in n?n.blocklist:void 0,l=c&&typeof c==`object`?c:{},u=Array.isArray(l.domains)?l.domains.filter(e=>typeof e==`string`&&e.trim().length>0):[],d=o.providers;return{regionMode:i,maxResults:s,providers:Array.isArray(d)?d.map(e=>{let t=e&&typeof e==`object`?e:{},n=t.type;return{type:n===`brave`||n===`tavily`||n===`bing`||n===`searxng`?n:`brave`,apiKey:typeof t.apiKey==`string`?t.apiKey:``,url:typeof t.url==`string`?t.url:``,disabled:t.disabled===!0}}):[],blocklistEnabled:l.enabled===!0,blocklistDomains:u}}async function Ci(e){let t=e.regionMode===`auto`?`auto`:e.regionMode===`cn`?`cn`:`global`,n={maxResults:e.maxResults,providers:e.providers.map(e=>{let t={type:e.type,apiKey:e.apiKey};return e.type===`searxng`&&e.url.trim()&&(t.url=e.url.trim().replace(/\/+$/,``)),e.disabled&&(t.disabled=!0),t})};await w(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n,blocklist:{enabled:e.blocklistEnabled,domains:e.blocklistDomains}}}})}),Qt()}async function wi(e){let t=await w(l(`/api/tools/web/reveal-search-api-key`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({index:e})});if(!t.ok||!t.payload)throw Error(t.error?.message??`Reveal failed`);return t.payload}function Ti(e){let t=(0,Q.c)(8),{label:n,description:r,children:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=a);let o;t[2]===r?o=t[3]:(o=(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r}),t[2]=r,t[3]=o);let s;return t[4]!==i||t[5]!==a||t[6]!==o?(s=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a,i,o]}),t[4]=i,t[5]=a,t[6]=o,t[7]=s):s=t[7],s}function Ei(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ht,`dark:border-edge`)}function Di(){return J(ct,jt)}var Oi=[`brave`,`tavily`,`bing`,`searxng`];function ki(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}var Ai=ot();function ji({embedded:e=!1}={}){let t=a(e=>e.language),n=s(t),r=n.webSearchSettings,i=n.logs,o=!!C(e=>e.token),[c,l]=(0,Z.useReducer)(Ai,{form:null,baseline:null}),u=c.form,d=c.baseline,[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),v=(0,Z.useRef)(!1),y=(0,Z.useRef)(null),{data:b,error:x,isLoading:S,mutate:w}=Fe(o);pt({enabled:o,parsed:(0,Z.useMemo)(()=>b?.payload?.config===void 0?null:Si(b.payload.config),[b]),dirty:v.current,trackedParsedRef:y,dispatch:l,onResetDirty:()=>{v.current=!1}});let T=!!(o&&S&&b===void 0&&!x),E=x instanceof Error?x.message:x?String(x):null,D=(0,Z.useMemo)(()=>!u||!d?!1:JSON.stringify(u)!==JSON.stringify(d),[u,d]),O=(0,Z.useCallback)(e=>{v.current=!0,l({type:`patch`,patch:e})},[]),k=(0,Z.useCallback)(async()=>{if(!(!u||f)){p(!0),h(null),_(!1);try{await Ci(u),v.current=!1,l({type:`saved`,value:u}),_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){h(e instanceof Error?e.message:r.saveError)}finally{p(!1)}}},[u,f,r.saveError]),A=(0,Z.useCallback)(()=>{d&&(v.current=!1,l({type:`discard`}),h(null),_(!1))},[d]);vr({id:`search`,dirty:D,saving:f,save:k,discard:A});let j=e?`flex flex-col gap-4`:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,M=e?`flex flex-col gap-3`:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`;return o?T?(0,$.jsxs)(`div`,{className:J(M,`items-center`),children:[(0,$.jsx)(q,{className:`size-8 animate-spin text-fg-muted`,"aria-hidden":!0}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.loading})]}):u?(0,$.jsxs)(`div`,{className:j,children:[(0,$.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[e?(0,$.jsx)(`div`,{className:`min-w-0`,"aria-hidden":!0}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:r.title}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.subtitle}),(0,$.jsxs)(`a`,{href:Rt(t,`gateway`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[r.docsLink,(0,$.jsx)(fe,{className:`size-3.5`})]})]}),e?null:(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[g?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:r.saved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!D||f,onClick:A,children:r.discard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!D||f,onClick:()=>void k(),children:f?r.saving:r.save})]})]}),D&&!e?(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:r.unsavedHint}):null,m?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,$.jsxs)(X,{children:[(0,$.jsx)(vn,{icon:We,title:r.sectionRegion,subtitle:r.sectionRegionHint}),(0,$.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,$.jsx)(Ti,{label:r.regionLabel,description:r.regionDesc,children:(0,$.jsxs)(`select`,{className:Di(),value:u.regionMode,onChange:e=>O({regionMode:e.target.value}),children:[(0,$.jsx)(`option`,{value:`auto`,children:r.regionAuto}),(0,$.jsx)(`option`,{value:`cn`,children:r.regionCn}),(0,$.jsx)(`option`,{value:`global`,children:r.regionGlobal})]})})})]}),(0,$.jsxs)(X,{children:[(0,$.jsx)(vn,{icon:kt,title:r.sectionBlocklist,subtitle:r.sectionBlocklistHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:u.blocklistEnabled,onChange:e=>O({blocklistEnabled:e.target.checked})}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:r.blocklistEnabled}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:r.blocklistEnabledDesc})]})]}),(0,$.jsx)(Ti,{label:r.blocklistDomains,description:r.blocklistDomainsDesc,children:(0,$.jsx)(`textarea`,{className:J(Ei(),`min-h-[6rem] font-mono text-xs`),value:u.blocklistDomains.join(`
|
|
2
|
-
`),placeholder:r.blocklistDomainsPlaceholder,disabled:!u.blocklistEnabled,onChange:e=>{O({blocklistDomains:e.target.value.split(/\r?\n/).flatMap(e=>{let t=e.trim().toLowerCase();return t?[t]:[]})})}})})]})]}),(0,$.jsxs)(X,{children:[(0,$.jsx)(vn,{icon:We,title:r.sectionSearch,subtitle:r.sectionSearchHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,$.jsx)(Ti,{label:r.maxResultsLabel,description:r.maxResultsDesc,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:50,className:Ei(),value:u.maxResults,onChange:e=>O({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:r.providersTitle}),u.providers.map((e,t)=>(0,$.jsx)(Mi,{row:e,providerIndex:t,labels:r,secretLabels:Ae(n.providersSettings),onChange:e=>{let n=[...u.providers];n[t]=e,O({providers:n})},onRemove:()=>{O({providers:u.providers.filter((e,n)=>n!==t)})}},`${e.type}:${e.url}:${e.apiKey}:${e.disabled}`)),(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>O({providers:[...u.providers,ki()]}),children:[(0,$.jsx)(dt,{className:`size-4`}),r.addProvider]})]})]})]}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r.footerHint})]}):(0,$.jsxs)(`div`,{className:M,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m??E??r.loadError}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:()=>void w(),children:i.refresh})]}):(0,$.jsxs)(`div`,{className:M,children:[e?null:(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:r.title}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.needToken})]})}function Mi(e){let t=(0,Q.c)(54),{row:n,providerIndex:r,labels:i,secretLabels:a,onChange:o,onRemove:s}=e,c;t[0]===r?c=t[1]:(c=()=>wi(r).then(Ni),t[0]=r,t[1]=c);let l=c,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=J(Di(),`min-w-[8rem]`),t[2]=u):u=t[2];let d=n.type,f;t[3]!==o||t[4]!==n?(f=e=>o({...n,type:e.target.value,url:e.target.value===`searxng`?n.url:``}),t[3]=o,t[4]=n,t[5]=f):f=t[5];let p;t[6]===i.providerTypes?p=t[7]:(p=Oi.map(e=>(0,$.jsx)(`option`,{value:e,children:i.providerTypes[e]},e)),t[6]=i.providerTypes,t[7]=p);let m;t[8]!==n.type||t[9]!==f||t[10]!==p?(m=(0,$.jsx)(`select`,{className:u,value:d,onChange:f,children:p}),t[8]=n.type,t[9]=f,t[10]=p,t[11]=m):m=t[11];let h;t[12]!==o||t[13]!==n?(h=e=>o({...n,disabled:e.target.checked}),t[12]=o,t[13]=n,t[14]=h):h=t[14];let g;t[15]!==n.disabled||t[16]!==h?(g=(0,$.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:n.disabled,onChange:h}),t[15]=n.disabled,t[16]=h,t[17]=g):g=t[17];let _;t[18]!==i.disabled||t[19]!==g?(_=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[g,i.disabled]}),t[18]=i.disabled,t[19]=g,t[20]=_):_=t[20];let v;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(Re,{className:`size-4`}),t[21]=v):v=t[21];let y;t[22]===s?y=t[23]:(y=(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:s,children:v}),t[22]=s,t[23]=y);let b;t[24]!==y||t[25]!==_?(b=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[_,y]}),t[24]=y,t[25]=_,t[26]=b):b=t[26];let x;t[27]!==b||t[28]!==m?(x=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[m,b]}),t[27]=b,t[28]=m,t[29]=x):x=t[29];let S;t[30]!==i.urlDesc||t[31]!==i.urlLabel||t[32]!==o||t[33]!==n?(S=n.type===`searxng`?(0,$.jsx)(Ti,{label:i.urlLabel,description:i.urlDesc,children:(0,$.jsx)(`input`,{type:`url`,className:Ei(),value:n.url,placeholder:`http://localhost:8080`,onChange:e=>o({...n,url:e.target.value})})}):null,t[30]=i.urlDesc,t[31]=i.urlLabel,t[32]=o,t[33]=n,t[34]=S):S=t[34];let C;t[35]!==o||t[36]!==n?(C=e=>o({...n,apiKey:e}),t[35]=o,t[36]=n,t[37]=C):C=t[37];let w;t[38]!==i.keyPlaceholder||t[39]!==i.keyPlaceholderMasked||t[40]!==i.saveError||t[41]!==l||t[42]!==n.apiKey||t[43]!==a||t[44]!==C?(w=(0,$.jsx)(ft,{value:n.apiKey,onChange:C,placeholder:i.keyPlaceholder,labels:a,reveal:l,loadFailedLabel:i.saveError,notInConfigFile:i.keyPlaceholderMasked}),t[38]=i.keyPlaceholder,t[39]=i.keyPlaceholderMasked,t[40]=i.saveError,t[41]=l,t[42]=n.apiKey,t[43]=a,t[44]=C,t[45]=w):w=t[45];let T;t[46]!==i.apiKeyDesc||t[47]!==i.apiKeyLabel||t[48]!==w?(T=(0,$.jsx)(Ti,{label:i.apiKeyLabel,description:i.apiKeyDesc,children:w}),t[46]=i.apiKeyDesc,t[47]=i.apiKeyLabel,t[48]=w,t[49]=T):T=t[49];let E;return t[50]!==x||t[51]!==S||t[52]!==T?(E=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-edge-subtle bg-surface-panel/60 p-4 dark:border-edge-subtle`,children:[x,S,T]}),t[50]=x,t[51]=S,t[52]=T,t[53]=E):E=t[53],E}function Ni(e){return e.apiKey??null}function Pi(){let e=(0,Q.c)(26),t=s(a(Bi)).modelsHub.saveBar,n=_r(zi),r=_r(Ri),i=_r(Li),o=_r(Ii),c=_r(Fi),l;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=[],e[0]=l):l=e[0];let[u,d]=(0,Z.useState)(l),[f,p]=(0,Z.useState)(!1);if(!n&&u.length===0&&!f)return null;let m;e[1]===o?m=e[2]:(m=async()=>{d([]),p(!1);let e=await o();e.ok&&e.saved>0?(p(!0),window.setTimeout(()=>p(!1),2500)):e.ok||d(e.failures)},e[1]=o,e[2]=m);let h=m,g;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(g=J(`sticky top-0 z-10 -mx-4 flex flex-col gap-2 border-b border-edge-subtle bg-surface-base/85 px-4 py-2 backdrop-blur`,`sm:flex-row sm:items-center sm:justify-between`),e[3]=g):g=e[3];let _=u.length>0?(0,$.jsx)(`span`,{className:`text-xs text-red-600 dark:text-red-400`,role:`alert`,children:t.failuresSummary.replace(`{{count}}`,String(u.length))}):null,v=!n||r,y;e[4]===c?y=e[5]:(y=()=>c(),e[4]=c,e[5]=y);let b;e[6]!==t.discardAll||e[7]!==v||e[8]!==y?(b=(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:v,onClick:y,children:t.discardAll}),e[6]=t.discardAll,e[7]=v,e[8]=y,e[9]=b):b=e[9];let x=!n||r,S;e[10]===h?S=e[11]:(S=()=>void h(),e[10]=h,e[11]=S);let C;e[12]===r?C=e[13]:(C=r?(0,$.jsx)(q,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):null,e[12]=r,e[13]=C);let w=r?`ml-1.5`:void 0,T;e[14]!==t.saveAll||e[15]!==w?(T=(0,$.jsx)(`span`,{className:w,children:t.saveAll}),e[14]=t.saveAll,e[15]=w,e[16]=T):T=e[16];let E;e[17]!==C||e[18]!==T||e[19]!==x||e[20]!==S?(E=(0,$.jsxs)(Y,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:x,onClick:S,children:[C,T]}),e[17]=C,e[18]=T,e[19]=x,e[20]=S,e[21]=E):E=e[21];let D;return e[22]!==E||e[23]!==_||e[24]!==b?(D=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[_,b,E]}),e[22]=E,e[23]=_,e[24]=b,e[25]=D):D=e[25],(0,$.jsxs)(`div`,{className:g,role:`region`,"aria-label":t.title,children:[(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n?t.dirtySummary.replace(`{{count}}`,String(i)):f?t.savedSummary:t.cleanSummary}),D]})}function Fi(e){return e.discardAll}function Ii(e){return e.saveAll}function Li(e){return e.dirtyCount}function Ri(e){return e.anySaving}function zi(e){return e.anyDirty}function Bi(e){return e.language}var Vi=[{value:`openai-completions`,label:`OpenAI Completions`},{value:`openai-responses`,label:`OpenAI Responses`},{value:`anthropic-messages`,label:`Anthropic Messages`},{value:`google-generative-ai`,label:`Google Generative AI`},{value:`azure-openai-responses`,label:`Azure OpenAI`},{value:`bedrock-converse-stream`,label:`AWS Bedrock`},{value:`openai-codex-responses`,label:`OpenAI Codex`},{value:`google-gemini-cli`,label:`Google Gemini CLI`},{value:`google-vertex`,label:`Google Vertex AI`}];function Hi(e){if(!e||typeof e!=`object`)return;let t=e;if(typeof t.error==`string`)return t.error;if(t.error&&typeof t.error==`object`&&`message`in t.error){let e=t.error.message;return typeof e==`string`?e:void 0}}function Ui(e){if(!e||typeof e!=`object`)return{providers:{}};let t=e,n=t.providers;return n&&typeof n==`object`&&!Array.isArray(n)?e:{...t,providers:{}}}async function Wi(){let e=await T(l(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Hi(t)||`HTTP ${e.status}`);return{...t.payload,config:Ui(t.payload.config)}}async function Gi(e){let t=await T(l(`/api/models-json`),{method:`PATCH`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(Hi(n)||`HTTP ${t.status}`);return await Ee(),n.payload}function Ki(){let e=(0,Q.c)(29),t=C(Zi),n=!!t,{data:r,isLoading:i}=Fe(n),a;e[0]===n?a=e[1]:(a=n?l(`/api/providers/meta`):null,e[0]=n,e[1]=a);let o;e[2]===t?o=e[3]:(o=async e=>{let{payload:n}=await(await fetch(e,{headers:{Authorization:`Bearer ${t}`}})).json();return n?.providers??[]},e[2]=t,e[3]=o);let s;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(s={revalidateOnFocus:!1},e[4]=s):s=e[4];let{data:c,isLoading:u}=d(a,o,s),f;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(f={revalidateOnFocus:!1},e[5]=f):f=e[5];let{data:p,isLoading:m}=d(n?je:null,Xi,f),h;e[6]===p?h=e[7]:(h=p===void 0?[]:p,e[6]=p,e[7]=h);let g=h,_;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(_={revalidateOnFocus:!1},e[8]=_):_=e[8];let{data:v}=d(n?ve:null,Yi,_),y;bb0:{if(!c||r===void 0){let t;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[9]=t):t=e[9],y=t;break bb0}let t;e[10]!==r?.payload?.config||e[11]!==c||e[12]!==g?(t=wt(c,St(r?.payload?.config),g),e[10]=r?.payload?.config,e[11]=c,e[12]=g,e[13]=t):t=e[13],y=t}let b=y,x;bb1:{if(!v){x=null;break bb1}let t;e[14]===v.config?t=e[15]:(t=Ui(v.config),e[14]=v.config,e[15]=t),x=t}let S=x,w;if(e[16]!==b||e[17]!==S||e[18]!==c||e[19]!==g){w=[];let t=new Set((c??[]).filter(Ji).map(qi));for(let e of b){if(!t.has(e.id))continue;let n=g.filter(t=>t.provider===e.id).length;w.push({id:e.id,name:e.name,configured:!0,isCustom:!1,modelCount:n})}if(S){let t;e[21]===S.providers?t=e[22]:(t=Object.entries(S.providers),e[21]=S.providers,e[22]=t);for(let[e,n]of t)w.some(t=>t.id===e)||w.push({id:e,name:e,configured:!0,isCustom:!0,modelCount:n.models?.length??0})}e[16]=b,e[17]=S,e[18]=c,e[19]=g,e[20]=w}else w=e[20];let T=w,E=i||u||m,D;return e[23]!==b||e[24]!==T||e[25]!==S||e[26]!==E||e[27]!==g?(D={cards:T,loading:E,builtinRows:b,customConfig:S,allModels:g},e[23]=b,e[24]=T,e[25]=S,e[26]=E,e[27]=g,e[28]=D):D=e[28],D}function qi(e){return e.id}function Ji(e){return e.configured}function Yi(){return Wi()}function Xi(){return tn()}function Zi(e){return e.token}function Qi(e){let t=(0,Q.c)(16),{labels:n,onAdd:r,onManage:i}=e,{cards:a,loading:o}=Ki();if(o){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(`div`,{className:`h-6 w-48 animate-pulse rounded bg-surface-hover`}),t[0]=e):e=t[0];let n;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[e,(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[1,2,3].map(ea)})]}),t[1]=n):n=t[1],n}let s;if(t[2]!==a||t[3]!==n||t[4]!==r||t[5]!==i){let e=a.filter($i),o=e.length>0?n.titleCount.replace(`{{count}}`,String(e.length)):n.title,c;t[7]===o?c=t[8]:(c=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:o}),t[7]=o,t[8]=c);let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(dt,{className:`size-3.5`,strokeWidth:2,"aria-hidden":!0}),t[9]=l):l=t[9];let u;t[10]!==n.addProvider||t[11]!==r?(u=(0,$.jsxs)(Y,{type:`button`,variant:`primary`,className:`gap-1.5`,onClick:r,children:[l,n.addProvider]}),t[10]=n.addProvider,t[11]=r,t[12]=u):u=t[12];let d;t[13]!==c||t[14]!==u?(d=(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[c,u]}),t[13]=c,t[14]=u,t[15]=d):d=t[15],s=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d,e.length===0?(0,$.jsxs)(`div`,{className:`rounded-2xl border border-dashed border-edge-subtle bg-surface-panel/40 px-6 py-10 text-center`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.empty}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.emptyHint}),(0,$.jsxs)(Y,{type:`button`,variant:`primary`,className:`mt-4 gap-1.5`,onClick:r,children:[(0,$.jsx)(dt,{className:`size-3.5`,strokeWidth:2,"aria-hidden":!0}),n.addProvider]})]}):(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:e.map(e=>(0,$.jsx)(ta,{card:e,labels:n,onManage:()=>i(e.id,e.isCustom)},e.id))})]}),t[2]=a,t[3]=n,t[4]=r,t[5]=i,t[6]=s}else s=t[6];return s}function $i(e){return e.configured}function ea(e){return(0,$.jsx)(`div`,{className:`h-32 animate-pulse rounded-2xl bg-surface-hover`},e)}function ta(e){let t=(0,Q.c)(28),{card:n,labels:r,onManage:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=J(`group relative flex flex-col justify-between rounded-2xl border border-edge-subtle bg-surface-base p-4 text-left transition-colors`,`hover:bg-surface-hover/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.pressCard),t[0]=a):a=t[0];let o;t[1]===n.name?o=t[2]:(o=(0,$.jsx)(`span`,{className:`truncate text-sm font-semibold text-fg`,children:n.name}),t[1]=n.name,t[2]=o);let s;t[3]!==n.isCustom||t[4]!==r.custom?(s=n.isCustom?(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-subtle`,children:r.custom}):null,t[3]=n.isCustom,t[4]=r.custom,t[5]=s):s=t[5];let c;t[6]!==o||t[7]!==s?(c=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[o,s]}),t[6]=o,t[7]=s,t[8]=c):c=t[8];let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(p,{className:`size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),t[9]=l):l=t[9];let u;t[10]===c?u=t[11]:(u=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[c,l]}),t[10]=c,t[11]=u);let d;t[12]!==n.modelCount||t[13]!==r.modelsCount||t[14]!==r.noModels?(d=n.modelCount>0?r.modelsCount.replace(`{{count}}`,String(n.modelCount)):r.noModels,t[12]=n.modelCount,t[13]=r.modelsCount,t[14]=r.noModels,t[15]=d):d=t[15];let f;t[16]===d?f=t[17]:(f=(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:d}),t[16]=d,t[17]=f);let m;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(G,{className:`size-3`,"aria-hidden":!0}),t[18]=m):m=t[18];let h;t[19]===r.manage?h=t[20]:(h=(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-xs font-medium text-accent-fg opacity-0 transition-opacity group-hover:opacity-100`,children:[m,r.manage]}),t[19]=r.manage,t[20]=h);let g;t[21]!==h||t[22]!==f?(g=(0,$.jsxs)(`div`,{className:`mt-2.5 flex items-center justify-between`,children:[f,h]}),t[21]=h,t[22]=f,t[23]=g):g=t[23];let _;return t[24]!==i||t[25]!==g||t[26]!==u?(_=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:a,children:[u,g]}),t[24]=i,t[25]=g,t[26]=u,t[27]=_):_=t[27],_}var na=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function ra(e){let t=new Map;for(let e of na)t.set(e,[]);for(let n of e){let e=n.category||`specialty`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t}var ia={ollama:{baseUrl:`http://localhost:11434/v1`,api:`openai-completions`,apiKey:`ollama`},lmstudio:{baseUrl:`http://localhost:1234/v1`,api:`openai-completions`,apiKey:`lmstudio`},openrouter:{baseUrl:`https://openrouter.ai/api/v1`,api:`openai-completions`,apiKey:``},zhipuCn:{baseUrl:`https://open.bigmodel.cn/api/coding/paas/v4`,api:`openai-completions`,apiKey:`ZHIPU_API_KEY`},zaiGeneral:{baseUrl:`https://api.z.ai/api/paas/v4`,api:`openai-completions`,apiKey:`ZAI_API_KEY`}};function aa(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}function oa(){return J(ct,jt)}function sa(e){let t=(0,Q.c)(21),{open:n,onOpenChange:r,builtinRows:i,customConfig:a,labels:o,language:s,onSaved:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l={type:`pick`},t[0]=l):l=t[0];let[u,d]=(0,Z.useState)(l),[f,p]=(0,Z.useState)(``),m;t[1]===r?m=t[2]:(m=e=>{e||window.setTimeout(()=>{d({type:`pick`}),p(``)},200),r(e)},t[1]=r,t[2]=m);let y=m,b;t[3]!==y||t[4]!==c?(b=()=>{c(),y(!1)},t[3]=y,t[4]=c,t[5]=b):b=t[5];let x=b,S;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(g,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Pe)}),t[6]=S):S=t[6];let C;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(C=J(`fixed left-1/2 top-1/2 flex max-h-[85vh] w-full max-w-lg -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge-subtle bg-surface-base shadow-xl`,Xt),t[7]=C):C=t[7];let w;t[8]!==i||t[9]!==a||t[10]!==x||t[11]!==o||t[12]!==s||t[13]!==f||t[14]!==u.providerId||t[15]!==u.type?(w=(0,$.jsxs)(h,{children:[S,(0,$.jsx)(_,{className:C,children:u.type===`pick`?(0,$.jsx)(la,{builtinRows:i,searchQuery:f,onSearchChange:p,labels:o,onPickBuiltin:e=>d({type:`builtin`,providerId:e}),onPickCustom:()=>d({type:`custom`})}):u.type===`builtin`?(0,$.jsx)(ua,{providerId:u.providerId,builtinRows:i,labels:o,language:s,onBack:()=>d({type:`pick`}),onSaved:x}):(0,$.jsx)(pa,{customConfig:a,labels:o,language:s,onBack:()=>d({type:`pick`}),onSaved:x})})]}),t[8]=i,t[9]=a,t[10]=x,t[11]=o,t[12]=s,t[13]=f,t[14]=u.providerId,t[15]=u.type,t[16]=w):w=t[16];let T;return t[17]!==y||t[18]!==n||t[19]!==w?(T=(0,$.jsx)(v,{open:n,onOpenChange:y,children:w}),t[17]=y,t[18]=n,t[19]=w,t[20]=T):T=t[20],T}function ca(e){let t=(0,Q.c)(4),{label:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=J(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),t[0]=r):r=t[0];let i;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(vt,{className:`size-4`,"aria-hidden":!0}),t[1]=i):i=t[1];let a;return t[2]===n?a=t[3]:(a=(0,$.jsx)(x,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:r,"aria-label":n,children:i})}),t[2]=n,t[3]=a),a}function la(e){let t=(0,Q.c)(42),{builtinRows:n,searchQuery:r,onSearchChange:i,labels:a,onPickBuiltin:o,onPickCustom:s}=e,c;t[0]===r?c=t[1]:(c=r.trim().toLowerCase(),t[0]=r,t[1]=c);let l=c,u;bb0:{if(!l){u=n;break bb0}let e;if(t[2]!==n||t[3]!==l){let r;t[5]===l?r=t[6]:(r=e=>{let t=V[e.id]?.aliases??[];return e.id.toLowerCase().includes(l)||e.name.toLowerCase().includes(l)||t.some(e=>e.toLowerCase().includes(l))},t[5]=l,t[6]=r),e=n.filter(r),t[2]=n,t[3]=l,t[4]=e}else e=t[4];u=e}let d=u,f;t[7]===d?f=t[8]:(f=ra(d),t[7]=d,t[8]=f);let m=f,h;t[9]===a.step1Title?h=t[10]:(h=(0,$.jsx)(b,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:a.step1Title}),t[9]=a.step1Title,t[10]=h);let g;t[11]===a.close?g=t[12]:(g=(0,$.jsx)(ca,{label:a.close}),t[11]=a.close,t[12]=g);let _;t[13]!==h||t[14]!==g?(_=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle px-5 py-4`,children:[h,g]}),t[13]=h,t[14]=g,t[15]=_):_=t[15];let v;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(We,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),t[16]=v):v=t[16];let y;t[17]===i?y=t[18]:(y=e=>i(e.target.value),t[17]=i,t[18]=y);let x=a.searchPlaceholder,S;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(S=J(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,ht),t[19]=S):S=t[19];let C;t[20]!==a.searchPlaceholder||t[21]!==r||t[22]!==y?(C=(0,$.jsx)(`div`,{className:`px-5 pt-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[v,(0,$.jsx)(`input`,{type:`search`,value:r,onChange:y,placeholder:x,autoComplete:`off`,autoFocus:!0,className:S})]})}),t[20]=a.searchPlaceholder,t[21]=r,t[22]=y,t[23]=C):C=t[23];let w;t[24]!==a.addCustom||t[25]!==a.customDescription||t[26]!==s||t[27]!==l?(w=l?null:(0,$.jsxs)(`button`,{type:`button`,onClick:s,className:J(`mb-3 flex w-full items-center gap-3 rounded-xl border border-dashed border-edge-subtle bg-surface-panel/40 px-4 py-3 text-left transition-colors`,`hover:bg-surface-hover/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.press),children:[(0,$.jsx)(Ce,{className:`size-5 shrink-0 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:a.addCustom}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:a.customDescription})]}),(0,$.jsx)(Nt,{className:`size-4 shrink-0 text-fg-subtle`,"aria-hidden":!0})]}),t[24]=a.addCustom,t[25]=a.customDescription,t[26]=s,t[27]=l,t[28]=w):w=t[28];let T;t[29]!==d.length||t[30]!==m||t[31]!==a.categories||t[32]!==a.noResults||t[33]!==o?(T=d.length===0?(0,$.jsx)(`p`,{className:`py-6 text-center text-sm text-fg-muted`,children:a.noResults}):(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:na.map(e=>{let t=m.get(e)??[];return t.length===0?null:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:a.categories[e]??e}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:t.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),className:J(`flex w-full items-center justify-between gap-2 rounded-lg px-3 py-2.5 text-left transition-colors`,`hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.press),children:[(0,$.jsx)(`span`,{className:`truncate text-sm text-fg`,children:e.name}),e.configured?(0,$.jsx)(p,{className:`size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):null]},e.id))})]},e)})}),t[29]=d.length,t[30]=m,t[31]=a.categories,t[32]=a.noResults,t[33]=o,t[34]=T):T=t[34];let E;t[35]!==w||t[36]!==T?(E=(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-3`,children:[w,T]}),t[35]=w,t[36]=T,t[37]=E):E=t[37];let D;return t[38]!==C||t[39]!==E||t[40]!==_?(D=(0,$.jsxs)($.Fragment,{children:[_,C,E]}),t[38]=C,t[39]=E,t[40]=_,t[41]=D):D=t[41],D}function ua({providerId:e,builtinRows:t,labels:n,language:r,onBack:i,onSaved:a}){let o=t.find(t=>t.id===e),c=V[e],[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),v=(0,Z.useRef)(null),y=Ae(s(r).providersSettings),x=(0,Z.useMemo)(()=>re(e,r),[e,r]),S=async()=>{let t=l.trim();if(t){f(!0),h(null);try{await O({[e]:t}),_(!0),window.setTimeout(a,600)}catch(e){h(e instanceof Error?e.message:n.saveError)}finally{f(!1)}}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,className:J(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),"aria-label":n.back,children:(0,$.jsx)(Nt,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(b,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:o?.name??e}),(0,$.jsx)(ca,{label:n.close})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 px-5 py-4`,children:[c?.description?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:c.description}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`builtin-api-key`,className:`text-sm font-medium text-fg`,children:n.apiKeyLabel}),(0,$.jsx)(ft,{id:`builtin-api-key`,value:l,onChange:u,placeholder:n.apiKeyPlaceholder,labels:y,inputRef:v,onKeyDown:e=>{e.key===`Enter`&&S()}})]}),x.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:x.map(({kind:e,href:t})=>(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[de(e,n),(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]},e))}):null,m?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!l.trim()||d||g,onClick:()=>void S(),children:g?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(p,{className:`size-3.5`,"aria-hidden":!0}),n.saved]}):d?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(q,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})]})]})]})}function da(e=`custom`){if(e!==`custom`&&ia[e]){let t=ia[e];return{preset:e,providerId:aa(e),baseUrl:t.baseUrl??``,api:t.api??`openai-completions`,apiKey:t.apiKey??``,modelIds:[``],error:null}}return{preset:`custom`,providerId:``,baseUrl:``,api:`openai-completions`,apiKey:``,modelIds:[``],error:null}}function fa(e,t){switch(t.type){case`applyPreset`:return t.key===`custom`?{...e,preset:`custom`,error:null}:ia[t.key]?{...da(t.key),modelIds:e.modelIds}:e;case`setProviderId`:return{...e,providerId:t.value};case`setBaseUrl`:return{...e,baseUrl:t.value};case`setApi`:return{...e,api:t.value};case`setApiKey`:return{...e,apiKey:t.value};case`addModelSlot`:return{...e,modelIds:[...e.modelIds,``]};case`updateModelId`:return{...e,modelIds:e.modelIds.map((e,n)=>n===t.index?t.value:e)};case`removeModelSlot`:return{...e,modelIds:e.modelIds.filter((e,n)=>n!==t.index)};case`setError`:return{...e,error:t.value}}}function pa({customConfig:e,labels:t,language:n,onBack:r,onSaved:i}){let[a,o]=(0,Z.useReducer)(fa,void 0,()=>da()),[c,l]=(0,Z.useState)(!1),u=Ae(s(n).providersSettings),{preset:d,providerId:f,baseUrl:p,api:m,apiKey:h,modelIds:g,error:_}=a,v=async()=>{let n=f.trim(),r=p.trim();if(!n){o({type:`setError`,value:t.providerIdRequired});return}if(!r){o({type:`setError`,value:t.baseUrlRequired});return}let a=g.map(e=>e.trim()).filter(Boolean);l(!0),o({type:`setError`,value:null});try{let t=e?.providers??{},o={baseUrl:r,api:m,apiKey:h.trim()||void 0,models:a.map(e=>({id:e}))};await Gi({providers:{...t,[n]:o}}),i()}catch(e){o({type:`setError`,value:e instanceof Error?e.message:t.saveError})}finally{l(!1)}},y=f.trim()&&p.trim();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:r,className:J(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),"aria-label":t.back,children:(0,$.jsx)(Nt,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(b,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:t.step2CustomTitle}),(0,$.jsx)(ca,{label:t.close})]}),(0,$.jsxs)(`div`,{className:`flex max-h-[60vh] flex-col gap-4 overflow-y-auto px-5 py-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.customDescription}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-preset`,className:`text-sm font-medium text-fg`,children:t.presetLabel}),(0,$.jsxs)(`select`,{id:`custom-preset`,value:d,onChange:e=>o({type:`applyPreset`,key:e.target.value}),className:oa(),children:[(0,$.jsx)(`option`,{value:`custom`,children:t.presetCustom}),(0,$.jsx)(`option`,{value:`ollama`,children:t.presetOllama}),(0,$.jsx)(`option`,{value:`lmstudio`,children:t.presetLmStudio}),(0,$.jsx)(`option`,{value:`openrouter`,children:t.presetOpenRouter}),(0,$.jsx)(`option`,{value:`zhipuCn`,children:t.presetZhipuCn}),(0,$.jsx)(`option`,{value:`zaiGeneral`,children:t.presetZaiGeneral})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-provider-id`,className:`text-sm font-medium text-fg`,children:t.providerIdLabel}),(0,$.jsx)(`input`,{id:`custom-provider-id`,type:`text`,autoComplete:`off`,autoFocus:!0,value:f,onChange:e=>o({type:`setProviderId`,value:e.target.value}),placeholder:t.providerIdPlaceholder,className:J(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,ht)})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-base-url`,className:`text-sm font-medium text-fg`,children:t.baseUrlLabel}),(0,$.jsx)(`input`,{id:`custom-base-url`,type:`url`,autoComplete:`off`,value:p,onChange:e=>o({type:`setBaseUrl`,value:e.target.value}),placeholder:t.baseUrlPlaceholder,className:J(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,ht)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-api-type`,className:`text-sm font-medium text-fg`,children:t.apiTypeLabel}),(0,$.jsx)(`select`,{id:`custom-api-type`,value:m,onChange:e=>o({type:`setApi`,value:e.target.value}),className:oa(),children:Vi.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-api-key`,className:`text-sm font-medium text-fg`,children:t.apiKeyLabel}),(0,$.jsx)(ft,{id:`custom-api-key`,value:h,onChange:e=>o({type:`setApiKey`,value:e}),placeholder:t.apiKeyPlaceholder,labels:u})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t.modelIdLabel}),g.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,autoComplete:`off`,value:e,onChange:e=>o({type:`updateModelId`,index:n,value:e.target.value}),placeholder:t.modelIdPlaceholder,className:J(`flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,ht)}),g.length>1?(0,$.jsx)(`button`,{type:`button`,onClick:()=>o({type:`removeModelSlot`,index:n}),className:J(`rounded-lg p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,K.press),children:(0,$.jsx)(vt,{className:`size-3.5`,"aria-hidden":!0})}):null]},n)),(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`w-fit gap-1.5 text-fg-muted`,onClick:()=>o({type:`addModelSlot`}),children:[(0,$.jsx)(dt,{className:`size-3.5`,"aria-hidden":!0}),t.addModel]})]}),_?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:_}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:r,children:t.cancel}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!y||c,onClick:()=>void v(),children:c?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(q,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),t.saving]}):t.save})]})]})}function ma(e){let t=(0,Q.c)(14),{providerId:n,inputId:r,value:i,onChange:a,labels:o}=e,s;t[0]===n?s=t[1]:(s=()=>he(n).then(ha),t[0]=n,t[1]=s);let c=s,l;t[2]!==r||t[3]!==o.apiKeyLabel?(l=(0,$.jsx)(`label`,{htmlFor:r,className:`text-sm font-medium text-fg`,children:o.apiKeyLabel}),t[2]=r,t[3]=o.apiKeyLabel,t[4]=l):l=t[4];let u;t[5]!==r||t[6]!==o||t[7]!==a||t[8]!==c||t[9]!==i?(u=(0,$.jsx)(ft,{id:r,value:i,onChange:a,placeholder:o.apiKeyPlaceholder,labels:o,reveal:c,loadFailedLabel:o.loadFailed,maskedHelp:o.maskedHelp,notInConfigFile:o.notInConfigFile}),t[5]=r,t[6]=o,t[7]=a,t[8]=c,t[9]=i,t[10]=u):u=t[10];let d;return t[11]!==l||t[12]!==u?(d=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[l,u]}),t[11]=l,t[12]=u,t[13]=d):d=t[13],d}function ha(e){return e.apiKey??null}function ga(e){let t=(0,Q.c)(16),{open:n,onOpenChange:r,providerId:i,isCustom:a,builtinRows:o,customConfig:s,allModels:c,labels:l,language:u,onSaved:d}=e,f;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(g,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Pe)}),t[0]=f):f=t[0];let p;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(p=J(`fixed left-1/2 top-1/2 flex max-h-[85vh] w-full max-w-lg -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge-subtle bg-surface-base shadow-xl`,Xt),t[1]=p):p=t[1];let m;t[2]!==c||t[3]!==o||t[4]!==s||t[5]!==a||t[6]!==l||t[7]!==u||t[8]!==r||t[9]!==d||t[10]!==i?(m=(0,$.jsxs)(h,{children:[f,(0,$.jsx)(_,{className:p,children:a?(0,$.jsx)(va,{providerId:i,customConfig:s,labels:l,onClose:()=>r(!1),onSaved:d}):(0,$.jsx)(_a,{providerId:i,builtinRows:o,allModels:c,labels:l,language:u,onClose:()=>r(!1),onSaved:d})})]}),t[2]=c,t[3]=o,t[4]=s,t[5]=a,t[6]=l,t[7]=u,t[8]=r,t[9]=d,t[10]=i,t[11]=m):m=t[11];let y;return t[12]!==r||t[13]!==n||t[14]!==m?(y=(0,$.jsx)(v,{open:n,onOpenChange:r,children:m}),t[12]=r,t[13]=n,t[14]=m,t[15]=y):y=t[15],y}function _a({providerId:e,builtinRows:t,allModels:n,labels:r,language:i,onClose:a,onSaved:o}){let s=t.find(t=>t.id===e),c=V[e],l=n.filter(t=>t.provider===e),[u,d]=(0,Z.useState)(s?.apiKey??``),[f,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(null),[y,S]=(0,Z.useState)(!1),C=(0,Z.useMemo)(()=>re(e,i),[e,i]),w=u!==(s?.apiKey??``),T=async()=>{let t=u.trim();if(!(!t||Se(t))){m(!0),v(null);try{await O({[e]:t}),g(!0),window.setTimeout(()=>{o(),a()},600)}catch(e){v(e instanceof Error?e.message:r.saveError)}finally{m(!1)}}},E=async()=>{try{await R(e),o(),a()}catch{}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(b,{className:`text-base font-semibold text-fg`,children:s?.name??e}),(0,$.jsx)(x,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),children:(0,$.jsx)(vt,{className:`size-4`,"aria-hidden":!0})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto px-5 py-4`,children:[c?.description?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:c.description}):null,s?.baseUrl?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r.apiUrlLabel}),(0,$.jsx)(`code`,{className:`break-all rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 font-mono text-xs text-fg-muted`,children:s.baseUrl})]}):s?.category===`extension`?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.apiUrlExtensionHint}):null,s?.supportsApiKey===!1?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`p`,{children:r.extensionKeyHint}),s?.extensionId?(0,$.jsxs)(_t,{to:`/settings/ext/${encodeURIComponent(s.extensionId)}`,className:`inline-flex w-fit items-center gap-1 font-medium text-accent hover:underline`,title:r.extensionSettingsLinkTitle,onClick:a,children:[r.openExtensionSettings,(0,$.jsx)(fe,{className:`size-3`,"aria-hidden":!0})]}):null]}):(0,$.jsx)(ma,{providerId:e,inputId:`manage-api-key`,value:u,onChange:e=>{d(e),g(!1)},labels:{apiKeyLabel:r.apiKeyLabel,apiKeyPlaceholder:r.apiKeyPlaceholder,maskedHelp:r.maskedHelp,copy:r.copy,copied:r.copied,show:r.showKey,hide:r.hideKey,notInConfigFile:r.notInConfigFile,loadFailed:r.loadFailed}}),C.length>0?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:C.map(({kind:e,href:t})=>(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[de(e,r),(0,$.jsx)(fe,{className:`size-3`,"aria-hidden":!0})]},e))}):null,l.length>0?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-medium text-fg`,children:[r.modelsLabel,` (`,l.length,`)`]}),(0,$.jsx)(`div`,{className:`max-h-40 overflow-y-auto rounded-lg border border-edge-subtle bg-surface-panel/40 p-2`,children:(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>(0,$.jsx)(`span`,{className:`inline-block rounded-md bg-surface-hover px-2 py-1 text-xs text-fg-muted`,children:e.id.includes(`/`)?e.id.split(`/`).pop():e.id},e.id))})})]}):(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.noModels}),_?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:_}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[s?.supportsApiKey===!1?(0,$.jsx)(`span`,{}):(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`gap-1.5 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,onClick:()=>S(!0),children:[(0,$.jsx)(Re,{className:`size-3.5`,"aria-hidden":!0}),r.remove]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:w&&!Se(u.trim())?(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!u.trim()||f||h,onClick:()=>void T(),children:h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(p,{className:`size-3.5`,"aria-hidden":!0}),r.saved]}):f?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(q,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),r.saving]}):r.save}):null})]}),(0,$.jsx)(Ht,{open:y,title:r.removeConfirmTitle,description:r.removeConfirmDescription.replace(`{{provider}}`,s?.name??e),confirmLabel:r.removeConfirmAction,cancelLabel:r.cancel,destructive:!0,onConfirm:()=>void E(),onCancel:()=>S(!1)})]})}function va({providerId:e,customConfig:t,labels:n,onClose:r,onSaved:i}){let a=t?.providers[e],[o,s]=(0,Z.useState)(a?.baseUrl??``),[c,l]=(0,Z.useState)(a?.apiKey??``),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),g=a?.models?.length??0,_=async()=>{if(t){d(!0),p(null);try{let n=c.trim(),s={...a,baseUrl:o.trim()||void 0,apiKey:Se(n)?a?.apiKey:n||void 0};await Gi({providers:{...t.providers,[e]:s}}),i(),r()}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}}},v=async()=>{if(t)try{let{[e]:n,...a}=t.providers;await Gi({providers:a}),i(),r()}catch{}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(b,{className:`text-base font-semibold text-fg`,children:e}),(0,$.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-subtle`,children:n.custom})]}),(0,$.jsx)(x,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:J(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),children:(0,$.jsx)(vt,{className:`size-4`,"aria-hidden":!0})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto px-5 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`manage-base-url`,className:`text-sm font-medium text-fg`,children:n.baseUrlLabel}),(0,$.jsx)(`input`,{id:`manage-base-url`,type:`url`,autoComplete:`off`,value:o,onChange:e=>s(e.target.value),className:J(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,ht)})]}),(0,$.jsx)(ma,{providerId:e,inputId:`manage-custom-api-key`,value:c,onChange:l,labels:{apiKeyLabel:n.apiKeyLabel,apiKeyPlaceholder:n.apiKeyPlaceholder,maskedHelp:n.maskedHelp,copy:n.copy,copied:n.copied,show:n.showKey,hide:n.hideKey,notInConfigFile:n.notInConfigFile,loadFailed:n.loadFailed}}),(0,$.jsx)(`div`,{className:`text-sm text-fg-muted`,children:g>0?n.modelsCount.replace(`{{count}}`,String(g)):n.noModels}),f?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`gap-1.5 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,onClick:()=>h(!0),children:[(0,$.jsx)(Re,{className:`size-3.5`,"aria-hidden":!0}),n.remove]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:u,onClick:()=>void _(),children:u?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(q,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})})]}),(0,$.jsx)(Ht,{open:m,title:n.removeConfirmTitle,description:n.removeConfirmDescription.replace(`{{provider}}`,e),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>void v(),onCancel:()=>h(!1)})]})}var ya=[`services`,`image-models`,`voice`,`search`];function ba(e){let t=(e??``).trim();return ya.includes(t)?t:`services`}function xa(){let e=(0,Q.c)(72),t=a(Ca),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n,i=r.modelsHub,[o,c]=Zt(),l;e[2]===o?l=e[3]:(l=ba(o.get(`tab`)),e[2]=o,e[3]=l);let u=l,[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(null),h=Ki(),g;e[4]!==i.servicesHint||e[5]!==i.tabs.services?(g={id:`services`,icon:Wt,label:i.tabs.services,hint:i.servicesHint},e[4]=i.servicesHint,e[5]=i.tabs.services,e[6]=g):g=e[6];let _;e[7]!==i.imageModelsHint||e[8]!==i.tabs.imageModels?(_={id:`image-models`,icon:z,label:i.tabs.imageModels,hint:i.imageModelsHint},e[7]=i.imageModelsHint,e[8]=i.tabs.imageModels,e[9]=_):_=e[9];let v;e[10]!==i.tabs.voice||e[11]!==i.voiceHint?(v={id:`voice`,icon:st,label:i.tabs.voice,hint:i.voiceHint},e[10]=i.tabs.voice,e[11]=i.voiceHint,e[12]=v):v=e[12];let y;e[13]!==i.searchHint||e[14]!==i.tabs.search?(y={id:`search`,icon:We,label:i.tabs.search,hint:i.searchHint},e[13]=i.searchHint,e[14]=i.tabs.search,e[15]=y):y=e[15];let b;e[16]!==g||e[17]!==_||e[18]!==v||e[19]!==y?(b=[g,_,v,y],e[16]=g,e[17]=_,e[18]=v,e[19]=y,e[20]=b):b=e[20];let x=b,S;e[21]===c?S=e[22]:(S=e=>{c(t=>{let n=new URLSearchParams(t);return e===`services`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},e[21]=c,e[22]=S);let C=S,w=Sa,T;e[23]===r.settingsSections.credentials?T=e[24]:(T=(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:r.settingsSections.credentials}),e[23]=r.settingsSections.credentials,e[24]=T);let E;e[25]===i.subtitle?E=e[26]:(E=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:i.subtitle}),e[25]=i.subtitle,e[26]=E);let D;e[27]===t?D=e[28]:(D=Rt(t,`configuration`),e[27]=t,e[28]=D);let O;e[29]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(fe,{className:`size-3.5`,"aria-hidden":!0}),e[29]=O):O=e[29];let k;e[30]!==i.docsLink||e[31]!==D?(k=(0,$.jsxs)(`a`,{href:D,target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[i.docsLink,O]}),e[30]=i.docsLink,e[31]=D,e[32]=k):k=e[32];let A;e[33]!==k||e[34]!==T||e[35]!==E?(A=(0,$.jsx)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[T,E,k]})}),e[33]=k,e[34]=T,e[35]=E,e[36]=A):A=e[36];let j;e[37]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(Pi,{}),e[37]=j):j=e[37];let M=i.tabsAria,N;e[38]!==u||e[39]!==C?(N=e=>{e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||(e.preventDefault(),C(ya[(ya.indexOf(u)+(e.key===`ArrowRight`?1:-1)+ya.length)%ya.length]))},e[38]=u,e[39]=C,e[40]=N):N=e[40];let P;e[41]!==u||e[42]!==C||e[43]!==x?(P=x.map(e=>{let{id:t,icon:n,label:r}=e,i=t===u;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":i,id:`hub-tab-${t}`,"aria-controls":`hub-panel-${t}`,className:J(`inline-flex shrink-0 items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.press,i?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>C(t),children:[(0,$.jsx)(n,{className:`size-3.5 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:r})]},t)}),e[41]=u,e[42]=C,e[43]=x,e[44]=P):P=e[44];let F;e[45]!==i.tabsAria||e[46]!==N||e[47]!==P?(F=(0,$.jsx)(`div`,{className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,role:`tablist`,"aria-label":M,onKeyDown:N,children:P}),e[45]=i.tabsAria,e[46]=N,e[47]=P,e[48]=F):F=e[48];let I;e[49]!==u||e[50]!==i.connectedProviders||e[51]!==x?(I=x.map(e=>(0,$.jsx)(Ta,{id:e.id,activeTab:u,hint:e.hint,children:e.id===`services`?(0,$.jsx)(Qi,{labels:i.connectedProviders,onAdd:()=>f(!0),onManage:(e,t)=>m({providerId:e,isCustom:t})}):(0,$.jsx)(wa,{tab:e.id})},e.id)),e[49]=u,e[50]=i.connectedProviders,e[51]=x,e[52]=I):I=e[52];let L;e[53]!==d||e[54]!==i.addProviderDialog||e[55]!==t||e[56]!==h.builtinRows||e[57]!==h.customConfig?(L=(0,$.jsx)(sa,{open:d,onOpenChange:f,builtinRows:h.builtinRows,customConfig:h.customConfig,labels:i.addProviderDialog,language:t,onSaved:w}),e[53]=d,e[54]=i.addProviderDialog,e[55]=t,e[56]=h.builtinRows,e[57]=h.customConfig,e[58]=L):L=e[58];let R;e[59]!==i.manageProviderDialog||e[60]!==t||e[61]!==p||e[62]!==h.allModels||e[63]!==h.builtinRows||e[64]!==h.customConfig?(R=p?(0,$.jsx)(ga,{open:!0,onOpenChange:e=>{e||m(null)},providerId:p.providerId,isCustom:p.isCustom,builtinRows:h.builtinRows,customConfig:h.customConfig,allModels:h.allModels,labels:i.manageProviderDialog,language:t,onSaved:w}):null,e[59]=i.manageProviderDialog,e[60]=t,e[61]=p,e[62]=h.allModels,e[63]=h.builtinRows,e[64]=h.customConfig,e[65]=R):R=e[65];let B;return e[66]!==A||e[67]!==F||e[68]!==I||e[69]!==L||e[70]!==R?(B=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[A,j,F,I,L,R]}),e[66]=A,e[67]=F,e[68]=I,e[69]=L,e[70]=R,e[71]=B):B=e[71],B}function Sa(){Ee()}function Ca(e){return e.language}function wa(e){let t=(0,Q.c)(3),{tab:n}=e;switch(n){case`services`:return null;case`image-models`:{let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Rr,{embedded:!0}),t[0]=e):e=t[0],e}case`voice`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(ci,{embedded:!0}),t[1]=e):e=t[1],e}case`search`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(ji,{embedded:!0}),t[2]=e):e=t[2],e}}}function Ta({id:e,activeTab:t,hint:n,children:r}){let i=e===t,a=(0,Z.useRef)(i);return i&&(a.current=!0),a.current?(0,$.jsxs)(`div`,{role:`tabpanel`,id:`hub-panel-${e}`,"aria-labelledby":`hub-tab-${e}`,hidden:!i,className:J(i?`flex min-w-0 flex-col gap-3`:void 0),children:[i?(0,$.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:n}):null,r]}):null}function Ea(){return J(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}var Da={default:{light:{canvas:`#f5f5f7`,panel:`#ffffff`,accent:`#2563eb`,fg:`#1d1d1f`,muted:`#d2d2d7`},dark:{canvas:`#1c1c1e`,panel:`#2c2c2e`,accent:`#3b82f6`,fg:`#f5f5f7`,muted:`#48484a`}},emerald:{light:{canvas:`#f0fdf4`,panel:`#ffffff`,accent:`#059669`,fg:`#052e16`,muted:`#86efac`},dark:{canvas:`#000000`,panel:`#0a0a0a`,accent:`#10b981`,fg:`#d1fae5`,muted:`#134e2a`}},mono:{light:{canvas:`#ffffff`,panel:`#f5f5f5`,accent:`#111111`,fg:`#111111`,muted:`#e5e7eb`},dark:{canvas:`#101010`,panel:`#1a1a1a`,accent:`#737373`,fg:`#fafafa`,muted:`#333333`}},clay:{light:{canvas:`#fffaf0`,panel:`#ffffff`,accent:`#1a3a3a`,fg:`#0a0a0a`,muted:`#e5e5e5`},dark:{canvas:`#0a1a1a`,panel:`#1a2a2a`,accent:`#ffb084`,fg:`#fffaf0`,muted:`#2a3a3a`}}};function Oa(e){let t=(0,Q.c)(24),{canvas:n,panel:r,accent:i,fg:a,muted:o}=e,s;t[0]===n?s=t[1]:(s={backgroundColor:n},t[0]=n,t[1]=s);let c;t[2]!==o||t[3]!==r?(c={backgroundColor:r,borderColor:o},t[2]=o,t[3]=r,t[4]=c):c=t[4];let l;t[5]===i?l=t[6]:(l=(0,$.jsx)(`div`,{className:`size-1 shrink-0 rounded-full`,style:{backgroundColor:i}}),t[5]=i,t[6]=l);let u;t[7]===a?u=t[8]:(u=(0,$.jsx)(`div`,{className:`h-1 min-w-0 flex-1 rounded-full`,style:{backgroundColor:a,opacity:.85}}),t[7]=a,t[8]=u);let d;t[9]!==l||t[10]!==u?(d=(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[l,u]}),t[9]=l,t[10]=u,t[11]=d):d=t[11];let f;t[12]===o?f=t[13]:(f=(0,$.jsx)(`div`,{className:`h-1 w-2/3 max-w-[70%] rounded-full`,style:{backgroundColor:o}}),t[12]=o,t[13]=f);let p;t[14]===o?p=t[15]:(p=(0,$.jsx)(`div`,{className:`size-1/2 max-w-[55%] rounded-full`,style:{backgroundColor:o}}),t[14]=o,t[15]=p);let m;t[16]!==c||t[17]!==d||t[18]!==f||t[19]!==p?(m=(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 rounded-sm border p-1`,style:c,children:[d,f,p]}),t[16]=c,t[17]=d,t[18]=f,t[19]=p,t[20]=m):m=t[20];let h;return t[21]!==s||t[22]!==m?(h=(0,$.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col justify-center gap-1 p-1.5`,style:s,children:m}),t[21]=s,t[22]=m,t[23]=h):h=t[23],h}function ka(e){let t=(0,Q.c)(8),{scheme:n}=e,{light:r,dark:i}=Da[n],a;t[0]===r?a=t[1]:(a=(0,$.jsx)(Oa,{...r}),t[0]=r,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(`div`,{className:`w-px shrink-0 bg-black/12 dark:bg-white/12`,"aria-hidden":!0}),t[2]=o):o=t[2];let s;t[3]===i?s=t[4]:(s=(0,$.jsx)(Oa,{...i}),t[3]=i,t[4]=s);let c;return t[5]!==a||t[6]!==s?(c=(0,$.jsxs)(`div`,{className:`flex h-11 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[a,o,s]}),t[5]=a,t[6]=s,t[7]=c):c=t[7],c}var Aa=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`},{value:`mono`,labelKey:`colorSchemeModernMono`},{value:`clay`,labelKey:`colorSchemeClay`}];function ja(){let e=(0,Q.c)(18),t=a(Pa),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.appearanceSettings,i=S(Na),o=S(Ma),c;e[2]===r.colorSchemeTitle?c=e[3]:(c=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:r.colorSchemeTitle}),e[2]=r.colorSchemeTitle,e[3]=c);let l;e[4]===r.colorSchemeDescription?l=e[5]:(l=(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:r.colorSchemeDescription}),e[4]=r.colorSchemeDescription,e[5]=l);let u;e[6]!==c||e[7]!==l?(u=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[c,l]}),e[6]=c,e[7]=l,e[8]=u):u=e[8];let d;e[9]!==r||e[10]!==i||e[11]!==o?(d=Aa.map(e=>{let{value:t,labelKey:n}=e,a=i===t;return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>o(t),className:J(`flex flex-col gap-2 rounded-xl border-2 p-2.5 text-left transition-[border-color,box-shadow,transform] duration-150`,K.pressCard,a?`border-accent shadow-[0_0_0_1px_var(--color-accent)]`:`border-edge-subtle hover:border-edge`),children:[(0,$.jsx)(ka,{scheme:t}),(0,$.jsx)(`span`,{className:J(`text-xs font-medium leading-none`,a?`text-accent-fg`:`text-fg-muted`),children:r[n]})]},t)}),e[9]=r,e[10]=i,e[11]=o,e[12]=d):d=e[12];let f;e[13]===d?f=e[14]:(f=(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:d}),e[13]=d,e[14]=f);let p;return e[15]!==u||e[16]!==f?(p=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-edge-subtle py-3.5 last:border-b-0 sm:py-4`,children:[u,f]}),e[15]=u,e[16]=f,e[17]=p):p=e[17],p}function Ma(e){return e.setColorScheme}function Na(e){return e.colorScheme}function Pa(e){return e.language}function Fa(){let e=(0,Q.c)(27),t=a(Ra),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.appearanceSettings,i=Ot(La),o=Ot(Ia),c;e[2]===r.developerGroupTitle?c=e[3]:(c=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:r.developerGroupTitle}),e[2]=r.developerGroupTitle,e[3]=c);let l;e[4]===r.developerGroupDescription?l=e[5]:(l=(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:r.developerGroupDescription}),e[4]=r.developerGroupDescription,e[5]=l);let u;e[6]!==c||e[7]!==l?(u=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[c,l]}),e[6]=c,e[7]=l,e[8]=u):u=e[8];let d;e[9]===r.showRawToolDataTitle?d=e[10]:(d=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:r.showRawToolDataTitle}),e[9]=r.showRawToolDataTitle,e[10]=d);let f;e[11]===r.showRawToolDataDescription?f=e[12]:(f=(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r.showRawToolDataDescription}),e[11]=r.showRawToolDataDescription,e[12]=f);let p;e[13]!==d||e[14]!==f?(p=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[d,f]}),e[13]=d,e[14]=f,e[15]=p):p=e[15];let m;e[16]===o?m=e[17]:(m=e=>o(e.target.checked),e[16]=o,e[17]=m);let h;e[18]!==i||e[19]!==m?(h=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i,onChange:m}),e[18]=i,e[19]=m,e[20]=h):h=e[20];let g;e[21]!==p||e[22]!==h?(g=(0,$.jsxs)(`label`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[p,h]}),e[21]=p,e[22]=h,e[23]=g):g=e[23];let _;return e[24]!==u||e[25]!==g?(_=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 py-3.5 sm:py-4`,children:[u,g]}),e[24]=u,e[25]=g,e[26]=_):_=e[26],_}function Ia(e){return e.setShowRawToolData}function La(e){return e.showRawToolData}function Ra(e){return e.language}function za(){let e=(0,Q.c)(33),t=a(Ba),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.appearanceSettings,i;e[2]===r.pageTitle?i=e[3]:(i=(0,$.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:r.pageTitle}),e[2]=r.pageTitle,e[3]=i);let o;e[4]===r.subtitle?o=e[5]:(o=(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.subtitle}),e[4]=r.subtitle,e[5]=o);let c;e[6]!==i||e[7]!==o?(c=(0,$.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[i,o]}),e[6]=i,e[7]=o,e[8]=c):c=e[8];let l;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=Ea(),e[9]=l):l=e[9];let u;e[10]===r.languageTitle?u=e[11]:(u=(0,$.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:r.languageTitle}),e[10]=r.languageTitle,e[11]=u);let d;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(qe,{variant:`page`,sections:[`language`]}),e[12]=d):d=e[12];let f;e[13]===u?f=e[14]:(f=(0,$.jsxs)(`section`,{className:l,"aria-labelledby":`pref-language-heading`,children:[u,d]}),e[13]=u,e[14]=f);let p;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(p=Ea(),e[15]=p):p=e[15];let m;e[16]===r.themeTitle?m=e[17]:(m=(0,$.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:r.themeTitle}),e[16]=r.themeTitle,e[17]=m);let h,g;e[18]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(qe,{variant:`page`,sections:[`theme`,`font`]}),g=(0,$.jsx)(ja,{}),e[18]=h,e[19]=g):(h=e[18],g=e[19]);let _;e[20]===m?_=e[21]:(_=(0,$.jsxs)(`section`,{className:p,"aria-labelledby":`pref-appearance-heading`,children:[m,h,g]}),e[20]=m,e[21]=_);let v;e[22]===Symbol.for(`react.memo_cache_sentinel`)?(v=Ea(),e[22]=v):v=e[22];let y;e[23]===r.developerGroupTitle?y=e[24]:(y=(0,$.jsx)(`h2`,{id:`pref-developer-heading`,className:`sr-only`,children:r.developerGroupTitle}),e[23]=r.developerGroupTitle,e[24]=y);let b;e[25]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(Fa,{}),e[25]=b):b=e[25];let x;e[26]===y?x=e[27]:(x=(0,$.jsxs)(`section`,{className:v,"aria-labelledby":`pref-developer-heading`,children:[y,b]}),e[26]=y,e[27]=x);let S;return e[28]!==_||e[29]!==x||e[30]!==c||e[31]!==f?(S=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[c,f,_,x]}),e[28]=_,e[29]=x,e[30]=c,e[31]=f,e[32]=S):S=e[32],S}function Ba(e){return e.language}function Va(){return l(`/api/dreaming`)}async function Ha(){let e=await w(Va());if(!e.payload)throw Error(`Missing payload`);return e.payload}async function Ua(e){await w(l(`/api/dreaming/action`),{method:`POST`,body:JSON.stringify({action:e})})}async function Wa(e=`deep`){let t=await w(l(`/api/dreaming/run`),{method:`POST`,body:JSON.stringify({phase:e})}),n=!!t.payload?.triggered,r=typeof t.payload?.jobId==`string`?t.payload.jobId:``;if(!n||!r)throw Error(`Failed to trigger`);return{triggered:n,jobId:r,phase:e}}async function Ga(e){let t=await w(l(`/api/dreaming/preview${typeof e==`number`&&Number.isFinite(e)?`?limit=${encodeURIComponent(String(e))}`:``}`));if(!t.payload)throw Error(`Missing payload`);return t.payload}async function Ka(e=50){return(await w(l(`/api/dreaming/events${`?limit=${encodeURIComponent(String(e))}`}`))).payload?.events??[]}function qa(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Ja={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},Ya={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},Xa={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},Za={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:Ja,deep:Ya,rem:Xa};function Qa(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function $a(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function eo(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function to(e){let t=qa(e)?e:{},n=qa(t.agents)?t.agents:{},r=qa(n.defaults)?n.defaults:{},i=qa(r.memory)?r.memory:{},a=qa(i.dreaming)?i.dreaming:{},o=qa(a.phases)?a.phases:{},s=qa(o.light)?o.light:{},c=qa(o.deep)?o.deep:{},l=qa(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():Za.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:Qa(typeof c.minScore==`number`?c.minScore:Number(c.minScore),Za.minScore),minRecallCount:Math.max(1,$a(c.minRecallCount,Za.minRecallCount)),limit:$a(c.limit,Za.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():Ja.cron,lookbackDays:Math.max(1,$a(s.lookbackDays,Ja.lookbackDays)),limit:$a(s.limit,Ja.limit),dedupeSimilarity:Qa(eo(s.dedupeSimilarity,Ja.dedupeSimilarity),Ja.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():Ya.cron,minScore:Qa(eo(c.minScore,Ya.minScore),Ya.minScore),minRecallCount:Math.max(1,$a(c.minRecallCount,Ya.minRecallCount)),limit:$a(c.limit,Ya.limit),recencyHalfLifeDays:Math.max(1,eo(c.recencyHalfLifeDays,Ya.recencyHalfLifeDays)),maxAgeDays:Math.max(1,eo(c.maxAgeDays,Ya.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():Xa.cron,lookbackDays:Math.max(1,$a(l.lookbackDays,Xa.lookbackDays)),limit:$a(l.limit,Xa.limit),minPatternStrength:Qa(eo(l.minPatternStrength,Xa.minPatternStrength),Xa.minPatternStrength)}}}async function no(e){let t=e.frequency.trim(),n=e.timezone.trim();await w(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({agents:{defaults:{memory:{dreaming:{enabled:!!e.enabled,frequency:t||null,timezone:n||null,phases:{light:{enabled:!!e.light.enabled,cron:e.light.cron.trim()||null,lookbackDays:Math.max(1,Math.floor(e.light.lookbackDays)),limit:Math.max(0,Math.floor(e.light.limit)),dedupeSimilarity:Qa(e.light.dedupeSimilarity,Ja.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:Qa(e.deep.minScore,Ya.minScore),minRecallCount:Math.max(1,Math.floor(e.deep.minRecallCount)),limit:Math.max(0,Math.floor(e.deep.limit)),recencyHalfLifeDays:Math.max(1,e.deep.recencyHalfLifeDays),maxAgeDays:Math.max(1,e.deep.maxAgeDays)},rem:{enabled:!!e.rem.enabled,cron:e.rem.cron.trim()||null,lookbackDays:Math.max(1,Math.floor(e.rem.lookbackDays)),limit:Math.max(0,Math.floor(e.rem.limit)),minPatternStrength:Qa(e.rem.minPatternStrength,Xa.minPatternStrength)}}}}}}})}),Qt()}var ro=`p-4 sm:px-5`,io=`mb-3`,ao=`rounded-xl border border-edge-subtle bg-surface-panel/30 p-3 sm:p-4`,oo=J(`mt-1 w-full rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm text-fg`,at);function so(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function co(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function lo(e,t){return e.locked?{text:t.lockValueLocked,className:`text-amber-600 dark:text-amber-400`}:{text:t.lockValueUnlocked,className:`text-emerald-600 dark:text-emerald-400`}}var uo=J(`h-9 min-w-0 flex-1 rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm tabular-nums text-fg`,at),fo=J(ct,`h-9 max-w-[11rem] shrink-0 text-xs sm:max-w-[12rem]`);function po(e,t){switch(e){case 3e4:return t.every30s;case 6e4:return t.every1min;case 3e5:return t.every5min;case 6e5:return t.every10min;case 9e5:return t.every15min;case 18e5:return t.every30min;case 36e5:return t.every1h;case 72e5:return t.every2h;default:return String(e)}}function mo({valueMs:e,onChangeMs:t,labels:n,disabled:r,presets:i=Sn,minSeconds:a=1}){let o=(0,Z.useMemo)(()=>new Set(i),[i]),s=(0,Z.useMemo)(()=>o.has(e)?String(e):``,[o,e]),[c,l]=(0,Z.useState)(null),u=(0,Z.useRef)(e);u.current!==e&&(u.current=e,l(null));let d=Math.max(a,Math.round(e/1e3)),f=c===null?String(d):c;return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n.secondsLabel}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`input`,{type:`number`,min:a,step:1,disabled:r,className:uo,value:f,onChange:e=>{let n=e.target.value;l(n);let r=parseInt(n,10);Number.isFinite(r)&&r>=a&&t(r*1e3)},onBlur:()=>{if(c===null)return;let e=parseInt(c,10);t(!Number.isFinite(e)||e<a?a*1e3:e*1e3),l(null)}}),(0,$.jsxs)(`select`,{className:fo,disabled:r,value:s,onChange:e=>{let n=e.target.value;n&&(t(parseInt(n,10)),l(null))},children:[(0,$.jsx)(`option`,{value:``,children:n.presets.custom}),i.map(e=>(0,$.jsx)(`option`,{value:String(e),children:po(e,n.presets)},e))]})]})]})}var ho=J(`mt-1 w-full rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm text-fg`,at),go=()=>({start:`09:00`,end:`22:00`,timezone:``});function _o(e){let t=(0,Q.c)(55),{value:n,onChange:r,labels:i,disabled:a}=e;if(!n){let e;t[0]===r?e=t[1]:(e=()=>r(go()),t[0]=r,t[1]=e);let n;return t[2]!==a||t[3]!==i.add||t[4]!==e?(n=(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`text-sm`,disabled:a,onClick:e,children:i.add}),t[2]=a,t[3]=i.add,t[4]=e,t[5]=n):n=t[5],n}let o;t[6]===i.start?o=t[7]:(o=(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:i.start}),t[6]=i.start,t[7]=o);let s;t[8]!==r||t[9]!==n?(s=e=>r({...n,start:e.target.value}),t[8]=r,t[9]=n,t[10]=s):s=t[10];let c;t[11]!==a||t[12]!==s||t[13]!==n.start?(c=(0,$.jsx)(`input`,{type:`time`,step:60,disabled:a,className:ho,value:n.start,onChange:s}),t[11]=a,t[12]=s,t[13]=n.start,t[14]=c):c=t[14];let l;t[15]!==o||t[16]!==c?(l=(0,$.jsxs)(`label`,{className:`block min-w-0`,children:[o,c]}),t[15]=o,t[16]=c,t[17]=l):l=t[17];let u;t[18]===i.end?u=t[19]:(u=(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:i.end}),t[18]=i.end,t[19]=u);let d;t[20]!==r||t[21]!==n?(d=e=>r({...n,end:e.target.value}),t[20]=r,t[21]=n,t[22]=d):d=t[22];let f;t[23]!==a||t[24]!==d||t[25]!==n.end?(f=(0,$.jsx)(`input`,{type:`time`,step:60,disabled:a,className:ho,value:n.end,onChange:d}),t[23]=a,t[24]=d,t[25]=n.end,t[26]=f):f=t[26];let p;t[27]!==u||t[28]!==f?(p=(0,$.jsxs)(`label`,{className:`block min-w-0`,children:[u,f]}),t[27]=u,t[28]=f,t[29]=p):p=t[29];let m;t[30]===i.timezone?m=t[31]:(m=(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:i.timezone}),t[30]=i.timezone,t[31]=m);let h;t[32]!==r||t[33]!==n?(h=e=>r({...n,timezone:e.target.value}),t[32]=r,t[33]=n,t[34]=h):h=t[34];let g;t[35]!==a||t[36]!==h||t[37]!==n.timezone?(g=(0,$.jsx)(`input`,{type:`text`,disabled:a,className:ho,value:n.timezone,onChange:h,placeholder:`Asia/Shanghai`,autoComplete:`off`}),t[35]=a,t[36]=h,t[37]=n.timezone,t[38]=g):g=t[38];let _;t[39]!==g||t[40]!==m?(_=(0,$.jsxs)(`label`,{className:`block min-w-0`,children:[m,g]}),t[39]=g,t[40]=m,t[41]=_):_=t[41];let v;t[42]!==_||t[43]!==l||t[44]!==p?(v=(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[l,p,_]}),t[42]=_,t[43]=l,t[44]=p,t[45]=v):v=t[45];let y;t[46]===r?y=t[47]:(y=()=>r(null),t[46]=r,t[47]=y);let b;t[48]!==a||t[49]!==i.clear||t[50]!==y?(b=(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`text-xs`,disabled:a,onClick:y,children:i.clear}),t[48]=a,t[49]=i.clear,t[50]=y,t[51]=b):b=t[51];let x;return t[52]!==v||t[53]!==b?(x=(0,$.jsxs)(`div`,{className:`space-y-2`,children:[v,b]}),t[52]=v,t[53]=b,t[54]=x):x=t[54],x}function vo(e){let t=(0,Q.c)(34),{disabled:n,label:r,hint:i,className:a}=e,o;t[0]===a?o=t[1]:(o=J(`flex flex-col gap-2`,a),t[0]=a,t[1]=o);let s;t[2]===r?s=t[3]:(s=r?(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:r}):null,t[2]=r,t[3]=s);let c;t[4]!==n||t[5]!==r||t[6]!==e.kind||t[7]!==e.labels||t[8]!==e.onChange||t[9]!==e.value?(c=e.kind===`cron`?(0,$.jsx)(Kn,{value:e.value,onChange:e.onChange,labels:e.labels,disabled:n,showHeading:!r}):null,t[4]=n,t[5]=r,t[6]=e.kind,t[7]=e.labels,t[8]=e.onChange,t[9]=e.value,t[10]=c):c=t[10];let l;t[11]!==n||t[12]!==e.kind||t[13]!==e.labels||t[14]!==e.minSeconds||t[15]!==e.onChangeMs||t[16]!==e.presets||t[17]!==e.valueMs?(l=e.kind===`interval`?(0,$.jsx)(mo,{valueMs:e.valueMs,onChangeMs:e.onChangeMs,labels:e.labels,disabled:n,presets:e.presets??Sn,minSeconds:e.minSeconds}):null,t[11]=n,t[12]=e.kind,t[13]=e.labels,t[14]=e.minSeconds,t[15]=e.onChangeMs,t[16]=e.presets,t[17]=e.valueMs,t[18]=l):l=t[18];let u;t[19]!==n||t[20]!==e.kind||t[21]!==e.labels||t[22]!==e.onChange||t[23]!==e.value?(u=e.kind===`active-hours`?(0,$.jsx)(_o,{value:e.value,onChange:e.onChange,labels:e.labels,disabled:n}):null,t[19]=n,t[20]=e.kind,t[21]=e.labels,t[22]=e.onChange,t[23]=e.value,t[24]=u):u=t[24];let d;t[25]===i?d=t[26]:(d=i?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:i}):null,t[25]=i,t[26]=d);let f;return t[27]!==o||t[28]!==s||t[29]!==c||t[30]!==l||t[31]!==u||t[32]!==d?(f=(0,$.jsxs)(`div`,{className:o,children:[s,c,l,u,d]}),t[27]=o,t[28]=s,t[29]=c,t[30]=l,t[31]=u,t[32]=d,t[33]=f):f=t[33],f}var yo=`text-xs font-medium text-fg-muted`,bo=`text-sm font-medium text-fg`;function xo(e){let t=(0,Q.c)(6),{label:n,children:r,className:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`span`,{className:yo,children:n}),t[0]=n,t[1]=a);let o;return t[2]!==r||t[3]!==i||t[4]!==a?(o=(0,$.jsxs)(`div`,{className:i,children:[a,r]}),t[2]=r,t[3]=i,t[4]=a,t[5]=o):o=t[5],o}function So(e){let t=(0,Q.c)(11),{label:n,children:r,className:i}=e,a;t[0]===i?a=t[1]:(a=J(`min-w-0`,i),t[0]=i,t[1]=a);let o;t[2]===n?o=t[3]:(o=(0,$.jsx)(`dt`,{className:yo,children:n}),t[2]=n,t[3]=o);let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=J(bo,`mt-0.5`),t[4]=s):s=t[4];let c;t[5]===r?c=t[6]:(c=(0,$.jsx)(`dd`,{className:s,children:r}),t[5]=r,t[6]=c);let l;return t[7]!==a||t[8]!==o||t[9]!==c?(l=(0,$.jsxs)(`div`,{className:a,children:[o,c]}),t[7]=a,t[8]=o,t[9]=c,t[10]=l):l=t[10],l}function Co(e){let t=(0,Q.c)(5),{label:n,className:r}=e,i;t[0]===r?i=t[1]:(i=J(`text-[0.7rem] font-semibold uppercase tracking-wider text-fg-muted`,r),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,$.jsx)(`h3`,{className:i,children:n}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a}function wo(e){let t=(0,Q.c)(38),{icon:n,title:r,hint:i,enabled:a,onEnabledChange:o,cron:s,onCronChange:c,scheduleLabels:l,disabled:u,onLabel:d,offLabel:f,cronLabel:p,children:m}=e,h;t[0]===n?h=t[1]:(h=(0,$.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:n}),t[0]=n,t[1]=h);let g;t[2]===r?g=t[3]:(g=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:r}),t[2]=r,t[3]=g);let _;t[4]===i?_=t[5]:(_=(0,$.jsx)(`p`,{className:`mt-0.5 text-xs leading-snug text-fg-muted`,children:i}),t[4]=i,t[5]=_);let v;t[6]!==g||t[7]!==_?(v=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[g,_]}),t[6]=g,t[7]=_,t[8]=v):v=t[8];let y;t[9]!==h||t[10]!==v?(y=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[h,v]}),t[9]=h,t[10]=v,t[11]=y):y=t[11];let b;t[12]===o?b=t[13]:(b=e=>o(e.target.checked),t[12]=o,t[13]=b);let x;t[14]!==u||t[15]!==a||t[16]!==b?(x=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:a,disabled:u,onChange:b}),t[14]=u,t[15]=a,t[16]=b,t[17]=x):x=t[17];let S=a?d:f,C;t[18]===S?C=t[19]:(C=(0,$.jsx)(`span`,{children:S}),t[18]=S,t[19]=C);let w;t[20]!==x||t[21]!==C?(w=(0,$.jsxs)(`label`,{className:`inline-flex shrink-0 items-center gap-2 text-xs text-fg`,children:[x,C]}),t[20]=x,t[21]=C,t[22]=w):w=t[22];let T;t[23]!==w||t[24]!==y?(T=(0,$.jsxs)(`div`,{className:`mb-2.5 flex flex-wrap items-start justify-between gap-2 border-b border-edge-subtle/80 pb-2.5`,children:[y,w]}),t[23]=w,t[24]=y,t[25]=T):T=t[25];let E;t[26]!==s||t[27]!==p||t[28]!==u||t[29]!==c||t[30]!==l?(E=(0,$.jsx)(vo,{kind:`cron`,className:`mb-2.5`,label:p,value:s,onChange:c,labels:l,disabled:u}),t[26]=s,t[27]=p,t[28]=u,t[29]=c,t[30]=l,t[31]=E):E=t[31];let D;t[32]===m?D=t[33]:(D=(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-4`,children:m}),t[32]=m,t[33]=D);let O;return t[34]!==T||t[35]!==E||t[36]!==D?(O=(0,$.jsxs)(`div`,{className:ao,children:[T,E,D]}),t[34]=T,t[35]=E,t[36]=D,t[37]=O):O=t[37],O}function To(e){let t=(0,Q.c)(23),{icon:n,label:r,enabled:i,cron:a,scheduleSummary:o,details:s,t:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=J(ao,`space-y-1`),t[0]=l):l=t[0];let u;t[1]===r?u=t[2]:(u=(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r}),t[1]=r,t[2]=u);let d=i?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`,f;t[3]===d?f=t[4]:(f=J(`ml-auto text-xs font-medium`,d),t[3]=d,t[4]=f);let p=i?c.on:c.off,m;t[5]!==f||t[6]!==p?(m=(0,$.jsx)(`span`,{className:f,children:p}),t[5]=f,t[6]=p,t[7]=m):m=t[7];let h;t[8]!==n||t[9]!==u||t[10]!==m?(h=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,u,m]}),t[8]=n,t[9]=u,t[10]=m,t[11]=h):h=t[11];let g;t[12]===o?g=t[13]:(g=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:o}),t[12]=o,t[13]=g);let _;t[14]===a?_=t[15]:(_=(0,$.jsx)(`p`,{className:`truncate font-mono text-[0.65rem] text-fg-subtle`,title:a,children:a}),t[14]=a,t[15]=_);let v;t[16]===s?v=t[17]:(v=(0,$.jsx)(`p`,{className:`text-[0.65rem] leading-snug text-fg-muted`,children:s}),t[16]=s,t[17]=v);let y;return t[18]!==v||t[19]!==h||t[20]!==g||t[21]!==_?(y=(0,$.jsxs)(`div`,{className:l,children:[h,g,_,v]}),t[18]=v,t[19]=h,t[20]=g,t[21]=_,t[22]=y):y=t[22],y}function Eo(e){let t=(0,Q.c)(9),{label:n,lastRun:r,t:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(Co,{label:n,className:`mb-2`}),t[0]=n,t[1]=a);let o;t[2]!==r||t[3]!==i.lastRunRaw||t[4]!==i.phaseLastRunEmpty?(o=r?.exists?(0,$.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,$.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:i.lastRunRaw})}),(0,$.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(r.raw,null,2)})]}):(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.phaseLastRunEmpty}),t[2]=r,t[3]=i.lastRunRaw,t[4]=i.phaseLastRunEmpty,t[5]=o):o=t[5];let s;return t[6]!==a||t[7]!==o?(s=(0,$.jsxs)(`div`,{className:`border-t border-edge-subtle/80 pt-3`,children:[a,o]}),t[6]=a,t[7]=o,t[8]=s):s=t[8],s}function Do(e){let t=(0,Q.c)(39),{t:n,r}=e,i=r.deep?.skipped,a=r.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`,o=r.ok?n.lastRunSuccess:n.lastRunFailure,s;t[0]!==a||t[1]!==o?(s=(0,$.jsx)(`span`,{className:a,children:o}),t[0]=a,t[1]=o,t[2]=s):s=t[2];let c;t[3]!==n.lastRunStatus||t[4]!==s?(c=(0,$.jsx)(So,{label:n.lastRunStatus,children:s}),t[3]=n.lastRunStatus,t[4]=s,t[5]=c):c=t[5];let l=n.lastRunDuration,u;t[6]===r.durationMs?u=t[7]:(u=co(r.durationMs),t[6]=r.durationMs,t[7]=u);let d;t[8]!==n.lastRunDuration||t[9]!==u?(d=(0,$.jsx)(So,{label:l,children:u}),t[8]=n.lastRunDuration,t[9]=u,t[10]=d):d=t[10];let f=n.lastRunRanked,p=String(r.deep?.candidatesRanked??`—`),m;t[11]!==n.lastRunRanked||t[12]!==p?(m=(0,$.jsx)(So,{label:f,children:p}),t[11]=n.lastRunRanked,t[12]=p,t[13]=m):m=t[13];let h=n.lastRunApplied,g=String(r.deep?.applied??`—`),_;t[14]!==n.lastRunApplied||t[15]!==g?(_=(0,$.jsx)(So,{label:h,children:g}),t[14]=n.lastRunApplied,t[15]=g,t[16]=_):_=t[16];let v;t[17]===r.reason?v=t[18]:(v=(0,$.jsx)(`span`,{className:`block text-pretty`,children:r.reason}),t[17]=r.reason,t[18]=v);let y;t[19]!==r.errorMessage||t[20]!==n.lastRunError?(y=r.errorMessage?(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-amber-600 dark:text-amber-400`,children:`${n.lastRunError}: ${r.errorMessage}`}):null,t[19]=r.errorMessage,t[20]=n.lastRunError,t[21]=y):y=t[21];let b;t[22]!==n.lastRunReason||t[23]!==v||t[24]!==y?(b=(0,$.jsxs)(So,{label:n.lastRunReason,className:`col-span-2 sm:col-span-3 lg:col-span-4`,children:[v,y]}),t[22]=n.lastRunReason,t[23]=v,t[24]=y,t[25]=b):b=t[25];let x;t[26]!==i||t[27]!==n.lastRunSkipContaminated||t[28]!==n.lastRunSkipHash||t[29]!==n.lastRunSkipKey||t[30]!==n.lastRunSkipRehydrate?(x=i?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(So,{label:n.lastRunSkipKey,children:String(i.alreadyPromotedKey)}),(0,$.jsx)(So,{label:n.lastRunSkipRehydrate,children:String(i.rehydrateFailed)}),(0,$.jsx)(So,{label:n.lastRunSkipContaminated,children:String(i.contaminated)}),(0,$.jsx)(So,{label:n.lastRunSkipHash,children:String(i.hashDuplicate)})]}):null,t[26]=i,t[27]=n.lastRunSkipContaminated,t[28]=n.lastRunSkipHash,t[29]=n.lastRunSkipKey,t[30]=n.lastRunSkipRehydrate,t[31]=x):x=t[31];let S;return t[32]!==m||t[33]!==_||t[34]!==b||t[35]!==x||t[36]!==c||t[37]!==d?(S=(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-3 lg:grid-cols-4`,children:[c,d,m,_,b,x]}),t[32]=m,t[33]=_,t[34]=b,t[35]=x,t[36]=c,t[37]=d,t[38]=S):S=t[38],S}function Oo(e){let t=(0,Q.c)(58),{t:n,schedulePickerLabels:r,hasToken:i,cfgForm:a,cfgBaseline:o,cfgSaving:s,cfgDirty:c,setCfgForm:l,setCfgOk:u,setCfgError:d,saveConfig:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=J(`min-w-0`,ro),t[0]=p):p=t[0];let m=!i||!a||s||!c,h;t[1]===f?h=t[2]:(h=()=>void f(),t[1]=f,t[2]=h);let g;t[3]===s?g=t[4]:(g=s?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,t[3]=s,t[4]=g);let _;t[5]!==n.saveConfig||t[6]!==m||t[7]!==h||t[8]!==g?(_=(0,$.jsxs)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:m,onClick:h,children:[g,n.saveConfig]}),t[5]=n.saveConfig,t[6]=m,t[7]=h,t[8]=g,t[9]=_):_=t[9];let v=!i||!a||s||!c,y;t[10]!==o||t[11]!==d||t[12]!==l||t[13]!==u?(y=()=>{u(!1),d(null),l(o)},t[10]=o,t[11]=d,t[12]=l,t[13]=u,t[14]=y):y=t[14];let b;t[15]!==n.resetConfig||t[16]!==v||t[17]!==y?(b=(0,$.jsx)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:v,onClick:y,children:n.resetConfig}),t[15]=n.resetConfig,t[16]=v,t[17]=y,t[18]=b):b=t[18];let x;t[19]!==_||t[20]!==b?(x=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[_,b]}),t[19]=_,t[20]=b,t[21]=x):x=t[21];let S;t[22]!==n.configHint||t[23]!==n.configTitle||t[24]!==x?(S=(0,$.jsx)(vn,{className:io,icon:G,title:n.configTitle,subtitle:n.configHint,trailing:x}),t[22]=n.configHint,t[23]=n.configTitle,t[24]=x,t[25]=S):S=t[25];let C;t[26]!==a||t[27]!==s||t[28]!==i||t[29]!==r||t[30]!==l||t[31]!==n.configDeepHalfLife||t[32]!==n.configDeepLimit||t[33]!==n.configDeepMaxAge||t[34]!==n.configDeepMinRecallCount||t[35]!==n.configDeepMinScore||t[36]!==n.configFrequency||t[37]!==n.configLightDedupe||t[38]!==n.configLightLimit||t[39]!==n.configLightLookbackDays||t[40]!==n.configLoading||t[41]!==n.configPhaseCron||t[42]!==n.configPhaseDeep||t[43]!==n.configPhaseDeepHint||t[44]!==n.configPhaseLight||t[45]!==n.configPhaseLightHint||t[46]!==n.configPhaseRem||t[47]!==n.configPhaseRemHint||t[48]!==n.configRemLimit||t[49]!==n.configRemLookbackDays||t[50]!==n.configRemMinStrength||t[51]!==n.configTimezone||t[52]!==n.off||t[53]!==n.on?(C=a?(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(`div`,{className:ao,children:(0,$.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 lg:grid-cols-12`,children:[(0,$.jsx)(`div`,{className:`lg:col-span-9`,children:(0,$.jsx)(vo,{kind:`cron`,label:n.configFrequency,value:a.frequency,onChange:e=>l(t=>t&&{...t,frequency:e}),labels:r,disabled:!i||s})}),(0,$.jsx)(xo,{label:n.configTimezone,className:`lg:col-span-3`,children:(0,$.jsx)(`input`,{className:oo,value:a.timezone,disabled:!i||s,onChange:e=>l(t=>t&&{...t,timezone:e.target.value}),placeholder:`Asia/Shanghai`})})]})}),(0,$.jsxs)(wo,{icon:(0,$.jsx)(Et,{className:`size-4 text-amber-500`}),title:n.configPhaseLight,hint:n.configPhaseLightHint,enabled:a.light.enabled,onEnabledChange:e=>l(t=>t&&{...t,light:{...t.light,enabled:e}}),cron:a.light.cron,onCronChange:e=>l(t=>t&&{...t,light:{...t.light,cron:e}}),scheduleLabels:r,disabled:!i||s,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,$.jsx)(xo,{label:n.configLightLookbackDays,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:1,className:oo,value:a.light.lookbackDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,light:{...t.light,lookbackDays:Number(e.target.value)}})})}),(0,$.jsx)(xo,{label:n.configLightLimit,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:0,className:oo,value:a.light.limit,disabled:!i||s,onChange:e=>l(t=>t&&{...t,light:{...t.light,limit:Number(e.target.value)}})})}),(0,$.jsx)(xo,{label:n.configLightDedupe,children:(0,$.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:oo,value:a.light.dedupeSimilarity,disabled:!i||s,onChange:e=>l(t=>t&&{...t,light:{...t.light,dedupeSimilarity:Number(e.target.value)}})})})]}),(0,$.jsxs)(wo,{icon:(0,$.jsx)(At,{className:`size-4 text-indigo-500`}),title:n.configPhaseDeep,hint:n.configPhaseDeepHint,enabled:a.deep.enabled,onEnabledChange:e=>l(t=>t&&{...t,deep:{...t.deep,enabled:e}}),cron:a.deep.cron,onCronChange:e=>l(t=>t&&{...t,deep:{...t.deep,cron:e}}),scheduleLabels:r,disabled:!i||s,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,$.jsx)(xo,{label:n.configDeepMinScore,children:(0,$.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:oo,value:a.deep.minScore,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,minScore:Number(e.target.value)}})})}),(0,$.jsx)(xo,{label:n.configDeepMinRecallCount,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:1,className:oo,value:a.deep.minRecallCount,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,minRecallCount:Number(e.target.value)}})})}),(0,$.jsx)(xo,{label:n.configDeepLimit,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:0,className:oo,value:a.deep.limit,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,limit:Number(e.target.value)}})})}),(0,$.jsx)(xo,{label:n.configDeepHalfLife,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:1,className:oo,value:a.deep.recencyHalfLifeDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,recencyHalfLifeDays:Number(e.target.value)}})})}),(0,$.jsx)(xo,{label:n.configDeepMaxAge,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:1,className:oo,value:a.deep.maxAgeDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,maxAgeDays:Number(e.target.value)}})})})]}),(0,$.jsxs)(wo,{icon:(0,$.jsx)(Oe,{className:`size-4 text-purple-500`}),title:n.configPhaseRem,hint:n.configPhaseRemHint,enabled:a.rem.enabled,onEnabledChange:e=>l(t=>t&&{...t,rem:{...t.rem,enabled:e}}),cron:a.rem.cron,onCronChange:e=>l(t=>t&&{...t,rem:{...t.rem,cron:e}}),scheduleLabels:r,disabled:!i||s,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,$.jsx)(xo,{label:n.configRemLookbackDays,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:1,className:oo,value:a.rem.lookbackDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,rem:{...t.rem,lookbackDays:Number(e.target.value)}})})}),(0,$.jsx)(xo,{label:n.configRemLimit,children:(0,$.jsx)(`input`,{type:`number`,step:`1`,min:0,className:oo,value:a.rem.limit,disabled:!i||s,onChange:e=>l(t=>t&&{...t,rem:{...t.rem,limit:Number(e.target.value)}})})}),(0,$.jsx)(xo,{label:n.configRemMinStrength,children:(0,$.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:oo,value:a.rem.minPatternStrength,disabled:!i||s,onChange:e=>l(t=>t&&{...t,rem:{...t.rem,minPatternStrength:Number(e.target.value)}})})})]})]}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.configLoading}),t[26]=a,t[27]=s,t[28]=i,t[29]=r,t[30]=l,t[31]=n.configDeepHalfLife,t[32]=n.configDeepLimit,t[33]=n.configDeepMaxAge,t[34]=n.configDeepMinRecallCount,t[35]=n.configDeepMinScore,t[36]=n.configFrequency,t[37]=n.configLightDedupe,t[38]=n.configLightLimit,t[39]=n.configLightLookbackDays,t[40]=n.configLoading,t[41]=n.configPhaseCron,t[42]=n.configPhaseDeep,t[43]=n.configPhaseDeepHint,t[44]=n.configPhaseLight,t[45]=n.configPhaseLightHint,t[46]=n.configPhaseRem,t[47]=n.configPhaseRemHint,t[48]=n.configRemLimit,t[49]=n.configRemLookbackDays,t[50]=n.configRemMinStrength,t[51]=n.configTimezone,t[52]=n.off,t[53]=n.on,t[54]=C):C=t[54];let w;return t[55]!==S||t[56]!==C?(w=(0,$.jsxs)(X,{className:p,children:[S,C]}),t[55]=S,t[56]=C,t[57]=w):w=t[57],w}function ko(e){let t=(0,Q.c)(20),{t:n,hasToken:r,eventsLoading:i,events:a,loadEvents:o}=e,s=!r||i,c;t[0]===o?c=t[1]:(c=()=>void o(),t[0]=o,t[1]=c);let l;t[2]===i?l=t[3]:(l=i?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,t[2]=i,t[3]=l);let u;t[4]!==n.eventsLoad||t[5]!==s||t[6]!==c||t[7]!==l?(u=(0,$.jsxs)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:s,onClick:c,children:[l,n.eventsLoad]}),t[4]=n.eventsLoad,t[5]=s,t[6]=c,t[7]=l,t[8]=u):u=t[8];let d;t[9]!==n.eventsHint||t[10]!==n.eventsTitle||t[11]!==u?(d=(0,$.jsx)(vn,{className:io,icon:yt,title:n.eventsTitle,subtitle:n.eventsHint,trailing:u}),t[9]=n.eventsHint,t[10]=n.eventsTitle,t[11]=u,t[12]=d):d=t[12];let f;t[13]!==a||t[14]!==n.eventsEmpty||t[15]!==n.eventsNotLoaded?(f=a?a.length>0?(0,$.jsx)(`div`,{className:`space-y-1.5`,children:a.map(Ao)}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsEmpty}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsNotLoaded}),t[13]=a,t[14]=n.eventsEmpty,t[15]=n.eventsNotLoaded,t[16]=f):f=t[16];let p;return t[17]!==d||t[18]!==f?(p=(0,$.jsxs)(X,{className:ro,children:[d,f]}),t[17]=d,t[18]=f,t[19]=p):p=t[19],p}function Ao(e){let t=e.phase===`light`?`☀️`:e.phase===`rem`?`✨`:`🌙`,n=e.phase===`light`?`scanned=${e.scannedEntries??0} new=${e.newSignals??0} deduped=${e.deduped??0}`:e.phase===`rem`?`patterns=${e.patternsDiscovered??0} analyzed=${e.entriesAnalyzed??0}`:`candidates=${e.candidates??0} applied=${e.applied??0}`;return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-xs`,children:[(0,$.jsx)(`span`,{children:t}),(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:e.phase}),(0,$.jsx)(`span`,{className:J(`font-medium`,e.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:e.ok?`OK`:`FAIL`}),(0,$.jsx)(`span`,{className:`text-fg-muted`,children:n}),(0,$.jsx)(`span`,{className:`text-fg-muted`,children:co(e.durationMs)}),(0,$.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:so(e.timestamp)})]},`${e.timestamp}:${e.phase}`)}function jo(e){let t=(0,Q.c)(40),{t:n,cfgForm:r,dreamingEnabled:i,hasToken:a,cfgSaving:o,enableSaving:s,runPhase:c,setRunPhase:l,runBusy:u,doRunNow:d,doRefresh:f,setDreamingEnabled:p}=e,m;t[0]===n.title?m=t[1]:(m=(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),t[0]=n.title,t[1]=m);let h;t[2]===n.subtitle?h=t[3]:(h=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),t[2]=n.subtitle,t[3]=h);let g;t[4]!==m||t[5]!==h?(g=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[m,h]}),t[4]=m,t[5]=h,t[6]=g):g=t[6];let _;t[7]!==r||t[8]!==o||t[9]!==i||t[10]!==s||t[11]!==a||t[12]!==p||t[13]!==n.configEnabled||t[14]!==n.off||t[15]!==n.on?(_=r?(0,$.jsxs)(`label`,{className:J(`inline-flex cursor-pointer items-center gap-2 rounded-xl border px-3 py-1.5 text-sm transition-colors`,i?`border-emerald-500/30 bg-emerald-500/5 text-fg`:`border-edge-subtle bg-surface-panel/50 text-fg-muted`),children:[(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:n.configEnabled}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,disabled:!a||o||s,onChange:e=>void p(e.target.checked)}),s?(0,$.jsx)(q,{className:`size-3.5 animate-spin text-fg-muted`,"aria-hidden":!0}):(0,$.jsx)(`span`,{className:J(`text-xs font-semibold`,i?`text-emerald-600 dark:text-emerald-400`:``),children:r.enabled?n.on:n.off})]}):null,t[7]=r,t[8]=o,t[9]=i,t[10]=s,t[11]=a,t[12]=p,t[13]=n.configEnabled,t[14]=n.off,t[15]=n.on,t[16]=_):_=t[16];let v;t[17]!==d||t[18]!==i||t[19]!==a||t[20]!==u||t[21]!==c||t[22]!==l||t[23]!==n.runNow||t[24]!==n.runNowHint?(v=i?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-2 py-1.5 text-xs text-fg`,value:c,onChange:e=>l(e.target.value),disabled:!a||u,children:[(0,$.jsx)(`option`,{value:`light`,children:`Light`}),(0,$.jsx)(`option`,{value:`deep`,children:`Deep`}),(0,$.jsx)(`option`,{value:`rem`,children:`REM`})]}),(0,$.jsxs)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!a||u,onClick:()=>void d(c),title:n.runNowHint,children:[u?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Pt,{className:`mr-2 size-4`,"aria-hidden":!0}),n.runNow]})]}):null,t[17]=d,t[18]=i,t[19]=a,t[20]=u,t[21]=c,t[22]=l,t[23]=n.runNow,t[24]=n.runNowHint,t[25]=v):v=t[25];let y=!a,b;t[26]===f?b=t[27]:(b=()=>void f(),t[26]=f,t[27]=b);let x;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(Ze,{className:`mr-2 size-4`,"aria-hidden":!0}),t[28]=x):x=t[28];let S;t[29]!==n.refresh||t[30]!==y||t[31]!==b?(S=(0,$.jsxs)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:y,onClick:b,children:[x,n.refresh]}),t[29]=n.refresh,t[30]=y,t[31]=b,t[32]=S):S=t[32];let C;t[33]!==_||t[34]!==v||t[35]!==S?(C=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[_,v,S]}),t[33]=_,t[34]=v,t[35]=S,t[36]=C):C=t[36];let w;return t[37]!==C||t[38]!==g?(w=(0,$.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[g,C]}),t[37]=C,t[38]=g,t[39]=w):w=t[39],w}function Mo(e){let t=(0,Q.c)(30),{t:n,disabled:r,actionBusy:i,doAction:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=J(`max-w-2xl`,ro),t[0]=o):o=t[0];let s;t[1]!==n.maintenanceHint||t[2]!==n.maintenanceTitle?(s=(0,$.jsx)(vn,{className:io,icon:et,title:n.maintenanceTitle,subtitle:n.maintenanceHint}),t[1]=n.maintenanceHint,t[2]=n.maintenanceTitle,t[3]=s):s=t[3];let c;t[4]!==a||t[5]!==n.confirmResetStore?(c=()=>{confirm(n.confirmResetStore)&&a(`reset_store`)},t[4]=a,t[5]=n.confirmResetStore,t[6]=c):c=t[6];let l;t[7]===i?l=t[8]:(l=i===`reset_store`?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Re,{className:`mr-2 size-4`,"aria-hidden":!0}),t[7]=i,t[8]=l);let u;t[9]!==r||t[10]!==n.resetStore||t[11]!==c||t[12]!==l?(u=(0,$.jsxs)(Y,{variant:`secondary`,disabled:r,onClick:c,children:[l,n.resetStore]}),t[9]=r,t[10]=n.resetStore,t[11]=c,t[12]=l,t[13]=u):u=t[13];let d;t[14]!==a||t[15]!==n.confirmClearLock?(d=()=>{confirm(n.confirmClearLock)&&a(`clear_lock`)},t[14]=a,t[15]=n.confirmClearLock,t[16]=d):d=t[16];let f;t[17]===i?f=t[18]:(f=i===`clear_lock`?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Mt,{className:`mr-2 size-4`,"aria-hidden":!0}),t[17]=i,t[18]=f);let p;t[19]!==r||t[20]!==n.clearLock||t[21]!==d||t[22]!==f?(p=(0,$.jsxs)(Y,{variant:`secondary`,disabled:r,onClick:d,children:[f,n.clearLock]}),t[19]=r,t[20]=n.clearLock,t[21]=d,t[22]=f,t[23]=p):p=t[23];let m;t[24]!==u||t[25]!==p?(m=(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[u,p]}),t[24]=u,t[25]=p,t[26]=m):m=t[26];let h;return t[27]!==s||t[28]!==m?(h=(0,$.jsxs)(X,{className:o,children:[s,m]}),t[27]=s,t[28]=m,t[29]=h):h=t[29],h}function No(e){let t=(0,Q.c)(21),{t:n,hasToken:r,previewLoading:i,previewItems:a,loadPreview:o}=e,s=!r||i,c;t[0]===o?c=t[1]:(c=()=>void o(),t[0]=o,t[1]=c);let l;t[2]===i?l=t[3]:(l=i?(0,$.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,t[2]=i,t[3]=l);let u;t[4]!==n.previewLoad||t[5]!==s||t[6]!==c||t[7]!==l?(u=(0,$.jsxs)(Y,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:s,onClick:c,children:[l,n.previewLoad]}),t[4]=n.previewLoad,t[5]=s,t[6]=c,t[7]=l,t[8]=u):u=t[8];let d;t[9]!==n.previewHint||t[10]!==n.previewTitle||t[11]!==u?(d=(0,$.jsx)(vn,{className:io,icon:zt,title:n.previewTitle,subtitle:n.previewHint,trailing:u}),t[9]=n.previewHint,t[10]=n.previewTitle,t[11]=u,t[12]=d):d=t[12];let f;t[13]!==a||t[14]!==n.previewEligible||t[15]!==n.previewEmpty||t[16]!==n.previewNotLoaded?(f=a?a.length>0?(0,$.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>{let t=`${e.path}:${e.startLine}-${e.endLine}`,r=e.skippedReason;return(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel/60 px-2.5 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:t}),(0,$.jsxs)(`span`,{children:[`score=`,e.score.toFixed(3)]}),(0,$.jsxs)(`span`,{children:[`recalls=`,e.recallCount]}),(0,$.jsxs)(`span`,{children:[`avg=`,e.avgScore.toFixed(3)]}),(0,$.jsxs)(`span`,{children:[`decay=`,e.recencyDecay?.toFixed(3)??`—`]}),r?(0,$.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r}):(0,$.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:n.previewEligible})]}),e.snippet?(0,$.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:e.snippet}):null]},`${e.key}:${e.hash}:${t}`)})}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewEmpty}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewNotLoaded}),t[13]=a,t[14]=n.previewEligible,t[15]=n.previewEmpty,t[16]=n.previewNotLoaded,t[17]=f):f=t[17];let p;return t[18]!==d||t[19]!==f?(p=(0,$.jsxs)(X,{className:ro,children:[d,f]}),t[18]=d,t[19]=f,t[20]=p):p=t[20],p}function Po(e){let t=(0,Q.c)(100),{t:n,data:r,isLoading:i,localeTag:a,scheduleBadgeLabels:o}=e,s;t[0]!==r||t[1]!==n?(s=r?lo(r.lock,n):null,t[0]=r,t[1]=n,t[2]=s):s=t[2];let c=s,l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=J(`min-w-0`,ro),t[3]=l):l=t[3];let u;t[4]===i?u=t[5]:(u=i?(0,$.jsx)(q,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null,t[4]=i,t[5]=u);let d;t[6]!==n.runtimeHint||t[7]!==n.runtimeTitle||t[8]!==u?(d=(0,$.jsx)(vn,{className:io,icon:yt,title:n.runtimeTitle,subtitle:n.runtimeHint,trailing:u}),t[6]=n.runtimeHint,t[7]=n.runtimeTitle,t[8]=u,t[9]=d):d=t[9];let f;t[10]===n.subsectionSchedule?f=t[11]:(f=(0,$.jsx)(Co,{label:n.subsectionSchedule,className:`mb-2`}),t[10]=n.subsectionSchedule,t[11]=f);let p=r?r.config.enabled?n.on:n.off:`—`,m;t[12]!==n.enabled||t[13]!==p?(m=(0,$.jsx)(So,{label:n.enabled,children:p}),t[12]=n.enabled,t[13]=p,t[14]=m):m=t[14];let h=c?.className,g=c?c.text:`—`,_;t[15]!==h||t[16]!==g?(_=(0,$.jsx)(`span`,{className:h,children:g}),t[15]=h,t[16]=g,t[17]=_):_=t[17];let v;t[18]!==n.lock||t[19]!==_?(v=(0,$.jsx)(So,{label:n.lock,children:_}),t[18]=n.lock,t[19]=_,t[20]=v):v=t[20];let y=r&&r.config.timezone||`—`,b;t[21]!==n.timezone||t[22]!==y?(b=(0,$.jsx)(So,{label:n.timezone,children:y}),t[21]=n.timezone,t[22]=y,t[23]=b):b=t[23];let x;t[24]!==r||t[25]!==a||t[26]!==o?(x=r?(0,$.jsx)(Mn,{kind:`cron`,expression:r.config.frequency,locale:a,labels:o,timezone:r.config.timezone||void 0}):`—`,t[24]=r,t[25]=a,t[26]=o,t[27]=x):x=t[27];let S;t[28]===r?S=t[29]:(S=r?.config.frequency?(0,$.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-[0.65rem] text-fg-subtle`,title:r.config.frequency,children:r.config.frequency}):null,t[28]=r,t[29]=S);let C;t[30]!==n.schedule||t[31]!==x||t[32]!==S?(C=(0,$.jsxs)(So,{label:n.schedule,className:`col-span-2 sm:col-span-2`,children:[x,S]}),t[30]=n.schedule,t[31]=x,t[32]=S,t[33]=C):C=t[33];let w;t[34]!==v||t[35]!==b||t[36]!==C||t[37]!==m?(w=(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[m,v,b,C]}),t[34]=v,t[35]=b,t[36]=C,t[37]=m,t[38]=w):w=t[38];let T;t[39]!==w||t[40]!==f?(T=(0,$.jsxs)(`div`,{className:ao,children:[f,w]}),t[39]=w,t[40]=f,t[41]=T):T=t[41];let E;t[42]===n.subsectionStore?E=t[43]:(E=(0,$.jsx)(Co,{label:n.subsectionStore,className:`mb-2`}),t[42]=n.subsectionStore,t[43]=E);let D=r?String(r.store.entryCount):`—`,O;t[44]!==n.storeEntries||t[45]!==D?(O=(0,$.jsx)(So,{label:n.storeEntries,children:D}),t[44]=n.storeEntries,t[45]=D,t[46]=O):O=t[46];let k=r?String(r.store.promotedCount):`—`,A;t[47]!==n.storePromoted||t[48]!==k?(A=(0,$.jsx)(So,{label:n.storePromoted,children:k}),t[47]=n.storePromoted,t[48]=k,t[49]=A):A=t[49];let j;t[50]===r?j=t[51]:(j=r?so(r.store.updatedAt):`—`,t[50]=r,t[51]=j);let M;t[52]!==n.storeUpdatedAt||t[53]!==j?(M=(0,$.jsx)(So,{label:n.storeUpdatedAt,children:j}),t[52]=n.storeUpdatedAt,t[53]=j,t[54]=M):M=t[54];let N;t[55]===r?N=t[56]:(N=r?so(r.store.lastPromotedAt):`—`,t[55]=r,t[56]=N);let P;t[57]!==n.storeLastPromotedAt||t[58]!==N?(P=(0,$.jsx)(So,{label:n.storeLastPromotedAt,children:N}),t[57]=n.storeLastPromotedAt,t[58]=N,t[59]=P):P=t[59];let F;t[60]!==O||t[61]!==A||t[62]!==M||t[63]!==P?(F=(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[O,A,M,P]}),t[60]=O,t[61]=A,t[62]=M,t[63]=P,t[64]=F):F=t[64];let I;t[65]!==E||t[66]!==F?(I=(0,$.jsxs)(`div`,{className:ao,children:[E,F]}),t[65]=E,t[66]=F,t[67]=I):I=t[67];let L;t[68]!==r||t[69]!==a||t[70]!==o||t[71]!==n?(L=r?.config?.phases?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Co,{label:n.subsectionPhases,className:`mb-2`}),(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[(0,$.jsx)(To,{icon:(0,$.jsx)(Et,{className:`size-4 text-amber-500`}),label:`Light`,enabled:r.config.phases.light.enabled,cron:r.config.phases.light.cron,scheduleSummary:xn(r.config.phases.light.cron,a,o,{timezone:r.config.timezone||void 0}),details:`lookback=${r.config.phases.light.lookbackDays}d, limit=${r.config.phases.light.limit}, dedupe=${r.config.phases.light.dedupeSimilarity}`,t:n}),(0,$.jsx)(To,{icon:(0,$.jsx)(At,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:r.config.phases.deep.enabled,cron:r.config.phases.deep.cron,scheduleSummary:xn(r.config.phases.deep.cron,a,o,{timezone:r.config.timezone||void 0}),details:`minScore=${r.config.phases.deep.minScore}, recalls≥${r.config.phases.deep.minRecallCount}, limit=${r.config.phases.deep.limit}, halfLife=${r.config.phases.deep.recencyHalfLifeDays}d`,t:n}),(0,$.jsx)(To,{icon:(0,$.jsx)(Oe,{className:`size-4 text-purple-500`}),label:`REM`,enabled:r.config.phases.rem.enabled,cron:r.config.phases.rem.cron,scheduleSummary:xn(r.config.phases.rem.cron,a,o,{timezone:r.config.timezone||void 0}),details:`lookback=${r.config.phases.rem.lookbackDays}d, limit=${r.config.phases.rem.limit}, strength≥${r.config.phases.rem.minPatternStrength}`,t:n})]})]}):null,t[68]=r,t[69]=a,t[70]=o,t[71]=n,t[72]=L):L=t[72];let R;t[73]===n.subsectionLastRun?R=t[74]:(R=(0,$.jsx)(Co,{label:n.subsectionLastRun,className:`mb-2`}),t[73]=n.subsectionLastRun,t[74]=R);let z;t[75]===n.lastRunBlockHint?z=t[76]:(z=(0,$.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:n.lastRunBlockHint}),t[75]=n.lastRunBlockHint,t[76]=z);let B;t[77]!==r||t[78]!==n?(B=r?.lastRun?.exists?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[r.lastRun.parseError?(0,$.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[n.lastRunParseError,`: `,r.lastRun.parseError]}):null,r.lastRun.record?(0,$.jsx)(`div`,{className:`rounded-lg border border-edge-subtle/80 bg-surface-panel/50 p-2.5`,children:(0,$.jsx)(Do,{t:n,r:r.lastRun.record})}):null,r.lastRun.raw!==void 0&&r.lastRun.raw!==null?(0,$.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,$.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,$.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(r.lastRun.raw,null,2)})]}):null]}):(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.lastRunEmpty}),t[77]=r,t[78]=n,t[79]=B):B=t[79];let V;t[80]!==R||t[81]!==z||t[82]!==B?(V=(0,$.jsxs)(`div`,{className:ao,children:[R,z,B]}),t[80]=R,t[81]=z,t[82]=B,t[83]=V):V=t[83];let ee=r?.lightLastRun,H;t[84]!==n||t[85]!==ee?(H=(0,$.jsx)(Eo,{label:n.subsectionLightLastRun,lastRun:ee,t:n}),t[84]=n,t[85]=ee,t[86]=H):H=t[86];let U=r?.remLastRun,W;t[87]!==n||t[88]!==U?(W=(0,$.jsx)(Eo,{label:n.subsectionRemLastRun,lastRun:U,t:n}),t[87]=n,t[88]=U,t[89]=W):W=t[89];let te;t[90]!==T||t[91]!==I||t[92]!==L||t[93]!==V||t[94]!==H||t[95]!==W?(te=(0,$.jsxs)(`div`,{className:`space-y-3`,children:[T,I,L,V,H,W]}),t[90]=T,t[91]=I,t[92]=L,t[93]=V,t[94]=H,t[95]=W,t[96]=te):te=t[96];let G;return t[97]!==te||t[98]!==d?(G=(0,$.jsxs)(X,{className:l,children:[d,te]}),t[97]=te,t[98]=d,t[99]=G):G=t[99],G}var Fo=[`config`,`runtime`,`insights`,`maintenance`],Io={config:G,runtime:yt,insights:zt,maintenance:et};function Lo(e){return e&&Fo.includes(e)?e:`config`}function Ro(e,t){return t===`config`?e.tabConfig:t===`runtime`?e.tabRuntime:t===`insights`?e.tabInsights:e.tabMaintenance}function zo(e,t){return t===`config`?e.configTabHint:t===`runtime`?e.runtimeTabHint:t===`insights`?e.insightsTabHint:e.maintenanceTabHint}function Bo(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:return{form:t.value,baseline:t.value};case`set`:return{...e,form:t.value};case`saved`:return{form:t.value,baseline:t.value}}}var Vo={actionBusy:null,actionError:null,actionOk:!1,runBusy:!1,runOk:!1,runError:null,runPhase:`deep`,cfgSaving:!1,enableSaving:!1,cfgOk:!1,cfgError:null,previewLoading:!1,previewError:null,previewItems:null,eventsLoading:!1,eventsError:null,events:null};function Ho(){let e=a(e=>e.language),t=s(e),n=t.dreamingSettings,r=t.cron.schedulePicker,i=t.cron.scheduleBadge,o=e===`zh`?`zh-CN`:`en-US`,c=!!C(e=>e.token),[l,u]=Zt(),f=Lo(l.get(`tab`)),p=(0,Z.useCallback)(e=>{u(t=>{let n=new URLSearchParams(t);return e===`config`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},[u]),{data:m}=Fe(c),[h,g]=(0,Z.useReducer)(Lt,Vo),{actionBusy:_,actionError:v,actionOk:y,runBusy:b,runOk:x,runError:S,runPhase:w,cfgSaving:T,enableSaving:E,cfgOk:D,cfgError:O,previewLoading:k,previewError:A,previewItems:j,eventsLoading:M,eventsError:N,events:P}=h,[F,I]=(0,Z.useReducer)(Bo,{form:null,baseline:null}),L=F.form,R=F.baseline,z=(0,Z.useRef)(!1),{data:B,error:V,isLoading:ee,mutate:H}=d(c?Va():null,Ha,{revalidateOnFocus:!1}),U=(0,Z.useMemo)(()=>{let e=[];return V&&e.push(V instanceof Error?V.message:String(V)),v&&e.push(v),S&&e.push(S),A&&e.push(A),N&&e.push(N),O&&e.push(O),e},[V,v,S,A,N,O]),W=(0,Z.useMemo)(()=>{let e=[];return D&&e.push(n.configSaved),x&&e.push(n.runQueued),y&&e.push(n.actionOk),e},[D,x,y,n]),te=(0,Z.useCallback)(async()=>{g({type:`patch`,patch:{actionOk:!1,actionError:null,runOk:!1,runError:null,cfgOk:!1,cfgError:null,previewError:null}}),await H()},[H]),G=(0,Z.useCallback)(async()=>{g({type:`patch`,patch:{previewLoading:!0,previewError:null}});try{g({type:`patch`,patch:{previewItems:(await Ga(20)).items??[]}})}catch(e){g({type:`patch`,patch:{previewError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{previewLoading:!1}})}},[]),ne=(0,Z.useCallback)(async()=>{g({type:`patch`,patch:{eventsLoading:!0,eventsError:null}});try{g({type:`patch`,patch:{events:await Ka(50)}})}catch(e){g({type:`patch`,patch:{eventsError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{eventsLoading:!1}})}},[]),re=(0,Z.useCallback)(async(e=`deep`)=>{g({type:`patch`,patch:{runBusy:!0,runOk:!1,runError:null}});try{await Wa(e),g({type:`patch`,patch:{runOk:!0}}),await H()}catch(e){g({type:`patch`,patch:{runError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{runBusy:!1}})}},[H]),ie=(0,Z.useCallback)(async e=>{g({type:`patch`,patch:{actionBusy:e,actionError:null,actionOk:!1}});try{await Ua(e),g({type:`patch`,patch:{actionOk:!0}}),await H()}catch(e){g({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{actionBusy:null}})}},[H]),ae=!c||ee||!!_,oe=(0,Z.useMemo)(()=>{let e=m?.payload?.config;return to(e??{})},[m]);(0,Z.useEffect)(()=>{if(!c){I({type:`reset`}),z.current=!1;return}z.current||I({type:`sync`,value:oe})},[oe,c]);let se=(0,Z.useMemo)(()=>!L||!R?!1:JSON.stringify(L)!==JSON.stringify(R),[L,R]),ce=(0,Z.useCallback)(async()=>{if(L){g({type:`patch`,patch:{cfgSaving:!0,cfgOk:!1,cfgError:null}});try{await no(L),I({type:`saved`,value:L}),z.current=!1,g({type:`patch`,patch:{cfgOk:!0}}),await H()}catch(e){g({type:`patch`,patch:{cfgError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{cfgSaving:!1}})}}},[L,H]),le=(0,Z.useCallback)(async e=>{if(!L||!c)return;let t={...L,enabled:e},n=L;z.current=!0,I({type:`set`,value:t}),g({type:`patch`,patch:{enableSaving:!0,cfgOk:!1,cfgError:null}});try{await no(t),I({type:`saved`,value:t}),z.current=!1,g({type:`patch`,patch:{cfgOk:!0}}),await H()}catch(e){I({type:`set`,value:n}),g({type:`patch`,patch:{cfgError:e instanceof Error?e.message:String(e)}})}finally{g({type:`patch`,patch:{enableSaving:!1}})}},[L,c,H]);return(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[(0,$.jsx)(jo,{t:n,cfgForm:L,dreamingEnabled:L?.enabled??oe.enabled,hasToken:c,cfgSaving:T,enableSaving:E,runPhase:w,setRunPhase:e=>g({type:`patch`,patch:{runPhase:e}}),runBusy:b,doRunNow:re,doRefresh:te,setDreamingEnabled:le}),U.length>0?(0,$.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-amber-500/20 bg-amber-500/5 px-4 py-3`,role:`alert`,children:U.map(e=>(0,$.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200/90`,children:e},e))}):null,W.length>0?(0,$.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-emerald-500/20 bg-emerald-500/5 px-4 py-3`,role:`status`,children:W.map(e=>(0,$.jsx)(`p`,{className:`text-sm text-emerald-800 dark:text-emerald-200/90`,children:e},e))}):null,(0,$.jsx)(Uo,{t:n,activeTab:f,onChange:p}),(0,$.jsx)(Wo,{t:n,id:`config`,activeTab:f,children:(0,$.jsx)(Oo,{t:n,schedulePickerLabels:r,hasToken:c,cfgForm:L,cfgBaseline:R,cfgSaving:T,cfgDirty:se,setCfgForm:e=>{z.current=!0;let t=typeof e==`function`?e(L):e;t&&I({type:`set`,value:t})},setCfgOk:e=>g({type:`patch`,patch:{cfgOk:e}}),setCfgError:e=>g({type:`patch`,patch:{cfgError:e}}),saveConfig:ce})}),(0,$.jsx)(Wo,{t:n,id:`runtime`,activeTab:f,children:(0,$.jsx)(Po,{t:n,data:B,isLoading:ee,localeTag:o,scheduleBadgeLabels:i})}),(0,$.jsx)(Wo,{t:n,id:`insights`,activeTab:f,children:(0,$.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-2`,children:[(0,$.jsx)(No,{t:n,hasToken:c,previewLoading:k,previewItems:j,loadPreview:G}),(0,$.jsx)(ko,{t:n,hasToken:c,eventsLoading:M,events:P,loadEvents:ne})]})}),(0,$.jsx)(Wo,{t:n,id:`maintenance`,activeTab:f,children:(0,$.jsx)(Mo,{t:n,disabled:ae,actionBusy:_,doAction:ie})})]})}function Uo(e){let t=(0,Q.c)(11),{t:n,activeTab:r,onChange:i}=e,a=n.tabsAriaLabel,o;t[0]!==r||t[1]!==i?(o=e=>{e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||(e.preventDefault(),i(Fo[(Fo.indexOf(r)+(e.key===`ArrowRight`?1:-1)+Fo.length)%Fo.length]))},t[0]=r,t[1]=i,t[2]=o):o=t[2];let s;t[3]!==r||t[4]!==i||t[5]!==n?(s=Fo.map(e=>{let t=Io[e],a=e===r;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":a,id:`dreaming-settings-tab-${e}`,"aria-controls":`dreaming-settings-panel-${e}`,className:J(`inline-flex shrink-0 items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.press,a?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>i(e),children:[(0,$.jsx)(t,{className:`size-3.5 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:Ro(n,e)})]},e)}),t[3]=r,t[4]=i,t[5]=n,t[6]=s):s=t[6];let c;return t[7]!==n.tabsAriaLabel||t[8]!==o||t[9]!==s?(c=(0,$.jsx)(`nav`,{"aria-label":a,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,role:`tablist`,onKeyDown:o,children:s}),t[7]=n.tabsAriaLabel,t[8]=o,t[9]=s,t[10]=c):c=t[10],c}function Wo(e){let t=(0,Q.c)(18),{t:n,id:r,activeTab:i,children:a}=e;if(i!==r)return null;let o=`dreaming-settings-panel-${r}`,s=`dreaming-settings-tab-${r}`,c;t[0]!==r||t[1]!==n?(c=Ro(n,r),t[0]=r,t[1]=n,t[2]=c):c=t[2];let l;t[3]===c?l=t[4]:(l=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:c}),t[3]=c,t[4]=l);let u;t[5]!==r||t[6]!==n?(u=zo(n,r),t[5]=r,t[6]=n,t[7]=u):u=t[7];let d;t[8]===u?d=t[9]:(d=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:u}),t[8]=u,t[9]=d);let f;t[10]!==l||t[11]!==d?(f=(0,$.jsxs)(`div`,{className:`mb-5`,children:[l,d]}),t[10]=l,t[11]=d,t[12]=f):f=t[12];let p;return t[13]!==a||t[14]!==o||t[15]!==s||t[16]!==f?(p=(0,$.jsxs)(`section`,{id:o,role:`tabpanel`,"aria-labelledby":s,className:`rounded-2xl border border-edge bg-surface-base px-4 py-5 sm:px-5`,children:[f,a]}),t[13]=a,t[14]=o,t[15]=s,t[16]=f,t[17]=p):p=t[17],p}var Go={enabled:!0,maxConcurrentJobs:5,defaultTimezone:`UTC`,historyRetentionDays:7,enableMetrics:!0};function Ko(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function qo(e){let t=Ko(e)?e:{},n=Ko(t.cron)?t.cron:{};return{enabled:n.enabled!==!1,maxConcurrentJobs:typeof n.maxConcurrentJobs==`number`&&Number.isFinite(n.maxConcurrentJobs)?Math.max(1,Math.min(100,Math.floor(n.maxConcurrentJobs))):Go.maxConcurrentJobs,defaultTimezone:typeof n.defaultTimezone==`string`&&n.defaultTimezone.trim()?n.defaultTimezone.trim():Go.defaultTimezone,historyRetentionDays:typeof n.historyRetentionDays==`number`&&Number.isFinite(n.historyRetentionDays)?Math.max(1,Math.min(365,Math.floor(n.historyRetentionDays))):Go.historyRetentionDays,enableMetrics:n.enableMetrics!==!1}}async function Jo(e){await w(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({cron:e})}),Qt()}function Yo(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,ht,`dark:border-edge`)}function Xo(){return{form:null,baseline:null,saving:!1,error:null,saveOk:!1,dirty:!1}}function Zo(e,t){switch(t.type){case`sync`:return{...e,form:structuredClone(t.parsed),baseline:structuredClone(t.parsed),saveOk:!1,dirty:!1};case`patch`:return e.form?{...e,form:{...e.form,...t.patch},dirty:!0,saveOk:!1}:e;case`discard`:return e.baseline?{...e,form:structuredClone(e.baseline),dirty:!1}:e;case`saveStart`:return{...e,saving:!0,error:null};case`saveSuccess`:return e.form?{...e,saving:!1,baseline:structuredClone(e.form),dirty:!1,saveOk:!0}:{...e,saving:!1};case`saveError`:return{...e,saving:!1,error:t.error};case`clearSaveOk`:return{...e,saveOk:!1}}}function Qo({hasToken:e}){let t=s(a(e=>e.language)).cron.globals,{data:n,isLoading:r}=Fe(e),i=(0,Z.useMemo)(()=>n?.payload?.config===void 0?null:structuredClone(qo(n.payload.config)),[n]),[o,c]=(0,Z.useReducer)(Zo,void 0,Xo),l=(0,Z.useRef)(i);e&&i!==null&&!o.dirty&&l.current!==i&&(l.current=i,c({type:`sync`,parsed:i}));let u=(0,Z.useMemo)(()=>!!(o.form&&o.baseline&&JSON.stringify(o.form)!==JSON.stringify(o.baseline)),[o.form,o.baseline]),d=(0,Z.useCallback)(e=>{c({type:`patch`,patch:e})},[]),f=(0,Z.useCallback)(async()=>{if(!(!o.form||o.saving)){c({type:`saveStart`});try{await Jo(o.form),c({type:`saveSuccess`}),window.setTimeout(()=>c({type:`clearSaveOk`}),2500)}catch(e){c({type:`saveError`,error:e instanceof Error?e.message:t.saveError})}}},[t.saveError,o.form,o.saving]);return!e||!o.form?r?(0,$.jsx)(X,{children:(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),t.loading]})}):null:(0,$.jsxs)(X,{children:[(0,$.jsx)(vn,{icon:W,title:t.title,subtitle:t.hint}),(0,$.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center justify-end gap-2`,children:[o.saveOk?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:t.saved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!u||o.saving,onClick:()=>c({type:`discard`}),children:t.discard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!u||o.saving,onClick:()=>void f(),children:o.saving?t.saving:t.save})]}),o.error?(0,$.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:o.error}):null,(0,$.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg sm:col-span-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:o.form.enabled,onChange:e=>d({enabled:e.target.checked})}),t.enabled]}),(0,$.jsx)($o,{label:t.maxConcurrent,value:o.form.maxConcurrentJobs,min:1,max:100,disabled:!o.form.enabled,onChange:e=>d({maxConcurrentJobs:e})}),(0,$.jsx)($o,{label:t.timezone,text:!0,value:o.form.defaultTimezone,disabled:!o.form.enabled,onTextChange:e=>d({defaultTimezone:e})}),(0,$.jsx)($o,{label:t.retentionDays,value:o.form.historyRetentionDays,min:1,max:365,disabled:!o.form.enabled,onChange:e=>d({historyRetentionDays:e})}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:o.form.enableMetrics,disabled:!o.form.enabled,onChange:e=>d({enableMetrics:e.target.checked})}),t.metrics]})]})]})}function $o(e){let t=(0,Q.c)(13),{label:n,value:r,min:i,max:a,disabled:o,text:s,onChange:c,onTextChange:l}=e,u;t[0]===n?u=t[1]:(u=(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=u);let d;t[2]!==o||t[3]!==a||t[4]!==i||t[5]!==c||t[6]!==l||t[7]!==s||t[8]!==r?(d=s?(0,$.jsx)(`input`,{className:J(Yo(),`font-mono text-xs`),value:String(r),disabled:o,onChange:e=>l?.(e.target.value)}):(0,$.jsx)(`input`,{type:`number`,min:i,max:a,disabled:o,className:J(Yo(),`max-w-xs font-mono text-xs`),value:typeof r==`number`?r:0,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&c&&i!==void 0&&a!==void 0&&c(Math.max(i,Math.min(a,Math.floor(t))))}}),t[2]=o,t[3]=a,t[4]=i,t[5]=c,t[6]=l,t[7]=s,t[8]=r,t[9]=d):d=t[9];let f;return t[10]!==u||t[11]!==d?(f=(0,$.jsxs)(`div`,{children:[u,d]}),t[10]=u,t[11]=d,t[12]=f):f=t[12],f}function es(){let e=(0,Q.c)(18),t=a(ns),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.cronSettingsPage,i=!!C(ts),o;e[2]===r.title?o=e[3]:(o=(0,$.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:r.title}),e[2]=r.title,e[3]=o);let c;e[4]===r.subtitle?c=e[5]:(c=(0,$.jsx)(`p`,{className:`max-w-2xl text-sm text-fg-muted`,children:r.subtitle}),e[4]=r.subtitle,e[5]=c);let l;e[6]===Symbol.for(`react.memo_cache_sentinel`)?(l=ce(`cron`),e[6]=l):l=e[6];let u;e[7]===r.tasksLink?u=e[8]:(u=(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:(0,$.jsx)(_t,{to:l,className:`font-medium text-accent-fg hover:underline`,children:r.tasksLink})}),e[7]=r.tasksLink,e[8]=u);let d;e[9]!==o||e[10]!==c||e[11]!==u?(d=(0,$.jsxs)(`header`,{className:`flex flex-col gap-2`,children:[o,c,u]}),e[9]=o,e[10]=c,e[11]=u,e[12]=d):d=e[12];let f;e[13]===i?f=e[14]:(f=(0,$.jsx)(Qo,{hasToken:i}),e[13]=i,e[14]=f);let p;return e[15]!==d||e[16]!==f?(p=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6 sm:px-8`,children:[d,f]}),e[15]=d,e[16]=f,e[17]=p):p=e[17],p}function ts(e){return e.token}function ns(e){return e.language}var rs={maxTurns:20,judgeModelRef:``,checklistMode:!0,maxConsecutiveParseFailures:3,judgeTimeoutSec:60,checklistHistoryChars:24e3};function is(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function as(e){let t=is(e)?e:{},n=is(t.goals)?t.goals:{};return{maxTurns:typeof n.maxTurns==`number`&&Number.isFinite(n.maxTurns)?Math.max(1,Math.min(500,Math.floor(n.maxTurns))):rs.maxTurns,judgeModelRef:typeof n.judgeModelRef==`string`?n.judgeModelRef:``,checklistMode:n.checklistMode!==!1,maxConsecutiveParseFailures:typeof n.maxConsecutiveParseFailures==`number`&&Number.isFinite(n.maxConsecutiveParseFailures)?Math.max(1,Math.min(20,Math.floor(n.maxConsecutiveParseFailures))):rs.maxConsecutiveParseFailures,judgeTimeoutSec:typeof n.judgeTimeoutMs==`number`&&Number.isFinite(n.judgeTimeoutMs)?Math.max(5,Math.min(120,Math.round(n.judgeTimeoutMs/1e3))):rs.judgeTimeoutSec,checklistHistoryChars:typeof n.checklistHistoryChars==`number`&&Number.isFinite(n.checklistHistoryChars)?Math.max(0,Math.min(1e5,Math.floor(n.checklistHistoryChars))):rs.checklistHistoryChars}}async function os(e){await w(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({goals:{maxTurns:e.maxTurns,...e.judgeModelRef.trim()?{judgeModelRef:e.judgeModelRef.trim()}:{judgeModelRef:null},checklistMode:e.checklistMode,maxConsecutiveParseFailures:e.maxConsecutiveParseFailures,judgeTimeoutMs:e.judgeTimeoutSec*1e3,checklistHistoryChars:e.checklistHistoryChars}})}),Qt()}function ss(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,ht,`dark:border-edge`)}function cs(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`patch`:return{...e,form:e.form?{...e.form,...t.patch}:null};case`discard`:return e.baseline?{form:structuredClone(e.baseline),baseline:e.baseline}:e;case`saved`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}}}function ls({hasToken:e}){let t=a(e=>e.language),n=s(t).goalsSettings,r=s(t).chat,{data:i,isLoading:o}=Fe(e),c=(0,Z.useMemo)(()=>i?.payload?.config===void 0?null:as(i.payload.config),[i]),[l,u]=(0,Z.useReducer)(cs,{form:null,baseline:null}),d=l.form,f=l.baseline,[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(null),_=(0,Z.useRef)(!1),v=(0,Z.useRef)(null);e?c!==null&&!_.current&&v.current!==c&&(v.current=c,u({type:`sync`,value:c})):v.current!==null&&(v.current=null,u({type:`reset`}),_.current=!1);let y=d&&f&&JSON.stringify(d)!==JSON.stringify(f),b=(0,Z.useCallback)(e=>{_.current=!0,u({type:`patch`,patch:e})},[]);return!e||!d?o?(0,$.jsx)(X,{children:(0,$.jsx)(q,{className:`size-4 animate-spin text-fg-muted`})}):null:(0,$.jsxs)(X,{children:[(0,$.jsx)(vn,{icon:we,title:n.title,subtitle:n.hint}),(0,$.jsxs)(`div`,{className:`mb-4 flex justify-end gap-2`,children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!y||p,onClick:()=>u({type:`discard`}),children:n.discard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!y||p,onClick:()=>{(async()=>{m(!0),g(null);try{await os(d),_.current=!1,u({type:`saved`,value:d})}catch(e){g(e instanceof Error?e.message:n.saveError)}finally{m(!1)}})()},children:p?n.saving:n.save})]}),h?(0,$.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:h}):null,(0,$.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n.maxTurns}),(0,$.jsx)(`input`,{type:`number`,min:1,max:500,className:ss(),value:d.maxTurns,onChange:e=>b({maxTurns:Number(e.target.value)||20})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n.judgeModelRef}),(0,$.jsx)(gt,{value:d.judgeModelRef,placeholder:n.judgeModelRefPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,className:`w-full max-w-none min-w-0`,onChange:e=>b({judgeModelRef:e})}),d.judgeModelRef.trim()?(0,$.jsx)(`button`,{type:`button`,className:`mt-1 text-xs text-accent hover:underline`,onClick:()=>b({judgeModelRef:``}),children:n.judgeModelRefUseDefault}):(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.judgeModelRefHint})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg sm:col-span-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:d.checklistMode,onChange:e=>b({checklistMode:e.target.checked})}),n.checklistMode]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n.parseFailures}),(0,$.jsx)(`input`,{type:`number`,min:1,max:20,className:ss(),value:d.maxConsecutiveParseFailures,onChange:e=>b({maxConsecutiveParseFailures:Number(e.target.value)||3})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n.judgeTimeoutSec}),(0,$.jsx)(`input`,{type:`number`,min:5,max:120,className:ss(),value:d.judgeTimeoutSec,onChange:e=>b({judgeTimeoutSec:Number(e.target.value)||60})})]}),(0,$.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,children:n.checklistHistoryChars}),(0,$.jsx)(`input`,{type:`number`,min:0,max:1e5,className:ss(),value:d.checklistHistoryChars,onChange:e=>b({checklistHistoryChars:Math.max(0,Math.min(1e5,Math.floor(Number(e.target.value)||0)))})}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.checklistHistoryCharsHint})]})]})]})}function us(){let e=(0,Q.c)(14),t=a(fs),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.goalsSettingsPage,i=!!C(ds),o;e[2]===r.title?o=e[3]:(o=(0,$.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:r.title}),e[2]=r.title,e[3]=o);let c;e[4]===r.subtitle?c=e[5]:(c=(0,$.jsx)(`p`,{className:`max-w-2xl text-sm text-fg-muted`,children:r.subtitle}),e[4]=r.subtitle,e[5]=c);let l;e[6]!==o||e[7]!==c?(l=(0,$.jsxs)(`header`,{className:`flex flex-col gap-2`,children:[o,c]}),e[6]=o,e[7]=c,e[8]=l):l=e[8];let u;e[9]===i?u=e[10]:(u=(0,$.jsx)(ls,{hasToken:i}),e[9]=i,e[10]=u);let d;return e[11]!==l||e[12]!==u?(d=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6 sm:px-8`,children:[l,u]}),e[11]=l,e[12]=u,e[13]=d):d=e[13],d}function ds(e){return e.token}function fs(e){return e.language}var ps={critical:3,warn:2,info:1};function ms(){return l(`/api/doctor?security=true`)}function hs(e){return e.toSorted((e,t)=>ps[t.severity]-ps[e.severity]||e.checkId.localeCompare(t.checkId))}function gs(e){let t=e?.checks?.find(e=>e.id===`security-audit`);if(!t)return{status:`skip`,message:`Security audit unavailable.`,hints:[],findings:[]};let n=hs((t.findings??[]).filter(e=>typeof e.checkId==`string`&&(e.severity===`critical`||e.severity===`warn`||e.severity===`info`)&&typeof e.title==`string`&&typeof e.detail==`string`));return{status:t.status,message:t.message,hints:Array.isArray(t.hints)?t.hints.filter(e=>typeof e==`string`):[],findings:n}}async function _s(){return gs(await w(ms()))}function vs(e){let t=(0,Q.c)(40),{enabled:n,refreshToken:r}=e,i=r===void 0?0:r,o=a(bs),c;t[0]===o?c=t[1]:(c=s(o),t[0]=o,t[1]=c);let l=c.gatewaySettings,u;t[2]!==n||t[3]!==i?(u=n?[ms(),i]:null,t[2]=n,t[3]=i,t[4]=u):u=t[4];let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p={revalidateOnFocus:!1},t[5]=p):p=t[5];let{data:m,error:h,isLoading:g,isValidating:_,mutate:v}=d(u,ys,p),y=m??null,b=h instanceof Error?h.message:h?String(h):null,x=g||_,S;t[6]===v?S=t[7]:(S=()=>{v(),f(ms())},t[6]=v,t[7]=S);let C=S,w=!n||x,T;t[8]===x?T=t[9]:(T=x?(0,$.jsx)(q,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ze,{className:`size-3.5`,"aria-hidden":!0}),t[8]=x,t[9]=T);let E;t[10]===l.securityAuditRefresh?E=t[11]:(E=(0,$.jsx)(`span`,{className:`ml-1.5`,children:l.securityAuditRefresh}),t[10]=l.securityAuditRefresh,t[11]=E);let D;t[12]!==C||t[13]!==w||t[14]!==T||t[15]!==E?(D=(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:w,onClick:C,children:[T,E]}),t[12]=C,t[13]=w,t[14]=T,t[15]=E,t[16]=D):D=t[16];let O;t[17]!==l.securityAuditSubtitle||t[18]!==l.securityAuditTitle||t[19]!==D?(O=(0,$.jsx)(vn,{icon:nn,title:l.securityAuditTitle,subtitle:l.securityAuditSubtitle,trailing:D}),t[17]=l.securityAuditSubtitle,t[18]=l.securityAuditTitle,t[19]=D,t[20]=O):O=t[20];let k;t[21]===l.securityAuditSavedConfigHint?k=t[22]:(k=(0,$.jsx)(`p`,{className:`mb-4 text-xs text-fg-subtle`,children:l.securityAuditSavedConfigHint}),t[21]=l.securityAuditSavedConfigHint,t[22]=k);let A;t[23]!==b||t[24]!==l.securityAuditLoadError?(A=b?(0,$.jsxs)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[l.securityAuditLoadError,`: `,b]}):null,t[23]=b,t[24]=l.securityAuditLoadError,t[25]=A):A=t[25];let j;t[26]!==y||t[27]!==b||t[28]!==l.securityAuditLoading||t[29]!==x?(j=!b&&x&&!y?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}),l.securityAuditLoading]}):null,t[26]=y,t[27]=b,t[28]=l.securityAuditLoading,t[29]=x,t[30]=j):j=t[30];let M;t[31]!==y||t[32]!==l?(M=y?(0,$.jsx)(xs,{g:l,audit:y}):null,t[31]=y,t[32]=l,t[33]=M):M=t[33];let N;return t[34]!==O||t[35]!==k||t[36]!==A||t[37]!==j||t[38]!==M?(N=(0,$.jsxs)(X,{children:[O,k,A,j,M]}),t[34]=O,t[35]=k,t[36]=A,t[37]=j,t[38]=M,t[39]=N):N=t[39],N}function ys(){return _s()}function bs(e){return e.language}function xs(e){let t=(0,Q.c)(40),{g:n,audit:r}=e,i,a,o,s,c,l,u;t[0]!==r.findings||t[1]!==r.status||t[2]!==n?(a=Ts(n,r.status,r.findings),u=`space-y-4`,c=J(`rounded-lg border px-3 py-2.5 text-sm`,a.bannerClass),l=`status`,s=`flex items-start gap-2`,i=a.icon,o=J(`mt-0.5 size-4 shrink-0`,a.iconClass),t[0]=r.findings,t[1]=r.status,t[2]=n,t[3]=i,t[4]=a,t[5]=o,t[6]=s,t[7]=c,t[8]=l,t[9]=u):(i=t[3],a=t[4],o=t[5],s=t[6],c=t[7],l=t[8],u=t[9]);let d;t[10]!==i||t[11]!==o?(d=(0,$.jsx)(i,{className:o,"aria-hidden":!0}),t[10]=i,t[11]=o,t[12]=d):d=t[12];let f;t[13]===a.title?f=t[14]:(f=(0,$.jsx)(`p`,{className:`font-medium`,children:a.title}),t[13]=a.title,t[14]=f);let p;t[15]===r.message?p=t[16]:(p=(0,$.jsx)(`p`,{className:`mt-0.5 text-xs opacity-90`,children:r.message}),t[15]=r.message,t[16]=p);let m;t[17]!==f||t[18]!==p?(m=(0,$.jsxs)(`div`,{children:[f,p]}),t[17]=f,t[18]=p,t[19]=m):m=t[19];let h;t[20]!==s||t[21]!==d||t[22]!==m?(h=(0,$.jsxs)(`div`,{className:s,children:[d,m]}),t[20]=s,t[21]=d,t[22]=m,t[23]=h):h=t[23];let g;t[24]!==h||t[25]!==c||t[26]!==l?(g=(0,$.jsx)(`div`,{className:c,role:l,children:h}),t[24]=h,t[25]=c,t[26]=l,t[27]=g):g=t[27];let _;t[28]!==r.findings||t[29]!==r.status||t[30]!==n?(_=r.findings.length>0?(0,$.jsx)(`ul`,{className:`space-y-2`,children:r.findings.map(e=>(0,$.jsx)(Cs,{g:n,finding:e},e.checkId))}):r.status===`pass`||r.status===`skip`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.securityAuditNoFindings}):null,t[28]=r.findings,t[29]=r.status,t[30]=n,t[31]=_):_=t[31];let v;t[32]!==r.hints||t[33]!==n?(v=r.hints.length>0?(0,$.jsxs)(`div`,{className:`space-y-1 border-t border-edge pt-3`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:n.securityAuditHintsTitle}),(0,$.jsx)(`ul`,{className:`space-y-1 text-xs text-fg-subtle`,children:r.hints.map(Ss)})]}):null,t[32]=r.hints,t[33]=n,t[34]=v):v=t[34];let y;return t[35]!==g||t[36]!==_||t[37]!==v||t[38]!==u?(y=(0,$.jsxs)(`div`,{className:u,children:[g,_,v]}),t[35]=g,t[36]=_,t[37]=v,t[38]=u,t[39]=y):y=t[39],y}function Ss(e){return(0,$.jsx)(`li`,{className:`font-mono`,children:e},e)}function Cs(e){let t=(0,Q.c)(31),{g:n,finding:r}=e,i,a,o,s;if(t[0]!==r.severity){let e=ws(r.severity);s=`rounded-lg border border-edge bg-surface-panel/50 px-3 py-2.5`,o=`flex items-start gap-2`,i=e.icon,a=J(`mt-0.5 size-4 shrink-0`,e.iconClass),t[0]=r.severity,t[1]=i,t[2]=a,t[3]=o,t[4]=s}else i=t[1],a=t[2],o=t[3],s=t[4];let c;t[5]!==i||t[6]!==a?(c=(0,$.jsx)(i,{className:a,"aria-hidden":!0}),t[5]=i,t[6]=a,t[7]=c):c=t[7];let l;t[8]===r.title?l=t[9]:(l=(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r.title}),t[8]=r.title,t[9]=l);let u;t[10]===r.checkId?u=t[11]:(u=(0,$.jsx)(`span`,{className:`font-mono text-[0.65rem] text-fg-subtle`,children:r.checkId}),t[10]=r.checkId,t[11]=u);let d;t[12]!==l||t[13]!==u?(d=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[l,u]}),t[12]=l,t[13]=u,t[14]=d):d=t[14];let f;t[15]===r.detail?f=t[16]:(f=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:r.detail}),t[15]=r.detail,t[16]=f);let p;t[17]!==r.remediation||t[18]!==n?(p=r.remediation?(0,$.jsxs)(`p`,{className:`mt-1.5 text-xs text-fg-subtle`,children:[(0,$.jsx)(`span`,{className:`text-fg-muted`,children:n.securityAuditRemediation}),` `,r.remediation]}):null,t[17]=r.remediation,t[18]=n,t[19]=p):p=t[19];let m;t[20]!==d||t[21]!==f||t[22]!==p?(m=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[d,f,p]}),t[20]=d,t[21]=f,t[22]=p,t[23]=m):m=t[23];let h;t[24]!==m||t[25]!==o||t[26]!==c?(h=(0,$.jsxs)(`div`,{className:o,children:[c,m]}),t[24]=m,t[25]=o,t[26]=c,t[27]=h):h=t[27];let g;return t[28]!==h||t[29]!==s?(g=(0,$.jsx)(`li`,{className:s,children:h}),t[28]=h,t[29]=s,t[30]=g):g=t[30],g}function ws(e){switch(e){case`critical`:return{icon:ut,iconClass:`text-red-600 dark:text-red-400`};case`warn`:return{icon:Jt,iconClass:`text-amber-600 dark:text-amber-400`};default:return{icon:Le,iconClass:`text-fg-muted`}}}function Ts(e,t,n){let r=n.filter(e=>e.severity===`critical`).length,i=n.filter(e=>e.severity===`warn`).length;return t===`fail`||r>0?{icon:ut,iconClass:`text-red-600 dark:text-red-400`,title:e.securityAuditStatusFail,bannerClass:`border-red-200 bg-red-50 text-red-950 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-100`}:t===`warn`||i>0?{icon:Jt,iconClass:`text-amber-600 dark:text-amber-400`,title:e.securityAuditStatusWarn,bannerClass:`border-amber-200 bg-amber-50 text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`}:t===`skip`?{icon:Le,iconClass:`text-fg-muted`,title:e.securityAuditStatusSkip,bannerClass:`border-edge bg-surface-panel/60 text-fg`}:{icon:nn,iconClass:`text-emerald-600 dark:text-emerald-400`,title:e.securityAuditStatusPass,bannerClass:`border-emerald-200 bg-emerald-50 text-emerald-950 dark:border-emerald-900/50 dark:bg-emerald-950/40 dark:text-emerald-100`}}function Es(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ht,`dark:border-edge`)}var Ds=[`network`,`access`,`updates`,`security`,`advanced`],Os={network:it,access:qt,updates:Ze,security:Me,advanced:ae};function ks(e){return e&&Ds.includes(e)?e:`network`}function As(e,t){return t===`network`?e.tabNetwork:t===`access`?e.tabAccess:t===`updates`?e.tabUpdates:t===`security`?e.tabSecurity:e.tabAdvanced}function js(e,t){return t===`network`?e.networkTabHint:t===`access`?e.accessTabHint:t===`updates`?e.updatesTabHint:t===`security`?e.securitySectionHint:e.advancedSectionHint}function Ms(e,t){switch(t.type){case`reset`:return{form:null,baseline:null,appliedBaseline:null};case`init-applied`:return{...e,appliedBaseline:structuredClone(t.value)};case`sync`:{let n=structuredClone(t.value);return{form:n,baseline:structuredClone(n),appliedBaseline:e.appliedBaseline}}case`set-form`:return e.form?{...e,form:t.updater(e.form)}:e;case`discard`:return e.baseline?{...e,form:structuredClone(e.baseline)}:e;case`saved`:{let n=structuredClone(t.value);return{form:n,baseline:structuredClone(n),appliedBaseline:e.appliedBaseline}}}}var Ns={saving:!1,error:null,saveOk:!1,auditRefreshToken:0,restarting:!1,restartConfirmOpen:!1};function Ps(){let e=a(e=>e.language),t=s(e),n=t.gatewaySettings,[r,i]=Zt(),o=ks(r.get(`tab`)),c=(0,Z.useCallback)(e=>{i(t=>{let n=new URLSearchParams(t);return e===`network`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},[i]),l=C(e=>e.token),u=C(e=>e.tokenExpired),d=C(e=>e.openTokenDialog),f=!!l,[p,m]=(0,Z.useReducer)(Ms,{form:null,baseline:null,appliedBaseline:null}),h=p.form,g=p.baseline,_=p.appliedBaseline,[v,y]=(0,Z.useReducer)(Lt,Ns),{saving:b,error:x,saveOk:S,auditRefreshToken:w,restarting:T,restartConfirmOpen:D}=v,O=(0,Z.useRef)(!1),k=(0,Z.useRef)(null),A=(0,Z.useRef)(!1),{data:j,error:M,isLoading:N,mutate:P}=Fe(f),F=(0,Z.useMemo)(()=>j?.payload?.config===void 0?null:structuredClone(On(j.payload.config)),[j]);f?F!==null&&(A.current||(A.current=!0,m({type:`init-applied`,value:F})),!O.current&&k.current!==F&&(k.current=F,m({type:`sync`,value:F}),y({type:`patch`,patch:{saveOk:!1}}))):(k.current!==null||A.current)&&(k.current=null,A.current=!1,m({type:`reset`}),O.current=!1);let I=!!(f&&N&&j===void 0&&!M),L=M instanceof Error?M.message:M?String(M):null,R=(0,Z.useMemo)(()=>!h||!g?!1:JSON.stringify(h)!==JSON.stringify(g),[h,g]),z=(0,Z.useMemo)(()=>!g||!_?!1:Nn(_,g),[_,g]),B=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,auth:{...t.auth,...e}})})},[]),V=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,updateChannel:e})})},[]),ee=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,corsOrigins:e})})},[]),H=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,bind:e})})},[]),U=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,customBindHost:e,bind:`custom`})})},[]),W=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,port:e})})},[]),te=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,auth:{...t.auth,rateLimit:{...t.auth.rateLimit,...e}}})})},[]),G=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,maxSseConnections:e})})},[]),ne=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,channelConnectDeferMode:e})})},[]),re=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,channelConnectDeferIds:e})})},[]),ie=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,channelConnectDeferSkipIds:e})})},[]),ae=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,trustedProxies:e})})},[]),oe=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,auth:{...t.auth,trustedProxy:{...t.auth.trustedProxy,...e}}})})},[]),se=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,securityStrict:e})})},[]),ce=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,allowRealIpFallback:e})})},[]),le=(0,Z.useCallback)(e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,dangerouslyAllowHostHeaderOriginFallback:e})})},[]),ue=(0,Z.useCallback)(async()=>{if(!h||b)return;let e=Pn(h);if(e){y({type:`patch`,patch:{error:e}});return}y({type:`patch`,patch:{saving:!0,error:null,saveOk:!1}});try{await wn(h),O.current=!1,m({type:`saved`,value:h}),y({type:`patch`,patch:{saveOk:!0,auditRefreshToken:w+1}}),window.setTimeout(()=>y({type:`patch`,patch:{saveOk:!1}}),2500)}catch(e){y({type:`patch`,patch:{error:e instanceof Error?e.message:n.saveError}})}finally{y({type:`patch`,patch:{saving:!1}})}},[h,b,n.saveError]),de=(0,Z.useCallback)(()=>{g&&(O.current=!1,m({type:`discard`}),y({type:`patch`,patch:{error:null,saveOk:!1}}))},[g]),pe=E(n),me=(0,Z.useCallback)(async()=>{if(!T){y({type:`patch`,patch:{restarting:!0,restartConfirmOpen:!1}});try{let e=await rt();e.ok?window.dispatchEvent(new Event(`gateway-restart-initiated`)):window.dispatchEvent(new CustomEvent(`extension-notification`,{detail:{type:`error`,title:n.restartGatewayFailed,message:e.message??``}}))}catch(e){window.dispatchEvent(new CustomEvent(`extension-notification`,{detail:{type:`error`,title:n.restartGatewayFailed,message:e instanceof Error?e.message:String(e)}}))}finally{y({type:`patch`,patch:{restarting:!1}})}}},[T,n.restartGatewayFailed]);return f?I?(0,$.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),n.loading]})}):h?(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,$.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.gateway}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,$.jsxs)(`a`,{href:Rt(e,`gateway`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,$.jsx)(fe,{className:`size-3.5`})]})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[S?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!R||b,onClick:de,children:n.discard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!R||b,onClick:()=>void ue(),children:b?n.saving:n.save})]})]}),u?(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-red-200 bg-red-50 px-4 py-3 dark:border-red-900/50 dark:bg-red-950/40`,role:`alert`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(ut,{className:`mt-0.5 size-4 shrink-0 text-red-600 dark:text-red-400`}),(0,$.jsx)(`p`,{className:`text-sm text-red-900 dark:text-red-100`,children:n.tokenExpired})]}),(0,$.jsx)(`div`,{children:(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>d(),children:n.updateToken})})]}):null,R?(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,x?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:x}):null,z?(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 dark:border-amber-800 dark:bg-amber-950/40`,children:[(0,$.jsx)(`p`,{className:`text-xs text-amber-950 dark:text-amber-100`,children:n.restartHint}),(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`shrink-0 gap-1.5 border-red-300 bg-red-50 text-xs text-red-700 hover:bg-red-100 dark:border-red-800 dark:bg-red-950/50 dark:text-red-300 dark:hover:bg-red-900/60`,disabled:T,onClick:()=>y({type:`patch`,patch:{restartConfirmOpen:!0}}),children:[T?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):(0,$.jsx)(Ye,{className:`size-3.5`}),n.restartGatewayButton]})]}):null,(0,$.jsx)(Ht,{open:D,title:n.restartGatewayButton,description:n.restartGatewayConfirm,confirmLabel:n.restartGatewayButton,cancelLabel:n.discard,destructive:!0,onConfirm:()=>void me(),onCancel:()=>y({type:`patch`,patch:{restartConfirmOpen:!1}})}),(0,$.jsx)(Fs,{g:n,activeTab:o,onChange:c}),(0,$.jsxs)(Is,{g:n,id:`network`,activeTab:o,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-bind-mode`,children:n.bindMode}),(0,$.jsxs)(`select`,{id:`gateway-bind-mode`,className:Es(),value:h.bind,onChange:e=>H(e.target.value),children:[(0,$.jsx)(`option`,{value:`loopback`,children:n.bindLoopback}),(0,$.jsx)(`option`,{value:`lan`,children:n.bindLan}),(0,$.jsx)(`option`,{value:`auto`,children:n.bindAuto}),(0,$.jsx)(`option`,{value:`custom`,children:n.bindCustom}),(0,$.jsx)(`option`,{value:`tailnet`,children:n.bindTailnet})]})]}),h.bind===`custom`?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-custom-bind-host`,children:n.customBindHost}),(0,$.jsx)(`input`,{id:`gateway-custom-bind-host`,className:J(Es(),`font-mono text-xs`),value:h.customBindHost,onChange:e=>U(e.target.value),placeholder:n.customBindHostPlaceholder,autoComplete:`off`})]}):null,(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-listen-port`,children:n.listenPort}),(0,$.jsx)(`input`,{id:`gateway-listen-port`,type:`number`,min:1,max:65535,className:J(Es(),`font-mono text-xs`),value:h.port,onChange:e=>{let t=Number(e.target.value);W(Number.isFinite(t)?Math.max(1,Math.min(65535,Math.floor(t))):h.port)}})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:n.listenHint})]}),(0,$.jsx)(Vs,{g:n,origins:h.corsOrigins,onChange:ee})]}),(0,$.jsxs)(Is,{g:n,id:`access`,activeTab:o,children:[h.auth.mode===`none`?(0,$.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:n.authModeNone}):null,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-auth-mode`,children:n.authMode}),(0,$.jsxs)(`select`,{id:`gateway-auth-mode`,value:h.auth.mode,onChange:e=>B({mode:e.target.value}),className:Es(),children:[(0,$.jsx)(`option`,{value:`token`,children:n.authModeToken}),(0,$.jsx)(`option`,{value:`password`,children:n.authModePassword}),(0,$.jsx)(`option`,{value:`trusted-proxy`,children:n.authModeTrustedProxy}),(0,$.jsx)(`option`,{value:`none`,children:n.authModeNoneLabel})]})]}),h.auth.mode===`trusted-proxy`?(0,$.jsx)(Rs,{g:n,form:h,onTrustedProxyChange:oe,onTrustedProxiesChange:ae,onAllowRealIpFallbackChange:ce}):null,h.auth.mode===`token`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Us,{id:`gateway-access-token`,label:n.accessToken,help:n.tokenHelp,placeholder:n.tokenPlaceholder,value:h.auth.token,labels:pe,reveal:()=>jn(`token`).then(e=>e.secret),loadFailedLabel:n.saveError,onChange:e=>B({token:e})}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>d(),children:n.changeToken})]}):null,h.auth.mode===`password`?(0,$.jsx)(Us,{id:`gateway-auth-password`,label:n.authPassword,help:n.authPasswordHelp,placeholder:n.authPasswordPlaceholder,value:h.auth.password,labels:pe,reveal:()=>jn(`password`).then(e=>e.secret),loadFailedLabel:n.saveError,onChange:e=>B({password:e})}):null,h.auth.mode===`none`?null:(0,$.jsx)(Hs,{g:n,rateLimit:h.auth.rateLimit,onChange:te})]}),(0,$.jsxs)(Is,{g:n,id:`updates`,activeTab:o,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-update-channel`,children:n.updateChannel}),(0,$.jsxs)(`select`,{id:`gateway-update-channel`,value:h.updateChannel,onChange:e=>V(e.target.value),className:Es(),children:[(0,$.jsx)(`option`,{value:`stable`,children:n.channelStable}),(0,$.jsx)(`option`,{value:`beta`,children:n.channelBeta}),(0,$.jsx)(`option`,{value:`dev`,children:n.channelDev})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateChannelHint})]}),(0,$.jsxs)(`div`,{className:`space-y-4 border-t border-edge pt-4`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.updateAutoSection}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateAutoSectionHint}),(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:h.updateCheckOnStart,onChange:e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,updateCheckOnStart:e.target.checked})})}}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:n.updateCheckOnStart}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.updateCheckOnStartHint})]})]}),(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:h.updateAutoEnabled,onChange:e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,updateAutoEnabled:e.target.checked})})}}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:n.updateAutoEnabled}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.updateAutoEnabledHint})]})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`update-auto-stable-delay`,children:n.updateAutoStableDelayHours}),(0,$.jsx)(`input`,{id:`update-auto-stable-delay`,type:`number`,min:0,disabled:!h.updateAutoEnabled,className:Es(),value:h.updateAutoStableDelayHours,onChange:e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,updateAutoStableDelayHours:Math.max(0,Math.floor(Number(e.target.value)||0))})})}}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.updateAutoStableDelayHoursHint})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`update-auto-stable-jitter`,children:n.updateAutoStableJitterHours}),(0,$.jsx)(`input`,{id:`update-auto-stable-jitter`,type:`number`,min:0,disabled:!h.updateAutoEnabled,className:Es(),value:h.updateAutoStableJitterHours,onChange:e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,updateAutoStableJitterHours:Math.max(0,Math.floor(Number(e.target.value)||0))})})}}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.updateAutoStableJitterHoursHint})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`update-auto-beta-interval`,children:n.updateAutoBetaCheckIntervalHours}),(0,$.jsx)(`input`,{id:`update-auto-beta-interval`,type:`number`,min:.25,step:.25,disabled:!h.updateAutoEnabled,className:Es(),value:h.updateAutoBetaCheckIntervalHours,onChange:e=>{O.current=!0,m({type:`set-form`,updater:t=>({...t,updateAutoBetaCheckIntervalHours:Math.max(.25,Number(e.target.value)||1)})})}}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.updateAutoBetaCheckIntervalHoursHint})]})]})]})]}),(0,$.jsxs)(Is,{g:n,id:`security`,activeTab:o,children:[(0,$.jsx)(vs,{enabled:f,refreshToken:w}),(0,$.jsx)(Ls,{g:n,form:h,onSecurityStrictChange:se,onDangerouslyAllowHostHeaderOriginFallbackChange:le})]}),(0,$.jsx)(Is,{g:n,id:`advanced`,activeTab:o,children:(0,$.jsx)(zs,{g:n,form:h,onMaxSseConnectionsChange:G,onDeferModeChange:ne,onDeferIdsChange:re,onSkipIdsChange:ie})})]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:x??L??n.loadError}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:()=>void P(),children:n.retry})]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.gateway}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Fs(e){let t=(0,Q.c)(11),{g:n,activeTab:r,onChange:i}=e,a=n.tabsAriaLabel,o;t[0]!==r||t[1]!==i?(o=e=>{e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||(e.preventDefault(),i(Ds[(Ds.indexOf(r)+(e.key===`ArrowRight`?1:-1)+Ds.length)%Ds.length]))},t[0]=r,t[1]=i,t[2]=o):o=t[2];let s;t[3]!==r||t[4]!==n||t[5]!==i?(s=Ds.map(e=>{let t=Os[e],a=e===r;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":a,"aria-controls":`gateway-settings-panel-${e}`,id:`gateway-settings-tab-${e}`,className:J(`inline-flex shrink-0 items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.press,a?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>i(e),children:[(0,$.jsx)(t,{className:`size-3.5 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:As(n,e)})]},e)}),t[3]=r,t[4]=n,t[5]=i,t[6]=s):s=t[6];let c;return t[7]!==n.tabsAriaLabel||t[8]!==o||t[9]!==s?(c=(0,$.jsx)(`nav`,{"aria-label":a,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,role:`tablist`,onKeyDown:o,children:s}),t[7]=n.tabsAriaLabel,t[8]=o,t[9]=s,t[10]=c):c=t[10],c}function Is(e){let t=(0,Q.c)(20),{g:n,id:r,activeTab:i,children:a}=e;if(i!==r)return null;let o=`gateway-settings-panel-${r}`,s=`gateway-settings-tab-${r}`,c;t[0]!==n||t[1]!==r?(c=As(n,r),t[0]=n,t[1]=r,t[2]=c):c=t[2];let l;t[3]===c?l=t[4]:(l=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:c}),t[3]=c,t[4]=l);let u;t[5]!==n||t[6]!==r?(u=js(n,r),t[5]=n,t[6]=r,t[7]=u):u=t[7];let d;t[8]===u?d=t[9]:(d=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:u}),t[8]=u,t[9]=d);let f;t[10]!==l||t[11]!==d?(f=(0,$.jsxs)(`div`,{className:`mb-5`,children:[l,d]}),t[10]=l,t[11]=d,t[12]=f):f=t[12];let p;t[13]===a?p=t[14]:(p=(0,$.jsx)(`div`,{className:`space-y-4`,children:a}),t[13]=a,t[14]=p);let m;return t[15]!==o||t[16]!==s||t[17]!==f||t[18]!==p?(m=(0,$.jsxs)(`section`,{id:o,role:`tabpanel`,"aria-labelledby":s,className:`rounded-2xl border border-edge bg-surface-base px-4 py-5 sm:px-5`,children:[f,p]}),t[15]=o,t[16]=s,t[17]=f,t[18]=p,t[19]=m):m=t[19],m}function Ls(e){let t=(0,Q.c)(37),{g:n,form:r,onSecurityStrictChange:i,onDangerouslyAllowHostHeaderOriginFallbackChange:a}=e,o;t[0]===i?o=t[1]:(o=e=>i(e.target.checked),t[0]=i,t[1]=o);let s;t[2]!==r.securityStrict||t[3]!==o?(s=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:r.securityStrict,onChange:o}),t[2]=r.securityStrict,t[3]=o,t[4]=s):s=t[4];let c;t[5]===n.securityStrict?c=t[6]:(c=(0,$.jsx)(`span`,{className:`font-medium`,children:n.securityStrict}),t[5]=n.securityStrict,t[6]=c);let l;t[7]===n.securityStrictHint?l=t[8]:(l=(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.securityStrictHint}),t[7]=n.securityStrictHint,t[8]=l);let u;t[9]!==c||t[10]!==l?(u=(0,$.jsxs)(`span`,{children:[c,l]}),t[9]=c,t[10]=l,t[11]=u):u=t[11];let d;t[12]!==s||t[13]!==u?(d=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[s,u]}),t[12]=s,t[13]=u,t[14]=d):d=t[14];let f;t[15]===a?f=t[16]:(f=e=>a(e.target.checked),t[15]=a,t[16]=f);let p;t[17]!==r.dangerouslyAllowHostHeaderOriginFallback||t[18]!==f?(p=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:r.dangerouslyAllowHostHeaderOriginFallback,onChange:f}),t[17]=r.dangerouslyAllowHostHeaderOriginFallback,t[18]=f,t[19]=p):p=t[19];let m;t[20]===n.dangerouslyAllowHostHeaderOriginFallback?m=t[21]:(m=(0,$.jsx)(`span`,{className:`font-medium`,children:n.dangerouslyAllowHostHeaderOriginFallback}),t[20]=n.dangerouslyAllowHostHeaderOriginFallback,t[21]=m);let h;t[22]===n.dangerouslyAllowHostHeaderOriginFallbackHint?h=t[23]:(h=(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.dangerouslyAllowHostHeaderOriginFallbackHint}),t[22]=n.dangerouslyAllowHostHeaderOriginFallbackHint,t[23]=h);let g;t[24]!==h||t[25]!==m?(g=(0,$.jsxs)(`span`,{children:[m,h]}),t[24]=h,t[25]=m,t[26]=g):g=t[26];let _;t[27]!==g||t[28]!==p?(_=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[p,g]}),t[27]=g,t[28]=p,t[29]=_):_=t[29];let v;t[30]!==r.dangerouslyAllowHostHeaderOriginFallback||t[31]!==n.dangerouslyAllowHostHeaderOriginFallbackWarning?(v=r.dangerouslyAllowHostHeaderOriginFallback?(0,$.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:n.dangerouslyAllowHostHeaderOriginFallbackWarning}):null,t[30]=r.dangerouslyAllowHostHeaderOriginFallback,t[31]=n.dangerouslyAllowHostHeaderOriginFallbackWarning,t[32]=v):v=t[32];let y;return t[33]!==_||t[34]!==v||t[35]!==d?(y=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[d,_,v]}),t[33]=_,t[34]=v,t[35]=d,t[36]=y):y=t[36],y}function Rs(e){let t=(0,Q.c)(80),{g:n,form:r,onTrustedProxyChange:i,onTrustedProxiesChange:a,onAllowRealIpFallbackChange:o}=e,s=r.auth.trustedProxy,c;t[0]===n.authModeTrustedProxyHint?c=t[1]:(c=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.authModeTrustedProxyHint}),t[0]=n.authModeTrustedProxyHint,t[1]=c);let l;t[2]===n.trustedProxyUserHeader?l=t[3]:(l=(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-trusted-proxy-user-header`,children:n.trustedProxyUserHeader}),t[2]=n.trustedProxyUserHeader,t[3]=l);let u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=J(Es(),`font-mono text-xs`),t[4]=u):u=t[4];let d;t[5]===i?d=t[6]:(d=e=>i({userHeader:e.target.value}),t[5]=i,t[6]=d);let f;t[7]!==n.trustedProxyUserHeaderPlaceholder||t[8]!==d||t[9]!==s.userHeader?(f=(0,$.jsx)(`input`,{id:`gateway-trusted-proxy-user-header`,className:u,value:s.userHeader,onChange:d,placeholder:n.trustedProxyUserHeaderPlaceholder,autoComplete:`off`}),t[7]=n.trustedProxyUserHeaderPlaceholder,t[8]=d,t[9]=s.userHeader,t[10]=f):f=t[10];let p;t[11]===n.trustedProxyUserHeaderHint?p=t[12]:(p=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.trustedProxyUserHeaderHint}),t[11]=n.trustedProxyUserHeaderHint,t[12]=p);let m;t[13]!==l||t[14]!==f||t[15]!==p?(m=(0,$.jsxs)(`div`,{children:[l,f,p]}),t[13]=l,t[14]=f,t[15]=p,t[16]=m):m=t[16];let h;t[17]===i?h=t[18]:(h=e=>i({requiredHeaders:e}),t[17]=i,t[18]=h);let g;t[19]!==n.channelIdListEmpty||t[20]!==n.trustedProxyRequiredHeaders||t[21]!==n.trustedProxyRequiredHeadersHint||t[22]!==n.trustedProxyUserHeaderPlaceholder||t[23]!==h||t[24]!==s.requiredHeaders?(g=(0,$.jsx)(Bs,{title:n.trustedProxyRequiredHeaders,hint:n.trustedProxyRequiredHeadersHint,emptyText:n.channelIdListEmpty,placeholder:n.trustedProxyUserHeaderPlaceholder,values:s.requiredHeaders,maxItems:32,onChange:h}),t[19]=n.channelIdListEmpty,t[20]=n.trustedProxyRequiredHeaders,t[21]=n.trustedProxyRequiredHeadersHint,t[22]=n.trustedProxyUserHeaderPlaceholder,t[23]=h,t[24]=s.requiredHeaders,t[25]=g):g=t[25];let _;t[26]===i?_=t[27]:(_=e=>i({allowUsers:e}),t[26]=i,t[27]=_);let v;t[28]!==n.channelIdListEmpty||t[29]!==n.trustedProxyAllowUsers||t[30]!==n.trustedProxyAllowUsersHint||t[31]!==n.trustedProxyUserHeaderPlaceholder||t[32]!==_||t[33]!==s.allowUsers?(v=(0,$.jsx)(Bs,{title:n.trustedProxyAllowUsers,hint:n.trustedProxyAllowUsersHint,emptyText:n.channelIdListEmpty,placeholder:n.trustedProxyUserHeaderPlaceholder,values:s.allowUsers,maxItems:128,onChange:_}),t[28]=n.channelIdListEmpty,t[29]=n.trustedProxyAllowUsers,t[30]=n.trustedProxyAllowUsersHint,t[31]=n.trustedProxyUserHeaderPlaceholder,t[32]=_,t[33]=s.allowUsers,t[34]=v):v=t[34];let y;t[35]===i?y=t[36]:(y=e=>i({allowLoopback:e.target.checked}),t[35]=i,t[36]=y);let b;t[37]!==y||t[38]!==s.allowLoopback?(b=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:s.allowLoopback,onChange:y}),t[37]=y,t[38]=s.allowLoopback,t[39]=b):b=t[39];let x;t[40]===n.trustedProxyAllowLoopback?x=t[41]:(x=(0,$.jsx)(`span`,{className:`font-medium`,children:n.trustedProxyAllowLoopback}),t[40]=n.trustedProxyAllowLoopback,t[41]=x);let S;t[42]===n.trustedProxyAllowLoopbackHint?S=t[43]:(S=(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.trustedProxyAllowLoopbackHint}),t[42]=n.trustedProxyAllowLoopbackHint,t[43]=S);let C;t[44]!==x||t[45]!==S?(C=(0,$.jsxs)(`span`,{children:[x,S]}),t[44]=x,t[45]=S,t[46]=C):C=t[46];let w;t[47]!==b||t[48]!==C?(w=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[b,C]}),t[47]=b,t[48]=C,t[49]=w):w=t[49];let T;t[50]!==r.trustedProxies||t[51]!==n.trustedProxies||t[52]!==n.trustedProxiesEmpty||t[53]!==n.trustedProxiesHint||t[54]!==n.trustedProxiesPlaceholder||t[55]!==a?(T=(0,$.jsx)(Bs,{title:n.trustedProxies,hint:n.trustedProxiesHint,emptyText:n.trustedProxiesEmpty,placeholder:n.trustedProxiesPlaceholder,values:r.trustedProxies,maxItems:64,onChange:a}),t[50]=r.trustedProxies,t[51]=n.trustedProxies,t[52]=n.trustedProxiesEmpty,t[53]=n.trustedProxiesHint,t[54]=n.trustedProxiesPlaceholder,t[55]=a,t[56]=T):T=t[56];let E;t[57]===o?E=t[58]:(E=e=>o(e.target.checked),t[57]=o,t[58]=E);let D;t[59]!==r.allowRealIpFallback||t[60]!==E?(D=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:r.allowRealIpFallback,onChange:E}),t[59]=r.allowRealIpFallback,t[60]=E,t[61]=D):D=t[61];let O;t[62]===n.allowRealIpFallback?O=t[63]:(O=(0,$.jsx)(`span`,{className:`font-medium`,children:n.allowRealIpFallback}),t[62]=n.allowRealIpFallback,t[63]=O);let k;t[64]===n.allowRealIpFallbackHint?k=t[65]:(k=(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:n.allowRealIpFallbackHint}),t[64]=n.allowRealIpFallbackHint,t[65]=k);let A;t[66]!==O||t[67]!==k?(A=(0,$.jsxs)(`span`,{children:[O,k]}),t[66]=O,t[67]=k,t[68]=A):A=t[68];let j;t[69]!==D||t[70]!==A?(j=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[D,A]}),t[69]=D,t[70]=A,t[71]=j):j=t[71];let M;return t[72]!==c||t[73]!==v||t[74]!==w||t[75]!==T||t[76]!==j||t[77]!==m||t[78]!==g?(M=(0,$.jsxs)(`div`,{className:`space-y-4 border-t border-edge pt-4`,children:[c,m,g,v,w,T,j]}),t[72]=c,t[73]=v,t[74]=w,t[75]=T,t[76]=j,t[77]=m,t[78]=g,t[79]=M):M=t[79],M}function zs(e){let t=(0,Q.c)(58),{g:n,form:r,onMaxSseConnectionsChange:i,onDeferModeChange:a,onDeferIdsChange:o,onSkipIdsChange:s}=e,c;t[0]===n.maxSseConnections?c=t[1]:(c=(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-max-sse`,children:n.maxSseConnections}),t[0]=n.maxSseConnections,t[1]=c);let l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=J(Es(),`max-w-xs font-mono text-xs`),t[2]=l):l=t[2];let u;t[3]===i?u=t[4]:(u=e=>{let t=Number(e.target.value);Number.isFinite(t)&&i(Math.max(1,Math.floor(t)))},t[3]=i,t[4]=u);let d;t[5]!==r.maxSseConnections||t[6]!==u?(d=(0,$.jsx)(`input`,{id:`gateway-max-sse`,type:`number`,min:1,className:l,value:r.maxSseConnections,onChange:u}),t[5]=r.maxSseConnections,t[6]=u,t[7]=d):d=t[7];let f;t[8]===n.maxSseConnectionsHint?f=t[9]:(f=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.maxSseConnectionsHint}),t[8]=n.maxSseConnectionsHint,t[9]=f);let p;t[10]!==c||t[11]!==d||t[12]!==f?(p=(0,$.jsxs)(`div`,{children:[c,d,f]}),t[10]=c,t[11]=d,t[12]=f,t[13]=p):p=t[13];let m;t[14]===n.channelConnectDeferMode?m=t[15]:(m=(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-channel-defer-mode`,children:n.channelConnectDeferMode}),t[14]=n.channelConnectDeferMode,t[15]=m);let h=r.channelConnectDeferMode,g;t[16]===a?g=t[17]:(g=e=>a(e.target.value),t[16]=a,t[17]=g);let _;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(_=Es(),t[18]=_):_=t[18];let v;t[19]===n.channelConnectDeferModeAuto?v=t[20]:(v=(0,$.jsx)(`option`,{value:`auto`,children:n.channelConnectDeferModeAuto}),t[19]=n.channelConnectDeferModeAuto,t[20]=v);let y;t[21]===n.channelConnectDeferModeOff?y=t[22]:(y=(0,$.jsx)(`option`,{value:`off`,children:n.channelConnectDeferModeOff}),t[21]=n.channelConnectDeferModeOff,t[22]=y);let b;t[23]===n.channelConnectDeferModeExplicit?b=t[24]:(b=(0,$.jsx)(`option`,{value:`explicit`,children:n.channelConnectDeferModeExplicit}),t[23]=n.channelConnectDeferModeExplicit,t[24]=b);let x;t[25]!==r.channelConnectDeferMode||t[26]!==v||t[27]!==y||t[28]!==b||t[29]!==g?(x=(0,$.jsxs)(`select`,{id:`gateway-channel-defer-mode`,value:h,onChange:g,className:_,children:[v,y,b]}),t[25]=r.channelConnectDeferMode,t[26]=v,t[27]=y,t[28]=b,t[29]=g,t[30]=x):x=t[30];let S;t[31]===n.channelConnectDeferModeHint?S=t[32]:(S=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.channelConnectDeferModeHint}),t[31]=n.channelConnectDeferModeHint,t[32]=S);let C;t[33]!==x||t[34]!==S||t[35]!==m?(C=(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[m,x,S]}),t[33]=x,t[34]=S,t[35]=m,t[36]=C):C=t[36];let w;t[37]!==r.channelConnectDeferIds||t[38]!==r.channelConnectDeferMode||t[39]!==n.channelConnectDeferIds||t[40]!==n.channelConnectDeferIdsHint||t[41]!==n.channelIdListEmpty||t[42]!==n.channelIdListPlaceholder||t[43]!==o?(w=r.channelConnectDeferMode===`explicit`?(0,$.jsx)(Bs,{title:n.channelConnectDeferIds,hint:n.channelConnectDeferIdsHint,emptyText:n.channelIdListEmpty,placeholder:n.channelIdListPlaceholder,values:r.channelConnectDeferIds,maxItems:24,onChange:o}):null,t[37]=r.channelConnectDeferIds,t[38]=r.channelConnectDeferMode,t[39]=n.channelConnectDeferIds,t[40]=n.channelConnectDeferIdsHint,t[41]=n.channelIdListEmpty,t[42]=n.channelIdListPlaceholder,t[43]=o,t[44]=w):w=t[44];let T;t[45]!==r.channelConnectDeferMode||t[46]!==r.channelConnectDeferSkipIds||t[47]!==n.channelConnectDeferSkipIds||t[48]!==n.channelConnectDeferSkipIdsHint||t[49]!==n.channelIdListEmpty||t[50]!==n.channelIdListPlaceholder||t[51]!==s?(T=r.channelConnectDeferMode===`off`?null:(0,$.jsx)(Bs,{title:n.channelConnectDeferSkipIds,hint:n.channelConnectDeferSkipIdsHint,emptyText:n.channelIdListEmpty,placeholder:n.channelIdListPlaceholder,values:r.channelConnectDeferSkipIds,maxItems:24,onChange:s}),t[45]=r.channelConnectDeferMode,t[46]=r.channelConnectDeferSkipIds,t[47]=n.channelConnectDeferSkipIds,t[48]=n.channelConnectDeferSkipIdsHint,t[49]=n.channelIdListEmpty,t[50]=n.channelIdListPlaceholder,t[51]=s,t[52]=T):T=t[52];let E;return t[53]!==C||t[54]!==w||t[55]!==T||t[56]!==p?(E=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[p,C,w,T]}),t[53]=C,t[54]=w,t[55]=T,t[56]=p,t[57]=E):E=t[57],E}function Bs(e){let t=(0,Q.c)(25),{title:n,hint:r,emptyText:i,placeholder:a,values:o,maxItems:s,onChange:c,children:l}=e,u;t[0]!==s||t[1]!==c||t[2]!==o?(u=e=>{let t=e.trim();!t||o.includes(t)||o.length>=s||c([...o,t])},t[0]=s,t[1]=c,t[2]=o,t[3]=u):u=t[3];let d=u,f;t[4]===n?f=t[5]:(f=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[4]=n,t[5]=f);let p;t[6]===r?p=t[7]:(p=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r}),t[6]=r,t[7]=p);let m;t[8]!==i||t[9]!==c||t[10]!==o?(m=o.length===0?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i}):(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:o.map(e=>(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-edge bg-surface-panel px-2 py-0.5 font-mono text-xs text-fg`,children:[e,(0,$.jsx)(`button`,{type:`button`,className:J(`text-fg-muted hover:text-fg`,K.press),"aria-label":`Remove ${e}`,onClick:()=>c(o.filter(t=>t!==e)),children:`×`})]},e))}),t[8]=i,t[9]=c,t[10]=o,t[11]=m):m=t[11];let h;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(h=J(Es(),`font-mono text-xs`),t[12]=h):h=t[12];let g=o.length>=s,_;t[13]===d?_=t[14]:(_=e=>{e.key===`Enter`&&(e.preventDefault(),d(e.target.value),e.target.value=``)},t[13]=d,t[14]=_);let v;t[15]!==a||t[16]!==g||t[17]!==_?(v=(0,$.jsx)(`input`,{className:h,placeholder:a,disabled:g,onKeyDown:_}),t[15]=a,t[16]=g,t[17]=_,t[18]=v):v=t[18];let y;return t[19]!==l||t[20]!==f||t[21]!==p||t[22]!==m||t[23]!==v?(y=(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[f,p,m,v,l]}),t[19]=l,t[20]=f,t[21]=p,t[22]=m,t[23]=v,t[24]=y):y=t[24],y}function Vs(e){let t=(0,Q.c)(13),{g:n,origins:r,onChange:i}=e,a;t[0]===r?a=t[1]:(a=r.includes(`*`),t[0]=r,t[1]=a);let o=a,s;t[2]!==n.corsOriginsWildcardWarning||t[3]!==o?(s=o?(0,$.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:n.corsOriginsWildcardWarning}):null,t[2]=n.corsOriginsWildcardWarning,t[3]=o,t[4]=s):s=t[4];let c;return t[5]!==n.corsOrigins||t[6]!==n.corsOriginsEmpty||t[7]!==n.corsOriginsHint||t[8]!==n.corsOriginsPlaceholder||t[9]!==i||t[10]!==r||t[11]!==s?(c=(0,$.jsx)(Bs,{title:n.corsOrigins,hint:n.corsOriginsHint,emptyText:n.corsOriginsEmpty,placeholder:n.corsOriginsPlaceholder,values:r,maxItems:128,onChange:i,children:s}),t[5]=n.corsOrigins,t[6]=n.corsOriginsEmpty,t[7]=n.corsOriginsHint,t[8]=n.corsOriginsPlaceholder,t[9]=i,t[10]=r,t[11]=s,t[12]=c):c=t[12],c}function Hs(e){let t=(0,Q.c)(73),{g:n,rateLimit:r,onChange:i}=e,a;t[0]===n.rateLimitTitle?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.rateLimitTitle}),t[0]=n.rateLimitTitle,t[1]=a);let o;t[2]===n.rateLimitHint?o=t[3]:(o=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.rateLimitHint}),t[2]=n.rateLimitHint,t[3]=o);let s;t[4]!==a||t[5]!==o?(s=(0,$.jsxs)(`div`,{children:[a,o]}),t[4]=a,t[5]=o,t[6]=s):s=t[6];let c;t[7]===i?c=t[8]:(c=e=>i({enabled:e.target.checked}),t[7]=i,t[8]=c);let l;t[9]!==r.enabled||t[10]!==c?(l=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,onChange:c}),t[9]=r.enabled,t[10]=c,t[11]=l):l=t[11];let u;t[12]!==n.rateLimitEnabled||t[13]!==l?(u=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[l,n.rateLimitEnabled]}),t[12]=n.rateLimitEnabled,t[13]=l,t[14]=u):u=t[14];let d=!r.enabled,f;t[15]===i?f=t[16]:(f=e=>i({exemptLoopback:e.target.checked}),t[15]=i,t[16]=f);let p;t[17]!==r.exemptLoopback||t[18]!==d||t[19]!==f?(p=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.exemptLoopback,disabled:d,onChange:f}),t[17]=r.exemptLoopback,t[18]=d,t[19]=f,t[20]=p):p=t[20];let m;t[21]!==n.rateLimitExemptLoopback||t[22]!==p?(m=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[p,n.rateLimitExemptLoopback]}),t[21]=n.rateLimitExemptLoopback,t[22]=p,t[23]=m):m=t[23];let h;t[24]===n.rateLimitMaxAttempts?h=t[25]:(h=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,htmlFor:`gateway-rate-max`,children:n.rateLimitMaxAttempts}),t[24]=n.rateLimitMaxAttempts,t[25]=h);let g;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(g=Es(),t[26]=g):g=t[26];let _=!r.enabled,v;t[27]===i?v=t[28]:(v=e=>{let t=Number(e.target.value);Number.isFinite(t)&&i({maxAttempts:Math.max(1,Math.floor(t))})},t[27]=i,t[28]=v);let y;t[29]!==r.maxAttempts||t[30]!==_||t[31]!==v?(y=(0,$.jsx)(`input`,{id:`gateway-rate-max`,type:`number`,min:1,className:g,value:r.maxAttempts,disabled:_,onChange:v}),t[29]=r.maxAttempts,t[30]=_,t[31]=v,t[32]=y):y=t[32];let b;t[33]!==h||t[34]!==y?(b=(0,$.jsxs)(`div`,{children:[h,y]}),t[33]=h,t[34]=y,t[35]=b):b=t[35];let x;t[36]===n.rateLimitWindowMinutes?x=t[37]:(x=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,htmlFor:`gateway-rate-window`,children:n.rateLimitWindowMinutes}),t[36]=n.rateLimitWindowMinutes,t[37]=x);let S;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(S=Es(),t[38]=S):S=t[38];let C;t[39]===r.windowMs?C=t[40]:(C=Math.round(r.windowMs/6e4),t[39]=r.windowMs,t[40]=C);let w=!r.enabled,T;t[41]===i?T=t[42]:(T=e=>{let t=Number(e.target.value);Number.isFinite(t)&&t>0&&i({windowMs:Math.floor(t)*6e4})},t[41]=i,t[42]=T);let E;t[43]!==C||t[44]!==w||t[45]!==T?(E=(0,$.jsx)(`input`,{id:`gateway-rate-window`,type:`number`,min:1,className:S,value:C,disabled:w,onChange:T}),t[43]=C,t[44]=w,t[45]=T,t[46]=E):E=t[46];let D;t[47]!==x||t[48]!==E?(D=(0,$.jsxs)(`div`,{children:[x,E]}),t[47]=x,t[48]=E,t[49]=D):D=t[49];let O;t[50]===n.rateLimitBlockMinutes?O=t[51]:(O=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,htmlFor:`gateway-rate-block`,children:n.rateLimitBlockMinutes}),t[50]=n.rateLimitBlockMinutes,t[51]=O);let k;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(k=Es(),t[52]=k):k=t[52];let A;t[53]===r.blockDurationMs?A=t[54]:(A=Math.round(r.blockDurationMs/6e4),t[53]=r.blockDurationMs,t[54]=A);let j=!r.enabled,M;t[55]===i?M=t[56]:(M=e=>{let t=Number(e.target.value);Number.isFinite(t)&&t>0&&i({blockDurationMs:Math.floor(t)*6e4})},t[55]=i,t[56]=M);let N;t[57]!==A||t[58]!==j||t[59]!==M?(N=(0,$.jsx)(`input`,{id:`gateway-rate-block`,type:`number`,min:1,className:k,value:A,disabled:j,onChange:M}),t[57]=A,t[58]=j,t[59]=M,t[60]=N):N=t[60];let P;t[61]!==O||t[62]!==N?(P=(0,$.jsxs)(`div`,{children:[O,N]}),t[61]=O,t[62]=N,t[63]=P):P=t[63];let F;t[64]!==b||t[65]!==D||t[66]!==P?(F=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[b,D,P]}),t[64]=b,t[65]=D,t[66]=P,t[67]=F):F=t[67];let I;return t[68]!==m||t[69]!==s||t[70]!==F||t[71]!==u?(I=(0,$.jsxs)(`div`,{className:`space-y-3 border-t border-edge pt-4`,children:[s,u,m,F]}),t[68]=m,t[69]=s,t[70]=F,t[71]=u,t[72]=I):I=t[72],I}function Us(e){let t=(0,Q.c)(17),{id:n,label:r,help:i,placeholder:a,value:o,labels:s,reveal:c,loadFailedLabel:l,onChange:u}=e,d;t[0]!==n||t[1]!==r?(d=(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:n,children:r}),t[0]=n,t[1]=r,t[2]=d):d=t[2];let f;t[3]!==n||t[4]!==s||t[5]!==l||t[6]!==u||t[7]!==a||t[8]!==c||t[9]!==o?(f=(0,$.jsx)(ft,{id:n,value:o,onChange:u,placeholder:a,labels:s,reveal:c,loadFailedLabel:l,inputClassName:`text-xs`}),t[3]=n,t[4]=s,t[5]=l,t[6]=u,t[7]=a,t[8]=c,t[9]=o,t[10]=f):f=t[10];let p;t[11]===i?p=t[12]:(p=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:i}),t[11]=i,t[12]=p);let m;return t[13]!==d||t[14]!==f||t[15]!==p?(m=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[d,f,p]}),t[13]=d,t[14]=f,t[15]=p,t[16]=m):m=t[16],m}function Ws(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ht,`dark:border-edge`)}function Gs(){return J(ct,jt)}var Ks=[`schedule`,`delivery`,`prompt`,`document`],qs={schedule:W,delivery:mt,prompt:F,document:ye};function Js(e){return e&&Ks.includes(e)?e:`schedule`}function Ys(e,t){return t===`schedule`?e.tabSchedule:t===`delivery`?e.tabDelivery:t===`prompt`?e.tabPrompt:e.tabDocument}function Xs(e,t){return t===`schedule`?e.scheduleTabHint:t===`delivery`?e.deliveryTabHint:t===`prompt`?e.promptTabHint:e.documentTabHint}function Zs(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`patch`:return{...e,form:e.form?{...e.form,...t.patch}:null};case`discard`:return e.baseline?{form:structuredClone(e.baseline),baseline:e.baseline}:e;case`saved`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}}}function Qs(e,t){switch(t.type){case`reset`:return{doc:``,baseline:``};case`sync`:return{doc:t.value,baseline:t.value};case`set`:return{...e,doc:t.value};case`discard`:return{...e,doc:e.baseline};case`saved`:return{doc:t.value,baseline:t.value}}}function $s(e){if(!e||typeof e!=`object`||Array.isArray(e))return``;let t=e.agents;if(!t||typeof t!=`object`||Array.isArray(t))return``;let n=t.defaults;if(!n||typeof n!=`object`||Array.isArray(n))return``;let r=n.workspace;return typeof r==`string`?r:``}var ec={saving:!1,error:null,triggerLoading:!1,triggerOk:!1,triggerError:null};function tc(){let e=a(e=>e.language),t=s(e),n=t.heartbeatSettings,r=!!C(e=>e.token),[i,o]=Zt(),c=Js(i.get(`tab`)),l=(0,Z.useCallback)(e=>{o(t=>{let n=new URLSearchParams(t);return e===`schedule`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},[o]),[u,f]=(0,Z.useReducer)(Zs,{form:null,baseline:null}),p=u.form,m=u.baseline,[h,g]=(0,Z.useReducer)(Qs,{doc:``,baseline:``}),_=h.doc,v=h.baseline,[y,b]=(0,Z.useReducer)(Lt,ec),{saving:x,error:S,triggerLoading:w,triggerOk:T,triggerError:E}=y,D=(0,Z.useRef)(!1),O=(0,Z.useRef)(!1),{data:k,error:A,isLoading:j,mutate:M}=Fe(r),{data:N,error:P,isLoading:F,mutate:I}=d(r?Wn():null,Vn,{revalidateOnFocus:!1}),{data:L=[]}=d(r?Bn():null,Rn,{revalidateOnFocus:!1}),R=(0,Z.useMemo)(()=>$s(k?.payload?.config),[k]),z=(0,Z.useMemo)(()=>qn(k?.payload?.config??{}),[k]),B=(0,Z.useMemo)(()=>!p||!m?!1:JSON.stringify(p)!==JSON.stringify(m),[p,m]),V=_!==v;(0,Z.useEffect)(()=>{if(!r){f({type:`reset`}),D.current=!1;return}k!==void 0&&(D.current||f({type:`sync`,value:z}))},[r,k,z]),(0,Z.useEffect)(()=>{if(!r){g({type:`reset`}),O.current=!1;return}N!==void 0&&(O.current||g({type:`sync`,value:N}))},[r,N]);let ee=A instanceof Error?A.message:A?String(A):P instanceof Error?P.message:P?String(P):null,H=!!(r&&(k===void 0||N===void 0)&&!ee&&(j||F)),U=p?.target.trim()??``,{data:W,setData:te}=be(()=>Cn(U),[r,U],{enabled:r&&U.length>0,initial:[],errorData:[]}),G=(0,Z.useCallback)(()=>{U&&Cn(U).then(te)},[U,te]),ne=(0,Z.useCallback)(async()=>{b({type:`patch`,patch:{triggerLoading:!0,triggerOk:!1,triggerError:null}});try{await Hn(),b({type:`patch`,patch:{triggerOk:!0}}),window.setTimeout(()=>b({type:`patch`,patch:{triggerOk:!1}}),3e3)}catch(e){b({type:`patch`,patch:{triggerError:e instanceof Error?e.message:n.triggerError}})}finally{b({type:`patch`,patch:{triggerLoading:!1}})}},[n.triggerError]),re=(0,Z.useCallback)(e=>{D.current=!0,f({type:`patch`,patch:e})},[]),ie=B||V,ae=(0,Z.useCallback)(()=>{f({type:`discard`}),g({type:`discard`}),D.current=!1,O.current=!1,b({type:`patch`,patch:{error:null}})},[]);return vr({id:`heartbeat`,dirty:ie,saving:x,save:(0,Z.useCallback)(async()=>{if(!(!p||x)){b({type:`patch`,patch:{saving:!0,error:null}});try{B&&(await Un(p),f({type:`saved`,value:p}),D.current=!1),V&&(await Gn(_),g({type:`saved`,value:_}),O.current=!1)}catch(e){let t=B?n.saveConfigError:n.saveDocError,r=e instanceof Error?e.message:t;throw b({type:`patch`,patch:{error:r}}),Error(r)}finally{b({type:`patch`,patch:{saving:!1}})}}},[B,V,_,p,n.saveConfigError,n.saveDocError,x]),discard:ae}),r?H?(0,$.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),n.loading]})}):p?(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,"aria-busy":x,"data-has-baseline":m?`1`:`0`,children:[(0,$.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.heartbeat}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,$.jsxs)(`a`,{href:Rt(e,`heartbeat`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,$.jsx)(fe,{className:`size-3.5`})]})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:w,onClick:()=>void ne(),children:[w?(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Pt,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),w?n.triggering:n.triggerNow]}),T?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.triggered}):null]})]}),(0,$.jsx)(Pi,{}),R?(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,$.jsx)(`span`,{className:`font-mono text-fg-muted`,children:R})]}):null,S?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:S}):null,E?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:E}):null,(0,$.jsx)(nc,{h:n,activeTab:c,onChange:l}),(0,$.jsx)(rc,{h:n,id:`schedule`,activeTab:c,children:(0,$.jsx)(ic,{h:n,form:p,update:re})}),(0,$.jsx)(rc,{h:n,id:`delivery`,activeTab:c,children:(0,$.jsx)(ac,{h:n,cron:t.cron,form:p,channels:L,sessionChatIds:W,onRefreshChatIds:G,update:re,inputClassName:Ws,selectClassName:Gs})}),(0,$.jsx)(rc,{h:n,id:`prompt`,activeTab:c,children:(0,$.jsx)(cc,{h:n,form:p,update:re,inputClassName:Ws})}),(0,$.jsxs)(rc,{h:n,id:`document`,activeTab:c,children:[(0,$.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:n.docHint}),(0,$.jsx)(`textarea`,{className:J(Ws(),`min-h-72 resize-y font-mono text-xs leading-relaxed`),value:_,onChange:e=>{O.current=!0,g({type:`set`,value:e.target.value})},spellCheck:!1,"aria-label":n.docSection,"data-doc-in-sync":_===v?`true`:`false`})]})]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:S??ee??n.loadError}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:()=>{M(),I()},children:n.retry})]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.heartbeat}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function nc(e){let t=(0,Q.c)(11),{h:n,activeTab:r,onChange:i}=e,a=n.tabsAriaLabel,o;t[0]!==r||t[1]!==i?(o=e=>{e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||(e.preventDefault(),i(Ks[(Ks.indexOf(r)+(e.key===`ArrowRight`?1:-1)+Ks.length)%Ks.length]))},t[0]=r,t[1]=i,t[2]=o):o=t[2];let s;t[3]!==r||t[4]!==n||t[5]!==i?(s=Ks.map(e=>{let t=qs[e],a=e===r;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":a,id:`heartbeat-settings-tab-${e}`,"aria-controls":`heartbeat-settings-panel-${e}`,className:J(`inline-flex shrink-0 items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.press,a?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>i(e),children:[(0,$.jsx)(t,{className:`size-3.5 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`span`,{children:Ys(n,e)})]},e)}),t[3]=r,t[4]=n,t[5]=i,t[6]=s):s=t[6];let c;return t[7]!==n.tabsAriaLabel||t[8]!==o||t[9]!==s?(c=(0,$.jsx)(`nav`,{"aria-label":a,className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,role:`tablist`,onKeyDown:o,children:s}),t[7]=n.tabsAriaLabel,t[8]=o,t[9]=s,t[10]=c):c=t[10],c}function rc(e){let t=(0,Q.c)(20),{h:n,id:r,activeTab:i,children:a}=e;if(i!==r)return null;let o=`heartbeat-settings-panel-${r}`,s=`heartbeat-settings-tab-${r}`,c;t[0]!==n||t[1]!==r?(c=Ys(n,r),t[0]=n,t[1]=r,t[2]=c):c=t[2];let l;t[3]===c?l=t[4]:(l=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:c}),t[3]=c,t[4]=l);let u;t[5]!==n||t[6]!==r?(u=Xs(n,r),t[5]=n,t[6]=r,t[7]=u):u=t[7];let d;t[8]===u?d=t[9]:(d=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:u}),t[8]=u,t[9]=d);let f;t[10]!==l||t[11]!==d?(f=(0,$.jsxs)(`div`,{className:`mb-5`,children:[l,d]}),t[10]=l,t[11]=d,t[12]=f):f=t[12];let p;t[13]===a?p=t[14]:(p=(0,$.jsx)(`div`,{className:`space-y-4`,children:a}),t[13]=a,t[14]=p);let m;return t[15]!==o||t[16]!==s||t[17]!==f||t[18]!==p?(m=(0,$.jsxs)(`section`,{id:o,role:`tabpanel`,"aria-labelledby":s,className:`rounded-2xl border border-edge bg-surface-base px-4 py-5 sm:px-5`,children:[f,p]}),t[15]=o,t[16]=s,t[17]=f,t[18]=p,t[19]=m):m=t[19],m}function ic(e){let t=(0,Q.c)(37),{h:n,form:r,update:i}=e,a;t[0]===i?a=t[1]:(a=e=>i({enabled:e.target.checked}),t[0]=i,t[1]=a);let o;t[2]!==r.enabled||t[3]!==a?(o=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,onChange:a}),t[2]=r.enabled,t[3]=a,t[4]=o):o=t[4];let s;t[5]!==n.enable||t[6]!==o?(s=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[o,n.enable]}),t[5]=n.enable,t[6]=o,t[7]=s):s=t[7];let c;t[8]===i?c=t[9]:(c=e=>i({intervalMs:e}),t[8]=i,t[9]=c);let l;t[10]!==n.intervalPresets||t[11]!==n.intervalSecondsLabel?(l={secondsLabel:n.intervalSecondsLabel,presets:n.intervalPresets},t[10]=n.intervalPresets,t[11]=n.intervalSecondsLabel,t[12]=l):l=t[12];let u=`${n.intervalHintPreset} ${n.intervalHint}`,d;t[13]!==r.intervalMs||t[14]!==n.interval||t[15]!==c||t[16]!==l||t[17]!==u?(d=(0,$.jsx)(vo,{kind:`interval`,label:n.interval,valueMs:r.intervalMs,onChangeMs:c,labels:l,hint:u}),t[13]=r.intervalMs,t[14]=n.interval,t[15]=c,t[16]=l,t[17]=u,t[18]=d):d=t[18];let f;t[19]===i?f=t[20]:(f=e=>i({activeHours:e}),t[19]=i,t[20]=f);let p;t[21]!==n.activeEnd||t[22]!==n.activeStart||t[23]!==n.activeTimezone||t[24]!==n.addActiveHours||t[25]!==n.clearActiveHours?(p={start:n.activeStart,end:n.activeEnd,timezone:n.activeTimezone,add:n.addActiveHours,clear:n.clearActiveHours},t[21]=n.activeEnd,t[22]=n.activeStart,t[23]=n.activeTimezone,t[24]=n.addActiveHours,t[25]=n.clearActiveHours,t[26]=p):p=t[26];let m;t[27]!==r.activeHours||t[28]!==n.activeHoursHint||t[29]!==n.activeHoursTitle||t[30]!==f||t[31]!==p?(m=(0,$.jsx)(vo,{kind:`active-hours`,label:n.activeHoursTitle,value:r.activeHours,onChange:f,labels:p,hint:n.activeHoursHint}),t[27]=r.activeHours,t[28]=n.activeHoursHint,t[29]=n.activeHoursTitle,t[30]=f,t[31]=p,t[32]=m):m=t[32];let h;return t[33]!==m||t[34]!==s||t[35]!==d?(h=(0,$.jsxs)($.Fragment,{children:[s,d,m]}),t[33]=m,t[34]=s,t[35]=d,t[36]=h):h=t[36],h}function ac(e){let t=(0,Q.c)(51),{h:n,cron:r,form:i,channels:a,sessionChatIds:o,onRefreshChatIds:s,update:c,inputClassName:l,selectClassName:u}=e,d;t[0]===a?d=t[1]:(d=new Set(a.map(sc)),t[0]=a,t[1]=d);let f=d,p;t[2]===i.target?p=t[3]:(p=i.target.trim(),t[2]=i.target,t[3]=p);let m=p,h=!!(m&&!f.has(m)),g;t[4]===n.deliveryHint?g=t[5]:(g=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.deliveryHint}),t[4]=n.deliveryHint,t[5]=g);let _;t[6]===r.channel?_=t[7]:(_=(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:r.channel}),t[6]=r.channel,t[7]=_);let v;t[8]===u?v=t[9]:(v=u(),t[8]=u,t[9]=v);let y;t[10]===c?y=t[11]:(y=e=>{c({target:e.target.value.trim(),targetChatId:``})},t[10]=c,t[11]=y);let b;t[12]===n.channelNone?b=t[13]:(b=(0,$.jsx)(`option`,{value:``,children:n.channelNone}),t[12]=n.channelNone,t[13]=b);let x;t[14]!==n.customChannelSuffix||t[15]!==h||t[16]!==m?(x=h?(0,$.jsxs)(`option`,{value:m,children:[m,` (`,n.customChannelSuffix,`)`]}):null,t[14]=n.customChannelSuffix,t[15]=h,t[16]=m,t[17]=x):x=t[17];let S;t[18]===a?S=t[19]:(S=a.map(oc),t[18]=a,t[19]=S);let C;t[20]!==v||t[21]!==y||t[22]!==b||t[23]!==x||t[24]!==S||t[25]!==m?(C=(0,$.jsxs)(`select`,{className:v,value:m,onChange:y,children:[b,x,S]}),t[20]=v,t[21]=y,t[22]=b,t[23]=x,t[24]=S,t[25]=m,t[26]=C):C=t[26];let w;t[27]!==C||t[28]!==_?(w=(0,$.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[_,C]}),t[27]=C,t[28]=_,t[29]=w):w=t[29];let T;t[30]!==r.enterManuallyOrSelect||t[31]!==r.lastActiveLabels||t[32]!==r.noRecentChats||t[33]!==r.noRecentChatsOption||t[34]!==r.recipient||t[35]!==r.recipientPlaceholder||t[36]!==r.refreshList||t[37]!==r.refreshRecipientHint||t[38]!==r.selectRecipient||t[39]!==i.targetChatId||t[40]!==l||t[41]!==s||t[42]!==u||t[43]!==o||t[44]!==m||t[45]!==c?(T=m?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:r.recipient}),(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:r.refreshRecipientHint,onClick:s,children:[(0,$.jsx)(Ze,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),r.refreshList]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,className:J(l(),`min-w-0 flex-1`),value:i.targetChatId,onChange:e=>c({targetChatId:e.target.value}),placeholder:r.recipientPlaceholder,autoComplete:`off`}),(0,$.jsxs)(`select`,{className:J(u(),`max-w-40 shrink-0 text-xs`),value:i.targetChatId,onChange:e=>{let t=e.target.value;t&&c({targetChatId:t})},children:[(0,$.jsx)(`option`,{value:``,children:r.selectRecipient}),o.length>0?o.map(e=>(0,$.jsx)(`option`,{value:e.chatId,children:bn(e,r.lastActiveLabels)},`${e.channel}-${e.chatId}`)):(0,$.jsx)(`option`,{value:``,disabled:!0,children:r.noRecentChatsOption})]})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:o.length>0?r.enterManuallyOrSelect:r.noRecentChats})]}):null,t[30]=r.enterManuallyOrSelect,t[31]=r.lastActiveLabels,t[32]=r.noRecentChats,t[33]=r.noRecentChatsOption,t[34]=r.recipient,t[35]=r.recipientPlaceholder,t[36]=r.refreshList,t[37]=r.refreshRecipientHint,t[38]=r.selectRecipient,t[39]=i.targetChatId,t[40]=l,t[41]=s,t[42]=u,t[43]=o,t[44]=m,t[45]=c,t[46]=T):T=t[46];let E;return t[47]!==w||t[48]!==T||t[49]!==g?(E=(0,$.jsxs)($.Fragment,{children:[g,w,T]}),t[47]=w,t[48]=T,t[49]=g,t[50]=E):E=t[50],E}function oc(e){return(0,$.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name)}function sc(e){return e.name}function cc(e){let t=(0,Q.c)(65),{h:n,form:r,update:i,inputClassName:a}=e,o;t[0]===i?o=t[1]:(o=e=>i({includeSystemPromptSection:e.target.checked}),t[0]=i,t[1]=o);let s;t[2]!==r.includeSystemPromptSection||t[3]!==o?(s=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:r.includeSystemPromptSection,onChange:o}),t[2]=r.includeSystemPromptSection,t[3]=o,t[4]=s):s=t[4];let c;t[5]===n.includeSystemPromptSectionHint?c=t[6]:(c=(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:n.includeSystemPromptSectionHint}),t[5]=n.includeSystemPromptSectionHint,t[6]=c);let l;t[7]!==n.includeSystemPromptSection||t[8]!==c?(l=(0,$.jsxs)(`span`,{children:[n.includeSystemPromptSection,c]}),t[7]=n.includeSystemPromptSection,t[8]=c,t[9]=l):l=t[9];let u;t[10]!==s||t[11]!==l?(u=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[s,l]}),t[10]=s,t[11]=l,t[12]=u):u=t[12];let d;t[13]===n.prompt?d=t[14]:(d=(0,$.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.prompt}),t[13]=n.prompt,t[14]=d);let f;t[15]===a?f=t[16]:(f=J(a(),`min-h-36 resize-y font-mono text-xs`),t[15]=a,t[16]=f);let p;t[17]===i?p=t[18]:(p=e=>i({prompt:e.target.value}),t[17]=i,t[18]=p);let m;t[19]!==r.prompt||t[20]!==n.promptPlaceholder||t[21]!==f||t[22]!==p?(m=(0,$.jsx)(`textarea`,{className:f,value:r.prompt,onChange:p,placeholder:n.promptPlaceholder}),t[19]=r.prompt,t[20]=n.promptPlaceholder,t[21]=f,t[22]=p,t[23]=m):m=t[23];let h;t[24]===n.promptHint?h=t[25]:(h=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.promptHint}),t[24]=n.promptHint,t[25]=h);let g;t[26]!==h||t[27]!==d||t[28]!==m?(g=(0,$.jsxs)(`div`,{children:[d,m,h]}),t[26]=h,t[27]=d,t[28]=m,t[29]=g):g=t[29];let _;t[30]===n.ackMaxChars?_=t[31]:(_=(0,$.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.ackMaxChars}),t[30]=n.ackMaxChars,t[31]=_);let v;t[32]===a?v=t[33]:(v=a(),t[32]=a,t[33]=v);let y=r.ackMaxChars===``?``:r.ackMaxChars,b;t[34]===i?b=t[35]:(b=e=>{let t=e.target.value;if(t===``){i({ackMaxChars:``});return}let n=parseInt(t,10);i({ackMaxChars:Number.isFinite(n)?n:``})},t[34]=i,t[35]=b);let x;t[36]!==n.ackDefaultPlaceholder||t[37]!==v||t[38]!==y||t[39]!==b?(x=(0,$.jsx)(`input`,{type:`number`,min:1,className:v,value:y,onChange:b,placeholder:n.ackDefaultPlaceholder}),t[36]=n.ackDefaultPlaceholder,t[37]=v,t[38]=y,t[39]=b,t[40]=x):x=t[40];let S;t[41]===n.ackMaxCharsHint?S=t[42]:(S=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.ackMaxCharsHint}),t[41]=n.ackMaxCharsHint,t[42]=S);let C;t[43]!==_||t[44]!==x||t[45]!==S?(C=(0,$.jsxs)(`div`,{children:[_,x,S]}),t[43]=_,t[44]=x,t[45]=S,t[46]=C):C=t[46];let w;t[47]===i?w=t[48]:(w=e=>i({isolatedSession:e.target.checked}),t[47]=i,t[48]=w);let T;t[49]!==r.isolatedSession||t[50]!==w?(T=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:r.isolatedSession,onChange:w}),t[49]=r.isolatedSession,t[50]=w,t[51]=T):T=t[51];let E;t[52]===n.isolatedSessionHint?E=t[53]:(E=(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:n.isolatedSessionHint}),t[52]=n.isolatedSessionHint,t[53]=E);let D;t[54]!==n.isolatedSession||t[55]!==E?(D=(0,$.jsxs)(`span`,{children:[n.isolatedSession,E]}),t[54]=n.isolatedSession,t[55]=E,t[56]=D):D=t[56];let O;t[57]!==T||t[58]!==D?(O=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[T,D]}),t[57]=T,t[58]=D,t[59]=O):O=t[59];let k;return t[60]!==g||t[61]!==C||t[62]!==O||t[63]!==u?(k=(0,$.jsxs)($.Fragment,{children:[u,g,C,O]}),t[60]=g,t[61]=C,t[62]=O,t[63]=u,t[64]=k):k=t[64],k}function lc(e,t){let{mutate:n}=u(),[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),l=(0,Z.useCallback)(async()=>{await Promise.all([n(`tunnel-pair-context`),n(`tunnel-pair`),n(`tunnel-status`),Qt()])},[n]);return{busy:r,error:a,confirmOpen:s,setConfirmOpen:c,runEnableLanPairing:(0,Z.useCallback)(async()=>{if(!(!e||r)){i(!0),o(null);try{let n=await Yt();if(!n.ok)throw Error(`Failed to enable LAN pairing`);if(n.requiresRestart){let t=await rt();if(!t.ok)throw Error(t.message??`Gateway restart failed`);if(!await $t(e))throw Error(`Gateway did not come back online in time`)}let r=n.requiresRestart?await Ie():n.context;if(!r?.pairingReady)throw Error(`LAN pairing is still not ready after restart`);return await l(),t?.(r),c(!1),r}catch(e){return o(e instanceof Error?e.message:`Enable LAN pairing failed`),null}finally{i(!1)}}},[r,e,t,l]),clearError:()=>o(null)}}function uc(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ht,`dark:border-edge`)}function dc(e){let t=(0,Q.c)(122),{pairQr:n,gatewayToken:r,streamlined:i,lanOnly:o,onRefreshQr:c}=e,l=i===void 0?!1:i,u=o===void 0?!1:o,d=a(mc),f;t[0]===d?f=t[1]:(f=s(d),t[0]=d,t[1]=f);let p=f,m=p.tunnelSettings,h=u?p.remoteAccess.lan:null,g;t[2]!==p.clipboard.copyFailed||t[3]!==m.pairCopied||t[4]!==m.pairCopyLink?(g={copy:m.pairCopyLink,copied:m.pairCopied,copyFailed:p.clipboard.copyFailed},t[2]=p.clipboard.copyFailed,t[3]=m.pairCopied,t[4]=m.pairCopyLink,t[5]=g):g=t[5];let _=g,{tunnelActive:v,tunnelStatus:y,tunnelQr:b,pairContext:x,pairBaseUrl:S,setPairBaseUrl:C,applySuggestedPairUrl:w,applyCandidateUrl:T,resetPairBaseFromContext:E,baseOk:D,localhostWarn:O,pairingBlocked:k,deepLink:A,qrPayload:j,qrDataUrl:M,qrGenFailed:N,encoding:P}=n,F;t[6]===E?F=t[7]:(F=e=>{E(e.recommended.url)},t[6]=E,t[7]=F);let I=lc(r,F),L,R,z,B,V;if(t[8]!==T||t[9]!==w||t[10]!==D||t[11]!==I||t[12]!==r||t[13]!==h||t[14]!==u||t[15]!==O||t[16]!==c||t[17]!==S||t[18]!==x?.candidates||t[19]!==x?.recommended||t[20]!==k||t[21]!==C||t[22]!==l||t[23]!==m.pairBaseUrlHint||t[24]!==m.pairBaseUrlLabel||t[25]!==m.pairBaseUrlPlaceholder||t[26]!==m.pairBlockedLoopbackBody||t[27]!==m.pairBlockedNextSteps||t[28]!==m.pairBlockedTitle||t[29]!==m.pairCandidatesTitle||t[30]!==m.pairEnableLanButton||t[31]!==m.pairEnableLanEnabling||t[32]!==m.pairEnableLanSecurityAuditLink||t[33]!==m.pairInvalidBaseUrl||t[34]!==m.pairLocalhostWarning||t[35]!==m.pairSelectCandidateHint||t[36]!==m.pairSelectCandidateTitle||t[37]!==m.pairSubtitle||t[38]!==m.pairSuggestedLanLabel||t[39]!==m.pairTitle||t[40]!==m.pairTunnelActive||t[41]!==m.pairTunnelLanUrl||t[42]!==m.pairTunnelPublicUrl||t[43]!==m.pairUseSuggestedUrl||t[44]!==m.pairWaitingForTunnel||t[45]!==m.refreshQr||t[46]!==v||t[47]!==b||t[48]!==y?.publicUrl){V=Symbol.for(`react.early_return_sentinel`);bb0:{let e=x?.candidates.filter(pc)??[],n=u?(e.find(fc)?.url??e[0]?.url??``).trim():x?.recommended.url?.trim()??``,i=(u||!v)&&e.length>1,a=function(t){if(e.length===0)return null;let n=t===`amber`?`text-amber-950 dark:text-amber-100`:`text-fg`,r=t===`amber`?`text-amber-950/80 dark:text-amber-200/90`:`text-fg-muted`;return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:J(`text-xs font-medium`,r),children:i?m.pairSelectCandidateTitle:m.pairCandidatesTitle}),(0,$.jsx)(`ul`,{className:`mt-1 space-y-1`,children:e.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,className:J(`w-full rounded-md border px-2 py-1.5 text-left font-mono text-[11px] transition-colors`,t===`amber`?`border-amber-300/70 hover:bg-amber-100/80 dark:border-amber-800 dark:hover:bg-amber-950/50`:`border-edge hover:bg-surface-panel`,S.trim()===e.url&&`border-accent bg-accent/5`,n),onClick:()=>T(e.url),children:[e.label?`${e.label}: `:``,e.url]})},e.url))}),i?(0,$.jsx)(`p`,{className:J(`mt-1 text-[11px] leading-relaxed`,r),children:m.pairSelectCandidateHint}):null]})};if(L=l&&!u,L&&!v){let e;t[54]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(H,{className:`size-4 text-accent`,strokeWidth:1.75}),t[54]=e):e=t[54];let n;t[55]===m.pairTitle?n=t[56]:(n=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[e,m.pairTitle]}),t[55]=m.pairTitle,t[56]=n);let r;t[57]===m.pairWaitingForTunnel?r=t[58]:(r=(0,$.jsx)(`p`,{className:`mt-2 text-sm text-fg-muted`,children:m.pairWaitingForTunnel}),t[57]=m.pairWaitingForTunnel,t[58]=r);let i;t[59]!==n||t[60]!==r?(i=(0,$.jsxs)(X,{children:[n,r]}),t[59]=n,t[60]=r,t[61]=i):i=t[61],V=i;break bb0}let o=h?.pairTitle??m.pairTitle,s=u?h?.pairSubtitle??m.pairSubtitle:v?m.pairTunnelActive:m.pairSubtitle,d=!!(c&&(u||l&&v)),f=L?`mb-2`:`mb-3`,p;t[62]===f?p=t[63]:(p=J(`flex flex-wrap items-start justify-between gap-2`,f),t[62]=f,t[63]=p);let g;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(H,{className:`size-4 text-accent`,strokeWidth:1.75}),t[64]=g):g=t[64];let _;t[65]===o?_=t[66]:(_=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[g,o]}),t[65]=o,t[66]=_);let E;t[67]!==L||t[68]!==s||t[69]!==m.pairSubtitle?(E=L?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:m.pairSubtitle}):(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:s}),t[67]=L,t[68]=s,t[69]=m.pairSubtitle,t[70]=E):E=t[70];let A;t[71]!==_||t[72]!==E?(A=(0,$.jsxs)(`div`,{children:[_,E]}),t[71]=_,t[72]=E,t[73]=A):A=t[73];let j;t[74]!==c||t[75]!==d||t[76]!==m.refreshQr?(j=d?(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`shrink-0`,onClick:()=>void c(),children:[(0,$.jsx)(Ze,{className:`size-4`}),m.refreshQr]}):null,t[74]=c,t[75]=d,t[76]=m.refreshQr,t[77]=j):j=t[77],t[78]!==p||t[79]!==A||t[80]!==j?(R=(0,$.jsxs)(`div`,{className:p,children:[A,j]}),t[78]=p,t[79]=A,t[80]=j,t[81]=R):R=t[81],z=k?(0,$.jsxs)(`div`,{className:`mb-3 space-y-3 rounded-lg border border-amber-200 bg-amber-50 px-3 py-3 dark:border-amber-900/50 dark:bg-amber-950/30`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-amber-950 dark:text-amber-100`,children:m.pairBlockedTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-amber-900 dark:text-amber-200`,children:m.pairBlockedLoopbackBody})]}),n?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-amber-950/80 dark:text-amber-200/90`,children:m.pairSuggestedLanLabel}),(0,$.jsx)(`div`,{className:`mt-0.5 break-all font-mono text-xs text-amber-950 dark:text-amber-100`,children:n})]}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:w,children:m.pairUseSuggestedUrl})]}):null,e.length>0?a(`amber`):null,(0,$.jsx)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:flex-wrap`,children:(0,$.jsxs)(Y,{type:`button`,className:`w-full sm:w-auto`,disabled:I.busy||!r,onClick:()=>I.setConfirmOpen(!0),children:[I.busy?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):null,I.busy?m.pairEnableLanEnabling:m.pairEnableLanButton]})}),I.error?(0,$.jsx)(`p`,{className:`text-xs text-red-800 dark:text-red-200`,children:I.error}):null,(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-amber-900 dark:text-amber-200`,children:u?h?.pairBlockedNextSteps??m.pairBlockedNextSteps:m.pairBlockedNextSteps}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(_t,{to:`/settings/gateway`,className:`inline-block text-xs font-medium text-accent hover:underline`,children:m.pairEnableLanSecurityAuditLink}),u&&h?.pairPublicTabLink?(0,$.jsx)(_t,{to:`/settings/remote-access?tab=public`,className:`inline-block text-xs font-medium text-accent hover:underline`,children:h.pairPublicTabLink}):null]})]}):null,B=v&&!u?L?null:(0,$.jsxs)(`div`,{className:`mb-3 space-y-2 rounded-lg border border-edge bg-surface-panel px-3 py-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.pairTunnelPublicUrl}),(0,$.jsx)(`div`,{className:`mt-0.5 break-all font-mono text-xs text-fg`,children:y?.publicUrl})]}),b?.lanUrl?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.pairTunnelLanUrl}),(0,$.jsx)(`div`,{className:`mt-0.5 break-all font-mono text-xs text-fg`,children:b.lanUrl})]}):null]}):(0,$.jsxs)(`div`,{className:`mb-3 space-y-1.5`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`tunnel-mobile-pair-base`,children:m.pairBaseUrlLabel}),(0,$.jsx)(`input`,{id:`tunnel-mobile-pair-base`,className:J(uc(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,placeholder:n||m.pairBaseUrlPlaceholder,value:S,onChange:e=>C(e.target.value)}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:m.pairBaseUrlHint}),!D&&S.trim()?(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:m.pairInvalidBaseUrl}):null,O?(0,$.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:m.pairLocalhostWarning}):null,i?a(`neutral`):null]})}t[8]=T,t[9]=w,t[10]=D,t[11]=I,t[12]=r,t[13]=h,t[14]=u,t[15]=O,t[16]=c,t[17]=S,t[18]=x?.candidates,t[19]=x?.recommended,t[20]=k,t[21]=C,t[22]=l,t[23]=m.pairBaseUrlHint,t[24]=m.pairBaseUrlLabel,t[25]=m.pairBaseUrlPlaceholder,t[26]=m.pairBlockedLoopbackBody,t[27]=m.pairBlockedNextSteps,t[28]=m.pairBlockedTitle,t[29]=m.pairCandidatesTitle,t[30]=m.pairEnableLanButton,t[31]=m.pairEnableLanEnabling,t[32]=m.pairEnableLanSecurityAuditLink,t[33]=m.pairInvalidBaseUrl,t[34]=m.pairLocalhostWarning,t[35]=m.pairSelectCandidateHint,t[36]=m.pairSelectCandidateTitle,t[37]=m.pairSubtitle,t[38]=m.pairSuggestedLanLabel,t[39]=m.pairTitle,t[40]=m.pairTunnelActive,t[41]=m.pairTunnelLanUrl,t[42]=m.pairTunnelPublicUrl,t[43]=m.pairUseSuggestedUrl,t[44]=m.pairWaitingForTunnel,t[45]=m.refreshQr,t[46]=v,t[47]=b,t[48]=y?.publicUrl,t[49]=L,t[50]=R,t[51]=z,t[52]=B,t[53]=V}else L=t[49],R=t[50],z=t[51],B=t[52],V=t[53];if(V!==Symbol.for(`react.early_return_sentinel`))return V;let ee;t[82]===m.pairSecurityNote?ee=t[83]:(ee=(0,$.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:m.pairSecurityNote}),t[82]=m.pairSecurityNote,t[83]=ee);let U;t[84]!==_||t[85]!==A||t[86]!==P||t[87]!==k||t[88]!==M||t[89]!==N||t[90]!==m.pairEncoding||t[91]!==m.pairImageError||t[92]!==m.pairQrDisabled?(U=A?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[M&&!N?(0,$.jsx)(`img`,{src:M,alt:``,className:`size-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):null,P?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m.pairEncoding}):null,N?(0,$.jsx)(`p`,{className:`text-center text-sm text-fg-muted sm:text-left`,children:m.pairImageError}):null,(0,$.jsx)(te,{text:A,labels:_})]}):k?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m.pairQrDisabled}):null,t[84]=_,t[85]=A,t[86]=P,t[87]=k,t[88]=M,t[89]=N,t[90]=m.pairEncoding,t[91]=m.pairImageError,t[92]=m.pairQrDisabled,t[93]=U):U=t[93];let W;t[94]!==L||t[95]!==j||t[96]!==m.deeplinkTitle?(W=j&&!L?(0,$.jsxs)(`details`,{className:`mt-3 rounded-lg border border-edge bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-fg-muted`,children:m.deeplinkTitle}),(0,$.jsx)(`p`,{className:`mt-2 break-all font-mono text-[10px] leading-relaxed text-fg-subtle`,children:j})]}):null,t[94]=L,t[95]=j,t[96]=m.deeplinkTitle,t[97]=W):W=t[97];let G;t[98]!==L||t[99]!==m.pairMobileProbeHint||t[100]!==m.pairSchemeHint?(G=L?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mt-3 break-all font-mono text-[10px] leading-relaxed text-fg-subtle`,children:m.pairSchemeHint}),(0,$.jsx)(`p`,{className:`mt-1 text-[10px] leading-relaxed text-fg-subtle`,children:m.pairMobileProbeHint})]}),t[98]=L,t[99]=m.pairMobileProbeHint,t[100]=m.pairSchemeHint,t[101]=G):G=t[101];let ne,re;t[102]===I?(ne=t[103],re=t[104]):(ne=()=>void I.runEnableLanPairing(),re=()=>{I.busy||I.setConfirmOpen(!1)},t[102]=I,t[103]=ne,t[104]=re);let ie;t[105]!==I.confirmOpen||t[106]!==m.consentCancel||t[107]!==m.pairEnableLanButton||t[108]!==m.pairEnableLanConfirmBody||t[109]!==m.pairEnableLanConfirmTitle||t[110]!==ne||t[111]!==re?(ie=(0,$.jsx)(Ht,{open:I.confirmOpen,title:m.pairEnableLanConfirmTitle,description:m.pairEnableLanConfirmBody,confirmLabel:m.pairEnableLanButton,cancelLabel:m.consentCancel,onConfirm:ne,onCancel:re}),t[105]=I.confirmOpen,t[106]=m.consentCancel,t[107]=m.pairEnableLanButton,t[108]=m.pairEnableLanConfirmBody,t[109]=m.pairEnableLanConfirmTitle,t[110]=ne,t[111]=re,t[112]=ie):ie=t[112];let ae;return t[113]!==ee||t[114]!==U||t[115]!==W||t[116]!==G||t[117]!==ie||t[118]!==R||t[119]!==z||t[120]!==B?(ae=(0,$.jsx)(X,{children:(0,$.jsxs)($.Fragment,{children:[R,z,B,ee,U,W,G,ie]})}),t[113]=ee,t[114]=U,t[115]=W,t[116]=G,t[117]=ie,t[118]=R,t[119]=z,t[120]=B,t[121]=ae):ae=t[121],ae}function fc(e){return e.reachable}function pc(e){return e.kind===`lan`}function mc(e){return e.language}function hc(e){let t=(0,Q.c)(40),{open:n,title:r,intro:i,bullets:a,checkboxLabel:o,confirmLabel:s,cancelLabel:c,onConfirm:l,onCancel:u}=e,[d,f]=(0,Z.useState)(!1),p;t[0]===u?p=t[1]:(p=e=>{e||(f(!1),u())},t[0]=u,t[1]=p);let m;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(g,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Pe)}),t[2]=m):m=t[2];let x;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(x=J(`fixed left-1/2 top-1/2 max-h-[min(90vh,40rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`,Xt),t[3]=x):x=t[3];let S;t[4]===r?S=t[5]:(S=(0,$.jsx)(b,{className:`text-base font-semibold text-fg`,children:r}),t[4]=r,t[5]=S);let C;t[6]===i?C=t[7]:(C=(0,$.jsx)(y,{className:`mt-2 text-sm text-fg-muted`,children:i}),t[6]=i,t[7]=C);let w;t[8]===a?w=t[9]:(w=a.map(gc),t[8]=a,t[9]=w);let T;t[10]===w?T=t[11]:(T=(0,$.jsx)(`ul`,{className:`mt-4 list-disc space-y-2 pl-5 text-sm text-fg-muted`,children:w}),t[10]=w,t[11]=T);let E;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(E=e=>f(e.target.checked),t[12]=E):E=t[12];let D;t[13]===d?D=t[14]:(D=(0,$.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 size-4 shrink-0 rounded border-edge accent-accent`,checked:d,onChange:E}),t[13]=d,t[14]=D);let O;t[15]===o?O=t[16]:(O=(0,$.jsx)(`span`,{children:o}),t[15]=o,t[16]=O);let k;t[17]!==O||t[18]!==D?(k=(0,$.jsxs)(`label`,{className:`mt-5 flex cursor-pointer items-start gap-3 text-sm text-fg`,children:[D,O]}),t[17]=O,t[18]=D,t[19]=k):k=t[19];let A;t[20]!==c||t[21]!==u?(A=(0,$.jsx)(Y,{type:`button`,variant:`secondary`,onClick:u,children:c}),t[20]=c,t[21]=u,t[22]=A):A=t[22];let j=!d,M;t[23]!==s||t[24]!==l||t[25]!==j?(M=(0,$.jsx)(Y,{type:`button`,disabled:j,onClick:l,children:s}),t[23]=s,t[24]=l,t[25]=j,t[26]=M):M=t[26];let N;t[27]!==A||t[28]!==M?(N=(0,$.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[A,M]}),t[27]=A,t[28]=M,t[29]=N):N=t[29];let P;t[30]!==k||t[31]!==N||t[32]!==S||t[33]!==C||t[34]!==T?(P=(0,$.jsxs)(h,{children:[m,(0,$.jsxs)(_,{className:x,onOpenAutoFocus:_c,children:[S,C,T,k,N]})]}),t[30]=k,t[31]=N,t[32]=S,t[33]=C,t[34]=T,t[35]=P):P=t[35];let F;return t[36]!==n||t[37]!==p||t[38]!==P?(F=(0,$.jsx)(v,{open:n,onOpenChange:p,children:P}),t[36]=n,t[37]=p,t[38]=P,t[39]=F):F=t[39],F}function gc(e){return(0,$.jsx)(`li`,{children:e},e)}function _c(e){return e.preventDefault()}function vc(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}var yc=[`preparing_frpc`,`registering`,`starting_frpc`];function bc(e){return e?e===`reconnecting_frpc`?yc.indexOf(`starting_frpc`):yc.indexOf(e):-1}function xc(e,t){if(t.state===`connected`)return`done`;let n=t.startProgress?.phase,r=yc.indexOf(e),i=bc(n);return i<0?t.state===`connecting`||t.state===`reconnecting`?`active`:`pending`:r<i?`done`:r===i?`active`:`pending`}function Sc(e,t,n){let r=n.startProgress;return xc(t,n)===`active`?t===`preparing_frpc`&&n.frpcDownload?n.frpcDownload.phase===`extracting`?e.frpcExtracting:n.frpcDownload.percent==null?e.frpcDownloading:e.frpcDownloadingPercent.replace(`{{percent}}`,String(n.frpcDownload.percent)):t===`registering`&&r?.publicUrl?e.stepRegisterDetail:t===`starting_frpc`?r?.phase===`reconnecting_frpc`?e.stepReconnectDetail:e.stepFrpcDetail:null:null}function Cc(e,t){switch(t){case`preparing_frpc`:return e.stepPrepareFrpc;case`registering`:return e.stepRegister;case`starting_frpc`:return e.stepFrpcLogin}}function wc(e){if(!e)return null;let t=Math.max(0,Math.floor((Date.now()-new Date(e).getTime())/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Tc(e){let t=(0,Q.c)(31),{status:n,t:r}=e,[,i]=(0,Z.useState)(0),a;t[0]!==i||t[1]!==n.state?(a=()=>{if(n.state!==`connecting`&&n.state!==`reconnecting`)return;let e=window.setInterval(()=>i(Ec),1e3);return()=>window.clearInterval(e)},t[0]=i,t[1]=n.state,t[2]=a):a=t[2];let o=n.startProgress?.startedAt,s;if(t[3]!==n.state||t[4]!==o?(s=[n.state,o],t[3]=n.state,t[4]=o,t[5]=s):s=t[5],(0,Z.useEffect)(a,s),!(n.state===`connecting`||n.state===`reconnecting`||n.state===`connected`&&n.startProgress))return null;let c,l,u,d,f;if(t[6]!==n||t[7]!==r){let e=wc(n.startProgress?.startedAt);c=!!n.publicUrl&&n.state!==`connected`&&n.startProgress?.phase!==`registering`,l=`mt-3 space-y-3 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-3`;let i;t[13]===r.startProgressTitle?i=t[14]:(i=(0,$.jsx)(`p`,{className:`text-xs font-medium text-fg`,children:r.startProgressTitle}),t[13]=r.startProgressTitle,t[14]=i);let a;t[15]===r.startProgressHint?a=t[16]:(a=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:r.startProgressHint}),t[15]=r.startProgressHint,t[16]=a),t[17]!==i||t[18]!==a?(u=(0,$.jsxs)(`div`,{children:[i,a]}),t[17]=i,t[18]=a,t[19]=u):u=t[19];let o=yc.map(e=>{let t=xc(e,n),i=Sc(r,e,n);return(0,$.jsxs)(`li`,{className:`flex gap-2 text-xs`,children:[(0,$.jsx)(`span`,{className:`mt-0.5 shrink-0 text-fg-subtle`,"aria-hidden":!0,children:t===`done`?(0,$.jsx)(tt,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`}):t===`active`?(0,$.jsx)(q,{className:`size-3.5 animate-spin text-accent`}):(0,$.jsx)(se,{className:`size-3.5`})}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:J(`font-medium`,t===`active`?`text-fg`:t===`done`?`text-fg-muted`:`text-fg-subtle`),children:Cc(r,e)}),i?(0,$.jsx)(`div`,{className:`mt-0.5 text-fg-muted`,children:i}):null,e===`preparing_frpc`&&t===`active`&&n.frpcDownload&&n.frpcDownload.phase===`downloading`?(0,$.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[(0,$.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-surface-panel`,children:(0,$.jsx)(`div`,{className:J(`h-full rounded-full bg-accent transition-[width] duration-300`,n.frpcDownload.percent==null&&`w-1/3 animate-pulse`),style:n.frpcDownload.percent==null?void 0:{width:`${n.frpcDownload.percent}%`}})}),n.frpcDownload.bytesReceived!=null&&n.frpcDownload.totalBytes?(0,$.jsxs)(`p`,{className:`text-fg-subtle`,children:[vc(n.frpcDownload.bytesReceived),` /`,` `,vc(n.frpcDownload.totalBytes)]}):null]}):null,e===`preparing_frpc`&&t===`active`&&n.frpcDownload?.url?(0,$.jsxs)(`p`,{className:`mt-2 text-fg-subtle`,children:[(0,$.jsxs)(`span`,{className:`font-sans`,children:[r.frpcDownloadingUrlLabel,`: `]}),(0,$.jsx)(`a`,{href:n.frpcDownload.url,target:`_blank`,rel:`noopener noreferrer`,className:`break-all font-mono text-[11px] text-accent hover:underline`,children:n.frpcDownload.url})]}):null]})]},e)});t[20]===o?d=t[21]:(d=(0,$.jsx)(`ol`,{className:`space-y-2`,children:o}),t[20]=o,t[21]=d),f=e&&n.startProgress?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.startProgressElapsed.replace(`{{elapsed}}`,e)}):null,t[6]=n,t[7]=r,t[8]=c,t[9]=l,t[10]=u,t[11]=d,t[12]=f}else c=t[8],l=t[9],u=t[10],d=t[11],f=t[12];let p;t[22]!==c||t[23]!==r.publicUrlPendingNotice?(p=c?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r.publicUrlPendingNotice}):null,t[22]=c,t[23]=r.publicUrlPendingNotice,t[24]=p):p=t[24];let m;return t[25]!==l||t[26]!==u||t[27]!==d||t[28]!==f||t[29]!==p?(m=(0,$.jsxs)(`div`,{className:l,children:[u,d,f,p]}),t[25]=l,t[26]=u,t[27]=d,t[28]=f,t[29]=p,t[30]=m):m=t[30],m}function Ec(e){return e+1}function Dc(e,t){return t.state===`connected`?e.statusConnected:t.state===`error`?e.statusError:t.startProgress?.phase===`reconnecting_frpc`?e.statusReconnecting:t.startProgress?.phase===`starting_frpc`?e.statusStartingFrpc:t.startProgress?.phase===`registering`?e.statusRegistering:t.startProgress?.phase===`preparing_frpc`||t.frpcDownload?e.statusPreparingFrpc:t.state===`connecting`||t.state===`reconnecting`?e.statusConnecting:e.statusOff}function Oc(e){return e.state===`connected`?`connected`:e.state===`error`?`error`:e.state===`connecting`||e.state===`reconnecting`||e.startProgress||e.frpcDownload?`progress`:`off`}function kc(e){switch(e){case`connected`:return`bg-emerald-500/15 text-emerald-700 dark:text-emerald-400`;case`progress`:return`bg-amber-500/15 text-amber-700 dark:text-amber-400`;case`error`:return`bg-red-500/15 text-red-700 dark:text-red-400`;default:return`bg-surface-hover text-fg-muted`}}function Ac(e){if(!e)return`—`;let t=Date.now()-new Date(e).getTime();if(t<0)return`—`;let n=Math.floor(t/6e4);return n<60?`${n}m`:`${Math.floor(n/60)}h ${n%60}m`}function jc(e){let t=(0,Q.c)(61),{t:n,status:r,isLoading:i,statusErr:a,starting:o,stopping:s,showConsentExpired:c,copyLabels:l,startDisabled:u,startDisabledReason:d,stepLabel:f,onStart:p,onStop:m}=e,h=u===void 0?!1:u,g,_,v,y,b,x,S;t[0]!==r||t[1]!==o?(S=Oc(r),g=r.enabled||o,_=o||r.state===`connecting`||r.state===`reconnecting`||!!r.startProgress||!!r.frpcDownload,t[9]===Symbol.for(`react.memo_cache_sentinel`)?(x=J(yn(),`space-y-4`),t[9]=x):x=t[9],b=`flex flex-wrap items-start justify-between gap-3`,y=`flex items-center gap-2`,v=J(`inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium`,kc(S)),t[0]=r,t[1]=o,t[2]=g,t[3]=_,t[4]=v,t[5]=y,t[6]=b,t[7]=x,t[8]=S):(g=t[2],_=t[3],v=t[4],y=t[5],b=t[6],x=t[7],S=t[8]);let C=S===`connected`&&`bg-emerald-500`,w=S===`progress`&&`bg-amber-500 animate-pulse`,T=S===`error`&&`bg-red-500`,E=S===`off`&&`bg-fg-subtle`,O;t[10]!==C||t[11]!==w||t[12]!==T||t[13]!==E?(O=J(`size-1.5 rounded-full`,C,w,T,E),t[10]=C,t[11]=w,t[12]=T,t[13]=E,t[14]=O):O=t[14];let k;t[15]===O?k=t[16]:(k=(0,$.jsx)(`span`,{className:O,"aria-hidden":!0}),t[15]=O,t[16]=k);let A;t[17]!==i||t[18]!==r||t[19]!==n?(A=i&&!r.enabled?n.loading:Dc(n,r),t[17]=i,t[18]=r,t[19]=n,t[20]=A):A=t[20];let j;t[21]!==k||t[22]!==A||t[23]!==v?(j=(0,$.jsxs)(`span`,{className:v,children:[k,A]}),t[21]=k,t[22]=A,t[23]=v,t[24]=j):j=t[24];let M;t[25]!==r.connectedSince||t[26]!==r.state||t[27]!==n.uptime?(M=r.connectedSince&&r.state===`connected`?(0,$.jsxs)(`span`,{className:`text-xs text-fg-subtle`,children:[n.uptime,` `,Ac(r.connectedSince)]}):null,t[25]=r.connectedSince,t[26]=r.state,t[27]=n.uptime,t[28]=M):M=t[28];let N;t[29]!==j||t[30]!==M||t[31]!==y?(N=(0,$.jsxs)(`div`,{className:y,children:[j,M]}),t[29]=j,t[30]=M,t[31]=y,t[32]=N):N=t[32];let P;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,$.jsx)(Ce,{className:`size-4 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),t[33]=P):P=t[33];let F;t[34]!==N||t[35]!==b?(F=(0,$.jsxs)(`div`,{className:b,children:[N,P]}),t[34]=N,t[35]=b,t[36]=F):F=t[36];let I;t[37]===a?I=t[38]:(I=a?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:a instanceof Error?a.message:String(a)}):null,t[37]=a,t[38]=I);let L;t[39]!==c||t[40]!==n.consentExpiredBanner?(L=c?(0,$.jsx)(`p`,{className:`rounded-lg border border-amber-500/25 bg-amber-500/5 px-3 py-2 text-xs text-fg-muted`,children:n.consentExpiredBanner}):null,t[39]=c,t[40]=n.consentExpiredBanner,t[41]=L):L=t[41];let R;t[42]!==g||t[43]!==l||t[44]!==p||t[45]!==m||t[46]!==_||t[47]!==r||t[48]!==h||t[49]!==d||t[50]!==o||t[51]!==f||t[52]!==s||t[53]!==n?(R=g?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[r.publicUrl?(0,$.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-3 py-3`,children:(0,$.jsx)(te,{label:n.publicUrlLabel,text:r.publicUrl,labels:l})}):null,_?(0,$.jsx)(Tc,{status:r,t:n}):null,r.lastError&&r.state===`error`?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:r.lastError}):null,(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.enabled?(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,disabled:s,onClick:m,children:[s?(0,$.jsx)(q,{className:`size-4 animate-spin`}):null,n.stop]}):(0,$.jsxs)(Y,{type:`button`,disabled:o,onClick:p,children:[o?(0,$.jsx)(q,{className:`size-4 animate-spin`}):(0,$.jsx)(D,{className:`size-4`}),n.start]})})]}):(0,$.jsxs)(`div`,{className:`space-y-4`,children:[f?(0,$.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:f}):null,(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-base font-semibold text-fg`,children:n.emptyStateTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:n.emptyStateBody})]}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-amber-500/25 bg-amber-500/5 px-3 py-2.5 text-xs text-fg-muted`,children:[(0,$.jsx)(Jt,{className:`mt-0.5 size-4 shrink-0 text-amber-600 dark:text-amber-400`}),(0,$.jsx)(`p`,{children:n.riskBannerBody})]}),h&&d?(0,$.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200`,children:d}):null,(0,$.jsxs)(Y,{type:`button`,disabled:o||h,onClick:p,className:`w-full sm:w-auto`,children:[o?(0,$.jsx)(q,{className:`size-4 animate-spin`}):(0,$.jsx)(D,{className:`size-4`}),n.start]})]}),t[42]=g,t[43]=l,t[44]=p,t[45]=m,t[46]=_,t[47]=r,t[48]=h,t[49]=d,t[50]=o,t[51]=f,t[52]=s,t[53]=n,t[54]=R):R=t[54];let z;return t[55]!==F||t[56]!==I||t[57]!==L||t[58]!==R||t[59]!==x?(z=(0,$.jsxs)(`section`,{className:x,children:[F,I,L,R]}),t[55]=F,t[56]=I,t[57]=L,t[58]=R,t[59]=x,t[60]=z):z=t[60],z}var Mc=`https://console.xopc.ai/keys/tunnel`,Nc={reconfiguring:!1};function Pc(e){let t=(0,Q.c)(84),{t:n,brokerSecretFromEnv:r,brokerSecretMissing:i,brokerSecretConfiguredInConfig:a,brokerSecretMaskedValue:o,brokerSecretDraft:s,savingBrokerSecret:c,brokerSecretNotice:l,copyFailedLabel:u,onDraftChange:d,onSave:f,onClear:p,sectionRef:m}=e,h=(0,Z.useId)(),g=i&&!r,_=!g,[v,y]=(0,Z.useReducer)(Lt,Nc),{reconfiguring:b}=v,x;t[0]!==a||t[1]!==s||t[2]!==r||t[3]!==b?(x=a&&!r&&!b&&!s.trim(),t[0]=a,t[1]=s,t[2]=r,t[3]=b,t[4]=x):x=t[4];let S=x,C;t[5]!==n.copied||t[6]!==n.copyKey||t[7]!==n.hideKey||t[8]!==n.showKey?(C={show:n.showKey,hide:n.hideKey,copy:n.copyKey,copied:n.copied},t[5]=n.copied,t[6]=n.copyKey,t[7]=n.hideKey,t[8]=n.showKey,t[9]=C):C=t[9];let w=C,T;t[10]===s?T=t[11]:(T=s.trim().length>0&&!Se(s.trim()),t[10]=s,t[11]=T);let E=T,D;t[12]===d?D=t[13]:(D=()=>{y({type:`patch`,patch:{reconfiguring:!1}}),d(``)},t[12]=d,t[13]=D);let O=D,k=g&&`ring-1 ring-amber-500/30`,A;t[14]===k?A=t[15]:(A=J(k),t[14]=k,t[15]=A);let j=_?`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`:g?`bg-amber-500/10 text-amber-700 dark:text-amber-400`:`bg-surface-hover text-fg-muted`,M;t[16]===j?M=t[17]:(M=J(`flex size-9 shrink-0 items-center justify-center rounded-lg`,j),t[16]=j,t[17]=M);let N;t[18]===_?N=t[19]:(N=_?(0,$.jsx)(tt,{className:`size-4`,strokeWidth:2,"aria-hidden":!0}):(0,$.jsx)(qt,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[18]=_,t[19]=N);let P;t[20]!==M||t[21]!==N?(P=(0,$.jsx)(`span`,{className:M,children:N}),t[20]=M,t[21]=N,t[22]=P):P=t[22];let F=_?n.brokerSecretReadyTitle:n.brokerSecretStepTitle,I;t[23]===F?I=t[24]:(I=(0,$.jsx)(`p`,{className:`text-sm font-semibold text-fg`,children:F}),t[23]=F,t[24]=I);let L=_?n.brokerSecretReadyHint:n.brokerSecretHint,R;t[25]===L?R=t[26]:(R=(0,$.jsx)(`p`,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:L}),t[25]=L,t[26]=R);let z;t[27]!==g||t[28]!==n.brokerSecretMissingHint?(z=g?(0,$.jsx)(`p`,{className:`mt-2 text-xs text-amber-800 dark:text-amber-200`,children:n.brokerSecretMissingHint}):null,t[27]=g,t[28]=n.brokerSecretMissingHint,t[29]=z):z=t[29];let B;t[30]!==I||t[31]!==R||t[32]!==z?(B=(0,$.jsxs)(`div`,{children:[I,R,z]}),t[30]=I,t[31]=R,t[32]=z,t[33]=B):B=t[33];let V;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,$.jsx)(fe,{className:`size-3`,"aria-hidden":!0}),t[34]=V):V=t[34];let ee;t[35]===n.brokerSecretConsoleLink?ee=t[36]:(ee=(0,$.jsxs)(`a`,{href:Mc,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex w-fit items-center gap-1 text-xs font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[n.brokerSecretConsoleLink,V]}),t[35]=n.brokerSecretConsoleLink,t[36]=ee);let H;t[37]!==r||t[38]!==n.brokerSecretEnvHint?(H=r?(0,$.jsx)(`p`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-xs text-fg-muted`,children:n.brokerSecretEnvHint}):null,t[37]=r,t[38]=n.brokerSecretEnvHint,t[39]=H):H=t[39];let U;t[40]!==a||t[41]!==s||t[42]!==r||t[43]!==o||t[44]!==E||t[45]!==O||t[46]!==u||t[47]!==h||t[48]!==g||t[49]!==p||t[50]!==d||t[51]!==f||t[52]!==b||t[53]!==c||t[54]!==w||t[55]!==S||t[56]!==n.brokerSecretCancelReconfigure||t[57]!==n.brokerSecretClear||t[58]!==n.brokerSecretMaskedHelp||t[59]!==n.brokerSecretNotInConfigFile||t[60]!==n.brokerSecretPlaceholder||t[61]!==n.brokerSecretReconfigure||t[62]!==n.brokerSecretRevealFailed||t[63]!==n.brokerSecretSave||t[64]!==n.brokerSecretSaveAndContinue||t[65]!==n.brokerSecretTitle?(U=S?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`label`,{className:`sr-only`,htmlFor:h,children:n.brokerSecretTitle}),(0,$.jsx)(ft,{id:h,value:o,labels:w,reveal:Fc,loadFailedLabel:u||n.brokerSecretRevealFailed,maskedHelp:n.brokerSecretMaskedHelp,notInConfigFile:n.brokerSecretNotInConfigFile,readOnly:!0}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:c,onClick:()=>{y({type:`patch`,patch:{reconfiguring:!0}})},children:n.brokerSecretReconfigure}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,disabled:c,onClick:p,children:n.brokerSecretClear})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`label`,{className:`sr-only`,htmlFor:h,children:n.brokerSecretTitle}),(0,$.jsx)(ft,{id:h,value:s,onChange:d,placeholder:n.brokerSecretPlaceholder,labels:w,disabled:c}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsxs)(Y,{type:`button`,disabled:c||!E,onClick:f,children:[c?(0,$.jsx)(q,{className:`size-4 animate-spin`}):null,g?n.brokerSecretSaveAndContinue:n.brokerSecretSave]}),a||r?(0,$.jsx)(Y,{type:`button`,variant:`ghost`,disabled:c,onClick:p,children:n.brokerSecretClear}):null,b?(0,$.jsx)(Y,{type:`button`,variant:`ghost`,disabled:c,onClick:O,children:n.brokerSecretCancelReconfigure}):null]})]}),t[40]=a,t[41]=s,t[42]=r,t[43]=o,t[44]=E,t[45]=O,t[46]=u,t[47]=h,t[48]=g,t[49]=p,t[50]=d,t[51]=f,t[52]=b,t[53]=c,t[54]=w,t[55]=S,t[56]=n.brokerSecretCancelReconfigure,t[57]=n.brokerSecretClear,t[58]=n.brokerSecretMaskedHelp,t[59]=n.brokerSecretNotInConfigFile,t[60]=n.brokerSecretPlaceholder,t[61]=n.brokerSecretReconfigure,t[62]=n.brokerSecretRevealFailed,t[63]=n.brokerSecretSave,t[64]=n.brokerSecretSaveAndContinue,t[65]=n.brokerSecretTitle,t[66]=U):U=t[66];let W;t[67]===l?W=t[68]:(W=l?(0,$.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,children:l}):null,t[67]=l,t[68]=W);let te;t[69]!==B||t[70]!==ee||t[71]!==H||t[72]!==U||t[73]!==W?(te=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[B,ee,H,U,W]}),t[69]=B,t[70]=ee,t[71]=H,t[72]=U,t[73]=W,t[74]=te):te=t[74];let G;t[75]!==P||t[76]!==te?(G=(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[P,te]}),t[75]=P,t[76]=te,t[77]=G):G=t[77];let ne;t[78]!==G||t[79]!==A?(ne=(0,$.jsx)(X,{className:A,children:G}),t[78]=G,t[79]=A,t[80]=ne):ne=t[80];let re;return t[81]!==m||t[82]!==ne?(re=(0,$.jsx)(`div`,{ref:m,id:`tunnel-broker-secret-setup`,children:ne}),t[81]=m,t[82]=ne,t[83]=re):re=t[83],re}function Fc(){return k().then(Ic)}function Ic(e){return e.registrationSecret??null}function Lc(e){let t=(0,Q.c)(10),{language:n,label:r,section:i,className:a}=e,o;t[0]!==n||t[1]!==i?(o=Je(n,i),t[0]=n,t[1]=i,t[2]=o):o=t[2];let s;t[3]===a?s=t[4]:(s=J(`inline-flex items-center gap-1 text-sm font-medium text-accent hover:underline`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,a),t[3]=a,t[4]=s);let c;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(fe,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t[5]=c):c=t[5];let l;return t[6]!==r||t[7]!==o||t[8]!==s?(l=(0,$.jsxs)(`a`,{href:o,target:`_blank`,rel:`noreferrer`,className:s,children:[r,c]}),t[6]=r,t[7]=o,t[8]=s,t[9]=l):l=t[9],l}var Rc=e(zn(),1),zc={width:216,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}};async function Bc(e){return Rc.toDataURL(e,zc)}function Vc(e){let t=e?.candidates??[],n=t.find(e=>e.kind===`lan`&&e.reachable),r=t.find(e=>e.kind===`lan`);return(n??r)?.url?.trim()??``}function Hc(e,t){let n=t.trim();return!n||!e?!1:e.candidates.some(e=>e.kind===`tunnel`&&e.url.trim()===n)}function Uc(e,t){return e?t?Vc(e)||e.recommended.url?.trim()||``:e.recommended.url?.trim()||``:``}function Wc(e,t){let n=t?.preferLan===!0,r=!!e,{mutate:i}=u(),a=(0,Z.useRef)(!1),{data:s}=d(r?`tunnel-status`:null,L,{refreshInterval:6e4}),{data:l,mutate:f}=d(r?`tunnel-pair-context`:null,ze,{refreshInterval:6e4});(0,Z.useEffect)(()=>{let e=()=>{i(`tunnel-status`),i(`tunnel-qr`),i(`tunnel-pair`),i(`tunnel-pair-context`)};return window.addEventListener(`tunnel-status`,e),()=>window.removeEventListener(`tunnel-status`,e)},[i]);let p=s?.state===`connected`&&!!s.publicUrl?.trim(),m=p&&!n,{data:h,mutate:g}=d(m&&r?`tunnel-qr`:null,B,{refreshInterval:4*6e4}),{data:_,mutate:v}=d(!m&&r&&l?.pairingReady?`tunnel-pair`:null,N,{refreshInterval:4*6e4}),[y,b]=(0,Z.useState)(``),[x,S]=(0,Z.useState)(``),[C,w]=(0,Z.useState)({pairContext:void 0,preferLan:n});if(!a.current&&(l!==C.pairContext||n!==C.preferLan)){w({pairContext:l,preferLan:n});let e=Uc(l,n);y!==e&&b(e)}let T=(0,Z.useCallback)(e=>{a.current=!0,b(e)},[]),E=(0,Z.useCallback)(()=>{let e=Uc(l,n);e&&(a.current=!0,b(e))},[l,n]),D=(0,Z.useCallback)(e=>{let t=e.trim();t&&(a.current=!0,b(t))},[]),O=(0,Z.useCallback)(e=>{a.current=!1,b(e?.trim()||Uc(l,n))},[l,n]),k=y.trim(),A=(0,Z.useMemo)(()=>{try{let e=new URL(k);return e.protocol===`http:`||e.protocol===`https:`}catch{return!1}},[k]),j=A&&c(k),M=!m&&!!(l&&!l.pairingReady&&l.blockReason===`GATEWAY_LOOPBACK_ONLY`),P=!m&&A&&!j&&!!_?.pairingSecret&&(l?.pairingReady===!0||!M),F=(0,Z.useMemo)(()=>{let e=Vc(l);return n?e||(k&&!Hc(l,k)?k:``):k},[l,n,k]),I=(0,Z.useMemo)(()=>{if(!e)return``;if(x.trim())return x.trim();if(m&&h?.qrPayload?.trim())return h.qrPayload.trim();if(!P||!_?.pairingSecret)return``;let t=l?.candidates.find(e=>e.kind===`tunnel`&&e.reachable),r=l?.candidates.find(e=>e.kind===`lan`&&e.reachable),i=n?F:t?.url??k;return i?o({baseUrl:i,pairingSecret:_.pairingSecret,lanUrl:n?null:t&&r?r.url:null}):``},[e,F,_?.pairingSecret,P,x,n,k,m,h?.qrPayload,l?.candidates]),R=be(()=>Bc(I),[I],{enabled:!!I,initial:null,errorData:null}),z=I?R.data:null,V=!!(I&&R.error!==null&&!R.loading);return{tunnelActive:p,tunnelStatus:s,tunnelQr:h,pairContext:l,pairBaseUrl:y,setPairBaseUrl:T,applySuggestedPairUrl:E,applyCandidateUrl:D,baseOk:A,localhostWarn:j,pairingBlocked:M,deepLink:I,qrPayload:I,qrDataUrl:z,qrGenFailed:V,encoding:!!(I&&!z&&!V),refreshQr:(0,Z.useCallback)(async e=>{if(e?.trim()){S(e.trim()),g({qrPayload:e.trim(),publicUrl:s?.publicUrl??``,lanUrl:h?.lanUrl??null},!1);return}S(``),await f(),m?await g():l?.pairingReady&&await v()},[v,f,g,l?.pairingReady,h?.lanUrl,s?.publicUrl,m]),resetPairBaseFromContext:O}}var Gc={actionError:null,starting:!1,stopping:!1,savingAutoStart:!1,consentOpen:!1,autoStartConfirmOpen:!1,releaseConfirmOpen:!1,releasing:!1,brokerSecretDraft:``,savingBrokerSecret:!1,brokerSecretNotice:null};function Kc({embedded:e=!1}){let t=a(e=>e.language),n=s(t).tunnelSettings,r=C(e=>e.token),i=!!r,[o,c]=(0,Z.useReducer)(Lt,Gc),{actionError:l,starting:u,stopping:f,savingAutoStart:p,consentOpen:m,autoStartConfirmOpen:h,releaseConfirmOpen:g,releasing:_,brokerSecretDraft:v,savingBrokerSecret:y,brokerSecretNotice:b}=o,x=(0,Z.useRef)(null),S=Wc(r??``),{data:w}=Fe(i),{data:T,error:E,isLoading:D,mutate:O}=d(i?`tunnel-status`:null,L,{refreshInterval:e=>u?1e3:e?.frpcDownload||e?.state===`connecting`||e?.state===`reconnecting`?2e3:6e4}),k=(0,Z.useMemo)(()=>{let e=w?.payload?.config;if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.tunnel;if(t&&typeof t==`object`&&!Array.isArray(t)&&t.autoStart===!0)return!0}return T?.config?.autoStart===!0},[w,T?.config?.autoStart]),A=(0,Z.useMemo)(()=>{let e=w?.payload?.config;if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.tunnel;if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t.registrationSecret;if(typeof e==`string`)return e}}return``},[w]),j=Se(A),M=T?.registrationSecret?.source===`env`,N=T?.registrationSecret?.source===`missing`,P=T?.registrationSecret?.configured===!0;(0,Z.useEffect)(()=>{let e=()=>{O()};return window.addEventListener(`tunnel-status`,e),()=>window.removeEventListener(`tunnel-status`,e)},[O]);let F=(0,Z.useMemo)(()=>[n.consentBullet1,n.consentBullet2,n.consentBullet3],[n.consentBullet1,n.consentBullet2,n.consentBullet3]),I=(0,Z.useCallback)(async()=>{c({type:`patch`,patch:{actionError:null}}),c({type:`patch`,patch:{starting:!0}});try{let e=await Ct();await O(),Qt(),await S.refreshQr(e.qrPayload)}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{starting:!1}})}},[O,S.refreshQr]),R=(0,Z.useCallback)(()=>{if(!P){c({type:`patch`,patch:{actionError:n.brokerSecretRequiredBeforeStart}}),x.current?.scrollIntoView({behavior:`smooth`,block:`start`});return}if(T?.consentRequired){c({type:`patch`,patch:{consentOpen:!0}});return}I()},[P,T?.consentRequired,I,n.brokerSecretRequiredBeforeStart]),z=(0,Z.useCallback)(async()=>{c({type:`patch`,patch:{consentOpen:!1}}),c({type:`patch`,patch:{actionError:null}});try{await Dt(),await Promise.all([O(),I()])}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}},[O,I]),B=(0,Z.useCallback)(async()=>{c({type:`patch`,patch:{actionError:null}}),c({type:`patch`,patch:{stopping:!0}});try{await _e(),await Promise.all([S.refreshQr(),O()]),Qt()}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{stopping:!1}})}},[O,S.refreshQr]),V=(0,Z.useCallback)(async e=>{c({type:`patch`,patch:{savingAutoStart:!0}}),c({type:`patch`,patch:{actionError:null}});try{await Te({autoStart:e}),Qt()}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{savingAutoStart:!1}})}},[]),ee=(0,Z.useCallback)(()=>{if(k){V(!1);return}if(T?.consentRequired){c({type:`patch`,patch:{actionError:n.consentExpiredBanner}});return}if(!T?.canAutoStart){c({type:`patch`,patch:{actionError:n.autoStartHint}});return}c({type:`patch`,patch:{autoStartConfirmOpen:!0}})},[V,T?.canAutoStart,T?.consentRequired,n,k]),H=(0,Z.useCallback)(async()=>{let e=v.trim();if(e){c({type:`patch`,patch:{savingBrokerSecret:!0,actionError:null,brokerSecretNotice:null}});try{await Te({registrationSecret:e}),c({type:`patch`,patch:{brokerSecretDraft:``,brokerSecretNotice:n.brokerSecretSaved}}),Qt(),await O(),c({type:`patch`,patch:{actionError:null}})}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{savingBrokerSecret:!1}})}}},[v,O,n.brokerSecretSaved]),U=(0,Z.useCallback)(async()=>{c({type:`patch`,patch:{savingBrokerSecret:!0,actionError:null,brokerSecretNotice:null}});try{await Te({registrationSecret:null}),c({type:`patch`,patch:{brokerSecretDraft:``,brokerSecretNotice:n.brokerSecretCleared}}),Qt(),await O()}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{savingBrokerSecret:!1}})}},[O,n.brokerSecretCleared]),W=(0,Z.useCallback)(async()=>{c({type:`patch`,patch:{releaseConfirmOpen:!1,actionError:null,releasing:!0}});try{await _e({release:!0}),await Promise.all([S.refreshQr(),O()]),Qt()}catch(e){c({type:`patch`,patch:{actionError:e instanceof Error?e.message:String(e)}})}finally{c({type:`patch`,patch:{releasing:!1}})}},[O,S.refreshQr]),te=(0,Z.useMemo)(()=>({copy:n.copyUrl,copied:n.copied,copyFailed:s(t).clipboard.copyFailed}),[t,n.copyUrl,n.copied]);if(!i)return(0,$.jsx)(`div`,{className:e?void 0:`mx-auto w-full max-w-app-main px-4 py-8`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})});let G=T??{enabled:!1,state:`disconnected`,subdomain:null,publicUrl:null,connectedSince:null,frpcPid:null,lastHeartbeatAt:null,lastError:null,consentRequired:!0,config:{autoStart:k,brokerUrl:`https://frp.xopc.ai/api`}},ne=T?.consentRequired&&(G.enabled||k||T?.consent?.acceptedAt),re=(0,$.jsx)(Pc,{t:n,brokerSecretFromEnv:M,brokerSecretMissing:N,brokerSecretConfiguredInConfig:j,brokerSecretMaskedValue:j?A:``,brokerSecretDraft:v,savingBrokerSecret:y,brokerSecretNotice:b,copyFailedLabel:s(t).clipboard.copyFailed,onDraftChange:e=>c({type:`patch`,patch:{brokerSecretDraft:e}}),onSave:()=>void H(),onClear:()=>void U(),sectionRef:x}),ie=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(hc,{open:m,title:n.consentTitle,intro:n.consentIntro,bullets:F,checkboxLabel:n.consentCheckbox,confirmLabel:ne?n.consentReconfirm:n.consentConfirm,cancelLabel:n.consentCancel,onConfirm:()=>void z(),onCancel:()=>c({type:`patch`,patch:{consentOpen:!1}})},m?`consent-open`:`consent-closed`),(0,$.jsx)(Ht,{open:h,title:n.autoStartConfirmTitle,description:n.autoStartConfirmBody,confirmLabel:n.autoStartConfirmLabel,cancelLabel:n.consentCancel,onConfirm:()=>{c({type:`patch`,patch:{autoStartConfirmOpen:!1}}),V(!0)},onCancel:()=>c({type:`patch`,patch:{autoStartConfirmOpen:!1}})}),(0,$.jsx)(Ht,{open:g,title:n.releaseConfirmTitle,description:n.releaseConfirmBody,confirmLabel:n.releaseConfirmLabel,cancelLabel:n.consentCancel,destructive:!0,onConfirm:()=>void W(),onCancel:()=>c({type:`patch`,patch:{releaseConfirmOpen:!1}})})]});return e?(0,$.jsxs)(`div`,{className:`flex w-full flex-col gap-4`,children:[l?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:l}):null,re,(0,$.jsx)(jc,{t:n,status:G,isLoading:D,statusErr:E,starting:u,stopping:f,showConsentExpired:!!ne,copyLabels:te,startDisabled:!P,startDisabledReason:P?void 0:n.brokerSecretRequiredBeforeStart,stepLabel:n.flowStepStart,onStart:R,onStop:()=>void B()}),(0,$.jsx)(dc,{pairQr:S,gatewayToken:r??``,streamlined:!0,onRefreshQr:()=>void S.refreshQr()}),(0,$.jsxs)(yr,{showLabel:n.showOptions,hideLabel:n.hideOptions,children:[(0,$.jsxs)(`label`,{className:J(`flex items-center gap-3 text-sm text-fg`,!k&&!T?.canAutoStart?`cursor-not-allowed opacity-60`:`cursor-pointer`),children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 rounded border-edge accent-accent`,checked:k,disabled:p||!k&&!T?.canAutoStart,onChange:ee}),n.autoStart]}),!T?.canAutoStart&&!k?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.autoStartHint}):null,G.subdomain||G.publicUrl?(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-edge-subtle pt-4`,children:[(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,disabled:_||f,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>c({type:`patch`,patch:{releaseConfirmOpen:!0}}),children:[_?(0,$.jsx)(q,{className:`size-4 animate-spin`}):null,n.release]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.releaseHint})]}):null]}),(0,$.jsx)(yr,{showLabel:n.showAdvanced,hideLabel:n.hideAdvanced,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-edge-subtle pt-4 text-xs text-fg-subtle`,children:[(0,$.jsxs)(`p`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(Ce,{className:`mt-0.5 size-4 shrink-0 text-accent`}),(0,$.jsx)(`span`,{children:n.brokerNote})]}),(0,$.jsx)(Lc,{language:t,label:n.brokerDocsLink,section:`public-tunnel`,className:`text-xs`})]})}),ie]}):(0,$.jsxs)(`div`,{className:e?`flex w-full flex-col gap-6`:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[e?null:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle})]}),l?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:l}):null,re,(0,$.jsx)(jc,{t:n,status:G,isLoading:D,statusErr:E,starting:u,stopping:f,showConsentExpired:!!ne,copyLabels:te,startDisabled:!P,startDisabledReason:P?void 0:n.brokerSecretRequiredBeforeStart,onStart:R,onStop:()=>void B()}),(0,$.jsx)(dc,{pairQr:S,gatewayToken:r??``}),G.subdomain||G.publicUrl?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,disabled:_||f,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>c({type:`patch`,patch:{releaseConfirmOpen:!0}}),children:[_?(0,$.jsx)(q,{className:`size-4 animate-spin`}):null,n.release]})}):null,G.subdomain||G.publicUrl?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.releaseHint}):null,(0,$.jsxs)(X,{children:[(0,$.jsx)(`h2`,{className:`mb-3 text-sm font-semibold text-fg`,children:n.optionsTitle}),(0,$.jsxs)(`label`,{className:J(`flex items-center gap-3 text-sm text-fg`,!k&&!T?.canAutoStart?`cursor-not-allowed opacity-60`:`cursor-pointer`),children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 rounded border-edge accent-accent`,checked:k,disabled:p||!k&&!T?.canAutoStart,onChange:ee}),n.autoStart]}),!T?.canAutoStart&&!k?(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:n.autoStartHint}):null]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-xs text-fg-subtle`,children:[(0,$.jsxs)(`p`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(Ce,{className:`mt-0.5 size-4 shrink-0 text-accent`}),(0,$.jsx)(`span`,{children:n.brokerNote})]}),(0,$.jsx)(Lc,{language:t,label:n.brokerDocsLink,section:`public-tunnel`,className:`text-xs`})]}),ie]})}async function qc(){let e=await T(`/api/exposure/status`);if(!e.ok)throw Error(`Failed to load exposure status (${e.status})`);return await e.json()}async function Jc(e=`serve`){let t=await T(`/api/exposure/tailscale/start`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({mode:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Start failed (${t.status})`)}return await t.json()}async function Yc(){let e=await T(`/api/exposure/tailscale/stop`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Stop failed (${e.status})`)}return await e.json()}var Xc=`https://tailscale.com/download`;function Zc(e){let t=(0,Q.c)(2),{label:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`a`,{href:Xc,target:`_blank`,rel:`noreferrer`,className:`font-medium text-accent hover:underline`,children:n}),t[0]=n,t[1]=r),r}function Qc({embedded:e=!1}){let t=a(e=>e.language),n=s(t).remoteAccess.tailscale,r=(0,Z.useMemo)(()=>({copy:n.copyUrl,copied:n.copied,copyFailed:s(t).clipboard.copyFailed}),[t,n.copyUrl,n.copied]),i=!!C(e=>e.token),[o,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),{data:f,mutate:p,isLoading:m}=d(i?`exposure-status`:null,qc,{refreshInterval:3e4}),h=f?.tailscale.hostname,g=f?.tailscale.active===!0,_=f?.tailscale.cliAvailable!==!1,v=h?`https://${h}/`:null,y=(0,Z.useCallback)(async()=>{c(!0),u(null);try{await Jc(`serve`),await p()}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(!1)}},[p]),b=(0,Z.useCallback)(async()=>{c(!0),u(null);try{await Yc(),await p()}catch(e){u(e instanceof Error?e.message:String(e))}finally{c(!1)}},[p]);if(!i)return null;let x=(0,$.jsxs)(`div`,{className:e?`space-y-4`:`mt-4 space-y-3`,children:[e?(0,$.jsxs)(`ol`,{className:`space-y-3 text-sm text-fg-muted`,children:[(0,$.jsxs)(`li`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center rounded-full bg-surface-hover text-xs font-semibold text-fg`,children:`1`}),(0,$.jsxs)(`span`,{children:[n.stepInstallBefore,(0,$.jsx)(Zc,{label:n.stepInstallLink}),n.stepInstallAfter]})]}),(0,$.jsxs)(`li`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center rounded-full bg-surface-hover text-xs font-semibold text-fg`,children:`2`}),(0,$.jsx)(`span`,{children:n.stepEnable})]}),(0,$.jsxs)(`li`,{className:`flex gap-2`,children:[(0,$.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center rounded-full bg-surface-hover text-xs font-semibold text-fg`,children:`3`}),(0,$.jsx)(`span`,{children:n.stepCopy})]})]}):null,e&&f?.tailscale.cliAvailable===!1?(0,$.jsxs)(`p`,{className:`rounded-lg border border-amber-500/25 bg-amber-500/5 px-3 py-2 text-sm text-fg-muted`,children:[n.cliMissingIntro,` `,(0,$.jsx)(Zc,{label:n.cliMissingDownloadLink}),n.cliMissingSuffix]}):null,m&&!f?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(X,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.statusLabel}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:g?n.statusActive:n.statusOff}),v?(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(te,{text:v,labels:r})}):null,l?(0,$.jsx)(`p`,{className:`mt-2 text-sm text-red-600 dark:text-red-400`,children:l}):null,(0,$.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:g?(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,disabled:o,onClick:()=>void b(),children:[o?(0,$.jsx)(q,{className:`mr-1 h-4 w-4 animate-spin`}):null,n.disableServe]}):(0,$.jsxs)(Y,{type:`button`,disabled:o||!_,onClick:()=>void y(),children:[o?(0,$.jsx)(q,{className:`mr-1 h-4 w-4 animate-spin`}):(0,$.jsx)(D,{className:`mr-1 h-4 w-4`}),n.enableServe]})})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.hint}),(0,$.jsx)(Lc,{language:t,label:n.docsLink,section:`tailscale-serve`,className:`mt-2`})]})]});return e?x:(0,$.jsxs)(X,{children:[(0,$.jsx)(vn,{icon:Ce,title:n.title,subtitle:n.subtitle}),x]})}function $c(){let e=(0,Q.c)(26),t=a(tl),n=C(el),r;e[0]===t?r=e[1]:(r=s(t),e[0]=t,e[1]=r);let i=r.remoteAccess.lan,o;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(o={preferLan:!0},e[2]=o):o=e[2];let c=Wc(n??``,o),l;e[3]!==i.subtitle||e[4]!==i.title?(l=(0,$.jsx)(vn,{icon:Be,title:i.title,subtitle:i.subtitle}),e[3]=i.subtitle,e[4]=i.title,e[5]=l):l=e[5];let u;e[6]===i.body?u=e[7]:(u=(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:i.body}),e[6]=i.body,e[7]=u);let d;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,$.jsx)(fe,{className:`size-3.5`,"aria-hidden":!0}),e[8]=d):d=e[8];let f;e[9]===i.link?f=e[10]:(f=(0,$.jsxs)(_t,{to:`/settings/gateway`,className:`inline-flex items-center gap-1.5 text-sm font-medium text-accent hover:underline`,children:[i.link,d]}),e[9]=i.link,e[10]=f);let p;e[11]!==u||e[12]!==f?(p=(0,$.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[u,f]}),e[11]=u,e[12]=f,e[13]=p):p=e[13];let m;e[14]!==l||e[15]!==p?(m=(0,$.jsxs)(X,{children:[l,p]}),e[14]=l,e[15]=p,e[16]=m):m=e[16];let h=n??``,g;e[17]===c?g=e[18]:(g=()=>void c.refreshQr(),e[17]=c,e[18]=g);let _;e[19]!==c||e[20]!==h||e[21]!==g?(_=(0,$.jsx)(dc,{pairQr:c,gatewayToken:h,lanOnly:!0,onRefreshQr:g}),e[19]=c,e[20]=h,e[21]=g,e[22]=_):_=e[22];let v;return e[23]!==_||e[24]!==m?(v=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[m,_]}),e[23]=_,e[24]=m,e[25]=v):v=e[25],v}function el(e){return e.token}function tl(e){return e.language}function nl(e){let t=(0,Q.c)(30),{embedded:n}=e,r=n===void 0?!1:n,i=a(rl),o;t[0]===i?o=t[1]:(o=s(i),t[0]=i,t[1]=o);let c=o.remoteAccess.ssh,[l,u]=(0,Z.useState)(!1),d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=async()=>{await Gt(`xopc gateway ssh-tunnel --target user@your-host --local-port 18790 --remote-port 18790`)&&(u(!0),setTimeout(()=>u(!1),2e3))},t[2]=d):d=t[2];let f=d,p;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(`pre`,{className:`overflow-x-auto rounded-lg border border-edge bg-surface px-3 py-2 text-xs text-fg-muted`,children:`xopc gateway ssh-tunnel --target user@your-host --local-port 18790 --remote-port 18790`}),t[3]=p):p=t[3];let h,g;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>void f(),g=(0,$.jsx)(m,{className:`mr-1 h-4 w-4`}),t[4]=h,t[5]=g):(h=t[4],g=t[5]);let _=l?c.copied:c.copy,v;t[6]===_?v=t[7]:(v=(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,onClick:h,children:[g,_]})}),t[6]=_,t[7]=v);let y;t[8]!==r||t[9]!==c.hint?(y=r?(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:c.hint}):null,t[8]=r,t[9]=c.hint,t[10]=y):y=t[10];let b;t[11]!==v||t[12]!==y?(b=(0,$.jsxs)($.Fragment,{children:[p,v,y]}),t[11]=v,t[12]=y,t[13]=b):b=t[13];let x=b;if(r){let e;t[14]!==c.subtitle||t[15]!==c.title?(e=(0,$.jsx)(vn,{icon:I,title:c.title,subtitle:c.subtitle}),t[14]=c.subtitle,t[15]=c.title,t[16]=e):e=t[16];let n;t[17]===x?n=t[18]:(n=(0,$.jsx)(`div`,{className:`mt-4 space-y-2`,children:x}),t[17]=x,t[18]=n);let r;return t[19]!==e||t[20]!==n?(r=(0,$.jsxs)(X,{children:[e,n]}),t[19]=e,t[20]=n,t[21]=r):r=t[21],r}let S;t[22]!==c.subtitle||t[23]!==c.title?(S=(0,$.jsx)(vn,{icon:I,title:c.title,subtitle:c.subtitle}),t[22]=c.subtitle,t[23]=c.title,t[24]=S):S=t[24];let C;t[25]===x?C=t[26]:(C=(0,$.jsx)(`div`,{className:`mt-4`,children:x}),t[25]=x,t[26]=C);let w;return t[27]!==S||t[28]!==C?(w=(0,$.jsxs)(X,{children:[S,C]}),t[27]=S,t[28]=C,t[29]=w):w=t[29],w}function rl(e){return e.language}function il(){let e=(0,Q.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(nl,{embedded:!0}),e[0]=t):t=e[0],t}function al(e){switch(e){case`active`:return`bg-emerald-500/15 text-emerald-700 dark:text-emerald-400`;case`connecting`:return`bg-amber-500/15 text-amber-700 dark:text-amber-400`;default:return`bg-surface-hover text-fg-muted`}}function ol(e){let t=(0,Q.c)(5),{label:n,kind:r}=e,i;t[0]===r?i=t[1]:(i=J(`rounded-full px-2 py-0.5 text-[11px] font-medium`,al(r)),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,$.jsx)(`span`,{className:i,children:n}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a}function sl(e){let t=(0,Q.c)(32),{onOpenTab:n}=e,r=a(ul),i;t[0]===r?i=t[1]:(i=s(r),t[0]=r,t[1]=i);let o=i.remoteAccess.guide,c=!!C(ll),l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l={refreshInterval:3e4},t[2]=l):l=t[2];let{data:u}=d(c?`exposure-status`:null,qc,l),f;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(f={refreshInterval:15e3},t[3]=f):f=t[3];let{data:p}=d(c?`tunnel-status`:null,L,f),m;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m={refreshInterval:6e4},t[4]=m):m=t[4];let{data:h}=d(c?`tunnel-pair-context`:null,ze,m);if(!c)return null;let g=u?.tailscale.active===!0,_=p?.state,v=p?.enabled&&_===`connected`,y=p?.enabled&&(_===`connecting`||_===`reconnecting`||!!p?.startProgress||!!p?.frpcDownload),b=(h?.candidates??[]).some(cl),x=g?`active`:`off`,S=g?o.statusActive:o.statusOff,w;t[5]!==o.tailscaleCardTitle||t[6]!==x||t[7]!==S?(w={tab:`tailscale`,icon:Ce,title:o.tailscaleCardTitle,kind:x,statusLabel:S},t[5]=o.tailscaleCardTitle,t[6]=x,t[7]=S,t[8]=w):w=t[8];let T=v?`active`:y?`connecting`:`off`,E=v?o.statusActive:y?o.statusConnecting:o.statusOff,D;t[9]!==o.publicCardTitle||t[10]!==T||t[11]!==E?(D={tab:`public`,icon:it,title:o.publicCardTitle,kind:T,statusLabel:E},t[9]=o.publicCardTitle,t[10]=T,t[11]=E,t[12]=D):D=t[12];let O=b?`active`:`off`,k=b?o.statusActive:o.statusOff,A;t[13]!==o.reverseProxyCardTitle||t[14]!==O||t[15]!==k?(A={tab:`reverse-proxy`,icon:Me,title:o.reverseProxyCardTitle,kind:O,statusLabel:k},t[13]=o.reverseProxyCardTitle,t[14]=O,t[15]=k,t[16]=A):A=t[16];let j;t[17]!==o.sshCardStatus||t[18]!==o.sshCardTitle?(j={tab:`ssh`,icon:I,title:o.sshCardTitle,kind:`off`,statusLabel:o.sshCardStatus},t[17]=o.sshCardStatus,t[18]=o.sshCardTitle,t[19]=j):j=t[19];let M;t[20]!==o.lanCardStatus||t[21]!==o.lanCardTitle?(M={tab:`lan`,icon:Be,title:o.lanCardTitle,kind:`off`,statusLabel:o.lanCardStatus},t[20]=o.lanCardStatus,t[21]=o.lanCardTitle,t[22]=M):M=t[22];let N;t[23]!==D||t[24]!==A||t[25]!==j||t[26]!==M||t[27]!==w?(N=[w,D,A,j,M],t[23]=D,t[24]=A,t[25]=j,t[26]=M,t[27]=w,t[28]=N):N=t[28];let P=N,F;return t[29]!==P||t[30]!==n?(F=(0,$.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5`,children:P.map(e=>{let t=e.icon;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(e.tab),className:J(`flex items-start gap-3 rounded-xl border border-edge-subtle bg-surface-base px-3 py-2.5 text-left transition-colors`,`hover:border-edge hover:bg-surface-hover/50`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),children:[(0,$.jsx)(`span`,{className:`flex size-8 shrink-0 items-center justify-center rounded-lg bg-surface-hover/90 text-fg-muted`,children:(0,$.jsx)(t,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-sm font-medium text-fg`,children:e.title}),(0,$.jsx)(ol,{label:e.statusLabel,kind:e.kind})]})]},`${e.tab}-${e.title}`)})}),t[29]=P,t[30]=n,t[31]=F):F=t[31],F}function cl(e){return e.kind===`reverse-proxy`}function ll(e){return e.token}function ul(e){return e.language}function dl(e){let t=(0,Q.c)(26),{title:n,description:r,recommended:i,icon:a,onOpen:o,openLabel:s,recommendedLabel:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=J(`group flex w-full flex-col rounded-2xl bg-surface-base px-4 py-4 text-left transition-colors`,`hover:bg-surface-hover/40`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),t[0]=l):l=t[0];let u;t[1]===a?u=t[2]:(u=(0,$.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-surface-hover/90 text-fg-muted`,children:(0,$.jsx)(a,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0})}),t[1]=a,t[2]=u);let d;t[3]===n?d=t[4]:(d=(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n}),t[3]=n,t[4]=d);let f;t[5]!==i||t[6]!==c?(f=i&&c?(0,$.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-[11px] font-medium text-accent-fg`,children:c}):null,t[5]=i,t[6]=c,t[7]=f):f=t[7];let p;t[8]!==d||t[9]!==f?(p=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d,f]}),t[8]=d,t[9]=f,t[10]=p):p=t[10];let m;t[11]===r?m=t[12]:(m=(0,$.jsx)(`p`,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:r}),t[11]=r,t[12]=m);let h;t[13]!==p||t[14]!==m?(h=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[p,m]}),t[13]=p,t[14]=m,t[15]=h):h=t[15];let g;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(Nt,{className:`mt-0.5 size-4 shrink-0 text-fg-subtle transition-transform group-hover:translate-x-0.5`,"aria-hidden":!0}),t[16]=g):g=t[16];let _;t[17]!==u||t[18]!==h?(_=(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[u,h,g]}),t[17]=u,t[18]=h,t[19]=_):_=t[19];let v;t[20]===s?v=t[21]:(v=(0,$.jsx)(`span`,{className:`mt-3 text-xs font-medium text-accent`,children:s}),t[20]=s,t[21]=v);let y;return t[22]!==o||t[23]!==v||t[24]!==_?(y=(0,$.jsxs)(`button`,{type:`button`,onClick:o,className:l,children:[_,v]}),t[22]=o,t[23]=v,t[24]=_,t[25]=y):y=t[25],y}function fl(e){let t=(0,Q.c)(83),{onOpenTab:n}=e,r=a(hl),i;t[0]===r?i=t[1]:(i=s(r),t[0]=r,t[1]=i);let o=i.remoteAccess,c=o.guide,l=!!C(ml),u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u={refreshInterval:3e4},t[2]=u):u=t[2];let{data:f}=d(l?`exposure-status`:null,qc,u),p;t[3]===f?.conflicts?p=t[4]:(p=f?.conflicts??[],t[3]=f?.conflicts,t[4]=p);let m=p;if(!l){let e;return t[5]===c.needToken?e=t[6]:(e=(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:c.needToken}),t[5]=c.needToken,t[6]=e),e}let h;t[7]===n?h=t[8]:(h=(0,$.jsx)(sl,{onOpenTab:n}),t[7]=n,t[8]=h);let g;t[9]!==m||t[10]!==c.conflictsHint||t[11]!==c.conflictsTitle?(g=m.length>0?(0,$.jsxs)(`div`,{className:`rounded-xl border border-amber-500/30 bg-amber-500/5 px-4 py-3 text-sm text-fg-muted`,children:[(0,$.jsx)(`p`,{className:`font-medium text-fg`,children:c.conflictsTitle}),(0,$.jsx)(`p`,{className:`mt-1`,children:c.conflictsHint}),(0,$.jsx)(`ul`,{className:`mt-2 list-inside list-disc text-xs`,children:m.map(pl)})]}):null,t[9]=m,t[10]=c.conflictsHint,t[11]=c.conflictsTitle,t[12]=g):g=t[12];let _;t[13]===c.pickMethod?_=t[14]:(_=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:c.pickMethod}),t[13]=c.pickMethod,t[14]=_);let v;t[15]===n?v=t[16]:(v=()=>n(`tailscale`),t[15]=n,t[16]=v);let y;t[17]!==c.configure||t[18]!==c.recommended||t[19]!==c.tailscaleCardDesc||t[20]!==c.tailscaleCardTitle||t[21]!==v?(y=(0,$.jsx)(dl,{icon:Ce,title:c.tailscaleCardTitle,description:c.tailscaleCardDesc,recommended:!0,recommendedLabel:c.recommended,openLabel:c.configure,onOpen:v}),t[17]=c.configure,t[18]=c.recommended,t[19]=c.tailscaleCardDesc,t[20]=c.tailscaleCardTitle,t[21]=v,t[22]=y):y=t[22];let b;t[23]===n?b=t[24]:(b=()=>n(`public`),t[23]=n,t[24]=b);let x;t[25]!==c.configure||t[26]!==c.publicCardDesc||t[27]!==c.publicCardTitle||t[28]!==b?(x=(0,$.jsx)(dl,{icon:it,title:c.publicCardTitle,description:c.publicCardDesc,openLabel:c.configure,onOpen:b}),t[25]=c.configure,t[26]=c.publicCardDesc,t[27]=c.publicCardTitle,t[28]=b,t[29]=x):x=t[29];let S;t[30]===n?S=t[31]:(S=()=>n(`reverse-proxy`),t[30]=n,t[31]=S);let w;t[32]!==c.configure||t[33]!==c.reverseProxyCardDesc||t[34]!==c.reverseProxyCardTitle||t[35]!==S?(w=(0,$.jsx)(dl,{icon:Me,title:c.reverseProxyCardTitle,description:c.reverseProxyCardDesc,openLabel:c.configure,onOpen:S}),t[32]=c.configure,t[33]=c.reverseProxyCardDesc,t[34]=c.reverseProxyCardTitle,t[35]=S,t[36]=w):w=t[36];let T;t[37]===n?T=t[38]:(T=()=>n(`ssh`),t[37]=n,t[38]=T);let E;t[39]!==c.configure||t[40]!==c.sshCardDesc||t[41]!==c.sshCardTitle||t[42]!==T?(E=(0,$.jsx)(dl,{icon:I,title:c.sshCardTitle,description:c.sshCardDesc,openLabel:c.configure,onOpen:T}),t[39]=c.configure,t[40]=c.sshCardDesc,t[41]=c.sshCardTitle,t[42]=T,t[43]=E):E=t[43];let D;t[44]===n?D=t[45]:(D=()=>n(`lan`),t[44]=n,t[45]=D);let O;t[46]!==c.configure||t[47]!==c.lanCardDesc||t[48]!==c.lanCardTitle||t[49]!==D?(O=(0,$.jsx)(dl,{icon:Be,title:c.lanCardTitle,description:c.lanCardDesc,openLabel:c.configure,onOpen:D}),t[46]=c.configure,t[47]=c.lanCardDesc,t[48]=c.lanCardTitle,t[49]=D,t[50]=O):O=t[50];let k;t[51]!==x||t[52]!==w||t[53]!==E||t[54]!==O||t[55]!==y?(k=(0,$.jsxs)(`div`,{className:`mt-3 grid gap-3 lg:grid-cols-2`,children:[y,x,w,E,O]}),t[51]=x,t[52]=w,t[53]=E,t[54]=O,t[55]=y,t[56]=k):k=t[56];let A;t[57]!==k||t[58]!==_?(A=(0,$.jsxs)(`div`,{children:[_,k]}),t[57]=k,t[58]=_,t[59]=A):A=t[59];let j;t[60]===c.oneAtATimeHint?j=t[61]:(j=(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:c.oneAtATimeHint}),t[60]=c.oneAtATimeHint,t[61]=j);let M;t[62]===o.advanced.proxyTitle?M=t[63]:(M=(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:o.advanced.proxyTitle}),t[62]=o.advanced.proxyTitle,t[63]=M);let N;t[64]===o.advanced.proxyBody?N=t[65]:(N=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:o.advanced.proxyBody}),t[64]=o.advanced.proxyBody,t[65]=N);let P;t[66]!==r||t[67]!==o.advanced.proxyDocs?(P=(0,$.jsx)(Lc,{language:r,label:o.advanced.proxyDocs,section:`advanced`,className:`mt-2`}),t[66]=r,t[67]=o.advanced.proxyDocs,t[68]=P):P=t[68];let F;t[69]!==M||t[70]!==N||t[71]!==P?(F=(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-base px-4 py-3`,children:[M,N,P]}),t[69]=M,t[70]=N,t[71]=P,t[72]=F):F=t[72];let L;t[73]!==c.docsLink||t[74]!==r?(L=(0,$.jsx)(Lc,{language:r,label:c.docsLink}),t[73]=c.docsLink,t[74]=r,t[75]=L):L=t[75];let R;return t[76]!==A||t[77]!==j||t[78]!==F||t[79]!==L||t[80]!==h||t[81]!==g?(R=(0,$.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[h,g,A,j,F,L]}),t[76]=A,t[77]=j,t[78]=F,t[79]=L,t[80]=h,t[81]=g,t[82]=R):R=t[82],R}function pl(e){return(0,$.jsx)(`li`,{children:e.message},e.code)}function ml(e){return e.token}function hl(e){return e.language}async function gl(e){let t=await T(l(`/api/tunnel/pair/probe-public`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:e})});if(!t.ok&&t.status!==400)throw Error(`Probe failed (${t.status})`);return await t.json()}async function _l(e){await w(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{publicUrl:e??null}})})}function vl(e){let t=e.split(`.`).map(e=>Number.parseInt(e,10));if(t.length!==4||t.some(e=>!Number.isFinite(e)))return!1;let[n,r]=t;return n===10||n===127||n===169&&r===254||n===172&&r>=16&&r<=31||n===192&&r===168||n===100&&r>=64&&r<=127}function yl(){return(0,Z.useMemo)(()=>{if(typeof window>`u`)return null;let{protocol:e,hostname:t,origin:n}=window.location;if(e!==`https:`&&e!==`http:`)return null;let r=t.toLowerCase();return!r||r===`localhost`||r===`127.0.0.1`||r===`::1`||r===`[::1]`||r.endsWith(`.local`)||r.endsWith(`.localhost`)||vl(r)?null:n.toLowerCase().replace(/\/+$/,``)},[])}function bl(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ht,`dark:border-edge`)}function xl(e){return(e?.candidates.find(e=>e.kind===`reverse-proxy`))?.url?.trim()||null}function Sl(e){return(e?.candidates.find(e=>e.kind===`lan`&&e.reachable))?.url?.trim()||null}function Cl(){let e=a(e=>e.language),t=s(e).remoteAccess.reverseProxy,n=!!C(e=>e.token),r=yl(),{mutate:i}=u(),{data:c,mutate:l}=d(n?`tunnel-pair-context`:null,ze,{refreshInterval:6e4}),f=xl(c),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)({busy:!1,result:null}),[_,v]=(0,Z.useState)({busy:!1,error:null});(0,Z.useEffect)(()=>{p||(f?m(f):r&&m(r))},[f,r,p]);let y=(0,Z.useMemo)(()=>p.trim()||(f??r??``),[f,r,p]),b=!f&&!!r&&y===r,x=Sl(c),{data:S,mutate:w}=d(n&&y?[`reverse-proxy-pair`,y]:null,()=>N(),{refreshInterval:4*6e4,revalidateOnFocus:!1}),T=(0,Z.useMemo)(()=>!y||!S?.pairingSecret?``:o({baseUrl:y,pairingSecret:S.pairingSecret,lanUrl:x}),[y,x,S?.pairingSecret]),E=be(()=>Bc(T),[T],{enabled:!!T,initial:null,errorData:null}),D=(0,Z.useCallback)(async()=>{let e=p.trim()||y;if(e){g({busy:!0,result:null});try{g({busy:!1,result:await gl(e)})}catch(e){g({busy:!1,result:{ok:!1,code:`NETWORK_ERROR`,message:e instanceof Error?e.message:String(e)}})}}},[p,y]),O=(0,Z.useCallback)(async()=>{let e=y.trim();if(e){v({busy:!0,error:null});try{await _l(e),await l(),await i(`tunnel-pair-context`),v({busy:!1,error:null})}catch(e){v({busy:!1,error:e instanceof Error?e.message:String(e)})}}},[y,i,l]),k=(0,Z.useCallback)(async()=>{v({busy:!0,error:null});try{await _l(null),await l(),await i(`tunnel-pair-context`),m(``),g({busy:!1,result:null}),v({busy:!1,error:null})}catch(e){v({busy:!1,error:e instanceof Error?e.message:String(e)})}},[i,l]),A=(0,Z.useCallback)(async()=>{await w()},[w]);return n?(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(X,{children:[(0,$.jsx)(vn,{icon:Ce,title:t.title,subtitle:t.subtitle}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,$.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`reverse-proxy-url`,children:t.urlLabel}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-stretch`,children:[(0,$.jsx)(`input`,{id:`reverse-proxy-url`,className:J(bl(),`font-mono text-xs sm:flex-1 sm:min-w-0 sm:w-auto`),type:`text`,autoComplete:`off`,spellCheck:!1,placeholder:t.urlPlaceholder,value:p,onChange:e=>{m(e.target.value),g({busy:!1,result:null})}}),(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,className:`shrink-0 whitespace-nowrap`,onClick:()=>void D(),disabled:h.busy||!p.trim(),children:[h.busy?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):null,h.busy?t.probing:t.probeButton]})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:t.urlHint}),b&&r?(0,$.jsxs)(`div`,{className:`rounded-lg border border-accent/40 bg-accent-soft/50 px-3 py-2 text-xs leading-relaxed text-accent-fg`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:t.autoDetectedTitle}),(0,$.jsx)(`div`,{className:`mt-1 break-all font-mono text-[11px]`,children:r}),(0,$.jsx)(`p`,{className:`mt-1`,children:t.autoDetectedHint})]}):null,h.result?(0,$.jsx)(wl,{result:h.result,labels:t.probeStatus}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:flex-wrap`,children:[y&&f!==y?(0,$.jsxs)(Y,{type:`button`,onClick:()=>void O(),disabled:_.busy,children:[_.busy?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):null,_.busy?t.saving:t.saveAsDefault]}):null,f?(0,$.jsx)(Y,{type:`button`,variant:`ghost`,onClick:()=>void k(),disabled:_.busy,children:t.clear}):null]}),_.error?(0,$.jsx)(`p`,{className:`text-xs text-red-800 dark:text-red-200`,children:_.error}):null,(0,$.jsx)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs leading-relaxed text-amber-950 dark:border-amber-800/60 dark:bg-amber-950/30 dark:text-amber-100`,children:t.certWarning})]})]}),(0,$.jsxs)(X,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-start justify-between gap-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:t.qrTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:t.qrSubtitle})]}),T?(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`shrink-0`,onClick:()=>void A(),children:[(0,$.jsx)(Ze,{className:`size-4`}),t.refreshQr]}):null]}),y?S?.pairingSecret?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[(0,$.jsxs)(`div`,{className:`break-all font-mono text-[11px] text-fg-muted`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:`baseUrl:`}),` `,y,x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`br`,{}),(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:`lanUrl:`}),` `,x]}):null]}),E.data?(0,$.jsx)(`img`,{src:E.data,alt:``,className:`size-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):E.loading?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.encoding}):null,(0,$.jsx)(te,{text:T,labels:{copy:t.copyLink,copied:t.copied,copyFailed:s(e).clipboard.copyFailed}})]}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.mintingSecret}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.noUrlYet})]})]}):null}function wl(e){let t=(0,Q.c)(18),{result:n,labels:r}=e;if(n.ok){let e;t[0]===r.ok?e=t[1]:(e=(0,$.jsx)(`span`,{className:`font-medium`,children:r.ok}),t[0]=r.ok,t[1]=e);let i;t[2]===n.latencyMs?i=t[3]:(i=(0,$.jsxs)(`span`,{className:`font-mono`,children:[n.latencyMs,`ms`]}),t[2]=n.latencyMs,t[3]=i);let a;t[4]!==r.mobileReady||t[5]!==n.mobilePairing?(a=n.mobilePairing?(0,$.jsxs)($.Fragment,{children:[` · `,(0,$.jsx)(`span`,{children:r.mobileReady})]}):null,t[4]=r.mobileReady,t[5]=n.mobilePairing,t[6]=a):a=t[6];let o;return t[7]!==e||t[8]!==i||t[9]!==a?(o=(0,$.jsxs)(`div`,{className:`rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs text-emerald-900 dark:border-emerald-800/60 dark:bg-emerald-950/30 dark:text-emerald-100`,children:[e,` · `,i,a]}),t[7]=e,t[8]=i,t[9]=a,t[10]=o):o=t[10],o}let i=r[`code_${n.code}`]??r.codeUnknown,a;t[11]===i?a=t[12]:(a=(0,$.jsx)(`span`,{className:`font-medium`,children:i}),t[11]=i,t[12]=a);let o;t[13]===n.message?o=t[14]:(o=n.message?(0,$.jsxs)($.Fragment,{children:[` — `,(0,$.jsx)(`span`,{className:`font-mono break-all`,children:n.message})]}):null,t[13]=n.message,t[14]=o);let s;return t[15]!==a||t[16]!==o?(s=(0,$.jsxs)(`div`,{className:`rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-900 dark:border-red-800/60 dark:bg-red-950/30 dark:text-red-100`,children:[a,o]}),t[15]=a,t[16]=o,t[17]=s):s=t[17],s}var Tl=[`guide`,`tailscale`,`public`,`reverse-proxy`,`ssh`,`lan`];function El(e){return e&&Tl.includes(e)?e:`guide`}function Dl(e,t){return e.tabs[t]}function Ol(e,t){return e.tabIntro[t]}function kl(e){switch(e){case`tailscale`:return`tailscale-serve`;case`public`:return`public-tunnel`;case`reverse-proxy`:return`reverse-proxy`;case`ssh`:return`ssh-tunnel`;case`lan`:return`lan`;default:return}}function Al(e){let t=(0,Q.c)(7),{tab:n,onOpenTab:r}=e;switch(n){case`guide`:{let e;return t[0]===r?e=t[1]:(e=(0,$.jsx)(fl,{onOpenTab:r}),t[0]=r,t[1]=e),e}case`tailscale`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Qc,{embedded:!0}),t[2]=e):e=t[2],e}case`public`:{let e;return t[3]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Kc,{embedded:!0}),t[3]=e):e=t[3],e}case`reverse-proxy`:{let e;return t[4]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Cl,{}),t[4]=e):e=t[4],e}case`ssh`:{let e;return t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(il,{}),t[5]=e):e=t[5],e}case`lan`:{let e;return t[6]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)($c,{}),t[6]=e):e=t[6],e}}}function jl(){let e=(0,Q.c)(2),t=a(Nl),n=s(t).remoteAccess,r=!!C(Ml),[i,o]=Zt(),c=El(i.get(`tab`)),l;e[0]===o?l=e[1]:(l=e=>{o(t=>{let n=new URLSearchParams(t);return e===`guide`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},e[0]=o,e[1]=l);let u=l,d=Ol(n,c);return(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-5 px-4 py-8`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.pageTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.pageSubtitle}),(0,$.jsx)(Lc,{language:t,label:n.docsLink,section:kl(c),className:`mt-1`})]}),r?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,role:`tablist`,"aria-label":n.tabsAria,onKeyDown:e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=Tl[(Tl.indexOf(c)+(e.key===`ArrowRight`?1:-1)+Tl.length)%Tl.length];u(t)},children:[(0,$.jsx)(`div`,{className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,children:Tl.map(e=>{let t=e===c;return(0,$.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":t,id:`remote-access-tab-${e}`,"aria-controls":`remote-access-panel-${e}`,className:J(`shrink-0 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,t?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>u(e),children:Dl(n,e)},e)})}),c===`public`?null:(0,$.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:d}),(0,$.jsx)(`div`,{role:`tabpanel`,id:`remote-access-panel-${c}`,"aria-labelledby":`remote-access-tab-${c}`,className:`min-w-0`,children:(0,$.jsx)(Al,{tab:c,onOpenTab:u})})]}):(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.guide.needToken})]})}function Ml(e){return e.token}function Nl(e){return e.language}var Pl={enabled:!0,defaultTtlHours:24,maxTtlDays:7,maxActiveShares:100,maxFileSizeMb:100,inlinePreviewMimes:[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`image/svg+xml`,`application/pdf`,`text/html`,`text/markdown`,`text/plain`,`application/json`]},Fl=36e5,Il=864e5,Ll=1048576;function Rl(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function zl(e,t=32){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()).slice(0,t):[]}function Bl(e){let t=Rl(e)?e:{},n=Rl(t.gateway)?t.gateway:{},r=Rl(n.share)?n.share:{},i=typeof r.defaultTtlMs==`number`&&Number.isFinite(r.defaultTtlMs)?Math.floor(r.defaultTtlMs):Pl.defaultTtlHours*Fl,a=typeof r.maxTtlMs==`number`&&Number.isFinite(r.maxTtlMs)?Math.floor(r.maxTtlMs):Pl.maxTtlDays*Il,o=typeof r.maxFileSize==`number`&&Number.isFinite(r.maxFileSize)?Math.floor(r.maxFileSize):Pl.maxFileSizeMb*Ll;return{enabled:r.enabled!==!1,defaultTtlHours:Math.max(1,Math.round(i/Fl)),maxTtlDays:Math.max(1,Math.round(a/Il)),maxActiveShares:typeof r.maxActiveShares==`number`&&Number.isFinite(r.maxActiveShares)?Math.max(1,Math.min(1e4,Math.floor(r.maxActiveShares))):Pl.maxActiveShares,maxFileSizeMb:Math.max(1,Math.round(o/Ll)),inlinePreviewMimes:zl(r.inlinePreviewMimes,32).length?zl(r.inlinePreviewMimes,32):[...Pl.inlinePreviewMimes]}}function Vl(e){let t=e.defaultTtlHours*Fl,n=e.maxTtlDays*Il;return t<6e4||t>6048e5?`Default share TTL must be between 1 minute and 7 days.`:n<6e4||n>2592e6?`Maximum share TTL must be between 1 minute and 30 days.`:t>n?`Default TTL cannot exceed maximum TTL.`:e.maxFileSizeMb<1||e.maxFileSizeMb>10240?`Maximum file size must be between 1 MB and 10 GB.`:null}async function Hl(e){let t=Vl(e);if(t)throw Error(t);await w(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{share:{enabled:e.enabled,defaultTtlMs:e.defaultTtlHours*Fl,maxTtlMs:e.maxTtlDays*Il,maxActiveShares:e.maxActiveShares,maxFileSize:e.maxFileSizeMb*Ll,inlinePreviewMimes:e.inlinePreviewMimes}}})}),Qt()}function Ul(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ht,`dark:border-edge`)}function Wl({hasToken:e}){let t=s(a(e=>e.language)).sharesSettings,{data:n,isLoading:r}=Fe(e),i=(0,Z.useMemo)(()=>n?.payload?.config===void 0?null:structuredClone(Bl(n.payload.config)),[n]),o=(0,Z.useRef)(!1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),g=c??i,_=i,v=(0,Z.useMemo)(()=>!g||!_?!1:JSON.stringify(g)!==JSON.stringify(_),[g,_]),y=(0,Z.useCallback)(e=>{o.current=!0,l(t=>{let n=t??_;return n?{...n,...e}:null})},[_]),b=(0,Z.useCallback)(async()=>{if(!(!g||u)){d(!0),p(null),h(!1);try{await Hl(g),o.current=!1,l(null),h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:t.policySaveError)}finally{d(!1)}}},[g,u,t.policySaveError]),x=(0,Z.useCallback)(()=>{o.current=!1,l(null),p(null),h(!1)},[]);return!e||!g?r?(0,$.jsx)(X,{children:(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),t.policyLoading]})}):null:(0,$.jsxs)(X,{children:[(0,$.jsxs)(`div`,{className:`mb-4 flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.policyTitle}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:t.policyHint})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[m?(0,$.jsx)(`span`,{className:`text-sm text-fg-muted`,children:t.policySaved}):null,(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:!v||u,onClick:x,children:t.policyDiscard}),(0,$.jsx)(Y,{type:`button`,variant:`primary`,disabled:!v||u,onClick:()=>void b(),children:u?t.policySaving:t.policySave})]})]}),v?(0,$.jsx)(`p`,{className:`mb-3 text-xs text-amber-800 dark:text-amber-200`,children:t.policyUnsaved}):null,f?(0,$.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:f}):null,(0,$.jsx)(`p`,{className:`mb-4 text-xs text-fg-subtle`,children:t.policyRestartHint}),(0,$.jsx)(Gl,{t,form:g,onChange:y})]})}function Gl(e){let t=(0,Q.c)(56),{t:n,form:r,onChange:i}=e,a;t[0]===i?a=t[1]:(a=e=>i({enabled:e.target.checked}),t[0]=i,t[1]=a);let o;t[2]!==r.enabled||t[3]!==a?(o=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,onChange:a}),t[2]=r.enabled,t[3]=a,t[4]=o):o=t[4];let s;t[5]!==n.policyEnabled||t[6]!==o?(s=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[o,n.policyEnabled]}),t[5]=n.policyEnabled,t[6]=o,t[7]=s):s=t[7];let c=!r.enabled,l;t[8]===i?l=t[9]:(l=e=>i({defaultTtlHours:e}),t[8]=i,t[9]=l);let u;t[10]!==r.defaultTtlHours||t[11]!==n.policyDefaultTtlHint||t[12]!==n.policyDefaultTtlHours||t[13]!==c||t[14]!==l?(u=(0,$.jsx)(Kl,{id:`share-default-ttl-hours`,label:n.policyDefaultTtlHours,hint:n.policyDefaultTtlHint,value:r.defaultTtlHours,min:1,max:168,disabled:c,onChange:l}),t[10]=r.defaultTtlHours,t[11]=n.policyDefaultTtlHint,t[12]=n.policyDefaultTtlHours,t[13]=c,t[14]=l,t[15]=u):u=t[15];let d=!r.enabled,f;t[16]===i?f=t[17]:(f=e=>i({maxTtlDays:e}),t[16]=i,t[17]=f);let p;t[18]!==r.maxTtlDays||t[19]!==n.policyMaxTtlDays||t[20]!==n.policyMaxTtlHint||t[21]!==d||t[22]!==f?(p=(0,$.jsx)(Kl,{id:`share-max-ttl-days`,label:n.policyMaxTtlDays,hint:n.policyMaxTtlHint,value:r.maxTtlDays,min:1,max:30,disabled:d,onChange:f}),t[18]=r.maxTtlDays,t[19]=n.policyMaxTtlDays,t[20]=n.policyMaxTtlHint,t[21]=d,t[22]=f,t[23]=p):p=t[23];let m=!r.enabled,h;t[24]===i?h=t[25]:(h=e=>i({maxActiveShares:e}),t[24]=i,t[25]=h);let g;t[26]!==r.maxActiveShares||t[27]!==n.policyMaxActiveShares||t[28]!==n.policyMaxActiveSharesHint||t[29]!==m||t[30]!==h?(g=(0,$.jsx)(Kl,{id:`share-max-active`,label:n.policyMaxActiveShares,hint:n.policyMaxActiveSharesHint,value:r.maxActiveShares,min:1,max:1e4,disabled:m,onChange:h}),t[26]=r.maxActiveShares,t[27]=n.policyMaxActiveShares,t[28]=n.policyMaxActiveSharesHint,t[29]=m,t[30]=h,t[31]=g):g=t[31];let _=!r.enabled,v;t[32]===i?v=t[33]:(v=e=>i({maxFileSizeMb:e}),t[32]=i,t[33]=v);let y;t[34]!==r.maxFileSizeMb||t[35]!==n.policyMaxFileSizeHint||t[36]!==n.policyMaxFileSizeMb||t[37]!==_||t[38]!==v?(y=(0,$.jsx)(Kl,{id:`share-max-file-mb`,label:n.policyMaxFileSizeMb,hint:n.policyMaxFileSizeHint,value:r.maxFileSizeMb,min:1,max:10240,disabled:_,onChange:v}),t[34]=r.maxFileSizeMb,t[35]=n.policyMaxFileSizeHint,t[36]=n.policyMaxFileSizeMb,t[37]=_,t[38]=v,t[39]=y):y=t[39];let b;t[40]!==g||t[41]!==y||t[42]!==u||t[43]!==p?(b=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[u,p,g,y]}),t[40]=g,t[41]=y,t[42]=u,t[43]=p,t[44]=b):b=t[44];let x=!r.enabled,S;t[45]===i?S=t[46]:(S=e=>i({inlinePreviewMimes:e}),t[45]=i,t[46]=S);let C;t[47]!==r.inlinePreviewMimes||t[48]!==n||t[49]!==x||t[50]!==S?(C=(0,$.jsx)(ql,{t:n,values:r.inlinePreviewMimes,disabled:x,onChange:S}),t[47]=r.inlinePreviewMimes,t[48]=n,t[49]=x,t[50]=S,t[51]=C):C=t[51];let w;return t[52]!==b||t[53]!==C||t[54]!==s?(w=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[s,b,C]}),t[52]=b,t[53]=C,t[54]=s,t[55]=w):w=t[55],w}function Kl(e){let t=(0,Q.c)(21),{id:n,label:r,hint:i,value:a,min:o,max:s,disabled:c,onChange:l}=e,u;t[0]!==n||t[1]!==r?(u=(0,$.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:n,children:r}),t[0]=n,t[1]=r,t[2]=u):u=t[2];let d;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(d=J(Ul(),`max-w-xs font-mono text-xs`),t[3]=d):d=t[3];let f;t[4]!==s||t[5]!==o||t[6]!==l?(f=e=>{let t=Number(e.target.value);Number.isFinite(t)&&l(Math.max(o,Math.min(s,Math.floor(t))))},t[4]=s,t[5]=o,t[6]=l,t[7]=f):f=t[7];let p;t[8]!==c||t[9]!==n||t[10]!==s||t[11]!==o||t[12]!==f||t[13]!==a?(p=(0,$.jsx)(`input`,{id:n,type:`number`,min:o,max:s,disabled:c,className:d,value:a,onChange:f}),t[8]=c,t[9]=n,t[10]=s,t[11]=o,t[12]=f,t[13]=a,t[14]=p):p=t[14];let m;t[15]===i?m=t[16]:(m=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:i}),t[15]=i,t[16]=m);let h;return t[17]!==u||t[18]!==p||t[19]!==m?(h=(0,$.jsxs)(`div`,{children:[u,p,m]}),t[17]=u,t[18]=p,t[19]=m,t[20]=h):h=t[20],h}function ql(e){let t=(0,Q.c)(25),{t:n,values:r,disabled:i,onChange:a}=e,o;t[0]!==a||t[1]!==r?(o=e=>{let t=e.trim();!t||r.includes(t)||r.length>=32||a([...r,t])},t[0]=a,t[1]=r,t[2]=o):o=t[2];let s=o,c;t[3]===n.policyInlinePreviewMimes?c=t[4]:(c=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.policyInlinePreviewMimes}),t[3]=n.policyInlinePreviewMimes,t[4]=c);let l;t[5]===n.policyInlinePreviewMimesHint?l=t[6]:(l=(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.policyInlinePreviewMimesHint}),t[5]=n.policyInlinePreviewMimesHint,t[6]=l);let u;t[7]!==i||t[8]!==a||t[9]!==r?(u=r.map(e=>(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-edge bg-surface-panel px-2 py-0.5 font-mono text-xs text-fg`,children:[e,i?null:(0,$.jsx)(`button`,{type:`button`,className:`text-fg-muted hover:text-fg`,"aria-label":`Remove ${e}`,onClick:()=>a(r.filter(t=>t!==e)),children:`×`})]},e)),t[7]=i,t[8]=a,t[9]=r,t[10]=u):u=t[10];let d;t[11]===u?d=t[12]:(d=(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:u}),t[11]=u,t[12]=d);let f;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(f=J(Ul(),`font-mono text-xs`),t[13]=f):f=t[13];let p=i||r.length>=32,m;t[14]===s?m=t[15]:(m=e=>{e.key===`Enter`&&(e.preventDefault(),s(e.target.value),e.target.value=``)},t[14]=s,t[15]=m);let h;t[16]!==n.policyMimePlaceholder||t[17]!==p||t[18]!==m?(h=(0,$.jsx)(`input`,{className:f,placeholder:n.policyMimePlaceholder,disabled:p,onKeyDown:m}),t[16]=n.policyMimePlaceholder,t[17]=p,t[18]=m,t[19]=h):h=t[19];let g;return t[20]!==c||t[21]!==l||t[22]!==d||t[23]!==h?(g=(0,$.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[c,l,d,h]}),t[20]=c,t[21]=l,t[22]=d,t[23]=h,t[24]=g):g=t[24],g}function Jl(e){let t=(0,Q.c)(99),{open:n,onOpenChange:r,onConfirm:i,initialPath:o,selectKind:c,sessionKey:l,agentId:u}=e,f=c===void 0?`any`:c,p=a(Zl),m;t[0]===p?m=t[1]:(m=s(p),t[0]=p,t[1]=m);let y=m,S=y.workspace,w=y.sharesSettings,T=U(Xl),{data:E}=d(C(Yl)?`picker-agents-list`:null,Ke),D;bb0:{let e;t[2]===u?e=t[3]:(e=u?.trim(),t[2]=u,t[3]=e);let n=e;if(n){D=n;break bb0}let r;t[4]===T?r=t[5]:(r=T.trim(),t[4]=T,t[5]=r);let i=r;if(i){D=i;break bb0}if(E?.defaultId){D=E.defaultId;break bb0}if(E?.agents?.[0]?.id){D=E.agents[0].id;break bb0}D=``}let O=D,[k,A]=(0,Z.useState)(O),j,M;t[6]===O?(j=t[7],M=t[8]):(j=()=>{A(O)},M=[O],t[6]=O,t[7]=j,t[8]=M),(0,Z.useEffect)(j,M);let{tree:N,loading:P,error:F,loadRoot:I,loadChildren:L,reset:R}=oe(k,l??null),z;t[9]===o?z=t[10]:(z=o?{path:o,isDirectory:!1}:null,t[9]=o,t[10]=z);let[B,V]=(0,Z.useState)(z),ee;t[11]!==o||t[12]!==I||t[13]!==n||t[14]!==R?(ee=()=>{if(!n){R(),V(o?{path:o,isDirectory:!1}:null);return}I()},t[11]=o,t[12]=I,t[13]=n,t[14]=R,t[15]=ee):ee=t[15];let H;t[16]!==o||t[17]!==I||t[18]!==n||t[19]!==k||t[20]!==R||t[21]!==l?(H=[n,k,l,I,R,o],t[16]=o,t[17]=I,t[18]=n,t[19]=k,t[20]=R,t[21]=l,t[22]=H):H=t[22],(0,Z.useEffect)(ee,H);let W;t[23]===L?W=t[24]:(W=e=>{L(e)},t[23]=L,t[24]=W);let te=W,G=B!==null&&(f===`any`||f===`file`&&!B.isDirectory||f===`directory`&&B.isDirectory),ne;bb1:{if(!B){ne=w.pickerHintNone;break bb1}if(f===`file`&&B.isDirectory){ne=w.pickerHintNeedsFile;break bb1}if(f===`directory`&&!B.isDirectory){ne=w.pickerHintNeedsDirectory;break bb1}ne=`${B.isDirectory?`📁`:`📄`} ${B.path}`}let re=ne,ie;t[25]===E?.agents?ie=t[26]:(ie=E?.agents??[],t[25]=E?.agents,t[26]=ie);let ae=ie,se;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(se=(0,$.jsx)(g,{className:`fixed inset-0 z-[70] bg-scrim backdrop-blur-[2px]`}),t[27]=se):se=t[27];let ce;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(ce=J(`fixed left-1/2 top-1/2 z-[71] w-[min(34rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2`,`flex h-[min(28rem,calc(100vh-3rem))] flex-col overflow-hidden rounded-lg border border-edge bg-surface-panel shadow-popover outline-none`),t[28]=ce):ce=t[28];let le;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(le=(0,$.jsx)(ge,{className:`size-4 shrink-0 text-fg-muted`,"aria-hidden":!0}),t[29]=le):le=t[29];let ue;t[30]===w.pickerTitle?ue=t[31]:(ue=(0,$.jsx)(b,{className:`min-w-0 flex-1 truncate text-base font-semibold text-fg`,children:w.pickerTitle}),t[30]=w.pickerTitle,t[31]=ue);let de=y.cron.refresh,fe=y.cron.refresh,pe;t[32]===I?pe=t[33]:(pe=()=>void I(),t[32]=I,t[33]=pe);let me=P&&`animate-spin`,he;t[34]===me?he=t[35]:(he=J(`size-4`,me),t[34]=me,t[35]=he);let _e;t[36]===he?_e=t[37]:(_e=(0,$.jsx)(Ze,{className:he,"aria-hidden":!0}),t[36]=he,t[37]=_e);let ve;t[38]!==P||t[39]!==y.cron.refresh||t[40]!==pe||t[41]!==_e?(ve=(0,$.jsx)(`button`,{type:`button`,className:`inline-flex size-8 shrink-0 items-center justify-center rounded-md text-fg-muted hover:bg-surface-hover hover:text-fg disabled:opacity-50`,title:de,"aria-label":fe,disabled:P,onClick:pe,children:_e}),t[38]=P,t[39]=y.cron.refresh,t[40]=pe,t[41]=_e,t[42]=ve):ve=t[42];let ye;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(ye=(0,$.jsx)(vt,{className:`size-4`}),t[43]=ye):ye=t[43];let be;t[44]===S.close?be=t[45]:(be=(0,$.jsx)(x,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`inline-flex size-8 shrink-0 items-center justify-center rounded-md text-fg-muted hover:bg-surface-hover hover:text-fg`,"aria-label":S.close,children:ye})}),t[44]=S.close,t[45]=be);let xe;t[46]!==ue||t[47]!==ve||t[48]!==be?(xe=(0,$.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center gap-2 border-b border-edge px-4`,children:[le,ue,ve,be]}),t[46]=ue,t[47]=ve,t[48]=be,t[49]=xe):xe=t[49];let Se;t[50]!==ae||t[51]!==E?.defaultId||t[52]!==k||t[53]!==w.pickerAgentLabel?(Se=ae.length>0?(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-edge px-4 py-2`,children:[(0,$.jsx)(`label`,{className:`text-xs text-fg-muted`,htmlFor:`picker-agent-select`,children:w.pickerAgentLabel}),(0,$.jsx)(`select`,{id:`picker-agent-select`,className:`min-w-0 flex-1 rounded-md border border-edge bg-surface-panel px-2 py-1 text-sm text-fg focus:outline-none focus:ring-2 focus:ring-accent`,value:k,onChange:e=>{A(e.target.value),V(null)},children:ae.map(e=>(0,$.jsxs)(`option`,{value:e.id,children:[e.name||e.id,e.id===E?.defaultId?` ★`:``]},e.id))})]}):null,t[50]=ae,t[51]=E?.defaultId,t[52]=k,t[53]=w.pickerAgentLabel,t[54]=Se):Se=t[54];let Ce;t[55]!==F||t[56]!==S.loadError?(Ce=F?(0,$.jsxs)(`p`,{className:`shrink-0 px-4 py-2 text-xs text-red-600 dark:text-red-400`,children:[S.loadError,`: `,F]}):null,t[55]=F,t[56]=S.loadError,t[57]=Ce):Ce=t[57];let we;t[58]!==te||t[59]!==P||t[60]!==B?.path||t[61]!==S.emptyDir||t[62]!==S.title||t[63]!==N?(we=P&&N.length===0?(0,$.jsxs)(`p`,{className:`flex shrink-0 items-center gap-2 px-4 py-3 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),S.title,`…`]}):(0,$.jsx)(Qe,{tree:N,selectedPath:B?.path??null,onSelectFile:e=>V({path:e,isDirectory:!1}),onSelectEntry:(e,t)=>V({path:e,isDirectory:t}),onExpandDir:te,onAction:void 0,emptyHint:S.emptyDir}),t[58]=te,t[59]=P,t[60]=B?.path,t[61]=S.emptyDir,t[62]=S.title,t[63]=N,t[64]=we):we=t[64];let Te;t[65]!==Ce||t[66]!==we?(Te=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[Ce,we]}),t[65]=Ce,t[66]=we,t[67]=Te):Te=t[67];let Ee;t[68]===re?Ee=t[69]:(Ee=(0,$.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-xs text-fg-muted`,children:re}),t[68]=re,t[69]=Ee);let De;t[70]===r?De=t[71]:(De=()=>r(!1),t[70]=r,t[71]=De);let Oe;t[72]!==w.cancel||t[73]!==De?(Oe=(0,$.jsx)(Y,{type:`button`,variant:`ghost`,onClick:De,children:w.cancel}),t[72]=w.cancel,t[73]=De,t[74]=Oe):Oe=t[74];let ke=!G,Ae;t[75]!==i||t[76]!==r||t[77]!==k||t[78]!==B?(Ae=()=>{B&&(i({...B,agentId:k}),r(!1))},t[75]=i,t[76]=r,t[77]=k,t[78]=B,t[79]=Ae):Ae=t[79];let je;t[80]!==w.pickerConfirm||t[81]!==ke||t[82]!==Ae?(je=(0,$.jsx)(Y,{type:`button`,disabled:ke,onClick:Ae,children:w.pickerConfirm}),t[80]=w.pickerConfirm,t[81]=ke,t[82]=Ae,t[83]=je):je=t[83];let Me;t[84]!==Oe||t[85]!==je?(Me=(0,$.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[Oe,je]}),t[84]=Oe,t[85]=je,t[86]=Me):Me=t[86];let Ne;t[87]!==Ee||t[88]!==Me?(Ne=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-t border-edge px-4 py-3`,children:[Ee,Me]}),t[87]=Ee,t[88]=Me,t[89]=Ne):Ne=t[89];let Pe;t[90]!==xe||t[91]!==Se||t[92]!==Te||t[93]!==Ne?(Pe=(0,$.jsxs)(h,{children:[se,(0,$.jsxs)(_,{className:ce,children:[xe,Se,Te,Ne]})]}),t[90]=xe,t[91]=Se,t[92]=Te,t[93]=Ne,t[94]=Pe):Pe=t[94];let Fe;return t[95]!==r||t[96]!==n||t[97]!==Pe?(Fe=(0,$.jsx)(v,{open:n,onOpenChange:r,children:Pe}),t[95]=r,t[96]=n,t[97]=Pe,t[98]=Fe):Fe=t[98],Fe}function Yl(e){return e.token}function Xl(e){return e.agentId}function Zl(e){return e.language}var Ql=[`shares`,`policy`];function $l(e){let t=(e??``).trim();return Ql.includes(t)?t:`shares`}function eu(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(1)} GB`}function tu(e,t){let n=new Date(e).getTime()-Date.now(),r=Math.abs(n),i=n<0;if(r<6e4)return t===`zh`?`刚刚`:`just now`;let a=Math.floor(r/6e4);if(a<60){let e=t===`zh`?`${a} 分钟`:`${a}m`;return i?t===`zh`?`${e}前`:`${e} ago`:e}let o=Math.floor(a/60);if(o<24){let e=t===`zh`?`${o} 小时`:`${o}h`;return i?t===`zh`?`${e}前`:`${e} ago`:e}let s=Math.floor(o/24),c=t===`zh`?`${s} 天`:`${s}d`;return i?t===`zh`?`${c}前`:`${c} ago`:c}var nu=[{value:36e5,key:`1h`},{value:216e5,key:`6h`},{value:864e5,key:`24h`},{value:2592e5,key:`3d`},{value:6048e5,key:`7d`}];function ru(){let e=(0,Q.c)(44),t=a(au),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.sharesSettings,i=!!C(iu),[o,c]=Zt(),l;e[2]===o?l=e[3]:(l=$l(o.get(`tab`)),e[2]=o,e[3]=l);let u=l,d;e[4]===c?d=e[5]:(d=e=>{c(t=>{let n=new URLSearchParams(t);return e===`shares`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0})},e[4]=c,e[5]=d);let f=d;if(!i){let t;return e[6]===r.needToken?t=e[7]:(t=(0,$.jsx)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.needToken})}),e[6]=r.needToken,e[7]=t),t}let p;e[8]!==r.tabPolicy||e[9]!==r.tabShares?(p={shares:r.tabShares,policy:r.tabPolicy},e[8]=r.tabPolicy,e[9]=r.tabShares,e[10]=p):p=e[10];let m=p,h;e[11]===r.title?h=e[12]:(h=(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:r.title}),e[11]=r.title,e[12]=h);let g;e[13]===r.subtitle?g=e[14]:(g=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.subtitle}),e[13]=r.subtitle,e[14]=g);let _;e[15]!==h||e[16]!==g?(_=(0,$.jsxs)(`div`,{children:[h,g]}),e[15]=h,e[16]=g,e[17]=_):_=e[17];let v=r.tabsAria,y;e[18]!==u||e[19]!==f?(y=e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=Ql[(Ql.indexOf(u)+(e.key===`ArrowRight`?1:-1)+Ql.length)%Ql.length];f(t)},e[18]=u,e[19]=f,e[20]=y):y=e[20];let b;e[21]!==u||e[22]!==f||e[23]!==m?(b=Ql.map(e=>{let t=e===u;return(0,$.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":t,id:`shares-tab-${e}`,"aria-controls":`shares-panel-${e}`,className:J(`shrink-0 rounded-lg px-3 py-2 text-sm font-medium transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.press,t?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>f(e),children:m[e]},e)}),e[21]=u,e[22]=f,e[23]=m,e[24]=b):b=e[24];let x;e[25]===b?x=e[26]:(x=(0,$.jsx)(`div`,{className:`-mx-1 flex gap-1 overflow-x-auto px-1 pb-1`,children:b}),e[25]=b,e[26]=x);let S=`shares-panel-${u}`,w=`shares-tab-${u}`,T;e[27]!==u||e[28]!==i||e[29]!==t||e[30]!==r?(T=u===`shares`?(0,$.jsx)(ou,{t:r,language:t}):(0,$.jsx)(Wl,{hasToken:i}),e[27]=u,e[28]=i,e[29]=t,e[30]=r,e[31]=T):T=e[31];let E;e[32]!==S||e[33]!==w||e[34]!==T?(E=(0,$.jsx)(`div`,{role:`tabpanel`,id:S,"aria-labelledby":w,className:`min-w-0`,children:T}),e[32]=S,e[33]=w,e[34]=T,e[35]=E):E=e[35];let D;e[36]!==r.tabsAria||e[37]!==x||e[38]!==E||e[39]!==y?(D=(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,role:`tablist`,"aria-label":v,onKeyDown:y,children:[x,E]}),e[36]=r.tabsAria,e[37]=x,e[38]=E,e[39]=y,e[40]=D):D=e[40];let O;return e[41]!==D||e[42]!==_?(O=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[_,D]}),e[41]=D,e[42]=_,e[43]=O):O=e[43],O}function iu(e){return e.token}function au(e){return e.language}function ou(e){let t=(0,Q.c)(60),{t:n,language:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={refreshInterval:3e4},t[0]=i):i=t[0];let{data:a,error:o,isLoading:s,mutate:c}=d(`shares-list`,j,i),l;t[1]===a?.payload?.shares?l=t[2]:(l=a?.payload?.shares??[],t[1]=a?.payload?.shares,t[2]=l);let u=l,[f,p]=(0,Z.useState)(!1),m;bb0:{if(f){m=u;break bb0}let e;t[3]===u?e=t[4]:(e=u.filter(uu),t[3]=u,t[4]=e),m=e}let h=m,g;t[5]===u?g=t[6]:(g=u.filter(lu),t[5]=u,t[6]=g);let _=g.length,v;t[7]===u?v=t[8]:(v=u.filter(cu),t[7]=u,t[8]=v);let y=v.length,b;t[9]===c?b=t[10]:(b=()=>void c(),t[9]=c,t[10]=b);let x;t[11]!==n||t[12]!==b?(x=(0,$.jsx)(fu,{t:n,onCreated:b}),t[11]=n,t[12]=b,t[13]=x):x=t[13];let S=f?n.allSharesTitle:n.listTitle,C;t[14]===_?C=t[15]:(C=_>0&&(0,$.jsxs)(`span`,{className:`ml-2 text-xs font-normal text-fg-muted`,children:[`(`,_,`)`]}),t[14]=_,t[15]=C);let w;t[16]!==S||t[17]!==C?(w=(0,$.jsxs)(`h2`,{className:`text-sm font-semibold text-fg`,children:[S,C]}),t[16]=S,t[17]=C,t[18]=w):w=t[18];let T;t[19]===c?T=t[20]:(T=()=>void c(),t[19]=c,t[20]=T);let E=s&&`animate-spin`,D;t[21]===E?D=t[22]:(D=J(`size-3.5`,E),t[21]=E,t[22]=D);let O;t[23]===D?O=t[24]:(O=(0,$.jsx)(Ze,{className:D}),t[23]=D,t[24]=O);let k;t[25]!==s||t[26]!==T||t[27]!==O?(k=(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`px-2 py-1`,onClick:T,disabled:s,children:O}),t[25]=s,t[26]=T,t[27]=O,t[28]=k):k=t[28];let A;t[29]!==y||t[30]!==f||t[31]!==n.hideExpired||t[32]!==n.showExpired?(A=y>0&&(0,$.jsx)(`button`,{type:`button`,className:`text-xs text-accent hover:underline`,onClick:()=>p(su),children:f?n.hideExpired:n.showExpired}),t[29]=y,t[30]=f,t[31]=n.hideExpired,t[32]=n.showExpired,t[33]=A):A=t[33];let M;t[34]!==k||t[35]!==A?(M=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[k,A]}),t[34]=k,t[35]=A,t[36]=M):M=t[36];let N;t[37]!==w||t[38]!==M?(N=(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[w,M]}),t[37]=w,t[38]=M,t[39]=N):N=t[39];let P;t[40]!==a||t[41]!==o||t[42]!==h||t[43]!==s||t[44]!==r||t[45]!==c||t[46]!==n?(P=s&&!a?(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`}),n.loading]}):o?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-red-600 dark:text-red-400`,children:[(0,$.jsx)(`span`,{children:n.error}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`px-2 py-1 text-xs`,onClick:()=>void c(),children:n.retry})]}):h.length===0?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.emptyState}):(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:h.map(e=>(0,$.jsx)(mu,{share:e,t:n,language:r,onRevoked:()=>void c(),onExtended:()=>void c()},e.id))}),t[40]=a,t[41]=o,t[42]=h,t[43]=s,t[44]=r,t[45]=c,t[46]=n,t[47]=P):P=t[47];let F;t[48]!==y||t[49]!==c||t[50]!==f||t[51]!==n?(F=y>0&&f&&(0,$.jsx)(hu,{t:n,onCleaned:()=>void c()}),t[48]=y,t[49]=c,t[50]=f,t[51]=n,t[52]=F):F=t[52];let I;t[53]!==N||t[54]!==P||t[55]!==F?(I=(0,$.jsxs)(X,{children:[N,P,F]}),t[53]=N,t[54]=P,t[55]=F,t[56]=I):I=t[56];let L;return t[57]!==I||t[58]!==x?(L=(0,$.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[x,I]}),t[57]=I,t[58]=x,t[59]=L):L=t[59],L}function su(e){return!e}function cu(e){return e.expired||e.revoked}function lu(e){return!e.expired&&!e.revoked}function uu(e){return!e.expired&&!e.revoked}var du={expanded:!0,path:``,isDirectory:!1,agentId:``,ttlMs:864e5,maxViews:null,description:``,directoryMode:`browse`,creating:!1,result:null,errorMsg:null,resultDialogOpen:!1,pickerOpen:!1};function fu({t:e,onCreated:t}){let[n,r]=(0,Z.useReducer)(Lt,du),{expanded:i,path:a,isDirectory:o,agentId:s,ttlMs:c,maxViews:l,description:u,directoryMode:d,creating:f,result:p,errorMsg:m,resultDialogOpen:h,pickerOpen:g}=n,_=(0,Z.useCallback)(async()=>{if(a.trim()){r({type:`patch`,patch:{creating:!0,errorMsg:null,result:null}});try{r({type:`patch`,patch:{result:(await Ne({path:a.trim(),ttlMs:c,maxViews:l,description:u.trim()||void 0,...s?{agentId:s}:{},...o?{kind:`directory`,directoryMode:d}:{}})).payload,resultDialogOpen:!0}}),t()}catch(e){r({type:`patch`,patch:{errorMsg:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{creating:!1}})}}},[a,o,s,c,l,u,d,t]),v=(0,Z.useCallback)(()=>{r({type:`patch`,patch:{path:``,isDirectory:!1,agentId:``,description:``,maxViews:null,ttlMs:864e5,directoryMode:`browse`,result:null,errorMsg:null}})},[]);return i?(0,$.jsxs)(X,{children:[(0,$.jsx)(`h2`,{className:`mb-1 text-sm font-semibold text-fg`,children:e.createTitle}),(0,$.jsx)(`p`,{className:`mb-4 text-xs text-fg-muted`,children:e.createHint}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.pathLabel}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`div`,{className:J(`flex min-w-0 flex-1 items-center gap-2 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm`,a?`text-fg`:`text-fg-subtle`),children:a?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":!0,children:o?`📁`:`📄`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:a,children:a})]}):(0,$.jsx)(`span`,{className:`truncate`,children:e.pathPlaceholder})}),(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,onClick:()=>r({type:`patch`,patch:{pickerOpen:!0}}),children:[(0,$.jsx)(ye,{className:`size-4`}),a?e.pathBrowseChange:e.pathBrowse]})]})]}),o?(0,$.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.directoryModeLabel}),(0,$.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:outline-none focus:ring-2 focus:ring-accent`,value:d,onChange:e=>r({type:`patch`,patch:{directoryMode:e.target.value===`zip-only`?`zip-only`:`browse`}}),children:[(0,$.jsx)(`option`,{value:`browse`,children:e.directoryModeBrowse}),(0,$.jsx)(`option`,{value:`zip-only`,children:e.directoryModeZipOnly})]})]}):null,(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,$.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.ttlLabel}),(0,$.jsx)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:outline-none focus:ring-2 focus:ring-accent`,value:c,onChange:e=>r({type:`patch`,patch:{ttlMs:Number(e.target.value)}}),children:nu.map(t=>(0,$.jsx)(`option`,{value:t.value,children:e.ttlOptions[t.key]},t.key))})]}),(0,$.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.maxViewsLabel}),(0,$.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:outline-none focus:ring-2 focus:ring-accent`,value:l??`unlimited`,onChange:e=>r({type:`patch`,patch:{maxViews:e.target.value===`unlimited`?null:Number(e.target.value)}}),children:[(0,$.jsx)(`option`,{value:`unlimited`,children:e.maxViewsUnlimited}),(0,$.jsx)(`option`,{value:`1`,children:`1`}),(0,$.jsx)(`option`,{value:`5`,children:`5`}),(0,$.jsx)(`option`,{value:`10`,children:`10`}),(0,$.jsx)(`option`,{value:`50`,children:`50`}),(0,$.jsx)(`option`,{value:`100`,children:`100`})]})]})]}),(0,$.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.descriptionLabel}),(0,$.jsx)(`input`,{type:`text`,className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:outline-none focus:ring-2 focus:ring-accent`,placeholder:e.descriptionPlaceholder,value:u,onChange:e=>r({type:`patch`,patch:{description:e.target.value}})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,$.jsxs)(Y,{type:`button`,disabled:f||!a.trim(),onClick:()=>void _(),children:[f?(0,$.jsx)(q,{className:`size-4 animate-spin`}):(0,$.jsx)(dt,{className:`size-4`}),f?e.creating:e.createButton]}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,onClick:()=>{v(),r({type:`patch`,patch:{expanded:!1}})},children:e.cancel})]}),m&&(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m})]}),(0,$.jsx)(Ve,{open:h,onOpenChange:e=>{r({type:`patch`,patch:{resultDialogOpen:e,...e?{}:{result:null}}})},result:p}),(0,$.jsx)(Jl,{open:g,onOpenChange:e=>r({type:`patch`,patch:{pickerOpen:e}}),initialPath:a||void 0,selectKind:`any`,onConfirm:e=>r({type:`patch`,patch:{path:e.path,isDirectory:e.isDirectory,agentId:e.agentId,directoryMode:`browse`}})})]}):(0,$.jsxs)(Y,{type:`button`,onClick:()=>r({type:`patch`,patch:{expanded:!0}}),className:`self-start`,children:[(0,$.jsx)(dt,{className:`size-4`}),e.createTitle]})}var pu={revokeOpen:!1,revoking:!1,linksOpen:!1,urlCopied:!1,copyFailed:!1,extending:!1};function mu({share:e,t,language:n,onRevoked:r,onExtended:i}){let[a,o]=(0,Z.useReducer)(Lt,pu),{revokeOpen:s,revoking:c,linksOpen:l,urlCopied:u,copyFailed:d,extending:f}=a,p=!e.expired&&!e.revoked,h=e.revoked?t.statusRevoked:e.expired?t.statusExpired:t.statusActive,g=e.revoked?`text-red-600 dark:text-red-400`:e.expired?`text-fg-subtle`:`text-emerald-600 dark:text-emerald-400`,_=(0,Z.useCallback)(async()=>{o({type:`patch`,patch:{revokeOpen:!1,revoking:!0}});try{await He(e.id),r()}catch{}finally{o({type:`patch`,patch:{revoking:!1}})}},[e.id,r]),v=(0,Z.useCallback)(async()=>{if(o({type:`patch`,patch:{linksOpen:!0,copyFailed:!1}}),!await Gt(e.shareUrl)){o({type:`patch`,patch:{copyFailed:!0}}),window.setTimeout(()=>o({type:`patch`,patch:{copyFailed:!1}}),2500);return}o({type:`patch`,patch:{urlCopied:!0}}),window.setTimeout(()=>o({type:`patch`,patch:{urlCopied:!1}}),2e3)},[e.shareUrl]),y=(0,Z.useCallback)(async()=>{o({type:`patch`,patch:{extending:!0}});try{await rn(e.id,864e5),i()}catch{}finally{o({type:`patch`,patch:{extending:!1}})}},[e.id,i]),b=`share-links-${e.id}`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsxs)(`button`,{type:`button`,className:J(`flex min-w-0 flex-1 items-start gap-3 rounded-md text-left`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),"aria-expanded":l,"aria-controls":b,onClick:()=>o({type:`patch`,patch:{linksOpen:!l}}),children:[(0,$.jsx)(xt,{className:J(`mt-0.5 size-4 shrink-0 text-fg-muted transition-transform`,l?`rotate-0`:`-rotate-90`),"aria-hidden":!0}),(0,$.jsx)(ye,{className:`mt-0.5 size-4 shrink-0 text-fg-muted`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-sm font-medium text-fg`,children:e.fileName}),(0,$.jsx)(`span`,{className:J(`text-xs font-medium`,g),children:h})]}),(0,$.jsx)(`p`,{className:`truncate text-xs text-fg-subtle`,children:e.workspaceRelativePath}),(0,$.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,$.jsx)(`span`,{children:eu(e.fileSize)}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(W,{className:`size-3`}),e.expired?n===`zh`?`已过期`:`expired`:tu(e.expiresAt,n)]}),(0,$.jsxs)(`span`,{children:[t.views,`: `,e.downloadCount,e.maxViews!==null&&` ${t.viewsOf} ${e.maxViews}`]}),e.description&&(0,$.jsx)(`span`,{className:`italic text-fg-subtle`,children:e.description})]})]})]}),(0,$.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:p&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`px-2 py-1`,title:t.copyUrl,onClick:()=>void v(),children:u?(0,$.jsx)(tt,{className:`size-3.5 text-emerald-500`}):(0,$.jsx)(m,{className:`size-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`px-2 py-1`,onClick:()=>void y(),disabled:f,title:t.extend,children:f?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):(0,$.jsx)(W,{className:`size-3.5`})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`px-2 py-1 text-red-600 hover:text-red-700 dark:text-red-400`,onClick:()=>o({type:`patch`,patch:{revokeOpen:!0}}),disabled:c,children:c?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):(0,$.jsx)(Re,{className:`size-3.5`})})]})})]}),p&&l?(0,$.jsxs)(`div`,{id:b,className:`mt-3 border-t border-edge-subtle pt-3 pl-7`,children:[(0,$.jsx)(Ge,{shareUrl:e.shareUrl,lanUrl:e.lanUrl,reachability:e.reachability,compact:!0}),d?(0,$.jsx)(`p`,{className:`mt-2 text-xs text-red-600 dark:text-red-400`,children:t.copyFailed}):null,(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(ne,{reachability:e.reachability})})]}):null]}),(0,$.jsx)(Ht,{open:s,title:t.revokeConfirmTitle,description:t.revokeConfirmBody,confirmLabel:t.revokeConfirmLabel,cancelLabel:t.cancel,destructive:!0,onConfirm:()=>void _(),onCancel:()=>o({type:`patch`,patch:{revokeOpen:!1}})})]})}function hu({t:e,onCleaned:t}){let[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),o=(0,Z.useCallback)(async()=>{r(!1),a(!0);try{await me(),t()}catch{}finally{a(!1)}},[t]);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,$.jsxs)(Y,{type:`button`,variant:`secondary`,disabled:i,onClick:()=>r(!0),className:`border-danger/40 px-2 py-1 text-xs text-danger hover:bg-danger/10`,children:[i?(0,$.jsx)(q,{className:`size-3.5 animate-spin`}):(0,$.jsx)(Re,{className:`size-3.5`}),e.cleanExpired]})}),(0,$.jsx)(Ht,{open:n,title:e.cleanExpiredConfirmTitle,description:e.cleanExpiredConfirmBody,confirmLabel:e.cleanExpiredConfirmLabel,cancelLabel:e.cancel,destructive:!0,onConfirm:()=>void o(),onCancel:()=>r(!1)})]})}function gu(e,t){return e==null?t:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function _u(e,t){return e===`PENDING_UPDATE`?t.pendingUpdate??t.generic:e===`UNINSTALLER_NOT_FOUND`?t.uninstallerNotFound??t.generic:e===`NOT_PACKAGED`?t.notPackaged??t.generic:t.generic}function vu(e,t){if(e.platform===`darwin`)return t.uninstallDescDarwin;if(e.platform===`win32`)return t.uninstallDescWin;if(e.platform===`linux`){if(e.linuxPackageKind===`appimage`)return t.uninstallDescLinuxAppImage;if(e.linuxPackageKind===`deb`){let n=e.linuxDebPackageName??`xopc`;return t.uninstallDescLinuxDeb.replace(/\{\{package\}\}/g,n)}return t.uninstallDescLinuxUnknown}return t.uninstallDescLinuxUnknown}var yu={info:null,loadError:null,actionError:null,copiedField:null,clearDialogOpen:!1,clearConfirmChecked:!1,clearConfirmText:``,uninstallDialogOpen:!1,removeUserDataOnUninstall:!1,busy:!1};function bu({api:e,messages:t,embedded:n=!0}){let[r,i]=(0,Z.useReducer)(Lt,yu),{info:a,loadError:o,actionError:s,copiedField:c,clearDialogOpen:l,clearConfirmChecked:u,clearConfirmText:d,uninstallDialogOpen:f,removeUserDataOnUninstall:p,busy:x}=r,S=(0,Z.useCallback)(async()=>{if(e?.getUninstallInfo){i({type:`patch`,patch:{loadError:null}});try{i({type:`patch`,patch:{info:await e.getUninstallInfo()}})}catch(e){i({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}}},[e]);(0,Z.useEffect)(()=>{S()},[S]);let C=async(e,n)=>{if(await Gt(e)){i({type:`patch`,patch:{actionError:null,copiedField:n}}),window.setTimeout(()=>i({type:`patch`,patch:{copiedField:null}}),2e3);return}i({type:`patch`,patch:{actionError:t.copyFailed}})},w=async e=>{let t=window.electronAPI?.shell;if(!t)return;let n=await t.openPath(e);n.error&&i({type:`patch`,patch:{actionError:n.error}})},T=async()=>{if(e?.clearUserData){i({type:`patch`,patch:{busy:!0,actionError:null}});try{let n=await e.clearUserData();n.ok||i({type:`patch`,patch:{actionError:_u(n.error,t.errors)}})}catch(e){i({type:`patch`,patch:{actionError:e instanceof Error?e.message:t.errors.generic}})}finally{i({type:`patch`,patch:{busy:!1,clearDialogOpen:!1,clearConfirmChecked:!1,clearConfirmText:``}})}}},E=async()=>{if(e?.uninstallApp){i({type:`patch`,patch:{busy:!0,actionError:null}});try{let n=await e.uninstallApp({removeUserData:p});n.ok||i({type:`patch`,patch:{actionError:_u(n.error,t.errors)}})}catch(e){i({type:`patch`,patch:{actionError:e instanceof Error?e.message:t.errors.generic}})}finally{i({type:`patch`,patch:{busy:!1,uninstallDialogOpen:!1}})}}};if(o)return(0,$.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:o});if(!a)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.loading});let D=!a.packaged,O=x||a.pendingUpdate||D,k=!D&&a.uninstallMode!==`unsupported`,A=vu(a,t),j=u&&d.trim()===t.clearDataConfirmPhrase;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(X,{children:[n?(0,$.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,$.jsx)(Bt,{className:`size-4 text-accent`,strokeWidth:1.75}),t.title]}):null,s?(0,$.jsx)(`p`,{className:`mb-3 text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:s}):null,D?(0,$.jsxs)(`div`,{className:`mb-4 rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-2.5`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.devOnlyTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:t.devOnlyBody})]}):null,a.pendingUpdate?(0,$.jsx)(`p`,{className:`mb-3 rounded-xl border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-800 dark:text-amber-200`,children:t.pendingUpdateBlocked}):null,a.hasSeparateCliData&&a.cliDataPath?(0,$.jsxs)(`div`,{className:`mb-4 rounded-xl border border-amber-500/30 bg-amber-500/10 px-3 py-2.5`,children:[(0,$.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:t.cliDataWarning}),(0,$.jsxs)(`button`,{type:`button`,className:J(`mt-2 inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,K.press),onClick:()=>void w(a.cliDataPath),children:[(0,$.jsx)(ge,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t.openCliData]})]}):null,(0,$.jsxs)(`dl`,{className:`space-y-3 text-sm`,children:[(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/60 p-3`,children:[(0,$.jsx)(`dt`,{className:`text-xs font-medium text-fg-muted`,children:t.appPath}),(0,$.jsxs)(`dd`,{className:`mt-1 flex items-start justify-between gap-2`,children:[(0,$.jsx)(`code`,{className:`break-all text-xs text-fg`,children:a.appPath}),(0,$.jsxs)(`button`,{type:`button`,className:J(`inline-flex shrink-0 items-center gap-1 rounded-lg border border-edge px-2 py-1 text-xs text-fg hover:bg-surface-hover`,K.press),onClick:()=>void C(a.appPath,`app`),children:[(0,$.jsx)(m,{className:`size-3`,"aria-hidden":!0}),c===`app`?t.copied:t.copyPath]})]})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/60 p-3`,children:[(0,$.jsx)(`dt`,{className:`text-xs font-medium text-fg-muted`,children:t.dataPath}),(0,$.jsxs)(`dd`,{className:`mt-1 flex items-start justify-between gap-2`,children:[(0,$.jsx)(`code`,{className:`break-all text-xs text-fg`,children:a.userDataPath}),(0,$.jsxs)(`button`,{type:`button`,className:J(`inline-flex shrink-0 items-center gap-1 rounded-lg border border-edge px-2 py-1 text-xs text-fg hover:bg-surface-hover`,K.press),onClick:()=>void C(a.userDataPath,`data`),children:[(0,$.jsx)(m,{className:`size-3`,"aria-hidden":!0}),c===`data`?t.copied:t.copyPath]})]}),(0,$.jsxs)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:[t.dataSize,`: `,gu(a.userDataSizeBytes,t.dataSizeUnknown)]})]})]}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.clearData}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:t.clearDataDesc})]}),(0,$.jsx)(`button`,{type:`button`,disabled:O,className:J(`inline-flex shrink-0 items-center justify-center rounded-lg border border-danger/40 bg-danger px-3 py-1.5 text-sm font-medium text-white hover:bg-danger/90 disabled:opacity-50`,K.press),onClick:()=>{i({type:`patch`,patch:{clearConfirmChecked:!1,clearConfirmText:``,clearDialogOpen:!0}})},children:t.clearData})]}),k?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.uninstall}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:A})]}),(0,$.jsx)(`button`,{type:`button`,disabled:O,className:J(`inline-flex shrink-0 items-center justify-center rounded-lg border border-edge bg-surface-base px-3 py-1.5 text-sm font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,K.press),onClick:()=>{i({type:`patch`,patch:{removeUserDataOnUninstall:!1,uninstallDialogOpen:!0}})},children:t.uninstall})]}):null]})]}),(0,$.jsx)(v,{open:l,onOpenChange:e=>{e||i({type:`patch`,patch:{clearDialogOpen:!1,clearConfirmChecked:!1,clearConfirmText:``}})},children:(0,$.jsxs)(h,{children:[(0,$.jsx)(g,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Pe)}),(0,$.jsxs)(_,{className:J(`fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,Xt,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,$.jsx)(b,{className:`text-base font-semibold text-fg`,children:t.clearDataConfirmTitle}),(0,$.jsx)(y,{className:`mt-2 text-sm text-fg-muted`,children:t.clearDataConfirmDesc}),(0,$.jsxs)(`label`,{className:`mt-4 flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:u,onChange:e=>i({type:`patch`,patch:{clearConfirmChecked:e.target.checked}})}),(0,$.jsx)(`span`,{children:t.clearDataConfirmCheckbox})]}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[(0,$.jsx)(`label`,{className:`block text-sm font-medium text-fg`,htmlFor:`clear-data-confirm`,children:t.clearDataConfirmLabel}),(0,$.jsx)(`input`,{id:`clear-data-confirm`,type:`text`,autoComplete:`off`,spellCheck:!1,className:J(`w-full rounded-md border border-edge bg-surface-panel px-3 py-1.5 font-mono text-xs text-fg`,`placeholder:text-fg-subtle`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel`,`dark:border-edge`),placeholder:t.clearDataConfirmPhrase,value:d,onChange:e=>i({type:`patch`,patch:{clearConfirmText:e.target.value}})}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.clearDataConfirmHint})]}),(0,$.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:x,onClick:()=>{i({type:`patch`,patch:{clearDialogOpen:!1,clearConfirmChecked:!1,clearConfirmText:``}})},children:t.cancel}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`,disabled:x||!j,onClick:()=>void T(),children:t.confirmClear})]})]})]})}),k?(0,$.jsx)(v,{open:f,onOpenChange:e=>{e||i({type:`patch`,patch:{uninstallDialogOpen:!1}})},children:(0,$.jsxs)(h,{children:[(0,$.jsx)(g,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Pe)}),(0,$.jsxs)(_,{className:J(`fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,Xt,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,$.jsx)(b,{className:`text-base font-semibold text-fg`,children:t.uninstallConfirmTitle}),(0,$.jsx)(y,{className:`mt-2 text-sm text-fg-muted`,children:A}),(0,$.jsxs)(`label`,{className:`mt-4 flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:p,onChange:e=>i({type:`patch`,patch:{removeUserDataOnUninstall:e.target.checked}})}),(0,$.jsx)(`span`,{children:t.removeUserDataCheckbox})]}),p?(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:t.clearDataConfirmDesc}):null,(0,$.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,$.jsx)(Y,{type:`button`,variant:`secondary`,disabled:x,onClick:()=>i({type:`patch`,patch:{uninstallDialogOpen:!1}}),children:t.cancel}),(0,$.jsx)(Y,{type:`button`,variant:`secondary`,className:`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`,disabled:x,onClick:()=>void E(),children:t.confirmUninstall})]})]})]})}):null]})}function xu(){let e=(0,Q.c)(22),t=a(Su),n;e[0]===t?n=e[1]:(n=s(t),e[0]=t,e[1]=n);let r=n.systemSettings,i=r.appManagement,o=typeof window<`u`?window.electronAPI?.system:void 0;if(!Ue()||!o){let t;e[2]===i.title?t=e[3]:(t=(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:i.title}),e[2]=i.title,e[3]=t);let n;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(n=yn(),e[4]=n):n=e[4];let a;e[5]===r.desktopOnlyTitle?a=e[6]:(a=(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:r.desktopOnlyTitle}),e[5]=r.desktopOnlyTitle,e[6]=a);let o;e[7]===r.desktopOnlyBody?o=e[8]:(o=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.desktopOnlyBody}),e[7]=r.desktopOnlyBody,e[8]=o);let s;e[9]!==a||e[10]!==o?(s=(0,$.jsxs)(`div`,{className:n,children:[a,o]}),e[9]=a,e[10]=o,e[11]=s):s=e[11];let c;return e[12]!==t||e[13]!==s?(c=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[t,s]}),e[12]=t,e[13]=s,e[14]=c):c=e[14],c}let c;e[15]===i.title?c=e[16]:(c=(0,$.jsx)(`div`,{children:(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:i.title})}),e[15]=i.title,e[16]=c);let l;e[17]===i?l=e[18]:(l=(0,$.jsx)(bu,{api:o,messages:i,embedded:!1}),e[17]=i,e[18]=l);let u;return e[19]!==c||e[20]!==l?(u=(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[c,l]}),e[19]=c,e[20]=l,e[21]=u):u=e[21],u}function Su(e){return e.language}async function Cu(){if(typeof navigator>`u`||!navigator.mediaDevices?.getUserMedia)return!1;try{let e=await navigator.mediaDevices.getUserMedia({audio:!0});for(let t of e.getTracks())t.stop();return!0}catch{return!1}}function wu(e,t,n){return e.outcome===`opened-settings`?n.openedSettings:e.status===`granted`&&t?e.outcome===`already-granted`?n.alreadyGranted:n.granted:t?e.status===`denied`?n.denied:n.prompted:n.rendererDenied}function Tu(e,t){return e.outcome===`opened-settings`?t.openedSettings:e.status===`granted`?e.outcome===`already-granted`?t.alreadyGranted:t.granted:t.denied}function Eu(e,t){return e.outcome===`opened-settings`?t.openedSettings:e.status===`granted`?e.outcome===`already-granted`?t.alreadyGranted:t.granted:e.status===`denied`?t.denied:t.prompted}function Du(e,t){return e.outcome===`opened-settings`?t.openedSettings:e.status===`granted`?e.outcome===`already-granted`?t.alreadyGranted:t.granted:e.status===`denied`?t.denied:t.prompted}var Ou=new Set([`microphone`,`accessibility`,`notifications`,`screen`]);function ku(e,t,n){return t===`granted`?!1:e===`accessibility`&&(n===`darwin`||n===`win32`||n===`linux`)||e===`screen`&&(n===`darwin`||n===`win32`)||Ou.has(e)?t===`unknown`:!1}function Au(e,t,n){return e===`accessibility`?!1:e===`screen`&&n===`linux`?!0:Ou.has(e)?t===`denied`:!0}var ju=[{key:`fullDisk`,pane:`fullDisk`,platforms:[`darwin`]},{key:`screen`,pane:`screen`},{key:`microphone`,pane:`microphone`},{key:`accessibility`,pane:`accessibility`},{key:`automation`,pane:`automation`},{key:`notifications`,pane:`notifications`},{key:`location`,pane:`location`}];function Mu(e){return e===`linux`?ju:ju.filter(t=>!t.platforms||t.platforms.includes(e))}function Nu(e,t){let n=s(e).systemSettings.status;return t===`granted`?{label:n.granted,className:`text-emerald-600 dark:text-emerald-400`}:t===`denied`?{label:n.denied,className:`text-amber-600 dark:text-amber-400`}:{label:n.unknown,className:`text-fg-muted`}}function Pu(e,t,n){let r=s(e).systemSettings.permUnknown?.[t];return r?n===`darwin`&&r.darwin?r.darwin:n===`win32`&&r.win32?r.win32:n===`linux`&&r.linux?r.linux:null:null}var Fu={behavior:null,perms:null,loadError:null,permFeedback:null,permBusy:!1,refreshing:!1};function Iu(){let e=a(e=>e.language),t=s(e).systemSettings,[n,r]=(0,Z.useReducer)(Lt,Fu),{behavior:i,perms:o,loadError:c,permFeedback:l,permBusy:u,refreshing:d}=n,f=typeof window<`u`?window.electronAPI?.system:void 0,p=(0,Z.useCallback)(async e=>{if(f){r({type:`patch`,patch:{loadError:null}});try{r({type:`patch`,patch:{behavior:await f.getBehavior(),perms:await f.getPermissions({probe:e?.showRefreshFeedback}),...e?.showRefreshFeedback?{permFeedback:t.refreshDone}:{}}})}catch(t){r({type:`patch`,patch:{loadError:t instanceof Error?t.message:String(t),...e?.showRefreshFeedback?{permFeedback:null}:{}}})}}},[f,t.refreshDone]),m=(0,Z.useCallback)(async()=>{if(!(d||u)){r({type:`patch`,patch:{refreshing:!0}});try{await p({showRefreshFeedback:!0})}finally{r({type:`patch`,patch:{refreshing:!1}})}}},[p,u,d]);if((0,Z.useEffect)(()=>{let e=new Set([t.refreshDone,t.openSettingsDone,t.openSettingsFailed,t.desktopNotify.testShown]);if(!l||!e.has(l))return;let n=window.setTimeout(()=>{r({type:`patch`,patch:{permFeedback:null}})},3e3);return()=>window.clearTimeout(n)},[l,t.openSettingsDone,t.openSettingsFailed,t.refreshDone,t.desktopNotify.testShown]),(0,Z.useEffect)(()=>{Ue()&&f&&p()},[f,p]),!Ue()||!f)return(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,$.jsxs)(`div`,{className:yn(),children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.desktopOnlyTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.desktopOnlyBody})]})]});let h=async e=>{try{let{behavior:t}=await f.setBehavior(e);r({type:`patch`,patch:{behavior:t}}),(e.notifyEnabled!==void 0||e.notifySoundEnabled!==void 0)&&xe()}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}},g=async e=>{if(!e){await h({notifyEnabled:!1});return}r({type:`patch`,patch:{permBusy:!0,permFeedback:null}});try{let e=await ke(t.desktopNotify.testTitle,t.desktopNotify.testBody);if(e===`unsupported`){r({type:`patch`,patch:{permFeedback:t.notificationsFeedback.unsupported}});return}if(e===`denied`){r({type:`patch`,patch:{permFeedback:t.desktopNotify.denied}});return}if(e===`default`){r({type:`patch`,patch:{permFeedback:t.notificationsFeedback.default}});return}await h({notifyEnabled:!0}),r({type:`patch`,patch:{perms:await f.getPermissions()}}),r({type:`patch`,patch:{permFeedback:t.desktopNotify.testShown}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{permBusy:!1}})}},_=async e=>{r({type:`patch`,patch:{permFeedback:null}}),r({type:`patch`,patch:{loadError:null}});try{(await f.openPrivacy(e)).ok?r({type:`patch`,patch:{permFeedback:t.openSettingsDone}}):r({type:`patch`,patch:{permFeedback:t.openSettingsFailed}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}},v=async()=>{r({type:`patch`,patch:{permBusy:!0,permFeedback:null}}),r({type:`patch`,patch:{loadError:null}});try{let e=await f.requestMicrophone(),n=await Cu();r({type:`patch`,patch:{perms:await f.getPermissions()}}),r({type:`patch`,patch:{permFeedback:wu(e,n,t.permFeedback)}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{permBusy:!1}})}},y=async()=>{if(f.requestAccessibility){r({type:`patch`,patch:{permBusy:!0,permFeedback:null}}),r({type:`patch`,patch:{loadError:null}});try{let e=await f.requestAccessibility();r({type:`patch`,patch:{perms:await f.getPermissions()}}),r({type:`patch`,patch:{permFeedback:Tu(e,t.accessibilityFeedback)}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{permBusy:!1}})}}},b=async()=>{if(f.requestNotifications){r({type:`patch`,patch:{permBusy:!0,permFeedback:null}}),r({type:`patch`,patch:{loadError:null}});try{let e=await f.requestNotifications();r({type:`patch`,patch:{perms:await f.getPermissions()}}),r({type:`patch`,patch:{permFeedback:Eu(e,t.notificationsFeedback)}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{permBusy:!1}})}}},x=async()=>{if(f.requestScreen){r({type:`patch`,patch:{permBusy:!0,permFeedback:null}}),r({type:`patch`,patch:{loadError:null}});try{let e=await f.requestScreen();r({type:`patch`,patch:{perms:await f.getPermissions()}}),r({type:`patch`,patch:{permFeedback:Du(e,t.screenFeedback)}})}catch(e){r({type:`patch`,patch:{loadError:e instanceof Error?e.message:String(e)}})}finally{r({type:`patch`,patch:{permBusy:!1}})}}},S=i?i.platform===`win32`?t.permissionsHintWin:i.platform===`linux`?t.permissionsHintLinux:i.platform===`darwin`?t.permissionsHintDarwin:t.permissionsHint:t.permissionsHint;return(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,$.jsx)(`div`,{children:(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title})}),c?(0,$.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:c}):null,l?(0,$.jsx)(`p`,{className:J(`text-sm`,l===t.refreshDone||l===t.openSettingsDone||l===t.permFeedback.granted||l===t.permFeedback.alreadyGranted||l===t.accessibilityFeedback.granted||l===t.accessibilityFeedback.alreadyGranted||l===t.notificationsFeedback.granted||l===t.notificationsFeedback.alreadyGranted||l===t.screenFeedback.granted||l===t.screenFeedback.alreadyGranted||l===t.desktopNotify.testShown?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`),role:`status`,"aria-live":`polite`,children:l}):null,(0,$.jsxs)(X,{children:[(0,$.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,$.jsx)(Me,{className:`size-4 text-accent`,strokeWidth:1.75}),t.behaviorGroup]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.openAtLogin}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.openAtLoginDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!i,checked:!!i?.openAtLogin,onChange:e=>{h({openAtLogin:e.target.checked})}})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.keepAwake}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.keepAwakeDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!i,checked:!!i?.keepAwakePreferred,onChange:e=>{h({keepAwakePreferred:e.target.checked})}})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifyDesktop}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifyDesktopDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!i||u,checked:!!i?.notifyEnabled,onChange:e=>{g(e.target.checked)}})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifySound}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifySoundDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!i,checked:!!i?.notifySoundEnabled,onChange:e=>{h({notifySoundEnabled:e.target.checked})}})]})]})]}),i&&o?(0,$.jsxs)(`section`,{className:yn(),children:[(0,$.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.permissionsTitle}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:S}),i.platform===`darwin`&&!i.packaged?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-amber-600 dark:text-amber-400`,children:t.permissionsHintDevDarwin}):null]}),(0,$.jsxs)(`button`,{type:`button`,disabled:d||u,"aria-busy":d,className:J(`mt-2 inline-flex max-w-full items-center justify-center gap-1.5 rounded-lg border border-edge bg-surface-panel px-3 py-1.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover disabled:opacity-50 sm:mt-0`,K.press),onClick:()=>void m(),children:[(0,$.jsx)(Ze,{className:J(`size-3.5`,d&&`animate-spin`),strokeWidth:1.75,"aria-hidden":!0}),d?t.refreshing:t.refresh]})]}),(0,$.jsx)(`ul`,{className:`space-y-3`,children:Mu(i.platform).map(({key:n,pane:r})=>{let a=Nu(e,o[n]),s=t.perm[n],c=o[n]===`unknown`?Pu(e,n,i.platform):null;return s?(0,$.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:s.title}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:s.desc}),(0,$.jsx)(`p`,{className:`mt-1 text-xs font-medium ${a.className}`,children:a.label}),c?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:c}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[n===`notifications`&&ku(n,o[n],i.platform)?(0,$.jsx)(`button`,{type:`button`,disabled:u,className:J(`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,K.press),onClick:()=>void b(),children:t.requestAccess}):null,n===`microphone`&&ku(n,o[n],i.platform)?(0,$.jsx)(`button`,{type:`button`,disabled:u,className:J(`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,K.press),onClick:()=>void v(),children:t.requestAccess}):null,n===`accessibility`&&ku(n,o[n],i.platform)?(0,$.jsx)(`button`,{type:`button`,disabled:u,className:J(`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,K.press),onClick:()=>void y(),children:t.requestAccess}):null,n===`screen`&&ku(n,o[n],i.platform)?(0,$.jsx)(`button`,{type:`button`,disabled:u,className:J(`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,K.press),onClick:()=>void x(),children:t.requestAccess}):null,Au(n,o[n],i.platform)?(0,$.jsxs)(`button`,{type:`button`,className:J(`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,K.press),onClick:()=>void _(r),children:[t.openSettings,(0,$.jsx)(fe,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]}):null]})]},n):null})})]}):null]})}var Lu=/^([^:=]+)[:=](.*)$/;function Ru(e){let t=e.trim();if(!t)return null;try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}))}catch{}let n=[];for(let e of t.split(/\r?\n/)){let t=e.trim();if(!t)continue;let r=Lu.exec(t);r&&n.push({key:r[1].trim(),value:r[2].trim()})}return n.length>0?n:null}function zu(e){let t={};for(let n of e){let e=n.key.trim();e&&(t[e]=n.value)}return Object.keys(t).length>0?t:void 0}function Bu(e){if(!e||typeof e!=`object`)return[{key:``,value:``}];let t=Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}));return t.length>0?t:[{key:``,value:``}]}function Vu(e){let t=e.trim();if(t)return t.split(/\s+/).filter(Boolean)}function Hu(e){let t=e.trim();if(!t)return;let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Expected a JSON object`);return n}function Uu(e){if(e.transport===`stdio`){let t={command:e.command.trim()},n=Vu(e.argsText);return n?.length&&(t.args=n),e.cwd.trim()&&(t.cwd=e.cwd.trim()),e.envJson.trim()&&(t.env=Hu(e.envJson)),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),t}let t={url:e.url.trim(),transport:e.transport},n=zu(e.headers);return n&&(t.headers=n),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),t}function Wu(e,t){let n=typeof t.url==`string`&&t.url.trim().length>0,r=typeof t.transport==`string`?t.transport.trim().toLowerCase():``,i=n?r===`sse`?`sse`:`streamable-http`:`stdio`,a=t.headers&&typeof t.headers==`object`&&!Array.isArray(t.headers)?t.headers:void 0;return{clientKey:e,id:e,transport:i,command:typeof t.command==`string`?t.command:``,argsText:Array.isArray(t.args)?t.args.map(String).join(` `):``,envJson:t.env&&typeof t.env==`object`?JSON.stringify(t.env,null,2):``,cwd:typeof t.cwd==`string`?t.cwd:typeof t.workingDirectory==`string`?t.workingDirectory:``,url:typeof t.url==`string`?t.url:``,headers:Bu(a),connectionTimeoutMs:typeof t.connectionTimeoutMs==`number`&&Number.isFinite(t.connectionTimeoutMs)?t.connectionTimeoutMs:void 0}}function Gu(e=``){return{clientKey:crypto.randomUUID(),id:e,transport:`stdio`,command:``,argsText:``,envJson:``,cwd:``,url:``,headers:[{key:`Authorization`,value:``}],connectionTimeoutMs:void 0}}function Ku(e){let t=e&&typeof e==`object`&&`mcp`in e?e.mcp:void 0,n=t&&typeof t==`object`?t:{},r=n.servers,i=r&&typeof r==`object`&&!Array.isArray(r)?Object.entries(r).flatMap(([e,t])=>!t||typeof t!=`object`?[]:[Wu(e,t)]).sort((e,t)=>e.id.localeCompare(t.id)):[],a=typeof n.sessionIdleTtlMs==`number`?n.sessionIdleTtlMs:void 0;return{sessionIdleTtlMinutes:a==null?void 0:a===0?0:Math.round(a/6e4),servers:i}}function qu(e){return Uu(e)}async function Ju(e){let t={};for(let n of e.servers){let e=n.id.trim();e&&(t[e]=Uu(n))}let n={servers:t};e.sessionIdleTtlMinutes!=null&&Number.isFinite(e.sessionIdleTtlMinutes)&&(n.sessionIdleTtlMs=e.sessionIdleTtlMinutes===0?0:Math.round(e.sessionIdleTtlMinutes*6e4)),await w(l(`/api/config`),{method:`PATCH`,body:JSON.stringify({mcp:n})}),Qt()}function Yu(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n==`string`){let e=n.trim();e&&t.push({name:e});continue}if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.name!=`string`)continue;let r=e.name.trim();if(!r)continue;let i=typeof e.shortName==`string`&&e.shortName.trim()?e.shortName.trim():void 0,a=typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0;t.push({name:r,shortName:i,description:a})}return t}async function Xu(e,t){let n=await w(l(`/api/mcp/servers/${encodeURIComponent(e)}/test`),{method:`POST`,body:t?JSON.stringify({server:t}):void 0});if(!n.payload)throw Error(n.error??`MCP test failed`);let r=Yu(n.payload.tools);return{serverId:n.payload.serverId??e,toolCount:typeof n.payload.toolCount==`number`?n.payload.toolCount:r.length,tools:r}}function Zu(e){return e.connectionTimeoutMs==null||!Number.isFinite(e.connectionTimeoutMs)?``:String(Math.round(e.connectionTimeoutMs/1e3))}function Qu(e){let t=e.trim();if(!t)return;let n=Number.parseInt(t,10);if(!(!Number.isFinite(n)||n<1||n>600))return n*1e3}function $u(e,t){return e.clientKey}function ed(e,t,n){let r=e.key.trim();if(r)return`key:${r}`;let i=e.value.trim();return i?`value:${i}`:`empty:${n.slice(0,t).filter(e=>!e.key.trim()&&!e.value.trim()).length}`}function td(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ht)}function nd({label:e,optionalLabel:t,addLabel:n,removeHeaderAria:r,pasteLabel:i,pasteFailed:a,keyPlaceholder:o,valuePlaceholder:s,headers:c,onChange:l}){let u=(e,t)=>{l(c.map((n,r)=>r===e?{...n,...t}:n))},d=()=>{l([...c,{key:``,value:``}])},f=e=>{let t=c.filter((t,n)=>n!==e);l(t.length>0?t:[{key:``,value:``}])},p=async()=>{try{let e=await Ft();if(!e){window.alert(a);return}let t=Ru(e);if(!t?.length){window.alert(a);return}l(t)}catch{window.alert(a)}};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 md:col-span-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-fg`,children:[(0,$.jsx)(`span`,{children:e}),t?(0,$.jsx)(`span`,{className:`font-normal text-fg-subtle`,children:t}):null]}),(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`h-8 gap-1.5 px-2 text-xs`,onClick:()=>void p(),children:[(0,$.jsx)(ue,{className:`size-3.5`,"aria-hidden":!0}),i]})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:c.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{className:J(td(),`min-w-0 flex-1 font-mono text-xs`),value:e.key,placeholder:o,onChange:e=>u(t,{key:e.target.value})}),(0,$.jsx)(`input`,{className:J(td(),`min-w-0 flex-[1.4] font-mono text-xs`),value:e.value,placeholder:s,onChange:e=>u(t,{value:e.target.value})}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 px-0`,disabled:c.length<=1&&!e.key&&!e.value,onClick:()=>f(t),"aria-label":r,children:(0,$.jsx)(Re,{className:`size-4 text-fg-subtle`,"aria-hidden":!0})})]},ed(e,t,c)))}),(0,$.jsxs)(`button`,{type:`button`,className:J(`self-start text-sm text-accent hover:underline`,K.press),onClick:d,children:[`+ `,n]})]})}var rd=[`stdio`,`sse`,`streamable-http`];function id(e){let t=(0,Q.c)(11),{label:n,description:r,required:i,children:a}=e,o;t[0]===i?o=t[1]:(o=i?(0,$.jsx)(`span`,{className:`ml-0.5 text-danger`,children:`*`}):null,t[0]=i,t[1]=o);let s;t[2]!==n||t[3]!==o?(s=(0,$.jsxs)(`div`,{className:`text-sm font-medium text-fg`,children:[n,o]}),t[2]=n,t[3]=o,t[4]=s):s=t[4];let c;t[5]===r?c=t[6]:(c=r?(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r}):null,t[5]=r,t[6]=c);let l;return t[7]!==a||t[8]!==s||t[9]!==c?(l=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[s,a,c]}),t[7]=a,t[8]=s,t[9]=c,t[10]=l):l=t[10],l}function ad(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ht)}function od(e){if(e.transport===`stdio`){let t=e.command.trim();if(!t)return``;let n=e.argsText.trim();return n?`${t} ${n}`:t}return e.url.trim()}function sd(e){let t=(0,Q.c)(100),{row:n,expanded:r,onToggle:i,t:a,testing:o,toolState:s,onUpdate:c,onRemove:l,onTest:u,onViewTools:d}=e,f;t[0]!==n.id||t[1]!==a.cardUntitled?(f=n.id.trim()||a.cardUntitled,t[0]=n.id,t[1]=a.cardUntitled,t[2]=f):f=t[2];let p=f,m;t[3]===n?m=t[4]:(m=od(n),t[3]=n,t[4]=m);let h=m,g=a.transportLabels[n.transport],_;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(_=J(`flex min-w-0 flex-1 items-start gap-2 rounded-lg text-left hover:opacity-90`,K.press),t[5]=_):_=t[5];let v=r?a.cardCollapseAria:a.cardExpandAria,y=r&&`rotate-180`,b;t[6]===y?b=t[7]:(b=J(`mt-0.5 size-4 shrink-0 text-fg-subtle transition-transform`,y),t[6]=y,t[7]=b);let x;t[8]===b?x=t[9]:(x=(0,$.jsx)(xt,{className:b,"aria-hidden":!0}),t[8]=b,t[9]=x);let S;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(Wt,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),t[10]=S):S=t[10];let C;t[11]===p?C=t[12]:(C=(0,$.jsx)(`span`,{className:`truncate font-medium text-fg`,children:p}),t[11]=p,t[12]=C);let w;t[13]===g?w=t[14]:(w=(0,$.jsx)(`span`,{className:`rounded-md border border-edge bg-surface-base px-1.5 py-0.5 text-[11px] text-fg-muted`,children:g}),t[13]=g,t[14]=w);let T;t[15]!==s.status||t[16]!==s.tools?(T=s.status===`ok`&&s.tools.length>0?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-edge bg-surface-base px-1.5 py-0.5 text-[11px] text-fg-muted`,children:[(0,$.jsx)(et,{className:`size-3`,"aria-hidden":!0}),s.tools.length]}):null,t[15]=s.status,t[16]=s.tools,t[17]=T):T=t[17];let E;t[18]!==w||t[19]!==T||t[20]!==C?(E=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[S,C,w,T]}),t[18]=w,t[19]=T,t[20]=C,t[21]=E):E=t[21];let D;t[22]!==r||t[23]!==h?(D=!r&&h?(0,$.jsx)(`p`,{className:`mt-1 truncate font-mono text-xs text-fg-subtle`,title:h,children:h}):null,t[22]=r,t[23]=h,t[24]=D):D=t[24];let O;t[25]!==r||t[26]!==s.message||t[27]!==s.status?(O=!r&&s.status===`error`?(0,$.jsx)(`p`,{className:`mt-1 truncate text-xs text-red-600 dark:text-red-300`,title:s.message,children:s.message}):null,t[25]=r,t[26]=s.message,t[27]=s.status,t[28]=O):O=t[28];let k;t[29]!==E||t[30]!==D||t[31]!==O?(k=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[E,D,O]}),t[29]=E,t[30]=D,t[31]=O,t[32]=k):k=t[32];let A;t[33]!==r||t[34]!==i||t[35]!==k||t[36]!==v||t[37]!==x?(A=(0,$.jsxs)(`button`,{type:`button`,className:_,"aria-expanded":r,"aria-label":v,onClick:i,children:[x,k]}),t[33]=r,t[34]=i,t[35]=k,t[36]=v,t[37]=x,t[38]=A):A=t[38];let j;t[39]!==n.id||t[40]!==o?(j=!n.id.trim()||o,t[39]=n.id,t[40]=o,t[41]=j):j=t[41];let M;t[42]===u?M=t[43]:(M=e=>{e.stopPropagation(),u()},t[42]=u,t[43]=M);let N;t[44]===o?N=t[45]:(N=o?(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(bt,{className:`size-4`,"aria-hidden":!0}),t[44]=o,t[45]=N);let P;t[46]!==a.testConnection||t[47]!==j||t[48]!==M||t[49]!==N?(P=(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-xs`,disabled:j,onClick:M,children:[N,a.testConnection]}),t[46]=a.testConnection,t[47]=j,t[48]=M,t[49]=N,t[50]=P):P=t[50];let F;t[51]===l?F=t[52]:(F=e=>{e.stopPropagation(),l()},t[51]=l,t[52]=F);let I;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(Re,{className:`size-4`,"aria-hidden":!0}),t[53]=I):I=t[53];let L;t[54]!==a.removeServer||t[55]!==F?(L=(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-xs`,onClick:F,children:[I,a.removeServer]}),t[54]=a.removeServer,t[55]=F,t[56]=L):L=t[56];let R;t[57]!==P||t[58]!==L?(R=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[P,L]}),t[57]=P,t[58]=L,t[59]=R):R=t[59];let z;t[60]!==A||t[61]!==R?(z=(0,$.jsxs)(`div`,{className:`flex items-start gap-2 p-4`,children:[A,R]}),t[60]=A,t[61]=R,t[62]=z):z=t[62];let B;t[63]!==r||t[64]!==c||t[65]!==d||t[66]!==n||t[67]!==a.addHeader||t[68]!==a.argsHint||t[69]!==a.argsLabel||t[70]!==a.commandLabel||t[71]!==a.cwdLabel||t[72]!==a.envHint||t[73]!==a.envLabel||t[74]!==a.headerKeyPlaceholder||t[75]!==a.headerValuePlaceholder||t[76]!==a.headersLabel||t[77]!==a.optionalSuffix||t[78]!==a.pasteHeaders||t[79]!==a.pasteHeadersFailed||t[80]!==a.removeHeader||t[81]!==a.serverIdLabel||t[82]!==a.serverIdPlaceholder||t[83]!==a.timeoutHint||t[84]!==a.timeoutLabel||t[85]!==a.timeoutPlaceholder||t[86]!==a.toolsEmpty||t[87]!==a.toolsLoading||t[88]!==a.toolsTitle||t[89]!==a.transportLabel||t[90]!==a.transportLabels||t[91]!==a.urlLabel||t[92]!==a.viewAllTools||t[93]!==s.message||t[94]!==s.status||t[95]!==s.tools?(B=r?(0,$.jsxs)(`div`,{className:`border-t border-edge px-4 pb-4 pt-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,$.jsx)(id,{label:a.transportLabel,required:!0,children:(0,$.jsx)(`select`,{className:ad(),value:n.transport,onChange:e=>c({transport:e.target.value}),children:rd.map(e=>(0,$.jsx)(`option`,{value:e,children:a.transportLabels[e]},e))})}),(0,$.jsx)(id,{label:a.serverIdLabel,required:!0,children:(0,$.jsx)(`input`,{className:ad(),value:n.id,placeholder:a.serverIdPlaceholder,onChange:e=>c({id:e.target.value})})}),n.transport===`stdio`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(id,{label:a.commandLabel,children:(0,$.jsx)(`input`,{className:ad(),value:n.command,onChange:e=>c({command:e.target.value})})}),(0,$.jsx)(id,{label:a.argsLabel,description:a.argsHint,children:(0,$.jsx)(`input`,{className:ad(),value:n.argsText,onChange:e=>c({argsText:e.target.value})})}),(0,$.jsx)(id,{label:a.cwdLabel,children:(0,$.jsx)(`input`,{className:ad(),value:n.cwd,onChange:e=>c({cwd:e.target.value})})}),(0,$.jsx)(id,{label:a.envLabel,description:a.envHint,children:(0,$.jsx)(`textarea`,{className:J(ad(),`min-h-[4rem] font-mono text-xs`),value:n.envJson,onChange:e=>c({envJson:e.target.value})})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`md:col-span-2`,children:(0,$.jsx)(id,{label:a.urlLabel,required:!0,children:(0,$.jsx)(`input`,{className:J(ad(),`font-mono text-xs`),value:n.url,placeholder:`https://example.com/mcp`,onChange:e=>c({url:e.target.value})})})}),(0,$.jsx)(nd,{label:a.headersLabel,optionalLabel:a.optionalSuffix,addLabel:a.addHeader,removeHeaderAria:a.removeHeader,pasteLabel:a.pasteHeaders,pasteFailed:a.pasteHeadersFailed,keyPlaceholder:a.headerKeyPlaceholder,valuePlaceholder:a.headerValuePlaceholder,headers:n.headers,onChange:e=>c({headers:e})})]}),(0,$.jsx)(id,{label:a.timeoutLabel,description:a.timeoutHint,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:600,className:ad(),value:Zu(n),placeholder:a.timeoutPlaceholder,onChange:e=>c({connectionTimeoutMs:Qu(e.target.value)})})})]}),s.status===`loading`?(0,$.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}),a.toolsLoading]}):null,s.status===`error`?(0,$.jsx)(`p`,{className:`mt-4 rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-xs text-red-600 dark:text-red-300`,children:s.message}):null,s.status===`ok`?(0,$.jsx)(`div`,{className:`mt-4 rounded-lg border border-edge bg-surface-base px-3 py-2.5`,children:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-fg`,children:[(0,$.jsx)(et,{className:`size-4 text-accent`,"aria-hidden":!0}),s.tools.length===0?a.toolsEmpty:a.toolsTitle.replace(`{{count}}`,String(s.tools.length))]}),s.tools.length>0?(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`h-8 text-xs`,onClick:()=>d(s.tools),children:a.viewAllTools}):null]})}):null]}):null,t[63]=r,t[64]=c,t[65]=d,t[66]=n,t[67]=a.addHeader,t[68]=a.argsHint,t[69]=a.argsLabel,t[70]=a.commandLabel,t[71]=a.cwdLabel,t[72]=a.envHint,t[73]=a.envLabel,t[74]=a.headerKeyPlaceholder,t[75]=a.headerValuePlaceholder,t[76]=a.headersLabel,t[77]=a.optionalSuffix,t[78]=a.pasteHeaders,t[79]=a.pasteHeadersFailed,t[80]=a.removeHeader,t[81]=a.serverIdLabel,t[82]=a.serverIdPlaceholder,t[83]=a.timeoutHint,t[84]=a.timeoutLabel,t[85]=a.timeoutPlaceholder,t[86]=a.toolsEmpty,t[87]=a.toolsLoading,t[88]=a.toolsTitle,t[89]=a.transportLabel,t[90]=a.transportLabels,t[91]=a.urlLabel,t[92]=a.viewAllTools,t[93]=s.message,t[94]=s.status,t[95]=s.tools,t[96]=B):B=t[96];let V;return t[97]!==z||t[98]!==B?(V=(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-panel`,children:[z,B]}),t[97]=z,t[98]=B,t[99]=V):V=t[99],V}function cd(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function ld(e,t,n){let r=t.trim().toLowerCase();if(!r)return!0;let i=e.shortName||cd(e.name,n);return[e.name,i,e.description].filter(Boolean).join(`
|
|
3
|
-
`).toLowerCase().includes(r)}function ud(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function dd(e){let t=(0,Q.c)(29),{tools:n,stripPrefix:r,searchPlaceholder:i,searchEmptyLabel:a}=e,[o,s]=(0,Z.useState)(``),c;if(t[0]!==o||t[1]!==r||t[2]!==n){let e;t[4]!==o||t[5]!==r?(e=e=>ld(e,o,r),t[4]=o,t[5]=r,t[6]=e):e=t[6],c=n.filter(e),t[0]=o,t[1]=r,t[2]=n,t[3]=c}else c=t[3];let l=c,u;t[7]===o?u=t[8]:(u=o.trim(),t[7]=o,t[8]=u);let d=u.length>0,f;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(We,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,"aria-hidden":!0}),t[9]=f):f=t[9];let p,m;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(p=J(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-9 pr-3 text-sm text-fg`,`placeholder:text-fg-subtle`,ht),m=e=>s(e.target.value),t[10]=p,t[11]=m):(p=t[10],m=t[11]);let h;t[12]!==o||t[13]!==i?(h=(0,$.jsxs)(`div`,{className:`relative`,children:[f,(0,$.jsx)(`input`,{type:`search`,value:o,placeholder:i,"aria-label":i,className:p,onChange:m})]}),t[12]=o,t[13]=i,t[14]=h):h=t[14];let g;t[15]!==l.length||t[16]!==d||t[17]!==n.length?(g=d?(0,$.jsxs)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:[l.length,` / `,n.length]}):null,t[15]=l.length,t[16]=d,t[17]=n.length,t[18]=g):g=t[18];let _;t[19]!==h||t[20]!==g?(_=(0,$.jsxs)(`div`,{className:`border-b border-edge px-5 py-3`,children:[h,g]}),t[19]=h,t[20]=g,t[21]=_):_=t[21];let v;t[22]!==l||t[23]!==a||t[24]!==r?(v=(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:l.length===0?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:a}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2`,children:l.map((e,t)=>{let n=e.shortName||ud(e.name,r)||e.name||`?`,i=e.name||`tool-${t}`;return(0,$.jsxs)(`li`,{className:`min-w-0 rounded-lg border border-edge bg-surface-base px-3 py-2.5`,children:[(0,$.jsx)(`div`,{className:`truncate font-mono text-sm font-medium text-fg`,title:e.name===n?n:e.name,children:n}),e.description?(0,$.jsx)(`p`,{className:`mt-1 truncate text-xs leading-relaxed text-fg-muted`,title:e.description,children:e.description}):null]},i)})})}),t[22]=l,t[23]=a,t[24]=r,t[25]=v):v=t[25];let y;return t[26]!==_||t[27]!==v?(y=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[_,v]}),t[26]=_,t[27]=v,t[28]=y):y=t[28],y}function fd(e){let t=(0,Q.c)(38),{open:n,onOpenChange:r,serverId:i,title:a,subtitle:o,searchPlaceholder:s,searchEmptyLabel:c,emptyLabel:l,closeLabel:u,tools:d,stripPrefix:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(g,{className:J(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Pe)}),t[0]=p):p=t[0];let m;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=J(`fixed left-1/2 top-1/2 flex max-h-[min(88vh,40rem)] w-[min(100%-2rem,min(92vw,36rem))] -translate-x-1/2 -translate-y-1/2 flex-col`,Xt,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`),t[1]=m):m=t[1];let S;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(et,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),t[2]=S):S=t[2];let C;t[3]===a?C=t[4]:(C=(0,$.jsxs)(b,{className:`flex items-center gap-2 text-base font-semibold text-fg`,children:[S,a]}),t[3]=a,t[4]=C);let w;t[5]!==i||t[6]!==o||t[7]!==d.length?(w=o.replace(`{{serverId}}`,i).replace(`{{count}}`,String(d.length)),t[5]=i,t[6]=o,t[7]=d.length,t[8]=w):w=t[8];let T;t[9]===w?T=t[10]:(T=(0,$.jsx)(y,{className:`mt-1 text-sm text-fg-muted`,children:w}),t[9]=w,t[10]=T);let E;t[11]!==C||t[12]!==T?(E=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[C,T]}),t[11]=C,t[12]=T,t[13]=E):E=t[13];let D;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(vt,{className:`size-4`,"aria-hidden":!0}),t[14]=D):D=t[14];let O;t[15]===u?O=t[16]:(O=(0,$.jsx)(x,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`ghost`,className:`size-8 shrink-0 px-0`,"aria-label":u,children:D})}),t[15]=u,t[16]=O);let k;t[17]!==E||t[18]!==O?(k=(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-edge px-5 py-4`,children:[E,O]}),t[17]=E,t[18]=O,t[19]=k):k=t[19];let A;t[20]!==l||t[21]!==n||t[22]!==c||t[23]!==s||t[24]!==i||t[25]!==f||t[26]!==d?(A=d.length>0?(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,$.jsx)(dd,{tools:d,stripPrefix:f,searchPlaceholder:s,searchEmptyLabel:c},`${i}-${n?`open`:`closed`}`)}):(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l})}),t[20]=l,t[21]=n,t[22]=c,t[23]=s,t[24]=i,t[25]=f,t[26]=d,t[27]=A):A=t[27];let j;t[28]===u?j=t[29]:(j=(0,$.jsx)(`div`,{className:`flex justify-end border-t border-edge px-5 py-3`,children:(0,$.jsx)(x,{asChild:!0,children:(0,$.jsx)(Y,{type:`button`,variant:`secondary`,children:u})})}),t[28]=u,t[29]=j);let M;t[30]!==k||t[31]!==A||t[32]!==j?(M=(0,$.jsxs)(h,{children:[p,(0,$.jsxs)(_,{className:m,children:[k,A,j]})]}),t[30]=k,t[31]=A,t[32]=j,t[33]=M):M=t[33];let N;return t[34]!==r||t[35]!==n||t[36]!==M?(N=(0,$.jsx)(v,{open:n,onOpenChange:r,children:M}),t[34]=r,t[35]=n,t[36]=M,t[37]=N):N=t[37],N}function pd(){return J(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ht)}function md(e,t){switch(t.type){case`reset`:return{form:null,baseline:null,expandedKeys:new Set};case`sync`:return{form:t.value,baseline:t.value,expandedKeys:new Set};case`set-form`:return e.form?{...e,form:t.updater(e.form)}:e;case`saved`:return{form:t.value,baseline:t.value,expandedKeys:new Set};case`toggle-expanded`:{let n=new Set(e.expandedKeys);return n.has(t.key)?n.delete(t.key):n.add(t.key),{...e,expandedKeys:n}}case`set-expanded`:return{...e,expandedKeys:t.keys}}}var hd={saving:!1,error:null,saveOk:!1,testingId:null,serverTools:{},toolsDialog:null};function gd(){let e=s(a(e=>e.language)),t=e.mcpSettings,n=!!C(e=>e.token),[r,i]=(0,Z.useReducer)(md,{form:null,baseline:null,expandedKeys:new Set}),o=r.form,c=r.baseline,l=r.expandedKeys,[u,d]=(0,Z.useReducer)(Lt,hd),{saving:f,error:p,saveOk:m,testingId:h,serverTools:g,toolsDialog:_}=u,v=(0,Z.useRef)(!1),{data:y,error:b,isLoading:x,mutate:S}=Fe(n),w=(0,Z.useMemo)(()=>y?.payload?.config===void 0?null:Ku(y.payload.config),[y]);(0,Z.useEffect)(()=>{if(!n){i({type:`reset`}),v.current=!1;return}w===null||v.current||i({type:`sync`,value:w})},[n,w]);let T=!!(n&&x&&y===void 0&&!b),E=b instanceof Error?b.message:b?String(b):null,D=(0,Z.useMemo)(()=>!o||!c?!1:JSON.stringify(o)!==JSON.stringify(c),[o,c]),O=(0,Z.useCallback)(e=>{i({type:`toggle-expanded`,key:e})},[]),k=(0,Z.useCallback)((e,t)=>{v.current=!0,i({type:`set-form`,updater:n=>{let r=[...n.servers],i=r[e];return i?(r[e]={...i,...t},t.id&&t.id!==i.id&&i.id&&d({type:`patch`,patch:{serverTools:(()=>{let e={...g};return delete e[i.id],e})()}}),{...n,servers:r}):n}})},[]),A=(0,Z.useCallback)(()=>{v.current=!0,i({type:`set-form`,updater:e=>{let t=e.servers.length,n=Gu(`server-${t+1}`),r=$u(n,t);return i({type:`set-expanded`,keys:new Set(l).add(r)}),{...e,servers:[...e.servers,n]}}})},[l]),j=(0,Z.useCallback)(e=>{v.current=!0,i({type:`set-form`,updater:t=>{let n=t.servers[e];if(n){let t=$u(n,e),r=new Set(l);r.delete(t),i({type:`set-expanded`,keys:r}),n.id&&d({type:`patch`,patch:{serverTools:(()=>{let e={...g};return delete e[n.id],e})()}})}return{...t,servers:t.servers.filter((t,n)=>n!==e)}}})},[l]),M=(0,Z.useCallback)(async()=>{if(!(!o||f)){d({type:`patch`,patch:{saving:!0,error:null,saveOk:!1}});try{await Ju(o);let e=structuredClone(o);v.current=!1,i({type:`saved`,value:e}),d({type:`patch`,patch:{saveOk:!0}}),S()}catch(e){d({type:`patch`,patch:{error:e instanceof Error?e.message:String(e)}})}finally{d({type:`patch`,patch:{saving:!1}})}}},[o,S,f]),N=(0,Z.useCallback)(async(e,t)=>{if(e.trim()){d({type:`patch`,patch:{testingId:e,error:null,serverTools:{...g,[e]:{status:`loading`}}}});try{let n=t?qu(t):void 0,r=await Xu(e.trim(),n);d({type:`patch`,patch:{serverTools:{...g,[e]:{status:`ok`,tools:r.tools}}}})}catch(t){let n=t instanceof Error?t.message:String(t);d({type:`patch`,patch:{serverTools:{...g,[e]:{status:`error`,message:n}}}})}finally{d({type:`patch`,patch:{testingId:null}})}}},[]);return n?T||!o?(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.loading})]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.title}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.subtitle})]}),(E||p)&&(0,$.jsx)(`p`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-300`,children:p??E}),m&&(0,$.jsx)(`p`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg-muted`,children:t.saved}),(0,$.jsxs)(X,{children:[(0,$.jsx)(vn,{icon:It,title:t.globalTitle,subtitle:t.globalHint}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.idleTtlLabel}),(0,$.jsx)(`input`,{type:`number`,min:0,className:pd(),value:o.sessionIdleTtlMinutes??``,placeholder:t.idleTtlPlaceholder,onChange:e=>{v.current=!0;let t=e.target.value.trim();i({type:`set-form`,updater:e=>({...e,sessionIdleTtlMinutes:t===``?void 0:Number.parseInt(t,10)})})}}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t.idleTtlHint})]})]}),(0,$.jsxs)(X,{children:[(0,$.jsx)(vn,{icon:Wt,title:t.serversTitle,subtitle:t.serversHint}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[o.servers.length===0?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.serversEmpty}):null,o.servers.map((e,n)=>{let r=$u(e,n),i=g[e.id]??{status:`idle`};return(0,$.jsx)(sd,{row:e,expanded:l.has(r),onToggle:()=>O(r),t,testing:h===e.id,toolState:i,onUpdate:e=>k(n,e),onRemove:()=>j(n),onTest:()=>void N(e.id,e),onViewTools:t=>d({type:`patch`,patch:{toolsDialog:{serverId:e.id,tools:t}}})},r)}),(0,$.jsxs)(Y,{type:`button`,variant:`ghost`,className:`self-start`,onClick:A,children:[(0,$.jsx)(dt,{className:`size-4`,"aria-hidden":!0}),t.addServer]})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsxs)(Y,{type:`button`,disabled:!D||f,onClick:()=>void M(),children:[f?(0,$.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,f?t.saving:t.save]}),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,disabled:!D||f,onClick:()=>{c&&(v.current=!1,i({type:`sync`,value:structuredClone(c)}),d({type:`patch`,patch:{saveOk:!1,error:null,serverTools:{}}}))},children:t.discard})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:t.disableHint}),_?(0,$.jsx)(fd,{open:!0,onOpenChange:e=>{e||d({type:`patch`,patch:{toolsDialog:null}})},serverId:_.serverId,title:t.toolsDialogTitle,subtitle:t.toolsDialogSubtitle,searchPlaceholder:t.toolsDialogSearchPlaceholder,searchEmptyLabel:t.toolsDialogSearchEmpty,emptyLabel:t.toolsEmpty,closeLabel:t.toolsDialogClose,tools:_.tools,stripPrefix:`${_.serverId.trim()}__`}):null]}):(0,$.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.token.description})]})}var _d=[`overview`,`appearance`,`system`,`app-management`,`agent-defaults`,`agent-browser`,`agent-mcp`,`credentials`,`gateway`,`heartbeat`,`tunnel`,`remote-access`,`shares`,`cron`,`goals`,`dreams`];function vd(){let e=(0,Q.c)(32),{section:t}=nt(),n=a(yd),r,i,o,c,l;if(e[0]!==n||e[1]!==t){l=Symbol.for(`react.early_return_sentinel`);bb0:{let a=s(n);if(t===`agent`||t===`agents`){let t;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)($e,{to:`/agents`,replace:!0}),e[7]=t):t=e[7],l=t;break bb0}if(!t||!_d.includes(t)){let t;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)($e,{to:`/settings/overview`,replace:!0}),e[8]=t):t=e[8],l=t;break bb0}if(t===`tunnel`){let t;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)($e,{to:`/settings/remote-access`,replace:!0}),e[9]=t):t=e[9],l=t;break bb0}let u=t;if(u===`overview`){let t;e[10]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(mr,{}),e[10]=t):t=e[10],l=t;break bb0}let d=a.settingsSections[u];if(u===`agent-defaults`){let t;e[11]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Fn,{}),e[11]=t):t=e[11],l=t;break bb0}if(u===`agent-browser`){let t;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(An,{}),e[12]=t):t=e[12],l=t;break bb0}if(u===`agent-mcp`){let t;e[13]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(gd,{}),e[13]=t):t=e[13],l=t;break bb0}if(u===`appearance`){let t;e[14]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(za,{}),e[14]=t):t=e[14],l=t;break bb0}if(u===`system`){let t;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Iu,{}),e[15]=t):t=e[15],l=t;break bb0}if(u===`app-management`){let t;e[16]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(xu,{}),e[16]=t):t=e[16],l=t;break bb0}if(u===`credentials`){let t;e[17]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(xa,{}),e[17]=t):t=e[17],l=t;break bb0}if(u===`gateway`){let t;e[18]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Ps,{}),e[18]=t):t=e[18],l=t;break bb0}if(u===`heartbeat`){let t;e[19]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(tc,{}),e[19]=t):t=e[19],l=t;break bb0}if(u===`tunnel`||u===`remote-access`){let t;e[20]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(jl,{}),e[20]=t):t=e[20],l=t;break bb0}if(u===`shares`){let t;e[21]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(ru,{}),e[21]=t):t=e[21],l=t;break bb0}if(u===`dreams`){let t;e[22]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Ho,{}),e[22]=t):t=e[22],l=t;break bb0}if(u===`cron`){let t;e[23]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(es,{}),e[23]=t):t=e[23],l=t;break bb0}if(u===`goals`){let t;e[24]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(us,{}),e[24]=t):t=e[24],l=t;break bb0}o=`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,c=(0,$.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:d}),r=`text-sm text-fg-muted`,i=a.settingsPage.comingSoon.replace(`{{title}}`,d)}e[0]=n,e[1]=t,e[2]=r,e[3]=i,e[4]=o,e[5]=c,e[6]=l}else r=e[2],i=e[3],o=e[4],c=e[5],l=e[6];if(l!==Symbol.for(`react.early_return_sentinel`))return l;let u;e[25]!==r||e[26]!==i?(u=(0,$.jsx)(`p`,{className:r,children:i}),e[25]=r,e[26]=i,e[27]=u):u=e[27];let d;return e[28]!==o||e[29]!==c||e[30]!==u?(d=(0,$.jsxs)(`div`,{className:o,children:[c,u]}),e[28]=o,e[29]=c,e[30]=u,e[31]=d):d=e[31],d}function yd(e){return e.language}export{vd as SettingsPage};
|