From 12b4bf638eb97ab252725a183654d30fb4b14b10 Mon Sep 17 00:00:00 2001 From: Sycun <165354365+Sycun@users.noreply.github.com> Date: Mon, 30 Nov 2026 16:59:32 +0800 Subject: [PATCH] fix(app,hitl,chat): lock DB instance before startup recovery and clear stale task/plan state --- .gitignore | 1 + internal/app/app.go | 26 +++++--- internal/app/instance_lock.go | 38 +++++++++++ internal/app/instance_lock_other.go | 9 +++ internal/app/instance_lock_test.go | 28 +++++++++ internal/app/instance_lock_unix.go | 13 ++++ internal/app/instance_lock_windows.go | 13 ++++ internal/handler/hitl.go | 63 +++++++++++++++---- internal/handler/hitl_restart_test.go | 29 +++++++++ web/frontend/src/pages/chat/index.jsx | 10 ++- ...N0Ndjf.js => AssetEditorModal-C2UJzIaS.js} | 2 +- ...Rdc0M.js => agents-management-BH4GA4Vt.js} | 2 +- ...-docs-BEMXmVy4.js => api-docs-BqzLMZ8q.js} | 2 +- ...-CwccI3Xb.js => asset-library-Btn_YOu0.js} | 2 +- ...xwryoaKx.js => asset-overview-ClxkP_Uu.js} | 2 +- ...ents-b_BWiEV4.js => c2-events-Cdd7cKs8.js} | 2 +- ...s-CE3GvlqS.js => c2-listeners-7rFR5Rx6.js} | 2 +- ...ds-B8TBcwqZ.js => c2-payloads-DP3Iw5IZ.js} | 2 +- ...es-DFa_6zU3.js => c2-profiles-Cxv9lUnu.js} | 2 +- ...ns-BFuBJt9m.js => c2-sessions-CnBIfRAo.js} | 2 +- ...ared-Car3lDYq.js => c2-shared-2EAlkwn6.js} | 2 +- ...ared-D-8kBzuC.js => c2-shared-BrRxH-6B.js} | 2 +- ...tasks-DSV9J8Vu.js => c2-tasks-FVvnpyKj.js} | 2 +- web/static/app/assets/chat-B3amLD8_.js | 5 -- ...les-D2U-2IVG.js => chat-files-BvkWbj5T.js} | 2 +- web/static/app/assets/chat-iFaq7TmY.js | 5 ++ ...oard-8XvRuqLB.js => dashboard-Dwi74cCO.js} | 2 +- ...zSIX6t.js => deep-assessments-BwHg6NCr.js} | 2 +- .../{hitl-CuqgPh-B.js => hitl-hVYHftcD.js} | 2 +- .../{index-CAEPLS-g.js => index-DNMXun-U.js} | 4 +- ...t-CnstRscn.js => info-collect-CIMK0OyE.js} | 2 +- ...XJ.js => knowledge-management-DxjSMTdf.js} | 2 +- ...s => knowledge-retrieval-logs-CJolZ5T-.js} | 2 +- ...BebvY2ig.js => mcp-management-Be2zIK90.js} | 2 +- ...or-CfVvha6O.js => mcp-monitor-DHXOIA-R.js} | 2 +- ...-Bqf7ZmWP.js => platform-rbac-BDY_zjz7.js} | 2 +- ...hub-FbKl43dM.js => plugin-hub-BhSjc1VJ.js} | 2 +- ...m-Bm3Gi6Yc.js => project-form-B7wV5B1p.js} | 2 +- ...jects-CMt4u2Qr.js => projects-CfcDnjFh.js} | 2 +- ...TD0STX.js => roles-management-DZI3VXhR.js} | 2 +- ...tings-yUhIZhl9.js => settings-CgtfKueL.js} | 2 +- ...jeibz.js => skills-management-CBXR8d2s.js} | 2 +- ...BUTc0QtL.js => skills-monitor-Bs5yNZYW.js} | 2 +- .../{tasks-CT27M-Wx.js => tasks-C9yzz-_n.js} | 2 +- ...ard-gHtviV0M.js => tool-guard-DY35NYks.js} | 2 +- ...XGKZewN.js => vulnerabilities-BRH58_rp.js} | 2 +- ...shell-CXOTGht5.js => webshell-CE6Yp5FY.js} | 2 +- ...lows-BnRbScwz.js => workflows-BgrBtPdj.js} | 2 +- web/static/app/index.html | 2 +- 49 files changed, 252 insertions(+), 64 deletions(-) create mode 100644 internal/app/instance_lock.go create mode 100644 internal/app/instance_lock_other.go create mode 100644 internal/app/instance_lock_test.go create mode 100644 internal/app/instance_lock_unix.go create mode 100644 internal/app/instance_lock_windows.go rename web/static/app/assets/{AssetEditorModal-HZN0Ndjf.js => AssetEditorModal-C2UJzIaS.js} (98%) rename web/static/app/assets/{agents-management-gLrRdc0M.js => agents-management-BH4GA4Vt.js} (97%) rename web/static/app/assets/{api-docs-BEMXmVy4.js => api-docs-BqzLMZ8q.js} (98%) rename web/static/app/assets/{asset-library-CwccI3Xb.js => asset-library-Btn_YOu0.js} (99%) rename web/static/app/assets/{asset-overview-xwryoaKx.js => asset-overview-ClxkP_Uu.js} (98%) rename web/static/app/assets/{c2-events-b_BWiEV4.js => c2-events-Cdd7cKs8.js} (95%) rename web/static/app/assets/{c2-listeners-CE3GvlqS.js => c2-listeners-7rFR5Rx6.js} (97%) rename web/static/app/assets/{c2-payloads-B8TBcwqZ.js => c2-payloads-DP3Iw5IZ.js} (97%) rename web/static/app/assets/{c2-profiles-DFa_6zU3.js => c2-profiles-Cxv9lUnu.js} (98%) rename web/static/app/assets/{c2-sessions-BFuBJt9m.js => c2-sessions-CnBIfRAo.js} (98%) rename web/static/app/assets/{c2-shared-Car3lDYq.js => c2-shared-2EAlkwn6.js} (94%) rename web/static/app/assets/{c2-shared-D-8kBzuC.js => c2-shared-BrRxH-6B.js} (96%) rename web/static/app/assets/{c2-tasks-DSV9J8Vu.js => c2-tasks-FVvnpyKj.js} (97%) delete mode 100644 web/static/app/assets/chat-B3amLD8_.js rename web/static/app/assets/{chat-files-D2U-2IVG.js => chat-files-BvkWbj5T.js} (99%) create mode 100644 web/static/app/assets/chat-iFaq7TmY.js rename web/static/app/assets/{dashboard-8XvRuqLB.js => dashboard-Dwi74cCO.js} (99%) rename web/static/app/assets/{deep-assessments-C1zSIX6t.js => deep-assessments-BwHg6NCr.js} (99%) rename web/static/app/assets/{hitl-CuqgPh-B.js => hitl-hVYHftcD.js} (99%) rename web/static/app/assets/{index-CAEPLS-g.js => index-DNMXun-U.js} (96%) rename web/static/app/assets/{info-collect-CnstRscn.js => info-collect-CIMK0OyE.js} (99%) rename web/static/app/assets/{knowledge-management-CQ0nnhXJ.js => knowledge-management-DxjSMTdf.js} (98%) rename web/static/app/assets/{knowledge-retrieval-logs-DY1jNxJ9.js => knowledge-retrieval-logs-CJolZ5T-.js} (96%) rename web/static/app/assets/{mcp-management-BebvY2ig.js => mcp-management-Be2zIK90.js} (99%) rename web/static/app/assets/{mcp-monitor-CfVvha6O.js => mcp-monitor-DHXOIA-R.js} (99%) rename web/static/app/assets/{platform-rbac-Bqf7ZmWP.js => platform-rbac-BDY_zjz7.js} (99%) rename web/static/app/assets/{plugin-hub-FbKl43dM.js => plugin-hub-BhSjc1VJ.js} (99%) rename web/static/app/assets/{project-form-Bm3Gi6Yc.js => project-form-B7wV5B1p.js} (94%) rename web/static/app/assets/{projects-CMt4u2Qr.js => projects-CfcDnjFh.js} (99%) rename web/static/app/assets/{roles-management-DGTD0STX.js => roles-management-DZI3VXhR.js} (99%) rename web/static/app/assets/{settings-yUhIZhl9.js => settings-CgtfKueL.js} (99%) rename web/static/app/assets/{skills-management-g8Njeibz.js => skills-management-CBXR8d2s.js} (97%) rename web/static/app/assets/{skills-monitor-BUTc0QtL.js => skills-monitor-Bs5yNZYW.js} (95%) rename web/static/app/assets/{tasks-CT27M-Wx.js => tasks-C9yzz-_n.js} (99%) rename web/static/app/assets/{tool-guard-gHtviV0M.js => tool-guard-DY35NYks.js} (99%) rename web/static/app/assets/{vulnerabilities-CXGKZewN.js => vulnerabilities-BRH58_rp.js} (99%) rename web/static/app/assets/{webshell-CXOTGht5.js => webshell-CE6Yp5FY.js} (99%) rename web/static/app/assets/{workflows-BnRbScwz.js => workflows-BgrBtPdj.js} (99%) diff --git a/.gitignore b/.gitignore index b7d3c996..3f6cda84 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ chat_uploads/ *.db-shm *.db-wal *.db-journal +*.instance.lock *.sqlite *.sqlite3 diff --git a/internal/app/app.go b/internal/app/app.go index 3fc911ca..206e17f4 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -79,6 +79,7 @@ type App struct { storageHandler *handler.StorageHandler // 运行空间占用统计与垃圾清理 auditSvc *audit.Service pluginHub *pluginhub.Manager + instanceUnlock func() } // New 创建新应用 @@ -104,16 +105,22 @@ func New(cfg *config.Config, log *logger.Logger, configPath, updateActivation st router.Use(corsMiddleware(cfg.Server.CORSAllowedOrigins)) router.Use(gzipMiddleware()) - // 初始化数据库 + // 初始化数据库前先申请排他实例锁,防止重复启动的新进程在端口绑定失败前提前执行 + // HITL / MCP / 深度测评的重启恢复逻辑,篡改正在运行实例的活跃任务状态。 dbPath := cfg.Database.Path if dbPath == "" { dbPath = "data/conversations.db" } - - // 确保目录存在 - if err := os.MkdirAll(filepath.Dir(dbPath), 0755); err != nil { - return nil, fmt.Errorf("创建数据库目录失败: %w", err) + instanceUnlock, err := lockDatabaseInstance(dbPath) + if err != nil { + return nil, err } + keepInstanceLock := false + defer func() { + if !keepInstanceLock { + instanceUnlock() + } + }() db, err := database.NewDB(dbPath, log.Logger) if err != nil { @@ -155,9 +162,6 @@ func New(cfg *config.Config, log *logger.Logger, configPath, updateActivation st monitorRetention.PurgeExpired() monitor.StartRetentionLoop(monitorRetention, log.Logger) - if err := handler.NewHITLManager(db, log.Logger).EnsureSchema(); err != nil { - log.Logger.Warn("初始化 HITL 表失败", zap.Error(err)) - } hitlRetention := hitl.NewService(db, cfg, log.Logger) hitlRetention.PurgeExpired() hitl.StartRetentionLoop(hitlRetention, log.Logger) @@ -559,6 +563,7 @@ func New(cfg *config.Config, log *logger.Logger, configPath, updateActivation st c2Handler: c2Handler, storageHandler: storageHandler, auditSvc: auditSvc, + instanceUnlock: instanceUnlock, } // 飞书/钉钉长连接(无需公网),启用时在后台启动;后续前端应用配置时会通过 RestartRobotConnections 重启 app.startRobotConnections() @@ -683,6 +688,7 @@ func New(cfg *config.Config, log *logger.Logger, configPath, updateActivation st ) agentHandler.StartDeepAssessmentRecovery() + keepInstanceLock = true return app, nil } @@ -911,6 +917,10 @@ func (a *App) shutdown() { a.logger.Logger.Warn("关闭主数据库连接失败", zap.Error(err)) } } + if a.instanceUnlock != nil { + a.instanceUnlock() + a.instanceUnlock = nil + } } // startRobotConnections 根据当前配置启动钉钉/飞书长连接(不先关闭已有连接,仅用于首次启动) diff --git a/internal/app/instance_lock.go b/internal/app/instance_lock.go new file mode 100644 index 00000000..01729c1b --- /dev/null +++ b/internal/app/instance_lock.go @@ -0,0 +1,38 @@ +package app + +import ( + "fmt" + "os" + "path/filepath" + "sync" +) + +// lockDatabaseInstance acquires a non-blocking OS kernel lock for dbPath before +// startup recovery mutates SQLite tables (such as hitl_interrupts, messages, +// mcp_executions, or deep_assessments). If a second server process is started +// accidentally while the primary server is still bound and running tasks, the +// second process fails fast without corrupting the live server's task state. +func lockDatabaseInstance(dbPath string) (func(), error) { + absPath, err := filepath.Abs(dbPath) + if err != nil { + return nil, err + } + if err := os.MkdirAll(filepath.Dir(absPath), 0755); err != nil { + return nil, fmt.Errorf("创建数据库目录失败: %w", err) + } + lockPath := absPath + ".instance.lock" + f, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0600) + if err != nil { + return nil, fmt.Errorf("打开实例锁文件失败 (%s): %w", lockPath, err) + } + if err := tryLockInstanceFile(f); err != nil { + _ = f.Close() + return nil, fmt.Errorf("另一个 CyberStrikeAI 服务实例正在运行并占用数据库 %s(请先停止旧进程,或在系统设置中使用一键更新)", dbPath) + } + var once sync.Once + return func() { + once.Do(func() { + _ = f.Close() + }) + }, nil +} diff --git a/internal/app/instance_lock_other.go b/internal/app/instance_lock_other.go new file mode 100644 index 00000000..db5e4f99 --- /dev/null +++ b/internal/app/instance_lock_other.go @@ -0,0 +1,9 @@ +//go:build !darwin && !linux && !freebsd && !openbsd && !netbsd && !dragonfly && !windows + +package app + +import "os" + +func tryLockInstanceFile(_ *os.File) error { + return nil +} diff --git a/internal/app/instance_lock_test.go b/internal/app/instance_lock_test.go new file mode 100644 index 00000000..f184ee6e --- /dev/null +++ b/internal/app/instance_lock_test.go @@ -0,0 +1,28 @@ +package app + +import ( + "path/filepath" + "strings" + "testing" +) + +func TestLockDatabaseInstanceRejectsConcurrentOwnerAndReacquiresAfterUnlock(t *testing.T) { + dbPath := filepath.Join(t.TempDir(), "data", "conversations.db") + + unlock, err := lockDatabaseInstance(dbPath) + if err != nil { + t.Fatalf("first lockDatabaseInstance failed: %v", err) + } + + if _, err := lockDatabaseInstance(dbPath); err == nil || !strings.Contains(err.Error(), "另一个 CyberStrikeAI 服务实例正在运行") { + t.Fatalf("expected concurrent lock to be rejected with clear message, got: %v", err) + } + + unlock() + + unlock2, err := lockDatabaseInstance(dbPath) + if err != nil { + t.Fatalf("reacquiring lock after unlock failed: %v", err) + } + unlock2() +} diff --git a/internal/app/instance_lock_unix.go b/internal/app/instance_lock_unix.go new file mode 100644 index 00000000..03c5274a --- /dev/null +++ b/internal/app/instance_lock_unix.go @@ -0,0 +1,13 @@ +//go:build darwin || linux || freebsd || openbsd || netbsd || dragonfly + +package app + +import ( + "os" + + "golang.org/x/sys/unix" +) + +func tryLockInstanceFile(f *os.File) error { + return unix.Flock(int(f.Fd()), unix.LOCK_EX|unix.LOCK_NB) +} diff --git a/internal/app/instance_lock_windows.go b/internal/app/instance_lock_windows.go new file mode 100644 index 00000000..f1db41d1 --- /dev/null +++ b/internal/app/instance_lock_windows.go @@ -0,0 +1,13 @@ +//go:build windows + +package app + +import ( + "os" + + "golang.org/x/sys/windows" +) + +func tryLockInstanceFile(f *os.File) error { + return windows.LockFileEx(windows.Handle(f.Fd()), windows.LOCKFILE_EXCLUSIVE_LOCK|windows.LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, &windows.Overlapped{}) +} diff --git a/internal/handler/hitl.go b/internal/handler/hitl.go index 4b6f5ab2..1d442ed6 100644 --- a/internal/handler/hitl.go +++ b/internal/handler/hitl.go @@ -570,8 +570,13 @@ func (m *HITLManager) waitDecision(ctx context.Context, p *pendingInterrupt, tim defer timer.Stop() timeoutCh = timer.C } - select { - case d := <-p.decideCh: + var dbPollCh <-chan time.Time + if m.db != nil && p.InterruptID != "" { + dbPoll := time.NewTicker(2 * time.Second) + defer dbPoll.Stop() + dbPollCh = dbPoll.C + } + applyDecision := func(d hitlDecision) (hitlDecision, error) { // 只有 review_edit 模式允许改参;其他模式一律忽略 edited arguments if p.Mode != "review_edit" && len(d.EditedArguments) > 0 { d.EditedArguments = nil @@ -579,15 +584,51 @@ func (m *HITLManager) waitDecision(ctx context.Context, p *pendingInterrupt, tim _, _ = m.db.Exec(`UPDATE hitl_interrupts SET status='decided', decision=?, decision_comment=?, decided_at=?, decided_by='human' WHERE id=?`, d.Decision, d.Comment, time.Now(), p.InterruptID) return d, nil - case <-timeoutCh: - comment := "HITL timeout auto-reject for safety" - _, _ = m.db.Exec(`UPDATE hitl_interrupts SET status='timeout', decision='reject', decision_comment=?, decided_at=?, decided_by='system' WHERE id=?`, - comment, time.Now(), p.InterruptID) - return hitlDecision{Decision: "reject", Comment: comment}, nil - case <-ctx.Done(): - _, _ = m.db.Exec(`UPDATE hitl_interrupts SET status='cancelled', decision='reject', decision_comment='task cancelled', decided_at=?, decided_by='system' WHERE id=?`, - time.Now(), p.InterruptID) - return hitlDecision{Decision: "reject", Comment: "task cancelled"}, ctx.Err() + } + for { + select { + case d := <-p.decideCh: + return applyDecision(d) + case <-dbPollCh: + select { + case d := <-p.decideCh: + return applyDecision(d) + default: + } + var status, decision, comment string + err := m.db.QueryRow(`SELECT status, COALESCE(decision,''), COALESCE(decision_comment,'') FROM hitl_interrupts WHERE id=?`, p.InterruptID). + Scan(&status, &decision, &comment) + if errors.Is(err, sql.ErrNoRows) { + return hitlDecision{Decision: "reject", Comment: "interrupt removed"}, context.Canceled + } + status = strings.ToLower(strings.TrimSpace(status)) + if err != nil || status == "pending" { + continue + } + switch status { + case "decided": + if strings.EqualFold(strings.TrimSpace(decision), "approve") { + return hitlDecision{Decision: "approve", Comment: comment}, nil + } + return hitlDecision{Decision: "reject", Comment: comment}, nil + case "timeout": + return hitlDecision{Decision: "reject", Comment: comment}, nil + default: + if strings.EqualFold(strings.TrimSpace(comment), "dismissed by user") { + return hitlDecision{Decision: "reject", Comment: comment}, nil + } + return hitlDecision{Decision: "reject", Comment: comment}, context.Canceled + } + case <-timeoutCh: + comment := "HITL timeout auto-reject for safety" + _, _ = m.db.Exec(`UPDATE hitl_interrupts SET status='timeout', decision='reject', decision_comment=?, decided_at=?, decided_by='system' WHERE id=?`, + comment, time.Now(), p.InterruptID) + return hitlDecision{Decision: "reject", Comment: comment}, nil + case <-ctx.Done(): + _, _ = m.db.Exec(`UPDATE hitl_interrupts SET status='cancelled', decision='reject', decision_comment='task cancelled', decided_at=?, decided_by='system' WHERE id=?`, + time.Now(), p.InterruptID) + return hitlDecision{Decision: "reject", Comment: "task cancelled"}, ctx.Err() + } } } diff --git a/internal/handler/hitl_restart_test.go b/internal/handler/hitl_restart_test.go index 00df54ee..66851dc6 100644 --- a/internal/handler/hitl_restart_test.go +++ b/internal/handler/hitl_restart_test.go @@ -1,10 +1,13 @@ package handler import ( + "context" "database/sql" + "errors" "path/filepath" "strings" "testing" + "time" "cyberstrike-ai/internal/database" @@ -249,3 +252,29 @@ func TestAuditAgentInterruptIsNotHumanPendingWork(t *testing.T) { t.Fatalf("unexpected human pending result: %#v", items) } } + +func TestWaitDecisionExitsWhenInterruptCancelledInDB(t *testing.T) { + db, err := database.NewDB(filepath.Join(t.TempDir(), "hitl-wait-cancel.db"), zap.NewNop()) + if err != nil { + t.Fatalf("open db: %v", err) + } + defer func() { _ = db.Close() }() + manager := NewHITLManager(db, zap.NewNop()) + if err := manager.EnsureSchema(); err != nil { + t.Fatalf("ensure schema: %v", err) + } + p, err := manager.CreatePendingInterrupt("conv-1", "msg-1", "approval", "exec", "call-1", `{}`, "human") + if err != nil { + t.Fatalf("create interrupt: %v", err) + } + if _, err := db.Exec(`UPDATE hitl_interrupts SET status='cancelled', decision='reject', decision_comment='process restarted' WHERE id=?`, p.InterruptID); err != nil { + t.Fatalf("cancel interrupt in db: %v", err) + } + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + _, waitErr := manager.waitDecision(ctx, p, 10*time.Minute) + if !errors.Is(waitErr, context.Canceled) { + t.Fatalf("expected waitDecision to return context.Canceled on external DB cancellation, got %v", waitErr) + } +} diff --git a/web/frontend/src/pages/chat/index.jsx b/web/frontend/src/pages/chat/index.jsx index 98dfa49c..b72ba018 100644 --- a/web/frontend/src/pages/chat/index.jsx +++ b/web/frontend/src/pages/chat/index.jsx @@ -376,9 +376,11 @@ export default function Page() { if (lastActive.current === conversationId && !backgroundRunning) { loadDetail(conversationId, { silent: true, force: true }); reloadConversations.current?.({ silent: true }); + refreshHitl(); + refreshPlan(); } lastActive.current = backgroundRunning ? conversationId : null; - }, [backgroundRunning, conversationId, loadDetail]); + }, [backgroundRunning, conversationId, loadDetail, refreshHitl, refreshPlan]); const stopTask = useCallback(async (targetId = '') => { if (!canStop) return; @@ -395,9 +397,13 @@ export default function Page() { await run.stop(requested); await reloadActiveTasks.current?.({ silent: true, force: true }); reloadConversations.current?.({ silent: true }); + refreshHitl(); + refreshPlan(); setTimeout(() => { reloadActiveTasks.current?.({ silent: true, force: true }); reloadConversations.current?.({ silent: true }); + refreshHitl(); + refreshPlan(); }, 950); } finally { if (effectiveId) { @@ -409,7 +415,7 @@ export default function Page() { }); } } - }, [canStop, live?.conversationId, run]); + }, [canStop, live?.conversationId, refreshHitl, refreshPlan, run]); const selectConversation = useCallback(id => { if (!id) return; diff --git a/web/static/app/assets/AssetEditorModal-HZN0Ndjf.js b/web/static/app/assets/AssetEditorModal-C2UJzIaS.js similarity index 98% rename from web/static/app/assets/AssetEditorModal-HZN0Ndjf.js rename to web/static/app/assets/AssetEditorModal-C2UJzIaS.js index ab5d025a..d919f451 100644 --- a/web/static/app/assets/AssetEditorModal-HZN0Ndjf.js +++ b/web/static/app/assets/AssetEditorModal-C2UJzIaS.js @@ -1,3 +1,3 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,I as i,R as a,i as o}from"./semi-65W_4I1v.js";import{F as s,L as c,S as l,c as u,x as d,z as f}from"./index-CAEPLS-g.js";import{t as p}from"./project-options-CMQbwv_U.js";import{E as m,a as h,c as g,h as _,i as v,o as y,p as b,s as x,u as S}from"./assetTarget-D2PEjBAg.js";var C=e(t(),1),w=e(n(),1),T=`asset-library-editor`;function E(e,t){return{target:S(e),host:e?.host||``,ip:e?.ip||``,domain:e?.domain||``,port:e?.port??void 0,protocol:e?.protocol||``,title:e?.title||``,server:e?.server||``,project_id:e?e.project_id||``:t,status:e?.status||`active`,environment:e?.environment||``,criticality:e?.criticality||``,country:e?.country||``,province:e?.province||``,city:e?.city||``,responsible_person:e?.responsible_person||``,department:e?.department||``,business_system:e?.business_system||``,tags:Array.isArray(e?.tags)?e.tags:[]}}function D({visible:e,asset:t,defaultProjectId:n=``,fixedProject:D=!1,projects:O,onClose:k,onSaved:A}){let j=s(),[M,N]=(0,C.useState)(null),[P,F]=(0,C.useState)(!1),[I,L]=(0,C.useState)(``),R=(0,C.useRef)(S(t)),z=(0,C.useMemo)(()=>E(t,n),[t,n,e]),B=!!t?.id;(0,C.useEffect)(()=>{e&&(R.current=S(t),L(``),F(!1))},[e,t]);let V=(0,C.useMemo)(()=>p(O,j,{currentId:z.project_id}),[O,j,z.project_id]),H=e=>{if(!M)return null;let t=String(M.getValue(`target`)||``).trim();try{let e=x(t);return M.setValues({host:e.host,ip:e.ip,domain:e.domain,port:e.port||void 0,protocol:e.protocol}),R.current=t,e}catch(t){return e&&L(t.message),null}},U=()=>{let e=M.getValue(),n=String(e.target||``).trim(),r={host:String(e.host||``).trim(),ip:String(e.ip||``).trim().toLowerCase(),domain:String(e.domain||``).trim(),port:Number(e.port||0),protocol:String(e.protocol||``).trim().toLowerCase(),title:String(e.title||``).trim(),server:String(e.server||``).trim(),status:e.status||`active`,source:t?.source||`manual`,source_query:t?.source_query||``,country:String(e.country||``).trim(),province:String(e.province||``).trim(),city:String(e.city||``).trim(),responsible_person:String(e.responsible_person||``).trim(),department:String(e.department||``).trim(),business_system:String(e.business_system||``).trim(),environment:e.environment||``,criticality:e.criticality||``,project_id:e.project_id||``,tags:Array.isArray(e.tags)?e.tags.map(e=>String(e).trim()).filter(Boolean):[]};if(n&&n!==R.current)try{let e=x(n);r={...r,host:r.host||e.host,ip:e.ip||r.ip,domain:e.domain||r.domain,port:e.port||r.port,protocol:e.protocol||r.protocol}}catch(e){throw Error(e.message)}return r},W=()=>{let e=g(M.getValue(`targets`));if(!e.length)throw Error(j(`assets.targetRequired`,null,`请输入资产地址`));if(e.length>200)throw Error(`一次最多添加 200 个地址`);let t=D?n:M.getValue(`project_id`)||``;return e.map(e=>{let n=x(e);return{host:n.host||n.domain||n.ip,ip:n.ip,domain:n.domain,port:n.port,protocol:n.protocol,status:`active`,source:`manual`,project_id:t,tags:[]}})},G=async()=>{if(P||!M)return;L(``);try{await M.validate()}catch{return}let e,n;try{B?e=U():n=W()}catch(e){L(e.message);return}F(!0);try{if(B)await c.put(`/assets/${encodeURIComponent(t.id)}`,e),d(j(`assets.updatedSuccessfully`,null,`资产已更新`));else{let e=await c.post(`/assets/import`,{assets:n,source:`manual`}),t=Number(e?.created||0),r=Number(e?.updated||0),i=Number(e?.skipped||0),a=Number(e?.project_conflicts||0),o=a?j(`assets.importProjectConflicts`,{count:a},`已跳过 ${a} 条归属不同的重复资产。`):``;if(!t&&!r&&i)throw Error(o||j(`assets.assetSkipped`,null,`资产未保存,可能已存在且你没有更新权限`));let s=[];t&&s.push(`新增 ${t}`),r&&s.push(`合并 ${r}`),i&&s.push(`跳过 ${i}`),d(s.length?`已写入资产库:${s.join(`,`)}`:j(`assets.createdSuccessfully`,null,`资产已添加`)),o&&l(o)}A?.(),k?.()}catch(e){L(f(e,j(`assets.saveFailed`,null,`保存资产失败`)))}finally{F(!1)}};return(0,w.jsxs)(u,{visible:e,title:B?j(`assets.editAssetTitle`,null,`编辑资产`):j(`assets.addAssetTitle`,null,`新增资产`),width:B?760:520,onCancel:k,onOk:G,okText:B?j(`common.save`,null,`保存`):j(`assets.addAssetAction`,null,`添加资产`),confirmLoading:P,closeOnEsc:!0,children:[I&&(0,w.jsx)(r,{type:`danger`,bordered:!0,closeIcon:null,description:I,className:`asset-library-form-error`}),(0,w.jsx)(o,{className:T,initValues:z,getFormApi:N,labelPosition:`top`,onSubmit:G,children:B?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`asset-library-form-grid asset-library-form-grid--full`,children:(0,w.jsx)(o.Input,{field:`target`,label:j(`assets.assetAddress`,null,`资产地址`),placeholder:`https://example.com:443 / example.com / 1.1.1.1:22`,helpText:j(`assets.assetAddressHint`,null,`可识别的 URL、域名、IP 和端口会自动解析`),onBlur:()=>H(!0),rules:[{required:!0,message:j(`assets.targetRequired`,null,`请输入资产地址`)},{validator:(e,t,n)=>{try{x(t),n()}catch(e){n(Error(e.message))}}}]})}),(0,w.jsxs)(`div`,{className:`asset-library-form-grid`,children:[(0,w.jsx)(o.Input,{field:`host`,label:j(`assets.hostUrl`,null,`完整 URL / Host`)}),(0,w.jsx)(o.Input,{field:`ip`,label:`IP`,rules:[{validator:(e,t,n)=>{!t||v(t)||h(t)?n():n(Error(j(`assets.ipInvalid`,null,`IP 地址格式无效`)))}}]}),(0,w.jsx)(o.Input,{field:`domain`,label:j(`assets.domain`,null,`域名`),rules:[{validator:(e,t,n)=>{!t||y(t)&&!v(t)&&!h(t)?n():n(Error(j(`assets.domainInvalid`,null,`域名格式无效`)))}}]}),(0,w.jsx)(o.InputNumber,{field:`port`,label:j(`assets.port`,null,`端口`),min:0,max:65535,style:{width:`100%`}}),(0,w.jsx)(o.Input,{field:`protocol`,label:j(`assets.protocol`,null,`协议`),rules:[{validator:(e,t,n)=>{!t||/^[a-z][a-z0-9+.-]{0,31}$/.test(String(t).toLowerCase())?n():n(Error(j(`assets.protocolInvalid`,null,`协议格式无效`)))}}]}),(0,w.jsx)(o.Input,{field:`title`,label:j(`assets.pageTitle`,null,`页面标题`)}),(0,w.jsx)(o.Input,{field:`server`,label:j(`assets.serverProduct`,null,`服务 / 产品`)}),(0,w.jsx)(o.Select,{field:`project_id`,label:j(`assets.project`,null,`所属项目`),optionList:V,filter:!0,showClear:!0,placeholder:j(`assets.unboundProject`,null,`暂不绑定`)}),(0,w.jsx)(o.Select,{field:`status`,label:j(`assets.status`,null,`状态`),optionList:m}),(0,w.jsx)(o.Select,{field:`environment`,label:j(`assets.environment`,null,`环境`),optionList:_,showClear:!0,placeholder:`—`}),(0,w.jsx)(o.Select,{field:`criticality`,label:j(`assets.criticality`,null,`重要性`),optionList:b,showClear:!0,placeholder:`—`}),(0,w.jsx)(o.Input,{field:`country`,label:j(`assets.country`,null,`国家/地区`)}),(0,w.jsx)(o.Input,{field:`province`,label:j(`assets.province`,null,`省份/州`)}),(0,w.jsx)(o.Input,{field:`city`,label:j(`assets.city`,null,`城市`)}),(0,w.jsx)(o.Input,{field:`responsible_person`,label:j(`assets.responsiblePerson`,null,`负责人`)}),(0,w.jsx)(o.Input,{field:`department`,label:j(`assets.department`,null,`部门`)}),(0,w.jsx)(o.Input,{field:`business_system`,label:j(`assets.businessSystem`,null,`业务系统`)})]}),(0,w.jsx)(o.TagInput,{field:`tags`,label:j(`assets.tagsLabel`,null,`标签`),placeholder:j(`assets.tagsPlaceholder`,null,`输入后按回车或逗号`),max:30,maxLength:64,addOnBlur:!0,separator:`,,`,style:{width:`100%`}}),(0,w.jsx)(i,{className:`asset-library-editor-actions`,children:(0,w.jsx)(a,{theme:`borderless`,onClick:()=>H(!0),children:j(`assets.parseTarget`,null,`解析资产地址`)})})]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(o.TextArea,{field:`targets`,label:j(`assets.assetAddress`,null,`资产地址`),rows:8,placeholder:`https://example.com/login +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,I as i,R as a,i as o}from"./semi-65W_4I1v.js";import{F as s,L as c,S as l,c as u,x as d,z as f}from"./index-DNMXun-U.js";import{t as p}from"./project-options-CMQbwv_U.js";import{E as m,a as h,c as g,h as _,i as v,o as y,p as b,s as x,u as S}from"./assetTarget-D2PEjBAg.js";var C=e(t(),1),w=e(n(),1),T=`asset-library-editor`;function E(e,t){return{target:S(e),host:e?.host||``,ip:e?.ip||``,domain:e?.domain||``,port:e?.port??void 0,protocol:e?.protocol||``,title:e?.title||``,server:e?.server||``,project_id:e?e.project_id||``:t,status:e?.status||`active`,environment:e?.environment||``,criticality:e?.criticality||``,country:e?.country||``,province:e?.province||``,city:e?.city||``,responsible_person:e?.responsible_person||``,department:e?.department||``,business_system:e?.business_system||``,tags:Array.isArray(e?.tags)?e.tags:[]}}function D({visible:e,asset:t,defaultProjectId:n=``,fixedProject:D=!1,projects:O,onClose:k,onSaved:A}){let j=s(),[M,N]=(0,C.useState)(null),[P,F]=(0,C.useState)(!1),[I,L]=(0,C.useState)(``),R=(0,C.useRef)(S(t)),z=(0,C.useMemo)(()=>E(t,n),[t,n,e]),B=!!t?.id;(0,C.useEffect)(()=>{e&&(R.current=S(t),L(``),F(!1))},[e,t]);let V=(0,C.useMemo)(()=>p(O,j,{currentId:z.project_id}),[O,j,z.project_id]),H=e=>{if(!M)return null;let t=String(M.getValue(`target`)||``).trim();try{let e=x(t);return M.setValues({host:e.host,ip:e.ip,domain:e.domain,port:e.port||void 0,protocol:e.protocol}),R.current=t,e}catch(t){return e&&L(t.message),null}},U=()=>{let e=M.getValue(),n=String(e.target||``).trim(),r={host:String(e.host||``).trim(),ip:String(e.ip||``).trim().toLowerCase(),domain:String(e.domain||``).trim(),port:Number(e.port||0),protocol:String(e.protocol||``).trim().toLowerCase(),title:String(e.title||``).trim(),server:String(e.server||``).trim(),status:e.status||`active`,source:t?.source||`manual`,source_query:t?.source_query||``,country:String(e.country||``).trim(),province:String(e.province||``).trim(),city:String(e.city||``).trim(),responsible_person:String(e.responsible_person||``).trim(),department:String(e.department||``).trim(),business_system:String(e.business_system||``).trim(),environment:e.environment||``,criticality:e.criticality||``,project_id:e.project_id||``,tags:Array.isArray(e.tags)?e.tags.map(e=>String(e).trim()).filter(Boolean):[]};if(n&&n!==R.current)try{let e=x(n);r={...r,host:r.host||e.host,ip:e.ip||r.ip,domain:e.domain||r.domain,port:e.port||r.port,protocol:e.protocol||r.protocol}}catch(e){throw Error(e.message)}return r},W=()=>{let e=g(M.getValue(`targets`));if(!e.length)throw Error(j(`assets.targetRequired`,null,`请输入资产地址`));if(e.length>200)throw Error(`一次最多添加 200 个地址`);let t=D?n:M.getValue(`project_id`)||``;return e.map(e=>{let n=x(e);return{host:n.host||n.domain||n.ip,ip:n.ip,domain:n.domain,port:n.port,protocol:n.protocol,status:`active`,source:`manual`,project_id:t,tags:[]}})},G=async()=>{if(P||!M)return;L(``);try{await M.validate()}catch{return}let e,n;try{B?e=U():n=W()}catch(e){L(e.message);return}F(!0);try{if(B)await c.put(`/assets/${encodeURIComponent(t.id)}`,e),d(j(`assets.updatedSuccessfully`,null,`资产已更新`));else{let e=await c.post(`/assets/import`,{assets:n,source:`manual`}),t=Number(e?.created||0),r=Number(e?.updated||0),i=Number(e?.skipped||0),a=Number(e?.project_conflicts||0),o=a?j(`assets.importProjectConflicts`,{count:a},`已跳过 ${a} 条归属不同的重复资产。`):``;if(!t&&!r&&i)throw Error(o||j(`assets.assetSkipped`,null,`资产未保存,可能已存在且你没有更新权限`));let s=[];t&&s.push(`新增 ${t}`),r&&s.push(`合并 ${r}`),i&&s.push(`跳过 ${i}`),d(s.length?`已写入资产库:${s.join(`,`)}`:j(`assets.createdSuccessfully`,null,`资产已添加`)),o&&l(o)}A?.(),k?.()}catch(e){L(f(e,j(`assets.saveFailed`,null,`保存资产失败`)))}finally{F(!1)}};return(0,w.jsxs)(u,{visible:e,title:B?j(`assets.editAssetTitle`,null,`编辑资产`):j(`assets.addAssetTitle`,null,`新增资产`),width:B?760:520,onCancel:k,onOk:G,okText:B?j(`common.save`,null,`保存`):j(`assets.addAssetAction`,null,`添加资产`),confirmLoading:P,closeOnEsc:!0,children:[I&&(0,w.jsx)(r,{type:`danger`,bordered:!0,closeIcon:null,description:I,className:`asset-library-form-error`}),(0,w.jsx)(o,{className:T,initValues:z,getFormApi:N,labelPosition:`top`,onSubmit:G,children:B?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`asset-library-form-grid asset-library-form-grid--full`,children:(0,w.jsx)(o.Input,{field:`target`,label:j(`assets.assetAddress`,null,`资产地址`),placeholder:`https://example.com:443 / example.com / 1.1.1.1:22`,helpText:j(`assets.assetAddressHint`,null,`可识别的 URL、域名、IP 和端口会自动解析`),onBlur:()=>H(!0),rules:[{required:!0,message:j(`assets.targetRequired`,null,`请输入资产地址`)},{validator:(e,t,n)=>{try{x(t),n()}catch(e){n(Error(e.message))}}}]})}),(0,w.jsxs)(`div`,{className:`asset-library-form-grid`,children:[(0,w.jsx)(o.Input,{field:`host`,label:j(`assets.hostUrl`,null,`完整 URL / Host`)}),(0,w.jsx)(o.Input,{field:`ip`,label:`IP`,rules:[{validator:(e,t,n)=>{!t||v(t)||h(t)?n():n(Error(j(`assets.ipInvalid`,null,`IP 地址格式无效`)))}}]}),(0,w.jsx)(o.Input,{field:`domain`,label:j(`assets.domain`,null,`域名`),rules:[{validator:(e,t,n)=>{!t||y(t)&&!v(t)&&!h(t)?n():n(Error(j(`assets.domainInvalid`,null,`域名格式无效`)))}}]}),(0,w.jsx)(o.InputNumber,{field:`port`,label:j(`assets.port`,null,`端口`),min:0,max:65535,style:{width:`100%`}}),(0,w.jsx)(o.Input,{field:`protocol`,label:j(`assets.protocol`,null,`协议`),rules:[{validator:(e,t,n)=>{!t||/^[a-z][a-z0-9+.-]{0,31}$/.test(String(t).toLowerCase())?n():n(Error(j(`assets.protocolInvalid`,null,`协议格式无效`)))}}]}),(0,w.jsx)(o.Input,{field:`title`,label:j(`assets.pageTitle`,null,`页面标题`)}),(0,w.jsx)(o.Input,{field:`server`,label:j(`assets.serverProduct`,null,`服务 / 产品`)}),(0,w.jsx)(o.Select,{field:`project_id`,label:j(`assets.project`,null,`所属项目`),optionList:V,filter:!0,showClear:!0,placeholder:j(`assets.unboundProject`,null,`暂不绑定`)}),(0,w.jsx)(o.Select,{field:`status`,label:j(`assets.status`,null,`状态`),optionList:m}),(0,w.jsx)(o.Select,{field:`environment`,label:j(`assets.environment`,null,`环境`),optionList:_,showClear:!0,placeholder:`—`}),(0,w.jsx)(o.Select,{field:`criticality`,label:j(`assets.criticality`,null,`重要性`),optionList:b,showClear:!0,placeholder:`—`}),(0,w.jsx)(o.Input,{field:`country`,label:j(`assets.country`,null,`国家/地区`)}),(0,w.jsx)(o.Input,{field:`province`,label:j(`assets.province`,null,`省份/州`)}),(0,w.jsx)(o.Input,{field:`city`,label:j(`assets.city`,null,`城市`)}),(0,w.jsx)(o.Input,{field:`responsible_person`,label:j(`assets.responsiblePerson`,null,`负责人`)}),(0,w.jsx)(o.Input,{field:`department`,label:j(`assets.department`,null,`部门`)}),(0,w.jsx)(o.Input,{field:`business_system`,label:j(`assets.businessSystem`,null,`业务系统`)})]}),(0,w.jsx)(o.TagInput,{field:`tags`,label:j(`assets.tagsLabel`,null,`标签`),placeholder:j(`assets.tagsPlaceholder`,null,`输入后按回车或逗号`),max:30,maxLength:64,addOnBlur:!0,separator:`,,`,style:{width:`100%`}}),(0,w.jsx)(i,{className:`asset-library-editor-actions`,children:(0,w.jsx)(a,{theme:`borderless`,onClick:()=>H(!0),children:j(`assets.parseTarget`,null,`解析资产地址`)})})]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(o.TextArea,{field:`targets`,label:j(`assets.assetAddress`,null,`资产地址`),rows:8,placeholder:`https://example.com/login example.com:443 1.1.1.1:22`,helpText:`每行一个,或用空格、逗号隔开。直接粘贴 URL、域名或 IP:端口。`,rules:[{required:!0,validator:(e,t,n)=>{let r=g(t);if(!r.length)n(Error(j(`assets.targetRequired`,null,`请输入资产地址`)));else{for(let e of r)try{x(e)}catch(t){n(Error(`${e}:${t.message}`));return}n()}}}]}),(0,w.jsx)(o.Select,{field:`project_id`,label:j(`assets.project`,null,`所属项目`),optionList:V,disabled:D,filter:!0,showClear:!D,placeholder:j(`assets.unboundProject`,null,`暂不绑定`),style:{width:`100%`}})]})},`${t?.id||`new-asset`}-${e?`open`:`closed`}`)]})}export{D as t}; \ No newline at end of file diff --git a/web/static/app/assets/agents-management-gLrRdc0M.js b/web/static/app/assets/agents-management-BH4GA4Vt.js similarity index 97% rename from web/static/app/assets/agents-management-gLrRdc0M.js rename to web/static/app/assets/agents-management-BH4GA4Vt.js index c6122c3e..21b440fb 100644 --- a/web/static/app/assets/agents-management-gLrRdc0M.js +++ b/web/static/app/assets/agents-management-BH4GA4Vt.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,Lt as a,N as o,Pt as s,R as c,U as l,ft as u,i as d,lt as f,ut as p}from"./semi-65W_4I1v.js";import{F as m,I as h,L as g,a as _,b as v,c as y,d as b,f as x,l as S,m as C,p as w,s as T,u as E,x as D,y as O}from"./index-CAEPLS-g.js";var k=e(t(),1),A=e(n(),1),{Text:j}=r;function M(){let e=m(),{hasPermission:t}=h(),n=t(`agents:write`),r=t(`agents:delete`),[M,N]=(0,k.useState)(``),[P,F]=(0,k.useState)(null),[I,L]=(0,k.useState)(null),[R,z]=(0,k.useState)(!1),B=_(()=>g.get(`/multi-agent/markdown-agents`),[]),V=(Array.isArray(B.data?.agents)?B.data.agents:[]).filter(e=>{if(!M)return!0;let t=M.toLowerCase();return[e.name,e.id,e.filename,e.description].some(e=>String(e||``).toLowerCase().includes(t))}),H=async e=>{try{F(await g.get(`/multi-agent/markdown-agents/${encodeURIComponent(e.filename)}`))}catch(e){v(e,`读取智能体失败`)}},U=async()=>{let e=await I.form.validate();z(!0);try{await g.post(`/multi-agent/markdown-agents`,{filename:e.filename?.trim()||``,name:e.name.trim(),description:e.description?.trim()||``,instruction:e.instruction,kind:e.kind||`sub`,tools:String(e.tools||``).split(`,`).map(e=>e.trim()).filter(Boolean)}),D(`智能体已保存`),L(null),B.reload()}catch(e){v(e,`保存智能体失败`)}finally{z(!1)}},W=e=>O({title:`删除智能体「${e.name||e.filename}」?`,onOk:async()=>{await g.del(`/multi-agent/markdown-agents/${encodeURIComponent(e.filename)}`),D(`已删除`),B.reload()}});return(0,A.jsxs)(`div`,{children:[(0,A.jsx)(w,{title:e(`agents.title`,null,`智能体管理`),description:B.data?.dir?`目录:${B.data.dir}`:`以 Markdown 文件定义的子智能体与编排器。`,extra:(0,A.jsxs)(i,{children:[(0,A.jsx)(c,{icon:(0,A.jsx)(p,{}),onClick:()=>B.reload(),loading:B.loading,children:`刷新`}),n&&(0,A.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,A.jsx)(u,{}),onClick:()=>L({record:null,form:{}}),children:`新建智能体`})]})}),B.data?.error&&(0,A.jsx)(S,{error:B.data.error}),(0,A.jsxs)(C,{title:`智能体(${V.length})`,children:[(0,A.jsx)(S,{error:B.error,onRetry:()=>B.reload()}),(0,A.jsx)(T,{columns:[{title:`智能体`,dataIndex:`name`,render:(e,t)=>(0,A.jsxs)(i,{vertical:!0,spacing:0,align:`start`,children:[(0,A.jsxs)(i,{children:[(0,A.jsx)(j,{strong:!0,children:e||t.id}),t.is_orchestrator&&(0,A.jsx)(o,{size:`small`,color:`purple`,children:`编排器`})]}),(0,A.jsx)(j,{type:`tertiary`,children:t.filename})]})},{title:`类型`,dataIndex:`kind`,width:110,render:e=>(0,A.jsx)(o,{size:`small`,children:e||`sub`})},{title:`描述`,dataIndex:`description`,render:e=>(0,A.jsx)(j,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:460},children:e||`—`})},{title:`操作`,width:180,render:(e,t)=>(0,A.jsxs)(i,{children:[(0,A.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>H(t),children:`详情`}),n&&(0,A.jsx)(c,{size:`small`,theme:`borderless`,icon:(0,A.jsx)(s,{}),onClick:()=>L({record:t,form:{}})}),r&&(0,A.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,A.jsx)(a,{}),onClick:()=>W(t)})]})}],dataSource:V,rowKey:`filename`,loading:B.loading,pagination:{pageSize:20},toolbar:(0,A.jsx)(l,{prefix:(0,A.jsx)(f,{}),value:M,onChange:N,placeholder:`搜索名称或文件名`,style:{width:280}})})]}),(0,A.jsx)(y,{title:I?.record?`编辑智能体`:`新建智能体`,visible:!!I,onCancel:()=>L(null),onOk:U,confirmLoading:R,width:760,children:(0,A.jsxs)(d,{getFormApi:e=>L(t=>t&&{...t,form:e}),initValues:I?.record?{filename:I.record.filename,name:I.record.name,description:I.record.description,kind:I.record.kind||`sub`}:{kind:`sub`},children:[(0,A.jsx)(d.Input,{field:`filename`,label:`文件名(留空自动生成)`,placeholder:`例如 recon.md`}),(0,A.jsx)(d.Input,{field:`name`,label:`名称`,rules:[{required:!0,message:`请输入名称`}]}),(0,A.jsx)(d.Input,{field:`description`,label:`描述`}),(0,A.jsx)(d.Select,{field:`kind`,label:`类型`,optionList:[{value:`sub`,label:`子智能体`},{value:`orchestrator`,label:`编排器`},{value:`plan_execute`,label:`计划执行`}]}),(0,A.jsx)(d.Input,{field:`tools`,label:`工具(逗号分隔)`,placeholder:`toolName, mcp::tool`}),(0,A.jsx)(d.TextArea,{field:`instruction`,label:`指令(Markdown)`,autosize:{minRows:8,maxRows:20}})]})},I?.record?.filename||`new-agent`),(0,A.jsx)(y,{title:P?.name||`智能体详情`,visible:!!P,onCancel:()=>F(null),width:720,children:P&&(0,A.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,A.jsx)(b,{items:[{label:`文件名`,value:P.filename},{label:`ID`,value:P.id},{label:`类型`,value:P.kind},{label:`绑定角色`,value:P.bind_role||`—`},{label:`最大迭代`,value:P.max_iterations??`—`},{label:`工具`,value:Array.isArray(P.tools)&&P.tools.length?P.tools.join(`、`):`—`}]}),(0,A.jsx)(x,{content:P.instruction||P.raw||``}),(0,A.jsx)(E,{value:P.raw||P,title:`原始 Markdown`,collapsed:!0})]})})]})}export{M as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,Lt as a,N as o,Pt as s,R as c,U as l,ft as u,i as d,lt as f,ut as p}from"./semi-65W_4I1v.js";import{F as m,I as h,L as g,a as _,b as v,c as y,d as b,f as x,l as S,m as C,p as w,s as T,u as E,x as D,y as O}from"./index-DNMXun-U.js";var k=e(t(),1),A=e(n(),1),{Text:j}=r;function M(){let e=m(),{hasPermission:t}=h(),n=t(`agents:write`),r=t(`agents:delete`),[M,N]=(0,k.useState)(``),[P,F]=(0,k.useState)(null),[I,L]=(0,k.useState)(null),[R,z]=(0,k.useState)(!1),B=_(()=>g.get(`/multi-agent/markdown-agents`),[]),V=(Array.isArray(B.data?.agents)?B.data.agents:[]).filter(e=>{if(!M)return!0;let t=M.toLowerCase();return[e.name,e.id,e.filename,e.description].some(e=>String(e||``).toLowerCase().includes(t))}),H=async e=>{try{F(await g.get(`/multi-agent/markdown-agents/${encodeURIComponent(e.filename)}`))}catch(e){v(e,`读取智能体失败`)}},U=async()=>{let e=await I.form.validate();z(!0);try{await g.post(`/multi-agent/markdown-agents`,{filename:e.filename?.trim()||``,name:e.name.trim(),description:e.description?.trim()||``,instruction:e.instruction,kind:e.kind||`sub`,tools:String(e.tools||``).split(`,`).map(e=>e.trim()).filter(Boolean)}),D(`智能体已保存`),L(null),B.reload()}catch(e){v(e,`保存智能体失败`)}finally{z(!1)}},W=e=>O({title:`删除智能体「${e.name||e.filename}」?`,onOk:async()=>{await g.del(`/multi-agent/markdown-agents/${encodeURIComponent(e.filename)}`),D(`已删除`),B.reload()}});return(0,A.jsxs)(`div`,{children:[(0,A.jsx)(w,{title:e(`agents.title`,null,`智能体管理`),description:B.data?.dir?`目录:${B.data.dir}`:`以 Markdown 文件定义的子智能体与编排器。`,extra:(0,A.jsxs)(i,{children:[(0,A.jsx)(c,{icon:(0,A.jsx)(p,{}),onClick:()=>B.reload(),loading:B.loading,children:`刷新`}),n&&(0,A.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,A.jsx)(u,{}),onClick:()=>L({record:null,form:{}}),children:`新建智能体`})]})}),B.data?.error&&(0,A.jsx)(S,{error:B.data.error}),(0,A.jsxs)(C,{title:`智能体(${V.length})`,children:[(0,A.jsx)(S,{error:B.error,onRetry:()=>B.reload()}),(0,A.jsx)(T,{columns:[{title:`智能体`,dataIndex:`name`,render:(e,t)=>(0,A.jsxs)(i,{vertical:!0,spacing:0,align:`start`,children:[(0,A.jsxs)(i,{children:[(0,A.jsx)(j,{strong:!0,children:e||t.id}),t.is_orchestrator&&(0,A.jsx)(o,{size:`small`,color:`purple`,children:`编排器`})]}),(0,A.jsx)(j,{type:`tertiary`,children:t.filename})]})},{title:`类型`,dataIndex:`kind`,width:110,render:e=>(0,A.jsx)(o,{size:`small`,children:e||`sub`})},{title:`描述`,dataIndex:`description`,render:e=>(0,A.jsx)(j,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:460},children:e||`—`})},{title:`操作`,width:180,render:(e,t)=>(0,A.jsxs)(i,{children:[(0,A.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>H(t),children:`详情`}),n&&(0,A.jsx)(c,{size:`small`,theme:`borderless`,icon:(0,A.jsx)(s,{}),onClick:()=>L({record:t,form:{}})}),r&&(0,A.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,A.jsx)(a,{}),onClick:()=>W(t)})]})}],dataSource:V,rowKey:`filename`,loading:B.loading,pagination:{pageSize:20},toolbar:(0,A.jsx)(l,{prefix:(0,A.jsx)(f,{}),value:M,onChange:N,placeholder:`搜索名称或文件名`,style:{width:280}})})]}),(0,A.jsx)(y,{title:I?.record?`编辑智能体`:`新建智能体`,visible:!!I,onCancel:()=>L(null),onOk:U,confirmLoading:R,width:760,children:(0,A.jsxs)(d,{getFormApi:e=>L(t=>t&&{...t,form:e}),initValues:I?.record?{filename:I.record.filename,name:I.record.name,description:I.record.description,kind:I.record.kind||`sub`}:{kind:`sub`},children:[(0,A.jsx)(d.Input,{field:`filename`,label:`文件名(留空自动生成)`,placeholder:`例如 recon.md`}),(0,A.jsx)(d.Input,{field:`name`,label:`名称`,rules:[{required:!0,message:`请输入名称`}]}),(0,A.jsx)(d.Input,{field:`description`,label:`描述`}),(0,A.jsx)(d.Select,{field:`kind`,label:`类型`,optionList:[{value:`sub`,label:`子智能体`},{value:`orchestrator`,label:`编排器`},{value:`plan_execute`,label:`计划执行`}]}),(0,A.jsx)(d.Input,{field:`tools`,label:`工具(逗号分隔)`,placeholder:`toolName, mcp::tool`}),(0,A.jsx)(d.TextArea,{field:`instruction`,label:`指令(Markdown)`,autosize:{minRows:8,maxRows:20}})]})},I?.record?.filename||`new-agent`),(0,A.jsx)(y,{title:P?.name||`智能体详情`,visible:!!P,onCancel:()=>F(null),width:720,children:P&&(0,A.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,A.jsx)(b,{items:[{label:`文件名`,value:P.filename},{label:`ID`,value:P.id},{label:`类型`,value:P.kind},{label:`绑定角色`,value:P.bind_role||`—`},{label:`最大迭代`,value:P.max_iterations??`—`},{label:`工具`,value:Array.isArray(P.tools)&&P.tools.length?P.tools.join(`、`):`—`}]}),(0,A.jsx)(x,{content:P.instruction||P.raw||``}),(0,A.jsx)(E,{value:P.raw||P,title:`原始 Markdown`,collapsed:!0})]})})]})}export{M as default}; \ No newline at end of file diff --git a/web/static/app/assets/api-docs-BEMXmVy4.js b/web/static/app/assets/api-docs-BqzLMZ8q.js similarity index 98% rename from web/static/app/assets/api-docs-BEMXmVy4.js rename to web/static/app/assets/api-docs-BqzLMZ8q.js index e16226f5..1572c2b0 100644 --- a/web/static/app/assets/api-docs-BEMXmVy4.js +++ b/web/static/app/assets/api-docs-BqzLMZ8q.js @@ -1,3 +1,3 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{D as r,F as i,G as a,I as o,N as s,R as c,S as l,U as u,c as d,ct as f,lt as p,ut as m,y as h}from"./semi-65W_4I1v.js";import{F as g,H as _,L as v,b as y,p as b,u as x,z as S}from"./index-CAEPLS-g.js";var C=e(t(),1),w=e(n(),1),{Text:T,Paragraph:E}=a,D={get:`blue`,post:`green`,put:`orange`,delete:`red`,patch:`violet`,head:`grey`,options:`grey`};function O(e){let t=e?.paths||{},n=[];return Object.entries(t).forEach(([e,t])=>{Object.entries(t||{}).forEach(([t,r])=>{r&&typeof r==`object`&&n.push({id:`${t.toUpperCase()} ${e}`,method:t.toUpperCase(),path:e,summary:r.summary||r.description||``,tag:r.tags&&r.tags[0]||`default`,operation:r})})}),n.sort((e,t)=>e.path.localeCompare(t.path)||e.method.localeCompare(t.method))}function k(e){return Array.from(e.matchAll(/\{([^}]+)\}/g)).map(e=>e[1])}function A({operation:e,spec:t}){let n=e.operation||{},i=n.parameters||[],a=k(e.path),[d,p]=(0,C.useState)({}),[m,h]=(0,C.useState)(``),[g,v]=(0,C.useState)(null),[b,E]=(0,C.useState)(!1);return(0,C.useEffect)(()=>{let e={};a.forEach(t=>{let n=i.find(e=>e.name===t&&e.in===`path`);e[t]=n?.schema?.default??n?.example??``}),i.filter(e=>e.in===`query`).forEach(t=>{t.schema?.default!==void 0&&(e[`query:${t.name}`]=String(t.schema.default))}),p(e),h(n.requestBody?`{ +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{D as r,F as i,G as a,I as o,N as s,R as c,S as l,U as u,c as d,ct as f,lt as p,ut as m,y as h}from"./semi-65W_4I1v.js";import{F as g,H as _,L as v,b as y,p as b,u as x,z as S}from"./index-DNMXun-U.js";var C=e(t(),1),w=e(n(),1),{Text:T,Paragraph:E}=a,D={get:`blue`,post:`green`,put:`orange`,delete:`red`,patch:`violet`,head:`grey`,options:`grey`};function O(e){let t=e?.paths||{},n=[];return Object.entries(t).forEach(([e,t])=>{Object.entries(t||{}).forEach(([t,r])=>{r&&typeof r==`object`&&n.push({id:`${t.toUpperCase()} ${e}`,method:t.toUpperCase(),path:e,summary:r.summary||r.description||``,tag:r.tags&&r.tags[0]||`default`,operation:r})})}),n.sort((e,t)=>e.path.localeCompare(t.path)||e.method.localeCompare(t.method))}function k(e){return Array.from(e.matchAll(/\{([^}]+)\}/g)).map(e=>e[1])}function A({operation:e,spec:t}){let n=e.operation||{},i=n.parameters||[],a=k(e.path),[d,p]=(0,C.useState)({}),[m,h]=(0,C.useState)(``),[g,v]=(0,C.useState)(null),[b,E]=(0,C.useState)(!1);return(0,C.useEffect)(()=>{let e={};a.forEach(t=>{let n=i.find(e=>e.name===t&&e.in===`path`);e[t]=n?.schema?.default??n?.example??``}),i.filter(e=>e.in===`query`).forEach(t=>{t.schema?.default!==void 0&&(e[`query:${t.name}`]=String(t.schema.default))}),p(e),h(n.requestBody?`{ }`:``),v(null)},[e.id]),(0,w.jsxs)(`div`,{className:`api-docs-try`,children:[(0,w.jsx)(r,{margin:`12px 0`}),(0,w.jsx)(T,{strong:!0,children:`在线调试`}),a.length>0&&(0,w.jsx)(`div`,{className:`api-docs-try-fields`,children:a.map(e=>(0,w.jsxs)(`label`,{className:`api-docs-try-field`,children:[(0,w.jsxs)(`span`,{children:[`路径参数 `,e]}),(0,w.jsx)(u,{size:`small`,value:d[e]??``,onChange:t=>p(n=>({...n,[e]:t}))})]},e))}),i.filter(e=>e.in===`query`).length>0&&(0,w.jsx)(`div`,{className:`api-docs-try-fields`,children:i.filter(e=>e.in===`query`).map(e=>(0,w.jsxs)(`label`,{className:`api-docs-try-field`,children:[(0,w.jsxs)(`span`,{children:[`查询参数 `,e.name,e.required?` *`:``]}),(0,w.jsx)(u,{size:`small`,value:d[`query:${e.name}`]??``,onChange:t=>p(n=>({...n,[`query:${e.name}`]:t})),placeholder:e.description||``})]},e.name))}),n.requestBody&&(0,w.jsxs)(`div`,{className:`api-docs-try-body`,children:[(0,w.jsx)(`span`,{children:`请求体(JSON)`}),(0,w.jsx)(l,{value:m,onChange:h,autosize:{minRows:5,maxRows:14}})]}),(0,w.jsxs)(o,{children:[(0,w.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,w.jsx)(f,{}),loading:b,onClick:async()=>{E(!0),v(null);try{if(a.some(e=>String(d[e]??``).trim()===``)){y(`请填写路径参数`);return}let t=e.path;a.forEach(e=>{t=t.replace(`{${e}}`,encodeURIComponent(d[e]??``))});let r={};i.filter(e=>e.in===`query`).forEach(e=>{let t=d[`query:${e.name}`];t!==void 0&&t!==``&&(r[e.name]=t)});let o={method:e.method,query:r,raw:!0,timeout:12e4};if(n.requestBody&&m.trim())try{o.body=JSON.parse(m)}catch{y(`请求体不是合法 JSON`),E(!1);return}if(!t.startsWith(`/`)||t.startsWith(`//`))throw Error(`接口地址必须为站内 API 路径`);let s=await _(t.startsWith(`/api/`)?t.slice(4):t,o),c=s.headers.get(`content-type`)||``,l;l=c.includes(`application/json`)?await s.json():await s.text(),v({ok:!0,status:s.status,payload:l})}catch(e){v({ok:!1,status:e.status||0,payload:S(e)})}finally{E(!1)}},children:`发送请求`}),(0,w.jsx)(c,{onClick:()=>v(null),children:`清空结果`})]}),g&&(0,w.jsxs)(`div`,{className:`api-docs-try-result`,children:[(0,w.jsx)(s,{color:g.ok?`green`:`red`,children:g.ok?`HTTP ${g.status}`:`失败 ${g.status||``}`}),(0,w.jsx)(x,{value:g.payload,title:`响应`})]})]})}function j(){let e=g(),[t,n]=(0,C.useState)(null),[r,a]=(0,C.useState)(!0),[l,f]=(0,C.useState)(null),[_,y]=(0,C.useState)(``),[k,j]=(0,C.useState)(`all`),[M,N]=(0,C.useState)(null),P=async()=>{a(!0),f(null);try{let e=await v.get(`/openapi/spec`);n(e)}catch(e){f(e)}finally{a(!1)}};(0,C.useEffect)(()=>{P()},[]);let F=(0,C.useMemo)(()=>O(t),[t]),I=(0,C.useMemo)(()=>F.filter(e=>{if(k!==`all`&&e.method!==k)return!1;if(!_)return!0;let t=_.toLowerCase();return e.path.toLowerCase().includes(t)||e.summary.toLowerCase().includes(t)||e.method.toLowerCase().includes(t)}),[F,_,k]),L=I.find(e=>e.id===M)||I[0]||null,R=(0,C.useMemo)(()=>{let e=new Map;return I.forEach(t=>{e.has(t.tag)||e.set(t.tag,[]),e.get(t.tag).push(t)}),[...e.entries()]},[I]);return(0,w.jsxs)(`div`,{className:`api-docs-page`,children:[(0,w.jsx)(b,{title:e(`apiDocs.title`,null,`API 文档`),description:t?.info?.description||`CyberStrikeAI 开放接口`,extra:(0,w.jsx)(c,{icon:(0,w.jsx)(m,{}),onClick:P,loading:r,children:`重新加载`})}),(0,w.jsxs)(`div`,{className:`api-docs-layout`,children:[(0,w.jsxs)(i,{className:`api-docs-sidebar`,bordered:!1,children:[(0,w.jsxs)(o,{vertical:!0,style:{width:`100%`},spacing:8,children:[(0,w.jsx)(u,{prefix:(0,w.jsx)(p,{}),value:_,onChange:y,placeholder:`搜索路径或说明`}),(0,w.jsx)(h,{value:k,onChange:j,style:{width:`100%`},optionList:[{value:`all`,label:`全部方法`},...[`GET`,`POST`,`PUT`,`DELETE`,`PATCH`].map(e=>({value:e,label:e}))]})]}),(0,w.jsxs)(`div`,{className:`api-docs-list`,children:[R.map(([e,t])=>(0,w.jsxs)(`div`,{className:`api-docs-group`,children:[(0,w.jsx)(T,{type:`tertiary`,className:`api-docs-group-title`,children:e}),t.map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`api-docs-item ${L?.id===e.id?`is-active`:``}`,onClick:()=>N(e.id),children:[(0,w.jsx)(s,{size:`small`,color:D[e.method.toLowerCase()],children:e.method}),(0,w.jsx)(`span`,{className:`api-docs-item-path`,children:e.path})]},e.id))]},e)),!r&&R.length===0&&(0,w.jsx)(T,{type:`tertiary`,children:`没有匹配的接口`})]})]}),(0,w.jsxs)(`div`,{className:`api-docs-detail`,children:[l&&(0,w.jsx)(i,{bordered:!1,children:(0,w.jsx)(T,{type:`danger`,children:S(l)})}),L?(0,w.jsxs)(i,{bordered:!1,children:[(0,w.jsxs)(`div`,{className:`api-docs-detail-head`,children:[(0,w.jsx)(s,{color:D[L.method.toLowerCase()],children:L.method}),(0,w.jsx)(`code`,{className:`api-docs-detail-path`,children:L.path})]}),(0,w.jsx)(E,{children:L.summary||`无说明`}),(0,w.jsxs)(d,{type:`line`,children:[(0,w.jsx)(d.TabPane,{itemKey:`params`,tab:`参数`,children:(0,w.jsx)(x,{value:L.operation.parameters||[],title:`Request Parameters`,collapsed:!0})}),(0,w.jsx)(d.TabPane,{itemKey:`body`,tab:`请求体`,children:(0,w.jsx)(x,{value:L.operation.requestBody||{},title:`Request Body`,collapsed:!0})}),(0,w.jsx)(d.TabPane,{itemKey:`responses`,tab:`响应`,children:(0,w.jsx)(x,{value:L.operation.responses||{},title:`Responses`,collapsed:!0})})]}),(0,w.jsx)(A,{operation:L,spec:t})]}):(0,w.jsx)(i,{bordered:!1,children:(0,w.jsx)(T,{type:`tertiary`,children:r?`加载中…`:`选择左侧接口查看详情`})})]})]})]})}export{j as default}; \ No newline at end of file diff --git a/web/static/app/assets/asset-library-CwccI3Xb.js b/web/static/app/assets/asset-library-Btn_YOu0.js similarity index 99% rename from web/static/app/assets/asset-library-CwccI3Xb.js rename to web/static/app/assets/asset-library-Btn_YOu0.js index 775565a2..0c2bbc22 100644 --- a/web/static/app/assets/asset-library-CwccI3Xb.js +++ b/web/static/app/assets/asset-library-Btn_YOu0.js @@ -1,3 +1,3 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{B as a,Bt as o,D as s,G as c,I as l,R as u,S as d,U as f,d as p,ft as m,h,j as g,lt as _,m as v,p as y,u as b,ut as x,y as S}from"./semi-65W_4I1v.js";import{E as C,F as w,I as ee,L as T,S as te,a as E,b as D,c as O,d as k,l as ne,m as re,n as ie,o as A,p as ae,s as oe,x as j,y as se,z as M}from"./index-CAEPLS-g.js";import{n as ce}from"./project-options-CMQbwv_U.js";import{A as le,C as ue,D as de,E as fe,M as pe,O as me,S as he,T as ge,_ as _e,a as ve,b as ye,d as be,f as xe,g as Se,h as N,i as P,k as F,l as I,m as Ce,n as we,o as L,p as Te,r as R,s as Ee,t as De,v as z,w as B,y as V}from"./assetTarget-D2PEjBAg.js";import{a as Oe,i as H,n as ke,r as U,t as Ae}from"./AssetBits-DtqSAj0f.js";import{t as je}from"./AssetEditorModal-HZN0Ndjf.js";var W=e(t(),1),G=e(r(),1),Me={q:``,protocol:``,source:``,tag:``,status:``,risk_level:``,environment:``,criticality:``,ip:``,domain:``,port:``,scan:``,sort:`last_seen_at:desc`};function Ne(){return{...Me}}function Pe({scope:e,filters:t,onChange:n,onReset:r,disabled:i}){let a=w(),o=(0,W.useId)(),[s,c]=(0,W.useState)(t.q||``);(0,W.useEffect)(()=>{c(t.q||``)},[t.q]);let l=[`status`,`risk_level`,`environment`,`criticality`,`ip`,`domain`,`port`,`scan`].filter(e=>t[e]).length;return(0,G.jsxs)(`div`,{className:`asset-library-filters`,children:[(0,G.jsxs)(`div`,{className:`asset-library-filter-row`,children:[(0,G.jsx)(`span`,{id:o,hidden:!0,children:a(`assets.scopeLabel`,null,`资产范围`)}),(0,G.jsx)(S,{"aria-labelledby":o,value:e.value,optionList:e.options,loading:e.loading,disabled:i,onChange:e.onChange,filter:!0}),(0,G.jsx)(f,{className:`asset-library-filter-search`,prefix:(0,G.jsx)(_,{}),value:s,disabled:i,placeholder:a(`assets.searchPlaceholder`,null,`搜索主机、IP、域名、标题、服务或标签`),onChange:e=>{c(e),n({q:e})},showClear:!0}),(0,G.jsx)(S,{value:t.protocol||void 0,placeholder:a(`assets.assetType`,null,`类型 / 协议`),optionList:ye,filter:!0,allowCreate:!0,showClear:!0,disabled:i,onChange:e=>n({protocol:e||``})}),(0,G.jsx)(f,{value:t.source,placeholder:a(`assets.source`,null,`来源`),disabled:i,onChange:e=>n({source:e}),showClear:!0}),(0,G.jsx)(f,{value:t.tag,placeholder:a(`assets.tagsLabel`,null,`标签`),disabled:i,onChange:e=>n({tag:e}),showClear:!0}),(0,G.jsx)(u,{onClick:r,disabled:i,children:a(`assets.resetFilters`,null,`重置`)})]}),(0,G.jsx)(g,{className:`asset-library-filter-advanced`,keepDOM:!1,children:(0,G.jsx)(g.Panel,{itemKey:`advanced`,header:`${a(`assets.advancedFilters`,null,`高级筛选`)}${l?`(${l})`:``}`,children:(0,G.jsxs)(`div`,{className:`asset-library-filter-grid`,children:[(0,G.jsx)(S,{value:t.status||void 0,placeholder:a(`assets.allStatuses`,null,`全部状态`),optionList:fe,showClear:!0,disabled:i,onChange:e=>n({status:e||``})}),(0,G.jsx)(S,{value:t.risk_level||void 0,placeholder:a(`assets.allRisks`,null,`全部风险`),optionList:he,showClear:!0,disabled:i,onChange:e=>n({risk_level:e||``})}),(0,G.jsx)(S,{value:t.environment||void 0,placeholder:a(`assets.allEnvironments`,null,`全部环境`),optionList:N,showClear:!0,disabled:i,onChange:e=>n({environment:e||``})}),(0,G.jsx)(S,{value:t.criticality||void 0,placeholder:a(`assets.allCriticalities`,null,`全部级别`),optionList:Te,showClear:!0,disabled:i,onChange:e=>n({criticality:e||``})}),(0,G.jsx)(f,{value:t.ip,placeholder:`IP`,disabled:i,onChange:e=>n({ip:e}),showClear:!0}),(0,G.jsx)(f,{value:t.domain,placeholder:a(`assets.domain`,null,`域名`),disabled:i,onChange:e=>n({domain:e}),showClear:!0}),(0,G.jsx)(f,{value:t.port,placeholder:a(`assets.port`,null,`端口`),disabled:i,onChange:e=>n({port:String(e||``).replace(/[^\d]/g,``)}),showClear:!0}),(0,G.jsx)(S,{value:t.scan||``,placeholder:a(`assets.scanState`,null,`扫描状态`),optionList:ue,disabled:i,onChange:e=>n({scan:e||``})}),(0,G.jsx)(S,{value:t.sort||`last_seen_at:desc`,optionList:B,disabled:i,onChange:e=>n({sort:e||`last_seen_at:desc`})})]})})})]})}var{Text:K}=c;function Fe({assets:e,loading:t,total:n,page:r,pageSize:i,onPageChange:a,onPageSizeChange:o,selectedRowKeys:s,onSelectionChange:c,onView:d,onEdit:f,onDelete:p,onRefresh:m,canWrite:h,canDelete:g}){let _=w(),v=e=>{se({title:_(`assets.deleteConfirm`,null,`确定删除该资产吗?`),content:R(e),okText:_(`common.delete`,null,`删除`),onOk:()=>{Promise.resolve(p(e)).catch(e=>D(e,_(`assets.deleteFailed`,null,`删除资产失败`)))}})},y=[{title:_(`assets.target`,null,`目标`),dataIndex:`host`,width:260,render:(e,t)=>(0,G.jsxs)(`div`,{className:`asset-library-target`,children:[(0,G.jsx)(Oe,{text:R(t),max:38}),(0,G.jsx)(K,{type:`tertiary`,size:`small`,children:[t.ip,t.domain].filter(Boolean).join(` · `)||`—`})]})},{title:_(`assets.service`,null,`服务`),dataIndex:`protocol`,width:150,render:(e,t)=>(0,G.jsx)(ke,{protocol:t.protocol,port:t.port})},{title:_(`assets.project`,null,`所属项目`),dataIndex:`project_name`,width:160,render:(e,t)=>(0,G.jsx)(Oe,{text:e||t.project_id||_(`assets.scopeUnassigned`,null,`未归属项目`),max:18})},{title:_(`assets.source`,null,`来源`),dataIndex:`source`,width:120,render:e=>(0,G.jsx)(Oe,{text:e,max:14})},{title:_(`assets.riskLevel`,null,`风险等级`),dataIndex:`risk_level`,width:150,render:(e,t)=>(0,G.jsxs)(l,{spacing:6,children:[(0,G.jsx)(U,{asset:t}),(0,G.jsx)(K,{type:`tertiary`,size:`small`,children:Number(t.vulnerability_count||0)})]})},{title:_(`assets.lastSeen`,null,`最近发现`),dataIndex:`last_seen_at`,width:170,render:e=>(0,G.jsx)(K,{size:`small`,children:C(e)})},{title:_(`common.actions`,null,`操作`),dataIndex:`id`,width:190,render:(e,t)=>(0,G.jsxs)(l,{spacing:4,children:[(0,G.jsx)(u,{theme:`borderless`,size:`small`,onClick:()=>d(t),children:_(`common.view`,null,`查看`)}),h&&(0,G.jsx)(u,{theme:`borderless`,size:`small`,onClick:()=>f(t),children:_(`common.edit`,null,`编辑`)}),g&&(0,G.jsx)(u,{theme:`borderless`,type:`danger`,size:`small`,onClick:()=>v(t),children:_(`common.delete`,null,`删除`)})]})}];return(0,G.jsx)(oe,{columns:y,dataSource:e,loading:t,rowKey:`id`,onRefresh:m,rowSelection:{selectedRowKeys:s,onChange:(e,t)=>c(e,t)},pagination:{currentPage:r,pageSize:i,total:n||0,showSizeChanger:!0,pageSizeOpts:[10,20,50,100],onPageChange:a,onPageSizeChange:o},emptyText:_(`common.noData`,null,`暂无数据`)})}var{Text:q}=c;function Ie({asset:e,visible:t,onClose:r,onEdit:i,onDelete:a,canWrite:o,canDelete:c}){let d=w(),f=n(),[p,m]=(0,W.useState)([]);if((0,W.useEffect)(()=>{if(!t||!e?.id){m([]);return}let n=!1;return T.get(`/assets/${e.id}/facts`).then(e=>{n||m(Array.isArray(e?.facts)?e.facts:[])}).catch(()=>{n||m([])}),()=>{n=!0}},[t,e?.id]),!e)return null;let h=()=>{if(e.last_scan_task_id){f(`/vulnerabilities?task_id=${encodeURIComponent(e.last_scan_task_id)}`);return}if(e.last_scan_conversation_id){f(`/vulnerabilities?conversation_id=${encodeURIComponent(e.last_scan_conversation_id)}`);return}let t=e.host||e.domain||e.ip||``;f(t?`/vulnerabilities?host_q=${encodeURIComponent(t)}`:`/vulnerabilities`)},g=[{label:`Host`,value:e.host||`—`},{label:`IP`,value:e.ip||`—`},{label:d(`assets.domain`,null,`域名`),value:e.domain||`—`},{label:d(`assets.service`,null,`服务`),value:(0,G.jsx)(ke,{protocol:e.protocol,port:e.port})},{label:d(`assets.project`,null,`所属项目`),value:e.project_name||e.project_id||`—`},{label:d(`assets.status`,null,`状态`),value:(0,G.jsx)(Ae,{status:e.status})},{label:d(`assets.riskLevel`,null,`风险等级`),value:(0,G.jsx)(U,{asset:e})},{label:d(`assets.environment`,null,`环境`),value:F(e.environment)||`—`},{label:d(`assets.criticality`,null,`重要性`),value:me(e.criticality)||`—`},{label:d(`assets.location`,null,`地区`),value:[e.country,e.province,e.city].filter(Boolean).join(` / `)||`—`},{label:d(`assets.responsiblePerson`,null,`负责人`),value:e.responsible_person||`—`},{label:d(`assets.department`,null,`部门`),value:e.department||`—`},{label:d(`assets.businessSystem`,null,`业务系统`),value:e.business_system||`—`},{label:d(`assets.title`,null,`标题/指纹`),value:e.title||`—`},{label:d(`assets.server`,null,`服务指纹`),value:e.server||`—`},{label:d(`assets.source`,null,`来源`),value:e.source||`—`},{label:d(`assets.sourceQuery`,null,`来源查询`),value:e.source_query?(0,G.jsx)(q,{code:!0,size:`small`,children:e.source_query}):`—`},{label:d(`assets.tagsLabel`,null,`标签`),value:(0,G.jsx)(H,{tags:e.tags,max:6})},{label:d(`assets.firstSeen`,null,`首次发现`),value:C(e.first_seen_at)},{label:d(`assets.lastSeen`,null,`最近发现`),value:C(e.last_seen_at)},{label:d(`assets.lastScan`,null,`上次扫描`),value:C(e.last_scan_at)},{label:`创建时间`,value:C(e.created_at)},{label:`更新时间`,value:C(e.updated_at)},{label:`资产 ID`,value:(0,G.jsx)(q,{copyable:{content:e.id},size:`small`,children:e.id})}];return(0,G.jsxs)(y,{visible:t,onCancel:r,title:d(`assets.detailTitle`,null,`资产详情`),width:620,placement:`right`,footer:(0,G.jsxs)(l,{children:[o&&(0,G.jsx)(u,{onClick:()=>i(e),children:d(`common.edit`,null,`编辑`)}),c&&(0,G.jsx)(u,{type:`danger`,onClick:()=>a(e),children:d(`common.delete`,null,`删除`)}),(0,G.jsx)(u,{theme:`borderless`,onClick:r,children:d(`common.close`,null,`关闭`)})]}),children:[(0,G.jsxs)(`div`,{className:`asset-library-detail-target`,children:[(0,G.jsxs)(`div`,{className:`asset-library-detail-target-main`,children:[(0,G.jsx)(q,{strong:!0,size:`large`,children:R(e)}),(0,G.jsx)(A,{text:R(e)})]}),(0,G.jsx)(q,{type:`tertiary`,children:[e.ip,e.domain,we(e)].filter(Boolean).join(` · `)||`—`}),(0,G.jsxs)(l,{spacing:6,wrap:!0,className:`asset-library-detail-badges`,children:[(0,G.jsx)(Ae,{status:e.status}),(0,G.jsx)(U,{asset:e}),(0,G.jsxs)(q,{type:`tertiary`,size:`small`,children:[d(`assets.relatedVulnerabilities`,null,`相关漏洞`),`:`,Number(e.vulnerability_count||0),e.risk_level?`(${le(e.risk_level)})`:``]})]})]}),(0,G.jsx)(s,{margin:`12px`}),(0,G.jsx)(k,{items:g,columns:2}),(0,G.jsx)(s,{margin:`12px`}),(0,G.jsx)(q,{strong:!0,children:`项目事实`}),p.length===0?(0,G.jsx)(q,{type:`tertiary`,size:`small`,children:`还没有关联到这条资产的项目事实。`}):p.map(e=>(0,G.jsxs)(`div`,{className:`asset-library-detail-target`,children:[(0,G.jsx)(q,{children:e.summary||e.fact_key}),(0,G.jsxs)(l,{children:[e.source_conversation_id?(0,G.jsx)(u,{size:`small`,theme:`borderless`,onClick:()=>f(`/chat?conversation=${encodeURIComponent(e.source_conversation_id)}`),children:`打开来源会话`}):null,e.project_id?(0,G.jsx)(u,{size:`small`,theme:`borderless`,onClick:()=>f(`/projects/${e.project_id}?tab=facts`),children:`项目事实`}):null]})]},e.id)),(0,G.jsx)(s,{margin:`12px`}),(0,G.jsxs)(l,{children:[(0,G.jsx)(u,{theme:`light`,onClick:h,children:d(`assets.viewRelatedVulnerabilities`,null,`查看关联漏洞`)}),e.project_id&&(0,G.jsx)(u,{theme:`borderless`,onClick:()=>f(`/projects?id=${encodeURIComponent(e.project_id)}`),children:d(`assets.viewProject`,null,`查看项目`)})]})]})}var Le={host:500,title:500,domain:253,protocol:32,server:255,country:255,province:255,city:255,responsible_person:255,department:255,business_system:255};function J(e){return String(e??``).replace(/^\uFEFF/,``).trim().toLowerCase().replace(/[\s_\-/.()()]+/g,``)}function Re(e){let t=J(e);return t&&_e.find(e=>(z[e]||[]).some(e=>J(e)===t))||``}function Y(e){let t=String(e??``).replace(/^\uFEFF/,``),n=[],r=[],i=``,a=!1;for(let e=0;e{c(t.q||``)},[t.q]);let l=[`status`,`risk_level`,`environment`,`criticality`,`ip`,`domain`,`port`,`scan`].filter(e=>t[e]).length;return(0,G.jsxs)(`div`,{className:`asset-library-filters`,children:[(0,G.jsxs)(`div`,{className:`asset-library-filter-row`,children:[(0,G.jsx)(`span`,{id:o,hidden:!0,children:a(`assets.scopeLabel`,null,`资产范围`)}),(0,G.jsx)(S,{"aria-labelledby":o,value:e.value,optionList:e.options,loading:e.loading,disabled:i,onChange:e.onChange,filter:!0}),(0,G.jsx)(f,{className:`asset-library-filter-search`,prefix:(0,G.jsx)(_,{}),value:s,disabled:i,placeholder:a(`assets.searchPlaceholder`,null,`搜索主机、IP、域名、标题、服务或标签`),onChange:e=>{c(e),n({q:e})},showClear:!0}),(0,G.jsx)(S,{value:t.protocol||void 0,placeholder:a(`assets.assetType`,null,`类型 / 协议`),optionList:ye,filter:!0,allowCreate:!0,showClear:!0,disabled:i,onChange:e=>n({protocol:e||``})}),(0,G.jsx)(f,{value:t.source,placeholder:a(`assets.source`,null,`来源`),disabled:i,onChange:e=>n({source:e}),showClear:!0}),(0,G.jsx)(f,{value:t.tag,placeholder:a(`assets.tagsLabel`,null,`标签`),disabled:i,onChange:e=>n({tag:e}),showClear:!0}),(0,G.jsx)(u,{onClick:r,disabled:i,children:a(`assets.resetFilters`,null,`重置`)})]}),(0,G.jsx)(g,{className:`asset-library-filter-advanced`,keepDOM:!1,children:(0,G.jsx)(g.Panel,{itemKey:`advanced`,header:`${a(`assets.advancedFilters`,null,`高级筛选`)}${l?`(${l})`:``}`,children:(0,G.jsxs)(`div`,{className:`asset-library-filter-grid`,children:[(0,G.jsx)(S,{value:t.status||void 0,placeholder:a(`assets.allStatuses`,null,`全部状态`),optionList:fe,showClear:!0,disabled:i,onChange:e=>n({status:e||``})}),(0,G.jsx)(S,{value:t.risk_level||void 0,placeholder:a(`assets.allRisks`,null,`全部风险`),optionList:he,showClear:!0,disabled:i,onChange:e=>n({risk_level:e||``})}),(0,G.jsx)(S,{value:t.environment||void 0,placeholder:a(`assets.allEnvironments`,null,`全部环境`),optionList:N,showClear:!0,disabled:i,onChange:e=>n({environment:e||``})}),(0,G.jsx)(S,{value:t.criticality||void 0,placeholder:a(`assets.allCriticalities`,null,`全部级别`),optionList:Te,showClear:!0,disabled:i,onChange:e=>n({criticality:e||``})}),(0,G.jsx)(f,{value:t.ip,placeholder:`IP`,disabled:i,onChange:e=>n({ip:e}),showClear:!0}),(0,G.jsx)(f,{value:t.domain,placeholder:a(`assets.domain`,null,`域名`),disabled:i,onChange:e=>n({domain:e}),showClear:!0}),(0,G.jsx)(f,{value:t.port,placeholder:a(`assets.port`,null,`端口`),disabled:i,onChange:e=>n({port:String(e||``).replace(/[^\d]/g,``)}),showClear:!0}),(0,G.jsx)(S,{value:t.scan||``,placeholder:a(`assets.scanState`,null,`扫描状态`),optionList:ue,disabled:i,onChange:e=>n({scan:e||``})}),(0,G.jsx)(S,{value:t.sort||`last_seen_at:desc`,optionList:B,disabled:i,onChange:e=>n({sort:e||`last_seen_at:desc`})})]})})})]})}var{Text:K}=c;function Fe({assets:e,loading:t,total:n,page:r,pageSize:i,onPageChange:a,onPageSizeChange:o,selectedRowKeys:s,onSelectionChange:c,onView:d,onEdit:f,onDelete:p,onRefresh:m,canWrite:h,canDelete:g}){let _=w(),v=e=>{se({title:_(`assets.deleteConfirm`,null,`确定删除该资产吗?`),content:R(e),okText:_(`common.delete`,null,`删除`),onOk:()=>{Promise.resolve(p(e)).catch(e=>D(e,_(`assets.deleteFailed`,null,`删除资产失败`)))}})},y=[{title:_(`assets.target`,null,`目标`),dataIndex:`host`,width:260,render:(e,t)=>(0,G.jsxs)(`div`,{className:`asset-library-target`,children:[(0,G.jsx)(Oe,{text:R(t),max:38}),(0,G.jsx)(K,{type:`tertiary`,size:`small`,children:[t.ip,t.domain].filter(Boolean).join(` · `)||`—`})]})},{title:_(`assets.service`,null,`服务`),dataIndex:`protocol`,width:150,render:(e,t)=>(0,G.jsx)(ke,{protocol:t.protocol,port:t.port})},{title:_(`assets.project`,null,`所属项目`),dataIndex:`project_name`,width:160,render:(e,t)=>(0,G.jsx)(Oe,{text:e||t.project_id||_(`assets.scopeUnassigned`,null,`未归属项目`),max:18})},{title:_(`assets.source`,null,`来源`),dataIndex:`source`,width:120,render:e=>(0,G.jsx)(Oe,{text:e,max:14})},{title:_(`assets.riskLevel`,null,`风险等级`),dataIndex:`risk_level`,width:150,render:(e,t)=>(0,G.jsxs)(l,{spacing:6,children:[(0,G.jsx)(U,{asset:t}),(0,G.jsx)(K,{type:`tertiary`,size:`small`,children:Number(t.vulnerability_count||0)})]})},{title:_(`assets.lastSeen`,null,`最近发现`),dataIndex:`last_seen_at`,width:170,render:e=>(0,G.jsx)(K,{size:`small`,children:C(e)})},{title:_(`common.actions`,null,`操作`),dataIndex:`id`,width:190,render:(e,t)=>(0,G.jsxs)(l,{spacing:4,children:[(0,G.jsx)(u,{theme:`borderless`,size:`small`,onClick:()=>d(t),children:_(`common.view`,null,`查看`)}),h&&(0,G.jsx)(u,{theme:`borderless`,size:`small`,onClick:()=>f(t),children:_(`common.edit`,null,`编辑`)}),g&&(0,G.jsx)(u,{theme:`borderless`,type:`danger`,size:`small`,onClick:()=>v(t),children:_(`common.delete`,null,`删除`)})]})}];return(0,G.jsx)(oe,{columns:y,dataSource:e,loading:t,rowKey:`id`,onRefresh:m,rowSelection:{selectedRowKeys:s,onChange:(e,t)=>c(e,t)},pagination:{currentPage:r,pageSize:i,total:n||0,showSizeChanger:!0,pageSizeOpts:[10,20,50,100],onPageChange:a,onPageSizeChange:o},emptyText:_(`common.noData`,null,`暂无数据`)})}var{Text:q}=c;function Ie({asset:e,visible:t,onClose:r,onEdit:i,onDelete:a,canWrite:o,canDelete:c}){let d=w(),f=n(),[p,m]=(0,W.useState)([]);if((0,W.useEffect)(()=>{if(!t||!e?.id){m([]);return}let n=!1;return T.get(`/assets/${e.id}/facts`).then(e=>{n||m(Array.isArray(e?.facts)?e.facts:[])}).catch(()=>{n||m([])}),()=>{n=!0}},[t,e?.id]),!e)return null;let h=()=>{if(e.last_scan_task_id){f(`/vulnerabilities?task_id=${encodeURIComponent(e.last_scan_task_id)}`);return}if(e.last_scan_conversation_id){f(`/vulnerabilities?conversation_id=${encodeURIComponent(e.last_scan_conversation_id)}`);return}let t=e.host||e.domain||e.ip||``;f(t?`/vulnerabilities?host_q=${encodeURIComponent(t)}`:`/vulnerabilities`)},g=[{label:`Host`,value:e.host||`—`},{label:`IP`,value:e.ip||`—`},{label:d(`assets.domain`,null,`域名`),value:e.domain||`—`},{label:d(`assets.service`,null,`服务`),value:(0,G.jsx)(ke,{protocol:e.protocol,port:e.port})},{label:d(`assets.project`,null,`所属项目`),value:e.project_name||e.project_id||`—`},{label:d(`assets.status`,null,`状态`),value:(0,G.jsx)(Ae,{status:e.status})},{label:d(`assets.riskLevel`,null,`风险等级`),value:(0,G.jsx)(U,{asset:e})},{label:d(`assets.environment`,null,`环境`),value:F(e.environment)||`—`},{label:d(`assets.criticality`,null,`重要性`),value:me(e.criticality)||`—`},{label:d(`assets.location`,null,`地区`),value:[e.country,e.province,e.city].filter(Boolean).join(` / `)||`—`},{label:d(`assets.responsiblePerson`,null,`负责人`),value:e.responsible_person||`—`},{label:d(`assets.department`,null,`部门`),value:e.department||`—`},{label:d(`assets.businessSystem`,null,`业务系统`),value:e.business_system||`—`},{label:d(`assets.title`,null,`标题/指纹`),value:e.title||`—`},{label:d(`assets.server`,null,`服务指纹`),value:e.server||`—`},{label:d(`assets.source`,null,`来源`),value:e.source||`—`},{label:d(`assets.sourceQuery`,null,`来源查询`),value:e.source_query?(0,G.jsx)(q,{code:!0,size:`small`,children:e.source_query}):`—`},{label:d(`assets.tagsLabel`,null,`标签`),value:(0,G.jsx)(H,{tags:e.tags,max:6})},{label:d(`assets.firstSeen`,null,`首次发现`),value:C(e.first_seen_at)},{label:d(`assets.lastSeen`,null,`最近发现`),value:C(e.last_seen_at)},{label:d(`assets.lastScan`,null,`上次扫描`),value:C(e.last_scan_at)},{label:`创建时间`,value:C(e.created_at)},{label:`更新时间`,value:C(e.updated_at)},{label:`资产 ID`,value:(0,G.jsx)(q,{copyable:{content:e.id},size:`small`,children:e.id})}];return(0,G.jsxs)(y,{visible:t,onCancel:r,title:d(`assets.detailTitle`,null,`资产详情`),width:620,placement:`right`,footer:(0,G.jsxs)(l,{children:[o&&(0,G.jsx)(u,{onClick:()=>i(e),children:d(`common.edit`,null,`编辑`)}),c&&(0,G.jsx)(u,{type:`danger`,onClick:()=>a(e),children:d(`common.delete`,null,`删除`)}),(0,G.jsx)(u,{theme:`borderless`,onClick:r,children:d(`common.close`,null,`关闭`)})]}),children:[(0,G.jsxs)(`div`,{className:`asset-library-detail-target`,children:[(0,G.jsxs)(`div`,{className:`asset-library-detail-target-main`,children:[(0,G.jsx)(q,{strong:!0,size:`large`,children:R(e)}),(0,G.jsx)(A,{text:R(e)})]}),(0,G.jsx)(q,{type:`tertiary`,children:[e.ip,e.domain,we(e)].filter(Boolean).join(` · `)||`—`}),(0,G.jsxs)(l,{spacing:6,wrap:!0,className:`asset-library-detail-badges`,children:[(0,G.jsx)(Ae,{status:e.status}),(0,G.jsx)(U,{asset:e}),(0,G.jsxs)(q,{type:`tertiary`,size:`small`,children:[d(`assets.relatedVulnerabilities`,null,`相关漏洞`),`:`,Number(e.vulnerability_count||0),e.risk_level?`(${le(e.risk_level)})`:``]})]})]}),(0,G.jsx)(s,{margin:`12px`}),(0,G.jsx)(k,{items:g,columns:2}),(0,G.jsx)(s,{margin:`12px`}),(0,G.jsx)(q,{strong:!0,children:`项目事实`}),p.length===0?(0,G.jsx)(q,{type:`tertiary`,size:`small`,children:`还没有关联到这条资产的项目事实。`}):p.map(e=>(0,G.jsxs)(`div`,{className:`asset-library-detail-target`,children:[(0,G.jsx)(q,{children:e.summary||e.fact_key}),(0,G.jsxs)(l,{children:[e.source_conversation_id?(0,G.jsx)(u,{size:`small`,theme:`borderless`,onClick:()=>f(`/chat?conversation=${encodeURIComponent(e.source_conversation_id)}`),children:`打开来源会话`}):null,e.project_id?(0,G.jsx)(u,{size:`small`,theme:`borderless`,onClick:()=>f(`/projects/${e.project_id}?tab=facts`),children:`项目事实`}):null]})]},e.id)),(0,G.jsx)(s,{margin:`12px`}),(0,G.jsxs)(l,{children:[(0,G.jsx)(u,{theme:`light`,onClick:h,children:d(`assets.viewRelatedVulnerabilities`,null,`查看关联漏洞`)}),e.project_id&&(0,G.jsx)(u,{theme:`borderless`,onClick:()=>f(`/projects?id=${encodeURIComponent(e.project_id)}`),children:d(`assets.viewProject`,null,`查看项目`)})]})]})}var Le={host:500,title:500,domain:253,protocol:32,server:255,country:255,province:255,city:255,responsible_person:255,department:255,business_system:255};function J(e){return String(e??``).replace(/^\uFEFF/,``).trim().toLowerCase().replace(/[\s_\-/.()()]+/g,``)}function Re(e){let t=J(e);return t&&_e.find(e=>(z[e]||[]).some(e=>J(e)===t))||``}function Y(e){let t=String(e??``).replace(/^\uFEFF/,``),n=[],r=[],i=``,a=!1;for(let e=0;ee.some(e=>String(e??``).trim()!==``))}function X(e,t,n=``){let r=String(e??``).trim();if(!r)return n;let i=r.toLowerCase();if(t[i])return i;let a=Object.entries(t).find(([,e])=>e===r);return a?a[0]:null}function ze(e,t){let n=String(e??``).trim();if(!n)return{projectId:``,projectName:``,error:``};let r=n.toLowerCase(),i=(t||[]).find(e=>String(e.id).toLowerCase()===r||String(e.name||``).trim().toLowerCase()===r);return i?{projectId:i.id,projectName:i.name,error:``}:{projectId:``,projectName:``,error:`项目不存在或无权访问:${n}`}}function Be(e,t,{projects:n,projectId:r,source:i}){let a=n=>({rowNumber:t,values:e,asset:null,error:n}),o=e.target||e.host||e.domain||e.ip||``;if(!o)return a(`缺少目标地址`);let s;try{s=Ee(o)}catch(e){return a(e.message)}let c=String(e.port??``).trim(),l=Number(c===``?s.port||0:c);if(!Number.isInteger(l)||l<0||l>65535)return a(`端口必须在 0–65535 之间`);let u=String(e.ip||s.ip||``).trim().toLowerCase();if(u&&!P(u)&&!ve(u))return a(`IP 地址格式无效`);let d=String(e.domain||s.domain||``).trim(),f=d?L(d):``;if(d&&!f)return a(`域名格式无效`);let p=String(e.protocol||s.protocol||``).trim().toLowerCase();if(p&&!/^[a-z][a-z0-9+.-]{0,31}$/.test(p))return a(`协议格式无效`);let m=X(e.status,ge,`active`);if(!m)return a(`状态仅支持 active 或 inactive`);let h=X(e.environment,Ce,``);if(h===null)return a(`环境值无效`);let g=X(e.criticality,xe,``);if(g===null)return a(`重要性值无效`);let _=ze(e.project||r,n);if(_.error)return a(_.error);if(r!==void 0&&_.projectId!==r)return a(`该行的项目与当前资产范围不一致`);let v=I(e.tags);if(v.length>30)return a(`标签最多 30 个`);if(v.some(e=>Array.from(e).length>64))return a(`单个标签最多 64 个字符`);let y={host:String(e.host||s.host||``).trim(),ip:u,domain:f,port:l,protocol:p,title:String(e.title||``).trim(),server:String(e.server||``).trim(),country:String(e.country||``).trim(),province:String(e.province||``).trim(),city:String(e.city||``).trim(),responsible_person:String(e.responsible_person||``).trim(),department:String(e.department||``).trim(),business_system:String(e.business_system||``).trim(),environment:h,criticality:g,status:m,tags:v,project_id:_.projectId,source:i||`manual-import`},b=Object.keys(Le).find(e=>Array.from(String(y[e]||``)).length>Le[e]);if(b)return a(`字段 ${b} 内容过长`);let x=be(y);return x?a(x):{rowNumber:t,values:e,asset:y,projectName:_.projectName,error:``}}function Ve(e){let t=new Map;return e.map(e=>{if(e.error||!e.asset)return e;let n=De(e.asset);return t.has(n)?{...e,error:`与第 ${t.get(n)} 行重复`}:(t.set(n,e.rowNumber),e)})}function He(e,t={}){let n=Y(e);if(n.length<2)throw Error(`文件中没有可导入的数据`);let r=n[0].map(Re);if(!r.some(Boolean))throw Error(`未识别到模板字段,请检查表头`);let i=n.slice(1);if(i.length>1e5)throw Error(`数据不能超过 ${V} 行`);return Ve(i.map((e,n)=>{let i={};return r.forEach((t,n)=>{t&&i[t]==null&&(i[t]=String(e[n]??``).trim())}),Be(i,n+2,t)}))}function Ue(e,t={}){let n;try{n=JSON.parse(String(e??``))}catch(e){throw Error(`JSON 解析失败:`+e.message)}let r=(Array.isArray(n)?n:Array.isArray(n?.assets)?n.assets:[n]).filter(e=>e&&typeof e==`object`);if(!r.length)throw Error(`文件中没有可导入的数据`);if(r.length>1e5)throw Error(`数据不能超过 ${V} 行`);return Ve(r.map((e,n)=>Be({target:e.target||e.host||e.domain||e.ip||``,host:e.host,ip:e.ip,domain:e.domain,port:e.port,protocol:e.protocol,title:e.title,server:e.server,country:e.country,province:e.province,city:e.city,responsible_person:e.responsible_person,department:e.department,business_system:e.business_system,environment:e.environment,criticality:e.criticality,status:e.status,tags:Array.isArray(e.tags)?e.tags.join(`,`):e.tags,project:e.project_id||e.project||e.project_name},n+1,t)))}function Z(){return`${_e.join(`,`)}\r\n`}function We(e){let t=String(e??``);return/[",\r\n]/.test(t)?`"${t.replaceAll(`"`,`""`)}"`:t}function Q(e,t){return t===`target`?R(e):t===`project`?e.project_name||e.project_id||``:t===`tags`?(e.tags||[]).join(`,`):t===`status`?pe(e.status):t===`environment`?F(e.environment):t===`criticality`?me(e.criticality):t===`risk_level`?le(e.risk_level):t===`vulnerability_count`?Number(e.vulnerability_count||0):e[t]??``}function Ge(e){let t=[Se.map(([,e])=>We(e)).join(`,`)];return(e||[]).forEach(e=>{t.push(Se.map(([t])=>We(Q(e,t))).join(`,`))}),`\uFEFF${t.join(`\r `)}`}function Ke(e,t,n=`text/csv;charset=utf-8`){let r=new Blob([t],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=e,document.body.appendChild(a),a.click(),a.remove(),setTimeout(()=>URL.revokeObjectURL(i),1e3)}var{Text:$}=c,qe=e=>[{title:e(`assets.rowNumber`,null,`行号`),dataIndex:`rowNumber`,width:70},{title:e(`assets.target`,null,`目标`),dataIndex:`target`,render:(e,t)=>R(t.asset||{target:t.values?.target})},{title:e(`assets.project`,null,`所属项目`),dataIndex:`project`,render:(e,t)=>t.projectName||t.values?.project||`—`},{title:e(`assets.status`,null,`状态`),dataIndex:`status`,render:(e,t)=>t.asset?.status||t.values?.status||`—`},{title:e(`assets.validationResult`,null,`校验结果`),dataIndex:`error`,render:t=>t?(0,G.jsx)($,{type:`danger`,size:`small`,children:t}):(0,G.jsx)($,{type:`success`,size:`small`,children:e(`assets.validationPassed`,null,`通过`)})}];function Je({visible:e,projects:t,defaultProjectId:n,onClose:r,onDone:i}){let s=w(),[c,f]=(0,W.useState)(`csv`),[p,m]=(0,W.useState)(``),[g,_]=(0,W.useState)(``),[v,y]=(0,W.useState)(``),[x,S]=(0,W.useState)(!1),C=(0,W.useRef)(null),ee=(0,W.useMemo)(()=>{if(!String(p||``).trim())return{records:[],error:``};try{let e={projects:t,projectId:n,source:`manual-import`};return{records:c===`csv`?He(p,e):Ue(p,e),error:``}}catch(e){return{records:[],error:e.message}}},[p,c,t,n]),E=ee.records,D=E.filter(e=>!e.error),k=E.length-D.length,ne=v||ee.error,re=()=>{m(``),_(``),f(`csv`),y(``),S(!1)},ie=()=>{x||(re(),r?.())},A=async e=>{if(!e)return;y(``);let t=String(e.name||``),n=t.split(`.`).pop().toLowerCase();if(![`csv`,`json`,`txt`].includes(n))y(`仅支持 .csv / .json / .txt 文件`);else if(e.size>104857600)y(s(`assets.fileTooLarge`,null,`文件不能超过 100 MB`));else try{let r=await e.text();f(n===`json`?`json`:`csv`),m(r),_(t)}catch(e){y(M(e,s(`assets.fileParseFailed`,null,`无法解析文件,请确认文件格式正确`)))}};return(0,G.jsxs)(O,{visible:e,title:s(`assets.bulkImportTitle`,null,`批量导入资产`),width:880,onCancel:ie,onOk:async()=>{if(!x&&D.length){y(``),S(!0);try{let e=await T.post(`/assets/import`,{assets:D.map(e=>e.asset),source:`manual-import`,source_query:g||`paste`}),t=Number(e?.skipped||0)+k,n=Number(e?.project_conflicts||0);j(s(`assets.bulkImportDone`,{created:Number(e?.created||0),updated:Number(e?.updated||0),skipped:t},`导入完成:新增 ${Number(e?.created||0)} 条,更新 ${Number(e?.updated||0)} 条,跳过 ${t} 条`)),n&&te(s(`assets.importProjectConflicts`,{count:n},`已跳过 ${n} 条归属不同的重复资产。`)),re(),i?.(),r?.()}catch(e){y(M(e,s(`assets.importFailed`,null,`资产入库失败`)))}finally{S(!1)}}},okText:s(`assets.importValidRowsCount`,{count:D.length},`导入 ${D.length} 条有效数据`),okButtonProps:{disabled:!D.length},confirmLoading:x,children:[(0,G.jsx)($,{type:`tertiary`,children:s(`assets.bulkImportSubtitle`,null,`支持 CSV / JSON 文本粘贴或文件上传,提交前会先校验并预览数据`)}),ne&&(0,G.jsx)(a,{type:`danger`,bordered:!0,closeIcon:null,description:ne,className:`asset-library-form-error`}),(0,G.jsxs)(l,{vertical:!0,align:`start`,spacing:10,className:`asset-library-import-body`,children:[(0,G.jsxs)(l,{children:[(0,G.jsx)(h,{type:`button`,value:c,options:[{value:`csv`,label:`CSV`},{value:`json`,label:`JSON`}],onChange:e=>{f(e.target.value),y(``)}}),(0,G.jsx)(u,{icon:(0,G.jsx)(o,{}),onClick:()=>C.current?.click(),children:s(`assets.chooseOrDropFile`,null,`选择文件`)}),(0,G.jsx)(`input`,{ref:C,type:`file`,accept:`.csv,.json,.txt`,className:`asset-library-file-input`,onChange:e=>{A(e.target.files?.[0]),e.target.value=``}}),(0,G.jsx)(u,{theme:`borderless`,onClick:()=>Ke(`asset-import-template.csv`,Z()),children:s(`assets.downloadCsv`,null,`下载 CSV 模板`)}),g&&(0,G.jsx)($,{type:`tertiary`,size:`small`,children:g})]}),(0,G.jsx)(d,{value:p,rows:8,className:`asset-library-import-textarea`,placeholder:c===`csv`?`target,project,tags,host,ip,domain,port,protocol,title,server,country,province,city,responsible_person,department,business_system,environment,criticality,status`:`[{"host":"https://example.com","ip":"1.1.1.1","port":443,"protocol":"https","tags":["prod"]}]`,onChange:e=>{m(e),y(``)}}),E.length>0&&(0,G.jsxs)(`div`,{className:`asset-library-import-preview`,children:[(0,G.jsx)($,{strong:!0,children:s(`assets.importPreviewSummary`,{total:E.length,valid:D.length,invalid:k},`共 ${E.length} 行,${D.length} 行有效,${k} 行需修正`)}),(0,G.jsx)(b,{columns:qe(s),dataSource:E.slice(0,10).map((e,t)=>({...e,id:t})),rowKey:`id`,size:`small`,pagination:!1}),E.length>10&&(0,G.jsx)($,{type:`tertiary`,size:`small`,children:s(`assets.previewLimitedShort`,{count:E.length},`仅展示前 10 行;提交时将处理全部 ${E.length} 行`)})]})]})]})}var{Text:Ye}=c;function Xe({visible:e,assets:t,onClose:n,onDone:r}){let i=w(),o=(0,W.useMemo)(()=>Array.isArray(t)?t:[],[t]),[s,c]=(0,W.useState)(``),[u,d]=(0,W.useState)(``),[f,p]=(0,W.useState)(!1);return(0,W.useEffect)(()=>{e&&(c(o[0]?.id||``),d(``),p(!1))},[e,o]),(0,G.jsxs)(O,{visible:e,title:i(`assets.mergeDuplicates`,null,`合并重复资产`),width:560,onCancel:n,onOk:async()=>{if(!(f||o.length<2)){p(!0),d(``);try{let e=await T.post(`/assets/merge`,{asset_ids:o.map(e=>e.id),primary_id:s||o[0].id});j(`已合并 ${Number(e?.merged||o.length)} 个资产`),r?.(),n?.()}catch(e){d(M(e,`合并资产失败`))}finally{p(!1)}}},okText:i(`assets.merge`,null,`合并`),okButtonProps:{disabled:o.length<2},confirmLoading:f,children:[o.length<2?(0,G.jsx)(a,{type:`warning`,bordered:!0,closeIcon:null,description:i(`assets.mergeRequiresMultiple`,null,`请至少选择两个重复资产`)}):(0,G.jsxs)(l,{vertical:!0,align:`start`,spacing:8,style:{width:`100%`},children:[(0,G.jsx)(Ye,{type:`tertiary`,children:i(`assets.mergeHint`,null,`将保留一个主资产,其余资产的空字段与标签会合并进来,然后删除被合并记录。所选资产必须共享域名、IP 或 Host。`)}),(0,G.jsx)(h,{value:s,onChange:e=>c(e.target.value),children:(0,G.jsx)(l,{vertical:!0,align:`start`,spacing:4,children:o.map(e=>(0,G.jsxs)(v,{value:e.id,children:[R(e),e.project_name?` · ${e.project_name}`:``]},e.id))})})]}),u&&(0,G.jsx)(a,{type:`danger`,bordered:!0,closeIcon:null,description:u,className:`asset-library-form-error`})]})}var{Text:Ze}=c;function Qe({visible:e,projects:t,assetIds:n,onClose:r,onDone:i}){let o=w(),[s,c]=(0,W.useState)(``),[u,d]=(0,W.useState)(!1),[f,m]=(0,W.useState)(``),[h,g]=(0,W.useState)(!1),_=(0,W.useMemo)(()=>Array.isArray(n)?n:[],[n]),v=(0,W.useMemo)(()=>(t||[]).map(e=>({value:e.id,label:e.name||e.id})),[t]);return(0,W.useEffect)(()=>{e&&(c(``),d(!1),m(``),g(!1))},[e]),(0,G.jsxs)(O,{visible:e,title:o(`assets.bindProjectTitle`,null,`绑定项目`),width:520,onCancel:r,onOk:async()=>{if(!h&&_.length){if(!u&&!s)m(o(`assets.selectProjectRequired`,null,`请选择要绑定的项目`));else{g(!0),m(``);try{await T.put(`/assets/project-binding`,{asset_ids:_,project_id:u?``:s}),j(o(`assets.bindProjectDone`,{count:_.length},`已更新 ${_.length} 个资产`)),i?.(),r?.()}catch(e){m(M(e,o(`assets.bindProjectFailed`,null,`绑定项目失败`)))}finally{g(!1)}}}},okText:u?o(`assets.unbindProject`,null,`解除绑定`):o(`assets.confirmBinding`,null,`确认绑定`),confirmLoading:h,children:[(0,G.jsxs)(l,{vertical:!0,align:`start`,spacing:10,style:{width:`100%`},children:[(0,G.jsx)(Ze,{type:`tertiary`,children:o(`assets.bindProjectCount`,{count:_.length},`将更新 ${_.length} 个资产`)}),(0,G.jsx)(S,{value:s||void 0,optionList:v,filter:!0,showClear:!0,disabled:u,placeholder:o(`assets.chooseProject`,null,`请选择项目`),onChange:e=>c(e||``),style:{width:`100%`}}),(0,G.jsxs)(l,{children:[(0,G.jsx)(p,{checked:u,onChange:d,size:`small`}),(0,G.jsx)(Ze,{size:`small`,children:o(`assets.unbindProject`,null,`解除项目绑定`)})]}),(0,G.jsx)(Ze,{type:`tertiary`,size:`small`,children:o(`assets.bindProjectHint`,null,`所选资产将统一更新为该项目归属。`)})]}),f&&(0,G.jsx)(a,{type:`danger`,bordered:!0,closeIcon:null,description:f,className:`asset-library-form-error`})]})}var{Text:$e}=c,et={status:``,environment:``,criticality:``,responsible_person:``,department:``,business_system:``,add_tags:``,remove_tags:``};function tt({visible:e,assetIds:t,onClose:n,onDone:r}){let i=w(),[o,s]=(0,W.useState)(et),[c,l]=(0,W.useState)(``),[u,d]=(0,W.useState)(!1),p=(0,W.useMemo)(()=>Array.isArray(t)?t:[],[t]);(0,W.useEffect)(()=>{e&&(s(et),l(``),d(!1))},[e]);let m=e=>s(t=>({...t,...e}));return(0,G.jsxs)(O,{visible:e,title:i(`assets.bulkEdit`,null,`批量编辑`),width:620,onCancel:n,onOk:async()=>{if(u||!p.length)return;let e={asset_ids:p};[`status`,`environment`,`criticality`,`responsible_person`,`department`,`business_system`].forEach(t=>{let n=String(o[t]||``).trim();n&&(e[t]=n)});let t=I(o.add_tags),i=I(o.remove_tags);if(t.length&&(e.add_tags=t),i.length&&(e.remove_tags=i),Object.keys(e).length===1)l(`请至少填写一项需要修改的内容`);else{d(!0),l(``);try{let t=await T.put(`/assets/bulk`,e);j(`已更新 ${Number(t?.updated||p.length)} 个资产`),r?.(),n?.()}catch(e){l(M(e,`批量编辑失败`))}finally{d(!1)}}},confirmLoading:u,children:[(0,G.jsxs)($e,{type:`tertiary`,children:[`将修改 `,p.length,` 个资产;空白字段保持原值。`]}),(0,G.jsxs)(`div`,{className:`asset-library-form-grid asset-library-form-grid--bulk`,children:[(0,G.jsx)(S,{value:o.status||void 0,placeholder:i(`assets.status`,null,`状态`),optionList:fe,showClear:!0,onChange:e=>m({status:e||``})}),(0,G.jsx)(S,{value:o.environment||void 0,placeholder:i(`assets.environment`,null,`环境`),optionList:N,showClear:!0,onChange:e=>m({environment:e||``})}),(0,G.jsx)(S,{value:o.criticality||void 0,placeholder:i(`assets.criticality`,null,`重要性`),optionList:Te,showClear:!0,onChange:e=>m({criticality:e||``})}),(0,G.jsx)(f,{value:o.responsible_person,placeholder:i(`assets.responsiblePerson`,null,`负责人`),onChange:e=>m({responsible_person:e})}),(0,G.jsx)(f,{value:o.department,placeholder:i(`assets.department`,null,`部门`),onChange:e=>m({department:e})}),(0,G.jsx)(f,{value:o.business_system,placeholder:i(`assets.businessSystem`,null,`业务系统`),onChange:e=>m({business_system:e})}),(0,G.jsx)(f,{value:o.add_tags,placeholder:`追加标签(逗号分隔)`,onChange:e=>m({add_tags:e})}),(0,G.jsx)(f,{value:o.remove_tags,placeholder:`移除标签(逗号分隔)`,onChange:e=>m({remove_tags:e})})]}),c&&(0,G.jsx)(a,{type:`danger`,bordered:!0,closeIcon:null,description:c,className:`asset-library-form-error`})]})}function nt(){let{data:e,loading:t,error:n,reload:r}=E(rt,[]);return{projects:e||[],loading:t,error:n,reload:r}}async function rt(){let e=[],t;do{let n=await T.get(`/projects`,{limit:500,offset:e.length}),r=n?.projects||[];if(e.push(...r),r.length<500)break;t=Number(n?.total||e.length)}while(e.length({project_id:e,project_unassigned:t===`unassigned`||void 0}),[e,t]),[_,v]=(0,W.useState)(()=>({...Ne(),q:r.get(`q`)||``})),[y,b]=(0,W.useState)(1),[S,C]=(0,W.useState)(20),[O,k]=(0,W.useState)({keys:[],rows:[]}),A=(0,W.useRef)(0),[oe,M]=(0,W.useState)(null),[le,ue]=(0,W.useState)(!1),[de,fe]=(0,W.useState)(null),[pe,me]=(0,W.useState)(!1),[he,ge]=(0,W.useState)(!1),[_e,ve]=(0,W.useState)(!1),[ye,be]=(0,W.useState)(!1),[xe,Se]=(0,W.useState)(!1),N=ie(_,300),P=(0,W.useMemo)(()=>({...at(N,y,S),...g}),[N,y,S,g]),{data:F,loading:I,error:Ce,reload:we}=E(()=>T.get(`/assets`,P),[P,d],{skip:!d}),{projects:L,loading:Te,error:R,reload:Ee}=n,De=(0,W.useMemo)(()=>Array.isArray(F?.assets)?F.assets:[],[F]),z=Ce?0:Number(F?.total||0),B=I||N!==_,V=[{value:`all`,label:s(`assets.scopeAll`,null,`全部资产`)},{value:`unassigned`,label:s(`assets.scopeUnassigned`,null,`未归属项目`)},...L.map(e=>({value:`project:${e.id}`,label:ce(e,s)}))];e&&!V.some(e=>e.value===t)&&V.push({value:t,label:e});let Oe=V.find(e=>e.value===t)?.label,H=(0,W.useRef)(``);(0,W.useEffect)(()=>()=>{A.current+=1},[]),(0,W.useEffect)(()=>{if(!h){H.current=``,M(null);return}if(!d||h===H.current)return;let e=!1;return T.get(`/assets`,{...g,id:h,page_size:1}).then(t=>{e||(H.current=h,M(t?.assets?.find(e=>e.id===h)||null))}).catch(t=>{e||D(t,s(`assets.loadFailed`,null,`加载资产失败`))}),()=>{e=!0}},[d,h,g,s]);let ke=e=>{if(e===t)return;let n=new URLSearchParams;e?.startsWith(`project:`)?n.set(`project_id`,e.slice(8)):e&&n.set(`scope`,e),i(n)},U=()=>{A.current+=1,k({keys:[],rows:[]})},Ae=e=>{v(t=>({...t,...e})),b(1),U()},Me=()=>{v(Ne()),b(1),U()},K=()=>{U(),we(),Ee()},q=e=>{let t=new URLSearchParams(r);e?t.set(`id`,e):t.delete(`id`),i(t,{replace:!0})},Le=e=>{H.current=e.id,M(e),e?.id&&q(e.id)},J=()=>{M(null),h&&(H.current=``,q(``))},Re=e=>{fe(e||null),ue(!0),f&&Ee()},Y=async()=>{U(),await we()},X=async e=>{await T.del(`/assets/${encodeURIComponent(e.id)}`),j(s(`assets.deleted`,null,`资产已删除`)),oe?.id===e.id&&J(),await Y()},ze=()=>{let e=O.keys;e.length&&se({title:s(`assets.deleteConfirm`,null,`确定删除所选资产吗?`),content:s(`assets.scopedDeleteConfirm`,{count:e.length,project:O.rows[0]?.project_name||O.rows[0]?.project_id||s(`assets.scopeUnassigned`,null,`未归属项目`)},`将永久删除所选的 ${e.length} 个资产。`),okText:s(`common.delete`,null,`删除`),onOk:async()=>{try{let t=await T.post(`/assets/batch-delete`,{asset_ids:e});j(`已删除 ${Number(t?.deleted||e.length)} 个资产`),await Y()}catch(e){D(e,`批量删除失败`)}}})},Be=(0,W.useMemo)(()=>{let{page:e,page_size:t,...n}=P;return n},[P]),Ve=async()=>{let e=++A.current;try{let t=await T.get(`/assets/selection`,Be);if(e!==A.current)return;let n=Array.isArray(t?.assets)?t.assets:[];k({keys:n.map(e=>e.id),rows:n}),j(s(`assets.allResultsSelected`,{count:n.length},`已选择 ${n.length} 项`))}catch(t){e===A.current&&D(t,`选择全部结果失败`)}},He=async e=>{if(!xe){Se(!0);try{let t=O.rows;if(e){let e=await T.get(`/assets/selection`,Be);t=Array.isArray(e?.assets)?e.assets:[]}else t.length||(t=De);if(!t.length){te(`没有可导出的资产`);return}Ke(`assets-${new Date().toISOString().slice(0,10)}.csv`,Ge(t)),j(`已导出 ${t.length} 个资产`)}catch(e){D(e,`导出失败`)}finally{Se(!1)}}},Ue=(e,t)=>{A.current+=1,k({keys:e||[],rows:t||[]})},Z=O.keys.length,We=new Set(O.rows.map(e=>e.project_id||``)).size>1,Q=Z>0&&!B&&!We;return d?(0,G.jsxs)(`div`,{className:`asset-library-page`,children:[(0,G.jsx)(ae,{title:s(`assets.libraryTitle`,null,`资产库`),extra:(0,G.jsxs)(l,{children:[(0,G.jsx)(u,{icon:(0,G.jsx)(x,{}),onClick:K,loading:I,children:s(`common.refresh`,null,`刷新`)}),f&&(0,G.jsx)(u,{icon:(0,G.jsx)(o,{}),onClick:()=>me(!0),children:s(`assets.bulkImport`,null,`批量导入`)}),f&&(0,G.jsx)(u,{theme:`solid`,type:`primary`,icon:(0,G.jsx)(m,{}),onClick:()=>Re(null),children:s(`assets.addAsset`,null,`新增资产`)})]})}),(0,G.jsxs)(re,{title:s(`assets.filterTitle`,null,`筛选条件`),children:[(0,G.jsx)(Pe,{scope:{value:t,options:V,loading:Te,onChange:ke},filters:_,onChange:Ae,onReset:Me}),(0,G.jsx)(ne,{error:R,onRetry:Ee})]}),(0,G.jsx)(ne,{error:Ce,onRetry:K}),(0,G.jsxs)(re,{title:`${Oe}(${z})`,extra:(0,G.jsxs)(l,{children:[(0,G.jsx)(u,{theme:`borderless`,disabled:!Z,onClick:U,children:s(`assets.clearSelection`,null,`清除选择`)}),(0,G.jsx)(u,{theme:`borderless`,disabled:B||!z,onClick:()=>He(!1),loading:xe,children:s(`assets.exportCsv`,null,`导出 CSV`)}),(0,G.jsx)(u,{theme:`borderless`,disabled:B||!z,onClick:()=>He(!0),loading:xe,children:s(`assets.exportAll`,null,`导出全部筛选结果`)})]}),children:[(0,G.jsxs)(`div`,{className:`asset-library-toolbar`,children:[(0,G.jsxs)(l,{children:[(0,G.jsx)(it,{type:`tertiary`,children:Z?s(`assets.selectedCount`,{count:Z},`已选择 ${Z} 项`):s(`assets.selectedCount`,{count:0},`已选择 0 项`)}),(0,G.jsx)(u,{theme:`borderless`,size:`small`,disabled:B||!z,onClick:Ve,children:s(`assets.selectAllResults`,{count:z},`选择全部 ${z} 项`)})]}),(0,G.jsxs)(l,{children:[f&&(0,G.jsx)(u,{size:`small`,disabled:!Q||Z<2||!p,onClick:()=>ge(!0),children:s(`assets.mergeDuplicates`,null,`合并重复资产`)}),f&&(0,G.jsx)(u,{size:`small`,disabled:!Q,onClick:()=>ve(!0),children:s(`assets.bindProject`,null,`绑定项目`)}),f&&(0,G.jsx)(u,{size:`small`,disabled:!Q,onClick:()=>be(!0),children:s(`assets.bulkEdit`,null,`批量编辑`)}),p&&(0,G.jsx)(u,{size:`small`,type:`danger`,disabled:!Q,onClick:ze,children:s(`assets.batchDelete`,null,`批量删除…`)})]})]}),We&&(f||p)&&(0,G.jsx)(it,{type:`tertiary`,size:`small`,children:s(`assets.mixedProjectSelection`,null,`批量修改前,请将选择缩小到同一项目或仅选择未归属资产。`)}),(0,G.jsx)(Fe,{assets:B||Ce?[]:De,loading:B,total:z,page:y,pageSize:S,onPageChange:e=>{b(e),U()},onPageSizeChange:e=>{C(e),b(1),U()},selectedRowKeys:O.keys,onSelectionChange:Ue,onView:Le,onEdit:Re,onDelete:X,onRefresh:K,canWrite:f,canDelete:p})]}),(0,G.jsx)(Ie,{asset:oe,visible:!!oe,onClose:J,onEdit:e=>{J(),Re(e)},onDelete:e=>{se({title:s(`assets.deleteConfirm`,null,`确定删除该资产吗?`),content:e.host||e.domain||e.ip,okText:s(`common.delete`,null,`删除`),onOk:()=>X(e).catch(e=>D(e,s(`assets.deleteFailed`,null,`删除资产失败`)))})},canWrite:f,canDelete:p}),(0,G.jsx)(je,{visible:le,asset:de,defaultProjectId:e,projects:L,onClose:()=>ue(!1),onSaved:Y}),(0,G.jsx)(Je,{visible:pe,defaultProjectId:t===`all`?void 0:e,projects:L,onClose:()=>me(!1),onDone:Y}),(0,G.jsx)(Xe,{visible:he,assets:O.rows,onClose:()=>ge(!1),onDone:Y}),(0,G.jsx)(Qe,{visible:_e,projects:L,assetIds:O.keys,onClose:()=>ve(!1),onDone:Y}),(0,G.jsx)(tt,{visible:ye,assetIds:O.keys,onClose:()=>be(!1),onDone:Y})]}):(0,G.jsxs)(`div`,{className:`asset-library-page`,children:[(0,G.jsx)(ae,{title:s(`assets.libraryTitle`,null,`资产库`),description:`资产列表、批量操作与导入需要资产读取权限。`}),(0,G.jsx)(a,{type:`warning`,bordered:!0,closeIcon:null,description:s(`assets.readDenied`,null,`当前账号没有 asset:read 权限,无法读取资产库;请联系管理员授权。`)})]})}export{at as buildAssetQuery,ot as default}; \ No newline at end of file diff --git a/web/static/app/assets/asset-overview-xwryoaKx.js b/web/static/app/assets/asset-overview-ClxkP_Uu.js similarity index 98% rename from web/static/app/assets/asset-overview-xwryoaKx.js rename to web/static/app/assets/asset-overview-ClxkP_Uu.js index e77b628c..57a5facf 100644 --- a/web/static/app/assets/asset-overview-xwryoaKx.js +++ b/web/static/app/assets/asset-overview-ClxkP_Uu.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r}from"./react-QV7DAAIx.js";import{B as i,E as a,G as o,I as s,R as c,g as l,h as u,lt as d,tn as f,ut as p}from"./semi-65W_4I1v.js";import{A as m,D as h,F as g,I as _,L as v,_ as y,a as b,l as x,m as S,p as C,s as w}from"./index-CAEPLS-g.js";import{a as T,n as E,r as D}from"./AssetBits-DtqSAj0f.js";import{r as O}from"./assetTarget-D2PEjBAg.js";var k=e(t(),1),A=e(r(),1),{Text:j}=o,M=[{value:7,label:`7 天`},{value:30,label:`30 天`},{value:90,label:`90 天`}];function N(e,t){let n=Number(e||0),r=Number(t||0);return r?Math.round(n/r*1e3)/10:0}function P(){let e=g(),t=n(),{hasPermission:r,hasAnyPermission:o}=_(),P=r(`asset:read`),F=o([`asset:read`,`fofa:execute`]),[I,L]=(0,k.useState)(30),R=b(()=>v.get(`/assets/stats`,{days:I}),[I],{skip:!P}),z=b(()=>v.get(`/assets`,{page:1,page_size:10,sort_by:`last_seen_at`,sort_order:`desc`}),[],{skip:!P}),B=R.data||{},V=B.coverage||{},H=Array.isArray(B.protocols)?B.protocols:[],U=(0,k.useMemo)(()=>H.reduce((e,t)=>e+Number(t.count||0),0),[H]),W=Array.isArray(z.data?.assets)?z.data.assets:[],G=[{id:`total`,label:e(`assets.totalAssets`,null,`资产总数`),value:h(B.total||0),detail:e(`assets.totalAssetsHint`,null,`当前纳入持续监测的资产`),loading:R.loading},{id:`ips`,label:e(`assets.ipCount`,null,`IP 数量`),value:h(B.ips||0),loading:R.loading},{id:`domains`,label:e(`assets.domainCount`,null,`域名数量`),value:h(B.domains||0),loading:R.loading},{id:`ports`,label:e(`assets.portCount`,null,`端口数量`),value:h(B.ports||0),loading:R.loading},{id:`protocols`,label:e(`assets.serviceTypes`,null,`服务类型`),value:h(H.length),detail:H[0]?`${e(`assets.topProtocol`,null,`主要协议`)}:${H[0].name}`:void 0,loading:R.loading},{id:`recent`,label:e(`assets.recentCount`,null,`近 7 天发现`),value:h(B.recent||0),detail:e(`assets.recentShare`,{percent:N(B.recent,B.total)},`占当前资产总量的 ${N(B.recent,B.total)}%`),loading:R.loading}],K=e=>{let n=new URLSearchParams({id:e.id});e.project_id?n.set(`project_id`,e.project_id):n.set(`scope`,`unassigned`),t(`/asset-library?${n}`)},q=[{title:e(`assets.target`,null,`目标`),dataIndex:`host`,render:(e,t)=>(0,A.jsxs)(`div`,{className:`asset-overview-target`,children:[(0,A.jsx)(T,{text:O(t),max:34}),(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:[t.ip,t.domain].filter(Boolean).join(` · `)||`—`})]})},{title:e(`assets.service`,null,`服务`),dataIndex:`protocol`,width:150,render:(e,t)=>(0,A.jsx)(E,{protocol:t.protocol,port:t.port})},{title:e(`assets.source`,null,`来源`),dataIndex:`source`,width:120,render:e=>(0,A.jsx)(T,{text:e,max:14})},{title:e(`assets.riskLevel`,null,`风险等级`),dataIndex:`risk_level`,width:120,render:(e,t)=>(0,A.jsx)(D,{asset:t})},{title:e(`assets.lastSeen`,null,`最近发现`),dataIndex:`last_seen_at`,width:130,render:t=>(0,A.jsx)(j,{size:`small`,children:m(t,e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:100,render:(t,n)=>(0,A.jsx)(c,{theme:`borderless`,size:`small`,onClick:()=>K(n),children:e(`common.view`,null,`查看`)})}],J=[{label:e(`assets.scannedAssets`,null,`已扫描资产`),value:h(V.scanned||0)},{label:e(`assets.recentlyScanned`,null,`近 30 天覆盖`),value:h(V.scanned_30d||0)},{label:e(`assets.neverScanned`,null,`从未扫描`),value:h(V.never_scanned||0)},{label:e(`assets.staleScans`,null,`超过 30 天未扫描`),value:h(V.stale||0)}];return(0,A.jsxs)(`div`,{className:`asset-overview-page`,children:[(0,A.jsx)(C,{title:e(`assets.overviewTitle`,null,`资产概览`),description:`汇总资产规模、服务类型、扫描覆盖与最近发现情况。`,extra:(0,A.jsxs)(s,{children:[(0,A.jsx)(u,{type:`button`,value:I,options:M,onChange:e=>L(Number(e.target.value)||30)}),(0,A.jsx)(c,{icon:(0,A.jsx)(p,{}),onClick:()=>{R.reload(),z.reload()},children:e(`common.refresh`,null,`刷新`)}),(0,A.jsx)(c,{icon:(0,A.jsx)(f,{}),onClick:()=>t(`/asset-library`),children:e(`assets.viewLibrary`,null,`查看资产库`)}),F&&(0,A.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,A.jsx)(d,{}),onClick:()=>t(`/info-collect`),children:e(`nav.infoCollect`,null,`信息收集`)})]})}),!P&&(0,A.jsx)(i,{type:`warning`,bordered:!0,closeIcon:null,description:e(`assets.readDenied`,null,`当前账号没有 asset:read 权限,无法读取资产统计;请联系管理员授权。`)}),P&&(0,A.jsx)(x,{error:R.error,onRetry:()=>R.reload()}),P&&(0,A.jsx)(y,{metrics:G,columns:6}),P&&(0,A.jsxs)(`div`,{className:`asset-overview-columns`,children:[(0,A.jsx)(S,{className:`asset-overview-card`,title:e(`assets.protocolDistribution`,null,`协议分布`),description:e(`assets.protocolDistributionHint`,null,`按已识别服务查看资产暴露构成`),extra:(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:e(`assets.protocolKinds`,{count:H.length},`${H.length} 种协议`)}),children:H.length===0?(0,A.jsx)(a,{title:e(`common.noData`,null,`暂无数据`),description:null,style:{padding:24}}):(0,A.jsx)(`div`,{className:`asset-overview-bars`,children:H.map(e=>{let t=N(e.count,B.total||U);return(0,A.jsxs)(`div`,{className:`asset-overview-bar-row`,children:[(0,A.jsx)(j,{size:`small`,className:`asset-overview-bar-label`,children:e.name||`unknown`}),(0,A.jsx)(l,{percent:t,showInfo:!1,stroke:`var(--semi-color-primary)`}),(0,A.jsxs)(j,{type:`tertiary`,size:`small`,className:`asset-overview-bar-value`,children:[h(e.count||0),` · `,t,`%`]})]},e.name)})})}),(0,A.jsx)(S,{className:`asset-overview-card`,title:e(`assets.scanCoverage`,null,`扫描覆盖`),description:e(`assets.scanCoverageHint`,null,`识别未扫描与长期未复查的资产缺口`),extra:(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:e(`assets.coverageMeta`,{scanned:V.scanned||0,total:B.total||0},`${V.scanned||0} / ${B.total||0} 已覆盖`)}),children:(0,A.jsxs)(`div`,{className:`asset-overview-coverage`,children:[(0,A.jsxs)(`div`,{className:`asset-overview-coverage-main`,children:[(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:e(`assets.overallCoverage`,null,`总体覆盖率`)}),(0,A.jsx)(l,{percent:Number(V.rate||0),stroke:Number(V.rate||0)>=80?`var(--semi-color-success)`:void 0,format:e=>`${e}%`})]}),(0,A.jsx)(`div`,{className:`asset-overview-coverage-grid`,children:J.map(e=>(0,A.jsxs)(`div`,{className:`asset-overview-coverage-item`,children:[(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:e.label}),(0,A.jsx)(j,{strong:!0,children:e.value})]},e.label))})]})}),(0,A.jsx)(S,{className:`asset-overview-card`,title:`观察覆盖`,description:`有成功回执的测评观察,或带成功工具回执的已确认项目事实。同一资产只计一次,不替代上面的扫描覆盖。`,extra:(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:`${B.observation?.observed||0} / ${B.observation?.total||B.total||0}`}),children:(0,A.jsxs)(`div`,{className:`asset-overview-coverage`,children:[(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:`已有观察证据`}),(0,A.jsx)(l,{percent:Number(B.observation?.rate||0),format:e=>`${e}%`})]})})]}),P&&(0,A.jsxs)(S,{title:e(`assets.recentAssets`,null,`最近资产`),description:`按最近发现时间排列的前 10 条资产。`,extra:(0,A.jsx)(c,{theme:`borderless`,onClick:()=>t(`/asset-library`),children:e(`assets.viewLibrary`,null,`查看资产库`)}),children:[(0,A.jsx)(x,{error:z.error,onRetry:()=>z.reload()}),(0,A.jsx)(w,{columns:q,dataSource:W,loading:z.loading,rowKey:`id`,pagination:!1,onRefresh:()=>z.reload(),emptyText:e(`common.noData`,null,`暂无数据`)})]})]})}export{P as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r}from"./react-QV7DAAIx.js";import{B as i,E as a,G as o,I as s,R as c,g as l,h as u,lt as d,tn as f,ut as p}from"./semi-65W_4I1v.js";import{A as m,D as h,F as g,I as _,L as v,_ as y,a as b,l as x,m as S,p as C,s as w}from"./index-DNMXun-U.js";import{a as T,n as E,r as D}from"./AssetBits-DtqSAj0f.js";import{r as O}from"./assetTarget-D2PEjBAg.js";var k=e(t(),1),A=e(r(),1),{Text:j}=o,M=[{value:7,label:`7 天`},{value:30,label:`30 天`},{value:90,label:`90 天`}];function N(e,t){let n=Number(e||0),r=Number(t||0);return r?Math.round(n/r*1e3)/10:0}function P(){let e=g(),t=n(),{hasPermission:r,hasAnyPermission:o}=_(),P=r(`asset:read`),F=o([`asset:read`,`fofa:execute`]),[I,L]=(0,k.useState)(30),R=b(()=>v.get(`/assets/stats`,{days:I}),[I],{skip:!P}),z=b(()=>v.get(`/assets`,{page:1,page_size:10,sort_by:`last_seen_at`,sort_order:`desc`}),[],{skip:!P}),B=R.data||{},V=B.coverage||{},H=Array.isArray(B.protocols)?B.protocols:[],U=(0,k.useMemo)(()=>H.reduce((e,t)=>e+Number(t.count||0),0),[H]),W=Array.isArray(z.data?.assets)?z.data.assets:[],G=[{id:`total`,label:e(`assets.totalAssets`,null,`资产总数`),value:h(B.total||0),detail:e(`assets.totalAssetsHint`,null,`当前纳入持续监测的资产`),loading:R.loading},{id:`ips`,label:e(`assets.ipCount`,null,`IP 数量`),value:h(B.ips||0),loading:R.loading},{id:`domains`,label:e(`assets.domainCount`,null,`域名数量`),value:h(B.domains||0),loading:R.loading},{id:`ports`,label:e(`assets.portCount`,null,`端口数量`),value:h(B.ports||0),loading:R.loading},{id:`protocols`,label:e(`assets.serviceTypes`,null,`服务类型`),value:h(H.length),detail:H[0]?`${e(`assets.topProtocol`,null,`主要协议`)}:${H[0].name}`:void 0,loading:R.loading},{id:`recent`,label:e(`assets.recentCount`,null,`近 7 天发现`),value:h(B.recent||0),detail:e(`assets.recentShare`,{percent:N(B.recent,B.total)},`占当前资产总量的 ${N(B.recent,B.total)}%`),loading:R.loading}],K=e=>{let n=new URLSearchParams({id:e.id});e.project_id?n.set(`project_id`,e.project_id):n.set(`scope`,`unassigned`),t(`/asset-library?${n}`)},q=[{title:e(`assets.target`,null,`目标`),dataIndex:`host`,render:(e,t)=>(0,A.jsxs)(`div`,{className:`asset-overview-target`,children:[(0,A.jsx)(T,{text:O(t),max:34}),(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:[t.ip,t.domain].filter(Boolean).join(` · `)||`—`})]})},{title:e(`assets.service`,null,`服务`),dataIndex:`protocol`,width:150,render:(e,t)=>(0,A.jsx)(E,{protocol:t.protocol,port:t.port})},{title:e(`assets.source`,null,`来源`),dataIndex:`source`,width:120,render:e=>(0,A.jsx)(T,{text:e,max:14})},{title:e(`assets.riskLevel`,null,`风险等级`),dataIndex:`risk_level`,width:120,render:(e,t)=>(0,A.jsx)(D,{asset:t})},{title:e(`assets.lastSeen`,null,`最近发现`),dataIndex:`last_seen_at`,width:130,render:t=>(0,A.jsx)(j,{size:`small`,children:m(t,e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:100,render:(t,n)=>(0,A.jsx)(c,{theme:`borderless`,size:`small`,onClick:()=>K(n),children:e(`common.view`,null,`查看`)})}],J=[{label:e(`assets.scannedAssets`,null,`已扫描资产`),value:h(V.scanned||0)},{label:e(`assets.recentlyScanned`,null,`近 30 天覆盖`),value:h(V.scanned_30d||0)},{label:e(`assets.neverScanned`,null,`从未扫描`),value:h(V.never_scanned||0)},{label:e(`assets.staleScans`,null,`超过 30 天未扫描`),value:h(V.stale||0)}];return(0,A.jsxs)(`div`,{className:`asset-overview-page`,children:[(0,A.jsx)(C,{title:e(`assets.overviewTitle`,null,`资产概览`),description:`汇总资产规模、服务类型、扫描覆盖与最近发现情况。`,extra:(0,A.jsxs)(s,{children:[(0,A.jsx)(u,{type:`button`,value:I,options:M,onChange:e=>L(Number(e.target.value)||30)}),(0,A.jsx)(c,{icon:(0,A.jsx)(p,{}),onClick:()=>{R.reload(),z.reload()},children:e(`common.refresh`,null,`刷新`)}),(0,A.jsx)(c,{icon:(0,A.jsx)(f,{}),onClick:()=>t(`/asset-library`),children:e(`assets.viewLibrary`,null,`查看资产库`)}),F&&(0,A.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,A.jsx)(d,{}),onClick:()=>t(`/info-collect`),children:e(`nav.infoCollect`,null,`信息收集`)})]})}),!P&&(0,A.jsx)(i,{type:`warning`,bordered:!0,closeIcon:null,description:e(`assets.readDenied`,null,`当前账号没有 asset:read 权限,无法读取资产统计;请联系管理员授权。`)}),P&&(0,A.jsx)(x,{error:R.error,onRetry:()=>R.reload()}),P&&(0,A.jsx)(y,{metrics:G,columns:6}),P&&(0,A.jsxs)(`div`,{className:`asset-overview-columns`,children:[(0,A.jsx)(S,{className:`asset-overview-card`,title:e(`assets.protocolDistribution`,null,`协议分布`),description:e(`assets.protocolDistributionHint`,null,`按已识别服务查看资产暴露构成`),extra:(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:e(`assets.protocolKinds`,{count:H.length},`${H.length} 种协议`)}),children:H.length===0?(0,A.jsx)(a,{title:e(`common.noData`,null,`暂无数据`),description:null,style:{padding:24}}):(0,A.jsx)(`div`,{className:`asset-overview-bars`,children:H.map(e=>{let t=N(e.count,B.total||U);return(0,A.jsxs)(`div`,{className:`asset-overview-bar-row`,children:[(0,A.jsx)(j,{size:`small`,className:`asset-overview-bar-label`,children:e.name||`unknown`}),(0,A.jsx)(l,{percent:t,showInfo:!1,stroke:`var(--semi-color-primary)`}),(0,A.jsxs)(j,{type:`tertiary`,size:`small`,className:`asset-overview-bar-value`,children:[h(e.count||0),` · `,t,`%`]})]},e.name)})})}),(0,A.jsx)(S,{className:`asset-overview-card`,title:e(`assets.scanCoverage`,null,`扫描覆盖`),description:e(`assets.scanCoverageHint`,null,`识别未扫描与长期未复查的资产缺口`),extra:(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:e(`assets.coverageMeta`,{scanned:V.scanned||0,total:B.total||0},`${V.scanned||0} / ${B.total||0} 已覆盖`)}),children:(0,A.jsxs)(`div`,{className:`asset-overview-coverage`,children:[(0,A.jsxs)(`div`,{className:`asset-overview-coverage-main`,children:[(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:e(`assets.overallCoverage`,null,`总体覆盖率`)}),(0,A.jsx)(l,{percent:Number(V.rate||0),stroke:Number(V.rate||0)>=80?`var(--semi-color-success)`:void 0,format:e=>`${e}%`})]}),(0,A.jsx)(`div`,{className:`asset-overview-coverage-grid`,children:J.map(e=>(0,A.jsxs)(`div`,{className:`asset-overview-coverage-item`,children:[(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:e.label}),(0,A.jsx)(j,{strong:!0,children:e.value})]},e.label))})]})}),(0,A.jsx)(S,{className:`asset-overview-card`,title:`观察覆盖`,description:`有成功回执的测评观察,或带成功工具回执的已确认项目事实。同一资产只计一次,不替代上面的扫描覆盖。`,extra:(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:`${B.observation?.observed||0} / ${B.observation?.total||B.total||0}`}),children:(0,A.jsxs)(`div`,{className:`asset-overview-coverage`,children:[(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:`已有观察证据`}),(0,A.jsx)(l,{percent:Number(B.observation?.rate||0),format:e=>`${e}%`})]})})]}),P&&(0,A.jsxs)(S,{title:e(`assets.recentAssets`,null,`最近资产`),description:`按最近发现时间排列的前 10 条资产。`,extra:(0,A.jsx)(c,{theme:`borderless`,onClick:()=>t(`/asset-library`),children:e(`assets.viewLibrary`,null,`查看资产库`)}),children:[(0,A.jsx)(x,{error:z.error,onRetry:()=>z.reload()}),(0,A.jsx)(w,{columns:q,dataSource:W,loading:z.loading,rowKey:`id`,pagination:!1,onRefresh:()=>z.reload(),emptyText:e(`common.noData`,null,`暂无数据`)})]})]})}export{P as default}; \ No newline at end of file diff --git a/web/static/app/assets/c2-events-b_BWiEV4.js b/web/static/app/assets/c2-events-Cdd7cKs8.js similarity index 95% rename from web/static/app/assets/c2-events-b_BWiEV4.js rename to web/static/app/assets/c2-events-Cdd7cKs8.js index 296d20cf..b7396a2c 100644 --- a/web/static/app/assets/c2-events-b_BWiEV4.js +++ b/web/static/app/assets/c2-events-Cdd7cKs8.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,N as a,R as o,U as s,p as c,ut as ee,y as l}from"./semi-65W_4I1v.js";import{E as te,F as ne,I as u,_ as d,a as f,b as p,l as m,m as h,p as re,r as g,s as ie,u as ae,x as _,y as v}from"./index-CAEPLS-g.js";import{c as oe,v as y}from"./c2-shared-Car3lDYq.js";import{g as b,m as x,n as S,p as C,r as w,t as T}from"./c2-shared-D-8kBzuC.js";var E=e(t(),1),D=e(n(),1),{Text:O}=r;function k(){let e=ne(),{hasPermission:t}=u(),n=t(`c2:delete`)||t(`c2:write`),[r,k]=(0,E.useState)(1),[A,se]=(0,E.useState)(20),[j,M]=(0,E.useState)(``),[N,P]=(0,E.useState)(``),[F,I]=(0,E.useState)(`24h`),[L,R]=(0,E.useState)(``),[z,B]=(0,E.useState)(``),[V,H]=(0,E.useState)([]),[U,W]=(0,E.useState)(null),G=(0,E.useMemo)(()=>({page:r,page_size:A,level:j||void 0,category:N||void 0,session_id:z||void 0,since:b(F)||void 0}),[r,A,j,N,z,F]),{data:K,loading:q,error:ce,reload:J}=f(()=>y(G),[G]),Y=Array.isArray(K?.events)?K.events:[],X=Number(K?.total??Y.length),Z=K?.level_counts||{};g(()=>J({silent:!0}),5e3);let Q=()=>{B(L.trim()),k(1),H([])},le=()=>{M(``),P(``),I(`24h`),R(``),B(``),k(1),H([])},ue=[{id:`total`,label:e(`c2.events.statTotal`,null,`当前筛选`),value:X},{id:`info`,label:e(`c2.events.info`,null,`信息`),value:Z.info||0},{id:`warn`,label:e(`c2.events.warn`,null,`警告`),value:Z.warn||0,tone:`warning`},{id:`critical`,label:e(`c2.events.critical`,null,`严重`),value:Z.critical||0,tone:`danger`}],$=t=>{v({title:e(`c2.events.batchDelete`,null,`删除事件`),content:t.length>1?e(`c2.events.confirmBatchDelete`,null,`确定删除选中的事件吗?此操作不可恢复。`).replace(`{{n}}`,String(t.length)):e(`c2.events.confirmDeleteOne`,null,`确定删除该条事件吗?此操作不可恢复。`),onOk:async()=>{try{let n=await oe(t);_(e(`c2.events.toastDeleted`,null,`已删除`).replace(`{{n}}`,String(n?.deleted??t.length))),H(e=>e.filter(e=>!t.includes(e))),J()}catch(e){p(e)}}})},de=[{title:e(`c2.events.level`,null,`级别`),dataIndex:`level`,width:90,render:t=>(0,D.jsx)(a,{size:`small`,color:S[t]||`grey`,children:e(`c2.events.${t||`info`}`,null,t||`—`)})},{title:e(`c2.events.category`,null,`类别`),dataIndex:`category`,width:110},{title:e(`c2.events.message`,null,`消息`),dataIndex:`message`,render:(e,t)=>(0,D.jsx)(`button`,{type:`button`,className:`c2-event-message`,onClick:()=>W(t),title:e,children:e||`—`})},{title:e(`c2.events.colSession`,null,`会话`),dataIndex:`sessionId`,width:150,render:e=>(0,D.jsx)(`span`,{className:`c2-mono`,children:e||`—`})},{title:e(`c2.events.colTask`,null,`任务`),dataIndex:`taskId`,width:150,render:e=>(0,D.jsx)(`span`,{className:`c2-mono`,children:e||`—`})},{title:e(`c2.events.time`,null,`时间`),dataIndex:`createdAt`,width:130,render:e=>(0,D.jsx)(x,{value:e})},{title:e(`c2.tasks.colActions`,null,`操作`),dataIndex:`actions`,width:130,render:(t,r)=>(0,D.jsxs)(i,{spacing:4,children:[(0,D.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>W(r),children:e(`c2.events.view`,null,`查看`)}),(0,D.jsx)(o,{size:`small`,theme:`borderless`,type:`danger`,disabled:!n,onClick:()=>$([r.id]),children:e(`c2.events.deleteOne`,null,`删除`)})]})}];return(0,D.jsxs)(`div`,{className:`c2-page`,id:`page-c2-events`,children:[(0,D.jsx)(re,{title:e(`c2.events.title`,null,`事件审计`),description:e(`c2.events.pageDesc`,null,`监听器、会话、任务与 OPSEC 事件留痕,5 秒自动刷新`),extra:[(0,D.jsx)(o,{icon:(0,D.jsx)(ee,{}),onClick:()=>J(),loading:q,children:e(`c2.events.refresh`,null,`刷新`)},`refresh`),(0,D.jsx)(o,{type:`danger`,disabled:!n||!V.length,onClick:()=>$(V),children:e(`c2.events.batchDelete`,null,`批量删除`)},`delete`)]}),(0,D.jsx)(d,{metrics:ue,columns:4}),(0,D.jsx)(m,{error:ce,onRetry:()=>J()}),(0,D.jsx)(h,{title:e(`c2.events.filterTitle`,null,`筛选`),extra:(0,D.jsx)(C,{value:F,onChange:e=>{I(e),k(1)},ns:`events`}),children:(0,D.jsxs)(`div`,{className:`c2-toolbar-fields`,children:[(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.events.level`,null,`级别`)}),(0,D.jsx)(l,{value:j,onChange:e=>{M(e||``),k(1)},style:{width:150},optionList:[{value:``,label:e(`c2.events.filterAllLevels`,null,`全部级别`)},...w]})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.events.category`,null,`类别`)}),(0,D.jsx)(l,{value:N,onChange:e=>{P(e||``),k(1)},style:{width:150},optionList:[{value:``,label:e(`c2.events.filterAllCategories`,null,`全部类别`)},...T]})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.events.filterSession`,null,`会话 ID`)}),(0,D.jsx)(s,{value:L,onChange:R,onEnterPress:Q,placeholder:e(`c2.events.filterSessionPlaceholder`,null,`s_xxxxxxxx`),style:{width:190}})]}),(0,D.jsxs)(i,{spacing:8,children:[(0,D.jsx)(o,{theme:`solid`,type:`primary`,onClick:Q,children:e(`c2.events.applyFilters`,null,`应用筛选`)}),(0,D.jsx)(o,{onClick:le,children:e(`c2.events.resetFilters`,null,`重置`)})]})]})}),(0,D.jsx)(h,{title:e(`c2.events.listTitle`,null,`事件列表`),children:(0,D.jsx)(ie,{columns:de,dataSource:Y,rowKey:`id`,loading:q,onRefresh:()=>J(),rowSelection:{selectedRowKeys:V,onChange:e=>H(e)},pagination:{currentPage:r,pageSize:A,total:X,onPageChange:e=>k(e),onPageSizeChange:e=>{se(e),k(1)}},emptyText:e(`c2.events.empty`,null,`暂无事件`)})}),(0,D.jsx)(c,{visible:!!U,title:e(`c2.events.detailTitle`,null,`事件详情`),width:560,onCancel:()=>W(null),children:U&&(0,D.jsxs)(`div`,{className:`c2-event-detail`,children:[(0,D.jsxs)(`div`,{className:`c2-event-detail-head`,children:[(0,D.jsx)(a,{size:`small`,color:S[U.level]||`grey`,children:U.level}),(0,D.jsx)(a,{size:`small`,children:U.category}),(0,D.jsx)(O,{type:`tertiary`,size:`small`,children:te(U.createdAt)})]}),(0,D.jsx)(O,{children:U.message}),(0,D.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.events.colId`,null,`事件 ID`)}),(0,D.jsx)(O,{className:`c2-mono`,copyable:{text:U.id},children:U.id}),U.sessionId&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.events.colSession`,null,`会话`)}),(0,D.jsx)(O,{className:`c2-mono`,children:U.sessionId})]}),U.data&&Object.keys(U.data).length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.events.detailData`,null,`附加数据`)}),(0,D.jsx)(ae,{value:U.data})]})]})})]})}export{k as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,N as a,R as o,U as s,p as c,ut as ee,y as l}from"./semi-65W_4I1v.js";import{E as te,F as ne,I as u,_ as d,a as f,b as p,l as m,m as h,p as re,r as g,s as ie,u as ae,x as _,y as v}from"./index-DNMXun-U.js";import{c as oe,v as y}from"./c2-shared-2EAlkwn6.js";import{g as b,m as x,n as S,p as C,r as w,t as T}from"./c2-shared-BrRxH-6B.js";var E=e(t(),1),D=e(n(),1),{Text:O}=r;function k(){let e=ne(),{hasPermission:t}=u(),n=t(`c2:delete`)||t(`c2:write`),[r,k]=(0,E.useState)(1),[A,se]=(0,E.useState)(20),[j,M]=(0,E.useState)(``),[N,P]=(0,E.useState)(``),[F,I]=(0,E.useState)(`24h`),[L,R]=(0,E.useState)(``),[z,B]=(0,E.useState)(``),[V,H]=(0,E.useState)([]),[U,W]=(0,E.useState)(null),G=(0,E.useMemo)(()=>({page:r,page_size:A,level:j||void 0,category:N||void 0,session_id:z||void 0,since:b(F)||void 0}),[r,A,j,N,z,F]),{data:K,loading:q,error:ce,reload:J}=f(()=>y(G),[G]),Y=Array.isArray(K?.events)?K.events:[],X=Number(K?.total??Y.length),Z=K?.level_counts||{};g(()=>J({silent:!0}),5e3);let Q=()=>{B(L.trim()),k(1),H([])},le=()=>{M(``),P(``),I(`24h`),R(``),B(``),k(1),H([])},ue=[{id:`total`,label:e(`c2.events.statTotal`,null,`当前筛选`),value:X},{id:`info`,label:e(`c2.events.info`,null,`信息`),value:Z.info||0},{id:`warn`,label:e(`c2.events.warn`,null,`警告`),value:Z.warn||0,tone:`warning`},{id:`critical`,label:e(`c2.events.critical`,null,`严重`),value:Z.critical||0,tone:`danger`}],$=t=>{v({title:e(`c2.events.batchDelete`,null,`删除事件`),content:t.length>1?e(`c2.events.confirmBatchDelete`,null,`确定删除选中的事件吗?此操作不可恢复。`).replace(`{{n}}`,String(t.length)):e(`c2.events.confirmDeleteOne`,null,`确定删除该条事件吗?此操作不可恢复。`),onOk:async()=>{try{let n=await oe(t);_(e(`c2.events.toastDeleted`,null,`已删除`).replace(`{{n}}`,String(n?.deleted??t.length))),H(e=>e.filter(e=>!t.includes(e))),J()}catch(e){p(e)}}})},de=[{title:e(`c2.events.level`,null,`级别`),dataIndex:`level`,width:90,render:t=>(0,D.jsx)(a,{size:`small`,color:S[t]||`grey`,children:e(`c2.events.${t||`info`}`,null,t||`—`)})},{title:e(`c2.events.category`,null,`类别`),dataIndex:`category`,width:110},{title:e(`c2.events.message`,null,`消息`),dataIndex:`message`,render:(e,t)=>(0,D.jsx)(`button`,{type:`button`,className:`c2-event-message`,onClick:()=>W(t),title:e,children:e||`—`})},{title:e(`c2.events.colSession`,null,`会话`),dataIndex:`sessionId`,width:150,render:e=>(0,D.jsx)(`span`,{className:`c2-mono`,children:e||`—`})},{title:e(`c2.events.colTask`,null,`任务`),dataIndex:`taskId`,width:150,render:e=>(0,D.jsx)(`span`,{className:`c2-mono`,children:e||`—`})},{title:e(`c2.events.time`,null,`时间`),dataIndex:`createdAt`,width:130,render:e=>(0,D.jsx)(x,{value:e})},{title:e(`c2.tasks.colActions`,null,`操作`),dataIndex:`actions`,width:130,render:(t,r)=>(0,D.jsxs)(i,{spacing:4,children:[(0,D.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>W(r),children:e(`c2.events.view`,null,`查看`)}),(0,D.jsx)(o,{size:`small`,theme:`borderless`,type:`danger`,disabled:!n,onClick:()=>$([r.id]),children:e(`c2.events.deleteOne`,null,`删除`)})]})}];return(0,D.jsxs)(`div`,{className:`c2-page`,id:`page-c2-events`,children:[(0,D.jsx)(re,{title:e(`c2.events.title`,null,`事件审计`),description:e(`c2.events.pageDesc`,null,`监听器、会话、任务与 OPSEC 事件留痕,5 秒自动刷新`),extra:[(0,D.jsx)(o,{icon:(0,D.jsx)(ee,{}),onClick:()=>J(),loading:q,children:e(`c2.events.refresh`,null,`刷新`)},`refresh`),(0,D.jsx)(o,{type:`danger`,disabled:!n||!V.length,onClick:()=>$(V),children:e(`c2.events.batchDelete`,null,`批量删除`)},`delete`)]}),(0,D.jsx)(d,{metrics:ue,columns:4}),(0,D.jsx)(m,{error:ce,onRetry:()=>J()}),(0,D.jsx)(h,{title:e(`c2.events.filterTitle`,null,`筛选`),extra:(0,D.jsx)(C,{value:F,onChange:e=>{I(e),k(1)},ns:`events`}),children:(0,D.jsxs)(`div`,{className:`c2-toolbar-fields`,children:[(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.events.level`,null,`级别`)}),(0,D.jsx)(l,{value:j,onChange:e=>{M(e||``),k(1)},style:{width:150},optionList:[{value:``,label:e(`c2.events.filterAllLevels`,null,`全部级别`)},...w]})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.events.category`,null,`类别`)}),(0,D.jsx)(l,{value:N,onChange:e=>{P(e||``),k(1)},style:{width:150},optionList:[{value:``,label:e(`c2.events.filterAllCategories`,null,`全部类别`)},...T]})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.events.filterSession`,null,`会话 ID`)}),(0,D.jsx)(s,{value:L,onChange:R,onEnterPress:Q,placeholder:e(`c2.events.filterSessionPlaceholder`,null,`s_xxxxxxxx`),style:{width:190}})]}),(0,D.jsxs)(i,{spacing:8,children:[(0,D.jsx)(o,{theme:`solid`,type:`primary`,onClick:Q,children:e(`c2.events.applyFilters`,null,`应用筛选`)}),(0,D.jsx)(o,{onClick:le,children:e(`c2.events.resetFilters`,null,`重置`)})]})]})}),(0,D.jsx)(h,{title:e(`c2.events.listTitle`,null,`事件列表`),children:(0,D.jsx)(ie,{columns:de,dataSource:Y,rowKey:`id`,loading:q,onRefresh:()=>J(),rowSelection:{selectedRowKeys:V,onChange:e=>H(e)},pagination:{currentPage:r,pageSize:A,total:X,onPageChange:e=>k(e),onPageSizeChange:e=>{se(e),k(1)}},emptyText:e(`c2.events.empty`,null,`暂无事件`)})}),(0,D.jsx)(c,{visible:!!U,title:e(`c2.events.detailTitle`,null,`事件详情`),width:560,onCancel:()=>W(null),children:U&&(0,D.jsxs)(`div`,{className:`c2-event-detail`,children:[(0,D.jsxs)(`div`,{className:`c2-event-detail-head`,children:[(0,D.jsx)(a,{size:`small`,color:S[U.level]||`grey`,children:U.level}),(0,D.jsx)(a,{size:`small`,children:U.category}),(0,D.jsx)(O,{type:`tertiary`,size:`small`,children:te(U.createdAt)})]}),(0,D.jsx)(O,{children:U.message}),(0,D.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.events.colId`,null,`事件 ID`)}),(0,D.jsx)(O,{className:`c2-mono`,copyable:{text:U.id},children:U.id}),U.sessionId&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.events.colSession`,null,`会话`)}),(0,D.jsx)(O,{className:`c2-mono`,children:U.sessionId})]}),U.data&&Object.keys(U.data).length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.events.detailData`,null,`附加数据`)}),(0,D.jsx)(ae,{value:U.data})]})]})})]})}export{k as default}; \ No newline at end of file diff --git a/web/static/app/assets/c2-listeners-CE3GvlqS.js b/web/static/app/assets/c2-listeners-7rFR5Rx6.js similarity index 97% rename from web/static/app/assets/c2-listeners-CE3GvlqS.js rename to web/static/app/assets/c2-listeners-7rFR5Rx6.js index c81b25aa..268cfb7a 100644 --- a/web/static/app/assets/c2-listeners-CE3GvlqS.js +++ b/web/static/app/assets/c2-listeners-7rFR5Rx6.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,N as a,R as o,ft as s,i as c,ut as l}from"./semi-65W_4I1v.js";import{E as u,F as d,I as f,_ as p,a as m,b as h,c as g,l as _,m as v,o as y,p as b,s as x,x as S,y as C}from"./index-CAEPLS-g.js";import{D as w,E as T,O as E,b as D,i as O,l as k,x as A,y as j}from"./c2-shared-Car3lDYq.js";import{a as M,i as N,o as P}from"./c2-shared-D-8kBzuC.js";import{t as F}from"./project-options-CMQbwv_U.js";var I=e(t(),1),L=e(n(),1),{Text:R}=r;function z(e){if(!e?.configJson)return{};try{return JSON.parse(e.configJson)||{}}catch{return{}}}function B(e){let t=z(e);return{name:e?.name||``,type:e?.type||`http_beacon`,project_id:e?.project_id||``,bind_host:e?.bindHost||`127.0.0.1`,bind_port:String(e?.bindPort??`4444`),callback_host:t.callback_host||``,profile_id:e?.profileId||``,remark:e?.remark||``,default_sleep:String(t.default_sleep??5),default_jitter:String(t.default_jitter??0),max_concurrent_tasks:String(t.max_concurrent_tasks??0),allow_legacy_shell:!!t.allow_legacy_shell}}function V({visible:e,record:t,projects:n,profiles:r,submitting:a,onCancel:s,onSubmit:l}){let u=d(),[f,p]=(0,I.useState)(null),[m,h]=(0,I.useState)(t?.type||`http_beacon`);return(0,L.jsx)(g,{visible:e,title:t?u(`c2.listeners.editTitle`,null,`编辑监听器`):u(`c2.listeners.modalCreateTitle`,null,`创建监听器`),footer:(0,L.jsxs)(i,{children:[(0,L.jsx)(o,{onClick:s,children:u(`c2.common.cancel`,null,`取消`)}),(0,L.jsx)(o,{theme:`solid`,type:`primary`,loading:a,onClick:()=>f?.submitForm(),children:t?u(`c2.listeners.save`,null,`保存`):u(`c2.listeners.submitCreate`,null,`创建`)})]}),width:620,onCancel:s,children:(0,L.jsxs)(c,{initValues:B(t),onSubmit:e=>{let t=Number(e.bind_port);l({name:String(e.name||``).trim(),type:e.type,project_id:e.project_id||``,bind_host:String(e.bind_host||``).trim()||`127.0.0.1`,bind_port:Number.isFinite(t)?t:0,callback_host:String(e.callback_host||``).trim(),profile_id:e.profile_id||``,remark:String(e.remark||``).trim(),config:{callback_host:String(e.callback_host||``).trim(),default_sleep:Number(e.default_sleep)||5,default_jitter:Number(e.default_jitter)||0,max_concurrent_tasks:Number(e.max_concurrent_tasks)||0,allow_legacy_shell:!!e.allow_legacy_shell}})},getFormApi:p,labelPosition:`top`,onValueChange:e=>{e.type&&h(e.type)},children:[(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Input,{field:`name`,label:u(`c2.listeners.name`,null,`名称`),placeholder:u(`c2.listeners.placeholderNameExample`,null,`例如 http-beacon-01`),rules:[{required:!0,message:u(`c2.listeners.nameRequired`,null,`请输入监听器名称`)}]}),(0,L.jsx)(c.Select,{field:`type`,label:u(`c2.listeners.type`,null,`类型`),optionList:P,disabled:!!t,style:{width:`100%`}})]}),(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Input,{field:`bind_host`,label:u(`c2.listeners.bindHost`,null,`绑定地址`),placeholder:`127.0.0.1`}),(0,L.jsx)(c.Input,{field:`bind_port`,label:u(`c2.listeners.bindPort`,null,`绑定端口`),placeholder:u(`c2.listeners.placeholderPort`,null,`输入端口号`),rules:[{required:!0,validator:(e,t)=>{let n=Number(t);return Number.isInteger(n)&&n>0&&n<=65535},message:u(`c2.listeners.portInvalid`,null,`端口必须为 1–65535 的整数`)}]})]}),(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:u(`c2.listeners.bindHintExternal`,null,`使用 0.0.0.0 允许外部访问`)}),(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Input,{field:`callback_host`,label:u(`c2.listeners.callbackHost`,null,`回连地址(可选)`),placeholder:`公网 IP 或域名`}),(0,L.jsx)(c.Select,{field:`profile_id`,label:u(`c2.listeners.malleableProfile`,null,`Malleable Profile`),optionList:[{value:``,label:u(`c2.listeners.malleableProfileNone`,null,`不使用`)},...r.map(e=>({value:e.id,label:e.name||e.id}))],style:{width:`100%`}})]}),(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Select,{field:`project_id`,label:u(`c2.listeners.project`,null,`所属项目`),optionList:[{value:``,label:u(`c2.listeners.projectNone`,null,`不绑定项目`)},...F(n,u,{currentId:t?.project_id||``})],style:{width:`100%`}}),(0,L.jsx)(c.Input,{field:`remark`,label:u(`c2.listeners.remark`,null,`备注`),placeholder:u(`c2.listeners.placeholderRemarkLong`,null,`可选的备注说明`)})]}),(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Input,{field:`default_sleep`,label:`默认 Sleep(秒)`,placeholder:`5`}),(0,L.jsx)(c.Input,{field:`default_jitter`,label:`默认 Jitter(%)`,placeholder:`0`})]}),(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Input,{field:`max_concurrent_tasks`,label:`单会话并发任务上限(0 不限)`,placeholder:`0`}),m===`tcp_reverse`&&(0,L.jsx)(c.Switch,{field:`allow_legacy_shell`,label:u(`c2.listeners.allowLegacyShell`,null,`允许未加密经典反弹 Shell(内网实验)`)})]})]},t?.id||`new`)})}var{Text:H}=r,U=e=>P.find(t=>t.value===e)?.label||e||`—`;function W(){let e=d(),{hasPermission:t}=f(),n=t(`c2:write`),r=t(`c2:delete`)||n,[c,P]=(0,I.useState)({visible:!1,record:null}),[F,R]=(0,I.useState)(!1),[z,B]=(0,I.useState)(``),[W,G]=(0,I.useState)(null),{data:K,loading:q,error:J,reload:Y}=m(()=>Promise.all([j(),D().catch(()=>({profiles:[]})),A()]),[]),X=Array.isArray(K?.[0]?.listeners)?K[0].listeners:[],Z=Array.isArray(K?.[1]?.profiles)?K[1].profiles:[],Q=Array.isArray(K?.[2])?K[2]:[],$=(0,I.useMemo)(()=>{let t=X.filter(e=>e.status===`running`).length,n=X.filter(e=>e.status===`error`).length;return[{id:`total`,label:e(`c2.listeners.statTotal`,null,`监听器总数`),value:X.length},{id:`running`,label:e(`c2.listeners.running`,null,`运行中`),value:t,tone:t?`success`:void 0},{id:`stopped`,label:e(`c2.listeners.stopped`,null,`已停止`),value:X.length-t-n},{id:`error`,label:e(`c2.listeners.statusError`,null,`异常`),value:n,tone:n?`danger`:void 0}]},[X,e]),ee=async(t,n)=>{B(t.id);try{n===`start`?(await T(t.id),S(e(`c2.listeners.toastStarted`,null,`监听器已启动`))):(await w(t.id),S(e(`c2.listeners.toastStopped`,null,`监听器已停止`))),Y()}catch(t){h(t,n===`start`?e(`c2.listeners.start`,null,`启动失败`):e(`c2.listeners.stop`,null,`停止失败`))}finally{B(``)}},te=t=>{C({title:e(`c2.listeners.delete`,null,`删除监听器`),content:e(`c2.listeners.confirmDelete`,null,`确定删除此监听器?相关会话与任务将被清除。`),onOk:async()=>{try{await k(t.id),S(e(`c2.listeners.toastDeleted`,null,`监听器已删除`)),Y()}catch(e){h(e)}}})},ne=async t=>{R(!0);try{if(c.record?.id)await E(c.record.id,t),S(e(`c2.listeners.toastUpdated`,null,`监听器已更新`));else{let n=await O(t);S(e(`c2.listeners.toastCreated`,null,`监听器已创建`)),n?.implant_token&&G({name:n.listener?.name||t.name,token:n.implant_token})}P({visible:!1,record:null}),Y()}catch(t){h(t,e(`c2.listeners.saveFailed`,null,`监听器保存失败`))}finally{R(!1)}},re=[{title:e(`c2.listeners.name`,null,`名称`),dataIndex:`name`,render:(e,t)=>(0,L.jsxs)(`div`,{className:`c2-listener-name`,children:[(0,L.jsx)(H,{strong:!0,children:e||t.id}),t.remark&&(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:t.remark})]})},{title:e(`c2.listeners.type`,null,`类型`),dataIndex:`type`,width:140,render:U},{title:e(`c2.listeners.bindEndpoint`,null,`监听地址`),dataIndex:`bindPort`,width:200,render:(e,t)=>(0,L.jsxs)(`span`,{className:`c2-mono`,children:[t.bindHost,`:`,e]})},{title:e(`c2.listeners.callbackShort`,null,`回连`),dataIndex:`configJson`,width:160,render:e=>{try{let t=JSON.parse(e||`{}`);return t.callback_host?(0,L.jsx)(`span`,{className:`c2-mono`,children:t.callback_host}):(0,L.jsx)(H,{type:`tertiary`,children:`—`})}catch{return(0,L.jsx)(H,{type:`tertiary`,children:`—`})}}},{title:e(`c2.listeners.status`,null,`状态`),dataIndex:`status`,width:120,render:(e,t)=>(0,L.jsxs)(`div`,{className:`c2-listener-status`,children:[(0,L.jsx)(a,{size:`small`,color:N[e]||`grey`,children:M[e]||e||`—`}),t.lastError&&(0,L.jsx)(H,{type:`danger`,size:`small`,children:t.lastError})]})},{title:e(`c2.listeners.startedAtPrefix`,null,`启动于`),dataIndex:`startedAt`,width:180,render:e=>e?u(e):(0,L.jsx)(H,{type:`tertiary`,children:`—`})},{title:e(`c2.listeners.actions`,null,`操作`),dataIndex:`actions`,width:220,render:(t,a)=>{let s=a.status===`running`;return(0,L.jsxs)(i,{spacing:4,wrap:!0,children:[(0,L.jsx)(o,{size:`small`,theme:`borderless`,disabled:!n,loading:z===a.id,onClick:()=>ee(a,s?`stop`:`start`),children:s?e(`c2.listeners.stop`,null,`停止`):e(`c2.listeners.start`,null,`启动`)}),(0,L.jsx)(o,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>P({visible:!0,record:a}),children:e(`c2.listeners.edit`,null,`编辑`)}),(0,L.jsx)(o,{size:`small`,theme:`borderless`,type:`danger`,disabled:!r,onClick:()=>te(a),children:e(`c2.listeners.delete`,null,`删除`)})]})}}];return(0,L.jsxs)(`div`,{className:`c2-page`,id:`page-c2-listeners`,children:[(0,L.jsx)(b,{title:e(`c2.listeners.title`,null,`监听器管理`),description:e(`c2.listeners.pageDesc`,null,`创建并启停 C2 监听器,启停状态即时同步到后端`),extra:[(0,L.jsx)(o,{icon:(0,L.jsx)(l,{}),onClick:Y,loading:q,children:e(`common.refresh`,null,`刷新`)},`refresh`),(0,L.jsx)(o,{theme:`solid`,type:`primary`,icon:(0,L.jsx)(s,{}),disabled:!n,onClick:()=>P({visible:!0,record:null}),children:e(`c2.listeners.create`,null,`创建监听器`)},`create`)]}),(0,L.jsx)(p,{metrics:$,columns:4}),(0,L.jsx)(_,{error:J,onRetry:Y}),(0,L.jsx)(v,{title:e(`c2.listeners.title`,null,`监听器列表`),children:(0,L.jsx)(x,{columns:re,dataSource:X,rowKey:`id`,loading:q,onRefresh:Y,pagination:{pageSize:10},emptyText:e(`c2.listeners.emptyTitle`,null,`暂无监听器`)})}),(0,L.jsx)(V,{visible:c.visible,record:c.record,projects:Q,profiles:Z,submitting:F,onCancel:()=>P({visible:!1,record:null}),onSubmit:ne}),(0,L.jsxs)(g,{visible:!!W,title:e(`c2.listeners.implantTokenTitle`,null,`植入体 Token`),onCancel:()=>G(null),footer:(0,L.jsx)(o,{onClick:()=>G(null),children:e(`c2.listeners.close`,null,`关闭`)}),children:[(0,L.jsx)(H,{type:`tertiary`,children:e(`c2.listeners.implantTokenHint`,null,`该 Token 仅在此处显示一次,请立即保存;后续可通过重新创建监听器获取。`)}),(0,L.jsxs)(`div`,{className:`c2-listener-token`,children:[(0,L.jsx)(`span`,{className:`c2-mono`,children:W?.token}),(0,L.jsx)(y,{text:W?.token||``})]})]})]})}export{W as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,N as a,R as o,ft as s,i as c,ut as l}from"./semi-65W_4I1v.js";import{E as u,F as d,I as f,_ as p,a as m,b as h,c as g,l as _,m as v,o as y,p as b,s as x,x as S,y as C}from"./index-DNMXun-U.js";import{D as w,E as T,O as E,b as D,i as O,l as k,x as A,y as j}from"./c2-shared-2EAlkwn6.js";import{a as M,i as N,o as P}from"./c2-shared-BrRxH-6B.js";import{t as F}from"./project-options-CMQbwv_U.js";var I=e(t(),1),L=e(n(),1),{Text:R}=r;function z(e){if(!e?.configJson)return{};try{return JSON.parse(e.configJson)||{}}catch{return{}}}function B(e){let t=z(e);return{name:e?.name||``,type:e?.type||`http_beacon`,project_id:e?.project_id||``,bind_host:e?.bindHost||`127.0.0.1`,bind_port:String(e?.bindPort??`4444`),callback_host:t.callback_host||``,profile_id:e?.profileId||``,remark:e?.remark||``,default_sleep:String(t.default_sleep??5),default_jitter:String(t.default_jitter??0),max_concurrent_tasks:String(t.max_concurrent_tasks??0),allow_legacy_shell:!!t.allow_legacy_shell}}function V({visible:e,record:t,projects:n,profiles:r,submitting:a,onCancel:s,onSubmit:l}){let u=d(),[f,p]=(0,I.useState)(null),[m,h]=(0,I.useState)(t?.type||`http_beacon`);return(0,L.jsx)(g,{visible:e,title:t?u(`c2.listeners.editTitle`,null,`编辑监听器`):u(`c2.listeners.modalCreateTitle`,null,`创建监听器`),footer:(0,L.jsxs)(i,{children:[(0,L.jsx)(o,{onClick:s,children:u(`c2.common.cancel`,null,`取消`)}),(0,L.jsx)(o,{theme:`solid`,type:`primary`,loading:a,onClick:()=>f?.submitForm(),children:t?u(`c2.listeners.save`,null,`保存`):u(`c2.listeners.submitCreate`,null,`创建`)})]}),width:620,onCancel:s,children:(0,L.jsxs)(c,{initValues:B(t),onSubmit:e=>{let t=Number(e.bind_port);l({name:String(e.name||``).trim(),type:e.type,project_id:e.project_id||``,bind_host:String(e.bind_host||``).trim()||`127.0.0.1`,bind_port:Number.isFinite(t)?t:0,callback_host:String(e.callback_host||``).trim(),profile_id:e.profile_id||``,remark:String(e.remark||``).trim(),config:{callback_host:String(e.callback_host||``).trim(),default_sleep:Number(e.default_sleep)||5,default_jitter:Number(e.default_jitter)||0,max_concurrent_tasks:Number(e.max_concurrent_tasks)||0,allow_legacy_shell:!!e.allow_legacy_shell}})},getFormApi:p,labelPosition:`top`,onValueChange:e=>{e.type&&h(e.type)},children:[(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Input,{field:`name`,label:u(`c2.listeners.name`,null,`名称`),placeholder:u(`c2.listeners.placeholderNameExample`,null,`例如 http-beacon-01`),rules:[{required:!0,message:u(`c2.listeners.nameRequired`,null,`请输入监听器名称`)}]}),(0,L.jsx)(c.Select,{field:`type`,label:u(`c2.listeners.type`,null,`类型`),optionList:P,disabled:!!t,style:{width:`100%`}})]}),(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Input,{field:`bind_host`,label:u(`c2.listeners.bindHost`,null,`绑定地址`),placeholder:`127.0.0.1`}),(0,L.jsx)(c.Input,{field:`bind_port`,label:u(`c2.listeners.bindPort`,null,`绑定端口`),placeholder:u(`c2.listeners.placeholderPort`,null,`输入端口号`),rules:[{required:!0,validator:(e,t)=>{let n=Number(t);return Number.isInteger(n)&&n>0&&n<=65535},message:u(`c2.listeners.portInvalid`,null,`端口必须为 1–65535 的整数`)}]})]}),(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:u(`c2.listeners.bindHintExternal`,null,`使用 0.0.0.0 允许外部访问`)}),(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Input,{field:`callback_host`,label:u(`c2.listeners.callbackHost`,null,`回连地址(可选)`),placeholder:`公网 IP 或域名`}),(0,L.jsx)(c.Select,{field:`profile_id`,label:u(`c2.listeners.malleableProfile`,null,`Malleable Profile`),optionList:[{value:``,label:u(`c2.listeners.malleableProfileNone`,null,`不使用`)},...r.map(e=>({value:e.id,label:e.name||e.id}))],style:{width:`100%`}})]}),(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Select,{field:`project_id`,label:u(`c2.listeners.project`,null,`所属项目`),optionList:[{value:``,label:u(`c2.listeners.projectNone`,null,`不绑定项目`)},...F(n,u,{currentId:t?.project_id||``})],style:{width:`100%`}}),(0,L.jsx)(c.Input,{field:`remark`,label:u(`c2.listeners.remark`,null,`备注`),placeholder:u(`c2.listeners.placeholderRemarkLong`,null,`可选的备注说明`)})]}),(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Input,{field:`default_sleep`,label:`默认 Sleep(秒)`,placeholder:`5`}),(0,L.jsx)(c.Input,{field:`default_jitter`,label:`默认 Jitter(%)`,placeholder:`0`})]}),(0,L.jsxs)(`div`,{className:`c2-form-row`,children:[(0,L.jsx)(c.Input,{field:`max_concurrent_tasks`,label:`单会话并发任务上限(0 不限)`,placeholder:`0`}),m===`tcp_reverse`&&(0,L.jsx)(c.Switch,{field:`allow_legacy_shell`,label:u(`c2.listeners.allowLegacyShell`,null,`允许未加密经典反弹 Shell(内网实验)`)})]})]},t?.id||`new`)})}var{Text:H}=r,U=e=>P.find(t=>t.value===e)?.label||e||`—`;function W(){let e=d(),{hasPermission:t}=f(),n=t(`c2:write`),r=t(`c2:delete`)||n,[c,P]=(0,I.useState)({visible:!1,record:null}),[F,R]=(0,I.useState)(!1),[z,B]=(0,I.useState)(``),[W,G]=(0,I.useState)(null),{data:K,loading:q,error:J,reload:Y}=m(()=>Promise.all([j(),D().catch(()=>({profiles:[]})),A()]),[]),X=Array.isArray(K?.[0]?.listeners)?K[0].listeners:[],Z=Array.isArray(K?.[1]?.profiles)?K[1].profiles:[],Q=Array.isArray(K?.[2])?K[2]:[],$=(0,I.useMemo)(()=>{let t=X.filter(e=>e.status===`running`).length,n=X.filter(e=>e.status===`error`).length;return[{id:`total`,label:e(`c2.listeners.statTotal`,null,`监听器总数`),value:X.length},{id:`running`,label:e(`c2.listeners.running`,null,`运行中`),value:t,tone:t?`success`:void 0},{id:`stopped`,label:e(`c2.listeners.stopped`,null,`已停止`),value:X.length-t-n},{id:`error`,label:e(`c2.listeners.statusError`,null,`异常`),value:n,tone:n?`danger`:void 0}]},[X,e]),ee=async(t,n)=>{B(t.id);try{n===`start`?(await T(t.id),S(e(`c2.listeners.toastStarted`,null,`监听器已启动`))):(await w(t.id),S(e(`c2.listeners.toastStopped`,null,`监听器已停止`))),Y()}catch(t){h(t,n===`start`?e(`c2.listeners.start`,null,`启动失败`):e(`c2.listeners.stop`,null,`停止失败`))}finally{B(``)}},te=t=>{C({title:e(`c2.listeners.delete`,null,`删除监听器`),content:e(`c2.listeners.confirmDelete`,null,`确定删除此监听器?相关会话与任务将被清除。`),onOk:async()=>{try{await k(t.id),S(e(`c2.listeners.toastDeleted`,null,`监听器已删除`)),Y()}catch(e){h(e)}}})},ne=async t=>{R(!0);try{if(c.record?.id)await E(c.record.id,t),S(e(`c2.listeners.toastUpdated`,null,`监听器已更新`));else{let n=await O(t);S(e(`c2.listeners.toastCreated`,null,`监听器已创建`)),n?.implant_token&&G({name:n.listener?.name||t.name,token:n.implant_token})}P({visible:!1,record:null}),Y()}catch(t){h(t,e(`c2.listeners.saveFailed`,null,`监听器保存失败`))}finally{R(!1)}},re=[{title:e(`c2.listeners.name`,null,`名称`),dataIndex:`name`,render:(e,t)=>(0,L.jsxs)(`div`,{className:`c2-listener-name`,children:[(0,L.jsx)(H,{strong:!0,children:e||t.id}),t.remark&&(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:t.remark})]})},{title:e(`c2.listeners.type`,null,`类型`),dataIndex:`type`,width:140,render:U},{title:e(`c2.listeners.bindEndpoint`,null,`监听地址`),dataIndex:`bindPort`,width:200,render:(e,t)=>(0,L.jsxs)(`span`,{className:`c2-mono`,children:[t.bindHost,`:`,e]})},{title:e(`c2.listeners.callbackShort`,null,`回连`),dataIndex:`configJson`,width:160,render:e=>{try{let t=JSON.parse(e||`{}`);return t.callback_host?(0,L.jsx)(`span`,{className:`c2-mono`,children:t.callback_host}):(0,L.jsx)(H,{type:`tertiary`,children:`—`})}catch{return(0,L.jsx)(H,{type:`tertiary`,children:`—`})}}},{title:e(`c2.listeners.status`,null,`状态`),dataIndex:`status`,width:120,render:(e,t)=>(0,L.jsxs)(`div`,{className:`c2-listener-status`,children:[(0,L.jsx)(a,{size:`small`,color:N[e]||`grey`,children:M[e]||e||`—`}),t.lastError&&(0,L.jsx)(H,{type:`danger`,size:`small`,children:t.lastError})]})},{title:e(`c2.listeners.startedAtPrefix`,null,`启动于`),dataIndex:`startedAt`,width:180,render:e=>e?u(e):(0,L.jsx)(H,{type:`tertiary`,children:`—`})},{title:e(`c2.listeners.actions`,null,`操作`),dataIndex:`actions`,width:220,render:(t,a)=>{let s=a.status===`running`;return(0,L.jsxs)(i,{spacing:4,wrap:!0,children:[(0,L.jsx)(o,{size:`small`,theme:`borderless`,disabled:!n,loading:z===a.id,onClick:()=>ee(a,s?`stop`:`start`),children:s?e(`c2.listeners.stop`,null,`停止`):e(`c2.listeners.start`,null,`启动`)}),(0,L.jsx)(o,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>P({visible:!0,record:a}),children:e(`c2.listeners.edit`,null,`编辑`)}),(0,L.jsx)(o,{size:`small`,theme:`borderless`,type:`danger`,disabled:!r,onClick:()=>te(a),children:e(`c2.listeners.delete`,null,`删除`)})]})}}];return(0,L.jsxs)(`div`,{className:`c2-page`,id:`page-c2-listeners`,children:[(0,L.jsx)(b,{title:e(`c2.listeners.title`,null,`监听器管理`),description:e(`c2.listeners.pageDesc`,null,`创建并启停 C2 监听器,启停状态即时同步到后端`),extra:[(0,L.jsx)(o,{icon:(0,L.jsx)(l,{}),onClick:Y,loading:q,children:e(`common.refresh`,null,`刷新`)},`refresh`),(0,L.jsx)(o,{theme:`solid`,type:`primary`,icon:(0,L.jsx)(s,{}),disabled:!n,onClick:()=>P({visible:!0,record:null}),children:e(`c2.listeners.create`,null,`创建监听器`)},`create`)]}),(0,L.jsx)(p,{metrics:$,columns:4}),(0,L.jsx)(_,{error:J,onRetry:Y}),(0,L.jsx)(v,{title:e(`c2.listeners.title`,null,`监听器列表`),children:(0,L.jsx)(x,{columns:re,dataSource:X,rowKey:`id`,loading:q,onRefresh:Y,pagination:{pageSize:10},emptyText:e(`c2.listeners.emptyTitle`,null,`暂无监听器`)})}),(0,L.jsx)(V,{visible:c.visible,record:c.record,projects:Q,profiles:Z,submitting:F,onCancel:()=>P({visible:!1,record:null}),onSubmit:ne}),(0,L.jsxs)(g,{visible:!!W,title:e(`c2.listeners.implantTokenTitle`,null,`植入体 Token`),onCancel:()=>G(null),footer:(0,L.jsx)(o,{onClick:()=>G(null),children:e(`c2.listeners.close`,null,`关闭`)}),children:[(0,L.jsx)(H,{type:`tertiary`,children:e(`c2.listeners.implantTokenHint`,null,`该 Token 仅在此处显示一次,请立即保存;后续可通过重新创建监听器获取。`)}),(0,L.jsxs)(`div`,{className:`c2-listener-token`,children:[(0,L.jsx)(`span`,{className:`c2-mono`,children:W?.token}),(0,L.jsx)(y,{text:W?.token||``})]})]})]})}export{W as default}; \ No newline at end of file diff --git a/web/static/app/assets/c2-payloads-B8TBcwqZ.js b/web/static/app/assets/c2-payloads-DP3Iw5IZ.js similarity index 97% rename from web/static/app/assets/c2-payloads-B8TBcwqZ.js rename to web/static/app/assets/c2-payloads-DP3Iw5IZ.js index fda3b105..32fd5836 100644 --- a/web/static/app/assets/c2-payloads-B8TBcwqZ.js +++ b/web/static/app/assets/c2-payloads-DP3Iw5IZ.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as ee,N as i,R as a,U as o,y as s}from"./semi-65W_4I1v.js";import{F as c,I as l,S as u,T as d,a as f,b as p,l as m,m as h,o as g,p as _,s as v,x as y}from"./index-CAEPLS-g.js";import{m as b,n as x,t as S,y as C}from"./c2-shared-Car3lDYq.js";import{o as w,s as T}from"./c2-shared-D-8kBzuC.js";var E=e(t(),1),D=e(n(),1),{Text:O,Title:k}=r,A=[{value:`linux`,label:`Linux`},{value:`windows`,label:`Windows`},{value:`darwin`,label:`macOS`}],j=[{value:`amd64`,label:`AMD64`},{value:`arm64`,label:`ARM64`},{value:`386`,label:`386`}],M=e=>w.find(t=>t.value===e)?.label||e||`—`;function N(){let e=c(),{hasPermission:t}=l(),n=t(`c2:write`),{data:r,loading:w,error:N,reload:P}=f(()=>C(),[]),F=Array.isArray(r?.listeners)?r.listeners:[],[I,L]=(0,E.useState)({listenerId:``,kind:``,host:``}),[R,z]=(0,E.useState)(null),[B,V]=(0,E.useState)(!1),[H,U]=(0,E.useState)({listenerId:``,host:``,os:`linux`,arch:`amd64`}),[W,G]=(0,E.useState)(null),[K,q]=(0,E.useState)(!1),[J,Y]=(0,E.useState)([]),X=(0,E.useMemo)(()=>F.find(e=>e.id===(I.listenerId||F[0]?.id))||null,[F,I.listenerId]),Z=T[X?.type]||[],Q=F.map(e=>({value:e.id,label:`${e.name||e.id} · ${M(e.type)}`})),te=async()=>{let t=I.listenerId||F[0]?.id;if(!t){u(e(`c2.payloads.toastPickListener`,null,`请先选择一个监听器`));return}let n=I.kind||Z[0]?.value;if(!n)u(e(`c2.payloads.noKindOption`,null,`无可用类型`));else{V(!0);try{let e=await S({listener_id:t,kind:n,host:I.host.trim()});z(e)}catch(t){p(t,e(`c2.payloads.toastOnelinerFail`,null,`生成 Oneliner 失败`))}finally{V(!1)}}},ne=async()=>{let t=H.listenerId||F[0]?.id;if(!t)u(e(`c2.payloads.toastPickListener`,null,`请先选择一个监听器`));else{q(!0);try{let n=(await x({listener_id:t,host:H.host.trim(),os:H.os,arch:H.arch,sleep_seconds:5,jitter_percent:0}))?.payload||null;if(G(n),n){let r=String(n.output_path||``).split(/[\\/]/).pop();Y(e=>[{id:n.payload_id||r,fileName:r,listenerId:t,os:n.os,arch:n.arch,size:n.size_bytes},...e]),y(e(`c2.payloads.toastBuildSuccess`,null,`构建成功`).replace(`{{bytes}}`,String(n.size_bytes||0)))}}catch(t){p(t,e(`c2.payloads.toastBuildFail`,null,`构建 Beacon 失败`))}finally{q(!1)}}},$=async t=>{if(!t.fileName?.startsWith(`beacon_`))u(e(`c2.payloads.invalidArtifact`,null,`该产物不可下载`));else try{await b(t.fileName,t.fileName),y(e(`c2.payloads.toastDownloadQueued`,null,`下载任务已排队`))}catch(t){p(t,e(`c2.payloads.download`,null,`下载失败`))}},re=[{title:e(`c2.payloads.fileName`,null,`文件`),dataIndex:`fileName`,render:e=>(0,D.jsx)(`span`,{className:`c2-mono`,children:e||`—`})},{title:e(`c2.payloads.os`,null,`系统`),dataIndex:`os`,width:100},{title:e(`c2.payloads.arch`,null,`架构`),dataIndex:`arch`,width:100},{title:e(`c2.payloads.size`,null,`大小`),dataIndex:`size`,width:110,render:e=>d(e)},{title:e(`c2.tasks.colActions`,null,`操作`),dataIndex:`actions`,width:120,render:(t,n)=>(0,D.jsx)(a,{size:`small`,theme:`borderless`,onClick:()=>$(n),children:e(`c2.payloads.download`,null,`下载`)})}];return(0,D.jsxs)(`div`,{className:`c2-page`,id:`page-c2-payloads`,children:[(0,D.jsx)(_,{title:e(`c2.payloads.title`,null,`Payload 生成`),description:e(`c2.payloads.pageDesc`,null,`生成单行反弹命令,或交叉编译完整 Beacon 二进制`),extra:[(0,D.jsx)(a,{onClick:P,loading:w,children:e(`common.refresh`,null,`刷新`)},`refresh`)]}),(0,D.jsx)(m,{error:N,onRetry:P}),(0,D.jsxs)(`div`,{className:`c2-payload-grid`,children:[(0,D.jsxs)(h,{title:e(`c2.payloads.oneliner`,null,`单行 Payload`),description:e(`c2.payloads.onelinerDesc`,null,`生成可在目标机直接执行的反弹命令`),children:[(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.listener`,null,`监听器`)}),(0,D.jsx)(s,{value:I.listenerId||F[0]?.id||``,onChange:e=>L(t=>({...t,listenerId:e,kind:``})),optionList:Q,placeholder:e(`c2.payloads.noListenersOption`,null,`暂无可用监听器`),style:{width:`100%`}})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.kind`,null,`类型`)}),(0,D.jsx)(s,{value:I.kind||Z[0]?.value||``,onChange:e=>L(t=>({...t,kind:e})),optionList:Z,placeholder:e(`c2.payloads.noKindOption`,null,`无可用类型`),style:{width:`100%`}})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.hostOptional`,null,`回连地址(可选)`)}),(0,D.jsx)(o,{value:I.host,onChange:e=>L(t=>({...t,host:e})),placeholder:e(`c2.payloads.placeholderListenerHost`,null,`留空则使用监听器回连地址`)})]}),(0,D.jsx)(a,{theme:`solid`,type:`primary`,block:!0,disabled:!n,loading:B,onClick:te,children:e(`c2.payloads.generateOnelinerBtn`,null,`生成 Oneliner`)}),R?.oneliner&&(0,D.jsxs)(`div`,{className:`c2-oneliner-result`,children:[(0,D.jsxs)(`div`,{className:`c2-oneliner-head`,children:[(0,D.jsxs)(ee,{spacing:6,children:[(0,D.jsx)(i,{size:`small`,children:R.kind}),(0,D.jsxs)(O,{type:`tertiary`,size:`small`,children:[R.host,`:`,R.port]})]}),(0,D.jsx)(g,{text:R.oneliner,label:e(`c2.payloads.copy`,null,`复制`),size:`small`})]}),(0,D.jsx)(`pre`,{className:`c2-pre`,children:R.oneliner})]})]}),(0,D.jsxs)(h,{title:e(`c2.payloads.build`,null,`编译 Beacon`),description:e(`c2.payloads.buildDesc`,null,`交叉编译多平台完整 Beacon 可执行文件`),children:[(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.listener`,null,`监听器`)}),(0,D.jsx)(s,{value:H.listenerId||F[0]?.id||``,onChange:e=>U(t=>({...t,listenerId:e})),optionList:Q,placeholder:e(`c2.payloads.noListenersOption`,null,`暂无可用监听器`),style:{width:`100%`}})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.hostOptional`,null,`回连地址(可选)`)}),(0,D.jsx)(o,{value:H.host,onChange:e=>U(t=>({...t,host:e})),placeholder:e(`c2.payloads.placeholderListenerHost`,null,`留空则使用监听器回连地址`)})]}),(0,D.jsxs)(`div`,{className:`c2-form-row`,children:[(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.os`,null,`目标系统`)}),(0,D.jsx)(s,{value:H.os,onChange:e=>U(t=>({...t,os:e})),optionList:A,style:{width:`100%`}})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.arch`,null,`目标架构`)}),(0,D.jsx)(s,{value:H.arch,onChange:e=>U(t=>({...t,arch:e})),optionList:j,style:{width:`100%`}})]})]}),(0,D.jsx)(a,{theme:`solid`,type:`primary`,block:!0,disabled:!n,loading:K,onClick:ne,children:e(`c2.payloads.buildBeaconBtn`,null,`构建 Beacon`)}),W&&(0,D.jsxs)(`div`,{className:`c2-build-result`,children:[(0,D.jsx)(k,{heading:6,children:e(`c2.payloads.buildSuccessTitle`,null,`构建成功`)}),(0,D.jsx)(O,{type:`tertiary`,size:`small`,children:e(`c2.payloads.buildMetaOsArch`,null,`系统 / 架构`).replace(`{{os}}`,W.os||`—`).replace(`{{arch}}`,W.arch||`—`)}),(0,D.jsx)(O,{type:`tertiary`,size:`small`,children:e(`c2.payloads.buildSize`,null,`大小`).replace(`{{bytes}}`,String(W.size_bytes||0))}),(0,D.jsx)(`pre`,{className:`c2-pre`,children:W.output_path}),(0,D.jsx)(a,{size:`small`,onClick:()=>$({fileName:String(W.output_path||``).split(/[\\/]/).pop(),...W}),children:e(`c2.payloads.download`,null,`下载`)})]})]})]}),(0,D.jsx)(h,{title:e(`c2.payloads.artifacts`,null,`本次会话构建产物`),children:(0,D.jsx)(v,{columns:re,dataSource:J,rowKey:`id`,pagination:{pageSize:10},emptyText:e(`c2.payloads.noArtifacts`,null,`暂无构建产物`)})})]})}export{N as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as ee,N as i,R as a,U as o,y as s}from"./semi-65W_4I1v.js";import{F as c,I as l,S as u,T as d,a as f,b as p,l as m,m as h,o as g,p as _,s as v,x as y}from"./index-DNMXun-U.js";import{m as b,n as x,t as S,y as C}from"./c2-shared-2EAlkwn6.js";import{o as w,s as T}from"./c2-shared-BrRxH-6B.js";var E=e(t(),1),D=e(n(),1),{Text:O,Title:k}=r,A=[{value:`linux`,label:`Linux`},{value:`windows`,label:`Windows`},{value:`darwin`,label:`macOS`}],j=[{value:`amd64`,label:`AMD64`},{value:`arm64`,label:`ARM64`},{value:`386`,label:`386`}],M=e=>w.find(t=>t.value===e)?.label||e||`—`;function N(){let e=c(),{hasPermission:t}=l(),n=t(`c2:write`),{data:r,loading:w,error:N,reload:P}=f(()=>C(),[]),F=Array.isArray(r?.listeners)?r.listeners:[],[I,L]=(0,E.useState)({listenerId:``,kind:``,host:``}),[R,z]=(0,E.useState)(null),[B,V]=(0,E.useState)(!1),[H,U]=(0,E.useState)({listenerId:``,host:``,os:`linux`,arch:`amd64`}),[W,G]=(0,E.useState)(null),[K,q]=(0,E.useState)(!1),[J,Y]=(0,E.useState)([]),X=(0,E.useMemo)(()=>F.find(e=>e.id===(I.listenerId||F[0]?.id))||null,[F,I.listenerId]),Z=T[X?.type]||[],Q=F.map(e=>({value:e.id,label:`${e.name||e.id} · ${M(e.type)}`})),te=async()=>{let t=I.listenerId||F[0]?.id;if(!t){u(e(`c2.payloads.toastPickListener`,null,`请先选择一个监听器`));return}let n=I.kind||Z[0]?.value;if(!n)u(e(`c2.payloads.noKindOption`,null,`无可用类型`));else{V(!0);try{let e=await S({listener_id:t,kind:n,host:I.host.trim()});z(e)}catch(t){p(t,e(`c2.payloads.toastOnelinerFail`,null,`生成 Oneliner 失败`))}finally{V(!1)}}},ne=async()=>{let t=H.listenerId||F[0]?.id;if(!t)u(e(`c2.payloads.toastPickListener`,null,`请先选择一个监听器`));else{q(!0);try{let n=(await x({listener_id:t,host:H.host.trim(),os:H.os,arch:H.arch,sleep_seconds:5,jitter_percent:0}))?.payload||null;if(G(n),n){let r=String(n.output_path||``).split(/[\\/]/).pop();Y(e=>[{id:n.payload_id||r,fileName:r,listenerId:t,os:n.os,arch:n.arch,size:n.size_bytes},...e]),y(e(`c2.payloads.toastBuildSuccess`,null,`构建成功`).replace(`{{bytes}}`,String(n.size_bytes||0)))}}catch(t){p(t,e(`c2.payloads.toastBuildFail`,null,`构建 Beacon 失败`))}finally{q(!1)}}},$=async t=>{if(!t.fileName?.startsWith(`beacon_`))u(e(`c2.payloads.invalidArtifact`,null,`该产物不可下载`));else try{await b(t.fileName,t.fileName),y(e(`c2.payloads.toastDownloadQueued`,null,`下载任务已排队`))}catch(t){p(t,e(`c2.payloads.download`,null,`下载失败`))}},re=[{title:e(`c2.payloads.fileName`,null,`文件`),dataIndex:`fileName`,render:e=>(0,D.jsx)(`span`,{className:`c2-mono`,children:e||`—`})},{title:e(`c2.payloads.os`,null,`系统`),dataIndex:`os`,width:100},{title:e(`c2.payloads.arch`,null,`架构`),dataIndex:`arch`,width:100},{title:e(`c2.payloads.size`,null,`大小`),dataIndex:`size`,width:110,render:e=>d(e)},{title:e(`c2.tasks.colActions`,null,`操作`),dataIndex:`actions`,width:120,render:(t,n)=>(0,D.jsx)(a,{size:`small`,theme:`borderless`,onClick:()=>$(n),children:e(`c2.payloads.download`,null,`下载`)})}];return(0,D.jsxs)(`div`,{className:`c2-page`,id:`page-c2-payloads`,children:[(0,D.jsx)(_,{title:e(`c2.payloads.title`,null,`Payload 生成`),description:e(`c2.payloads.pageDesc`,null,`生成单行反弹命令,或交叉编译完整 Beacon 二进制`),extra:[(0,D.jsx)(a,{onClick:P,loading:w,children:e(`common.refresh`,null,`刷新`)},`refresh`)]}),(0,D.jsx)(m,{error:N,onRetry:P}),(0,D.jsxs)(`div`,{className:`c2-payload-grid`,children:[(0,D.jsxs)(h,{title:e(`c2.payloads.oneliner`,null,`单行 Payload`),description:e(`c2.payloads.onelinerDesc`,null,`生成可在目标机直接执行的反弹命令`),children:[(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.listener`,null,`监听器`)}),(0,D.jsx)(s,{value:I.listenerId||F[0]?.id||``,onChange:e=>L(t=>({...t,listenerId:e,kind:``})),optionList:Q,placeholder:e(`c2.payloads.noListenersOption`,null,`暂无可用监听器`),style:{width:`100%`}})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.kind`,null,`类型`)}),(0,D.jsx)(s,{value:I.kind||Z[0]?.value||``,onChange:e=>L(t=>({...t,kind:e})),optionList:Z,placeholder:e(`c2.payloads.noKindOption`,null,`无可用类型`),style:{width:`100%`}})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.hostOptional`,null,`回连地址(可选)`)}),(0,D.jsx)(o,{value:I.host,onChange:e=>L(t=>({...t,host:e})),placeholder:e(`c2.payloads.placeholderListenerHost`,null,`留空则使用监听器回连地址`)})]}),(0,D.jsx)(a,{theme:`solid`,type:`primary`,block:!0,disabled:!n,loading:B,onClick:te,children:e(`c2.payloads.generateOnelinerBtn`,null,`生成 Oneliner`)}),R?.oneliner&&(0,D.jsxs)(`div`,{className:`c2-oneliner-result`,children:[(0,D.jsxs)(`div`,{className:`c2-oneliner-head`,children:[(0,D.jsxs)(ee,{spacing:6,children:[(0,D.jsx)(i,{size:`small`,children:R.kind}),(0,D.jsxs)(O,{type:`tertiary`,size:`small`,children:[R.host,`:`,R.port]})]}),(0,D.jsx)(g,{text:R.oneliner,label:e(`c2.payloads.copy`,null,`复制`),size:`small`})]}),(0,D.jsx)(`pre`,{className:`c2-pre`,children:R.oneliner})]})]}),(0,D.jsxs)(h,{title:e(`c2.payloads.build`,null,`编译 Beacon`),description:e(`c2.payloads.buildDesc`,null,`交叉编译多平台完整 Beacon 可执行文件`),children:[(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.listener`,null,`监听器`)}),(0,D.jsx)(s,{value:H.listenerId||F[0]?.id||``,onChange:e=>U(t=>({...t,listenerId:e})),optionList:Q,placeholder:e(`c2.payloads.noListenersOption`,null,`暂无可用监听器`),style:{width:`100%`}})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.hostOptional`,null,`回连地址(可选)`)}),(0,D.jsx)(o,{value:H.host,onChange:e=>U(t=>({...t,host:e})),placeholder:e(`c2.payloads.placeholderListenerHost`,null,`留空则使用监听器回连地址`)})]}),(0,D.jsxs)(`div`,{className:`c2-form-row`,children:[(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.os`,null,`目标系统`)}),(0,D.jsx)(s,{value:H.os,onChange:e=>U(t=>({...t,os:e})),optionList:A,style:{width:`100%`}})]}),(0,D.jsxs)(`div`,{className:`c2-field`,children:[(0,D.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.payloads.arch`,null,`目标架构`)}),(0,D.jsx)(s,{value:H.arch,onChange:e=>U(t=>({...t,arch:e})),optionList:j,style:{width:`100%`}})]})]}),(0,D.jsx)(a,{theme:`solid`,type:`primary`,block:!0,disabled:!n,loading:K,onClick:ne,children:e(`c2.payloads.buildBeaconBtn`,null,`构建 Beacon`)}),W&&(0,D.jsxs)(`div`,{className:`c2-build-result`,children:[(0,D.jsx)(k,{heading:6,children:e(`c2.payloads.buildSuccessTitle`,null,`构建成功`)}),(0,D.jsx)(O,{type:`tertiary`,size:`small`,children:e(`c2.payloads.buildMetaOsArch`,null,`系统 / 架构`).replace(`{{os}}`,W.os||`—`).replace(`{{arch}}`,W.arch||`—`)}),(0,D.jsx)(O,{type:`tertiary`,size:`small`,children:e(`c2.payloads.buildSize`,null,`大小`).replace(`{{bytes}}`,String(W.size_bytes||0))}),(0,D.jsx)(`pre`,{className:`c2-pre`,children:W.output_path}),(0,D.jsx)(a,{size:`small`,onClick:()=>$({fileName:String(W.output_path||``).split(/[\\/]/).pop(),...W}),children:e(`c2.payloads.download`,null,`下载`)})]})]})]}),(0,D.jsx)(h,{title:e(`c2.payloads.artifacts`,null,`本次会话构建产物`),children:(0,D.jsx)(v,{columns:re,dataSource:J,rowKey:`id`,pagination:{pageSize:10},emptyText:e(`c2.payloads.noArtifacts`,null,`暂无构建产物`)})})]})}export{N as default}; \ No newline at end of file diff --git a/web/static/app/assets/c2-profiles-DFa_6zU3.js b/web/static/app/assets/c2-profiles-Cxv9lUnu.js similarity index 98% rename from web/static/app/assets/c2-profiles-DFa_6zU3.js rename to web/static/app/assets/c2-profiles-Cxv9lUnu.js index aaef735d..60519496 100644 --- a/web/static/app/assets/c2-profiles-DFa_6zU3.js +++ b/web/static/app/assets/c2-profiles-Cxv9lUnu.js @@ -1,2 +1,2 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,N as a,R as o,ft as s,i as c,ut as l}from"./semi-65W_4I1v.js";import{E as u,F as d,I as f,S as p,_ as m,a as h,b as g,c as _,l as v,m as y,p as b,s as x,u as S,x as C,y as w}from"./index-CAEPLS-g.js";import{a as T,b as E,k as D,u as O}from"./c2-shared-Car3lDYq.js";var k=e(t(),1),A=e(n(),1),{Text:j}=r;function M(e){return{name:e?.name||``,user_agent:e?.userAgent||``,uris:Array.isArray(e?.uris)?e.uris.join(` +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,N as a,R as o,ft as s,i as c,ut as l}from"./semi-65W_4I1v.js";import{E as u,F as d,I as f,S as p,_ as m,a as h,b as g,c as _,l as v,m as y,p as b,s as x,u as S,x as C,y as w}from"./index-DNMXun-U.js";import{a as T,b as E,k as D,u as O}from"./c2-shared-2EAlkwn6.js";var k=e(t(),1),A=e(n(),1),{Text:j}=r;function M(e){return{name:e?.name||``,user_agent:e?.userAgent||``,uris:Array.isArray(e?.uris)?e.uris.join(` `):``,jitter_min:String(e?.jitterMinMs??0),jitter_max:String(e?.jitterMaxMs??0),request_headers:e?.requestHeaders?JSON.stringify(e.requestHeaders,null,2):``,response_headers:e?.responseHeaders?JSON.stringify(e.responseHeaders,null,2):``,body_template:e?.bodyTemplate||``}}function N(e,t){let n=String(e||``).trim();if(!n)return{};try{let e=JSON.parse(n);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`not an object`);return e}catch{return p(t(`c2.profiles.toastInvalidHeadersJson`,null,`响应头 JSON 无效`)),null}}function P({visible:e,record:t,submitting:n,onCancel:r,onSubmit:a}){let s=d(),[l,u]=(0,k.useState)(null);return(0,A.jsx)(_,{visible:e,title:t?s(`c2.profiles.editTitle`,null,`编辑 Profile`):s(`c2.profiles.modalCreateTitle`,null,`创建 Malleable Profile`),footer:(0,A.jsxs)(i,{children:[(0,A.jsx)(o,{onClick:r,children:s(`c2.common.cancel`,null,`取消`)}),(0,A.jsx)(o,{theme:`solid`,type:`primary`,loading:n,onClick:()=>l?.submitForm(),children:t?s(`c2.profiles.save`,null,`保存`):s(`c2.profiles.submitCreate`,null,`创建`)})]}),width:640,onCancel:r,children:(0,A.jsxs)(c,{initValues:M(t),onSubmit:e=>{let t=Number(e.jitter_min),n=Number(e.jitter_max);if(!Number.isInteger(t)||!Number.isInteger(n)||t<0||ne.trim()).filter(Boolean),jitterMinMs:t,jitterMaxMs:n,requestHeaders:r,responseHeaders:i,bodyTemplate:String(e.body_template||``)})},getFormApi:u,labelPosition:`top`,children:[(0,A.jsx)(c.Input,{field:`name`,label:s(`c2.profiles.profileNameLabel`,null,`Profile 名称`),placeholder:s(`c2.profiles.placeholderProfileName`,null,`例如 cdn-fronting`),rules:[{required:!0,message:s(`c2.profiles.toastNameRequired`,null,`请填写 Profile 名称`)}]}),(0,A.jsx)(c.Input,{field:`user_agent`,label:s(`c2.profiles.userAgent`,null,`User-Agent`),placeholder:`Mozilla/5.0 ...`}),(0,A.jsx)(c.TextArea,{field:`uris`,label:s(`c2.profiles.labelBeaconUris`,null,`Beacon URI(每行一个)`),placeholder:`/api/v1/ping`,autosize:{minRows:2,maxRows:5}}),(0,A.jsxs)(`div`,{className:`c2-form-row`,children:[(0,A.jsx)(c.Input,{field:`jitter_min`,label:s(`c2.profiles.labelJitterMin`,null,`Jitter 最小值 (ms)`),placeholder:`0`}),(0,A.jsx)(c.Input,{field:`jitter_max`,label:s(`c2.profiles.labelJitterMax`,null,`Jitter 最大值 (ms)`),placeholder:`0`})]}),(0,A.jsx)(c.TextArea,{field:`request_headers`,label:s(`c2.profiles.requestHeadersJson`,null,`自定义请求头 (JSON)`),placeholder:`{"X-Forwarded-For":"127.0.0.1"}`,autosize:{minRows:2,maxRows:6}}),(0,A.jsx)(c.TextArea,{field:`response_headers`,label:s(`c2.profiles.labelRespHeaders`,null,`自定义响应头 (JSON)`),placeholder:`{"Server":"nginx"}`,autosize:{minRows:2,maxRows:6}}),(0,A.jsx)(c.TextArea,{field:`body_template`,label:s(`c2.profiles.bodyTemplate`,null,`响应体模板`),placeholder:`{"status":"ok"}`,autosize:{minRows:2,maxRows:6}}),(0,A.jsx)(j,{type:`tertiary`,size:`small`,children:s(`c2.profiles.hintHeaders`,null,`用于伪装为合法服务的 HTTP 响应头`)})]},t?.id||`new`)})}var{Text:F}=r;function I(){let e=d(),{hasPermission:t}=f(),n=t(`c2:write`),r=t(`c2:delete`)||n,[c,p]=(0,k.useState)({visible:!1,record:null}),[_,j]=(0,k.useState)(!1),[M,N]=(0,k.useState)(null),{data:I,loading:L,error:R,reload:z}=h(()=>E(),[]),B=Array.isArray(I?.profiles)?I.profiles:[],V=(0,k.useMemo)(()=>[{id:`total`,label:e(`c2.profiles.total`,null,`Profile 总数`),value:B.length},{id:`jitter`,label:e(`c2.profiles.withJitter`,null,`启用 Jitter`),value:B.filter(e=>Number(e.jitterMaxMs)>0).length},{id:`uris`,label:e(`c2.profiles.withUris`,null,`自定义 URI`),value:B.filter(e=>Array.isArray(e.uris)&&e.uris.length>0).length},{id:`headers`,label:e(`c2.profiles.withHeaders`,null,`自定义响应头`),value:B.filter(e=>e.responseHeaders&&Object.keys(e.responseHeaders).length>0).length}],[B,e]),H=async t=>{j(!0);try{c.record?.id?(await D(c.record.id,t),C(e(`c2.profiles.toastUpdated`,null,`Profile 已更新`))):(await T(t),C(e(`c2.profiles.toastCreated`,null,`Profile 已创建`))),p({visible:!1,record:null}),z()}catch(t){g(t,e(`c2.profiles.saveFailed`,null,`Profile 保存失败`))}finally{j(!1)}},U=t=>{w({title:e(`c2.profiles.delete`,null,`删除 Profile`),content:e(`c2.profiles.confirmDelete`,null,`确定删除此 Profile?`),onOk:async()=>{try{await O(t.id),C(e(`c2.profiles.toastDeleted`,null,`Profile 已删除`)),z()}catch(e){g(e)}}})},W=[{title:e(`c2.profiles.name`,null,`名称`),dataIndex:`name`,render:(e,t)=>(0,A.jsx)(`button`,{type:`button`,className:`c2-profile-name`,onClick:()=>N(t),children:e||t.id})},{title:e(`c2.profiles.userAgent`,null,`User-Agent`),dataIndex:`userAgent`,render:e=>(0,A.jsx)(`span`,{className:`c2-mono c2-profile-ua`,title:e,children:e||`—`})},{title:e(`c2.profiles.uris`,null,`URI 路径`),dataIndex:`uris`,width:220,render:e=>Array.isArray(e)&&e.length?(0,A.jsx)(i,{spacing:4,wrap:!0,children:e.slice(0,3).map(e=>(0,A.jsx)(a,{size:`small`,children:e},e))}):(0,A.jsx)(F,{type:`tertiary`,children:`—`})},{title:e(`c2.profiles.jitter`,null,`Jitter 范围`),dataIndex:`jitterMinMs`,width:140,render:(e,t)=>`${e||0} – ${t.jitterMaxMs||0} ms`},{title:e(`c2.profiles.createdAt`,null,`创建时间`),dataIndex:`createdAt`,width:170,render:e=>u(e)},{title:e(`c2.tasks.colActions`,null,`操作`),dataIndex:`actions`,width:180,render:(t,a)=>(0,A.jsxs)(i,{spacing:4,children:[(0,A.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>N(a),children:e(`c2.profiles.view`,null,`查看`)}),(0,A.jsx)(o,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>p({visible:!0,record:a}),children:e(`c2.profiles.edit`,null,`编辑`)}),(0,A.jsx)(o,{size:`small`,theme:`borderless`,type:`danger`,disabled:!r,onClick:()=>U(a),children:e(`c2.profiles.delete`,null,`删除`)})]})}];return(0,A.jsxs)(`div`,{className:`c2-page`,id:`page-c2-profiles`,children:[(0,A.jsx)(b,{title:e(`c2.profiles.title`,null,`流量伪装`),description:e(`c2.profiles.pageDesc`,null,`维护 HTTP/HTTPS Beacon 的 UA、URI 与响应头模板`),extra:[(0,A.jsx)(o,{icon:(0,A.jsx)(l,{}),onClick:z,loading:L,children:e(`common.refresh`,null,`刷新`)},`refresh`),(0,A.jsx)(o,{theme:`solid`,type:`primary`,icon:(0,A.jsx)(s,{}),disabled:!n,onClick:()=>p({visible:!0,record:null}),children:e(`c2.profiles.createBtn`,null,`创建 Profile`)},`create`)]}),(0,A.jsx)(m,{metrics:V,columns:4}),(0,A.jsx)(v,{error:R,onRetry:z}),(0,A.jsx)(y,{title:e(`c2.profiles.listTitle`,null,`Profile 列表`),children:(0,A.jsx)(x,{columns:W,dataSource:B,rowKey:`id`,loading:L,onRefresh:z,pagination:{pageSize:10},emptyText:e(`c2.profiles.empty`,null,`暂无 Profile`)})}),M&&(0,A.jsx)(y,{title:`${e(`c2.profiles.detailTitle`,null,`Profile 详情`)} · ${M.name||M.id}`,extra:(0,A.jsx)(o,{size:`small`,onClick:()=>N(null),children:e(`c2.profiles.close`,null,`收起`)}),children:(0,A.jsx)(S,{value:M})}),(0,A.jsx)(P,{visible:c.visible,record:c.record,submitting:_,onCancel:()=>p({visible:!1,record:null}),onSubmit:H})]})}export{I as default}; \ No newline at end of file diff --git a/web/static/app/assets/c2-sessions-BFuBJt9m.js b/web/static/app/assets/c2-sessions-CnBIfRAo.js similarity index 98% rename from web/static/app/assets/c2-sessions-BFuBJt9m.js rename to web/static/app/assets/c2-sessions-CnBIfRAo.js index d1fd932d..c8aa84e3 100644 --- a/web/static/app/assets/c2-sessions-BFuBJt9m.js +++ b/web/static/app/assets/c2-sessions-CnBIfRAo.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{E as i,G as a,I as o,N as s,P as c,R as l,S as u,U as d,W as f,c as p,ct as m,lt as h,ut as g,y as _}from"./semi-65W_4I1v.js";import{E as v,F as y,I as b,S as x,a as S,b as C,c as w,d as T,l as E,m as D,n as O,p as k,r as A,s as j,u as M,x as N,y as P}from"./index-CAEPLS-g.js";import{C as F,S as ee,T as te,_ as I,d as L,f as R,g as z,h as B,o as ne,p as V,r as H,s as U,w as W,y as re}from"./c2-shared-Car3lDYq.js";import{c as ie,h as G,l as ae,m as oe,u as K}from"./c2-shared-D-8kBzuC.js";var q=e(t(),1),J=e(n(),1),se=0,ce=()=>(se+=1,se),le=e=>new Promise(t=>setTimeout(t,e));function ue({session:e,canWrite:t,onTaskCreated:n}){let r=y(),[i,a]=(0,q.useState)([]),[c,u]=(0,q.useState)(``),[f,p]=(0,q.useState)(!1),[h,g]=(0,q.useState)(``),_=(0,q.useRef)(!0),v=(0,q.useRef)(null);(0,q.useEffect)(()=>()=>{_.current=!1},[]),(0,q.useEffect)(()=>{let e=v.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let b=(0,q.useCallback)(e=>{a(t=>[...t,{id:ce(),...e}])},[]),S=async e=>{let t=600;for(let n=0;n<40;n+=1){if(!_.current)return null;let n=(await I(e))?.task;if(!n)return null;if([`success`,`failed`,`cancelled`].includes(n.status))return n;await le(t),t=Math.min(Math.round(t*1.4),4e3)}return null},w=async i=>{let a=String(i??c).trim();if(a){if(!t)x(r(`c2.sessions.writeRequired`,null,`当前账号没有下发任务的权限`));else{u(``),b({kind:`cmd`,text:a}),p(!0);try{let t=(await ne(e.id,{task_type:`shell`,payload:{command:a,timeout_seconds:60}}))?.task?.id;if(!t){b({kind:`err`,text:r(`c2.sessions.termNoSession`,null,`下发失败:未返回任务 ID`)});return}g(t),n?.();let i=await S(t);if(!i){b({kind:`warn`,text:r(`c2.sessions.termWaitTimeout`,null,`[等待结果超时]`)});return}i.resultText&&b({kind:i.status===`success`?`out`:`warn`,text:i.resultText}),i.error&&b({kind:`err`,text:i.error}),i.status===`cancelled`&&b({kind:`warn`,text:r(`c2.tasks.cancelled`,null,`已取消`)})}catch(e){b({kind:`err`,text:e?.message||r(`c2.sessions.termStatusErr`,null,`执行失败`)}),C(e)}finally{_.current&&(p(!1),g(``))}}}};return(0,J.jsxs)(`div`,{className:`c2-terminal`,children:[(0,J.jsx)(`div`,{className:`c2-terminal-bar`,children:(0,J.jsxs)(o,{spacing:8,children:[(0,J.jsx)(s,{size:`small`,color:f?`amber`:`green`,children:f?r(`c2.sessions.termStatusExec`,null,`执行中…`):r(`c2.sessions.termStatusReady`,null,`就绪`)}),(0,J.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>a([]),children:r(`c2.sessions.clearTerminal`,null,`清屏`)}),f&&h&&(0,J.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,onClick:async()=>{if(h)try{await H(h),b({kind:`warn`,text:r(`c2.tasks.toastCancelled`,null,`任务已取消`)})}catch(e){C(e)}},children:r(`c2.tasks.cancelBtn`,null,`取消`)})]})}),(0,J.jsxs)(`div`,{className:`c2-terminal-log`,ref:v,children:[(0,J.jsx)(`div`,{className:`c2-terminal-welcome`,children:r(`c2.sessions.terminalWelcome`,null,`C2 终端 — 回车执行;命令以 shell 任务下发并等待结果`)}),i.map(e=>(0,J.jsx)(`pre`,{className:`c2-terminal-line kind-${e.kind}`,children:e.kind===`cmd`?`$ ${e.text}`:e.text},e.id))]}),(0,J.jsxs)(`div`,{className:`c2-terminal-input`,children:[(0,J.jsx)(d,{value:c,onChange:u,onEnterPress:()=>f?x(r(`c2.sessions.termWaitFinish`,null,`请等待当前命令执行完成`)):w(),placeholder:r(`c2.sessions.commandPlaceholder`,null,`输入命令后回车下发`),disabled:f||!t,prefix:`$`}),(0,J.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,J.jsx)(m,{}),loading:f,disabled:!t,onClick:()=>w(),children:r(`c2.sessions.execute`,null,`执行命令`)})]})]})}function de(e){let t=String(e||``).split(/\r?\n/),n=[];for(let e of t){let t=e.trim();if(!t||/^total\s+\d+/i.test(t))continue;let r=t.split(` `);if(r.length>=4){let e=r.slice(3).join(` `).trim();if(!e||e===`.`||e===`..`)continue;let t=r[0].trim(),i=r[1].trim();n.push({name:e,size:r[2].trim(),mode:i||t,isDir:t.startsWith(`d`)||i.startsWith(`d`)});continue}let i=t.match(/^\S{1,10}\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\S+\s+\S+\s+(.+)$/);if(!i)continue;let a=i[1].trim(),o=a.indexOf(` -> `);if(o>0&&(a=a.slice(0,o).trim()),!a||a===`.`||a===`..`)continue;let s=t.split(/\s+/);n.push({name:a,size:s[4]||``,mode:s[0]||``,isDir:(s[0]||``).startsWith(`d`)})}return n}function Y(e){let t=String(e??``).trim();return t?/^[A-Za-z]:/.test(t)?t.replace(/\\+$/,``)||t:(t=t.replace(/\\/g,`/`).replace(/\/{2,}/g,`/`),t.length>1&&(t=t.replace(/\/+$/,``)),t||`.`):`.`}function X(e,t){let n=Y(e);return t?/^[A-Za-z]:/.test(t)||t.startsWith(`/`)||n===`.`||n===``?Y(t):Y(`${n}${n.includes(`\\`)?`\\`:`/`}${t}`):n}function fe(e){let t=Y(e);if(t===`.`||t===`/`||/^[A-Za-z]:$/.test(t))return t;let n=t.includes(`\\`)?`\\`:`/`,r=t.lastIndexOf(n);if(r<0)return`.`;if(r===0)return`/`;let i=t.slice(0,r);return/^[A-Za-z]:$/.test(i)?`${i}${n}`:i}var{Text:pe}=a,me=e=>new Promise(t=>setTimeout(t,e));async function he(e){let t=600;for(let n=0;n<40;n+=1){let n=(await I(e))?.task;if(!n)return null;if([`success`,`failed`,`cancelled`].includes(n.status))return n;await me(t),t=Math.min(Math.round(t*1.4),4e3)}return null}function ge({session:e,canWrite:t}){let n=y(),[r,i]=(0,q.useState)(`.`),[a,s]=(0,q.useState)(`.`),[c,u]=(0,q.useState)([]),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(!1),[_,v]=(0,q.useState)(null),[b,S]=(0,q.useState)(``),w=(0,q.useRef)(!0);(0,q.useEffect)(()=>()=>{w.current=!1},[]);let T=(0,q.useCallback)(async t=>{let a=Y(t??r);h(!0),v(null);try{let t=(await U({session_id:e.id,task_type:`ls`,payload:{path:a}}))?.task?.id;if(!t)throw Error(n(`c2.files.failed`,null,`列目录失败`));let r=await he(t);if(!w.current)return;if(!r){v(n(`c2.files.timeout`,null,`加载文件超时`));return}if(r.status!==`success`){v(r.error||n(`c2.files.failed`,null,`列目录失败`)),u([]),p(r.resultText||``);return}p(r.resultText||``),u(de(r.resultText||``)),i(a),s(a)}catch(e){w.current&&v(e)}finally{w.current&&h(!1)}},[e.id,r,n]);(0,q.useEffect)(()=>{i(`.`),s(`.`),u([]),T(`.`)},[e.id]);let D=async i=>{if(!t){x(n(`c2.files.writeRequired`,null,`当前账号没有下发任务的权限`));return}let a=X(r,i.name);try{let t=(await U({session_id:e.id,task_type:`download`,payload:{path:a}}))?.task?.id;if(!t)throw Error(n(`c2.files.failed`,null,`下载失败`));let r=await he(t);if(!r||r.status!==`success`)throw Error(r?.error||n(`c2.files.failed`,null,`下载失败`));await B(r.id,i.name),N(n(`c2.files.downloadOk`,null,`下载成功`))}catch(e){C(e,n(`c2.files.failed`,null,`下载失败`))}},O=c.filter(e=>{let t=b.trim().toLowerCase();return!t||e.name.toLowerCase().includes(t)}),k=[{title:n(`c2.files.colName`,null,`名称`),dataIndex:`name`,render:(e,t)=>(0,J.jsxs)(`button`,{type:`button`,className:`c2-file-name ${t.isDir?`is-dir`:``}`,onClick:()=>t.isDir?T(X(r,e)):D(t),children:[e,t.isDir?`/`:``]})},{title:n(`c2.files.colSize`,null,`大小`),dataIndex:`size`,width:120},{title:n(`c2.files.colMode`,null,`权限`),dataIndex:`mode`,width:160},{title:n(`c2.files.colActions`,null,`操作`),dataIndex:`actions`,width:160,render:(e,i)=>i.isDir?(0,J.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>T(X(r,i.name)),children:n(`c2.files.open`,null,`打开`)}):(0,J.jsx)(l,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>D(i),children:n(`c2.files.download`,null,`下载`)})}];return(0,J.jsxs)(`div`,{className:`c2-files`,children:[(0,J.jsx)(`div`,{className:`c2-files-toolbar`,children:(0,J.jsxs)(o,{spacing:8,wrap:!0,children:[(0,J.jsx)(l,{size:`small`,onClick:()=>T(fe(r)),children:n(`c2.files.parent`,null,`上级目录`)}),(0,J.jsx)(l,{size:`small`,icon:(0,J.jsx)(g,{}),loading:m,onClick:()=>T(r),children:n(`c2.files.refresh`,null,`刷新`)}),(0,J.jsx)(d,{size:`small`,value:a,onChange:s,onEnterPress:()=>T(a),className:`c2-files-path`}),(0,J.jsx)(l,{size:`small`,onClick:()=>T(a),children:n(`c2.files.go`,null,`跳转`)}),(0,J.jsx)(d,{size:`small`,value:b,onChange:S,placeholder:n(`c2.files.filter`,null,`过滤名称`),className:`c2-files-filter`})]})}),(0,J.jsxs)(pe,{type:`tertiary`,size:`small`,children:[n(`c2.files.currentPath`,null,`当前目录`),`:`,r]}),(0,J.jsx)(E,{error:_,onRetry:()=>T(r)}),c.length===0&&f.trim()&&!m?(0,J.jsx)(`pre`,{className:`c2-pre`,children:f}):(0,J.jsx)(j,{columns:k,dataSource:O,rowKey:`name`,loading:m,pagination:{pageSize:20},emptyText:n(`c2.files.emptyDir`,null,`空目录`)})]})}function _e({session:e,canDelete:t,onChanged:n}){let r=y(),[i,a]=(0,q.useState)(null),{data:c,loading:u,error:d,reload:f}=S(()=>F({session_id:e.id,limit:100}),[e.id]),p=Array.isArray(c?.tasks)?c.tasks:[];A(()=>f({silent:!0}),5e3);let m=async e=>{try{await H(e.id),N(r(`c2.tasks.toastCancelled`,null,`任务已取消`)),f({silent:!0}),n?.()}catch(e){C(e)}},h=e=>{P({title:r(`c2.tasks.deleteOne`,null,`删除任务`),content:r(`c2.tasks.confirmDeleteOne`,null,`确定从服务器删除该任务记录吗?此操作不可恢复。`),onOk:async()=>{try{await V([e.id]),N(r(`c2.tasks.toastDeleted`,null,`已删除 {{n}} 条`).replace(`{{n}}`,`1`)),f({silent:!0}),n?.()}catch(e){C(e)}}})},g=[{title:r(`c2.tasks.colType`,null,`类型`),dataIndex:`taskType`,width:120},{title:r(`c2.tasks.colCommand`,null,`命令`),dataIndex:`payload`,render:e=>{let t=e?.command||e?.path||``;return(0,J.jsx)(`span`,{className:`c2-mono`,children:t||`—`})}},{title:r(`c2.tasks.colStatus`,null,`状态`),dataIndex:`status`,width:110,render:e=>(0,J.jsx)(s,{size:`small`,color:K[e]||`grey`,children:r(`c2.tasks.${e||`queued`}`,null,e||`—`)})},{title:r(`c2.tasks.colDuration`,null,`耗时`),dataIndex:`durationMs`,width:100,render:e=>G(e)},{title:r(`c2.tasks.colCreated`,null,`创建时间`),dataIndex:`createdAt`,width:140,render:e=>(0,J.jsx)(oe,{value:e})},{title:r(`c2.tasks.colActions`,null,`操作`),dataIndex:`actions`,width:200,render:(e,n)=>(0,J.jsxs)(o,{spacing:4,wrap:!0,children:[(0,J.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>a(n),children:r(`c2.tasks.view`,null,`查看`)}),[`queued`,`sent`,`running`].includes(n.status)&&(0,J.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>m(n),children:r(`c2.tasks.cancelBtn`,null,`取消`)}),(0,J.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>h(n),children:r(`c2.tasks.deleteBtn`,null,`删除`)})]})}];return(0,J.jsxs)(`div`,{className:`c2-session-tasks`,children:[(0,J.jsx)(E,{error:d,onRetry:()=>f()}),(0,J.jsx)(j,{columns:g,dataSource:p,rowKey:`id`,loading:u,onRefresh:()=>f(),pagination:{pageSize:10},emptyText:r(`c2.tasks.emptySession`,null,`该会话暂无任务`)}),(0,J.jsx)(w,{visible:!!i,title:r(`c2.tasks.modalTitle`,null,`任务详情`),width:720,onCancel:()=>a(null),footer:(0,J.jsx)(l,{onClick:()=>a(null),children:r(`c2.tasks.close`,null,`关闭`)}),children:i&&(0,J.jsxs)(`div`,{className:`c2-task-detail`,children:[(0,J.jsxs)(`div`,{className:`c2-task-detail-meta`,children:[(0,J.jsx)(`span`,{className:`c2-mono`,children:i.id}),(0,J.jsx)(s,{size:`small`,color:K[i.status]||`grey`,children:i.status}),(0,J.jsx)(`span`,{className:`c2-muted`,children:v(i.createdAt)})]}),i.payload&&(0,J.jsx)(M,{title:r(`c2.tasks.labelPayload`,null,`参数`),value:i.payload,collapsed:!0}),i.resultText&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`c2-field-label`,children:r(`c2.tasks.labelResult`,null,`输出`)}),(0,J.jsx)(`pre`,{className:`c2-pre`,children:i.resultText})]}),i.error&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`c2-field-label`,children:r(`c2.tasks.labelError`,null,`错误`)}),(0,J.jsx)(`pre`,{className:`c2-pre c2-pre-error`,children:i.error})]})]})})]})}var{Text:Z}=a;function ve({session:e,canWrite:t,onEditNote:n}){let r=y(),i=[{label:r(`c2.sessions.infoSessionId`,null,`会话 ID`),value:(0,J.jsx)(Z,{copyable:{text:e.id},className:`c2-mono`,children:e.id})},{label:r(`c2.sessions.infoImplantUuid`,null,`植入体 UUID`),value:(0,J.jsx)(Z,{className:`c2-mono`,children:e.implantUuid||`—`})},{label:r(`c2.sessions.infoHostname`,null,`主机名`),value:e.hostname||`—`},{label:r(`c2.sessions.infoUsername`,null,`用户名`),value:e.username||`—`},{label:r(`c2.sessions.infoProcess`,null,`进程`),value:e.processName||`—`},{label:r(`c2.sessions.infoPid`,null,`PID`),value:e.pid||`—`}],a=[{label:r(`c2.sessions.infoOs`,null,`操作系统`),value:e.os||`—`},{label:r(`c2.sessions.infoArch`,null,`架构`),value:e.arch||`—`},{label:r(`c2.sessions.infoAdmin`,null,`管理员`),value:e.isAdmin?r(`c2.sessions.adminYes`,null,`是`):r(`c2.sessions.adminNo`,null,`否`)},{label:r(`c2.sessions.infoInternalIp`,null,`内网 IP`),value:(0,J.jsx)(`span`,{className:`c2-mono`,children:e.internalIp||`—`})},{label:r(`c2.sessions.ip`,null,`外网 IP`),value:(0,J.jsx)(`span`,{className:`c2-mono`,children:e.externalIp||`—`})},{label:r(`c2.sessions.infoSleep`,null,`Sleep`),value:`${e.sleepSeconds||0}s ± ${e.jitterPercent||0}%`}],s=[{label:r(`c2.sessions.infoFirstSeen`,null,`首次上线`),value:v(e.firstSeenAt)},{label:r(`c2.sessions.infoLastCheckin`,null,`上次心跳`),value:v(e.lastCheckIn)},{label:r(`c2.sessions.status`,null,`状态`),value:e.status||`—`},{label:r(`c2.sessions.listener`,null,`监听器`),value:(0,J.jsx)(`span`,{className:`c2-mono`,children:e.listenerId||`—`})}];return(0,J.jsxs)(`div`,{className:`c2-session-info`,children:[(0,J.jsx)(D,{title:r(`c2.sessions.infoSectionIdentity`,null,`身份信息`),children:(0,J.jsx)(T,{items:i,columns:2})}),(0,J.jsx)(D,{title:r(`c2.sessions.infoSectionSystem`,null,`系统环境`),children:(0,J.jsx)(T,{items:a,columns:2})}),(0,J.jsx)(D,{title:r(`c2.sessions.infoSectionNetwork`,null,`网络与信标`),children:(0,J.jsx)(T,{items:s,columns:2})}),(0,J.jsx)(D,{title:r(`c2.sessions.infoSectionNote`,null,`备注`),extra:(0,J.jsx)(o,{children:(0,J.jsx)(l,{size:`small`,disabled:!t,onClick:n,children:r(`c2.sessions.noteEdit`,null,`编辑`)})}),children:(0,J.jsx)(Z,{type:e.note?void 0:`tertiary`,children:e.note||r(`c2.sessions.infoNoteEmpty`,null,`暂无备注`)})}),e.metadata&&Object.keys(e.metadata).length>0&&(0,J.jsx)(D,{title:r(`c2.sessions.infoMetadata`,null,`原始元数据`),children:(0,J.jsx)(M,{value:e.metadata,collapsed:!0})})]})}var{Text:Q}=a;function ye({session:e,canWrite:t,canDelete:n,onChanged:r,onDeleted:i}){let a=y(),[c,f]=(0,q.useState)(`terminal`),[m,h]=(0,q.useState)(null),[_,v]=(0,q.useState)(null),[b,T]=(0,q.useState)(!1),{data:D,loading:O,error:k,reload:A}=S(()=>z(e.id),[e.id]),j=D?.session||e,M=()=>h({sleepSeconds:String(j.sleepSeconds||5),jitterPercent:String(j.jitterPercent||0)}),F=()=>v({note:j.note||``}),ee=async()=>{let e=Number(m.sleepSeconds),t=Number(m.jitterPercent);if(!Number.isFinite(e)||e<1)x(a(`c2.sessions.toastSleepInvalid`,null,`Sleep 间隔至少为 1 秒`));else if(!Number.isFinite(t)||t<0||t>100)x(a(`c2.sessions.toastSleepInvalid`,null,`抖动百分比需在 0–100 之间`));else{T(!0);try{await te(j.id,{sleepSeconds:e,jitterPercent:t}),N(a(`c2.sessions.toastSleepUpdated`,null,`Sleep 设置已更新`)),h(null),A({silent:!0}),r?.()}catch(e){C(e)}finally{T(!1)}}},I=async()=>{let e=String(_.note||``).trim();if(e.length>2e3)x(a(`c2.sessions.toastNoteTooLong`,null,`备注最多 2000 字`));else{T(!0);try{await W(j.id,e),N(a(`c2.sessions.toastNoteSaved`,null,`备注已保存`)),v(null),A({silent:!0}),r?.()}catch(e){C(e)}finally{T(!1)}}},R=()=>{P({title:a(`c2.sessions.cardDeleteSession`,null,`删除会话`),content:a(`c2.sessions.confirmDeleteSession`,null,`从服务器删除此会话及其关联任务与文件记录?`),onOk:async()=>{try{await L(j.id),N(a(`c2.sessions.toastSessionDeleted`,null,`会话记录已删除`)),i?.()}catch(e){C(e)}}})},B=[{tab:a(`c2.sessions.terminal`,null,`终端`),itemKey:`terminal`,children:(0,J.jsx)(ue,{session:j,canWrite:t,onTaskCreated:A})},{tab:a(`c2.sessions.files`,null,`文件`),itemKey:`files`,children:(0,J.jsx)(ge,{session:j,canWrite:t})},{tab:a(`c2.sessions.tasks`,null,`任务`),itemKey:`tasks`,children:(0,J.jsx)(_e,{session:j,canDelete:n,onChanged:A})},{tab:a(`c2.sessions.info`,null,`信息`),itemKey:`info`,children:(0,J.jsx)(ve,{session:j,canWrite:t,onEditNote:F})}];return(0,J.jsxs)(`div`,{className:`c2-session-detail`,children:[(0,J.jsxs)(`div`,{className:`c2-session-head`,children:[(0,J.jsxs)(`div`,{className:`c2-session-title`,children:[(0,J.jsx)(Q,{strong:!0,className:`c2-session-hostname`,children:j.hostname||a(`c2.sessions.unknownHost`,null,`未知主机`)}),(0,J.jsxs)(o,{spacing:6,wrap:!0,children:[(0,J.jsx)(s,{size:`small`,color:ie[j.status]||`grey`,children:a(`c2.sessions.${j.status||`active`}`,null,j.status||`—`)}),(0,J.jsxs)(s,{size:`small`,children:[j.os||`—`,`/`,j.arch||`—`]}),j.isAdmin&&(0,J.jsx)(s,{size:`small`,color:`red`,children:a(`c2.sessions.rootBadge`,null,`ROOT`)}),(0,J.jsxs)(Q,{type:`tertiary`,size:`small`,children:[j.username||`—`,`@`,j.internalIp||j.externalIp||`—`]}),(0,J.jsxs)(Q,{type:`tertiary`,size:`small`,children:[`sleep `,j.sleepSeconds||0,`s ± `,j.jitterPercent||0,`%`]})]})]}),(0,J.jsxs)(o,{spacing:6,wrap:!0,children:[(0,J.jsx)(l,{size:`small`,icon:(0,J.jsx)(g,{}),loading:O,onClick:()=>A(),children:a(`common.refresh`,null,`刷新`)}),(0,J.jsx)(l,{size:`small`,disabled:!t,onClick:M,children:a(`c2.sessions.btnSleep`,null,`Sleep`)}),(0,J.jsx)(l,{size:`small`,disabled:!t,onClick:F,children:a(`c2.sessions.noteEdit`,null,`备注`)}),(0,J.jsx)(l,{size:`small`,type:`danger`,disabled:!n,onClick:R,children:a(`c2.sessions.cardDeleteSession`,null,`删除会话`)})]})]}),(0,J.jsx)(E,{error:k,onRetry:A}),(0,J.jsx)(p,{type:`button`,activeKey:c,onChange:f,items:B}),(0,J.jsxs)(w,{visible:!!m,title:a(`c2.sessions.sleepModalTitle`,null,`心跳配置`),width:440,onCancel:()=>h(null),onOk:ee,confirmLoading:b,children:[(0,J.jsx)(Q,{type:`tertiary`,size:`small`,children:a(`c2.sessions.sleepModalHint`,null,`保存后将写入服务端并下发 sleep 任务。`)}),(0,J.jsxs)(`div`,{className:`c2-session-modal-field`,children:[(0,J.jsx)(Q,{size:`small`,children:a(`c2.sessions.promptSleepSeconds`,null,`Sleep 间隔(秒)`)}),(0,J.jsx)(d,{value:m?.sleepSeconds||``,onChange:e=>h(t=>({...t,sleepSeconds:e}))})]}),(0,J.jsxs)(`div`,{className:`c2-session-modal-field`,children:[(0,J.jsx)(Q,{size:`small`,children:a(`c2.sessions.promptJitterPercent`,null,`抖动百分比(0–100)`)}),(0,J.jsx)(d,{value:m?.jitterPercent||``,onChange:e=>h(t=>({...t,jitterPercent:e}))})]})]}),(0,J.jsx)(w,{visible:!!_,title:a(`c2.sessions.infoNote`,null,`备注`),width:480,onCancel:()=>v(null),onOk:I,confirmLoading:b,children:(0,J.jsx)(u,{value:_?.note||``,onChange:e=>v(t=>({...t,note:e})),placeholder:a(`c2.sessions.notePlaceholder`,null,`添加备注,便于识别该会话…`),autosize:{minRows:4,maxRows:10}})})]})}var{Text:$}=a;function be(){let e=y(),{hasPermission:t}=b(),n=t(`c2:write`),a=t(`c2:delete`)||n,[o,u]=r(),p=o.get(`id`)||``,[m,v]=(0,q.useState)(``),[x,w]=(0,q.useState)(``),[T,D]=(0,q.useState)(!1),[j,M]=(0,q.useState)(``),[F,te]=(0,q.useState)(!0),I=O(j,300),L=(0,q.useMemo)(()=>({status:m||void 0,listener_id:x||void 0,search:I||void 0,suspicious:T?`1`:void 0,limit:200}),[m,x,I,T]),{data:z,loading:B,error:ne,reload:V}=S(()=>Promise.all([ee(L),re().catch(()=>({listeners:[]}))]),[L]),H=Array.isArray(z?.[0]?.sessions)?z[0].sessions:[],U=Array.isArray(z?.[1]?.listeners)?z[1].listeners:[];A(()=>{F&&V({silent:!0})},F?1e4:0);let W=(0,q.useMemo)(()=>H.find(e=>e.id===p)||null,[H,p]),G=e=>{let t=new URLSearchParams(o);e?t.set(`id`,e):t.delete(`id`),u(t,{replace:!0})};return(0,J.jsxs)(`div`,{className:`c2-page`,id:`page-c2-sessions`,children:[(0,J.jsx)(k,{title:e(`c2.sessions.title`,null,`会话管理`),description:e(`c2.sessions.pageDesc`,null,`查看上线会话,下发命令、浏览文件并管理任务历史`),extra:[(0,J.jsx)(l,{icon:(0,J.jsx)(g,{}),onClick:V,loading:B,children:e(`common.refresh`,null,`刷新`)},`refresh`),(0,J.jsx)(l,{type:`danger`,disabled:!a||!H.length,onClick:()=>{H.length?P({title:e(`c2.sessions.deleteFiltered`,null,`删除筛选结果`),content:e(`c2.sessions.confirmDeleteFiltered`,null,`确定删除当前筛选结果中的全部会话?`).replace(`{{n}}`,String(H.length)),onOk:async()=>{try{let t=await R(H.map(e=>e.id));N(e(`c2.sessions.toastBatchDeleted`,null,`已删除 {{n}} 个会话`).replace(`{{n}}`,String(t?.deleted??H.length))),G(``),V()}catch(e){C(e)}}}):C(e(`c2.sessions.toastSelectFirst`,null,`没有可删除的会话`))},children:e(`c2.sessions.deleteFiltered`,null,`删除筛选结果`)},`delete`)]}),(0,J.jsx)(E,{error:ne,onRetry:V}),(0,J.jsxs)(`div`,{className:`c2-session-layout`,children:[(0,J.jsxs)(`aside`,{className:`c2-session-sidebar`,children:[(0,J.jsxs)(`div`,{className:`c2-session-filters`,children:[(0,J.jsx)(_,{size:`small`,value:m,onChange:e=>v(e||``),style:{width:`100%`},optionList:[{value:``,label:e(`c2.sessions.filterAllStatus`,null,`全部状态`)},...ae]}),(0,J.jsx)(_,{size:`small`,value:x,onChange:e=>w(e||``),style:{width:`100%`},optionList:[{value:``,label:e(`c2.sessions.filterAllListeners`,null,`全部监听器`)},...U.map(e=>({value:e.id,label:e.name||e.id}))]}),(0,J.jsx)(d,{size:`small`,value:j,onChange:M,prefix:(0,J.jsx)(h,{}),placeholder:e(`c2.sessions.filterSearchPlaceholder`,null,`搜索主机名 / 用户 / IP`)}),(0,J.jsxs)(`div`,{className:`c2-session-filter-foot`,children:[(0,J.jsx)(c,{checked:T,onChange:e=>D(!!e.target.checked),children:(0,J.jsx)($,{size:`small`,children:e(`c2.sessions.filterSuspicious`,null,`疑似误报`)})}),(0,J.jsx)(c,{checked:F,onChange:e=>te(!!e.target.checked),children:(0,J.jsx)($,{size:`small`,children:e(`c2.sessions.autoRefresh`,null,`自动刷新`)})})]}),(0,J.jsx)($,{type:`tertiary`,size:`small`,children:e(`c2.sessions.listCount`,null,`共 {{n}} 条`).replace(`{{n}}`,String(H.length))})]}),(0,J.jsxs)(`div`,{className:`c2-session-list`,children:[B&&!H.length&&(0,J.jsx)(`div`,{className:`c2-session-loading`,children:(0,J.jsx)(f,{})}),!B&&H.length===0&&(0,J.jsx)(i,{title:j||m||x?e(`c2.sessions.emptyFilter`,null,`没有符合筛选条件的会话`):e(`c2.sessions.listEmpty`,null,`暂无会话`),description:null,style:{padding:24}}),H.map(t=>(0,J.jsxs)(`button`,{type:`button`,className:`c2-session-item ${t.id===p?`is-active`:``}`,onClick:()=>G(t.id),children:[(0,J.jsxs)(`div`,{className:`c2-session-item-head`,children:[(0,J.jsx)(`span`,{className:`c2-session-host`,children:t.hostname||e(`c2.sessions.unknownHost`,null,`未知`)}),(0,J.jsx)(s,{size:`small`,color:ie[t.status]||`grey`,children:e(`c2.sessions.${t.status||`active`}`,null,t.status||`—`)})]}),(0,J.jsxs)(`div`,{className:`c2-session-item-meta`,children:[(0,J.jsx)(`span`,{children:t.username||`—`}),(0,J.jsxs)(`span`,{children:[t.os||`—`,`/`,t.arch||`—`]}),t.isAdmin&&(0,J.jsx)(s,{size:`small`,color:`red`,children:`ROOT`})]}),(0,J.jsxs)(`div`,{className:`c2-session-item-foot`,children:[(0,J.jsx)(`span`,{className:`c2-mono`,children:t.internalIp||t.externalIp||`—`}),(0,J.jsx)(oe,{value:t.lastCheckIn})]})]},t.id))]})]}),(0,J.jsx)(`section`,{className:`c2-session-main`,children:W?(0,J.jsx)(ye,{session:W,canWrite:n,canDelete:a,onChanged:V,onDeleted:()=>{G(``),V()}},W.id):(0,J.jsx)(i,{title:e(`c2.sessions.selectPromptTitle`,null,`选择会话`),description:e(`c2.sessions.selectPromptHint`,null,`在左侧列表中点击一个会话,查看终端、文件与任务详情。`),style:{padding:64}})})]})]})}export{be as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{E as i,G as a,I as o,N as s,P as c,R as l,S as u,U as d,W as f,c as p,ct as m,lt as h,ut as g,y as _}from"./semi-65W_4I1v.js";import{E as v,F as y,I as b,S as x,a as S,b as C,c as w,d as T,l as E,m as D,n as O,p as k,r as A,s as j,u as M,x as N,y as P}from"./index-DNMXun-U.js";import{C as F,S as ee,T as te,_ as I,d as L,f as R,g as z,h as B,o as ne,p as V,r as H,s as U,w as W,y as re}from"./c2-shared-2EAlkwn6.js";import{c as ie,h as G,l as ae,m as oe,u as K}from"./c2-shared-BrRxH-6B.js";var q=e(t(),1),J=e(n(),1),se=0,ce=()=>(se+=1,se),le=e=>new Promise(t=>setTimeout(t,e));function ue({session:e,canWrite:t,onTaskCreated:n}){let r=y(),[i,a]=(0,q.useState)([]),[c,u]=(0,q.useState)(``),[f,p]=(0,q.useState)(!1),[h,g]=(0,q.useState)(``),_=(0,q.useRef)(!0),v=(0,q.useRef)(null);(0,q.useEffect)(()=>()=>{_.current=!1},[]),(0,q.useEffect)(()=>{let e=v.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let b=(0,q.useCallback)(e=>{a(t=>[...t,{id:ce(),...e}])},[]),S=async e=>{let t=600;for(let n=0;n<40;n+=1){if(!_.current)return null;let n=(await I(e))?.task;if(!n)return null;if([`success`,`failed`,`cancelled`].includes(n.status))return n;await le(t),t=Math.min(Math.round(t*1.4),4e3)}return null},w=async i=>{let a=String(i??c).trim();if(a){if(!t)x(r(`c2.sessions.writeRequired`,null,`当前账号没有下发任务的权限`));else{u(``),b({kind:`cmd`,text:a}),p(!0);try{let t=(await ne(e.id,{task_type:`shell`,payload:{command:a,timeout_seconds:60}}))?.task?.id;if(!t){b({kind:`err`,text:r(`c2.sessions.termNoSession`,null,`下发失败:未返回任务 ID`)});return}g(t),n?.();let i=await S(t);if(!i){b({kind:`warn`,text:r(`c2.sessions.termWaitTimeout`,null,`[等待结果超时]`)});return}i.resultText&&b({kind:i.status===`success`?`out`:`warn`,text:i.resultText}),i.error&&b({kind:`err`,text:i.error}),i.status===`cancelled`&&b({kind:`warn`,text:r(`c2.tasks.cancelled`,null,`已取消`)})}catch(e){b({kind:`err`,text:e?.message||r(`c2.sessions.termStatusErr`,null,`执行失败`)}),C(e)}finally{_.current&&(p(!1),g(``))}}}};return(0,J.jsxs)(`div`,{className:`c2-terminal`,children:[(0,J.jsx)(`div`,{className:`c2-terminal-bar`,children:(0,J.jsxs)(o,{spacing:8,children:[(0,J.jsx)(s,{size:`small`,color:f?`amber`:`green`,children:f?r(`c2.sessions.termStatusExec`,null,`执行中…`):r(`c2.sessions.termStatusReady`,null,`就绪`)}),(0,J.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>a([]),children:r(`c2.sessions.clearTerminal`,null,`清屏`)}),f&&h&&(0,J.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,onClick:async()=>{if(h)try{await H(h),b({kind:`warn`,text:r(`c2.tasks.toastCancelled`,null,`任务已取消`)})}catch(e){C(e)}},children:r(`c2.tasks.cancelBtn`,null,`取消`)})]})}),(0,J.jsxs)(`div`,{className:`c2-terminal-log`,ref:v,children:[(0,J.jsx)(`div`,{className:`c2-terminal-welcome`,children:r(`c2.sessions.terminalWelcome`,null,`C2 终端 — 回车执行;命令以 shell 任务下发并等待结果`)}),i.map(e=>(0,J.jsx)(`pre`,{className:`c2-terminal-line kind-${e.kind}`,children:e.kind===`cmd`?`$ ${e.text}`:e.text},e.id))]}),(0,J.jsxs)(`div`,{className:`c2-terminal-input`,children:[(0,J.jsx)(d,{value:c,onChange:u,onEnterPress:()=>f?x(r(`c2.sessions.termWaitFinish`,null,`请等待当前命令执行完成`)):w(),placeholder:r(`c2.sessions.commandPlaceholder`,null,`输入命令后回车下发`),disabled:f||!t,prefix:`$`}),(0,J.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,J.jsx)(m,{}),loading:f,disabled:!t,onClick:()=>w(),children:r(`c2.sessions.execute`,null,`执行命令`)})]})]})}function de(e){let t=String(e||``).split(/\r?\n/),n=[];for(let e of t){let t=e.trim();if(!t||/^total\s+\d+/i.test(t))continue;let r=t.split(` `);if(r.length>=4){let e=r.slice(3).join(` `).trim();if(!e||e===`.`||e===`..`)continue;let t=r[0].trim(),i=r[1].trim();n.push({name:e,size:r[2].trim(),mode:i||t,isDir:t.startsWith(`d`)||i.startsWith(`d`)});continue}let i=t.match(/^\S{1,10}\s+\d+\s+\S+\s+\S+\s+\d+\s+\S+\s+\S+\s+\S+\s+(.+)$/);if(!i)continue;let a=i[1].trim(),o=a.indexOf(` -> `);if(o>0&&(a=a.slice(0,o).trim()),!a||a===`.`||a===`..`)continue;let s=t.split(/\s+/);n.push({name:a,size:s[4]||``,mode:s[0]||``,isDir:(s[0]||``).startsWith(`d`)})}return n}function Y(e){let t=String(e??``).trim();return t?/^[A-Za-z]:/.test(t)?t.replace(/\\+$/,``)||t:(t=t.replace(/\\/g,`/`).replace(/\/{2,}/g,`/`),t.length>1&&(t=t.replace(/\/+$/,``)),t||`.`):`.`}function X(e,t){let n=Y(e);return t?/^[A-Za-z]:/.test(t)||t.startsWith(`/`)||n===`.`||n===``?Y(t):Y(`${n}${n.includes(`\\`)?`\\`:`/`}${t}`):n}function fe(e){let t=Y(e);if(t===`.`||t===`/`||/^[A-Za-z]:$/.test(t))return t;let n=t.includes(`\\`)?`\\`:`/`,r=t.lastIndexOf(n);if(r<0)return`.`;if(r===0)return`/`;let i=t.slice(0,r);return/^[A-Za-z]:$/.test(i)?`${i}${n}`:i}var{Text:pe}=a,me=e=>new Promise(t=>setTimeout(t,e));async function he(e){let t=600;for(let n=0;n<40;n+=1){let n=(await I(e))?.task;if(!n)return null;if([`success`,`failed`,`cancelled`].includes(n.status))return n;await me(t),t=Math.min(Math.round(t*1.4),4e3)}return null}function ge({session:e,canWrite:t}){let n=y(),[r,i]=(0,q.useState)(`.`),[a,s]=(0,q.useState)(`.`),[c,u]=(0,q.useState)([]),[f,p]=(0,q.useState)(``),[m,h]=(0,q.useState)(!1),[_,v]=(0,q.useState)(null),[b,S]=(0,q.useState)(``),w=(0,q.useRef)(!0);(0,q.useEffect)(()=>()=>{w.current=!1},[]);let T=(0,q.useCallback)(async t=>{let a=Y(t??r);h(!0),v(null);try{let t=(await U({session_id:e.id,task_type:`ls`,payload:{path:a}}))?.task?.id;if(!t)throw Error(n(`c2.files.failed`,null,`列目录失败`));let r=await he(t);if(!w.current)return;if(!r){v(n(`c2.files.timeout`,null,`加载文件超时`));return}if(r.status!==`success`){v(r.error||n(`c2.files.failed`,null,`列目录失败`)),u([]),p(r.resultText||``);return}p(r.resultText||``),u(de(r.resultText||``)),i(a),s(a)}catch(e){w.current&&v(e)}finally{w.current&&h(!1)}},[e.id,r,n]);(0,q.useEffect)(()=>{i(`.`),s(`.`),u([]),T(`.`)},[e.id]);let D=async i=>{if(!t){x(n(`c2.files.writeRequired`,null,`当前账号没有下发任务的权限`));return}let a=X(r,i.name);try{let t=(await U({session_id:e.id,task_type:`download`,payload:{path:a}}))?.task?.id;if(!t)throw Error(n(`c2.files.failed`,null,`下载失败`));let r=await he(t);if(!r||r.status!==`success`)throw Error(r?.error||n(`c2.files.failed`,null,`下载失败`));await B(r.id,i.name),N(n(`c2.files.downloadOk`,null,`下载成功`))}catch(e){C(e,n(`c2.files.failed`,null,`下载失败`))}},O=c.filter(e=>{let t=b.trim().toLowerCase();return!t||e.name.toLowerCase().includes(t)}),k=[{title:n(`c2.files.colName`,null,`名称`),dataIndex:`name`,render:(e,t)=>(0,J.jsxs)(`button`,{type:`button`,className:`c2-file-name ${t.isDir?`is-dir`:``}`,onClick:()=>t.isDir?T(X(r,e)):D(t),children:[e,t.isDir?`/`:``]})},{title:n(`c2.files.colSize`,null,`大小`),dataIndex:`size`,width:120},{title:n(`c2.files.colMode`,null,`权限`),dataIndex:`mode`,width:160},{title:n(`c2.files.colActions`,null,`操作`),dataIndex:`actions`,width:160,render:(e,i)=>i.isDir?(0,J.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>T(X(r,i.name)),children:n(`c2.files.open`,null,`打开`)}):(0,J.jsx)(l,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>D(i),children:n(`c2.files.download`,null,`下载`)})}];return(0,J.jsxs)(`div`,{className:`c2-files`,children:[(0,J.jsx)(`div`,{className:`c2-files-toolbar`,children:(0,J.jsxs)(o,{spacing:8,wrap:!0,children:[(0,J.jsx)(l,{size:`small`,onClick:()=>T(fe(r)),children:n(`c2.files.parent`,null,`上级目录`)}),(0,J.jsx)(l,{size:`small`,icon:(0,J.jsx)(g,{}),loading:m,onClick:()=>T(r),children:n(`c2.files.refresh`,null,`刷新`)}),(0,J.jsx)(d,{size:`small`,value:a,onChange:s,onEnterPress:()=>T(a),className:`c2-files-path`}),(0,J.jsx)(l,{size:`small`,onClick:()=>T(a),children:n(`c2.files.go`,null,`跳转`)}),(0,J.jsx)(d,{size:`small`,value:b,onChange:S,placeholder:n(`c2.files.filter`,null,`过滤名称`),className:`c2-files-filter`})]})}),(0,J.jsxs)(pe,{type:`tertiary`,size:`small`,children:[n(`c2.files.currentPath`,null,`当前目录`),`:`,r]}),(0,J.jsx)(E,{error:_,onRetry:()=>T(r)}),c.length===0&&f.trim()&&!m?(0,J.jsx)(`pre`,{className:`c2-pre`,children:f}):(0,J.jsx)(j,{columns:k,dataSource:O,rowKey:`name`,loading:m,pagination:{pageSize:20},emptyText:n(`c2.files.emptyDir`,null,`空目录`)})]})}function _e({session:e,canDelete:t,onChanged:n}){let r=y(),[i,a]=(0,q.useState)(null),{data:c,loading:u,error:d,reload:f}=S(()=>F({session_id:e.id,limit:100}),[e.id]),p=Array.isArray(c?.tasks)?c.tasks:[];A(()=>f({silent:!0}),5e3);let m=async e=>{try{await H(e.id),N(r(`c2.tasks.toastCancelled`,null,`任务已取消`)),f({silent:!0}),n?.()}catch(e){C(e)}},h=e=>{P({title:r(`c2.tasks.deleteOne`,null,`删除任务`),content:r(`c2.tasks.confirmDeleteOne`,null,`确定从服务器删除该任务记录吗?此操作不可恢复。`),onOk:async()=>{try{await V([e.id]),N(r(`c2.tasks.toastDeleted`,null,`已删除 {{n}} 条`).replace(`{{n}}`,`1`)),f({silent:!0}),n?.()}catch(e){C(e)}}})},g=[{title:r(`c2.tasks.colType`,null,`类型`),dataIndex:`taskType`,width:120},{title:r(`c2.tasks.colCommand`,null,`命令`),dataIndex:`payload`,render:e=>{let t=e?.command||e?.path||``;return(0,J.jsx)(`span`,{className:`c2-mono`,children:t||`—`})}},{title:r(`c2.tasks.colStatus`,null,`状态`),dataIndex:`status`,width:110,render:e=>(0,J.jsx)(s,{size:`small`,color:K[e]||`grey`,children:r(`c2.tasks.${e||`queued`}`,null,e||`—`)})},{title:r(`c2.tasks.colDuration`,null,`耗时`),dataIndex:`durationMs`,width:100,render:e=>G(e)},{title:r(`c2.tasks.colCreated`,null,`创建时间`),dataIndex:`createdAt`,width:140,render:e=>(0,J.jsx)(oe,{value:e})},{title:r(`c2.tasks.colActions`,null,`操作`),dataIndex:`actions`,width:200,render:(e,n)=>(0,J.jsxs)(o,{spacing:4,wrap:!0,children:[(0,J.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>a(n),children:r(`c2.tasks.view`,null,`查看`)}),[`queued`,`sent`,`running`].includes(n.status)&&(0,J.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>m(n),children:r(`c2.tasks.cancelBtn`,null,`取消`)}),(0,J.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>h(n),children:r(`c2.tasks.deleteBtn`,null,`删除`)})]})}];return(0,J.jsxs)(`div`,{className:`c2-session-tasks`,children:[(0,J.jsx)(E,{error:d,onRetry:()=>f()}),(0,J.jsx)(j,{columns:g,dataSource:p,rowKey:`id`,loading:u,onRefresh:()=>f(),pagination:{pageSize:10},emptyText:r(`c2.tasks.emptySession`,null,`该会话暂无任务`)}),(0,J.jsx)(w,{visible:!!i,title:r(`c2.tasks.modalTitle`,null,`任务详情`),width:720,onCancel:()=>a(null),footer:(0,J.jsx)(l,{onClick:()=>a(null),children:r(`c2.tasks.close`,null,`关闭`)}),children:i&&(0,J.jsxs)(`div`,{className:`c2-task-detail`,children:[(0,J.jsxs)(`div`,{className:`c2-task-detail-meta`,children:[(0,J.jsx)(`span`,{className:`c2-mono`,children:i.id}),(0,J.jsx)(s,{size:`small`,color:K[i.status]||`grey`,children:i.status}),(0,J.jsx)(`span`,{className:`c2-muted`,children:v(i.createdAt)})]}),i.payload&&(0,J.jsx)(M,{title:r(`c2.tasks.labelPayload`,null,`参数`),value:i.payload,collapsed:!0}),i.resultText&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`c2-field-label`,children:r(`c2.tasks.labelResult`,null,`输出`)}),(0,J.jsx)(`pre`,{className:`c2-pre`,children:i.resultText})]}),i.error&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`c2-field-label`,children:r(`c2.tasks.labelError`,null,`错误`)}),(0,J.jsx)(`pre`,{className:`c2-pre c2-pre-error`,children:i.error})]})]})})]})}var{Text:Z}=a;function ve({session:e,canWrite:t,onEditNote:n}){let r=y(),i=[{label:r(`c2.sessions.infoSessionId`,null,`会话 ID`),value:(0,J.jsx)(Z,{copyable:{text:e.id},className:`c2-mono`,children:e.id})},{label:r(`c2.sessions.infoImplantUuid`,null,`植入体 UUID`),value:(0,J.jsx)(Z,{className:`c2-mono`,children:e.implantUuid||`—`})},{label:r(`c2.sessions.infoHostname`,null,`主机名`),value:e.hostname||`—`},{label:r(`c2.sessions.infoUsername`,null,`用户名`),value:e.username||`—`},{label:r(`c2.sessions.infoProcess`,null,`进程`),value:e.processName||`—`},{label:r(`c2.sessions.infoPid`,null,`PID`),value:e.pid||`—`}],a=[{label:r(`c2.sessions.infoOs`,null,`操作系统`),value:e.os||`—`},{label:r(`c2.sessions.infoArch`,null,`架构`),value:e.arch||`—`},{label:r(`c2.sessions.infoAdmin`,null,`管理员`),value:e.isAdmin?r(`c2.sessions.adminYes`,null,`是`):r(`c2.sessions.adminNo`,null,`否`)},{label:r(`c2.sessions.infoInternalIp`,null,`内网 IP`),value:(0,J.jsx)(`span`,{className:`c2-mono`,children:e.internalIp||`—`})},{label:r(`c2.sessions.ip`,null,`外网 IP`),value:(0,J.jsx)(`span`,{className:`c2-mono`,children:e.externalIp||`—`})},{label:r(`c2.sessions.infoSleep`,null,`Sleep`),value:`${e.sleepSeconds||0}s ± ${e.jitterPercent||0}%`}],s=[{label:r(`c2.sessions.infoFirstSeen`,null,`首次上线`),value:v(e.firstSeenAt)},{label:r(`c2.sessions.infoLastCheckin`,null,`上次心跳`),value:v(e.lastCheckIn)},{label:r(`c2.sessions.status`,null,`状态`),value:e.status||`—`},{label:r(`c2.sessions.listener`,null,`监听器`),value:(0,J.jsx)(`span`,{className:`c2-mono`,children:e.listenerId||`—`})}];return(0,J.jsxs)(`div`,{className:`c2-session-info`,children:[(0,J.jsx)(D,{title:r(`c2.sessions.infoSectionIdentity`,null,`身份信息`),children:(0,J.jsx)(T,{items:i,columns:2})}),(0,J.jsx)(D,{title:r(`c2.sessions.infoSectionSystem`,null,`系统环境`),children:(0,J.jsx)(T,{items:a,columns:2})}),(0,J.jsx)(D,{title:r(`c2.sessions.infoSectionNetwork`,null,`网络与信标`),children:(0,J.jsx)(T,{items:s,columns:2})}),(0,J.jsx)(D,{title:r(`c2.sessions.infoSectionNote`,null,`备注`),extra:(0,J.jsx)(o,{children:(0,J.jsx)(l,{size:`small`,disabled:!t,onClick:n,children:r(`c2.sessions.noteEdit`,null,`编辑`)})}),children:(0,J.jsx)(Z,{type:e.note?void 0:`tertiary`,children:e.note||r(`c2.sessions.infoNoteEmpty`,null,`暂无备注`)})}),e.metadata&&Object.keys(e.metadata).length>0&&(0,J.jsx)(D,{title:r(`c2.sessions.infoMetadata`,null,`原始元数据`),children:(0,J.jsx)(M,{value:e.metadata,collapsed:!0})})]})}var{Text:Q}=a;function ye({session:e,canWrite:t,canDelete:n,onChanged:r,onDeleted:i}){let a=y(),[c,f]=(0,q.useState)(`terminal`),[m,h]=(0,q.useState)(null),[_,v]=(0,q.useState)(null),[b,T]=(0,q.useState)(!1),{data:D,loading:O,error:k,reload:A}=S(()=>z(e.id),[e.id]),j=D?.session||e,M=()=>h({sleepSeconds:String(j.sleepSeconds||5),jitterPercent:String(j.jitterPercent||0)}),F=()=>v({note:j.note||``}),ee=async()=>{let e=Number(m.sleepSeconds),t=Number(m.jitterPercent);if(!Number.isFinite(e)||e<1)x(a(`c2.sessions.toastSleepInvalid`,null,`Sleep 间隔至少为 1 秒`));else if(!Number.isFinite(t)||t<0||t>100)x(a(`c2.sessions.toastSleepInvalid`,null,`抖动百分比需在 0–100 之间`));else{T(!0);try{await te(j.id,{sleepSeconds:e,jitterPercent:t}),N(a(`c2.sessions.toastSleepUpdated`,null,`Sleep 设置已更新`)),h(null),A({silent:!0}),r?.()}catch(e){C(e)}finally{T(!1)}}},I=async()=>{let e=String(_.note||``).trim();if(e.length>2e3)x(a(`c2.sessions.toastNoteTooLong`,null,`备注最多 2000 字`));else{T(!0);try{await W(j.id,e),N(a(`c2.sessions.toastNoteSaved`,null,`备注已保存`)),v(null),A({silent:!0}),r?.()}catch(e){C(e)}finally{T(!1)}}},R=()=>{P({title:a(`c2.sessions.cardDeleteSession`,null,`删除会话`),content:a(`c2.sessions.confirmDeleteSession`,null,`从服务器删除此会话及其关联任务与文件记录?`),onOk:async()=>{try{await L(j.id),N(a(`c2.sessions.toastSessionDeleted`,null,`会话记录已删除`)),i?.()}catch(e){C(e)}}})},B=[{tab:a(`c2.sessions.terminal`,null,`终端`),itemKey:`terminal`,children:(0,J.jsx)(ue,{session:j,canWrite:t,onTaskCreated:A})},{tab:a(`c2.sessions.files`,null,`文件`),itemKey:`files`,children:(0,J.jsx)(ge,{session:j,canWrite:t})},{tab:a(`c2.sessions.tasks`,null,`任务`),itemKey:`tasks`,children:(0,J.jsx)(_e,{session:j,canDelete:n,onChanged:A})},{tab:a(`c2.sessions.info`,null,`信息`),itemKey:`info`,children:(0,J.jsx)(ve,{session:j,canWrite:t,onEditNote:F})}];return(0,J.jsxs)(`div`,{className:`c2-session-detail`,children:[(0,J.jsxs)(`div`,{className:`c2-session-head`,children:[(0,J.jsxs)(`div`,{className:`c2-session-title`,children:[(0,J.jsx)(Q,{strong:!0,className:`c2-session-hostname`,children:j.hostname||a(`c2.sessions.unknownHost`,null,`未知主机`)}),(0,J.jsxs)(o,{spacing:6,wrap:!0,children:[(0,J.jsx)(s,{size:`small`,color:ie[j.status]||`grey`,children:a(`c2.sessions.${j.status||`active`}`,null,j.status||`—`)}),(0,J.jsxs)(s,{size:`small`,children:[j.os||`—`,`/`,j.arch||`—`]}),j.isAdmin&&(0,J.jsx)(s,{size:`small`,color:`red`,children:a(`c2.sessions.rootBadge`,null,`ROOT`)}),(0,J.jsxs)(Q,{type:`tertiary`,size:`small`,children:[j.username||`—`,`@`,j.internalIp||j.externalIp||`—`]}),(0,J.jsxs)(Q,{type:`tertiary`,size:`small`,children:[`sleep `,j.sleepSeconds||0,`s ± `,j.jitterPercent||0,`%`]})]})]}),(0,J.jsxs)(o,{spacing:6,wrap:!0,children:[(0,J.jsx)(l,{size:`small`,icon:(0,J.jsx)(g,{}),loading:O,onClick:()=>A(),children:a(`common.refresh`,null,`刷新`)}),(0,J.jsx)(l,{size:`small`,disabled:!t,onClick:M,children:a(`c2.sessions.btnSleep`,null,`Sleep`)}),(0,J.jsx)(l,{size:`small`,disabled:!t,onClick:F,children:a(`c2.sessions.noteEdit`,null,`备注`)}),(0,J.jsx)(l,{size:`small`,type:`danger`,disabled:!n,onClick:R,children:a(`c2.sessions.cardDeleteSession`,null,`删除会话`)})]})]}),(0,J.jsx)(E,{error:k,onRetry:A}),(0,J.jsx)(p,{type:`button`,activeKey:c,onChange:f,items:B}),(0,J.jsxs)(w,{visible:!!m,title:a(`c2.sessions.sleepModalTitle`,null,`心跳配置`),width:440,onCancel:()=>h(null),onOk:ee,confirmLoading:b,children:[(0,J.jsx)(Q,{type:`tertiary`,size:`small`,children:a(`c2.sessions.sleepModalHint`,null,`保存后将写入服务端并下发 sleep 任务。`)}),(0,J.jsxs)(`div`,{className:`c2-session-modal-field`,children:[(0,J.jsx)(Q,{size:`small`,children:a(`c2.sessions.promptSleepSeconds`,null,`Sleep 间隔(秒)`)}),(0,J.jsx)(d,{value:m?.sleepSeconds||``,onChange:e=>h(t=>({...t,sleepSeconds:e}))})]}),(0,J.jsxs)(`div`,{className:`c2-session-modal-field`,children:[(0,J.jsx)(Q,{size:`small`,children:a(`c2.sessions.promptJitterPercent`,null,`抖动百分比(0–100)`)}),(0,J.jsx)(d,{value:m?.jitterPercent||``,onChange:e=>h(t=>({...t,jitterPercent:e}))})]})]}),(0,J.jsx)(w,{visible:!!_,title:a(`c2.sessions.infoNote`,null,`备注`),width:480,onCancel:()=>v(null),onOk:I,confirmLoading:b,children:(0,J.jsx)(u,{value:_?.note||``,onChange:e=>v(t=>({...t,note:e})),placeholder:a(`c2.sessions.notePlaceholder`,null,`添加备注,便于识别该会话…`),autosize:{minRows:4,maxRows:10}})})]})}var{Text:$}=a;function be(){let e=y(),{hasPermission:t}=b(),n=t(`c2:write`),a=t(`c2:delete`)||n,[o,u]=r(),p=o.get(`id`)||``,[m,v]=(0,q.useState)(``),[x,w]=(0,q.useState)(``),[T,D]=(0,q.useState)(!1),[j,M]=(0,q.useState)(``),[F,te]=(0,q.useState)(!0),I=O(j,300),L=(0,q.useMemo)(()=>({status:m||void 0,listener_id:x||void 0,search:I||void 0,suspicious:T?`1`:void 0,limit:200}),[m,x,I,T]),{data:z,loading:B,error:ne,reload:V}=S(()=>Promise.all([ee(L),re().catch(()=>({listeners:[]}))]),[L]),H=Array.isArray(z?.[0]?.sessions)?z[0].sessions:[],U=Array.isArray(z?.[1]?.listeners)?z[1].listeners:[];A(()=>{F&&V({silent:!0})},F?1e4:0);let W=(0,q.useMemo)(()=>H.find(e=>e.id===p)||null,[H,p]),G=e=>{let t=new URLSearchParams(o);e?t.set(`id`,e):t.delete(`id`),u(t,{replace:!0})};return(0,J.jsxs)(`div`,{className:`c2-page`,id:`page-c2-sessions`,children:[(0,J.jsx)(k,{title:e(`c2.sessions.title`,null,`会话管理`),description:e(`c2.sessions.pageDesc`,null,`查看上线会话,下发命令、浏览文件并管理任务历史`),extra:[(0,J.jsx)(l,{icon:(0,J.jsx)(g,{}),onClick:V,loading:B,children:e(`common.refresh`,null,`刷新`)},`refresh`),(0,J.jsx)(l,{type:`danger`,disabled:!a||!H.length,onClick:()=>{H.length?P({title:e(`c2.sessions.deleteFiltered`,null,`删除筛选结果`),content:e(`c2.sessions.confirmDeleteFiltered`,null,`确定删除当前筛选结果中的全部会话?`).replace(`{{n}}`,String(H.length)),onOk:async()=>{try{let t=await R(H.map(e=>e.id));N(e(`c2.sessions.toastBatchDeleted`,null,`已删除 {{n}} 个会话`).replace(`{{n}}`,String(t?.deleted??H.length))),G(``),V()}catch(e){C(e)}}}):C(e(`c2.sessions.toastSelectFirst`,null,`没有可删除的会话`))},children:e(`c2.sessions.deleteFiltered`,null,`删除筛选结果`)},`delete`)]}),(0,J.jsx)(E,{error:ne,onRetry:V}),(0,J.jsxs)(`div`,{className:`c2-session-layout`,children:[(0,J.jsxs)(`aside`,{className:`c2-session-sidebar`,children:[(0,J.jsxs)(`div`,{className:`c2-session-filters`,children:[(0,J.jsx)(_,{size:`small`,value:m,onChange:e=>v(e||``),style:{width:`100%`},optionList:[{value:``,label:e(`c2.sessions.filterAllStatus`,null,`全部状态`)},...ae]}),(0,J.jsx)(_,{size:`small`,value:x,onChange:e=>w(e||``),style:{width:`100%`},optionList:[{value:``,label:e(`c2.sessions.filterAllListeners`,null,`全部监听器`)},...U.map(e=>({value:e.id,label:e.name||e.id}))]}),(0,J.jsx)(d,{size:`small`,value:j,onChange:M,prefix:(0,J.jsx)(h,{}),placeholder:e(`c2.sessions.filterSearchPlaceholder`,null,`搜索主机名 / 用户 / IP`)}),(0,J.jsxs)(`div`,{className:`c2-session-filter-foot`,children:[(0,J.jsx)(c,{checked:T,onChange:e=>D(!!e.target.checked),children:(0,J.jsx)($,{size:`small`,children:e(`c2.sessions.filterSuspicious`,null,`疑似误报`)})}),(0,J.jsx)(c,{checked:F,onChange:e=>te(!!e.target.checked),children:(0,J.jsx)($,{size:`small`,children:e(`c2.sessions.autoRefresh`,null,`自动刷新`)})})]}),(0,J.jsx)($,{type:`tertiary`,size:`small`,children:e(`c2.sessions.listCount`,null,`共 {{n}} 条`).replace(`{{n}}`,String(H.length))})]}),(0,J.jsxs)(`div`,{className:`c2-session-list`,children:[B&&!H.length&&(0,J.jsx)(`div`,{className:`c2-session-loading`,children:(0,J.jsx)(f,{})}),!B&&H.length===0&&(0,J.jsx)(i,{title:j||m||x?e(`c2.sessions.emptyFilter`,null,`没有符合筛选条件的会话`):e(`c2.sessions.listEmpty`,null,`暂无会话`),description:null,style:{padding:24}}),H.map(t=>(0,J.jsxs)(`button`,{type:`button`,className:`c2-session-item ${t.id===p?`is-active`:``}`,onClick:()=>G(t.id),children:[(0,J.jsxs)(`div`,{className:`c2-session-item-head`,children:[(0,J.jsx)(`span`,{className:`c2-session-host`,children:t.hostname||e(`c2.sessions.unknownHost`,null,`未知`)}),(0,J.jsx)(s,{size:`small`,color:ie[t.status]||`grey`,children:e(`c2.sessions.${t.status||`active`}`,null,t.status||`—`)})]}),(0,J.jsxs)(`div`,{className:`c2-session-item-meta`,children:[(0,J.jsx)(`span`,{children:t.username||`—`}),(0,J.jsxs)(`span`,{children:[t.os||`—`,`/`,t.arch||`—`]}),t.isAdmin&&(0,J.jsx)(s,{size:`small`,color:`red`,children:`ROOT`})]}),(0,J.jsxs)(`div`,{className:`c2-session-item-foot`,children:[(0,J.jsx)(`span`,{className:`c2-mono`,children:t.internalIp||t.externalIp||`—`}),(0,J.jsx)(oe,{value:t.lastCheckIn})]})]},t.id))]})]}),(0,J.jsx)(`section`,{className:`c2-session-main`,children:W?(0,J.jsx)(ye,{session:W,canWrite:n,canDelete:a,onChanged:V,onDeleted:()=>{G(``),V()}},W.id):(0,J.jsx)(i,{title:e(`c2.sessions.selectPromptTitle`,null,`选择会话`),description:e(`c2.sessions.selectPromptHint`,null,`在左侧列表中点击一个会话,查看终端、文件与任务详情。`),style:{padding:64}})})]})]})}export{be as default}; \ No newline at end of file diff --git a/web/static/app/assets/c2-shared-Car3lDYq.js b/web/static/app/assets/c2-shared-2EAlkwn6.js similarity index 94% rename from web/static/app/assets/c2-shared-Car3lDYq.js rename to web/static/app/assets/c2-shared-2EAlkwn6.js index 5ceffbc3..cf32366b 100644 --- a/web/static/app/assets/c2-shared-Car3lDYq.js +++ b/web/static/app/assets/c2-shared-2EAlkwn6.js @@ -1 +1 @@ -import{L as e,R as t}from"./index-CAEPLS-g.js";var n=encodeURIComponent,r=t=>e.get(`/c2/listeners`,t),i=t=>e.post(`/c2/listeners`,t),a=(t,r)=>e.put(`/c2/listeners/${n(t)}`,r),o=t=>e.del(`/c2/listeners/${n(t)}`),s=t=>e.post(`/c2/listeners/${n(t)}/start`,{}),c=t=>e.post(`/c2/listeners/${n(t)}/stop`,{}),l=t=>e.get(`/c2/sessions`,t),u=t=>e.get(`/c2/sessions/${n(t)}`),d=t=>e.del(`/c2/sessions/${n(t)}`),f=t=>e.del(`/c2/sessions`,{body:{ids:t}}),p=(t,{sleepSeconds:r,jitterPercent:i})=>e.put(`/c2/sessions/${n(t)}/sleep`,{sleep_seconds:r,jitter_percent:i}),m=(t,r)=>e.put(`/c2/sessions/${n(t)}/note`,{note:r}),h=t=>e.get(`/c2/tasks`,t),g=t=>e.get(`/c2/tasks/${n(t)}`),_=t=>e.post(`/c2/tasks`,t),v=(t,r)=>e.post(`/c2/sessions/${n(t)}/tasks`,r),y=t=>e.post(`/c2/tasks/${n(t)}/cancel`,{}),b=(t,r=30)=>e.get(`/c2/tasks/${n(t)}/wait`,{timeout:r},{timeout:(r+10)*1e3}),x=t=>e.del(`/c2/tasks`,{body:{ids:t}}),S=(e,r)=>t(`/c2/tasks/${n(e)}/result-file`,{filename:r}),C=t=>e.post(`/c2/payloads/oneliner`,t),w=t=>e.post(`/c2/payloads/build`,t),T=(e,r)=>t(`/c2/payloads/${n(e)}/download`,{filename:r}),E=t=>e.get(`/c2/events`,t),D=t=>e.del(`/c2/events`,{body:{ids:t}}),O=()=>e.get(`/c2/profiles`),k=t=>e.post(`/c2/profiles`,t),A=(t,r)=>e.put(`/c2/profiles/${n(t)}`,r),j=t=>e.del(`/c2/profiles/${n(t)}`);async function M(){try{let t=await e.get(`/projects`,{limit:200});return Array.isArray(t?.projects)?t.projects:[]}catch{return[]}}export{b as A,h as C,c as D,s as E,a as O,l as S,p as T,g as _,k as a,O as b,D as c,d,f,u as g,S as h,i,A as k,o as l,T as m,w as n,v as o,x as p,y as r,_ as s,C as t,j as u,E as v,m as w,M as x,r as y}; \ No newline at end of file +import{L as e,R as t}from"./index-DNMXun-U.js";var n=encodeURIComponent,r=t=>e.get(`/c2/listeners`,t),i=t=>e.post(`/c2/listeners`,t),a=(t,r)=>e.put(`/c2/listeners/${n(t)}`,r),o=t=>e.del(`/c2/listeners/${n(t)}`),s=t=>e.post(`/c2/listeners/${n(t)}/start`,{}),c=t=>e.post(`/c2/listeners/${n(t)}/stop`,{}),l=t=>e.get(`/c2/sessions`,t),u=t=>e.get(`/c2/sessions/${n(t)}`),d=t=>e.del(`/c2/sessions/${n(t)}`),f=t=>e.del(`/c2/sessions`,{body:{ids:t}}),p=(t,{sleepSeconds:r,jitterPercent:i})=>e.put(`/c2/sessions/${n(t)}/sleep`,{sleep_seconds:r,jitter_percent:i}),m=(t,r)=>e.put(`/c2/sessions/${n(t)}/note`,{note:r}),h=t=>e.get(`/c2/tasks`,t),g=t=>e.get(`/c2/tasks/${n(t)}`),_=t=>e.post(`/c2/tasks`,t),v=(t,r)=>e.post(`/c2/sessions/${n(t)}/tasks`,r),y=t=>e.post(`/c2/tasks/${n(t)}/cancel`,{}),b=(t,r=30)=>e.get(`/c2/tasks/${n(t)}/wait`,{timeout:r},{timeout:(r+10)*1e3}),x=t=>e.del(`/c2/tasks`,{body:{ids:t}}),S=(e,r)=>t(`/c2/tasks/${n(e)}/result-file`,{filename:r}),C=t=>e.post(`/c2/payloads/oneliner`,t),w=t=>e.post(`/c2/payloads/build`,t),T=(e,r)=>t(`/c2/payloads/${n(e)}/download`,{filename:r}),E=t=>e.get(`/c2/events`,t),D=t=>e.del(`/c2/events`,{body:{ids:t}}),O=()=>e.get(`/c2/profiles`),k=t=>e.post(`/c2/profiles`,t),A=(t,r)=>e.put(`/c2/profiles/${n(t)}`,r),j=t=>e.del(`/c2/profiles/${n(t)}`);async function M(){try{let t=await e.get(`/projects`,{limit:200});return Array.isArray(t?.projects)?t.projects:[]}catch{return[]}}export{b as A,h as C,c as D,s as E,a as O,l as S,p as T,g as _,k as a,O as b,D as c,d,f,u as g,S as h,i,A as k,o as l,T as m,w as n,v as o,x as p,y as r,_ as s,C as t,j as u,E as v,m as w,M as x,r as y}; \ No newline at end of file diff --git a/web/static/app/assets/c2-shared-D-8kBzuC.js b/web/static/app/assets/c2-shared-BrRxH-6B.js similarity index 96% rename from web/static/app/assets/c2-shared-D-8kBzuC.js rename to web/static/app/assets/c2-shared-BrRxH-6B.js index b6256482..24a8c624 100644 --- a/web/static/app/assets/c2-shared-D-8kBzuC.js +++ b/web/static/app/assets/c2-shared-BrRxH-6B.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{G as t,I as n,R as r}from"./semi-65W_4I1v.js";import{A as i,E as a,F as o}from"./index-CAEPLS-g.js";import"./c2-shared-Car3lDYq.js";import{t as s}from"./react-QV7DAAIx.js";var c=e(s(),1),{Text:l}=t,u=[{value:`http_beacon`,label:`HTTP Beacon`},{value:`https_beacon`,label:`HTTPS Beacon`},{value:`tcp_reverse`,label:`TCP 反向`},{value:`websocket`,label:`WebSocket`}],d={running:`运行中`,stopped:`已停止`,error:`异常`},f={tcp_reverse:[{value:`bash`,label:`Bash (/dev/tcp)`},{value:`nc`,label:`Netcat (-e)`},{value:`nc_mkfifo`,label:`Netcat (mkfifo)`},{value:`python`,label:`Python`},{value:`perl`,label:`Perl`},{value:`powershell`,label:`PowerShell`}],http_beacon:[{value:`curl_beacon`,label:`Curl Beacon (HTTP)`}],https_beacon:[{value:`curl_beacon`,label:`Curl Beacon (HTTP)`}],websocket:[{value:`curl_beacon`,label:`Curl Beacon (HTTP)`}]},p=[{value:`shell`,label:`shell`},{value:`exec`,label:`exec`},{value:`ls`,label:`ls`},{value:`pwd`,label:`pwd`},{value:`cd`,label:`cd`},{value:`ps`,label:`ps`},{value:`kill_proc`,label:`kill_proc`},{value:`download`,label:`download`},{value:`upload`,label:`upload`},{value:`screenshot`,label:`screenshot`},{value:`sleep`,label:`sleep`},{value:`exit`,label:`exit`},{value:`self_delete`,label:`self_delete`},{value:`port_fwd`,label:`port_fwd`},{value:`socks_start`,label:`socks_start`},{value:`socks_stop`,label:`socks_stop`},{value:`load_assembly`,label:`load_assembly`},{value:`persist`,label:`persist`}],m=[{value:`queued`,label:`队列中`},{value:`sent`,label:`已发送`},{value:`running`,label:`执行中`},{value:`success`,label:`成功`},{value:`failed`,label:`失败`},{value:`cancelled`,label:`已取消`}],h=[{value:`info`,label:`信息`},{value:`warn`,label:`警告`},{value:`critical`,label:`严重`}],g=[{value:`listener`,label:`监听器`},{value:`session`,label:`会话`},{value:`task`,label:`任务`},{value:`payload`,label:`Payload`},{value:`opsec`,label:`OPSEC`}],_=[{value:`active`,label:`活跃`},{value:`sleeping`,label:`休眠`},{value:`dead`,label:`离线`},{value:`killed`,label:`已终止`}],v=[{value:`15m`,label:`最近15分钟`,ms:9e5},{value:`1h`,label:`最近1小时`,ms:36e5},{value:`24h`,label:`最近24小时`,ms:864e5},{value:`7d`,label:`最近7天`,ms:6048e5},{value:`all`,label:`全部`,ms:0}];function y(e){let t=v.find(t=>t.value===e);return!t||!t.ms?``:new Date(Date.now()-t.ms).toISOString()}function b({value:e,onChange:t,ns:i=`tasks`}){let a=o();return(0,c.jsxs)(n,{spacing:6,wrap:!0,className:`c2-time-presets`,children:[(0,c.jsx)(l,{type:`tertiary`,size:`small`,children:a(`c2.tasks.timePresets`,null,`快捷`)}),v.map(n=>(0,c.jsx)(r,{size:`small`,theme:n.value===e?`solid`:`borderless`,type:n.value===e?`primary`:`tertiary`,onClick:()=>t(n.value),children:a(`c2.${i}.preset${n.value===`all`?`All`:n.value}`,null,n.label)},n.value))]})}function x(e){let t=Number(e);return!Number.isFinite(t)||t<=0?`—`:t<1e3?`${Math.round(t)}ms`:t<6e4?`${(t/1e3).toFixed(1)}秒`:`${Math.round(t/6e4)}分钟`}function S({value:e}){let t=o();return e?(0,c.jsx)(`span`,{className:`c2-time-text`,title:a(e),children:i(e,t)}):(0,c.jsx)(l,{type:`tertiary`,children:`—`})}var C={running:`green`,stopped:`grey`,error:`red`},w={queued:`amber`,sent:`blue`,running:`blue`,success:`green`,failed:`red`,cancelled:`grey`},T={active:`green`,sleeping:`amber`,dead:`grey`,killed:`red`},E={info:`blue`,warn:`amber`,critical:`red`};export{d as a,T as c,m as d,p as f,y as g,x as h,C as i,_ as l,S as m,E as n,u as o,b as p,h as r,f as s,g as t,w as u}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{G as t,I as n,R as r}from"./semi-65W_4I1v.js";import{A as i,E as a,F as o}from"./index-DNMXun-U.js";import"./c2-shared-2EAlkwn6.js";import{t as s}from"./react-QV7DAAIx.js";var c=e(s(),1),{Text:l}=t,u=[{value:`http_beacon`,label:`HTTP Beacon`},{value:`https_beacon`,label:`HTTPS Beacon`},{value:`tcp_reverse`,label:`TCP 反向`},{value:`websocket`,label:`WebSocket`}],d={running:`运行中`,stopped:`已停止`,error:`异常`},f={tcp_reverse:[{value:`bash`,label:`Bash (/dev/tcp)`},{value:`nc`,label:`Netcat (-e)`},{value:`nc_mkfifo`,label:`Netcat (mkfifo)`},{value:`python`,label:`Python`},{value:`perl`,label:`Perl`},{value:`powershell`,label:`PowerShell`}],http_beacon:[{value:`curl_beacon`,label:`Curl Beacon (HTTP)`}],https_beacon:[{value:`curl_beacon`,label:`Curl Beacon (HTTP)`}],websocket:[{value:`curl_beacon`,label:`Curl Beacon (HTTP)`}]},p=[{value:`shell`,label:`shell`},{value:`exec`,label:`exec`},{value:`ls`,label:`ls`},{value:`pwd`,label:`pwd`},{value:`cd`,label:`cd`},{value:`ps`,label:`ps`},{value:`kill_proc`,label:`kill_proc`},{value:`download`,label:`download`},{value:`upload`,label:`upload`},{value:`screenshot`,label:`screenshot`},{value:`sleep`,label:`sleep`},{value:`exit`,label:`exit`},{value:`self_delete`,label:`self_delete`},{value:`port_fwd`,label:`port_fwd`},{value:`socks_start`,label:`socks_start`},{value:`socks_stop`,label:`socks_stop`},{value:`load_assembly`,label:`load_assembly`},{value:`persist`,label:`persist`}],m=[{value:`queued`,label:`队列中`},{value:`sent`,label:`已发送`},{value:`running`,label:`执行中`},{value:`success`,label:`成功`},{value:`failed`,label:`失败`},{value:`cancelled`,label:`已取消`}],h=[{value:`info`,label:`信息`},{value:`warn`,label:`警告`},{value:`critical`,label:`严重`}],g=[{value:`listener`,label:`监听器`},{value:`session`,label:`会话`},{value:`task`,label:`任务`},{value:`payload`,label:`Payload`},{value:`opsec`,label:`OPSEC`}],_=[{value:`active`,label:`活跃`},{value:`sleeping`,label:`休眠`},{value:`dead`,label:`离线`},{value:`killed`,label:`已终止`}],v=[{value:`15m`,label:`最近15分钟`,ms:9e5},{value:`1h`,label:`最近1小时`,ms:36e5},{value:`24h`,label:`最近24小时`,ms:864e5},{value:`7d`,label:`最近7天`,ms:6048e5},{value:`all`,label:`全部`,ms:0}];function y(e){let t=v.find(t=>t.value===e);return!t||!t.ms?``:new Date(Date.now()-t.ms).toISOString()}function b({value:e,onChange:t,ns:i=`tasks`}){let a=o();return(0,c.jsxs)(n,{spacing:6,wrap:!0,className:`c2-time-presets`,children:[(0,c.jsx)(l,{type:`tertiary`,size:`small`,children:a(`c2.tasks.timePresets`,null,`快捷`)}),v.map(n=>(0,c.jsx)(r,{size:`small`,theme:n.value===e?`solid`:`borderless`,type:n.value===e?`primary`:`tertiary`,onClick:()=>t(n.value),children:a(`c2.${i}.preset${n.value===`all`?`All`:n.value}`,null,n.label)},n.value))]})}function x(e){let t=Number(e);return!Number.isFinite(t)||t<=0?`—`:t<1e3?`${Math.round(t)}ms`:t<6e4?`${(t/1e3).toFixed(1)}秒`:`${Math.round(t/6e4)}分钟`}function S({value:e}){let t=o();return e?(0,c.jsx)(`span`,{className:`c2-time-text`,title:a(e),children:i(e,t)}):(0,c.jsx)(l,{type:`tertiary`,children:`—`})}var C={running:`green`,stopped:`grey`,error:`red`},w={queued:`amber`,sent:`blue`,running:`blue`,success:`green`,failed:`red`,cancelled:`grey`},T={active:`green`,sleeping:`amber`,dead:`grey`,killed:`red`},E={info:`blue`,warn:`amber`,critical:`red`};export{d as a,T as c,m as d,p as f,y as g,x as h,C as i,_ as l,S as m,E as n,u as o,b as p,h as r,f as s,g as t,w as u}; \ No newline at end of file diff --git a/web/static/app/assets/c2-tasks-DSV9J8Vu.js b/web/static/app/assets/c2-tasks-FVvnpyKj.js similarity index 97% rename from web/static/app/assets/c2-tasks-DSV9J8Vu.js rename to web/static/app/assets/c2-tasks-FVvnpyKj.js index af2d70fc..8bcce80a 100644 --- a/web/static/app/assets/c2-tasks-DSV9J8Vu.js +++ b/web/static/app/assets/c2-tasks-FVvnpyKj.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{G as i,I as a,N as o,R as s,U as c,ft as l,i as u,ut as d,y as f}from"./semi-65W_4I1v.js";import{E as ee,F as p,I as te,_ as ne,a as re,b as m,c as h,l as ie,m as g,p as ae,r as _,s as v,x as y,y as oe}from"./index-CAEPLS-g.js";import{A as se,C as ce,h as le,p as ue,r as de,s as b}from"./c2-shared-Car3lDYq.js";import{d as fe,f as x,g as pe,h as S,m as me,p as he,u as C}from"./c2-shared-D-8kBzuC.js";var w=e(t(),1),T=e(n(),1),{Text:E}=i,D=new Set([`shell`,`exec`]),O=new Set([`ls`,`download`,`cd`]);function ge({visible:e,defaultSessionId:t,onCancel:n,onSubmit:r,submitting:i}){let o=p(),[c,l]=(0,w.useState)(null),[d,f]=(0,w.useState)(`shell`);return(0,T.jsx)(h,{visible:e,title:o(`c2.tasks.createTitle`,null,`下发任务`),footer:(0,T.jsxs)(a,{children:[(0,T.jsx)(s,{onClick:n,children:o(`c2.tasks.cancelFilters`,null,`取消`)}),(0,T.jsx)(s,{theme:`solid`,type:`primary`,loading:i,onClick:()=>c?.submitForm(),children:o(`c2.tasks.createSubmit`,null,`下发`)})]}),width:560,onCancel:n,children:(0,T.jsxs)(u,{initValues:{session_id:t||``,task_type:`shell`,command:``,timeout_seconds:`60`,extra:``},onSubmit:e=>{let t={},n=String(e.command||``).trim();if(D.has(e.task_type)){t.command=n;let r=Number(e.timeout_seconds);Number.isFinite(r)&&r>0&&(t.timeout_seconds=r)}else(O.has(e.task_type)||n)&&(t.path=n);let i=String(e.extra||``).trim();if(i)try{Object.assign(t,JSON.parse(i))}catch{t.raw=i}r({session_id:String(e.session_id||``).trim(),task_type:e.task_type||`shell`,payload:t,source:`manual`})},getFormApi:l,labelPosition:`top`,onValueChange:e=>{e.task_type&&f(e.task_type)},children:[(0,T.jsx)(u.Input,{field:`session_id`,label:o(`c2.tasks.labelSession`,null,`会话`),placeholder:`s_xxxxxxxx`,rules:[{required:!0,message:o(`c2.tasks.labelSession`,null,`请填写会话 ID`)}]}),(0,T.jsx)(u.Select,{field:`task_type`,label:o(`c2.tasks.labelType`,null,`类型`),optionList:x,style:{width:`100%`}}),(0,T.jsx)(u.Input,{field:`command`,label:D.has(d)?o(`c2.tasks.labelCommand`,null,`命令`):o(`c2.tasks.labelPath`,null,`路径`),placeholder:D.has(d)?`whoami`:`/etc/passwd`}),D.has(d)&&(0,T.jsx)(u.Input,{field:`timeout_seconds`,label:o(`c2.tasks.labelTimeout`,null,`超时(秒)`),placeholder:`60`}),(0,T.jsx)(u.Input,{field:`extra`,label:o(`c2.tasks.labelExtraPayload`,null,`附加参数(JSON,可选)`),placeholder:`{"key":"value"}`}),(0,T.jsx)(E,{type:`tertiary`,size:`small`,children:o(`c2.tasks.createHint`,null,`任务入队后由植入体在下次心跳拉取;危险类型可能需要人机协同审批。`)})]},e?`open`:`closed`)})}var{Text:k}=i;function A(){let e=p(),{hasPermission:t}=te(),n=t(`c2:write`),i=t(`c2:delete`)||n,[u,E]=r(),[D,O]=(0,w.useState)(1),[A,_e]=(0,w.useState)(20),[j,M]=(0,w.useState)(``),[N,P]=(0,w.useState)(``),[F,I]=(0,w.useState)(`all`),[L,R]=(0,w.useState)(u.get(`session_id`)||``),[z,B]=(0,w.useState)(u.get(`session_id`)||``),[V,H]=(0,w.useState)(null),[ve,U]=(0,w.useState)(!1),[ye,W]=(0,w.useState)(!1),G=(0,w.useMemo)(()=>({page:D,page_size:A,status:j||void 0,task_type:N||void 0,session_id:z||void 0,since:pe(F)||void 0}),[D,A,j,N,z,F]),{data:K,loading:q,error:be,reload:J}=re(()=>ce(G),[G]),Y=Array.isArray(K?.tasks)?K.tasks:[],X=Number(K?.total??Y.length),Z=K?.status_counts||{};_(()=>J({silent:!0}),5e3);let Q=()=>{B(L.trim()),O(1);let e=new URLSearchParams(u);L.trim()?e.set(`session_id`,L.trim()):e.delete(`session_id`),E(e,{replace:!0})},xe=()=>{M(``),P(``),I(`all`),R(``),B(``),O(1),E(new URLSearchParams,{replace:!0})},Se=[{id:`total`,label:e(`c2.tasks.statTotal`,null,`当前筛选`),value:X},{id:`success`,label:e(`c2.tasks.success`,null,`成功`),value:Z.success||0,tone:`success`},{id:`failed`,label:e(`c2.tasks.failed`,null,`失败`),value:Z.failed||0,tone:`danger`},{id:`pending`,label:e(`c2.tasks.pending`,null,`待处理`),value:(Z.queued||0)+(Z.sent||0)+(Z.running||0),tone:`warning`}],Ce=async t=>{try{await de(t.id),y(e(`c2.tasks.toastCancelled`,null,`任务已取消`)),J({silent:!0})}catch(e){m(e)}},we=t=>{oe({title:e(`c2.tasks.deleteOne`,null,`删除任务`),content:e(`c2.tasks.confirmDeleteOne`,null,`确定从服务器删除该任务记录吗?此操作不可恢复。`),onOk:async()=>{try{await ue([t.id]),y(e(`c2.tasks.toastDeleted`,null,`已删除 {{n}} 条`).replace(`{{n}}`,`1`)),J()}catch(e){m(e)}}})},Te=async t=>{try{let n=await se(t.id,20);n?.task&&H(n.task),y(e(`c2.tasks.toastWaited`,null,`已获取最新任务状态`)),J({silent:!0})}catch(t){m(t,e(`c2.tasks.waitTimeout`,null,`等待任务完成超时`))}},$=async t=>{try{await le(t.id),y(e(`c2.tasks.downloadOk`,null,`已开始下载`))}catch(t){m(t,e(`c2.tasks.labelResult`,null,`下载结果文件失败`))}},Ee=async t=>{W(!0);try{await b(t),y(e(`c2.tasks.toastCreated`,null,`任务已下发`)),U(!1),J()}catch(t){m(t,e(`c2.tasks.createFailed`,null,`下发任务失败`))}finally{W(!1)}},De=[{title:e(`c2.tasks.colTask`,null,`任务`),dataIndex:`id`,width:150,render:e=>(0,T.jsx)(`span`,{className:`c2-mono`,children:e})},{title:e(`c2.tasks.colSession`,null,`会话`),dataIndex:`sessionId`,width:150,render:e=>(0,T.jsx)(`span`,{className:`c2-mono`,children:e||`—`})},{title:e(`c2.tasks.colType`,null,`类型`),dataIndex:`taskType`,width:110},{title:e(`c2.tasks.colCommand`,null,`命令`),dataIndex:`payload`,render:e=>{let t=e?.command||e?.path||``;return(0,T.jsx)(`span`,{className:`c2-mono c2-task-command`,title:t,children:t||`—`})}},{title:e(`c2.tasks.colStatus`,null,`状态`),dataIndex:`status`,width:110,render:t=>(0,T.jsx)(o,{size:`small`,color:C[t]||`grey`,children:e(`c2.tasks.${t||`queued`}`,null,t||`—`)})},{title:e(`c2.tasks.colDuration`,null,`耗时`),dataIndex:`durationMs`,width:100,render:e=>S(e)},{title:e(`c2.tasks.colCreated`,null,`创建时间`),dataIndex:`createdAt`,width:130,render:e=>(0,T.jsx)(me,{value:e})},{title:e(`c2.tasks.colActions`,null,`操作`),dataIndex:`actions`,width:210,render:(t,n)=>(0,T.jsxs)(a,{spacing:4,wrap:!0,children:[(0,T.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>H(n),children:e(`c2.tasks.view`,null,`查看`)}),[`queued`,`sent`,`running`].includes(n.status)&&(0,T.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>Ce(n),children:e(`c2.tasks.cancelBtn`,null,`取消`)}),n.resultBlobPath&&(0,T.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>$(n),children:e(`c2.tasks.downloadResult`,null,`结果文件`)}),(0,T.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,disabled:!i,onClick:()=>we(n),children:e(`c2.tasks.deleteBtn`,null,`删除`)})]})}];return(0,T.jsxs)(`div`,{className:`c2-page`,id:`page-c2-tasks`,children:[(0,T.jsx)(ae,{title:e(`c2.tasks.title`,null,`任务管理`),description:e(`c2.tasks.pageDesc`,null,`按状态、类型、会话与时间窗筛选任务,5 秒自动轮询最新状态`),extra:[(0,T.jsx)(s,{icon:(0,T.jsx)(d,{}),onClick:()=>J(),loading:q,children:e(`c2.tasks.refresh`,null,`刷新任务`)},`refresh`),(0,T.jsx)(s,{theme:`solid`,type:`primary`,icon:(0,T.jsx)(l,{}),disabled:!n,onClick:()=>U(!0),children:e(`c2.tasks.createTitle`,null,`下发任务`)},`create`)]}),(0,T.jsx)(ne,{metrics:Se,columns:4}),(0,T.jsx)(ie,{error:be,onRetry:()=>J()}),(0,T.jsx)(g,{title:e(`c2.tasks.filterTitle`,null,`筛选`),extra:(0,T.jsx)(he,{value:F,onChange:e=>{I(e),O(1)},ns:`tasks`}),children:(0,T.jsxs)(`div`,{className:`c2-toolbar-fields`,children:[(0,T.jsxs)(`div`,{className:`c2-field`,children:[(0,T.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.tasks.colStatus`,null,`状态`)}),(0,T.jsx)(f,{value:j,onChange:e=>{M(e||``),O(1)},style:{width:160},optionList:[{value:``,label:e(`c2.tasks.filterAllStatuses`,null,`全部状态`)},...fe]})]}),(0,T.jsxs)(`div`,{className:`c2-field`,children:[(0,T.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.tasks.colType`,null,`类型`)}),(0,T.jsx)(f,{value:N,onChange:e=>{P(e||``),O(1)},style:{width:160},optionList:[{value:``,label:e(`c2.tasks.filterAllTypes`,null,`全部类型`)},...x]})]}),(0,T.jsxs)(`div`,{className:`c2-field`,children:[(0,T.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.tasks.filterSession`,null,`会话 ID`)}),(0,T.jsx)(c,{value:L,onChange:R,onEnterPress:Q,placeholder:e(`c2.tasks.filterSessionPlaceholder`,null,`s_xxxxxxxx`),style:{width:190}})]}),(0,T.jsxs)(a,{spacing:8,children:[(0,T.jsx)(s,{theme:`solid`,type:`primary`,onClick:Q,children:e(`c2.tasks.applyFilters`,null,`应用筛选`)}),(0,T.jsx)(s,{onClick:xe,children:e(`c2.tasks.resetFilters`,null,`重置`)})]})]})}),(0,T.jsx)(g,{title:e(`c2.tasks.listTitle`,null,`任务列表`),children:(0,T.jsx)(v,{columns:De,dataSource:Y,rowKey:`id`,loading:q,onRefresh:()=>J(),pagination:{currentPage:D,pageSize:A,total:X,onPageChange:e=>O(e),onPageSizeChange:e=>{_e(e),O(1)}},emptyText:e(`c2.tasks.emptyAll`,null,`暂无任务`)})}),(0,T.jsx)(ge,{visible:ve,defaultSessionId:z,submitting:ye,onCancel:()=>U(!1),onSubmit:Ee}),(0,T.jsx)(h,{visible:!!V,title:e(`c2.tasks.modalTitle`,null,`任务详情`),width:760,onCancel:()=>H(null),footer:(0,T.jsxs)(a,{children:[V&&[`queued`,`sent`,`running`].includes(V.status)&&(0,T.jsx)(s,{onClick:()=>Te(V),children:e(`c2.tasks.waitBtn`,null,`等待完成`)}),V?.resultBlobPath&&(0,T.jsx)(s,{onClick:()=>$(V),children:e(`c2.tasks.downloadResult`,null,`下载结果文件`)}),(0,T.jsx)(s,{onClick:()=>H(null),children:e(`c2.tasks.close`,null,`关闭`)})]}),children:V&&(0,T.jsxs)(`div`,{className:`c2-task-detail`,children:[(0,T.jsxs)(`div`,{className:`c2-task-detail-meta`,children:[(0,T.jsx)(`span`,{className:`c2-mono`,children:V.id}),(0,T.jsx)(o,{size:`small`,color:C[V.status]||`grey`,children:V.status}),(0,T.jsx)(k,{type:`tertiary`,size:`small`,children:ee(V.createdAt)}),(0,T.jsx)(k,{type:`tertiary`,size:`small`,children:S(V.durationMs)})]}),(0,T.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.tasks.labelPayload`,null,`参数`)}),(0,T.jsx)(`pre`,{className:`c2-pre`,children:JSON.stringify(V.payload||{},null,2)}),V.resultText&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.tasks.labelResult`,null,`输出`)}),(0,T.jsx)(`pre`,{className:`c2-pre`,children:V.resultText})]}),V.error&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.tasks.labelError`,null,`错误`)}),(0,T.jsx)(`pre`,{className:`c2-pre c2-pre-error`,children:V.error})]})]})})]})}export{A as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{G as i,I as a,N as o,R as s,U as c,ft as l,i as u,ut as d,y as f}from"./semi-65W_4I1v.js";import{E as ee,F as p,I as te,_ as ne,a as re,b as m,c as h,l as ie,m as g,p as ae,r as _,s as v,x as y,y as oe}from"./index-DNMXun-U.js";import{A as se,C as ce,h as le,p as ue,r as de,s as b}from"./c2-shared-2EAlkwn6.js";import{d as fe,f as x,g as pe,h as S,m as me,p as he,u as C}from"./c2-shared-BrRxH-6B.js";var w=e(t(),1),T=e(n(),1),{Text:E}=i,D=new Set([`shell`,`exec`]),O=new Set([`ls`,`download`,`cd`]);function ge({visible:e,defaultSessionId:t,onCancel:n,onSubmit:r,submitting:i}){let o=p(),[c,l]=(0,w.useState)(null),[d,f]=(0,w.useState)(`shell`);return(0,T.jsx)(h,{visible:e,title:o(`c2.tasks.createTitle`,null,`下发任务`),footer:(0,T.jsxs)(a,{children:[(0,T.jsx)(s,{onClick:n,children:o(`c2.tasks.cancelFilters`,null,`取消`)}),(0,T.jsx)(s,{theme:`solid`,type:`primary`,loading:i,onClick:()=>c?.submitForm(),children:o(`c2.tasks.createSubmit`,null,`下发`)})]}),width:560,onCancel:n,children:(0,T.jsxs)(u,{initValues:{session_id:t||``,task_type:`shell`,command:``,timeout_seconds:`60`,extra:``},onSubmit:e=>{let t={},n=String(e.command||``).trim();if(D.has(e.task_type)){t.command=n;let r=Number(e.timeout_seconds);Number.isFinite(r)&&r>0&&(t.timeout_seconds=r)}else(O.has(e.task_type)||n)&&(t.path=n);let i=String(e.extra||``).trim();if(i)try{Object.assign(t,JSON.parse(i))}catch{t.raw=i}r({session_id:String(e.session_id||``).trim(),task_type:e.task_type||`shell`,payload:t,source:`manual`})},getFormApi:l,labelPosition:`top`,onValueChange:e=>{e.task_type&&f(e.task_type)},children:[(0,T.jsx)(u.Input,{field:`session_id`,label:o(`c2.tasks.labelSession`,null,`会话`),placeholder:`s_xxxxxxxx`,rules:[{required:!0,message:o(`c2.tasks.labelSession`,null,`请填写会话 ID`)}]}),(0,T.jsx)(u.Select,{field:`task_type`,label:o(`c2.tasks.labelType`,null,`类型`),optionList:x,style:{width:`100%`}}),(0,T.jsx)(u.Input,{field:`command`,label:D.has(d)?o(`c2.tasks.labelCommand`,null,`命令`):o(`c2.tasks.labelPath`,null,`路径`),placeholder:D.has(d)?`whoami`:`/etc/passwd`}),D.has(d)&&(0,T.jsx)(u.Input,{field:`timeout_seconds`,label:o(`c2.tasks.labelTimeout`,null,`超时(秒)`),placeholder:`60`}),(0,T.jsx)(u.Input,{field:`extra`,label:o(`c2.tasks.labelExtraPayload`,null,`附加参数(JSON,可选)`),placeholder:`{"key":"value"}`}),(0,T.jsx)(E,{type:`tertiary`,size:`small`,children:o(`c2.tasks.createHint`,null,`任务入队后由植入体在下次心跳拉取;危险类型可能需要人机协同审批。`)})]},e?`open`:`closed`)})}var{Text:k}=i;function A(){let e=p(),{hasPermission:t}=te(),n=t(`c2:write`),i=t(`c2:delete`)||n,[u,E]=r(),[D,O]=(0,w.useState)(1),[A,_e]=(0,w.useState)(20),[j,M]=(0,w.useState)(``),[N,P]=(0,w.useState)(``),[F,I]=(0,w.useState)(`all`),[L,R]=(0,w.useState)(u.get(`session_id`)||``),[z,B]=(0,w.useState)(u.get(`session_id`)||``),[V,H]=(0,w.useState)(null),[ve,U]=(0,w.useState)(!1),[ye,W]=(0,w.useState)(!1),G=(0,w.useMemo)(()=>({page:D,page_size:A,status:j||void 0,task_type:N||void 0,session_id:z||void 0,since:pe(F)||void 0}),[D,A,j,N,z,F]),{data:K,loading:q,error:be,reload:J}=re(()=>ce(G),[G]),Y=Array.isArray(K?.tasks)?K.tasks:[],X=Number(K?.total??Y.length),Z=K?.status_counts||{};_(()=>J({silent:!0}),5e3);let Q=()=>{B(L.trim()),O(1);let e=new URLSearchParams(u);L.trim()?e.set(`session_id`,L.trim()):e.delete(`session_id`),E(e,{replace:!0})},xe=()=>{M(``),P(``),I(`all`),R(``),B(``),O(1),E(new URLSearchParams,{replace:!0})},Se=[{id:`total`,label:e(`c2.tasks.statTotal`,null,`当前筛选`),value:X},{id:`success`,label:e(`c2.tasks.success`,null,`成功`),value:Z.success||0,tone:`success`},{id:`failed`,label:e(`c2.tasks.failed`,null,`失败`),value:Z.failed||0,tone:`danger`},{id:`pending`,label:e(`c2.tasks.pending`,null,`待处理`),value:(Z.queued||0)+(Z.sent||0)+(Z.running||0),tone:`warning`}],Ce=async t=>{try{await de(t.id),y(e(`c2.tasks.toastCancelled`,null,`任务已取消`)),J({silent:!0})}catch(e){m(e)}},we=t=>{oe({title:e(`c2.tasks.deleteOne`,null,`删除任务`),content:e(`c2.tasks.confirmDeleteOne`,null,`确定从服务器删除该任务记录吗?此操作不可恢复。`),onOk:async()=>{try{await ue([t.id]),y(e(`c2.tasks.toastDeleted`,null,`已删除 {{n}} 条`).replace(`{{n}}`,`1`)),J()}catch(e){m(e)}}})},Te=async t=>{try{let n=await se(t.id,20);n?.task&&H(n.task),y(e(`c2.tasks.toastWaited`,null,`已获取最新任务状态`)),J({silent:!0})}catch(t){m(t,e(`c2.tasks.waitTimeout`,null,`等待任务完成超时`))}},$=async t=>{try{await le(t.id),y(e(`c2.tasks.downloadOk`,null,`已开始下载`))}catch(t){m(t,e(`c2.tasks.labelResult`,null,`下载结果文件失败`))}},Ee=async t=>{W(!0);try{await b(t),y(e(`c2.tasks.toastCreated`,null,`任务已下发`)),U(!1),J()}catch(t){m(t,e(`c2.tasks.createFailed`,null,`下发任务失败`))}finally{W(!1)}},De=[{title:e(`c2.tasks.colTask`,null,`任务`),dataIndex:`id`,width:150,render:e=>(0,T.jsx)(`span`,{className:`c2-mono`,children:e})},{title:e(`c2.tasks.colSession`,null,`会话`),dataIndex:`sessionId`,width:150,render:e=>(0,T.jsx)(`span`,{className:`c2-mono`,children:e||`—`})},{title:e(`c2.tasks.colType`,null,`类型`),dataIndex:`taskType`,width:110},{title:e(`c2.tasks.colCommand`,null,`命令`),dataIndex:`payload`,render:e=>{let t=e?.command||e?.path||``;return(0,T.jsx)(`span`,{className:`c2-mono c2-task-command`,title:t,children:t||`—`})}},{title:e(`c2.tasks.colStatus`,null,`状态`),dataIndex:`status`,width:110,render:t=>(0,T.jsx)(o,{size:`small`,color:C[t]||`grey`,children:e(`c2.tasks.${t||`queued`}`,null,t||`—`)})},{title:e(`c2.tasks.colDuration`,null,`耗时`),dataIndex:`durationMs`,width:100,render:e=>S(e)},{title:e(`c2.tasks.colCreated`,null,`创建时间`),dataIndex:`createdAt`,width:130,render:e=>(0,T.jsx)(me,{value:e})},{title:e(`c2.tasks.colActions`,null,`操作`),dataIndex:`actions`,width:210,render:(t,n)=>(0,T.jsxs)(a,{spacing:4,wrap:!0,children:[(0,T.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>H(n),children:e(`c2.tasks.view`,null,`查看`)}),[`queued`,`sent`,`running`].includes(n.status)&&(0,T.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>Ce(n),children:e(`c2.tasks.cancelBtn`,null,`取消`)}),n.resultBlobPath&&(0,T.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>$(n),children:e(`c2.tasks.downloadResult`,null,`结果文件`)}),(0,T.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,disabled:!i,onClick:()=>we(n),children:e(`c2.tasks.deleteBtn`,null,`删除`)})]})}];return(0,T.jsxs)(`div`,{className:`c2-page`,id:`page-c2-tasks`,children:[(0,T.jsx)(ae,{title:e(`c2.tasks.title`,null,`任务管理`),description:e(`c2.tasks.pageDesc`,null,`按状态、类型、会话与时间窗筛选任务,5 秒自动轮询最新状态`),extra:[(0,T.jsx)(s,{icon:(0,T.jsx)(d,{}),onClick:()=>J(),loading:q,children:e(`c2.tasks.refresh`,null,`刷新任务`)},`refresh`),(0,T.jsx)(s,{theme:`solid`,type:`primary`,icon:(0,T.jsx)(l,{}),disabled:!n,onClick:()=>U(!0),children:e(`c2.tasks.createTitle`,null,`下发任务`)},`create`)]}),(0,T.jsx)(ne,{metrics:Se,columns:4}),(0,T.jsx)(ie,{error:be,onRetry:()=>J()}),(0,T.jsx)(g,{title:e(`c2.tasks.filterTitle`,null,`筛选`),extra:(0,T.jsx)(he,{value:F,onChange:e=>{I(e),O(1)},ns:`tasks`}),children:(0,T.jsxs)(`div`,{className:`c2-toolbar-fields`,children:[(0,T.jsxs)(`div`,{className:`c2-field`,children:[(0,T.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.tasks.colStatus`,null,`状态`)}),(0,T.jsx)(f,{value:j,onChange:e=>{M(e||``),O(1)},style:{width:160},optionList:[{value:``,label:e(`c2.tasks.filterAllStatuses`,null,`全部状态`)},...fe]})]}),(0,T.jsxs)(`div`,{className:`c2-field`,children:[(0,T.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.tasks.colType`,null,`类型`)}),(0,T.jsx)(f,{value:N,onChange:e=>{P(e||``),O(1)},style:{width:160},optionList:[{value:``,label:e(`c2.tasks.filterAllTypes`,null,`全部类型`)},...x]})]}),(0,T.jsxs)(`div`,{className:`c2-field`,children:[(0,T.jsx)(`span`,{className:`c2-field-label`,children:e(`c2.tasks.filterSession`,null,`会话 ID`)}),(0,T.jsx)(c,{value:L,onChange:R,onEnterPress:Q,placeholder:e(`c2.tasks.filterSessionPlaceholder`,null,`s_xxxxxxxx`),style:{width:190}})]}),(0,T.jsxs)(a,{spacing:8,children:[(0,T.jsx)(s,{theme:`solid`,type:`primary`,onClick:Q,children:e(`c2.tasks.applyFilters`,null,`应用筛选`)}),(0,T.jsx)(s,{onClick:xe,children:e(`c2.tasks.resetFilters`,null,`重置`)})]})]})}),(0,T.jsx)(g,{title:e(`c2.tasks.listTitle`,null,`任务列表`),children:(0,T.jsx)(v,{columns:De,dataSource:Y,rowKey:`id`,loading:q,onRefresh:()=>J(),pagination:{currentPage:D,pageSize:A,total:X,onPageChange:e=>O(e),onPageSizeChange:e=>{_e(e),O(1)}},emptyText:e(`c2.tasks.emptyAll`,null,`暂无任务`)})}),(0,T.jsx)(ge,{visible:ve,defaultSessionId:z,submitting:ye,onCancel:()=>U(!1),onSubmit:Ee}),(0,T.jsx)(h,{visible:!!V,title:e(`c2.tasks.modalTitle`,null,`任务详情`),width:760,onCancel:()=>H(null),footer:(0,T.jsxs)(a,{children:[V&&[`queued`,`sent`,`running`].includes(V.status)&&(0,T.jsx)(s,{onClick:()=>Te(V),children:e(`c2.tasks.waitBtn`,null,`等待完成`)}),V?.resultBlobPath&&(0,T.jsx)(s,{onClick:()=>$(V),children:e(`c2.tasks.downloadResult`,null,`下载结果文件`)}),(0,T.jsx)(s,{onClick:()=>H(null),children:e(`c2.tasks.close`,null,`关闭`)})]}),children:V&&(0,T.jsxs)(`div`,{className:`c2-task-detail`,children:[(0,T.jsxs)(`div`,{className:`c2-task-detail-meta`,children:[(0,T.jsx)(`span`,{className:`c2-mono`,children:V.id}),(0,T.jsx)(o,{size:`small`,color:C[V.status]||`grey`,children:V.status}),(0,T.jsx)(k,{type:`tertiary`,size:`small`,children:ee(V.createdAt)}),(0,T.jsx)(k,{type:`tertiary`,size:`small`,children:S(V.durationMs)})]}),(0,T.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.tasks.labelPayload`,null,`参数`)}),(0,T.jsx)(`pre`,{className:`c2-pre`,children:JSON.stringify(V.payload||{},null,2)}),V.resultText&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.tasks.labelResult`,null,`输出`)}),(0,T.jsx)(`pre`,{className:`c2-pre`,children:V.resultText})]}),V.error&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`c2-field-label`,children:e(`c2.tasks.labelError`,null,`错误`)}),(0,T.jsx)(`pre`,{className:`c2-pre c2-pre-error`,children:V.error})]})]})})]})}export{A as default}; \ No newline at end of file diff --git a/web/static/app/assets/chat-B3amLD8_.js b/web/static/app/assets/chat-B3amLD8_.js deleted file mode 100644 index 45e793d3..00000000 --- a/web/static/app/assets/chat-B3amLD8_.js +++ /dev/null @@ -1,5 +0,0 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{$ as a,B as o,C as s,E as c,F as l,G as u,Gt as d,H as f,I as p,It as m,K as h,L as g,Lt as _,N as v,P as y,Pt as b,R as x,S,U as C,Ut as w,Vt as T,W as E,Y as D,Z as O,Zt as k,_ as ee,at as te,en as A,f as j,ft as ne,g as re,h as ie,it as ae,j as M,kt as oe,lt as N,mt as se,nn as ce,on as P,p as le,rt as ue,ut as de,v as F,vt as fe,w as pe,y as me,zt as he}from"./semi-65W_4I1v.js";import{D as I,E as L,F as R,I as ge,L as z,P as _e,S as B,V as ve,a as ye,b as V,f as be,i as xe,k as Se,l as H,n as Ce,o as we,r as Te,u as Ee,x as De,y as Oe,z as ke}from"./index-CAEPLS-g.js";import{n as Ae,t as je}from"./retest-EzTZPjnQ.js";import{n as Me,t as Ne}from"./agent-handoff-DzQOcr38.js";import{t as Pe}from"./project-form-Bm3Gi6Yc.js";import{n as Fe,r as Ie,t as U}from"./model-channel-mQ6lfvSO.js";import{n as Le,t as Re}from"./project-options-CMQbwv_U.js";var W=e(t(),1),G=e(r(),1),ze=new Set([`failed`,`timeout`,`cancelled`,`completed`,`cleanup_unconfirmed`]),Be={running:{key:`tasks.statusRunning`,fallback:`执行中`,color:`blue`},cancelling:{key:`tasks.statusCancelling`,fallback:`取消中`,color:`amber`},cleaning:{key:`tasks.statusCleaning`,fallback:`清理中`,color:`amber`},cleanup_failed:{key:`tasks.statusCleanupFailed`,fallback:`清理异常(自动重试)`,color:`orange`},cleanup_unconfirmed:{key:`tasks.statusCleanupUnconfirmed`,fallback:`远端停止状态待确认`,color:`amber`},failed:{key:`tasks.statusFailed`,fallback:`执行失败`,color:`red`},timeout:{key:`tasks.statusTimeout`,fallback:`执行超时`,color:`red`},cancelled:{key:`tasks.statusCancelled`,fallback:`已取消`,color:`grey`},completed:{key:`tasks.statusCompleted`,fallback:`已完成`,color:`green`}};function Ve(e){return(Array.isArray(e)?e:[]).filter(Boolean).slice().sort((e,t)=>{let n=Date.parse(e?.startedAt||``),r=Date.parse(t?.startedAt||``),i=Number.isFinite(n)?n:2**53-1,a=Number.isFinite(r)?r:2**53-1;if(i!==a)return i-a;let o=String(e?.conversationId||``).localeCompare(String(t?.conversationId||``));return o===0?String(e?.runId||``).localeCompare(String(t?.runId||``)):o})}function He(e,t,n,r){let i=String(e?.conversationId||``).trim();return i&&i===t&&String(n||``).trim()?String(n).trim():String(e?.title||``).trim()||String(e?.message||``).trim()||r(`tasks.unnamedTask`,null,`未命名任务`)}function Ue({tasks:e,currentConversationId:t=``,currentConversationTitle:n=``,canStop:r=!1,stoppingIds:i,onSelect:a,onStop:o}){let{lang:s,t:c}=_e(),l=(0,W.useMemo)(()=>Ve(e),[e]);return l.length?(0,G.jsx)(`div`,{className:`chat-active-tasks`,role:`region`,"aria-label":c(`dashboard.runningTasks`,null,`运行中任务`),children:l.map((e,l)=>{let u=String(e?.conversationId||``).trim(),d=String(e?.status||`running`).toLowerCase(),f=Be[d]||Be.running,p=c(f.key,null,f.fallback),m=ze.has(d),h=d===`cancelling`||!!(u&&i?.has(u)),g=!!(u&&u===t),_=He(e,t,n,c),y=Se(e?.startedAt,s),b=y===`—`?``:y,S=u?`${c(`tasks.viewConversation`,null,`查看对话`)}:${_}`:_;return(0,G.jsxs)(`div`,{className:`chat-active-task${g?` is-current`:``}${u?` is-clickable`:``}`,"data-conversation-id":u||void 0,onClick:e=>{u&&(e.target.closest(`.chat-active-task-stop`)||e.target.closest(`.chat-active-task-main`)||a?.(u))},children:[(0,G.jsxs)(`button`,{type:`button`,className:`chat-active-task-main`,disabled:!u,title:S,onClick:()=>u&&a?.(u),children:[(0,G.jsx)(v,{size:`small`,shape:`circle`,color:f.color,type:`light`,className:`chat-active-task-status`,children:p}),(0,G.jsx)(`span`,{className:`chat-active-task-title`,children:_})]}),(0,G.jsxs)(`div`,{className:`chat-active-task-actions`,children:[b?(0,G.jsx)(`span`,{className:`chat-active-task-time`,children:b}):null,!m&&(0,G.jsx)(x,{size:`small`,type:`danger`,theme:`light`,className:`chat-active-task-stop`,disabled:!r||!u||h,onClick:()=>u&&o?.(u),children:h?c(`tasks.cancelling`,null,`取消中...`):c(`tasks.stopTask`,null,`停止任务`)})]})]},e?.runId||`${u||`task`}-${l}`)})}):null}var{Text:We,Title:Ge}=u,Ke={single:{key:`chat.agentModePiSingle`,label:`单代理`,color:`blue`},deep:{key:`chat.agentModeDeep`,label:`Deep`,color:`purple`},plan_execute:{key:`chat.agentModePlanExecuteLabel`,label:`Plan-Execute`,color:`orange`},supervisor:{key:`chat.agentModeSupervisorLabel`,label:`Supervisor`,color:`green`}};function qe({conversation:e,mode:t,hitlCount:n,conversationId:r,narrow:i,onToggleSidebar:a,onRefresh:o}){let s=R(),c=Ke[t]||Ke.single,l=e?.title||s(`chat.newChat`,null,`新对话`);return(0,G.jsxs)(`header`,{className:`chat-header`,children:[(0,G.jsxs)(`div`,{className:`chat-header-main`,children:[(0,G.jsxs)(`div`,{className:`chat-header-heading`,children:[(0,G.jsx)(Ge,{heading:3,className:`chat-header-title`,title:l,children:l}),(0,G.jsxs)(p,{spacing:6,wrap:!0,className:`chat-header-tags`,children:[e?.pinned&&(0,G.jsx)(v,{size:`small`,color:`amber`,children:s(`chat.pinned`,null,`已置顶`)}),(0,G.jsx)(v,{size:`small`,color:c.color,children:s(c.key,null,c.label)}),n>0&&(0,G.jsx)(v,{size:`small`,color:`orange`,children:s(`chat.pendingApprovals`,{count:n},`待审批 ${n}`)})]})]}),(0,G.jsx)(We,{type:`tertiary`,size:`small`,className:`chat-header-description`,children:r?s(`chat.conversationHint`,null,`会话历史与工具执行过程会自动落库`):s(`chat.newConversationHint`,null,`输入内容即可创建新对话`)})]}),(0,G.jsxs)(p,{spacing:8,wrap:!0,className:`chat-header-actions`,children:[i&&(0,G.jsx)(x,{icon:(0,G.jsx)(fe,{}),onClick:a,children:s(`chat.conversations`,null,`会话`)}),r&&(0,G.jsx)(x,{theme:`borderless`,type:`tertiary`,icon:(0,G.jsx)(de,{"aria-hidden":`true`}),title:s(`chat.refreshConversationHint`,null,`重新读取会话列表、消息、待审批项和执行计划`),onClick:o,children:s(`chat.refreshConversation`,null,`刷新对话`)})]})]})}var Je=[`default`,`off`,`on`,`auto`],K=[`low`,`medium`,`high`,`xhigh`,`max`];function Ye(e,t,n){return t!==`off`&&n?e(`chat.reasoningEffortLabels.${n}`,null,{low:`低`,medium:`中`,high:`高`,xhigh:`超高`,max:`ultra`}[n]):e(`chat.reasoningMode${t[0].toUpperCase()}${t.slice(1)}`,null,{default:`跟随系统`,off:`关闭`,on:`开启`,auto:`自动`}[t])}function Xe(e,t){let[n,r]=(0,W.useState)(()=>{try{return localStorage.getItem(e)??t}catch{return t}});return[n,t=>{r(t);try{localStorage.setItem(e,t)}catch{}}]}function Ze(e,t){return e?.image_input===`enabled`?`enabled`:e?.image_input===`disabled`?`disabled`:t===!0?`enabled`:t===!1?`disabled`:`auto`}function Qe(e){let[t,n]=Xe(`cyberstrike-chat-ai-channel`,``),[r,i]=Xe(`cyberstrike-chat-reasoning-mode`,`default`),[a,o]=Xe(`cyberstrike-chat-reasoning-effort`,``),s=ye(({signal:e}={})=>z.get(`/config`,{include_tools:0},{signal:e}),[e],{skip:!e}),c=s.data?.ai,l={...s,data:c},u=Object.entries(c?.channels||{}).sort(([e],[t])=>e.localeCompare(t)),d=t.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``),f=u.find(([e])=>e===t)?.[0]||u.find(([e])=>e===d)?.[0]||``,p=f||c?.default_channel||``,m=p?c?.channels?.[p]:s.data?.openai,h=m?.reasoning?.allow_client_reasoning===!1,g=String(s.data?.vision?.model||``).trim(),_=!!(s.data?.vision?.enabled&&g),v=Ze(m,s.data?.image_input_defaults?.[p]),y=Je.includes(r)?r:`default`,b=K.includes(a)?a:``,x={mode:y==="default"?void 0:y,effort:y===`off`?void 0:b||void 0};return{channel:f,channels:u,setChannel:n,config:l,mode:y,setMode:i,effort:b,setEffort:o,overrideBlocked:h,vision:{ready:_,model:g,nativeMode:v},waitingForChannel:!!(e&&t&&l.loading),request:{aiChannelId:e&&f||void 0,reasoning:x.mode||x.effort?x:void 0}}}var{Text:$e}=u,et=[`off`,`approval`,`review_edit`],tt=[60,300,600,0],nt=`tool_search, skill, task, write_todos, transfer_to_agent, exit, TaskCreate, TaskGet, TaskUpdate, TaskList, upsert_project_fact, get_project_fact`;function rt(e,t){return t===!1?`off`:et.includes(e)?e:`off`}function q(e){return e===`audit_agent`?`audit_agent`:`human`}function it(e,t=300){if(e==null||e===``)return t;let n=Number(e);return Number.isFinite(n)?Math.max(0,Math.min(86400,Math.round(n))):t}function at(e){return(Array.isArray(e)?e:String(e||``).split(/[,\n\r]+/)).map(e=>String(e||``).trim()).filter(Boolean)}function J(e,t){let n=new Set(at(t).map(e=>e.toLowerCase()));return at(e).filter(e=>!n.has(e.toLowerCase())).join(`, `)}function ot(e,t,n){if(n)return{mode:rt(n.mode,n.enabled),reviewer:q(n.reviewer),timeoutSeconds:it(n.timeoutSeconds),sensitiveTools:at(n.sensitiveTools).join(`, `)};let r=t?e?.hitl:null;return{mode:t?rt(r?.mode,r?.enabled):rt(e?.defaultMode),reviewer:q(t?r?.reviewer:e?.defaultReviewer),timeoutSeconds:it(t?r?.timeoutSeconds??e?.defaultTimeoutSeconds:e?.defaultTimeoutSeconds),sensitiveTools:t?J(r?.sensitiveTools,e?.hitlGlobalToolWhitelist):nt}}function st(e){return{enabled:e.mode!==`off`,mode:e.mode,reviewer:e.reviewer,sensitiveTools:at(e.sensitiveTools),timeoutSeconds:e.timeoutSeconds}}function ct({label:e,...t}){let n=(0,W.useId)();return(0,G.jsxs)(`div`,{className:`chat-setting-field`,children:[(0,G.jsx)($e,{id:n,strong:!0,children:e}),(0,G.jsx)(me,{"aria-labelledby":n,...t})]})}function lt({model:e,busy:t,canReadConfig:r}){let i=R(),a=n(),o=(0,W.useId)(),s=(0,W.useRef)(null),c=e.config.data?.default_channel,l=c?U(c,e.config.data?.channels?.[c]):``,u=i(`chat.aiChannelDefault`,null,`跟随默认通道`),d=[{value:``,label:l?`${u} · ${l}`:u},...Fe(e.channels)],f=Object.fromEntries(Je.map(e=>[e,Ye(i,e,``)])),p=t||e.overrideBlocked,m=[``,...K],h=Object.fromEntries(m.map((e,t)=>[t,Ye(i,e?`on`:`default`,e)])),g=()=>{e.setMode(`default`),e.setEffort(``)};return(0,G.jsxs)(`div`,{className:`chat-reasoning-picker${!e.overrideBlocked&&e.mode!==`off`&&e.effort===`max`?` is-max`:``}${p?` is-disabled`:``}`,ref:s,children:[(0,G.jsxs)(`div`,{className:`chat-reasoning-heading`,children:[(0,G.jsx)(pe,{trigger:`click`,position:`bottomLeft`,className:`chat-reasoning-mode-menu`,getPopupContainer:()=>s.current,showTick:!0,menu:Je.map(t=>({node:`item`,name:f[t],active:e.mode===t,disabled:p,onClick:()=>t==="default"?g():e.setMode(t)})),children:(0,G.jsx)(x,{theme:`borderless`,type:`tertiary`,icon:(0,G.jsx)(k,{}),className:`chat-reasoning-mode`,"aria-label":i(`chat.reasoningModeLabel`,null,`模型推理`),title:`${i(`chat.reasoningModeLabel`,null,`模型推理`)} · ${f[e.overrideBlocked?`default`:e.mode]}`,disabled:p})}),(0,G.jsx)($e,{strong:!0,className:`chat-reasoning-value`,role:`status`,children:e.overrideBlocked?f.default:Ye(i,e.mode,e.effort)}),(0,G.jsx)(x,{theme:`borderless`,type:`tertiary`,icon:(0,G.jsx)(O,{}),"aria-label":i(`chat.reasoningReset`,null,`重置推理设置`),title:i(`chat.reasoningReset`,null,`重置推理设置`),disabled:p,onClick:g})]}),r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{id:o,hidden:!0,children:i(`chat.aiChannelLabel`,null,`AI 通道`)}),(0,G.jsx)(me,{className:`chat-reasoning-channel`,"aria-labelledby":o,value:e.channel,optionList:d,renderSelectedItem:e=>e.value===``?l||i(`chat.aiChannelDefaultShort`,null,`默认通道`):Ie(e),arrowIcon:(0,G.jsx)(w,{size:`small`}),borderless:!0,onSelect:e.setChannel,dropdownMatchSelectWidth:!1,dropdownStyle:{maxWidth:`calc(100vw - 32px)`},loading:e.config.loading,disabled:t||e.config.loading||!!e.config.error}),(0,G.jsx)(H,{error:e.config.error,onRetry:()=>e.config.reload()})]}):(0,G.jsx)($e,{type:`tertiary`,className:`chat-reasoning-channel-label`,children:u}),(0,G.jsx)(j,{className:`chat-reasoning-slider`,"aria-label":i(`chat.reasoningEffortLabel`,null,`推理强度`),min:0,max:m.length-1,step:1,marks:h,showMarkLabel:!1,tipFormatter:e=>h[e],getAriaValueText:t=>e.mode===`off`&&!e.overrideBlocked?f.off:h[t],value:e.overrideBlocked?0:m.indexOf(e.effort),disabled:p||e.mode===`off`,onChange:t=>{e.setEffort(m[t]),e.setMode(t===0?`default`:e.mode===`auto`?`auto`:`on`)}}),e.overrideBlocked&&(0,G.jsx)($e,{type:`tertiary`,size:`small`,className:`chat-reasoning-hint`,children:i(`chat.reasoningOverrideBlocked`,null,`此通道使用系统设置中的推理强度。`)}),r&&!e.config.loading&&!e.config.error&&(0,G.jsxs)(`div`,{className:`chat-vision-entry`,children:[(0,G.jsx)($e,{type:`tertiary`,size:`small`,className:`chat-vision-entry-status`,children:e.vision?.ready?`辅助识图:${e.vision.model}`:e.vision?.nativeMode===`enabled`?`图片识别:通道原生支持`:`当前模型不支持识图?`}),(0,G.jsx)(`button`,{type:`button`,className:`chat-vision-entry-link`,onClick:()=>a(`/settings?section=models&focus=vision`),children:e.vision?.ready?`配置`:`配置视觉模型`})]})]})}function ut({onClose:e,narrow:t,canEnableHitl:n,conversationId:r,draftHitl:i,onDraftHitlChange:a}){let o=R(),s=o(`chat.hitlTitle`,null,`人机协同`),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(!1),g=(0,W.useRef)(0),_=(0,W.useRef)(i),v=(0,W.useId)(),y=(0,W.useId)();_.current=i;let b=ye(()=>z.get(r?`/hitl/config/${encodeURIComponent(r)}`:`/hitl/default-config`),[r]);(0,W.useEffect)(()=>{b.data&&(p(ot(b.data,r,_.current)),h(!1))},[b.data,r]);let x={off:o(`chat.hitlModeOff`,null,`关闭`),approval:o(`chat.hitlModeApproval`,null,`审批模式`),review_edit:o(`chat.hitlModeReviewEdit`,null,`审查编辑`)},C={60:o(`chat.hitlTimeoutOneMinute`,null,`1 分钟`),300:o(`chat.hitlTimeoutFiveMinutes`,null,`5 分钟`),600:o(`chat.hitlTimeoutTenMinutes`,null,`10 分钟`),0:o(`chat.hitlTimeoutUnlimited`,null,`不限制`)},w=tt.map(e=>({value:e,label:C[e]}));f&&!tt.includes(f.timeoutSeconds)&&w.unshift({value:f.timeoutSeconds,label:`${f.timeoutSeconds}s`});let T=!n||c,D=async e=>{let t=++g.current,n=st(e);l(!0),d(!1);try{if(await z.put(`/hitl/config`,{conversationId:r,...n}),t!==g.current)return;b.setData(e=>({...e,hitl:n})),d(!0)}catch(e){t===g.current&&(V(e,o(`chat.hitlApplyFail`,null,`同步到服务器失败`)),b.reload({silent:!0}))}finally{t===g.current&&l(!1)}},O=e=>{let t={...f,...e};p(t),h(!1),d(!1),r?D(t):a(st(t))};return(0,G.jsx)(le,{visible:!0,title:s,"aria-label":s,width:t?`100%`:420,closable:!c,maskClosable:!c,closeOnEsc:!c,onCancel:e,children:(0,G.jsx)(`div`,{className:`chat-settings-fields`,children:(0,G.jsxs)(`section`,{className:`chat-setting-field chat-setting-hitl`,children:[(0,G.jsx)($e,{type:`tertiary`,size:`small`,children:o(`chat.sessionSettingsHint`,null,`人机协同设置只影响后续消息。`)}),(c||u)&&(0,G.jsx)($e,{type:`tertiary`,size:`small`,role:`status`,children:c?o(`chat.systemModelSaving`,null,`正在保存…`):o(`chat.hitlApplyOkSync`,null,`人机协同配置已保存并同步到服务器。`)}),(0,G.jsx)(H,{error:b.error,onRetry:()=>b.reload()}),b.loading&&(0,G.jsx)(E,{}),f&&b.data&&!b.error&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ct,{label:o(`chat.hitlModeLabel`,null,`模式`),value:f.mode,optionList:et.map(e=>({value:e,label:x[e]})),onSelect:e=>O({mode:e}),disabled:T}),(0,G.jsxs)(`div`,{className:`chat-setting-field`,children:[(0,G.jsx)($e,{id:v,strong:!0,children:o(`chat.hitlReviewerLabel`,null,`审批方`)}),(0,G.jsx)(ie,{"aria-labelledby":v,type:`button`,className:`chat-setting-reviewer`,value:f.reviewer,options:[{value:`human`,label:o(`chat.hitlReviewerHuman`,null,`人工审批`)},{value:`audit_agent`,label:o(`chat.hitlReviewerAgent`,null,`审计 Agent`)}],onChange:e=>O({reviewer:e.target.value}),disabled:T}),(0,G.jsx)($e,{type:`tertiary`,size:`small`,children:o(`chat.hitlReviewerHint`,null,`可在人工与审计 Agent 之间随时切换;规则与白名单不变。人机协同为「关闭」时也可预先选择。`)})]}),(0,G.jsx)(ct,{label:o(`chat.hitlTimeoutLabel`,null,`审批等待时限`),value:f.timeoutSeconds,optionList:w,onSelect:e=>O({timeoutSeconds:Number(e)}),disabled:T}),(0,G.jsxs)(`div`,{className:`chat-setting-field`,children:[(0,G.jsx)($e,{id:y,strong:!0,children:o(`chat.hitlWhitelistTools`,null,`白名单工具(免审批,逗号分隔)`)}),(0,G.jsx)(S,{"aria-labelledby":y,value:f.sensitiveTools,placeholder:o(`chat.hitlWhitelistPlaceholder`,null,`例:read_file, grep 或每行一个工具名(与 config 全局白名单合并)`),rows:5,disabled:T,onChange:e=>{let t={...f,sensitiveTools:e};p(t),h(!0),d(!1),r||a(st(t))},onBlur:()=>{m&&r&&!T&&(h(!1),D(f))}}),(0,G.jsx)($e,{type:`tertiary`,size:`small`,children:o(`chat.hitlWhitelistHint`,null,`白名单内工具免审批;每行一个或逗号分隔,与 config 全局白名单合并。`)})]})]})]})})})}var{Text:dt}=u;function ft({item:e,active:t,editing:n,editingTitle:r,onStartEdit:i,onEditingTitle:a,onCommitEdit:o,onCancelEdit:s,onSelect:c,onPin:l,onDelete:u,canWrite:d,canDelete:f,selected:p,onToggleSelect:m,batchMode:h}){let g=R(),v=String(e.title||g(`chat.untitled`,null,`未命名对话`));return(0,G.jsxs)(`div`,{className:`chat-conv-item ${t?`is-active`:``}`,children:[h&&(0,G.jsx)(y,{className:`chat-conv-check`,"aria-label":`${g(`chat.selectConversation`,null,`选择对话`)}:${v}`,checked:p,onChange:t=>m(e.id,t.target.checked)}),n?(0,G.jsxs)(`div`,{className:`chat-conv-edit`,children:[(0,G.jsx)(C,{size:`small`,"aria-label":g(`chat.renameConversationTitle`,null,`重命名`),value:r,autoFocus:!0,onChange:a,onEnterPress:o,onKeyDown:e=>{e.key===`Escape`&&s()}}),(0,G.jsxs)(`div`,{className:`chat-conv-edit-actions`,children:[(0,G.jsx)(x,{size:`small`,theme:`solid`,onClick:o,children:g(`common.save`,null,`保存`)}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,onClick:s,children:g(`common.cancel`,null,`取消`)})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{type:`button`,className:`chat-conv-main`,"aria-current":t?`true`:void 0,title:v,onClick:()=>c(e.id),children:[(0,G.jsxs)(`span`,{className:`chat-conv-title`,children:[e.pinned&&(0,G.jsx)(ae,{size:`small`,className:`chat-conv-pin`}),(0,G.jsx)(`span`,{className:`chat-conv-title-text`,children:v})]}),(0,G.jsx)(`span`,{className:`chat-conv-meta`,children:L(e.updatedAt||e.createdAt)})]}),!h&&(0,G.jsxs)(`div`,{className:`chat-conv-actions`,children:[d&&(0,G.jsx)(P,{content:g(`chat.renameConversationTitle`,null,`重命名`),children:(0,G.jsx)(x,{size:`small`,theme:`borderless`,"aria-label":g(`chat.renameConversationTitle`,null,`重命名`),icon:(0,G.jsx)(b,{}),onClick:()=>i(e)})}),d&&(0,G.jsx)(P,{content:e.pinned?g(`chat.unpin`,null,`取消置顶`):g(`chat.pin`,null,`置顶`),children:(0,G.jsx)(x,{size:`small`,theme:`borderless`,icon:(0,G.jsx)(ae,{}),"aria-label":e.pinned?g(`chat.unpin`,null,`取消置顶`):g(`chat.pin`,null,`置顶`),type:e.pinned?`warning`:`tertiary`,onClick:()=>l(e)})}),f&&(0,G.jsx)(ee,{title:g(`chat.deleteConversationConfirm`,null,`确认删除该对话?删除后不可恢复。`),onConfirm:()=>u(e),children:(0,G.jsx)(x,{size:`small`,theme:`borderless`,type:`danger`,"aria-label":g(`chat.deleteConversationTitle`,null,`删除对话`),icon:(0,G.jsx)(_,{})})})]})]})]})}function pt({items:e,groups:t,expandedGroup:n,groupTotal:r,onToggleGroup:i,loading:a,error:o,onRetry:l,search:u,onSearch:f,projectId:p,onProjectChange:m,projects:h,page:_,pageSize:v,onPageChange:b,selectedId:S,onSelect:w,onCreate:T,onRename:E,onPin:D,onDelete:O,onBatchDelete:k,canWrite:ee,canDelete:te}){let A=R(),j=e,re=(0,W.useId)(),ie=(0,W.useId)(),[ae,M]=(0,W.useState)(``),[se,ce]=(0,W.useState)(``),[P,le]=(0,W.useState)(!1),[ue,fe]=(0,W.useState)([]),pe=j.length>0&&j.every(e=>ue.includes(e.id)),he=!pe&&j.some(e=>ue.includes(e.id));(0,W.useEffect)(()=>{fe([]),le(!1)},[_,p,u,n]);let I=(0,W.useMemo)(()=>[{value:``,label:A(`chat.filterAllProjects`,null,`全部项目`)},...(Array.isArray(h)?h:[]).map(e=>({value:e.id,label:Le(e,A)}))],[h,A]),L=(e,t)=>{fe(n=>t?[...new Set([...n,e])]:n.filter(t=>t!==e))},ge=e=>{M(e.id),ce(String(e.title||``))},z=()=>{let e=ae,t=se.trim();M(``),e&&t&&E(e,t)},_e=(0,G.jsxs)(G.Fragment,{children:[a&&!j.length&&(0,G.jsx)(g,{placeholder:(0,G.jsx)(g.Paragraph,{rows:6}),loading:!0}),!a&&!o&&!j.length&&(0,G.jsx)(c,{title:A(`chat.noHistoryConversations`,null,`暂无历史对话`),description:null,className:`chat-sidebar-empty`}),(0,G.jsx)(s,{dataSource:j,split:!1,renderItem:e=>(0,G.jsx)(ft,{item:e,active:e.id===S,editing:ae===e.id,editingTitle:se,onStartEdit:ge,onEditingTitle:ce,onCommitEdit:z,onCancelEdit:()=>M(``),onSelect:w,onPin:D,onDelete:O,canWrite:ee,canDelete:te,batchMode:P,selected:ue.includes(e.id),onToggleSelect:L},e.id)})]});return(0,G.jsxs)(`div`,{className:`chat-sidebar-inner`,children:[(0,G.jsxs)(`div`,{className:`chat-sidebar-head`,children:[(0,G.jsx)(dt,{strong:!0,className:`chat-sidebar-title`,children:A(`chat.conversations`,null,`会话`)}),(0,G.jsx)(x,{icon:(0,G.jsx)(ne,{}),theme:`borderless`,className:`chat-new-chat`,onClick:T,disabled:!ee,children:A(`chat.newChat`,null,`新建对话`)})]}),(0,G.jsxs)(`div`,{className:`chat-sidebar-filters`,children:[(0,G.jsx)(C,{prefix:(0,G.jsx)(N,{}),"aria-label":A(`chat.searchHistory`,null,`搜索历史对话`),placeholder:A(`chat.searchHistory`,null,`搜索历史对话`),value:u,onChange:f,showClear:!0}),(0,G.jsx)(`span`,{id:ie,hidden:!0,children:A(`chat.filterByProject`,null,`按项目过滤`)}),(0,G.jsx)(me,{value:p,optionList:I,onChange:m,className:`chat-sidebar-project`,"aria-labelledby":ie,placeholder:A(`chat.filterByProject`,null,`按项目过滤`)})]}),(0,G.jsxs)(`div`,{className:`chat-sidebar-tools`,children:[(0,G.jsxs)(dt,{type:`tertiary`,size:`small`,children:[A(`chat.recentConversations`,null,`最近对话`),` · `,t.reduce((e,t)=>e+t.total,0)]}),(0,G.jsxs)(`div`,{className:`chat-sidebar-tools-actions`,children:[te&&j.length>0&&(0,G.jsx)(x,{size:`small`,theme:P?`solid`:`borderless`,onClick:()=>{le(!P),fe([])},children:P?A(`common.cancel`,null,`取消`):A(`chat.batchManage`,null,`批量管理`)}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,"aria-label":A(`chat.refreshConversationList`,null,`刷新会话列表`),title:A(`chat.refreshConversationList`,null,`刷新会话列表`),icon:(0,G.jsx)(de,{}),onClick:l})]})]}),P&&(0,G.jsxs)(`div`,{className:`chat-batch-bar`,children:[(0,G.jsx)(y,{className:`chat-batch-select-all`,checked:pe,indeterminate:he,disabled:a||!j.length,onChange:e=>fe(e.target.checked?j.map(e=>e.id):[]),children:A(`chat.selectPage`,null,`全选本页`)}),(0,G.jsxs)(dt,{size:`small`,children:[A(`chat.selectedCount`,null,`已选`),` `,ue.length]}),(0,G.jsx)(x,{size:`small`,type:`danger`,disabled:!ue.length,onClick:async()=>{await k(ue),fe([]),le(!1)},children:A(`chat.batchDelete`,null,`批量删除`)})]}),(0,G.jsxs)(`div`,{className:`chat-conv-list`,children:[(0,G.jsx)(H,{error:o,onRetry:l}),!t.length&&!a&&!o&&(0,G.jsx)(c,{title:A(`chat.noHistoryConversations`,null,`暂无历史对话`),description:null,className:`chat-sidebar-empty`}),t.map(e=>{let t=e.id===n,r=re+`-`+e.id;return(0,G.jsxs)(`div`,{className:`chat-conv-group`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`chat-conv-group-toggle`,"aria-expanded":t,"aria-controls":r,title:e.projectId?e.title+` · `+e.projectId:e.title,onClick:()=>i(e.id),children:[(0,G.jsx)(oe,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`chat-conv-group-name`,children:e.title}),(0,G.jsx)(`span`,{className:`chat-conv-group-count`,children:e.total}),(0,G.jsx)(d,{"aria-hidden":`true`,className:`chat-conv-group-chevron`})]}),(0,G.jsx)(`div`,{id:r,className:`chat-conv-group-content`,hidden:!t,children:t&&_e})]},e.id)})]}),n&&r>v&&(0,G.jsx)(`div`,{className:`chat-sidebar-pager`,children:(0,G.jsx)(F,{size:`small`,total:r,pageSize:v,currentPage:_,onPageChange:b,showSizeChanger:!1})})]})}var mt=new Set([`taskcreate`,`taskupdate`,`tasklist`,`taskget`,`write_todos`]),ht=new Set([`heartbeat`,`response_delta`,`thinking_stream_delta`,`reasoning_chain_stream_delta`,`tool_result_delta`]),gt=200,_t=2e4;function Y(e){return e==null?``:String(e)}function vt(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:null}function X(e,t=_t){let n=Y(e);return n.length<=t?n:`${n.slice(0,t)}\n…(已截断,共 ${n.length} 字符)`}function Z(e,t=6e3){if(e==null)return``;try{return X(typeof e==`string`?e:JSON.stringify(e,null,2),t)}catch{return X(String(e),t)}}function yt({conversationId:e=``,id:t}={}){return{id:t||`live-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,conversationId:e,status:`streaming`,text:``,blocks:[],toolsByCallId:new Map,events:[],error:``,notice:``,statusText:``,messageId:``,userMessageId:``,finalizable:null,startedAt:Date.now(),endedAt:0,seq:0}}function Q(e,t){return e.seq+=1,`${t}-${e.seq}`}function bt(e,t){let n=Y(t.type);ht.has(n)||(e.events.push({at:Date.now(),type:n,message:Y(t.message),data:t.data===void 0?null:t.data}),e.events.length>gt&&e.events.splice(0,e.events.length-gt))}function $(e,{title:t,message:n,tone:r=`info`,data:i=null}){let a=e.blocks[e.blocks.length-1];if(a&&a.kind===`note`&&a.title===t&&a.message===Y(n))return a;let o={kind:`note`,id:Q(e,`note`),title:t,message:X(n),tone:r,data:i};return e.blocks.push(o),o}function xt(e,t,n=`thinking`){let r=Y(t)||Q(e,`reasoning`),i=r?e.blocks.find(e=>e.kind===`reasoning`&&e.key===r):null;return i||(i={kind:`reasoning`,id:Q(e,`reason`),key:r,stream:Y(t),label:n,text:``},e.blocks.push(i)),i}function St(e){let t=vt(e.argumentsObj);if(t&&Object.keys(t).length)return t;let n=e.arguments??e.argumentsObj??null;if(typeof n!=`string`)return n;if(!n.trim())return null;try{return JSON.parse(n)}catch{return n}}function Ct(e){return St(vt(e?.data)||{})}function wt(e){let t=vt(e?.data)||{};return Z(t.resultPreview??t.result??t.error??e?.message,8e3)}function Tt({blocks:e,toolsByCallId:t},{toolCallId:n,toolName:r,agentName:i}){let a=e=>!i||!e.agentName||e.agentName===i,o=t.get(n)?.filter(a);return o?.length?o.find(e=>!e.hasResult)||o[o.length-1]:r?e.find(e=>e.kind===`tool`&&!e.hasResult&&e.toolName===r&&a(e)&&(!n||!e.toolCallId)):null}function Et(e){let t=Y(e.displayStatus||e.status).toLowerCase();return t===`cancelled`||t===`canceled`?`cancelled`:t===`background_running`?`running`:t===`blocked`?`blocked`:e.isError===!0||e.success===!1?`failed`:`success`}function Dt(e,t,n,r,i,a){var o,s;let c={toolCallId:Y(n.toolCallId),toolName:Y(n.toolName),agentName:Y(n.agentName)},l=St(n),u=t===`tool_result`,d=Y(a),f=u?Tt(e,c):null;if(f?!u&&d&&!f.callDetailId&&(f.callDetailId=d):(f={kind:`tool`,id:i(`tool`),toolCallId:``,toolName:c.toolName,agentName:c.agentName,args:l,result:``,status:`running`,processDetailId:d,callDetailId:u?``:d,resultDetailId:u?d:``,argsDeferred:!!(!u&&n._argsDeferred&&d),resultDeferred:!1,hasDeferredPayload:!!(n._hasPayload||n._argsDeferred),hasResult:!1},e.blocks.push(f)),c.toolCallId&&!f.toolCallId){f.toolCallId=c.toolCallId;let t=e.toolsByCallId.get(f.toolCallId);t?t.push(f):e.toolsByCallId.set(f.toolCallId,[f])}if(!u){n._argsDeferred&&d&&(f.argsDeferred=!0,f.hasDeferredPayload=!0);return}f.hasResult=!0,(o=f).toolName||(o.toolName=c.toolName),(s=f).agentName||(s.agentName=c.agentName),d&&(f.resultDetailId=d),f.status=Et(n),l!==null&&(f.args===null||vt(f.args)&&!Object.keys(f.args).length)&&(f.args=l,f.argsDeferred=!1);let p=n.resultPreview??n.result??n.error??(Y(r).trim()?r:void 0);p!=null&&Y(p)!==``?(f.result=Z(p,8e3),f.resultDeferred=!1):n._payloadDeferred&&n._hasPayload!==!1&&d&&(f.resultDeferred=!0,f.hasDeferredPayload=!0)}function Ot(e,t){if(!e||!t||typeof t!=`object`)return e;let n=Y(t.type),r=vt(t.data)||{};switch(bt(e,t),n){case`heartbeat`:break;case`conversation`:r.conversationId&&(e.conversationId=Y(r.conversationId));break;case`message_saved`:r.userMessageId&&(e.userMessageId=Y(r.userMessageId));break;case`progress`:e.statusText=Y(t.message)||e.statusText;break;case`iteration`:{let n=Number(r.iteration)||1,i=Y(r.piScope).trim(),a=Y(r.agentName).trim(),o=i===`main`?a?`主代理 · ${a}`:`主代理`:i===`sub`?`子代理${a?` · ${a}`:``}`:``;e.blocks.push({kind:`iteration`,id:Q(e,`iter`),title:`第 ${n} 轮迭代${o?` · ${o}`:``}`,message:X(t.message,2e3)});break}case`thinking_stream_start`:case`reasoning_chain_stream_start`:{let t=xt(e,r.streamId,n===`reasoning_chain_stream_start`?`reasoning_chain`:`thinking`);t.text=``;break}case`thinking_stream_delta`:case`reasoning_chain_stream_delta`:{let i=xt(e,r.streamId,n===`reasoning_chain_stream_delta`?`reasoning_chain`:`thinking`),a=typeof r.accumulated==`string`?r.accumulated:null;i.text=X(a===null?i.text+Y(t.message):a);break}case`thinking`:case`reasoning_chain`:if(r.streamId){let i=xt(e,r.streamId,n===`reasoning_chain`?`reasoning_chain`:`thinking`);Y(t.message)&&(i.text=X(t.message));break}e.blocks.push({kind:`reasoning`,id:Q(e,`reason`),key:Q(e,`reasonkey`),stream:``,label:n===`reasoning_chain`?`reasoning_chain`:`thinking`,text:X(t.message)});break;case`response_start`:r.conversationId&&(e.conversationId=Y(r.conversationId)),e.statusText||(e.statusText=`正在生成回复…`);break;case`response_delta`:{let n=typeof r.accumulated==`string`?r.accumulated:null;e.text=X(n===null?e.text+Y(t.message):n,6e4);break}case`response`:{let n=Y(t.message);n&&(e.text=X(n,6e4)),r.messageId&&(e.messageId=Y(r.messageId)),r.conversationId&&(e.conversationId=Y(r.conversationId)),r.finalizable===!1?e.finalizable=!1:r.finalizable===!0&&(e.finalizable=!0);break}case`tool_call`:case`tool_result`:Dt(e,n,r,t.message,t=>Q(e,t),r.processDetailId);break;case`tool_calls_detected`:$(e,{title:`🔧 检测到工具调用`,message:t.message,data:r});break;case`hitl_interrupt`:$(e,{title:`🧑‍⚖️ 等待人工审批`,message:`${Y(r.toolName)||`工具`} · ${Y(t.message)||`命中审批策略`}`,tone:`warning`,data:r});break;case`hitl_resumed`:$(e,{title:`✅ 审批通过`,message:Y(t.message),tone:`success`,data:r});break;case`hitl_rejected`:$(e,{title:`⛔ 审批被拒绝`,message:Y(t.message),tone:`danger`,data:r});break;case`hitl_audit_agent_started`:$(e,{title:`🛡 审计代理审查中`,message:Y(t.message),tone:`info`,data:r});break;case`hitl_audit_agent`:$(e,{title:`🛡 审计代理已裁决`,message:`${Y(r.decision)||`-`}${r.comment?` · ${Y(r.comment)}`:``}`,tone:`info`,data:r});break;case`warning`:case`iteration_limit_reached`:case`pi_pending_orphaned`:$(e,{title:`⚠️ ${Y(t.message)||`提示`}`,message:Y(t.message),tone:`warning`,data:r});break;case`finalization_check`:$(e,{title:`🔎 最终化校验未通过`,message:Y(t.message),tone:`warning`,data:r}),r.finalizable===!1&&(e.finalizable=!1);break;case`finalization_auto_continue`:case`finalization_pending_tools_cancelled`:case`agent_empty_response_continue`:case`agent_run_retry`:case`pi_model_retry`:case`pi_model_failover`:case`pi_stream_error`:$(e,{title:Y(t.message)||`运行提示`,message:Y(t.message),tone:`warning`,data:r});break;case`agent_usage_summary`:e.blocks.push({kind:`usage`,id:Q(e,`usage`),data:r});break;case`user_interrupt_continue`:$(e,{title:`⏸️ 用户中断并继续`,message:Y(t.message),tone:`info`,data:r});break;case`agent_reply`:$(e,{title:`💬 ${Y(r.agentName)||`子代理`}回复`,message:Y(t.message),data:r});break;case`workflow_start`:case`workflow_done`:case`workflow_node_start`:case`workflow_node_result`:case`workflow_branch_taken`:case`workflow_branch_skipped`:case`workflow_tool_start`:case`workflow_agent_output`:case`workflow_hitl_checkpoint`:case`workflow_hitl_waiting`:case`workflow_hitl_resumed`:case`workflow_hitl_rejected`:case`workflow_paused`:$(e,{title:`🧭 ${Y(t.message)||n}`,message:Y(t.message),data:r});break;case`cancelled`:e.status=`cancelled`,e.notice=Y(t.message)||`任务已取消`,e.endedAt=Date.now();break;case`error`:e.status=`error`,e.error=Y(t.message)||`执行失败`,e.endedAt=Date.now();break;case`done`:e.status===`streaming`&&(e.status=r.status===`blocked`||e.finalizable===!1?`blocked`:`done`),r.workflowStatus===`awaiting_hitl`&&(e.statusText=`工作流等待审批`),e.endedAt=Date.now()}return e}var kt={streaming:{label:`生成中`,color:`blue`},done:{label:`已完成`,color:`green`},blocked:{label:`未完成`,color:`orange`},disconnected:{label:`连接已结束`,color:`grey`},error:{label:`失败`,color:`red`},cancelled:{label:`已取消`,color:`grey`}};function At(e){let t=[],n={blocks:t,toolsByCallId:new Map},r=0,i=e=>(r+=1,`h-${e}-${r}`),a=Y(e?.reasoningContent).trim();return a&&t.push({kind:`reasoning`,id:i(`reason`),key:`reasoningContent`,stream:``,label:`thinking`,text:X(a)}),(Array.isArray(e?.processDetails)?e.processDetails:[]).forEach(e=>{let r=Y(e?.eventType),a=vt(e?.data)||{},o=Y(e?.message);switch(r){case`iteration`:{let e=Number(a.iteration)||1,n=Y(a.piScope).trim(),r=Y(a.agentName).trim();t.push({kind:`iteration`,id:i(`iter`),title:`第 ${e} 轮迭代${n===`main`?` · 主代理`:n===`sub`?` · 子代理`:``}${r?` · ${r}`:``}`,message:X(o,2e3)});break}case`thinking`:case`reasoning_chain`:{let n=!!(a._payloadDeferred&&e?.id&&!o.trim());if(!o.trim()&&!n)break;t.push({kind:`reasoning`,id:i(`reason`),detailId:Y(e?.id),key:Y(a.streamId)||i(`reasonkey`),stream:Y(a.streamId),label:r,text:n?``:X(o),textLength:n?Number(a._textLength)||0:o.length,payloadDeferred:n});break}case`tool_call`:case`tool_result`:Dt(n,r,a,o,i,e?.id);break;case`planning`:if(!o.trim())break;t.push({kind:`note`,id:i(`note`),title:`📝 规划`,message:X(o,4e3),tone:`info`,data:null});break;case`hitl_interrupt`:case`hitl_resumed`:case`hitl_rejected`:case`hitl_audit_agent`:case`hitl_audit_agent_started`:{let e=r===`hitl_rejected`?`danger`:r===`hitl_resumed`?`success`:`info`,n=r===`hitl_interrupt`?`🧑‍⚖️ 人工审批`:r===`hitl_rejected`?`⛔ 审批被拒绝`:r===`hitl_resumed`?`✅ 审批通过`:`🛡 审计代理`;t.push({kind:`note`,id:i(`note`),title:n,message:`${o}${a.toolName?` · ${Y(a.toolName)}`:``}${a.decision?` · ${Y(a.decision)}`:``}`,tone:e,data:null});break}case`error`:case`timeout`:case`cancelled`:t.push({kind:`note`,id:i(`note`),title:r===`cancelled`?`⏹ 已取消`:`❌ 执行异常`,message:o,tone:`danger`,data:null});break;case`agent_reply`:t.push({kind:`note`,id:i(`note`),title:`💬 子代理回复`,message:X(o,6e3),tone:`info`,data:null});break;case`agent_usage_summary`:t.push({kind:`usage`,id:i(`usage`),data:a});break;case`progress`:break;default:(o.trim()||Object.keys(a).length)&&t.push({kind:`note`,id:i(`note`),title:Y(r)||`过程事件`,message:X(o,4e3),tone:`info`,data:Object.keys(a).length?a:null})}}),t}var{Text:jt}=u,Mt={running:{color:`blue`,label:`执行中`},success:{color:`green`,label:`完成`},failed:{color:`red`,label:`失败`},cancelled:{color:`grey`,label:`已取消`},blocked:{color:`orange`,label:`已拦截`}};function Nt(e){return Array.isArray(e)?e.includes(`1`):e===`1`}function Pt({block:e,defaultOpen:t}){let[n,r]=(0,W.useState)(!!t),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(``),u=(0,W.useRef)(null),d=e.text||i,f=d?d.length:Number(e.textLength)||0,p=!!(e.payloadDeferred&&e.detailId&&!d),m=(0,W.useCallback)(async()=>{if(!e.detailId)return;u.current?.abort();let t=new AbortController;u.current=t,s(!0),l(``);try{let n=await z.get(`/process-details/${encodeURIComponent(e.detailId)}`,null,{signal:t.signal});if(t.signal.aborted)return;let r=n?.processDetail;a(String(r?.message||``))}catch(e){t.signal.aborted||l(ke(e,`加载思考过程失败`))}finally{u.current===t&&(u.current=null,s(!1))}},[e.detailId]);(0,W.useEffect)(()=>()=>u.current?.abort(),[]),(0,W.useEffect)(()=>{n&&p&&!o&&!c&&m()},[n,p,o,c,m]);let h=(0,W.useMemo)(()=>n&&d?X(d):``,[n,d]);if(!d.trim()&&!e.payloadDeferred)return null;let g=e.label===`reasoning_chain`?`🔗 推理过程`:`🤔 思考过程`;return(0,G.jsx)(M,{className:`chat-block-collapse`,activeKey:n?[`1`]:[],onChange:e=>r(Nt(e)),children:(0,G.jsxs)(M.Panel,{itemKey:`1`,header:(0,G.jsxs)(`span`,{className:`chat-block-title`,children:[g,` · `,f,` 字符`]}),children:[n&&o&&(0,G.jsxs)(`div`,{className:`chat-tool-loading`,children:[(0,G.jsx)(E,{size:`small`}),(0,G.jsx)(`span`,{children:`正在加载思考过程…`})]}),n&&c&&(0,G.jsxs)(`div`,{className:`chat-tool-error`,children:[(0,G.jsx)(`span`,{children:c}),(0,G.jsx)(`button`,{type:`button`,className:`chat-link-btn`,onClick:()=>void m(),children:`重试`})]}),n&&h&&(0,G.jsx)(`pre`,{className:`chat-pre`,children:h})]})})}function Ft({block:e,index:t,total:n}){let{t:r}=_e(),[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(void 0),[c,l]=(0,W.useState)(void 0),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(``),m=(0,W.useRef)(null),h=Mt[e.status]||Mt.running,g=o===void 0?e.args:o,_=c===void 0?e.result||``:c,y=!!(e.argsDeferred&&e.callDetailId&&o===void 0),b=!!(e.resultDeferred&&e.resultDetailId&&c===void 0),x=!!(g!=null&&g!==``||_||y||b||e.hasDeferredPayload),S=(0,W.useCallback)(async()=>{let t=[];if(y&&e.callDetailId&&t.push({kind:`args`,id:e.callDetailId}),b&&e.resultDetailId&&t.push({kind:`result`,id:e.resultDetailId}),!t.length)return;m.current?.abort();let n=new AbortController;m.current=n,d(!0),p(``);try{let e=await Promise.all(t.map(async e=>{let t=await z.get(`/process-details/${encodeURIComponent(e.id)}`,null,{signal:n.signal});return{kind:e.kind,detail:t?.processDetail||null}}));if(n.signal.aborted)return;for(let t of e)t.kind===`args`?s(Ct(t.detail)):t.kind===`result`&&l(wt(t.detail))}catch(e){n.signal.aborted||p(ke(e,`加载工具详情失败`))}finally{m.current===n&&(m.current=null,d(!1))}},[e.callDetailId,e.resultDetailId,y,b]);(0,W.useEffect)(()=>()=>m.current?.abort(),[]),(0,W.useEffect)(()=>{i&&(y||b)&&!u&&!f&&S()},[i,y,b,u,f,S]);let C=(0,W.useMemo)(()=>i?Z(g):``,[i,g]),w=i?_:``,T=e.toolName||r(`chat.unknownTool`,null,`未知工具`),D=(0,G.jsxs)(`span`,{className:`chat-tool-head`,children:[(0,G.jsxs)(`span`,{className:`chat-tool-name`,children:[e.agentName?`${e.agentName} · `:``,r(`chat.callTool`,{name:T,index:t,total:n},`调用工具: ${T} (${t}/${n})`)]}),(0,G.jsx)(v,{size:`small`,color:h.color,shape:`circle`,children:h.label})]});return x?(0,G.jsx)(`div`,{className:`chat-tool`,children:(0,G.jsx)(M,{className:`chat-block-collapse`,activeKey:i?[`1`]:[],onChange:e=>a(Nt(e)),children:(0,G.jsxs)(M.Panel,{itemKey:`1`,header:D,children:[i&&u&&(0,G.jsxs)(`div`,{className:`chat-tool-loading`,children:[(0,G.jsx)(E,{size:`small`}),(0,G.jsx)(`span`,{children:`正在加载工具详情…`})]}),i&&f&&(0,G.jsxs)(`div`,{className:`chat-tool-error`,children:[(0,G.jsx)(`span`,{children:f}),(0,G.jsx)(`button`,{type:`button`,className:`chat-link-btn`,onClick:()=>void S(),children:`重试`})]}),i&&C&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(jt,{type:`tertiary`,size:`small`,children:`参数`}),(0,G.jsx)(`pre`,{className:`chat-pre`,children:C})]}),i&&w&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(jt,{type:`tertiary`,size:`small`,children:`结果`}),(0,G.jsx)(`pre`,{className:`chat-pre`,children:w})]})]})})}):(0,G.jsx)(`div`,{className:`chat-tool`,children:(0,G.jsx)(`div`,{className:`chat-tool-head-row`,children:D})})}function It({block:e}){let[t,n]=(0,W.useState)(!1),r=e.tone||`info`;return(0,G.jsxs)(`div`,{className:`chat-note chat-note-${r}`,children:[(0,G.jsxs)(`div`,{className:`chat-note-head`,children:[(0,G.jsx)(`span`,{className:`chat-note-title`,children:e.title}),e.data&&(0,G.jsx)(`button`,{type:`button`,className:`chat-link-btn`,onClick:()=>n(!t),children:t?`收起 JSON`:`查看 JSON`})]}),e.message&&(0,G.jsx)(`div`,{className:`chat-note-body`,children:e.message}),t&&e.data&&(0,G.jsx)(Ee,{value:e.data,collapsed:!1,title:`事件数据`})]})}function Lt({data:e}){let{t,lang:n}=_e(),r=e=>I(Math.max(0,Math.trunc(Number(e)||0)),n),i=[[`chat.piUsageModelCalls`,e.modelCalls],[`chat.piUsagePromptTokens`,e.promptTokens],[`chat.piUsageCompletionTokens`,e.completionTokens],[`chat.piUsageTotalTokens`,e.totalTokens]],a=[[`chat.piUsageCachedTokens`,e.cachedTokens],[`chat.piUsageCacheWriteTokens`,e.cacheWriteTokens],[`chat.piUsageReasoningTokens`,e.reasoningTokens]],o=[...i,...a.filter(([,e])=>Number(e)>0)].map(([e,n])=>`${t(e)}: ${r(n)}`).join(` -`),s=Number(e.totalTokens),c=[e.agentName,t(`chat.piUsageSummaryTitle`),Number.isFinite(s)&&s>0?r(s):``].filter(Boolean).join(` · `);return(0,G.jsx)(It,{block:{title:c,message:o,data:e}})}function Rt({events:e}){return!e||!e.length?null:(0,G.jsx)(M,{className:`chat-block-collapse chat-event-log`,children:(0,G.jsx)(M.Panel,{itemKey:`1`,header:(0,G.jsxs)(`span`,{className:`chat-block-title`,children:[`🧾 原始事件 · `,e.length,` 条`]}),children:(0,G.jsx)(`pre`,{className:`chat-pre`,children:e.map((e,t)=>`${t+1}. ${JSON.stringify(e)}`).join(` -`)})})})}var zt=(0,W.memo)(function({text:e,blocks:t,events:n,streaming:r=!1,openReasoning:i=!1,isAssistant:a=!1}){let{t:o}=_e(),s=Array.isArray(t)?t:[],c=e||``,l=s.filter(e=>e.kind===`tool`).length,u=0;return(0,G.jsxs)(`div`,{className:`chat-turn-body`,children:[s.map(e=>e.kind===`reasoning`?(0,G.jsx)(Pt,{block:e,defaultOpen:i},e.id):e.kind===`tool`?(u+=1,(0,G.jsx)(Ft,{block:e,index:u,total:l},e.id)):e.kind===`iteration`?(0,G.jsx)(`div`,{className:`chat-iteration`,children:(0,G.jsx)(`span`,{className:`chat-iteration-label`,children:e.title})},e.id):e.kind===`note`?(0,G.jsx)(It,{block:e},e.id):e.kind===`usage`?(0,G.jsx)(Lt,{data:e.data},e.id):null),(0,G.jsx)(Rt,{events:n}),c.trim()&&(a&&!r?(0,G.jsx)(`section`,{className:`chat-task-summary`,"aria-label":o(`chat.taskSummary`),"data-chat-summary":!0,children:(0,G.jsxs)(`details`,{open:!0,children:[(0,G.jsx)(`summary`,{className:`chat-task-summary-title`,children:o(`chat.taskSummary`)}),(0,G.jsx)(`div`,{className:`chat-task-summary-content`,children:(0,G.jsx)(be,{content:c})})]},c.length)}):r?(0,G.jsx)(`pre`,{className:`chat-pre chat-stream-text`,children:c}):(0,G.jsx)(be,{content:c})),!c.trim()&&r&&(0,G.jsx)(`div`,{className:`chat-stream-placeholder`,children:`正在生成…`})]})}),{Paragraph:Bt,Text:Vt}=u,Ht=40,Ut=40;function Wt(e){let t=String(e||``);return t.length<=128?t:`${t.length}:${t.slice(0,64)}:${t.slice(-64)}`}function Gt(){let e=R();return(0,G.jsx)(`div`,{className:`chat-welcome`,children:(0,G.jsx)(c,{image:(0,G.jsx)(`span`,{className:`chat-welcome-mark`,"aria-hidden":`true`,children:(0,G.jsx)(he,{size:`extra-large`})}),title:e(`chat.welcomeHeading`,null,`让安全探索,从对话开始`),description:(0,G.jsx)(Bt,{type:`tertiary`,className:`chat-welcome-description`,children:e(`chat.welcomeScopeDescription`,null,`描述测试目标与授权范围,或上传相关材料,即可开始对话。`)})})})}function Kt(e,t,n){let[r,i]=(0,W.useState)(()=>Date.now());if((0,W.useEffect)(()=>{if(!n)return;let e=setInterval(()=>i(Date.now()),1e3);return()=>clearInterval(e)},[n]),!e)return``;let a=Math.max(0,Math.round(((n?r:t||e)-e)/1e3));return a<60?`${a}s`:`${Math.floor(a/60)}m${a%60}s`}var qt=(0,W.memo)(function({message:e,canDelete:t,onDeleteTurn:n}){let r=R(),i=e.role===`user`,a=e.role===`system`,o=(0,W.useMemo)(()=>At(e),[e]),s=e.createdAt?L(e.createdAt):``,c=String(e.content||``);return a?(0,G.jsx)(`div`,{className:`chat-system-row`,children:(0,G.jsx)(Vt,{type:`tertiary`,children:c})},e.id):(0,G.jsxs)(`div`,{className:`chat-msg ${i?`chat-msg-user`:`chat-msg-assistant`}`,children:[(0,G.jsx)(f,{size:`small`,color:i?`grey`:`blue`,className:`chat-avatar`,"aria-hidden":`true`,children:i?(0,G.jsx)(D,{}):`AI`}),(0,G.jsxs)(`div`,{className:`chat-bubble`,children:[(0,G.jsxs)(`div`,{className:`chat-bubble-head`,children:[(0,G.jsx)(`span`,{className:`chat-bubble-role`,children:i?r(`chat.you`,null,`我`):r(`chat.assistant`,null,`助手`)}),s&&(0,G.jsx)(`span`,{className:`chat-bubble-time`,children:s}),(0,G.jsxs)(`span`,{className:`chat-bubble-actions`,children:[!i&&c&&(0,G.jsx)(we,{text:c,size:`small`}),t&&i&&e.id&&(0,G.jsx)(P,{content:r(`chat.deleteTurnTitle`,null,`删除本轮`),children:(0,G.jsx)(x,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,G.jsx)(_,{}),"aria-label":r(`chat.deleteTurnTitle`,null,`删除本轮`),onClick:()=>n(e)})})]})]}),c||o.length>0?(0,G.jsx)(zt,{text:c,blocks:o,events:null,isAssistant:!i}):(0,G.jsx)(Vt,{type:`tertiary`,children:`—`})]})]},e.id)});function Jt({live:e}){let t=R(),n=kt[e.status]||kt.streaming,r=Kt(e.startedAt,e.endedAt,e.status===`streaming`);return(0,G.jsxs)(`div`,{className:`chat-msg chat-msg-assistant chat-msg-live`,children:[(0,G.jsx)(f,{size:`small`,color:`blue`,className:`chat-avatar`,children:`AI`}),(0,G.jsxs)(`div`,{className:`chat-bubble`,children:[(0,G.jsxs)(`div`,{className:`chat-bubble-head`,children:[(0,G.jsx)(`span`,{className:`chat-bubble-role`,children:t(`chat.assistant`,null,`助手`)}),(0,G.jsx)(v,{size:`small`,color:n.color,shape:`circle`,children:n.label}),r&&(0,G.jsx)(`span`,{className:`chat-bubble-time`,children:r}),e.statusText&&(0,G.jsx)(`span`,{className:`chat-live-status`,children:e.statusText})]}),(0,G.jsx)(zt,{isAssistant:!0,text:e.text,blocks:e.blocks,events:e.events,streaming:e.status===`streaming`,openReasoning:e.status===`streaming`}),e.error&&(0,G.jsx)(`div`,{className:`chat-live-error`,children:e.error}),e.notice&&(0,G.jsx)(`div`,{className:`chat-live-notice`,children:e.notice}),e.finalizable===!1&&(0,G.jsx)(`div`,{className:`chat-live-notice`,children:`本轮回复未通过最终化校验,内容可能不完整。`})]})]})}function Yt({conversationId:e,messages:t,live:n,loading:r,error:i,onRetry:a,canDelete:o,onDeleteTurn:s}){let c=R(),l=(0,W.useRef)(null),u=(0,W.useRef)(!0),d=(0,W.useRef)(``),[f,p]=(0,W.useState)(!0),[m,h]=(0,W.useState)(Ht),g=Array.isArray(t)?t:[],_=Math.max(0,g.length-m),v=(0,W.useMemo)(()=>_>0?g.slice(_):g,[g,_]),y=g[g.length-1],b=Wt(y?.content),S=`${g.length}:${y?.id||``}:${b}:${y?.processDetails?.length||0}`,C=n?n.status!==`streaming`&&n.text.trim()?`live:${e}:${n.messageId||n.id}:${Wt(n.text)}`:``:!r&&y?.role===`assistant`&&String(y.content||``).trim()?`history:${e}:${y.id}:${b}`:``,w=(0,W.useMemo)(()=>{if(!n)return S;let e=n.blocks.map(e=>`${e.kind}:${e.id}:${e.text?e.text.length:0}:${e.status||``}`).join(`|`);return`${S}#${n.id}#${n.status}#${n.text.length}#${e}`},[S,n]),T=(0,W.useCallback)((e=!1)=>{let t=l.current;t&&t.scrollTo({top:t.scrollHeight,behavior:e?`smooth`:`auto`})},[]),D=(0,W.useCallback)((e=!1)=>{let t=l.current;if(!t)return;let n=t.querySelectorAll(`.chat-msg`),r=n[n.length-1]?.querySelector(`[data-chat-summary]`);if(!r){T(e);return}let i=r.getBoundingClientRect().top-t.getBoundingClientRect().top+t.scrollTop-12;t.scrollTo({top:Math.max(0,i),behavior:e?`smooth`:`auto`})},[T]),O=(0,W.useCallback)(()=>{let e=l.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<120;u.current=t,p(t)},[]);return(0,W.useEffect)(()=>{u.current=!0,d.current=``,p(!0),h(Ht);let e=setTimeout(()=>D(!1),30);return()=>clearTimeout(e)},[e,D]),(0,W.useEffect)(()=>{n?.id&&(u.current=!0)},[n?.id]),(0,W.useEffect)(()=>{if(r)return;let e=C&&d.current!==C;e&&(d.current=C),(e||u.current)&&D(!1)},[w,C,r,D]),e||n||g.length?(0,G.jsxs)(`div`,{className:`chat-message-wrap`,children:[(0,G.jsxs)(`div`,{className:`chat-messages`,ref:l,onScroll:O,children:[(0,G.jsx)(H,{error:i,onRetry:a}),r&&(0,G.jsx)(`div`,{className:`chat-loading`,children:(0,G.jsx)(E,{size:`middle`})}),!r&&!g.length&&!n&&(0,G.jsx)(Gt,{}),!r&&_>0&&(0,G.jsxs)(`div`,{className:`chat-history-more`,children:[(0,G.jsx)(x,{size:`small`,theme:`light`,onClick:()=>h(e=>e+Ut),children:c(`chat.loadEarlierMessages`,{count:Math.min(Ut,_)},`显示更早的 ${Math.min(Ut,_)} 条消息`)}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,onClick:()=>h(g.length),children:c(`chat.showAllMessages`,{total:g.length},`显示全部(共 ${g.length} 条)`)})]}),v.map(e=>(0,G.jsx)(qt,{message:e,canDelete:o,onDeleteTurn:s},e.id)),n&&(0,G.jsx)(Jt,{live:n}),i&&!r&&(0,G.jsx)(x,{icon:(0,G.jsx)(de,{}),theme:`borderless`,onClick:a,className:`chat-retry-inline`,children:c(`common.refresh`,null,`刷新`)})]}),!f&&(0,G.jsx)(x,{className:`chat-scroll-bottom`,icon:(0,G.jsx)(ce,{}),size:`small`,theme:`solid`,onClick:()=>{u.current=!0,p(!0),T(!0)},children:c(`chat.returnToLatest`,null,`回到底部`)})]}):(0,G.jsx)(`div`,{className:`chat-message-wrap`,children:(0,G.jsx)(`div`,{className:`chat-messages`,ref:l,children:(0,G.jsx)(Gt,{})})})}var{Text:Xt}=u,Zt=[`single`,`deep`,`plan_execute`,`supervisor`],Qt=`__create_project__`;function $t({value:e,onChange:t,onSend:r,onStop:i,canStop:a,sending:s,checkingRun:c,canWrite:l,canExecute:u,mode:f,onModeChange:p,projectId:g,onProjectChange:_,onCreateProject:y,projects:b,projectDisabled:C,role:w,onRoleChange:T,roles:E,roleDisabled:O,model:k,canReadConfig:ee,onOpenHitl:j,attachments:re,onPickFiles:ie,onRemoveAttachment:ae,uploading:M}){let N=R(),ce=n(),le=(0,W.useRef)(null),de=(0,W.useId)(),F=(0,W.useId)(),fe=(0,W.useId)(),pe=Array.isArray(re)?re:[],he=pe.some(e=>String(e?.mimeType||``).startsWith(`image/`)||/\.(?:png|jpe?g|gif|webp|bmp)$/i.test(String(e?.fileName||``))),I=(0,W.useMemo)(()=>[{value:`single`,title:N(`chat.agentModePiSingle`,null,`单代理`),description:N(`chat.agentModePiSingleHint`,null,`使用设置中选择的 Pi 或兼容运行时执行单代理任务`)},{value:`deep`,title:N(`chat.agentModeDeep`,null,`Deep(DeepAgent)`),description:N(`chat.agentModeDeepHint`,null,`Pi 多代理,适合复杂安全测试、多阶段 task 子代理委派与汇总`)},{value:`plan_execute`,title:N(`chat.agentModePlanExecuteLabel`,null,`Plan-Execute`),description:N(`chat.agentModePlanExecuteHint`,null,`规划 → 执行 → 重规划(单执行器带工具)`)},{value:`supervisor`,title:N(`chat.agentModeSupervisorLabel`,null,`Supervisor(专家路由)`),description:N(`chat.agentModeSupervisorHint`,null,`专家路由场景:监督者通过 transfer 动态分派多个专业子代理`)}].map(({value:e,title:t,description:n})=>({value:e,title:t,label:(0,G.jsxs)(`span`,{className:`chat-mode-option`,children:[(0,G.jsx)(`span`,{children:t}),(0,G.jsx)(`span`,{className:`chat-mode-option-description`,children:n})]})})),[N]),L=[{value:``,label:N(`chat.defaultWorkspace`,null,`默认工作区`)},...Re(b,N,{currentId:g,disableCurrentArchived:!0,fallbackLabel:N(`chat.boundProject`,null,`已绑定项目`)})];g&&!L.some(e=>e.value===g)&&L.push({value:g,label:N(`chat.boundProject`,null,`已绑定项目`)}),y&&L.push({value:Qt,label:`+ ${N(`projects.newProject`,null,`新建项目`)}`});let ge=(0,W.useMemo)(()=>{let e=(Array.isArray(E)?E:[]).filter(e=>e?.name),t=e.filter(e=>e.enabled!==!1&&e.name!==`默认`).sort((e,t)=>e.name.localeCompare(t.name,`zh-CN`)),n=e.find(e=>e.name===`默认`),r=e=>({value:e.name===`默认`?``:e.name,name:e.name===`默认`?N(`chat.defaultRole`,null,`默认`):e.name,icon:e.icon||``,description:e.description||``,label:(0,G.jsxs)(`span`,{className:`chat-role-option`,children:[(0,G.jsxs)(`span`,{className:`chat-role-option-title`,children:[e.icon?(0,G.jsx)(`span`,{className:`chat-role-icon`,"aria-hidden":`true`,children:e.icon}):null,(0,G.jsx)(`span`,{children:e.name===`默认`?N(`chat.defaultRole`,null,`默认`):e.name})]}),e.description?(0,G.jsx)(`span`,{className:`chat-role-option-description`,children:e.description}):null]})}),i=[r({name:`默认`,icon:n?.icon||``,description:n?.description||``})],a=new Set([``]);for(let e of t)a.has(e.name)||(a.add(e.name),i.push(r(e)));if(w&&!a.has(w)){let t=e.find(e=>e.name===w);i.push(r(t||{name:w,icon:``,description:``}))}return i},[w,E,N]),z=ge.find(e=>e.value===(w||``))||ge[0],_e=Number(M)||pe.filter(e=>e.uploading).length,B=!l||!u,ve=s||c,ye=k.channel||k.config.data?.default_channel,V=ye?U(ye,k.config.data?.channels?.[ye]):N(`chat.aiChannelDefaultShort`,null,`默认通道`),be=k.overrideBlocked?Ye(N,`default`,``):Ye(N,k.mode,k.effort);return(0,G.jsxs)(`div`,{className:`chat-composer`,children:[B&&(0,G.jsx)(o,{type:`warning`,bordered:!0,closeIcon:null,className:`chat-composer-banner`,description:l?N(`chat.noExecutePermission`,null,`当前账号没有智能体执行权限(agent:execute),发送已禁用。`):N(`chat.noWritePermission`,null,`当前账号没有对话写入权限(chat:write),发送已禁用。`)}),(0,G.jsx)(`div`,{className:`chat-composer-shell`,children:(0,G.jsxs)(`div`,{className:`chat-composer-box`,children:[(0,G.jsxs)(`div`,{className:`chat-composer-context`,children:[(0,G.jsx)(`span`,{id:de,hidden:!0,children:N(`chat.agentModeSelectAria`,null,`选择对话执行模式`)}),(0,G.jsx)(me,{value:f,optionList:I,renderSelectedItem:e=>(0,G.jsx)(`span`,{title:e.title,children:e.title}),onChange:p,prefix:(0,G.jsx)(m,{"aria-hidden":`true`}),className:`chat-context-select chat-composer-mode`,dropdownClassName:`chat-mode-dropdown`,size:`small`,position:`topLeft`,"aria-labelledby":de,disabled:ve||B}),(0,G.jsx)(`span`,{className:`chat-context-divider`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{id:F,hidden:!0,children:N(`chat.chooseWorkspace`,null,`选择会话工作区`)}),(0,G.jsx)(me,{value:g,optionList:L,onChange:e=>{e===Qt?y?.():_(e)},prefix:(0,G.jsx)(oe,{"aria-hidden":`true`}),className:`chat-context-select chat-composer-project`,dropdownClassName:`chat-project-dropdown`,dropdownMatchSelectWidth:!1,position:`topLeft`,size:`small`,renderSelectedItem:e=>(0,G.jsx)(`span`,{title:e.label,children:e.label}),"aria-labelledby":F,disabled:ve||C||!l}),T&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`chat-context-divider`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{id:fe,hidden:!0,children:N(`chat.selectRole`,null,`选择角色`)}),(0,G.jsx)(me,{value:w||``,optionList:ge,onChange:T,prefix:z?.icon?(0,G.jsx)(`span`,{className:`chat-role-icon`,"aria-hidden":`true`,children:z.icon}):(0,G.jsx)(D,{"aria-hidden":`true`}),className:`chat-context-select chat-composer-role`,dropdownClassName:`chat-role-dropdown`,dropdownMatchSelectWidth:!1,position:`topLeft`,size:`small`,renderSelectedItem:e=>(0,G.jsx)(`span`,{title:e.description||e.name,children:e.name}),"aria-labelledby":fe,disabled:ve||O||!l})]})]}),(0,G.jsx)(`input`,{ref:le,type:`file`,multiple:!0,hidden:!0,onChange:e=>{e.target.files?.length&&ie(Array.from(e.target.files)),e.target.value=``}}),pe.length>0&&(0,G.jsx)(`div`,{className:`chat-file-list`,children:pe.map(e=>(0,G.jsxs)(v,{className:`chat-file-chip ${e.error?`is-error`:``} ${e.uploading?`is-uploading`:``}`,size:`large`,color:e.error?`red`:e.uploading?`amber`:`blue`,closable:!0,onClose:()=>ae(e.id),children:[(0,G.jsx)(se,{size:`small`}),(0,G.jsx)(`span`,{className:`chat-file-name`,title:e.fileName,children:e.fileName}),(0,G.jsx)(`span`,{className:`chat-file-state`,children:e.uploading?`上传中…`:e.error?`上传失败`:`已上传`})]},e.id))}),he&&ee&&!k.config.loading&&k.vision?.nativeMode!==`enabled`&&(0,G.jsxs)(`div`,{className:`chat-image-vision-tip${k.vision?.ready?` is-ready`:``}`,children:[(0,G.jsx)(`span`,{children:k.vision?.ready?`已启用独立视觉模型(${k.vision.model}),若当前模型不支持图片输入将自动通过 analyze_image 识图。`:`若当前对话模型不支持识别图片,可开启独立「视觉分析模型」代为识图(或为支持识图的通道启用原生图片输入)。`}),(0,G.jsx)(`button`,{type:`button`,className:`chat-vision-entry-link`,onClick:()=>ce(`/settings?section=models&focus=vision`),children:k.vision?.ready?`切换视觉模型`:`去开启视觉模型`})]}),(0,G.jsx)(S,{className:`chat-textarea`,borderless:!0,value:e,onChange:t,onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent?.isComposing||(e.preventDefault(),ve||B||O||_e>0||r())},disabled:B,autosize:{minRows:2,maxRows:8},"aria-label":N(`chat.composerLabel`,null,`对话内容`),placeholder:N(`chat.composerPlaceholder`,null,`描述目标、授权范围与需求,或附上相关材料…`)}),(0,G.jsxs)(`div`,{className:`chat-composer-toolbar`,children:[(0,G.jsxs)(`div`,{className:`chat-composer-controls`,children:[(0,G.jsx)(P,{content:N(`chat.selectFile`,null,`选择附件`),children:(0,G.jsx)(x,{icon:(0,G.jsx)(ne,{}),theme:`borderless`,type:`tertiary`,"aria-label":N(`chat.attachmentsLabel`,null,`附件`),disabled:B,onClick:()=>le.current?.click()})}),(0,G.jsx)(x,{icon:(0,G.jsx)(te,{}),theme:`borderless`,type:`tertiary`,className:`chat-composer-hitl`,"aria-label":N(`chat.hitlTitle`,null,`人机协同`),disabled:!j,onClick:j,children:N(`chat.hitlTitle`,null,`人机协同`)})]}),(0,G.jsxs)(`div`,{className:`chat-composer-submit`,children:[(0,G.jsx)(h,{trigger:`click`,position:`topRight`,className:`chat-model-popover`,condition:!ve,content:(0,G.jsx)(lt,{model:k,busy:ve||B,canReadConfig:ee}),children:(0,G.jsxs)(x,{theme:`borderless`,type:`tertiary`,className:`chat-composer-model`,"aria-label":N(`chat.modelSettingsAria`,null,`选择 AI 通道、模型与推理设置`),title:`${V} · ${be}`,disabled:ve,children:[(0,G.jsx)(`span`,{className:`chat-composer-model-name`,children:V}),(0,G.jsx)(`span`,{className:`chat-composer-effort`,children:be}),(0,G.jsx)(d,{size:`small`})]})}),s?(0,G.jsx)(x,{type:`danger`,className:`chat-composer-send`,icon:(0,G.jsx)(ue,{}),"aria-label":N(`chat.stop`,null,`停止`),onClick:i,disabled:!a}):(0,G.jsx)(P,{content:N(`chat.sendHint`,null,`Enter 发送 · Shift+Enter 换行`),children:(0,G.jsx)(x,{theme:`solid`,className:`chat-composer-send`,icon:(0,G.jsx)(A,{}),"aria-label":N(`chat.send`,null,`发送`),disabled:B||c||O||_e>0,onClick:r})})]})]}),_e>0&&(0,G.jsx)(Xt,{type:`tertiary`,size:`small`,role:`status`,children:N(`chat.waitingAttachmentsUpload`,null,`附件上传中…`)})]})})]})}var{Text:en}=u,tn={approval:`仅审批`,feedback:`审批并反馈`,followup:`审批并追问`,review_edit:`审查编辑`};function nn(e){if(!e)return null;let t=e.payload;if(typeof t==`string`)try{t=JSON.parse(t)}catch{t=null}t&&typeof t==`object`||(t={});let n=t.argumentsObj&&typeof t.argumentsObj==`object`?t.argumentsObj:t.arguments||null;return{...e,payload:t,interruptId:String(e.id||e.interruptId||``),toolName:String(e.toolName||t.toolName||`未知工具`),mode:String(e.mode||t.mode||`approval`).toLowerCase(),args:n}}function rn({item:e,busy:t,readOnly:n,onApprove:r,onReject:i,onDismiss:o}){let s=R(),c=(0,W.useMemo)(()=>nn(e),[e]),[u,d]=(0,W.useState)(``);if(!c)return null;let f=Z(c.args,4e3),m=tn[c.mode]||c.mode,h=n||t||!c.interruptId;return(0,G.jsxs)(l,{className:`chat-hitl-card`,bordered:!0,title:(0,G.jsxs)(`span`,{className:`chat-hitl-title`,children:[(0,G.jsx)(`span`,{children:s(`chat.hitlTitle`,null,`人工审批`)}),(0,G.jsx)(v,{size:`small`,color:`orange`,shape:`circle`,children:m}),(0,G.jsx)(`span`,{className:`chat-hitl-tool`,children:c.toolName})]}),headerExtraContent:(0,G.jsx)(en,{type:`tertiary`,size:`small`,children:c.createdAt?L(c.createdAt):``}),children:[(0,G.jsxs)(`div`,{className:`chat-hitl-meta`,children:[c.reviewer&&(0,G.jsxs)(en,{type:`tertiary`,size:`small`,children:[`审批人:`,c.reviewer===`audit_agent`?`审计代理`:`人工`]}),c.expiresAt&&(0,G.jsxs)(en,{type:`tertiary`,size:`small`,children:[`到期:`,L(c.expiresAt)]}),c.conversationId&&(0,G.jsxs)(en,{type:`tertiary`,size:`small`,children:[`会话:`,String(c.conversationId).slice(0,8)]})]}),f&&(0,G.jsx)(M,{className:`chat-block-collapse`,children:(0,G.jsx)(M.Panel,{itemKey:`1`,header:(0,G.jsx)(`span`,{className:`chat-block-title`,children:`调用参数`}),children:(0,G.jsx)(`pre`,{className:`chat-pre`,children:f})})}),(0,G.jsxs)(`div`,{className:`chat-hitl-actions`,children:[(0,G.jsx)(C,{size:`small`,placeholder:s(`chat.hitlComment`,null,`审批备注(拒绝时建议填写原因)`),disabled:n,value:u,onChange:d,className:`chat-hitl-comment`}),(0,G.jsxs)(p,{children:[(0,G.jsx)(x,{theme:`solid`,size:`small`,icon:(0,G.jsx)(a,{}),disabled:h,onClick:()=>r(c,u),children:s(`chat.hitlApprove`,null,`批准`)}),(0,G.jsx)(x,{type:`danger`,size:`small`,icon:(0,G.jsx)(T,{}),disabled:h,onClick:()=>i(c,u),children:s(`chat.hitlReject`,null,`拒绝`)}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,disabled:h,onClick:()=>o(c),children:s(`chat.hitlDismiss`,null,`忽略`)})]})]})]})}var{Text:an}=u;function on({items:e,busyId:t,readOnly:n,onRefresh:r,onDecide:i,onDismiss:a}){let o=R(),s=Array.isArray(e)?e:[];return s.length?(0,G.jsxs)(`div`,{className:`chat-hitl-dock`,children:[(0,G.jsxs)(`div`,{className:`chat-hitl-dock-head`,children:[(0,G.jsx)(an,{strong:!0,children:o(`chat.pendingApprovals`,{count:s.length},`待审批 ${s.length}`)}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,icon:(0,G.jsx)(de,{}),onClick:r})]}),s.map(e=>(0,G.jsx)(rn,{item:e,readOnly:n,busy:t===String(e.id||e.interruptId),onApprove:(e,t)=>i(e,`approve`,t),onReject:(e,t)=>i(e,`reject`,t),onDismiss:a},e.id||e.interruptId))]}):null}var{Text:sn}=u,cn={pending:{color:`grey`,label:`待处理`},in_progress:{color:`blue`,label:`进行中`},completed:{color:`green`,label:`已完成`},blocked:{color:`orange`,label:`阻塞`},deleted:{color:`grey`,label:`已删除`}};function ln({plan:e,loading:t,onRefresh:n}){let r=R(),i=Array.isArray(e?.tasks)?e.tasks.filter(e=>String(e.status||``).toLowerCase()!==`deleted`):[],a=Number(e?.total)||i.length,o=Number(e?.completed)||i.filter(e=>e.status===`completed`).length,s=a?Math.round(o/a*100):0;return(0,G.jsxs)(`div`,{className:`chat-plan`,children:[(0,G.jsxs)(`div`,{className:`chat-plan-toolbar`,children:[(0,G.jsx)(sn,{type:`tertiary`,size:`small`,children:e?.running?r(`chat.planRunning`,null,`任务执行中`):r(`chat.planIdle`,null,`当前没有运行中的任务`)}),(0,G.jsx)(x,{size:`small`,icon:(0,G.jsx)(de,{}),onClick:n,loading:t,children:r(`common.refresh`,null,`刷新`)})]}),(0,G.jsx)(re,{percent:s,showInfo:!0}),(0,G.jsx)(sn,{type:`tertiary`,size:`small`,children:r(`chat.planSummary`,{total:a,done:o},`共 ${a} 项,已完成 ${o} 项`)}),!i.length&&(0,G.jsx)(c,{title:r(`chat.planEmpty`,null,`暂无执行计划`),description:r(`chat.planEmptyHint`,null,`代理调用任务工具后,这里会显示任务看板。`),style:{padding:24}}),(0,G.jsx)(`div`,{className:`chat-plan-list`,children:i.map((e,t)=>{let n=String(e.status||`pending`).toLowerCase(),r=cn[n]||cn.pending;return(0,G.jsxs)(`div`,{className:`chat-plan-item ${n===`in_progress`?`is-active`:``}`,children:[(0,G.jsxs)(`div`,{className:`chat-plan-item-head`,children:[(0,G.jsx)(`span`,{className:`chat-plan-index`,children:t+1}),(0,G.jsx)(`span`,{className:`chat-plan-subject`,children:e.subject||e.activeForm||`—`}),(0,G.jsx)(v,{size:`small`,color:r.color,shape:`circle`,children:r.label})]}),e.description&&(0,G.jsx)(`div`,{className:`chat-plan-desc`,children:e.description})]},e.id||t)})})]})}function un({visible:e,onClose:t,plan:n,loading:r,onRefresh:i}){let a=R()(`chat.planTasks`,null,`执行计划`);return(0,G.jsx)(le,{title:a,"aria-label":a,visible:e,onCancel:t,width:`min(100%, 560px)`,placement:`right`,children:(0,G.jsx)(ln,{plan:n,loading:r,onRefresh:i})})}function dn({conversationRef:e,bindConversation:t,requestDetailReload:n,onTaskStarted:r,onSettled:i,onHitlEvent:a,onPlanTool:o,t:s}){let[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)([]),m=(0,W.useRef)(null),h=(0,W.useRef)(null),g=(0,W.useRef)(null),_=(0,W.useRef)(null),v=(0,W.useCallback)(()=>{_.current&&(clearTimeout(_.current),_.current=null)},[]),y=(0,W.useCallback)((e=!1)=>{let t=()=>{g.current=null,m.current&&l({...m.current})};e?(g.current&&(clearTimeout(g.current),g.current=null),t()):g.current||(g.current=setTimeout(t,80))},[]),b=(0,W.useCallback)(t=>{if(!t||t.markedFinished||h.current!==t)return;t.markedFinished=!0,v(),t.live.status===`streaming`&&(t.live.status=t.live.error?`error`:`done`,t.live.endedAt=Date.now()),y(!0),i?.(),d(!1),p(t.live.events.slice(-80));let r=t.live.conversationId||e.current;r?Promise.resolve(n?.(r,{silent:!0})).then(e=>{h.current===t&&e&&(h.current=null,m.current=null,l(null))}):(h.current=null,m.current=null,l(null))},[v,e,y,i,n]);return{live:c,sending:u,lastEvents:f,send:(0,W.useCallback)(({message:n,attachments:i,mode:c,projectId:u,role:f,aiChannelId:g,reasoning:x,hitl:S,requireHumanApproval:C})=>{v();let w={live:yt({conversationId:e.current}),markedFinished:!1,stopRequested:!1,abort:null};h.current=w,m.current=w.live,l({...w.live}),d(!0),p([]),_.current=setTimeout(()=>{_.current=null,!w.markedFinished&&h.current===w&&r?.()},200);let T=c!==`single`,E={message:n,conversationId:e.current||``,aiChannelId:g,reasoning:x,hitl:S,requireHumanApproval:C||void 0};!e.current&&u&&(E.projectId=u),f&&(E.role=f),T&&(E.orchestration=c),Array.isArray(i)&&i.length&&(E.attachments=i.map(e=>({fileName:e.fileName,mimeType:e.mimeType||``,serverPath:e.serverPath}))),w.abort=ve(T?`/multi-agent/stream`:`/agent/stream`,E,{onEvent(n){if(w.markedFinished||h.current!==w)return;Ot(w.live,n);let r=n?.type;if(r===`conversation`&&n?.data?.conversationId){let r=String(n.data.conversationId);w.live.conversationId=r,e.current!==r&&t?.(r)}(r===`hitl_interrupt`||r===`hitl_resumed`||r===`hitl_rejected`)&&a?.(),(r===`tool_call`||r===`tool_result`)&&mt.has(String(n?.data?.toolName||``).toLowerCase())&&o?.(),r===`done`||r===`error`||r===`cancelled`?b(w):y()},onError(e){w.markedFinished||h.current!==w||(w.live.status=`error`,w.live.error=ke(e,s(`chat.streamFailed`,null,`流式连接失败`)),w.live.endedAt=Date.now(),b(w))},onClose(){w.markedFinished||h.current!==w||(w.live.status=`disconnected`,w.live.endedAt=Date.now(),w.stopRequested||(w.live.notice=s(`chat.streamEndedWithoutDone`,null,`连接提前结束,未收到任务完成信号。任务可能仍在后端执行。`),B(w.live.notice)),b(w))}})},[t,v,e,b,y,a,o,r,s]),stop:(0,W.useCallback)(async(t=``)=>{let r=h.current,i=typeof t==`string`?t.trim():``,a=r&&!r.markedFinished&&(r.live?.conversationId||e.current)||``,o=i||e.current||a||``,c=!(!r||r.markedFinished||i&&o!==a);if(o)try{await z.post(`/agent-loop/cancel`,{conversationId:o}),c&&r&&(r.stopRequested=!0),De(s(`chat.stopRequested`,null,`已请求停止任务`))}catch(e){B(ke(e,s(`chat.stopFailed`,null,`停止请求失败`)))}c&&r?.abort?.(),setTimeout(()=>{o&&e.current===o&&n?.(o,{silent:!0,force:!0})},900)},[e,n,s]),reset:(0,W.useCallback)(()=>{v();let e=h.current;e&&!e.markedFinished&&e.abort?.(),h.current=null,m.current=null,g.current&&(clearTimeout(g.current),g.current=null),l(null),d(!1),p([])},[]),isStreaming:(0,W.useCallback)(e=>{let t=h.current;return!!(t&&!t.markedFinished&&e&&t.live.conversationId===e)},[])}}function fn({t:e,conversationRef:t,newProjectId:n,canWrite:r,reloadList:i,requestDetailReload:a,navigate:o,onSelectionCleared:s}){return{createConversation:(0,W.useCallback)(async()=>{if(r)try{let t=(await z.post(`/conversations`,{title:e(`chat.newChat`,null,`新对话`),projectId:n||void 0}))?.id;i(),t&&o({conversation:t}),De(e(`chat.created`,null,`已创建对话`))}catch(t){V(t,e(`chat.createFailed`,null,`创建对话失败`))}},[r,o,n,i,e]),renameConversation:(0,W.useCallback)(async(n,r)=>{try{await z.put(`/conversations/${encodeURIComponent(n)}`,{title:r}),De(e(`chat.renamed`,null,`已重命名`)),i(),n===t.current&&a(n,{silent:!0})}catch(t){V(t,e(`chat.renameFailed`,null,`重命名失败`))}},[t,i,a,e]),togglePin:(0,W.useCallback)(async t=>{try{await z.put(`/conversations/${encodeURIComponent(t.id)}/pinned`,{pinned:!t.pinned}),i()}catch(t){V(t,e(`chat.pinFailed`,null,`置顶操作失败`))}},[i,e]),deleteConversation:(0,W.useCallback)(async n=>{try{await z.del(`/conversations/${encodeURIComponent(n.id)}`),De(e(`chat.deleted`,null,`已删除对话`)),n.id===t.current&&(s(),o({},{replace:!0})),i()}catch(t){V(t,e(`chat.deleteFailed`,null,`删除对话失败`))}},[t,o,s,i,e]),batchDelete:(0,W.useCallback)(async n=>{let r=(await Promise.allSettled(n.map(e=>z.del(`/conversations/${encodeURIComponent(e)}`)))).filter(e=>e.status===`rejected`).length;r?B(e(`chat.batchDeletePartial`,{failed:r},`有 ${r} 个对话删除失败`)):De(e(`chat.batchDeleted`,{count:n.length},`已删除 ${n.length} 个对话`)),n.includes(t.current)&&(s(),o({},{replace:!0})),i()},[t,o,s,i,e]),deleteTurn:(0,W.useCallback)(n=>{let r=t.current;r&&n?.id&&Oe({title:e(`chat.deleteTurnTitle`,null,`删除本轮`),content:e(`chat.deleteTurnConfirm`,null,`将删除该轮提问与全部回答,删除后不可恢复。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await z.post(`/conversations/${encodeURIComponent(r)}/delete-turn`,{messageId:n.id}),De(e(`chat.turnDeleted`,null,`已删除该轮`)),await a(r,{silent:!0}),i()}catch(t){V(t,e(`chat.deleteTurnFailed`,null,`删除轮次失败`))}}})},[t,i,a,e])}}var{Text:pn}=u,mn=20,hn=`__none__`,gn=`csai-chat-agent-mode`,_n=`csai-chat-role`;function vn(e){let t=typeof e==`string`?e.trim():``;return!t||t===`默认`?``:t}var yn={tasks:[],total:0,completed:0,activeStep:0,running:!1},bn={conversation:null,messages:[],loading:!1,error:null};function xn(e){let[t,n]=(0,W.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(e).matches);return(0,W.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(e),r=e=>n(e.matches);return n(t.matches),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function Sn(){let e=R(),{hasPermission:t}=ge(),n=t(`chat:write`),r=t(`project:write`),a=t(`agent:execute`),o=t(`chat:delete`),s=t(`tasks:read`),c=t(`tasks:write`),l=t(`hitl:read`),u=t(`hitl:write`),d=t(`config:read`),f=t(`roles:read`),[p,m]=i(),h=p.get(`conversation`)||``,g=(0,W.useRef)(h),_=(0,W.useRef)(null);(0,W.useLayoutEffect)(()=>{g.current=h},[h]);let[v,y]=(0,W.useState)(``),b=Ce(v,350),[S,C]=(0,W.useState)(``),[w,T]=(0,W.useState)(hn),[E,D]=(0,W.useState)(!0),[O,k]=(0,W.useState)(1),[ee,te]=(0,W.useState)(``),[A,j]=(0,W.useState)(!1),[ne,ie]=(0,W.useState)(!1),[ae,oe]=xe(gn,`single`),N=Zt.includes(ae)?ae:`single`,[se,ce]=xe(_n,``),[P,ue]=(0,W.useState)(()=>new Map),de=(0,W.useRef)(``),F=Qe(d),[fe,pe]=(0,W.useState)(!1),[me,he]=(0,W.useState)(null),[I,L]=(0,W.useState)(bn),[_e,ve]=(0,W.useState)(()=>new Map),{draft:be=``,attachments:Se=[]}=_e.get(h)||{},H=(0,W.useCallback)((e,t)=>{ve(n=>{let r=new Map(n);return r.set(e,t(n.get(e)||{})),r})},[]),we=e=>H(h,t=>({...t,draft:e})),[Ee,Oe]=(0,W.useState)(null),ke=l&&Ee?.id===h?Ee.items:[],[Fe,Ie]=(0,W.useState)(``),[U,Le]=(0,W.useState)(yn),[Re,Be]=(0,W.useState)(!1),[Ve,He]=(0,W.useState)(!1),[We,Ge]=(0,W.useState)(!1),Ke=xn(`(max-width: 900px)`),Je=(0,W.useRef)(0),K=(0,W.useRef)(null),Ye=(0,W.useRef)({id:``,active:!1}),Xe=(0,W.useRef)(0),Ze=(0,W.useRef)(0),[$e,et]=(0,W.useState)(()=>new Set),tt=ye(async({signal:e}={})=>{let t=await z.get(`/agent-loop/tasks`,null,{signal:e}),n=Array.isArray(t?.tasks)?t.tasks.filter(Boolean):[];return{checkedId:h,tasks:n}},[h,s],{skip:!s}),nt=(0,W.useRef)(tt.reload);(0,W.useEffect)(()=>{nt.current=tt.reload},[tt.reload]);let rt=(0,W.useMemo)(()=>s&&Array.isArray(tt.data?.tasks)?tt.data.tasks:[],[tt.data,s]),q=!!(s&&h&&rt.some(e=>e.conversationId===h&&!ze.has(String(e.status||``).toLowerCase()))),it=!!(s&&h&&tt.data?.checkedId!==h&&!tt.error),at=(0,W.useRef)(null),J=ye(async({signal:e}={})=>({...await z.get(`/conversations`,{limit:mn,offset:(O-1)*mn,search:b||void 0,project_id:w,group_by_project:1},{signal:e}),projectGroup:w,page:O,search:b}),[O,b,w]),ot=(0,W.useRef)(J.reload);(0,W.useEffect)(()=>{ot.current=J.reload},[J.reload]);let st=ye(({signal:e}={})=>z.get(`/projects`,{limit:200},{signal:e}),[]),ct=ye(({signal:e}={})=>z.get(`/roles`,null,{signal:e}),[f],{skip:!f}),lt=(0,W.useMemo)(()=>Array.isArray(st.data?.projects)?st.data.projects:[],[st.data]),dt=(0,W.useMemo)(()=>(Array.isArray(ct.data?.roles)?ct.data.roles:[]).filter(e=>e&&String(e.name||``).trim()).map(e=>({name:String(e.name).trim(),description:String(e.description||``),icon:String(e.icon||``),enabled:e.enabled!==!1})),[ct.data]),ft=e=>{ie(!1),e?.id&&(st.setData(t=>({...t,projects:[e,...t?.projects||[]]})),Dt(e.id))},mt=Array.isArray(J.data?.projectGroups)?J.data.projectGroups:[],ht=J.data?.projectGroup===w&&J.data?.search===b,gt=ht&&J.data?.page===O,_t=gt&&Array.isArray(J.data.conversations)?J.data.conversations:[],Y=ht&&J.data.total||0;(0,W.useEffect)(()=>{if(!gt)return;let e=Math.max(1,Math.ceil(Y/mn));O>e&&k(e)},[gt,Y,O]);let vt=(0,W.useCallback)(e=>{T(e),D(!0),k(1)},[]),X=(0,W.useCallback)(async(e,{silent:t=!1,force:n=!1}={})=>{if(!e)return K.current?.abort(),K.current=null,Ye.current={id:``,active:!1},L(bn),null;if(t&&!n&&Ye.current.active&&Ye.current.id===e)return null;K.current?.abort();let r=new AbortController;K.current=r,Ye.current={id:e,active:!0};let i=++Je.current;t||L(e=>({...e,loading:!0,error:null}));try{let t=await z.get(`/conversations/${encodeURIComponent(e)}`,{include_process_details:`summary`},{signal:r.signal});return r.signal.aborted||i!==Je.current||g.current!==e?null:(L({conversation:t||null,messages:Array.isArray(t?.messages)?t.messages:[],loading:!1,error:null}),t)}catch(t){return r.signal.aborted||i===Je.current&&g.current===e&&L(e=>({...e,loading:!1,error:t})),null}finally{K.current===r&&(K.current=null,Ye.current={id:``,active:!1})}},[]);(0,W.useEffect)(()=>()=>{K.current?.abort(),K.current=null,Ye.current={id:``,active:!1}},[]);let Z=(0,W.useCallback)(async()=>{let e=g.current,t=++Xe.current;if(e&&l)try{let n=await z.get(`/hitl/pending`,{conversationId:e,pageSize:50});if(t!==Xe.current||g.current!==e)return;let r=(Array.isArray(n?.items)?n.items:[]).filter(t=>!t.conversationId||t.conversationId===e);Oe({id:e,items:r})}catch{}},[l]),yt=(0,W.useCallback)(async()=>{let e=g.current;if(!e){Le(yn);return}let t=++Ze.current;Be(!0);try{let n=await z.get(`/conversations/${encodeURIComponent(e)}/plan-tasks`);t===Ze.current&&g.current===e&&Le(n&&typeof n==`object`?n:yn)}catch{}finally{t===Ze.current&&g.current===e&&Be(!1)}},[]),Q=dn({conversationRef:g,bindConversation:(0,W.useCallback)(e=>{he(null),_.current=e,g.current=e,ue(t=>{if(t.has(e))return t;let n=new Map(t);return n.set(e,de.current),n}),m({conversation:e},{replace:!0}),ot.current?.({silent:!0})},[m]),requestDetailReload:X,onTaskStarted:(0,W.useCallback)(()=>{nt.current?.({silent:!0,force:!0})},[]),onSettled:(0,W.useCallback)(()=>{nt.current?.({silent:!0,force:!0}),ot.current?.({silent:!0}),Z(),yt()},[Z,yt]),onHitlEvent:Z,onPlanTool:yt,t:e}),{live:bt,sending:$,lastEvents:xt,reset:St,isStreaming:Ct}=Q;(0,W.useEffect)(()=>{let e=h&&_.current===h;_.current=null,e||Ct(h)||(St(),K.current?.abort(),K.current=null,Ye.current={id:``,active:!1},Je.current++,Xe.current++,Ze.current++,L(bn),Oe(null),Ie(``),Le(yn),Be(!1),He(!1),h&&(X(h),Z(),yt()))},[h,Ct,St,X,Z,yt]),Te(()=>{typeof document<`u`&&document.hidden||(($||q)&&(Z(),yt()),s&&nt.current?.({silent:!0}),q&&!$&&g.current&&X(g.current,{silent:!0}))},$||q||rt.length>0?4e3:s?6e3:0),(0,W.useEffect)(()=>{if(!s||typeof document>`u`)return;let e=()=>{document.hidden||nt.current?.({silent:!0})};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[s]),(0,W.useEffect)(()=>{at.current===h&&!q&&(X(h,{silent:!0,force:!0}),ot.current?.({silent:!0})),at.current=q?h:null},[q,h,X]);let wt=(0,W.useCallback)(async(e=``)=>{if(!c)return;let t=typeof e==`string`?e.trim():``,n=t||g.current||bt?.conversationId||``;n&&et(e=>{let t=new Set(e);return t.add(n),t});try{await Q.stop(t),await nt.current?.({silent:!0,force:!0}),ot.current?.({silent:!0}),setTimeout(()=>{nt.current?.({silent:!0,force:!0}),ot.current?.({silent:!0})},950)}finally{n&&et(e=>{if(!e.has(n))return e;let t=new Set(e);return t.delete(n),t})}},[c,bt?.conversationId,Q]),Tt=(0,W.useCallback)(e=>{e&&(e!==g.current&&m({conversation:e}),Ge(!1))},[m]),Et=(0,W.useCallback)(()=>{ot.current?.({silent:!0})},[]),Dt=async t=>{if(!n||$||q||it||A)return;let r=t||``,i=g.current;if(!i)te(r);else if(!(I.conversation?.id!==i||I.loading||I.error)){j(!0);try{await z.put(`/conversations/${encodeURIComponent(i)}/project`,{projectId:r}),L(e=>e.conversation?.id===i?{...e,conversation:{...e.conversation,projectId:r}}:e),S&&S!==r||vt(r||hn),Et()}catch(t){V(t,e(`chat.projectChangeFailed`,null,`更新对话所属项目失败`))}finally{j(!1)}}},{createConversation:Ot,renameConversation:kt,togglePin:At,deleteConversation:jt,batchDelete:Mt,deleteTurn:Nt}=fn({t:e,conversationRef:g,newProjectId:ee,canWrite:n,reloadList:Et,requestDetailReload:X,navigate:m,onSelectionCleared:(0,W.useCallback)(()=>L(bn),[])}),Pt=(0,W.useCallback)(async(t,n,r)=>{let i=g.current;if(u&&t?.interruptId&&Ee?.id===i&&Ee.items.some(e=>String(e.id||e.interruptId)===t.interruptId)){Ie(t.interruptId);try{await z.post(`/hitl/decision`,{interruptId:t.interruptId,decision:n,comment:r||``}),De(n===`approve`?e(`chat.hitlApproved`,null,`已批准本次调用`):e(`chat.hitlRejected`,null,`已拒绝本次调用`)),Oe(e=>e?.id===i?{id:i,items:e.items.filter(e=>String(e.id||e.interruptId)!==t.interruptId)}:e)}catch(t){V(t,e(`chat.hitlDecisionFailed`,null,`提交审批失败`))}finally{g.current===i&&(Ie(``),Z())}}},[Ee,u,Z,e]),Ft=(0,W.useCallback)(async t=>{let n=g.current;if(u&&t?.interruptId&&Ee?.id===n&&Ee.items.some(e=>String(e.id||e.interruptId)===t.interruptId)){Ie(t.interruptId);try{await z.post(`/hitl/dismiss`,{interruptId:t.interruptId}),De(e(`chat.hitlDismissed`,null,`已忽略该审批`)),Oe(e=>e?.id===n?{id:n,items:e.items.filter(e=>String(e.id||e.interruptId)!==t.interruptId)}:e)}catch(t){V(t,e(`chat.hitlDismissFailed`,null,`忽略审批失败`))}finally{g.current===n&&(Ie(``),Z())}}},[Ee,u,Z,e]),It=(0,W.useCallback)(async t=>{let n=g.current,r=e=>H(n,t=>({...t,attachments:e(t.attachments||[])})),i=t.map((e,t)=>({id:`att-${Date.now()}-${t}`,fileName:e.name,mimeType:e.type||``,serverPath:``,uploading:!0,error:!1}));r(e=>[...e,...i]),await Promise.all(i.map(async(i,a)=>{let o=new FormData;o.append(`file`,t[a]),n&&o.append(`conversationId`,n);try{let e=await z.post(`/chat-uploads`,o),t=String(e?.absolutePath||``).trim();if(!t)throw Error(`服务端未返回文件路径`);r(e=>e.map(e=>e.id===i.id?{...e,serverPath:t,uploading:!1,error:!1}:e))}catch(t){r(e=>e.map(e=>e.id===i.id?{...e,uploading:!1,error:!0}:e)),V(t,e(`chat.attachmentUploadFailed`,{name:i.fileName},`附件 ${i.fileName} 上传失败`))}}))},[H,e]),Lt=(0,W.useCallback)(e=>{H(h,t=>({...t,attachments:(t.attachments||[]).filter(t=>t.id!==e)}))},[h,H]),Rt=P.has(h),zt=I.conversation?.id===h?I.conversation:null,Bt=!h||Rt||!!zt,Vt=Rt?vn(P.get(h)):zt?vn(zt.roleName):h?``:vn(se),Ht=(0,W.useCallback)(e=>{let t=vn(e);ce(t),ue(e=>{let n=new Map(e);return n.set(h,t),n})},[h,ce]),Ut=(0,W.useCallback)(()=>{if(!n||!a||$||q||it||A||F.waitingForChannel||!Bt)return;let t=be.trim();if(!t&&!Se.length){B(e(`chat.emptyMessage`,null,`请输入内容或添加附件`));return}if(Se.some(e=>e.uploading)){B(e(`chat.waitingAttachmentsUpload`,null,`附件仍在上传,请稍候`));return}let r=Se.filter(e=>e.serverPath&&!e.error);if(Se.length&&r.length!==Se.length){B(e(`chat.attachmentsUploadIncomplete`,null,`存在上传失败的附件,请移除后再发送`));return}let i=t||e(`chat.filePrompt`,null,`请解析我上传的附件。`),o=r.length?`${i}\n${r.map(e=>`📎 ${e.fileName}`).join(` -`)}`:i;L(e=>({...e,messages:[...e.messages||[],{id:`local-${Date.now()}`,role:`user`,content:o,createdAt:new Date().toISOString()}]})),St(),H(h,()=>({draft:``,attachments:[]})),de.current=Vt,Q.send({message:i,attachments:r,mode:N,projectId:ee,role:Vt,...F.request,hitl:!h&&u&&me||void 0})},[Se,q,n,a,u,it,h,be,me,N,F,ee,A,St,Vt,Bt,Q,$,e,H]),Wt=(0,W.useRef)(new Set),Gt=(0,W.useRef)(``),Kt=(0,W.useRef)(``);(0,W.useEffect)(()=>{if(!h)return;let t=Ae(h);if(!t)return;let r=String(t.prompt||``).trim();if(!r){je(h);return}if(I.error||!n||!a){Gt.current!==h&&(Gt.current=h,je(h),B(e(`vulnerabilityRetest.startFailed`,null,`复测尚未成功发送,提示词已保存在分支中,请返回该分支继续。`)));return}if($||q||it||!Bt||I.conversation?.id!==h)return;je(h);let i=g.current;Wt.current.add(i),H(i,e=>({...e,draft:``,attachments:[]})),L(e=>e.conversation?.id===i?{...e,messages:[...e.messages||[],{id:`local-${Date.now()}`,role:`user`,content:r,createdAt:new Date().toISOString()}]}:e),St(),Q.send({message:r,mode:N,role:Vt,...F.request})},[h,I.conversation,I.error,$,q,it,Bt,n,a,N,F,St,Vt,Q,e,H]),(0,W.useEffect)(()=>{if(h)return;let e=Me();if(!e)return;let t=String(e.prompt||``).trim();t?$||q||it||F.waitingForChannel||!Bt||(Ne(),n&&a&&e.autoSend!==!1?(L(e=>({...e,messages:[...e.messages||[],{id:`local-${Date.now()}`,role:`user`,content:t,createdAt:new Date().toISOString()}]})),St(),H(``,()=>({draft:``,attachments:[]})),de.current=Vt,Q.send({message:t,mode:N,projectId:ee,role:Vt,...F.request,hitl:u&&me||void 0})):H(``,e=>({...e,draft:t}))):Ne()},[h,$,q,it,F,Bt,n,a,u,me,N,ee,St,Vt,Q,H]),(0,W.useEffect)(()=>{let e=I.conversation,t=String(e?.retest?.pending_prompt||``).trim();h&&e?.id===h&&t&&(Wt.current.has(h)||Ae(h)||$||q||String(be||``).trim()||Kt.current!==h&&(Kt.current=h,H(h,e=>({...e,draft:t}))))},[h,I.conversation,be,$,q,H]);let qt=I.conversation,Jt=(0,W.useRef)(``);(0,W.useEffect)(()=>{if(!h){Jt.current=``;return}if(qt?.id!==h||Jt.current===h)return;Jt.current=h;let e=qt.projectId||hn;S&&S!==e||w===e&&E||vt(e)},[qt,h,E,vt,S,w]);let Xt=mt.find(e=>!e.projectId)?.total||0,Qt=[{id:hn,title:e(`chat.defaultWorkspace`,null,`默认工作区`),total:Xt},...mt.filter(e=>e.projectId).map(t=>({id:t.projectId,title:lt.find(e=>e.id===t.projectId)?.name||e(`chat.boundProject`,null,`已绑定项目`),total:t.total,projectId:t.projectId}))],en=(0,G.jsx)(pt,{items:E?_t:[],groups:Qt.filter(e=>!S||e.id===S),expandedGroup:E?w:``,groupTotal:Y,onToggleGroup:e=>{e===w&&E?D(!1):e===w?D(!0):vt(e)},loading:J.loading||!gt&&!J.error,error:J.error,onRetry:()=>J.reload(),search:v,onSearch:e=>{y(e),k(1)},projectId:S,onProjectChange:e=>{C(e||``),vt(e||hn)},projects:lt,page:O,pageSize:mn,onPageChange:k,selectedId:h,onSelect:Tt,onCreate:Ot,onRename:kt,onPin:At,onDelete:jt,onBatchDelete:Mt,canWrite:n,canDelete:o}),tn=(0,W.useCallback)(()=>h?X(h,{force:!0}):null,[h,X]);return(0,G.jsxs)(`div`,{className:`chat-page`,children:[!Ke&&(0,G.jsx)(`aside`,{className:`chat-sidebar`,children:en}),(0,G.jsxs)(`section`,{className:`chat-main`,children:[(0,G.jsx)(qe,{conversation:qt,mode:N,hitlCount:ke.length,conversationId:h,narrow:Ke,onToggleSidebar:()=>Ge(!0),onRefresh:()=>{nt.current?.({silent:!0,force:!0}),ot.current?.(),h&&X(h),Z(),yt()}}),(0,G.jsxs)(`div`,{className:`chat-panel`,children:[(0,G.jsx)(Ue,{tasks:rt,currentConversationId:h,currentConversationTitle:qt?.id===h?qt?.title:``,canStop:c,stoppingIds:$e,onSelect:Tt,onStop:wt}),(0,G.jsx)(Yt,{conversationId:h,messages:I.messages,live:bt,loading:I.loading||!(!h||I.conversation||I.error),error:I.error,onRetry:tn,canDelete:o,onDeleteTurn:Nt}),U.running&&U.total>0&&(0,G.jsxs)(`div`,{className:`chat-plan-strip`,children:[(0,G.jsx)(pn,{size:`small`,children:e(`chat.planTasks`,null,`执行计划`)}),(0,G.jsx)(re,{percent:Math.round(Number(U.completed||0)/Math.max(1,Number(U.total))*100),showInfo:!1,size:`small`,className:`chat-plan-strip-bar`}),(0,G.jsxs)(pn,{size:`small`,type:`tertiary`,children:[U.completed,`/`,U.total,U.activeStep?` · ${e(`chat.planStep`,{step:U.activeStep},`第 ${U.activeStep} 步`)}`:``]}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,onClick:()=>{yt(),He(!0)},children:e(`chat.planDetails`,null,`详情`)})]}),xt.length>0&&!bt&&(0,G.jsx)(M,{className:`chat-events-strip`,children:(0,G.jsx)(M.Panel,{itemKey:`1`,header:`${e(`chat.rawEvents`,null,`本轮原始事件`)} · ${xt.length}`,children:(0,G.jsx)(`pre`,{className:`chat-pre`,children:xt.map((e,t)=>`${t+1}. ${JSON.stringify(e)}`).join(` -`)})})}),(0,G.jsx)(on,{items:ke,readOnly:!u,busyId:Fe,onRefresh:Z,onDecide:Pt,onDismiss:Ft}),(0,G.jsx)($t,{value:be,onChange:we,onSend:Ut,onStop:()=>wt(),canStop:c,sending:$||q,checkingRun:it||A||F.waitingForChannel,canWrite:n,canExecute:a,mode:N,onModeChange:e=>oe(Zt.includes(e)?e:`single`),projectId:h?qt?.projectId||``:ee,onProjectChange:Dt,onCreateProject:r&&n&&!st.loading?()=>ie(!0):void 0,projects:lt,projectDisabled:st.loading||!(!h||!I.loading&&qt&&!I.error),role:Vt,onRoleChange:Ht,roles:dt,roleDisabled:!Bt,model:F,canReadConfig:d,onOpenHitl:l?()=>pe(!0):void 0,attachments:Se,onPickFiles:It,onRemoveAttachment:Lt,uploading:Se.filter(e=>e.uploading).length})]})]}),ne&&(0,G.jsx)(Pe,{visible:!0,onCancel:()=>ie(!1),onSaved:ft}),fe&&l&&(0,G.jsx)(ut,{onClose:()=>pe(!1),narrow:Ke,canEnableHitl:u,conversationId:h,draftHitl:h?null:me,onDraftHitlChange:he},h),(0,G.jsx)(le,{visible:Ke&&We,placement:`left`,width:300,onCancel:()=>Ge(!1),title:e(`chat.conversations`,null,`会话列表`),bodyStyle:{padding:0},children:en}),(0,G.jsx)(un,{visible:Ve,onClose:()=>He(!1),plan:U,loading:Re,onRefresh:yt})]})}export{Sn as default}; \ No newline at end of file diff --git a/web/static/app/assets/chat-files-D2U-2IVG.js b/web/static/app/assets/chat-files-BvkWbj5T.js similarity index 99% rename from web/static/app/assets/chat-files-D2U-2IVG.js rename to web/static/app/assets/chat-files-BvkWbj5T.js index cc8d3307..20cba5b5 100644 --- a/web/static/app/assets/chat-files-D2U-2IVG.js +++ b/web/static/app/assets/chat-files-BvkWbj5T.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,N as a,R as o,U as s,W as c,X as ee,ft as l,lt as u,p as d,ut as f,y as p}from"./semi-65W_4I1v.js";import{E as m,F as h,I as te,L as g,R as _,S as ne,T as v,a as re,b as y,c as ie,l as b,m as x,n as ae,o as S,p as oe,s as se,x as C,y as ce}from"./index-CAEPLS-g.js";var w=e(t(),1);function le(e){return g.get(`/chat-uploads`,e)}function ue(e,{relativeDir:t}={}){let n=new FormData;return n.append(`file`,e,e.name),t&&n.append(`relativeDir`,t),g.post(`/chat-uploads`,n)}function de(e,t){return g.post(`/chat-uploads/mkdir`,{parent:e||``,name:t})}function fe(e){return g.del(`/chat-uploads`,{body:{path:e}})}function T(e){return g.get(`/chat-uploads/content`,{path:e})}function pe(e,t=`file`){return g.get(`/chat-uploads/path`,{path:e,kind:t})}function me(e){return _(`/chat-uploads/export`,{query:e,filename:`chat-files-export.zip`})}function E(e,t){return _(`/chat-uploads/download`,{query:{path:e},filename:t})}async function D(e){let t=await(await g.raw(`/chat-uploads/download`,{query:{path:e},timeout:12e4})).blob();return{url:URL.createObjectURL(t),type:t.type,size:t.size}}var O=e(n(),1),{Text:k}=r,he=/\.(png|jpe?g|gif|webp|bmp|svg|ico)$/i,A=/\.(txt|log|md|markdown|json|ya?ml|csv|tsv|xml|html?|css|jsx?|tsx?|py|go|java|c|h|cpp|sh|sql|ini|conf|toml|env|pem)$/i;function j(e){let t=e?.name||``;return he.test(t)?`image`:A.test(t)?`text`:`binary`}function ge({item:e,onClose:t}){let n=h(),[r,i]=(0,w.useState)(!1),[a,s]=(0,w.useState)(null),[ee,l]=(0,w.useState)(``),[u,f]=(0,w.useState)(``),[p,m]=(0,w.useState)(`text`);return(0,w.useEffect)(()=>{let t=``,n=!1;if(!e)return l(``),f(``),s(null),()=>{};let r=j(e);return m(r),i(!0),s(null),l(``),f(``),(async()=>{try{if(r===`image`){let r=await D(e.relativePath);if(n){URL.revokeObjectURL(r.url);return}t=r.url,f(r.url)}else if(r===`text`){let t=await T(e.relativePath);if(n)return;l(t?.content??``)}}catch(e){n||(s(e),r===`text`&&m(`binary`))}finally{n||i(!1)}})(),()=>{n=!0,t&&URL.revokeObjectURL(t)}},[e]),(0,O.jsx)(d,{visible:!!e,title:e?.name||n(`chatFilesPage.previewTitle`,null,`文件预览`),width:720,onCancel:t,footer:(0,O.jsx)(o,{onClick:async()=>{if(e)try{await E(e.relativePath,e.name)}catch(e){y(e,n(`chatFilesPage.errorGeneric`,null,`操作失败,请稍后重试。`))}},children:n(`chatFilesPage.download`,null,`下载`)}),children:e&&(0,O.jsxs)(`div`,{className:`chat-files-preview`,children:[(0,O.jsxs)(`div`,{className:`chat-files-preview-meta`,children:[(0,O.jsx)(k,{type:`tertiary`,size:`small`,children:v(e.size)}),(0,O.jsx)(k,{type:`tertiary`,size:`small`,className:`chat-files-mono`,children:e.relativePath}),(0,O.jsx)(S,{text:e.relativePath,label:n(`chatFilesPage.copyPath`,null,`复制路径`),size:`small`})]}),(0,O.jsx)(b,{error:p===`binary`?null:a}),r&&(0,O.jsx)(`div`,{className:`chat-files-preview-loading`,children:(0,O.jsx)(c,{})}),!r&&p===`image`&&u&&(0,O.jsx)(`img`,{className:`chat-files-preview-image`,src:u,alt:e.name}),!r&&p===`text`&&(0,O.jsx)(`pre`,{className:`chat-files-preview-text`,children:ee}),!r&&p===`binary`&&(0,O.jsx)(k,{type:`tertiary`,children:n(`chatFilesPage.editBinaryHint`,null,`图片、压缩包等二进制文件无法在此以文本方式编辑,请使用「下载」后在本地查看或处理。`)})]})})}var{Text:M}=r,_e=[{value:`all`,label:`全部`},{value:`upload`,label:`对话附件`},{value:`reduction`,label:`工具输出`},{value:`workspace`,label:`工作目录`},{value:`conversation_artifact`,label:`会话产物`}],ve={upload:`对话附件`,reduction:`工具输出`,workspace:`工作目录`,conversation_artifact:`会话产物`};function N(e){let t=String(e||``).split(`/`);return t.pop(),t.join(`/`)}function P(e){let t=String(e||``).split(`/`);return t[t.length-1]||e}function F(){let e=h(),{hasPermission:t}=te(),n=t(`files:write`),r=t(`files:delete`)||n,c=(0,w.useRef)(null),[d,g]=(0,w.useState)(`list`),[_,S]=(0,w.useState)(``),[T,D]=(0,w.useState)(``),[k,he]=(0,w.useState)(`all`),[A,j]=(0,w.useState)(``),[F,I]=(0,w.useState)(``),[L,R]=(0,w.useState)(1),[z,ye]=(0,w.useState)(20),[be,B]=(0,w.useState)(null),[V,H]=(0,w.useState)(null),[xe,U]=(0,w.useState)(!1),W=ae(A,300),G=(0,w.useMemo)(()=>{let e={conversation:_.trim()||void 0,project:T.trim()||void 0,source:k===`all`?void 0:k,search:W.trim()||void 0};return d===`browse`?{...e,page:1,pageSize:`all`}:{...e,page:L,pageSize:z}},[d,_,T,k,W,L,z]),{data:K,loading:q,error:Se,reload:J}=re(()=>le(G),[G]),Y=Array.isArray(K?.files)?K.files:[],X=Array.isArray(K?.folders)?K.folders:[],Z=Number(K?.total??Y.length),Q=(0,w.useMemo)(()=>d===`browse`?{folders:X.filter(e=>N(e)===F),files:Y.filter(e=>N(e.relativePath)===F)}:{folders:[],files:Y},[d,X,Y,F]),Ce=(0,w.useMemo)(()=>{let t=F?F.split(`/`):[],n=[{label:e(`chatFilesPage.browseRoot`,null,`文件`),path:``}];return t.forEach((e,r)=>n.push({label:e,path:t.slice(0,r+1).join(`/`)})),n},[F,e]),we=async t=>{try{let n=await pe(t.relativePath,`file`);await navigator.clipboard.writeText(n?.absolutePath||t.relativePath),C(e(`chatFilesPage.pathCopied`,null,`路径已复制,可到对话中粘贴使用`))}catch(t){y(t,e(`chatFilesPage.errorGeneric`,null,`操作失败,请稍后重试。`))}},Te=async t=>{try{await E(t.relativePath,t.name)}catch(t){y(t,e(`chatFilesPage.errorGeneric`,null,`操作失败,请稍后重试。`))}},Ee=t=>{ce({title:e(`chatFilesPage.confirmDelete`,null,`确定删除该文件?`),content:t.relativePath,onOk:async()=>{try{await fe(t.relativePath),C(e(`chatFilesPage.deleted`,null,`已删除`)),J()}catch(e){y(e)}}})},De=()=>c.current?.click(),Oe=async t=>{let n=Array.from(t.target.files||[]);if(t.target.value=``,n.length){U(!0);try{for(let e of n)await ue(e,{relativeDir:d===`browse`?F:``});C(e(`chatFilesPage.uploadOkHint`,null,`上传成功。点击「复制路径」可复制绝对路径到剪贴板。`)),J()}catch(t){y(t,e(`chatFilesPage.errorGeneric`,null,`操作失败,请稍后重试。`))}finally{U(!1)}}},ke=async()=>{let t=String(V?.name||``).trim();if(!t||t.includes(`/`)||t.includes(`\\`)||t===`.`||t===`..`)ne(e(`chatFilesPage.mkdirInvalidName`,null,`名称无效:不能为空,且不能包含 /、\\ 或 . / ..`));else try{await de(d===`browse`?F:``,t),C(e(`chatFilesPage.mkdirOk`,null,`文件夹已创建`)),H(null),J()}catch(t){y(t,e(`chatFilesPage.errorGeneric`,null,`操作失败,请稍后重试。`))}},Ae=async()=>{try{await me({conversation:_.trim()||void 0,project:T.trim()||void 0,source:k===`all`?void 0:k,search:W.trim()||void 0}),C(e(`chatFilesPage.exportStarted`,null,`已开始导出当前文件`))}catch(t){y(t,e(`chatFilesPage.exportEmpty`,null,`没有可导出的文件`))}},je=[{title:e(`chatFilesPage.colName`,null,`文件名`),dataIndex:`name`,render:(e,t)=>(0,O.jsx)(`button`,{type:`button`,className:`chat-files-name`,onClick:()=>B(t),title:t.relativePath,children:e||P(t.relativePath)})},{title:e(`chatFilesPage.sourceFilter`,null,`来源`),dataIndex:`source`,width:110,render:e=>(0,O.jsx)(a,{size:`small`,children:ve[e]||e||`对话附件`})},{title:e(`chatFilesPage.colConversation`,null,`会话`),dataIndex:`conversationTitle`,width:180,render:(e,t)=>(0,O.jsx)(M,{type:`tertiary`,size:`small`,ellipsis:{showTooltip:!0},children:e||t.conversationId||`—`})},{title:e(`chatFilesPage.colSubPath`,null,`路径`),dataIndex:`relativePath`,width:220,render:e=>(0,O.jsx)(`span`,{className:`chat-files-path`,children:e})},{title:e(`chatFilesPage.colSize`,null,`大小`),dataIndex:`size`,width:100,render:e=>v(e)},{title:e(`chatFilesPage.colModified`,null,`修改时间`),dataIndex:`modifiedUnix`,width:170,render:e=>m(e?e*1e3:null)},{title:e(`chatFilesPage.colActions`,null,`操作`),dataIndex:`actions`,width:260,render:(t,n)=>(0,O.jsxs)(i,{spacing:4,wrap:!0,children:[(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>B(n),children:e(`chatFilesPage.preview`,null,`预览`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>we(n),children:e(`chatFilesPage.copyPath`,null,`复制路径`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>Te(n),children:e(`chatFilesPage.download`,null,`下载`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,type:`danger`,disabled:!r,onClick:()=>Ee(n),children:e(`chatFilesPage.delete`,null,`删除`)})]})}],Me=[{title:e(`chatFilesPage.colName`,null,`文件名`),dataIndex:`name`,render:(e,t)=>t.isDir?(0,O.jsxs)(`button`,{type:`button`,className:`chat-files-name is-dir`,onClick:()=>I(t.path),children:[e,`/`]}):(0,O.jsx)(`button`,{type:`button`,className:`chat-files-name`,onClick:()=>B(t),title:t.relativePath,children:e})},{title:e(`chatFilesPage.colSize`,null,`大小`),dataIndex:`size`,width:110,render:e=>e===void 0?`—`:v(e)},{title:e(`chatFilesPage.colModified`,null,`修改时间`),dataIndex:`modifiedUnix`,width:180,render:e=>e?m(e*1e3):`—`},{title:e(`chatFilesPage.colActions`,null,`操作`),dataIndex:`actions`,width:240,render:(t,n)=>n.isDir?(0,O.jsx)(i,{spacing:4,children:(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>I(n.path),children:e(`chatFilesPage.enterFolder`,null,`进入`)})}):(0,O.jsxs)(i,{spacing:4,wrap:!0,children:[(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>B(n),children:e(`chatFilesPage.preview`,null,`预览`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>we(n),children:e(`chatFilesPage.copyPath`,null,`复制路径`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>Te(n),children:e(`chatFilesPage.download`,null,`下载`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,type:`danger`,disabled:!r,onClick:()=>Ee(n),children:e(`chatFilesPage.delete`,null,`删除`)})]})}],Ne=[...Q.folders.map(e=>({rowKey:`dir:${e}`,isDir:!0,path:e,name:P(e)})),...Q.files.map(e=>({...e,rowKey:e.relativePath}))],$=d===`browse`?Ne:Y;return(0,O.jsxs)(`div`,{className:`chat-files-page`,id:`page-chat-files`,children:[(0,O.jsx)(oe,{title:e(`chatFilesPage.title`,null,`文件管理`),description:e(`chatFilesPage.intro`,null,`管理在对话中上传的文件,可复制路径供 AI 引用`),extra:[(0,O.jsx)(o,{onClick:Ae,children:e(`chatFilesPage.export`,null,`导出当前结果`)},`export`),(0,O.jsx)(o,{icon:(0,O.jsx)(l,{}),disabled:!n,onClick:()=>H({name:``}),children:e(`chatFilesPage.newFolderButton`,null,`新建文件夹`)},`mkdir`),(0,O.jsx)(o,{theme:`solid`,type:`primary`,icon:(0,O.jsx)(ee,{}),loading:xe,disabled:!n,onClick:De,children:e(`chatFilesPage.upload`,null,`上传文件`)},`upload`),(0,O.jsx)(o,{icon:(0,O.jsx)(f,{}),onClick:J,loading:q,children:e(`common.refresh`,null,`刷新`)},`refresh`)]}),(0,O.jsx)(`input`,{ref:c,type:`file`,multiple:!0,hidden:!0,onChange:Oe}),(0,O.jsx)(b,{error:Se,onRetry:J}),(0,O.jsx)(x,{title:e(`chatFilesPage.filterTitle`,null,`筛选`),children:(0,O.jsxs)(`div`,{className:`chat-files-fields`,children:[(0,O.jsxs)(`div`,{className:`chat-files-field`,children:[(0,O.jsx)(`span`,{className:`chat-files-field-label`,children:e(`chatFilesPage.conversationFilter`,null,`会话 ID`)}),(0,O.jsx)(s,{value:_,onChange:e=>{S(e),R(1)},placeholder:e(`chatFilesPage.conversationPlaceholder`,null,`留空表示全部`),style:{width:200}})]}),(0,O.jsxs)(`div`,{className:`chat-files-field`,children:[(0,O.jsx)(`span`,{className:`chat-files-field-label`,children:e(`chatFilesPage.projectFilter`,null,`项目 ID`)}),(0,O.jsx)(s,{value:T,onChange:e=>{D(e),R(1)},placeholder:e(`chatFilesPage.projectPlaceholder`,null,`留空表示全部`),style:{width:200}})]}),(0,O.jsxs)(`div`,{className:`chat-files-field`,children:[(0,O.jsx)(`span`,{className:`chat-files-field-label`,children:e(`chatFilesPage.searchName`,null,`文件名`)}),(0,O.jsx)(s,{value:A,onChange:e=>{j(e),R(1)},prefix:(0,O.jsx)(u,{}),placeholder:e(`chatFilesPage.searchNamePlaceholder`,null,`筛选文件名`),style:{width:200}})]}),(0,O.jsxs)(`div`,{className:`chat-files-field`,children:[(0,O.jsx)(`span`,{className:`chat-files-field-label`,children:e(`chatFilesPage.sourceFilter`,null,`来源`)}),(0,O.jsx)(p,{value:k,onChange:e=>{he(e||`all`),R(1)},optionList:_e,style:{width:160}})]}),(0,O.jsxs)(`div`,{className:`chat-files-field`,children:[(0,O.jsx)(`span`,{className:`chat-files-field-label`,children:e(`chatFilesPage.groupBy`,null,`分组方式`)}),(0,O.jsx)(p,{value:d,onChange:e=>{g(e||`list`),R(1),I(``)},optionList:[{value:`list`,label:e(`chatFilesPage.groupNone`,null,`不分组(平铺)`)},{value:`browse`,label:e(`chatFilesPage.groupByFolder`,null,`按文件夹(路径浏览)`)}],style:{width:200}})]})]})}),d===`browse`&&(0,O.jsx)(`nav`,{className:`chat-files-breadcrumb`,"aria-label":`breadcrumb`,children:Ce.map((e,t)=>(0,O.jsxs)(`span`,{className:`chat-files-breadcrumb-item`,children:[t>0&&(0,O.jsx)(`span`,{className:`chat-files-breadcrumb-sep`,children:`/`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>I(e.path),children:e.label})]},e.path||`root`))}),(0,O.jsx)(x,{title:d===`browse`?e(`chatFilesPage.browseRoot`,null,`文件`):e(`chatFilesPage.listTitle`,null,`附件列表`),extra:(0,O.jsx)(M,{type:`tertiary`,size:`small`,children:e(`chatFilesPage.paginationInfo`,null,`显示 {{start}}-{{end}} / {{total}} 个文件`).replace(`{{start}}`,$.length?`1`:`0`).replace(`{{end}}`,String($.length)).replace(`{{total}}`,String(d===`browse`?$.length:Z))}),children:(0,O.jsx)(se,{columns:d===`browse`?Me:je,dataSource:$,rowKey:e=>e.rowKey||e.relativePath,loading:q,onRefresh:J,pagination:d!==`browse`&&{currentPage:L,pageSize:z,total:Z,onPageChange:e=>R(e),onPageSizeChange:e=>{ye(e),R(1)}},emptyText:d===`browse`?e(`chatFilesPage.folderEmpty`,null,`此文件夹为空`):e(`chatFilesPage.empty`,null,`暂无对话附件`)})}),(0,O.jsx)(ge,{item:be,onClose:()=>B(null)}),(0,O.jsxs)(ie,{visible:!!V,title:e(`chatFilesPage.newFolderTitle`,null,`新建文件夹`),width:420,onCancel:()=>H(null),onOk:ke,children:[(0,O.jsxs)(M,{type:`tertiary`,size:`small`,children:[e(`chatFilesPage.newFolderLocation`,null,`位置`),`:`,d===`browse`&&F?F:`/`]}),(0,O.jsx)(s,{value:V?.name||``,onChange:e=>H({name:e}),placeholder:e(`chatFilesPage.newFolderNamePlaceholder`,null,`仅名称,不含 /`),style:{marginTop:8}})]})]})}export{F as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,N as a,R as o,U as s,W as c,X as ee,ft as l,lt as u,p as d,ut as f,y as p}from"./semi-65W_4I1v.js";import{E as m,F as h,I as te,L as g,R as _,S as ne,T as v,a as re,b as y,c as ie,l as b,m as x,n as ae,o as S,p as oe,s as se,x as C,y as ce}from"./index-DNMXun-U.js";var w=e(t(),1);function le(e){return g.get(`/chat-uploads`,e)}function ue(e,{relativeDir:t}={}){let n=new FormData;return n.append(`file`,e,e.name),t&&n.append(`relativeDir`,t),g.post(`/chat-uploads`,n)}function de(e,t){return g.post(`/chat-uploads/mkdir`,{parent:e||``,name:t})}function fe(e){return g.del(`/chat-uploads`,{body:{path:e}})}function T(e){return g.get(`/chat-uploads/content`,{path:e})}function pe(e,t=`file`){return g.get(`/chat-uploads/path`,{path:e,kind:t})}function me(e){return _(`/chat-uploads/export`,{query:e,filename:`chat-files-export.zip`})}function E(e,t){return _(`/chat-uploads/download`,{query:{path:e},filename:t})}async function D(e){let t=await(await g.raw(`/chat-uploads/download`,{query:{path:e},timeout:12e4})).blob();return{url:URL.createObjectURL(t),type:t.type,size:t.size}}var O=e(n(),1),{Text:k}=r,he=/\.(png|jpe?g|gif|webp|bmp|svg|ico)$/i,A=/\.(txt|log|md|markdown|json|ya?ml|csv|tsv|xml|html?|css|jsx?|tsx?|py|go|java|c|h|cpp|sh|sql|ini|conf|toml|env|pem)$/i;function j(e){let t=e?.name||``;return he.test(t)?`image`:A.test(t)?`text`:`binary`}function ge({item:e,onClose:t}){let n=h(),[r,i]=(0,w.useState)(!1),[a,s]=(0,w.useState)(null),[ee,l]=(0,w.useState)(``),[u,f]=(0,w.useState)(``),[p,m]=(0,w.useState)(`text`);return(0,w.useEffect)(()=>{let t=``,n=!1;if(!e)return l(``),f(``),s(null),()=>{};let r=j(e);return m(r),i(!0),s(null),l(``),f(``),(async()=>{try{if(r===`image`){let r=await D(e.relativePath);if(n){URL.revokeObjectURL(r.url);return}t=r.url,f(r.url)}else if(r===`text`){let t=await T(e.relativePath);if(n)return;l(t?.content??``)}}catch(e){n||(s(e),r===`text`&&m(`binary`))}finally{n||i(!1)}})(),()=>{n=!0,t&&URL.revokeObjectURL(t)}},[e]),(0,O.jsx)(d,{visible:!!e,title:e?.name||n(`chatFilesPage.previewTitle`,null,`文件预览`),width:720,onCancel:t,footer:(0,O.jsx)(o,{onClick:async()=>{if(e)try{await E(e.relativePath,e.name)}catch(e){y(e,n(`chatFilesPage.errorGeneric`,null,`操作失败,请稍后重试。`))}},children:n(`chatFilesPage.download`,null,`下载`)}),children:e&&(0,O.jsxs)(`div`,{className:`chat-files-preview`,children:[(0,O.jsxs)(`div`,{className:`chat-files-preview-meta`,children:[(0,O.jsx)(k,{type:`tertiary`,size:`small`,children:v(e.size)}),(0,O.jsx)(k,{type:`tertiary`,size:`small`,className:`chat-files-mono`,children:e.relativePath}),(0,O.jsx)(S,{text:e.relativePath,label:n(`chatFilesPage.copyPath`,null,`复制路径`),size:`small`})]}),(0,O.jsx)(b,{error:p===`binary`?null:a}),r&&(0,O.jsx)(`div`,{className:`chat-files-preview-loading`,children:(0,O.jsx)(c,{})}),!r&&p===`image`&&u&&(0,O.jsx)(`img`,{className:`chat-files-preview-image`,src:u,alt:e.name}),!r&&p===`text`&&(0,O.jsx)(`pre`,{className:`chat-files-preview-text`,children:ee}),!r&&p===`binary`&&(0,O.jsx)(k,{type:`tertiary`,children:n(`chatFilesPage.editBinaryHint`,null,`图片、压缩包等二进制文件无法在此以文本方式编辑,请使用「下载」后在本地查看或处理。`)})]})})}var{Text:M}=r,_e=[{value:`all`,label:`全部`},{value:`upload`,label:`对话附件`},{value:`reduction`,label:`工具输出`},{value:`workspace`,label:`工作目录`},{value:`conversation_artifact`,label:`会话产物`}],ve={upload:`对话附件`,reduction:`工具输出`,workspace:`工作目录`,conversation_artifact:`会话产物`};function N(e){let t=String(e||``).split(`/`);return t.pop(),t.join(`/`)}function P(e){let t=String(e||``).split(`/`);return t[t.length-1]||e}function F(){let e=h(),{hasPermission:t}=te(),n=t(`files:write`),r=t(`files:delete`)||n,c=(0,w.useRef)(null),[d,g]=(0,w.useState)(`list`),[_,S]=(0,w.useState)(``),[T,D]=(0,w.useState)(``),[k,he]=(0,w.useState)(`all`),[A,j]=(0,w.useState)(``),[F,I]=(0,w.useState)(``),[L,R]=(0,w.useState)(1),[z,ye]=(0,w.useState)(20),[be,B]=(0,w.useState)(null),[V,H]=(0,w.useState)(null),[xe,U]=(0,w.useState)(!1),W=ae(A,300),G=(0,w.useMemo)(()=>{let e={conversation:_.trim()||void 0,project:T.trim()||void 0,source:k===`all`?void 0:k,search:W.trim()||void 0};return d===`browse`?{...e,page:1,pageSize:`all`}:{...e,page:L,pageSize:z}},[d,_,T,k,W,L,z]),{data:K,loading:q,error:Se,reload:J}=re(()=>le(G),[G]),Y=Array.isArray(K?.files)?K.files:[],X=Array.isArray(K?.folders)?K.folders:[],Z=Number(K?.total??Y.length),Q=(0,w.useMemo)(()=>d===`browse`?{folders:X.filter(e=>N(e)===F),files:Y.filter(e=>N(e.relativePath)===F)}:{folders:[],files:Y},[d,X,Y,F]),Ce=(0,w.useMemo)(()=>{let t=F?F.split(`/`):[],n=[{label:e(`chatFilesPage.browseRoot`,null,`文件`),path:``}];return t.forEach((e,r)=>n.push({label:e,path:t.slice(0,r+1).join(`/`)})),n},[F,e]),we=async t=>{try{let n=await pe(t.relativePath,`file`);await navigator.clipboard.writeText(n?.absolutePath||t.relativePath),C(e(`chatFilesPage.pathCopied`,null,`路径已复制,可到对话中粘贴使用`))}catch(t){y(t,e(`chatFilesPage.errorGeneric`,null,`操作失败,请稍后重试。`))}},Te=async t=>{try{await E(t.relativePath,t.name)}catch(t){y(t,e(`chatFilesPage.errorGeneric`,null,`操作失败,请稍后重试。`))}},Ee=t=>{ce({title:e(`chatFilesPage.confirmDelete`,null,`确定删除该文件?`),content:t.relativePath,onOk:async()=>{try{await fe(t.relativePath),C(e(`chatFilesPage.deleted`,null,`已删除`)),J()}catch(e){y(e)}}})},De=()=>c.current?.click(),Oe=async t=>{let n=Array.from(t.target.files||[]);if(t.target.value=``,n.length){U(!0);try{for(let e of n)await ue(e,{relativeDir:d===`browse`?F:``});C(e(`chatFilesPage.uploadOkHint`,null,`上传成功。点击「复制路径」可复制绝对路径到剪贴板。`)),J()}catch(t){y(t,e(`chatFilesPage.errorGeneric`,null,`操作失败,请稍后重试。`))}finally{U(!1)}}},ke=async()=>{let t=String(V?.name||``).trim();if(!t||t.includes(`/`)||t.includes(`\\`)||t===`.`||t===`..`)ne(e(`chatFilesPage.mkdirInvalidName`,null,`名称无效:不能为空,且不能包含 /、\\ 或 . / ..`));else try{await de(d===`browse`?F:``,t),C(e(`chatFilesPage.mkdirOk`,null,`文件夹已创建`)),H(null),J()}catch(t){y(t,e(`chatFilesPage.errorGeneric`,null,`操作失败,请稍后重试。`))}},Ae=async()=>{try{await me({conversation:_.trim()||void 0,project:T.trim()||void 0,source:k===`all`?void 0:k,search:W.trim()||void 0}),C(e(`chatFilesPage.exportStarted`,null,`已开始导出当前文件`))}catch(t){y(t,e(`chatFilesPage.exportEmpty`,null,`没有可导出的文件`))}},je=[{title:e(`chatFilesPage.colName`,null,`文件名`),dataIndex:`name`,render:(e,t)=>(0,O.jsx)(`button`,{type:`button`,className:`chat-files-name`,onClick:()=>B(t),title:t.relativePath,children:e||P(t.relativePath)})},{title:e(`chatFilesPage.sourceFilter`,null,`来源`),dataIndex:`source`,width:110,render:e=>(0,O.jsx)(a,{size:`small`,children:ve[e]||e||`对话附件`})},{title:e(`chatFilesPage.colConversation`,null,`会话`),dataIndex:`conversationTitle`,width:180,render:(e,t)=>(0,O.jsx)(M,{type:`tertiary`,size:`small`,ellipsis:{showTooltip:!0},children:e||t.conversationId||`—`})},{title:e(`chatFilesPage.colSubPath`,null,`路径`),dataIndex:`relativePath`,width:220,render:e=>(0,O.jsx)(`span`,{className:`chat-files-path`,children:e})},{title:e(`chatFilesPage.colSize`,null,`大小`),dataIndex:`size`,width:100,render:e=>v(e)},{title:e(`chatFilesPage.colModified`,null,`修改时间`),dataIndex:`modifiedUnix`,width:170,render:e=>m(e?e*1e3:null)},{title:e(`chatFilesPage.colActions`,null,`操作`),dataIndex:`actions`,width:260,render:(t,n)=>(0,O.jsxs)(i,{spacing:4,wrap:!0,children:[(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>B(n),children:e(`chatFilesPage.preview`,null,`预览`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>we(n),children:e(`chatFilesPage.copyPath`,null,`复制路径`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>Te(n),children:e(`chatFilesPage.download`,null,`下载`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,type:`danger`,disabled:!r,onClick:()=>Ee(n),children:e(`chatFilesPage.delete`,null,`删除`)})]})}],Me=[{title:e(`chatFilesPage.colName`,null,`文件名`),dataIndex:`name`,render:(e,t)=>t.isDir?(0,O.jsxs)(`button`,{type:`button`,className:`chat-files-name is-dir`,onClick:()=>I(t.path),children:[e,`/`]}):(0,O.jsx)(`button`,{type:`button`,className:`chat-files-name`,onClick:()=>B(t),title:t.relativePath,children:e})},{title:e(`chatFilesPage.colSize`,null,`大小`),dataIndex:`size`,width:110,render:e=>e===void 0?`—`:v(e)},{title:e(`chatFilesPage.colModified`,null,`修改时间`),dataIndex:`modifiedUnix`,width:180,render:e=>e?m(e*1e3):`—`},{title:e(`chatFilesPage.colActions`,null,`操作`),dataIndex:`actions`,width:240,render:(t,n)=>n.isDir?(0,O.jsx)(i,{spacing:4,children:(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>I(n.path),children:e(`chatFilesPage.enterFolder`,null,`进入`)})}):(0,O.jsxs)(i,{spacing:4,wrap:!0,children:[(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>B(n),children:e(`chatFilesPage.preview`,null,`预览`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>we(n),children:e(`chatFilesPage.copyPath`,null,`复制路径`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,onClick:()=>Te(n),children:e(`chatFilesPage.download`,null,`下载`)}),(0,O.jsx)(o,{size:`small`,theme:`borderless`,type:`danger`,disabled:!r,onClick:()=>Ee(n),children:e(`chatFilesPage.delete`,null,`删除`)})]})}],Ne=[...Q.folders.map(e=>({rowKey:`dir:${e}`,isDir:!0,path:e,name:P(e)})),...Q.files.map(e=>({...e,rowKey:e.relativePath}))],$=d===`browse`?Ne:Y;return(0,O.jsxs)(`div`,{className:`chat-files-page`,id:`page-chat-files`,children:[(0,O.jsx)(oe,{title:e(`chatFilesPage.title`,null,`文件管理`),description:e(`chatFilesPage.intro`,null,`管理在对话中上传的文件,可复制路径供 AI 引用`),extra:[(0,O.jsx)(o,{onClick:Ae,children:e(`chatFilesPage.export`,null,`导出当前结果`)},`export`),(0,O.jsx)(o,{icon:(0,O.jsx)(l,{}),disabled:!n,onClick:()=>H({name:``}),children:e(`chatFilesPage.newFolderButton`,null,`新建文件夹`)},`mkdir`),(0,O.jsx)(o,{theme:`solid`,type:`primary`,icon:(0,O.jsx)(ee,{}),loading:xe,disabled:!n,onClick:De,children:e(`chatFilesPage.upload`,null,`上传文件`)},`upload`),(0,O.jsx)(o,{icon:(0,O.jsx)(f,{}),onClick:J,loading:q,children:e(`common.refresh`,null,`刷新`)},`refresh`)]}),(0,O.jsx)(`input`,{ref:c,type:`file`,multiple:!0,hidden:!0,onChange:Oe}),(0,O.jsx)(b,{error:Se,onRetry:J}),(0,O.jsx)(x,{title:e(`chatFilesPage.filterTitle`,null,`筛选`),children:(0,O.jsxs)(`div`,{className:`chat-files-fields`,children:[(0,O.jsxs)(`div`,{className:`chat-files-field`,children:[(0,O.jsx)(`span`,{className:`chat-files-field-label`,children:e(`chatFilesPage.conversationFilter`,null,`会话 ID`)}),(0,O.jsx)(s,{value:_,onChange:e=>{S(e),R(1)},placeholder:e(`chatFilesPage.conversationPlaceholder`,null,`留空表示全部`),style:{width:200}})]}),(0,O.jsxs)(`div`,{className:`chat-files-field`,children:[(0,O.jsx)(`span`,{className:`chat-files-field-label`,children:e(`chatFilesPage.projectFilter`,null,`项目 ID`)}),(0,O.jsx)(s,{value:T,onChange:e=>{D(e),R(1)},placeholder:e(`chatFilesPage.projectPlaceholder`,null,`留空表示全部`),style:{width:200}})]}),(0,O.jsxs)(`div`,{className:`chat-files-field`,children:[(0,O.jsx)(`span`,{className:`chat-files-field-label`,children:e(`chatFilesPage.searchName`,null,`文件名`)}),(0,O.jsx)(s,{value:A,onChange:e=>{j(e),R(1)},prefix:(0,O.jsx)(u,{}),placeholder:e(`chatFilesPage.searchNamePlaceholder`,null,`筛选文件名`),style:{width:200}})]}),(0,O.jsxs)(`div`,{className:`chat-files-field`,children:[(0,O.jsx)(`span`,{className:`chat-files-field-label`,children:e(`chatFilesPage.sourceFilter`,null,`来源`)}),(0,O.jsx)(p,{value:k,onChange:e=>{he(e||`all`),R(1)},optionList:_e,style:{width:160}})]}),(0,O.jsxs)(`div`,{className:`chat-files-field`,children:[(0,O.jsx)(`span`,{className:`chat-files-field-label`,children:e(`chatFilesPage.groupBy`,null,`分组方式`)}),(0,O.jsx)(p,{value:d,onChange:e=>{g(e||`list`),R(1),I(``)},optionList:[{value:`list`,label:e(`chatFilesPage.groupNone`,null,`不分组(平铺)`)},{value:`browse`,label:e(`chatFilesPage.groupByFolder`,null,`按文件夹(路径浏览)`)}],style:{width:200}})]})]})}),d===`browse`&&(0,O.jsx)(`nav`,{className:`chat-files-breadcrumb`,"aria-label":`breadcrumb`,children:Ce.map((e,t)=>(0,O.jsxs)(`span`,{className:`chat-files-breadcrumb-item`,children:[t>0&&(0,O.jsx)(`span`,{className:`chat-files-breadcrumb-sep`,children:`/`}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>I(e.path),children:e.label})]},e.path||`root`))}),(0,O.jsx)(x,{title:d===`browse`?e(`chatFilesPage.browseRoot`,null,`文件`):e(`chatFilesPage.listTitle`,null,`附件列表`),extra:(0,O.jsx)(M,{type:`tertiary`,size:`small`,children:e(`chatFilesPage.paginationInfo`,null,`显示 {{start}}-{{end}} / {{total}} 个文件`).replace(`{{start}}`,$.length?`1`:`0`).replace(`{{end}}`,String($.length)).replace(`{{total}}`,String(d===`browse`?$.length:Z))}),children:(0,O.jsx)(se,{columns:d===`browse`?Me:je,dataSource:$,rowKey:e=>e.rowKey||e.relativePath,loading:q,onRefresh:J,pagination:d!==`browse`&&{currentPage:L,pageSize:z,total:Z,onPageChange:e=>R(e),onPageSizeChange:e=>{ye(e),R(1)}},emptyText:d===`browse`?e(`chatFilesPage.folderEmpty`,null,`此文件夹为空`):e(`chatFilesPage.empty`,null,`暂无对话附件`)})}),(0,O.jsx)(ge,{item:be,onClose:()=>B(null)}),(0,O.jsxs)(ie,{visible:!!V,title:e(`chatFilesPage.newFolderTitle`,null,`新建文件夹`),width:420,onCancel:()=>H(null),onOk:ke,children:[(0,O.jsxs)(M,{type:`tertiary`,size:`small`,children:[e(`chatFilesPage.newFolderLocation`,null,`位置`),`:`,d===`browse`&&F?F:`/`]}),(0,O.jsx)(s,{value:V?.name||``,onChange:e=>H({name:e}),placeholder:e(`chatFilesPage.newFolderNamePlaceholder`,null,`仅名称,不含 /`),style:{marginTop:8}})]})]})}export{F as default}; \ No newline at end of file diff --git a/web/static/app/assets/chat-iFaq7TmY.js b/web/static/app/assets/chat-iFaq7TmY.js new file mode 100644 index 00000000..bd7469e4 --- /dev/null +++ b/web/static/app/assets/chat-iFaq7TmY.js @@ -0,0 +1,5 @@ +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{$ as a,B as o,C as s,E as c,F as l,G as u,Gt as d,H as f,I as p,It as m,K as h,L as g,Lt as _,N as v,P as y,Pt as b,R as x,S,U as C,Ut as w,Vt as T,W as E,Y as D,Z as O,Zt as k,_ as ee,at as te,en as A,f as j,ft as ne,g as re,h as ie,it as ae,j as M,kt as oe,lt as N,mt as se,nn as ce,on as P,p as le,rt as ue,ut as de,v as F,vt as fe,w as pe,y as me,zt as he}from"./semi-65W_4I1v.js";import{D as I,E as L,F as R,I as ge,L as z,P as _e,S as B,V as ve,a as ye,b as V,f as be,i as xe,k as Se,l as H,n as Ce,o as we,r as Te,u as Ee,x as De,y as Oe,z as ke}from"./index-DNMXun-U.js";import{n as Ae,t as je}from"./retest-EzTZPjnQ.js";import{n as Me,t as Ne}from"./agent-handoff-DzQOcr38.js";import{t as Pe}from"./project-form-B7wV5B1p.js";import{n as Fe,r as Ie,t as U}from"./model-channel-mQ6lfvSO.js";import{n as Le,t as Re}from"./project-options-CMQbwv_U.js";var W=e(t(),1),G=e(r(),1),ze=new Set([`failed`,`timeout`,`cancelled`,`completed`,`cleanup_unconfirmed`]),Be={running:{key:`tasks.statusRunning`,fallback:`执行中`,color:`blue`},cancelling:{key:`tasks.statusCancelling`,fallback:`取消中`,color:`amber`},cleaning:{key:`tasks.statusCleaning`,fallback:`清理中`,color:`amber`},cleanup_failed:{key:`tasks.statusCleanupFailed`,fallback:`清理异常(自动重试)`,color:`orange`},cleanup_unconfirmed:{key:`tasks.statusCleanupUnconfirmed`,fallback:`远端停止状态待确认`,color:`amber`},failed:{key:`tasks.statusFailed`,fallback:`执行失败`,color:`red`},timeout:{key:`tasks.statusTimeout`,fallback:`执行超时`,color:`red`},cancelled:{key:`tasks.statusCancelled`,fallback:`已取消`,color:`grey`},completed:{key:`tasks.statusCompleted`,fallback:`已完成`,color:`green`}};function Ve(e){return(Array.isArray(e)?e:[]).filter(Boolean).slice().sort((e,t)=>{let n=Date.parse(e?.startedAt||``),r=Date.parse(t?.startedAt||``),i=Number.isFinite(n)?n:2**53-1,a=Number.isFinite(r)?r:2**53-1;if(i!==a)return i-a;let o=String(e?.conversationId||``).localeCompare(String(t?.conversationId||``));return o===0?String(e?.runId||``).localeCompare(String(t?.runId||``)):o})}function He(e,t,n,r){let i=String(e?.conversationId||``).trim();return i&&i===t&&String(n||``).trim()?String(n).trim():String(e?.title||``).trim()||String(e?.message||``).trim()||r(`tasks.unnamedTask`,null,`未命名任务`)}function Ue({tasks:e,currentConversationId:t=``,currentConversationTitle:n=``,canStop:r=!1,stoppingIds:i,onSelect:a,onStop:o}){let{lang:s,t:c}=_e(),l=(0,W.useMemo)(()=>Ve(e),[e]);return l.length?(0,G.jsx)(`div`,{className:`chat-active-tasks`,role:`region`,"aria-label":c(`dashboard.runningTasks`,null,`运行中任务`),children:l.map((e,l)=>{let u=String(e?.conversationId||``).trim(),d=String(e?.status||`running`).toLowerCase(),f=Be[d]||Be.running,p=c(f.key,null,f.fallback),m=ze.has(d),h=d===`cancelling`||!!(u&&i?.has(u)),g=!!(u&&u===t),_=He(e,t,n,c),y=Se(e?.startedAt,s),b=y===`—`?``:y,S=u?`${c(`tasks.viewConversation`,null,`查看对话`)}:${_}`:_;return(0,G.jsxs)(`div`,{className:`chat-active-task${g?` is-current`:``}${u?` is-clickable`:``}`,"data-conversation-id":u||void 0,onClick:e=>{u&&(e.target.closest(`.chat-active-task-stop`)||e.target.closest(`.chat-active-task-main`)||a?.(u))},children:[(0,G.jsxs)(`button`,{type:`button`,className:`chat-active-task-main`,disabled:!u,title:S,onClick:()=>u&&a?.(u),children:[(0,G.jsx)(v,{size:`small`,shape:`circle`,color:f.color,type:`light`,className:`chat-active-task-status`,children:p}),(0,G.jsx)(`span`,{className:`chat-active-task-title`,children:_})]}),(0,G.jsxs)(`div`,{className:`chat-active-task-actions`,children:[b?(0,G.jsx)(`span`,{className:`chat-active-task-time`,children:b}):null,!m&&(0,G.jsx)(x,{size:`small`,type:`danger`,theme:`light`,className:`chat-active-task-stop`,disabled:!r||!u||h,onClick:()=>u&&o?.(u),children:h?c(`tasks.cancelling`,null,`取消中...`):c(`tasks.stopTask`,null,`停止任务`)})]})]},e?.runId||`${u||`task`}-${l}`)})}):null}var{Text:We,Title:Ge}=u,Ke={single:{key:`chat.agentModePiSingle`,label:`单代理`,color:`blue`},deep:{key:`chat.agentModeDeep`,label:`Deep`,color:`purple`},plan_execute:{key:`chat.agentModePlanExecuteLabel`,label:`Plan-Execute`,color:`orange`},supervisor:{key:`chat.agentModeSupervisorLabel`,label:`Supervisor`,color:`green`}};function qe({conversation:e,mode:t,hitlCount:n,conversationId:r,narrow:i,onToggleSidebar:a,onRefresh:o}){let s=R(),c=Ke[t]||Ke.single,l=e?.title||s(`chat.newChat`,null,`新对话`);return(0,G.jsxs)(`header`,{className:`chat-header`,children:[(0,G.jsxs)(`div`,{className:`chat-header-main`,children:[(0,G.jsxs)(`div`,{className:`chat-header-heading`,children:[(0,G.jsx)(Ge,{heading:3,className:`chat-header-title`,title:l,children:l}),(0,G.jsxs)(p,{spacing:6,wrap:!0,className:`chat-header-tags`,children:[e?.pinned&&(0,G.jsx)(v,{size:`small`,color:`amber`,children:s(`chat.pinned`,null,`已置顶`)}),(0,G.jsx)(v,{size:`small`,color:c.color,children:s(c.key,null,c.label)}),n>0&&(0,G.jsx)(v,{size:`small`,color:`orange`,children:s(`chat.pendingApprovals`,{count:n},`待审批 ${n}`)})]})]}),(0,G.jsx)(We,{type:`tertiary`,size:`small`,className:`chat-header-description`,children:r?s(`chat.conversationHint`,null,`会话历史与工具执行过程会自动落库`):s(`chat.newConversationHint`,null,`输入内容即可创建新对话`)})]}),(0,G.jsxs)(p,{spacing:8,wrap:!0,className:`chat-header-actions`,children:[i&&(0,G.jsx)(x,{icon:(0,G.jsx)(fe,{}),onClick:a,children:s(`chat.conversations`,null,`会话`)}),r&&(0,G.jsx)(x,{theme:`borderless`,type:`tertiary`,icon:(0,G.jsx)(de,{"aria-hidden":`true`}),title:s(`chat.refreshConversationHint`,null,`重新读取会话列表、消息、待审批项和执行计划`),onClick:o,children:s(`chat.refreshConversation`,null,`刷新对话`)})]})]})}var Je=[`default`,`off`,`on`,`auto`],Ye=[`low`,`medium`,`high`,`xhigh`,`max`];function Xe(e,t,n){return t!==`off`&&n?e(`chat.reasoningEffortLabels.${n}`,null,{low:`低`,medium:`中`,high:`高`,xhigh:`超高`,max:`ultra`}[n]):e(`chat.reasoningMode${t[0].toUpperCase()}${t.slice(1)}`,null,{default:`跟随系统`,off:`关闭`,on:`开启`,auto:`自动`}[t])}function Ze(e,t){let[n,r]=(0,W.useState)(()=>{try{return localStorage.getItem(e)??t}catch{return t}});return[n,t=>{r(t);try{localStorage.setItem(e,t)}catch{}}]}function Qe(e,t){return e?.image_input===`enabled`?`enabled`:e?.image_input===`disabled`?`disabled`:t===!0?`enabled`:t===!1?`disabled`:`auto`}function $e(e){let[t,n]=Ze(`cyberstrike-chat-ai-channel`,``),[r,i]=Ze(`cyberstrike-chat-reasoning-mode`,`default`),[a,o]=Ze(`cyberstrike-chat-reasoning-effort`,``),s=ye(({signal:e}={})=>z.get(`/config`,{include_tools:0},{signal:e}),[e],{skip:!e}),c=s.data?.ai,l={...s,data:c},u=Object.entries(c?.channels||{}).sort(([e],[t])=>e.localeCompare(t)),d=t.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``),f=u.find(([e])=>e===t)?.[0]||u.find(([e])=>e===d)?.[0]||``,p=f||c?.default_channel||``,m=p?c?.channels?.[p]:s.data?.openai,h=m?.reasoning?.allow_client_reasoning===!1,g=String(s.data?.vision?.model||``).trim(),_=!!(s.data?.vision?.enabled&&g),v=Qe(m,s.data?.image_input_defaults?.[p]),y=Je.includes(r)?r:`default`,b=Ye.includes(a)?a:``,x={mode:y==="default"?void 0:y,effort:y===`off`?void 0:b||void 0};return{channel:f,channels:u,setChannel:n,config:l,mode:y,setMode:i,effort:b,setEffort:o,overrideBlocked:h,vision:{ready:_,model:g,nativeMode:v},waitingForChannel:!!(e&&t&&l.loading),request:{aiChannelId:e&&f||void 0,reasoning:x.mode||x.effort?x:void 0}}}var{Text:et}=u,tt=[`off`,`approval`,`review_edit`],nt=[60,300,600,0],rt=`tool_search, skill, task, write_todos, transfer_to_agent, exit, TaskCreate, TaskGet, TaskUpdate, TaskList, upsert_project_fact, get_project_fact`;function it(e,t){return t===!1?`off`:tt.includes(e)?e:`off`}function K(e){return e===`audit_agent`?`audit_agent`:`human`}function at(e,t=300){if(e==null||e===``)return t;let n=Number(e);return Number.isFinite(n)?Math.max(0,Math.min(86400,Math.round(n))):t}function ot(e){return(Array.isArray(e)?e:String(e||``).split(/[,\n\r]+/)).map(e=>String(e||``).trim()).filter(Boolean)}function q(e,t){let n=new Set(ot(t).map(e=>e.toLowerCase()));return ot(e).filter(e=>!n.has(e.toLowerCase())).join(`, `)}function st(e,t,n){if(n)return{mode:it(n.mode,n.enabled),reviewer:K(n.reviewer),timeoutSeconds:at(n.timeoutSeconds),sensitiveTools:ot(n.sensitiveTools).join(`, `)};let r=t?e?.hitl:null;return{mode:t?it(r?.mode,r?.enabled):it(e?.defaultMode),reviewer:K(t?r?.reviewer:e?.defaultReviewer),timeoutSeconds:at(t?r?.timeoutSeconds??e?.defaultTimeoutSeconds:e?.defaultTimeoutSeconds),sensitiveTools:t?q(r?.sensitiveTools,e?.hitlGlobalToolWhitelist):rt}}function ct(e){return{enabled:e.mode!==`off`,mode:e.mode,reviewer:e.reviewer,sensitiveTools:ot(e.sensitiveTools),timeoutSeconds:e.timeoutSeconds}}function lt({label:e,...t}){let n=(0,W.useId)();return(0,G.jsxs)(`div`,{className:`chat-setting-field`,children:[(0,G.jsx)(et,{id:n,strong:!0,children:e}),(0,G.jsx)(me,{"aria-labelledby":n,...t})]})}function ut({model:e,busy:t,canReadConfig:r}){let i=R(),a=n(),o=(0,W.useId)(),s=(0,W.useRef)(null),c=e.config.data?.default_channel,l=c?U(c,e.config.data?.channels?.[c]):``,u=i(`chat.aiChannelDefault`,null,`跟随默认通道`),d=[{value:``,label:l?`${u} · ${l}`:u},...Fe(e.channels)],f=Object.fromEntries(Je.map(e=>[e,Xe(i,e,``)])),p=t||e.overrideBlocked,m=[``,...Ye],h=Object.fromEntries(m.map((e,t)=>[t,Xe(i,e?`on`:`default`,e)])),g=()=>{e.setMode(`default`),e.setEffort(``)};return(0,G.jsxs)(`div`,{className:`chat-reasoning-picker${!e.overrideBlocked&&e.mode!==`off`&&e.effort===`max`?` is-max`:``}${p?` is-disabled`:``}`,ref:s,children:[(0,G.jsxs)(`div`,{className:`chat-reasoning-heading`,children:[(0,G.jsx)(pe,{trigger:`click`,position:`bottomLeft`,className:`chat-reasoning-mode-menu`,getPopupContainer:()=>s.current,showTick:!0,menu:Je.map(t=>({node:`item`,name:f[t],active:e.mode===t,disabled:p,onClick:()=>t==="default"?g():e.setMode(t)})),children:(0,G.jsx)(x,{theme:`borderless`,type:`tertiary`,icon:(0,G.jsx)(k,{}),className:`chat-reasoning-mode`,"aria-label":i(`chat.reasoningModeLabel`,null,`模型推理`),title:`${i(`chat.reasoningModeLabel`,null,`模型推理`)} · ${f[e.overrideBlocked?`default`:e.mode]}`,disabled:p})}),(0,G.jsx)(et,{strong:!0,className:`chat-reasoning-value`,role:`status`,children:e.overrideBlocked?f.default:Xe(i,e.mode,e.effort)}),(0,G.jsx)(x,{theme:`borderless`,type:`tertiary`,icon:(0,G.jsx)(O,{}),"aria-label":i(`chat.reasoningReset`,null,`重置推理设置`),title:i(`chat.reasoningReset`,null,`重置推理设置`),disabled:p,onClick:g})]}),r?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{id:o,hidden:!0,children:i(`chat.aiChannelLabel`,null,`AI 通道`)}),(0,G.jsx)(me,{className:`chat-reasoning-channel`,"aria-labelledby":o,value:e.channel,optionList:d,renderSelectedItem:e=>e.value===``?l||i(`chat.aiChannelDefaultShort`,null,`默认通道`):Ie(e),arrowIcon:(0,G.jsx)(w,{size:`small`}),borderless:!0,onSelect:e.setChannel,dropdownMatchSelectWidth:!1,dropdownStyle:{maxWidth:`calc(100vw - 32px)`},loading:e.config.loading,disabled:t||e.config.loading||!!e.config.error}),(0,G.jsx)(H,{error:e.config.error,onRetry:()=>e.config.reload()})]}):(0,G.jsx)(et,{type:`tertiary`,className:`chat-reasoning-channel-label`,children:u}),(0,G.jsx)(j,{className:`chat-reasoning-slider`,"aria-label":i(`chat.reasoningEffortLabel`,null,`推理强度`),min:0,max:m.length-1,step:1,marks:h,showMarkLabel:!1,tipFormatter:e=>h[e],getAriaValueText:t=>e.mode===`off`&&!e.overrideBlocked?f.off:h[t],value:e.overrideBlocked?0:m.indexOf(e.effort),disabled:p||e.mode===`off`,onChange:t=>{e.setEffort(m[t]),e.setMode(t===0?`default`:e.mode===`auto`?`auto`:`on`)}}),e.overrideBlocked&&(0,G.jsx)(et,{type:`tertiary`,size:`small`,className:`chat-reasoning-hint`,children:i(`chat.reasoningOverrideBlocked`,null,`此通道使用系统设置中的推理强度。`)}),r&&!e.config.loading&&!e.config.error&&(0,G.jsxs)(`div`,{className:`chat-vision-entry`,children:[(0,G.jsx)(et,{type:`tertiary`,size:`small`,className:`chat-vision-entry-status`,children:e.vision?.ready?`辅助识图:${e.vision.model}`:e.vision?.nativeMode===`enabled`?`图片识别:通道原生支持`:`当前模型不支持识图?`}),(0,G.jsx)(`button`,{type:`button`,className:`chat-vision-entry-link`,onClick:()=>a(`/settings?section=models&focus=vision`),children:e.vision?.ready?`配置`:`配置视觉模型`})]})]})}function dt({onClose:e,narrow:t,canEnableHitl:n,conversationId:r,draftHitl:i,onDraftHitlChange:a}){let o=R(),s=o(`chat.hitlTitle`,null,`人机协同`),[c,l]=(0,W.useState)(!1),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(!1),g=(0,W.useRef)(0),_=(0,W.useRef)(i),v=(0,W.useId)(),y=(0,W.useId)();_.current=i;let b=ye(()=>z.get(r?`/hitl/config/${encodeURIComponent(r)}`:`/hitl/default-config`),[r]);(0,W.useEffect)(()=>{b.data&&(p(st(b.data,r,_.current)),h(!1))},[b.data,r]);let x={off:o(`chat.hitlModeOff`,null,`关闭`),approval:o(`chat.hitlModeApproval`,null,`审批模式`),review_edit:o(`chat.hitlModeReviewEdit`,null,`审查编辑`)},C={60:o(`chat.hitlTimeoutOneMinute`,null,`1 分钟`),300:o(`chat.hitlTimeoutFiveMinutes`,null,`5 分钟`),600:o(`chat.hitlTimeoutTenMinutes`,null,`10 分钟`),0:o(`chat.hitlTimeoutUnlimited`,null,`不限制`)},w=nt.map(e=>({value:e,label:C[e]}));f&&!nt.includes(f.timeoutSeconds)&&w.unshift({value:f.timeoutSeconds,label:`${f.timeoutSeconds}s`});let T=!n||c,D=async e=>{let t=++g.current,n=ct(e);l(!0),d(!1);try{if(await z.put(`/hitl/config`,{conversationId:r,...n}),t!==g.current)return;b.setData(e=>({...e,hitl:n})),d(!0)}catch(e){t===g.current&&(V(e,o(`chat.hitlApplyFail`,null,`同步到服务器失败`)),b.reload({silent:!0}))}finally{t===g.current&&l(!1)}},O=e=>{let t={...f,...e};p(t),h(!1),d(!1),r?D(t):a(ct(t))};return(0,G.jsx)(le,{visible:!0,title:s,"aria-label":s,width:t?`100%`:420,closable:!c,maskClosable:!c,closeOnEsc:!c,onCancel:e,children:(0,G.jsx)(`div`,{className:`chat-settings-fields`,children:(0,G.jsxs)(`section`,{className:`chat-setting-field chat-setting-hitl`,children:[(0,G.jsx)(et,{type:`tertiary`,size:`small`,children:o(`chat.sessionSettingsHint`,null,`人机协同设置只影响后续消息。`)}),(c||u)&&(0,G.jsx)(et,{type:`tertiary`,size:`small`,role:`status`,children:c?o(`chat.systemModelSaving`,null,`正在保存…`):o(`chat.hitlApplyOkSync`,null,`人机协同配置已保存并同步到服务器。`)}),(0,G.jsx)(H,{error:b.error,onRetry:()=>b.reload()}),b.loading&&(0,G.jsx)(E,{}),f&&b.data&&!b.error&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(lt,{label:o(`chat.hitlModeLabel`,null,`模式`),value:f.mode,optionList:tt.map(e=>({value:e,label:x[e]})),onSelect:e=>O({mode:e}),disabled:T}),(0,G.jsxs)(`div`,{className:`chat-setting-field`,children:[(0,G.jsx)(et,{id:v,strong:!0,children:o(`chat.hitlReviewerLabel`,null,`审批方`)}),(0,G.jsx)(ie,{"aria-labelledby":v,type:`button`,className:`chat-setting-reviewer`,value:f.reviewer,options:[{value:`human`,label:o(`chat.hitlReviewerHuman`,null,`人工审批`)},{value:`audit_agent`,label:o(`chat.hitlReviewerAgent`,null,`审计 Agent`)}],onChange:e=>O({reviewer:e.target.value}),disabled:T}),(0,G.jsx)(et,{type:`tertiary`,size:`small`,children:o(`chat.hitlReviewerHint`,null,`可在人工与审计 Agent 之间随时切换;规则与白名单不变。人机协同为「关闭」时也可预先选择。`)})]}),(0,G.jsx)(lt,{label:o(`chat.hitlTimeoutLabel`,null,`审批等待时限`),value:f.timeoutSeconds,optionList:w,onSelect:e=>O({timeoutSeconds:Number(e)}),disabled:T}),(0,G.jsxs)(`div`,{className:`chat-setting-field`,children:[(0,G.jsx)(et,{id:y,strong:!0,children:o(`chat.hitlWhitelistTools`,null,`白名单工具(免审批,逗号分隔)`)}),(0,G.jsx)(S,{"aria-labelledby":y,value:f.sensitiveTools,placeholder:o(`chat.hitlWhitelistPlaceholder`,null,`例:read_file, grep 或每行一个工具名(与 config 全局白名单合并)`),rows:5,disabled:T,onChange:e=>{let t={...f,sensitiveTools:e};p(t),h(!0),d(!1),r||a(ct(t))},onBlur:()=>{m&&r&&!T&&(h(!1),D(f))}}),(0,G.jsx)(et,{type:`tertiary`,size:`small`,children:o(`chat.hitlWhitelistHint`,null,`白名单内工具免审批;每行一个或逗号分隔,与 config 全局白名单合并。`)})]})]})]})})})}var{Text:ft}=u;function pt({item:e,active:t,editing:n,editingTitle:r,onStartEdit:i,onEditingTitle:a,onCommitEdit:o,onCancelEdit:s,onSelect:c,onPin:l,onDelete:u,canWrite:d,canDelete:f,selected:p,onToggleSelect:m,batchMode:h}){let g=R(),v=String(e.title||g(`chat.untitled`,null,`未命名对话`));return(0,G.jsxs)(`div`,{className:`chat-conv-item ${t?`is-active`:``}`,children:[h&&(0,G.jsx)(y,{className:`chat-conv-check`,"aria-label":`${g(`chat.selectConversation`,null,`选择对话`)}:${v}`,checked:p,onChange:t=>m(e.id,t.target.checked)}),n?(0,G.jsxs)(`div`,{className:`chat-conv-edit`,children:[(0,G.jsx)(C,{size:`small`,"aria-label":g(`chat.renameConversationTitle`,null,`重命名`),value:r,autoFocus:!0,onChange:a,onEnterPress:o,onKeyDown:e=>{e.key===`Escape`&&s()}}),(0,G.jsxs)(`div`,{className:`chat-conv-edit-actions`,children:[(0,G.jsx)(x,{size:`small`,theme:`solid`,onClick:o,children:g(`common.save`,null,`保存`)}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,onClick:s,children:g(`common.cancel`,null,`取消`)})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{type:`button`,className:`chat-conv-main`,"aria-current":t?`true`:void 0,title:v,onClick:()=>c(e.id),children:[(0,G.jsxs)(`span`,{className:`chat-conv-title`,children:[e.pinned&&(0,G.jsx)(ae,{size:`small`,className:`chat-conv-pin`}),(0,G.jsx)(`span`,{className:`chat-conv-title-text`,children:v})]}),(0,G.jsx)(`span`,{className:`chat-conv-meta`,children:L(e.updatedAt||e.createdAt)})]}),!h&&(0,G.jsxs)(`div`,{className:`chat-conv-actions`,children:[d&&(0,G.jsx)(P,{content:g(`chat.renameConversationTitle`,null,`重命名`),children:(0,G.jsx)(x,{size:`small`,theme:`borderless`,"aria-label":g(`chat.renameConversationTitle`,null,`重命名`),icon:(0,G.jsx)(b,{}),onClick:()=>i(e)})}),d&&(0,G.jsx)(P,{content:e.pinned?g(`chat.unpin`,null,`取消置顶`):g(`chat.pin`,null,`置顶`),children:(0,G.jsx)(x,{size:`small`,theme:`borderless`,icon:(0,G.jsx)(ae,{}),"aria-label":e.pinned?g(`chat.unpin`,null,`取消置顶`):g(`chat.pin`,null,`置顶`),type:e.pinned?`warning`:`tertiary`,onClick:()=>l(e)})}),f&&(0,G.jsx)(ee,{title:g(`chat.deleteConversationConfirm`,null,`确认删除该对话?删除后不可恢复。`),onConfirm:()=>u(e),children:(0,G.jsx)(x,{size:`small`,theme:`borderless`,type:`danger`,"aria-label":g(`chat.deleteConversationTitle`,null,`删除对话`),icon:(0,G.jsx)(_,{})})})]})]})]})}function mt({items:e,groups:t,expandedGroup:n,groupTotal:r,onToggleGroup:i,loading:a,error:o,onRetry:l,search:u,onSearch:f,projectId:p,onProjectChange:m,projects:h,page:_,pageSize:v,onPageChange:b,selectedId:S,onSelect:w,onCreate:T,onRename:E,onPin:D,onDelete:O,onBatchDelete:k,canWrite:ee,canDelete:te}){let A=R(),j=e,re=(0,W.useId)(),ie=(0,W.useId)(),[ae,M]=(0,W.useState)(``),[se,ce]=(0,W.useState)(``),[P,le]=(0,W.useState)(!1),[ue,fe]=(0,W.useState)([]),pe=j.length>0&&j.every(e=>ue.includes(e.id)),he=!pe&&j.some(e=>ue.includes(e.id));(0,W.useEffect)(()=>{fe([]),le(!1)},[_,p,u,n]);let I=(0,W.useMemo)(()=>[{value:``,label:A(`chat.filterAllProjects`,null,`全部项目`)},...(Array.isArray(h)?h:[]).map(e=>({value:e.id,label:Le(e,A)}))],[h,A]),L=(e,t)=>{fe(n=>t?[...new Set([...n,e])]:n.filter(t=>t!==e))},ge=e=>{M(e.id),ce(String(e.title||``))},z=()=>{let e=ae,t=se.trim();M(``),e&&t&&E(e,t)},_e=(0,G.jsxs)(G.Fragment,{children:[a&&!j.length&&(0,G.jsx)(g,{placeholder:(0,G.jsx)(g.Paragraph,{rows:6}),loading:!0}),!a&&!o&&!j.length&&(0,G.jsx)(c,{title:A(`chat.noHistoryConversations`,null,`暂无历史对话`),description:null,className:`chat-sidebar-empty`}),(0,G.jsx)(s,{dataSource:j,split:!1,renderItem:e=>(0,G.jsx)(pt,{item:e,active:e.id===S,editing:ae===e.id,editingTitle:se,onStartEdit:ge,onEditingTitle:ce,onCommitEdit:z,onCancelEdit:()=>M(``),onSelect:w,onPin:D,onDelete:O,canWrite:ee,canDelete:te,batchMode:P,selected:ue.includes(e.id),onToggleSelect:L},e.id)})]});return(0,G.jsxs)(`div`,{className:`chat-sidebar-inner`,children:[(0,G.jsxs)(`div`,{className:`chat-sidebar-head`,children:[(0,G.jsx)(ft,{strong:!0,className:`chat-sidebar-title`,children:A(`chat.conversations`,null,`会话`)}),(0,G.jsx)(x,{icon:(0,G.jsx)(ne,{}),theme:`borderless`,className:`chat-new-chat`,onClick:T,disabled:!ee,children:A(`chat.newChat`,null,`新建对话`)})]}),(0,G.jsxs)(`div`,{className:`chat-sidebar-filters`,children:[(0,G.jsx)(C,{prefix:(0,G.jsx)(N,{}),"aria-label":A(`chat.searchHistory`,null,`搜索历史对话`),placeholder:A(`chat.searchHistory`,null,`搜索历史对话`),value:u,onChange:f,showClear:!0}),(0,G.jsx)(`span`,{id:ie,hidden:!0,children:A(`chat.filterByProject`,null,`按项目过滤`)}),(0,G.jsx)(me,{value:p,optionList:I,onChange:m,className:`chat-sidebar-project`,"aria-labelledby":ie,placeholder:A(`chat.filterByProject`,null,`按项目过滤`)})]}),(0,G.jsxs)(`div`,{className:`chat-sidebar-tools`,children:[(0,G.jsxs)(ft,{type:`tertiary`,size:`small`,children:[A(`chat.recentConversations`,null,`最近对话`),` · `,t.reduce((e,t)=>e+t.total,0)]}),(0,G.jsxs)(`div`,{className:`chat-sidebar-tools-actions`,children:[te&&j.length>0&&(0,G.jsx)(x,{size:`small`,theme:P?`solid`:`borderless`,onClick:()=>{le(!P),fe([])},children:P?A(`common.cancel`,null,`取消`):A(`chat.batchManage`,null,`批量管理`)}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,"aria-label":A(`chat.refreshConversationList`,null,`刷新会话列表`),title:A(`chat.refreshConversationList`,null,`刷新会话列表`),icon:(0,G.jsx)(de,{}),onClick:l})]})]}),P&&(0,G.jsxs)(`div`,{className:`chat-batch-bar`,children:[(0,G.jsx)(y,{className:`chat-batch-select-all`,checked:pe,indeterminate:he,disabled:a||!j.length,onChange:e=>fe(e.target.checked?j.map(e=>e.id):[]),children:A(`chat.selectPage`,null,`全选本页`)}),(0,G.jsxs)(ft,{size:`small`,children:[A(`chat.selectedCount`,null,`已选`),` `,ue.length]}),(0,G.jsx)(x,{size:`small`,type:`danger`,disabled:!ue.length,onClick:async()=>{await k(ue),fe([]),le(!1)},children:A(`chat.batchDelete`,null,`批量删除`)})]}),(0,G.jsxs)(`div`,{className:`chat-conv-list`,children:[(0,G.jsx)(H,{error:o,onRetry:l}),!t.length&&!a&&!o&&(0,G.jsx)(c,{title:A(`chat.noHistoryConversations`,null,`暂无历史对话`),description:null,className:`chat-sidebar-empty`}),t.map(e=>{let t=e.id===n,r=re+`-`+e.id;return(0,G.jsxs)(`div`,{className:`chat-conv-group`,children:[(0,G.jsxs)(`button`,{type:`button`,className:`chat-conv-group-toggle`,"aria-expanded":t,"aria-controls":r,title:e.projectId?e.title+` · `+e.projectId:e.title,onClick:()=>i(e.id),children:[(0,G.jsx)(oe,{"aria-hidden":`true`}),(0,G.jsx)(`span`,{className:`chat-conv-group-name`,children:e.title}),(0,G.jsx)(`span`,{className:`chat-conv-group-count`,children:e.total}),(0,G.jsx)(d,{"aria-hidden":`true`,className:`chat-conv-group-chevron`})]}),(0,G.jsx)(`div`,{id:r,className:`chat-conv-group-content`,hidden:!t,children:t&&_e})]},e.id)})]}),n&&r>v&&(0,G.jsx)(`div`,{className:`chat-sidebar-pager`,children:(0,G.jsx)(F,{size:`small`,total:r,pageSize:v,currentPage:_,onPageChange:b,showSizeChanger:!1})})]})}var ht=new Set([`taskcreate`,`taskupdate`,`tasklist`,`taskget`,`write_todos`]),gt=new Set([`heartbeat`,`response_delta`,`thinking_stream_delta`,`reasoning_chain_stream_delta`,`tool_result_delta`]),_t=200,vt=2e4;function J(e){return e==null?``:String(e)}function yt(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:null}function Y(e,t=vt){let n=J(e);return n.length<=t?n:`${n.slice(0,t)}\n…(已截断,共 ${n.length} 字符)`}function X(e,t=6e3){if(e==null)return``;try{return Y(typeof e==`string`?e:JSON.stringify(e,null,2),t)}catch{return Y(String(e),t)}}function Z({conversationId:e=``,id:t}={}){return{id:t||`live-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,conversationId:e,status:`streaming`,text:``,blocks:[],toolsByCallId:new Map,events:[],error:``,notice:``,statusText:``,messageId:``,userMessageId:``,finalizable:null,startedAt:Date.now(),endedAt:0,seq:0}}function Q(e,t){return e.seq+=1,`${t}-${e.seq}`}function bt(e,t){let n=J(t.type);gt.has(n)||(e.events.push({at:Date.now(),type:n,message:J(t.message),data:t.data===void 0?null:t.data}),e.events.length>_t&&e.events.splice(0,e.events.length-_t))}function $(e,{title:t,message:n,tone:r=`info`,data:i=null}){let a=e.blocks[e.blocks.length-1];if(a&&a.kind===`note`&&a.title===t&&a.message===J(n))return a;let o={kind:`note`,id:Q(e,`note`),title:t,message:Y(n),tone:r,data:i};return e.blocks.push(o),o}function xt(e,t,n=`thinking`){let r=J(t)||Q(e,`reasoning`),i=r?e.blocks.find(e=>e.kind===`reasoning`&&e.key===r):null;return i||(i={kind:`reasoning`,id:Q(e,`reason`),key:r,stream:J(t),label:n,text:``},e.blocks.push(i)),i}function St(e){let t=yt(e.argumentsObj);if(t&&Object.keys(t).length)return t;let n=e.arguments??e.argumentsObj??null;if(typeof n!=`string`)return n;if(!n.trim())return null;try{return JSON.parse(n)}catch{return n}}function Ct(e){return St(yt(e?.data)||{})}function wt(e){let t=yt(e?.data)||{};return X(t.resultPreview??t.result??t.error??e?.message,8e3)}function Tt({blocks:e,toolsByCallId:t},{toolCallId:n,toolName:r,agentName:i}){let a=e=>!i||!e.agentName||e.agentName===i,o=t.get(n)?.filter(a);return o?.length?o.find(e=>!e.hasResult)||o[o.length-1]:r?e.find(e=>e.kind===`tool`&&!e.hasResult&&e.toolName===r&&a(e)&&(!n||!e.toolCallId)):null}function Et(e){let t=J(e.displayStatus||e.status).toLowerCase();return t===`cancelled`||t===`canceled`?`cancelled`:t===`background_running`?`running`:t===`blocked`?`blocked`:e.isError===!0||e.success===!1?`failed`:`success`}function Dt(e,t,n,r,i,a){var o,s;let c={toolCallId:J(n.toolCallId),toolName:J(n.toolName),agentName:J(n.agentName)},l=St(n),u=t===`tool_result`,d=J(a),f=u?Tt(e,c):null;if(f?!u&&d&&!f.callDetailId&&(f.callDetailId=d):(f={kind:`tool`,id:i(`tool`),toolCallId:``,toolName:c.toolName,agentName:c.agentName,args:l,result:``,status:`running`,processDetailId:d,callDetailId:u?``:d,resultDetailId:u?d:``,argsDeferred:!!(!u&&n._argsDeferred&&d),resultDeferred:!1,hasDeferredPayload:!!(n._hasPayload||n._argsDeferred),hasResult:!1},e.blocks.push(f)),c.toolCallId&&!f.toolCallId){f.toolCallId=c.toolCallId;let t=e.toolsByCallId.get(f.toolCallId);t?t.push(f):e.toolsByCallId.set(f.toolCallId,[f])}if(!u){n._argsDeferred&&d&&(f.argsDeferred=!0,f.hasDeferredPayload=!0);return}f.hasResult=!0,(o=f).toolName||(o.toolName=c.toolName),(s=f).agentName||(s.agentName=c.agentName),d&&(f.resultDetailId=d),f.status=Et(n),l!==null&&(f.args===null||yt(f.args)&&!Object.keys(f.args).length)&&(f.args=l,f.argsDeferred=!1);let p=n.resultPreview??n.result??n.error??(J(r).trim()?r:void 0);p!=null&&J(p)!==``?(f.result=X(p,8e3),f.resultDeferred=!1):n._payloadDeferred&&n._hasPayload!==!1&&d&&(f.resultDeferred=!0,f.hasDeferredPayload=!0)}function Ot(e,t){if(!e||!t||typeof t!=`object`)return e;let n=J(t.type),r=yt(t.data)||{};switch(bt(e,t),n){case`heartbeat`:break;case`conversation`:r.conversationId&&(e.conversationId=J(r.conversationId));break;case`message_saved`:r.userMessageId&&(e.userMessageId=J(r.userMessageId));break;case`progress`:e.statusText=J(t.message)||e.statusText;break;case`iteration`:{let n=Number(r.iteration)||1,i=J(r.piScope).trim(),a=J(r.agentName).trim(),o=i===`main`?a?`主代理 · ${a}`:`主代理`:i===`sub`?`子代理${a?` · ${a}`:``}`:``;e.blocks.push({kind:`iteration`,id:Q(e,`iter`),title:`第 ${n} 轮迭代${o?` · ${o}`:``}`,message:Y(t.message,2e3)});break}case`thinking_stream_start`:case`reasoning_chain_stream_start`:{let t=xt(e,r.streamId,n===`reasoning_chain_stream_start`?`reasoning_chain`:`thinking`);t.text=``;break}case`thinking_stream_delta`:case`reasoning_chain_stream_delta`:{let i=xt(e,r.streamId,n===`reasoning_chain_stream_delta`?`reasoning_chain`:`thinking`),a=typeof r.accumulated==`string`?r.accumulated:null;i.text=Y(a===null?i.text+J(t.message):a);break}case`thinking`:case`reasoning_chain`:if(r.streamId){let i=xt(e,r.streamId,n===`reasoning_chain`?`reasoning_chain`:`thinking`);J(t.message)&&(i.text=Y(t.message));break}e.blocks.push({kind:`reasoning`,id:Q(e,`reason`),key:Q(e,`reasonkey`),stream:``,label:n===`reasoning_chain`?`reasoning_chain`:`thinking`,text:Y(t.message)});break;case`response_start`:r.conversationId&&(e.conversationId=J(r.conversationId)),e.statusText||(e.statusText=`正在生成回复…`);break;case`response_delta`:{let n=typeof r.accumulated==`string`?r.accumulated:null;e.text=Y(n===null?e.text+J(t.message):n,6e4);break}case`response`:{let n=J(t.message);n&&(e.text=Y(n,6e4)),r.messageId&&(e.messageId=J(r.messageId)),r.conversationId&&(e.conversationId=J(r.conversationId)),r.finalizable===!1?e.finalizable=!1:r.finalizable===!0&&(e.finalizable=!0);break}case`tool_call`:case`tool_result`:Dt(e,n,r,t.message,t=>Q(e,t),r.processDetailId);break;case`tool_calls_detected`:$(e,{title:`🔧 检测到工具调用`,message:t.message,data:r});break;case`hitl_interrupt`:$(e,{title:`🧑‍⚖️ 等待人工审批`,message:`${J(r.toolName)||`工具`} · ${J(t.message)||`命中审批策略`}`,tone:`warning`,data:r});break;case`hitl_resumed`:$(e,{title:`✅ 审批通过`,message:J(t.message),tone:`success`,data:r});break;case`hitl_rejected`:$(e,{title:`⛔ 审批被拒绝`,message:J(t.message),tone:`danger`,data:r});break;case`hitl_audit_agent_started`:$(e,{title:`🛡 审计代理审查中`,message:J(t.message),tone:`info`,data:r});break;case`hitl_audit_agent`:$(e,{title:`🛡 审计代理已裁决`,message:`${J(r.decision)||`-`}${r.comment?` · ${J(r.comment)}`:``}`,tone:`info`,data:r});break;case`warning`:case`iteration_limit_reached`:case`pi_pending_orphaned`:$(e,{title:`⚠️ ${J(t.message)||`提示`}`,message:J(t.message),tone:`warning`,data:r});break;case`finalization_check`:$(e,{title:`🔎 最终化校验未通过`,message:J(t.message),tone:`warning`,data:r}),r.finalizable===!1&&(e.finalizable=!1);break;case`finalization_auto_continue`:case`finalization_pending_tools_cancelled`:case`agent_empty_response_continue`:case`agent_run_retry`:case`pi_model_retry`:case`pi_model_failover`:case`pi_stream_error`:$(e,{title:J(t.message)||`运行提示`,message:J(t.message),tone:`warning`,data:r});break;case`agent_usage_summary`:e.blocks.push({kind:`usage`,id:Q(e,`usage`),data:r});break;case`user_interrupt_continue`:$(e,{title:`⏸️ 用户中断并继续`,message:J(t.message),tone:`info`,data:r});break;case`agent_reply`:$(e,{title:`💬 ${J(r.agentName)||`子代理`}回复`,message:J(t.message),data:r});break;case`workflow_start`:case`workflow_done`:case`workflow_node_start`:case`workflow_node_result`:case`workflow_branch_taken`:case`workflow_branch_skipped`:case`workflow_tool_start`:case`workflow_agent_output`:case`workflow_hitl_checkpoint`:case`workflow_hitl_waiting`:case`workflow_hitl_resumed`:case`workflow_hitl_rejected`:case`workflow_paused`:$(e,{title:`🧭 ${J(t.message)||n}`,message:J(t.message),data:r});break;case`cancelled`:e.status=`cancelled`,e.notice=J(t.message)||`任务已取消`,e.endedAt=Date.now();break;case`error`:e.status=`error`,e.error=J(t.message)||`执行失败`,e.endedAt=Date.now();break;case`done`:e.status===`streaming`&&(e.status=r.status===`blocked`||e.finalizable===!1?`blocked`:`done`),r.workflowStatus===`awaiting_hitl`&&(e.statusText=`工作流等待审批`),e.endedAt=Date.now()}return e}var kt={streaming:{label:`生成中`,color:`blue`},done:{label:`已完成`,color:`green`},blocked:{label:`未完成`,color:`orange`},disconnected:{label:`连接已结束`,color:`grey`},error:{label:`失败`,color:`red`},cancelled:{label:`已取消`,color:`grey`}};function At(e){let t=[],n={blocks:t,toolsByCallId:new Map},r=0,i=e=>(r+=1,`h-${e}-${r}`),a=J(e?.reasoningContent).trim();return a&&t.push({kind:`reasoning`,id:i(`reason`),key:`reasoningContent`,stream:``,label:`thinking`,text:Y(a)}),(Array.isArray(e?.processDetails)?e.processDetails:[]).forEach(e=>{let r=J(e?.eventType),a=yt(e?.data)||{},o=J(e?.message);switch(r){case`iteration`:{let e=Number(a.iteration)||1,n=J(a.piScope).trim(),r=J(a.agentName).trim();t.push({kind:`iteration`,id:i(`iter`),title:`第 ${e} 轮迭代${n===`main`?` · 主代理`:n===`sub`?` · 子代理`:``}${r?` · ${r}`:``}`,message:Y(o,2e3)});break}case`thinking`:case`reasoning_chain`:{let n=!!(a._payloadDeferred&&e?.id&&!o.trim());if(!o.trim()&&!n)break;t.push({kind:`reasoning`,id:i(`reason`),detailId:J(e?.id),key:J(a.streamId)||i(`reasonkey`),stream:J(a.streamId),label:r,text:n?``:Y(o),textLength:n?Number(a._textLength)||0:o.length,payloadDeferred:n});break}case`tool_call`:case`tool_result`:Dt(n,r,a,o,i,e?.id);break;case`planning`:if(!o.trim())break;t.push({kind:`note`,id:i(`note`),title:`📝 规划`,message:Y(o,4e3),tone:`info`,data:null});break;case`hitl_interrupt`:case`hitl_resumed`:case`hitl_rejected`:case`hitl_audit_agent`:case`hitl_audit_agent_started`:{let e=r===`hitl_rejected`?`danger`:r===`hitl_resumed`?`success`:`info`,n=r===`hitl_interrupt`?`🧑‍⚖️ 人工审批`:r===`hitl_rejected`?`⛔ 审批被拒绝`:r===`hitl_resumed`?`✅ 审批通过`:`🛡 审计代理`;t.push({kind:`note`,id:i(`note`),title:n,message:`${o}${a.toolName?` · ${J(a.toolName)}`:``}${a.decision?` · ${J(a.decision)}`:``}`,tone:e,data:null});break}case`error`:case`timeout`:case`cancelled`:t.push({kind:`note`,id:i(`note`),title:r===`cancelled`?`⏹ 已取消`:`❌ 执行异常`,message:o,tone:`danger`,data:null});break;case`agent_reply`:t.push({kind:`note`,id:i(`note`),title:`💬 子代理回复`,message:Y(o,6e3),tone:`info`,data:null});break;case`agent_usage_summary`:t.push({kind:`usage`,id:i(`usage`),data:a});break;case`progress`:break;default:(o.trim()||Object.keys(a).length)&&t.push({kind:`note`,id:i(`note`),title:J(r)||`过程事件`,message:Y(o,4e3),tone:`info`,data:Object.keys(a).length?a:null})}}),t}var{Text:jt}=u,Mt={running:{color:`blue`,label:`执行中`},success:{color:`green`,label:`完成`},failed:{color:`red`,label:`失败`},cancelled:{color:`grey`,label:`已取消`},blocked:{color:`orange`,label:`已拦截`}};function Nt(e){return Array.isArray(e)?e.includes(`1`):e===`1`}function Pt({block:e,defaultOpen:t}){let[n,r]=(0,W.useState)(!!t),[i,a]=(0,W.useState)(``),[o,s]=(0,W.useState)(!1),[c,l]=(0,W.useState)(``),u=(0,W.useRef)(null),d=e.text||i,f=d?d.length:Number(e.textLength)||0,p=!!(e.payloadDeferred&&e.detailId&&!d),m=(0,W.useCallback)(async()=>{if(!e.detailId)return;u.current?.abort();let t=new AbortController;u.current=t,s(!0),l(``);try{let n=await z.get(`/process-details/${encodeURIComponent(e.detailId)}`,null,{signal:t.signal});if(t.signal.aborted)return;let r=n?.processDetail;a(String(r?.message||``))}catch(e){t.signal.aborted||l(ke(e,`加载思考过程失败`))}finally{u.current===t&&(u.current=null,s(!1))}},[e.detailId]);(0,W.useEffect)(()=>()=>u.current?.abort(),[]),(0,W.useEffect)(()=>{n&&p&&!o&&!c&&m()},[n,p,o,c,m]);let h=(0,W.useMemo)(()=>n&&d?Y(d):``,[n,d]);if(!d.trim()&&!e.payloadDeferred)return null;let g=e.label===`reasoning_chain`?`🔗 推理过程`:`🤔 思考过程`;return(0,G.jsx)(M,{className:`chat-block-collapse`,activeKey:n?[`1`]:[],onChange:e=>r(Nt(e)),children:(0,G.jsxs)(M.Panel,{itemKey:`1`,header:(0,G.jsxs)(`span`,{className:`chat-block-title`,children:[g,` · `,f,` 字符`]}),children:[n&&o&&(0,G.jsxs)(`div`,{className:`chat-tool-loading`,children:[(0,G.jsx)(E,{size:`small`}),(0,G.jsx)(`span`,{children:`正在加载思考过程…`})]}),n&&c&&(0,G.jsxs)(`div`,{className:`chat-tool-error`,children:[(0,G.jsx)(`span`,{children:c}),(0,G.jsx)(`button`,{type:`button`,className:`chat-link-btn`,onClick:()=>void m(),children:`重试`})]}),n&&h&&(0,G.jsx)(`pre`,{className:`chat-pre`,children:h})]})})}function Ft({block:e,index:t,total:n}){let{t:r}=_e(),[i,a]=(0,W.useState)(!1),[o,s]=(0,W.useState)(void 0),[c,l]=(0,W.useState)(void 0),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)(``),m=(0,W.useRef)(null),h=Mt[e.status]||Mt.running,g=o===void 0?e.args:o,_=c===void 0?e.result||``:c,y=!!(e.argsDeferred&&e.callDetailId&&o===void 0),b=!!(e.resultDeferred&&e.resultDetailId&&c===void 0),x=!!(g!=null&&g!==``||_||y||b||e.hasDeferredPayload),S=(0,W.useCallback)(async()=>{let t=[];if(y&&e.callDetailId&&t.push({kind:`args`,id:e.callDetailId}),b&&e.resultDetailId&&t.push({kind:`result`,id:e.resultDetailId}),!t.length)return;m.current?.abort();let n=new AbortController;m.current=n,d(!0),p(``);try{let e=await Promise.all(t.map(async e=>{let t=await z.get(`/process-details/${encodeURIComponent(e.id)}`,null,{signal:n.signal});return{kind:e.kind,detail:t?.processDetail||null}}));if(n.signal.aborted)return;for(let t of e)t.kind===`args`?s(Ct(t.detail)):t.kind===`result`&&l(wt(t.detail))}catch(e){n.signal.aborted||p(ke(e,`加载工具详情失败`))}finally{m.current===n&&(m.current=null,d(!1))}},[e.callDetailId,e.resultDetailId,y,b]);(0,W.useEffect)(()=>()=>m.current?.abort(),[]),(0,W.useEffect)(()=>{i&&(y||b)&&!u&&!f&&S()},[i,y,b,u,f,S]);let C=(0,W.useMemo)(()=>i?X(g):``,[i,g]),w=i?_:``,T=e.toolName||r(`chat.unknownTool`,null,`未知工具`),D=(0,G.jsxs)(`span`,{className:`chat-tool-head`,children:[(0,G.jsxs)(`span`,{className:`chat-tool-name`,children:[e.agentName?`${e.agentName} · `:``,r(`chat.callTool`,{name:T,index:t,total:n},`调用工具: ${T} (${t}/${n})`)]}),(0,G.jsx)(v,{size:`small`,color:h.color,shape:`circle`,children:h.label})]});return x?(0,G.jsx)(`div`,{className:`chat-tool`,children:(0,G.jsx)(M,{className:`chat-block-collapse`,activeKey:i?[`1`]:[],onChange:e=>a(Nt(e)),children:(0,G.jsxs)(M.Panel,{itemKey:`1`,header:D,children:[i&&u&&(0,G.jsxs)(`div`,{className:`chat-tool-loading`,children:[(0,G.jsx)(E,{size:`small`}),(0,G.jsx)(`span`,{children:`正在加载工具详情…`})]}),i&&f&&(0,G.jsxs)(`div`,{className:`chat-tool-error`,children:[(0,G.jsx)(`span`,{children:f}),(0,G.jsx)(`button`,{type:`button`,className:`chat-link-btn`,onClick:()=>void S(),children:`重试`})]}),i&&C&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(jt,{type:`tertiary`,size:`small`,children:`参数`}),(0,G.jsx)(`pre`,{className:`chat-pre`,children:C})]}),i&&w&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(jt,{type:`tertiary`,size:`small`,children:`结果`}),(0,G.jsx)(`pre`,{className:`chat-pre`,children:w})]})]})})}):(0,G.jsx)(`div`,{className:`chat-tool`,children:(0,G.jsx)(`div`,{className:`chat-tool-head-row`,children:D})})}function It({block:e}){let[t,n]=(0,W.useState)(!1),r=e.tone||`info`;return(0,G.jsxs)(`div`,{className:`chat-note chat-note-${r}`,children:[(0,G.jsxs)(`div`,{className:`chat-note-head`,children:[(0,G.jsx)(`span`,{className:`chat-note-title`,children:e.title}),e.data&&(0,G.jsx)(`button`,{type:`button`,className:`chat-link-btn`,onClick:()=>n(!t),children:t?`收起 JSON`:`查看 JSON`})]}),e.message&&(0,G.jsx)(`div`,{className:`chat-note-body`,children:e.message}),t&&e.data&&(0,G.jsx)(Ee,{value:e.data,collapsed:!1,title:`事件数据`})]})}function Lt({data:e}){let{t,lang:n}=_e(),r=e=>I(Math.max(0,Math.trunc(Number(e)||0)),n),i=[[`chat.piUsageModelCalls`,e.modelCalls],[`chat.piUsagePromptTokens`,e.promptTokens],[`chat.piUsageCompletionTokens`,e.completionTokens],[`chat.piUsageTotalTokens`,e.totalTokens]],a=[[`chat.piUsageCachedTokens`,e.cachedTokens],[`chat.piUsageCacheWriteTokens`,e.cacheWriteTokens],[`chat.piUsageReasoningTokens`,e.reasoningTokens]],o=[...i,...a.filter(([,e])=>Number(e)>0)].map(([e,n])=>`${t(e)}: ${r(n)}`).join(` +`),s=Number(e.totalTokens),c=[e.agentName,t(`chat.piUsageSummaryTitle`),Number.isFinite(s)&&s>0?r(s):``].filter(Boolean).join(` · `);return(0,G.jsx)(It,{block:{title:c,message:o,data:e}})}function Rt({events:e}){return!e||!e.length?null:(0,G.jsx)(M,{className:`chat-block-collapse chat-event-log`,children:(0,G.jsx)(M.Panel,{itemKey:`1`,header:(0,G.jsxs)(`span`,{className:`chat-block-title`,children:[`🧾 原始事件 · `,e.length,` 条`]}),children:(0,G.jsx)(`pre`,{className:`chat-pre`,children:e.map((e,t)=>`${t+1}. ${JSON.stringify(e)}`).join(` +`)})})})}var zt=(0,W.memo)(function({text:e,blocks:t,events:n,streaming:r=!1,openReasoning:i=!1,isAssistant:a=!1}){let{t:o}=_e(),s=Array.isArray(t)?t:[],c=e||``,l=s.filter(e=>e.kind===`tool`).length,u=0;return(0,G.jsxs)(`div`,{className:`chat-turn-body`,children:[s.map(e=>e.kind===`reasoning`?(0,G.jsx)(Pt,{block:e,defaultOpen:i},e.id):e.kind===`tool`?(u+=1,(0,G.jsx)(Ft,{block:e,index:u,total:l},e.id)):e.kind===`iteration`?(0,G.jsx)(`div`,{className:`chat-iteration`,children:(0,G.jsx)(`span`,{className:`chat-iteration-label`,children:e.title})},e.id):e.kind===`note`?(0,G.jsx)(It,{block:e},e.id):e.kind===`usage`?(0,G.jsx)(Lt,{data:e.data},e.id):null),(0,G.jsx)(Rt,{events:n}),c.trim()&&(a&&!r?(0,G.jsx)(`section`,{className:`chat-task-summary`,"aria-label":o(`chat.taskSummary`),"data-chat-summary":!0,children:(0,G.jsxs)(`details`,{open:!0,children:[(0,G.jsx)(`summary`,{className:`chat-task-summary-title`,children:o(`chat.taskSummary`)}),(0,G.jsx)(`div`,{className:`chat-task-summary-content`,children:(0,G.jsx)(be,{content:c})})]},c.length)}):r?(0,G.jsx)(`pre`,{className:`chat-pre chat-stream-text`,children:c}):(0,G.jsx)(be,{content:c})),!c.trim()&&r&&(0,G.jsx)(`div`,{className:`chat-stream-placeholder`,children:`正在生成…`})]})}),{Paragraph:Bt,Text:Vt}=u,Ht=40,Ut=40;function Wt(e){let t=String(e||``);return t.length<=128?t:`${t.length}:${t.slice(0,64)}:${t.slice(-64)}`}function Gt(){let e=R();return(0,G.jsx)(`div`,{className:`chat-welcome`,children:(0,G.jsx)(c,{image:(0,G.jsx)(`span`,{className:`chat-welcome-mark`,"aria-hidden":`true`,children:(0,G.jsx)(he,{size:`extra-large`})}),title:e(`chat.welcomeHeading`,null,`让安全探索,从对话开始`),description:(0,G.jsx)(Bt,{type:`tertiary`,className:`chat-welcome-description`,children:e(`chat.welcomeScopeDescription`,null,`描述测试目标与授权范围,或上传相关材料,即可开始对话。`)})})})}function Kt(e,t,n){let[r,i]=(0,W.useState)(()=>Date.now());if((0,W.useEffect)(()=>{if(!n)return;let e=setInterval(()=>i(Date.now()),1e3);return()=>clearInterval(e)},[n]),!e)return``;let a=Math.max(0,Math.round(((n?r:t||e)-e)/1e3));return a<60?`${a}s`:`${Math.floor(a/60)}m${a%60}s`}var qt=(0,W.memo)(function({message:e,canDelete:t,onDeleteTurn:n}){let r=R(),i=e.role===`user`,a=e.role===`system`,o=(0,W.useMemo)(()=>At(e),[e]),s=e.createdAt?L(e.createdAt):``,c=String(e.content||``);return a?(0,G.jsx)(`div`,{className:`chat-system-row`,children:(0,G.jsx)(Vt,{type:`tertiary`,children:c})},e.id):(0,G.jsxs)(`div`,{className:`chat-msg ${i?`chat-msg-user`:`chat-msg-assistant`}`,children:[(0,G.jsx)(f,{size:`small`,color:i?`grey`:`blue`,className:`chat-avatar`,"aria-hidden":`true`,children:i?(0,G.jsx)(D,{}):`AI`}),(0,G.jsxs)(`div`,{className:`chat-bubble`,children:[(0,G.jsxs)(`div`,{className:`chat-bubble-head`,children:[(0,G.jsx)(`span`,{className:`chat-bubble-role`,children:i?r(`chat.you`,null,`我`):r(`chat.assistant`,null,`助手`)}),s&&(0,G.jsx)(`span`,{className:`chat-bubble-time`,children:s}),(0,G.jsxs)(`span`,{className:`chat-bubble-actions`,children:[!i&&c&&(0,G.jsx)(we,{text:c,size:`small`}),t&&i&&e.id&&(0,G.jsx)(P,{content:r(`chat.deleteTurnTitle`,null,`删除本轮`),children:(0,G.jsx)(x,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,G.jsx)(_,{}),"aria-label":r(`chat.deleteTurnTitle`,null,`删除本轮`),onClick:()=>n(e)})})]})]}),c||o.length>0?(0,G.jsx)(zt,{text:c,blocks:o,events:null,isAssistant:!i}):(0,G.jsx)(Vt,{type:`tertiary`,children:`—`})]})]},e.id)});function Jt({live:e}){let t=R(),n=kt[e.status]||kt.streaming,r=Kt(e.startedAt,e.endedAt,e.status===`streaming`);return(0,G.jsxs)(`div`,{className:`chat-msg chat-msg-assistant chat-msg-live`,children:[(0,G.jsx)(f,{size:`small`,color:`blue`,className:`chat-avatar`,children:`AI`}),(0,G.jsxs)(`div`,{className:`chat-bubble`,children:[(0,G.jsxs)(`div`,{className:`chat-bubble-head`,children:[(0,G.jsx)(`span`,{className:`chat-bubble-role`,children:t(`chat.assistant`,null,`助手`)}),(0,G.jsx)(v,{size:`small`,color:n.color,shape:`circle`,children:n.label}),r&&(0,G.jsx)(`span`,{className:`chat-bubble-time`,children:r}),e.statusText&&(0,G.jsx)(`span`,{className:`chat-live-status`,children:e.statusText})]}),(0,G.jsx)(zt,{isAssistant:!0,text:e.text,blocks:e.blocks,events:e.events,streaming:e.status===`streaming`,openReasoning:e.status===`streaming`}),e.error&&(0,G.jsx)(`div`,{className:`chat-live-error`,children:e.error}),e.notice&&(0,G.jsx)(`div`,{className:`chat-live-notice`,children:e.notice}),e.finalizable===!1&&(0,G.jsx)(`div`,{className:`chat-live-notice`,children:`本轮回复未通过最终化校验,内容可能不完整。`})]})]})}function Yt({conversationId:e,messages:t,live:n,loading:r,error:i,onRetry:a,canDelete:o,onDeleteTurn:s}){let c=R(),l=(0,W.useRef)(null),u=(0,W.useRef)(!0),d=(0,W.useRef)(``),[f,p]=(0,W.useState)(!0),[m,h]=(0,W.useState)(Ht),g=Array.isArray(t)?t:[],_=Math.max(0,g.length-m),v=(0,W.useMemo)(()=>_>0?g.slice(_):g,[g,_]),y=g[g.length-1],b=Wt(y?.content),S=`${g.length}:${y?.id||``}:${b}:${y?.processDetails?.length||0}`,C=n?n.status!==`streaming`&&n.text.trim()?`live:${e}:${n.messageId||n.id}:${Wt(n.text)}`:``:!r&&y?.role===`assistant`&&String(y.content||``).trim()?`history:${e}:${y.id}:${b}`:``,w=(0,W.useMemo)(()=>{if(!n)return S;let e=n.blocks.map(e=>`${e.kind}:${e.id}:${e.text?e.text.length:0}:${e.status||``}`).join(`|`);return`${S}#${n.id}#${n.status}#${n.text.length}#${e}`},[S,n]),T=(0,W.useCallback)((e=!1)=>{let t=l.current;t&&t.scrollTo({top:t.scrollHeight,behavior:e?`smooth`:`auto`})},[]),D=(0,W.useCallback)((e=!1)=>{let t=l.current;if(!t)return;let n=t.querySelectorAll(`.chat-msg`),r=n[n.length-1]?.querySelector(`[data-chat-summary]`);if(!r){T(e);return}let i=r.getBoundingClientRect().top-t.getBoundingClientRect().top+t.scrollTop-12;t.scrollTo({top:Math.max(0,i),behavior:e?`smooth`:`auto`})},[T]),O=(0,W.useCallback)(()=>{let e=l.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<120;u.current=t,p(t)},[]);return(0,W.useEffect)(()=>{u.current=!0,d.current=``,p(!0),h(Ht);let e=setTimeout(()=>D(!1),30);return()=>clearTimeout(e)},[e,D]),(0,W.useEffect)(()=>{n?.id&&(u.current=!0)},[n?.id]),(0,W.useEffect)(()=>{if(r)return;let e=C&&d.current!==C;e&&(d.current=C),(e||u.current)&&D(!1)},[w,C,r,D]),e||n||g.length?(0,G.jsxs)(`div`,{className:`chat-message-wrap`,children:[(0,G.jsxs)(`div`,{className:`chat-messages`,ref:l,onScroll:O,children:[(0,G.jsx)(H,{error:i,onRetry:a}),r&&(0,G.jsx)(`div`,{className:`chat-loading`,children:(0,G.jsx)(E,{size:`middle`})}),!r&&!g.length&&!n&&(0,G.jsx)(Gt,{}),!r&&_>0&&(0,G.jsxs)(`div`,{className:`chat-history-more`,children:[(0,G.jsx)(x,{size:`small`,theme:`light`,onClick:()=>h(e=>e+Ut),children:c(`chat.loadEarlierMessages`,{count:Math.min(Ut,_)},`显示更早的 ${Math.min(Ut,_)} 条消息`)}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,onClick:()=>h(g.length),children:c(`chat.showAllMessages`,{total:g.length},`显示全部(共 ${g.length} 条)`)})]}),v.map(e=>(0,G.jsx)(qt,{message:e,canDelete:o,onDeleteTurn:s},e.id)),n&&(0,G.jsx)(Jt,{live:n}),i&&!r&&(0,G.jsx)(x,{icon:(0,G.jsx)(de,{}),theme:`borderless`,onClick:a,className:`chat-retry-inline`,children:c(`common.refresh`,null,`刷新`)})]}),!f&&(0,G.jsx)(x,{className:`chat-scroll-bottom`,icon:(0,G.jsx)(ce,{}),size:`small`,theme:`solid`,onClick:()=>{u.current=!0,p(!0),T(!0)},children:c(`chat.returnToLatest`,null,`回到底部`)})]}):(0,G.jsx)(`div`,{className:`chat-message-wrap`,children:(0,G.jsx)(`div`,{className:`chat-messages`,ref:l,children:(0,G.jsx)(Gt,{})})})}var{Text:Xt}=u,Zt=[`single`,`deep`,`plan_execute`,`supervisor`],Qt=`__create_project__`;function $t({value:e,onChange:t,onSend:r,onStop:i,canStop:a,sending:s,checkingRun:c,canWrite:l,canExecute:u,mode:f,onModeChange:p,projectId:g,onProjectChange:_,onCreateProject:y,projects:b,projectDisabled:C,role:w,onRoleChange:T,roles:E,roleDisabled:O,model:k,canReadConfig:ee,onOpenHitl:j,attachments:re,onPickFiles:ie,onRemoveAttachment:ae,uploading:M}){let N=R(),ce=n(),le=(0,W.useRef)(null),de=(0,W.useId)(),F=(0,W.useId)(),fe=(0,W.useId)(),pe=Array.isArray(re)?re:[],he=pe.some(e=>String(e?.mimeType||``).startsWith(`image/`)||/\.(?:png|jpe?g|gif|webp|bmp)$/i.test(String(e?.fileName||``))),I=(0,W.useMemo)(()=>[{value:`single`,title:N(`chat.agentModePiSingle`,null,`单代理`),description:N(`chat.agentModePiSingleHint`,null,`使用设置中选择的 Pi 或兼容运行时执行单代理任务`)},{value:`deep`,title:N(`chat.agentModeDeep`,null,`Deep(DeepAgent)`),description:N(`chat.agentModeDeepHint`,null,`Pi 多代理,适合复杂安全测试、多阶段 task 子代理委派与汇总`)},{value:`plan_execute`,title:N(`chat.agentModePlanExecuteLabel`,null,`Plan-Execute`),description:N(`chat.agentModePlanExecuteHint`,null,`规划 → 执行 → 重规划(单执行器带工具)`)},{value:`supervisor`,title:N(`chat.agentModeSupervisorLabel`,null,`Supervisor(专家路由)`),description:N(`chat.agentModeSupervisorHint`,null,`专家路由场景:监督者通过 transfer 动态分派多个专业子代理`)}].map(({value:e,title:t,description:n})=>({value:e,title:t,label:(0,G.jsxs)(`span`,{className:`chat-mode-option`,children:[(0,G.jsx)(`span`,{children:t}),(0,G.jsx)(`span`,{className:`chat-mode-option-description`,children:n})]})})),[N]),L=[{value:``,label:N(`chat.defaultWorkspace`,null,`默认工作区`)},...Re(b,N,{currentId:g,disableCurrentArchived:!0,fallbackLabel:N(`chat.boundProject`,null,`已绑定项目`)})];g&&!L.some(e=>e.value===g)&&L.push({value:g,label:N(`chat.boundProject`,null,`已绑定项目`)}),y&&L.push({value:Qt,label:`+ ${N(`projects.newProject`,null,`新建项目`)}`});let ge=(0,W.useMemo)(()=>{let e=(Array.isArray(E)?E:[]).filter(e=>e?.name),t=e.filter(e=>e.enabled!==!1&&e.name!==`默认`).sort((e,t)=>e.name.localeCompare(t.name,`zh-CN`)),n=e.find(e=>e.name===`默认`),r=e=>({value:e.name===`默认`?``:e.name,name:e.name===`默认`?N(`chat.defaultRole`,null,`默认`):e.name,icon:e.icon||``,description:e.description||``,label:(0,G.jsxs)(`span`,{className:`chat-role-option`,children:[(0,G.jsxs)(`span`,{className:`chat-role-option-title`,children:[e.icon?(0,G.jsx)(`span`,{className:`chat-role-icon`,"aria-hidden":`true`,children:e.icon}):null,(0,G.jsx)(`span`,{children:e.name===`默认`?N(`chat.defaultRole`,null,`默认`):e.name})]}),e.description?(0,G.jsx)(`span`,{className:`chat-role-option-description`,children:e.description}):null]})}),i=[r({name:`默认`,icon:n?.icon||``,description:n?.description||``})],a=new Set([``]);for(let e of t)a.has(e.name)||(a.add(e.name),i.push(r(e)));if(w&&!a.has(w)){let t=e.find(e=>e.name===w);i.push(r(t||{name:w,icon:``,description:``}))}return i},[w,E,N]),z=ge.find(e=>e.value===(w||``))||ge[0],_e=Number(M)||pe.filter(e=>e.uploading).length,B=!l||!u,ve=s||c,ye=k.channel||k.config.data?.default_channel,V=ye?U(ye,k.config.data?.channels?.[ye]):N(`chat.aiChannelDefaultShort`,null,`默认通道`),be=k.overrideBlocked?Xe(N,`default`,``):Xe(N,k.mode,k.effort);return(0,G.jsxs)(`div`,{className:`chat-composer`,children:[B&&(0,G.jsx)(o,{type:`warning`,bordered:!0,closeIcon:null,className:`chat-composer-banner`,description:l?N(`chat.noExecutePermission`,null,`当前账号没有智能体执行权限(agent:execute),发送已禁用。`):N(`chat.noWritePermission`,null,`当前账号没有对话写入权限(chat:write),发送已禁用。`)}),(0,G.jsx)(`div`,{className:`chat-composer-shell`,children:(0,G.jsxs)(`div`,{className:`chat-composer-box`,children:[(0,G.jsxs)(`div`,{className:`chat-composer-context`,children:[(0,G.jsx)(`span`,{id:de,hidden:!0,children:N(`chat.agentModeSelectAria`,null,`选择对话执行模式`)}),(0,G.jsx)(me,{value:f,optionList:I,renderSelectedItem:e=>(0,G.jsx)(`span`,{title:e.title,children:e.title}),onChange:p,prefix:(0,G.jsx)(m,{"aria-hidden":`true`}),className:`chat-context-select chat-composer-mode`,dropdownClassName:`chat-mode-dropdown`,size:`small`,position:`topLeft`,"aria-labelledby":de,disabled:ve||B}),(0,G.jsx)(`span`,{className:`chat-context-divider`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{id:F,hidden:!0,children:N(`chat.chooseWorkspace`,null,`选择会话工作区`)}),(0,G.jsx)(me,{value:g,optionList:L,onChange:e=>{e===Qt?y?.():_(e)},prefix:(0,G.jsx)(oe,{"aria-hidden":`true`}),className:`chat-context-select chat-composer-project`,dropdownClassName:`chat-project-dropdown`,dropdownMatchSelectWidth:!1,position:`topLeft`,size:`small`,renderSelectedItem:e=>(0,G.jsx)(`span`,{title:e.label,children:e.label}),"aria-labelledby":F,disabled:ve||C||!l}),T&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`chat-context-divider`,"aria-hidden":`true`}),(0,G.jsx)(`span`,{id:fe,hidden:!0,children:N(`chat.selectRole`,null,`选择角色`)}),(0,G.jsx)(me,{value:w||``,optionList:ge,onChange:T,prefix:z?.icon?(0,G.jsx)(`span`,{className:`chat-role-icon`,"aria-hidden":`true`,children:z.icon}):(0,G.jsx)(D,{"aria-hidden":`true`}),className:`chat-context-select chat-composer-role`,dropdownClassName:`chat-role-dropdown`,dropdownMatchSelectWidth:!1,position:`topLeft`,size:`small`,renderSelectedItem:e=>(0,G.jsx)(`span`,{title:e.description||e.name,children:e.name}),"aria-labelledby":fe,disabled:ve||O||!l})]})]}),(0,G.jsx)(`input`,{ref:le,type:`file`,multiple:!0,hidden:!0,onChange:e=>{e.target.files?.length&&ie(Array.from(e.target.files)),e.target.value=``}}),pe.length>0&&(0,G.jsx)(`div`,{className:`chat-file-list`,children:pe.map(e=>(0,G.jsxs)(v,{className:`chat-file-chip ${e.error?`is-error`:``} ${e.uploading?`is-uploading`:``}`,size:`large`,color:e.error?`red`:e.uploading?`amber`:`blue`,closable:!0,onClose:()=>ae(e.id),children:[(0,G.jsx)(se,{size:`small`}),(0,G.jsx)(`span`,{className:`chat-file-name`,title:e.fileName,children:e.fileName}),(0,G.jsx)(`span`,{className:`chat-file-state`,children:e.uploading?`上传中…`:e.error?`上传失败`:`已上传`})]},e.id))}),he&&ee&&!k.config.loading&&k.vision?.nativeMode!==`enabled`&&(0,G.jsxs)(`div`,{className:`chat-image-vision-tip${k.vision?.ready?` is-ready`:``}`,children:[(0,G.jsx)(`span`,{children:k.vision?.ready?`已启用独立视觉模型(${k.vision.model}),若当前模型不支持图片输入将自动通过 analyze_image 识图。`:`若当前对话模型不支持识别图片,可开启独立「视觉分析模型」代为识图(或为支持识图的通道启用原生图片输入)。`}),(0,G.jsx)(`button`,{type:`button`,className:`chat-vision-entry-link`,onClick:()=>ce(`/settings?section=models&focus=vision`),children:k.vision?.ready?`切换视觉模型`:`去开启视觉模型`})]}),(0,G.jsx)(S,{className:`chat-textarea`,borderless:!0,value:e,onChange:t,onKeyDown:e=>{e.key!==`Enter`||e.shiftKey||e.nativeEvent?.isComposing||(e.preventDefault(),ve||B||O||_e>0||r())},disabled:B,autosize:{minRows:2,maxRows:8},"aria-label":N(`chat.composerLabel`,null,`对话内容`),placeholder:N(`chat.composerPlaceholder`,null,`描述目标、授权范围与需求,或附上相关材料…`)}),(0,G.jsxs)(`div`,{className:`chat-composer-toolbar`,children:[(0,G.jsxs)(`div`,{className:`chat-composer-controls`,children:[(0,G.jsx)(P,{content:N(`chat.selectFile`,null,`选择附件`),children:(0,G.jsx)(x,{icon:(0,G.jsx)(ne,{}),theme:`borderless`,type:`tertiary`,"aria-label":N(`chat.attachmentsLabel`,null,`附件`),disabled:B,onClick:()=>le.current?.click()})}),(0,G.jsx)(x,{icon:(0,G.jsx)(te,{}),theme:`borderless`,type:`tertiary`,className:`chat-composer-hitl`,"aria-label":N(`chat.hitlTitle`,null,`人机协同`),disabled:!j,onClick:j,children:N(`chat.hitlTitle`,null,`人机协同`)})]}),(0,G.jsxs)(`div`,{className:`chat-composer-submit`,children:[(0,G.jsx)(h,{trigger:`click`,position:`topRight`,className:`chat-model-popover`,condition:!ve,content:(0,G.jsx)(ut,{model:k,busy:ve||B,canReadConfig:ee}),children:(0,G.jsxs)(x,{theme:`borderless`,type:`tertiary`,className:`chat-composer-model`,"aria-label":N(`chat.modelSettingsAria`,null,`选择 AI 通道、模型与推理设置`),title:`${V} · ${be}`,disabled:ve,children:[(0,G.jsx)(`span`,{className:`chat-composer-model-name`,children:V}),(0,G.jsx)(`span`,{className:`chat-composer-effort`,children:be}),(0,G.jsx)(d,{size:`small`})]})}),s?(0,G.jsx)(x,{type:`danger`,className:`chat-composer-send`,icon:(0,G.jsx)(ue,{}),"aria-label":N(`chat.stop`,null,`停止`),onClick:i,disabled:!a}):(0,G.jsx)(P,{content:N(`chat.sendHint`,null,`Enter 发送 · Shift+Enter 换行`),children:(0,G.jsx)(x,{theme:`solid`,className:`chat-composer-send`,icon:(0,G.jsx)(A,{}),"aria-label":N(`chat.send`,null,`发送`),disabled:B||c||O||_e>0,onClick:r})})]})]}),_e>0&&(0,G.jsx)(Xt,{type:`tertiary`,size:`small`,role:`status`,children:N(`chat.waitingAttachmentsUpload`,null,`附件上传中…`)})]})})]})}var{Text:en}=u,tn={approval:`仅审批`,feedback:`审批并反馈`,followup:`审批并追问`,review_edit:`审查编辑`};function nn(e){if(!e)return null;let t=e.payload;if(typeof t==`string`)try{t=JSON.parse(t)}catch{t=null}t&&typeof t==`object`||(t={});let n=t.argumentsObj&&typeof t.argumentsObj==`object`?t.argumentsObj:t.arguments||null;return{...e,payload:t,interruptId:String(e.id||e.interruptId||``),toolName:String(e.toolName||t.toolName||`未知工具`),mode:String(e.mode||t.mode||`approval`).toLowerCase(),args:n}}function rn({item:e,busy:t,readOnly:n,onApprove:r,onReject:i,onDismiss:o}){let s=R(),c=(0,W.useMemo)(()=>nn(e),[e]),[u,d]=(0,W.useState)(``);if(!c)return null;let f=X(c.args,4e3),m=tn[c.mode]||c.mode,h=n||t||!c.interruptId;return(0,G.jsxs)(l,{className:`chat-hitl-card`,bordered:!0,title:(0,G.jsxs)(`span`,{className:`chat-hitl-title`,children:[(0,G.jsx)(`span`,{children:s(`chat.hitlTitle`,null,`人工审批`)}),(0,G.jsx)(v,{size:`small`,color:`orange`,shape:`circle`,children:m}),(0,G.jsx)(`span`,{className:`chat-hitl-tool`,children:c.toolName})]}),headerExtraContent:(0,G.jsx)(en,{type:`tertiary`,size:`small`,children:c.createdAt?L(c.createdAt):``}),children:[(0,G.jsxs)(`div`,{className:`chat-hitl-meta`,children:[c.reviewer&&(0,G.jsxs)(en,{type:`tertiary`,size:`small`,children:[`审批人:`,c.reviewer===`audit_agent`?`审计代理`:`人工`]}),c.expiresAt&&(0,G.jsxs)(en,{type:`tertiary`,size:`small`,children:[`到期:`,L(c.expiresAt)]}),c.conversationId&&(0,G.jsxs)(en,{type:`tertiary`,size:`small`,children:[`会话:`,String(c.conversationId).slice(0,8)]})]}),f&&(0,G.jsx)(M,{className:`chat-block-collapse`,children:(0,G.jsx)(M.Panel,{itemKey:`1`,header:(0,G.jsx)(`span`,{className:`chat-block-title`,children:`调用参数`}),children:(0,G.jsx)(`pre`,{className:`chat-pre`,children:f})})}),(0,G.jsxs)(`div`,{className:`chat-hitl-actions`,children:[(0,G.jsx)(C,{size:`small`,placeholder:s(`chat.hitlComment`,null,`审批备注(拒绝时建议填写原因)`),disabled:n,value:u,onChange:d,className:`chat-hitl-comment`}),(0,G.jsxs)(p,{children:[(0,G.jsx)(x,{theme:`solid`,size:`small`,icon:(0,G.jsx)(a,{}),disabled:h,onClick:()=>r(c,u),children:s(`chat.hitlApprove`,null,`批准`)}),(0,G.jsx)(x,{type:`danger`,size:`small`,icon:(0,G.jsx)(T,{}),disabled:h,onClick:()=>i(c,u),children:s(`chat.hitlReject`,null,`拒绝`)}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,disabled:h,onClick:()=>o(c),children:s(`chat.hitlDismiss`,null,`忽略`)})]})]})]})}var{Text:an}=u;function on({items:e,busyId:t,readOnly:n,onRefresh:r,onDecide:i,onDismiss:a}){let o=R(),s=Array.isArray(e)?e:[];return s.length?(0,G.jsxs)(`div`,{className:`chat-hitl-dock`,children:[(0,G.jsxs)(`div`,{className:`chat-hitl-dock-head`,children:[(0,G.jsx)(an,{strong:!0,children:o(`chat.pendingApprovals`,{count:s.length},`待审批 ${s.length}`)}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,icon:(0,G.jsx)(de,{}),onClick:r})]}),s.map(e=>(0,G.jsx)(rn,{item:e,readOnly:n,busy:t===String(e.id||e.interruptId),onApprove:(e,t)=>i(e,`approve`,t),onReject:(e,t)=>i(e,`reject`,t),onDismiss:a},e.id||e.interruptId))]}):null}var{Text:sn}=u,cn={pending:{color:`grey`,label:`待处理`},in_progress:{color:`blue`,label:`进行中`},completed:{color:`green`,label:`已完成`},blocked:{color:`orange`,label:`阻塞`},deleted:{color:`grey`,label:`已删除`}};function ln({plan:e,loading:t,onRefresh:n}){let r=R(),i=Array.isArray(e?.tasks)?e.tasks.filter(e=>String(e.status||``).toLowerCase()!==`deleted`):[],a=Number(e?.total)||i.length,o=Number(e?.completed)||i.filter(e=>e.status===`completed`).length,s=a?Math.round(o/a*100):0;return(0,G.jsxs)(`div`,{className:`chat-plan`,children:[(0,G.jsxs)(`div`,{className:`chat-plan-toolbar`,children:[(0,G.jsx)(sn,{type:`tertiary`,size:`small`,children:e?.running?r(`chat.planRunning`,null,`任务执行中`):r(`chat.planIdle`,null,`当前没有运行中的任务`)}),(0,G.jsx)(x,{size:`small`,icon:(0,G.jsx)(de,{}),onClick:n,loading:t,children:r(`common.refresh`,null,`刷新`)})]}),(0,G.jsx)(re,{percent:s,showInfo:!0}),(0,G.jsx)(sn,{type:`tertiary`,size:`small`,children:r(`chat.planSummary`,{total:a,done:o},`共 ${a} 项,已完成 ${o} 项`)}),!i.length&&(0,G.jsx)(c,{title:r(`chat.planEmpty`,null,`暂无执行计划`),description:r(`chat.planEmptyHint`,null,`代理调用任务工具后,这里会显示任务看板。`),style:{padding:24}}),(0,G.jsx)(`div`,{className:`chat-plan-list`,children:i.map((e,t)=>{let n=String(e.status||`pending`).toLowerCase(),r=cn[n]||cn.pending;return(0,G.jsxs)(`div`,{className:`chat-plan-item ${n===`in_progress`?`is-active`:``}`,children:[(0,G.jsxs)(`div`,{className:`chat-plan-item-head`,children:[(0,G.jsx)(`span`,{className:`chat-plan-index`,children:t+1}),(0,G.jsx)(`span`,{className:`chat-plan-subject`,children:e.subject||e.activeForm||`—`}),(0,G.jsx)(v,{size:`small`,color:r.color,shape:`circle`,children:r.label})]}),e.description&&(0,G.jsx)(`div`,{className:`chat-plan-desc`,children:e.description})]},e.id||t)})})]})}function un({visible:e,onClose:t,plan:n,loading:r,onRefresh:i}){let a=R()(`chat.planTasks`,null,`执行计划`);return(0,G.jsx)(le,{title:a,"aria-label":a,visible:e,onCancel:t,width:`min(100%, 560px)`,placement:`right`,children:(0,G.jsx)(ln,{plan:n,loading:r,onRefresh:i})})}function dn({conversationRef:e,bindConversation:t,requestDetailReload:n,onTaskStarted:r,onSettled:i,onHitlEvent:a,onPlanTool:o,t:s}){let[c,l]=(0,W.useState)(null),[u,d]=(0,W.useState)(!1),[f,p]=(0,W.useState)([]),m=(0,W.useRef)(null),h=(0,W.useRef)(null),g=(0,W.useRef)(null),_=(0,W.useRef)(null),v=(0,W.useCallback)(()=>{_.current&&(clearTimeout(_.current),_.current=null)},[]),y=(0,W.useCallback)((e=!1)=>{let t=()=>{g.current=null,m.current&&l({...m.current})};e?(g.current&&(clearTimeout(g.current),g.current=null),t()):g.current||(g.current=setTimeout(t,80))},[]),b=(0,W.useCallback)(t=>{if(!t||t.markedFinished||h.current!==t)return;t.markedFinished=!0,v(),t.live.status===`streaming`&&(t.live.status=t.live.error?`error`:`done`,t.live.endedAt=Date.now()),y(!0),i?.(),d(!1),p(t.live.events.slice(-80));let r=t.live.conversationId||e.current;r?Promise.resolve(n?.(r,{silent:!0})).then(e=>{h.current===t&&e&&(h.current=null,m.current=null,l(null))}):(h.current=null,m.current=null,l(null))},[v,e,y,i,n]);return{live:c,sending:u,lastEvents:f,send:(0,W.useCallback)(({message:n,attachments:i,mode:c,projectId:u,role:f,aiChannelId:g,reasoning:x,hitl:S,requireHumanApproval:C})=>{v();let w={live:Z({conversationId:e.current}),markedFinished:!1,stopRequested:!1,abort:null};h.current=w,m.current=w.live,l({...w.live}),d(!0),p([]),_.current=setTimeout(()=>{_.current=null,!w.markedFinished&&h.current===w&&r?.()},200);let T=c!==`single`,E={message:n,conversationId:e.current||``,aiChannelId:g,reasoning:x,hitl:S,requireHumanApproval:C||void 0};!e.current&&u&&(E.projectId=u),f&&(E.role=f),T&&(E.orchestration=c),Array.isArray(i)&&i.length&&(E.attachments=i.map(e=>({fileName:e.fileName,mimeType:e.mimeType||``,serverPath:e.serverPath}))),w.abort=ve(T?`/multi-agent/stream`:`/agent/stream`,E,{onEvent(n){if(w.markedFinished||h.current!==w)return;Ot(w.live,n);let r=n?.type;if(r===`conversation`&&n?.data?.conversationId){let r=String(n.data.conversationId);w.live.conversationId=r,e.current!==r&&t?.(r)}(r===`hitl_interrupt`||r===`hitl_resumed`||r===`hitl_rejected`)&&a?.(),(r===`tool_call`||r===`tool_result`)&&ht.has(String(n?.data?.toolName||``).toLowerCase())&&o?.(),r===`done`||r===`error`||r===`cancelled`?b(w):y()},onError(e){w.markedFinished||h.current!==w||(w.live.status=`error`,w.live.error=ke(e,s(`chat.streamFailed`,null,`流式连接失败`)),w.live.endedAt=Date.now(),b(w))},onClose(){w.markedFinished||h.current!==w||(w.live.status=`disconnected`,w.live.endedAt=Date.now(),w.stopRequested||(w.live.notice=s(`chat.streamEndedWithoutDone`,null,`连接提前结束,未收到任务完成信号。任务可能仍在后端执行。`),B(w.live.notice)),b(w))}})},[t,v,e,b,y,a,o,r,s]),stop:(0,W.useCallback)(async(t=``)=>{let r=h.current,i=typeof t==`string`?t.trim():``,a=r&&!r.markedFinished&&(r.live?.conversationId||e.current)||``,o=i||e.current||a||``,c=!(!r||r.markedFinished||i&&o!==a);if(o)try{await z.post(`/agent-loop/cancel`,{conversationId:o}),c&&r&&(r.stopRequested=!0),De(s(`chat.stopRequested`,null,`已请求停止任务`))}catch(e){B(ke(e,s(`chat.stopFailed`,null,`停止请求失败`)))}c&&r?.abort?.(),setTimeout(()=>{o&&e.current===o&&n?.(o,{silent:!0,force:!0})},900)},[e,n,s]),reset:(0,W.useCallback)(()=>{v();let e=h.current;e&&!e.markedFinished&&e.abort?.(),h.current=null,m.current=null,g.current&&(clearTimeout(g.current),g.current=null),l(null),d(!1),p([])},[]),isStreaming:(0,W.useCallback)(e=>{let t=h.current;return!!(t&&!t.markedFinished&&e&&t.live.conversationId===e)},[])}}function fn({t:e,conversationRef:t,newProjectId:n,canWrite:r,reloadList:i,requestDetailReload:a,navigate:o,onSelectionCleared:s}){return{createConversation:(0,W.useCallback)(async()=>{if(r)try{let t=(await z.post(`/conversations`,{title:e(`chat.newChat`,null,`新对话`),projectId:n||void 0}))?.id;i(),t&&o({conversation:t}),De(e(`chat.created`,null,`已创建对话`))}catch(t){V(t,e(`chat.createFailed`,null,`创建对话失败`))}},[r,o,n,i,e]),renameConversation:(0,W.useCallback)(async(n,r)=>{try{await z.put(`/conversations/${encodeURIComponent(n)}`,{title:r}),De(e(`chat.renamed`,null,`已重命名`)),i(),n===t.current&&a(n,{silent:!0})}catch(t){V(t,e(`chat.renameFailed`,null,`重命名失败`))}},[t,i,a,e]),togglePin:(0,W.useCallback)(async t=>{try{await z.put(`/conversations/${encodeURIComponent(t.id)}/pinned`,{pinned:!t.pinned}),i()}catch(t){V(t,e(`chat.pinFailed`,null,`置顶操作失败`))}},[i,e]),deleteConversation:(0,W.useCallback)(async n=>{try{await z.del(`/conversations/${encodeURIComponent(n.id)}`),De(e(`chat.deleted`,null,`已删除对话`)),n.id===t.current&&(s(),o({},{replace:!0})),i()}catch(t){V(t,e(`chat.deleteFailed`,null,`删除对话失败`))}},[t,o,s,i,e]),batchDelete:(0,W.useCallback)(async n=>{let r=(await Promise.allSettled(n.map(e=>z.del(`/conversations/${encodeURIComponent(e)}`)))).filter(e=>e.status===`rejected`).length;r?B(e(`chat.batchDeletePartial`,{failed:r},`有 ${r} 个对话删除失败`)):De(e(`chat.batchDeleted`,{count:n.length},`已删除 ${n.length} 个对话`)),n.includes(t.current)&&(s(),o({},{replace:!0})),i()},[t,o,s,i,e]),deleteTurn:(0,W.useCallback)(n=>{let r=t.current;r&&n?.id&&Oe({title:e(`chat.deleteTurnTitle`,null,`删除本轮`),content:e(`chat.deleteTurnConfirm`,null,`将删除该轮提问与全部回答,删除后不可恢复。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await z.post(`/conversations/${encodeURIComponent(r)}/delete-turn`,{messageId:n.id}),De(e(`chat.turnDeleted`,null,`已删除该轮`)),await a(r,{silent:!0}),i()}catch(t){V(t,e(`chat.deleteTurnFailed`,null,`删除轮次失败`))}}})},[t,i,a,e])}}var{Text:pn}=u,mn=20,hn=`__none__`,gn=`csai-chat-agent-mode`,_n=`csai-chat-role`;function vn(e){let t=typeof e==`string`?e.trim():``;return!t||t===`默认`?``:t}var yn={tasks:[],total:0,completed:0,activeStep:0,running:!1},bn={conversation:null,messages:[],loading:!1,error:null};function xn(e){let[t,n]=(0,W.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(e).matches);return(0,W.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(e),r=e=>n(e.matches);return n(t.matches),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function Sn(){let e=R(),{hasPermission:t}=ge(),n=t(`chat:write`),r=t(`project:write`),a=t(`agent:execute`),o=t(`chat:delete`),s=t(`tasks:read`),c=t(`tasks:write`),l=t(`hitl:read`),u=t(`hitl:write`),d=t(`config:read`),f=t(`roles:read`),[p,m]=i(),h=p.get(`conversation`)||``,g=(0,W.useRef)(h),_=(0,W.useRef)(null);(0,W.useLayoutEffect)(()=>{g.current=h},[h]);let[v,y]=(0,W.useState)(``),b=Ce(v,350),[S,C]=(0,W.useState)(``),[w,T]=(0,W.useState)(hn),[E,D]=(0,W.useState)(!0),[O,k]=(0,W.useState)(1),[ee,te]=(0,W.useState)(``),[A,j]=(0,W.useState)(!1),[ne,ie]=(0,W.useState)(!1),[ae,oe]=xe(gn,`single`),N=Zt.includes(ae)?ae:`single`,[se,ce]=xe(_n,``),[P,ue]=(0,W.useState)(()=>new Map),de=(0,W.useRef)(``),F=$e(d),[fe,pe]=(0,W.useState)(!1),[me,he]=(0,W.useState)(null),[I,L]=(0,W.useState)(bn),[_e,ve]=(0,W.useState)(()=>new Map),{draft:be=``,attachments:Se=[]}=_e.get(h)||{},H=(0,W.useCallback)((e,t)=>{ve(n=>{let r=new Map(n);return r.set(e,t(n.get(e)||{})),r})},[]),we=e=>H(h,t=>({...t,draft:e})),[Ee,Oe]=(0,W.useState)(null),ke=l&&Ee?.id===h?Ee.items:[],[Fe,Ie]=(0,W.useState)(``),[U,Le]=(0,W.useState)(yn),[Re,Be]=(0,W.useState)(!1),[Ve,He]=(0,W.useState)(!1),[We,Ge]=(0,W.useState)(!1),Ke=xn(`(max-width: 900px)`),Je=(0,W.useRef)(0),Ye=(0,W.useRef)(null),Xe=(0,W.useRef)({id:``,active:!1}),Ze=(0,W.useRef)(0),Qe=(0,W.useRef)(0),[et,tt]=(0,W.useState)(()=>new Set),nt=ye(async({signal:e}={})=>{let t=await z.get(`/agent-loop/tasks`,null,{signal:e}),n=Array.isArray(t?.tasks)?t.tasks.filter(Boolean):[];return{checkedId:h,tasks:n}},[h,s],{skip:!s}),rt=(0,W.useRef)(nt.reload);(0,W.useEffect)(()=>{rt.current=nt.reload},[nt.reload]);let it=(0,W.useMemo)(()=>s&&Array.isArray(nt.data?.tasks)?nt.data.tasks:[],[nt.data,s]),K=!!(s&&h&&it.some(e=>e.conversationId===h&&!ze.has(String(e.status||``).toLowerCase()))),at=!!(s&&h&&nt.data?.checkedId!==h&&!nt.error),ot=(0,W.useRef)(null),q=ye(async({signal:e}={})=>({...await z.get(`/conversations`,{limit:mn,offset:(O-1)*mn,search:b||void 0,project_id:w,group_by_project:1},{signal:e}),projectGroup:w,page:O,search:b}),[O,b,w]),st=(0,W.useRef)(q.reload);(0,W.useEffect)(()=>{st.current=q.reload},[q.reload]);let ct=ye(({signal:e}={})=>z.get(`/projects`,{limit:200},{signal:e}),[]),lt=ye(({signal:e}={})=>z.get(`/roles`,null,{signal:e}),[f],{skip:!f}),ut=(0,W.useMemo)(()=>Array.isArray(ct.data?.projects)?ct.data.projects:[],[ct.data]),ft=(0,W.useMemo)(()=>(Array.isArray(lt.data?.roles)?lt.data.roles:[]).filter(e=>e&&String(e.name||``).trim()).map(e=>({name:String(e.name).trim(),description:String(e.description||``),icon:String(e.icon||``),enabled:e.enabled!==!1})),[lt.data]),pt=e=>{ie(!1),e?.id&&(ct.setData(t=>({...t,projects:[e,...t?.projects||[]]})),Dt(e.id))},ht=Array.isArray(q.data?.projectGroups)?q.data.projectGroups:[],gt=q.data?.projectGroup===w&&q.data?.search===b,_t=gt&&q.data?.page===O,vt=_t&&Array.isArray(q.data.conversations)?q.data.conversations:[],J=gt&&q.data.total||0;(0,W.useEffect)(()=>{if(!_t)return;let e=Math.max(1,Math.ceil(J/mn));O>e&&k(e)},[_t,J,O]);let yt=(0,W.useCallback)(e=>{T(e),D(!0),k(1)},[]),Y=(0,W.useCallback)(async(e,{silent:t=!1,force:n=!1}={})=>{if(!e)return Ye.current?.abort(),Ye.current=null,Xe.current={id:``,active:!1},L(bn),null;if(t&&!n&&Xe.current.active&&Xe.current.id===e)return null;Ye.current?.abort();let r=new AbortController;Ye.current=r,Xe.current={id:e,active:!0};let i=++Je.current;t||L(e=>({...e,loading:!0,error:null}));try{let t=await z.get(`/conversations/${encodeURIComponent(e)}`,{include_process_details:`summary`},{signal:r.signal});return r.signal.aborted||i!==Je.current||g.current!==e?null:(L({conversation:t||null,messages:Array.isArray(t?.messages)?t.messages:[],loading:!1,error:null}),t)}catch(t){return r.signal.aborted||i===Je.current&&g.current===e&&L(e=>({...e,loading:!1,error:t})),null}finally{Ye.current===r&&(Ye.current=null,Xe.current={id:``,active:!1})}},[]);(0,W.useEffect)(()=>()=>{Ye.current?.abort(),Ye.current=null,Xe.current={id:``,active:!1}},[]);let X=(0,W.useCallback)(async()=>{let e=g.current,t=++Ze.current;if(e&&l)try{let n=await z.get(`/hitl/pending`,{conversationId:e,pageSize:50});if(t!==Ze.current||g.current!==e)return;let r=(Array.isArray(n?.items)?n.items:[]).filter(t=>!t.conversationId||t.conversationId===e);Oe({id:e,items:r})}catch{}},[l]),Z=(0,W.useCallback)(async()=>{let e=g.current;if(!e){Le(yn);return}let t=++Qe.current;Be(!0);try{let n=await z.get(`/conversations/${encodeURIComponent(e)}/plan-tasks`);t===Qe.current&&g.current===e&&Le(n&&typeof n==`object`?n:yn)}catch{}finally{t===Qe.current&&g.current===e&&Be(!1)}},[]),Q=dn({conversationRef:g,bindConversation:(0,W.useCallback)(e=>{he(null),_.current=e,g.current=e,ue(t=>{if(t.has(e))return t;let n=new Map(t);return n.set(e,de.current),n}),m({conversation:e},{replace:!0}),st.current?.({silent:!0})},[m]),requestDetailReload:Y,onTaskStarted:(0,W.useCallback)(()=>{rt.current?.({silent:!0,force:!0})},[]),onSettled:(0,W.useCallback)(()=>{rt.current?.({silent:!0,force:!0}),st.current?.({silent:!0}),X(),Z()},[X,Z]),onHitlEvent:X,onPlanTool:Z,t:e}),{live:bt,sending:$,lastEvents:xt,reset:St,isStreaming:Ct}=Q;(0,W.useEffect)(()=>{let e=h&&_.current===h;_.current=null,e||Ct(h)||(St(),Ye.current?.abort(),Ye.current=null,Xe.current={id:``,active:!1},Je.current++,Ze.current++,Qe.current++,L(bn),Oe(null),Ie(``),Le(yn),Be(!1),He(!1),h&&(Y(h),X(),Z()))},[h,Ct,St,Y,X,Z]),Te(()=>{typeof document<`u`&&document.hidden||(($||K)&&(X(),Z()),s&&rt.current?.({silent:!0}),K&&!$&&g.current&&Y(g.current,{silent:!0}))},$||K||it.length>0?4e3:s?6e3:0),(0,W.useEffect)(()=>{if(!s||typeof document>`u`)return;let e=()=>{document.hidden||rt.current?.({silent:!0})};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[s]),(0,W.useEffect)(()=>{ot.current===h&&!K&&(Y(h,{silent:!0,force:!0}),st.current?.({silent:!0}),X(),Z()),ot.current=K?h:null},[K,h,Y,X,Z]);let wt=(0,W.useCallback)(async(e=``)=>{if(!c)return;let t=typeof e==`string`?e.trim():``,n=t||g.current||bt?.conversationId||``;n&&tt(e=>{let t=new Set(e);return t.add(n),t});try{await Q.stop(t),await rt.current?.({silent:!0,force:!0}),st.current?.({silent:!0}),X(),Z(),setTimeout(()=>{rt.current?.({silent:!0,force:!0}),st.current?.({silent:!0}),X(),Z()},950)}finally{n&&tt(e=>{if(!e.has(n))return e;let t=new Set(e);return t.delete(n),t})}},[c,bt?.conversationId,X,Z,Q]),Tt=(0,W.useCallback)(e=>{e&&(e!==g.current&&m({conversation:e}),Ge(!1))},[m]),Et=(0,W.useCallback)(()=>{st.current?.({silent:!0})},[]),Dt=async t=>{if(!n||$||K||at||A)return;let r=t||``,i=g.current;if(!i)te(r);else if(!(I.conversation?.id!==i||I.loading||I.error)){j(!0);try{await z.put(`/conversations/${encodeURIComponent(i)}/project`,{projectId:r}),L(e=>e.conversation?.id===i?{...e,conversation:{...e.conversation,projectId:r}}:e),S&&S!==r||yt(r||hn),Et()}catch(t){V(t,e(`chat.projectChangeFailed`,null,`更新对话所属项目失败`))}finally{j(!1)}}},{createConversation:Ot,renameConversation:kt,togglePin:At,deleteConversation:jt,batchDelete:Mt,deleteTurn:Nt}=fn({t:e,conversationRef:g,newProjectId:ee,canWrite:n,reloadList:Et,requestDetailReload:Y,navigate:m,onSelectionCleared:(0,W.useCallback)(()=>L(bn),[])}),Pt=(0,W.useCallback)(async(t,n,r)=>{let i=g.current;if(u&&t?.interruptId&&Ee?.id===i&&Ee.items.some(e=>String(e.id||e.interruptId)===t.interruptId)){Ie(t.interruptId);try{await z.post(`/hitl/decision`,{interruptId:t.interruptId,decision:n,comment:r||``}),De(n===`approve`?e(`chat.hitlApproved`,null,`已批准本次调用`):e(`chat.hitlRejected`,null,`已拒绝本次调用`)),Oe(e=>e?.id===i?{id:i,items:e.items.filter(e=>String(e.id||e.interruptId)!==t.interruptId)}:e)}catch(t){V(t,e(`chat.hitlDecisionFailed`,null,`提交审批失败`))}finally{g.current===i&&(Ie(``),X())}}},[Ee,u,X,e]),Ft=(0,W.useCallback)(async t=>{let n=g.current;if(u&&t?.interruptId&&Ee?.id===n&&Ee.items.some(e=>String(e.id||e.interruptId)===t.interruptId)){Ie(t.interruptId);try{await z.post(`/hitl/dismiss`,{interruptId:t.interruptId}),De(e(`chat.hitlDismissed`,null,`已忽略该审批`)),Oe(e=>e?.id===n?{id:n,items:e.items.filter(e=>String(e.id||e.interruptId)!==t.interruptId)}:e)}catch(t){V(t,e(`chat.hitlDismissFailed`,null,`忽略审批失败`))}finally{g.current===n&&(Ie(``),X())}}},[Ee,u,X,e]),It=(0,W.useCallback)(async t=>{let n=g.current,r=e=>H(n,t=>({...t,attachments:e(t.attachments||[])})),i=t.map((e,t)=>({id:`att-${Date.now()}-${t}`,fileName:e.name,mimeType:e.type||``,serverPath:``,uploading:!0,error:!1}));r(e=>[...e,...i]),await Promise.all(i.map(async(i,a)=>{let o=new FormData;o.append(`file`,t[a]),n&&o.append(`conversationId`,n);try{let e=await z.post(`/chat-uploads`,o),t=String(e?.absolutePath||``).trim();if(!t)throw Error(`服务端未返回文件路径`);r(e=>e.map(e=>e.id===i.id?{...e,serverPath:t,uploading:!1,error:!1}:e))}catch(t){r(e=>e.map(e=>e.id===i.id?{...e,uploading:!1,error:!0}:e)),V(t,e(`chat.attachmentUploadFailed`,{name:i.fileName},`附件 ${i.fileName} 上传失败`))}}))},[H,e]),Lt=(0,W.useCallback)(e=>{H(h,t=>({...t,attachments:(t.attachments||[]).filter(t=>t.id!==e)}))},[h,H]),Rt=P.has(h),zt=I.conversation?.id===h?I.conversation:null,Bt=!h||Rt||!!zt,Vt=Rt?vn(P.get(h)):zt?vn(zt.roleName):h?``:vn(se),Ht=(0,W.useCallback)(e=>{let t=vn(e);ce(t),ue(e=>{let n=new Map(e);return n.set(h,t),n})},[h,ce]),Ut=(0,W.useCallback)(()=>{if(!n||!a||$||K||at||A||F.waitingForChannel||!Bt)return;let t=be.trim();if(!t&&!Se.length){B(e(`chat.emptyMessage`,null,`请输入内容或添加附件`));return}if(Se.some(e=>e.uploading)){B(e(`chat.waitingAttachmentsUpload`,null,`附件仍在上传,请稍候`));return}let r=Se.filter(e=>e.serverPath&&!e.error);if(Se.length&&r.length!==Se.length){B(e(`chat.attachmentsUploadIncomplete`,null,`存在上传失败的附件,请移除后再发送`));return}let i=t||e(`chat.filePrompt`,null,`请解析我上传的附件。`),o=r.length?`${i}\n${r.map(e=>`📎 ${e.fileName}`).join(` +`)}`:i;L(e=>({...e,messages:[...e.messages||[],{id:`local-${Date.now()}`,role:`user`,content:o,createdAt:new Date().toISOString()}]})),St(),H(h,()=>({draft:``,attachments:[]})),de.current=Vt,Q.send({message:i,attachments:r,mode:N,projectId:ee,role:Vt,...F.request,hitl:!h&&u&&me||void 0})},[Se,K,n,a,u,at,h,be,me,N,F,ee,A,St,Vt,Bt,Q,$,e,H]),Wt=(0,W.useRef)(new Set),Gt=(0,W.useRef)(``),Kt=(0,W.useRef)(``);(0,W.useEffect)(()=>{if(!h)return;let t=Ae(h);if(!t)return;let r=String(t.prompt||``).trim();if(!r){je(h);return}if(I.error||!n||!a){Gt.current!==h&&(Gt.current=h,je(h),B(e(`vulnerabilityRetest.startFailed`,null,`复测尚未成功发送,提示词已保存在分支中,请返回该分支继续。`)));return}if($||K||at||!Bt||I.conversation?.id!==h)return;je(h);let i=g.current;Wt.current.add(i),H(i,e=>({...e,draft:``,attachments:[]})),L(e=>e.conversation?.id===i?{...e,messages:[...e.messages||[],{id:`local-${Date.now()}`,role:`user`,content:r,createdAt:new Date().toISOString()}]}:e),St(),Q.send({message:r,mode:N,role:Vt,...F.request})},[h,I.conversation,I.error,$,K,at,Bt,n,a,N,F,St,Vt,Q,e,H]),(0,W.useEffect)(()=>{if(h)return;let e=Me();if(!e)return;let t=String(e.prompt||``).trim();t?$||K||at||F.waitingForChannel||!Bt||(Ne(),n&&a&&e.autoSend!==!1?(L(e=>({...e,messages:[...e.messages||[],{id:`local-${Date.now()}`,role:`user`,content:t,createdAt:new Date().toISOString()}]})),St(),H(``,()=>({draft:``,attachments:[]})),de.current=Vt,Q.send({message:t,mode:N,projectId:ee,role:Vt,...F.request,hitl:u&&me||void 0})):H(``,e=>({...e,draft:t}))):Ne()},[h,$,K,at,F,Bt,n,a,u,me,N,ee,St,Vt,Q,H]),(0,W.useEffect)(()=>{let e=I.conversation,t=String(e?.retest?.pending_prompt||``).trim();h&&e?.id===h&&t&&(Wt.current.has(h)||Ae(h)||$||K||String(be||``).trim()||Kt.current!==h&&(Kt.current=h,H(h,e=>({...e,draft:t}))))},[h,I.conversation,be,$,K,H]);let qt=I.conversation,Jt=(0,W.useRef)(``);(0,W.useEffect)(()=>{if(!h){Jt.current=``;return}if(qt?.id!==h||Jt.current===h)return;Jt.current=h;let e=qt.projectId||hn;S&&S!==e||w===e&&E||yt(e)},[qt,h,E,yt,S,w]);let Xt=ht.find(e=>!e.projectId)?.total||0,Qt=[{id:hn,title:e(`chat.defaultWorkspace`,null,`默认工作区`),total:Xt},...ht.filter(e=>e.projectId).map(t=>({id:t.projectId,title:ut.find(e=>e.id===t.projectId)?.name||e(`chat.boundProject`,null,`已绑定项目`),total:t.total,projectId:t.projectId}))],en=(0,G.jsx)(mt,{items:E?vt:[],groups:Qt.filter(e=>!S||e.id===S),expandedGroup:E?w:``,groupTotal:J,onToggleGroup:e=>{e===w&&E?D(!1):e===w?D(!0):yt(e)},loading:q.loading||!_t&&!q.error,error:q.error,onRetry:()=>q.reload(),search:v,onSearch:e=>{y(e),k(1)},projectId:S,onProjectChange:e=>{C(e||``),yt(e||hn)},projects:ut,page:O,pageSize:mn,onPageChange:k,selectedId:h,onSelect:Tt,onCreate:Ot,onRename:kt,onPin:At,onDelete:jt,onBatchDelete:Mt,canWrite:n,canDelete:o}),tn=(0,W.useCallback)(()=>h?Y(h,{force:!0}):null,[h,Y]);return(0,G.jsxs)(`div`,{className:`chat-page`,children:[!Ke&&(0,G.jsx)(`aside`,{className:`chat-sidebar`,children:en}),(0,G.jsxs)(`section`,{className:`chat-main`,children:[(0,G.jsx)(qe,{conversation:qt,mode:N,hitlCount:ke.length,conversationId:h,narrow:Ke,onToggleSidebar:()=>Ge(!0),onRefresh:()=>{rt.current?.({silent:!0,force:!0}),st.current?.(),h&&Y(h),X(),Z()}}),(0,G.jsxs)(`div`,{className:`chat-panel`,children:[(0,G.jsx)(Ue,{tasks:it,currentConversationId:h,currentConversationTitle:qt?.id===h?qt?.title:``,canStop:c,stoppingIds:et,onSelect:Tt,onStop:wt}),(0,G.jsx)(Yt,{conversationId:h,messages:I.messages,live:bt,loading:I.loading||!(!h||I.conversation||I.error),error:I.error,onRetry:tn,canDelete:o,onDeleteTurn:Nt}),U.running&&U.total>0&&(0,G.jsxs)(`div`,{className:`chat-plan-strip`,children:[(0,G.jsx)(pn,{size:`small`,children:e(`chat.planTasks`,null,`执行计划`)}),(0,G.jsx)(re,{percent:Math.round(Number(U.completed||0)/Math.max(1,Number(U.total))*100),showInfo:!1,size:`small`,className:`chat-plan-strip-bar`}),(0,G.jsxs)(pn,{size:`small`,type:`tertiary`,children:[U.completed,`/`,U.total,U.activeStep?` · ${e(`chat.planStep`,{step:U.activeStep},`第 ${U.activeStep} 步`)}`:``]}),(0,G.jsx)(x,{size:`small`,theme:`borderless`,onClick:()=>{Z(),He(!0)},children:e(`chat.planDetails`,null,`详情`)})]}),xt.length>0&&!bt&&(0,G.jsx)(M,{className:`chat-events-strip`,children:(0,G.jsx)(M.Panel,{itemKey:`1`,header:`${e(`chat.rawEvents`,null,`本轮原始事件`)} · ${xt.length}`,children:(0,G.jsx)(`pre`,{className:`chat-pre`,children:xt.map((e,t)=>`${t+1}. ${JSON.stringify(e)}`).join(` +`)})})}),(0,G.jsx)(on,{items:ke,readOnly:!u,busyId:Fe,onRefresh:X,onDecide:Pt,onDismiss:Ft}),(0,G.jsx)($t,{value:be,onChange:we,onSend:Ut,onStop:()=>wt(),canStop:c,sending:$||K,checkingRun:at||A||F.waitingForChannel,canWrite:n,canExecute:a,mode:N,onModeChange:e=>oe(Zt.includes(e)?e:`single`),projectId:h?qt?.projectId||``:ee,onProjectChange:Dt,onCreateProject:r&&n&&!ct.loading?()=>ie(!0):void 0,projects:ut,projectDisabled:ct.loading||!(!h||!I.loading&&qt&&!I.error),role:Vt,onRoleChange:Ht,roles:ft,roleDisabled:!Bt,model:F,canReadConfig:d,onOpenHitl:l?()=>pe(!0):void 0,attachments:Se,onPickFiles:It,onRemoveAttachment:Lt,uploading:Se.filter(e=>e.uploading).length})]})]}),ne&&(0,G.jsx)(Pe,{visible:!0,onCancel:()=>ie(!1),onSaved:pt}),fe&&l&&(0,G.jsx)(dt,{onClose:()=>pe(!1),narrow:Ke,canEnableHitl:u,conversationId:h,draftHitl:h?null:me,onDraftHitlChange:he},h),(0,G.jsx)(le,{visible:Ke&&We,placement:`left`,width:300,onCancel:()=>Ge(!1),title:e(`chat.conversations`,null,`会话列表`),bodyStyle:{padding:0},children:en}),(0,G.jsx)(un,{visible:Ve,onClose:()=>He(!1),plan:U,loading:Re,onRefresh:Z})]})}export{Sn as default}; \ No newline at end of file diff --git a/web/static/app/assets/dashboard-8XvRuqLB.js b/web/static/app/assets/dashboard-Dwi74cCO.js similarity index 99% rename from web/static/app/assets/dashboard-8XvRuqLB.js rename to web/static/app/assets/dashboard-Dwi74cCO.js index 852d185a..14162f96 100644 --- a/web/static/app/assets/dashboard-8XvRuqLB.js +++ b/web/static/app/assets/dashboard-Dwi74cCO.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,u as i,y as a}from"./react-QV7DAAIx.js";import{B as o,C as s,E as c,G as l,I as u,Kt as d,N as f,R as p,Zt as m,at as h,et as g,g as _,qt as v,tn as y,ut as b,y as x,zt as S}from"./semi-65W_4I1v.js";import{A as C,D as w,E as T,F as E,L as D,O as ee,_ as O,a as k,h as A,l as j,m as M,p as te,r as ne,w as N}from"./index-CAEPLS-g.js";var P=e(t(),1),F=e(r(),1),I=[`严重`,`高危`,`中危`,`低危`,`信息`],L=[[0,`safe`,`Safe`,`安全`],[3,`low`,`Low`,`低`],[10,`medium`,`Medium`,`中`],[30,`high`,`High`,`高`],[1/0,`severe`,`Severe`,`极高`]],R=[[`open`,`Open`,`待处理`],[`confirmed`,`Confirmed`,`已确认`],[`fixed`,`Fixed`,`已修复`],[`ignored`,`Ignored`,`已忽略`],[`false_positive`,`FalsePositive`,`误报`]];function z(e){return e[0].toUpperCase()+e.slice(1)}function B(e){if(e==null||e===``||![`number`,`string`].includes(typeof e))return null;let t=Number(e);return Number.isFinite(t)&&t>=0?t:null}function V(e){let t=B(e);return t===null?`—`:w(t)}function H(e,t){let n=e?.by_severity;return!n||typeof n!=`object`||Array.isArray(n)?null:B(n[t]??0)}function U(e,t){let n=new URLSearchParams;e&&n.set(`severity`,e),t&&n.set(`status`,t);let r=n.toString();return`/vulnerabilities`+(r?`?`+r:``)}function W(e,t){let n=(e,t)=>`${(210+e*Math.cos(t)).toFixed(3)} ${(201-e*Math.sin(t)).toFixed(3)}`;return`M ${n(188,e)} A 188 188 0 0 1 ${n(188,t)} L ${n(137,t)} A 137 137 0 0 0 ${n(137,e)} Z`}function G(e,t){if(!t)return[];let n=[],r=Math.PI;for(let i of e){if(!i.count)continue;let e=Math.PI*i.count/t,a=r-e,o=Math.min(.014,e/5);n.push({...i,d:W(r-o,a+o)}),r=a}return n}function K({rows:e,total:t,status:n,loading:r,t:a}){let o=(0,P.useId)(),[s,c]=(0,P.useState)(``),[l,u]=(0,P.useState)(``),d=s||l,f=e.find(e=>e.key===d),p=r?`…`:V(f?f.count:t),m=G(e,t),h=e=>({onPointerEnter:()=>c(e),onPointerLeave:()=>c(``),onFocus:()=>u(e),onBlur:()=>u(``)});return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:`dashboard-severity-chart`,children:[(0,F.jsxs)(`svg`,{viewBox:`0 0 420 217`,role:`group`,"aria-label":a(`dashboard.severityDistribution`,null,`漏洞严重程度分布`),children:[(0,F.jsx)(`defs`,{children:e.map(e=>(0,F.jsxs)(`linearGradient`,{id:o+e.key,x1:`12%`,y1:`0%`,x2:`84%`,y2:`100%`,"data-severity":e.key,children:[(0,F.jsx)(`stop`,{offset:`0%`,stopColor:`var(--severity-light)`}),(0,F.jsx)(`stop`,{offset:`100%`,stopColor:`var(--severity-color)`})]},e.key))}),(0,F.jsx)(`path`,{className:`dashboard-ring-track`,d:W(Math.PI,0)}),m.map(e=>(0,F.jsxs)(i,{to:U(e.key,n),className:`dashboard-ring-link`,"data-severity":e.key,"aria-label":`${e.label} · ${V(e.count)}`,"data-muted":!!(d&&e.key!==d),...h(e.key),children:[(0,F.jsx)(`title`,{children:`${e.label} · ${V(e.count)} (${e.percent}%)`}),(0,F.jsx)(`path`,{d:e.d,fill:`url(#${o+e.key})`})]},e.key))]}),(0,F.jsxs)(`div`,{className:`dashboard-ring-center`,"data-severity":f?.key,children:[(0,F.jsx)(`strong`,{children:p}),(0,F.jsx)(`span`,{children:f?.label||a(`dashboard.totalVulns`,null,`总漏洞数`)})]})]}),(0,F.jsx)(`div`,{className:`dashboard-severity-legend`,children:e.map(e=>(0,F.jsxs)(i,{className:`dashboard-severity-item`,"data-severity":e.key,"data-active":d===e.key,to:U(e.key,n),...h(e.key),children:[(0,F.jsx)(`span`,{className:`dashboard-severity-dot`,"aria-hidden":`true`}),(0,F.jsx)(`span`,{className:`dashboard-severity-name`,children:e.label}),(0,F.jsx)(`strong`,{children:r?`…`:V(e.count)}),(0,F.jsx)(`span`,{className:`dashboard-severity-percent`,children:!r&&e.percent!==null?`${e.percent}%`:`—`})]},e.key))})]})}function q({stats:e,latest:t,t:n}){let r=N.map(t=>H(e,t)),a=r.some(e=>e===null)?null:r[0]*10+r[1]*5+r[2]*2+r[3]*.5,[,o,s,c]=a===null?[null,`unknown`,``,``]:L.find(([e])=>a<=e);return(0,F.jsxs)(`aside`,{className:`dashboard-risk-summary`,"aria-label":n(`dashboard.riskLevel`,null,`风险等级`),children:[(0,F.jsxs)(`div`,{className:`dashboard-risk-score`,"data-tone":o,children:[(0,F.jsxs)(`span`,{className:`dashboard-risk-caption`,children:[n(`dashboard.riskLevel`,null,`风险等级`),(0,F.jsx)(f,{size:`small`,className:`dashboard-risk-tag`,children:s?n(`dashboard.risk`+s,null,c):`—`})]}),(0,F.jsx)(_,{percent:Math.min(a??0,100),size:`small`,showInfo:!1,stroke:`var(--risk-accent)`,"aria-label":n(`dashboard.riskScore`,null,`加权风险分`)}),(0,F.jsxs)(`span`,{className:`dashboard-risk-caption`,children:[n(`dashboard.riskScore`,null,`加权风险分`),(0,F.jsx)(`strong`,{children:a===null?`—`:`${w(a)}${a>=100?`+`:``}`})]})]}),(0,F.jsxs)(`div`,{className:`dashboard-risk-pending`,children:[(0,F.jsx)(`span`,{children:n(`dashboard.statusOpen`,null,`待处理`)}),(0,F.jsx)(`div`,{className:`dashboard-risk-pending-links`,children:N.slice(0,2).map((e,t)=>(0,F.jsxs)(i,{to:U(e,`open`),"data-severity":e,children:[(0,F.jsx)(`strong`,{children:V(r[t])}),(0,F.jsx)(`span`,{children:n(`dashboard.severity`+z(e),null,I[t])})]},e))})]}),(0,F.jsxs)(`div`,{className:`dashboard-risk-latest`,children:[(0,F.jsx)(`span`,{children:n(`dashboard.latestFound`,null,`最近发现`)}),(0,F.jsx)(`strong`,{children:t?C(t,n):`—`})]})]})}function J({counts:e,states:t,t:n}){let r=B(e?.fixed??0)??0,a=B(e?.confirmed??0)??0,o=(B(e?.open??0)??0)+a+r,s=o?r/o*100:null;return(0,F.jsxs)(`div`,{className:`dashboard-resolution`,children:[(0,F.jsx)(`div`,{className:`dashboard-resolution-grid`,children:t.map(({value:t,label:n})=>(0,F.jsxs)(i,{to:U(``,t),"data-status":t,className:`dashboard-resolution-item`,children:[(0,F.jsx)(`strong`,{children:V(e?e[t]??0:null)}),(0,F.jsx)(`span`,{children:n})]},t))}),(0,F.jsxs)(`div`,{className:`dashboard-resolution-heading`,children:[(0,F.jsx)(`span`,{children:n(`dashboard.fixRate`,null,`修复率`)}),(0,F.jsxs)(`span`,{children:[(0,F.jsx)(`strong`,{className:`dashboard-risk-value`,children:s===null?`—`:`${s.toFixed(s===100?0:1)}%`}),e&&(0,F.jsxs)(`small`,{children:[`(`,w(r),` / `,w(o),`)`]})]})]}),(0,F.jsxs)(`div`,{className:`dashboard-resolution-track`,"aria-hidden":`true`,children:[(0,F.jsx)(`span`,{style:{width:`${s??0}%`}}),(0,F.jsx)(`span`,{style:{width:`${o?a/o*100:0}%`}})]}),(0,F.jsx)(`div`,{className:`dashboard-resolution-legend`,children:[`fixed`,`confirmed`,`open`].map(e=>(0,F.jsx)(`span`,{"data-status":e,children:t.find(t=>t.value===e).label},e))})]})}function re({stats:e,pendingStats:t,latest:n,loadedAt:r,loading:s}){let c=E(),[l,u]=a(),d=R.map(([e,t,n])=>({value:e,label:c(`dashboard.status`+t,null,n)})),f=l.get(`risk_status`),p=d.some(e=>e.value===f)?f:``,m=!!(p&&p!==`open`),h=k(async()=>{try{return{status:p,stats:await D.get(`/vulnerabilities/stats`,{status:p})}}catch(e){return{status:p,error:e}}},[p,r],{skip:!m}),g=h.data?.status===p,_=p===`open`?t:m?g?h.data.stats:null:e,v=s||m&&(h.loading||!g),b=N.map(e=>H(_,e)),S=b.some(e=>e===null)?null:Math.max(B(_?.total)??0,b.reduce((e,t)=>e+t,0)),C=N.map((e,t)=>({key:e,label:c(`dashboard.severity`+z(e),null,I[t]),count:b[t],percent:S===null?null:S===0?0:Math.round(b[t]/S*100)}));return(0,F.jsxs)(M,{className:`dashboard-vulnerability-card`,bodyClassName:`dashboard-vulnerability-body`,title:c(`dashboard.severityDistribution`,null,`漏洞严重程度分布`),extra:(0,F.jsxs)(`div`,{className:`dashboard-vulnerability-actions`,children:[(0,F.jsx)(x,{"aria-label":c(`dashboard.statusFilter`,null,`状态筛选`),size:`small`,value:p||`all`,optionList:[{value:`all`,label:c(`dashboard.allStatuses`,null,`全部状态`)},...d],onChange:e=>u(t=>{let n=new URLSearchParams(t);return e===`all`?n.delete(`risk_status`):n.set(`risk_status`,e),n},{replace:!0})}),(0,F.jsxs)(i,{className:`dashboard-vulnerability-all`,to:U(``,p),children:[c(`dashboard.viewAll`,null,`查看全部`).replace(/\s*→\s*$/,``),(0,F.jsx)(y,{"aria-hidden":`true`})]})]}),children:[m&&g&&h.data.error&&(0,F.jsx)(o,{type:`warning`,closeIcon:null,description:(0,F.jsxs)(`button`,{type:`button`,className:`dashboard-filter-retry`,onClick:()=>h.reload(),children:[c(`common.loadFailed`,null,`加载失败`),` · `,c(`common.refresh`,null,`刷新`)]})}),(0,F.jsxs)(`div`,{className:`dashboard-vulnerability-grid`,children:[(0,F.jsx)(q,{stats:t,latest:n,t:c}),(0,F.jsx)(K,{rows:C,total:S,status:p,loading:v,t:c},p)]}),(0,F.jsx)(J,{counts:e?.by_status,states:d,t:c})]})}var{Text:Y}=l,ie=new Intl.NumberFormat(`en`,{notation:`compact`,maximumFractionDigits:1});async function X(e,t){try{return await D.get(e,t)}catch{return null}}async function ae(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_]=await Promise.all([X(`/agent-loop/tasks`),X(`/vulnerabilities/stats`),X(`/vulnerabilities/stats`,{status:`open`}),X(`/vulnerabilities`,{limit:8,page:1}),X(`/batch-tasks`,{limit:200,page:1}),X(`/monitor/stats`,{top:8}),X(`/usage/tokens`,{days:7,limit:20}),X(`/knowledge/stats`),X(`/skills/stats`),X(`/roles`),X(`/multi-agent/markdown-agents`),X(`/hitl/pending`),X(`/external-mcp/stats`),X(`/webshell/connections`),X(`/c2/listeners`),X(`/c2/sessions`,{limit:200}),X(`/projects/dashboard-summary`,{fact_limit:8}),X(`/config/tools`,{page:1,page_size:1,include_external:!1})]),v={agentTasks:e,vulnStats:t,pendingVulnStats:n,vulnList:r,batchQueues:i,monitorStats:a,tokenUsage:o,knowledgeStats:s,skillsStats:c,roles:l,agents:u,hitlPending:d,externalMcp:f,webshell:p,c2Listeners:m,c2Sessions:h,projectSummary:g,toolsConfig:_};return{...v,unavailableCount:Object.values(v).filter(e=>e==null).length,sourceCount:Object.keys(v).length,loadedAt:new Date().toISOString()}}function Z(e,...t){if(Array.isArray(e))return e;for(let n of t)if(Array.isArray(e?.[n]))return e[n];return null}function Q(e,...t){return Z(e,...t)?.length??null}function $({loading:e,unavailable:t,title:n,description:r}){return(0,F.jsx)(c,{className:`dashboard-empty`,title:e?`正在加载数据`:t?`数据暂不可用`:n,description:e?`正在读取最新记录,请稍候。`:t?`未能取得数据,请稍后刷新重试。`:r})}function oe({data:e,loading:t,onOpen:n}){let r=Z(e,`vulnerabilities`);return(0,F.jsx)(s,{className:`dashboard-list dashboard-feed`,loading:t,dataSource:r||[],emptyContent:(0,F.jsx)($,{loading:t,unavailable:r===null,title:`暂无漏洞记录`,description:`测评发现的漏洞会汇集到这里,便于跟进与复核。`}),renderItem:e=>(0,F.jsx)(s.Item,{main:(0,F.jsxs)(`div`,{className:`dashboard-record`,children:[(0,F.jsx)(p,{theme:`borderless`,className:`dashboard-record-link`,onClick:()=>n(e.id),children:e.title||e.name||`未命名漏洞`}),(0,F.jsxs)(Y,{type:`tertiary`,size:`small`,className:`dashboard-meta`,children:[e.host||e.target||`—`,` · `,T(e.created_at)]})]}),extra:(0,F.jsx)(A,{severity:e.severity})},e.id)})}function se({summary:e,loading:t,onOpen:n}){let r=Z(e,`recent_facts`,`facts`);return(0,F.jsx)(s,{className:`dashboard-list dashboard-feed dashboard-facts`,split:!1,loading:t,dataSource:r||[],emptyContent:(0,F.jsx)($,{loading:t,unavailable:r===null,title:`暂无近期事实`,description:`项目沉淀的事实与证据将在这里展示。`}),renderItem:(e,t)=>(0,F.jsx)(s.Item,{main:(0,F.jsxs)(`div`,{className:`dashboard-record`,children:[(0,F.jsx)(Y,{strong:!0,className:`dashboard-fact-title`,children:e.title||e.summary||e.key||e.fact_key||e.subject||`事实`}),(0,F.jsx)(Y,{type:`tertiary`,size:`small`,className:`dashboard-meta`,children:e.project_name||e.projectName||e.value||`—`})]}),extra:(0,F.jsxs)(u,{spacing:8,children:[e.status&&(0,F.jsx)(f,{size:`small`,children:e.status}),e.project_id&&(0,F.jsx)(p,{theme:`borderless`,icon:(0,F.jsx)(y,{}),"aria-label":`查看所属项目`,onClick:()=>n(e.project_id)})]})},e.id||e.key||e.fact_key||t)})}function ce(){let e=E(),t=n(),{data:r,loading:i,error:a,reload:c}=k(ae,[]);ne(()=>c({silent:!0}),6e4);let l=(0,P.useMemo)(()=>{let n=Q(r?.agentTasks,`tasks`),a=B(r?.tokenUsage?.summary?.totalTokens),o=H(r?.vulnStats,`critical`),s=H(r?.pendingVulnStats,`high`),c=r?.monitorStats?.summary,l=B(c?.successCalls),u=B(c?.failedCalls),f=l===null||u===null?null:l+u,p=f>0?l/f:null,_=Z(r?.batchQueues,`queues`)?.filter(e=>String(e.status).toLowerCase()===`running`).length;return[{id:`tasks`,label:e(`dashboard.runningConversations`,null,`运行中任务`),value:V(n),detail:`运行中批量队列 ${V(_)}`,icon:(0,F.jsx)(d,{}),onClick:()=>t(`/tasks`)},{id:`vulnerabilities`,label:e(`dashboard.vulnTotal`,null,`漏洞总数`),value:V(r?.vulnStats?.total),detail:e(`dashboard.openHighCountLabel`,{count:V(s)},`待处理高危 ${V(s)}`),tone:o>0?`danger`:void 0,icon:(0,F.jsx)(h,{}),onClick:()=>t(`/vulnerabilities`)},{id:`calls`,label:e(`dashboard.toolCalls`,null,`工具调用`),value:V(c?.totalCalls),detail:`涉及工具 ${V(c?.toolCount)}`,icon:(0,F.jsx)(g,{}),onClick:()=>t(`/mcp-monitor`)},{id:`rate`,label:e(`dashboard.successRate`,null,`执行成功率`),value:p===null?`—`:ee(p),detail:f===null?`执行结果暂不可用`:f===0?`尚无已完成调用`:`失败 ${V(u)} 次`,tone:p!==null&&p<.8?`warning`:void 0,icon:(0,F.jsx)(v,{}),onClick:()=>t(`/mcp-monitor`)},{id:`tokens`,label:e(`dashboard.tokenUsage`,null,`Token 用量(7 天)`),value:a>=1e6?ie.format(a):V(a),valueTitle:a>=1e6?V(a):void 0,detail:`调用次数 ${V(r?.tokenUsage?.summary?.modelCalls??r?.tokenUsage?.summary?.calls)}`,icon:(0,F.jsx)(m,{}),onClick:()=>t(`/settings?section=token-usage`)}].map(e=>({...e,loading:i,detail:i?`正在刷新数据`:e.detail}))},[r,i,t,e]),f=(0,P.useMemo)(()=>{let e=[],t=H(r?.vulnStats,`critical`);t>0&&e.push({id:`critical`,text:`${V(t)} 条严重漏洞`,page:`/vulnerabilities`});let n=Q(r?.hitlPending,`items`,`pending`);n>0&&e.push({id:`pending`,text:`${V(n)} 项审批待处理`,page:`/hitl`});let i=B(r?.monitorStats?.summary?.failedCalls);i>0&&e.push({id:`failed`,text:`工具调用失败 ${V(i)} 次`,page:`/mcp-monitor`});let a=B(r?.externalMcp?.total),o=B(r?.externalMcp?.connected);return a!==null&&o!==null&&a>o&&e.push({id:`mcp`,text:`${V(a-o)} 个外部 MCP 未连接`,page:`/mcp-management`}),e},[r]),_=(0,P.useMemo)(()=>[{id:`tools`,label:`MCP 工具`,value:r?.toolsConfig?.total,page:`/mcp-management`},{id:`knowledge`,label:`知识条目`,value:r?.knowledgeStats?.total_items,page:`/knowledge-management`},{id:`skills`,label:`技能`,value:r?.skillsStats?.total_skills,page:`/skills-management`},{id:`roles`,label:`角色`,value:Q(r?.roles,`roles`),page:`/roles-management`},{id:`agents`,label:`智能体`,value:Q(r?.agents,`agents`),page:`/agents-management`},{id:`webshell`,label:`WebShell 连接`,value:Q(r?.webshell,`connections`),page:`/webshell`},{id:`listeners`,label:`C2 监听器`,value:Q(r?.c2Listeners,`listeners`),page:`/c2-listeners`},{id:`sessions`,label:`C2 会话`,value:Q(r?.c2Sessions,`sessions`,`items`),page:`/c2-sessions`}],[r]),x=r?.loadedAt?T(r.loadedAt):`—`,C=e=>t(`/projects?id=${encodeURIComponent(e)}`);return(0,F.jsxs)(`div`,{className:`dashboard-page`,"aria-busy":i,children:[(0,F.jsx)(te,{title:e(`dashboard.title`,null,`仪表盘`),description:`最近刷新 ${x} · 每 60 秒自动刷新`,extra:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(p,{icon:(0,F.jsx)(b,{}),onClick:()=>c(),loading:i,children:e(`common.refresh`,null,`刷新`)}),(0,F.jsx)(p,{theme:`solid`,icon:(0,F.jsx)(S,{}),onClick:()=>t(`/chat`),children:`进入对话`})]})}),(0,F.jsx)(O,{metrics:l,columns:5}),(0,F.jsx)(j,{error:a,onRetry:()=>c()}),r?.unavailableCount>0&&(0,F.jsx)(o,{className:`dashboard-notice`,type:`info`,fullMode:!1,closeIcon:null,title:r.unavailableCount===r.sourceCount?`数据暂不可用`:`部分数据不可用`,description:r.unavailableCount===r.sourceCount?`本次未能取得仪表盘数据,请检查服务连接后刷新重试。`:`${r.unavailableCount} 项数据源未能加载,相关数值以 — 显示。已返回的数据仍可查看,请稍后刷新重试。`}),f.length>0&&(0,F.jsx)(o,{className:`dashboard-notice`,type:`warning`,fullMode:!1,closeIcon:null,description:(0,F.jsxs)(u,{wrap:!0,spacing:8,children:[(0,F.jsx)(Y,{strong:!0,children:`需要关注`}),f.map(e=>(0,F.jsx)(p,{theme:`borderless`,type:`warning`,icon:(0,F.jsx)(y,{}),iconPosition:`right`,onClick:()=>t(e.page),children:e.text},e.id))]})}),(0,F.jsxs)(`div`,{className:`dashboard-grid`,children:[(0,F.jsxs)(`div`,{className:`dashboard-column`,children:[(0,F.jsx)(re,{stats:r?.vulnStats,pendingStats:r?.pendingVulnStats,latest:r?.vulnList?.vulnerabilities?.[0]?.created_at,loadedAt:r?.loadedAt,loading:i}),(0,F.jsx)(M,{title:e(`dashboard.recentVulns`,null,`最近漏洞`),extra:(0,F.jsx)(p,{theme:`borderless`,size:`small`,icon:(0,F.jsx)(y,{}),iconPosition:`right`,onClick:()=>t(`/vulnerabilities`),children:`查看全部`}),children:(0,F.jsx)(oe,{data:r?.vulnList,loading:i,onOpen:e=>t(`/vulnerabilities?id=${encodeURIComponent(e)}`)})})]}),(0,F.jsxs)(`div`,{className:`dashboard-column`,children:[(0,F.jsx)(M,{title:e(`dashboard.projects`,null,`项目概览`),extra:(0,F.jsx)(p,{theme:`borderless`,size:`small`,icon:(0,F.jsx)(y,{}),iconPosition:`right`,onClick:()=>t(`/projects`),children:`全部项目`}),children:(0,F.jsx)(ue,{summary:r?.projectSummary,loading:i,onOpen:C})}),(0,F.jsx)(M,{title:e(`dashboard.toolsTop`,null,`工具调用 Top`),extra:(0,F.jsx)(p,{theme:`borderless`,size:`small`,onClick:()=>t(`/mcp-monitor`),children:`调用监控`}),children:(0,F.jsx)(le,{data:r?.monitorStats,loading:i})}),(0,F.jsx)(M,{className:`dashboard-capability-card`,bodyClassName:`dashboard-capability-body`,title:e(`dashboard.capability`,null,`能力与运行态`),children:(0,F.jsx)(s,{className:`dashboard-capabilities`,split:!1,dataSource:_,renderItem:e=>(0,F.jsx)(s.Item,{children:(0,F.jsxs)(p,{block:!0,theme:`borderless`,type:`tertiary`,className:`dashboard-capability`,onClick:()=>t(e.page),children:[(0,F.jsx)(`span`,{children:e.label}),(0,F.jsx)(`span`,{className:`dashboard-capability-value`,children:i?`…`:V(e.value)})]})},e.id)})})]})]}),(0,F.jsx)(M,{className:`dashboard-facts-card`,title:e(`dashboard.recentFacts`,null,`近期事实`),children:(0,F.jsx)(se,{summary:r?.projectSummary,loading:i,onOpen:C})})]})}function le({data:e,loading:t}){let n=Z(e,`topTools`),r=n?.slice(0,8).map(e=>({name:e.name||e.toolName||`未命名工具`,count:B(e.count??e.calls??e.totalCalls)}))||[],i=Math.max(...r.map(e=>e.count??0),1);return(0,F.jsx)(s,{className:`dashboard-list`,loading:t,dataSource:r,emptyContent:(0,F.jsx)($,{loading:t,unavailable:n===null,title:`暂无工具调用`,description:`执行任务后,可在这里查看使用最多的工具。`}),renderItem:(e,t)=>(0,F.jsxs)(s.Item,{className:`dashboard-tool-row`,children:[(0,F.jsx)(Y,{type:`tertiary`,size:`small`,className:`dashboard-tool-rank`,children:t+1}),(0,F.jsxs)(`div`,{className:`dashboard-record`,children:[(0,F.jsxs)(`div`,{className:`dashboard-tool-heading`,children:[(0,F.jsx)(Y,{className:`dashboard-tool-name`,title:e.name,children:e.name}),(0,F.jsxs)(Y,{type:`secondary`,size:`small`,className:`dashboard-count`,children:[V(e.count),` 次`]})]}),e.count!==null&&(0,F.jsx)(_,{percent:Math.round(e.count/i*100),showInfo:!1,size:`small`,stroke:`var(--semi-color-primary)`,"aria-label":`${e.name}调用次数`,"aria-valuetext":`${V(e.count)} 次`})]})]},`${e.name}-${t}`)})}function ue({summary:e,loading:t,onOpen:n}){let r=Z(e,`projects`),i=Z(e,`recent_facts`,`facts`),a=e?.totals||e,o=[[`活跃项目`,a?.active_projects??a?.activeProjects],[`事实总数`,a?.total_facts??a?.totalFacts],[`最近事实`,i?.length]];return(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`dl`,{className:`dashboard-project-totals`,children:o.map(([e,n])=>(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`dt`,{children:e}),(0,F.jsx)(`dd`,{children:t?`…`:V(n)})]},e))}),(0,F.jsx)(s,{className:`dashboard-list dashboard-feed`,loading:t,dataSource:r?.slice(0,6)||[],emptyContent:(0,F.jsx)($,{loading:t,unavailable:!e,title:r===null?`在项目中继续工作`:`暂无项目`,description:r===null?`当前摘要提供项目与事实统计,完整列表请查看全部项目。`:`创建项目后,在这里跟进项目进展。`}),renderItem:e=>(0,F.jsx)(s.Item,{main:(0,F.jsxs)(`div`,{className:`dashboard-record`,children:[(0,F.jsx)(p,{theme:`borderless`,className:`dashboard-record-link`,onClick:()=>n(e.id),children:e.name||`未命名项目`}),(0,F.jsxs)(Y,{type:`tertiary`,size:`small`,className:`dashboard-meta`,children:[e.status||`—`,` · `,T(e.updated_at)]})]})},e.id)})]})}export{ce as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,u as i,y as a}from"./react-QV7DAAIx.js";import{B as o,C as s,E as c,G as l,I as u,Kt as d,N as f,R as p,Zt as m,at as h,et as g,g as _,qt as v,tn as y,ut as b,y as x,zt as S}from"./semi-65W_4I1v.js";import{A as C,D as w,E as T,F as E,L as D,O as ee,_ as O,a as k,h as A,l as j,m as M,p as te,r as ne,w as N}from"./index-DNMXun-U.js";var P=e(t(),1),F=e(r(),1),I=[`严重`,`高危`,`中危`,`低危`,`信息`],L=[[0,`safe`,`Safe`,`安全`],[3,`low`,`Low`,`低`],[10,`medium`,`Medium`,`中`],[30,`high`,`High`,`高`],[1/0,`severe`,`Severe`,`极高`]],R=[[`open`,`Open`,`待处理`],[`confirmed`,`Confirmed`,`已确认`],[`fixed`,`Fixed`,`已修复`],[`ignored`,`Ignored`,`已忽略`],[`false_positive`,`FalsePositive`,`误报`]];function z(e){return e[0].toUpperCase()+e.slice(1)}function B(e){if(e==null||e===``||![`number`,`string`].includes(typeof e))return null;let t=Number(e);return Number.isFinite(t)&&t>=0?t:null}function V(e){let t=B(e);return t===null?`—`:w(t)}function H(e,t){let n=e?.by_severity;return!n||typeof n!=`object`||Array.isArray(n)?null:B(n[t]??0)}function U(e,t){let n=new URLSearchParams;e&&n.set(`severity`,e),t&&n.set(`status`,t);let r=n.toString();return`/vulnerabilities`+(r?`?`+r:``)}function W(e,t){let n=(e,t)=>`${(210+e*Math.cos(t)).toFixed(3)} ${(201-e*Math.sin(t)).toFixed(3)}`;return`M ${n(188,e)} A 188 188 0 0 1 ${n(188,t)} L ${n(137,t)} A 137 137 0 0 0 ${n(137,e)} Z`}function G(e,t){if(!t)return[];let n=[],r=Math.PI;for(let i of e){if(!i.count)continue;let e=Math.PI*i.count/t,a=r-e,o=Math.min(.014,e/5);n.push({...i,d:W(r-o,a+o)}),r=a}return n}function K({rows:e,total:t,status:n,loading:r,t:a}){let o=(0,P.useId)(),[s,c]=(0,P.useState)(``),[l,u]=(0,P.useState)(``),d=s||l,f=e.find(e=>e.key===d),p=r?`…`:V(f?f.count:t),m=G(e,t),h=e=>({onPointerEnter:()=>c(e),onPointerLeave:()=>c(``),onFocus:()=>u(e),onBlur:()=>u(``)});return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:`dashboard-severity-chart`,children:[(0,F.jsxs)(`svg`,{viewBox:`0 0 420 217`,role:`group`,"aria-label":a(`dashboard.severityDistribution`,null,`漏洞严重程度分布`),children:[(0,F.jsx)(`defs`,{children:e.map(e=>(0,F.jsxs)(`linearGradient`,{id:o+e.key,x1:`12%`,y1:`0%`,x2:`84%`,y2:`100%`,"data-severity":e.key,children:[(0,F.jsx)(`stop`,{offset:`0%`,stopColor:`var(--severity-light)`}),(0,F.jsx)(`stop`,{offset:`100%`,stopColor:`var(--severity-color)`})]},e.key))}),(0,F.jsx)(`path`,{className:`dashboard-ring-track`,d:W(Math.PI,0)}),m.map(e=>(0,F.jsxs)(i,{to:U(e.key,n),className:`dashboard-ring-link`,"data-severity":e.key,"aria-label":`${e.label} · ${V(e.count)}`,"data-muted":!!(d&&e.key!==d),...h(e.key),children:[(0,F.jsx)(`title`,{children:`${e.label} · ${V(e.count)} (${e.percent}%)`}),(0,F.jsx)(`path`,{d:e.d,fill:`url(#${o+e.key})`})]},e.key))]}),(0,F.jsxs)(`div`,{className:`dashboard-ring-center`,"data-severity":f?.key,children:[(0,F.jsx)(`strong`,{children:p}),(0,F.jsx)(`span`,{children:f?.label||a(`dashboard.totalVulns`,null,`总漏洞数`)})]})]}),(0,F.jsx)(`div`,{className:`dashboard-severity-legend`,children:e.map(e=>(0,F.jsxs)(i,{className:`dashboard-severity-item`,"data-severity":e.key,"data-active":d===e.key,to:U(e.key,n),...h(e.key),children:[(0,F.jsx)(`span`,{className:`dashboard-severity-dot`,"aria-hidden":`true`}),(0,F.jsx)(`span`,{className:`dashboard-severity-name`,children:e.label}),(0,F.jsx)(`strong`,{children:r?`…`:V(e.count)}),(0,F.jsx)(`span`,{className:`dashboard-severity-percent`,children:!r&&e.percent!==null?`${e.percent}%`:`—`})]},e.key))})]})}function q({stats:e,latest:t,t:n}){let r=N.map(t=>H(e,t)),a=r.some(e=>e===null)?null:r[0]*10+r[1]*5+r[2]*2+r[3]*.5,[,o,s,c]=a===null?[null,`unknown`,``,``]:L.find(([e])=>a<=e);return(0,F.jsxs)(`aside`,{className:`dashboard-risk-summary`,"aria-label":n(`dashboard.riskLevel`,null,`风险等级`),children:[(0,F.jsxs)(`div`,{className:`dashboard-risk-score`,"data-tone":o,children:[(0,F.jsxs)(`span`,{className:`dashboard-risk-caption`,children:[n(`dashboard.riskLevel`,null,`风险等级`),(0,F.jsx)(f,{size:`small`,className:`dashboard-risk-tag`,children:s?n(`dashboard.risk`+s,null,c):`—`})]}),(0,F.jsx)(_,{percent:Math.min(a??0,100),size:`small`,showInfo:!1,stroke:`var(--risk-accent)`,"aria-label":n(`dashboard.riskScore`,null,`加权风险分`)}),(0,F.jsxs)(`span`,{className:`dashboard-risk-caption`,children:[n(`dashboard.riskScore`,null,`加权风险分`),(0,F.jsx)(`strong`,{children:a===null?`—`:`${w(a)}${a>=100?`+`:``}`})]})]}),(0,F.jsxs)(`div`,{className:`dashboard-risk-pending`,children:[(0,F.jsx)(`span`,{children:n(`dashboard.statusOpen`,null,`待处理`)}),(0,F.jsx)(`div`,{className:`dashboard-risk-pending-links`,children:N.slice(0,2).map((e,t)=>(0,F.jsxs)(i,{to:U(e,`open`),"data-severity":e,children:[(0,F.jsx)(`strong`,{children:V(r[t])}),(0,F.jsx)(`span`,{children:n(`dashboard.severity`+z(e),null,I[t])})]},e))})]}),(0,F.jsxs)(`div`,{className:`dashboard-risk-latest`,children:[(0,F.jsx)(`span`,{children:n(`dashboard.latestFound`,null,`最近发现`)}),(0,F.jsx)(`strong`,{children:t?C(t,n):`—`})]})]})}function J({counts:e,states:t,t:n}){let r=B(e?.fixed??0)??0,a=B(e?.confirmed??0)??0,o=(B(e?.open??0)??0)+a+r,s=o?r/o*100:null;return(0,F.jsxs)(`div`,{className:`dashboard-resolution`,children:[(0,F.jsx)(`div`,{className:`dashboard-resolution-grid`,children:t.map(({value:t,label:n})=>(0,F.jsxs)(i,{to:U(``,t),"data-status":t,className:`dashboard-resolution-item`,children:[(0,F.jsx)(`strong`,{children:V(e?e[t]??0:null)}),(0,F.jsx)(`span`,{children:n})]},t))}),(0,F.jsxs)(`div`,{className:`dashboard-resolution-heading`,children:[(0,F.jsx)(`span`,{children:n(`dashboard.fixRate`,null,`修复率`)}),(0,F.jsxs)(`span`,{children:[(0,F.jsx)(`strong`,{className:`dashboard-risk-value`,children:s===null?`—`:`${s.toFixed(s===100?0:1)}%`}),e&&(0,F.jsxs)(`small`,{children:[`(`,w(r),` / `,w(o),`)`]})]})]}),(0,F.jsxs)(`div`,{className:`dashboard-resolution-track`,"aria-hidden":`true`,children:[(0,F.jsx)(`span`,{style:{width:`${s??0}%`}}),(0,F.jsx)(`span`,{style:{width:`${o?a/o*100:0}%`}})]}),(0,F.jsx)(`div`,{className:`dashboard-resolution-legend`,children:[`fixed`,`confirmed`,`open`].map(e=>(0,F.jsx)(`span`,{"data-status":e,children:t.find(t=>t.value===e).label},e))})]})}function re({stats:e,pendingStats:t,latest:n,loadedAt:r,loading:s}){let c=E(),[l,u]=a(),d=R.map(([e,t,n])=>({value:e,label:c(`dashboard.status`+t,null,n)})),f=l.get(`risk_status`),p=d.some(e=>e.value===f)?f:``,m=!!(p&&p!==`open`),h=k(async()=>{try{return{status:p,stats:await D.get(`/vulnerabilities/stats`,{status:p})}}catch(e){return{status:p,error:e}}},[p,r],{skip:!m}),g=h.data?.status===p,_=p===`open`?t:m?g?h.data.stats:null:e,v=s||m&&(h.loading||!g),b=N.map(e=>H(_,e)),S=b.some(e=>e===null)?null:Math.max(B(_?.total)??0,b.reduce((e,t)=>e+t,0)),C=N.map((e,t)=>({key:e,label:c(`dashboard.severity`+z(e),null,I[t]),count:b[t],percent:S===null?null:S===0?0:Math.round(b[t]/S*100)}));return(0,F.jsxs)(M,{className:`dashboard-vulnerability-card`,bodyClassName:`dashboard-vulnerability-body`,title:c(`dashboard.severityDistribution`,null,`漏洞严重程度分布`),extra:(0,F.jsxs)(`div`,{className:`dashboard-vulnerability-actions`,children:[(0,F.jsx)(x,{"aria-label":c(`dashboard.statusFilter`,null,`状态筛选`),size:`small`,value:p||`all`,optionList:[{value:`all`,label:c(`dashboard.allStatuses`,null,`全部状态`)},...d],onChange:e=>u(t=>{let n=new URLSearchParams(t);return e===`all`?n.delete(`risk_status`):n.set(`risk_status`,e),n},{replace:!0})}),(0,F.jsxs)(i,{className:`dashboard-vulnerability-all`,to:U(``,p),children:[c(`dashboard.viewAll`,null,`查看全部`).replace(/\s*→\s*$/,``),(0,F.jsx)(y,{"aria-hidden":`true`})]})]}),children:[m&&g&&h.data.error&&(0,F.jsx)(o,{type:`warning`,closeIcon:null,description:(0,F.jsxs)(`button`,{type:`button`,className:`dashboard-filter-retry`,onClick:()=>h.reload(),children:[c(`common.loadFailed`,null,`加载失败`),` · `,c(`common.refresh`,null,`刷新`)]})}),(0,F.jsxs)(`div`,{className:`dashboard-vulnerability-grid`,children:[(0,F.jsx)(q,{stats:t,latest:n,t:c}),(0,F.jsx)(K,{rows:C,total:S,status:p,loading:v,t:c},p)]}),(0,F.jsx)(J,{counts:e?.by_status,states:d,t:c})]})}var{Text:Y}=l,ie=new Intl.NumberFormat(`en`,{notation:`compact`,maximumFractionDigits:1});async function X(e,t){try{return await D.get(e,t)}catch{return null}}async function ae(){let[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_]=await Promise.all([X(`/agent-loop/tasks`),X(`/vulnerabilities/stats`),X(`/vulnerabilities/stats`,{status:`open`}),X(`/vulnerabilities`,{limit:8,page:1}),X(`/batch-tasks`,{limit:200,page:1}),X(`/monitor/stats`,{top:8}),X(`/usage/tokens`,{days:7,limit:20}),X(`/knowledge/stats`),X(`/skills/stats`),X(`/roles`),X(`/multi-agent/markdown-agents`),X(`/hitl/pending`),X(`/external-mcp/stats`),X(`/webshell/connections`),X(`/c2/listeners`),X(`/c2/sessions`,{limit:200}),X(`/projects/dashboard-summary`,{fact_limit:8}),X(`/config/tools`,{page:1,page_size:1,include_external:!1})]),v={agentTasks:e,vulnStats:t,pendingVulnStats:n,vulnList:r,batchQueues:i,monitorStats:a,tokenUsage:o,knowledgeStats:s,skillsStats:c,roles:l,agents:u,hitlPending:d,externalMcp:f,webshell:p,c2Listeners:m,c2Sessions:h,projectSummary:g,toolsConfig:_};return{...v,unavailableCount:Object.values(v).filter(e=>e==null).length,sourceCount:Object.keys(v).length,loadedAt:new Date().toISOString()}}function Z(e,...t){if(Array.isArray(e))return e;for(let n of t)if(Array.isArray(e?.[n]))return e[n];return null}function Q(e,...t){return Z(e,...t)?.length??null}function $({loading:e,unavailable:t,title:n,description:r}){return(0,F.jsx)(c,{className:`dashboard-empty`,title:e?`正在加载数据`:t?`数据暂不可用`:n,description:e?`正在读取最新记录,请稍候。`:t?`未能取得数据,请稍后刷新重试。`:r})}function oe({data:e,loading:t,onOpen:n}){let r=Z(e,`vulnerabilities`);return(0,F.jsx)(s,{className:`dashboard-list dashboard-feed`,loading:t,dataSource:r||[],emptyContent:(0,F.jsx)($,{loading:t,unavailable:r===null,title:`暂无漏洞记录`,description:`测评发现的漏洞会汇集到这里,便于跟进与复核。`}),renderItem:e=>(0,F.jsx)(s.Item,{main:(0,F.jsxs)(`div`,{className:`dashboard-record`,children:[(0,F.jsx)(p,{theme:`borderless`,className:`dashboard-record-link`,onClick:()=>n(e.id),children:e.title||e.name||`未命名漏洞`}),(0,F.jsxs)(Y,{type:`tertiary`,size:`small`,className:`dashboard-meta`,children:[e.host||e.target||`—`,` · `,T(e.created_at)]})]}),extra:(0,F.jsx)(A,{severity:e.severity})},e.id)})}function se({summary:e,loading:t,onOpen:n}){let r=Z(e,`recent_facts`,`facts`);return(0,F.jsx)(s,{className:`dashboard-list dashboard-feed dashboard-facts`,split:!1,loading:t,dataSource:r||[],emptyContent:(0,F.jsx)($,{loading:t,unavailable:r===null,title:`暂无近期事实`,description:`项目沉淀的事实与证据将在这里展示。`}),renderItem:(e,t)=>(0,F.jsx)(s.Item,{main:(0,F.jsxs)(`div`,{className:`dashboard-record`,children:[(0,F.jsx)(Y,{strong:!0,className:`dashboard-fact-title`,children:e.title||e.summary||e.key||e.fact_key||e.subject||`事实`}),(0,F.jsx)(Y,{type:`tertiary`,size:`small`,className:`dashboard-meta`,children:e.project_name||e.projectName||e.value||`—`})]}),extra:(0,F.jsxs)(u,{spacing:8,children:[e.status&&(0,F.jsx)(f,{size:`small`,children:e.status}),e.project_id&&(0,F.jsx)(p,{theme:`borderless`,icon:(0,F.jsx)(y,{}),"aria-label":`查看所属项目`,onClick:()=>n(e.project_id)})]})},e.id||e.key||e.fact_key||t)})}function ce(){let e=E(),t=n(),{data:r,loading:i,error:a,reload:c}=k(ae,[]);ne(()=>c({silent:!0}),6e4);let l=(0,P.useMemo)(()=>{let n=Q(r?.agentTasks,`tasks`),a=B(r?.tokenUsage?.summary?.totalTokens),o=H(r?.vulnStats,`critical`),s=H(r?.pendingVulnStats,`high`),c=r?.monitorStats?.summary,l=B(c?.successCalls),u=B(c?.failedCalls),f=l===null||u===null?null:l+u,p=f>0?l/f:null,_=Z(r?.batchQueues,`queues`)?.filter(e=>String(e.status).toLowerCase()===`running`).length;return[{id:`tasks`,label:e(`dashboard.runningConversations`,null,`运行中任务`),value:V(n),detail:`运行中批量队列 ${V(_)}`,icon:(0,F.jsx)(d,{}),onClick:()=>t(`/tasks`)},{id:`vulnerabilities`,label:e(`dashboard.vulnTotal`,null,`漏洞总数`),value:V(r?.vulnStats?.total),detail:e(`dashboard.openHighCountLabel`,{count:V(s)},`待处理高危 ${V(s)}`),tone:o>0?`danger`:void 0,icon:(0,F.jsx)(h,{}),onClick:()=>t(`/vulnerabilities`)},{id:`calls`,label:e(`dashboard.toolCalls`,null,`工具调用`),value:V(c?.totalCalls),detail:`涉及工具 ${V(c?.toolCount)}`,icon:(0,F.jsx)(g,{}),onClick:()=>t(`/mcp-monitor`)},{id:`rate`,label:e(`dashboard.successRate`,null,`执行成功率`),value:p===null?`—`:ee(p),detail:f===null?`执行结果暂不可用`:f===0?`尚无已完成调用`:`失败 ${V(u)} 次`,tone:p!==null&&p<.8?`warning`:void 0,icon:(0,F.jsx)(v,{}),onClick:()=>t(`/mcp-monitor`)},{id:`tokens`,label:e(`dashboard.tokenUsage`,null,`Token 用量(7 天)`),value:a>=1e6?ie.format(a):V(a),valueTitle:a>=1e6?V(a):void 0,detail:`调用次数 ${V(r?.tokenUsage?.summary?.modelCalls??r?.tokenUsage?.summary?.calls)}`,icon:(0,F.jsx)(m,{}),onClick:()=>t(`/settings?section=token-usage`)}].map(e=>({...e,loading:i,detail:i?`正在刷新数据`:e.detail}))},[r,i,t,e]),f=(0,P.useMemo)(()=>{let e=[],t=H(r?.vulnStats,`critical`);t>0&&e.push({id:`critical`,text:`${V(t)} 条严重漏洞`,page:`/vulnerabilities`});let n=Q(r?.hitlPending,`items`,`pending`);n>0&&e.push({id:`pending`,text:`${V(n)} 项审批待处理`,page:`/hitl`});let i=B(r?.monitorStats?.summary?.failedCalls);i>0&&e.push({id:`failed`,text:`工具调用失败 ${V(i)} 次`,page:`/mcp-monitor`});let a=B(r?.externalMcp?.total),o=B(r?.externalMcp?.connected);return a!==null&&o!==null&&a>o&&e.push({id:`mcp`,text:`${V(a-o)} 个外部 MCP 未连接`,page:`/mcp-management`}),e},[r]),_=(0,P.useMemo)(()=>[{id:`tools`,label:`MCP 工具`,value:r?.toolsConfig?.total,page:`/mcp-management`},{id:`knowledge`,label:`知识条目`,value:r?.knowledgeStats?.total_items,page:`/knowledge-management`},{id:`skills`,label:`技能`,value:r?.skillsStats?.total_skills,page:`/skills-management`},{id:`roles`,label:`角色`,value:Q(r?.roles,`roles`),page:`/roles-management`},{id:`agents`,label:`智能体`,value:Q(r?.agents,`agents`),page:`/agents-management`},{id:`webshell`,label:`WebShell 连接`,value:Q(r?.webshell,`connections`),page:`/webshell`},{id:`listeners`,label:`C2 监听器`,value:Q(r?.c2Listeners,`listeners`),page:`/c2-listeners`},{id:`sessions`,label:`C2 会话`,value:Q(r?.c2Sessions,`sessions`,`items`),page:`/c2-sessions`}],[r]),x=r?.loadedAt?T(r.loadedAt):`—`,C=e=>t(`/projects?id=${encodeURIComponent(e)}`);return(0,F.jsxs)(`div`,{className:`dashboard-page`,"aria-busy":i,children:[(0,F.jsx)(te,{title:e(`dashboard.title`,null,`仪表盘`),description:`最近刷新 ${x} · 每 60 秒自动刷新`,extra:(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(p,{icon:(0,F.jsx)(b,{}),onClick:()=>c(),loading:i,children:e(`common.refresh`,null,`刷新`)}),(0,F.jsx)(p,{theme:`solid`,icon:(0,F.jsx)(S,{}),onClick:()=>t(`/chat`),children:`进入对话`})]})}),(0,F.jsx)(O,{metrics:l,columns:5}),(0,F.jsx)(j,{error:a,onRetry:()=>c()}),r?.unavailableCount>0&&(0,F.jsx)(o,{className:`dashboard-notice`,type:`info`,fullMode:!1,closeIcon:null,title:r.unavailableCount===r.sourceCount?`数据暂不可用`:`部分数据不可用`,description:r.unavailableCount===r.sourceCount?`本次未能取得仪表盘数据,请检查服务连接后刷新重试。`:`${r.unavailableCount} 项数据源未能加载,相关数值以 — 显示。已返回的数据仍可查看,请稍后刷新重试。`}),f.length>0&&(0,F.jsx)(o,{className:`dashboard-notice`,type:`warning`,fullMode:!1,closeIcon:null,description:(0,F.jsxs)(u,{wrap:!0,spacing:8,children:[(0,F.jsx)(Y,{strong:!0,children:`需要关注`}),f.map(e=>(0,F.jsx)(p,{theme:`borderless`,type:`warning`,icon:(0,F.jsx)(y,{}),iconPosition:`right`,onClick:()=>t(e.page),children:e.text},e.id))]})}),(0,F.jsxs)(`div`,{className:`dashboard-grid`,children:[(0,F.jsxs)(`div`,{className:`dashboard-column`,children:[(0,F.jsx)(re,{stats:r?.vulnStats,pendingStats:r?.pendingVulnStats,latest:r?.vulnList?.vulnerabilities?.[0]?.created_at,loadedAt:r?.loadedAt,loading:i}),(0,F.jsx)(M,{title:e(`dashboard.recentVulns`,null,`最近漏洞`),extra:(0,F.jsx)(p,{theme:`borderless`,size:`small`,icon:(0,F.jsx)(y,{}),iconPosition:`right`,onClick:()=>t(`/vulnerabilities`),children:`查看全部`}),children:(0,F.jsx)(oe,{data:r?.vulnList,loading:i,onOpen:e=>t(`/vulnerabilities?id=${encodeURIComponent(e)}`)})})]}),(0,F.jsxs)(`div`,{className:`dashboard-column`,children:[(0,F.jsx)(M,{title:e(`dashboard.projects`,null,`项目概览`),extra:(0,F.jsx)(p,{theme:`borderless`,size:`small`,icon:(0,F.jsx)(y,{}),iconPosition:`right`,onClick:()=>t(`/projects`),children:`全部项目`}),children:(0,F.jsx)(ue,{summary:r?.projectSummary,loading:i,onOpen:C})}),(0,F.jsx)(M,{title:e(`dashboard.toolsTop`,null,`工具调用 Top`),extra:(0,F.jsx)(p,{theme:`borderless`,size:`small`,onClick:()=>t(`/mcp-monitor`),children:`调用监控`}),children:(0,F.jsx)(le,{data:r?.monitorStats,loading:i})}),(0,F.jsx)(M,{className:`dashboard-capability-card`,bodyClassName:`dashboard-capability-body`,title:e(`dashboard.capability`,null,`能力与运行态`),children:(0,F.jsx)(s,{className:`dashboard-capabilities`,split:!1,dataSource:_,renderItem:e=>(0,F.jsx)(s.Item,{children:(0,F.jsxs)(p,{block:!0,theme:`borderless`,type:`tertiary`,className:`dashboard-capability`,onClick:()=>t(e.page),children:[(0,F.jsx)(`span`,{children:e.label}),(0,F.jsx)(`span`,{className:`dashboard-capability-value`,children:i?`…`:V(e.value)})]})},e.id)})})]})]}),(0,F.jsx)(M,{className:`dashboard-facts-card`,title:e(`dashboard.recentFacts`,null,`近期事实`),children:(0,F.jsx)(se,{summary:r?.projectSummary,loading:i,onOpen:C})})]})}function le({data:e,loading:t}){let n=Z(e,`topTools`),r=n?.slice(0,8).map(e=>({name:e.name||e.toolName||`未命名工具`,count:B(e.count??e.calls??e.totalCalls)}))||[],i=Math.max(...r.map(e=>e.count??0),1);return(0,F.jsx)(s,{className:`dashboard-list`,loading:t,dataSource:r,emptyContent:(0,F.jsx)($,{loading:t,unavailable:n===null,title:`暂无工具调用`,description:`执行任务后,可在这里查看使用最多的工具。`}),renderItem:(e,t)=>(0,F.jsxs)(s.Item,{className:`dashboard-tool-row`,children:[(0,F.jsx)(Y,{type:`tertiary`,size:`small`,className:`dashboard-tool-rank`,children:t+1}),(0,F.jsxs)(`div`,{className:`dashboard-record`,children:[(0,F.jsxs)(`div`,{className:`dashboard-tool-heading`,children:[(0,F.jsx)(Y,{className:`dashboard-tool-name`,title:e.name,children:e.name}),(0,F.jsxs)(Y,{type:`secondary`,size:`small`,className:`dashboard-count`,children:[V(e.count),` 次`]})]}),e.count!==null&&(0,F.jsx)(_,{percent:Math.round(e.count/i*100),showInfo:!1,size:`small`,stroke:`var(--semi-color-primary)`,"aria-label":`${e.name}调用次数`,"aria-valuetext":`${V(e.count)} 次`})]})]},`${e.name}-${t}`)})}function ue({summary:e,loading:t,onOpen:n}){let r=Z(e,`projects`),i=Z(e,`recent_facts`,`facts`),a=e?.totals||e,o=[[`活跃项目`,a?.active_projects??a?.activeProjects],[`事实总数`,a?.total_facts??a?.totalFacts],[`最近事实`,i?.length]];return(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`dl`,{className:`dashboard-project-totals`,children:o.map(([e,n])=>(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`dt`,{children:e}),(0,F.jsx)(`dd`,{children:t?`…`:V(n)})]},e))}),(0,F.jsx)(s,{className:`dashboard-list dashboard-feed`,loading:t,dataSource:r?.slice(0,6)||[],emptyContent:(0,F.jsx)($,{loading:t,unavailable:!e,title:r===null?`在项目中继续工作`:`暂无项目`,description:r===null?`当前摘要提供项目与事实统计,完整列表请查看全部项目。`:`创建项目后,在这里跟进项目进展。`}),renderItem:e=>(0,F.jsx)(s.Item,{main:(0,F.jsxs)(`div`,{className:`dashboard-record`,children:[(0,F.jsx)(p,{theme:`borderless`,className:`dashboard-record-link`,onClick:()=>n(e.id),children:e.name||`未命名项目`}),(0,F.jsxs)(Y,{type:`tertiary`,size:`small`,className:`dashboard-meta`,children:[e.status||`—`,` · `,T(e.updated_at)]})]})},e.id)})]})}export{ce as default}; \ No newline at end of file diff --git a/web/static/app/assets/deep-assessments-C1zSIX6t.js b/web/static/app/assets/deep-assessments-BwHg6NCr.js similarity index 99% rename from web/static/app/assets/deep-assessments-C1zSIX6t.js rename to web/static/app/assets/deep-assessments-BwHg6NCr.js index aefa0d62..52abaa66 100644 --- a/web/static/app/assets/deep-assessments-C1zSIX6t.js +++ b/web/static/app/assets/deep-assessments-BwHg6NCr.js @@ -1,2 +1,2 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,u as r,y as i}from"./react-QV7DAAIx.js";import{B as a,E as o,G as s,I as c,Lt as l,N as u,P as d,R as f,S as p,U as m,W as h,c as g,d as _,ft as v,g as y,h as b,i as x,lt as S,s as C,ut as w,x as T,y as ee}from"./semi-65W_4I1v.js";import{D as E,E as D,F as O,I as k,L as A,R as j,S as M,_ as N,a as P,b as F,c as I,d as L,f as R,h as te,l as z,m as B,n as ne,o as V,p as re,r as ie,s as H,t as ae,u as U,v as oe,x as W,y as se}from"./index-CAEPLS-g.js";import{n as ce,r as le}from"./model-channel-mQ6lfvSO.js";import{t as ue}from"./project-form-Bm3Gi6Yc.js";import{a as G,i as de,n as K,o as fe,r as pe,t as me}from"./graph-parents-i1hc3RVG.js";var q=e(t(),1),J={draft:`草稿`,running:`执行中`,pending:`待执行`,completed:`已完成`,blocked:`受阻`,failed:`失败`,paused:`已暂停`,pausing:`暂停中`,cancelling:`停止中`,cancelled:`已停止`,recovering:`待恢复`,waiting_retry:`等待模型恢复`,waiting_input:`待答复`,waiting_progress:`等待新进展`,needs_review:`待核对`,uncertain:`结果不明`,interrupted:`已中断`,cleanup_unconfirmed:`待确认资源停止`,retired:`已撤下`,reconciled:`已核对`,yielded:`分段完成`,archived:`已归档`},Y=[`running`,`pausing`,`cancelling`],X=[`completed`,`cancelled`],Z=[`needs_review`,`uncertain`,`cleanup_unconfirmed`],he={goal:`目标`,step:`探索意图`,observation:`观察`,receipt:`执行回执`,memory:`Pi 摘要`,digest:`历史归档`,guidance:`人工线索`,fact:`事实`,finding:`漏洞`},ge={observed:`直接观察`,inferred:`推断待证`,reported:`待独立复核`,confirmed:`复核确认`,refuted:`复核否定`,inconclusive:`复核未定`,unreviewed:`历史记录待核对`,summary:`压缩摘要`,note:`观察记录`,user:`用户提供`,folded:`已折叠`,superseded:`已替代的归档`,completed:`已完成`,running:`处理中`,failed:`失败`,uncertain:`结果待核对`,cancelled:`已取消`,reconciled:`已核对`,interrupted:`已中断`,error:`执行失败`,missing:`缺证据`,needs_review:`待复核`,has_evidence:`已有证据`},_e={started:`开始/继续测评`,reopened:`继续已停止的测评`,step_started:`意图开始执行`,planning:`更新计划`,plan_updated:`计划已更新`,checkpoint:`已保存进展`,step_result:`意图执行结果`,settled:`调度已结束`,stop_requested:`暂停/停止请求`,intent_pause:`暂停此意图`,intent_resume:`意图已恢复排队`,intent_priority:`优先级已调整`,intent_guidance:`收到定向补充`,waiting_progress:`等待新进展`,waiting_retry:`等待模型恢复`,waiting_input:`等待答复`,blocked:`执行受阻`,guidance:`收到补充方向`,retry_scheduled:`稍后重试模型`,review_gap:`验收仍有缺口`,shutdown:`保存进度并关闭`,retry:`步骤已重新排队`,reconciled:`已确认核对`},ve={observed:`已观察`,inferred:`推断`},ye={observed:`green`,inferred:`amber`},be={has_evidence:`已有证据`,missing:`缺证据`,needs_review:`待人工复核`},xe={has_evidence:`green`,missing:`red`,needs_review:`amber`},Se=`assessments:write`,Ce=`assessments:delete`;function Q(e,t){return t?e(`deepAssessments.states.${t}`,null,J[t]||t):`—`}function we(e,t){return e(`deepAssessments.graphKinds.${t}`,null,he[t]||t||`节点`)}function Te(e,t){return t?e(`deepAssessments.graphStates.${t}`,null,ge[t]||Q(e,t)):`—`}function Ee(e,t){return t?e(`deepAssessments.workbench.events.${t}`,null,_e[t]||t):`事件`}function De(e,t){return e(`deepAssessments.confidence.${t}`,null,ve[t]||t||`—`)}function Oe(e,t){return e(`deepAssessments.acceptanceStatus.${t}`,null,be[t]||t||`—`)}function ke(e){return Y.includes(e?.status)}function Ae(e){return X.includes(e?.status)}function je(e){return e?Number(e.review_count)>0||Z.includes(e.status)?!0:(e.steps||[]).some(e=>Z.includes(e.status)):!1}function Me(e){return!!e&&!e.archived&&!Ae(e)&&!ke(e)&&!e.question&&e.status!==`waiting_input`}function Ne(e){return!!e&&!e.archived&&[`running`,`recovering`,`waiting_retry`,`waiting_progress`].includes(e.status)}function Pe(e){return!!e&&!e.archived&&!Ae(e)}function Fe(e){return!!e&&e.status===`cancelled`&&!e.archived}function Ie(e){return!!e&&!e.archived&&!ke(e)&&!je(e)&&![`recovering`,`needs_review`,`uncertain`,`cleanup_unconfirmed`].includes(e.status)}function Le(e){return!!e?.archived}function Re(e){return!!e&&!ke(e)}function ze(e,t){let n=e||{},r=(n.completed||0)+(n.retired||0),i=Number.isFinite(t)&&t>0?t:Object.values(n).reduce((e,t)=>e+Number(t||0),0),a=i>0?Math.round(r/i*100):0;return{done:r,total:i,percent:Math.min(100,Math.max(0,a))}}function Be(e){let t=Math.floor(Number(e));if(!Number.isFinite(t)||t<0)return`—`;if(t<60)return`${t} 秒`;let n=`${Math.floor(t/60)%60} 分 ${t%60} 秒`;return t<3600?n:`${Math.floor(t/3600)} 小时 ${n}`}function Ve(e,t=80){let n=String(e??``);return n.length>t?`${n.slice(0,t)}…`:n}function He(e){if(typeof e!=`string`)return e;let t=e.trim();if(!t||t[0]!==`{`&&t[0]!==`[`)return e;try{return JSON.parse(t)}catch{return e}}var Ue={goal:`#0066ff`,step:`#13a8a8`,fact:`#00b42a`,finding:`#f53f3f`,observation:`#722ed1`,receipt:`#86909c`,memory:`#ff7d00`,digest:`#c9cdd4`,guidance:`#eb2f96`},$=e(n(),1),We=[{value:``,label:`系统默认`},{value:`off`,label:`关闭审批`},{value:`human`,label:`人工审批`},{value:`audit_agent`,label:`审计代理审批`},{value:`review_edit`,label:`复核并允许编辑`}],Ge=[{value:``,label:`继承项目设置 / 默认不限速`},{value:`off`,label:`关闭限速提示(off)`},{value:`quiet`,label:`低噪串行(quiet · 2 RPS)`},{value:`balanced`,label:`均衡速率(balanced · 5 RPS)`},{value:`aggressive`,label:`维护窗口高吞吐(aggressive · 20 RPS)`}],Ke=`默认`;function qe(e){if(typeof e==`string`)return{name:e.trim(),icon:``};if(!e||typeof e!=`object`)return null;let t=String(e.name||``).trim();return t?{name:t,icon:String(e.icon||``).trim()}:null}function Je(e){return{value:e.name===Ke?``:e.name,name:e.name,icon:e.icon,label:(0,$.jsxs)(`span`,{className:`assessment-role-option`,children:[e.icon?(0,$.jsx)(`span`,{className:`assessment-role-icon`,"aria-hidden":`true`,children:e.icon}):null,(0,$.jsx)(`span`,{children:e.name})]})}}function Ye(e){let t=(Array.isArray(e)?e:[]).map(qe).filter(Boolean),n=t.filter(e=>e.name!==Ke),r=t.find(e=>e.name===Ke);return[...r?[Je(r)]:[],...n.map(Je)]}function Xe({projectId:e}){let t=O(),n=P(()=>A.get(`/assets`,{project_id:e,page:1,page_size:1}),[e]),r=Number.isFinite(Number(n.data?.total))?Number(n.data.total):null,i=t(`common.loading`,null,`加载中…`);return!n.loading&&n.error?i=`资产库暂时读不到。保存后仍使用该项目在资产库中的资产。`:!n.loading&&r===0?i=`这个项目的资产库还是空的。测评中新发现的目标会写进资产库,对话和批量任务也能看到。`:!n.loading&&r!=null&&(i=`资产范围是资产库里这个项目的 ${r} 个资产。对话、批量任务和这次测评用的是同一批,会自动交给模型。`),(0,$.jsx)(x.Slot,{label:t(`deepAssessments.assetScope`,null,`资产范围`),children:(0,$.jsx)(s.Text,{type:`tertiary`,role:`status`,children:i})})}function Ze({visible:e,onCancel:t,onCreated:n}){let r=O(),i=r(`deepAssessments.create`,null,`新建测评`),{hasPermission:o}=k(),s=o(`project:read`)&&o(`project:write`),c=(0,q.useId)(),l=(0,q.useRef)(null),[u,d]=(0,q.useState)(null),[p,m]=(0,q.useState)(null),[g,_]=(0,q.useState)(!1),[y,b]=(0,q.useState)(!1),[S,C]=(0,q.useState)(``),w=g||y,T=(0,q.useCallback)(()=>{d(null),m(null),C(``),A.get(`/deep-assessments/options`).then(e=>d(e||{})).catch(e=>m(e))},[]);(0,q.useEffect)(()=>{e&&T()},[e,T]);let ee=e=>{C(e||``)},E=async e=>{if(!w){_(!0);try{let t={name:String(e.name||``).trim(),objective:String(e.objective||``).trim(),scope:String(e.scope||``).trim(),criteria:String(e.criteria||``).trim(),project_id:e.project_id||``,role:e.role||``,model:e.model||``,hitl_policy:e.hitl_policy||``,noise_profile:e.noise_profile||``,concurrency:Number(e.concurrency)||2,auto_resume:e.auto_resume!==!1},i=await A.post(`/deep-assessments`,t);W(r(`deepAssessments.saved`,null,`已创建测评`)),n?.(i?.task)}catch(e){F(e,r(`deepAssessments.saveFailed`,null,`创建失败`))}finally{_(!1)}}},D=e=>{b(!1),e?.id&&(d(t=>({...t,projects:[e,...t?.projects||[]]})),l.current?.setValue(`project_id`,e.id),ee(e.id))},j=ce((u?.models||[]).map(e=>[e.id,e])),M=Ye(u?.roles),N=(u?.projects||[]).map(e=>({value:e.id,label:e.name||e.id}));return(0,$.jsxs)(I,{visible:e,title:i,"aria-label":i,onCancel:t,width:680,closable:!w,closeOnEsc:!w,maskClosable:!w,footer:(0,$.jsxs)(`div`,{className:`assessment-form-actions`,children:[(0,$.jsx)(f,{theme:`borderless`,onClick:t,disabled:w,children:r(`deepAssessments.close`,null,`关闭`)}),(0,$.jsx)(f,{htmlType:`submit`,form:c,theme:`solid`,type:`primary`,loading:g,disabled:w||!u&&!p,children:r(`deepAssessments.save`,null,`保存草稿`)})]}),children:[p?(0,$.jsxs)(`div`,{className:`assessment-error-block`,children:[(0,$.jsx)(z,{error:p}),(0,$.jsx)(f,{size:`small`,onClick:T,children:`重试`})]}):null,!u&&!p?(0,$.jsx)(`div`,{className:`assessment-loading`,children:(0,$.jsx)(h,{})}):(0,$.jsxs)(x,{id:c,getFormApi:e=>{l.current=e},initValues:{concurrency:2,auto_resume:!0,hitl_policy:``,noise_profile:``,role:``},labelPosition:`top`,autoScrollToError:!0,onSubmit:E,children:[(0,$.jsx)(x.Input,{field:`name`,label:r(`deepAssessments.name`,null,`测评名称`),maxLength:200,placeholder:`留空则取目标前 80 个字符`}),(0,$.jsx)(x.TextArea,{field:`objective`,label:r(`deepAssessments.objective`,null,`目标`),rows:3,maxLength:16e3,placeholder:`要达成的最终结果,例如:评估 example.com 对外接口的认证与越权风险并给出可复现证据。`,rules:[{required:!0,message:`请填写测评目标`}]}),(0,$.jsx)(x.TextArea,{field:`scope`,label:r(`deepAssessments.scopeOptional`,null,`补充限制与排除项(选填)`),rows:2,maxLength:16e3,placeholder:`例如:排除支付接口;不修改生产数据;不做压力测试。留空表示无额外限制。`}),(0,$.jsx)(x.TextArea,{field:`criteria`,label:r(`deepAssessments.criteriaOptional`,null,`验收条件(选填)`),rows:3,maxLength:8e3,placeholder:`每行一条验收条件,例如:确认的漏洞附复现步骤和原始证据。留空沿用目标。`}),(0,$.jsxs)(`div`,{className:`assessment-form-grid`,children:[(0,$.jsx)(x.Select,{field:`model`,label:r(`deepAssessments.model`,null,`模型渠道`),optionList:[{value:``,label:`系统默认`},...j],renderSelectedItem:le,style:{width:`100%`}}),(0,$.jsx)(x.Select,{field:`role`,label:r(`deepAssessments.role`,null,`角色`),optionList:M,renderSelectedItem:e=>(0,$.jsxs)(`span`,{className:`assessment-role-option`,children:[e.icon?(0,$.jsx)(`span`,{className:`assessment-role-icon`,"aria-hidden":`true`,children:e.icon}):null,(0,$.jsx)(`span`,{children:e.name})]}),style:{width:`100%`}}),(0,$.jsxs)(`div`,{className:`assessment-project-field`,children:[(0,$.jsx)(x.Select,{field:`project_id`,label:r(`deepAssessments.project`,null,`关联项目`),optionList:[{value:``,label:`不关联`},...N],style:{width:`100%`},onChange:ee}),s&&(0,$.jsx)(f,{icon:(0,$.jsx)(v,{"aria-hidden":!0}),theme:`light`,type:`primary`,disabled:g,onClick:()=>b(!0),children:r(`projects.newProject`,null,`新建项目`)})]}),S&&(0,$.jsx)(Xe,{projectId:S},S),(0,$.jsx)(x.InputNumber,{field:`concurrency`,label:r(`deepAssessments.concurrency`,null,`并行步骤`),min:1,max:4,style:{width:`100%`}})]}),(0,$.jsxs)(`div`,{className:`assessment-form-grid`,children:[(0,$.jsx)(x.Select,{field:`hitl_policy`,label:`人工审批策略`,optionList:We,style:{width:`100%`}}),(0,$.jsx)(x.Select,{field:`noise_profile`,label:r(`deepAssessments.noiseProfile`,null,`任务速率/噪音档位`),optionList:Ge,style:{width:`100%`}})]}),(0,$.jsx)(x.Switch,{field:`auto_resume`,label:r(`deepAssessments.autoResume`,null,`服务重启后自动恢复结果明确的步骤`)}),(0,$.jsx)(a,{type:`info`,bordered:!0,closeIcon:null,className:`assessment-form-note`,description:`创建后保存为草稿,需要手动点击“开始 / 继续”才会执行。关联项目后,资产范围直接使用资产库中的项目资产。`})]}),y&&(0,$.jsx)(ue,{visible:!0,onCancel:()=>b(!1),onSaved:D})]})}var{Text:Qe}=s,$e=[`draft`,`running`,`paused`,`blocked`,`failed`,`waiting_input`,`waiting_retry`,`recovering`,`uncertain`,`cleanup_unconfirmed`,`completed`,`cancelled`].map(e=>({value:e,label:J[e]}));function et({onOpen:e}){let t=O(),{hasPermission:n}=k(),[r,i]=(0,q.useState)(``),[a,o]=(0,q.useState)(``),[s,u]=(0,q.useState)(!1),[d,p]=(0,q.useState)(0),[h,g]=(0,q.useState)(!1),[_,x]=(0,q.useState)({}),C=ne(r,300),T=n(Se),j=n(Ce),M=(0,q.useMemo)(()=>({q:C,status:a,limit:20,offset:d*20,archived:s?`true`:``}),[C,a,d,s]),N=P(()=>A.get(`/deep-assessments`,M),[M]),I=(0,q.useMemo)(()=>N.data?.tasks||[],[N.data]);(0,q.useEffect)(()=>{p(0)},[C,a,s]),(0,q.useEffect)(()=>{let e=I.filter(e=>!_[`${e.id}:${e.updated_at}`]);if(!e.length)return;let t=!1,n=0,r={},i=async()=>{for(;!t&&n{!t&&Object.keys(r).length&&x(e=>({...e,...r}))}),()=>{t=!0}},[I]);let L=e=>{se({title:t(`deepAssessments.delete`,null,`删除`),content:`删除测评「${e.name||e.id}」?关联执行会话仍保留。`,okText:t(`deepAssessments.delete`,null,`删除`),onOk:async()=>{try{await A.del(`/deep-assessments/${e.id}`),W(t(`deepAssessments.deleted`,null,`已删除`)),await N.reload()}catch(e){F(e,t(`deepAssessments.deleteFailed`,null,`删除失败`))}}})},R=[{title:t(`deepAssessments.name`,null,`测评名称`),dataIndex:`name`,width:260,render:(t,n)=>(0,$.jsxs)(`div`,{className:`assessment-list-name`,children:[(0,$.jsx)(f,{theme:`borderless`,className:`assessment-link`,onClick:()=>e?.(n.id),children:t||n.id}),(0,$.jsx)(Qe,{type:`tertiary`,size:`small`,className:`assessment-ellipsis`,children:n.id})]})},{title:t(`deepAssessments.status`,null,`状态`),dataIndex:`status`,width:130,render:(e,n)=>(0,$.jsxs)(c,{spacing:4,children:[(0,$.jsx)(oe,{status:e,label:Q(t,e)}),n.archived?(0,$.jsx)(oe,{status:`archived`,label:Q(t,`archived`)}):null,je(n)?(0,$.jsx)(oe,{status:`needs_review`,label:Q(t,`needs_review`)}):null]})},{title:t(`deepAssessments.objective`,null,`目标`),dataIndex:`summary`,render:(e,t)=>{let n=_[`${t.id}:${t.updated_at}`]?.objective||e||`—`;return(0,$.jsx)(Qe,{ellipsis:{showTooltip:!0},className:`assessment-ellipsis`,children:n})}},{title:`进度`,width:190,align:`left`,render:(e,t)=>{let n=_[`${t.id}:${t.updated_at}`];if(!n)return(0,$.jsx)(Qe,{type:`tertiary`,children:`—`});let r=ze(n.counts,n.total);return(0,$.jsxs)(`div`,{className:`assessment-progress`,children:[(0,$.jsx)(y,{percent:r.percent,showInfo:!0,size:`small`,strokeWidth:6}),(0,$.jsxs)(Qe,{type:`tertiary`,size:`small`,children:[r.done,` / `,r.total,` 意图`]})]})}},{title:t(`deepAssessments.rounds`,null,`规划轮次`),dataIndex:`rounds`,width:100,render:e=>E(e||0)},{title:t(`deepAssessments.createdAt`,null,`创建时间`),dataIndex:`created_at`,width:170,render:e=>D(e)},{title:`操作`,width:150,render:(n,r)=>(0,$.jsxs)(c,{spacing:4,children:[(0,$.jsx)(f,{theme:`borderless`,size:`small`,onClick:()=>e?.(r.id),children:`进入`}),(0,$.jsx)(f,{theme:`borderless`,type:`danger`,size:`small`,icon:(0,$.jsx)(l,{}),disabled:!j||!Re(r),onClick:()=>L(r),children:t(`deepAssessments.delete`,null,`删除`)})]})}];return(0,$.jsxs)(`div`,{className:`assessment-page`,children:[(0,$.jsx)(re,{title:t(`deepAssessments.title`,null,`深度测评`),description:t(`deepAssessments.subtitle`,null,`围绕一个目标持续探索,保存证据与进度,跨会话继续执行。`),extra:[(0,$.jsx)(f,{icon:(0,$.jsx)(w,{}),onClick:()=>N.reload(),loading:N.loading,children:t(`deepAssessments.refresh`,null,`刷新`)},`refresh`),(0,$.jsx)(f,{icon:(0,$.jsx)(v,{}),theme:`solid`,type:`primary`,disabled:!T,onClick:()=>g(!0),children:t(`deepAssessments.create`,null,`新建测评`)},`create`)]}),(0,$.jsx)(z,{error:N.error,onRetry:()=>N.reload()}),(0,$.jsxs)(B,{className:`assessment-list-card`,title:t(`deepAssessments.listTitle`,null,`测评列表`),extra:(0,$.jsx)(b,{className:`assessment-view-options`,"aria-label":t(`deepAssessments.archiveFilter`,null,`归档状态`),type:`button`,value:s?`archived`:`unarchived`,options:[{value:`unarchived`,label:t(`deepAssessments.unarchivedTasks`,null,`未归档`)},{value:`archived`,label:t(`deepAssessments.archivedTasks`,null,`已归档`)}],onChange:e=>u(e.target.value===`archived`)}),children:[(0,$.jsxs)(`div`,{className:`assessment-toolbar`,children:[(0,$.jsx)(m,{prefix:(0,$.jsx)(S,{}),value:r,onChange:i,placeholder:t(`deepAssessments.search`,null,`搜索测评名称`),style:{width:260},showClear:!0}),(0,$.jsx)(ee,{value:a,onChange:e=>o(e||``),optionList:[{value:``,label:t(`deepAssessments.all`,null,`全部状态`)},...$e],style:{width:160}})]}),(0,$.jsx)(H,{columns:R,dataSource:I,rowKey:`id`,loading:N.loading,pagination:!1,emptyText:t(`deepAssessments.empty`,null,`暂无测评,先创建一个目标。`)}),(0,$.jsx)(`div`,{className:`assessment-pager`,children:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:d===0,onClick:()=>p(e=>Math.max(0,e-1)),children:t(`deepAssessments.previous`,null,`上一页`)}),(0,$.jsxs)(Qe,{type:`tertiary`,children:[`第 `,d+1,` 页`]}),(0,$.jsx)(f,{size:`small`,disabled:!N.data?.has_more,onClick:()=>p(e=>e+1),children:t(`deepAssessments.next`,null,`下一页`)})]})})]}),(0,$.jsx)(Ze,{visible:h,onCancel:()=>g(!1),onCreated:t=>{g(!1),N.reload(),t?.id&&e?.(t.id)}})]})}var{Paragraph:tt,Text:nt}=s,rt=e=>JSON.stringify([e.surface,e.risk_area]),it=e=>JSON.stringify([e.kind,e.surface,e.risk_area,e.goal_id]);function at({id:e,reloadToken:t,onView:n}){let r=O(),i=P(()=>A.get(`/deep-assessments/${e}/coverage`),[e,t]),a=i.data,o=!!n,s=(e,t)=>r(`deepAssessments.coverage.${e}`,t),l={title:s(`surface`),dataIndex:`surface`,width:180,render:e=>e||`—`},d={title:s(`riskArea`),dataIndex:`risk_area`,width:140},p=[l,d,{title:s(`outcome`),dataIndex:`outcome`,width:150,render:e=>s(`outcomes.${e}`)},{title:s(`evidence`),dataIndex:`evidence`,width:180,render:e=>e||`—`},{title:s(`reason`),dataIndex:`reason`,render:e=>e||`—`}],m=[l,d,{title:s(`gap`),dataIndex:`kind`,render:e=>s(`gapKinds.${e}`)},{title:s(`goalRef`),dataIndex:`goal_id`,width:160,render:e=>e||`—`}];return(0,$.jsxs)(B,{title:s(`title`),extra:o?(0,$.jsx)(f,{size:`small`,onClick:n,children:s(`view`)}):(0,$.jsx)(f,{size:`small`,onClick:()=>i.reload(),loading:i.loading,children:r(`common.refresh`)}),children:[(0,$.jsx)(z,{error:i.error,onRetry:()=>i.reload()}),i.loading&&!a?(0,$.jsx)(nt,{type:`tertiary`,children:s(`loading`)}):null,a?(0,$.jsxs)(`div`,{className:`assessment-tab assessment-coverage`,children:[(0,$.jsx)(tt,{children:s(`summary`,{records:a.records.length,gaps:a.gaps.length})}),a.records.length>0?(0,$.jsx)(c,{wrap:!0,children:Object.entries(a.counts).map(([e,t])=>(0,$.jsxs)(u,{children:[s(`outcomes.${e}`),` · `,t]},e))}):null,o?(0,$.jsxs)($.Fragment,{children:[a.goals.length>0?(0,$.jsxs)(`section`,{children:[(0,$.jsx)(nt,{strong:!0,children:s(`goals`)}),(0,$.jsx)(`ul`,{children:a.goals.map(e=>(0,$.jsxs)(`li`,{children:[e.text,` `,e.risk_class?(0,$.jsx)(u,{size:`small`,children:e.risk_class}):null]},e.goal_id))})]}):null,a.constraints.length>0?(0,$.jsxs)(`section`,{children:[(0,$.jsx)(nt,{strong:!0,children:s(`constraints`)}),(0,$.jsx)(`ul`,{children:a.constraints.map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsx)(u,{size:`small`,children:s(`constraintKinds.${e.kind}`)}),` `,e.text,` `,(0,$.jsxs)(nt,{type:`tertiary`,children:[`(`,e.origin,`)`]})]},e.constraint_id))})]}):null]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{columns:p,dataSource:a.records,rowKey:rt,pagination:a.records.length>10&&void 0,emptyText:s(`emptyRecords`)}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(nt,{strong:!0,children:s(`gaps`)}),(0,$.jsx)(tt,{type:`tertiary`,children:s(`gapHint`)}),(0,$.jsx)(H,{columns:m,dataSource:a.gaps,rowKey:it,pagination:a.gaps.length>10&&void 0,emptyText:s(`emptyGaps`)})]})]})]}):null]})}var{Text:ot,Paragraph:st}=s,ct={blocked:`error`,waiting_input:`warning`,completed:`success`,stop_requested:`warning`,retry:`warning`};function lt({startedAt:e,seconds:t}){let[n,r]=(0,q.useState)(Date.now);return ie(()=>r(Date.now()),1e3),Be(t+Math.max(0,Math.floor((n-e)/1e3)))}function ut({id:e}){let[t,n]=(0,q.useState)(null);return(0,q.useEffect)(()=>{let t=!1;return A.get(`/assets/collections/${e}`).then(e=>{t||n(e?.collection||null)}).catch(()=>{t||n(null)}),()=>{t=!0}},[e]),t?(0,$.jsxs)(ot,{type:`tertiary`,children:[`本次范围 `,t.name,`:可见资产 `,t.member_count||0,` 个,已确认观察 `,t.observed||0,` 个。项目历史观察和逐项验收分开统计,缺证据的必验项保持未完成。`]}):null}function dt({task:e,canWrite:t,events:n,eventsError:r,autoRefresh:i,onAutoRefreshChange:a,onRefreshEvents:s,onGoTab:l,onGuidance:d,onAnswer:p,reloadToken:m}){let h=O(),g={};(e.steps||[]).forEach(e=>{g[e.status]=(g[e.status]||0)+1});let v=ze(g,(e.steps||[]).length),y=e.review_count||(e.steps||[]).filter(e=>[`uncertain`,`cleanup_unconfirmed`].includes(e.status)).length,b=e.active_seconds??0,x=ke(e)?Date.parse(e.run_started_at):NaN,S=Be(b);e.archived?S=`已归档`:Number.isFinite(x)&&(S=(0,$.jsx)(lt,{startedAt:x,seconds:b},x));let w=[{id:`status`,label:h(`deepAssessments.status`,null,`状态`),value:(0,$.jsx)(`span`,{className:`assessment-status-value`,children:Q(h,e.status)}),detail:S},{id:`progress`,label:`意图完成度`,value:`${v.percent}%`,detail:`${v.done} / ${v.total} 已结束`},{id:`rounds`,label:h(`deepAssessments.rounds`,null,`规划轮次`),value:E(e.rounds||0)},{id:`tokens`,label:h(`deepAssessments.tokens`,null,`累计 Token`),value:E(e.tokens_used||0)},{id:`review`,label:`待核对`,value:E(y),detail:y?`需要人工确认工具结果`:`无待核对记录`}],T=[{label:h(`deepAssessments.objective`,null,`目标`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.objective||`—`})},{label:h(`deepAssessments.scope`,null,`补充限制与排除项`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.scope&&e.scope.trim()!==(e.objective||``).trim()?e.scope:`—`})},{label:h(`deepAssessments.criteria`,null,`验收条件`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.criteria||`—`})},{label:h(`deepAssessments.strategy`,null,`最近规划路线`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.strategy||`—`})},{label:h(`deepAssessments.summary`,null,`当前结论 / 缺口`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.summary||`—`})}];e.question&&T.push({label:h(`deepAssessments.question`,null,`待补充信息`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.question})});let ee=n.slice().reverse().slice(0,120);return(0,$.jsxs)(`div`,{className:`assessment-tab`,children:[(0,$.jsx)(N,{metrics:w,columns:5}),e.collection_id?(0,$.jsx)(ut,{id:e.collection_id}):null,(0,$.jsxs)(B,{title:`目标与测评要求`,extra:(0,$.jsxs)(c,{children:[t&&!e.archived&&e.status!==`completed`&&e.status!==`cancelled`?(0,$.jsx)(f,{size:`small`,onClick:d,children:`补充方向`}):null,e.question?(0,$.jsx)(f,{size:`small`,theme:`solid`,type:`primary`,onClick:p,children:`答复`}):null,(0,$.jsx)(f,{size:`small`,onClick:()=>l?.(`intents`),children:`查看意图`})]}),children:[(0,$.jsx)(L,{items:T,columns:1}),(0,$.jsxs)(`div`,{className:`assessment-facts-row`,children:[(0,$.jsxs)(ot,{type:`tertiary`,children:[`自动续跑:`,e.auto_resume?`已开启`:`已关闭`]}),(0,$.jsxs)(ot,{type:`tertiary`,children:[`并行步骤:`,e.concurrency||`—`]}),(0,$.jsxs)(ot,{type:`tertiary`,children:[`人工审批:`,e.hitl_policy||`系统默认`]}),e.noise_profile?(0,$.jsxs)(ot,{type:`tertiary`,children:[`噪音档位:`,e.noise_profile]}):null,(0,$.jsxs)(ot,{type:`tertiary`,children:[`最近更新:`,D(e.updated_at)]})]}),Array.isArray(e.guidance)&&e.guidance.length?(0,$.jsxs)(`div`,{className:`assessment-guidance`,children:[(0,$.jsx)(ot,{strong:!0,children:`人工补充`}),e.guidance.map((e,t)=>(0,$.jsxs)(`div`,{className:`assessment-guidance-item`,children:[(0,$.jsxs)(ot,{type:`tertiary`,children:[`#`,t+1]}),(0,$.jsx)(st,{className:`assessment-pre`,children:e})]},`${t}-${e.slice(0,8)}`))]}):null,(0,$.jsx)(st,{type:`tertiary`,className:`assessment-hint`,children:`打开页面不会自动启动任务;自动续跑只针对服务重启前的执行,草稿、手动暂停和待核对任务不会自动开始。`})]}),(0,$.jsx)(at,{id:e.id,reloadToken:m,onView:()=>l?.(`acceptance`)},e.id),(0,$.jsxs)(B,{title:h(`deepAssessments.activity`,null,`运行记录`),description:`事件按时间倒序展示;运行中每 10 秒自动拉取,页面隐藏时跳过。`,extra:(0,$.jsxs)(c,{children:[(0,$.jsx)(ot,{type:`tertiary`,size:`small`,children:`自动刷新`}),(0,$.jsx)(_,{size:`small`,checked:i,onChange:e=>a?.(!!e)}),(0,$.jsx)(f,{size:`small`,onClick:s,children:`立即刷新`})]}),children:[(0,$.jsx)(z,{error:r,onRetry:s}),ee.length===0?(0,$.jsx)(o,{title:`暂无运行记录`,description:`开始测评后,规划、执行与核对事件会显示在这里。`,style:{padding:32}}):(0,$.jsx)(`div`,{className:`assessment-timeline`,children:(0,$.jsx)(C,{children:ee.map(e=>(0,$.jsxs)(C.Item,{time:D(e.created_at),type:ct[e.kind]||`default`,children:[(0,$.jsxs)(`div`,{className:`assessment-event-head`,children:[(0,$.jsx)(ot,{strong:!0,children:Ee(h,e.kind)}),e.step_id?(0,$.jsx)(u,{size:`small`,color:`grey`,children:e.step_id}):null]}),e.message?(0,$.jsx)(`div`,{className:`assessment-event-message`,children:e.message}):null]},e.id))})})]})]})}var{Text:ft,Paragraph:pt}=s,mt=[`running`,`pending`,`pausing`,`paused`,`completed`,`blocked`,`failed`,`uncertain`,`cleanup_unconfirmed`,`interrupted`,`retired`,`reconciled`];function ht({id:e,reloadToken:t,status:n,onStatusChange:r,onChanged:i,archived:a,taskStatus:o,revision:s}){let l=O(),{hasPermission:d}=k(),p=d(Se),[m,h]=(0,q.useState)(!1),[g,_]=(0,q.useState)(!1),[v,y]=(0,q.useState)(0),[b,x]=(0,q.useState)(null);(0,q.useEffect)(()=>{y(0)},[n]);let S=P(()=>A.get(`/deep-assessments/${e}/intents`,{status:n,offset:v}),[e,n,v,t]),C=S.data,w=C?.intents||[],T=C?.counts||{},D=async t=>{h(!0);try{await A.post(`/deep-assessments/${e}/control/intent-pause`,{revision:s,step_id:t.id}),W(`已提交此方向的暂停请求`)}catch(e){F(e,`暂停方向失败`)}finally{h(!1),x(null),i?.()}},j=t=>{se({title:`确认已核对`,content:`确认只解除本步骤的待核对状态,不会自动执行;原有进度和证据保留。`,okText:`确认已核对`,danger:!1,onOk:async()=>{_(!0);try{let n=await A.get(`/deep-assessments/${e}/steps/${t.id}`);await A.post(`/deep-assessments/${e}/control/reconcile`,{revision:n?.revision,step_id:t.id,reconciled:!0,cleanup_confirmed:!0}),W(`已记录核对,待核对列表已更新`),x(null),await S.reload(),i?.()}catch(e){F(e,`核对失败`)}finally{_(!1)}}})},M=(0,q.useMemo)(()=>{let e=mt.filter(e=>T[e]);return Object.keys(T).forEach(t=>{e.includes(t)||e.push(t)}),[{value:``,label:`${l(`deepAssessments.all`,null,`全部状态`)} · ${C?.total??0}`},...e.map(e=>({value:e,label:`${Q(l,e)} · ${T[e]}`}))]},[T,C?.total,l]),N=[{title:l(`deepAssessments.status`,null,`状态`),dataIndex:`status`,width:140,render:e=>(0,$.jsx)(oe,{status:e,label:Q(l,e)})},{title:`意图`,dataIndex:`title`,render:(e,t)=>(0,$.jsxs)(`div`,{className:`assessment-list-name`,children:[(0,$.jsx)(ft,{ellipsis:{showTooltip:!0},children:e||t.id}),t.summary?(0,$.jsx)(ft,{type:`tertiary`,size:`small`,className:`assessment-ellipsis`,children:Ve(t.summary,120)}):null]})},{title:l(`deepAssessments.priority`,null,`优先级`),dataIndex:`priority`,width:90,render:e=>e||100},{title:l(`deepAssessments.assets`,null,`关联资产`),dataIndex:`asset_ids`,width:100,render:e=>(e||[]).length||`—`},{title:`证据回执`,dataIndex:`evidence`,width:100,render:e=>(e||[]).length||`—`},{title:`执行分段`,dataIndex:`attempts`,width:90,render:e=>E(e||0)},{title:`最近进展`,dataIndex:`last_progress`,render:e=>e?(0,$.jsx)(ft,{type:`tertiary`,ellipsis:{showTooltip:!0},children:e}):`—`}];return(0,$.jsxs)(`div`,{className:`assessment-tab`,children:[(0,$.jsxs)(B,{title:l(`deepAssessments.plan`,null,`意图队列`),description:`队列按优先级排序;状态只表示执行情况,不代表漏洞或完成结论。`,extra:(0,$.jsx)(f,{size:`small`,onClick:()=>S.reload(),loading:S.loading,children:`刷新`}),children:[(0,$.jsxs)(`div`,{className:`assessment-toolbar`,children:[(0,$.jsx)(ee,{value:n,onChange:e=>r?.(e||``),optionList:M,style:{width:200}}),(0,$.jsxs)(ft,{type:`tertiary`,children:[`共 `,C?.total??0,` 条意图`]})]}),(0,$.jsx)(z,{error:S.error,onRetry:()=>S.reload()}),(0,$.jsx)(H,{columns:N,dataSource:w,rowKey:`id`,loading:S.loading,pagination:!1,onRow:e=>({onClick:()=>x(e),style:{cursor:`pointer`}}),emptyText:l(`deepAssessments.noIntents`,null,`暂无意图,开始测评后由规划器逐步生成探索方向。`)}),(0,$.jsx)(`div`,{className:`assessment-pager`,children:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:v===0,onClick:()=>y(e=>Math.max(0,e-20)),children:l(`deepAssessments.previous`,null,`上一页`)}),(0,$.jsx)(ft,{type:`tertiary`,children:w.length?`${v+1} - ${v+w.length}`:`0`}),(0,$.jsx)(f,{size:`small`,disabled:!C?.has_more,onClick:()=>y(e=>e+20),children:l(`deepAssessments.next`,null,`下一页`)})]})})]}),(0,$.jsx)(I,{visible:!!b,onCancel:()=>x(null),title:b?.title||`意图详情`,width:560,footer:null,children:b?(0,$.jsxs)(`div`,{className:`assessment-drawer`,children:[p&&!a&&o===`running`&&[`pending`,`running`].includes(b.status)&&(0,$.jsx)(f,{onClick:()=>D(b),loading:m,disabled:m,children:`暂停此方向`}),(0,$.jsx)(L,{columns:2,items:[{label:l(`deepAssessments.status`,null,`状态`),value:(0,$.jsx)(oe,{status:b.status,label:Q(l,b.status)})},{label:`意图 ID`,value:b.id},{label:l(`deepAssessments.priority`,null,`优先级`),value:b.priority||100},{label:`执行分段`,value:b.attempts||0},{label:`手动暂停`,value:b.user_paused?`是`:`否`},{label:`执行会话`,value:b.conversation_id||`—`},{label:l(`deepAssessments.assets`,null,`关联资产`),value:(b.asset_ids||[]).join(`, `)||`—`},{label:`来源节点`,value:(b.source_ids||[]).join(`, `)||`—`},{label:`前置意图`,value:(b.depends_on||[]).join(`, `)||`—`},{label:`证据引用`,value:(b.evidence||[]).join(`, `)||`—`}]}),(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`执行说明`}),(0,$.jsx)(pt,{className:`assessment-pre`,children:b.instruction||`—`})]}),(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`结果摘要`}),(0,$.jsx)(pt,{className:`assessment-pre`,children:b.summary||`—`})]}),b.last_progress?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`最近进展`}),(0,$.jsx)(pt,{className:`assessment-pre`,children:b.last_progress})]}):null,Array.isArray(b.guidance)&&b.guidance.length?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`定向补充`}),b.guidance.map((e,t)=>(0,$.jsxs)(`div`,{className:`assessment-guidance-item`,children:[(0,$.jsxs)(u,{size:`small`,color:`grey`,children:[`#`,t+1]}),(0,$.jsx)(pt,{className:`assessment-pre`,children:e})]},`${t}-${e.slice(0,8)}`))]}):null,[`uncertain`,`cleanup_unconfirmed`].includes(b.status)?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`待核对`}),(0,$.jsx)(pt,{type:`tertiary`,className:`assessment-hint`,children:`确认只解除本步骤的待核对状态,不会自动执行;仍有结果不明的调用时请保持停止。`}),(0,$.jsx)(f,{size:`small`,theme:`solid`,type:`primary`,disabled:!p||a,loading:g,onClick:()=>j(b),children:`确认已核对`})]}):null,b.conversations?.length?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`历史执行会话`}),(0,$.jsx)(pt,{className:`assessment-pre`,children:b.conversations.join(` +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,u as r,y as i}from"./react-QV7DAAIx.js";import{B as a,E as o,G as s,I as c,Lt as l,N as u,P as d,R as f,S as p,U as m,W as h,c as g,d as _,ft as v,g as y,h as b,i as x,lt as S,s as C,ut as w,x as T,y as ee}from"./semi-65W_4I1v.js";import{D as E,E as D,F as O,I as k,L as A,R as j,S as M,_ as N,a as P,b as F,c as I,d as L,f as R,h as te,l as z,m as B,n as ne,o as V,p as re,r as ie,s as H,t as ae,u as U,v as oe,x as W,y as se}from"./index-DNMXun-U.js";import{n as ce,r as le}from"./model-channel-mQ6lfvSO.js";import{t as ue}from"./project-form-B7wV5B1p.js";import{a as G,i as de,n as K,o as fe,r as pe,t as me}from"./graph-parents-i1hc3RVG.js";var q=e(t(),1),J={draft:`草稿`,running:`执行中`,pending:`待执行`,completed:`已完成`,blocked:`受阻`,failed:`失败`,paused:`已暂停`,pausing:`暂停中`,cancelling:`停止中`,cancelled:`已停止`,recovering:`待恢复`,waiting_retry:`等待模型恢复`,waiting_input:`待答复`,waiting_progress:`等待新进展`,needs_review:`待核对`,uncertain:`结果不明`,interrupted:`已中断`,cleanup_unconfirmed:`待确认资源停止`,retired:`已撤下`,reconciled:`已核对`,yielded:`分段完成`,archived:`已归档`},Y=[`running`,`pausing`,`cancelling`],X=[`completed`,`cancelled`],Z=[`needs_review`,`uncertain`,`cleanup_unconfirmed`],he={goal:`目标`,step:`探索意图`,observation:`观察`,receipt:`执行回执`,memory:`Pi 摘要`,digest:`历史归档`,guidance:`人工线索`,fact:`事实`,finding:`漏洞`},ge={observed:`直接观察`,inferred:`推断待证`,reported:`待独立复核`,confirmed:`复核确认`,refuted:`复核否定`,inconclusive:`复核未定`,unreviewed:`历史记录待核对`,summary:`压缩摘要`,note:`观察记录`,user:`用户提供`,folded:`已折叠`,superseded:`已替代的归档`,completed:`已完成`,running:`处理中`,failed:`失败`,uncertain:`结果待核对`,cancelled:`已取消`,reconciled:`已核对`,interrupted:`已中断`,error:`执行失败`,missing:`缺证据`,needs_review:`待复核`,has_evidence:`已有证据`},_e={started:`开始/继续测评`,reopened:`继续已停止的测评`,step_started:`意图开始执行`,planning:`更新计划`,plan_updated:`计划已更新`,checkpoint:`已保存进展`,step_result:`意图执行结果`,settled:`调度已结束`,stop_requested:`暂停/停止请求`,intent_pause:`暂停此意图`,intent_resume:`意图已恢复排队`,intent_priority:`优先级已调整`,intent_guidance:`收到定向补充`,waiting_progress:`等待新进展`,waiting_retry:`等待模型恢复`,waiting_input:`等待答复`,blocked:`执行受阻`,guidance:`收到补充方向`,retry_scheduled:`稍后重试模型`,review_gap:`验收仍有缺口`,shutdown:`保存进度并关闭`,retry:`步骤已重新排队`,reconciled:`已确认核对`},ve={observed:`已观察`,inferred:`推断`},ye={observed:`green`,inferred:`amber`},be={has_evidence:`已有证据`,missing:`缺证据`,needs_review:`待人工复核`},xe={has_evidence:`green`,missing:`red`,needs_review:`amber`},Se=`assessments:write`,Ce=`assessments:delete`;function Q(e,t){return t?e(`deepAssessments.states.${t}`,null,J[t]||t):`—`}function we(e,t){return e(`deepAssessments.graphKinds.${t}`,null,he[t]||t||`节点`)}function Te(e,t){return t?e(`deepAssessments.graphStates.${t}`,null,ge[t]||Q(e,t)):`—`}function Ee(e,t){return t?e(`deepAssessments.workbench.events.${t}`,null,_e[t]||t):`事件`}function De(e,t){return e(`deepAssessments.confidence.${t}`,null,ve[t]||t||`—`)}function Oe(e,t){return e(`deepAssessments.acceptanceStatus.${t}`,null,be[t]||t||`—`)}function ke(e){return Y.includes(e?.status)}function Ae(e){return X.includes(e?.status)}function je(e){return e?Number(e.review_count)>0||Z.includes(e.status)?!0:(e.steps||[]).some(e=>Z.includes(e.status)):!1}function Me(e){return!!e&&!e.archived&&!Ae(e)&&!ke(e)&&!e.question&&e.status!==`waiting_input`}function Ne(e){return!!e&&!e.archived&&[`running`,`recovering`,`waiting_retry`,`waiting_progress`].includes(e.status)}function Pe(e){return!!e&&!e.archived&&!Ae(e)}function Fe(e){return!!e&&e.status===`cancelled`&&!e.archived}function Ie(e){return!!e&&!e.archived&&!ke(e)&&!je(e)&&![`recovering`,`needs_review`,`uncertain`,`cleanup_unconfirmed`].includes(e.status)}function Le(e){return!!e?.archived}function Re(e){return!!e&&!ke(e)}function ze(e,t){let n=e||{},r=(n.completed||0)+(n.retired||0),i=Number.isFinite(t)&&t>0?t:Object.values(n).reduce((e,t)=>e+Number(t||0),0),a=i>0?Math.round(r/i*100):0;return{done:r,total:i,percent:Math.min(100,Math.max(0,a))}}function Be(e){let t=Math.floor(Number(e));if(!Number.isFinite(t)||t<0)return`—`;if(t<60)return`${t} 秒`;let n=`${Math.floor(t/60)%60} 分 ${t%60} 秒`;return t<3600?n:`${Math.floor(t/3600)} 小时 ${n}`}function Ve(e,t=80){let n=String(e??``);return n.length>t?`${n.slice(0,t)}…`:n}function He(e){if(typeof e!=`string`)return e;let t=e.trim();if(!t||t[0]!==`{`&&t[0]!==`[`)return e;try{return JSON.parse(t)}catch{return e}}var Ue={goal:`#0066ff`,step:`#13a8a8`,fact:`#00b42a`,finding:`#f53f3f`,observation:`#722ed1`,receipt:`#86909c`,memory:`#ff7d00`,digest:`#c9cdd4`,guidance:`#eb2f96`},$=e(n(),1),We=[{value:``,label:`系统默认`},{value:`off`,label:`关闭审批`},{value:`human`,label:`人工审批`},{value:`audit_agent`,label:`审计代理审批`},{value:`review_edit`,label:`复核并允许编辑`}],Ge=[{value:``,label:`继承项目设置 / 默认不限速`},{value:`off`,label:`关闭限速提示(off)`},{value:`quiet`,label:`低噪串行(quiet · 2 RPS)`},{value:`balanced`,label:`均衡速率(balanced · 5 RPS)`},{value:`aggressive`,label:`维护窗口高吞吐(aggressive · 20 RPS)`}],Ke=`默认`;function qe(e){if(typeof e==`string`)return{name:e.trim(),icon:``};if(!e||typeof e!=`object`)return null;let t=String(e.name||``).trim();return t?{name:t,icon:String(e.icon||``).trim()}:null}function Je(e){return{value:e.name===Ke?``:e.name,name:e.name,icon:e.icon,label:(0,$.jsxs)(`span`,{className:`assessment-role-option`,children:[e.icon?(0,$.jsx)(`span`,{className:`assessment-role-icon`,"aria-hidden":`true`,children:e.icon}):null,(0,$.jsx)(`span`,{children:e.name})]})}}function Ye(e){let t=(Array.isArray(e)?e:[]).map(qe).filter(Boolean),n=t.filter(e=>e.name!==Ke),r=t.find(e=>e.name===Ke);return[...r?[Je(r)]:[],...n.map(Je)]}function Xe({projectId:e}){let t=O(),n=P(()=>A.get(`/assets`,{project_id:e,page:1,page_size:1}),[e]),r=Number.isFinite(Number(n.data?.total))?Number(n.data.total):null,i=t(`common.loading`,null,`加载中…`);return!n.loading&&n.error?i=`资产库暂时读不到。保存后仍使用该项目在资产库中的资产。`:!n.loading&&r===0?i=`这个项目的资产库还是空的。测评中新发现的目标会写进资产库,对话和批量任务也能看到。`:!n.loading&&r!=null&&(i=`资产范围是资产库里这个项目的 ${r} 个资产。对话、批量任务和这次测评用的是同一批,会自动交给模型。`),(0,$.jsx)(x.Slot,{label:t(`deepAssessments.assetScope`,null,`资产范围`),children:(0,$.jsx)(s.Text,{type:`tertiary`,role:`status`,children:i})})}function Ze({visible:e,onCancel:t,onCreated:n}){let r=O(),i=r(`deepAssessments.create`,null,`新建测评`),{hasPermission:o}=k(),s=o(`project:read`)&&o(`project:write`),c=(0,q.useId)(),l=(0,q.useRef)(null),[u,d]=(0,q.useState)(null),[p,m]=(0,q.useState)(null),[g,_]=(0,q.useState)(!1),[y,b]=(0,q.useState)(!1),[S,C]=(0,q.useState)(``),w=g||y,T=(0,q.useCallback)(()=>{d(null),m(null),C(``),A.get(`/deep-assessments/options`).then(e=>d(e||{})).catch(e=>m(e))},[]);(0,q.useEffect)(()=>{e&&T()},[e,T]);let ee=e=>{C(e||``)},E=async e=>{if(!w){_(!0);try{let t={name:String(e.name||``).trim(),objective:String(e.objective||``).trim(),scope:String(e.scope||``).trim(),criteria:String(e.criteria||``).trim(),project_id:e.project_id||``,role:e.role||``,model:e.model||``,hitl_policy:e.hitl_policy||``,noise_profile:e.noise_profile||``,concurrency:Number(e.concurrency)||2,auto_resume:e.auto_resume!==!1},i=await A.post(`/deep-assessments`,t);W(r(`deepAssessments.saved`,null,`已创建测评`)),n?.(i?.task)}catch(e){F(e,r(`deepAssessments.saveFailed`,null,`创建失败`))}finally{_(!1)}}},D=e=>{b(!1),e?.id&&(d(t=>({...t,projects:[e,...t?.projects||[]]})),l.current?.setValue(`project_id`,e.id),ee(e.id))},j=ce((u?.models||[]).map(e=>[e.id,e])),M=Ye(u?.roles),N=(u?.projects||[]).map(e=>({value:e.id,label:e.name||e.id}));return(0,$.jsxs)(I,{visible:e,title:i,"aria-label":i,onCancel:t,width:680,closable:!w,closeOnEsc:!w,maskClosable:!w,footer:(0,$.jsxs)(`div`,{className:`assessment-form-actions`,children:[(0,$.jsx)(f,{theme:`borderless`,onClick:t,disabled:w,children:r(`deepAssessments.close`,null,`关闭`)}),(0,$.jsx)(f,{htmlType:`submit`,form:c,theme:`solid`,type:`primary`,loading:g,disabled:w||!u&&!p,children:r(`deepAssessments.save`,null,`保存草稿`)})]}),children:[p?(0,$.jsxs)(`div`,{className:`assessment-error-block`,children:[(0,$.jsx)(z,{error:p}),(0,$.jsx)(f,{size:`small`,onClick:T,children:`重试`})]}):null,!u&&!p?(0,$.jsx)(`div`,{className:`assessment-loading`,children:(0,$.jsx)(h,{})}):(0,$.jsxs)(x,{id:c,getFormApi:e=>{l.current=e},initValues:{concurrency:2,auto_resume:!0,hitl_policy:``,noise_profile:``,role:``},labelPosition:`top`,autoScrollToError:!0,onSubmit:E,children:[(0,$.jsx)(x.Input,{field:`name`,label:r(`deepAssessments.name`,null,`测评名称`),maxLength:200,placeholder:`留空则取目标前 80 个字符`}),(0,$.jsx)(x.TextArea,{field:`objective`,label:r(`deepAssessments.objective`,null,`目标`),rows:3,maxLength:16e3,placeholder:`要达成的最终结果,例如:评估 example.com 对外接口的认证与越权风险并给出可复现证据。`,rules:[{required:!0,message:`请填写测评目标`}]}),(0,$.jsx)(x.TextArea,{field:`scope`,label:r(`deepAssessments.scopeOptional`,null,`补充限制与排除项(选填)`),rows:2,maxLength:16e3,placeholder:`例如:排除支付接口;不修改生产数据;不做压力测试。留空表示无额外限制。`}),(0,$.jsx)(x.TextArea,{field:`criteria`,label:r(`deepAssessments.criteriaOptional`,null,`验收条件(选填)`),rows:3,maxLength:8e3,placeholder:`每行一条验收条件,例如:确认的漏洞附复现步骤和原始证据。留空沿用目标。`}),(0,$.jsxs)(`div`,{className:`assessment-form-grid`,children:[(0,$.jsx)(x.Select,{field:`model`,label:r(`deepAssessments.model`,null,`模型渠道`),optionList:[{value:``,label:`系统默认`},...j],renderSelectedItem:le,style:{width:`100%`}}),(0,$.jsx)(x.Select,{field:`role`,label:r(`deepAssessments.role`,null,`角色`),optionList:M,renderSelectedItem:e=>(0,$.jsxs)(`span`,{className:`assessment-role-option`,children:[e.icon?(0,$.jsx)(`span`,{className:`assessment-role-icon`,"aria-hidden":`true`,children:e.icon}):null,(0,$.jsx)(`span`,{children:e.name})]}),style:{width:`100%`}}),(0,$.jsxs)(`div`,{className:`assessment-project-field`,children:[(0,$.jsx)(x.Select,{field:`project_id`,label:r(`deepAssessments.project`,null,`关联项目`),optionList:[{value:``,label:`不关联`},...N],style:{width:`100%`},onChange:ee}),s&&(0,$.jsx)(f,{icon:(0,$.jsx)(v,{"aria-hidden":!0}),theme:`light`,type:`primary`,disabled:g,onClick:()=>b(!0),children:r(`projects.newProject`,null,`新建项目`)})]}),S&&(0,$.jsx)(Xe,{projectId:S},S),(0,$.jsx)(x.InputNumber,{field:`concurrency`,label:r(`deepAssessments.concurrency`,null,`并行步骤`),min:1,max:4,style:{width:`100%`}})]}),(0,$.jsxs)(`div`,{className:`assessment-form-grid`,children:[(0,$.jsx)(x.Select,{field:`hitl_policy`,label:`人工审批策略`,optionList:We,style:{width:`100%`}}),(0,$.jsx)(x.Select,{field:`noise_profile`,label:r(`deepAssessments.noiseProfile`,null,`任务速率/噪音档位`),optionList:Ge,style:{width:`100%`}})]}),(0,$.jsx)(x.Switch,{field:`auto_resume`,label:r(`deepAssessments.autoResume`,null,`服务重启后自动恢复结果明确的步骤`)}),(0,$.jsx)(a,{type:`info`,bordered:!0,closeIcon:null,className:`assessment-form-note`,description:`创建后保存为草稿,需要手动点击“开始 / 继续”才会执行。关联项目后,资产范围直接使用资产库中的项目资产。`})]}),y&&(0,$.jsx)(ue,{visible:!0,onCancel:()=>b(!1),onSaved:D})]})}var{Text:Qe}=s,$e=[`draft`,`running`,`paused`,`blocked`,`failed`,`waiting_input`,`waiting_retry`,`recovering`,`uncertain`,`cleanup_unconfirmed`,`completed`,`cancelled`].map(e=>({value:e,label:J[e]}));function et({onOpen:e}){let t=O(),{hasPermission:n}=k(),[r,i]=(0,q.useState)(``),[a,o]=(0,q.useState)(``),[s,u]=(0,q.useState)(!1),[d,p]=(0,q.useState)(0),[h,g]=(0,q.useState)(!1),[_,x]=(0,q.useState)({}),C=ne(r,300),T=n(Se),j=n(Ce),M=(0,q.useMemo)(()=>({q:C,status:a,limit:20,offset:d*20,archived:s?`true`:``}),[C,a,d,s]),N=P(()=>A.get(`/deep-assessments`,M),[M]),I=(0,q.useMemo)(()=>N.data?.tasks||[],[N.data]);(0,q.useEffect)(()=>{p(0)},[C,a,s]),(0,q.useEffect)(()=>{let e=I.filter(e=>!_[`${e.id}:${e.updated_at}`]);if(!e.length)return;let t=!1,n=0,r={},i=async()=>{for(;!t&&n{!t&&Object.keys(r).length&&x(e=>({...e,...r}))}),()=>{t=!0}},[I]);let L=e=>{se({title:t(`deepAssessments.delete`,null,`删除`),content:`删除测评「${e.name||e.id}」?关联执行会话仍保留。`,okText:t(`deepAssessments.delete`,null,`删除`),onOk:async()=>{try{await A.del(`/deep-assessments/${e.id}`),W(t(`deepAssessments.deleted`,null,`已删除`)),await N.reload()}catch(e){F(e,t(`deepAssessments.deleteFailed`,null,`删除失败`))}}})},R=[{title:t(`deepAssessments.name`,null,`测评名称`),dataIndex:`name`,width:260,render:(t,n)=>(0,$.jsxs)(`div`,{className:`assessment-list-name`,children:[(0,$.jsx)(f,{theme:`borderless`,className:`assessment-link`,onClick:()=>e?.(n.id),children:t||n.id}),(0,$.jsx)(Qe,{type:`tertiary`,size:`small`,className:`assessment-ellipsis`,children:n.id})]})},{title:t(`deepAssessments.status`,null,`状态`),dataIndex:`status`,width:130,render:(e,n)=>(0,$.jsxs)(c,{spacing:4,children:[(0,$.jsx)(oe,{status:e,label:Q(t,e)}),n.archived?(0,$.jsx)(oe,{status:`archived`,label:Q(t,`archived`)}):null,je(n)?(0,$.jsx)(oe,{status:`needs_review`,label:Q(t,`needs_review`)}):null]})},{title:t(`deepAssessments.objective`,null,`目标`),dataIndex:`summary`,render:(e,t)=>{let n=_[`${t.id}:${t.updated_at}`]?.objective||e||`—`;return(0,$.jsx)(Qe,{ellipsis:{showTooltip:!0},className:`assessment-ellipsis`,children:n})}},{title:`进度`,width:190,align:`left`,render:(e,t)=>{let n=_[`${t.id}:${t.updated_at}`];if(!n)return(0,$.jsx)(Qe,{type:`tertiary`,children:`—`});let r=ze(n.counts,n.total);return(0,$.jsxs)(`div`,{className:`assessment-progress`,children:[(0,$.jsx)(y,{percent:r.percent,showInfo:!0,size:`small`,strokeWidth:6}),(0,$.jsxs)(Qe,{type:`tertiary`,size:`small`,children:[r.done,` / `,r.total,` 意图`]})]})}},{title:t(`deepAssessments.rounds`,null,`规划轮次`),dataIndex:`rounds`,width:100,render:e=>E(e||0)},{title:t(`deepAssessments.createdAt`,null,`创建时间`),dataIndex:`created_at`,width:170,render:e=>D(e)},{title:`操作`,width:150,render:(n,r)=>(0,$.jsxs)(c,{spacing:4,children:[(0,$.jsx)(f,{theme:`borderless`,size:`small`,onClick:()=>e?.(r.id),children:`进入`}),(0,$.jsx)(f,{theme:`borderless`,type:`danger`,size:`small`,icon:(0,$.jsx)(l,{}),disabled:!j||!Re(r),onClick:()=>L(r),children:t(`deepAssessments.delete`,null,`删除`)})]})}];return(0,$.jsxs)(`div`,{className:`assessment-page`,children:[(0,$.jsx)(re,{title:t(`deepAssessments.title`,null,`深度测评`),description:t(`deepAssessments.subtitle`,null,`围绕一个目标持续探索,保存证据与进度,跨会话继续执行。`),extra:[(0,$.jsx)(f,{icon:(0,$.jsx)(w,{}),onClick:()=>N.reload(),loading:N.loading,children:t(`deepAssessments.refresh`,null,`刷新`)},`refresh`),(0,$.jsx)(f,{icon:(0,$.jsx)(v,{}),theme:`solid`,type:`primary`,disabled:!T,onClick:()=>g(!0),children:t(`deepAssessments.create`,null,`新建测评`)},`create`)]}),(0,$.jsx)(z,{error:N.error,onRetry:()=>N.reload()}),(0,$.jsxs)(B,{className:`assessment-list-card`,title:t(`deepAssessments.listTitle`,null,`测评列表`),extra:(0,$.jsx)(b,{className:`assessment-view-options`,"aria-label":t(`deepAssessments.archiveFilter`,null,`归档状态`),type:`button`,value:s?`archived`:`unarchived`,options:[{value:`unarchived`,label:t(`deepAssessments.unarchivedTasks`,null,`未归档`)},{value:`archived`,label:t(`deepAssessments.archivedTasks`,null,`已归档`)}],onChange:e=>u(e.target.value===`archived`)}),children:[(0,$.jsxs)(`div`,{className:`assessment-toolbar`,children:[(0,$.jsx)(m,{prefix:(0,$.jsx)(S,{}),value:r,onChange:i,placeholder:t(`deepAssessments.search`,null,`搜索测评名称`),style:{width:260},showClear:!0}),(0,$.jsx)(ee,{value:a,onChange:e=>o(e||``),optionList:[{value:``,label:t(`deepAssessments.all`,null,`全部状态`)},...$e],style:{width:160}})]}),(0,$.jsx)(H,{columns:R,dataSource:I,rowKey:`id`,loading:N.loading,pagination:!1,emptyText:t(`deepAssessments.empty`,null,`暂无测评,先创建一个目标。`)}),(0,$.jsx)(`div`,{className:`assessment-pager`,children:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:d===0,onClick:()=>p(e=>Math.max(0,e-1)),children:t(`deepAssessments.previous`,null,`上一页`)}),(0,$.jsxs)(Qe,{type:`tertiary`,children:[`第 `,d+1,` 页`]}),(0,$.jsx)(f,{size:`small`,disabled:!N.data?.has_more,onClick:()=>p(e=>e+1),children:t(`deepAssessments.next`,null,`下一页`)})]})})]}),(0,$.jsx)(Ze,{visible:h,onCancel:()=>g(!1),onCreated:t=>{g(!1),N.reload(),t?.id&&e?.(t.id)}})]})}var{Paragraph:tt,Text:nt}=s,rt=e=>JSON.stringify([e.surface,e.risk_area]),it=e=>JSON.stringify([e.kind,e.surface,e.risk_area,e.goal_id]);function at({id:e,reloadToken:t,onView:n}){let r=O(),i=P(()=>A.get(`/deep-assessments/${e}/coverage`),[e,t]),a=i.data,o=!!n,s=(e,t)=>r(`deepAssessments.coverage.${e}`,t),l={title:s(`surface`),dataIndex:`surface`,width:180,render:e=>e||`—`},d={title:s(`riskArea`),dataIndex:`risk_area`,width:140},p=[l,d,{title:s(`outcome`),dataIndex:`outcome`,width:150,render:e=>s(`outcomes.${e}`)},{title:s(`evidence`),dataIndex:`evidence`,width:180,render:e=>e||`—`},{title:s(`reason`),dataIndex:`reason`,render:e=>e||`—`}],m=[l,d,{title:s(`gap`),dataIndex:`kind`,render:e=>s(`gapKinds.${e}`)},{title:s(`goalRef`),dataIndex:`goal_id`,width:160,render:e=>e||`—`}];return(0,$.jsxs)(B,{title:s(`title`),extra:o?(0,$.jsx)(f,{size:`small`,onClick:n,children:s(`view`)}):(0,$.jsx)(f,{size:`small`,onClick:()=>i.reload(),loading:i.loading,children:r(`common.refresh`)}),children:[(0,$.jsx)(z,{error:i.error,onRetry:()=>i.reload()}),i.loading&&!a?(0,$.jsx)(nt,{type:`tertiary`,children:s(`loading`)}):null,a?(0,$.jsxs)(`div`,{className:`assessment-tab assessment-coverage`,children:[(0,$.jsx)(tt,{children:s(`summary`,{records:a.records.length,gaps:a.gaps.length})}),a.records.length>0?(0,$.jsx)(c,{wrap:!0,children:Object.entries(a.counts).map(([e,t])=>(0,$.jsxs)(u,{children:[s(`outcomes.${e}`),` · `,t]},e))}):null,o?(0,$.jsxs)($.Fragment,{children:[a.goals.length>0?(0,$.jsxs)(`section`,{children:[(0,$.jsx)(nt,{strong:!0,children:s(`goals`)}),(0,$.jsx)(`ul`,{children:a.goals.map(e=>(0,$.jsxs)(`li`,{children:[e.text,` `,e.risk_class?(0,$.jsx)(u,{size:`small`,children:e.risk_class}):null]},e.goal_id))})]}):null,a.constraints.length>0?(0,$.jsxs)(`section`,{children:[(0,$.jsx)(nt,{strong:!0,children:s(`constraints`)}),(0,$.jsx)(`ul`,{children:a.constraints.map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsx)(u,{size:`small`,children:s(`constraintKinds.${e.kind}`)}),` `,e.text,` `,(0,$.jsxs)(nt,{type:`tertiary`,children:[`(`,e.origin,`)`]})]},e.constraint_id))})]}):null]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{columns:p,dataSource:a.records,rowKey:rt,pagination:a.records.length>10&&void 0,emptyText:s(`emptyRecords`)}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(nt,{strong:!0,children:s(`gaps`)}),(0,$.jsx)(tt,{type:`tertiary`,children:s(`gapHint`)}),(0,$.jsx)(H,{columns:m,dataSource:a.gaps,rowKey:it,pagination:a.gaps.length>10&&void 0,emptyText:s(`emptyGaps`)})]})]})]}):null]})}var{Text:ot,Paragraph:st}=s,ct={blocked:`error`,waiting_input:`warning`,completed:`success`,stop_requested:`warning`,retry:`warning`};function lt({startedAt:e,seconds:t}){let[n,r]=(0,q.useState)(Date.now);return ie(()=>r(Date.now()),1e3),Be(t+Math.max(0,Math.floor((n-e)/1e3)))}function ut({id:e}){let[t,n]=(0,q.useState)(null);return(0,q.useEffect)(()=>{let t=!1;return A.get(`/assets/collections/${e}`).then(e=>{t||n(e?.collection||null)}).catch(()=>{t||n(null)}),()=>{t=!0}},[e]),t?(0,$.jsxs)(ot,{type:`tertiary`,children:[`本次范围 `,t.name,`:可见资产 `,t.member_count||0,` 个,已确认观察 `,t.observed||0,` 个。项目历史观察和逐项验收分开统计,缺证据的必验项保持未完成。`]}):null}function dt({task:e,canWrite:t,events:n,eventsError:r,autoRefresh:i,onAutoRefreshChange:a,onRefreshEvents:s,onGoTab:l,onGuidance:d,onAnswer:p,reloadToken:m}){let h=O(),g={};(e.steps||[]).forEach(e=>{g[e.status]=(g[e.status]||0)+1});let v=ze(g,(e.steps||[]).length),y=e.review_count||(e.steps||[]).filter(e=>[`uncertain`,`cleanup_unconfirmed`].includes(e.status)).length,b=e.active_seconds??0,x=ke(e)?Date.parse(e.run_started_at):NaN,S=Be(b);e.archived?S=`已归档`:Number.isFinite(x)&&(S=(0,$.jsx)(lt,{startedAt:x,seconds:b},x));let w=[{id:`status`,label:h(`deepAssessments.status`,null,`状态`),value:(0,$.jsx)(`span`,{className:`assessment-status-value`,children:Q(h,e.status)}),detail:S},{id:`progress`,label:`意图完成度`,value:`${v.percent}%`,detail:`${v.done} / ${v.total} 已结束`},{id:`rounds`,label:h(`deepAssessments.rounds`,null,`规划轮次`),value:E(e.rounds||0)},{id:`tokens`,label:h(`deepAssessments.tokens`,null,`累计 Token`),value:E(e.tokens_used||0)},{id:`review`,label:`待核对`,value:E(y),detail:y?`需要人工确认工具结果`:`无待核对记录`}],T=[{label:h(`deepAssessments.objective`,null,`目标`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.objective||`—`})},{label:h(`deepAssessments.scope`,null,`补充限制与排除项`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.scope&&e.scope.trim()!==(e.objective||``).trim()?e.scope:`—`})},{label:h(`deepAssessments.criteria`,null,`验收条件`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.criteria||`—`})},{label:h(`deepAssessments.strategy`,null,`最近规划路线`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.strategy||`—`})},{label:h(`deepAssessments.summary`,null,`当前结论 / 缺口`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.summary||`—`})}];e.question&&T.push({label:h(`deepAssessments.question`,null,`待补充信息`),value:(0,$.jsx)(st,{className:`assessment-pre`,children:e.question})});let ee=n.slice().reverse().slice(0,120);return(0,$.jsxs)(`div`,{className:`assessment-tab`,children:[(0,$.jsx)(N,{metrics:w,columns:5}),e.collection_id?(0,$.jsx)(ut,{id:e.collection_id}):null,(0,$.jsxs)(B,{title:`目标与测评要求`,extra:(0,$.jsxs)(c,{children:[t&&!e.archived&&e.status!==`completed`&&e.status!==`cancelled`?(0,$.jsx)(f,{size:`small`,onClick:d,children:`补充方向`}):null,e.question?(0,$.jsx)(f,{size:`small`,theme:`solid`,type:`primary`,onClick:p,children:`答复`}):null,(0,$.jsx)(f,{size:`small`,onClick:()=>l?.(`intents`),children:`查看意图`})]}),children:[(0,$.jsx)(L,{items:T,columns:1}),(0,$.jsxs)(`div`,{className:`assessment-facts-row`,children:[(0,$.jsxs)(ot,{type:`tertiary`,children:[`自动续跑:`,e.auto_resume?`已开启`:`已关闭`]}),(0,$.jsxs)(ot,{type:`tertiary`,children:[`并行步骤:`,e.concurrency||`—`]}),(0,$.jsxs)(ot,{type:`tertiary`,children:[`人工审批:`,e.hitl_policy||`系统默认`]}),e.noise_profile?(0,$.jsxs)(ot,{type:`tertiary`,children:[`噪音档位:`,e.noise_profile]}):null,(0,$.jsxs)(ot,{type:`tertiary`,children:[`最近更新:`,D(e.updated_at)]})]}),Array.isArray(e.guidance)&&e.guidance.length?(0,$.jsxs)(`div`,{className:`assessment-guidance`,children:[(0,$.jsx)(ot,{strong:!0,children:`人工补充`}),e.guidance.map((e,t)=>(0,$.jsxs)(`div`,{className:`assessment-guidance-item`,children:[(0,$.jsxs)(ot,{type:`tertiary`,children:[`#`,t+1]}),(0,$.jsx)(st,{className:`assessment-pre`,children:e})]},`${t}-${e.slice(0,8)}`))]}):null,(0,$.jsx)(st,{type:`tertiary`,className:`assessment-hint`,children:`打开页面不会自动启动任务;自动续跑只针对服务重启前的执行,草稿、手动暂停和待核对任务不会自动开始。`})]}),(0,$.jsx)(at,{id:e.id,reloadToken:m,onView:()=>l?.(`acceptance`)},e.id),(0,$.jsxs)(B,{title:h(`deepAssessments.activity`,null,`运行记录`),description:`事件按时间倒序展示;运行中每 10 秒自动拉取,页面隐藏时跳过。`,extra:(0,$.jsxs)(c,{children:[(0,$.jsx)(ot,{type:`tertiary`,size:`small`,children:`自动刷新`}),(0,$.jsx)(_,{size:`small`,checked:i,onChange:e=>a?.(!!e)}),(0,$.jsx)(f,{size:`small`,onClick:s,children:`立即刷新`})]}),children:[(0,$.jsx)(z,{error:r,onRetry:s}),ee.length===0?(0,$.jsx)(o,{title:`暂无运行记录`,description:`开始测评后,规划、执行与核对事件会显示在这里。`,style:{padding:32}}):(0,$.jsx)(`div`,{className:`assessment-timeline`,children:(0,$.jsx)(C,{children:ee.map(e=>(0,$.jsxs)(C.Item,{time:D(e.created_at),type:ct[e.kind]||`default`,children:[(0,$.jsxs)(`div`,{className:`assessment-event-head`,children:[(0,$.jsx)(ot,{strong:!0,children:Ee(h,e.kind)}),e.step_id?(0,$.jsx)(u,{size:`small`,color:`grey`,children:e.step_id}):null]}),e.message?(0,$.jsx)(`div`,{className:`assessment-event-message`,children:e.message}):null]},e.id))})})]})]})}var{Text:ft,Paragraph:pt}=s,mt=[`running`,`pending`,`pausing`,`paused`,`completed`,`blocked`,`failed`,`uncertain`,`cleanup_unconfirmed`,`interrupted`,`retired`,`reconciled`];function ht({id:e,reloadToken:t,status:n,onStatusChange:r,onChanged:i,archived:a,taskStatus:o,revision:s}){let l=O(),{hasPermission:d}=k(),p=d(Se),[m,h]=(0,q.useState)(!1),[g,_]=(0,q.useState)(!1),[v,y]=(0,q.useState)(0),[b,x]=(0,q.useState)(null);(0,q.useEffect)(()=>{y(0)},[n]);let S=P(()=>A.get(`/deep-assessments/${e}/intents`,{status:n,offset:v}),[e,n,v,t]),C=S.data,w=C?.intents||[],T=C?.counts||{},D=async t=>{h(!0);try{await A.post(`/deep-assessments/${e}/control/intent-pause`,{revision:s,step_id:t.id}),W(`已提交此方向的暂停请求`)}catch(e){F(e,`暂停方向失败`)}finally{h(!1),x(null),i?.()}},j=t=>{se({title:`确认已核对`,content:`确认只解除本步骤的待核对状态,不会自动执行;原有进度和证据保留。`,okText:`确认已核对`,danger:!1,onOk:async()=>{_(!0);try{let n=await A.get(`/deep-assessments/${e}/steps/${t.id}`);await A.post(`/deep-assessments/${e}/control/reconcile`,{revision:n?.revision,step_id:t.id,reconciled:!0,cleanup_confirmed:!0}),W(`已记录核对,待核对列表已更新`),x(null),await S.reload(),i?.()}catch(e){F(e,`核对失败`)}finally{_(!1)}}})},M=(0,q.useMemo)(()=>{let e=mt.filter(e=>T[e]);return Object.keys(T).forEach(t=>{e.includes(t)||e.push(t)}),[{value:``,label:`${l(`deepAssessments.all`,null,`全部状态`)} · ${C?.total??0}`},...e.map(e=>({value:e,label:`${Q(l,e)} · ${T[e]}`}))]},[T,C?.total,l]),N=[{title:l(`deepAssessments.status`,null,`状态`),dataIndex:`status`,width:140,render:e=>(0,$.jsx)(oe,{status:e,label:Q(l,e)})},{title:`意图`,dataIndex:`title`,render:(e,t)=>(0,$.jsxs)(`div`,{className:`assessment-list-name`,children:[(0,$.jsx)(ft,{ellipsis:{showTooltip:!0},children:e||t.id}),t.summary?(0,$.jsx)(ft,{type:`tertiary`,size:`small`,className:`assessment-ellipsis`,children:Ve(t.summary,120)}):null]})},{title:l(`deepAssessments.priority`,null,`优先级`),dataIndex:`priority`,width:90,render:e=>e||100},{title:l(`deepAssessments.assets`,null,`关联资产`),dataIndex:`asset_ids`,width:100,render:e=>(e||[]).length||`—`},{title:`证据回执`,dataIndex:`evidence`,width:100,render:e=>(e||[]).length||`—`},{title:`执行分段`,dataIndex:`attempts`,width:90,render:e=>E(e||0)},{title:`最近进展`,dataIndex:`last_progress`,render:e=>e?(0,$.jsx)(ft,{type:`tertiary`,ellipsis:{showTooltip:!0},children:e}):`—`}];return(0,$.jsxs)(`div`,{className:`assessment-tab`,children:[(0,$.jsxs)(B,{title:l(`deepAssessments.plan`,null,`意图队列`),description:`队列按优先级排序;状态只表示执行情况,不代表漏洞或完成结论。`,extra:(0,$.jsx)(f,{size:`small`,onClick:()=>S.reload(),loading:S.loading,children:`刷新`}),children:[(0,$.jsxs)(`div`,{className:`assessment-toolbar`,children:[(0,$.jsx)(ee,{value:n,onChange:e=>r?.(e||``),optionList:M,style:{width:200}}),(0,$.jsxs)(ft,{type:`tertiary`,children:[`共 `,C?.total??0,` 条意图`]})]}),(0,$.jsx)(z,{error:S.error,onRetry:()=>S.reload()}),(0,$.jsx)(H,{columns:N,dataSource:w,rowKey:`id`,loading:S.loading,pagination:!1,onRow:e=>({onClick:()=>x(e),style:{cursor:`pointer`}}),emptyText:l(`deepAssessments.noIntents`,null,`暂无意图,开始测评后由规划器逐步生成探索方向。`)}),(0,$.jsx)(`div`,{className:`assessment-pager`,children:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:v===0,onClick:()=>y(e=>Math.max(0,e-20)),children:l(`deepAssessments.previous`,null,`上一页`)}),(0,$.jsx)(ft,{type:`tertiary`,children:w.length?`${v+1} - ${v+w.length}`:`0`}),(0,$.jsx)(f,{size:`small`,disabled:!C?.has_more,onClick:()=>y(e=>e+20),children:l(`deepAssessments.next`,null,`下一页`)})]})})]}),(0,$.jsx)(I,{visible:!!b,onCancel:()=>x(null),title:b?.title||`意图详情`,width:560,footer:null,children:b?(0,$.jsxs)(`div`,{className:`assessment-drawer`,children:[p&&!a&&o===`running`&&[`pending`,`running`].includes(b.status)&&(0,$.jsx)(f,{onClick:()=>D(b),loading:m,disabled:m,children:`暂停此方向`}),(0,$.jsx)(L,{columns:2,items:[{label:l(`deepAssessments.status`,null,`状态`),value:(0,$.jsx)(oe,{status:b.status,label:Q(l,b.status)})},{label:`意图 ID`,value:b.id},{label:l(`deepAssessments.priority`,null,`优先级`),value:b.priority||100},{label:`执行分段`,value:b.attempts||0},{label:`手动暂停`,value:b.user_paused?`是`:`否`},{label:`执行会话`,value:b.conversation_id||`—`},{label:l(`deepAssessments.assets`,null,`关联资产`),value:(b.asset_ids||[]).join(`, `)||`—`},{label:`来源节点`,value:(b.source_ids||[]).join(`, `)||`—`},{label:`前置意图`,value:(b.depends_on||[]).join(`, `)||`—`},{label:`证据引用`,value:(b.evidence||[]).join(`, `)||`—`}]}),(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`执行说明`}),(0,$.jsx)(pt,{className:`assessment-pre`,children:b.instruction||`—`})]}),(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`结果摘要`}),(0,$.jsx)(pt,{className:`assessment-pre`,children:b.summary||`—`})]}),b.last_progress?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`最近进展`}),(0,$.jsx)(pt,{className:`assessment-pre`,children:b.last_progress})]}):null,Array.isArray(b.guidance)&&b.guidance.length?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`定向补充`}),b.guidance.map((e,t)=>(0,$.jsxs)(`div`,{className:`assessment-guidance-item`,children:[(0,$.jsxs)(u,{size:`small`,color:`grey`,children:[`#`,t+1]}),(0,$.jsx)(pt,{className:`assessment-pre`,children:e})]},`${t}-${e.slice(0,8)}`))]}):null,[`uncertain`,`cleanup_unconfirmed`].includes(b.status)?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`待核对`}),(0,$.jsx)(pt,{type:`tertiary`,className:`assessment-hint`,children:`确认只解除本步骤的待核对状态,不会自动执行;仍有结果不明的调用时请保持停止。`}),(0,$.jsx)(f,{size:`small`,theme:`solid`,type:`primary`,disabled:!p||a,loading:g,onClick:()=>j(b),children:`确认已核对`})]}):null,b.conversations?.length?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(ft,{strong:!0,children:`历史执行会话`}),(0,$.jsx)(pt,{className:`assessment-pre`,children:b.conversations.join(` `)})]}):null]}):null})]})}var{Text:gt,Paragraph:_t}=s;function vt({id:e,reloadToken:t}){let n=O(),[r,i]=(0,q.useState)(``),[a,o]=(0,q.useState)(0),[s,l]=(0,q.useState)(null);(0,q.useEffect)(()=>{o(0)},[r]);let d=P(()=>A.get(`/deep-assessments/${e}/facts`,{confidence:r,offset:a}),[e,r,a,t]),p=d.data,m=p?.facts||[],h=[{title:`置信度`,dataIndex:`confidence`,width:110,render:e=>(0,$.jsx)(u,{color:ye[e]||`grey`,shape:`circle`,children:De(n,e)})},{title:`摘要`,dataIndex:`summary`,render:(e,t)=>(0,$.jsxs)(`div`,{className:`assessment-list-name`,children:[(0,$.jsx)(gt,{ellipsis:{showTooltip:!0},children:e||t.id}),t.body?(0,$.jsx)(gt,{type:`tertiary`,size:`small`,className:`assessment-ellipsis`,children:Ve(t.body,140)}):null]})},{title:`来源意图`,dataIndex:`step_id`,width:140,render:e=>e||`—`},{title:n(`deepAssessments.assets`,null,`关联资产`),dataIndex:`asset_ids`,width:140,render:e=>(e||[]).length?(0,$.jsx)(gt,{ellipsis:{showTooltip:!0},children:e.join(`, `)}):`—`},{title:`证据回执`,dataIndex:`evidence`,width:100,render:e=>(e||[]).length||`—`},{title:`时间`,dataIndex:`created_at`,width:170,render:e=>D(e)}];return(0,$.jsxs)(`div`,{className:`assessment-tab`,children:[(0,$.jsxs)(B,{title:n(`deepAssessments.facts`,null,`事实`),description:`observed 表示有原始成功回执支撑;inferred 只是推断,不是证据。`,extra:(0,$.jsx)(f,{size:`small`,onClick:()=>d.reload(),loading:d.loading,children:`刷新`}),children:[(0,$.jsx)(`div`,{className:`assessment-toolbar`,children:(0,$.jsx)(ee,{value:r,onChange:e=>i(e||``),optionList:[{value:``,label:n(`deepAssessments.all`,null,`全部状态`)},{value:`observed`,label:De(n,`observed`)},{value:`inferred`,label:De(n,`inferred`)}],style:{width:160}})}),(0,$.jsx)(z,{error:d.error,onRetry:()=>d.reload()}),(0,$.jsx)(H,{columns:h,dataSource:m,rowKey:`id`,loading:d.loading,pagination:!1,onRow:e=>({onClick:()=>l(e),style:{cursor:`pointer`}}),emptyText:n(`deepAssessments.noFacts`,null,`暂无事实记录。`)}),(0,$.jsx)(`div`,{className:`assessment-pager`,children:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:a===0,onClick:()=>o(e=>Math.max(0,e-20)),children:n(`deepAssessments.previous`,null,`上一页`)}),(0,$.jsx)(gt,{type:`tertiary`,children:m.length?`${a+1} - ${a+m.length}`:`0`}),(0,$.jsx)(f,{size:`small`,disabled:!p?.has_more,onClick:()=>o(e=>e+20),children:n(`deepAssessments.next`,null,`下一页`)})]})})]}),(0,$.jsx)(I,{visible:!!s,onCancel:()=>l(null),title:`事实详情`,width:620,footer:null,children:s?(0,$.jsxs)(`div`,{className:`assessment-drawer`,children:[(0,$.jsx)(L,{columns:2,items:[{label:`置信度`,value:(0,$.jsx)(u,{color:ye[s.confidence]||`grey`,children:De(n,s.confidence)})},{label:`事实 ID`,value:s.id},{label:`来源意图`,value:s.step_id||`—`},{label:`时间`,value:D(s.created_at)},{label:n(`deepAssessments.assets`,null,`关联资产`),value:(s.asset_ids||[]).join(`, `)||`—`},{label:`证据回执`,value:(s.evidence||[]).join(`, `)||`—`},{label:`来源节点`,value:(s.source_ids||[]).join(`, `)||`—`}]}),(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(gt,{strong:!0,children:`摘要`}),(0,$.jsx)(_t,{className:`assessment-pre`,children:s.summary||`—`})]}),(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(gt,{strong:!0,children:`正文`}),(0,$.jsx)(_t,{className:`assessment-pre`,children:s.body||`—`})]}),(0,$.jsx)(U,{title:`原始记录`,value:s,collapsed:!0})]}):null})]})}var{Text:yt}=s,bt=20,xt={cloud_access_key:`AK/SK`,credential:`账号凭据`,api_token:`API Key / Token`,other:`其他线索`};function St({endpoint:e,item:t,onClose:n,onSaved:r}){let i=O(),a=(0,q.useRef)(null),[o,s]=(0,q.useState)(!1),[c,l]=(0,q.useState)(null),u=t.id?i(`deepAssessments.surface.edit`,null,`编辑线索`):i(`deepAssessments.surface.add`,null,`新增线索`),d=Object.entries(xt).map(([e,t])=>({value:e,label:i(`deepAssessments.surface.kinds.${e}`,null,t)}));return(0,$.jsxs)(I,{visible:!0,title:u,"aria-label":u,onCancel:n,width:520,closable:!o,closeOnEsc:!o,maskClosable:!o,footer:(0,$.jsxs)(`div`,{className:`assessment-form-actions`,children:[(0,$.jsx)(f,{onClick:n,disabled:o,children:i(`common.cancel`,null,`取消`)}),(0,$.jsx)(f,{theme:`solid`,onClick:()=>a.current?.submitForm(),loading:o,disabled:o,children:i(`common.save`,null,`保存`)})]}),children:[(0,$.jsx)(yt,{type:`tertiary`,children:i(`deepAssessments.surface.redactionHint`,null,`请填写脱敏信息。密钥、密码和令牌原文应留在原证据位置。`)}),(0,$.jsxs)(x,{getFormApi:e=>{a.current=e},initValues:t,labelPosition:`top`,onSubmit:async({kind:n,summary:a=``,location:o=``,fact_id:c=``})=>{s(!0),l(null);let u={kind:n,summary:a.trim(),location:o.trim(),fact_id:c.trim()};try{t.id?await A.put(`${e}/${encodeURIComponent(t.id)}`,{...u,revision:t.revision}):await A.post(e,u),W(i(`deepAssessments.surface.saved`,null,`已保存攻击面线索`)),r()}catch(e){l(e)}finally{s(!1)}},disabled:o,children:[(0,$.jsx)(x.RadioGroup,{field:`kind`,label:i(`deepAssessments.surface.kind`,null,`类型`),options:d,direction:`vertical`,rules:[{required:!0,message:i(`deepAssessments.surface.kindRequired`,null,`请选择线索类型`)}]}),(0,$.jsx)(x.Input,{field:`summary`,label:i(`deepAssessments.surface.summary`,null,`脱敏摘要`),maxLength:120,rules:[{required:!0,whitespace:!0,message:i(`deepAssessments.surface.summaryRequired`,null,`请填写脱敏摘要`)}]}),(0,$.jsx)(x.Input,{field:`location`,label:i(`deepAssessments.surface.location`,null,`发现位置`),maxLength:240}),(0,$.jsx)(x.Input,{field:`fact_id`,label:i(`deepAssessments.surface.factId`,null,`关联事实 ID(选填)`),placeholder:i(`deepAssessments.surface.factHint`,null,`可从本次测评的事实详情复制`),maxLength:128}),(0,$.jsx)(z,{error:c})]})]})}function Ct({id:e,canWrite:t,reloadToken:n}){let i=O(),[a,o]=(0,q.useState)(0),[s,l]=(0,q.useState)(null),d=`/deep-assessments/${e}/surface-items`,p=P(()=>A.get(d,{offset:a}),[d,a,n]),m=p.data?.items||[],h=[{title:i(`deepAssessments.surface.kind`,null,`类型`),dataIndex:`kind`,width:135,render:e=>(0,$.jsx)(u,{size:`small`,children:i(`deepAssessments.surface.kinds.${e}`,null,xt[e]||e)})},{title:i(`deepAssessments.surface.summary`,null,`脱敏摘要`),dataIndex:`summary`},{title:i(`deepAssessments.surface.location`,null,`发现位置`),dataIndex:`location`,render:e=>e||`—`},{title:i(`deepAssessments.surface.evidence`,null,`证据`),dataIndex:`fact_id`,width:145,render:t=>t?(0,$.jsx)(r,{to:`?${new URLSearchParams({id:e,tab:`evidence-path`,fact_id:t})}`,children:i(`deepAssessments.surface.viewEvidence`,null,`查看证据路径`)}):`—`},...t?[{title:i(`deepAssessments.actions`,null,`操作`),key:`actions`,width:95,render:(e,t)=>(0,$.jsx)(f,{size:`small`,theme:`borderless`,onClick:()=>l(t),children:i(`deepAssessments.surface.edit`,null,`编辑线索`)})}]:[]];return(0,$.jsxs)(B,{title:i(`deepAssessments.surface.title`,null,`攻击面线索`),extra:t&&(0,$.jsx)(f,{icon:(0,$.jsx)(v,{}),size:`small`,onClick:()=>l({kind:`cloud_access_key`}),children:i(`deepAssessments.surface.add`,null,`新增线索`)}),children:[(0,$.jsx)(z,{error:p.error,onRetry:p.reload}),(0,$.jsx)(H,{columns:h,dataSource:m,rowKey:`id`,loading:p.loading,pagination:!1,emptyText:i(`deepAssessments.surface.empty`,null,`暂无攻击面线索。`)}),(a>0||p.data?.has_more)&&(0,$.jsx)(`div`,{className:`assessment-pager`,children:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:a===0,onClick:()=>o(e=>e-bt),children:i(`deepAssessments.previous`,null,`上一页`)}),(0,$.jsx)(f,{size:`small`,disabled:!p.data?.has_more,onClick:()=>o(e=>e+bt),children:i(`deepAssessments.next`,null,`下一页`)})]})}),s&&t&&(0,$.jsx)(St,{endpoint:d,item:s,onClose:()=>l(null),onSaved:()=>{l(null),a===0?p.reload():o(0)}})]})}var{Text:wt}=s;function Tt({visible:e,task:t,onCancel:n,onSaved:r}){O();let[i,a]=(0,q.useState)(``),[o,s]=(0,q.useState)(1),[l,u]=(0,q.useState)([]),[d,p]=(0,q.useState)(!1),h=ne(i,300);(0,q.useEffect)(()=>{e&&(a(``),s(1),u([]))},[e]),(0,q.useEffect)(()=>{s(1)},[h]);let g=P(()=>A.get(`/assets`,{page:o,page_size:10,q:h,project_id:t?.project_id||``}),[o,h,t?.project_id,e],{skip:!e}),_=g.data?.assets||[];return(0,$.jsxs)(I,{visible:e,title:`关联共享资产`,"aria-label":`关联共享资产`,onCancel:n,width:760,closable:!d,closeOnEsc:!d,maskClosable:!d,footer:(0,$.jsxs)(`div`,{className:`assessment-form-actions`,children:[(0,$.jsx)(f,{onClick:n,disabled:d,children:`取消`}),(0,$.jsx)(f,{theme:`solid`,onClick:async()=>{if(l.length){p(!0);try{await A.post(`/deep-assessments/${t.id}/assets`,{asset_ids:l}),W(`已关联资产`),r?.()}catch(e){F(e,`关联资产失败`)}finally{p(!1)}}},loading:d,disabled:!l.length||d,children:`关联${l.length?` ${l.length} 项`:``}`})]}),children:[(0,$.jsxs)(`div`,{className:`assessment-toolbar`,children:[(0,$.jsx)(m,{prefix:(0,$.jsx)(S,{}),value:i,onChange:a,placeholder:`按地址、IP 或域名搜索`,style:{width:280},showClear:!0}),(0,$.jsx)(wt,{type:`tertiary`,children:`仅显示当前账号可读、且与测评同项目的资产。`})]}),(0,$.jsx)(z,{error:g.error,onRetry:()=>g.reload()}),(0,$.jsx)(H,{columns:[{title:`资产`,dataIndex:`host`,render:(e,t)=>(0,$.jsxs)(`div`,{className:`assessment-list-name`,children:[(0,$.jsx)(wt,{strong:!0,children:e||t.ip||t.domain||t.id}),(0,$.jsx)(wt,{type:`tertiary`,size:`small`,children:[t.ip,t.port?`:${t.port}`:``,t.protocol].filter(Boolean).join(` `)})]})},{title:`项目`,dataIndex:`project_name`,width:160,render:e=>e||`—`},{title:`状态`,dataIndex:`status`,width:90,render:e=>e||`—`}],dataSource:_,rowKey:`id`,loading:g.loading,pagination:!1,rowSelection:{selectedRowKeys:l,onChange:e=>u((e||[]).map(String))},emptyText:`没有匹配的资产,可先在资产库登记。`}),(0,$.jsx)(`div`,{className:`assessment-pager`,children:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:o<=1,onClick:()=>s(e=>Math.max(1,e-1)),children:`上一页`}),(0,$.jsxs)(wt,{type:`tertiary`,children:[`第 `,o,` 页`]}),(0,$.jsx)(f,{size:`small`,disabled:!g.data?.total_pages||o>=g.data.total_pages,onClick:()=>s(e=>e+1),children:`下一页`})]})})]})}function Et({taskId:e,assetId:t}){let n=P(()=>A.get(`/deep-assessments/${e}/assets`,{asset_id:t}),[e,t],{skip:!t}),r=n.data?.endpoints||[];return n.loading&&!n.data?(0,$.jsx)(wt,{type:`tertiary`,children:`正在读取端点…`}):r.length?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(wt,{strong:!0,children:`端点`}),r.map(e=>(0,$.jsx)(`div`,{children:(0,$.jsxs)(wt,{children:[e.method,` `,e.path]})},e.id))]}):(0,$.jsx)(wt,{type:`tertiary`,children:`这个服务在资产库里还没有端点。任务中发现的路径会写到这里。`})}var Dt=new Set([`running`,`recovering`,`waiting_progress`,`waiting_retry`,`pausing`,`cancelling`]);function Ot({id:e,task:t,observation:n,reloadToken:r}){let i=O(),{hasPermission:a}=k(),[o,s]=(0,q.useState)(0),[l,d]=(0,q.useState)(!1),[p,m]=(0,q.useState)(null),h=P(()=>A.get(`/deep-assessments/${e}/assets`,{offset:o,observation:n}),[e,o,n,r]);ie(()=>{document.hidden||h.reload({silent:!0})},Dt.has(t?.status)?1e4:0);let g=h.data,_=g?.assets||[],y=g?.coverage||{},b=y.linked??g?.total??0,x=y.with_observed_evidence??0,S=b?Math.round(x/b*100):0,C=a(Se),w=(0,q.useMemo)(()=>[{id:`linked`,label:`关联资产`,value:b},{id:`observed`,label:`已有观察证据`,value:x},{id:`coverage`,label:`观察覆盖率`,value:`${S}%`,detail:`只统计当前账号可读的关联资产`},{id:`nodes`,label:i(`deepAssessments.attackSurfaceGraphNodes`,null,`攻击面图节点`),value:g?.nodes?.length??0}],[i,b,x,S,g?.nodes?.length]);return(0,$.jsxs)(`div`,{className:`assessment-tab`,children:[(0,$.jsx)(N,{metrics:w,columns:4}),(0,$.jsx)(Ct,{id:e,canWrite:C&&!t?.archived,reloadToken:r}),(0,$.jsxs)(B,{title:i(`deepAssessments.attackSurfaceGraph`,null,`攻击面图`),description:`与资产库是同一批记录。项目资产和任务中新发现的同范围服务、端点会自动出现。观察覆盖只统计已有事实的资产。`,extra:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{icon:(0,$.jsx)(v,{}),size:`small`,disabled:!C||t?.archived,onClick:()=>d(!0),children:`从资产库补充`}),(0,$.jsx)(f,{size:`small`,onClick:()=>h.reload(),loading:h.loading,children:`刷新`})]}),children:[(0,$.jsx)(z,{error:h.error,onRetry:()=>h.reload()}),(0,$.jsx)(H,{columns:[{title:`资产`,dataIndex:`host`,render:(e,t)=>(0,$.jsxs)(`div`,{className:`assessment-list-name`,children:[(0,$.jsx)(wt,{strong:!0,children:e||t.ip||t.domain||t.id}),(0,$.jsx)(wt,{type:`tertiary`,size:`small`,children:[t.ip,t.domain].filter(Boolean).join(` · `)||t.id})]})},{title:`项目`,dataIndex:`project_name`,width:160,render:e=>e||`—`},{title:`端口 / 协议`,width:130,render:(e,t)=>[t.port||null,t.protocol||null].filter(Boolean).join(` / `)||`—`},{title:`状态`,dataIndex:`status`,width:100,render:e=>e?(0,$.jsx)(u,{size:`small`,children:e}):`—`},{title:`风险`,dataIndex:`risk_level`,width:90,render:e=>e||`—`},{title:`最近发现`,dataIndex:`last_seen_at`,width:170,render:e=>D(e)}],dataSource:_,rowKey:`id`,loading:h.loading,pagination:!1,onRow:e=>({onClick:()=>m(e),style:{cursor:`pointer`}}),emptyText:`资产库里还没有纳入本次测评的资产。关联项目后会自动带入该项目的资产。`}),(0,$.jsx)(`div`,{className:`assessment-pager`,children:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:o===0,onClick:()=>s(e=>Math.max(0,e-20)),children:i(`deepAssessments.previous`,null,`上一页`)}),(0,$.jsxs)(wt,{type:`tertiary`,children:[`共 `,g?.total??0,` 项`]}),(0,$.jsx)(f,{size:`small`,disabled:!g?.has_more,onClick:()=>s(e=>e+20),children:i(`deepAssessments.next`,null,`下一页`)})]})})]}),(0,$.jsx)(Tt,{visible:l,task:t,onCancel:()=>d(!1),onSaved:()=>{d(!1),h.reload()}}),(0,$.jsx)(I,{visible:!!p,onCancel:()=>m(null),title:`资产详情`,width:560,footer:null,children:p?(0,$.jsxs)(`div`,{className:`assessment-drawer`,children:[(0,$.jsx)(L,{columns:2,items:[{label:`资产`,value:p.host||p.ip||p.id},{label:`ID`,value:p.id},{label:`IP`,value:p.ip||`—`},{label:`域名`,value:p.domain||`—`},{label:`端口`,value:p.port||`—`},{label:`协议`,value:p.protocol||`—`},{label:`项目`,value:p.project_name||`—`},{label:`状态`,value:p.status||`—`},{label:`风险`,value:p.risk_level||`—`},{label:`最近发现`,value:D(p.last_seen_at)}]}),(0,$.jsx)(Et,{taskId:e,assetId:p.id}),(0,$.jsx)(U,{title:`原始资产记录`,value:p,collapsed:!0})]}):null})]})}var kt=[{label:`规划与依赖`,color:`#548df0`,relations:[`plans`,`depends_on`]},{label:`产出与证据`,color:`#24aa94`,relations:[`produces`,`supports`,`derives`,`reviews`]},{label:`线索与引用`,color:`#aa78e8`,relations:[`guides`,`informs`]},{label:`执行与记录`,color:`#dc913a`,relations:[`executes`,`records`,`summarizes`]},{label:`归档与其他`,color:`#8b9bb3`,relations:[]}],At=e=>e.boundary||[`receipt`,`observation`,`memory`].includes(e.kind);function jt(e,t){let n=t.get(e.source),r=t.get(e.target);return e.projection?4:n.kind===`step`&&n.step_id&&n.step_id===r.step_id?0:[`plans`,`depends_on`,`contains`,`archives`].includes(e.relation)?1:[`informs`,`supports`,`derives`].includes(e.relation)?3:2}function Mt(e,t,n){let r=[t],i=new Set;for(;r.length;){let t=r.pop();if(t===n)return!0;i.has(t)||(i.add(t),r.push(...e.get(t)))}return!1}function Nt(e){let t=new Map((e?.nodes||[]).map(e=>[e.id,e])),n=new Set,r=new Map,i=(e?.edges||[]).filter(e=>t.has(e.source)&&t.has(e.target)).map(e=>{let t=kt.find(t=>t.relations.includes(e.relation))||kt.at(-1);n.add(t);let i=JSON.stringify([e.source,e.target,e.relation,e.projection]),a=r.get(i)||0;return r.set(i,a+1),{...e,id:`edge:${i}:${a}`,color:t.color}}),a=i.map(e=>({edge:e,priority:jt(e,t)}));a.sort((e,n)=>e.priority-n.priority||Number(!!t.get(e.edge.source).boundary)-Number(!!t.get(n.edge.source).boundary)||e.edge.source.localeCompare(n.edge.source)||e.edge.target.localeCompare(n.edge.target)||(e.edge.relation||``).localeCompare(n.edge.relation||``));let o=me(a.map(e=>e.edge),e=>t.get(e).kind===`goal`),s=new Set([...o.parentEdges].map(e=>e.id)),c=new Set([...o.parentEdges].filter(e=>!At(t.get(e.target))).map(e=>e.id)),l=new Map([...t.keys()].map(e=>[e,new Set]));for(let[e,t]of o.parents)l.get(e).add(t);for(let{edge:e}of a)e.relation!==`depends_on`||e.projection||s.has(e.id)||t.get(e.target).kind===`goal`||Mt(l,e.source,e.target)||(l.get(e.target).add(e.source),s.add(e.id),At(t.get(e.target))||c.add(e.id));let u=new Set([...t.values()].filter(e=>!At(e)).map(e=>e.id));for(let e of i)c.has(e.id)&&(u.add(e.source),u.add(e.target));return{nodes:t,edges:i,upstream:l,layoutEdges:s,backbone:c,overview:u,legend:kt.filter(e=>n.has(e)),dense:t.size>20||i.length>t.size*1.5}}var Pt=27,Ft=118;function It({nodes:e,upstream:t}){let n=new Map,r=[],i=[...e.values()].some(e=>e.kind===`goal`),a=r=>{if(!n.has(r)){let o=t.get(r),s=o.size?Math.max(...[...o].map(a))+1:Number(i&&e.get(r).kind!==`goal`);n.set(r,s)}return n.get(r)};for(let t of e.keys()){let e=a(t);(r[e]??(r[e]=[])).push(t)}let o=new Map,s=Math.min(17,Math.max(3,Math.ceil(Math.sqrt(e.size*1.6)))),c=0;for(let n of r){let r=n.map(e=>{let n=t.get(e);return{id:e,center:n.size?[...n].reduce((e,t)=>e+o.get(t).y,0)/n.size:0}});r.sort((e,t)=>e.center-t.center);let i=r.map(e=>e.id),a=i.length>s?[i.filter(t=>!At(e.get(t))),i.filter(t=>At(e.get(t)))]:[i],l=0;for(let e of a){if(!e.length)continue;let t=Math.ceil(e.length/s),n=Math.ceil(e.length/t);for(let t=0;to.set(e,{x:c,y:(t-(r.length-1)/2)*Ft+i})),c+=266,l+=1}}c+=Pt}return o}function Lt(e,t){let n=It(e);if(!t.size)return n;let r=new Map([...t].filter(([t])=>e.nodes.has(t)));for(let[t,i]of n){if(r.has(t))continue;let n=[...e.upstream.get(t)].map(e=>r.get(e).x+266),a=Math.max(i.x,...n),o=[...r.values()].filter(e=>Math.abs(e.x-a)<133),s=i.y;for(let e=1;o.some(e=>Math.abs(e.y-s)1&&e.zoom(1).center(t))}function Vt(e,t){return[...[...e.nodes.values()].map(e=>({data:{id:e.id,kind:e.kind,color:Ue[e.kind]||`#86909c`},position:t.get(e.id)})),...e.edges.map(n=>{let r=t.get(n.source),i=t.get(n.target),a=i.x-r.x,o=[];return a!==0&&o.push(a>0?`forward`:`backward`),a>0&&e.layoutEdges.has(n.id)&&o.push(a>399?`long-flow`:`flow`),e.layoutEdges.has(n.id)||o.push(`cross-link`),{data:{...n,projection:n.projection||``,bend:i.y{u.current={model:e,selectedId:n,showAll:r,locate:i,onSelect:a},o.current?.sync()},[e,n,r,i,a,o]),(0,q.useEffect)(()=>{let e=c.current,n=l.current;if(!t){f([]);return}let r=!1,i,a,s,d,p,m,h,g,_=u.current.showAll;return f([]),ae(async()=>{let{default:e}=await import(`./cytoscape.esm-BPjn7guX.js`);return{default:e}},[]).then(({default:t})=>{if(r)return;i=t({container:e,style:Rt,layout:{name:`preset`,fit:!1},wheelSensitivity:.2,minZoom:.005,maxZoom:3,boxSelectionEnabled:!1,autounselectify:!0}),d=de(n,i);let c=()=>i.$id(u.current.selectedId)[0],l=()=>{cancelAnimationFrame(a),a=requestAnimationFrame(()=>f(G(i,{anchorId:p,allowCompact:e=>zt.has(e.data(`kind`))})))},v=()=>{let{model:e,selectedId:t,showAll:n,locate:r}=u.current,a=c(),o=a?.connectedEdges()||i.collection(),s=o.connectedNodes(),d=!n&&e.dense&&e.overview.size>0;if(i.batch(()=>{i.nodes().forEach(t=>{let n=t===a||s.has(t);t.toggleClass(`current`,t===a),t.toggleClass(`dim`,!(!a||n)),t.toggleClass(`hidden`,d&&!n&&!e.overview.has(t.id()))}),i.edges().forEach(t=>{let r=o.has(t);t.toggleClass(`related`,r),t.toggleClass(`dim`,!(!a||r)),t.toggleClass(`hidden`,!n&&e.dense&&!e.backbone.has(t.id())&&!r)})}),r&&r!==h&&a?.id()===r.id){h=r;let e=Math.max(i.zoom(),1);i.zoom(e).center(a)}else!a&&(n!==_||!t&&d&&g?.hidden())&&Bt(i);g=a,_=n,l()},y=(e=!1)=>{let{model:t}=u.current,n=!m;if(e||t!==m){let n=e?It(t):Lt(t,new Map(i.nodes().map(e=>[e.id(),e.position()])));m=t,p=[...t.nodes.values()].find(e=>e.kind===`goal`)?.id,i.json({elements:Vt(t,n)})}v(),(e||n&&!h)&&Bt(i)};o.current={sync:y,fit:()=>Bt(i),zoom:e=>fe(i,e),resetLayout:()=>y(!0)},y(),i.on(`pan zoom position`,l),i.on(`tap`,e=>{e.target===i?u.current.onSelect(``):e.target.isNode()&&u.current.onSelect(e.target.id())});let b=i.width(),x=i.height();s=new ResizeObserver(()=>{let e=b,t=x;i.resize();let n=i.width(),r=i.height();if(n===b&&r===x)return;i.panBy({x:(n-b)/2,y:(r-x)/2}),b=n,x=r;let a=c(),o=a?.renderedPosition();o&&(o.x<30||o.x>b-30||o.y<30||o.y>x-30)?i.center(a):!a&&(n{r||F(e,`图谱渲染失败`)}),()=>{r=!0,cancelAnimationFrame(a),s?.disconnect(),d?.(),i?.destroy(),o.current=null}},[t,o]),(0,$.jsxs)(`div`,{className:`assessment-graph-viewport`,role:`group`,"aria-label":`探索图`,children:[(0,$.jsx)(`div`,{ref:c,className:`assessment-graph-canvas`}),(0,$.jsx)(`div`,{ref:l,className:`graph-node-layer`,children:d.map(t=>{let r=e.nodes.get(t.id);if(!r)return null;let i=(r.title||r.id).replace(/\s+/g,` `).trim()||r.id;return(0,$.jsx)(K,{card:t,id:r.id,title:i,type:r.kind,category:we(s,r.kind),color:Ue[r.kind]||`#86909c`,factKey:r.id,boundary:r.boundary,selected:r.id===n,onSelect:a},r.id)})})]})}var{Text:Ut,Paragraph:Wt}=s,Gt=6;function Kt({task:e,t,onIntent:n,onGoIntents:r}){let i=e.steps||[],a=new Map(i.map(e=>[e.id,e.title||e.id])),o=i.filter(e=>e.status===`completed`).length,s=e.summary?.trim();return(0,$.jsxs)(`details`,{className:`assessment-graph-brief`,children:[(0,$.jsxs)(`summary`,{children:[(0,$.jsx)(Ut,{strong:!0,children:`目标拆解与阶段总结`}),(0,$.jsx)(Ut,{type:`tertiary`,size:`small`,className:`assessment-graph-brief-counts`,children:i.length?`${i.length} 个意图 · ${o} 个已完成`:`暂无意图`})]}),(0,$.jsxs)(`div`,{className:`assessment-graph-brief-grid`,children:[(0,$.jsxs)(`section`,{className:`assessment-graph-brief-content`,children:[(0,$.jsx)(Ut,{strong:!0,children:t(`deepAssessments.objective`,null,`目标`)}),(0,$.jsx)(Wt,{className:`assessment-pre`,children:e.objective||e.name||`—`}),i.length?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`ul`,{className:`assessment-graph-intents`,"aria-label":`目标拆解`,children:i.slice(-6).map(e=>{let r=(e.depends_on||[]).map(e=>a.get(e)||e);return(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`div`,{className:`assessment-graph-intent-head`,children:[(0,$.jsx)(f,{size:`small`,theme:`borderless`,onClick:()=>n(e.id),title:a.get(e.id),children:a.get(e.id)}),e.status?(0,$.jsx)(u,{size:`small`,children:Q(t,e.status)}):null]}),r.length?(0,$.jsxs)(Ut,{size:`small`,type:`tertiary`,children:[`上游依赖 · `,r.slice(0,2).join(`、`),r.length>2?` 等 ${r.length} 项`:``]}):null]},e.id)})}),i.length>Gt?(0,$.jsx)(f,{size:`small`,theme:`borderless`,onClick:r,children:`查看全部意图`}):null]}):(0,$.jsx)(Ut,{type:`tertiary`,size:`small`,children:`已有计划中的意图会显示在这里。`})]}),(0,$.jsxs)(`section`,{className:`assessment-graph-brief-content`,children:[(0,$.jsx)(Ut,{strong:!0,children:`阶段总结`}),(0,$.jsx)(Wt,{className:`assessment-pre assessment-graph-summary`,children:s||`当前还没有保存的阶段总结。`}),s&&e.updated_at?(0,$.jsxs)(Ut,{size:`small`,type:`tertiary`,children:[`测评更新于 `,D(e.updated_at)]}):null]})]})]})}var{Text:qt,Paragraph:Jt}=s;function Yt({id:e,task:t,reloadToken:n,onGoIntents:r,autoRefresh:i,onAutoRefreshChange:a,onRefreshTask:s,refreshPaused:l}){let d=O(),[p,m]=(0,q.useState)(`summary`),[h,g]=(0,q.useState)(``),[v,y]=(0,q.useState)(0),[x,S]=(0,q.useState)(``),[C,w]=(0,q.useState)(!1),[T,E]=(0,q.useState)(null),[k,j]=(0,q.useState)(null),[M,N]=(0,q.useState)([]),[I,R]=(0,q.useState)(0),[te,ne]=(0,q.useState)(!1),[V,re]=(0,q.useState)(0),[H,ae]=(0,q.useState)(!1),[oe,W]=(0,q.useState)(!1),[se,ce]=(0,q.useState)(null),[le,ue]=(0,q.useState)(!1),G=(0,q.useRef)(null),de=(0,q.useRef)(null),K=(0,q.useRef)(!1),fe=(0,q.useRef)(0),me=JSON.stringify([e,p,h,v]),J=P(async()=>{let t=await A.get(`/deep-assessments/${e}/graph`,{view:p,scope:h,offset:v,limit:80}),n=JSON.stringify(t),r=de.current;if(r?.key===me&&r.snapshot===n)return r;let i={key:me,snapshot:n,graph:t};return de.current=i,i},[e,p,h,v,n]),Y=J.data?.graph,X=(0,q.useMemo)(()=>Nt(Y),[Y]),Z=[...X.nodes.values()],he=X.overview.size?X.nodes.size-X.overview.size:0,ge=X.dense&&(he>0||X.edges.length>X.backbone.size),_e=(0,q.useCallback)(async(t,n={})=>{let{appendBody:r=!1,appendLinks:i=!1,center:a=!1}=n,o=++fe.current;if(S(t),a&&E({id:t}),!r&&!i&&(j(null),N([]),ce(null)),ue(!1),W(!!t),t)try{let n=await A.get(`/deep-assessments/${e}/graph/node`,{node_id:t,offset:r?V:0,links_offset:i?I:0});if(o!==fe.current)return;if(!i){let e=n?.node||null;j(t=>r&&t&&e&&t.id===e.id?{...e,body:`${t.body||``}${e.body||``}`}:e),re(Number(n?.next_offset)||0),ae(!!n?.has_more)}r||(N(e=>i?[...e,...n?.relations||[]]:n?.relations||[]),R(Number(n?.relations_next_offset)||0),ne(!!n?.relations_has_more))}catch(e){o===fe.current&&F(e,`读取节点失败`)}finally{o===fe.current&&W(!1)}},[e,V,I]),ve=async()=>{if(!k)return;let t=fe.current;ue(!0);try{let n=await A.get(`/deep-assessments/${e}/evidence-path`,{fact_id:k.id});t===fe.current&&ce(n)}catch(e){t===fe.current&&F(e,`读取证据路径失败`)}finally{t===fe.current&&ue(!1)}},ye=e=>Promise.all([J.reload(e),s(e)]);ie(async()=>{if(!(document.hidden||l||J.loading||K.current)){K.current=!0;try{await ye({silent:!0})}finally{K.current=!1}}},i?1e4:0);let be=(0,$.jsxs)(c,{wrap:!0,children:[(0,$.jsx)(b,{className:`assessment-view-options`,"aria-label":d(`deepAssessments.graphView.label`,null,`图谱视图`),type:`button`,value:p,options:[{value:`summary`,label:d(`deepAssessments.graphView.summary`,null,`主链路`)},{value:`full`,label:d(`deepAssessments.graphView.full`,null,`执行记录`)}],onChange:e=>{m(e.target.value),y(0)}}),(0,$.jsx)(f,{size:`small`,onClick:()=>{g(``),y(0)},disabled:!h&&v===0,children:`全图概览`}),(0,$.jsx)(f,{size:`small`,onClick:()=>ye(),loading:J.loading,children:`刷新`})]}),xe=Z.map(e=>({value:e.id,title:e.title||e.id,label:`${e.boundary?`引用 · `:``}${we(d,e.kind)} · ${Ve(e.title||e.id,40)}`}));return(0,$.jsx)(`div`,{className:`assessment-tab`,children:(0,$.jsxs)(B,{title:d(`deepAssessments.graph`,null,`探索图`),description:`点击节点查看原文与直接关联,放大可查看更多卡片内容。`,extra:be,children:[(0,$.jsx)(z,{error:J.error,onRetry:()=>ye()}),(0,$.jsx)(Kt,{task:t,t:d,onIntent:e=>_e(`step:${e}`,{center:!0}),onGoIntents:r}),(0,$.jsxs)(`div`,{className:`assessment-graph-meta`,children:[(0,$.jsxs)(qt,{type:`tertiary`,children:[`当前页节点 `,Y?.primary_count??Math.max(0,Z.length-1),` / `,Y?.total??0,` · `,`已折叠 `,Y?.folded??0,` · `,`隐藏明细 `,Y?.details_hidden??0,` · `,`跨页引用 `,Y?.boundary_total??0]}),h?(0,$.jsxs)(c,{children:[(0,$.jsxs)(u,{size:`small`,color:`blue`,children:[`已聚焦 `,h]}),(0,$.jsx)(f,{size:`small`,theme:`borderless`,onClick:()=>{g(``),y(0)},children:`返回全图`})]}):null,(0,$.jsxs)(c,{spacing:6,children:[(0,$.jsx)(qt,{size:`small`,type:`tertiary`,children:`自动刷新`}),(0,$.jsx)(_,{size:`small`,"aria-label":`自动刷新探索图`,checked:i,onChange:a})]})]}),J.loading&&!Y?(0,$.jsx)(qt,{type:`tertiary`,children:`正在读取图谱…`}):null,(0,$.jsxs)(`div`,{className:`assessment-graph-toolbar`,children:[(0,$.jsx)(ee,{"aria-label":`搜索图谱节点`,value:X.nodes.has(x)?x:void 0,onChange:e=>_e(e?String(e):``,{center:!!e}),optionList:xe,placeholder:`搜索并定位节点`,className:`assessment-graph-search`,filter:(e,t)=>`${t.label} ${t.title} ${t.value}`.toLowerCase().includes(e.toLowerCase().trim()),showClear:!0}),(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:v===0,onClick:()=>y(e=>Math.max(0,e-80)),children:d(`deepAssessments.previous`,null,`上一页`)}),(0,$.jsxs)(qt,{type:`tertiary`,children:[`第 `,Math.floor(v/80)+1,` 页`]}),(0,$.jsx)(f,{size:`small`,disabled:!Y?.has_more,onClick:()=>y(e=>e+80),children:d(`deepAssessments.next`,null,`下一页`)})]})]}),Y&&Z.length===0&&!x?(0,$.jsx)(o,{title:`暂无图谱节点`,description:`开始测评后会生成目标、意图、事实与证据节点。`,style:{padding:48}}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`assessment-graph-layout${x?` with-details`:``}`,children:[(0,$.jsx)(Ht,{model:X,graphKey:J.data?.key,selectedId:x,showAll:C,locate:T,onSelect:_e,chartRef:G}),x?(0,$.jsx)(`div`,{className:`assessment-node-panel`,"aria-live":`polite`,children:(0,$.jsxs)(`div`,{className:`assessment-node-body`,children:[(0,$.jsxs)(`div`,{className:`assessment-node-head`,children:[(0,$.jsxs)(`div`,{className:`assessment-node-title`,children:[(0,$.jsx)(qt,{strong:!0,children:k?.title||X.nodes.get(x)?.title||x}),(0,$.jsx)(f,{size:`small`,theme:`borderless`,onClick:()=>_e(``),children:`关闭详情`})]}),(0,$.jsxs)(c,{spacing:4,children:[k?(0,$.jsx)(u,{size:`small`,color:`blue`,children:we(d,k.kind)}):null,k?.state?(0,$.jsx)(u,{size:`small`,color:`grey`,children:Te(d,k.state)}):null,k?.boundary?(0,$.jsx)(u,{size:`small`,color:`amber`,children:`跨页引用`}):null]})]}),oe?(0,$.jsx)(qt,{type:`tertiary`,children:`正在读取节点…`}):null,k?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Jt,{className:`assessment-pre assessment-node-content`,children:k.body||`—`}),H?(0,$.jsx)(f,{size:`small`,onClick:()=>_e(k.id,{appendBody:!0}),loading:oe,children:`继续读取原文`}):null,(0,$.jsx)(L,{columns:1,items:[{label:`节点 ID`,value:k.id},{label:`意图`,value:k.step_id||`—`},{label:`更新轮次`,value:k.updated_round??`—`},{label:`更新时间`,value:D(k.updated_at)}]}),M.length?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(qt,{strong:!0,children:`关联节点`}),(0,$.jsx)(`div`,{className:`assessment-relations`,children:M.map((e,t)=>(0,$.jsxs)(f,{size:`small`,theme:`borderless`,onClick:()=>e.node?.id&&_e(e.node.id,{center:!0}),children:[e.direction===`upstream`?`上游`:`下游`,` · `,e.relation,` · `,Ve(e.node?.title,30)]},`${e.node?.id}-${t}`))}),te?(0,$.jsx)(f,{size:`small`,onClick:()=>_e(k.id,{appendLinks:!0}),loading:oe,children:`继续查看关联`}):null]}):null,k.kind===`fact`?(0,$.jsx)(f,{size:`small`,onClick:ve,loading:le,children:`查看证据路径`}):null,k.step_id?(0,$.jsx)(f,{size:`small`,theme:`borderless`,onClick:()=>{g(k.id),y(0)},children:`展开此节点分支`}):null,se?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsxs)(qt,{strong:!0,children:[`证据路径 · `,se.title||se.root]}),(0,$.jsxs)(qt,{type:`tertiary`,size:`small`,children:[`节点 `,Array.isArray(se.nodes)?se.nodes.length:0,` · 未归属回执 `,se.unattributed_receipts||0]}),(0,$.jsx)(`div`,{className:`assessment-path-list`,children:(se.nodes||[]).map(e=>(0,$.jsxs)(`div`,{className:`assessment-path-node`,children:[(0,$.jsx)(u,{size:`small`,children:we(d,e.kind)}),(0,$.jsx)(qt,{ellipsis:{showTooltip:!0},children:e.title||e.id})]},e.id))}),(0,$.jsx)(U,{title:`证据路径原始数据`,value:se,collapsed:!0})]}):null,(0,$.jsx)(U,{title:`节点来源`,value:k.source||{},collapsed:!0})]}):null]})}):null]}),(0,$.jsxs)(`div`,{className:`assessment-graph-tools`,children:[(0,$.jsxs)(c,{wrap:!0,children:[(0,$.jsx)(f,{size:`small`,"aria-label":`缩小图谱`,disabled:!Z.length,onClick:()=>G.current?.zoom(.8),children:`−`}),(0,$.jsx)(f,{size:`small`,"aria-label":`放大图谱`,disabled:!Z.length,onClick:()=>G.current?.zoom(1.25),children:`+`}),(0,$.jsx)(f,{size:`small`,disabled:!Z.length,onClick:()=>G.current?.fit(),children:`适应画布`}),(0,$.jsx)(f,{size:`small`,disabled:!Z.length,onClick:()=>G.current?.resetLayout(),children:`重置布局`})]}),ge?(0,$.jsxs)(c,{wrap:!0,children:[(0,$.jsxs)(qt,{size:`small`,type:`tertiary`,children:[C?`全部 ${X.edges.length} 条连线`:`主干 ${X.backbone.size} / ${X.edges.length} 条连线`,!C&&he>0?` · 收起 ${he} 个明细节点`:null]}),(0,$.jsx)(f,{size:`small`,onClick:()=>w(e=>!e),children:C?`仅看主干`:`显示全部节点与连线`})]}):null]}),Z.length?(0,$.jsx)(`div`,{className:`assessment-graph-legend`,role:`group`,"aria-label":`节点图例`,children:[...new Set(Z.map(e=>e.kind))].map(e=>(0,$.jsxs)(`span`,{style:{"--graph-node-color":Ue[e]||`#86909c`},children:[(0,$.jsx)(pe,{type:e}),we(d,e)]},e))}):null,X.legend.length?(0,$.jsx)(`div`,{className:`assessment-graph-legend`,role:`group`,"aria-label":`连线图例`,children:X.legend.map(({label:e,color:t})=>(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`i`,{"aria-hidden":`true`,style:{backgroundColor:t}}),e]},e))}):null]})]})})}var{Text:Xt,Paragraph:Zt}=s,Qt={open:`待处理`,confirmed:`已确认`,fixed:`已修复`,false_positive:`误报`,ignored:`已忽略`};function $t({id:e,reloadToken:t}){let n=O(),[r,i]=(0,q.useState)(0),[a,o]=(0,q.useState)(null),[s,l]=(0,q.useState)(!1),d=P(()=>A.get(`/deep-assessments/${e}/vulnerabilities`,{limit:20,offset:r}),[e,r,t]),p=d.data,m=p?.vulnerabilities||[],h=async t=>{l(!0);try{let n=await A.get(`/deep-assessments/${e}/vulnerabilities/${t.id}`);o(n)}catch(e){F(e,`读取漏洞详情失败`)}finally{l(!1)}},g=a?.vulnerability||null,_=[{title:`漏洞标题`,dataIndex:`title`,render:(e,t)=>(0,$.jsxs)(`div`,{className:`assessment-list-name`,children:[(0,$.jsx)(Xt,{strong:!0,ellipsis:{showTooltip:!0},children:e||t.id}),t.target?(0,$.jsx)(Xt,{type:`tertiary`,size:`small`,className:`assessment-ellipsis`,children:t.target}):null]})},{title:`严重级别`,dataIndex:`severity`,width:100,render:e=>(0,$.jsx)(te,{severity:e})},{title:n(`deepAssessments.status`,null,`状态`),dataIndex:`status`,width:100,render:e=>(0,$.jsx)(u,{size:`small`,children:Qt[e]||e||`—`})},{title:`来源意图`,dataIndex:`assessment_step_title`,width:220,render:(e,t)=>e||t.assessment_step_id||`—`},{title:`登记时间`,dataIndex:`created_at`,width:170,render:e=>D(e)},{title:`操作`,width:90,render:(e,t)=>(0,$.jsx)(f,{size:`small`,theme:`borderless`,onClick:()=>h(t),loading:s,children:`详情`})}];return(0,$.jsxs)(`div`,{className:`assessment-tab`,children:[(0,$.jsxs)(B,{title:n(`deepAssessments.findings`,null,`关联漏洞`),description:`已登记的发现仍需要独立复现;报告记录不等于独立确认。`,extra:(0,$.jsx)(f,{size:`small`,onClick:()=>d.reload(),loading:d.loading,children:`刷新`}),children:[(0,$.jsx)(z,{error:d.error,onRetry:()=>d.reload()}),(0,$.jsx)(H,{columns:_,dataSource:m,rowKey:`id`,loading:d.loading,pagination:!1,onRow:e=>({onClick:()=>h(e),style:{cursor:`pointer`}}),emptyText:`暂未登记漏洞。`}),(0,$.jsx)(`div`,{className:`assessment-pager`,children:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:r===0,onClick:()=>i(e=>Math.max(0,e-20)),children:n(`deepAssessments.previous`,null,`上一页`)}),(0,$.jsxs)(Xt,{type:`tertiary`,children:[`共 `,p?.total??0,` 条`]}),(0,$.jsx)(f,{size:`small`,disabled:!p?.has_more,onClick:()=>i(e=>e+20),children:n(`deepAssessments.next`,null,`下一页`)})]})})]}),(0,$.jsx)(I,{visible:!!a,onCancel:()=>o(null),title:g?.title||`漏洞详情`,width:680,footer:null,children:g?(0,$.jsxs)(`div`,{className:`assessment-drawer`,children:[(0,$.jsx)(L,{columns:2,items:[{label:`严重级别`,value:(0,$.jsx)(te,{severity:g.severity})},{label:n(`deepAssessments.status`,null,`状态`),value:Qt[g.status]||g.status},{label:`类型`,value:g.type||`—`},{label:`目标`,value:g.target||`—`},{label:`来源意图`,value:a.step?.title||g.assessment_step_title||g.assessment_step_id||`—`},{label:`登记时间`,value:D(g.created_at)},{label:`漏洞 ID`,value:g.id}]}),[[`描述`,g.description],[`前置条件`,g.preconditions],[`复现步骤`,g.reproduction_steps],[`复现证据`,g.evidence],[`影响`,g.impact],[`修复建议`,g.recommendation],[`复核说明`,g.retest_notes]].filter(([,e])=>e).map(([e,t])=>(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(Xt,{strong:!0,children:e}),(0,$.jsx)(Zt,{className:`assessment-pre`,children:t})]},e)),a.step?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(Xt,{strong:!0,children:`来源意图摘要`}),(0,$.jsx)(Zt,{className:`assessment-pre`,children:Ve(a.step.summary||a.step.instruction,600)})]}):null,(0,$.jsx)(U,{title:`原始漏洞记录`,value:a,collapsed:!0})]}):null})]})}var{Text:en,Paragraph:tn}=s,nn=[``,`has_evidence`,`missing`,`needs_review`];function rn({visible:e,id:t,onCancel:n,edit:r,onEdit:i,onSave:a,saving:o,saveError:s}){let l=O(),h=r?`编辑验收证据关联`:`证据来源`,[g,_]=(0,q.useState)(`fact`),[v,y]=(0,q.useState)(``),[b,x]=(0,q.useState)(0),C=ne(v,300);(0,q.useEffect)(()=>{x(0)},[g,C]);let w=P(()=>A.get(`/deep-assessments/${t}/acceptance/sources`,{kind:g,q:C,offset:b}),[t,g,C,b,e],{skip:!e}),T=w.data,E=T?.sources||[],k=g===`fact`?`fact_ids`:`receipt_ids`,j=(e,t)=>i(k,t?[...r[k],e]:r[k].filter(t=>t!==e)),M=[...r?[{key:`selected`,title:`关联`,width:80,render:(e,t)=>(0,$.jsx)(d,{checked:r[k].includes(t.id),disabled:o,"aria-label":`关联 ${t.title||t.id}`,onChange:e=>j(t.id,e.target.checked)})}]:[],{title:`证据`,dataIndex:`title`,render:(e,t)=>(0,$.jsxs)(`div`,{className:`assessment-list-name`,children:[(0,$.jsx)(en,{ellipsis:{showTooltip:!0},children:e||t.id}),(0,$.jsx)(en,{type:`tertiary`,size:`small`,className:`assessment-ellipsis`,children:t.id})]})},{title:l(`deepAssessments.status`,null,`状态`),dataIndex:`state`,width:120,render:e=>(0,$.jsx)(u,{size:`small`,children:Te(l,e)})},{title:`来源意图`,dataIndex:`step_id`,width:140,render:e=>e||`—`},{title:`回执引用`,dataIndex:`receipt_ids`,width:100,render:e=>(e||[]).length||`—`},{title:`时间`,dataIndex:`created_at`,width:170,render:e=>D(e)}];return(0,$.jsxs)(I,{visible:e,title:h,"aria-label":h,onCancel:n,width:900,closable:!o,closeOnEsc:!o,maskClosable:!o,footer:r&&(0,$.jsxs)(`div`,{className:`assessment-form-actions`,children:[(0,$.jsx)(f,{onClick:n,disabled:o,children:`取消`}),(0,$.jsx)(f,{theme:`solid`,onClick:a,loading:o,disabled:o,children:`保存证据关联`})]}),children:[(0,$.jsxs)(`div`,{className:`assessment-toolbar`,children:[(0,$.jsx)(ee,{value:g,onChange:e=>_(e||`fact`),optionList:[{value:`fact`,label:`事实`},{value:`receipt`,label:`原始回执`}],style:{width:140}}),(0,$.jsx)(m,{prefix:(0,$.jsx)(S,{}),value:v,onChange:y,placeholder:`按名称、来源意图或 ID 搜索`,style:{width:280},showClear:!0}),(0,$.jsx)(en,{type:`tertiary`,children:`只有原始回执与 observed 事实可作为验收依据。`})]}),(0,$.jsx)(z,{error:w.error,onRetry:()=>w.reload()}),(0,$.jsx)(H,{columns:M,dataSource:E,rowKey:`id`,loading:w.loading,pagination:!1,emptyText:`没有匹配的证据记录。`}),(0,$.jsx)(`div`,{className:`assessment-pager`,children:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:b===0,onClick:()=>x(e=>Math.max(0,e-20)),children:l(`deepAssessments.previous`,null,`上一页`)}),(0,$.jsx)(en,{type:`tertiary`,children:E.length?`${b+1} - ${b+E.length}`:`0`}),(0,$.jsx)(f,{size:`small`,disabled:!T?.has_more,onClick:()=>x(e=>e+20),children:l(`deepAssessments.next`,null,`下一页`)})]})}),r&&(0,$.jsxs)(`div`,{className:`assessment-section`,children:[(0,$.jsx)(c,{wrap:!0,children:[`fact_ids`,`receipt_ids`].flatMap(e=>r[e].map(t=>(0,$.jsx)(u,{closable:!o,onClose:()=>i(e,r[e].filter(e=>e!==t)),children:(e===`fact_ids`?`事实`:`回执`)+` · `+(r.titles[t]||t)},e+t)))}),(0,$.jsx)(d,{checked:r.needs_review,disabled:o,onChange:e=>i(`needs_review`,e.target.checked),children:`标记待人工复核`}),(0,$.jsx)(p,{"aria-label":`复核说明`,placeholder:`复核说明`,value:r.review_note,disabled:o,onChange:e=>i(`review_note`,e)}),(0,$.jsx)(z,{error:s})]})]})}function an({id:e,criterion:t,canWrite:n,reloadToken:r}){let i=O(),[a,o]=(0,q.useState)(``),[s,l]=(0,q.useState)(null),[d,p]=(0,q.useState)(null),[m,h]=(0,q.useState)(!1),[g,_]=(0,q.useState)(null),v=(0,q.useRef)(null),b=(0,q.useRef)(0),[x,S]=(0,q.useState)(!1),[C,w]=(0,q.useState)(null),[T,E]=(0,q.useState)(!1),D=P(()=>A.get(`/deep-assessments/${e}/acceptance`),[e,r]),k=D.data?.rows||[],j=k.find(e=>e.number===s);(0,q.useEffect)(()=>{t&&v.current!==t&&k.some(e=>e.number===t)&&(v.current=t,b.current++,w(null),E(!1),l(t))},[t,k]);let M=(0,q.useMemo)(()=>{let e={has_evidence:0,missing:0,needs_review:0};return k.forEach(t=>{e[t.status]=(e[t.status]||0)+1}),e},[k]),R=k.length?Math.round(M.has_evidence/k.length*100):0,te=a?k.filter(e=>e.status===a):k,ne=[{id:`total`,label:`验收项`,value:k.length},{id:`has_evidence`,label:Oe(i,`has_evidence`),value:M.has_evidence||0},{id:`missing`,label:Oe(i,`missing`),value:M.missing||0},{id:`needs_review`,label:Oe(i,`needs_review`),value:M.needs_review||0}],V=e=>{b.current++,l(e?.number??null),w(null),E(!1)},re=()=>{j&&n&&(_(null),p({number:j.number,revision:j.revision,fact_ids:j.fact_ids||[],receipt_ids:j.receipt_ids||[],needs_review:!!j.needs_review,review_note:j.review_note||``,titles:Object.fromEntries([...j.facts||[],...j.receipts||[]].map(e=>[e.id,e.title]))}),S(!0))},ie=()=>{S(!1),p(null)},ae=async()=>{if(!n||!d||m)return;let{number:t,revision:r,fact_ids:i,receipt_ids:a,needs_review:o,review_note:s}=d;h(!0),_(null);try{await A.put(`/deep-assessments/${encodeURIComponent(e)}/acceptance/${t}`,{revision:r,fact_ids:i,receipt_ids:a,needs_review:o,review_note:s}),W(`验收证据关联已保存`),ie(),await D.reload()}catch(e){_(e.status===409?Error(`验收项已有修改。请取消编辑,重新打开后再保存。`):e),e.status===409&&D.reload()}finally{h(!1)}},oe=async()=>{if(!j)return;let t=++b.current;E(!0);try{let n=await A.get(`/deep-assessments/${e}/evidence-path`,{criterion:j.number});t===b.current&&w(n)}catch(e){t===b.current&&F(e,`读取证据路径失败`)}finally{t===b.current&&E(!1)}},se=[{title:`序号`,dataIndex:`number`,width:70},{title:`验收项`,dataIndex:`text`,render:(e,t)=>(0,$.jsxs)(`div`,{className:`assessment-list-name`,children:[(0,$.jsx)(en,{ellipsis:{showTooltip:!0},children:e||`—`}),t.review_note?(0,$.jsxs)(en,{type:`tertiary`,size:`small`,className:`assessment-ellipsis`,children:[`复核说明:`,Ve(t.review_note,80)]}):null]})},{title:i(`deepAssessments.status`,null,`状态`),dataIndex:`status`,width:120,render:e=>(0,$.jsx)(u,{color:xe[e]||`grey`,shape:`circle`,children:Oe(i,e)})},{title:`事实`,dataIndex:`facts`,width:80,render:e=>(e||[]).length},{title:`回执`,dataIndex:`receipts`,width:80,render:e=>(e||[]).length},{title:`操作`,width:110,render:(e,t)=>(0,$.jsx)(f,{size:`small`,theme:`borderless`,onClick:()=>V(t),children:`查看证据`})}];return(0,$.jsxs)(`div`,{className:`assessment-tab`,children:[(0,$.jsx)(N,{metrics:ne,columns:4}),(0,$.jsxs)(B,{title:i(`deepAssessments.acceptance`,null,`验收证据`),description:`状态反映证据关联情况,验收结论由审阅人核对;观察事实需有本意图的原始成功回执。`,extra:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,onClick:()=>D.reload(),loading:D.loading,children:`刷新`}),(0,$.jsx)(f,{size:`small`,onClick:()=>S(!0),children:`浏览证据来源`})]}),children:[(0,$.jsxs)(`div`,{className:`assessment-toolbar`,children:[(0,$.jsxs)(c,{children:[(0,$.jsx)(y,{percent:R,showInfo:!0,size:`small`,strokeWidth:8,style:{width:220}}),(0,$.jsxs)(en,{type:`tertiary`,children:[`已有证据覆盖 `,R,`%`]})]}),(0,$.jsx)(ee,{value:a,onChange:e=>o(e||``),optionList:nn.map(e=>({value:e,label:e?`${Oe(i,e)} · ${M[e]||0}`:`${i(`deepAssessments.all`,null,`全部`)} · ${k.length}`})),style:{width:190}})]}),(0,$.jsx)(z,{error:D.error,onRetry:()=>D.reload()}),(0,$.jsx)(H,{columns:se,dataSource:te,rowKey:`number`,loading:D.loading,pagination:!1,onRow:e=>({onClick:()=>V(e),style:{cursor:`pointer`}}),emptyText:`没有符合筛选条件的验收项。`})]}),(0,$.jsx)(at,{id:e,reloadToken:r},e),(0,$.jsx)(rn,{visible:x,id:e,onCancel:ie,edit:d,onEdit:(e,t)=>p(n=>({...n,[e]:t})),onSave:ae,saving:m,saveError:g}),(0,$.jsx)(I,{visible:!!j,onCancel:()=>V(null),title:j?`验收项 ${j.number}`:`验收项`,width:720,closeOnEsc:!x,footer:null,children:j?(0,$.jsxs)(`div`,{className:`assessment-drawer`,children:[(0,$.jsx)(L,{columns:1,items:[{label:`验收条件`,value:(0,$.jsx)(tn,{className:`assessment-pre`,children:j.text||`—`})},{label:i(`deepAssessments.status`,null,`状态`),value:(0,$.jsx)(u,{color:xe[j.status]||`grey`,children:Oe(i,j.status)})},{label:`复核说明`,value:j.review_note||`—`},{label:`人工标记待复核`,value:j.needs_review?`是`:`否`}]}),(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(en,{strong:!0,children:`关联事实`}),(0,$.jsx)(H,{columns:[{title:`事实`,dataIndex:`title`,render:(e,t)=>(0,$.jsx)(en,{ellipsis:{showTooltip:!0},children:e||t.id})},{title:`状态`,dataIndex:`state`,width:120,render:e=>Te(i,e)},{title:`回执引用`,dataIndex:`receipt_ids`,width:100,render:e=>(e||[]).length}],dataSource:j.facts||[],rowKey:`id`,pagination:!1,size:`small`,emptyText:`暂无关联事实。`})]}),(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(en,{strong:!0,children:`关联回执`}),(0,$.jsx)(H,{columns:[{title:`回执`,dataIndex:`title`,render:(e,t)=>(0,$.jsx)(en,{ellipsis:{showTooltip:!0},children:e||t.id})},{title:`状态`,dataIndex:`state`,width:120,render:e=>Te(i,e)},{title:`来源意图`,dataIndex:`step_id`,width:140}],dataSource:j.receipts||[],rowKey:`id`,pagination:!1,size:`small`,emptyText:`暂无关联回执。`})]}),(0,$.jsxs)(c,{children:[n&&(0,$.jsx)(f,{size:`small`,theme:`solid`,onClick:re,children:`编辑证据关联`}),(0,$.jsx)(f,{size:`small`,onClick:oe,loading:T,children:`读取局部证据图`}),(0,$.jsx)(f,{size:`small`,theme:`borderless`,onClick:()=>S(!0),children:`浏览证据来源`})]}),C?(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsxs)(en,{strong:!0,children:[`证据路径 · `,C.title||C.root]}),(0,$.jsx)(`div`,{className:`assessment-path-list`,children:(C.nodes||[]).map(e=>(0,$.jsxs)(`div`,{className:`assessment-path-node`,children:[(0,$.jsx)(u,{size:`small`,children:e.kind}),(0,$.jsx)(en,{ellipsis:{showTooltip:!0},children:e.title||e.id})]},e.id))}),(0,$.jsx)(U,{title:`证据路径原始数据`,value:C,collapsed:!0})]}):null]}):null})]})}var{Text:on,Paragraph:sn}=s,cn=[{value:`receipts`,label:`执行回执`},{value:`path`,label:`证据路径`},{value:`history`,label:`历次测评`,permission:`asset:read`},{value:`endpoints`,label:`端点证据`,permission:`asset:read`}],ln=2e5,un=e=>typeof e==`string`&&e.length>ln?`${e.slice(0,ln)}\n…(已截断 ${e.length-ln} 字符,完整内容请下载原始回执)`:He(e),dn=[{value:`criterion`,label:`验收项序号`},{value:`asset`,label:`资产 ID`},{value:`fact`,label:`事实 ID`}];function fn({id:e,criterion:t=0,factId:n=``,stepId:r=``,reloadToken:i}){let a=O(),{hasPermission:o}=k(),s=(0,q.useMemo)(()=>cn.filter(e=>!e.permission||o(e.permission)),[o]),[l,d]=(0,q.useState)(t>0||n?`path`:`receipts`),p=s.some(e=>e.value===l)?l:`receipts`,[h,g]=(0,q.useState)(0),[_,v]=(0,q.useState)(null),y=P(()=>A.get(`/deep-assessments/${e}/receipts`,{offset:h,step_id:r}),[e,h,r,i],{skip:p!==`receipts`}),[b,x]=(0,q.useState)(n?`fact`:`criterion`),[S,C]=(0,q.useState)(n||(t>0?String(t):``)),[w,E]=(0,q.useState)(null),[j,N]=(0,q.useState)({loading:!1,error:null}),[F,R]=(0,q.useState)(``),[te,ne]=(0,q.useState)(``),[V,re]=(0,q.useState)(null),[ie,ae]=(0,q.useState)({loading:!1,error:null}),[W,se]=(0,q.useState)(null),[ce,le]=(0,q.useState)({loading:!1,error:null});(0,q.useEffect)(()=>{g(0)},[p]);let ue=async()=>{let t=S.trim(),n=null;if(b===`criterion`){let e=Number(t);if(!Number.isFinite(e)||e<1){M(`请填写有效的验收项序号`);return}n={criterion:Math.floor(e)}}else if(b===`asset`){if(!t){M(`请填写资产 ID`);return}n={asset_id:t}}else{if(!t){M(`请填写事实 ID`);return}n={fact_id:t}}N({loading:!0,error:null});try{let t=await A.get(`/deep-assessments/${e}/evidence-path`,n);E(t),N({loading:!1,error:null})}catch(e){E(null),N({loading:!1,error:e})}};(0,q.useEffect)(()=>{(t>0||n)&&ue()},[e,t,n]);let G=async()=>{let t=F.trim();if(!t)M(`请填写资产 ID`);else{ae({loading:!0,error:null}),ne(t);try{let n=await A.get(`/deep-assessments/${e}/evidence-history`,{asset_id:t});re(n),ae({loading:!1,error:null})}catch(e){re(null),ae({loading:!1,error:e})}}},de=async()=>{let t=F.trim();if(!t)M(`请填写资产 ID`);else{le({loading:!0,error:null});try{let n=await A.get(`/deep-assessments/${e}/endpoint-evidence`,{asset_id:t});se(n),le({loading:!1,error:null})}catch(e){se(null),le({loading:!1,error:e})}}},K=y.data?.receipts||[],fe=[{title:a(`deepAssessments.status`,null,`状态`),dataIndex:`status`,width:110,render:e=>(0,$.jsx)(oe,{status:e,label:Q(a,e)})},{title:`工具`,dataIndex:`tool`,width:200,render:(e,t)=>(0,$.jsxs)(`div`,{className:`assessment-list-name`,children:[(0,$.jsx)(on,{strong:!0,children:e||`—`}),(0,$.jsx)(on,{type:`tertiary`,size:`small`,className:`assessment-ellipsis`,children:t.id})]})},{title:`来源意图`,dataIndex:`step_id`,width:160,render:e=>e||`—`},{title:`执行 ID`,dataIndex:`execution_id`,render:e=>e?(0,$.jsx)(on,{type:`tertiary`,ellipsis:{showTooltip:!0},children:e}):`—`},{title:`操作`,width:90,render:(e,t)=>(0,$.jsx)(f,{size:`small`,theme:`borderless`,onClick:()=>v(t),children:`查看`})}];return(0,$.jsxs)(`div`,{className:`assessment-tab`,children:[(0,$.jsxs)(B,{title:a(`deepAssessments.evidence`,null,`证据回执`),description:`回执是执行原始记录;路径与对照只读展示已保存的关联,不改变测评状态。`,extra:(0,$.jsxs)(c,{children:[(0,$.jsx)(ee,{value:p,onChange:e=>d(e||`receipts`),optionList:s.map(e=>({value:e.value,label:e.label})),style:{width:160}}),(0,$.jsx)(f,{size:`small`,onClick:()=>p===`receipts`?y.reload():void 0,disabled:p!==`receipts`,children:`刷新`})]}),children:[p===`receipts`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{error:y.error,onRetry:()=>y.reload()}),(0,$.jsx)(H,{columns:fe,dataSource:K,rowKey:`id`,loading:y.loading,pagination:!1,onRow:e=>({onClick:()=>v(e),style:{cursor:`pointer`}}),emptyText:a(`deepAssessments.noRecords`,null,`暂无记录`)}),(0,$.jsx)(`div`,{className:`assessment-pager`,children:(0,$.jsxs)(c,{children:[(0,$.jsx)(f,{size:`small`,disabled:h===0,onClick:()=>g(e=>Math.max(0,e-50)),children:a(`deepAssessments.previous`,null,`上一页`)}),(0,$.jsxs)(on,{type:`tertiary`,children:[`共 `,K.length,` 条`]}),(0,$.jsx)(f,{size:`small`,disabled:!y.data?.has_more,onClick:()=>g(e=>e+50),children:a(`deepAssessments.next`,null,`下一页`)})]})})]}):null,p===`path`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`assessment-toolbar`,children:[(0,$.jsx)(ee,{value:b,onChange:e=>x(e||`criterion`),optionList:dn,style:{width:150}}),b===`criterion`?(0,$.jsx)(T,{value:S===``?void 0:Number(S),onChange:e=>C(e==null?``:String(e)),min:1,placeholder:`验收项序号`,style:{width:160}}):(0,$.jsx)(m,{value:S,onChange:C,placeholder:b===`asset`?`资产 ID`:`事实 ID`,style:{width:320},showClear:!0}),(0,$.jsx)(f,{size:`small`,theme:`solid`,type:`primary`,onClick:ue,loading:j.loading,children:`读取证据路径`})]}),(0,$.jsx)(z,{error:j.error,onRetry:ue}),w?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(L,{columns:3,items:[{label:`根节点`,value:w.title||w.root},{label:`节点数`,value:w.total??(w.nodes||[]).length},{label:`已折叠`,value:w.folded??0},{label:`未归属回执`,value:w.unattributed_receipts??0},{label:`相关意图`,value:w.related_intent_count??0},{label:`还有更多`,value:w.has_more?`是`:`否`}]}),(0,$.jsx)(H,{columns:[{title:`类型`,dataIndex:`kind`,width:120,render:(e,t)=>we(a,e)||t.kind},{title:`标题`,dataIndex:`title`,render:(e,t)=>(0,$.jsx)(on,{ellipsis:{showTooltip:!0},children:e||t.id})},{title:`状态`,dataIndex:`state`,width:120,render:e=>Te(a,e)},{title:`来源意图`,dataIndex:`step_id`,width:150,render:e=>e||`—`}],dataSource:w.nodes||[],rowKey:`id`,pagination:!1,size:`small`,emptyText:`证据路径为空。`}),(0,$.jsxs)(on,{type:`tertiary`,size:`small`,children:[`关联边 `,Array.isArray(w.edges)?w.edges.length:0,` 条`]}),(0,$.jsx)(U,{title:`证据路径原始数据`,value:w,collapsed:!0})]}):null]}):null,p===`history`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`assessment-toolbar`,children:[(0,$.jsx)(m,{value:F,onChange:R,placeholder:`资产 ID`,style:{width:340},showClear:!0}),(0,$.jsx)(f,{size:`small`,theme:`solid`,type:`primary`,onClick:G,loading:ie.loading,children:`读取历次测评`})]}),(0,$.jsx)(z,{error:ie.error,onRetry:G}),V?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(on,{strong:!0,children:[V.title||V.asset_id,` · 本次测评`]}),(0,$.jsx)(L,{columns:3,items:[{label:`测评`,value:V.current?.name||`—`},{label:`状态`,value:Q(a,V.current?.state)},{label:`有效观察`,value:V.current?.observed_facts??0},{label:`证据端点`,value:V.current?.observed_endpoints??0},{label:`待复核验收项`,value:(V.current?.pending_criteria||[]).join(`, `)||`—`},{label:`最近观察`,value:D(V.current?.last_observation)}]}),(0,$.jsx)(H,{columns:[{title:`较早测评`,dataIndex:`name`,render:(e,t)=>(0,$.jsx)(on,{ellipsis:{showTooltip:!0},children:e||t.task_id})},{title:`状态`,dataIndex:`state`,width:110,render:e=>Q(a,e)},{title:`有效观察`,dataIndex:`observed_facts`,width:100},{title:`证据端点`,dataIndex:`observed_endpoints`,width:100},{title:`新增观察`,dataIndex:`new_observations`,width:100},{title:`新增端点`,dataIndex:`new_endpoints`,width:100},{title:`前次有本次无`,dataIndex:`unseen_now`,width:120},{title:`可比较`,dataIndex:`comparable`,width:90,render:e=>e?`是`:`否`},{title:`创建时间`,dataIndex:`created_at`,width:170,render:e=>D(e)}],dataSource:V.prior||[],rowKey:`task_id`,pagination:!1,size:`small`,emptyText:te?`暂无可读的较早测评记录。`:`—`}),(0,$.jsx)(sn,{type:`tertiary`,className:`assessment-hint`,children:`差异基于两次已保存的证据记录;范围或项目口径不同时保留记录供人工对照。`}),(0,$.jsx)(U,{title:`历次测评原始数据`,value:V,collapsed:!0})]}):null]}):null,p===`endpoints`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`assessment-toolbar`,children:[(0,$.jsx)(m,{value:F,onChange:R,placeholder:`资产 ID`,style:{width:340},showClear:!0}),(0,$.jsx)(f,{size:`small`,theme:`solid`,type:`primary`,onClick:de,loading:ce.loading,children:`读取端点证据`})]}),(0,$.jsx)(z,{error:ce.error,onRetry:de}),W?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(L,{columns:4,items:[{label:`资产`,value:W.title||`—`},{label:`已有观察`,value:W.counts?.observed??0},{label:`待复核`,value:W.counts?.needs_review??0},{label:`缺证据`,value:W.counts?.missing??0}]}),(0,$.jsx)(H,{columns:[{title:`方法`,dataIndex:`method`,width:90},{title:`路径`,dataIndex:`path`,render:(e,t)=>(0,$.jsx)(on,{ellipsis:{showTooltip:!0},children:e||t.id})},{title:`名称`,dataIndex:`title`,width:220,render:e=>e||`—`},{title:`证据状态`,dataIndex:`status`,width:120,render:e=>(0,$.jsx)(u,{size:`small`,children:Te(a,e)})}],dataSource:W.endpoints||[],rowKey:`id`,pagination:!1,size:`small`,emptyText:`该资产暂无登记端点。`}),(0,$.jsx)(sn,{type:`tertiary`,className:`assessment-hint`,children:`端点状态来自明确关联的事实;服务级观察不会计入端点。端点关联的写入在攻击面图与漏洞复核流程中完成。`}),(0,$.jsx)(U,{title:`端点证据原始数据`,value:W,collapsed:!0})]}):null]}):null]}),(0,$.jsx)(I,{visible:!!_,onCancel:()=>v(null),title:_?`${_.tool||`回执`} · ${_.step_id||``}`:`回执详情`,width:720,footer:null,children:_?(0,$.jsxs)(`div`,{className:`assessment-drawer`,children:[(0,$.jsx)(L,{columns:2,items:[{label:a(`deepAssessments.status`,null,`状态`),value:(0,$.jsx)(oe,{status:_.status,label:Q(a,_.status)})},{label:`回执 ID`,value:_.id},{label:`来源意图`,value:_.step_id||`—`},{label:`执行 ID`,value:_.execution_id||`—`}]}),(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(on,{strong:!0,children:`调用参数`}),(0,$.jsx)(U,{title:`arguments`,value:un(_.arguments),collapsed:!1})]}),(0,$.jsxs)(`section`,{className:`assessment-section`,children:[(0,$.jsx)(on,{strong:!0,children:`调用结果`}),(0,$.jsx)(U,{title:`result`,value:un(_.result),collapsed:!0})]})]}):null})]})}function pn({id:e,task:t,reloadToken:n}){let r=O(),[i,a]=(0,q.useState)(!1),s=P(()=>A.get(`/deep-assessments/${e}/report`),[e,n]),l=typeof s.data==`string`?s.data:``,u=String(t?.name||e).replace(/[\\/:*?"<>|\s]+/g,`_`).slice(0,60)||e;return(0,$.jsx)(`div`,{className:`assessment-tab`,children:(0,$.jsxs)(B,{title:r(`deepAssessments.reportTitle`,null,`测评报告`),description:r(`deepAssessments.coverage.reportDescription`),extra:(0,$.jsxs)(c,{children:[(0,$.jsx)(V,{text:l,label:`复制 Markdown`}),(0,$.jsx)(f,{size:`small`,onClick:()=>s.reload(),loading:s.loading,children:`刷新`}),(0,$.jsx)(f,{size:`small`,theme:`solid`,type:`primary`,onClick:async()=>{a(!0);try{let t=await j(`/deep-assessments/${e}/report`,{filename:`assessment-${u}.md`});W(`已下载 ${t}`)}catch(e){F(e,`下载失败`)}finally{a(!1)}},loading:i,disabled:!l,children:r(`deepAssessments.report`,null,`下载报告`)})]}),children:[(0,$.jsx)(z,{error:s.error,onRetry:()=>s.reload()}),l?(0,$.jsx)(`div`,{className:`assessment-report`,children:(0,$.jsx)(R,{content:l})}):s.loading?null:(0,$.jsx)(o,{title:`报告为空`,description:`开始测评并保存进展后可生成报告。`,style:{padding:40}})]})})}function mn({id:e}){let[t,n]=(0,q.useState)(!1),[r,i]=(0,q.useState)(``),[a,o]=(0,q.useState)([]),[c,l]=(0,q.useState)(!1),[u,d]=(0,q.useState)(null),m=(0,q.useRef)(null),h=(0,q.useRef)(null);(0,q.useEffect)(()=>()=>m.current?.abort(),[]),(0,q.useEffect)(()=>{t&&a.length&&h.current?.scrollIntoView({block:`nearest`})},[t,a]);let g=async()=>{let t=r.trim();if(!t||m.current)return;let n=new AbortController;m.current=n,l(!0),d(null);try{let r=a.slice(-3).map(e=>({question:e.question.slice(0,600),answer:e.answer.slice(0,1e3)})),s=await A.post(`/deep-assessments/${encodeURIComponent(e)}/question`,{question:t,history:r},{signal:n.signal,timeout:95e3});o(e=>[...e,{question:t,answer:s.answer,updated:s.updated_at}]),i(``)}catch(e){n.signal.aborted||d(e)}finally{m.current=null,l(!1)}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(f,{onClick:()=>n(!0),children:`测评问答`}),(0,$.jsxs)(I,{visible:t,title:`测评问答`,onCancel:()=>n(!1),width:540,footer:(0,$.jsxs)(`form`,{className:`assessment-question-form`,onSubmit:e=>{e.preventDefault(),e.currentTarget.elements.namedItem(`question`)?.focus(),g()},children:[(0,$.jsx)(p,{name:`question`,"aria-label":`询问测评进展`,placeholder:`当前在做什么?有哪些方向正在等待处理?`,rows:3,maxLength:2e3,value:r,onChange:i,readOnly:c}),(0,$.jsx)(f,{htmlType:`submit`,theme:`solid`,loading:c,disabled:c||!r.trim(),children:`发送`})]}),children:[(0,$.jsx)(s.Paragraph,{type:`tertiary`,children:`只读问答。模型根据提问时的测评记录回答,离开本次测评页面后清空对话。`}),(0,$.jsxs)(`div`,{role:`log`,"aria-label":`问答记录`,"aria-live":`polite`,children:[a.map((e,t)=>(0,$.jsxs)(`section`,{className:`assessment-question-turn`,ref:t===a.length-1?h:void 0,children:[(0,$.jsx)(s.Text,{strong:!0,children:`你`}),(0,$.jsx)(`p`,{children:e.question}),(0,$.jsx)(s.Text,{strong:!0,children:`模型`}),(0,$.jsx)(`p`,{children:e.answer}),(0,$.jsxs)(s.Text,{size:`small`,type:`tertiary`,children:[`任务更新于 `,D(e.updated)]})]},t)),c?(0,$.jsx)(s.Text,{type:`tertiary`,children:`正在读取进展并生成回答…`}):null]}),(0,$.jsx)(z,{error:u,onRetry:g})]})]})}var{Text:hn}=s,gn=[{key:`overview`,i18n:`deepAssessments.overview`,fallback:`概览`},{key:`intents`,i18n:`deepAssessments.intents`,fallback:`意图`},{key:`facts`,i18n:`deepAssessments.facts`,fallback:`事实`},{key:`assets`,i18n:`deepAssessments.attackSurfaceGraph`,fallback:`攻击面图`,permission:`asset:read`},{key:`graph`,i18n:`deepAssessments.graph`,fallback:`图谱`},{key:`findings`,i18n:`deepAssessments.findings`,fallback:`漏洞`,permission:`vulnerability:read`},{key:`acceptance`,i18n:`deepAssessments.acceptance`,fallback:`验收`},{key:`evidence`,i18n:`deepAssessments.evidence`,fallback:`证据`},{key:`report`,i18n:`deepAssessments.reportTab`,fallback:`报告`}];function _n({id:e,tab:t,criterion:n,evidencePath:r,evidenceStepId:i,evidenceFactId:o,observation:s,onTabChange:u,onBack:d,onDeleted:m}){let h=O(),{hasPermission:_}=k(),v=P(()=>A.get(`/deep-assessments/${e}`),[e]),y=v.data?.task||null,b=y?.name?.trim(),x=y?.objective?.trim(),S=x===b||b?.length>1&&b.endsWith(`…`)&&x?.startsWith(b.slice(0,-1)),[C,T]=(0,q.useState)([]),[ee,j]=(0,q.useState)(null),[N,L]=(0,q.useState)(!0),[R,te]=(0,q.useState)(``),[B,ne]=(0,q.useState)(0),[V,H]=(0,q.useState)(``),[ae,U]=(0,q.useState)(``),[ce,le]=(0,q.useState)(``),ue=ae===`answer`?`答复并继续`:`补充线索或调整方向`,G=(0,q.useRef)(0),de=(0,q.useRef)(!1),K=_(Se),fe=_(Ce),pe=_(`agent:execute`),me=(0,q.useMemo)(()=>gn.filter(e=>!e.permission||_(e.permission)),[_]),J=me.some(e=>e.key===t)?t:`overview`,Y=(0,q.useCallback)(async(t=!1)=>{if((t||!de.current)&&(t||!document.hidden&&N)){de.current=!0;try{let n=await A.get(`/deep-assessments/${e}/events`,t?{latest:`true`}:{after:G.current}),r=Array.isArray(n?.events)?n.events:[];t?(T(r),G.current=r.length&&Number(r[r.length-1].id)||0):r.length&&(T(e=>[...e,...r].slice(-500)),G.current=Number(r[r.length-1].id)||G.current),j(null)}catch(e){t&&j(e)}finally{de.current=!1}}},[e,N]);(0,q.useEffect)(()=>(G.current=0,T([]),j(null),Y(!0),()=>{G.current=0}),[e]),(0,q.useEffect)(()=>{J===`overview`&&Y(!1)},[J]),ie(()=>{document.hidden||(Y(!1),R||v.reload({silent:!0}))},J===`overview`&&N?1e4:0);let X=async()=>{await v.reload(),ne(e=>e+1),Y(!0)},Z=async(t,n={})=>{if(y&&K){te(t);try{let r=await A.post(`/deep-assessments/${e}/control/${t}`,{revision:y.revision,...n});r?.task&&v.setData(e=>({...e,task:r.task})),r?.start_error?M(r.start_error):W(h(`deepAssessments.updated`,null,`已更新`)),ne(e=>e+1),Y(!0),v.reload({silent:!0})}catch(e){F(e,h(`deepAssessments.controlFailed`,null,`操作失败`)),v.reload()}finally{te(``)}}},he=async()=>{if(!y)return;let t=ce.trim();if(!t)M(`请填写补充内容`);else{te(`message`);try{let n=await A.post(`/deep-assessments/${e}/control/${ae}`,{revision:y.revision,message:t});n?.task&&v.setData(e=>({...e,task:n.task})),n?.start_error?M(n.start_error):W(ae===`answer`?`已答复并继续`:`已提交方向`),U(``),le(``),ne(e=>e+1),Y(!0),v.reload({silent:!0})}catch(e){F(e,`提交失败`)}finally{te(``)}}},ge=[y&&pe?(0,$.jsx)(mn,{id:e},e):null,(0,$.jsx)(f,{theme:`borderless`,onClick:d,children:`返回列表`},`back`),(0,$.jsx)(f,{icon:(0,$.jsx)(w,{}),onClick:X,loading:v.loading&&!R,children:`刷新`},`refresh`),(0,$.jsx)(f,{theme:`solid`,type:`primary`,disabled:!K||!pe||!!R||!Me(y),loading:R===`start`,onClick:()=>Z(`start`),children:h(`deepAssessments.start`,null,`开始 / 继续`)},`start`),(0,$.jsx)(f,{disabled:!K||!!R||!Ne(y),loading:R===`pause`,onClick:()=>Z(`pause`),children:h(`deepAssessments.pause`,null,`暂停`)},`pause`),(0,$.jsx)(f,{type:`danger`,disabled:!K||!!R||!Pe(y),loading:R===`cancel`,onClick:()=>Z(`cancel`),children:h(`deepAssessments.cancel`,null,`停止`)},`cancel`),Fe(y)?(0,$.jsx)(f,{disabled:!K||!pe||!!R,loading:R===`continue-stopped`,onClick:()=>Z(`continue-stopped`),children:`继续测评`},`continue`):null,(0,$.jsx)(f,{disabled:!K||!!R||(y?.archived?!Le(y):!Ie(y)),loading:R===`archive`||R===`restore`,onClick:()=>Z(y?.archived?`restore`:`archive`),children:y?.archived?`恢复到列表`:`归档`},`archive`),(0,$.jsx)(f,{type:`danger`,theme:`borderless`,icon:(0,$.jsx)(l,{}),disabled:!fe||!!R||!Re(y),onClick:()=>{y&&se({title:h(`deepAssessments.delete`,null,`删除`),content:`删除本条测评?关联执行会话仍保留。`,okText:h(`deepAssessments.delete`,null,`删除`),onOk:async()=>{try{await A.del(`/deep-assessments/${e}`),W(h(`deepAssessments.deleted`,null,`已删除`)),m?.()}catch(e){F(e,`删除失败`)}}})},children:h(`deepAssessments.delete`,null,`删除`)},`delete`)];return(0,$.jsxs)(`div`,{className:`assessment-page`,children:[(0,$.jsx)(re,{title:b||h(`deepAssessments.title`,null,`深度测评`),description:x&&!S?Ve(x,160):null,extra:ge,children:(0,$.jsxs)(c,{spacing:8,wrap:!0,className:`assessment-meta`,children:[y?(0,$.jsx)(oe,{status:y.status,label:Q(h,y.status)}):null,y?.archived?(0,$.jsx)(oe,{status:`archived`,label:Q(h,`archived`)}):null,y&&je(y)?(0,$.jsx)(oe,{status:`needs_review`,label:Q(h,`needs_review`)}):null,y?(0,$.jsxs)(hn,{type:`tertiary`,children:[`模型 `,v.data?.model_channel_name||y.model||`系统默认`]}):null,y?.role?(0,$.jsxs)(hn,{type:`tertiary`,children:[`角色 `,y.role]}):null,y?(0,$.jsxs)(hn,{type:`tertiary`,children:[`规划轮次 `,E(y.rounds||0)]}):null,y?(0,$.jsxs)(hn,{type:`tertiary`,children:[`累计 Token `,E(y.tokens_used||0)]}):null,y?.created_at?(0,$.jsxs)(hn,{type:`tertiary`,children:[`创建于 `,D(y.created_at)]}):null]})}),(0,$.jsx)(z,{error:v.error,onRetry:X}),y?.archived?(0,$.jsx)(a,{type:`info`,bordered:!0,closeIcon:null,description:`测评已归档。恢复到列表后才能继续控制、关联资产或补充方向。`}):null,y?.status===`blocked`?(0,$.jsx)(a,{type:`danger`,bordered:!0,closeIcon:null,className:`assessment-banner`,description:y.summary||`测评受阻,请查看运行记录定位原因;排除后可手动继续。`,children:(0,$.jsx)(f,{size:`small`,onClick:()=>u?.(`overview`),children:`查看运行记录`})}):null,y?.question?(0,$.jsx)(a,{type:`warning`,bordered:!0,closeIcon:null,className:`assessment-banner`,description:`执行需要人工确认:${y.question}`,children:(0,$.jsx)(f,{size:`small`,theme:`solid`,type:`primary`,disabled:!K||!pe,onClick:()=>{U(`answer`),le(``)},children:`答复并继续`})}):null,y&&!y.archived&&je(y)?(0,$.jsx)(a,{type:`warning`,bordered:!0,closeIcon:null,className:`assessment-banner`,description:`有结果不明的工具调用待核对(${y.review_count||(y.steps||[]).filter(e=>[`uncertain`,`cleanup_unconfirmed`].includes(e.status)).length} 项)。核对只更新记录,不会自动执行。`,children:(0,$.jsx)(f,{size:`small`,onClick:()=>{H(`uncertain`),u?.(`intents`)},children:`处理待核对`})}):null,(0,$.jsx)(g,{type:`line`,activeKey:J,onChange:e=>u?.(e),tabList:me.map(e=>({itemKey:e.key,tab:h(e.i18n,null,e.fallback)})),className:`assessment-tabs`,children:y?J===`overview`?(0,$.jsx)(dt,{task:y,reloadToken:B,canWrite:K&&pe,events:C,eventsError:ee,autoRefresh:N,onAutoRefreshChange:L,onRefreshEvents:()=>Y(!0),onGoTab:u,onGuidance:()=>{U(`guidance`),le(``)},onAnswer:()=>{U(`answer`),le(``)}}):J===`intents`?(0,$.jsx)(ht,{id:e,reloadToken:B,status:V,onStatusChange:H,archived:!!y.archived,taskStatus:y.status,revision:y.revision,onChanged:()=>{ne(e=>e+1),v.reload({silent:!0})}}):J===`facts`?(0,$.jsx)(vt,{id:e,reloadToken:B,task:y}):J===`assets`?(0,$.jsx)(Ot,{id:e,task:y,observation:s,reloadToken:B}):J===`graph`?(0,$.jsx)(Yt,{id:e,task:y,reloadToken:B,onGoIntents:()=>u?.(`intents`),autoRefresh:N,onAutoRefreshChange:L,onRefreshTask:v.reload,refreshPaused:!!R||v.loading}):J===`findings`?(0,$.jsx)($t,{id:e,task:y,reloadToken:B}):J===`acceptance`?(0,$.jsx)(an,{id:e,criterion:n,canWrite:K&&!y.archived,reloadToken:B}):J===`evidence`?(0,$.jsx)(fn,{id:e,criterion:r?n:0,factId:o,stepId:i,reloadToken:B},`${r}-${n}-${i}-${o}`):(0,$.jsx)(pn,{id:e,task:y,reloadToken:B}):null}),!y&&v.loading?(0,$.jsx)(`div`,{className:`assessment-loading`,children:`正在读取测评…`}):null,(0,$.jsxs)(I,{visible:!!ae,title:ue,"aria-label":ue,onCancel:()=>U(``),width:560,closable:R!==`message`,closeOnEsc:R!==`message`,maskClosable:R!==`message`,footer:(0,$.jsxs)(`div`,{className:`assessment-form-actions`,children:[(0,$.jsx)(f,{onClick:()=>U(``),disabled:R===`message`,children:`取消`}),(0,$.jsx)(f,{theme:`solid`,onClick:he,loading:R===`message`,disabled:R===`message`,children:`提交`})]}),children:[(0,$.jsx)(`p`,{className:`assessment-hint`,children:ae===`answer`?`答复会保存到人工补充并清除待答复状态,随后自动继续测评。`:`当前执行账号可以在测评运行时提交补充,下一轮规划会读取。`}),(0,$.jsx)(p,{value:ce,onChange:le,rows:5,maxLength:8e3,placeholder:`例如:优先验证登录接口的越权风险,并附上原始请求回执。`})]})]})}function vn(){let e=O(),{hasPermission:t}=k(),[n,r]=i(),a=n.get(`id`)||n.get(`assessment_id`)||``,s=n.get(`tab`)||`overview`,c=s===`evidence-path`?`evidence`:s,l=(0,q.useCallback)(e=>{let t=new URLSearchParams;t.set(`id`,e),t.set(`tab`,`overview`),r(t)},[r]),u=(0,q.useCallback)(e=>{let t=new URLSearchParams;t.set(`id`,a),t.set(`tab`,e),r(t,{replace:!0})},[a,r]),d=(0,q.useCallback)(()=>{r(new URLSearchParams,{replace:!1})},[r]);return t(`assessments:read`)?a?(0,$.jsx)(_n,{id:a,tab:c,criterion:Number(n.get(`criterion`))||0,evidencePath:s===`evidence-path`,evidenceStepId:n.get(`step_id`)||``,evidenceFactId:s===`evidence-path`&&n.get(`fact_id`)||``,observation:n.get(`observation`)||``,onTabChange:u,onBack:d,onDeleted:d},a):(0,$.jsx)(et,{onOpen:l}):(0,$.jsx)(`div`,{className:`assessment-page`,children:(0,$.jsx)(o,{title:e(`common.forbidden`,null,`当前账号没有访问该页面的权限`),description:`深度测评需要 assessments:read 权限,请联系管理员分配。`,style:{padding:64}})})}export{vn as default}; \ No newline at end of file diff --git a/web/static/app/assets/hitl-CuqgPh-B.js b/web/static/app/assets/hitl-hVYHftcD.js similarity index 99% rename from web/static/app/assets/hitl-CuqgPh-B.js rename to web/static/app/assets/hitl-hVYHftcD.js index b181246f..573e2b3e 100644 --- a/web/static/app/assets/hitl-CuqgPh-B.js +++ b/web/static/app/assets/hitl-hVYHftcD.js @@ -1,4 +1,4 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{B as i,E as a,G as o,I as s,N as c,R as l,S as u,U as d,V as f,W as p,c as m,h,lt as g,m as _,p as v,ut as y,v as b,y as x}from"./semi-65W_4I1v.js";import{E as S,F as C,I as w,L as T,S as E,a as D,b as O,d as k,l as A,m as j,n as ee,o as M,p as N,s as P,u as F,x as I,y as L}from"./index-CAEPLS-g.js";var R=e(t(),1),z=[{value:`off`,label:`关闭`,hint:`不拦截工具调用`},{value:`approval`,label:`审批模式`,hint:`只裁决通过/拒绝`},{value:`review_edit`,label:`审查编辑模式`,hint:`可收窄参数后放行`}],te={approve:`通过`,reject:`拒绝`},B={approve:`green`,reject:`red`},V={human:`人工`,audit_agent:`审计 Agent`,system:`系统`,manual:`手动录入`};function H(e){let t=String(e||``).trim().toLowerCase().replace(/-/g,`_`);return t===`feedback`||t===`followup`?`approval`:[`off`,`approval`,`review_edit`].includes(t)?t:`off`}function U(e){let t=H(e),n=z.find(e=>e.value===t);return n?n.label:t}function W(e){let t=String(e||``).trim().toLowerCase();return t===`audit_agent`||t===`agent`||t===`ai`?`audit_agent`:`human`}function G(e){return W(e)===`audit_agent`?`审计 Agent`:`人工审批`}function K(e){let t=String(e||``).trim().toLowerCase();return te[t]||t||`—`}function q(e){return B[String(e||``).toLowerCase()]||`grey`}function ne(e){return V[String(e||``).trim().toLowerCase()]||e||`—`}function re(e){let t=String(e||``).trim().toLowerCase();return t===`pending`?`待审批`:t===`decided`?`已裁决`:t===`timeout`?`超时自动拒绝`:t===`cancelled`?`已取消`:e||`—`}function J(e){if(!e)return{};if(typeof e==`object`)return e;try{let t=JSON.parse(String(e));return t&&typeof t==`object`?t:{}}catch{return{}}}function ie(e){if(!e||typeof e!=`object`)return null;if(e.argumentsObj&&typeof e.argumentsObj==`object`)return e.argumentsObj;if(typeof e.arguments==`string`&&e.arguments.trim())try{let t=JSON.parse(e.arguments);if(t&&typeof t==`object`)return t}catch{return{raw:e.arguments}}return e.arguments&&typeof e.arguments==`object`?e.arguments:null}function ae(e){return!e||typeof e!=`object`?[]:[{key:`userMessage`,label:`用户消息`,value:e.userMessage},{key:`thinking`,label:`思考`,value:e.thinking},{key:`reasoningChain`,label:`推理链`,value:e.reasoningChain},{key:`planning`,label:`计划`,value:e.planning}].filter(e=>String(e.value||``).trim())}function oe(e){let t=e?.executionResult;if(!t||typeof t!=`object`)return null;let n=String(t.result||``).trim();return n?{success:t.success===!0,text:n}:null}function se(e){let t=e?.hitlApproval;if(!t||typeof t!=`object`)return``;let n=Number(t.timeoutSeconds)||0;if(n<=0)return`无超时限制`;let r=t.expiresAt?new Date(t.expiresAt):null;return r&&Number.isFinite(r.getTime())?r.getTime()<=Date.now()?`已于 ${S(r)} 到期`:`${S(r)} 截止`:`${n} 秒内需裁决`}function Y(e){return e?S(e):`—`}function ce(e){return String(e||``).split(/[\n,,;;]/).map(e=>e.trim()).filter(Boolean).filter((e,t,n)=>n.indexOf(e)===t)}function X(e){let t=[];return e?.userMessage&&t.push(`用户消息`),e?.thinking&&t.push(`思考`),e?.executionResult&&t.push(`执行结果`),t.length?t.join(` · `):`—`}var Z=e(n(),1);function Q({payload:e}){let t=ae(e),n=oe(e);return!t.length&&!n?null:(0,Z.jsxs)(`div`,{className:`hitl-context-blocks`,children:[t.map(e=>(0,Z.jsxs)(`div`,{className:`hitl-context-block`,children:[(0,Z.jsx)(`span`,{className:`hitl-context-label`,children:e.label}),(0,Z.jsx)(`pre`,{className:`hitl-context-text`,children:String(e.value)})]},e.key)),n&&(0,Z.jsxs)(`div`,{className:`hitl-context-block ${n.success?`hitl-state-success`:`hitl-state-failed`}`,children:[(0,Z.jsx)(`span`,{className:`hitl-context-label`,children:`执行结果(${n.success?`成功`:`失败`})`}),(0,Z.jsx)(`pre`,{className:`hitl-context-text`,children:n.text})]})]})}var{Text:le}=o;function ue({item:e,canWrite:t,onDone:n}){let r=(0,R.useMemo)(()=>J(e.payload),[e.payload]),i=(0,R.useMemo)(()=>ie(r),[r]),a=H(e.mode)===`review_edit`,o=W(e.reviewer),[f,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(()=>a&&i?JSON.stringify(i,null,2):``),[g,_]=(0,R.useState)(``),[v,y]=(0,R.useState)(``),b=(0,R.useCallback)(async t=>{if(g)return;let r;if(a&&m.trim()){try{r=JSON.parse(m)}catch(e){y(`修改后的参数不是合法 JSON:${e.message}`);return}if(!r||typeof r!=`object`||Array.isArray(r)){y(`修改后的参数必须是 JSON 对象`);return}}y(``),_(t);try{await T.post(`/hitl/decision`,{interruptId:e.id,decision:t,comment:f.trim(),editedArguments:r}),I(t===`approve`?`已通过,工具将继续执行`:`已拒绝本次工具调用`),n?.()}catch(t){if(t?.status===409){await T.post(`/hitl/dismiss`,{interruptId:e.id}).catch(()=>null),E(`该审批已被处理,列表已刷新`),n?.();return}O(t,`提交审批失败`)}finally{_(``)}},[a,m,g,f,e.id,n]),x=(0,R.useCallback)(()=>{L({title:`忽略该审批`,content:`忽略后该审批记为取消(reject),本次工具调用不会继续执行,记录可在审批日志中查看。`,okText:`忽略`,onOk:async()=>{try{await T.post(`/hitl/dismiss`,{interruptId:e.id}),I(`已忽略该审批`),n?.()}catch(e){O(e,`忽略审批失败`)}}})},[e.id,n]);return(0,Z.jsxs)(`div`,{className:`hitl-pending-card`,children:[(0,Z.jsxs)(`div`,{className:`hitl-pending-head`,children:[(0,Z.jsxs)(s,{spacing:6,wrap:!0,children:[(0,Z.jsx)(c,{size:`small`,color:`blue`,shape:`square`,children:e.toolName||`—`}),(0,Z.jsx)(c,{size:`small`,color:a?`violet`:`grey`,children:U(e.mode)}),(0,Z.jsx)(c,{size:`small`,color:o===`audit_agent`?`green`:`grey`,children:G(e.reviewer)})]}),(0,Z.jsxs)(s,{spacing:6,children:[(0,Z.jsx)(le,{type:`tertiary`,size:`small`,children:Y(e.createdAt)}),(0,Z.jsx)(l,{size:`small`,theme:`borderless`,disabled:!t||!!g,onClick:x,children:`忽略`})]})]}),(0,Z.jsxs)(`div`,{className:`hitl-pending-meta`,children:[(0,Z.jsx)(`span`,{className:`hitl-pending-meta-label`,children:`会话`}),(0,Z.jsx)(`span`,{className:`hitl-mono`,children:e.conversationId||`—`}),e.conversationId&&(0,Z.jsx)(M,{text:e.conversationId,size:`small`}),(0,Z.jsx)(`span`,{className:`hitl-pending-deadline`,children:se(r)})]}),(0,Z.jsx)(Q,{payload:r}),i&&(0,Z.jsx)(F,{title:`请求参数`,value:i,collapsed:!0}),(0,Z.jsxs)(`div`,{className:`hitl-pending-editor`,children:[(0,Z.jsx)(`span`,{className:`hitl-context-label`,children:a?`修改后的参数(可编辑,留空表示沿用原参数)`:`审批模式:仅可通过/拒绝,参数编辑已禁用`}),(0,Z.jsx)(u,{rows:a?6:3,value:a?m:i?JSON.stringify(i,null,2):``,disabled:!a,spellCheck:!1,className:`hitl-args-textarea`,onChange:e=>{h(e),v&&y(``)}})]}),v&&(0,Z.jsx)(`div`,{className:`hitl-inline-error`,children:v}),(0,Z.jsx)(d,{value:f,placeholder:`审批备注(可选),例如:只读命令,允许执行`,onChange:e=>p(e)}),(0,Z.jsxs)(`div`,{className:`hitl-pending-actions`,children:[(0,Z.jsx)(l,{type:`danger`,theme:`light`,disabled:!t||!!g,loading:g===`reject`,onClick:()=>b(`reject`),children:`拒绝`}),(0,Z.jsx)(l,{theme:`solid`,disabled:!t||!!g,loading:g===`approve`,onClick:()=>b(`approve`),children:a&&m.trim()&&m.trim()!==(i?JSON.stringify(i,null,2):``)?`保存修改并放行`:`通过`})]}),(0,Z.jsx)(F,{title:`完整载荷`,value:r,collapsed:!0})]})}function de({canWrite:e,onCountChange:t,refreshKey:n=0}){let r=C(),[i,o]=(0,R.useState)(1),[s,c]=(0,R.useState)(20),[l,u]=(0,R.useState)(``),f=ee(l,350),m=D(()=>T.get(`/hitl/pending`,{page:i,pageSize:s,q:f}),[i,s,f,n]),h=m.data?.items||[],g=Number(m.data?.total)||0;(0,R.useEffect)(()=>{t?.(g)},[t,g]);let _=(0,R.useCallback)(e=>{c(e),o(1)},[]);return(0,Z.jsxs)(`div`,{className:`hitl-pending-panel`,children:[(0,Z.jsxs)(`div`,{className:`hitl-panel-toolbar`,children:[(0,Z.jsx)(d,{showClear:!0,value:l,style:{width:300},placeholder:r(`hitl.searchPlaceholder`,null,`搜索工具、会话或载荷…`),onChange:e=>{u(e),o(1)}}),(0,Z.jsxs)(le,{type:`tertiary`,size:`small`,children:[r(`hitl.pendingTitle`,null,`待审批请求`),` · `,g]})]}),(0,Z.jsx)(A,{error:m.error,onRetry:()=>m.reload()}),m.loading&&!h.length&&(0,Z.jsx)(`div`,{className:`hitl-panel-loading`,children:(0,Z.jsx)(p,{})}),!m.loading&&!h.length&&!m.error&&(0,Z.jsx)(a,{title:r(`hitl.emptyState`,null,`暂无待审批请求`),description:`工具调用命中敏感规则时会在此等待裁决。`,style:{padding:48}}),(0,Z.jsx)(`div`,{className:`hitl-pending-list`,children:h.map(t=>(0,Z.jsx)(ue,{item:t,canWrite:e,onDone:()=>{h.length<=1&&i>1?o(i-1):m.reload()}},t.id))}),g>0&&(0,Z.jsx)(`div`,{className:`hitl-panel-pagination`,children:(0,Z.jsx)(b,{currentPage:i,pageSize:s,total:g,showSizeChanger:!0,pageSizeOpts:[10,20,50],showTotal:!0,onPageChange:e=>o(e),onPageSizeChange:_})})]})}var{Text:fe}=o;function pe({logId:e,onClose:t}){let n=C(),{data:r,loading:i,error:a,reload:o}=D(()=>T.get(`/hitl/logs/${encodeURIComponent(e)}`),[e],{skip:!e}),u=(0,R.useMemo)(()=>J(r?.payload),[r?.payload]),d=[r?.auditBackend,r?.auditModel].filter(Boolean).join(` · `);return(0,Z.jsxs)(v,{visible:!!e,onCancel:t,width:720,title:n(`hitl.logModalView`,null,`审批日志详情`),footer:(0,Z.jsx)(l,{onClick:t,children:n(`common.close`,null,`关闭`)}),children:[(0,Z.jsx)(A,{error:a,onRetry:o}),i&&!r&&(0,Z.jsx)(`div`,{className:`hitl-panel-loading`,children:(0,Z.jsx)(p,{})}),r&&(0,Z.jsxs)(`div`,{className:`hitl-log-detail`,children:[(0,Z.jsx)(k,{columns:2,items:[{label:n(`hitl.colTool`,null,`工具`),value:(0,Z.jsx)(fe,{strong:!0,children:r.toolName||`—`})},{label:n(`hitl.colDecision`,null,`决策`),value:(0,Z.jsx)(c,{size:`small`,color:q(r.decision),children:K(r.decision)})},{label:`状态`,value:re(r.status)},{label:n(`hitl.colDecidedBy`,null,`审批方`),value:ne(r.decidedBy)},{label:`审批方类型`,value:G(r.reviewer)},{label:`审批引擎`,value:d||`—`},{label:n(`hitl.colConversation`,null,`会话`),value:r.conversationId?(0,Z.jsxs)(s,{spacing:4,children:[(0,Z.jsx)(`span`,{className:`hitl-mono`,children:r.conversationId}),(0,Z.jsx)(M,{text:r.conversationId,size:`small`})]}):`—`},{label:`模式`,value:r.mode||`—`},{label:`创建时间`,value:Y(r.createdAt)},{label:`裁决时间`,value:Y(r.decidedAt)},{label:`ID`,value:(0,Z.jsx)(`span`,{className:`hitl-mono`,children:r.id})},{label:n(`hitl.fieldComment`,null,`备注`),value:r.comment||`—`}]}),(0,Z.jsx)(Q,{payload:u}),(0,Z.jsx)(F,{title:n(`hitl.fieldPayload`,null,`载荷`),value:u,collapsed:!0})]})]})}function me({canWrite:e,detailId:t,onOpenDetail:n,onCloseDetail:r,refreshKey:i=0}){let a=C(),[o,u]=(0,R.useState)(1),[f,p]=(0,R.useState)(20),[m,h]=(0,R.useState)(``),g=ee(m,350),[_,v]=(0,R.useState)(`all`),[b,S]=(0,R.useState)(`all`),[w,E]=(0,R.useState)([]),k=(0,R.useMemo)(()=>({q:g,decision:_===`all`?``:_,decidedBy:b===`all`?``:b}),[g,_,b]),j=D(()=>T.get(`/hitl/logs`,{page:o,pageSize:f,...k}),[o,f,k,i]),M=j.data?.items||[],N=Number(j.data?.total)||0,F=Number(j.data?.retentionDays)||0,z=(0,R.useCallback)(()=>j.reload(),[j.reload]),te=(0,R.useCallback)(()=>{w.length&&L({title:`批量删除审批日志`,content:`确定删除选中的 ${w.length} 条审批日志?此操作不可恢复。`,okText:a(`common.delete`,null,`删除`),onOk:async()=>{try{await T.del(`/hitl/logs`,{body:{ids:w}}),I(`已删除 ${w.length} 条审批日志`),E([]),z()}catch(e){O(e,`批量删除审批日志失败`)}}})},[z,w,a]),B=(0,R.useCallback)(()=>{L({title:a(`hitl.clearAll`,null,`清空审计日志`),content:g||_!==`all`||b!==`all`?`将清空当前筛选条件下的全部已裁决日志(不会删除待审批项)。`:`将清空全部已裁决审批日志(不会删除待审批项)。`,okText:a(`hitl.clearAll`,null,`清空`),onOk:async()=>{try{await T.del(`/hitl/logs`,{query:k,body:{all:!0}}),I(`审批日志已清空`),E([]),u(1),z()}catch(e){O(e,`清空审批日志失败`)}}})},[b,_,g,k,z,a]),V=[{title:a(`hitl.colTool`,null,`工具`),dataIndex:`toolName`,width:220,ellipsis:!0,render:e=>(0,Z.jsx)(`span`,{className:`hitl-mono hitl-ellipsis`,title:e||``,children:e||`—`})},{title:a(`hitl.colConversation`,null,`会话`),dataIndex:`conversationId`,width:200,render:e=>(0,Z.jsx)(`span`,{className:`hitl-mono hitl-ellipsis`,title:e||``,children:e||`—`})},{title:a(`hitl.colDecision`,null,`决策`),dataIndex:`decision`,width:100,render:e=>(0,Z.jsx)(c,{size:`small`,color:q(e),children:K(e)})},{title:a(`hitl.colDecidedBy`,null,`审批方`),dataIndex:`decidedBy`,width:140,render:(e,t)=>(0,Z.jsxs)(`div`,{className:`hitl-log-by`,children:[(0,Z.jsx)(`span`,{children:ne(e)}),t.auditBackend&&(0,Z.jsx)(`span`,{className:`hitl-log-engine`,children:[t.auditBackend,t.auditModel].filter(Boolean).join(` · `)})]})},{title:`备注`,dataIndex:`comment`,render:(e,t)=>(0,Z.jsx)(`span`,{title:e||``,children:e||X(J(t.payload))})},{title:a(`hitl.colTime`,null,`时间`),dataIndex:`decidedAt`,width:180,render:(e,t)=>Y(e||t.createdAt)},{title:a(`common.actions`,null,`操作`),dataIndex:`id`,width:90,render:e=>(0,Z.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>n(e),children:a(`common.view`,null,`详情`)})}],H={currentPage:o,pageSize:f,total:N,showSizeChanger:!0,pageSizeOpts:[20,50,100],showTotal:!0,onPageChange:e=>u(e),onPageSizeChange:e=>{p(e),u(1)}};return(0,Z.jsxs)(`div`,{className:`hitl-logs-panel`,children:[F>0&&(0,Z.jsx)(`p`,{className:`hitl-retention-hint`,children:a(`hitl.retentionHint`,{days:F},`审批日志保留 ${F} 天,到期自动清理。`)}),(0,Z.jsx)(A,{error:j.error,onRetry:z}),(0,Z.jsx)(P,{columns:V,dataSource:M,rowKey:`id`,loading:j.loading,pagination:H,size:`small`,scroll:{x:1280},emptyText:a(`hitl.logsEmpty`,null,`暂无审批日志`),rowSelection:{selectedRowKeys:w,onChange:e=>E(e||[])},toolbar:(0,Z.jsxs)(s,{spacing:8,wrap:!0,children:[(0,Z.jsx)(d,{showClear:!0,style:{width:220},value:m,placeholder:a(`hitl.searchPlaceholder`,null,`搜索工具、会话或载荷…`),onChange:e=>{h(e),u(1)}}),(0,Z.jsx)(x,{value:_,style:{width:120},optionList:[{value:`all`,label:a(`hitl.filterAll`,null,`全部`)},{value:`approve`,label:a(`hitl.decisionApprove`,null,`通过`)},{value:`reject`,label:a(`hitl.decisionReject`,null,`拒绝`)}],onChange:e=>{v(e),u(1)}}),(0,Z.jsx)(x,{value:b,style:{width:150},optionList:[{value:`all`,label:a(`hitl.filterAll`,null,`全部`)},{value:`human`,label:a(`hitl.reviewerHuman`,null,`人工`)},{value:`audit_agent`,label:a(`hitl.reviewerAgent`,null,`审计 Agent`)},{value:`system`,label:a(`hitl.reviewerSystem`,null,`系统`)},{value:`manual`,label:a(`hitl.reviewerManual`,null,`手动录入`)}],onChange:e=>{S(e),u(1)}}),(0,Z.jsx)(l,{icon:(0,Z.jsx)(y,{}),theme:`borderless`,size:`small`,onClick:z,loading:j.loading,children:a(`common.refresh`,null,`刷新`)}),(0,Z.jsxs)(l,{size:`small`,type:`danger`,theme:`borderless`,disabled:!e||!w.length,onClick:te,children:[`批量删除`,w.length?`(${w.length})`:``]}),(0,Z.jsx)(l,{size:`small`,type:`danger`,theme:`borderless`,disabled:!e||!N,onClick:B,children:a(`hitl.clearAll`,null,`清空`)})]})}),(0,Z.jsx)(pe,{logId:t,onClose:r})]})}var{Text:he}=o;function ge({canWrite:e,refreshKey:t=0}){let n=C(),{data:r,loading:i,error:a,reload:o}=D(()=>T.get(`/hitl/tool-whitelist`),[t]),[d,f]=(0,R.useState)(``),[p,m]=(0,R.useState)(``);(0,R.useEffect)(()=>{r&&f((r.toolWhitelist||[]).join(` +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{B as i,E as a,G as o,I as s,N as c,R as l,S as u,U as d,V as f,W as p,c as m,h,lt as g,m as _,p as v,ut as y,v as b,y as x}from"./semi-65W_4I1v.js";import{E as S,F as C,I as w,L as T,S as E,a as D,b as O,d as k,l as A,m as j,n as ee,o as M,p as N,s as P,u as F,x as I,y as L}from"./index-DNMXun-U.js";var R=e(t(),1),z=[{value:`off`,label:`关闭`,hint:`不拦截工具调用`},{value:`approval`,label:`审批模式`,hint:`只裁决通过/拒绝`},{value:`review_edit`,label:`审查编辑模式`,hint:`可收窄参数后放行`}],te={approve:`通过`,reject:`拒绝`},B={approve:`green`,reject:`red`},V={human:`人工`,audit_agent:`审计 Agent`,system:`系统`,manual:`手动录入`};function H(e){let t=String(e||``).trim().toLowerCase().replace(/-/g,`_`);return t===`feedback`||t===`followup`?`approval`:[`off`,`approval`,`review_edit`].includes(t)?t:`off`}function U(e){let t=H(e),n=z.find(e=>e.value===t);return n?n.label:t}function W(e){let t=String(e||``).trim().toLowerCase();return t===`audit_agent`||t===`agent`||t===`ai`?`audit_agent`:`human`}function G(e){return W(e)===`audit_agent`?`审计 Agent`:`人工审批`}function K(e){let t=String(e||``).trim().toLowerCase();return te[t]||t||`—`}function q(e){return B[String(e||``).toLowerCase()]||`grey`}function ne(e){return V[String(e||``).trim().toLowerCase()]||e||`—`}function re(e){let t=String(e||``).trim().toLowerCase();return t===`pending`?`待审批`:t===`decided`?`已裁决`:t===`timeout`?`超时自动拒绝`:t===`cancelled`?`已取消`:e||`—`}function J(e){if(!e)return{};if(typeof e==`object`)return e;try{let t=JSON.parse(String(e));return t&&typeof t==`object`?t:{}}catch{return{}}}function ie(e){if(!e||typeof e!=`object`)return null;if(e.argumentsObj&&typeof e.argumentsObj==`object`)return e.argumentsObj;if(typeof e.arguments==`string`&&e.arguments.trim())try{let t=JSON.parse(e.arguments);if(t&&typeof t==`object`)return t}catch{return{raw:e.arguments}}return e.arguments&&typeof e.arguments==`object`?e.arguments:null}function ae(e){return!e||typeof e!=`object`?[]:[{key:`userMessage`,label:`用户消息`,value:e.userMessage},{key:`thinking`,label:`思考`,value:e.thinking},{key:`reasoningChain`,label:`推理链`,value:e.reasoningChain},{key:`planning`,label:`计划`,value:e.planning}].filter(e=>String(e.value||``).trim())}function oe(e){let t=e?.executionResult;if(!t||typeof t!=`object`)return null;let n=String(t.result||``).trim();return n?{success:t.success===!0,text:n}:null}function se(e){let t=e?.hitlApproval;if(!t||typeof t!=`object`)return``;let n=Number(t.timeoutSeconds)||0;if(n<=0)return`无超时限制`;let r=t.expiresAt?new Date(t.expiresAt):null;return r&&Number.isFinite(r.getTime())?r.getTime()<=Date.now()?`已于 ${S(r)} 到期`:`${S(r)} 截止`:`${n} 秒内需裁决`}function Y(e){return e?S(e):`—`}function ce(e){return String(e||``).split(/[\n,,;;]/).map(e=>e.trim()).filter(Boolean).filter((e,t,n)=>n.indexOf(e)===t)}function X(e){let t=[];return e?.userMessage&&t.push(`用户消息`),e?.thinking&&t.push(`思考`),e?.executionResult&&t.push(`执行结果`),t.length?t.join(` · `):`—`}var Z=e(n(),1);function Q({payload:e}){let t=ae(e),n=oe(e);return!t.length&&!n?null:(0,Z.jsxs)(`div`,{className:`hitl-context-blocks`,children:[t.map(e=>(0,Z.jsxs)(`div`,{className:`hitl-context-block`,children:[(0,Z.jsx)(`span`,{className:`hitl-context-label`,children:e.label}),(0,Z.jsx)(`pre`,{className:`hitl-context-text`,children:String(e.value)})]},e.key)),n&&(0,Z.jsxs)(`div`,{className:`hitl-context-block ${n.success?`hitl-state-success`:`hitl-state-failed`}`,children:[(0,Z.jsx)(`span`,{className:`hitl-context-label`,children:`执行结果(${n.success?`成功`:`失败`})`}),(0,Z.jsx)(`pre`,{className:`hitl-context-text`,children:n.text})]})]})}var{Text:le}=o;function ue({item:e,canWrite:t,onDone:n}){let r=(0,R.useMemo)(()=>J(e.payload),[e.payload]),i=(0,R.useMemo)(()=>ie(r),[r]),a=H(e.mode)===`review_edit`,o=W(e.reviewer),[f,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(()=>a&&i?JSON.stringify(i,null,2):``),[g,_]=(0,R.useState)(``),[v,y]=(0,R.useState)(``),b=(0,R.useCallback)(async t=>{if(g)return;let r;if(a&&m.trim()){try{r=JSON.parse(m)}catch(e){y(`修改后的参数不是合法 JSON:${e.message}`);return}if(!r||typeof r!=`object`||Array.isArray(r)){y(`修改后的参数必须是 JSON 对象`);return}}y(``),_(t);try{await T.post(`/hitl/decision`,{interruptId:e.id,decision:t,comment:f.trim(),editedArguments:r}),I(t===`approve`?`已通过,工具将继续执行`:`已拒绝本次工具调用`),n?.()}catch(t){if(t?.status===409){await T.post(`/hitl/dismiss`,{interruptId:e.id}).catch(()=>null),E(`该审批已被处理,列表已刷新`),n?.();return}O(t,`提交审批失败`)}finally{_(``)}},[a,m,g,f,e.id,n]),x=(0,R.useCallback)(()=>{L({title:`忽略该审批`,content:`忽略后该审批记为取消(reject),本次工具调用不会继续执行,记录可在审批日志中查看。`,okText:`忽略`,onOk:async()=>{try{await T.post(`/hitl/dismiss`,{interruptId:e.id}),I(`已忽略该审批`),n?.()}catch(e){O(e,`忽略审批失败`)}}})},[e.id,n]);return(0,Z.jsxs)(`div`,{className:`hitl-pending-card`,children:[(0,Z.jsxs)(`div`,{className:`hitl-pending-head`,children:[(0,Z.jsxs)(s,{spacing:6,wrap:!0,children:[(0,Z.jsx)(c,{size:`small`,color:`blue`,shape:`square`,children:e.toolName||`—`}),(0,Z.jsx)(c,{size:`small`,color:a?`violet`:`grey`,children:U(e.mode)}),(0,Z.jsx)(c,{size:`small`,color:o===`audit_agent`?`green`:`grey`,children:G(e.reviewer)})]}),(0,Z.jsxs)(s,{spacing:6,children:[(0,Z.jsx)(le,{type:`tertiary`,size:`small`,children:Y(e.createdAt)}),(0,Z.jsx)(l,{size:`small`,theme:`borderless`,disabled:!t||!!g,onClick:x,children:`忽略`})]})]}),(0,Z.jsxs)(`div`,{className:`hitl-pending-meta`,children:[(0,Z.jsx)(`span`,{className:`hitl-pending-meta-label`,children:`会话`}),(0,Z.jsx)(`span`,{className:`hitl-mono`,children:e.conversationId||`—`}),e.conversationId&&(0,Z.jsx)(M,{text:e.conversationId,size:`small`}),(0,Z.jsx)(`span`,{className:`hitl-pending-deadline`,children:se(r)})]}),(0,Z.jsx)(Q,{payload:r}),i&&(0,Z.jsx)(F,{title:`请求参数`,value:i,collapsed:!0}),(0,Z.jsxs)(`div`,{className:`hitl-pending-editor`,children:[(0,Z.jsx)(`span`,{className:`hitl-context-label`,children:a?`修改后的参数(可编辑,留空表示沿用原参数)`:`审批模式:仅可通过/拒绝,参数编辑已禁用`}),(0,Z.jsx)(u,{rows:a?6:3,value:a?m:i?JSON.stringify(i,null,2):``,disabled:!a,spellCheck:!1,className:`hitl-args-textarea`,onChange:e=>{h(e),v&&y(``)}})]}),v&&(0,Z.jsx)(`div`,{className:`hitl-inline-error`,children:v}),(0,Z.jsx)(d,{value:f,placeholder:`审批备注(可选),例如:只读命令,允许执行`,onChange:e=>p(e)}),(0,Z.jsxs)(`div`,{className:`hitl-pending-actions`,children:[(0,Z.jsx)(l,{type:`danger`,theme:`light`,disabled:!t||!!g,loading:g===`reject`,onClick:()=>b(`reject`),children:`拒绝`}),(0,Z.jsx)(l,{theme:`solid`,disabled:!t||!!g,loading:g===`approve`,onClick:()=>b(`approve`),children:a&&m.trim()&&m.trim()!==(i?JSON.stringify(i,null,2):``)?`保存修改并放行`:`通过`})]}),(0,Z.jsx)(F,{title:`完整载荷`,value:r,collapsed:!0})]})}function de({canWrite:e,onCountChange:t,refreshKey:n=0}){let r=C(),[i,o]=(0,R.useState)(1),[s,c]=(0,R.useState)(20),[l,u]=(0,R.useState)(``),f=ee(l,350),m=D(()=>T.get(`/hitl/pending`,{page:i,pageSize:s,q:f}),[i,s,f,n]),h=m.data?.items||[],g=Number(m.data?.total)||0;(0,R.useEffect)(()=>{t?.(g)},[t,g]);let _=(0,R.useCallback)(e=>{c(e),o(1)},[]);return(0,Z.jsxs)(`div`,{className:`hitl-pending-panel`,children:[(0,Z.jsxs)(`div`,{className:`hitl-panel-toolbar`,children:[(0,Z.jsx)(d,{showClear:!0,value:l,style:{width:300},placeholder:r(`hitl.searchPlaceholder`,null,`搜索工具、会话或载荷…`),onChange:e=>{u(e),o(1)}}),(0,Z.jsxs)(le,{type:`tertiary`,size:`small`,children:[r(`hitl.pendingTitle`,null,`待审批请求`),` · `,g]})]}),(0,Z.jsx)(A,{error:m.error,onRetry:()=>m.reload()}),m.loading&&!h.length&&(0,Z.jsx)(`div`,{className:`hitl-panel-loading`,children:(0,Z.jsx)(p,{})}),!m.loading&&!h.length&&!m.error&&(0,Z.jsx)(a,{title:r(`hitl.emptyState`,null,`暂无待审批请求`),description:`工具调用命中敏感规则时会在此等待裁决。`,style:{padding:48}}),(0,Z.jsx)(`div`,{className:`hitl-pending-list`,children:h.map(t=>(0,Z.jsx)(ue,{item:t,canWrite:e,onDone:()=>{h.length<=1&&i>1?o(i-1):m.reload()}},t.id))}),g>0&&(0,Z.jsx)(`div`,{className:`hitl-panel-pagination`,children:(0,Z.jsx)(b,{currentPage:i,pageSize:s,total:g,showSizeChanger:!0,pageSizeOpts:[10,20,50],showTotal:!0,onPageChange:e=>o(e),onPageSizeChange:_})})]})}var{Text:fe}=o;function pe({logId:e,onClose:t}){let n=C(),{data:r,loading:i,error:a,reload:o}=D(()=>T.get(`/hitl/logs/${encodeURIComponent(e)}`),[e],{skip:!e}),u=(0,R.useMemo)(()=>J(r?.payload),[r?.payload]),d=[r?.auditBackend,r?.auditModel].filter(Boolean).join(` · `);return(0,Z.jsxs)(v,{visible:!!e,onCancel:t,width:720,title:n(`hitl.logModalView`,null,`审批日志详情`),footer:(0,Z.jsx)(l,{onClick:t,children:n(`common.close`,null,`关闭`)}),children:[(0,Z.jsx)(A,{error:a,onRetry:o}),i&&!r&&(0,Z.jsx)(`div`,{className:`hitl-panel-loading`,children:(0,Z.jsx)(p,{})}),r&&(0,Z.jsxs)(`div`,{className:`hitl-log-detail`,children:[(0,Z.jsx)(k,{columns:2,items:[{label:n(`hitl.colTool`,null,`工具`),value:(0,Z.jsx)(fe,{strong:!0,children:r.toolName||`—`})},{label:n(`hitl.colDecision`,null,`决策`),value:(0,Z.jsx)(c,{size:`small`,color:q(r.decision),children:K(r.decision)})},{label:`状态`,value:re(r.status)},{label:n(`hitl.colDecidedBy`,null,`审批方`),value:ne(r.decidedBy)},{label:`审批方类型`,value:G(r.reviewer)},{label:`审批引擎`,value:d||`—`},{label:n(`hitl.colConversation`,null,`会话`),value:r.conversationId?(0,Z.jsxs)(s,{spacing:4,children:[(0,Z.jsx)(`span`,{className:`hitl-mono`,children:r.conversationId}),(0,Z.jsx)(M,{text:r.conversationId,size:`small`})]}):`—`},{label:`模式`,value:r.mode||`—`},{label:`创建时间`,value:Y(r.createdAt)},{label:`裁决时间`,value:Y(r.decidedAt)},{label:`ID`,value:(0,Z.jsx)(`span`,{className:`hitl-mono`,children:r.id})},{label:n(`hitl.fieldComment`,null,`备注`),value:r.comment||`—`}]}),(0,Z.jsx)(Q,{payload:u}),(0,Z.jsx)(F,{title:n(`hitl.fieldPayload`,null,`载荷`),value:u,collapsed:!0})]})]})}function me({canWrite:e,detailId:t,onOpenDetail:n,onCloseDetail:r,refreshKey:i=0}){let a=C(),[o,u]=(0,R.useState)(1),[f,p]=(0,R.useState)(20),[m,h]=(0,R.useState)(``),g=ee(m,350),[_,v]=(0,R.useState)(`all`),[b,S]=(0,R.useState)(`all`),[w,E]=(0,R.useState)([]),k=(0,R.useMemo)(()=>({q:g,decision:_===`all`?``:_,decidedBy:b===`all`?``:b}),[g,_,b]),j=D(()=>T.get(`/hitl/logs`,{page:o,pageSize:f,...k}),[o,f,k,i]),M=j.data?.items||[],N=Number(j.data?.total)||0,F=Number(j.data?.retentionDays)||0,z=(0,R.useCallback)(()=>j.reload(),[j.reload]),te=(0,R.useCallback)(()=>{w.length&&L({title:`批量删除审批日志`,content:`确定删除选中的 ${w.length} 条审批日志?此操作不可恢复。`,okText:a(`common.delete`,null,`删除`),onOk:async()=>{try{await T.del(`/hitl/logs`,{body:{ids:w}}),I(`已删除 ${w.length} 条审批日志`),E([]),z()}catch(e){O(e,`批量删除审批日志失败`)}}})},[z,w,a]),B=(0,R.useCallback)(()=>{L({title:a(`hitl.clearAll`,null,`清空审计日志`),content:g||_!==`all`||b!==`all`?`将清空当前筛选条件下的全部已裁决日志(不会删除待审批项)。`:`将清空全部已裁决审批日志(不会删除待审批项)。`,okText:a(`hitl.clearAll`,null,`清空`),onOk:async()=>{try{await T.del(`/hitl/logs`,{query:k,body:{all:!0}}),I(`审批日志已清空`),E([]),u(1),z()}catch(e){O(e,`清空审批日志失败`)}}})},[b,_,g,k,z,a]),V=[{title:a(`hitl.colTool`,null,`工具`),dataIndex:`toolName`,width:220,ellipsis:!0,render:e=>(0,Z.jsx)(`span`,{className:`hitl-mono hitl-ellipsis`,title:e||``,children:e||`—`})},{title:a(`hitl.colConversation`,null,`会话`),dataIndex:`conversationId`,width:200,render:e=>(0,Z.jsx)(`span`,{className:`hitl-mono hitl-ellipsis`,title:e||``,children:e||`—`})},{title:a(`hitl.colDecision`,null,`决策`),dataIndex:`decision`,width:100,render:e=>(0,Z.jsx)(c,{size:`small`,color:q(e),children:K(e)})},{title:a(`hitl.colDecidedBy`,null,`审批方`),dataIndex:`decidedBy`,width:140,render:(e,t)=>(0,Z.jsxs)(`div`,{className:`hitl-log-by`,children:[(0,Z.jsx)(`span`,{children:ne(e)}),t.auditBackend&&(0,Z.jsx)(`span`,{className:`hitl-log-engine`,children:[t.auditBackend,t.auditModel].filter(Boolean).join(` · `)})]})},{title:`备注`,dataIndex:`comment`,render:(e,t)=>(0,Z.jsx)(`span`,{title:e||``,children:e||X(J(t.payload))})},{title:a(`hitl.colTime`,null,`时间`),dataIndex:`decidedAt`,width:180,render:(e,t)=>Y(e||t.createdAt)},{title:a(`common.actions`,null,`操作`),dataIndex:`id`,width:90,render:e=>(0,Z.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>n(e),children:a(`common.view`,null,`详情`)})}],H={currentPage:o,pageSize:f,total:N,showSizeChanger:!0,pageSizeOpts:[20,50,100],showTotal:!0,onPageChange:e=>u(e),onPageSizeChange:e=>{p(e),u(1)}};return(0,Z.jsxs)(`div`,{className:`hitl-logs-panel`,children:[F>0&&(0,Z.jsx)(`p`,{className:`hitl-retention-hint`,children:a(`hitl.retentionHint`,{days:F},`审批日志保留 ${F} 天,到期自动清理。`)}),(0,Z.jsx)(A,{error:j.error,onRetry:z}),(0,Z.jsx)(P,{columns:V,dataSource:M,rowKey:`id`,loading:j.loading,pagination:H,size:`small`,scroll:{x:1280},emptyText:a(`hitl.logsEmpty`,null,`暂无审批日志`),rowSelection:{selectedRowKeys:w,onChange:e=>E(e||[])},toolbar:(0,Z.jsxs)(s,{spacing:8,wrap:!0,children:[(0,Z.jsx)(d,{showClear:!0,style:{width:220},value:m,placeholder:a(`hitl.searchPlaceholder`,null,`搜索工具、会话或载荷…`),onChange:e=>{h(e),u(1)}}),(0,Z.jsx)(x,{value:_,style:{width:120},optionList:[{value:`all`,label:a(`hitl.filterAll`,null,`全部`)},{value:`approve`,label:a(`hitl.decisionApprove`,null,`通过`)},{value:`reject`,label:a(`hitl.decisionReject`,null,`拒绝`)}],onChange:e=>{v(e),u(1)}}),(0,Z.jsx)(x,{value:b,style:{width:150},optionList:[{value:`all`,label:a(`hitl.filterAll`,null,`全部`)},{value:`human`,label:a(`hitl.reviewerHuman`,null,`人工`)},{value:`audit_agent`,label:a(`hitl.reviewerAgent`,null,`审计 Agent`)},{value:`system`,label:a(`hitl.reviewerSystem`,null,`系统`)},{value:`manual`,label:a(`hitl.reviewerManual`,null,`手动录入`)}],onChange:e=>{S(e),u(1)}}),(0,Z.jsx)(l,{icon:(0,Z.jsx)(y,{}),theme:`borderless`,size:`small`,onClick:z,loading:j.loading,children:a(`common.refresh`,null,`刷新`)}),(0,Z.jsxs)(l,{size:`small`,type:`danger`,theme:`borderless`,disabled:!e||!w.length,onClick:te,children:[`批量删除`,w.length?`(${w.length})`:``]}),(0,Z.jsx)(l,{size:`small`,type:`danger`,theme:`borderless`,disabled:!e||!N,onClick:B,children:a(`hitl.clearAll`,null,`清空`)})]})}),(0,Z.jsx)(pe,{logId:t,onClose:r})]})}var{Text:he}=o;function ge({canWrite:e,refreshKey:t=0}){let n=C(),{data:r,loading:i,error:a,reload:o}=D(()=>T.get(`/hitl/tool-whitelist`),[t]),[d,f]=(0,R.useState)(``),[p,m]=(0,R.useState)(``);(0,R.useEffect)(()=>{r&&f((r.toolWhitelist||[]).join(` `))},[r]);let h=(0,R.useMemo)(()=>ce(d),[d]),g=(0,R.useMemo)(()=>(r?.toolWhitelist||[]).join(` `),[r]),_=d.trim()!==g.trim(),v=(0,R.useCallback)(async()=>{m(`put`);try{let e=await T.put(`/hitl/tool-whitelist`,{toolWhitelist:h});I(n(`hitl.whitelistSaved`,null,`白名单已保存`)),f((e?.toolWhitelist||h).join(` `)),o({silent:!0})}catch(e){O(e,n(`hitl.whitelistSaveFailed`,null,`保存白名单失败`))}finally{m(``)}},[o,n,h]),b=(0,R.useCallback)(async()=>{m(`post`);try{let e=await T.post(`/hitl/tool-whitelist`,{sensitiveTools:h});I(e?.hitlGlobalWhitelistMerged?`已合并到全局白名单`:`没有新增工具,白名单未变化`),f((e?.hitlGlobalToolWhitelist||h).join(` diff --git a/web/static/app/assets/index-CAEPLS-g.js b/web/static/app/assets/index-DNMXun-U.js similarity index 96% rename from web/static/app/assets/index-CAEPLS-g.js rename to web/static/app/assets/index-DNMXun-U.js index ef156e89..e87e36f9 100644 --- a/web/static/app/assets/index-CAEPLS-g.js +++ b/web/static/app/assets/index-DNMXun-U.js @@ -1,4 +1,4 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dashboard-8XvRuqLB.js","assets/rolldown-runtime-WkwZ5CU-.js","assets/react-QV7DAAIx.js","assets/semi-65W_4I1v.js","assets/semi-BUXPdXzR.css","assets/dashboard-Dk6QMmtm.css","assets/chat-B3amLD8_.js","assets/retest-EzTZPjnQ.js","assets/agent-handoff-DzQOcr38.js","assets/project-form-Bm3Gi6Yc.js","assets/model-channel-mQ6lfvSO.js","assets/project-options-CMQbwv_U.js","assets/chat-B_1ruiFc.css","assets/deep-assessments-C1zSIX6t.js","assets/graph-parents-i1hc3RVG.js","assets/graph-parents-BbkuhUnk.css","assets/deep-assessments-BVUI7zDD.css","assets/hitl-CuqgPh-B.js","assets/hitl-BqmzzDjt.css","assets/tool-guard-gHtviV0M.js","assets/tool-guard-DKIWLN1V.css","assets/projects-CMt4u2Qr.js","assets/AssetEditorModal-HZN0Ndjf.js","assets/assetTarget-D2PEjBAg.js","assets/projects-CCzxY6zz.css","assets/asset-overview-xwryoaKx.js","assets/AssetBits-DtqSAj0f.js","assets/asset-overview-DEMYiRVr.css","assets/asset-library-CwccI3Xb.js","assets/asset-library-a5Vth3JU.css","assets/info-collect-CnstRscn.js","assets/info-collect-BrIcieOX.css","assets/vulnerabilities-CXGKZewN.js","assets/vulnerabilities-BPt2JmiL.css","assets/tasks-CT27M-Wx.js","assets/tasks-BtBBHKoW.css","assets/workflows-BnRbScwz.js","assets/workflows-EsKm07MV.css","assets/webshell-CXOTGht5.js","assets/webshell-BdcYpY5u.css","assets/c2-listeners-CE3GvlqS.js","assets/c2-shared-Car3lDYq.js","assets/c2-shared-B-Nz9eUh.css","assets/c2-shared-D-8kBzuC.js","assets/c2-listeners-KjhK45yg.css","assets/c2-sessions-BFuBJt9m.js","assets/c2-sessions-DLf_n8Eq.css","assets/c2-tasks-DSV9J8Vu.js","assets/c2-tasks-B5H34xZF.css","assets/c2-payloads-B8TBcwqZ.js","assets/c2-payloads-CnRJmaJm.css","assets/c2-events-b_BWiEV4.js","assets/c2-events-BVd4qqKy.css","assets/c2-profiles-DFa_6zU3.js","assets/c2-profiles-BpNJlhDC.css","assets/chat-files-D2U-2IVG.js","assets/chat-files-wKL7Vwmw.css","assets/plugin-hub-FbKl43dM.js","assets/plugin-hub-Yl4AUy33.css","assets/mcp-monitor-CfVvha6O.js","assets/mcp-monitor-8VvqmnVY.css","assets/mcp-management-BebvY2ig.js","assets/mcp-management-CEr7J00D.css","assets/knowledge-retrieval-logs-DY1jNxJ9.js","assets/knowledge-management-CQ0nnhXJ.js","assets/skills-monitor-BUTc0QtL.js","assets/skills-management-g8Njeibz.js","assets/agents-management-gLrRdc0M.js","assets/roles-management-DGTD0STX.js","assets/roles-management-CAkb5FLz.css","assets/platform-rbac-Bqf7ZmWP.js","assets/settings-yUhIZhl9.js","assets/settings-Cjg19I8_.css","assets/api-docs-BEMXmVy4.js","assets/api-docs-B_T3BEfL.css"])))=>i.map(i=>d[i]); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dashboard-Dwi74cCO.js","assets/rolldown-runtime-WkwZ5CU-.js","assets/react-QV7DAAIx.js","assets/semi-65W_4I1v.js","assets/semi-BUXPdXzR.css","assets/dashboard-Dk6QMmtm.css","assets/chat-iFaq7TmY.js","assets/retest-EzTZPjnQ.js","assets/agent-handoff-DzQOcr38.js","assets/project-form-B7wV5B1p.js","assets/model-channel-mQ6lfvSO.js","assets/project-options-CMQbwv_U.js","assets/chat-B_1ruiFc.css","assets/deep-assessments-BwHg6NCr.js","assets/graph-parents-i1hc3RVG.js","assets/graph-parents-BbkuhUnk.css","assets/deep-assessments-BVUI7zDD.css","assets/hitl-hVYHftcD.js","assets/hitl-BqmzzDjt.css","assets/tool-guard-DY35NYks.js","assets/tool-guard-DKIWLN1V.css","assets/projects-CfcDnjFh.js","assets/AssetEditorModal-C2UJzIaS.js","assets/assetTarget-D2PEjBAg.js","assets/projects-CCzxY6zz.css","assets/asset-overview-ClxkP_Uu.js","assets/AssetBits-DtqSAj0f.js","assets/asset-overview-DEMYiRVr.css","assets/asset-library-Btn_YOu0.js","assets/asset-library-a5Vth3JU.css","assets/info-collect-CIMK0OyE.js","assets/info-collect-BrIcieOX.css","assets/vulnerabilities-BRH58_rp.js","assets/vulnerabilities-BPt2JmiL.css","assets/tasks-C9yzz-_n.js","assets/tasks-BtBBHKoW.css","assets/workflows-BgrBtPdj.js","assets/workflows-EsKm07MV.css","assets/webshell-CE6Yp5FY.js","assets/webshell-BdcYpY5u.css","assets/c2-listeners-7rFR5Rx6.js","assets/c2-shared-2EAlkwn6.js","assets/c2-shared-B-Nz9eUh.css","assets/c2-shared-BrRxH-6B.js","assets/c2-listeners-KjhK45yg.css","assets/c2-sessions-CnBIfRAo.js","assets/c2-sessions-DLf_n8Eq.css","assets/c2-tasks-FVvnpyKj.js","assets/c2-tasks-B5H34xZF.css","assets/c2-payloads-DP3Iw5IZ.js","assets/c2-payloads-CnRJmaJm.css","assets/c2-events-Cdd7cKs8.js","assets/c2-events-BVd4qqKy.css","assets/c2-profiles-Cxv9lUnu.js","assets/c2-profiles-BpNJlhDC.css","assets/chat-files-BvkWbj5T.js","assets/chat-files-wKL7Vwmw.css","assets/plugin-hub-BhSjc1VJ.js","assets/plugin-hub-Yl4AUy33.css","assets/mcp-monitor-DHXOIA-R.js","assets/mcp-monitor-8VvqmnVY.css","assets/mcp-management-Be2zIK90.js","assets/mcp-management-CEr7J00D.css","assets/knowledge-retrieval-logs-CJolZ5T-.js","assets/knowledge-management-DxjSMTdf.js","assets/skills-monitor-Bs5yNZYW.js","assets/skills-management-CBXR8d2s.js","assets/agents-management-BH4GA4Vt.js","assets/roles-management-DZI3VXhR.js","assets/roles-management-CAkb5FLz.css","assets/platform-rbac-BDY_zjz7.js","assets/settings-CgtfKueL.js","assets/settings-Cjg19I8_.css","assets/api-docs-BqzLMZ8q.js","assets/api-docs-B_T3BEfL.css"])))=>i.map(i=>d[i]); import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{$t as t,A as n,At as r,B as i,Ct as a,E as o,F as s,G as c,Gt as l,H as u,Ht as d,I as f,J as p,Jt as m,K as h,Kt as g,L as _,M as ee,N as te,Nt as ne,O as v,Qt as y,R as b,Rt as x,St as re,T as ie,Tt as S,Ut as ae,V as oe,W as se,Wt as ce,Xt as le,Y as ue,Yt as de,Zt as fe,an as pe,at as me,b as he,bt as ge,dt as _e,et as ve,ht as ye,i as C,kt as be,n as xe,nt as Se,o as Ce,ot as we,p as Te,r as Ee,rn as De,st as Oe,t as w,u as ke,ut as T,vt as Ae,w as E,wt as je,z as Me,zt as Ne}from"./semi-65W_4I1v.js";import{S as Pe,b as Fe,d as Ie,f as Le,g as D,h as Re,l as ze,m as Be,p as Ve,t as He,v as Ue}from"./react-QV7DAAIx.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var O=e(Pe(),1),We=Fe(),Ge=`cyberstrike-auth`;function Ke(){try{let e=localStorage.getItem(Ge);if(!e)return null;let t=JSON.parse(e);if(!t?.token||!t?.expiresAt)return null;let n=new Date(t.expiresAt);return!Number.isFinite(n.getTime())||n.getTime()<=Date.now()?null:{token:t.token,expiresAt:n.toISOString(),user:t.user||null,roles:Array.isArray(t.roles)?t.roles:[],permissions:Array.isArray(t.permissions)?t.permissions:[],scope:t.scope||``}}catch(e){return console.warn(`读取会话失败:`,e),null}}function qe(e){e?localStorage.setItem(Ge,JSON.stringify(e)):localStorage.removeItem(Ge)}var Je=null,Ye=null;function Xe(e){Je=e||null}function Ze(){return Je}function Qe(e,t){let n=Ye;Ye=e||null;try{return t()}finally{Ye=n}}var k=class extends Error{constructor(e,{status:t=0,payload:n=null,path:r=``}={}){super(e),this.name=`ApiError`,this.status=t,this.payload=n,this.path=r}};function $e(e,t){let n=e.startsWith(`http`)?e:`/api${e.startsWith(`/`)?e:`/${e}`}`;if(!t)return n;let r=new URLSearchParams;for(let[e,n]of Object.entries(t))n!=null&&n!==``&&(Array.isArray(n)?n.forEach(t=>r.append(e,t)):r.append(e,String(n)));let i=r.toString();return i?`${n}${n.includes(`?`)?`&`:`?`}${i}`:n}async function et(e){let t=e.headers.get(`content-type`)||``;try{if(t.includes(`application/json`)){let t=await e.json();return{message:t.error||t.message||`请求失败(HTTP ${e.status})`,payload:t}}let n=await e.text();return{message:n?.slice(0,300)||`请求失败(HTTP ${e.status})`,payload:n}}catch{return{message:`请求失败(HTTP ${e.status})`,payload:null}}}async function A(e,t={}){let{method:n=`GET`,body:r,query:i,headers:a={},signal:o,raw:s=!1,timeout:c=6e4}=t,l=o===void 0?n.toUpperCase()===`GET`?Ye:void 0:o,u={Accept:`application/json`,...a},d=r;r!=null&&!(r instanceof FormData)&&typeof r!=`string`&&!(r instanceof Blob)&&(u[`Content-Type`]=`application/json`,d=JSON.stringify(r)),Je&&!u.Authorization&&(u.Authorization=`Bearer ${Je}`);let f=new AbortController,p=c?setTimeout(()=>f.abort(),c):null,m=()=>f.abort();l&&(l.aborted?f.abort():l.addEventListener(`abort`,m,{once:!0}));let h;try{h=await fetch($e(e,i),{method:n,headers:u,body:d,signal:f.signal})}catch(t){throw t.name===`AbortError`?new k(`请求已取消`,{path:e}):new k(`网络连接失败,请检查服务状态`,{path:e})}finally{p&&clearTimeout(p),l&&l.removeEventListener(`abort`,m)}if(h.status===401&&window.dispatchEvent(new CustomEvent(`csai:unauthorized`)),!h.ok){let{message:t,payload:n}=await et(h);throw new k(t,{status:h.status,payload:n,path:e})}return s?h:h.status===204?null:(h.headers.get(`content-type`)||``).includes(`application/json`)?h.json():h.text()}var j={get:(e,t,n={})=>A(e,{...n,query:t}),post:(e,t,n={})=>A(e,{...n,method:`POST`,body:t}),put:(e,t,n={})=>A(e,{...n,method:`PUT`,body:t}),patch:(e,t,n={})=>A(e,{...n,method:`PATCH`,body:t}),del:(e,t={})=>A(e,{...t,method:`DELETE`}),raw:(e,t={})=>A(e,{...t,raw:!0})};async function tt(e,{query:t,filename:n,method:r=`GET`,body:i}={}){let a=await A(e,{method:r,body:i,query:t,raw:!0,timeout:12e4}),o=await a.blob(),s=a.headers.get(`content-disposition`)||``,c=s.match(/filename\*=UTF-8''([^;]+)/i),l=s.match(/filename="?([^";]+)"?/i),u=n||(c?decodeURIComponent(c[1]):l?.[1])||`download.bin`,d=URL.createObjectURL(o),f=document.createElement(`a`);return f.href=d,f.download=u,document.body.appendChild(f),f.click(),f.remove(),setTimeout(()=>URL.revokeObjectURL(d),1e3),u}function nt(e,t,{onEvent:n,onError:r,onClose:i,signal:a}={}){let o=new AbortController;a&&(a.aborted?o.abort():a.addEventListener(`abort`,()=>o.abort(),{once:!0}));let s={"Content-Type":`application/json`,Accept:`text/event-stream`};return Je&&(s.Authorization=`Bearer ${Je}`),(async()=>{try{let r=await fetch($e(e),{method:`POST`,headers:s,body:JSON.stringify(t||{}),signal:o.signal});if(r.status===401&&window.dispatchEvent(new CustomEvent(`csai:unauthorized`)),!r.ok){let{message:t}=await et(r);throw new k(t,{status:r.status,path:e})}if(!r.body)throw new k(`服务端未返回流式响应`,{path:e});let a=r.body.getReader(),c=new TextDecoder,l=``,u=!1;for(;!u;){let{done:e,value:t}=await a.read();if(e)break;l+=c.decode(t,{stream:!0});let r;for(;(r=l.indexOf(` `))>=0;){let e=l.slice(0,r).replace(/\r$/,``);if(l=l.slice(r+1),!e.startsWith(`data:`))continue;let t=e.slice(5).trim();if(!t)continue;if(t===`[DONE]`){u=!0;break}let i;try{i=JSON.parse(t)}catch{continue}n?.(i)}}i?.()}catch(e){if(e.name===`AbortError`){i?.();return}r?.(e)}})(),()=>o.abort()}function rt(e,t=`操作失败`){return e?typeof e==`string`?e:e.message||t:t}var M=e(He(),1),it=(0,O.createContext)(null);function at(e,t){return e?{token:t||e.token,expiresAt:e.expires_at||e.expiresAt||``,appVersion:typeof e.app_version==`string`?e.app_version.trim():``,user:e.user||null,roles:Array.isArray(e.roles)?e.roles:[],permissions:Array.isArray(e.permissions)?e.permissions:[],scope:e.scope||``}:null}function ot({children:e}){let t=(0,O.useRef)(Ke()).current,[n,r]=(0,O.useState)(t),[i,a]=(0,O.useState)(!!t);(0,O.useEffect)(()=>{if(Xe(t?.token||null),!t?.token){a(!1);return}let e=!1;return j.get(`/auth/validate`).then(n=>{if(e)return;let i=at(n,t.token);r(i),qe(i)}).catch(()=>{e||(r(null),qe(null),Xe(null))}).finally(()=>{e||a(!1)}),()=>{e=!0}},[]);let o=(0,O.useCallback)(()=>{r(null),Xe(null),qe(null)},[]);(0,O.useEffect)(()=>{let e=()=>o();return window.addEventListener(`csai:unauthorized`,e),()=>window.removeEventListener(`csai:unauthorized`,e)},[o]);let s=(0,O.useCallback)(async(e,t)=>{let n=await j.post(`/auth/login`,{username:String(e||``).trim(),password:t}),i=at(n,n?.token);return Xe(i?.token||null),qe(i),r(i),i},[]),c=(0,O.useCallback)(async()=>{try{await j.post(`/auth/logout`,{})}catch{}o()},[o]),l=(0,O.useMemo)(()=>new Set(n?.permissions||[]),[n]),u=(0,O.useCallback)(e=>!e||String(e).split(/\s+/).some(e=>l.has(e)),[l]),d=(0,O.useCallback)(e=>{let t=Array.isArray(e)?e:String(e||``).split(/\s+/).filter(Boolean);return!t.length||t.some(e=>l.has(e))},[l]),f=(0,O.useCallback)(async()=>{if(!n?.token)return null;let e=at(await j.get(`/auth/validate`),n.token);return r(e),qe(e),e},[n?.token]),p=(0,O.useMemo)(()=>({session:n,user:n?.user||null,roles:n?.roles||[],permissions:l,hasPermission:u,hasAnyPermission:d,checking:i,authenticated:!!n?.token,login:s,logout:c,refresh:f}),[n,l,u,d,i,s,c,f]);return(0,M.jsx)(it.Provider,{value:p,children:e})}function st(){let e=(0,O.useContext)(it);if(!e)throw Error(`useAuth 必须在 AuthProvider 内使用`);return e}var ct=[{id:`zh-CN`,label:`简体中文`},{id:`en-US`,label:`English`},{id:`ru-RU`,label:`Русский`},{id:`ar-SA`,label:`العربية`}],lt=`csai_lang`,ut=`zh-CN`,dt=`/static/i18n`,ft=new Map;function pt(){try{let e=localStorage.getItem(lt);if(e&&ct.some(t=>t.id===e))return e}catch{}let e=String(navigator.language||``).toLowerCase();return e.startsWith(`zh`)?`zh-CN`:e.startsWith(`ru`)?`ru-RU`:e.startsWith(`ar`)?`ar-SA`:e.startsWith(`en`)?`en-US`:ut}function mt(e){return ft.has(e)||ft.set(e,fetch(`${dt}/${e}.json`,{cache:`no-cache`}).then(e=>e.ok?e.json():{}).catch(()=>({}))),ft.get(e)}function ht(e,t){if(!e)return;let n=e;for(let e of String(t).split(`.`)){if(typeof n!=`object`||!n)return;n=n[e]}return typeof n==`string`?n:void 0}function N(e,t){return t?e.replace(/\{\{\s*(\w+)\s*\}\}/g,(e,n)=>t[n]===void 0?e:String(t[n])):e}var gt=(0,O.createContext)({lang:ut,t:e=>e,ready:!1,setLanguage:()=>{}});function _t({children:e}){let[t,n]=(0,O.useState)(pt),[r,i]=(0,O.useState)({}),[a,o]=(0,O.useState)(!1);(0,O.useEffect)(()=>{let e=!1;Promise.all([mt(t),mt(ut),mt(`en-US`)]).then(([t,n,r])=>{e||(i({current:t,fallback:n,english:r}),o(!0))}),document.documentElement.lang=t,document.documentElement.dir=t===`ar-SA`?`rtl`:`ltr`;try{localStorage.setItem(lt,t)}catch{}return()=>{e=!0}},[t]);let s=(0,O.useCallback)((e,t,n)=>{if(!e)return n??``;let i=ht(r.current,e)??ht(r.fallback,e)??ht(r.english,e);return i===void 0?n??e:N(i,t)},[r]),c=(0,O.useCallback)(e=>{e&&e!==t&&(o(!1),n(e),window.dispatchEvent(new CustomEvent(`csai:languagechange`,{detail:{lang:e}})))},[t]),l=(0,O.useMemo)(()=>({lang:t,t:s,ready:a,setLanguage:c}),[t,s,a,c]);return(0,M.jsx)(gt.Provider,{value:l,children:e})}function vt(){return(0,O.useContext)(gt)}function P(){return(0,O.useContext)(gt).t}var yt=`cyberstrike-theme`,bt=[`system`,`light`,`dark`];function xt(){try{let e=localStorage.getItem(yt);return bt.includes(e)?e:`system`}catch{return`system`}}function St(){return typeof window<`u`&&window.matchMedia?window.matchMedia(`(prefers-color-scheme: dark)`).matches:!1}function Ct(e){return e===`dark`||e===`light`?e:St()?`dark`:`light`}function wt(e){let t=Ct(e),n=document.documentElement;return n.setAttribute(`data-theme`,t),n.setAttribute(`data-theme-preference`,e),n.style.colorScheme=t,document.body?.setAttribute(`theme-mode`,t===`dark`?`dark`:`light`),t}var F=(0,O.createContext)({preference:`system`,theme:`light`,setPreference:()=>{},toggle:()=>{}});function Tt({children:e}){let[t,n]=(0,O.useState)(xt),[r,i]=(0,O.useState)(()=>Ct(xt()));(0,O.useLayoutEffect)(()=>{i(wt(t));try{localStorage.setItem(yt,t)}catch{}if(t!==`system`||!window.matchMedia)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>i(wt(t));return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[t]),(0,O.useEffect)(()=>{document.body?.setAttribute(`theme-mode`,r===`dark`?`dark`:`light`)},[r]);let a=(0,O.useCallback)(e=>{bt.includes(e)&&n(e)},[]),o=(0,O.useCallback)(()=>{n(e=>Ct(e)===`dark`?`light`:`dark`)},[]),s=(0,O.useMemo)(()=>({preference:t,theme:r,setPreference:a,toggle:o}),[t,r,a,o]);return(0,M.jsx)(F.Provider,{value:s,children:e})}function Et(){return(0,O.useContext)(F)}var Dt=[{id:`dashboard`,i18n:`nav.dashboard`,fallback:`仪表盘`,icon:S},{id:`chat`,i18n:`nav.chat`,fallback:`对话`,icon:Ne},{id:`deep-assessments`,i18n:`nav.deepAssessments`,fallback:`深度测评`,icon:t},{id:`security`,i18n:`nav.security`,fallback:`安全防护`,icon:me,anyPermission:[`hitl:read`,`config:read`],children:[{id:`hitl`,i18n:`nav.hitl`,fallback:`人机协同`,permission:`hitl:read`},{id:`tool-guard`,i18n:`nav.toolGuard`,fallback:`调用拦截`,permission:`config:read`}]},{id:`projects`,i18n:`nav.projects`,fallback:`项目管理`,icon:m},{id:`assets`,i18n:`nav.assets`,fallback:`资产管理`,icon:r,anyPermission:[`asset:read`,`fofa:execute`],children:[{id:`asset-overview`,i18n:`nav.assetOverview`,fallback:`资产概览`},{id:`asset-library`,i18n:`nav.assetLibrary`,fallback:`资产库`},{id:`info-collect`,i18n:`nav.infoCollect`,fallback:`信息收集`}]},{id:`vulnerabilities`,i18n:`nav.vulnerabilities`,fallback:`漏洞管理`,icon:me},{id:`tasks`,i18n:`nav.tasks`,fallback:`任务管理`,icon:g},{id:`workflows`,i18n:`nav.workflows`,fallback:`工作流`,icon:de},{id:`webshell`,i18n:`nav.webshell`,fallback:`WebShell管理`,icon:ve},{id:`c2`,i18n:`nav.c2`,fallback:`C2`,icon:fe,children:[{id:`c2-listeners`,i18n:`nav.c2Listeners`,fallback:`监听器`},{id:`c2-sessions`,i18n:`nav.c2Sessions`,fallback:`会话`},{id:`c2-tasks`,i18n:`nav.c2Tasks`,fallback:`任务`},{id:`c2-payloads`,i18n:`nav.c2Payloads`,fallback:`载荷`},{id:`c2-events`,i18n:`nav.c2Events`,fallback:`事件`},{id:`c2-profiles`,i18n:`nav.c2Profiles`,fallback:`流量伪装`}]},{id:`chat-files`,i18n:`nav.chatFiles`,fallback:`文件管理`,icon:be},{id:`plugin-hub`,i18n:`nav.pluginHub`,fallback:`能力平台`,icon:De,permission:`plugins:read`},{id:`mcp`,i18n:`nav.mcp`,fallback:`MCP`,icon:Oe,children:[{id:`mcp-monitor`,i18n:`nav.mcpMonitor`,fallback:`MCP状态监控`},{id:`mcp-management`,i18n:`nav.mcpManagement`,fallback:`MCP管理`}]},{id:`knowledge`,i18n:`nav.knowledge`,fallback:`知识`,icon:le,children:[{id:`knowledge-retrieval-logs`,i18n:`nav.knowledgeRetrievalLogs`,fallback:`检索历史`},{id:`knowledge-management`,i18n:`nav.knowledgeManagement`,fallback:`知识管理`}]},{id:`skills`,i18n:`nav.skills`,fallback:`技能`,icon:_e,children:[{id:`skills-monitor`,i18n:`nav.skillsMonitor`,fallback:`技能状态`},{id:`skills-management`,i18n:`nav.skillsManagement`,fallback:`技能管理`}]},{id:`agents`,i18n:`nav.agents`,fallback:`智能体`,icon:p,children:[{id:`agents-management`,i18n:`nav.agentsManagement`,fallback:`智能体管理`}]},{id:`roles`,i18n:`nav.roles`,fallback:`角色`,icon:ue,children:[{id:`roles-management`,i18n:`nav.rolesManagement`,fallback:`角色管理`}]},{id:`platform-rbac`,i18n:`nav.platformRbac`,fallback:`平台权限`,icon:ge},{id:`settings`,i18n:`nav.settings`,fallback:`系统设置`,icon:we},{id:`api-docs`,i18n:`apiDocs.title`,fallback:`API 文档`,icon:t}],Ot=[{id:`workspace`,i18n:`nav.groupWorkspace`,fallback:`工作台`,pages:[`dashboard`,`chat`,`deep-assessments`,`security`]},{id:`operations`,i18n:`nav.groupOperations`,fallback:`安全作业`,pages:[`projects`,`assets`,`vulnerabilities`,`tasks`,`workflows`,`webshell`,`c2`,`chat-files`]},{id:`capabilities`,i18n:`nav.groupCapabilities`,fallback:`能力中心`,pages:[`plugin-hub`,`mcp`,`knowledge`,`skills`,`agents`,`roles`]},{id:`platform`,i18n:`nav.groupPlatform`,fallback:`平台管理`,pages:[`platform-rbac`,`settings`,`api-docs`]}],kt=Dt.flatMap(e=>e.children?e.children.map(t=>({...t,parent:e.id})):[e]);function At(e){return kt.find(t=>t.id===e)||Dt.find(t=>t.id===e)||null}function jt(e){"@babel/helpers - typeof";return jt=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},jt(e)}function Mt(e,t){if(jt(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(jt(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Nt(e){var t=Mt(e,`string`);return jt(t)==`symbol`?t:t+``}function I(e,t,n){return(t=Nt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var Pt;function Ft(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var It=Ft();function Lt(e){It=e}var Rt={exec:()=>null};function L(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(R.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var zt=(()=>{try{return!0}catch{return!1}})(),R={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`)},Bt=/^(?:[ \t]*(?:\n|$))+/,Vt=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ht=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,z=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ut=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,B=/(?:[*+-]|\d{1,9}[.)])/,Wt=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Gt=L(Wt).replace(/bull/g,B).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),Kt=L(Wt).replace(/bull/g,B).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),qt=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Jt=/^[^\n]+/,Yt=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Xt=L(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,Yt).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Zt=L(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,B).getRegex(),Qt=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,$t=/|$))/,en=L(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|\\n*|$)|\\n*|$)|)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,$t).replace(`tag`,Qt).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),tn=L(qt).replace(`hr`,z).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Qt).getRegex(),nn={blockquote:L(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,tn).getRegex(),code:Vt,def:Xt,fences:Ht,heading:Ut,hr:z,html:en,lheading:Gt,list:Zt,newline:Bt,paragraph:tn,table:Rt,text:Jt},rn=L(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,z).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Qt).getRegex(),an={...nn,lheading:Kt,table:rn,paragraph:L(qt).replace(`hr`,z).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,rn).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)]) `).replace(`html`,`)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Qt).getRegex()},on={...nn,html:L(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+? *(?:\\n{2,}|\\s*$)|\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,$t).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Rt,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:L(qt).replace(`hr`,z).replace(`heading`,` *#{1,6} *[^ ]`).replace(`lheading`,Gt).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},sn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,cn=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ln=/^( {2,}|\\)\n(?!\s*$)/,un=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\`+)[^`]+\k(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,zt?"(?`+)[^`]+\k(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),yn=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,bn=L(yn,`u`).replace(/punct/g,dn).getRegex(),xn=L(yn,`u`).replace(/punct/g,hn).getRegex(),Sn=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,Cn=L(Sn,`gu`).replace(/notPunctSpace/g,pn).replace(/punctSpace/g,fn).replace(/punct/g,dn).getRegex(),wn=L(Sn,`gu`).replace(/notPunctSpace/g,_n).replace(/punctSpace/g,gn).replace(/punct/g,hn).getRegex(),Tn=L(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,pn).replace(/punctSpace/g,fn).replace(/punct/g,dn).getRegex(),En=L(/\\(punct)/,`gu`).replace(/punct/g,dn).getRegex(),Dn=L(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),On=L($t).replace(`(?:-->|$)`,`-->`).getRegex(),kn=L(`^comment|^|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^|^`).replace(`comment`,On).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),An=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,jn=L(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace(`label`,An).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Mn=L(/^!?\[(label)\]\[(ref)\]/).replace(`label`,An).replace(`ref`,Yt).getRegex(),Nn=L(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,Yt).getRegex(),Pn=L(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,Mn).replace(`nolink`,Nn).getRegex(),Fn=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,In={_backpedal:Rt,anyPunctuation:En,autolink:Dn,blockSkip:vn,br:ln,code:cn,del:Rt,emStrongLDelim:bn,emStrongRDelimAst:Cn,emStrongRDelimUnd:Tn,escape:sn,link:jn,nolink:Nn,punctuation:mn,reflink:Mn,reflinkSearch:Pn,tag:kn,text:un,url:Rt},Ln={...In,link:L(/^!?\[(label)\]\((.*?)\)/).replace(`label`,An).getRegex(),reflink:L(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,An).getRegex()},Rn={...In,emStrongRDelimAst:wn,emStrongLDelim:xn,url:L(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,Fn).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:L(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\":`>`,'"':`"`,"'":`'`},Un=e=>Hn[e];function V(e,t){if(t){if(R.escapeTest.test(e))return e.replace(R.escapeReplace,Un)}else if(R.escapeTestNoEncode.test(e))return e.replace(R.escapeReplaceNoEncode,Un);return e}function Wn(e){try{e=encodeURI(e).replace(R.percentDecode,`%`)}catch{return null}return e}function Gn(e,t){let n=e.replace(R.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(R.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t){if(n.length>t)n.splice(t);else for(;n.length0?-2:-1}function Jn(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function Yn(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(` @@ -61,4 +61,4 @@ ${e} `+this.renderer.text(i);n+=t?this.renderer.paragraph({type:`paragraph`,raw:o,text:o,tokens:[{type:`text`,raw:o,text:o,escaped:!0}]}):o;continue}default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}parseInline(e,t=this.renderer){let n=``;for(let r=0;r{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new Zn(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new Xn(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new $n;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=$n.passThroughHooks.has(n)?e=>{if(this.defaults.async&&$n.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return H.lex(e,t??this.defaults)}parser(e,t){return U.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer():e?H.lex:H.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser():e?U.parse:U.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer():e?H.lex:H.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser():e?U.parse:U.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=` Please report this to https://github.com/markedjs/marked.`,e){let e=`

An error occurred:

`+V(n.message+``,!0)+`
`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function W(e,t){return er.parse(e,t)}W.options=W.setOptions=function(e){return er.setOptions(e),W.defaults=er.defaults,Lt(W.defaults),W},W.getDefaults=Ft,W.defaults=It,W.use=function(...e){return er.use(...e),W.defaults=er.defaults,Lt(W.defaults),W},W.walkTokens=function(e,t){return er.walkTokens(e,t)},W.parseInline=er.parseInline,W.Parser=U,W.parser=U.parse,W.Renderer=Zn,W.TextRenderer=Qn,W.Lexer=H,W.lexer=H.lex,W.Tokenizer=Xn,W.Hooks=$n,W.parse=W,W.options,W.setOptions,W.use,W.walkTokens,W.parseInline,U.parse,H.lex;function tr(e,t){this.v=e,this.k=t}function nr(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`?null:Y(BigInt.prototype.toString),Rr=typeof Symbol>`u`?null:Y(Symbol.prototype.toString),q=Y(Object.prototype.hasOwnProperty),zr=Y(Object.prototype.toString),Br=RegExp.prototype.test,J=function(e,t){return e instanceof RegExp&&(e.lastIndex=0),_r(Br,e,[t])},Vr=Hr(TypeError);function Y(e){return function(t){var n=[...arguments].slice(1);return _r(e,t,n)}}function Hr(e){return function(){return vr(e,[...arguments])}}function X(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:kr;if(dr&&dr(e,null),!Tr(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(fr(t)||(t[r]=e),i=e)}e[i]=!0}return e}function Ur(e){for(let t=0;t/g),ci=K(/\${[\w\W]*/g),li=K(/{{|}}|\${|<%|%>|<%|%>/),ui=K(/^data-[\-\w.\u00B7-\uFFFF]+$/),di=K(/^aria-[\-\w]+$/),fi=K(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),pi=K(/^(?:\w+script|data):/i),mi=K(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),hi=K(/^html$/i),gi=K(/^[a-z][.\w]*(-[.\w]+)+$/i),_i=K(/<[/\w!]/g),vi=K(/<[/\w]/g),yi=K(/<\/no(script|embed|frames)/i),bi=K(/\/>/i),xi=K(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i),Si=K(/^[\r\n\t ]+/),Q={element:1,text:3,processingInstruction:7,comment:8,document:9,documentFragment:11},Ci=G(X({},[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`])),wi=function(){return typeof window>`u`?null:window},Ti=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},Ei=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Di=function(e,t,n,r){return q(e,t)&&Tr(e[t])?X(r.base?Gr(r.base):{},e[t],r.transform):n},Oi=function(e,t,n){let r=q(e,t)?e[t]:void 0;return r&&typeof r==`object`?Wr(r):n};function ki(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:wi(),t=e=>ki(e);if(t.version=`3.4.18`,t.removed=[],!e||!e.document||e.document.nodeType!==Q.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript,a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter,l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=Z(d,`cloneNode`),p=Z(d,`remove`),m=Z(d,`removeAttributeNode`),h=Z(d,`nextSibling`),g=Z(d,`childNodes`),_=Z(d,`parentNode`),ee=Z(d,`shadowRoot`),te=Z(d,`attributes`),ne=o&&o.prototype?Z(o.prototype,`nodeType`):null,v=o&&o.prototype?Z(o.prototype,`nodeName`):null,y=o&&o.prototype?Z(o.prototype,`ownerDocument`):null,b=function(e){return ne?ne(e):e.nodeType},x=function(e){return v?v(e):e.nodeName},re=qr(d,`namespaceURI`),ie=function(e){return re?re(e):e.namespaceURI};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let S,ae=``,oe,se=!1,ce=0,le=function(){if(ce>0)throw Vr(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},ue=function(e){le(),ce++;try{return S.createHTML(e)}finally{ce--}},de=function(e){return S&&Ge?ue(e):e},fe=function(e){le(),ce++;try{return S.createScriptURL(e)}finally{ce--}},pe=function(){return se||(oe=Ti(u,i),se=!0),oe},me=n,he=me.implementation,ge=me.createNodeIterator,_e=me.createDocumentFragment,ve=me.getElementsByTagName,ye=r.importNode,C=Ei();t.isSupported=typeof lr==`function`&&typeof _==`function`&&he&&he.createHTMLDocument!==void 0;let be=oi,xe=si,Se=ci,Ce=ui,we=di,Te=pi,Ee=mi,De=gi,Oe=fi,w=null,ke=X({},[...Yr,...Xr,...Zr,...$r,...ti]),T=null,Ae=X({},[...ni,...ri,...ii,...ai]),E=null,je=null,Me=null,Ne=Object.seal(hr(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),Pe=!0,Fe=!0,Ie=!1,Le=!0,D=!1,Re=!0,ze=!1,Be=!1,Ve=null,He=null,Ue=!1,O=!1,We=!1,Ge=!1,Ke=!0,qe=!1,Je=`user-content-`,Ye=!0,Xe=!1,Ze=null,Qe=!1,k=null,$e=X({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),et=null,A=X({},[`audio`,`video`,`img`,`source`,`image`,`track`]),j=null,tt=X({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),nt=`http://www.w3.org/1998/Math/MathML`,rt=`http://www.w3.org/2000/svg`,M=`http://www.w3.org/1999/xhtml`,it=M,at=!1,ot=null,st=X({},[nt,rt,M],Ar),ct=G(X({},[`mi`,`mo`,`mn`,`ms`,`mtext`])),lt=null,ut=G(X({},[`annotation-xml`])),dt=null,ft=G(hr(null)),pt=X({},[`title`,`style`,`font`,`a`,`script`]),mt=null,ht=[`application/xhtml+xml`,`text/html`],N=null,gt=null,_t=n.createElement(`form`),vt=function(e){return e instanceof RegExp||e instanceof Function},P=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};e&&typeof e==`object`||(e={}),e=Wr(e),mt=ht.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,N=mt===`application/xhtml+xml`?Ar:kr,w=Di(e,`ALLOWED_TAGS`,ke,{transform:N}),T=Di(e,`ALLOWED_ATTR`,Ae,{transform:N}),ot=Di(e,`ALLOWED_NAMESPACES`,st,{transform:Ar}),j=Di(e,`ADD_URI_SAFE_ATTR`,tt,{transform:N,base:tt}),et=Di(e,`ADD_DATA_URI_TAGS`,A,{transform:N,base:A}),k=Di(e,`FORBID_CONTENTS`,$e,{transform:N}),je=Di(e,`FORBID_TAGS`,hr(null),{transform:N}),Me=Di(e,`FORBID_ATTR`,hr(null),{transform:N}),Qe=q(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?Wr(e.USE_PROFILES):e.USE_PROFILES:!1,Pe=e.ALLOW_ARIA_ATTR!==!1,Fe=e.ALLOW_DATA_ATTR!==!1,Ie=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Le=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,D=e.SAFE_FOR_TEMPLATES||!1,Re=e.SAFE_FOR_XML!==!1,ze=e.WHOLE_DOCUMENT||!1,O=e.RETURN_DOM||!1,We=e.RETURN_DOM_FRAGMENT||!1,Ge=e.RETURN_TRUSTED_TYPE||!1,Ue=e.FORCE_BODY||!1,Ke=e.SANITIZE_DOM!==!1,qe=e.SANITIZE_NAMED_PROPS||!1,Ye=e.KEEP_CONTENT!==!1,Xe=e.IN_PLACE||!1,Oe=Jr(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:fi,it=typeof e.NAMESPACE==`string`?e.NAMESPACE:M,lt=Oi(e,`MATHML_TEXT_INTEGRATION_POINTS`,ct),dt=Oi(e,`HTML_INTEGRATION_POINTS`,ut);let t=Oi(e,`CUSTOM_ELEMENT_HANDLING`,ft);if(E=hr(null),q(t,`tagNameCheck`)&&vt(t.tagNameCheck)&&(E.tagNameCheck=t.tagNameCheck),q(t,`attributeNameCheck`)&&vt(t.attributeNameCheck)&&(E.attributeNameCheck=t.attributeNameCheck),q(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(E.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),K(E),D&&(Fe=!1),We&&(O=!0),Qe&&((q(e,`ALLOWED_TAGS`)||q(e,`ALLOWED_ATTR`))&&typeof console<`u`&&typeof console.warn==`function`&&console.warn(`DOMPurify: USE_PROFILES overrides ALLOWED_TAGS and ALLOWED_ATTR. Do not use these options together.`),w=X({},ti),T=hr(null),Qe.html===!0&&(X(w,Yr),X(T,ni)),Qe.svg===!0&&(X(w,Xr),X(T,ri),X(T,ai)),Qe.svgFilters===!0&&(X(w,Zr),X(T,ri),X(T,ai)),Qe.mathMl===!0&&(X(w,$r),X(T,ii),X(T,ai))),Ne.tagCheck=null,Ne.attributeCheck=null,q(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?Ne.tagCheck=e.ADD_TAGS:Tr(e.ADD_TAGS)&&(w===ke&&(w=Gr(w)),X(w,e.ADD_TAGS,N))),q(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?Ne.attributeCheck=e.ADD_ATTR:Tr(e.ADD_ATTR)&&(T===Ae&&(T=Gr(T)),X(T,e.ADD_ATTR,N))),q(e,`ADD_FORBID_CONTENTS`)&&Tr(e.ADD_FORBID_CONTENTS)&&(k===$e&&(k=Gr(k)),X(k,e.ADD_FORBID_CONTENTS,N)),Ye&&(w[`#text`]=!0),ze&&X(w,[`html`,`head`,`body`]),w.table&&(w.tbody=!0,delete je.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw Vr(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw Vr(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=S;S=e.TRUSTED_TYPES_POLICY;try{ae=ue(``)}catch(e){throw S=t,e}}else e.TRUSTED_TYPES_POLICY===null?(S=void 0,ae=``):(S===void 0&&(S=pe()),S&&typeof ae==`string`&&(ae=ue(``)));gt=G(e)},yt=X({},[...Xr,...Zr,...Qr]),bt=X({},[...$r,...ei]),xt=function(e,t,n){return t===M?e===`svg`:t===nt?e===`svg`&&(n===`annotation-xml`||lt[n]):!!yt[e]},St=function(e,t,n){return t===M?e===`math`:t===rt?e===`math`&&dt[n]:!!bt[e]},Ct=function(e,t,n){return t===rt&&!dt[n]||t===nt&&!lt[n]?!1:!bt[e]&&(pt[e]||!yt[e])},wt=function(e){let t=ie(e),n=kr(x(e)),r=_(e),i=it,a=`template`;return r&&b(r)===Q.element&&(i=ie(r),a=kr(x(r))),ot[t]?t===rt?xt(n,i,a):t===nt?St(n,i,a):t===M?Ct(n,i,a):mt===`application/xhtml+xml`:!1},F=function(e){Sr(t.removed,{element:e});try{_(e).removeChild(e)}catch{if(p(e),!_(e))throw Vr(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},Tt=function(e,t,n){try{m(e,t)}catch{try{e.removeAttribute(n)}catch{}}},Et=function(e){At(e);let t=g(e);t&&yr(Cr(t),e=>{try{p(e)}catch{}}),b(e)===Q.element&&Ot(e,!1)},Dt=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}if(Sr(t.removed,{attribute:r||null,from:n}),r)Tt(n,r,e);else try{n.removeAttribute(e)}catch{}if(e===`is`){if(O||We)try{F(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},Ot=function(e,t){let n=te(e);if(n)for(let r=n.length-1;r>=0;--r){let i=n[r],a=i&&i.name;typeof a==`string`&&!(t&&T[N(a)])&&Tt(e,i,a)}},kt=function(e,t){let n=arguments.length>2&&arguments[2]!==void 0&&arguments[2],r=[e];for(;r.length>0;){let e=r.pop();if(t(e)===!1)continue;if(n&&b(e)===Q.element){let t=ee(e);z(t)&&r.push(t)}let i=g(e);if(i)for(let e=i.length-1;e>=0;--e)r.push(i[e])}},At=function(e){kt(e,e=>{b(e)===Q.element&&Ot(e,!0)})},jt=function(e){let t=[];return kt(e,e=>{t.push(e)},!0),t},Mt=function(e,t){let n=Er();yr(jt(e),e=>{b(e)===Q.element&&Dr(n,e)}),yr(t,e=>{b(e)===Q.element&&!Or(n,e)&&Ot(e,!0)})},Nt=function(e,n){let r=!1;return yr(t.removed,t=>{t.element&&(r=r||t.element===e,At(t.element))}),Mt(e,n),r},I=function(e,t){let n=Ze,r=null,i=()=>(r||(r=Er(),yr(t,e=>{Dr(r,e)})),r);for(let t=0;;t++){let r=jt(e),a=[e],o=!1;if(yr(r,e=>{b(e)===Q.documentFragment?Sr(a,e):!o&&!Or(n,e)&&(o=Or(i(),e))}),!o)return;if(t>=8)throw Vr(`the tree kept changing during in-place sanitization; refusing to return it`);yr(a,(t,n)=>{Pt(t,n>0,e,i())})}},Pt=function(e,t,n,r){let i=L(e),a;for(;a=i.nextNode();)Or(r,a)&&!Or(Ze,a)&&(t&&B(C.uponSanitizeShadowNode,a,null),rn(a,n))},Ft=function(e){Ze&&Dr(Ze,e)},It=function(e,t){return Re?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},Lt=function(e){Re&&kt(e,e=>{let t=b(e);if(t===Q.processingInstruction||t===Q.comment&&J(vi,e.data)){try{p(e)}catch{}return!1}if(t===Q.element){let t=e,n=N(x(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&It(`for`,n)&&t.removeAttribute(`for`)}catch{}}return!0})},Rt=function(e){let t=null,r=null;if(Ue)e=``+e;else{let t=jr(e,Si);r=t&&t[0]}mt===`application/xhtml+xml`&&it===M&&(e=``+e+``);let i=S?ue(e):e;if(it===M)try{t=new l().parseFromString(i,mt)}catch{}if(!t||!t.documentElement){t=he.createDocument(it,`template`,null);try{t.documentElement.innerHTML=at?ae:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),it===M?ve.call(t,ze?`html`:`body`)[0]:ze?t.documentElement:a},L=function(e){let t=arguments.length>1&&arguments[1]!==void 0&&arguments[1],n=y?y(e):e.ownerDocument;return ge.call(n||e,e,(t?0:c.SHOW_ELEMENT)|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},zt=function(e){return e=Mr(e,be,` `),e=Mr(e,xe,` `),e=Mr(e,Se,` `),e},R=function(e){Bt(e);let t=e.querySelectorAll?.call(e,`template`);t&&yr(t,e=>{z(e.content)&&R(e.content)})},Bt=function(e){e.normalize();let t=L(e,!0),n=t.nextNode();for(;n;)n.data=zt(n.data),n=t.nextNode()},Vt=function(e){let t=v?v(e):null;return typeof t!=`string`||N(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==te(e)||typeof e.removeAttribute!=`function`||typeof e.removeAttributeNode!=`function`||typeof e.getAttributeNode!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==ne(e)||e.childNodes!==g(e)},Ht=function(e){if(!ne||typeof e!=`object`||!e)return null;try{let t=ne(e);return typeof t==`number`?t:null}catch{return null}},z=function(e){return Ht(e)===Q.documentFragment},Ut=function(e){return Ht(e)!==null};function B(e,n,r){e.length!==0&&yr(e,e=>{e.call(t,n,r,gt)})}let Wt=function(e,t,n){return!!(Re&&n===Q.element&&e.hasChildNodes()&&!Ut(e.firstElementChild)&&J(_i,e.textContent)&&J(_i,e.innerHTML)||Re&&Ci[t]&&n===Q.element&&ie(e)===M&&(Ut(e.firstElementChild)||typeof e.textContent==`string`&&J(_i,e.textContent))||n===Q.processingInstruction||Re&&n===Q.comment&&J(vi,e.data))},Gt=function(e,t){return e instanceof RegExp?J(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},Kt=function(e,t,n){if(!je[t]&&Qt(t)&&Gt(E.tagNameCheck,t))return!1;if(Ye&&!k[t]&&!k[kr(t)]){let t=_(e),r=g(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,h(e))}}}return F(e),!0},qt=function(e,t,n,r){return e.length===0?t:t===n||t===r?Gr(t):t},Jt=function(e,t){return e===t||_(e)!==null?!1:(Xe&&At(e),!0)},Yt=function(e,n){if(Ft(e),B(C.beforeSanitizeElements,e,null),Jt(e,n))return!0;if(Vt(e))return F(e),!0;let r=N(x(e)),i=b(e);if(w=qt(C.uponSanitizeElement,w,ke,Ve),B(C.uponSanitizeElement,e,{tagName:r,allowedTags:w}),Jt(e,n))return!0;if(Wt(e,r,i))return F(e),!0;if(je[r]||!(Ne.tagCheck instanceof Function&&Ne.tagCheck(r))&&!w[r]){let t=Kt(e,r,n);return t===!1&&(B(C.afterSanitizeElements,e,null),Jt(e,n))?!0:t}if(i===Q.element&&!wt(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&J(yi,e.innerHTML))return F(e),!0;if(D&&i===Q.text){let n=e.textContent,r=zt(n);n!==r&&(Sr(t.removed,{element:e.cloneNode()}),e.textContent=r)}return B(C.afterSanitizeElements,e,null),Jt(e,n)},Xt=function(e,t,r){if(Me[t]||It(t,e)||Ke&&(t===`id`||t===`name`)&&(r in n||r in _t))return!1;let i=T[t]||Ne.attributeCheck instanceof Function&&Ne.attributeCheck(t,e);if(Fe&&J(Ce,t)||Pe&&J(we,t))return!0;if(!i)return Qt(e)&&Gt(E.tagNameCheck,e)&&Gt(E.attributeNameCheck,t,e)||t===`is`&&E.allowCustomizedBuiltInElements&&Gt(E.tagNameCheck,r);if(j[t])return!0;let a=Mr(r,Ee,``);return J(Oe,a)||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&Nr(r,`data:`)===0&&et[e]||Ie&&!J(Te,a)?!0:!r},Zt=X({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Qt=function(e){return!Zt[kr(e)]&&J(De,e)},$t=function(e,t,n,r){if(S&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return ue(r);case`TrustedScriptURL`:return fe(r)}return r},en=function(e,t,n,r){try{return n?e.setAttributeNS(n,t,r):e.setAttribute(t,r),!Vt(e)||(F(e),!1)}catch{return Dt(t,e),!1}},tn=function(e,t){return Re&&J(xi,t)?!0:kr(e)===`attributename`&&Nr(t,`href`)!==-1},nn=function(e,n){if(B(C.beforeSanitizeAttributes,e,null),Jt(e,n))return;let r=e.attributes;if(!r||Vt(e))return;T=qt(C.uponSanitizeAttribute,T,Ae,He);let i={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:T,forceKeepAttr:void 0},a=r.length,o=N(x(e));for(;a--;){let n=r[a],s=n.name,c=n.namespaceURI,l=n.value,u=N(s),d=l,f=s===`value`?d:Pr(d),p=!1;i.attrName=u,i.attrValue=f,i.keepAttr=!0,i.forceKeepAttr=void 0,B(C.uponSanitizeAttribute,e,i),f=i.attrValue,qe&&(u===`id`||u===`name`)&&Nr(f,Je)!==0&&(Dt(s,e,n),f=Je+f,p=!0),tn(s,f)?Dt(s,e,n):i.forceKeepAttr||(i.keepAttr?!Le&&J(bi,f)?Dt(s,e,n):(D&&(f=zt(f)),Xt(o,u,f)?(f=$t(o,u,c,f),f!==d&&en(e,s,c,f)&&p&&xr(t.removed)):Dt(s,e,n)):Dt(s,e,n))}B(C.afterSanitizeAttributes,e,null),Jt(e,n)},rn=function(e,t){Yt(e,t),nn(e,t),z(e.content)&&an(e.content)},an=function(e){let t=null,n=L(e);for(B(C.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(B(C.uponSanitizeShadowNode,t,null),rn(t,e),b(t)===Q.element){let e=ee(t);z(e)&&(on(e),an(e))}D&&Bt(e),B(C.afterSanitizeShadowDOM,e,null)},on=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){an(e.shadow);continue}let n=e.node,r=b(n)===Q.element,i=g(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=v?v(n):null;if(typeof e==`string`&&N(e)===`template`){let e=n.content;z(e)&&t.push({node:e,shadow:null})}}if(r){let e=ee(n);z(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(at=!e,at&&(e=``),typeof e!=`string`&&!Ut(e)&&(e=Kr(e),typeof e!=`string`))throw Vr(`dirty is not a string, aborting`);if(!t.isSupported)return e;Be?(w=Ve,T=He):P(n),t.removed=[];let c=Xe&&typeof e!=`string`&&Ut(e),l=[],u=Ze;if(c){Lt(e);let t=x(e);if(typeof t==`string`){let n=N(t);if(!w[n]||je[n])throw Et(e),Vr(`root node is forbidden and cannot be sanitized in-place`)}if(Vt(e))throw Et(e),Vr(`root node is clobbered and cannot be sanitized in-place`);l=jt(e),Ze=Er()}else if(Ut(e))i=Rt(``),a=i.ownerDocument.importNode(e,!0),a.nodeType===Q.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),on(i);else{if(!O&&!D&&!ze&&e.indexOf(`<`)===-1)return de(e);if(i=Rt(e),!i)return O?null:Ge?ae:``}i&&Ue&&F(i.firstChild);let d=c?e:i;try{c&&on(e);let t=L(d);for(;o=t.nextNode();)rn(o,d);c&&I(e,l)}catch(t){throw c&&(Et(e),Nt(e,l)),t}finally{Ze=u}if(c){if(Nt(e,l))throw Vr(`a node selected for removal could not be safely returned; refusing to sanitize in place`);return D&&R(e),e}if(O){if(D&&R(i),We)for(s=_e.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(T.shadowroot||T.shadowrootmode)&&(s=ye.call(r,s,!0)),s}let f=()=>ze?i.outerHTML:i.innerHTML,p=f();return D&&J(li,p)&&(Bt(i),p=f()),ze&&w[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&J(hi,i.ownerDocument.doctype.name)&&(p=` -`+p),de(p)},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};P(e),Be=!0,Ve=w,He=T},t.clearConfig=function(){gt=null,Be=!1,Ve=null,He=null,S=oe,ae=``},t.isValidAttribute=function(e,t,n){gt||P({});let r=N(e),i=N(t);return typeof n==`string`&&(tn(t,n)||!Le&&J(bi,n))?!1:Xt(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&q(C,e)&&Sr(C[e],t)},t.removeHook=function(e,t){if(q(C,e)){if(t!==void 0){let n=br(C[e],t);return n===-1?void 0:wr(C[e],n,1)[0]}return xr(C[e])}},t.removeHooks=function(e){q(C,e)&&(C[e]=[])},t.removeAllHooks=function(){C=Ei()},t}var Ai=ki(),ji=[`critical`,`high`,`medium`,`low`,`info`],Mi={critical:`red`,high:`orange`,medium:`amber`,low:`blue`,info:`grey`},Ni={critical:`严重`,high:`高危`,medium:`中危`,low:`低危`,info:`信息`},Pi={running:`blue`,pending:`amber`,queued:`amber`,paused:`grey`,success:`green`,succeeded:`green`,completed:`green`,done:`green`,failed:`red`,error:`red`,cancelled:`grey`,canceled:`grey`,stopped:`grey`,active:`green`,inactive:`grey`,online:`green`,offline:`grey`,open:`red`,closed:`green`,archived:`grey`};function Fi(e,t=`zh-CN`){if(!e)return`—`;let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.getTime())?n.toLocaleString(t,{hour12:!1}):`—`}function Ii(e,t=`zh-CN`){if(!e)return`—`;let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.getTime())?n.toLocaleDateString(t):`—`}function Li(e,t=`zh-CN`){if(!e)return`—`;let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.getTime())?n.toLocaleTimeString(t,{hour12:!1}):`—`}function Ri(e,t){if(!e)return`—`;let n=new Date(e);if(!Number.isFinite(n.getTime()))return`—`;let r=Date.now()-n.getTime();return r<6e4?t?.(`common.justNow`,null,`刚刚`)||`刚刚`:r<36e5?t?.(`common.minutesAgo`,{n:Math.floor(r/6e4)},`${Math.floor(r/6e4)} 分钟前`):r<864e5?t?.(`common.hoursAgo`,{n:Math.floor(r/36e5)},`${Math.floor(r/36e5)} 小时前`):r<2592e6?t?.(`common.daysAgo`,{n:Math.floor(r/864e5)},`${Math.floor(r/864e5)} 天前`):Ii(e)}function zi(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return`—`;if(t<1024)return`${t} B`;let n=[`KB`,`MB`,`GB`,`TB`],r=t/1024,i=0;for(;r>=1024&&i=100?0:1)} ${n[i]}`}function Bi(e,t=`zh-CN`){let n=Number(e);return Number.isFinite(n)?n.toLocaleString(t):`—`}function Vi(e,t=1){let n=Number(e);return Number.isFinite(n)?`${(n*(n<=1?100:1)).toFixed(t)}%`:`—`}function Hi(e){return Mi[String(e||``).toLowerCase()]||`grey`}function Ui(e){return Pi[String(e||``).toLowerCase()]||`grey`}function Wi(e,t=120){let n=String(e??``);return n.length>t?`${n.slice(0,t)}…`:n}var{Title:Gi,Text:Ki,Paragraph:qi}=c;function Ji(e){Ce.success({content:e,duration:2})}function Yi(e){Ce.warning({content:e,duration:3})}function Xi(e,t=`操作失败`){Ce.error({content:rt(e,t),duration:4})}function Zi({title:e,description:t,extra:n,children:r}){return(0,M.jsxs)(`header`,{className:`cs-page-header`,children:[(0,M.jsxs)(`div`,{className:`cs-page-header-main`,children:[(0,M.jsx)(Gi,{heading:3,className:`cs-page-title`,children:e}),t&&(0,M.jsx)(Ki,{type:`tertiary`,className:`cs-page-desc`,children:t}),r]}),n&&(0,M.jsx)(f,{className:`cs-page-header-extra`,wrap:!0,children:n})]})}function Qi({title:e,description:t,extra:n,children:r,className:i=``,bodyClassName:a=``}){return(0,M.jsxs)(s,{className:`cs-section-card ${i}`,title:e?(0,M.jsx)(`span`,{className:`cs-section-title`,children:e}):void 0,headerExtraContent:n,bordered:!1,children:[t&&(0,M.jsx)(qi,{type:`tertiary`,className:`cs-section-desc`,children:t}),(0,M.jsx)(`div`,{className:a,children:r})]})}function $i({metrics:e,columns:t=4}){return(0,M.jsx)(`div`,{className:`cs-stat-grid`,style:{"--cs-stat-columns":t},children:e.map(e=>(0,M.jsx)(ea,{...e},e.id||e.label))})}function ea({label:e,value:t,valueTitle:n,detail:r,tone:i,severity:a,icon:o,onClick:c,pressed:l,loading:u=!1}){let d=(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`span`,{className:`cs-stat-head`,children:[(0,M.jsx)(Ki,{type:`tertiary`,className:`cs-stat-label`,children:e}),o&&(0,M.jsx)(`span`,{className:`cs-stat-icon ${i?`tone-${i}`:``}`,"aria-hidden":`true`,children:o})]}),(0,M.jsx)(_,{loading:u,placeholder:(0,M.jsx)(_.Title,{style:{width:`60%`,height:36,margin:`8px 0`}}),children:(0,M.jsx)(`span`,{className:`cs-stat-value ${i?`tone-${i}`:``}`,title:n,children:t??`—`})}),r&&(0,M.jsx)(`span`,{className:`cs-stat-detail`,children:r})]});return c?(0,M.jsx)(b,{className:`cs-stat-card is-clickable`,theme:`borderless`,onClick:c,"aria-label":String(e),"aria-pressed":l,"data-severity":a,children:d}):(0,M.jsx)(s,{className:`cs-stat-card`,"data-severity":a,bordered:!1,children:d})}function ta({columns:e,dataSource:t,rowKey:n=`id`,loading:r,pagination:i,emptyText:a,onRefresh:s,toolbar:c,size:l=`default`,className:u=``,...d}){let f=P(),p=i!==!1&&{pageSize:10,showSizeChanger:!0,pageSizeOpts:[10,20,50,100],showTotal:!0,...i||{}};return(0,M.jsxs)(`div`,{className:`cs-table-wrap ${u}`,children:[(c||s)&&(0,M.jsxs)(`div`,{className:`cs-table-toolbar`,children:[(0,M.jsx)(`div`,{className:`cs-table-toolbar-main`,children:c}),s&&(0,M.jsx)(b,{icon:(0,M.jsx)(T,{}),theme:`borderless`,onClick:s,loading:r,children:f(`common.refresh`,null,`刷新`)})]}),(0,M.jsx)(`div`,{className:`cs-table-scroll`,children:(0,M.jsx)(ke,{columns:e,dataSource:t||[],rowKey:n,loading:r,pagination:p,size:l,empty:(0,M.jsx)(o,{image:(0,M.jsx)(je,{size:`extra-large`}),title:a||f(`common.noData`,null,`暂无数据`),description:null,className:`cs-table-empty`}),...d})})]})}function na({error:e,onRetry:t}){let n=P();return e?(0,M.jsx)(i,{type:`danger`,bordered:!0,closeIcon:null,className:`cs-error-banner`,description:(0,M.jsxs)(f,{wrap:!0,children:[(0,M.jsx)(`span`,{children:rt(e,n(`common.loadFailed`,null,`加载失败`))}),t&&(0,M.jsx)(b,{size:`small`,onClick:t,children:n(`common.refresh`,null,`刷新`)})]})}):null}function ra({severity:e,size:t=`small`}){let n=String(e||``).toLowerCase();return(0,M.jsx)(te,{size:t,color:Hi(n),shape:`circle`,className:`cs-severity-tag`,"data-severity":ji.includes(n)?n:void 0,children:Ni[n]||e||`—`})}function ia({status:e,label:t,size:n=`small`}){let r=String(e||``).toLowerCase();return(0,M.jsx)(te,{size:n,color:Ui(r),shape:`square`,children:t||e||`—`})}function aa({text:e,label:t,size:n=`default`,theme:r=`borderless`}){let i=P();return(0,M.jsx)(b,{size:n,theme:r,icon:(0,M.jsx)(x,{}),"aria-label":t||i(`common.copy`,null,`复制`),onClick:async()=>{try{await navigator.clipboard.writeText(String(e??``)),Ji(i(`common.copied`,null,`已复制`))}catch(e){Xi(e,i(`common.copyFailed`,null,`复制失败`))}},children:t})}function oa({content:e,className:t=``}){let n=(0,O.useMemo)(()=>{let t=W.parse(String(e??``),{breaks:!0,gfm:!0});return Ai.sanitize(t,{ADD_ATTR:[`target`,`rel`]})},[e]);return(0,M.jsx)(`div`,{className:`cs-markdown ${t}`,dangerouslySetInnerHTML:{__html:n}})}function sa({value:e,collapsed:t=!1,title:n}){let[r,i]=(0,O.useState)(!t),a=P(),o=(0,O.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]);return(0,M.jsxs)(`div`,{className:`cs-json-viewer`,children:[(0,M.jsxs)(`div`,{className:`cs-json-viewer-head`,children:[(0,M.jsx)(Ki,{strong:!0,children:n||`JSON`}),(0,M.jsxs)(f,{spacing:4,children:[(0,M.jsx)(aa,{text:o}),(0,M.jsx)(b,{theme:`borderless`,size:`small`,icon:r?(0,M.jsx)(d,{}):(0,M.jsx)(l,{}),"aria-expanded":r,"aria-label":a(r?`common.collapse`:`common.expand`,null,r?`收起`:`展开`),onClick:()=>i(e=>!e)})]})]}),(0,M.jsx)(ee,{isOpen:r,children:(0,M.jsx)(`pre`,{className:`cs-json-viewer-body`,children:o})})]})}function ca({items:e,columns:t=2}){return(0,M.jsx)(v,{className:`cs-description-list`,layout:`horizontal`,align:`plain`,column:t,data:e.filter(Boolean).map(e=>({key:e.label,value:e.value??`—`}))})}function la({title:e,content:t,okText:n,danger:r=!0,onOk:i}){ie.confirm({title:e,content:t,okText:n||`确定`,cancelText:`取消`,okButtonProps:r?{type:`danger`}:void 0,onOk:i})}var ua=`a[href], button, input, select, textarea, iframe, [tabindex], [contenteditable="true"]`;function da({title:e,visible:t,onCancel:n,width:r=560,footer:i,children:a,className:o,closeOnEsc:s=!0,mask:c=!0,maskClosable:l=!0,onOk:u,formId:d,okText:f,cancelText:p,okButtonProps:m,cancelButtonProps:h,confirmLoading:g,..._}){let ee=P(),te=(0,O.useRef)(null),[ne,v]=(0,O.useState)(!1),y=g??ne,x=(0,O.useCallback)(e=>{let t=e?.closest(`[role="dialog"]`);if(!t)return;te.current=t;let n=document.activeElement;return c&&(t.setAttribute(`aria-modal`,`true`),queueMicrotask(()=>{te.current===t&&!t.contains(document.activeElement)&&t.focus({preventScroll:!0})})),()=>{if(te.current=null,!c)return;t.removeAttribute(`aria-modal`);let e=document.activeElement;n?.isConnected&&(t.contains(e)||e===document.body)&&n.focus({preventScroll:!0})}},[c]);(0,O.useEffect)(()=>{if(!t)return;let e=e=>{let t=te.current,r=document.activeElement;if(e.defaultPrevented||!t?.contains(r)||(e.key===`Escape`&&s&&n&&(e.preventDefault(),n(e)),e.key!==`Tab`||!c))return;let i=[...t.querySelectorAll(ua)].filter(e=>e.tabIndex>=0&&!e.matches(`:disabled`)&&e.getClientRects().length),a=i[0],o=i.at(-1);(!a||(e.shiftKey?r===a||r===t:r===o))&&(e.preventDefault(),(e.shiftKey?o:a)?.focus())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s,c,n,t]);let re=e=>{if(y)return;let t=u?.(e);if(g===void 0&&typeof t?.then==`function`){v(!0);let e=()=>v(!1);Promise.resolve(t).then(e,e)}},ie=i===void 0&&(u||d)?(0,M.jsxs)(M.Fragment,{children:[n&&(0,M.jsx)(b,{type:`tertiary`,onClick:n,...h,children:p||ee(`common.cancel`,null,`取消`)}),(0,M.jsx)(b,{theme:`solid`,type:`primary`,...m,loading:y,disabled:y||m?.disabled,onClick:d?void 0:re,form:d,htmlType:d?`submit`:`button`,children:f||ee(`common.ok`,null,`确定`)})]}):i;return(0,M.jsxs)(Te,{title:e,visible:t,onCancel:n,width:r,footer:ie,mask:c,maskClosable:l&&!y,closeOnEsc:!1,className:`cs-drawer ${o||``}`,"aria-label":typeof e==`string`?e:void 0,..._,children:[(0,M.jsx)(`span`,{hidden:!0,ref:x}),a]})}function fa(e,t=[],{initial:n=null,skip:r=!1}={}){let[i,a]=(0,O.useState)(n),[o,s]=(0,O.useState)(!r),[c,l]=(0,O.useState)(null),u=(0,O.useRef)(0),d=(0,O.useRef)(null),f=(0,O.useRef)(!1),p=(0,O.useCallback)(async(t={})=>{if(r||t.silent&&!t.force&&f.current)return null;d.current?.abort();let n=new AbortController;d.current=n,f.current=!0;let i=++u.current;t.silent||s(!0),l(null);try{let t=await Qe(n.signal,()=>e({signal:n.signal}));return!n.signal.aborted&&i===u.current&&a(t),t}catch(e){return n.signal.aborted||i===u.current&&l(e),null}finally{d.current===n&&(d.current=null,f.current=!1),!n.signal.aborted&&i===u.current&&s(!1)}},t);return(0,O.useEffect)(()=>{if(r)d.current?.abort(),d.current=null,f.current=!1,s(!1);else return p(),()=>{u.current+=1,d.current?.abort(),d.current=null,f.current=!1}},[p,r]),{data:i,setData:a,loading:o,error:c,reload:p}}function pa(e,t=300){let[n,r]=(0,O.useState)(e);return(0,O.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function ma(e,t){let n=(0,O.useRef)(e);(0,O.useEffect)(()=>{n.current=e},[e]),(0,O.useEffect)(()=>{if(!t)return;let e=setInterval(()=>n.current(),t);return()=>clearInterval(e)},[t])}function ha(e,t){let[n,r]=(0,O.useState)(()=>{try{let n=localStorage.getItem(e);return n===null?t:JSON.parse(n)}catch{return t}});return(0,O.useEffect)(()=>{try{localStorage.setItem(e,JSON.stringify(n))}catch{}},[e,n]),[n,r]}var{Text:ga}=c,_a={position:`right`,contentClassName:`cs-nav-flyout`};function va(){let[e,t]=(0,O.useState)(()=>window.matchMedia(`(max-width: 900px)`).matches);return(0,O.useEffect)(()=>{let e=window.matchMedia(`(max-width: 900px)`),n=e=>t(e.matches);return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function ya(e,t,n,r){return e.filter(e=>(!e.anyPermission||r(e.anyPermission))&&(!e.permission||n(e.permission))).map(e=>{let r=e.children?e.children.filter(e=>!e.permission||n(e.permission)):null;return r&&r.length===0?null:{itemKey:e.id,text:t(e.i18n,null,e.fallback),icon:e.icon?(0,M.jsx)(e.icon,{"aria-hidden":`true`}):void 0,items:r?r.map(e=>({itemKey:e.id,text:t(e.i18n,null,e.fallback)})):void 0}}).filter(Boolean)}function ba(){let{preference:e,setPreference:t}=Et(),n=P(),r=[{key:`system`,label:n(`theme.system`,null,`跟随系统`)},{key:`light`,label:n(`theme.light`,null,`浅色`)},{key:`dark`,label:n(`theme.dark`,null,`暗色`)}],i=r.find(t=>t.key===e)||r[0];return(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:r.map(n=>({node:`item`,name:n.label,active:n.key===e,onClick:()=>t(n.key)})),children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:e===`dark`?(0,M.jsx)(ye,{}):(0,M.jsx)(Se,{}),"aria-label":i.label})})}function xa(){let{lang:e,setLanguage:t}=vt();return(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:ct.map(n=>({node:`item`,name:n.label,active:n.id===e,onClick:()=>t(n.id)})),children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:(0,M.jsx)(re,{}),"aria-label":e})})}function Sa({navigate:e}){let t=P(),[n,r]=(0,O.useState)([]),[i,a]=(0,O.useState)(0),[o,s]=(0,O.useState)(!1),[c,l]=(0,O.useState)(!1),u=(0,O.useRef)(null),d=(0,O.useRef)(!1),f=async({force:e=!1}={})=>{if(!e&&d.current)return;u.current?.abort();let t=new AbortController;u.current=t,d.current=!0;try{let e=await j.get(`/notifications/summary`,{limit:80,lang:document.documentElement.lang||`zh-CN`},{signal:t.signal});if(t.signal.aborted)return;let n=Array.isArray(e?.items)?e.items:[];r(n),a(e?.unreadCount??n.filter(e=>!e.read).length)}catch{}finally{u.current===t&&(u.current=null,d.current=!1)}};(0,O.useEffect)(()=>(f({force:!0}),()=>{u.current?.abort(),u.current=null,d.current=!1}),[]),ma(()=>f(),6e4);let p=async()=>{let e=n.filter(e=>!e.read).map(e=>e.id).filter(Boolean);if(e.length&&!c){l(!0);try{await j.post(`/notifications/read`,{eventIds:e}),await f({force:!0})}catch(e){Xi(e)}finally{l(!1)}}},m=t=>{s(!1),t.type===`vulnerability_created`&&t.vulnerabilityId?e(`/vulnerabilities?id=${encodeURIComponent(t.vulnerabilityId)}`):(t.type===`task_completed`||t.type===`long_running_tasks`)&&t.conversationId?e(`/chat?conversation=${encodeURIComponent(t.conversationId)}`):t.type===`task_failed`?e(`/mcp-monitor`):t.type===`hitl_pending`?e(`/hitl`):t.type===`c2_session_online`&&e(`/c2-sessions`)},g=(0,M.jsxs)(`div`,{className:`cs-notification-panel`,children:[(0,M.jsxs)(`div`,{className:`cs-notification-head`,children:[(0,M.jsx)(ga,{strong:!0,children:t(`notifications.title`,null,`通知`)}),(0,M.jsx)(b,{size:`small`,theme:`borderless`,onClick:p,loading:c,children:t(`notifications.markAllRead`,null,`全部标记已读`)})]}),(0,M.jsxs)(`div`,{className:`cs-notification-list`,children:[n.length===0&&(0,M.jsx)(ga,{type:`tertiary`,children:t(`notifications.empty`,null,`暂无新通知`)}),n.map(e=>(0,M.jsxs)(`button`,{type:`button`,className:`cs-notification-item`,onClick:()=>m(e),children:[(0,M.jsx)(`span`,{className:`cs-notification-dot level-${e.level||`p2`}`}),(0,M.jsxs)(`span`,{className:`cs-notification-body`,children:[(0,M.jsx)(`span`,{className:`cs-notification-title`,children:e.title||e.message||e.type}),(0,M.jsxs)(`span`,{className:`cs-notification-meta`,children:[e.ts?Fi(e.ts):``,e.count>1?` · ×${e.count}`:``]})]})]},e.id||`${e.type}-${e.ts}`))]})]});return(0,M.jsx)(h,{content:g,trigger:`click`,position:`bottomRight`,visible:o,onVisibleChange:s,children:(0,M.jsx)(oe,{count:i||null,overflowCount:99,type:`danger`,children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:(0,M.jsx)(y,{}),"aria-label":t(`notifications.title`,null,`通知`)})})})}function Ca({navigate:e}){let{user:t,logout:n,refresh:r}=st(),i=P(),[o,s]=(0,O.useState)(!1),c=(0,O.useId)(),[l,d]=(0,O.useState)(null),[f,p]=(0,O.useState)(!1);return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:[{node:`title`,name:t?.display_name||t?.username||`admin`},{node:`item`,name:i(`auth.changePassword`,null,`修改密码`),icon:(0,M.jsx)(a,{}),onClick:()=>s(!0)},{node:`item`,name:i(`auth.refreshSession`,null,`刷新会话权限`),onClick:()=>r().then(()=>Ji(i(`auth.sessionRefreshed`,null,`会话已刷新`))).catch(e=>Xi(e))},{node:`divider`},{node:`item`,name:i(`auth.logout`,null,`退出登录`),icon:(0,M.jsx)(ne,{}),onClick:async()=>{await n(),e(`/dashboard`)}}],children:(0,M.jsxs)(b,{theme:`borderless`,type:`tertiary`,className:`cs-user-trigger`,"aria-label":i(`auth.userMenu`,null,`用户菜单`),children:[(0,M.jsx)(u,{size:`extra-small`,color:`blue`,children:(t?.display_name||t?.username||`A`).slice(0,1).toUpperCase()}),(0,M.jsx)(`span`,{className:`cs-user-name`,children:t?.display_name||t?.username||`admin`})]})}),(0,M.jsx)(da,{title:i(`auth.changePassword`,null,`修改密码`),visible:o,onCancel:()=>s(!1),formId:c,okText:i(`common.save`,null,`保存`),confirmLoading:f,width:420,children:(0,M.jsxs)(C,{id:c,onSubmit:async e=>{p(!0);try{await j.post(`/auth/change-password`,{oldPassword:e.oldPassword,newPassword:e.newPassword}),Ji(i(`auth.passwordChanged`,null,`密码已更新`)),s(!1),l?.reset()}catch(e){Xi(e,i(`auth.changeFailed`,null,`修改密码失败`))}finally{p(!1)}},getFormApi:d,children:[(0,M.jsx)(C.Input,{field:`oldPassword`,label:i(`auth.currentPassword`,null,`当前密码`),type:`password`,rules:[{required:!0,message:i(`auth.required`,null,`必填`)}]}),(0,M.jsx)(C.Input,{field:`newPassword`,label:i(`auth.newPassword`,null,`新密码`),type:`password`,rules:[{required:!0,min:8,message:i(`auth.passwordMin`,null,`至少 8 位`)}]}),(0,M.jsx)(C.Input,{field:`confirmPassword`,label:i(`auth.confirmPassword`,null,`确认新密码`),type:`password`,rules:[{required:!0,message:i(`auth.required`,null,`必填`)},{validator:(e,t)=>t===l?.getValue(`newPassword`),message:i(`auth.passwordMismatch`,null,`两次输入不一致`)}]})]})})]})}function wa(){let{session:e,hasPermission:t,hasAnyPermission:n}=st(),r=(0,O.useId)(),i=P(),a=Re(),o=D(),s=va(),[c,l]=(0,O.useState)(()=>localStorage.getItem(`csai-nav-collapsed`)===`1`),[u,d]=(0,O.useState)(!1),[p,m]=(0,O.useState)([]),h=a.pathname.replace(/^\//,``).split(`/`)[0]||`dashboard`,g=At(h),_=(0,O.useMemo)(()=>[h],[h]),ee=(0,O.useMemo)(()=>ya(Dt,i,t,n),[i,t,n]);(0,O.useEffect)(()=>{d(!1),g?.parent&&m(e=>e.includes(g.parent)?e:[...e,g.parent])},[a.pathname,g?.parent]),(0,O.useEffect)(()=>{document.title=`${g?i(g.i18n,null,g.fallback):`工作台`} · CyberStrikeAI`},[g,i]);let te=({itemKey:e})=>{let t=a.search,n=[`chat`,`vulnerabilities`,`settings`,`deep-assessments`].includes(e)&&h===e?t:``;o(`/${e}${n}`)},ne=()=>{l(e=>(localStorage.setItem(`csai-nav-collapsed`,e?`0`:`1`),!e))},v=c&&!s,y=!v&&e?.appVersion,x=(0,M.jsxs)(`div`,{className:`cs-sidebar-inner ${v?`is-compact`:``}`,children:[(0,M.jsxs)(b,{className:`cs-brand`,theme:`borderless`,type:`tertiary`,onClick:()=>o(`/dashboard`),"aria-label":`CyberStrikeAI`,"aria-describedby":y?r:void 0,children:[(0,M.jsx)(`img`,{src:`/static/logo.png`,alt:``,className:`cs-brand-logo`}),!v&&(0,M.jsxs)(`span`,{className:`cs-brand-copy`,children:[(0,M.jsxs)(`span`,{className:`cs-brand-name`,children:[`CyberStrike`,(0,M.jsx)(`span`,{children:`AI`})]}),y&&(0,M.jsx)(`span`,{id:r,className:`cs-brand-version`,dir:`ltr`,title:`${i(`header.version`,null,`当前版本`)} ${y}`,children:y})]})]}),(0,M.jsx)(`div`,{className:`cs-nav-scroll`,children:Ot.map(e=>{let t=ee.filter(t=>e.pages.includes(t.itemKey));return t.length?(0,M.jsxs)(`section`,{className:`cs-nav-section`,"aria-label":i(e.i18n,null,e.fallback),children:[!v&&(0,M.jsx)(`div`,{className:`cs-nav-section-label`,children:i(e.i18n,null,e.fallback)}),(0,M.jsx)(he,{className:`cs-nav`,style:{width:`100%`},items:t,selectedKeys:_,onSelect:te,isCollapsed:v,subDropdownProps:_a,openKeys:p,onOpenChange:({openKeys:e})=>m(e)})]},e.id):null})}),!s&&(0,M.jsx)(`div`,{className:`cs-nav-footer`,children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,block:!0,icon:v?(0,M.jsx)(ae,{}):(0,M.jsx)(ce,{}),"aria-label":i(v?`nav.expand`:`nav.collapse`,null,v?`展开菜单`:`收起菜单`),onClick:ne,children:!v&&i(`nav.collapse`,null,`收起菜单`)})})]}),re=g?i(g.i18n,null,g.fallback):`CyberStrikeAI`,ie=g?.parent?At(g.parent):null,S=ie?i(ie.i18n,null,ie.fallback):``;return(0,M.jsxs)(`div`,{className:`cs-shell ${c&&!s?`is-collapsed`:``}`,children:[!s&&(0,M.jsx)(`aside`,{className:`cs-sider`,children:x}),s&&(0,M.jsx)(Te,{visible:u,onCancel:()=>d(!1),placement:`left`,width:264,title:i(`nav.navigation`,null,`导航`),bodyStyle:{padding:0},className:`cs-mobile-nav`,children:x}),(0,M.jsxs)(`div`,{className:`cs-main`,children:[(0,M.jsxs)(`header`,{className:`cs-header`,children:[(0,M.jsxs)(`div`,{className:`cs-header-left`,children:[s&&(0,M.jsx)(b,{theme:`borderless`,icon:(0,M.jsx)(Ae,{}),onClick:()=>d(!0),"aria-label":i(`common.expandPanel`,null,`展开面板`)}),(0,M.jsxs)(Me,{className:`cs-header-crumb`,compact:!1,children:[(0,M.jsx)(Me.Item,{onClick:()=>o(`/dashboard`),children:i(`nav.groupWorkspace`,null,`工作台`)}),S&&(0,M.jsx)(Me.Item,{children:S}),(0,M.jsx)(Me.Item,{children:re})]})]}),(0,M.jsxs)(f,{className:`cs-header-actions`,spacing:4,children:[(0,M.jsx)(Sa,{navigate:o}),(0,M.jsx)(xa,{}),(0,M.jsx)(ba,{}),(0,M.jsx)(Ca,{navigate:o})]})]}),(0,M.jsx)(`main`,{className:`cs-content ${h===`chat`?`cs-content-workspace`:``}`,id:`main-content`,children:(0,M.jsx)(Le,{context:{navigate:o,pageId:h,mobile:s}})})]})]})}var{Title:Ta,Text:Ea,Paragraph:Da}=c;function Oa(){let{login:e}=st(),n=P(),[r,a]=(0,O.useState)(!1),[o,c]=(0,O.useState)(``);async function l(t){a(!0),c(``);try{await e(t.username,t.password)}catch(e){c(rt(e,n(`login.loginFailed`,null,`登录失败`)))}finally{a(!1)}}return(0,M.jsxs)(`main`,{className:`cs-login-page`,children:[(0,M.jsxs)(`section`,{className:`cs-login-story`,children:[(0,M.jsxs)(`div`,{className:`cs-login-brand`,children:[(0,M.jsx)(`img`,{src:`/static/logo.png`,alt:``,className:`cs-login-logo`}),(0,M.jsxs)(`span`,{className:`cs-brand-name`,children:[`CyberStrike`,(0,M.jsx)(`span`,{children:`AI`})]})]}),(0,M.jsxs)(`div`,{className:`cs-login-intro`,children:[(0,M.jsx)(`span`,{className:`cs-login-emblem`,"aria-hidden":`true`,children:(0,M.jsx)(me,{size:`extra-large`})}),(0,M.jsx)(Ta,{heading:1,className:`cs-login-headline`,children:n(`login.headline`,null,`让每一次探索,都有据可循。`)}),(0,M.jsx)(Da,{type:`tertiary`,children:n(`login.intro`,null,`从目标梳理到证据归档,在一个工作台中完成你的安全研究。`)}),(0,M.jsxs)(`div`,{className:`cs-login-features`,children:[(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(m,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.projectTitle`,null,`围绕项目协作`)}),n(`login.projectHint`,null,`跨会话共享目标、上下文与研究进展`)]})]}),(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(de,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.assessmentTitle`,null,`让探索持续推进`)}),n(`login.assessmentHint`,null,`规划、执行与人工复核,始终保持可控`)]})]}),(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(t,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.evidenceTitle`,null,`以证据支撑结论`)}),n(`login.evidenceHint`,null,`保留发现、来源与验收记录`)]})]})]})]}),(0,M.jsx)(Ea,{type:`tertiary`,size:`small`,children:n(`login.platformTagline`,null,`AI 驱动的安全研究工作台`)})]}),(0,M.jsx)(`section`,{className:`cs-login-form-panel`,children:(0,M.jsxs)(s,{className:`cs-login-card`,bordered:!1,children:[(0,M.jsx)(Ta,{heading:2,className:`cs-login-form-heading`,children:n(`login.welcome`,null,`欢迎回来`)}),(0,M.jsx)(Ea,{type:`tertiary`,children:n(`login.welcomeHint`,null,`登录你的安全工作台,继续探索。`)}),(0,M.jsxs)(C,{onSubmit:l,className:`cs-login-form`,children:[o&&(0,M.jsx)(i,{type:`danger`,description:o,closeIcon:null,className:`cs-error-banner`}),(0,M.jsx)(C.Input,{field:`username`,label:n(`login.username`,null,`用户名`),prefix:(0,M.jsx)(ue,{}),placeholder:n(`login.usernamePlaceholder`,null,`请输入用户名`),size:`large`,autoComplete:`username`,rules:[{required:!0,message:n(`login.usernameRequired`,null,`请输入用户名`)}]}),(0,M.jsx)(C.Input,{field:`password`,label:n(`login.password`,null,`密码`),prefix:(0,M.jsx)(ge,{}),type:`password`,size:`large`,autoComplete:`current-password`,placeholder:n(`login.passwordPlaceholder`,null,`请输入密码`),rules:[{required:!0,message:n(`login.passwordRequired`,null,`请输入密码`)}]}),(0,M.jsx)(b,{htmlType:`submit`,theme:`solid`,type:`primary`,size:`large`,block:!0,loading:r,children:n(`login.submit`,null,`登录`)})]}),(0,M.jsx)(Ea,{type:`tertiary`,className:`cs-login-note`,children:n(`login.authorizedOnly`,null,`仅在明确授权的范围内开展安全测试`)})]})})]})}var ka=`modulepreload`,Aa=function(e){return`/static/app/`+e},ja={},Ma=function(e){return e.pathname.endsWith(`.css`)},Na=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},$=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=Aa(t,n);let r=s(t),i=Ma(r);return Na(ja,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:ka,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{let i=a=>{t.removeEventListener(`load`,i),t.removeEventListener(`error`,i),a.type===`error`?n(Error(`Unable to preload CSS for ${r}`)):e(a)};t.addEventListener(`load`,i),t.addEventListener(`error`,i)})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Pa={dashboard:(0,O.lazy)(()=>$(()=>import(`./dashboard-8XvRuqLB.js`),__vite__mapDeps([0,1,2,3,4,5]))),chat:(0,O.lazy)(()=>$(()=>import(`./chat-B3amLD8_.js`),__vite__mapDeps([6,1,2,3,4,7,8,9,10,11,12]))),"deep-assessments":(0,O.lazy)(()=>$(()=>import(`./deep-assessments-C1zSIX6t.js`),__vite__mapDeps([13,1,2,3,4,10,9,14,15,16]))),hitl:(0,O.lazy)(()=>$(()=>import(`./hitl-CuqgPh-B.js`),__vite__mapDeps([17,1,2,3,4,18]))),"tool-guard":(0,O.lazy)(()=>$(()=>import(`./tool-guard-gHtviV0M.js`),__vite__mapDeps([19,1,2,3,4,20]))),projects:(0,O.lazy)(()=>$(()=>import(`./projects-CMt4u2Qr.js`),__vite__mapDeps([21,1,2,3,4,9,14,15,22,11,23,24]))),"asset-overview":(0,O.lazy)(()=>$(()=>import(`./asset-overview-xwryoaKx.js`),__vite__mapDeps([25,1,2,3,4,26,23,27]))),"asset-library":(0,O.lazy)(()=>$(()=>import(`./asset-library-CwccI3Xb.js`),__vite__mapDeps([28,1,2,3,4,11,23,26,22,29]))),"info-collect":(0,O.lazy)(()=>$(()=>import(`./info-collect-CnstRscn.js`),__vite__mapDeps([30,1,2,3,4,11,26,23,31]))),vulnerabilities:(0,O.lazy)(()=>$(()=>import(`./vulnerabilities-CXGKZewN.js`),__vite__mapDeps([32,1,2,3,4,7,11,33]))),tasks:(0,O.lazy)(()=>$(()=>import(`./tasks-CT27M-Wx.js`),__vite__mapDeps([34,1,2,3,4,11,35]))),workflows:(0,O.lazy)(()=>$(()=>import(`./workflows-BnRbScwz.js`),__vite__mapDeps([36,1,2,3,4,37]))),webshell:(0,O.lazy)(()=>$(()=>import(`./webshell-CXOTGht5.js`),__vite__mapDeps([38,1,2,3,4,11,39]))),"c2-listeners":(0,O.lazy)(()=>$(()=>import(`./c2-listeners-CE3GvlqS.js`),__vite__mapDeps([40,1,2,3,4,41,42,43,11,44]))),"c2-sessions":(0,O.lazy)(()=>$(()=>import(`./c2-sessions-BFuBJt9m.js`),__vite__mapDeps([45,1,2,3,4,41,42,43,46]))),"c2-tasks":(0,O.lazy)(()=>$(()=>import(`./c2-tasks-DSV9J8Vu.js`),__vite__mapDeps([47,1,2,3,4,41,42,43,48]))),"c2-payloads":(0,O.lazy)(()=>$(()=>import(`./c2-payloads-B8TBcwqZ.js`),__vite__mapDeps([49,1,2,3,4,41,42,43,50]))),"c2-events":(0,O.lazy)(()=>$(()=>import(`./c2-events-b_BWiEV4.js`),__vite__mapDeps([51,1,2,3,4,41,42,43,52]))),"c2-profiles":(0,O.lazy)(()=>$(()=>import(`./c2-profiles-DFa_6zU3.js`),__vite__mapDeps([53,1,2,3,4,41,42,54]))),"chat-files":(0,O.lazy)(()=>$(()=>import(`./chat-files-D2U-2IVG.js`),__vite__mapDeps([55,1,2,3,4,56]))),"plugin-hub":(0,O.lazy)(()=>$(()=>import(`./plugin-hub-FbKl43dM.js`),__vite__mapDeps([57,1,2,3,4,8,58]))),"mcp-monitor":(0,O.lazy)(()=>$(()=>import(`./mcp-monitor-CfVvha6O.js`),__vite__mapDeps([59,1,2,3,4,60]))),"mcp-management":(0,O.lazy)(()=>$(()=>import(`./mcp-management-BebvY2ig.js`),__vite__mapDeps([61,1,2,3,4,62]))),"knowledge-retrieval-logs":(0,O.lazy)(()=>$(()=>import(`./knowledge-retrieval-logs-DY1jNxJ9.js`),__vite__mapDeps([63,1,2,3,4]))),"knowledge-management":(0,O.lazy)(()=>$(()=>import(`./knowledge-management-CQ0nnhXJ.js`),__vite__mapDeps([64,1,2,3,4]))),"skills-monitor":(0,O.lazy)(()=>$(()=>import(`./skills-monitor-BUTc0QtL.js`),__vite__mapDeps([65,1,3,2,4]))),"skills-management":(0,O.lazy)(()=>$(()=>import(`./skills-management-g8Njeibz.js`),__vite__mapDeps([66,1,2,3,4]))),"agents-management":(0,O.lazy)(()=>$(()=>import(`./agents-management-gLrRdc0M.js`),__vite__mapDeps([67,1,2,3,4]))),"roles-management":(0,O.lazy)(()=>$(()=>import(`./roles-management-DGTD0STX.js`),__vite__mapDeps([68,1,2,3,4,69]))),"platform-rbac":(0,O.lazy)(()=>$(()=>import(`./platform-rbac-Bqf7ZmWP.js`),__vite__mapDeps([70,1,2,3,4]))),settings:(0,O.lazy)(()=>$(()=>import(`./settings-yUhIZhl9.js`),__vite__mapDeps([71,1,2,3,4,10,72]))),"api-docs":(0,O.lazy)(()=>$(()=>import(`./api-docs-BEMXmVy4.js`),__vite__mapDeps([73,1,2,3,4,74])))},{Title:Fa,Text:Ia}=c;function La(){return(0,M.jsx)(`div`,{className:`cs-page-loading`,children:(0,M.jsx)(se,{size:`large`})})}function Ra({code:e,title:t,description:n}){return(0,M.jsxs)(`div`,{className:`cs-page-loading`,style:{flexDirection:`column`,gap:8},children:[(0,M.jsx)(Fa,{heading:2,style:{margin:0},children:e}),(0,M.jsx)(Ia,{strong:!0,children:t}),n&&(0,M.jsx)(Ia,{type:`tertiary`,children:n})]})}function za(){let{pageId:e}=Ue(),{hasPermission:t,hasAnyPermission:n}=st(),r=P(),i=At(e),a=e?Pa[e]:null,o=(0,O.useMemo)(()=>{if(!i)return!0;if(i.anyPermission)return n(i.anyPermission);if(i.permission)return t(i.permission);let e=i.parent?At(i.parent):null;return!e?.anyPermission||n(e.anyPermission)},[i,t,n]);return i?a?o?(0,M.jsx)(O.Suspense,{fallback:(0,M.jsx)(La,{}),children:(0,M.jsx)(a,{})}):(0,M.jsx)(Ra,{code:`403`,title:r(`common.forbidden`,null,`当前账号没有访问该页面的权限`)}):(0,M.jsx)(Ra,{code:`404`,title:i.fallback,description:r(`common.pagePending`,null,`页面尚未注册`)}):(0,M.jsx)(Ra,{code:`404`,title:r(`common.pageNotFound`,null,`页面不存在`)})}function Ba(){let{authenticated:e,checking:t}=st();return t?(0,M.jsx)(La,{}):e?(0,M.jsx)(Be,{children:(0,M.jsxs)(Ve,{element:(0,M.jsx)(wa,{}),children:[(0,M.jsx)(Ve,{path:`/`,element:(0,M.jsx)(Ie,{to:`/dashboard`,replace:!0})}),(0,M.jsx)(Ve,{path:`/system-update`,element:(0,M.jsx)(Ie,{to:`/settings?section=update`,replace:!0})}),(0,M.jsx)(Ve,{path:`/:pageId`,element:(0,M.jsx)(za,{})}),(0,M.jsx)(Ve,{path:`*`,element:(0,M.jsx)(Ie,{to:`/dashboard`,replace:!0})})]})}):(0,M.jsx)(Oa,{})}var Va={"zh-CN":pe,"en-US":Ee,"ru-RU":xe,"ar-SA":w};function Ha(){let{lang:e}=vt();return(0,M.jsx)(n,{locale:Va[e]||pe,direction:e===`ar-SA`?`rtl`:`ltr`,children:(0,M.jsx)(ot,{children:(0,M.jsx)(ze,{children:(0,M.jsx)(Ba,{})})})})}(0,We.createRoot)(document.getElementById(`root`)).render((0,M.jsx)(O.StrictMode,{children:(0,M.jsx)(Tt,{children:(0,M.jsx)(_t,{children:(0,M.jsx)(Ha,{})})})}));export{Ri as A,Ze as B,Ni as C,Bi as D,Fi as E,P as F,A as H,st as I,j as L,Et as M,ct as N,Vi as O,vt as P,tt as R,Yi as S,zi as T,nt as V,$i as _,fa as a,Xi as b,da as c,ca as d,oa as f,ea as g,ra as h,ha as i,Wi as j,Li as k,na as l,Qi as m,pa as n,aa as o,Zi as p,ma as r,ta as s,$ as t,sa as u,ia as v,ji as w,Ji as x,la as y,rt as z}; \ No newline at end of file +`+p),de(p)},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};P(e),Be=!0,Ve=w,He=T},t.clearConfig=function(){gt=null,Be=!1,Ve=null,He=null,S=oe,ae=``},t.isValidAttribute=function(e,t,n){gt||P({});let r=N(e),i=N(t);return typeof n==`string`&&(tn(t,n)||!Le&&J(bi,n))?!1:Xt(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&q(C,e)&&Sr(C[e],t)},t.removeHook=function(e,t){if(q(C,e)){if(t!==void 0){let n=br(C[e],t);return n===-1?void 0:wr(C[e],n,1)[0]}return xr(C[e])}},t.removeHooks=function(e){q(C,e)&&(C[e]=[])},t.removeAllHooks=function(){C=Ei()},t}var Ai=ki(),ji=[`critical`,`high`,`medium`,`low`,`info`],Mi={critical:`red`,high:`orange`,medium:`amber`,low:`blue`,info:`grey`},Ni={critical:`严重`,high:`高危`,medium:`中危`,low:`低危`,info:`信息`},Pi={running:`blue`,pending:`amber`,queued:`amber`,paused:`grey`,success:`green`,succeeded:`green`,completed:`green`,done:`green`,failed:`red`,error:`red`,cancelled:`grey`,canceled:`grey`,stopped:`grey`,active:`green`,inactive:`grey`,online:`green`,offline:`grey`,open:`red`,closed:`green`,archived:`grey`};function Fi(e,t=`zh-CN`){if(!e)return`—`;let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.getTime())?n.toLocaleString(t,{hour12:!1}):`—`}function Ii(e,t=`zh-CN`){if(!e)return`—`;let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.getTime())?n.toLocaleDateString(t):`—`}function Li(e,t=`zh-CN`){if(!e)return`—`;let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.getTime())?n.toLocaleTimeString(t,{hour12:!1}):`—`}function Ri(e,t){if(!e)return`—`;let n=new Date(e);if(!Number.isFinite(n.getTime()))return`—`;let r=Date.now()-n.getTime();return r<6e4?t?.(`common.justNow`,null,`刚刚`)||`刚刚`:r<36e5?t?.(`common.minutesAgo`,{n:Math.floor(r/6e4)},`${Math.floor(r/6e4)} 分钟前`):r<864e5?t?.(`common.hoursAgo`,{n:Math.floor(r/36e5)},`${Math.floor(r/36e5)} 小时前`):r<2592e6?t?.(`common.daysAgo`,{n:Math.floor(r/864e5)},`${Math.floor(r/864e5)} 天前`):Ii(e)}function zi(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return`—`;if(t<1024)return`${t} B`;let n=[`KB`,`MB`,`GB`,`TB`],r=t/1024,i=0;for(;r>=1024&&i=100?0:1)} ${n[i]}`}function Bi(e,t=`zh-CN`){let n=Number(e);return Number.isFinite(n)?n.toLocaleString(t):`—`}function Vi(e,t=1){let n=Number(e);return Number.isFinite(n)?`${(n*(n<=1?100:1)).toFixed(t)}%`:`—`}function Hi(e){return Mi[String(e||``).toLowerCase()]||`grey`}function Ui(e){return Pi[String(e||``).toLowerCase()]||`grey`}function Wi(e,t=120){let n=String(e??``);return n.length>t?`${n.slice(0,t)}…`:n}var{Title:Gi,Text:Ki,Paragraph:qi}=c;function Ji(e){Ce.success({content:e,duration:2})}function Yi(e){Ce.warning({content:e,duration:3})}function Xi(e,t=`操作失败`){Ce.error({content:rt(e,t),duration:4})}function Zi({title:e,description:t,extra:n,children:r}){return(0,M.jsxs)(`header`,{className:`cs-page-header`,children:[(0,M.jsxs)(`div`,{className:`cs-page-header-main`,children:[(0,M.jsx)(Gi,{heading:3,className:`cs-page-title`,children:e}),t&&(0,M.jsx)(Ki,{type:`tertiary`,className:`cs-page-desc`,children:t}),r]}),n&&(0,M.jsx)(f,{className:`cs-page-header-extra`,wrap:!0,children:n})]})}function Qi({title:e,description:t,extra:n,children:r,className:i=``,bodyClassName:a=``}){return(0,M.jsxs)(s,{className:`cs-section-card ${i}`,title:e?(0,M.jsx)(`span`,{className:`cs-section-title`,children:e}):void 0,headerExtraContent:n,bordered:!1,children:[t&&(0,M.jsx)(qi,{type:`tertiary`,className:`cs-section-desc`,children:t}),(0,M.jsx)(`div`,{className:a,children:r})]})}function $i({metrics:e,columns:t=4}){return(0,M.jsx)(`div`,{className:`cs-stat-grid`,style:{"--cs-stat-columns":t},children:e.map(e=>(0,M.jsx)(ea,{...e},e.id||e.label))})}function ea({label:e,value:t,valueTitle:n,detail:r,tone:i,severity:a,icon:o,onClick:c,pressed:l,loading:u=!1}){let d=(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`span`,{className:`cs-stat-head`,children:[(0,M.jsx)(Ki,{type:`tertiary`,className:`cs-stat-label`,children:e}),o&&(0,M.jsx)(`span`,{className:`cs-stat-icon ${i?`tone-${i}`:``}`,"aria-hidden":`true`,children:o})]}),(0,M.jsx)(_,{loading:u,placeholder:(0,M.jsx)(_.Title,{style:{width:`60%`,height:36,margin:`8px 0`}}),children:(0,M.jsx)(`span`,{className:`cs-stat-value ${i?`tone-${i}`:``}`,title:n,children:t??`—`})}),r&&(0,M.jsx)(`span`,{className:`cs-stat-detail`,children:r})]});return c?(0,M.jsx)(b,{className:`cs-stat-card is-clickable`,theme:`borderless`,onClick:c,"aria-label":String(e),"aria-pressed":l,"data-severity":a,children:d}):(0,M.jsx)(s,{className:`cs-stat-card`,"data-severity":a,bordered:!1,children:d})}function ta({columns:e,dataSource:t,rowKey:n=`id`,loading:r,pagination:i,emptyText:a,onRefresh:s,toolbar:c,size:l=`default`,className:u=``,...d}){let f=P(),p=i!==!1&&{pageSize:10,showSizeChanger:!0,pageSizeOpts:[10,20,50,100],showTotal:!0,...i||{}};return(0,M.jsxs)(`div`,{className:`cs-table-wrap ${u}`,children:[(c||s)&&(0,M.jsxs)(`div`,{className:`cs-table-toolbar`,children:[(0,M.jsx)(`div`,{className:`cs-table-toolbar-main`,children:c}),s&&(0,M.jsx)(b,{icon:(0,M.jsx)(T,{}),theme:`borderless`,onClick:s,loading:r,children:f(`common.refresh`,null,`刷新`)})]}),(0,M.jsx)(`div`,{className:`cs-table-scroll`,children:(0,M.jsx)(ke,{columns:e,dataSource:t||[],rowKey:n,loading:r,pagination:p,size:l,empty:(0,M.jsx)(o,{image:(0,M.jsx)(je,{size:`extra-large`}),title:a||f(`common.noData`,null,`暂无数据`),description:null,className:`cs-table-empty`}),...d})})]})}function na({error:e,onRetry:t}){let n=P();return e?(0,M.jsx)(i,{type:`danger`,bordered:!0,closeIcon:null,className:`cs-error-banner`,description:(0,M.jsxs)(f,{wrap:!0,children:[(0,M.jsx)(`span`,{children:rt(e,n(`common.loadFailed`,null,`加载失败`))}),t&&(0,M.jsx)(b,{size:`small`,onClick:t,children:n(`common.refresh`,null,`刷新`)})]})}):null}function ra({severity:e,size:t=`small`}){let n=String(e||``).toLowerCase();return(0,M.jsx)(te,{size:t,color:Hi(n),shape:`circle`,className:`cs-severity-tag`,"data-severity":ji.includes(n)?n:void 0,children:Ni[n]||e||`—`})}function ia({status:e,label:t,size:n=`small`}){let r=String(e||``).toLowerCase();return(0,M.jsx)(te,{size:n,color:Ui(r),shape:`square`,children:t||e||`—`})}function aa({text:e,label:t,size:n=`default`,theme:r=`borderless`}){let i=P();return(0,M.jsx)(b,{size:n,theme:r,icon:(0,M.jsx)(x,{}),"aria-label":t||i(`common.copy`,null,`复制`),onClick:async()=>{try{await navigator.clipboard.writeText(String(e??``)),Ji(i(`common.copied`,null,`已复制`))}catch(e){Xi(e,i(`common.copyFailed`,null,`复制失败`))}},children:t})}function oa({content:e,className:t=``}){let n=(0,O.useMemo)(()=>{let t=W.parse(String(e??``),{breaks:!0,gfm:!0});return Ai.sanitize(t,{ADD_ATTR:[`target`,`rel`]})},[e]);return(0,M.jsx)(`div`,{className:`cs-markdown ${t}`,dangerouslySetInnerHTML:{__html:n}})}function sa({value:e,collapsed:t=!1,title:n}){let[r,i]=(0,O.useState)(!t),a=P(),o=(0,O.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]);return(0,M.jsxs)(`div`,{className:`cs-json-viewer`,children:[(0,M.jsxs)(`div`,{className:`cs-json-viewer-head`,children:[(0,M.jsx)(Ki,{strong:!0,children:n||`JSON`}),(0,M.jsxs)(f,{spacing:4,children:[(0,M.jsx)(aa,{text:o}),(0,M.jsx)(b,{theme:`borderless`,size:`small`,icon:r?(0,M.jsx)(d,{}):(0,M.jsx)(l,{}),"aria-expanded":r,"aria-label":a(r?`common.collapse`:`common.expand`,null,r?`收起`:`展开`),onClick:()=>i(e=>!e)})]})]}),(0,M.jsx)(ee,{isOpen:r,children:(0,M.jsx)(`pre`,{className:`cs-json-viewer-body`,children:o})})]})}function ca({items:e,columns:t=2}){return(0,M.jsx)(v,{className:`cs-description-list`,layout:`horizontal`,align:`plain`,column:t,data:e.filter(Boolean).map(e=>({key:e.label,value:e.value??`—`}))})}function la({title:e,content:t,okText:n,danger:r=!0,onOk:i}){ie.confirm({title:e,content:t,okText:n||`确定`,cancelText:`取消`,okButtonProps:r?{type:`danger`}:void 0,onOk:i})}var ua=`a[href], button, input, select, textarea, iframe, [tabindex], [contenteditable="true"]`;function da({title:e,visible:t,onCancel:n,width:r=560,footer:i,children:a,className:o,closeOnEsc:s=!0,mask:c=!0,maskClosable:l=!0,onOk:u,formId:d,okText:f,cancelText:p,okButtonProps:m,cancelButtonProps:h,confirmLoading:g,..._}){let ee=P(),te=(0,O.useRef)(null),[ne,v]=(0,O.useState)(!1),y=g??ne,x=(0,O.useCallback)(e=>{let t=e?.closest(`[role="dialog"]`);if(!t)return;te.current=t;let n=document.activeElement;return c&&(t.setAttribute(`aria-modal`,`true`),queueMicrotask(()=>{te.current===t&&!t.contains(document.activeElement)&&t.focus({preventScroll:!0})})),()=>{if(te.current=null,!c)return;t.removeAttribute(`aria-modal`);let e=document.activeElement;n?.isConnected&&(t.contains(e)||e===document.body)&&n.focus({preventScroll:!0})}},[c]);(0,O.useEffect)(()=>{if(!t)return;let e=e=>{let t=te.current,r=document.activeElement;if(e.defaultPrevented||!t?.contains(r)||(e.key===`Escape`&&s&&n&&(e.preventDefault(),n(e)),e.key!==`Tab`||!c))return;let i=[...t.querySelectorAll(ua)].filter(e=>e.tabIndex>=0&&!e.matches(`:disabled`)&&e.getClientRects().length),a=i[0],o=i.at(-1);(!a||(e.shiftKey?r===a||r===t:r===o))&&(e.preventDefault(),(e.shiftKey?o:a)?.focus())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s,c,n,t]);let re=e=>{if(y)return;let t=u?.(e);if(g===void 0&&typeof t?.then==`function`){v(!0);let e=()=>v(!1);Promise.resolve(t).then(e,e)}},ie=i===void 0&&(u||d)?(0,M.jsxs)(M.Fragment,{children:[n&&(0,M.jsx)(b,{type:`tertiary`,onClick:n,...h,children:p||ee(`common.cancel`,null,`取消`)}),(0,M.jsx)(b,{theme:`solid`,type:`primary`,...m,loading:y,disabled:y||m?.disabled,onClick:d?void 0:re,form:d,htmlType:d?`submit`:`button`,children:f||ee(`common.ok`,null,`确定`)})]}):i;return(0,M.jsxs)(Te,{title:e,visible:t,onCancel:n,width:r,footer:ie,mask:c,maskClosable:l&&!y,closeOnEsc:!1,className:`cs-drawer ${o||``}`,"aria-label":typeof e==`string`?e:void 0,..._,children:[(0,M.jsx)(`span`,{hidden:!0,ref:x}),a]})}function fa(e,t=[],{initial:n=null,skip:r=!1}={}){let[i,a]=(0,O.useState)(n),[o,s]=(0,O.useState)(!r),[c,l]=(0,O.useState)(null),u=(0,O.useRef)(0),d=(0,O.useRef)(null),f=(0,O.useRef)(!1),p=(0,O.useCallback)(async(t={})=>{if(r||t.silent&&!t.force&&f.current)return null;d.current?.abort();let n=new AbortController;d.current=n,f.current=!0;let i=++u.current;t.silent||s(!0),l(null);try{let t=await Qe(n.signal,()=>e({signal:n.signal}));return!n.signal.aborted&&i===u.current&&a(t),t}catch(e){return n.signal.aborted||i===u.current&&l(e),null}finally{d.current===n&&(d.current=null,f.current=!1),!n.signal.aborted&&i===u.current&&s(!1)}},t);return(0,O.useEffect)(()=>{if(r)d.current?.abort(),d.current=null,f.current=!1,s(!1);else return p(),()=>{u.current+=1,d.current?.abort(),d.current=null,f.current=!1}},[p,r]),{data:i,setData:a,loading:o,error:c,reload:p}}function pa(e,t=300){let[n,r]=(0,O.useState)(e);return(0,O.useEffect)(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function ma(e,t){let n=(0,O.useRef)(e);(0,O.useEffect)(()=>{n.current=e},[e]),(0,O.useEffect)(()=>{if(!t)return;let e=setInterval(()=>n.current(),t);return()=>clearInterval(e)},[t])}function ha(e,t){let[n,r]=(0,O.useState)(()=>{try{let n=localStorage.getItem(e);return n===null?t:JSON.parse(n)}catch{return t}});return(0,O.useEffect)(()=>{try{localStorage.setItem(e,JSON.stringify(n))}catch{}},[e,n]),[n,r]}var{Text:ga}=c,_a={position:`right`,contentClassName:`cs-nav-flyout`};function va(){let[e,t]=(0,O.useState)(()=>window.matchMedia(`(max-width: 900px)`).matches);return(0,O.useEffect)(()=>{let e=window.matchMedia(`(max-width: 900px)`),n=e=>t(e.matches);return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function ya(e,t,n,r){return e.filter(e=>(!e.anyPermission||r(e.anyPermission))&&(!e.permission||n(e.permission))).map(e=>{let r=e.children?e.children.filter(e=>!e.permission||n(e.permission)):null;return r&&r.length===0?null:{itemKey:e.id,text:t(e.i18n,null,e.fallback),icon:e.icon?(0,M.jsx)(e.icon,{"aria-hidden":`true`}):void 0,items:r?r.map(e=>({itemKey:e.id,text:t(e.i18n,null,e.fallback)})):void 0}}).filter(Boolean)}function ba(){let{preference:e,setPreference:t}=Et(),n=P(),r=[{key:`system`,label:n(`theme.system`,null,`跟随系统`)},{key:`light`,label:n(`theme.light`,null,`浅色`)},{key:`dark`,label:n(`theme.dark`,null,`暗色`)}],i=r.find(t=>t.key===e)||r[0];return(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:r.map(n=>({node:`item`,name:n.label,active:n.key===e,onClick:()=>t(n.key)})),children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:e===`dark`?(0,M.jsx)(ye,{}):(0,M.jsx)(Se,{}),"aria-label":i.label})})}function xa(){let{lang:e,setLanguage:t}=vt();return(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:ct.map(n=>({node:`item`,name:n.label,active:n.id===e,onClick:()=>t(n.id)})),children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:(0,M.jsx)(re,{}),"aria-label":e})})}function Sa({navigate:e}){let t=P(),[n,r]=(0,O.useState)([]),[i,a]=(0,O.useState)(0),[o,s]=(0,O.useState)(!1),[c,l]=(0,O.useState)(!1),u=(0,O.useRef)(null),d=(0,O.useRef)(!1),f=async({force:e=!1}={})=>{if(!e&&d.current)return;u.current?.abort();let t=new AbortController;u.current=t,d.current=!0;try{let e=await j.get(`/notifications/summary`,{limit:80,lang:document.documentElement.lang||`zh-CN`},{signal:t.signal});if(t.signal.aborted)return;let n=Array.isArray(e?.items)?e.items:[];r(n),a(e?.unreadCount??n.filter(e=>!e.read).length)}catch{}finally{u.current===t&&(u.current=null,d.current=!1)}};(0,O.useEffect)(()=>(f({force:!0}),()=>{u.current?.abort(),u.current=null,d.current=!1}),[]),ma(()=>f(),6e4);let p=async()=>{let e=n.filter(e=>!e.read).map(e=>e.id).filter(Boolean);if(e.length&&!c){l(!0);try{await j.post(`/notifications/read`,{eventIds:e}),await f({force:!0})}catch(e){Xi(e)}finally{l(!1)}}},m=t=>{s(!1),t.type===`vulnerability_created`&&t.vulnerabilityId?e(`/vulnerabilities?id=${encodeURIComponent(t.vulnerabilityId)}`):(t.type===`task_completed`||t.type===`long_running_tasks`)&&t.conversationId?e(`/chat?conversation=${encodeURIComponent(t.conversationId)}`):t.type===`task_failed`?e(`/mcp-monitor`):t.type===`hitl_pending`?e(`/hitl`):t.type===`c2_session_online`&&e(`/c2-sessions`)},g=(0,M.jsxs)(`div`,{className:`cs-notification-panel`,children:[(0,M.jsxs)(`div`,{className:`cs-notification-head`,children:[(0,M.jsx)(ga,{strong:!0,children:t(`notifications.title`,null,`通知`)}),(0,M.jsx)(b,{size:`small`,theme:`borderless`,onClick:p,loading:c,children:t(`notifications.markAllRead`,null,`全部标记已读`)})]}),(0,M.jsxs)(`div`,{className:`cs-notification-list`,children:[n.length===0&&(0,M.jsx)(ga,{type:`tertiary`,children:t(`notifications.empty`,null,`暂无新通知`)}),n.map(e=>(0,M.jsxs)(`button`,{type:`button`,className:`cs-notification-item`,onClick:()=>m(e),children:[(0,M.jsx)(`span`,{className:`cs-notification-dot level-${e.level||`p2`}`}),(0,M.jsxs)(`span`,{className:`cs-notification-body`,children:[(0,M.jsx)(`span`,{className:`cs-notification-title`,children:e.title||e.message||e.type}),(0,M.jsxs)(`span`,{className:`cs-notification-meta`,children:[e.ts?Fi(e.ts):``,e.count>1?` · ×${e.count}`:``]})]})]},e.id||`${e.type}-${e.ts}`))]})]});return(0,M.jsx)(h,{content:g,trigger:`click`,position:`bottomRight`,visible:o,onVisibleChange:s,children:(0,M.jsx)(oe,{count:i||null,overflowCount:99,type:`danger`,children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,icon:(0,M.jsx)(y,{}),"aria-label":t(`notifications.title`,null,`通知`)})})})}function Ca({navigate:e}){let{user:t,logout:n,refresh:r}=st(),i=P(),[o,s]=(0,O.useState)(!1),c=(0,O.useId)(),[l,d]=(0,O.useState)(null),[f,p]=(0,O.useState)(!1);return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(E,{trigger:`click`,position:`bottomRight`,menu:[{node:`title`,name:t?.display_name||t?.username||`admin`},{node:`item`,name:i(`auth.changePassword`,null,`修改密码`),icon:(0,M.jsx)(a,{}),onClick:()=>s(!0)},{node:`item`,name:i(`auth.refreshSession`,null,`刷新会话权限`),onClick:()=>r().then(()=>Ji(i(`auth.sessionRefreshed`,null,`会话已刷新`))).catch(e=>Xi(e))},{node:`divider`},{node:`item`,name:i(`auth.logout`,null,`退出登录`),icon:(0,M.jsx)(ne,{}),onClick:async()=>{await n(),e(`/dashboard`)}}],children:(0,M.jsxs)(b,{theme:`borderless`,type:`tertiary`,className:`cs-user-trigger`,"aria-label":i(`auth.userMenu`,null,`用户菜单`),children:[(0,M.jsx)(u,{size:`extra-small`,color:`blue`,children:(t?.display_name||t?.username||`A`).slice(0,1).toUpperCase()}),(0,M.jsx)(`span`,{className:`cs-user-name`,children:t?.display_name||t?.username||`admin`})]})}),(0,M.jsx)(da,{title:i(`auth.changePassword`,null,`修改密码`),visible:o,onCancel:()=>s(!1),formId:c,okText:i(`common.save`,null,`保存`),confirmLoading:f,width:420,children:(0,M.jsxs)(C,{id:c,onSubmit:async e=>{p(!0);try{await j.post(`/auth/change-password`,{oldPassword:e.oldPassword,newPassword:e.newPassword}),Ji(i(`auth.passwordChanged`,null,`密码已更新`)),s(!1),l?.reset()}catch(e){Xi(e,i(`auth.changeFailed`,null,`修改密码失败`))}finally{p(!1)}},getFormApi:d,children:[(0,M.jsx)(C.Input,{field:`oldPassword`,label:i(`auth.currentPassword`,null,`当前密码`),type:`password`,rules:[{required:!0,message:i(`auth.required`,null,`必填`)}]}),(0,M.jsx)(C.Input,{field:`newPassword`,label:i(`auth.newPassword`,null,`新密码`),type:`password`,rules:[{required:!0,min:8,message:i(`auth.passwordMin`,null,`至少 8 位`)}]}),(0,M.jsx)(C.Input,{field:`confirmPassword`,label:i(`auth.confirmPassword`,null,`确认新密码`),type:`password`,rules:[{required:!0,message:i(`auth.required`,null,`必填`)},{validator:(e,t)=>t===l?.getValue(`newPassword`),message:i(`auth.passwordMismatch`,null,`两次输入不一致`)}]})]})})]})}function wa(){let{session:e,hasPermission:t,hasAnyPermission:n}=st(),r=(0,O.useId)(),i=P(),a=Re(),o=D(),s=va(),[c,l]=(0,O.useState)(()=>localStorage.getItem(`csai-nav-collapsed`)===`1`),[u,d]=(0,O.useState)(!1),[p,m]=(0,O.useState)([]),h=a.pathname.replace(/^\//,``).split(`/`)[0]||`dashboard`,g=At(h),_=(0,O.useMemo)(()=>[h],[h]),ee=(0,O.useMemo)(()=>ya(Dt,i,t,n),[i,t,n]);(0,O.useEffect)(()=>{d(!1),g?.parent&&m(e=>e.includes(g.parent)?e:[...e,g.parent])},[a.pathname,g?.parent]),(0,O.useEffect)(()=>{document.title=`${g?i(g.i18n,null,g.fallback):`工作台`} · CyberStrikeAI`},[g,i]);let te=({itemKey:e})=>{let t=a.search,n=[`chat`,`vulnerabilities`,`settings`,`deep-assessments`].includes(e)&&h===e?t:``;o(`/${e}${n}`)},ne=()=>{l(e=>(localStorage.setItem(`csai-nav-collapsed`,e?`0`:`1`),!e))},v=c&&!s,y=!v&&e?.appVersion,x=(0,M.jsxs)(`div`,{className:`cs-sidebar-inner ${v?`is-compact`:``}`,children:[(0,M.jsxs)(b,{className:`cs-brand`,theme:`borderless`,type:`tertiary`,onClick:()=>o(`/dashboard`),"aria-label":`CyberStrikeAI`,"aria-describedby":y?r:void 0,children:[(0,M.jsx)(`img`,{src:`/static/logo.png`,alt:``,className:`cs-brand-logo`}),!v&&(0,M.jsxs)(`span`,{className:`cs-brand-copy`,children:[(0,M.jsxs)(`span`,{className:`cs-brand-name`,children:[`CyberStrike`,(0,M.jsx)(`span`,{children:`AI`})]}),y&&(0,M.jsx)(`span`,{id:r,className:`cs-brand-version`,dir:`ltr`,title:`${i(`header.version`,null,`当前版本`)} ${y}`,children:y})]})]}),(0,M.jsx)(`div`,{className:`cs-nav-scroll`,children:Ot.map(e=>{let t=ee.filter(t=>e.pages.includes(t.itemKey));return t.length?(0,M.jsxs)(`section`,{className:`cs-nav-section`,"aria-label":i(e.i18n,null,e.fallback),children:[!v&&(0,M.jsx)(`div`,{className:`cs-nav-section-label`,children:i(e.i18n,null,e.fallback)}),(0,M.jsx)(he,{className:`cs-nav`,style:{width:`100%`},items:t,selectedKeys:_,onSelect:te,isCollapsed:v,subDropdownProps:_a,openKeys:p,onOpenChange:({openKeys:e})=>m(e)})]},e.id):null})}),!s&&(0,M.jsx)(`div`,{className:`cs-nav-footer`,children:(0,M.jsx)(b,{theme:`borderless`,type:`tertiary`,block:!0,icon:v?(0,M.jsx)(ae,{}):(0,M.jsx)(ce,{}),"aria-label":i(v?`nav.expand`:`nav.collapse`,null,v?`展开菜单`:`收起菜单`),onClick:ne,children:!v&&i(`nav.collapse`,null,`收起菜单`)})})]}),re=g?i(g.i18n,null,g.fallback):`CyberStrikeAI`,ie=g?.parent?At(g.parent):null,S=ie?i(ie.i18n,null,ie.fallback):``;return(0,M.jsxs)(`div`,{className:`cs-shell ${c&&!s?`is-collapsed`:``}`,children:[!s&&(0,M.jsx)(`aside`,{className:`cs-sider`,children:x}),s&&(0,M.jsx)(Te,{visible:u,onCancel:()=>d(!1),placement:`left`,width:264,title:i(`nav.navigation`,null,`导航`),bodyStyle:{padding:0},className:`cs-mobile-nav`,children:x}),(0,M.jsxs)(`div`,{className:`cs-main`,children:[(0,M.jsxs)(`header`,{className:`cs-header`,children:[(0,M.jsxs)(`div`,{className:`cs-header-left`,children:[s&&(0,M.jsx)(b,{theme:`borderless`,icon:(0,M.jsx)(Ae,{}),onClick:()=>d(!0),"aria-label":i(`common.expandPanel`,null,`展开面板`)}),(0,M.jsxs)(Me,{className:`cs-header-crumb`,compact:!1,children:[(0,M.jsx)(Me.Item,{onClick:()=>o(`/dashboard`),children:i(`nav.groupWorkspace`,null,`工作台`)}),S&&(0,M.jsx)(Me.Item,{children:S}),(0,M.jsx)(Me.Item,{children:re})]})]}),(0,M.jsxs)(f,{className:`cs-header-actions`,spacing:4,children:[(0,M.jsx)(Sa,{navigate:o}),(0,M.jsx)(xa,{}),(0,M.jsx)(ba,{}),(0,M.jsx)(Ca,{navigate:o})]})]}),(0,M.jsx)(`main`,{className:`cs-content ${h===`chat`?`cs-content-workspace`:``}`,id:`main-content`,children:(0,M.jsx)(Le,{context:{navigate:o,pageId:h,mobile:s}})})]})]})}var{Title:Ta,Text:Ea,Paragraph:Da}=c;function Oa(){let{login:e}=st(),n=P(),[r,a]=(0,O.useState)(!1),[o,c]=(0,O.useState)(``);async function l(t){a(!0),c(``);try{await e(t.username,t.password)}catch(e){c(rt(e,n(`login.loginFailed`,null,`登录失败`)))}finally{a(!1)}}return(0,M.jsxs)(`main`,{className:`cs-login-page`,children:[(0,M.jsxs)(`section`,{className:`cs-login-story`,children:[(0,M.jsxs)(`div`,{className:`cs-login-brand`,children:[(0,M.jsx)(`img`,{src:`/static/logo.png`,alt:``,className:`cs-login-logo`}),(0,M.jsxs)(`span`,{className:`cs-brand-name`,children:[`CyberStrike`,(0,M.jsx)(`span`,{children:`AI`})]})]}),(0,M.jsxs)(`div`,{className:`cs-login-intro`,children:[(0,M.jsx)(`span`,{className:`cs-login-emblem`,"aria-hidden":`true`,children:(0,M.jsx)(me,{size:`extra-large`})}),(0,M.jsx)(Ta,{heading:1,className:`cs-login-headline`,children:n(`login.headline`,null,`让每一次探索,都有据可循。`)}),(0,M.jsx)(Da,{type:`tertiary`,children:n(`login.intro`,null,`从目标梳理到证据归档,在一个工作台中完成你的安全研究。`)}),(0,M.jsxs)(`div`,{className:`cs-login-features`,children:[(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(m,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.projectTitle`,null,`围绕项目协作`)}),n(`login.projectHint`,null,`跨会话共享目标、上下文与研究进展`)]})]}),(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(de,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.assessmentTitle`,null,`让探索持续推进`)}),n(`login.assessmentHint`,null,`规划、执行与人工复核,始终保持可控`)]})]}),(0,M.jsxs)(`div`,{className:`cs-login-feature`,children:[(0,M.jsx)(t,{size:`large`}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`strong`,{children:n(`login.evidenceTitle`,null,`以证据支撑结论`)}),n(`login.evidenceHint`,null,`保留发现、来源与验收记录`)]})]})]})]}),(0,M.jsx)(Ea,{type:`tertiary`,size:`small`,children:n(`login.platformTagline`,null,`AI 驱动的安全研究工作台`)})]}),(0,M.jsx)(`section`,{className:`cs-login-form-panel`,children:(0,M.jsxs)(s,{className:`cs-login-card`,bordered:!1,children:[(0,M.jsx)(Ta,{heading:2,className:`cs-login-form-heading`,children:n(`login.welcome`,null,`欢迎回来`)}),(0,M.jsx)(Ea,{type:`tertiary`,children:n(`login.welcomeHint`,null,`登录你的安全工作台,继续探索。`)}),(0,M.jsxs)(C,{onSubmit:l,className:`cs-login-form`,children:[o&&(0,M.jsx)(i,{type:`danger`,description:o,closeIcon:null,className:`cs-error-banner`}),(0,M.jsx)(C.Input,{field:`username`,label:n(`login.username`,null,`用户名`),prefix:(0,M.jsx)(ue,{}),placeholder:n(`login.usernamePlaceholder`,null,`请输入用户名`),size:`large`,autoComplete:`username`,rules:[{required:!0,message:n(`login.usernameRequired`,null,`请输入用户名`)}]}),(0,M.jsx)(C.Input,{field:`password`,label:n(`login.password`,null,`密码`),prefix:(0,M.jsx)(ge,{}),type:`password`,size:`large`,autoComplete:`current-password`,placeholder:n(`login.passwordPlaceholder`,null,`请输入密码`),rules:[{required:!0,message:n(`login.passwordRequired`,null,`请输入密码`)}]}),(0,M.jsx)(b,{htmlType:`submit`,theme:`solid`,type:`primary`,size:`large`,block:!0,loading:r,children:n(`login.submit`,null,`登录`)})]}),(0,M.jsx)(Ea,{type:`tertiary`,className:`cs-login-note`,children:n(`login.authorizedOnly`,null,`仅在明确授权的范围内开展安全测试`)})]})})]})}var ka=`modulepreload`,Aa=function(e){return`/static/app/`+e},ja={},Ma=function(e){return e.pathname.endsWith(`.css`)},Na=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},$=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=Aa(t,n);let r=s(t),i=Ma(r);return Na(ja,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:ka,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{let i=a=>{t.removeEventListener(`load`,i),t.removeEventListener(`error`,i),a.type===`error`?n(Error(`Unable to preload CSS for ${r}`)):e(a)};t.addEventListener(`load`,i),t.addEventListener(`error`,i)})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Pa={dashboard:(0,O.lazy)(()=>$(()=>import(`./dashboard-Dwi74cCO.js`),__vite__mapDeps([0,1,2,3,4,5]))),chat:(0,O.lazy)(()=>$(()=>import(`./chat-iFaq7TmY.js`),__vite__mapDeps([6,1,2,3,4,7,8,9,10,11,12]))),"deep-assessments":(0,O.lazy)(()=>$(()=>import(`./deep-assessments-BwHg6NCr.js`),__vite__mapDeps([13,1,2,3,4,10,9,14,15,16]))),hitl:(0,O.lazy)(()=>$(()=>import(`./hitl-hVYHftcD.js`),__vite__mapDeps([17,1,2,3,4,18]))),"tool-guard":(0,O.lazy)(()=>$(()=>import(`./tool-guard-DY35NYks.js`),__vite__mapDeps([19,1,2,3,4,20]))),projects:(0,O.lazy)(()=>$(()=>import(`./projects-CfcDnjFh.js`),__vite__mapDeps([21,1,2,3,4,9,14,15,22,11,23,24]))),"asset-overview":(0,O.lazy)(()=>$(()=>import(`./asset-overview-ClxkP_Uu.js`),__vite__mapDeps([25,1,2,3,4,26,23,27]))),"asset-library":(0,O.lazy)(()=>$(()=>import(`./asset-library-Btn_YOu0.js`),__vite__mapDeps([28,1,2,3,4,11,23,26,22,29]))),"info-collect":(0,O.lazy)(()=>$(()=>import(`./info-collect-CIMK0OyE.js`),__vite__mapDeps([30,1,2,3,4,11,26,23,31]))),vulnerabilities:(0,O.lazy)(()=>$(()=>import(`./vulnerabilities-BRH58_rp.js`),__vite__mapDeps([32,1,2,3,4,7,11,33]))),tasks:(0,O.lazy)(()=>$(()=>import(`./tasks-C9yzz-_n.js`),__vite__mapDeps([34,1,2,3,4,11,35]))),workflows:(0,O.lazy)(()=>$(()=>import(`./workflows-BgrBtPdj.js`),__vite__mapDeps([36,1,2,3,4,37]))),webshell:(0,O.lazy)(()=>$(()=>import(`./webshell-CE6Yp5FY.js`),__vite__mapDeps([38,1,2,3,4,11,39]))),"c2-listeners":(0,O.lazy)(()=>$(()=>import(`./c2-listeners-7rFR5Rx6.js`),__vite__mapDeps([40,1,2,3,4,41,42,43,11,44]))),"c2-sessions":(0,O.lazy)(()=>$(()=>import(`./c2-sessions-CnBIfRAo.js`),__vite__mapDeps([45,1,2,3,4,41,42,43,46]))),"c2-tasks":(0,O.lazy)(()=>$(()=>import(`./c2-tasks-FVvnpyKj.js`),__vite__mapDeps([47,1,2,3,4,41,42,43,48]))),"c2-payloads":(0,O.lazy)(()=>$(()=>import(`./c2-payloads-DP3Iw5IZ.js`),__vite__mapDeps([49,1,2,3,4,41,42,43,50]))),"c2-events":(0,O.lazy)(()=>$(()=>import(`./c2-events-Cdd7cKs8.js`),__vite__mapDeps([51,1,2,3,4,41,42,43,52]))),"c2-profiles":(0,O.lazy)(()=>$(()=>import(`./c2-profiles-Cxv9lUnu.js`),__vite__mapDeps([53,1,2,3,4,41,42,54]))),"chat-files":(0,O.lazy)(()=>$(()=>import(`./chat-files-BvkWbj5T.js`),__vite__mapDeps([55,1,2,3,4,56]))),"plugin-hub":(0,O.lazy)(()=>$(()=>import(`./plugin-hub-BhSjc1VJ.js`),__vite__mapDeps([57,1,2,3,4,8,58]))),"mcp-monitor":(0,O.lazy)(()=>$(()=>import(`./mcp-monitor-DHXOIA-R.js`),__vite__mapDeps([59,1,2,3,4,60]))),"mcp-management":(0,O.lazy)(()=>$(()=>import(`./mcp-management-Be2zIK90.js`),__vite__mapDeps([61,1,2,3,4,62]))),"knowledge-retrieval-logs":(0,O.lazy)(()=>$(()=>import(`./knowledge-retrieval-logs-CJolZ5T-.js`),__vite__mapDeps([63,1,2,3,4]))),"knowledge-management":(0,O.lazy)(()=>$(()=>import(`./knowledge-management-DxjSMTdf.js`),__vite__mapDeps([64,1,2,3,4]))),"skills-monitor":(0,O.lazy)(()=>$(()=>import(`./skills-monitor-Bs5yNZYW.js`),__vite__mapDeps([65,1,3,2,4]))),"skills-management":(0,O.lazy)(()=>$(()=>import(`./skills-management-CBXR8d2s.js`),__vite__mapDeps([66,1,2,3,4]))),"agents-management":(0,O.lazy)(()=>$(()=>import(`./agents-management-BH4GA4Vt.js`),__vite__mapDeps([67,1,2,3,4]))),"roles-management":(0,O.lazy)(()=>$(()=>import(`./roles-management-DZI3VXhR.js`),__vite__mapDeps([68,1,2,3,4,69]))),"platform-rbac":(0,O.lazy)(()=>$(()=>import(`./platform-rbac-BDY_zjz7.js`),__vite__mapDeps([70,1,2,3,4]))),settings:(0,O.lazy)(()=>$(()=>import(`./settings-CgtfKueL.js`),__vite__mapDeps([71,1,2,3,4,10,72]))),"api-docs":(0,O.lazy)(()=>$(()=>import(`./api-docs-BqzLMZ8q.js`),__vite__mapDeps([73,1,2,3,4,74])))},{Title:Fa,Text:Ia}=c;function La(){return(0,M.jsx)(`div`,{className:`cs-page-loading`,children:(0,M.jsx)(se,{size:`large`})})}function Ra({code:e,title:t,description:n}){return(0,M.jsxs)(`div`,{className:`cs-page-loading`,style:{flexDirection:`column`,gap:8},children:[(0,M.jsx)(Fa,{heading:2,style:{margin:0},children:e}),(0,M.jsx)(Ia,{strong:!0,children:t}),n&&(0,M.jsx)(Ia,{type:`tertiary`,children:n})]})}function za(){let{pageId:e}=Ue(),{hasPermission:t,hasAnyPermission:n}=st(),r=P(),i=At(e),a=e?Pa[e]:null,o=(0,O.useMemo)(()=>{if(!i)return!0;if(i.anyPermission)return n(i.anyPermission);if(i.permission)return t(i.permission);let e=i.parent?At(i.parent):null;return!e?.anyPermission||n(e.anyPermission)},[i,t,n]);return i?a?o?(0,M.jsx)(O.Suspense,{fallback:(0,M.jsx)(La,{}),children:(0,M.jsx)(a,{})}):(0,M.jsx)(Ra,{code:`403`,title:r(`common.forbidden`,null,`当前账号没有访问该页面的权限`)}):(0,M.jsx)(Ra,{code:`404`,title:i.fallback,description:r(`common.pagePending`,null,`页面尚未注册`)}):(0,M.jsx)(Ra,{code:`404`,title:r(`common.pageNotFound`,null,`页面不存在`)})}function Ba(){let{authenticated:e,checking:t}=st();return t?(0,M.jsx)(La,{}):e?(0,M.jsx)(Be,{children:(0,M.jsxs)(Ve,{element:(0,M.jsx)(wa,{}),children:[(0,M.jsx)(Ve,{path:`/`,element:(0,M.jsx)(Ie,{to:`/dashboard`,replace:!0})}),(0,M.jsx)(Ve,{path:`/system-update`,element:(0,M.jsx)(Ie,{to:`/settings?section=update`,replace:!0})}),(0,M.jsx)(Ve,{path:`/:pageId`,element:(0,M.jsx)(za,{})}),(0,M.jsx)(Ve,{path:`*`,element:(0,M.jsx)(Ie,{to:`/dashboard`,replace:!0})})]})}):(0,M.jsx)(Oa,{})}var Va={"zh-CN":pe,"en-US":Ee,"ru-RU":xe,"ar-SA":w};function Ha(){let{lang:e}=vt();return(0,M.jsx)(n,{locale:Va[e]||pe,direction:e===`ar-SA`?`rtl`:`ltr`,children:(0,M.jsx)(ot,{children:(0,M.jsx)(ze,{children:(0,M.jsx)(Ba,{})})})})}(0,We.createRoot)(document.getElementById(`root`)).render((0,M.jsx)(O.StrictMode,{children:(0,M.jsx)(Tt,{children:(0,M.jsx)(_t,{children:(0,M.jsx)(Ha,{})})})}));export{Ri as A,Ze as B,Ni as C,Bi as D,Fi as E,P as F,A as H,st as I,j as L,Et as M,ct as N,Vi as O,vt as P,tt as R,Yi as S,zi as T,nt as V,$i as _,fa as a,Xi as b,da as c,ca as d,oa as f,ea as g,ra as h,ha as i,Wi as j,Li as k,na as l,Qi as m,pa as n,aa as o,Zi as p,ma as r,ta as s,$ as t,sa as u,ia as v,ji as w,Ji as x,la as y,rt as z}; \ No newline at end of file diff --git a/web/static/app/assets/info-collect-CnstRscn.js b/web/static/app/assets/info-collect-CIMK0OyE.js similarity index 99% rename from web/static/app/assets/info-collect-CnstRscn.js rename to web/static/app/assets/info-collect-CIMK0OyE.js index 986ef37f..bb42cbf2 100644 --- a/web/static/app/assets/info-collect-CnstRscn.js +++ b/web/static/app/assets/info-collect-CIMK0OyE.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,Bt as i,E as a,G as o,I as s,R as c,S as l,U as u,W as d,d as f,lt as ee,p,ut as m,v as h,x as g,y as _}from"./semi-65W_4I1v.js";import{F as v,I as te,L as y,S as b,b as x,c as S,d as C,i as ne,l as w,m as re,p as ie,s as T,u as ae,x as oe}from"./index-CAEPLS-g.js";import{t as se}from"./project-options-CMQbwv_U.js";import{a as E}from"./AssetBits-DtqSAj0f.js";import{a as D,i as O,o as k}from"./assetTarget-D2PEjBAg.js";var A=e(t(),1),j={fofa:{label:`FOFA`,maxSize:1e4,defaultFields:`host,ip,port,domain,title,protocol,country,region,city,server`,placeholder:`app="Apache" && country="CN"`,fieldPresets:[[`最小字段`,`host,ip,port,domain`],[`Web 常用`,`host,title,ip,port,domain,protocol,server,icp,country,region,city`],[`情报增强`,`host,ip,port,domain,title,protocol,country,region,city,server,asn,org,icp,header,banner`]],queryPresets:[[`Apache + 中国`,`app="Apache" && country="CN"`],[`登录页 + 中国`,`title="登录" && country="CN"`],[`指定域名`,`domain="example.com"`],[`指定 IP`,`ip="1.1.1.1"`]],supportsFull:!0},zoomeye:{label:`ZoomEye`,maxSize:1e4,defaultFields:`ip,port,domain,hostname,title,service,app,country,city`,placeholder:`app="Apache" && country="CN"`,fieldPresets:[[`最小字段`,`ip,port,domain,hostname`],[`Web 常用`,`ip,port,domain,hostname,title,service,app,country,city`],[`情报增强`,`ip,port,domain,hostname,title,service,app,country,city,org,isp,ssl`]],queryPresets:[[`Apache + 中国`,`app="Apache" && country="CN"`],[`SSH 服务`,`service="ssh"`],[`指定域名`,`domain="example.com"`],[`指定 IP`,`ip="1.1.1.1"`]],supportsFull:!1},quake:{label:`Quake`,maxSize:1e4,defaultFields:`ip,port,domain,service.name,service.http.title,location.country_cn,location.province_cn,location.city_cn`,placeholder:`service.name:"http" AND country_cn:"中国"`,fieldPresets:[[`最小字段`,`ip,port,domain`],[`Web 常用`,`ip,port,domain,service.name,service.http.title,location.country_cn,location.city_cn`],[`情报增强`,`ip,port,domain,service.name,service.http.title,service.http.server,location.country_cn,location.province_cn,location.city_cn,asn`]],queryPresets:[[`HTTP + 中国`,`service.name:"http" AND country_cn:"中国"`],[`443 端口`,`port:443`],[`指定域名`,`domain:"example.com"`],[`指定 IP`,`ip:"1.1.1.1"`]],supportsFull:!0},shodan:{label:`Shodan`,maxSize:1e3,defaultFields:`ip_str,port,hostnames,domains,org,isp,location.country_name,location.city,product,transport`,placeholder:`product:nginx country:CN`,fieldPresets:[[`最小字段`,`ip_str,port,hostnames,domains`],[`Web 常用`,`ip_str,port,hostnames,domains,product,org,location.country_name,location.city`],[`情报增强`,`ip_str,port,hostnames,domains,org,isp,asn,location.country_name,location.city,product,transport,ssl.cert.subject.cn`]],queryPresets:[[`Nginx + 中国`,`product:nginx country:CN`],[`SSH 服务`,`port:22`],[`证书域名`,`ssl.cert.subject.cn:example.com`],[`Amazon 443`,`org:"Amazon" port:443`]],supportsFull:!1}},ce=Object.entries(j).map(([e,t])=>({value:e,label:t.label}));function le(e){return j[e]||j.fofa}function ue(e,t=5){let n=[`host`,`ip`,`port`,`domain`,`title`,`protocol`,`server`,`country`,`city`].filter(t=>e.includes(t)),r=e.filter(e=>!n.includes(e));return[...n,...r].slice(0,t)}function de(e,t){if(!e||typeof e!=`object`)return``;let n=t=>{for(let n of t){let t=e[n];if(Array.isArray(t)&&t.length)return String(t[0]);if(t)return String(t)}return``},r=n([`host`,`url`,`hostname`]);if(r)return r;let i=n([`domain`,`domains`,`hostnames`]);if(i)return i;let a=n([`ip`,`ip_str`]),o=e.port;return a?o?`${a}:${o}`:a:``}function fe(e,t){let n=new Set(t.map(Number));return(e||[]).filter((e,t)=>n.has(t))}var M=e(n(),1),{Text:N}=o;function P(e){if(e==null||e===``)return(0,M.jsx)(N,{type:`tertiary`,children:`—`});let t=Array.isArray(e)?e.join(`, `):typeof e==`object`?JSON.stringify(e):String(e);return(0,M.jsx)(E,{text:t,max:44})}function F(e,t){let n=de(e,t);return n?/^https?:\/\//i.test(n)?(0,M.jsx)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,className:`info-collect-target-link`,children:(0,M.jsx)(E,{text:n,max:44})}):(0,M.jsx)(E,{text:n,max:44}):(0,M.jsx)(N,{type:`tertiary`,children:`—`})}function pe({fields:e,results:t,visibleFields:n,selectedKeys:r,onSelectionChange:i,onOpenDetail:a,loading:o}){let s=v(),l=Array.isArray(e)?e:[],u=(Array.isArray(n)?n:[]).filter(e=>l.includes(e)),d=[{title:s(`assets.target`,null,`目标`),dataIndex:`__target`,width:240,render:(e,t)=>F(t,l)},...u.map(e=>({title:e,dataIndex:e,render:(t,n)=>P(n[e])})),{title:s(`common.actions`,null,`操作`),dataIndex:`__actions`,width:90,render:(e,t)=>(0,M.jsx)(c,{theme:`borderless`,size:`small`,onClick:()=>a(t),children:s(`common.view`,null,`详情`)})}],f=(t||[]).map((e,t)=>({...e,__key:String(t),__index:t}));return(0,M.jsx)(T,{columns:d,dataSource:f,rowKey:`__key`,loading:o,pagination:!1,rowSelection:{selectedRowKeys:r,onChange:e=>i(e)},emptyText:s(`infoCollect.noResults`,null,`暂无结果`)})}var{Text:I}=o;function me({visible:e,provider:t,text:n,onClose:i,onApply:a}){let o=v(),[u,f]=(0,A.useState)(!1),[ee,p]=(0,A.useState)(null),[m,h]=(0,A.useState)(null),[g,_]=(0,A.useState)(``),[te,b]=(0,A.useState)(0);(0,A.useEffect)(()=>{if(!e)return;let r=String(n||``).trim();if(!r)return;let i=!1;return f(!0),p(null),h(null),_(``),y.post(`/fofa/parse`,{provider:t,text:r}).then(e=>{i||(h(e||{}),_(String(e?.query||``)))}).catch(e=>{i||p(e)}).finally(()=>{i||f(!1)}),()=>{i=!0}},[e,t,n,te]);let x=e=>{let t=String(g||``).trim();t&&a?.(t,!!e)},C=Array.isArray(m?.warnings)?m.warnings.filter(Boolean):[];return(0,M.jsx)(S,{visible:e,title:o(`infoCollect.parseResultTitle`,null,`语法解析结果`),width:640,onCancel:i,footer:(0,M.jsxs)(s,{children:[(0,M.jsx)(c,{theme:`borderless`,onClick:i,children:o(`common.cancel`,null,`取消`)}),(0,M.jsx)(c,{onClick:()=>x(!1),disabled:!g.trim()||u,children:o(`infoCollect.parseModalApply`,null,`填入查询框`)}),(0,M.jsx)(c,{theme:`solid`,type:`primary`,onClick:()=>x(!0),disabled:!g.trim()||u,children:o(`infoCollect.parseModalApplyRun`,null,`填入并查询`)})]}),children:(0,M.jsxs)(s,{vertical:!0,align:`start`,spacing:10,style:{width:`100%`},children:[(0,M.jsxs)(I,{type:`tertiary`,children:[o(`infoCollect.naturalLanguageLabel`,null,`自然语言`),`:`,String(n||``).trim()||`—`]}),u&&(0,M.jsxs)(s,{children:[(0,M.jsx)(d,{size:`small`}),(0,M.jsx)(I,{type:`tertiary`,children:o(`infoCollect.parsePending`,null,`正在解析,请稍候…`)})]}),(0,M.jsx)(w,{error:ee,onRetry:()=>b(e=>e+1)}),m&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(l,{value:g,rows:3,className:`info-collect-parse-query`,onChange:_}),m.explanation&&(0,M.jsxs)(`div`,{className:`info-collect-parse-block`,children:[(0,M.jsx)(I,{strong:!0,size:`small`,children:o(`infoCollect.explanation`,null,`字段映射说明`)}),(0,M.jsx)(I,{type:`tertiary`,size:`small`,children:m.explanation})]}),C.length>0&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,description:C.join(`;`)})]})]})})}function L(e,t,n){if(e&&!Array.isArray(e)&&typeof e==`object`){let t=e[n];return Array.isArray(t)?t.filter(Boolean).join(`,`):t==null?``:String(t).trim()}let r=Array.isArray(t)?t.indexOf(n):-1;if(r<0||!Array.isArray(e))return``;let i=e[r];return i==null?``:String(i).trim()}function R(e,t,n){for(let r of n){let n=L(e,t,r);if(n)return n}return``}function z(e,t,n=`fofa`){let r=Number.parseInt(L(e,t,`port`),10),i=R(e,t,[`ip`,`ip_str`]),a=O(i)||D(i)?i.toLowerCase():``,o=R(e,t,[`domain`,`hostname`,`hostnames`,`domains`]).split(`,`)[0].replace(/^\[|\]$/g,``).replace(/^"|"$/g,``),s=o&&!O(o)&&!D(o)?k(o):``,c=R(e,t,[`protocol`,`service.name`,`transport`]).toLowerCase();return{host:R(e,t,[`host`,`hostname`]).split(`,`)[0].trim(),ip:a,port:Number.isFinite(r)?r:0,domain:s,protocol:/^[a-z][a-z0-9+.-]{0,31}$/.test(c)?c:``,title:R(e,t,[`title`,`service.http.title`]),server:R(e,t,[`server`,`product`]),country:R(e,t,[`country`,`location.country_cn`,`location.country_name`]),province:R(e,t,[`region`,`province`,`location.province_cn`]),city:R(e,t,[`city`,`location.city_cn`,`location.city`]),source:n||`fofa`,status:`active`}}async function he(e,{fields:t,provider:n,query:r,projectId:i,collectionName:a}){let o=(e||[]).map(e=>z(e,t,n)),s=o.filter(e=>e.host||e.ip||e.domain),c=o.length-s.length;if(!s.length)return{assets:s,invalidCount:c,created:0,updated:0,skipped:0};i&&s.forEach(e=>{e.project_id=i});let l={assets:s,source:n||`fofa`,source_query:r||``};i&&(l.collection={project_id:i,name:String(a||r||`导入资产`).trim()});let u=await y.post(`/assets/import`,l);return{assets:s,invalidCount:c,created:Number(u?.created||0),updated:Number(u?.updated||0),skipped:Number(u?.skipped||0),collection:u?.collection||null}}var{Text:B}=o,ge=`csf.info-collect.form`,V={provider:`fofa`,query:``,size:100,fields:j.fofa.defaultFields,full:!1};function H(){let e=v(),{hasPermission:t}=te(),n=t(`fofa:execute`),o=t(`asset:write`),[d,S]=ne(ge,V),[T,E]=(0,A.useState)(``),[D,O]=(0,A.useState)(!1),[k,j]=(0,A.useState)(null),[N,P]=(0,A.useState)(!1),[F,I]=(0,A.useState)(null),[L,R]=(0,A.useState)([]),[z,H]=(0,A.useState)([]),[U,_e]=(0,A.useState)(null),[ve,ye]=(0,A.useState)(!1),[be,xe]=(0,A.useState)([]),[W,Se]=(0,A.useState)(``),[Ce,we]=(0,A.useState)(``),G=le(d.provider),Te=G.label;(0,A.useEffect)(()=>{if(!t(`project:read`))return;let e=!1;return y.get(`/projects`,{limit:500}).then(t=>{e||xe(Array.isArray(t?.projects)?t.projects:[])}).catch(()=>{e||xe([])}),()=>{e=!0}},[t]),(0,A.useEffect)(()=>{H([]),R([]),j(null),I(null)},[d.provider]);let K=e=>S(t=>({...V,...t,...e})),Ee=e=>{let t=le(e);K({provider:e,fields:t.defaultFields,size:Math.min(Number(d.size||100),t.maxSize),full:!1})},q=Math.min(Math.max(Number(d.size||100),1),G.maxSize),J=async(t=1,r)=>{if(!n){b(e(`infoCollect.permissionDenied`,null,`当前账号没有 fofa:execute 权限`));return}let i=String(r??d.query??``).trim();if(!i)b(e(`infoCollect.enterFofaQuery`,null,`请输入查询语法`));else{P(!0),I(null);try{let e=await y.post(`/fofa/search`,{provider:d.provider,query:i,size:q,page:t,fields:d.fields,full:!!d.full});j(e),R([]),H(ue(e?.fields||[],5))}catch(e){I(e),j(null)}finally{P(!1)}}},De=()=>{S({...V}),j(null),I(null),R([]),H([]),E(``)},Y=Array.isArray(k?.fields)?k.fields:[],X=Array.isArray(k?.results)?k.results:[],Z=Number(k?.total||0),Q=Number(k?.size||q),$=Number(k?.page||1),Oe=async()=>{if(ve)return;if(!o){b(e(`infoCollect.noImportPermission`,null,`当前账号没有 asset:write 权限`));return}if(!L.length){b(e(`infoCollect.selectRowsFirst`,null,`请先选择需要入库的结果`));return}let t=fe(X,L);ye(!0);try{let n=await he(t,{fields:Y,provider:k?.provider||d.provider,query:k?.query||d.query,projectId:W,collectionName:Ce});if(!n.assets.length){b(e(`assets.noValidImportTarget`,null,`所选结果中没有可入库的有效资产目标`));return}let r=n.invalidCount?e(`assets.importDoneWithInvalid`,{created:n.created,updated:n.updated,invalid:n.invalidCount},`已新增 ${n.created} 条,更新 ${n.updated} 条,跳过 ${n.invalidCount} 条无有效目标的结果`):e(`assets.importDone`,{created:n.created,updated:n.updated},`已新增 ${n.created} 条,更新 ${n.updated} 条`),i=n.collection?.name?`,已写入资产库,并记下检索结果「${n.collection.name}」`:``;oe(`${r}${i}`),R([])}catch(t){x(t,e(`assets.importFailed`,null,`资产入库失败`))}finally{ye(!1)}},ke=(e,t)=>{K({query:e}),O(!1),t&&J(1,e)},Ae=(0,A.useMemo)(()=>U?Y.map(e=>{let t=U[e];return{label:e,value:Array.isArray(t)?t.join(`, `):t==null?`—`:String(t)}}):[],[U,Y]),je=k?e(`infoCollect.resultsMeta`,{total:Z,count:X.length,page:$,size:Q},`${Te} · 共 ${Z} 条 · 第 ${$} 页 · 每页 ${Q} 条 · 返回 ${X.length} 条`):``;return(0,M.jsxs)(`div`,{className:`info-collect-page`,children:[(0,M.jsx)(ie,{title:e(`infoCollectPage.title`,null,`信息收集`),description:`使用 FOFA 等空间测绘语法检索资产,并把结果直接入库。`,extra:(0,M.jsxs)(s,{children:[(0,M.jsx)(c,{icon:(0,M.jsx)(m,{}),onClick:()=>{k&&J($)},children:e(`common.refresh`,null,`刷新`)}),(0,M.jsx)(c,{onClick:De,children:e(`infoCollectPage.reset`,null,`重置`)})]})}),!n&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,className:`info-collect-permission`,description:e(`infoCollect.permissionDeniedHint`,null,`当前账号没有 fofa:execute 权限:查询、列字段与入库操作不可用,请联系管理员授权。`)}),(0,M.jsx)(w,{error:F,onRetry:()=>J($)}),(0,M.jsx)(re,{title:e(`infoCollectPage.fofaQuerySyntax`,null,`查询语法`),children:(0,M.jsxs)(`div`,{className:`info-collect-form`,children:[(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(_,{value:d.provider,optionList:ce,onChange:Ee,style:{width:150}}),(0,M.jsxs)(`span`,{className:`info-collect-size`,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:e(`infoCollectPage.returnCount`,null,`返回数量`)}),(0,M.jsx)(g,{value:q,min:1,max:G.maxSize,onChange:e=>K({size:e}),style:{width:120}})]}),(0,M.jsx)(f,{checked:!!d.full,disabled:!G.supportsFull,onChange:e=>K({full:e})}),(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:`full`}),(0,M.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,M.jsx)(ee,{}),onClick:()=>J(1),loading:N,disabled:!n,children:e(`infoCollectPage.confirm`,null,`查询`)}),(0,M.jsx)(c,{disabled:!T.trim()||!n,onClick:()=>O(!0),title:e(`infoCollectPage.parseBtnTitle`,null,`将自然语言解析为查询语法`),children:e(`infoCollectPage.parseBtn`,null,`AI 解析`)})]}),(0,M.jsx)(l,{value:d.query,rows:3,placeholder:`${Te}:${G.placeholder}`,className:`info-collect-query`,onChange:e=>K({query:e})}),(0,M.jsxs)(s,{wrap:!0,className:`info-collect-presets`,children:[(0,M.jsxs)(B,{type:`tertiary`,size:`small`,children:[e(`infoCollectPage.fillExample`,null,`示例`),`:`]}),G.queryPresets.map(([e,t])=>(0,M.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>K({query:t}),children:e},e))]}),(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:e(`infoCollectPage.returnFields`,null,`返回字段`)}),(0,M.jsx)(u,{value:d.fields,onChange:e=>K({fields:e}),className:`info-collect-fields`,style:{width:420}}),G.fieldPresets.map(([e,t])=>(0,M.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>K({fields:t}),children:e},e))]}),(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(_,{value:W,optionList:[{value:``,label:`不归入项目集合`},...se(be,e,{currentId:W})],placeholder:`归入项目`,style:{width:220},onChange:e=>Se(e||``)}),(0,M.jsx)(u,{value:Ce,disabled:!W,placeholder:`集合名称,留空则使用查询语句`,style:{width:280},onChange:we})]}),(0,M.jsx)(l,{value:T,rows:2,placeholder:e(`infoCollectPage.nlPlaceholder`,null,`自然语言:例如 找中国 Apache 站点,标题包含登录`),className:`info-collect-natural`,onChange:E})]})}),(0,M.jsxs)(re,{className:`info-collect-results`,title:e(`infoCollectPage.queryResults`,null,`查询结果`),extra:(0,M.jsxs)(s,{className:`info-collect-results-actions`,wrap:!0,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:je}),(0,M.jsx)(_,{multiple:!0,value:z,optionList:Y.map(e=>({value:e,label:e})),disabled:!Y.length,placeholder:e(`infoCollectPage.showColumns`,null,`显示字段`),maxTagCount:5,style:{minWidth:220},onChange:e=>{let t=(e||[]).slice(0,5);(e||[]).length>5&&b(`最多显示 5 个字段`),H(t)}}),(0,M.jsx)(c,{icon:(0,M.jsx)(i,{}),disabled:!o||!L.length,loading:ve,onClick:Oe,children:e(`assets.importSelected`,null,`入库所选`)})]}),children:[k?.warning&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,className:`info-collect-warning`,description:k.warning}),!k&&!N&&!F?(0,M.jsx)(a,{title:e(`infoCollect.noResults`,null,`暂无结果`),description:n?`输入查询语法后点击“查询”。`:`当前账号缺少 fofa:execute 权限。`,style:{padding:40}}):(0,M.jsx)(pe,{fields:Y,results:X,visibleFields:z,selectedKeys:L,onSelectionChange:R,onOpenDetail:_e,loading:N}),k&&Z>Q&&(0,M.jsx)(`div`,{className:`info-collect-pagination`,children:(0,M.jsx)(h,{total:Z,pageSize:Q,currentPage:$,onPageChange:e=>J(e),showTotal:!0})}),k&&(0,M.jsx)(B,{type:`tertiary`,size:`small`,className:`info-collect-selected-meta`,children:e(`infoCollectPage.selectedRows`,{count:L.length},`已选择 ${L.length} 条`)})]}),(0,M.jsx)(p,{visible:!!U,onCancel:()=>_e(null),title:e(`infoCollect.detailTitle`,null,`结果详情`),width:600,placement:`right`,children:U&&(0,M.jsxs)(`div`,{className:`info-collect-detail`,children:[(0,M.jsx)(B,{strong:!0,children:de(U,Y)||`—`}),(0,M.jsx)(C,{items:Ae,columns:1}),(0,M.jsx)(ae,{value:U,title:`原始 JSON`})]})}),(0,M.jsx)(me,{visible:D,provider:d.provider,text:T,onClose:()=>O(!1),onApply:ke})]})}export{H as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,Bt as i,E as a,G as o,I as s,R as c,S as l,U as u,W as d,d as f,lt as ee,p,ut as m,v as h,x as g,y as _}from"./semi-65W_4I1v.js";import{F as v,I as te,L as y,S as b,b as x,c as S,d as C,i as ne,l as w,m as re,p as ie,s as T,u as ae,x as oe}from"./index-DNMXun-U.js";import{t as se}from"./project-options-CMQbwv_U.js";import{a as E}from"./AssetBits-DtqSAj0f.js";import{a as D,i as O,o as k}from"./assetTarget-D2PEjBAg.js";var A=e(t(),1),j={fofa:{label:`FOFA`,maxSize:1e4,defaultFields:`host,ip,port,domain,title,protocol,country,region,city,server`,placeholder:`app="Apache" && country="CN"`,fieldPresets:[[`最小字段`,`host,ip,port,domain`],[`Web 常用`,`host,title,ip,port,domain,protocol,server,icp,country,region,city`],[`情报增强`,`host,ip,port,domain,title,protocol,country,region,city,server,asn,org,icp,header,banner`]],queryPresets:[[`Apache + 中国`,`app="Apache" && country="CN"`],[`登录页 + 中国`,`title="登录" && country="CN"`],[`指定域名`,`domain="example.com"`],[`指定 IP`,`ip="1.1.1.1"`]],supportsFull:!0},zoomeye:{label:`ZoomEye`,maxSize:1e4,defaultFields:`ip,port,domain,hostname,title,service,app,country,city`,placeholder:`app="Apache" && country="CN"`,fieldPresets:[[`最小字段`,`ip,port,domain,hostname`],[`Web 常用`,`ip,port,domain,hostname,title,service,app,country,city`],[`情报增强`,`ip,port,domain,hostname,title,service,app,country,city,org,isp,ssl`]],queryPresets:[[`Apache + 中国`,`app="Apache" && country="CN"`],[`SSH 服务`,`service="ssh"`],[`指定域名`,`domain="example.com"`],[`指定 IP`,`ip="1.1.1.1"`]],supportsFull:!1},quake:{label:`Quake`,maxSize:1e4,defaultFields:`ip,port,domain,service.name,service.http.title,location.country_cn,location.province_cn,location.city_cn`,placeholder:`service.name:"http" AND country_cn:"中国"`,fieldPresets:[[`最小字段`,`ip,port,domain`],[`Web 常用`,`ip,port,domain,service.name,service.http.title,location.country_cn,location.city_cn`],[`情报增强`,`ip,port,domain,service.name,service.http.title,service.http.server,location.country_cn,location.province_cn,location.city_cn,asn`]],queryPresets:[[`HTTP + 中国`,`service.name:"http" AND country_cn:"中国"`],[`443 端口`,`port:443`],[`指定域名`,`domain:"example.com"`],[`指定 IP`,`ip:"1.1.1.1"`]],supportsFull:!0},shodan:{label:`Shodan`,maxSize:1e3,defaultFields:`ip_str,port,hostnames,domains,org,isp,location.country_name,location.city,product,transport`,placeholder:`product:nginx country:CN`,fieldPresets:[[`最小字段`,`ip_str,port,hostnames,domains`],[`Web 常用`,`ip_str,port,hostnames,domains,product,org,location.country_name,location.city`],[`情报增强`,`ip_str,port,hostnames,domains,org,isp,asn,location.country_name,location.city,product,transport,ssl.cert.subject.cn`]],queryPresets:[[`Nginx + 中国`,`product:nginx country:CN`],[`SSH 服务`,`port:22`],[`证书域名`,`ssl.cert.subject.cn:example.com`],[`Amazon 443`,`org:"Amazon" port:443`]],supportsFull:!1}},ce=Object.entries(j).map(([e,t])=>({value:e,label:t.label}));function le(e){return j[e]||j.fofa}function ue(e,t=5){let n=[`host`,`ip`,`port`,`domain`,`title`,`protocol`,`server`,`country`,`city`].filter(t=>e.includes(t)),r=e.filter(e=>!n.includes(e));return[...n,...r].slice(0,t)}function de(e,t){if(!e||typeof e!=`object`)return``;let n=t=>{for(let n of t){let t=e[n];if(Array.isArray(t)&&t.length)return String(t[0]);if(t)return String(t)}return``},r=n([`host`,`url`,`hostname`]);if(r)return r;let i=n([`domain`,`domains`,`hostnames`]);if(i)return i;let a=n([`ip`,`ip_str`]),o=e.port;return a?o?`${a}:${o}`:a:``}function fe(e,t){let n=new Set(t.map(Number));return(e||[]).filter((e,t)=>n.has(t))}var M=e(n(),1),{Text:N}=o;function P(e){if(e==null||e===``)return(0,M.jsx)(N,{type:`tertiary`,children:`—`});let t=Array.isArray(e)?e.join(`, `):typeof e==`object`?JSON.stringify(e):String(e);return(0,M.jsx)(E,{text:t,max:44})}function F(e,t){let n=de(e,t);return n?/^https?:\/\//i.test(n)?(0,M.jsx)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,className:`info-collect-target-link`,children:(0,M.jsx)(E,{text:n,max:44})}):(0,M.jsx)(E,{text:n,max:44}):(0,M.jsx)(N,{type:`tertiary`,children:`—`})}function pe({fields:e,results:t,visibleFields:n,selectedKeys:r,onSelectionChange:i,onOpenDetail:a,loading:o}){let s=v(),l=Array.isArray(e)?e:[],u=(Array.isArray(n)?n:[]).filter(e=>l.includes(e)),d=[{title:s(`assets.target`,null,`目标`),dataIndex:`__target`,width:240,render:(e,t)=>F(t,l)},...u.map(e=>({title:e,dataIndex:e,render:(t,n)=>P(n[e])})),{title:s(`common.actions`,null,`操作`),dataIndex:`__actions`,width:90,render:(e,t)=>(0,M.jsx)(c,{theme:`borderless`,size:`small`,onClick:()=>a(t),children:s(`common.view`,null,`详情`)})}],f=(t||[]).map((e,t)=>({...e,__key:String(t),__index:t}));return(0,M.jsx)(T,{columns:d,dataSource:f,rowKey:`__key`,loading:o,pagination:!1,rowSelection:{selectedRowKeys:r,onChange:e=>i(e)},emptyText:s(`infoCollect.noResults`,null,`暂无结果`)})}var{Text:I}=o;function me({visible:e,provider:t,text:n,onClose:i,onApply:a}){let o=v(),[u,f]=(0,A.useState)(!1),[ee,p]=(0,A.useState)(null),[m,h]=(0,A.useState)(null),[g,_]=(0,A.useState)(``),[te,b]=(0,A.useState)(0);(0,A.useEffect)(()=>{if(!e)return;let r=String(n||``).trim();if(!r)return;let i=!1;return f(!0),p(null),h(null),_(``),y.post(`/fofa/parse`,{provider:t,text:r}).then(e=>{i||(h(e||{}),_(String(e?.query||``)))}).catch(e=>{i||p(e)}).finally(()=>{i||f(!1)}),()=>{i=!0}},[e,t,n,te]);let x=e=>{let t=String(g||``).trim();t&&a?.(t,!!e)},C=Array.isArray(m?.warnings)?m.warnings.filter(Boolean):[];return(0,M.jsx)(S,{visible:e,title:o(`infoCollect.parseResultTitle`,null,`语法解析结果`),width:640,onCancel:i,footer:(0,M.jsxs)(s,{children:[(0,M.jsx)(c,{theme:`borderless`,onClick:i,children:o(`common.cancel`,null,`取消`)}),(0,M.jsx)(c,{onClick:()=>x(!1),disabled:!g.trim()||u,children:o(`infoCollect.parseModalApply`,null,`填入查询框`)}),(0,M.jsx)(c,{theme:`solid`,type:`primary`,onClick:()=>x(!0),disabled:!g.trim()||u,children:o(`infoCollect.parseModalApplyRun`,null,`填入并查询`)})]}),children:(0,M.jsxs)(s,{vertical:!0,align:`start`,spacing:10,style:{width:`100%`},children:[(0,M.jsxs)(I,{type:`tertiary`,children:[o(`infoCollect.naturalLanguageLabel`,null,`自然语言`),`:`,String(n||``).trim()||`—`]}),u&&(0,M.jsxs)(s,{children:[(0,M.jsx)(d,{size:`small`}),(0,M.jsx)(I,{type:`tertiary`,children:o(`infoCollect.parsePending`,null,`正在解析,请稍候…`)})]}),(0,M.jsx)(w,{error:ee,onRetry:()=>b(e=>e+1)}),m&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(l,{value:g,rows:3,className:`info-collect-parse-query`,onChange:_}),m.explanation&&(0,M.jsxs)(`div`,{className:`info-collect-parse-block`,children:[(0,M.jsx)(I,{strong:!0,size:`small`,children:o(`infoCollect.explanation`,null,`字段映射说明`)}),(0,M.jsx)(I,{type:`tertiary`,size:`small`,children:m.explanation})]}),C.length>0&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,description:C.join(`;`)})]})]})})}function L(e,t,n){if(e&&!Array.isArray(e)&&typeof e==`object`){let t=e[n];return Array.isArray(t)?t.filter(Boolean).join(`,`):t==null?``:String(t).trim()}let r=Array.isArray(t)?t.indexOf(n):-1;if(r<0||!Array.isArray(e))return``;let i=e[r];return i==null?``:String(i).trim()}function R(e,t,n){for(let r of n){let n=L(e,t,r);if(n)return n}return``}function z(e,t,n=`fofa`){let r=Number.parseInt(L(e,t,`port`),10),i=R(e,t,[`ip`,`ip_str`]),a=O(i)||D(i)?i.toLowerCase():``,o=R(e,t,[`domain`,`hostname`,`hostnames`,`domains`]).split(`,`)[0].replace(/^\[|\]$/g,``).replace(/^"|"$/g,``),s=o&&!O(o)&&!D(o)?k(o):``,c=R(e,t,[`protocol`,`service.name`,`transport`]).toLowerCase();return{host:R(e,t,[`host`,`hostname`]).split(`,`)[0].trim(),ip:a,port:Number.isFinite(r)?r:0,domain:s,protocol:/^[a-z][a-z0-9+.-]{0,31}$/.test(c)?c:``,title:R(e,t,[`title`,`service.http.title`]),server:R(e,t,[`server`,`product`]),country:R(e,t,[`country`,`location.country_cn`,`location.country_name`]),province:R(e,t,[`region`,`province`,`location.province_cn`]),city:R(e,t,[`city`,`location.city_cn`,`location.city`]),source:n||`fofa`,status:`active`}}async function he(e,{fields:t,provider:n,query:r,projectId:i,collectionName:a}){let o=(e||[]).map(e=>z(e,t,n)),s=o.filter(e=>e.host||e.ip||e.domain),c=o.length-s.length;if(!s.length)return{assets:s,invalidCount:c,created:0,updated:0,skipped:0};i&&s.forEach(e=>{e.project_id=i});let l={assets:s,source:n||`fofa`,source_query:r||``};i&&(l.collection={project_id:i,name:String(a||r||`导入资产`).trim()});let u=await y.post(`/assets/import`,l);return{assets:s,invalidCount:c,created:Number(u?.created||0),updated:Number(u?.updated||0),skipped:Number(u?.skipped||0),collection:u?.collection||null}}var{Text:B}=o,ge=`csf.info-collect.form`,V={provider:`fofa`,query:``,size:100,fields:j.fofa.defaultFields,full:!1};function H(){let e=v(),{hasPermission:t}=te(),n=t(`fofa:execute`),o=t(`asset:write`),[d,S]=ne(ge,V),[T,E]=(0,A.useState)(``),[D,O]=(0,A.useState)(!1),[k,j]=(0,A.useState)(null),[N,P]=(0,A.useState)(!1),[F,I]=(0,A.useState)(null),[L,R]=(0,A.useState)([]),[z,H]=(0,A.useState)([]),[U,_e]=(0,A.useState)(null),[ve,ye]=(0,A.useState)(!1),[be,xe]=(0,A.useState)([]),[W,Se]=(0,A.useState)(``),[Ce,we]=(0,A.useState)(``),G=le(d.provider),Te=G.label;(0,A.useEffect)(()=>{if(!t(`project:read`))return;let e=!1;return y.get(`/projects`,{limit:500}).then(t=>{e||xe(Array.isArray(t?.projects)?t.projects:[])}).catch(()=>{e||xe([])}),()=>{e=!0}},[t]),(0,A.useEffect)(()=>{H([]),R([]),j(null),I(null)},[d.provider]);let K=e=>S(t=>({...V,...t,...e})),Ee=e=>{let t=le(e);K({provider:e,fields:t.defaultFields,size:Math.min(Number(d.size||100),t.maxSize),full:!1})},q=Math.min(Math.max(Number(d.size||100),1),G.maxSize),J=async(t=1,r)=>{if(!n){b(e(`infoCollect.permissionDenied`,null,`当前账号没有 fofa:execute 权限`));return}let i=String(r??d.query??``).trim();if(!i)b(e(`infoCollect.enterFofaQuery`,null,`请输入查询语法`));else{P(!0),I(null);try{let e=await y.post(`/fofa/search`,{provider:d.provider,query:i,size:q,page:t,fields:d.fields,full:!!d.full});j(e),R([]),H(ue(e?.fields||[],5))}catch(e){I(e),j(null)}finally{P(!1)}}},De=()=>{S({...V}),j(null),I(null),R([]),H([]),E(``)},Y=Array.isArray(k?.fields)?k.fields:[],X=Array.isArray(k?.results)?k.results:[],Z=Number(k?.total||0),Q=Number(k?.size||q),$=Number(k?.page||1),Oe=async()=>{if(ve)return;if(!o){b(e(`infoCollect.noImportPermission`,null,`当前账号没有 asset:write 权限`));return}if(!L.length){b(e(`infoCollect.selectRowsFirst`,null,`请先选择需要入库的结果`));return}let t=fe(X,L);ye(!0);try{let n=await he(t,{fields:Y,provider:k?.provider||d.provider,query:k?.query||d.query,projectId:W,collectionName:Ce});if(!n.assets.length){b(e(`assets.noValidImportTarget`,null,`所选结果中没有可入库的有效资产目标`));return}let r=n.invalidCount?e(`assets.importDoneWithInvalid`,{created:n.created,updated:n.updated,invalid:n.invalidCount},`已新增 ${n.created} 条,更新 ${n.updated} 条,跳过 ${n.invalidCount} 条无有效目标的结果`):e(`assets.importDone`,{created:n.created,updated:n.updated},`已新增 ${n.created} 条,更新 ${n.updated} 条`),i=n.collection?.name?`,已写入资产库,并记下检索结果「${n.collection.name}」`:``;oe(`${r}${i}`),R([])}catch(t){x(t,e(`assets.importFailed`,null,`资产入库失败`))}finally{ye(!1)}},ke=(e,t)=>{K({query:e}),O(!1),t&&J(1,e)},Ae=(0,A.useMemo)(()=>U?Y.map(e=>{let t=U[e];return{label:e,value:Array.isArray(t)?t.join(`, `):t==null?`—`:String(t)}}):[],[U,Y]),je=k?e(`infoCollect.resultsMeta`,{total:Z,count:X.length,page:$,size:Q},`${Te} · 共 ${Z} 条 · 第 ${$} 页 · 每页 ${Q} 条 · 返回 ${X.length} 条`):``;return(0,M.jsxs)(`div`,{className:`info-collect-page`,children:[(0,M.jsx)(ie,{title:e(`infoCollectPage.title`,null,`信息收集`),description:`使用 FOFA 等空间测绘语法检索资产,并把结果直接入库。`,extra:(0,M.jsxs)(s,{children:[(0,M.jsx)(c,{icon:(0,M.jsx)(m,{}),onClick:()=>{k&&J($)},children:e(`common.refresh`,null,`刷新`)}),(0,M.jsx)(c,{onClick:De,children:e(`infoCollectPage.reset`,null,`重置`)})]})}),!n&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,className:`info-collect-permission`,description:e(`infoCollect.permissionDeniedHint`,null,`当前账号没有 fofa:execute 权限:查询、列字段与入库操作不可用,请联系管理员授权。`)}),(0,M.jsx)(w,{error:F,onRetry:()=>J($)}),(0,M.jsx)(re,{title:e(`infoCollectPage.fofaQuerySyntax`,null,`查询语法`),children:(0,M.jsxs)(`div`,{className:`info-collect-form`,children:[(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(_,{value:d.provider,optionList:ce,onChange:Ee,style:{width:150}}),(0,M.jsxs)(`span`,{className:`info-collect-size`,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:e(`infoCollectPage.returnCount`,null,`返回数量`)}),(0,M.jsx)(g,{value:q,min:1,max:G.maxSize,onChange:e=>K({size:e}),style:{width:120}})]}),(0,M.jsx)(f,{checked:!!d.full,disabled:!G.supportsFull,onChange:e=>K({full:e})}),(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:`full`}),(0,M.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,M.jsx)(ee,{}),onClick:()=>J(1),loading:N,disabled:!n,children:e(`infoCollectPage.confirm`,null,`查询`)}),(0,M.jsx)(c,{disabled:!T.trim()||!n,onClick:()=>O(!0),title:e(`infoCollectPage.parseBtnTitle`,null,`将自然语言解析为查询语法`),children:e(`infoCollectPage.parseBtn`,null,`AI 解析`)})]}),(0,M.jsx)(l,{value:d.query,rows:3,placeholder:`${Te}:${G.placeholder}`,className:`info-collect-query`,onChange:e=>K({query:e})}),(0,M.jsxs)(s,{wrap:!0,className:`info-collect-presets`,children:[(0,M.jsxs)(B,{type:`tertiary`,size:`small`,children:[e(`infoCollectPage.fillExample`,null,`示例`),`:`]}),G.queryPresets.map(([e,t])=>(0,M.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>K({query:t}),children:e},e))]}),(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:e(`infoCollectPage.returnFields`,null,`返回字段`)}),(0,M.jsx)(u,{value:d.fields,onChange:e=>K({fields:e}),className:`info-collect-fields`,style:{width:420}}),G.fieldPresets.map(([e,t])=>(0,M.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>K({fields:t}),children:e},e))]}),(0,M.jsxs)(s,{className:`info-collect-form-row`,children:[(0,M.jsx)(_,{value:W,optionList:[{value:``,label:`不归入项目集合`},...se(be,e,{currentId:W})],placeholder:`归入项目`,style:{width:220},onChange:e=>Se(e||``)}),(0,M.jsx)(u,{value:Ce,disabled:!W,placeholder:`集合名称,留空则使用查询语句`,style:{width:280},onChange:we})]}),(0,M.jsx)(l,{value:T,rows:2,placeholder:e(`infoCollectPage.nlPlaceholder`,null,`自然语言:例如 找中国 Apache 站点,标题包含登录`),className:`info-collect-natural`,onChange:E})]})}),(0,M.jsxs)(re,{className:`info-collect-results`,title:e(`infoCollectPage.queryResults`,null,`查询结果`),extra:(0,M.jsxs)(s,{className:`info-collect-results-actions`,wrap:!0,children:[(0,M.jsx)(B,{type:`tertiary`,size:`small`,children:je}),(0,M.jsx)(_,{multiple:!0,value:z,optionList:Y.map(e=>({value:e,label:e})),disabled:!Y.length,placeholder:e(`infoCollectPage.showColumns`,null,`显示字段`),maxTagCount:5,style:{minWidth:220},onChange:e=>{let t=(e||[]).slice(0,5);(e||[]).length>5&&b(`最多显示 5 个字段`),H(t)}}),(0,M.jsx)(c,{icon:(0,M.jsx)(i,{}),disabled:!o||!L.length,loading:ve,onClick:Oe,children:e(`assets.importSelected`,null,`入库所选`)})]}),children:[k?.warning&&(0,M.jsx)(r,{type:`warning`,bordered:!0,closeIcon:null,className:`info-collect-warning`,description:k.warning}),!k&&!N&&!F?(0,M.jsx)(a,{title:e(`infoCollect.noResults`,null,`暂无结果`),description:n?`输入查询语法后点击“查询”。`:`当前账号缺少 fofa:execute 权限。`,style:{padding:40}}):(0,M.jsx)(pe,{fields:Y,results:X,visibleFields:z,selectedKeys:L,onSelectionChange:R,onOpenDetail:_e,loading:N}),k&&Z>Q&&(0,M.jsx)(`div`,{className:`info-collect-pagination`,children:(0,M.jsx)(h,{total:Z,pageSize:Q,currentPage:$,onPageChange:e=>J(e),showTotal:!0})}),k&&(0,M.jsx)(B,{type:`tertiary`,size:`small`,className:`info-collect-selected-meta`,children:e(`infoCollectPage.selectedRows`,{count:L.length},`已选择 ${L.length} 条`)})]}),(0,M.jsx)(p,{visible:!!U,onCancel:()=>_e(null),title:e(`infoCollect.detailTitle`,null,`结果详情`),width:600,placement:`right`,children:U&&(0,M.jsxs)(`div`,{className:`info-collect-detail`,children:[(0,M.jsx)(B,{strong:!0,children:de(U,Y)||`—`}),(0,M.jsx)(C,{items:Ae,columns:1}),(0,M.jsx)(ae,{value:U,title:`原始 JSON`})]})}),(0,M.jsx)(me,{visible:D,provider:d.provider,text:T,onClose:()=>O(!1),onApply:ke})]})}export{H as default}; \ No newline at end of file diff --git a/web/static/app/assets/knowledge-management-CQ0nnhXJ.js b/web/static/app/assets/knowledge-management-DxjSMTdf.js similarity index 98% rename from web/static/app/assets/knowledge-management-CQ0nnhXJ.js rename to web/static/app/assets/knowledge-management-DxjSMTdf.js index 2daaaa75..0a584e59 100644 --- a/web/static/app/assets/knowledge-management-CQ0nnhXJ.js +++ b/web/static/app/assets/knowledge-management-DxjSMTdf.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r}from"./react-QV7DAAIx.js";import{B as ee,G as i,I as a,Lt as o,N as s,Pt as te,R as c,U as ne,ft as re,i as l,lt as u,ot as d,ut as f,y as p}from"./semi-65W_4I1v.js";import{D as m,E as h,F as ie,I as ae,L as g,_,a as v,b as y,c as b,d as x,f as S,l as oe,m as se,p as C,s as w,x as T,y as ce}from"./index-CAEPLS-g.js";var E=e(t(),1),D=e(r(),1),{Text:O}=i;function k(){let e=ie(),t=n(),{hasPermission:r}=ae(),i=r(`knowledge:write`),k=r(`config:read`),[A,le]=(0,E.useState)(``),[j,M]=(0,E.useState)(``),[N,P]=(0,E.useState)(1),[F,I]=(0,E.useState)(20),[L,R]=(0,E.useState)(null),[z,B]=(0,E.useState)(null),[V,H]=(0,E.useState)(!1),[U,W]=(0,E.useState)(!1),[G,K]=(0,E.useState)(null),q=v(()=>g.get(`/knowledge/items`,{category:A||void 0,search:j||void 0,limit:F,offset:(N-1)*F}),[A,j,N,F]),J=v(()=>g.get(`/knowledge/stats`),[]),Y=v(()=>g.get(`/knowledge/categories`),[]),X=v(()=>g.get(`/knowledge/index-status`),[]),ue=Array.isArray(q.data?.items)?q.data.items:[],de=Number(q.data?.total||0),Z=q.data?.enabled===!1||X.data?.enabled===!1,fe=(Array.isArray(Y.data?.categories)?Y.data.categories:[]).map(e=>typeof e==`string`?{value:e,label:e}:{value:e.name||e.category,label:e.name||e.category}),Q=(0,E.useCallback)(()=>{q.reload(),J.reload(),X.reload()},[q,J,X]),pe=async()=>{let e=await L.form.validate();H(!0);try{let t={category:e.category.trim(),title:e.title.trim(),content:e.content};L.item?.id?await g.put(`/knowledge/items/${encodeURIComponent(L.item.id)}`,t):await g.post(`/knowledge/items`,t),T(L.item?.id?`知识项已更新`:`知识项已创建`),R(null),Q()}catch(e){y(e,`保存失败`)}finally{H(!1)}},me=e=>ce({title:`删除知识项「${e.title}」?`,content:`删除后需要重新索引,且不可恢复。`,onOk:async()=>{await g.del(`/knowledge/items/${encodeURIComponent(e.id)}`),T(`已删除`),Q()}}),$=async e=>{try{await g.post(`/knowledge/index`,e?{full:!0}:{}),T(`索引任务已提交`),X.reload()}catch(e){y(e,`构建索引失败`)}},he=async e=>{try{K(await g.post(`/knowledge/search`,{query:e,topK:5}))}catch(e){y(e,`检索失败`)}};return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(C,{title:e(`knowledge.title`,null,`知识管理`),description:`知识条目会参与智能体检索;修改后需要重建索引才能生效。`,extra:(0,D.jsxs)(a,{wrap:!0,children:[k&&(0,D.jsx)(c,{icon:(0,D.jsx)(d,{}),onClick:()=>t(`/settings?section=knowledge`),children:`知识库设置`}),(0,D.jsx)(c,{icon:(0,D.jsx)(f,{}),onClick:Q,children:`刷新`}),i&&(0,D.jsx)(c,{disabled:Z,onClick:()=>$(!1),children:`构建索引`}),i&&(0,D.jsx)(c,{disabled:Z,onClick:()=>$(!0),children:`全量重建`}),i&&(0,D.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,D.jsx)(re,{}),disabled:Z,onClick:()=>R({item:null,form:{}}),children:`新增知识`})]})}),Z&&(0,D.jsx)(ee,{type:`warning`,bordered:!0,closeIcon:null,style:{marginBottom:16},description:(0,D.jsxs)(a,{wrap:!0,children:[(0,D.jsx)(`span`,{children:q.data?.message||X.data?.message||`知识库功能未启用,请先在系统设置中开启知识检索并配置嵌入模型。`}),k&&(0,D.jsx)(c,{size:`small`,theme:`solid`,type:`primary`,onClick:()=>t(`/settings?section=knowledge`),children:`前往启用知识库`})]})}),(0,D.jsx)(_,{columns:4,metrics:[{id:`items`,label:`知识条目`,value:m(J.data?.total_items||0),loading:J.loading},{id:`categories`,label:`分类数`,value:m(J.data?.total_categories||0),loading:J.loading},{id:`indexed`,label:`已索引`,value:m(X.data?.indexed_items??X.data?.total_indexed??0),loading:X.loading},{id:`pending`,label:`待索引`,value:m(X.data?.pending_items??0),loading:X.loading}]}),(0,D.jsxs)(se,{title:`知识条目`,children:[(0,D.jsx)(oe,{error:q.error,onRetry:()=>q.reload()}),(0,D.jsx)(w,{columns:[{title:`标题`,dataIndex:`title`,render:(e,t)=>(0,D.jsx)(O,{strong:!0,children:e||t.filePath})},{title:`分类`,dataIndex:`category`,width:160,render:e=>e?(0,D.jsx)(s,{size:`small`,children:e}):`—`},{title:`更新时间`,dataIndex:`updatedAt`,width:180,render:e=>h(e)},{title:`操作`,width:150,render:(e,t)=>(0,D.jsxs)(a,{children:[(0,D.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>B(t),children:`查看`}),i&&(0,D.jsx)(c,{size:`small`,theme:`borderless`,icon:(0,D.jsx)(te,{}),onClick:()=>R({item:t,form:{}})}),i&&(0,D.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,D.jsx)(o,{}),onClick:()=>me(t)})]})}],dataSource:ue,rowKey:`id`,loading:q.loading,pagination:{currentPage:N,pageSize:F,total:de,onPageChange:P,onPageSizeChange:e=>{I(e),P(1)}},toolbar:(0,D.jsxs)(a,{children:[(0,D.jsx)(ne,{prefix:(0,D.jsx)(u,{}),value:j,onChange:e=>{M(e),P(1)},placeholder:`搜索标题或内容`,style:{width:220}}),(0,D.jsx)(p,{value:A,onChange:e=>{le(e||``),P(1)},placeholder:`全部分类`,style:{width:180},showClear:!0,optionList:fe}),(0,D.jsx)(c,{onClick:()=>W(!0),children:`检索测试`})]})})]}),(0,D.jsx)(b,{title:L?.item?`编辑知识项`:`新增知识项`,visible:!!L,onCancel:()=>R(null),onOk:pe,confirmLoading:V,width:760,children:(0,D.jsxs)(l,{getFormApi:e=>R(t=>t&&{...t,form:e}),initValues:L?.item?{category:L.item.category,title:L.item.title,content:L.item.content}:{},children:[(0,D.jsx)(l.Input,{field:`category`,label:`分类`,rules:[{required:!0,message:`请输入分类`}],placeholder:`例如 sql_injection`}),(0,D.jsx)(l.Input,{field:`title`,label:`标题`,rules:[{required:!0,message:`请输入标题`}]}),(0,D.jsx)(l.TextArea,{field:`content`,label:`内容(Markdown)`,rules:[{required:!0,message:`请输入内容`}],autosize:{minRows:10,maxRows:24}})]})},L?.item?.id||`new`),(0,D.jsx)(b,{title:z?.title||`知识项`,visible:!!z,onCancel:()=>B(null),width:640,children:z&&(0,D.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,D.jsx)(x,{items:[{label:`分类`,value:z.category},{label:`文件路径`,value:z.filePath},{label:`创建时间`,value:h(z.createdAt)},{label:`更新时间`,value:h(z.updatedAt)}]}),(0,D.jsx)(S,{content:z.content||`(内容需要打开原文查看)`})]})}),(0,D.jsxs)(b,{title:`知识检索测试`,visible:U,onCancel:()=>{W(!1),K(null)},footer:null,width:720,children:[(0,D.jsxs)(l,{onSubmit:({query:e})=>he(e),children:[(0,D.jsx)(l.Input,{field:`query`,label:`检索语句`,rules:[{required:!0,message:`请输入检索语句`}]}),(0,D.jsx)(c,{htmlType:`submit`,theme:`solid`,type:`primary`,children:`检索`})]}),G&&(0,D.jsxs)(`div`,{style:{marginTop:16,display:`flex`,flexDirection:`column`,gap:8},children:[(G.results||[]).map((e,t)=>(0,D.jsxs)(`div`,{style:{border:`1px solid var(--semi-color-border)`,borderRadius:8,padding:12},children:[(0,D.jsxs)(a,{children:[(0,D.jsxs)(s,{color:`blue`,children:[`#`,t+1]}),(0,D.jsx)(O,{strong:!0,children:e.item?.title||e.title||e.id}),e.score!==void 0&&(0,D.jsxs)(O,{type:`tertiary`,children:[`相似度 `,Number(e.score).toFixed(3)]})]}),(0,D.jsx)(`div`,{style:{marginTop:8},children:(0,D.jsx)(S,{content:String(e.content||e.item?.content||``).slice(0,600)})})]},e.id||t)),(G.results||[]).length===0&&(0,D.jsx)(O,{type:`tertiary`,children:`没有命中结果`})]})]})]})}export{k as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r}from"./react-QV7DAAIx.js";import{B as ee,G as i,I as a,Lt as o,N as s,Pt as te,R as c,U as ne,ft as re,i as l,lt as u,ot as d,ut as f,y as p}from"./semi-65W_4I1v.js";import{D as m,E as h,F as ie,I as ae,L as g,_,a as v,b as y,c as b,d as x,f as S,l as oe,m as se,p as C,s as w,x as T,y as ce}from"./index-DNMXun-U.js";var E=e(t(),1),D=e(r(),1),{Text:O}=i;function k(){let e=ie(),t=n(),{hasPermission:r}=ae(),i=r(`knowledge:write`),k=r(`config:read`),[A,le]=(0,E.useState)(``),[j,M]=(0,E.useState)(``),[N,P]=(0,E.useState)(1),[F,I]=(0,E.useState)(20),[L,R]=(0,E.useState)(null),[z,B]=(0,E.useState)(null),[V,H]=(0,E.useState)(!1),[U,W]=(0,E.useState)(!1),[G,K]=(0,E.useState)(null),q=v(()=>g.get(`/knowledge/items`,{category:A||void 0,search:j||void 0,limit:F,offset:(N-1)*F}),[A,j,N,F]),J=v(()=>g.get(`/knowledge/stats`),[]),Y=v(()=>g.get(`/knowledge/categories`),[]),X=v(()=>g.get(`/knowledge/index-status`),[]),ue=Array.isArray(q.data?.items)?q.data.items:[],de=Number(q.data?.total||0),Z=q.data?.enabled===!1||X.data?.enabled===!1,fe=(Array.isArray(Y.data?.categories)?Y.data.categories:[]).map(e=>typeof e==`string`?{value:e,label:e}:{value:e.name||e.category,label:e.name||e.category}),Q=(0,E.useCallback)(()=>{q.reload(),J.reload(),X.reload()},[q,J,X]),pe=async()=>{let e=await L.form.validate();H(!0);try{let t={category:e.category.trim(),title:e.title.trim(),content:e.content};L.item?.id?await g.put(`/knowledge/items/${encodeURIComponent(L.item.id)}`,t):await g.post(`/knowledge/items`,t),T(L.item?.id?`知识项已更新`:`知识项已创建`),R(null),Q()}catch(e){y(e,`保存失败`)}finally{H(!1)}},me=e=>ce({title:`删除知识项「${e.title}」?`,content:`删除后需要重新索引,且不可恢复。`,onOk:async()=>{await g.del(`/knowledge/items/${encodeURIComponent(e.id)}`),T(`已删除`),Q()}}),$=async e=>{try{await g.post(`/knowledge/index`,e?{full:!0}:{}),T(`索引任务已提交`),X.reload()}catch(e){y(e,`构建索引失败`)}},he=async e=>{try{K(await g.post(`/knowledge/search`,{query:e,topK:5}))}catch(e){y(e,`检索失败`)}};return(0,D.jsxs)(`div`,{children:[(0,D.jsx)(C,{title:e(`knowledge.title`,null,`知识管理`),description:`知识条目会参与智能体检索;修改后需要重建索引才能生效。`,extra:(0,D.jsxs)(a,{wrap:!0,children:[k&&(0,D.jsx)(c,{icon:(0,D.jsx)(d,{}),onClick:()=>t(`/settings?section=knowledge`),children:`知识库设置`}),(0,D.jsx)(c,{icon:(0,D.jsx)(f,{}),onClick:Q,children:`刷新`}),i&&(0,D.jsx)(c,{disabled:Z,onClick:()=>$(!1),children:`构建索引`}),i&&(0,D.jsx)(c,{disabled:Z,onClick:()=>$(!0),children:`全量重建`}),i&&(0,D.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,D.jsx)(re,{}),disabled:Z,onClick:()=>R({item:null,form:{}}),children:`新增知识`})]})}),Z&&(0,D.jsx)(ee,{type:`warning`,bordered:!0,closeIcon:null,style:{marginBottom:16},description:(0,D.jsxs)(a,{wrap:!0,children:[(0,D.jsx)(`span`,{children:q.data?.message||X.data?.message||`知识库功能未启用,请先在系统设置中开启知识检索并配置嵌入模型。`}),k&&(0,D.jsx)(c,{size:`small`,theme:`solid`,type:`primary`,onClick:()=>t(`/settings?section=knowledge`),children:`前往启用知识库`})]})}),(0,D.jsx)(_,{columns:4,metrics:[{id:`items`,label:`知识条目`,value:m(J.data?.total_items||0),loading:J.loading},{id:`categories`,label:`分类数`,value:m(J.data?.total_categories||0),loading:J.loading},{id:`indexed`,label:`已索引`,value:m(X.data?.indexed_items??X.data?.total_indexed??0),loading:X.loading},{id:`pending`,label:`待索引`,value:m(X.data?.pending_items??0),loading:X.loading}]}),(0,D.jsxs)(se,{title:`知识条目`,children:[(0,D.jsx)(oe,{error:q.error,onRetry:()=>q.reload()}),(0,D.jsx)(w,{columns:[{title:`标题`,dataIndex:`title`,render:(e,t)=>(0,D.jsx)(O,{strong:!0,children:e||t.filePath})},{title:`分类`,dataIndex:`category`,width:160,render:e=>e?(0,D.jsx)(s,{size:`small`,children:e}):`—`},{title:`更新时间`,dataIndex:`updatedAt`,width:180,render:e=>h(e)},{title:`操作`,width:150,render:(e,t)=>(0,D.jsxs)(a,{children:[(0,D.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>B(t),children:`查看`}),i&&(0,D.jsx)(c,{size:`small`,theme:`borderless`,icon:(0,D.jsx)(te,{}),onClick:()=>R({item:t,form:{}})}),i&&(0,D.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,D.jsx)(o,{}),onClick:()=>me(t)})]})}],dataSource:ue,rowKey:`id`,loading:q.loading,pagination:{currentPage:N,pageSize:F,total:de,onPageChange:P,onPageSizeChange:e=>{I(e),P(1)}},toolbar:(0,D.jsxs)(a,{children:[(0,D.jsx)(ne,{prefix:(0,D.jsx)(u,{}),value:j,onChange:e=>{M(e),P(1)},placeholder:`搜索标题或内容`,style:{width:220}}),(0,D.jsx)(p,{value:A,onChange:e=>{le(e||``),P(1)},placeholder:`全部分类`,style:{width:180},showClear:!0,optionList:fe}),(0,D.jsx)(c,{onClick:()=>W(!0),children:`检索测试`})]})})]}),(0,D.jsx)(b,{title:L?.item?`编辑知识项`:`新增知识项`,visible:!!L,onCancel:()=>R(null),onOk:pe,confirmLoading:V,width:760,children:(0,D.jsxs)(l,{getFormApi:e=>R(t=>t&&{...t,form:e}),initValues:L?.item?{category:L.item.category,title:L.item.title,content:L.item.content}:{},children:[(0,D.jsx)(l.Input,{field:`category`,label:`分类`,rules:[{required:!0,message:`请输入分类`}],placeholder:`例如 sql_injection`}),(0,D.jsx)(l.Input,{field:`title`,label:`标题`,rules:[{required:!0,message:`请输入标题`}]}),(0,D.jsx)(l.TextArea,{field:`content`,label:`内容(Markdown)`,rules:[{required:!0,message:`请输入内容`}],autosize:{minRows:10,maxRows:24}})]})},L?.item?.id||`new`),(0,D.jsx)(b,{title:z?.title||`知识项`,visible:!!z,onCancel:()=>B(null),width:640,children:z&&(0,D.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,D.jsx)(x,{items:[{label:`分类`,value:z.category},{label:`文件路径`,value:z.filePath},{label:`创建时间`,value:h(z.createdAt)},{label:`更新时间`,value:h(z.updatedAt)}]}),(0,D.jsx)(S,{content:z.content||`(内容需要打开原文查看)`})]})}),(0,D.jsxs)(b,{title:`知识检索测试`,visible:U,onCancel:()=>{W(!1),K(null)},footer:null,width:720,children:[(0,D.jsxs)(l,{onSubmit:({query:e})=>he(e),children:[(0,D.jsx)(l.Input,{field:`query`,label:`检索语句`,rules:[{required:!0,message:`请输入检索语句`}]}),(0,D.jsx)(c,{htmlType:`submit`,theme:`solid`,type:`primary`,children:`检索`})]}),G&&(0,D.jsxs)(`div`,{style:{marginTop:16,display:`flex`,flexDirection:`column`,gap:8},children:[(G.results||[]).map((e,t)=>(0,D.jsxs)(`div`,{style:{border:`1px solid var(--semi-color-border)`,borderRadius:8,padding:12},children:[(0,D.jsxs)(a,{children:[(0,D.jsxs)(s,{color:`blue`,children:[`#`,t+1]}),(0,D.jsx)(O,{strong:!0,children:e.item?.title||e.title||e.id}),e.score!==void 0&&(0,D.jsxs)(O,{type:`tertiary`,children:[`相似度 `,Number(e.score).toFixed(3)]})]}),(0,D.jsx)(`div`,{style:{marginTop:8},children:(0,D.jsx)(S,{content:String(e.content||e.item?.content||``).slice(0,600)})})]},e.id||t)),(G.results||[]).length===0&&(0,D.jsx)(O,{type:`tertiary`,children:`没有命中结果`})]})]})]})}export{k as default}; \ No newline at end of file diff --git a/web/static/app/assets/knowledge-retrieval-logs-DY1jNxJ9.js b/web/static/app/assets/knowledge-retrieval-logs-CJolZ5T-.js similarity index 96% rename from web/static/app/assets/knowledge-retrieval-logs-DY1jNxJ9.js rename to web/static/app/assets/knowledge-retrieval-logs-CJolZ5T-.js index 1252fa4c..b2bc678b 100644 --- a/web/static/app/assets/knowledge-retrieval-logs-DY1jNxJ9.js +++ b/web/static/app/assets/knowledge-retrieval-logs-CJolZ5T-.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,Lt as a,N as o,R as s,U as c,lt as l,ut as u}from"./semi-65W_4I1v.js";import{E as d,F as f,I as p,L as m,a as h,c as g,d as _,l as v,m as y,p as b,s as x,u as S,x as C,y as w}from"./index-CAEPLS-g.js";var T=e(t(),1),E=e(n(),1),{Text:D}=r;function O(){let e=f(),{hasPermission:t}=p(),n=t(`knowledge:delete`),[r,O]=(0,T.useState)(``),[k,A]=(0,T.useState)(50),[j,M]=(0,T.useState)(null),N=h(()=>m.get(`/knowledge/retrieval-logs`,{conversationId:r||void 0,limit:k}),[r,k]),P=Array.isArray(N.data?.logs)?N.data.logs:[],F=e=>w({title:`删除该检索日志?`,content:e.query||e.id,onOk:async()=>{await m.del(`/knowledge/retrieval-logs/${encodeURIComponent(e.id)}`),C(`已删除`),N.reload()}});return(0,E.jsxs)(`div`,{children:[(0,E.jsx)(b,{title:e(`knowledge.retrievalLogsTitle`,null,`检索历史`),description:`记录智能体每次知识库检索的语句、命中项与会话,用于回溯回答依据。`,extra:(0,E.jsx)(s,{icon:(0,E.jsx)(u,{}),onClick:()=>N.reload(),loading:N.loading,children:`刷新`})}),(0,E.jsxs)(y,{title:`检索记录(${P.length})`,children:[(0,E.jsx)(v,{error:N.error,onRetry:()=>N.reload()}),(0,E.jsx)(x,{columns:[{title:`检索语句`,dataIndex:`query`,render:(e,t)=>(0,E.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>M(t),style:{background:`none`,border:`none`,padding:0,cursor:`pointer`,textAlign:`left`,color:`var(--semi-color-primary)`},children:e||`—`})},{title:`风险类型`,dataIndex:`riskType`,width:140,render:e=>e?(0,E.jsx)(o,{size:`small`,children:e}):`—`},{title:`命中知识项`,dataIndex:`retrievedItems`,width:120,render:e=>(0,E.jsxs)(D,{type:`tertiary`,children:[Array.isArray(e)?e.length:0,` 条`]})},{title:`会话`,dataIndex:`conversationId`,width:200,render:e=>(0,E.jsx)(D,{type:`tertiary`,ellipsis:{showTooltip:!0},children:e||`—`})},{title:`时间`,dataIndex:`createdAt`,width:180,render:e=>d(e)},{title:`操作`,width:110,render:(e,t)=>(0,E.jsxs)(i,{children:[(0,E.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>M(t),children:`详情`}),n&&(0,E.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,E.jsx)(a,{}),onClick:()=>F(t)})]})}],dataSource:P,rowKey:`id`,loading:N.loading,pagination:!1,toolbar:(0,E.jsxs)(i,{children:[(0,E.jsx)(c,{prefix:(0,E.jsx)(l,{}),placeholder:`按会话 ID 过滤`,value:r,onChange:O,style:{width:260}}),(0,E.jsx)(c,{placeholder:`条数`,value:String(k),onChange:e=>A(Math.min(Math.max(Number(e)||50,1),500)),style:{width:100},suffix:(0,E.jsx)(D,{type:`tertiary`,children:`条`})})]})})]}),(0,E.jsx)(g,{title:`检索日志详情`,visible:!!j,onCancel:()=>M(null),width:560,children:j&&(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,E.jsx)(_,{items:[{label:`日志 ID`,value:j.id},{label:`检索语句`,value:j.query},{label:`风险类型`,value:j.riskType||`—`},{label:`会话 ID`,value:j.conversationId||`—`},{label:`消息 ID`,value:j.messageId||`—`},{label:`时间`,value:d(j.createdAt)}]}),(0,E.jsx)(S,{value:j.retrievedItems||[],title:`命中知识项`})]})})]})}export{O as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,Lt as a,N as o,R as s,U as c,lt as l,ut as u}from"./semi-65W_4I1v.js";import{E as d,F as f,I as p,L as m,a as h,c as g,d as _,l as v,m as y,p as b,s as x,u as S,x as C,y as w}from"./index-DNMXun-U.js";var T=e(t(),1),E=e(n(),1),{Text:D}=r;function O(){let e=f(),{hasPermission:t}=p(),n=t(`knowledge:delete`),[r,O]=(0,T.useState)(``),[k,A]=(0,T.useState)(50),[j,M]=(0,T.useState)(null),N=h(()=>m.get(`/knowledge/retrieval-logs`,{conversationId:r||void 0,limit:k}),[r,k]),P=Array.isArray(N.data?.logs)?N.data.logs:[],F=e=>w({title:`删除该检索日志?`,content:e.query||e.id,onOk:async()=>{await m.del(`/knowledge/retrieval-logs/${encodeURIComponent(e.id)}`),C(`已删除`),N.reload()}});return(0,E.jsxs)(`div`,{children:[(0,E.jsx)(b,{title:e(`knowledge.retrievalLogsTitle`,null,`检索历史`),description:`记录智能体每次知识库检索的语句、命中项与会话,用于回溯回答依据。`,extra:(0,E.jsx)(s,{icon:(0,E.jsx)(u,{}),onClick:()=>N.reload(),loading:N.loading,children:`刷新`})}),(0,E.jsxs)(y,{title:`检索记录(${P.length})`,children:[(0,E.jsx)(v,{error:N.error,onRetry:()=>N.reload()}),(0,E.jsx)(x,{columns:[{title:`检索语句`,dataIndex:`query`,render:(e,t)=>(0,E.jsx)(`button`,{type:`button`,className:`link-button`,onClick:()=>M(t),style:{background:`none`,border:`none`,padding:0,cursor:`pointer`,textAlign:`left`,color:`var(--semi-color-primary)`},children:e||`—`})},{title:`风险类型`,dataIndex:`riskType`,width:140,render:e=>e?(0,E.jsx)(o,{size:`small`,children:e}):`—`},{title:`命中知识项`,dataIndex:`retrievedItems`,width:120,render:e=>(0,E.jsxs)(D,{type:`tertiary`,children:[Array.isArray(e)?e.length:0,` 条`]})},{title:`会话`,dataIndex:`conversationId`,width:200,render:e=>(0,E.jsx)(D,{type:`tertiary`,ellipsis:{showTooltip:!0},children:e||`—`})},{title:`时间`,dataIndex:`createdAt`,width:180,render:e=>d(e)},{title:`操作`,width:110,render:(e,t)=>(0,E.jsxs)(i,{children:[(0,E.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>M(t),children:`详情`}),n&&(0,E.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,E.jsx)(a,{}),onClick:()=>F(t)})]})}],dataSource:P,rowKey:`id`,loading:N.loading,pagination:!1,toolbar:(0,E.jsxs)(i,{children:[(0,E.jsx)(c,{prefix:(0,E.jsx)(l,{}),placeholder:`按会话 ID 过滤`,value:r,onChange:O,style:{width:260}}),(0,E.jsx)(c,{placeholder:`条数`,value:String(k),onChange:e=>A(Math.min(Math.max(Number(e)||50,1),500)),style:{width:100},suffix:(0,E.jsx)(D,{type:`tertiary`,children:`条`})})]})})]}),(0,E.jsx)(g,{title:`检索日志详情`,visible:!!j,onCancel:()=>M(null),width:560,children:j&&(0,E.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,E.jsx)(_,{items:[{label:`日志 ID`,value:j.id},{label:`检索语句`,value:j.query},{label:`风险类型`,value:j.riskType||`—`},{label:`会话 ID`,value:j.conversationId||`—`},{label:`消息 ID`,value:j.messageId||`—`},{label:`时间`,value:d(j.createdAt)}]}),(0,E.jsx)(S,{value:j.retrievedItems||[],title:`命中知识项`})]})})]})}export{O as default}; \ No newline at end of file diff --git a/web/static/app/assets/mcp-management-BebvY2ig.js b/web/static/app/assets/mcp-management-Be2zIK90.js similarity index 99% rename from web/static/app/assets/mcp-management-BebvY2ig.js rename to web/static/app/assets/mcp-management-Be2zIK90.js index 7e9d2c36..a72fac73 100644 --- a/web/static/app/assets/mcp-management-BebvY2ig.js +++ b/web/static/app/assets/mcp-management-Be2zIK90.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,G as i,I as a,N as o,P as s,R as c,S as l,U as u,d,ft as f,lt as p,ut as m,y as h}from"./semi-65W_4I1v.js";import{F as g,I as _,L as v,_ as y,a as b,b as x,c as S,l as C,m as w,n as T,o as E,p as D,r as O,s as k,x as A,y as j,z as M}from"./index-CAEPLS-g.js";var N=e(t(),1),P={connected:{color:`green`,label:`已连接`},connecting:{color:`blue`,label:`连接中`},disconnected:{color:`amber`,label:`未连接`},disabled:{color:`grey`,label:`已停用`},error:{color:`red`,label:`连接失败`}};function F(e){return P[String(e||``).toLowerCase()]||{color:`grey`,label:e||`未知`}}function I(e){return e?String(e.type||e.transport||(e.command?`stdio`:`http`)).toLowerCase():`http`}function L(e){return e?e.is_external&&e.external_mcp?`${e.external_mcp}::${e.name}`:e.name||``:``}function R(e){return e?e.is_external?`外部 · ${e.external_mcp||`未知`}`:`内置`:`—`}var z=e(n(),1),{Text:B}=i,V={"my-stdio-server":{command:`python3`,args:["${HOME}/mcp-servers/main.py",`--port`,"${MCP_PORT:-3000}"],env:{API_KEY:"${API_KEY}",LOG_LEVEL:"${LOG_LEVEL:-INFO}"},timeout:300},"my-http-server":{type:`http`,url:`https://mcp.example.com/mcp`,headers:{Authorization:"Bearer ${MCP_TOKEN}"}},"my-sse-server":{type:`sse`,url:`http://127.0.0.1:8081/mcp/sse`}};function H(e,{editingName:t}){if(typeof e!=`object`||!e||Array.isArray(e))return{error:`配置必须是 JSON 对象`};let n=Object.keys(e);if(!n.length)return{error:`至少需要一个 MCP 配置`};if(t&&!e[t])return{error:`编辑模式下 JSON 必须包含配置名称 "${t}"`};for(let t of n){if(!t.trim())return{error:`配置名称不能为空`};let n=e[t];if(typeof n!=`object`||!n||Array.isArray(n))return{error:`"${t}" 的配置必须是对象`};delete n.external_mcp_enable;let r=n.type||n.transport||(n.command?`stdio`:n.url?`http`:``);if(!r)return{error:`"${t}" 需要指定 command(stdio)或 url + type(http/sse)`};if(r===`stdio`&&!n.command)return{error:`"${t}" 的 stdio 模式需要 command`};if((r===`http`||r===`sse`)&&!n.url)return{error:`"${t}" 的 ${r} 模式需要 url`}}return{error:``,names:n}}function U({canWrite:e,onChanged:t,refreshKey:n=0}){let i=g(),s=b(()=>v.get(`/external-mcp`),[n]),[u,d]=(0,N.useState)(``),[p,h]=(0,N.useState)(!1),[_,y]=(0,N.useState)(null),[T,D]=(0,N.useState)(``),[k,P]=(0,N.useState)(``),[L,R]=(0,N.useState)(!1),U=(0,N.useMemo)(()=>{let e=s.data?.servers||{};return Object.entries(e).sort(([e],[t])=>e.localeCompare(t))},[s.data]),W=(0,N.useCallback)(e=>s.reload(e),[s.reload]);O(()=>{typeof document<`u`&&document.hidden||W({silent:!0})},8e3);let G=(0,N.useCallback)(()=>{y(null),D(``),P(``),h(!0)},[]),K=(0,N.useCallback)(async e=>{y(e),D(``),P(``),h(!0);try{let t={...(await v.get(`/external-mcp/${encodeURIComponent(e)}`))?.config||{}};delete t.tool_count,delete t.external_mcp_enable,D(JSON.stringify({[e]:t},null,2))}catch(e){h(!1),x(e,i(`mcp.getConfigFailed`,null,`获取外部MCP配置失败`))}},[i]),q=(0,N.useCallback)(()=>{h(!1),y(null),P(``)},[]),J=(0,N.useCallback)(async(e,n)=>{let r=n===`connected`?`stop`:`start`;d(e);try{await v.post(`/external-mcp/${encodeURIComponent(e)}/${r}`,{}),A(r===`start`?`已提交启动请求,正在后台连接`:`外部 MCP 已停止`),W({silent:!0}),t?.()}catch(e){x(e,i(`mcp.operationFailed`,null,`操作失败`))}finally{d(``)}},[t,W,i]),Y=(0,N.useCallback)(e=>{j({title:i(`mcp.deleteExternalConfirm`,{name:e},`确定要删除外部MCP "${e}" 吗?`),content:`删除后该 MCP 的工具将从对话中移除。`,okText:i(`common.delete`,null,`删除`),onOk:async()=>{try{await v.del(`/external-mcp/${encodeURIComponent(e)}`),A(i(`mcp.deleteSuccess`,null,`删除成功`)),W(),t?.()}catch(e){x(e,i(`mcp.operationFailed`,null,`删除失败`))}}})},[t,W,i]),X=(0,N.useCallback)(async()=>{let e=T.trim();if(!e){P(i(`mcp.jsonEmpty`,null,`JSON不能为空`));return}let n;try{n=JSON.parse(e)}catch(e){P(`${i(`mcp.jsonError`,null,`JSON格式错误`)}: ${e.message}`);return}let{error:r,names:a}=H(n,{editingName:_});if(r)P(r);else{P(``),R(!0);try{let e=_?[_]:a;for(let t of e)await v.put(`/external-mcp/${encodeURIComponent(t)}`,{config:n[t]});A(i(`mcp.saveSuccess`,null,`保存成功`)),q(),W(),t?.()}catch(e){P(`${i(`mcp.operationFailed`,null,`保存失败`)}: ${M(e)}`)}finally{R(!1)}}},[q,_,T,t,W,i]),Z=(0,z.jsxs)(a,{spacing:8,children:[(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(m,{}),theme:`borderless`,onClick:()=>W(),loading:s.loading,children:i(`common.refresh`,null,`刷新`)}),(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(f,{}),disabled:!e,onClick:G,children:i(`mcp.addExternalMCP`,null,`添加外部MCP`)})]});return(0,z.jsxs)(w,{title:i(`mcp.externalConfig`,null,`外部 MCP 配置`),description:`stdio 传 command/args/env,http 与 sse 传 url/headers;状态每 8 秒自动刷新。`,extra:Z,children:[(0,z.jsx)(C,{error:s.error,onRetry:()=>W()}),!U.length&&!s.loading&&(0,z.jsxs)(`div`,{className:`mcp-management-empty`,children:[(0,z.jsx)(`p`,{children:i(`mcp.noExternalMCP`,null,`暂无外部 MCP`)}),(0,z.jsx)(c,{size:`small`,disabled:!e,onClick:G,children:i(`mcp.clickToAddExternal`,null,`点击添加外部 MCP`)})]}),(0,z.jsx)(`div`,{className:`mcp-management-mcp-grid`,children:U.map(([t,n])=>{let s=n?.config||{},l=String(n?.status||`disconnected`),d=F(l),f=I(s),p=l===`connected`;return(0,z.jsxs)(`div`,{className:`mcp-management-mcp-card`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-mcp-head`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-mcp-title`,children:[(0,z.jsx)(B,{strong:!0,children:t}),(0,z.jsx)(o,{size:`small`,color:d.color,children:d.label}),(0,z.jsx)(o,{size:`small`,color:`grey`,children:f.toUpperCase()}),Number(n?.tool_count)>0&&(0,z.jsx)(o,{size:`small`,color:`blue`,children:`${n.tool_count} 个工具`})]}),(0,z.jsxs)(a,{spacing:4,wrap:!0,children:[(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e||u===t||l===`connecting`,loading:u===t,onClick:()=>J(t,l),children:l===`connecting`?i(`mcp.connecting`,null,`连接中`):p?i(`mcp.stop`,null,`停止`):i(`mcp.start`,null,`启动`)}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>K(t),children:i(`common.edit`,null,`编辑`)}),(0,z.jsx)(c,{size:`small`,type:`danger`,theme:`borderless`,disabled:!e,onClick:()=>Y(t),children:i(`common.delete`,null,`删除`)})]})]}),(l===`error`||l===`disconnected`)&&n?.error&&(0,z.jsx)(r,{type:l===`error`?`danger`:`warning`,className:`mcp-management-mcp-error`,description:(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:n.error})}),(0,z.jsxs)(`div`,{className:`mcp-management-mcp-meta`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.transportMode`,null,`传输方式`)}),(0,z.jsx)(`span`,{children:f.toUpperCase()})]}),s.description&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.description`,null,`描述`)}),(0,z.jsx)(`span`,{children:s.description})]}),f===`stdio`&&s.command&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.command`,null,`命令`)}),(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:s.command})]}),f!==`stdio`&&s.url&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:`URL`}),(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:s.url})]}),Number(s.timeout)>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.timeout`,null,`超时`)}),(0,z.jsxs)(`span`,{children:[s.timeout,` `,i(`mcp.secondsUnit`,null,`秒`)]})]})]})]},t)})}),(0,z.jsx)(S,{title:_?`${i(`mcp.editExternalMCP`,null,`编辑外部MCP`)} · ${_}`:i(`mcp.addExternalMCP`,null,`添加外部 MCP`),visible:p,onCancel:q,onOk:X,confirmLoading:L,width:760,okText:i(`common.save`,null,`保存`),cancelText:i(`common.cancel`,null,`取消`),children:(0,z.jsxs)(`div`,{className:`mcp-management-form`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-form-head`,children:[(0,z.jsx)(B,{type:`tertiary`,children:_?`编辑模式下只提交当前名称的配置;external_mcp_enable 由启停按钮维护。`:`支持一次粘贴多个 MCP:{"name": {...}};保存后逐个写入 config.yaml。`}),!_&&(0,z.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>D(JSON.stringify(V,null,2)),children:`载入示例`}),T&&(0,z.jsx)(E,{text:T,size:`small`})]}),(0,z.jsx)(l,{className:`mcp-management-json`,rows:16,value:T,spellCheck:!1,placeholder:`{"my-http-server": {"type": "http", "url": "https://mcp.example.com/mcp"}}`,onChange:e=>{D(e),k&&P(``)}}),k&&(0,z.jsx)(`div`,{className:`mcp-management-form-error`,children:k})]})})]})}var{Text:W}=i;function G({canWrite:e,refreshKey:t=0}){let n=g(),[r,i]=(0,N.useState)(1),[l,f]=(0,N.useState)(20),[_,y]=(0,N.useState)(``),S=T(_,350),[E,D]=(0,N.useState)(`all`),[O,j]=(0,N.useState)(!0),[M,P]=(0,N.useState)({}),[F,I]=(0,N.useState)(!1),B=(0,N.useRef)(new Map),V=b(()=>v.get(`/config/tools`,{page:r,page_size:l,search:S,tool_filter:E===`all`?``:E,include_external:O?``:`0`}),[r,l,S,E,O,t]),H=V.data?.tools||[],U=Number(V.data?.total)||0,G=(0,N.useDeferredValue)(H);(0,N.useEffect)(()=>{(H||[]).forEach(e=>B.current.set(L(e),e))},[H]);let K=(0,N.useMemo)(()=>Object.keys(M),[M]),q=(0,N.useCallback)(e=>Object.prototype.hasOwnProperty.call(M,L(e))?M[L(e)]:e.enabled,[M]),J=(0,N.useCallback)((e,t)=>{let n=L(e);P(r=>{let i={...r};return t===e.enabled?delete i[n]:i[n]=t,i})},[]),Y=(0,N.useCallback)(e=>{P(t=>{let n={...t};return(H||[]).forEach(t=>{let r=L(t);t.enabled===e?delete n[r]:n[r]=e}),n})},[H]),X=(0,N.useCallback)(()=>P({}),[]),Z=(0,N.useCallback)(async()=>{let e=Object.entries(M);if(e.length){I(!0);try{let t=e.map(([e,t])=>{let n=B.current.get(e);return{name:n?.name||e.split(`::`).pop()||e,enabled:t,is_external:!!n?.is_external,external_mcp:n?.external_mcp||``}});await v.put(`/config`,{tools:t}),await v.post(`/config/apply`,{}),A(n(`mcp.toolsConfigSaved`,null,`工具配置已成功保存`)),P({}),V.reload({silent:!0})}catch(e){x(e,n(`mcp.saveToolsConfigFailed`,null,`保存工具配置失败`))}finally{I(!1)}}},[M,V.reload,n]),Q=[{title:n(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`name`,render:e=>(0,z.jsx)(`span`,{className:`mcp-management-mono mcp-management-tool-name`,children:e})},{title:`来源`,dataIndex:`is_external`,width:180,render:(e,t)=>(0,z.jsx)(o,{size:`small`,color:e?`blue`:`grey`,children:R(t)})},{title:n(`mcp.filterEnabled`,null,`已启用`),dataIndex:`enabled`,width:110,render:(t,n)=>(0,z.jsx)(d,{size:`small`,checked:q(n),disabled:!e,onChange:e=>J(n,e)})},{title:n(`mcp.description`,null,`描述`),dataIndex:`description`,render:e=>(0,z.jsx)(W,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:560},children:e||n(`mcp.noDescription`,null,`暂无描述`)})}],$={currentPage:r,pageSize:l,total:U,showSizeChanger:!0,pageSizeOpts:[20,50,100],showTotal:!0,onPageChange:e=>i(e),onPageSizeChange:e=>{f(e),i(1)}},ee=[{value:`all`,label:n(`mcp.filterAll`,null,`全部`)},{value:`on`,label:n(`mcp.filterEnabled`,null,`已启用`)},{value:`off`,label:n(`mcp.filterDisabled`,null,`已停用`)}];return(0,z.jsxs)(w,{title:n(`mcp.toolConfig`,null,`MCP 工具配置`),description:`${n(`mcp.currentPageEnabled`,null,`当前页已启用`)} ${(G||[]).filter(e=>q(e)).length} / ${G.length} · ${n(`mcp.totalEnabled`,null,`已启用工具总数`)} ${V.data?.total_enabled??`—`}`,extra:(0,z.jsxs)(a,{spacing:8,children:[K.length>0&&(0,z.jsx)(o,{size:`small`,color:`amber`,children:`未保存 ${K.length} 项`}),K.length>0&&(0,z.jsx)(c,{size:`small`,theme:`borderless`,onClick:X,disabled:F,children:`放弃修改`}),(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(m,{}),theme:`borderless`,onClick:()=>V.reload(),loading:V.loading,children:n(`common.refresh`,null,`刷新`)}),(0,z.jsx)(c,{size:`small`,theme:`solid`,disabled:!e||!K.length,loading:F,onClick:Z,children:n(`mcp.saveToolConfig`,null,`保存工具配置`)})]}),children:[(0,z.jsx)(C,{error:V.error,onRetry:()=>V.reload()}),(0,z.jsx)(k,{columns:Q,dataSource:H,rowKey:e=>L(e),loading:V.loading,pagination:$,size:`small`,emptyText:n(`mcp.noTools`,null,`暂无工具`),toolbar:(0,z.jsxs)(a,{spacing:8,wrap:!0,children:[(0,z.jsx)(u,{prefix:(0,z.jsx)(p,{}),showClear:!0,style:{width:240},value:_,placeholder:n(`mcp.toolSearchPlaceholder`,null,`搜索工具…`),onChange:e=>{y(e),i(1)}}),(0,z.jsx)(h,{value:E,style:{width:140},optionList:ee,onChange:e=>{D(e),i(1)}}),(0,z.jsx)(s,{checked:O,onChange:e=>{j(e.target.checked),i(1)},children:`包含外部 MCP 工具`}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>Y(!0),children:n(`mcp.selectAll`,null,`全选`)}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>Y(!1),children:n(`mcp.deselectAll`,null,`全不选`)})]})}),(0,z.jsx)(`p`,{className:`mcp-management-hint`,children:`保存只提交本次改动的工具项;应用后由后端重新注册 MCP 工具。直接注册(未写入 config.yaml)的工具切换不会落盘。`})]})}function K(){let e=g(),{hasPermission:t}=_(),n=t(`mcp:write`),[r,i]=(0,N.useState)(0),o=b(()=>v.get(`/external-mcp/stats`),[r]),s=o.data||{},l=(0,N.useCallback)(()=>{i(e=>e+1),o.reload({silent:!0})},[o.reload]);return(0,z.jsxs)(`div`,{className:`mcp-management-page`,children:[(0,z.jsx)(D,{title:e(`mcp.managementTitle`,null,`MCP 管理`),description:`维护外部 MCP 连接与工具启用状态;改动写入 config.yaml 后立即生效。`,extra:(0,z.jsx)(a,{children:(0,z.jsx)(c,{icon:(0,z.jsx)(m,{}),onClick:l,loading:o.loading,children:e(`common.refresh`,null,`刷新`)})})}),(0,z.jsx)(y,{columns:4,metrics:[{id:`total`,label:e(`mcp.totalCount`,null,`总数`),value:o.error?`—`:s.total??0,detail:e(`mcp.externalConfig`,null,`外部 MCP 配置`),loading:o.loading&&!o.data},{id:`enabled`,label:e(`mcp.enabledCount`,null,`已启用`),value:o.error?`—`:s.enabled??0,tone:`success`,loading:o.loading&&!o.data},{id:`connected`,label:e(`mcp.connectedCount`,null,`已连接`),value:o.error?`—`:s.connected??0,tone:s.connected>0?`success`:void 0,loading:o.loading&&!o.data},{id:`disabled`,label:e(`mcp.disabledCount`,null,`已停用`),value:o.error?`—`:s.disabled??0,loading:o.loading&&!o.data}]}),(0,z.jsx)(C,{error:o.error,onRetry:l}),(0,z.jsx)(U,{canWrite:n,onChanged:l,refreshKey:r}),(0,z.jsx)(G,{canWrite:n,refreshKey:r})]})}export{K as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,G as i,I as a,N as o,P as s,R as c,S as l,U as u,d,ft as f,lt as p,ut as m,y as h}from"./semi-65W_4I1v.js";import{F as g,I as _,L as v,_ as y,a as b,b as x,c as S,l as C,m as w,n as T,o as E,p as D,r as O,s as k,x as A,y as j,z as M}from"./index-DNMXun-U.js";var N=e(t(),1),P={connected:{color:`green`,label:`已连接`},connecting:{color:`blue`,label:`连接中`},disconnected:{color:`amber`,label:`未连接`},disabled:{color:`grey`,label:`已停用`},error:{color:`red`,label:`连接失败`}};function F(e){return P[String(e||``).toLowerCase()]||{color:`grey`,label:e||`未知`}}function I(e){return e?String(e.type||e.transport||(e.command?`stdio`:`http`)).toLowerCase():`http`}function L(e){return e?e.is_external&&e.external_mcp?`${e.external_mcp}::${e.name}`:e.name||``:``}function R(e){return e?e.is_external?`外部 · ${e.external_mcp||`未知`}`:`内置`:`—`}var z=e(n(),1),{Text:B}=i,V={"my-stdio-server":{command:`python3`,args:["${HOME}/mcp-servers/main.py",`--port`,"${MCP_PORT:-3000}"],env:{API_KEY:"${API_KEY}",LOG_LEVEL:"${LOG_LEVEL:-INFO}"},timeout:300},"my-http-server":{type:`http`,url:`https://mcp.example.com/mcp`,headers:{Authorization:"Bearer ${MCP_TOKEN}"}},"my-sse-server":{type:`sse`,url:`http://127.0.0.1:8081/mcp/sse`}};function H(e,{editingName:t}){if(typeof e!=`object`||!e||Array.isArray(e))return{error:`配置必须是 JSON 对象`};let n=Object.keys(e);if(!n.length)return{error:`至少需要一个 MCP 配置`};if(t&&!e[t])return{error:`编辑模式下 JSON 必须包含配置名称 "${t}"`};for(let t of n){if(!t.trim())return{error:`配置名称不能为空`};let n=e[t];if(typeof n!=`object`||!n||Array.isArray(n))return{error:`"${t}" 的配置必须是对象`};delete n.external_mcp_enable;let r=n.type||n.transport||(n.command?`stdio`:n.url?`http`:``);if(!r)return{error:`"${t}" 需要指定 command(stdio)或 url + type(http/sse)`};if(r===`stdio`&&!n.command)return{error:`"${t}" 的 stdio 模式需要 command`};if((r===`http`||r===`sse`)&&!n.url)return{error:`"${t}" 的 ${r} 模式需要 url`}}return{error:``,names:n}}function U({canWrite:e,onChanged:t,refreshKey:n=0}){let i=g(),s=b(()=>v.get(`/external-mcp`),[n]),[u,d]=(0,N.useState)(``),[p,h]=(0,N.useState)(!1),[_,y]=(0,N.useState)(null),[T,D]=(0,N.useState)(``),[k,P]=(0,N.useState)(``),[L,R]=(0,N.useState)(!1),U=(0,N.useMemo)(()=>{let e=s.data?.servers||{};return Object.entries(e).sort(([e],[t])=>e.localeCompare(t))},[s.data]),W=(0,N.useCallback)(e=>s.reload(e),[s.reload]);O(()=>{typeof document<`u`&&document.hidden||W({silent:!0})},8e3);let G=(0,N.useCallback)(()=>{y(null),D(``),P(``),h(!0)},[]),K=(0,N.useCallback)(async e=>{y(e),D(``),P(``),h(!0);try{let t={...(await v.get(`/external-mcp/${encodeURIComponent(e)}`))?.config||{}};delete t.tool_count,delete t.external_mcp_enable,D(JSON.stringify({[e]:t},null,2))}catch(e){h(!1),x(e,i(`mcp.getConfigFailed`,null,`获取外部MCP配置失败`))}},[i]),q=(0,N.useCallback)(()=>{h(!1),y(null),P(``)},[]),J=(0,N.useCallback)(async(e,n)=>{let r=n===`connected`?`stop`:`start`;d(e);try{await v.post(`/external-mcp/${encodeURIComponent(e)}/${r}`,{}),A(r===`start`?`已提交启动请求,正在后台连接`:`外部 MCP 已停止`),W({silent:!0}),t?.()}catch(e){x(e,i(`mcp.operationFailed`,null,`操作失败`))}finally{d(``)}},[t,W,i]),Y=(0,N.useCallback)(e=>{j({title:i(`mcp.deleteExternalConfirm`,{name:e},`确定要删除外部MCP "${e}" 吗?`),content:`删除后该 MCP 的工具将从对话中移除。`,okText:i(`common.delete`,null,`删除`),onOk:async()=>{try{await v.del(`/external-mcp/${encodeURIComponent(e)}`),A(i(`mcp.deleteSuccess`,null,`删除成功`)),W(),t?.()}catch(e){x(e,i(`mcp.operationFailed`,null,`删除失败`))}}})},[t,W,i]),X=(0,N.useCallback)(async()=>{let e=T.trim();if(!e){P(i(`mcp.jsonEmpty`,null,`JSON不能为空`));return}let n;try{n=JSON.parse(e)}catch(e){P(`${i(`mcp.jsonError`,null,`JSON格式错误`)}: ${e.message}`);return}let{error:r,names:a}=H(n,{editingName:_});if(r)P(r);else{P(``),R(!0);try{let e=_?[_]:a;for(let t of e)await v.put(`/external-mcp/${encodeURIComponent(t)}`,{config:n[t]});A(i(`mcp.saveSuccess`,null,`保存成功`)),q(),W(),t?.()}catch(e){P(`${i(`mcp.operationFailed`,null,`保存失败`)}: ${M(e)}`)}finally{R(!1)}}},[q,_,T,t,W,i]),Z=(0,z.jsxs)(a,{spacing:8,children:[(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(m,{}),theme:`borderless`,onClick:()=>W(),loading:s.loading,children:i(`common.refresh`,null,`刷新`)}),(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(f,{}),disabled:!e,onClick:G,children:i(`mcp.addExternalMCP`,null,`添加外部MCP`)})]});return(0,z.jsxs)(w,{title:i(`mcp.externalConfig`,null,`外部 MCP 配置`),description:`stdio 传 command/args/env,http 与 sse 传 url/headers;状态每 8 秒自动刷新。`,extra:Z,children:[(0,z.jsx)(C,{error:s.error,onRetry:()=>W()}),!U.length&&!s.loading&&(0,z.jsxs)(`div`,{className:`mcp-management-empty`,children:[(0,z.jsx)(`p`,{children:i(`mcp.noExternalMCP`,null,`暂无外部 MCP`)}),(0,z.jsx)(c,{size:`small`,disabled:!e,onClick:G,children:i(`mcp.clickToAddExternal`,null,`点击添加外部 MCP`)})]}),(0,z.jsx)(`div`,{className:`mcp-management-mcp-grid`,children:U.map(([t,n])=>{let s=n?.config||{},l=String(n?.status||`disconnected`),d=F(l),f=I(s),p=l===`connected`;return(0,z.jsxs)(`div`,{className:`mcp-management-mcp-card`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-mcp-head`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-mcp-title`,children:[(0,z.jsx)(B,{strong:!0,children:t}),(0,z.jsx)(o,{size:`small`,color:d.color,children:d.label}),(0,z.jsx)(o,{size:`small`,color:`grey`,children:f.toUpperCase()}),Number(n?.tool_count)>0&&(0,z.jsx)(o,{size:`small`,color:`blue`,children:`${n.tool_count} 个工具`})]}),(0,z.jsxs)(a,{spacing:4,wrap:!0,children:[(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e||u===t||l===`connecting`,loading:u===t,onClick:()=>J(t,l),children:l===`connecting`?i(`mcp.connecting`,null,`连接中`):p?i(`mcp.stop`,null,`停止`):i(`mcp.start`,null,`启动`)}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>K(t),children:i(`common.edit`,null,`编辑`)}),(0,z.jsx)(c,{size:`small`,type:`danger`,theme:`borderless`,disabled:!e,onClick:()=>Y(t),children:i(`common.delete`,null,`删除`)})]})]}),(l===`error`||l===`disconnected`)&&n?.error&&(0,z.jsx)(r,{type:l===`error`?`danger`:`warning`,className:`mcp-management-mcp-error`,description:(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:n.error})}),(0,z.jsxs)(`div`,{className:`mcp-management-mcp-meta`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.transportMode`,null,`传输方式`)}),(0,z.jsx)(`span`,{children:f.toUpperCase()})]}),s.description&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.description`,null,`描述`)}),(0,z.jsx)(`span`,{children:s.description})]}),f===`stdio`&&s.command&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.command`,null,`命令`)}),(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:s.command})]}),f!==`stdio`&&s.url&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:`URL`}),(0,z.jsx)(`span`,{className:`mcp-management-mono`,children:s.url})]}),Number(s.timeout)>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`mcp-management-meta-label`,children:i(`mcp.timeout`,null,`超时`)}),(0,z.jsxs)(`span`,{children:[s.timeout,` `,i(`mcp.secondsUnit`,null,`秒`)]})]})]})]},t)})}),(0,z.jsx)(S,{title:_?`${i(`mcp.editExternalMCP`,null,`编辑外部MCP`)} · ${_}`:i(`mcp.addExternalMCP`,null,`添加外部 MCP`),visible:p,onCancel:q,onOk:X,confirmLoading:L,width:760,okText:i(`common.save`,null,`保存`),cancelText:i(`common.cancel`,null,`取消`),children:(0,z.jsxs)(`div`,{className:`mcp-management-form`,children:[(0,z.jsxs)(`div`,{className:`mcp-management-form-head`,children:[(0,z.jsx)(B,{type:`tertiary`,children:_?`编辑模式下只提交当前名称的配置;external_mcp_enable 由启停按钮维护。`:`支持一次粘贴多个 MCP:{"name": {...}};保存后逐个写入 config.yaml。`}),!_&&(0,z.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>D(JSON.stringify(V,null,2)),children:`载入示例`}),T&&(0,z.jsx)(E,{text:T,size:`small`})]}),(0,z.jsx)(l,{className:`mcp-management-json`,rows:16,value:T,spellCheck:!1,placeholder:`{"my-http-server": {"type": "http", "url": "https://mcp.example.com/mcp"}}`,onChange:e=>{D(e),k&&P(``)}}),k&&(0,z.jsx)(`div`,{className:`mcp-management-form-error`,children:k})]})})]})}var{Text:W}=i;function G({canWrite:e,refreshKey:t=0}){let n=g(),[r,i]=(0,N.useState)(1),[l,f]=(0,N.useState)(20),[_,y]=(0,N.useState)(``),S=T(_,350),[E,D]=(0,N.useState)(`all`),[O,j]=(0,N.useState)(!0),[M,P]=(0,N.useState)({}),[F,I]=(0,N.useState)(!1),B=(0,N.useRef)(new Map),V=b(()=>v.get(`/config/tools`,{page:r,page_size:l,search:S,tool_filter:E===`all`?``:E,include_external:O?``:`0`}),[r,l,S,E,O,t]),H=V.data?.tools||[],U=Number(V.data?.total)||0,G=(0,N.useDeferredValue)(H);(0,N.useEffect)(()=>{(H||[]).forEach(e=>B.current.set(L(e),e))},[H]);let K=(0,N.useMemo)(()=>Object.keys(M),[M]),q=(0,N.useCallback)(e=>Object.prototype.hasOwnProperty.call(M,L(e))?M[L(e)]:e.enabled,[M]),J=(0,N.useCallback)((e,t)=>{let n=L(e);P(r=>{let i={...r};return t===e.enabled?delete i[n]:i[n]=t,i})},[]),Y=(0,N.useCallback)(e=>{P(t=>{let n={...t};return(H||[]).forEach(t=>{let r=L(t);t.enabled===e?delete n[r]:n[r]=e}),n})},[H]),X=(0,N.useCallback)(()=>P({}),[]),Z=(0,N.useCallback)(async()=>{let e=Object.entries(M);if(e.length){I(!0);try{let t=e.map(([e,t])=>{let n=B.current.get(e);return{name:n?.name||e.split(`::`).pop()||e,enabled:t,is_external:!!n?.is_external,external_mcp:n?.external_mcp||``}});await v.put(`/config`,{tools:t}),await v.post(`/config/apply`,{}),A(n(`mcp.toolsConfigSaved`,null,`工具配置已成功保存`)),P({}),V.reload({silent:!0})}catch(e){x(e,n(`mcp.saveToolsConfigFailed`,null,`保存工具配置失败`))}finally{I(!1)}}},[M,V.reload,n]),Q=[{title:n(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`name`,render:e=>(0,z.jsx)(`span`,{className:`mcp-management-mono mcp-management-tool-name`,children:e})},{title:`来源`,dataIndex:`is_external`,width:180,render:(e,t)=>(0,z.jsx)(o,{size:`small`,color:e?`blue`:`grey`,children:R(t)})},{title:n(`mcp.filterEnabled`,null,`已启用`),dataIndex:`enabled`,width:110,render:(t,n)=>(0,z.jsx)(d,{size:`small`,checked:q(n),disabled:!e,onChange:e=>J(n,e)})},{title:n(`mcp.description`,null,`描述`),dataIndex:`description`,render:e=>(0,z.jsx)(W,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:560},children:e||n(`mcp.noDescription`,null,`暂无描述`)})}],$={currentPage:r,pageSize:l,total:U,showSizeChanger:!0,pageSizeOpts:[20,50,100],showTotal:!0,onPageChange:e=>i(e),onPageSizeChange:e=>{f(e),i(1)}},ee=[{value:`all`,label:n(`mcp.filterAll`,null,`全部`)},{value:`on`,label:n(`mcp.filterEnabled`,null,`已启用`)},{value:`off`,label:n(`mcp.filterDisabled`,null,`已停用`)}];return(0,z.jsxs)(w,{title:n(`mcp.toolConfig`,null,`MCP 工具配置`),description:`${n(`mcp.currentPageEnabled`,null,`当前页已启用`)} ${(G||[]).filter(e=>q(e)).length} / ${G.length} · ${n(`mcp.totalEnabled`,null,`已启用工具总数`)} ${V.data?.total_enabled??`—`}`,extra:(0,z.jsxs)(a,{spacing:8,children:[K.length>0&&(0,z.jsx)(o,{size:`small`,color:`amber`,children:`未保存 ${K.length} 项`}),K.length>0&&(0,z.jsx)(c,{size:`small`,theme:`borderless`,onClick:X,disabled:F,children:`放弃修改`}),(0,z.jsx)(c,{size:`small`,icon:(0,z.jsx)(m,{}),theme:`borderless`,onClick:()=>V.reload(),loading:V.loading,children:n(`common.refresh`,null,`刷新`)}),(0,z.jsx)(c,{size:`small`,theme:`solid`,disabled:!e||!K.length,loading:F,onClick:Z,children:n(`mcp.saveToolConfig`,null,`保存工具配置`)})]}),children:[(0,z.jsx)(C,{error:V.error,onRetry:()=>V.reload()}),(0,z.jsx)(k,{columns:Q,dataSource:H,rowKey:e=>L(e),loading:V.loading,pagination:$,size:`small`,emptyText:n(`mcp.noTools`,null,`暂无工具`),toolbar:(0,z.jsxs)(a,{spacing:8,wrap:!0,children:[(0,z.jsx)(u,{prefix:(0,z.jsx)(p,{}),showClear:!0,style:{width:240},value:_,placeholder:n(`mcp.toolSearchPlaceholder`,null,`搜索工具…`),onChange:e=>{y(e),i(1)}}),(0,z.jsx)(h,{value:E,style:{width:140},optionList:ee,onChange:e=>{D(e),i(1)}}),(0,z.jsx)(s,{checked:O,onChange:e=>{j(e.target.checked),i(1)},children:`包含外部 MCP 工具`}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>Y(!0),children:n(`mcp.selectAll`,null,`全选`)}),(0,z.jsx)(c,{size:`small`,theme:`borderless`,disabled:!e,onClick:()=>Y(!1),children:n(`mcp.deselectAll`,null,`全不选`)})]})}),(0,z.jsx)(`p`,{className:`mcp-management-hint`,children:`保存只提交本次改动的工具项;应用后由后端重新注册 MCP 工具。直接注册(未写入 config.yaml)的工具切换不会落盘。`})]})}function K(){let e=g(),{hasPermission:t}=_(),n=t(`mcp:write`),[r,i]=(0,N.useState)(0),o=b(()=>v.get(`/external-mcp/stats`),[r]),s=o.data||{},l=(0,N.useCallback)(()=>{i(e=>e+1),o.reload({silent:!0})},[o.reload]);return(0,z.jsxs)(`div`,{className:`mcp-management-page`,children:[(0,z.jsx)(D,{title:e(`mcp.managementTitle`,null,`MCP 管理`),description:`维护外部 MCP 连接与工具启用状态;改动写入 config.yaml 后立即生效。`,extra:(0,z.jsx)(a,{children:(0,z.jsx)(c,{icon:(0,z.jsx)(m,{}),onClick:l,loading:o.loading,children:e(`common.refresh`,null,`刷新`)})})}),(0,z.jsx)(y,{columns:4,metrics:[{id:`total`,label:e(`mcp.totalCount`,null,`总数`),value:o.error?`—`:s.total??0,detail:e(`mcp.externalConfig`,null,`外部 MCP 配置`),loading:o.loading&&!o.data},{id:`enabled`,label:e(`mcp.enabledCount`,null,`已启用`),value:o.error?`—`:s.enabled??0,tone:`success`,loading:o.loading&&!o.data},{id:`connected`,label:e(`mcp.connectedCount`,null,`已连接`),value:o.error?`—`:s.connected??0,tone:s.connected>0?`success`:void 0,loading:o.loading&&!o.data},{id:`disabled`,label:e(`mcp.disabledCount`,null,`已停用`),value:o.error?`—`:s.disabled??0,loading:o.loading&&!o.data}]}),(0,z.jsx)(C,{error:o.error,onRetry:l}),(0,z.jsx)(U,{canWrite:n,onChanged:l,refreshKey:r}),(0,z.jsx)(G,{canWrite:n,refreshKey:r})]})}export{K as default}; \ No newline at end of file diff --git a/web/static/app/assets/mcp-monitor-CfVvha6O.js b/web/static/app/assets/mcp-monitor-DHXOIA-R.js similarity index 99% rename from web/static/app/assets/mcp-monitor-CfVvha6O.js rename to web/static/app/assets/mcp-monitor-DHXOIA-R.js index df84fe90..a36100e2 100644 --- a/web/static/app/assets/mcp-monitor-CfVvha6O.js +++ b/web/static/app/assets/mcp-monitor-DHXOIA-R.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{B as i,G as a,I as o,N as s,R as c,S as l,T as u,U as d,W as f,lt as p,p as m,ut as h,y as g}from"./semi-65W_4I1v.js";import{D as _,E as v,F as y,I as b,L as x,O as S,S as ee,_ as C,a as w,b as T,d as E,g as D,i as te,l as O,m as k,n as ne,o as A,p as re,r as ie,s as j,u as M,x as N,y as ae}from"./index-CAEPLS-g.js";var P=e(t(),1),F=[`completed`,`running`,`queued`,`failed`,`blocked`,`hard_timeout`,`cancelled`,`orphaned`],I={pending:`statusPending`,queued:`statusQueued`,running:`statusRunning`,completed:`statusCompleted`,failed:`statusFailed`,blocked:`statusBlocked`,cancelled:`statusCancelled`,hard_timeout:`statusHardTimeout`,orphaned:`statusOrphaned`},L={pending:`等待中`,queued:`排队中`,running:`执行中`,completed:`已完成`,failed:`失败`,blocked:`已拦截`,cancelled:`已终止`,hard_timeout:`执行超时`,orphaned:`孤儿任务`},R={completed:`green`,running:`blue`,queued:`amber`,failed:`red`,blocked:`orange`,hard_timeout:`red`,cancelled:`grey`,orphaned:`grey`};function z(e){return String(e||``).trim().toLowerCase()}function B(e,t){let n=z(t),r=I[n];return r?e(`mcpMonitor.${r}`,null,L[n]||n):t||`—`}function V(e){return R[z(e)]||`grey`}function H(e){return z(e)===`running`}function U(e){let t=String(e||``).trim();return t?t.includes(`::`)?t.replace(/::/g,`__`):t:``}function W(e){if(!e)return null;let t=Number(e.duration);if(Number.isFinite(t)&&t>0)return t/1e6;let n=e.startTime?new Date(e.startTime).getTime():NaN,r=e.endTime?new Date(e.endTime).getTime():NaN;return Number.isFinite(n)&&Number.isFinite(r)&&r>=n?r-n:null}function G(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return`—`;if(t<1e3)return`${Math.round(t)} ms`;if(t<6e4)return`${(t/1e3).toFixed(2)} s`;let n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return n<60?`${n} 分 ${r} 秒`:`${Math.floor(n/60)} 小时 ${n%60} 分`}function K(e){if(!e)return null;let t=(Number(e.totalCalls)||0)-(Number(e.blockedCalls)||0);return t<=0?null:(Number(e.successCalls)||0)/t}function q(e,t=1){return e==null||!Number.isFinite(Number(e))?`—`:`${(Number(e)*100).toFixed(t)}%`}function oe(e){let t=(e||[]).map(W).filter(e=>Number.isFinite(e)&&e>=0);return t.length?t.reduce((e,t)=>e+t,0)/t.length:null}function J(e,t){let n=new Date(e);if(!Number.isFinite(n.getTime()))return``;let r=e=>String(e).padStart(2,`0`),i=`${r(n.getMonth()+1)}-${r(n.getDate())}`;return t===`30d`?i:t===`7d`?`${i} ${r(n.getHours())}h`:`${r(n.getHours())}:00`}function Y(e,t){let n=e?.t?new Date(e.t).toLocaleString(`zh-CN`,{hour12:!1}):`—`;return t(`mcpMonitor.timelineTooltip`,{time:n,total:e?.total||0,failed:e?.failed||0,blocked:e?.blocked||0},`${n} 总调用 ${e?.total||0},失败 ${e?.failed||0},拦截 ${e?.blocked||0}`)}var X=e(n(),1);function se({summary:e,loading:t,avgMs:n=null,avgSamples:r=0}){let i=y(),a=K(e);return(0,X.jsx)(C,{columns:4,metrics:[{id:`calls`,label:i(`mcpMonitor.totalCalls`,null,`调用次数`),value:e?e.totalCalls??0:`—`,detail:e?i(`mcpMonitor.statsFromAllTools`,null,`全部工具累计,含已拦截调用`):void 0,loading:t},{id:`rate`,label:i(`mcpMonitor.successRate`,null,`成功率`),value:q(a),detail:e?`${i(`common.ok`,null,`成功`)} ${e.successCalls??0} / ${i(`mcpMonitor.failedColumn`,null,`失败`)} ${e.failedCalls??0}`:void 0,tone:a===null?void 0:a>=.95?`success`:a>=.8?`warning`:`danger`,loading:t},{id:`avg`,label:`平均耗时`,value:n===null?`—`:G(n),detail:r>0?`按当前页 ${r} 条计时记录估算`:`当前页暂无可计时的执行记录`,loading:t},{id:`failed`,label:i(`mcpMonitor.failedMetric`,null,`失败数`),value:e?e.failedCalls??0:`—`,detail:e?`${i(`mcpMonitor.blockedCount`,{n:e.blockedCalls??0},`安全拦截 ${e.blockedCalls??0}`)} · ${i(`mcpMonitor.lastCall`,null,`最近调用`)} ${e.lastCallTime?v(e.lastCallTime):`—`}`:void 0,tone:e&&e.failedCalls>0?`danger`:void 0,loading:t}]})}function ce({topTools:e,loading:t,onFilterTool:n,activeTool:r}){let i=y(),a=(0,P.useMemo)(()=>(e||[]).map(e=>{let t=Number(e.totalCalls)||0,n=Number(e.blockedCalls)||0,r=Number(e.successCalls)||0,i=t-n;return{...e,key:e.toolName,displayName:U(e.toolName),rate:i>0?r/i:null}}),[e]),o=[{title:i(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`displayName`,render:(e,t)=>(0,X.jsx)(`button`,{type:`button`,className:`mcp-monitor-tool-link ${r&&r===t.toolName?`mcp-monitor-link-active`:``}`,onClick:()=>n?.(t.toolName),children:e||i(`mcpMonitor.unknownTool`,null,`未知工具`)})},{title:i(`mcpMonitor.columnCalls`,null,`调用`),dataIndex:`totalCalls`,width:90,render:e=>e??0},{title:i(`mcpMonitor.successColumn`,null,`成功`),dataIndex:`successCalls`,width:90,render:e=>e??0},{title:i(`mcpMonitor.failedColumn`,null,`失败`),dataIndex:`failedCalls`,width:90,render:e=>(0,X.jsx)(`span`,{className:e>0?`mcp-monitor-danger`:void 0,children:e??0})},{title:i(`mcpMonitor.blockedColumn`,null,`拦截`),dataIndex:`blockedCalls`,width:90,render:e=>e?(0,X.jsx)(s,{size:`small`,color:`orange`,children:e}):0},{title:i(`mcpMonitor.columnSuccessRate`,null,`成功率`),dataIndex:`rate`,width:110,render:e=>e===null?`—`:S(e,1)}];return(0,X.jsx)(k,{title:i(`mcpMonitor.toolStatsTitle`,null,`工具统计`),description:i(`mcpMonitor.toolStatsHint`,null,`点击工具名筛选下方执行记录`),children:(0,X.jsx)(j,{columns:o,dataSource:a,rowKey:`key`,loading:t,pagination:!1,size:`small`,emptyText:i(`mcpMonitor.noStatsData`,null,`暂无统计数据`)})})}var le=[{value:`24h`,labelKey:`timelineRange24h`,fallback:`24 小时`},{value:`7d`,labelKey:`timelineRange7d`,fallback:`7 天`},{value:`30d`,labelKey:`timelineRange30d`,fallback:`30 天`}];function ue({data:e,loading:t,error:n,range:r,onRangeChange:i,onRetry:a}){let o=y(),s=Array.isArray(e?.points)?e.points:[],c=e?.summary||{},l=Number(c.peak)||0,u=(0,P.useMemo)(()=>s.reduce((e,t)=>Math.max(e,Number(t.total)||0),0),[s]),d=Number(c.totalCalls)||0,f=Math.max(1,Math.ceil(s.length/8)),p=le.map(e=>({value:e.value,label:o(`mcpMonitor.${e.labelKey}`,null,e.fallback)}));return(0,X.jsxs)(k,{title:o(`mcpMonitor.timelineTitle`,null,`调用趋势`),description:o(`mcpMonitor.timelineHint`,null,`全部工具合计,失败与拦截单独着色`),extra:(0,X.jsx)(g,{size:`small`,value:r,optionList:p,style:{width:120},onChange:i}),children:[(0,X.jsx)(O,{error:n,onRetry:a}),(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-summary`,children:[(0,X.jsx)(D,{label:o(`mcpMonitor.timelineTotalLegend`,null,`总调用`),value:_(d),loading:t}),(0,X.jsx)(D,{label:`峰值 / 桶`,value:_(l),detail:o(`mcpMonitor.scopeTimeline`,null,`当前时间范围`),loading:t}),(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-legend`,children:[(0,X.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,X.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-total`}),o(`mcpMonitor.timelineTotalLegend`,null,`总调用`)]}),(0,X.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,X.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-failed`}),o(`mcpMonitor.timelineFailedLegend`,null,`失败`)]}),(0,X.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,X.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-blocked`}),o(`mcpMonitor.timelineBlockedLegend`,null,`安全拦截`)]})]})]}),t&&!s.length?(0,X.jsx)(`div`,{className:`mcp-monitor-timeline-empty`,children:o(`mcpMonitor.timelineLoading`,null,`趋势加载中…`)}):d===0||u===0?(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-empty`,children:[(0,X.jsx)(`p`,{children:o(`mcpMonitor.timelineNoData`,null,`该时段暂无调用`)}),(0,X.jsx)(`p`,{className:`mcp-monitor-timeline-hint`,children:o(`mcpMonitor.timelineEmptyHint`,null,`调用 MCP 工具后此处会出现趋势`)})]}):(0,X.jsx)(`div`,{className:`mcp-monitor-timeline-chart`,role:`img`,"aria-label":o(`mcpMonitor.timelineTitle`,null,`调用趋势`),children:s.map((e,t)=>{let n=Number(e.total)||0,i=Number(e.failed)||0,a=Number(e.blocked)||0,s=n>0?Math.max(3,n/u*100):0,c=n>0?i/n*100:0,l=n>0?a/n*100:0,d=J(e.t,r);return(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-slot`,title:Y(e,o),children:[(0,X.jsx)(`div`,{className:`mcp-monitor-timeline-bar-wrap`,children:(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-bar`,style:{height:`${s}%`},children:[l>0&&(0,X.jsx)(`span`,{className:`mcp-monitor-timeline-seg mcp-monitor-seg-blocked`,style:{height:`${l}%`}}),c>0&&(0,X.jsx)(`span`,{className:`mcp-monitor-timeline-seg mcp-monitor-seg-failed`,style:{height:`${c}%`}})]})}),(0,X.jsx)(`span`,{className:`mcp-monitor-timeline-tick`,children:t%f===0?d:``})]},e.t||t)})})]})}function Z({status:e}){let t=y();return(0,X.jsx)(s,{size:`small`,color:V(e),shape:`square`,children:B(t,e)})}function de({data:e,loading:t,error:n,page:r,pageSize:i,status:a,toolInput:s,selected:l,onQuery:u,onPageChange:f,onRefresh:m,onOpenDetail:h,onCancel:_,onDelete:b,onSelectionChange:x,canWrite:S,canDelete:ee}){let C=y(),w=e?.executions||[],T=Number(e?.total)||0,E=[{value:`all`,label:C(`mcp.filterAll`,null,`全部`)},...F.map(e=>({value:e,label:B(C,e)}))],D=[{title:C(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`toolName`,render:e=>(0,X.jsx)(`span`,{className:`mcp-monitor-cell-tool`,children:U(e)||C(`mcpMonitor.unknownTool`,null,`未知工具`)})},{title:C(`mcpMonitor.columnStatus`,null,`状态`),dataIndex:`status`,width:110,render:e=>(0,X.jsx)(Z,{status:e})},{title:C(`mcpMonitor.columnStartTime`,null,`开始时间`),dataIndex:`startTime`,width:180,render:e=>v(e)},{title:C(`mcpMonitor.columnDuration`,null,`耗时`),dataIndex:`duration`,width:110,render:(e,t)=>G(W(t))},{title:C(`common.actions`,null,`操作`),dataIndex:`id`,width:230,render:(e,t)=>(0,X.jsxs)(o,{spacing:4,wrap:!0,children:[(0,X.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>h(e),children:C(`mcpMonitor.viewDetail`,null,`详情`)}),H(t.status)&&(0,X.jsx)(c,{size:`small`,theme:`borderless`,disabled:!S,onClick:()=>_(t),children:C(`mcpMonitor.terminateExecution`,null,`终止`)}),(0,X.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,disabled:!ee,onClick:()=>b(t),children:C(`common.delete`,null,`删除`)})]})}];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(O,{error:n,onRetry:m}),(0,X.jsx)(j,{columns:D,dataSource:w,rowKey:`id`,loading:t,pagination:{currentPage:r,pageSize:i,total:T,showSizeChanger:!0,pageSizeOpts:[20,50,100],showTotal:!0,onPageChange:e=>f(e,i),onPageSizeChange:e=>f(1,e)},onRefresh:m,emptyText:C(`mcpMonitor.noExecutions`,null,`暂无执行记录`),rowSelection:{selectedRowKeys:l,onChange:e=>x(e||[])},toolbar:(0,X.jsxs)(o,{spacing:8,wrap:!0,children:[(0,X.jsx)(d,{prefix:(0,X.jsx)(p,{}),value:s,showClear:!0,style:{width:220},placeholder:C(`mcp.toolSearchPlaceholder`,null,`输入工具名称…`),onChange:e=>u({toolInput:e})}),(0,X.jsx)(g,{value:a,style:{width:150},optionList:E,onChange:e=>u({status:e})})]})})]})}var{Text:Q}=a;function fe({executionId:e,onClose:t,canWrite:n,onCancelRequest:r}){let a=y(),{data:s,loading:l,error:u,reload:d}=w(()=>x.get(`/monitor/execution/${encodeURIComponent(e)}`),[e],{skip:!e}),p=e?s:null,h=p?H(p.status):!1;return(0,X.jsxs)(m,{visible:!!e,onCancel:t,title:a(`mcpMonitor.viewDetail`,null,`执行详情`),width:720,footer:p?(0,X.jsxs)(o,{children:[h&&(0,X.jsx)(c,{theme:`solid`,disabled:!n,onClick:()=>r(p),children:a(`mcpMonitor.terminateExecution`,null,`终止`)}),(0,X.jsx)(c,{onClick:t,children:a(`common.close`,null,`关闭`)})]}):null,children:[!p&&l&&(0,X.jsx)(`div`,{className:`mcp-monitor-detail-loading`,children:(0,X.jsx)(f,{})}),(0,X.jsx)(O,{error:u,onRetry:d}),p&&(0,X.jsxs)(`div`,{className:`mcp-monitor-detail`,children:[(0,X.jsx)(E,{columns:2,items:[{label:`工具`,value:(0,X.jsx)(Q,{strong:!0,children:U(p.toolName)||`—`})},{label:a(`mcpMonitor.columnStatus`,null,`状态`),value:(0,X.jsx)(Z,{status:p.status})},{label:`执行 ID`,value:(0,X.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.id})},{label:a(`mcpMonitor.columnStartTime`,null,`开始时间`),value:v(p.startTime)},{label:`结束时间`,value:p.endTime?v(p.endTime):`—`},{label:a(`mcpMonitor.columnDuration`,null,`耗时`),value:G(W(p))},{label:`关联会话`,value:p.conversationId?(0,X.jsxs)(o,{spacing:4,children:[(0,X.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.conversationId}),(0,X.jsx)(A,{text:p.conversationId,size:`small`})]}):`—`},{label:`结果状态`,value:p.result?p.result.isError?`错误结果`:p.result.blocked?`已拦截`:`正常返回`:`无返回`}]}),p.error&&(0,X.jsx)(i,{type:`danger`,className:`mcp-monitor-detail-error`,description:(0,X.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.error})}),(0,X.jsx)(`div`,{className:`mcp-monitor-detail-section`,children:(0,X.jsx)(M,{title:a(`mcpDetailModal.requestParams`,null,`入参`),value:p.arguments??{}})}),(0,X.jsx)(`div`,{className:`mcp-monitor-detail-section`,children:p.result?(0,X.jsx)(M,{title:a(`mcpDetailModal.responseResult`,null,`出参`),value:p.result}):(0,X.jsx)(`div`,{className:`mcp-monitor-detail-empty`,children:h?a(`mcpDetailModal.runningNoResponseYet`,null,`尚无返回,工具可能仍在执行。`):a(`chat.noResponseData`,null,`暂无响应数据`)})}),p.partialOutput&&(0,X.jsxs)(`div`,{className:`mcp-monitor-detail-section`,children:[(0,X.jsxs)(`div`,{className:`mcp-monitor-detail-section-head`,children:[(0,X.jsx)(Q,{strong:!0,children:`实时输出尾部`}),(0,X.jsxs)(o,{spacing:4,children:[p.partialOutputBytes?(0,X.jsxs)(Q,{type:`tertiary`,children:[p.partialOutputBytes,` B`]}):null,(0,X.jsx)(A,{text:p.partialOutput,size:`small`})]})]}),(0,X.jsx)(`pre`,{className:`mcp-monitor-detail-pre`,children:p.partialOutput})]}),(0,X.jsxs)(`div`,{className:`mcp-monitor-detail-footnote`,children:[B(a,p.status),` · `,a(`mcpMonitor.statsFromAllTools`,null,`全部工具累计`)]})]})]})}function $(){let e=y(),{hasPermission:t}=b(),[n,i]=r(),a=t(`monitor:write`)||t(`mcp:write`),s=t(`monitor:delete`),[d,f]=(0,P.useState)(1),[p,m]=(0,P.useState)(20),[g,_]=(0,P.useState)(`all`),[v,S]=(0,P.useState)(``),C=ne(v,350),[E,D]=(0,P.useState)([]),[O,A]=te(`mcp-monitor-timeline-range`,`7d`),[j,M]=(0,P.useState)(null),[F,I]=(0,P.useState)(``),[L,R]=(0,P.useState)(!1),z=n.get(`id`)||``,B=[`24h`,`7d`,`30d`].includes(O)?O:`7d`,V=w(()=>x.get(`/monitor`,{page:d,page_size:p,status:g===`all`?``:g,tool:C}),[d,p,g,C]),H=w(()=>x.get(`/monitor/stats`,{top:12}),[]),G=w(()=>x.get(`/monitor/calls-timeline`,{range:B}),[B]),K=V.data?.executions||[],q=H.data?.summary||V.data?.summary||null,J=H.data?.topTools||V.data?.topTools||[],Y=Number(V.data?.retentionDays)||0,le=(0,P.useMemo)(()=>K.filter(e=>W(e)!==null).length,[K]),Z=(0,P.useMemo)(()=>oe(K),[K]);ie(()=>{typeof document<`u`&&document.hidden||(V.reload({silent:!0}),G.reload({silent:!0}))},5e3),ie(()=>{typeof document<`u`&&document.hidden||H.reload({silent:!0})},2e4);let Q=(0,P.useCallback)(()=>{V.reload(),H.reload({silent:!0}),G.reload({silent:!0})},[V.reload,H.reload,G.reload]),$=(0,P.useCallback)(e=>{let t=new URLSearchParams(n);t.set(`id`,e),i(t,{replace:!0})},[n,i]),pe=(0,P.useCallback)(()=>{let e=new URLSearchParams(n);e.delete(`id`),i(e,{replace:!0})},[n,i]),me=(0,P.useCallback)(e=>{Object.prototype.hasOwnProperty.call(e,`toolInput`)&&S(e.toolInput),e.status!==void 0&&_(e.status),f(1),D([])},[]),he=(0,P.useCallback)((e,t)=>{f(e),t&&t!==p&&m(t)},[p]),ge=(0,P.useCallback)(e=>{S(U(e)),f(1),D([])},[]),_e=(0,P.useCallback)(t=>{ae({title:e(`mcpMonitor.deleteExecTitle`,null,`删除此执行记录`),content:`确定删除 ${U(t.toolName)||`该`} 的执行记录?此操作不可恢复。`,okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/monitor/execution/${encodeURIComponent(t.id)}`),D(e=>e.filter(e=>e!==t.id)),N(e(`mcpMonitor.execDeleted`,null,`执行记录已删除`)),Q()}catch(t){T(t,e(`mcpMonitor.deleteExecFailed`,null,`删除执行记录失败`))}}})},[Q,e]),ve=(0,P.useCallback)(async()=>{if(!E.length){ee(e(`mcpMonitor.selectExecFirst`,null,`请先选择要删除的执行记录`));return}let t=[];try{let e=await x.post(`/monitor/executions/names`,{ids:E});t=[...new Set(Object.values(e||{}).map(e=>U(e?.toolName)).filter(Boolean))]}catch{t=[]}let n=t.length?`涉及工具:${t.slice(0,3).join(`、`)}${t.length>3?` 等`:``}。`:``;ae({title:e(`mcpMonitor.batchDeleteConfirm`,{count:E.length},`确定删除选中的 ${E.length} 条执行记录?`),content:`${n}此操作不可恢复。`,okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/monitor/executions`,{body:{ids:E}}),N(`已删除 ${E.length} 条执行记录`),D([]),Q()}catch(t){T(t,e(`mcp.batchDeleteFailed`,null,`批量删除执行记录失败`))}}})},[Q,E,e]),ye=(0,P.useCallback)(e=>{M(e),I(``)},[]),be=(0,P.useCallback)(async()=>{if(j?.id){R(!0);try{await x.post(`/monitor/execution/${encodeURIComponent(j.id)}/cancel`,{note:F.trim()}),N(e(`mcpDetailModal.abortSuccess`,null,`已发送终止请求`)),M(null),Q()}catch(t){T(t,e(`mcpDetailModal.abortFailed`,null,`终止失败`))}finally{R(!1)}}},[F,j,Q,e]),xe=Y>0?e(`mcpMonitor.retentionHint`,{days:Y},`执行记录保留 ${Y} 天,失败与拦截调用单独标记。`):`统计全部 MCP 工具调用,失败与拦截调用单独标记。`;return(0,X.jsxs)(`div`,{className:`mcp-monitor-page`,children:[(0,X.jsx)(re,{title:e(`mcp.monitorTitle`,null,`MCP 状态监控`),description:xe,extra:(0,X.jsx)(o,{children:(0,X.jsx)(c,{icon:(0,X.jsx)(h,{}),onClick:Q,loading:V.loading||H.loading,children:e(`common.refresh`,null,`刷新`)})})}),(0,X.jsx)(se,{summary:q,loading:H.loading&&!q,avgMs:Z,avgSamples:le}),(0,X.jsx)(ue,{data:G.data,loading:G.loading,error:G.error,range:B,onRangeChange:e=>{e&&A(e)},onRetry:()=>G.reload()}),(0,X.jsx)(ce,{topTools:J,loading:H.loading&&!J.length,onFilterTool:ge,activeTool:C}),(0,X.jsx)(k,{title:e(`mcp.latestExecutions`,null,`最新执行记录`),description:e(`mcpMonitor.emptyHint`,null,`在对话或任务中调用 MCP 工具后,执行记录将显示在此处`),extra:E.length>0?(0,X.jsxs)(o,{spacing:8,children:[(0,X.jsx)(`span`,{className:`mcp-monitor-selected`,children:e(`mcp.selectedCount`,{count:E.length},`已选择 ${E.length} 项`)}),(0,X.jsx)(c,{size:`small`,disabled:!s,type:`danger`,onClick:ve,children:e(`mcp.deleteSelected`,null,`批量删除`)}),(0,X.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>D([]),children:e(`mcpMonitor.deselectAll`,null,`取消全选`)})]}):null,children:(0,X.jsx)(de,{data:V.data,loading:V.loading,error:V.error,page:d,pageSize:p,status:g,toolInput:v,selected:E,onQuery:me,onPageChange:he,onRefresh:()=>V.reload(),onOpenDetail:$,onCancel:ye,onDelete:_e,onSelectionChange:D,canWrite:a,canDelete:s})}),(0,X.jsx)(fe,{executionId:z,onClose:pe,canWrite:a,onCancelRequest:e=>{pe(),ye(e)}}),(0,X.jsxs)(u,{title:e(`mcpMonitor.terminateExecution`,null,`终止执行`),visible:!!j,confirmLoading:L,maskClosable:!L,okText:e(`mcpMonitor.terminateExecution`,null,`终止`),cancelText:e(`common.cancel`,null,`取消`),onCancel:()=>M(null),onOk:be,children:[(0,X.jsx)(`p`,{className:`mcp-monitor-cancel-hint`,children:e(`mcpDetailModal.abortHint`,null,`终止仅取消本次工具调用,不会停止整条对话;说明会与工具输出一起交给模型。`)}),(0,X.jsx)(l,{rows:4,value:F,placeholder:e(`mcpDetailModal.abortNotePlaceholder`,null,`终止说明(可选),例如:命令执行时间过长,先终止。`),onChange:e=>I(e)})]})]})}export{$ as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{B as i,G as a,I as o,N as s,R as c,S as l,T as u,U as d,W as f,lt as p,p as m,ut as h,y as g}from"./semi-65W_4I1v.js";import{D as _,E as v,F as y,I as b,L as x,O as S,S as ee,_ as C,a as w,b as T,d as E,g as D,i as te,l as O,m as k,n as ne,o as A,p as re,r as ie,s as j,u as M,x as N,y as ae}from"./index-DNMXun-U.js";var P=e(t(),1),F=[`completed`,`running`,`queued`,`failed`,`blocked`,`hard_timeout`,`cancelled`,`orphaned`],I={pending:`statusPending`,queued:`statusQueued`,running:`statusRunning`,completed:`statusCompleted`,failed:`statusFailed`,blocked:`statusBlocked`,cancelled:`statusCancelled`,hard_timeout:`statusHardTimeout`,orphaned:`statusOrphaned`},L={pending:`等待中`,queued:`排队中`,running:`执行中`,completed:`已完成`,failed:`失败`,blocked:`已拦截`,cancelled:`已终止`,hard_timeout:`执行超时`,orphaned:`孤儿任务`},R={completed:`green`,running:`blue`,queued:`amber`,failed:`red`,blocked:`orange`,hard_timeout:`red`,cancelled:`grey`,orphaned:`grey`};function z(e){return String(e||``).trim().toLowerCase()}function B(e,t){let n=z(t),r=I[n];return r?e(`mcpMonitor.${r}`,null,L[n]||n):t||`—`}function V(e){return R[z(e)]||`grey`}function H(e){return z(e)===`running`}function U(e){let t=String(e||``).trim();return t?t.includes(`::`)?t.replace(/::/g,`__`):t:``}function W(e){if(!e)return null;let t=Number(e.duration);if(Number.isFinite(t)&&t>0)return t/1e6;let n=e.startTime?new Date(e.startTime).getTime():NaN,r=e.endTime?new Date(e.endTime).getTime():NaN;return Number.isFinite(n)&&Number.isFinite(r)&&r>=n?r-n:null}function G(e){let t=Number(e);if(!Number.isFinite(t)||t<0)return`—`;if(t<1e3)return`${Math.round(t)} ms`;if(t<6e4)return`${(t/1e3).toFixed(2)} s`;let n=Math.floor(t/6e4),r=Math.round(t%6e4/1e3);return n<60?`${n} 分 ${r} 秒`:`${Math.floor(n/60)} 小时 ${n%60} 分`}function K(e){if(!e)return null;let t=(Number(e.totalCalls)||0)-(Number(e.blockedCalls)||0);return t<=0?null:(Number(e.successCalls)||0)/t}function q(e,t=1){return e==null||!Number.isFinite(Number(e))?`—`:`${(Number(e)*100).toFixed(t)}%`}function oe(e){let t=(e||[]).map(W).filter(e=>Number.isFinite(e)&&e>=0);return t.length?t.reduce((e,t)=>e+t,0)/t.length:null}function J(e,t){let n=new Date(e);if(!Number.isFinite(n.getTime()))return``;let r=e=>String(e).padStart(2,`0`),i=`${r(n.getMonth()+1)}-${r(n.getDate())}`;return t===`30d`?i:t===`7d`?`${i} ${r(n.getHours())}h`:`${r(n.getHours())}:00`}function Y(e,t){let n=e?.t?new Date(e.t).toLocaleString(`zh-CN`,{hour12:!1}):`—`;return t(`mcpMonitor.timelineTooltip`,{time:n,total:e?.total||0,failed:e?.failed||0,blocked:e?.blocked||0},`${n} 总调用 ${e?.total||0},失败 ${e?.failed||0},拦截 ${e?.blocked||0}`)}var X=e(n(),1);function se({summary:e,loading:t,avgMs:n=null,avgSamples:r=0}){let i=y(),a=K(e);return(0,X.jsx)(C,{columns:4,metrics:[{id:`calls`,label:i(`mcpMonitor.totalCalls`,null,`调用次数`),value:e?e.totalCalls??0:`—`,detail:e?i(`mcpMonitor.statsFromAllTools`,null,`全部工具累计,含已拦截调用`):void 0,loading:t},{id:`rate`,label:i(`mcpMonitor.successRate`,null,`成功率`),value:q(a),detail:e?`${i(`common.ok`,null,`成功`)} ${e.successCalls??0} / ${i(`mcpMonitor.failedColumn`,null,`失败`)} ${e.failedCalls??0}`:void 0,tone:a===null?void 0:a>=.95?`success`:a>=.8?`warning`:`danger`,loading:t},{id:`avg`,label:`平均耗时`,value:n===null?`—`:G(n),detail:r>0?`按当前页 ${r} 条计时记录估算`:`当前页暂无可计时的执行记录`,loading:t},{id:`failed`,label:i(`mcpMonitor.failedMetric`,null,`失败数`),value:e?e.failedCalls??0:`—`,detail:e?`${i(`mcpMonitor.blockedCount`,{n:e.blockedCalls??0},`安全拦截 ${e.blockedCalls??0}`)} · ${i(`mcpMonitor.lastCall`,null,`最近调用`)} ${e.lastCallTime?v(e.lastCallTime):`—`}`:void 0,tone:e&&e.failedCalls>0?`danger`:void 0,loading:t}]})}function ce({topTools:e,loading:t,onFilterTool:n,activeTool:r}){let i=y(),a=(0,P.useMemo)(()=>(e||[]).map(e=>{let t=Number(e.totalCalls)||0,n=Number(e.blockedCalls)||0,r=Number(e.successCalls)||0,i=t-n;return{...e,key:e.toolName,displayName:U(e.toolName),rate:i>0?r/i:null}}),[e]),o=[{title:i(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`displayName`,render:(e,t)=>(0,X.jsx)(`button`,{type:`button`,className:`mcp-monitor-tool-link ${r&&r===t.toolName?`mcp-monitor-link-active`:``}`,onClick:()=>n?.(t.toolName),children:e||i(`mcpMonitor.unknownTool`,null,`未知工具`)})},{title:i(`mcpMonitor.columnCalls`,null,`调用`),dataIndex:`totalCalls`,width:90,render:e=>e??0},{title:i(`mcpMonitor.successColumn`,null,`成功`),dataIndex:`successCalls`,width:90,render:e=>e??0},{title:i(`mcpMonitor.failedColumn`,null,`失败`),dataIndex:`failedCalls`,width:90,render:e=>(0,X.jsx)(`span`,{className:e>0?`mcp-monitor-danger`:void 0,children:e??0})},{title:i(`mcpMonitor.blockedColumn`,null,`拦截`),dataIndex:`blockedCalls`,width:90,render:e=>e?(0,X.jsx)(s,{size:`small`,color:`orange`,children:e}):0},{title:i(`mcpMonitor.columnSuccessRate`,null,`成功率`),dataIndex:`rate`,width:110,render:e=>e===null?`—`:S(e,1)}];return(0,X.jsx)(k,{title:i(`mcpMonitor.toolStatsTitle`,null,`工具统计`),description:i(`mcpMonitor.toolStatsHint`,null,`点击工具名筛选下方执行记录`),children:(0,X.jsx)(j,{columns:o,dataSource:a,rowKey:`key`,loading:t,pagination:!1,size:`small`,emptyText:i(`mcpMonitor.noStatsData`,null,`暂无统计数据`)})})}var le=[{value:`24h`,labelKey:`timelineRange24h`,fallback:`24 小时`},{value:`7d`,labelKey:`timelineRange7d`,fallback:`7 天`},{value:`30d`,labelKey:`timelineRange30d`,fallback:`30 天`}];function ue({data:e,loading:t,error:n,range:r,onRangeChange:i,onRetry:a}){let o=y(),s=Array.isArray(e?.points)?e.points:[],c=e?.summary||{},l=Number(c.peak)||0,u=(0,P.useMemo)(()=>s.reduce((e,t)=>Math.max(e,Number(t.total)||0),0),[s]),d=Number(c.totalCalls)||0,f=Math.max(1,Math.ceil(s.length/8)),p=le.map(e=>({value:e.value,label:o(`mcpMonitor.${e.labelKey}`,null,e.fallback)}));return(0,X.jsxs)(k,{title:o(`mcpMonitor.timelineTitle`,null,`调用趋势`),description:o(`mcpMonitor.timelineHint`,null,`全部工具合计,失败与拦截单独着色`),extra:(0,X.jsx)(g,{size:`small`,value:r,optionList:p,style:{width:120},onChange:i}),children:[(0,X.jsx)(O,{error:n,onRetry:a}),(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-summary`,children:[(0,X.jsx)(D,{label:o(`mcpMonitor.timelineTotalLegend`,null,`总调用`),value:_(d),loading:t}),(0,X.jsx)(D,{label:`峰值 / 桶`,value:_(l),detail:o(`mcpMonitor.scopeTimeline`,null,`当前时间范围`),loading:t}),(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-legend`,children:[(0,X.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,X.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-total`}),o(`mcpMonitor.timelineTotalLegend`,null,`总调用`)]}),(0,X.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,X.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-failed`}),o(`mcpMonitor.timelineFailedLegend`,null,`失败`)]}),(0,X.jsxs)(`span`,{className:`mcp-monitor-legend-item`,children:[(0,X.jsx)(`i`,{className:`mcp-monitor-legend-dot mcp-monitor-legend-blocked`}),o(`mcpMonitor.timelineBlockedLegend`,null,`安全拦截`)]})]})]}),t&&!s.length?(0,X.jsx)(`div`,{className:`mcp-monitor-timeline-empty`,children:o(`mcpMonitor.timelineLoading`,null,`趋势加载中…`)}):d===0||u===0?(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-empty`,children:[(0,X.jsx)(`p`,{children:o(`mcpMonitor.timelineNoData`,null,`该时段暂无调用`)}),(0,X.jsx)(`p`,{className:`mcp-monitor-timeline-hint`,children:o(`mcpMonitor.timelineEmptyHint`,null,`调用 MCP 工具后此处会出现趋势`)})]}):(0,X.jsx)(`div`,{className:`mcp-monitor-timeline-chart`,role:`img`,"aria-label":o(`mcpMonitor.timelineTitle`,null,`调用趋势`),children:s.map((e,t)=>{let n=Number(e.total)||0,i=Number(e.failed)||0,a=Number(e.blocked)||0,s=n>0?Math.max(3,n/u*100):0,c=n>0?i/n*100:0,l=n>0?a/n*100:0,d=J(e.t,r);return(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-slot`,title:Y(e,o),children:[(0,X.jsx)(`div`,{className:`mcp-monitor-timeline-bar-wrap`,children:(0,X.jsxs)(`div`,{className:`mcp-monitor-timeline-bar`,style:{height:`${s}%`},children:[l>0&&(0,X.jsx)(`span`,{className:`mcp-monitor-timeline-seg mcp-monitor-seg-blocked`,style:{height:`${l}%`}}),c>0&&(0,X.jsx)(`span`,{className:`mcp-monitor-timeline-seg mcp-monitor-seg-failed`,style:{height:`${c}%`}})]})}),(0,X.jsx)(`span`,{className:`mcp-monitor-timeline-tick`,children:t%f===0?d:``})]},e.t||t)})})]})}function Z({status:e}){let t=y();return(0,X.jsx)(s,{size:`small`,color:V(e),shape:`square`,children:B(t,e)})}function de({data:e,loading:t,error:n,page:r,pageSize:i,status:a,toolInput:s,selected:l,onQuery:u,onPageChange:f,onRefresh:m,onOpenDetail:h,onCancel:_,onDelete:b,onSelectionChange:x,canWrite:S,canDelete:ee}){let C=y(),w=e?.executions||[],T=Number(e?.total)||0,E=[{value:`all`,label:C(`mcp.filterAll`,null,`全部`)},...F.map(e=>({value:e,label:B(C,e)}))],D=[{title:C(`mcpMonitor.columnTool`,null,`工具`),dataIndex:`toolName`,render:e=>(0,X.jsx)(`span`,{className:`mcp-monitor-cell-tool`,children:U(e)||C(`mcpMonitor.unknownTool`,null,`未知工具`)})},{title:C(`mcpMonitor.columnStatus`,null,`状态`),dataIndex:`status`,width:110,render:e=>(0,X.jsx)(Z,{status:e})},{title:C(`mcpMonitor.columnStartTime`,null,`开始时间`),dataIndex:`startTime`,width:180,render:e=>v(e)},{title:C(`mcpMonitor.columnDuration`,null,`耗时`),dataIndex:`duration`,width:110,render:(e,t)=>G(W(t))},{title:C(`common.actions`,null,`操作`),dataIndex:`id`,width:230,render:(e,t)=>(0,X.jsxs)(o,{spacing:4,wrap:!0,children:[(0,X.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>h(e),children:C(`mcpMonitor.viewDetail`,null,`详情`)}),H(t.status)&&(0,X.jsx)(c,{size:`small`,theme:`borderless`,disabled:!S,onClick:()=>_(t),children:C(`mcpMonitor.terminateExecution`,null,`终止`)}),(0,X.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,disabled:!ee,onClick:()=>b(t),children:C(`common.delete`,null,`删除`)})]})}];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(O,{error:n,onRetry:m}),(0,X.jsx)(j,{columns:D,dataSource:w,rowKey:`id`,loading:t,pagination:{currentPage:r,pageSize:i,total:T,showSizeChanger:!0,pageSizeOpts:[20,50,100],showTotal:!0,onPageChange:e=>f(e,i),onPageSizeChange:e=>f(1,e)},onRefresh:m,emptyText:C(`mcpMonitor.noExecutions`,null,`暂无执行记录`),rowSelection:{selectedRowKeys:l,onChange:e=>x(e||[])},toolbar:(0,X.jsxs)(o,{spacing:8,wrap:!0,children:[(0,X.jsx)(d,{prefix:(0,X.jsx)(p,{}),value:s,showClear:!0,style:{width:220},placeholder:C(`mcp.toolSearchPlaceholder`,null,`输入工具名称…`),onChange:e=>u({toolInput:e})}),(0,X.jsx)(g,{value:a,style:{width:150},optionList:E,onChange:e=>u({status:e})})]})})]})}var{Text:Q}=a;function fe({executionId:e,onClose:t,canWrite:n,onCancelRequest:r}){let a=y(),{data:s,loading:l,error:u,reload:d}=w(()=>x.get(`/monitor/execution/${encodeURIComponent(e)}`),[e],{skip:!e}),p=e?s:null,h=p?H(p.status):!1;return(0,X.jsxs)(m,{visible:!!e,onCancel:t,title:a(`mcpMonitor.viewDetail`,null,`执行详情`),width:720,footer:p?(0,X.jsxs)(o,{children:[h&&(0,X.jsx)(c,{theme:`solid`,disabled:!n,onClick:()=>r(p),children:a(`mcpMonitor.terminateExecution`,null,`终止`)}),(0,X.jsx)(c,{onClick:t,children:a(`common.close`,null,`关闭`)})]}):null,children:[!p&&l&&(0,X.jsx)(`div`,{className:`mcp-monitor-detail-loading`,children:(0,X.jsx)(f,{})}),(0,X.jsx)(O,{error:u,onRetry:d}),p&&(0,X.jsxs)(`div`,{className:`mcp-monitor-detail`,children:[(0,X.jsx)(E,{columns:2,items:[{label:`工具`,value:(0,X.jsx)(Q,{strong:!0,children:U(p.toolName)||`—`})},{label:a(`mcpMonitor.columnStatus`,null,`状态`),value:(0,X.jsx)(Z,{status:p.status})},{label:`执行 ID`,value:(0,X.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.id})},{label:a(`mcpMonitor.columnStartTime`,null,`开始时间`),value:v(p.startTime)},{label:`结束时间`,value:p.endTime?v(p.endTime):`—`},{label:a(`mcpMonitor.columnDuration`,null,`耗时`),value:G(W(p))},{label:`关联会话`,value:p.conversationId?(0,X.jsxs)(o,{spacing:4,children:[(0,X.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.conversationId}),(0,X.jsx)(A,{text:p.conversationId,size:`small`})]}):`—`},{label:`结果状态`,value:p.result?p.result.isError?`错误结果`:p.result.blocked?`已拦截`:`正常返回`:`无返回`}]}),p.error&&(0,X.jsx)(i,{type:`danger`,className:`mcp-monitor-detail-error`,description:(0,X.jsx)(`span`,{className:`mcp-monitor-mono`,children:p.error})}),(0,X.jsx)(`div`,{className:`mcp-monitor-detail-section`,children:(0,X.jsx)(M,{title:a(`mcpDetailModal.requestParams`,null,`入参`),value:p.arguments??{}})}),(0,X.jsx)(`div`,{className:`mcp-monitor-detail-section`,children:p.result?(0,X.jsx)(M,{title:a(`mcpDetailModal.responseResult`,null,`出参`),value:p.result}):(0,X.jsx)(`div`,{className:`mcp-monitor-detail-empty`,children:h?a(`mcpDetailModal.runningNoResponseYet`,null,`尚无返回,工具可能仍在执行。`):a(`chat.noResponseData`,null,`暂无响应数据`)})}),p.partialOutput&&(0,X.jsxs)(`div`,{className:`mcp-monitor-detail-section`,children:[(0,X.jsxs)(`div`,{className:`mcp-monitor-detail-section-head`,children:[(0,X.jsx)(Q,{strong:!0,children:`实时输出尾部`}),(0,X.jsxs)(o,{spacing:4,children:[p.partialOutputBytes?(0,X.jsxs)(Q,{type:`tertiary`,children:[p.partialOutputBytes,` B`]}):null,(0,X.jsx)(A,{text:p.partialOutput,size:`small`})]})]}),(0,X.jsx)(`pre`,{className:`mcp-monitor-detail-pre`,children:p.partialOutput})]}),(0,X.jsxs)(`div`,{className:`mcp-monitor-detail-footnote`,children:[B(a,p.status),` · `,a(`mcpMonitor.statsFromAllTools`,null,`全部工具累计`)]})]})]})}function $(){let e=y(),{hasPermission:t}=b(),[n,i]=r(),a=t(`monitor:write`)||t(`mcp:write`),s=t(`monitor:delete`),[d,f]=(0,P.useState)(1),[p,m]=(0,P.useState)(20),[g,_]=(0,P.useState)(`all`),[v,S]=(0,P.useState)(``),C=ne(v,350),[E,D]=(0,P.useState)([]),[O,A]=te(`mcp-monitor-timeline-range`,`7d`),[j,M]=(0,P.useState)(null),[F,I]=(0,P.useState)(``),[L,R]=(0,P.useState)(!1),z=n.get(`id`)||``,B=[`24h`,`7d`,`30d`].includes(O)?O:`7d`,V=w(()=>x.get(`/monitor`,{page:d,page_size:p,status:g===`all`?``:g,tool:C}),[d,p,g,C]),H=w(()=>x.get(`/monitor/stats`,{top:12}),[]),G=w(()=>x.get(`/monitor/calls-timeline`,{range:B}),[B]),K=V.data?.executions||[],q=H.data?.summary||V.data?.summary||null,J=H.data?.topTools||V.data?.topTools||[],Y=Number(V.data?.retentionDays)||0,le=(0,P.useMemo)(()=>K.filter(e=>W(e)!==null).length,[K]),Z=(0,P.useMemo)(()=>oe(K),[K]);ie(()=>{typeof document<`u`&&document.hidden||(V.reload({silent:!0}),G.reload({silent:!0}))},5e3),ie(()=>{typeof document<`u`&&document.hidden||H.reload({silent:!0})},2e4);let Q=(0,P.useCallback)(()=>{V.reload(),H.reload({silent:!0}),G.reload({silent:!0})},[V.reload,H.reload,G.reload]),$=(0,P.useCallback)(e=>{let t=new URLSearchParams(n);t.set(`id`,e),i(t,{replace:!0})},[n,i]),pe=(0,P.useCallback)(()=>{let e=new URLSearchParams(n);e.delete(`id`),i(e,{replace:!0})},[n,i]),me=(0,P.useCallback)(e=>{Object.prototype.hasOwnProperty.call(e,`toolInput`)&&S(e.toolInput),e.status!==void 0&&_(e.status),f(1),D([])},[]),he=(0,P.useCallback)((e,t)=>{f(e),t&&t!==p&&m(t)},[p]),ge=(0,P.useCallback)(e=>{S(U(e)),f(1),D([])},[]),_e=(0,P.useCallback)(t=>{ae({title:e(`mcpMonitor.deleteExecTitle`,null,`删除此执行记录`),content:`确定删除 ${U(t.toolName)||`该`} 的执行记录?此操作不可恢复。`,okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/monitor/execution/${encodeURIComponent(t.id)}`),D(e=>e.filter(e=>e!==t.id)),N(e(`mcpMonitor.execDeleted`,null,`执行记录已删除`)),Q()}catch(t){T(t,e(`mcpMonitor.deleteExecFailed`,null,`删除执行记录失败`))}}})},[Q,e]),ve=(0,P.useCallback)(async()=>{if(!E.length){ee(e(`mcpMonitor.selectExecFirst`,null,`请先选择要删除的执行记录`));return}let t=[];try{let e=await x.post(`/monitor/executions/names`,{ids:E});t=[...new Set(Object.values(e||{}).map(e=>U(e?.toolName)).filter(Boolean))]}catch{t=[]}let n=t.length?`涉及工具:${t.slice(0,3).join(`、`)}${t.length>3?` 等`:``}。`:``;ae({title:e(`mcpMonitor.batchDeleteConfirm`,{count:E.length},`确定删除选中的 ${E.length} 条执行记录?`),content:`${n}此操作不可恢复。`,okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/monitor/executions`,{body:{ids:E}}),N(`已删除 ${E.length} 条执行记录`),D([]),Q()}catch(t){T(t,e(`mcp.batchDeleteFailed`,null,`批量删除执行记录失败`))}}})},[Q,E,e]),ye=(0,P.useCallback)(e=>{M(e),I(``)},[]),be=(0,P.useCallback)(async()=>{if(j?.id){R(!0);try{await x.post(`/monitor/execution/${encodeURIComponent(j.id)}/cancel`,{note:F.trim()}),N(e(`mcpDetailModal.abortSuccess`,null,`已发送终止请求`)),M(null),Q()}catch(t){T(t,e(`mcpDetailModal.abortFailed`,null,`终止失败`))}finally{R(!1)}}},[F,j,Q,e]),xe=Y>0?e(`mcpMonitor.retentionHint`,{days:Y},`执行记录保留 ${Y} 天,失败与拦截调用单独标记。`):`统计全部 MCP 工具调用,失败与拦截调用单独标记。`;return(0,X.jsxs)(`div`,{className:`mcp-monitor-page`,children:[(0,X.jsx)(re,{title:e(`mcp.monitorTitle`,null,`MCP 状态监控`),description:xe,extra:(0,X.jsx)(o,{children:(0,X.jsx)(c,{icon:(0,X.jsx)(h,{}),onClick:Q,loading:V.loading||H.loading,children:e(`common.refresh`,null,`刷新`)})})}),(0,X.jsx)(se,{summary:q,loading:H.loading&&!q,avgMs:Z,avgSamples:le}),(0,X.jsx)(ue,{data:G.data,loading:G.loading,error:G.error,range:B,onRangeChange:e=>{e&&A(e)},onRetry:()=>G.reload()}),(0,X.jsx)(ce,{topTools:J,loading:H.loading&&!J.length,onFilterTool:ge,activeTool:C}),(0,X.jsx)(k,{title:e(`mcp.latestExecutions`,null,`最新执行记录`),description:e(`mcpMonitor.emptyHint`,null,`在对话或任务中调用 MCP 工具后,执行记录将显示在此处`),extra:E.length>0?(0,X.jsxs)(o,{spacing:8,children:[(0,X.jsx)(`span`,{className:`mcp-monitor-selected`,children:e(`mcp.selectedCount`,{count:E.length},`已选择 ${E.length} 项`)}),(0,X.jsx)(c,{size:`small`,disabled:!s,type:`danger`,onClick:ve,children:e(`mcp.deleteSelected`,null,`批量删除`)}),(0,X.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>D([]),children:e(`mcpMonitor.deselectAll`,null,`取消全选`)})]}):null,children:(0,X.jsx)(de,{data:V.data,loading:V.loading,error:V.error,page:d,pageSize:p,status:g,toolInput:v,selected:E,onQuery:me,onPageChange:he,onRefresh:()=>V.reload(),onOpenDetail:$,onCancel:ye,onDelete:_e,onSelectionChange:D,canWrite:a,canDelete:s})}),(0,X.jsx)(fe,{executionId:z,onClose:pe,canWrite:a,onCancelRequest:e=>{pe(),ye(e)}}),(0,X.jsxs)(u,{title:e(`mcpMonitor.terminateExecution`,null,`终止执行`),visible:!!j,confirmLoading:L,maskClosable:!L,okText:e(`mcpMonitor.terminateExecution`,null,`终止`),cancelText:e(`common.cancel`,null,`取消`),onCancel:()=>M(null),onOk:be,children:[(0,X.jsx)(`p`,{className:`mcp-monitor-cancel-hint`,children:e(`mcpDetailModal.abortHint`,null,`终止仅取消本次工具调用,不会停止整条对话;说明会与工具输出一起交给模型。`)}),(0,X.jsx)(l,{rows:4,value:F,placeholder:e(`mcpDetailModal.abortNotePlaceholder`,null,`终止说明(可选),例如:命令执行时间过长,先终止。`),onChange:e=>I(e)})]})]})}export{$ as default}; \ No newline at end of file diff --git a/web/static/app/assets/platform-rbac-Bqf7ZmWP.js b/web/static/app/assets/platform-rbac-BDY_zjz7.js similarity index 99% rename from web/static/app/assets/platform-rbac-Bqf7ZmWP.js rename to web/static/app/assets/platform-rbac-BDY_zjz7.js index 3568c9e4..99c2f36d 100644 --- a/web/static/app/assets/platform-rbac-Bqf7ZmWP.js +++ b/web/static/app/assets/platform-rbac-BDY_zjz7.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,Lt as a,N as o,P as s,Pt as c,R as l,U as u,c as d,ft as f,i as p,ut as m,y as h}from"./semi-65W_4I1v.js";import{E as g,F as _,I as v,L as y,a as b,b as x,c as S,l as C,m as w,n as T,p as E,s as D,x as O,y as k}from"./index-CAEPLS-g.js";var A=e(t(),1),j=e(n(),1),M=[[`project`,`项目`],[`conversation`,`会话`],[`asset`,`资产`],[`vulnerability`,`漏洞`],[`deep_assessment`,`深度测评`],[`batch_task`,`批量任务`]];function N({users:e,onCancel:t,onSaved:n}){let a=(0,A.useId)(),[o,s]=(0,A.useState)(M[0][0]),[c,d]=(0,A.useState)(``),[f,m]=(0,A.useState)(0),[g,_]=(0,A.useState)([]),[v,x]=(0,A.useState)(null),[w,E]=(0,A.useState)(!1),D=T(c,250),k=b(async()=>({type:o,q:D,offset:f,payload:await y.get(`/rbac/resources`,{type:o,q:D,limit:20,offset:f})}),[o,D,f]),N=k.data?.type===o&&k.data.q===D&&k.data.offset===f?k.data.payload:null,P=Array.isArray(N?.resources)?N.resources:[],F=new Map([...g,...P.map(e=>[e.id,e.label||e.id])]);return(0,j.jsx)(S,{visible:!0,title:`新增资源授权`,width:560,closable:!w,maskClosable:!w,closeOnEsc:!w,onCancel:t,formId:a,okText:`保存授权`,confirmLoading:w,cancelButtonProps:{disabled:w},children:(0,j.jsxs)(p,{id:a,onSubmit:async e=>{if(w)return;x(null);let t=String(e.ids||``).split(/[\s,,;;]+/).filter(Boolean),r=[...new Set([...g.map(([e])=>e),...t])];if(!r.length||r.length>100)x(Error(`请选择或输入 1 至 100 个资源 ID`));else{E(!0);try{await y.post(`/rbac/resource-assignments`,{user_id:e.user_id,resource_type:o,resource_ids:r}),O(`资源授权已保存`),n()}catch(e){x(e)}finally{E(!1)}}},initValues:{resource_type:o},children:[(0,j.jsx)(p.Select,{field:`user_id`,label:`用户`,filter:!0,optionList:e.map(e=>({value:e.id,label:e.display_name||e.username})),rules:[{required:!0,message:`请选择用户`}]}),(0,j.jsx)(p.Select,{field:`resource_type`,label:`资源类型`,optionList:M.map(([e,t])=>({value:e,label:t})),onChange:e=>{s(e),_([]),d(``),m(0)}}),(0,j.jsx)(p.Slot,{label:`按名称或 ID 搜索`,children:(0,j.jsx)(u,{"aria-label":`搜索资源`,value:c,onChange:e=>{d(e),m(0)}})}),(0,j.jsxs)(p.Slot,{label:`选择资源`,children:[(0,j.jsxs)(i,{wrap:!0,children:[(0,j.jsx)(l,{size:`small`,disabled:f===0||k.loading,onClick:()=>m(e=>Math.max(0,e-20)),children:`上一页`}),(0,j.jsxs)(r.Text,{type:`tertiary`,children:[f+P.length,` / `,N?.total??`—`]}),(0,j.jsx)(l,{size:`small`,disabled:!N?.has_more||k.loading,onClick:()=>m(e=>e+20),children:`下一页`})]}),(0,j.jsx)(h,{multiple:!0,style:{width:`100%`,marginTop:8},loading:k.loading,value:g.map(([e])=>e),"aria-label":`选择资源`,optionList:[...F].map(([e,t])=>({value:e,label:t})),onChange:e=>_((e||[]).map(e=>[e,F.get(e)||e]))})]}),(0,j.jsx)(p.TextArea,{field:`ids`,label:`手动输入资源 ID`,placeholder:`多个 ID 用空格或换行分隔`,rows:2}),(0,j.jsx)(C,{error:v||k.error})]})})}var{Text:P}=r;function F({value:e=[],options:t,onChange:n}){let r=(0,A.useMemo)(()=>{let e=new Map;return t.forEach(t=>{let[n]=t.split(`:`);e.has(n)||e.set(n,[]),e.get(n).push(t)}),[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0]))},[t]);return(0,j.jsx)(`div`,{style:{maxHeight:320,overflow:`auto`,border:`1px solid var(--semi-color-border)`,borderRadius:8,padding:12},children:r.map(([t,r])=>(0,j.jsxs)(`div`,{style:{marginBottom:10},children:[(0,j.jsx)(P,{type:`tertiary`,style:{fontSize:12,textTransform:`uppercase`},children:t}),(0,j.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:8,marginTop:4},children:r.map(t=>(0,j.jsx)(s,{checked:e.includes(t),onChange:r=>{let i=new Set(e);r.target.checked?i.add(t):i.delete(t),n([...i])},children:t.split(`:`)[1]},t))})]},t))})}function I(){let e=_(),{hasPermission:t}=v(),n=t(`rbac:write`),[r,s]=(0,A.useState)(`roles`),[u,h]=(0,A.useState)(null),[T,M]=(0,A.useState)(null),[I,L]=(0,A.useState)(!1),[R,z]=(0,A.useState)(!1),B=b(()=>y.get(`/rbac/metadata`),[]),V=b(()=>y.get(`/rbac/roles`),[]),H=b(()=>y.get(`/rbac/users`),[]),U=b(()=>y.get(`/rbac/resource-assignments`),[]),W=B.data?.permissions?Object.keys(B.data.permissions):[],G=Array.isArray(V.data?.roles)?V.data.roles:[],K=Array.isArray(H.data?.users)?H.data.users:[],q=Array.isArray(U.data?.assignments)?U.data.assignments:[],J=G.map(e=>({value:e.id,label:e.name})),Y=new Map(G.map(e=>[e.id,e.name])),X=new Map(K.map(e=>[e.id,e.display_name||e.username])),Z=async()=>{let e=await u.form.validate();z(!0);try{let t={name:e.name.trim(),description:e.description||``,scope:e.scope||``,permissions:u.permissions||[]};u.role?.id?await y.put(`/rbac/roles/${encodeURIComponent(u.role.id)}`,t):await y.post(`/rbac/roles`,t),O(`角色已保存`),h(null),V.reload(),B.reload()}catch(e){x(e,`保存角色失败`)}finally{z(!1)}},Q=async()=>{let e=await T.form.validate();z(!0);try{let t={display_name:e.display_name||``,enabled:e.enabled!==!1,roles:e.roles||[]};T.user?.id?(e.password&&(t.password=e.password),await y.put(`/rbac/users/${encodeURIComponent(T.user.id)}`,t)):await y.post(`/rbac/users`,{...t,username:e.username.trim(),password:e.password}),O(`用户已保存`),M(null),H.reload()}catch(e){x(e,`保存用户失败`)}finally{z(!1)}},$=e=>k({title:`删除角色「${e.name}」?`,onOk:async()=>{await y.del(`/rbac/roles/${encodeURIComponent(e.id)}`),O(`已删除`),V.reload()}}),ee=e=>k({title:`删除用户「${e.username}」?`,onOk:async()=>{await y.del(`/rbac/users/${encodeURIComponent(e.id)}`),O(`已删除`),H.reload()}}),te=e=>k({title:`删除该资源授权?`,content:`${e.resourceType||``} ${e.resourceId||``}`,onOk:async()=>{await y.del(`/rbac/resource-assignments/${encodeURIComponent(e.id)}`),O(`已删除`),U.reload()}});return(0,j.jsxs)(`div`,{children:[(0,j.jsx)(E,{title:e(`auth.rbacTitle`,null,`平台权限`),description:`平台账号、角色与资源授权;角色决定接口权限键,资源授权决定可见数据范围。`,extra:(0,j.jsx)(l,{icon:(0,j.jsx)(m,{}),onClick:()=>{V.reload(),H.reload(),U.reload(),B.reload()},children:`刷新`})}),(0,j.jsxs)(d,{type:`line`,activeKey:r,onChange:s,children:[(0,j.jsx)(d.TabPane,{itemKey:`roles`,tab:`角色权限(${G.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,j.jsx)(f,{}),onClick:()=>h({role:null,permissions:[],form:{}}),children:`新建角色`}),children:[(0,j.jsx)(C,{error:V.error,onRetry:()=>V.reload()}),(0,j.jsx)(D,{columns:[{title:`角色`,dataIndex:`name`,render:(e,t)=>(0,j.jsxs)(i,{vertical:!0,spacing:0,align:`start`,children:[(0,j.jsx)(P,{strong:!0,children:e}),(0,j.jsx)(P,{type:`tertiary`,children:t.description||`—`})]})},{title:`数据范围`,dataIndex:`scope`,width:130,render:e=>e?(0,j.jsx)(o,{size:`small`,children:e}):`—`},{title:`权限数`,dataIndex:`permissions`,width:100,render:e=>Array.isArray(e)?e.length:0},{title:`系统内置`,dataIndex:`is_system`,width:100,render:e=>e?(0,j.jsx)(o,{size:`small`,color:`blue`,children:`是`}):`否`},{title:`操作`,width:160,render:(e,t)=>(0,j.jsxs)(i,{children:[n&&!t.is_system&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,j.jsx)(c,{}),onClick:()=>h({role:t,permissions:t.permissions||[],form:{}}),children:`编辑`}),n&&!t.is_system&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>$(t)})]})}],dataSource:G,rowKey:`id`,loading:V.loading,pagination:{pageSize:20}})]})}),(0,j.jsx)(d.TabPane,{itemKey:`users`,tab:`平台用户(${K.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,j.jsx)(f,{}),onClick:()=>M({user:null,form:{}}),children:`新建用户`}),children:[(0,j.jsx)(C,{error:H.error,onRetry:()=>H.reload()}),(0,j.jsx)(D,{columns:[{title:`用户名`,dataIndex:`username`,render:(e,t)=>(0,j.jsxs)(i,{vertical:!0,spacing:0,align:`start`,children:[(0,j.jsx)(P,{strong:!0,children:e}),(0,j.jsx)(P,{type:`tertiary`,children:t.display_name||`—`})]})},{title:`角色`,dataIndex:`roles`,width:260,render:e=>Array.isArray(e)&&e.length?(0,j.jsx)(i,{wrap:!0,spacing:4,children:e.map(e=>(0,j.jsx)(o,{size:`small`,children:Y.get(e)||e},e))}):`—`},{title:`状态`,dataIndex:`enabled`,width:100,render:e=>e===!1?(0,j.jsx)(o,{size:`small`,color:`grey`,children:`停用`}):(0,j.jsx)(o,{size:`small`,color:`green`,children:`启用`})},{title:`操作`,width:160,render:(e,t)=>(0,j.jsxs)(i,{children:[n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,j.jsx)(c,{}),onClick:()=>M({user:t,form:{}}),children:`编辑`}),n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>ee(t)})]})}],dataSource:K,rowKey:`id`,loading:H.loading,pagination:{pageSize:20}})]})}),(0,j.jsx)(d.TabPane,{itemKey:`assignments`,tab:`资源授权(${q.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,icon:(0,j.jsx)(f,{}),onClick:()=>L(!0),children:`新增资源授权`}),children:[(0,j.jsx)(C,{error:U.error,onRetry:()=>U.reload()}),(0,j.jsx)(D,{columns:[{title:`资源类型`,dataIndex:`resourceType`,width:140,render:e=>e||`—`},{title:`资源`,dataIndex:`resourceId`,render:(e,t)=>t.resourceLabel||e||`—`},{title:`用户`,dataIndex:`userId`,render:e=>X.get(e)||e||`—`},{title:`创建时间`,dataIndex:`createdAt`,width:180,render:e=>g(e)},{title:`操作`,width:100,render:(e,t)=>n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>te(t)})}],dataSource:q,rowKey:`id`,loading:U.loading,pagination:{pageSize:20}})]})})]}),n&&I&&(0,j.jsx)(N,{users:K,onCancel:()=>L(!1),onSaved:()=>{L(!1),U.reload()}}),(0,j.jsx)(S,{title:u?.role?`编辑角色`:`新建角色`,visible:!!u,onCancel:()=>h(null),onOk:Z,confirmLoading:R,width:820,children:u&&(0,j.jsxs)(p,{getFormApi:e=>h(t=>t&&{...t,form:e}),initValues:u.role?{name:u.role.name,description:u.role.description,scope:u.role.scope}:{},children:[(0,j.jsx)(p.Input,{field:`name`,label:`角色名称`,rules:[{required:!0,message:`请输入角色名称`}]}),(0,j.jsx)(p.Input,{field:`description`,label:`描述`}),(0,j.jsx)(p.Select,{field:`scope`,label:`数据范围`,optionList:(B.data?.scopes||[`all`,`assigned`,`own`]).map(e=>({value:e,label:e}))}),(0,j.jsx)(p.Slot,{label:`权限`,children:(0,j.jsx)(F,{value:u.permissions,options:W,onChange:e=>h(t=>({...t,permissions:e}))})})]})},u?.role?.id||`new-rbac-role`),(0,j.jsx)(S,{title:T?.user?`编辑用户`:`新建用户`,visible:!!T,onCancel:()=>M(null),onOk:Q,confirmLoading:R,width:620,children:T&&(0,j.jsxs)(p,{getFormApi:e=>M(t=>t&&{...t,form:e}),initValues:T.user?{username:T.user.username,display_name:T.user.display_name,enabled:T.user.enabled!==!1,roles:T.user.roles||[]}:{enabled:!0,roles:[]},children:[(0,j.jsx)(p.Input,{field:`username`,label:`用户名`,disabled:!!T.user,rules:[{required:!0,message:`请输入用户名`}]}),(0,j.jsx)(p.Input,{field:`display_name`,label:`显示名称`}),(0,j.jsx)(p.Input,{field:`password`,label:T.user?`重置密码(留空不修改)`:`密码`,mode:`password`,rules:T.user?[]:[{required:!0,min:8,message:`至少 8 位`}]}),(0,j.jsx)(p.Select,{field:`roles`,label:`角色`,multiple:!0,optionList:J}),(0,j.jsx)(p.Slot,{label:`启用`,children:(0,j.jsx)(p.Switch,{field:`enabled`})})]})},T?.user?.id||`new-rbac-user`)]})}export{I as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,I as i,Lt as a,N as o,P as s,Pt as c,R as l,U as u,c as d,ft as f,i as p,ut as m,y as h}from"./semi-65W_4I1v.js";import{E as g,F as _,I as v,L as y,a as b,b as x,c as S,l as C,m as w,n as T,p as E,s as D,x as O,y as k}from"./index-DNMXun-U.js";var A=e(t(),1),j=e(n(),1),M=[[`project`,`项目`],[`conversation`,`会话`],[`asset`,`资产`],[`vulnerability`,`漏洞`],[`deep_assessment`,`深度测评`],[`batch_task`,`批量任务`]];function N({users:e,onCancel:t,onSaved:n}){let a=(0,A.useId)(),[o,s]=(0,A.useState)(M[0][0]),[c,d]=(0,A.useState)(``),[f,m]=(0,A.useState)(0),[g,_]=(0,A.useState)([]),[v,x]=(0,A.useState)(null),[w,E]=(0,A.useState)(!1),D=T(c,250),k=b(async()=>({type:o,q:D,offset:f,payload:await y.get(`/rbac/resources`,{type:o,q:D,limit:20,offset:f})}),[o,D,f]),N=k.data?.type===o&&k.data.q===D&&k.data.offset===f?k.data.payload:null,P=Array.isArray(N?.resources)?N.resources:[],F=new Map([...g,...P.map(e=>[e.id,e.label||e.id])]);return(0,j.jsx)(S,{visible:!0,title:`新增资源授权`,width:560,closable:!w,maskClosable:!w,closeOnEsc:!w,onCancel:t,formId:a,okText:`保存授权`,confirmLoading:w,cancelButtonProps:{disabled:w},children:(0,j.jsxs)(p,{id:a,onSubmit:async e=>{if(w)return;x(null);let t=String(e.ids||``).split(/[\s,,;;]+/).filter(Boolean),r=[...new Set([...g.map(([e])=>e),...t])];if(!r.length||r.length>100)x(Error(`请选择或输入 1 至 100 个资源 ID`));else{E(!0);try{await y.post(`/rbac/resource-assignments`,{user_id:e.user_id,resource_type:o,resource_ids:r}),O(`资源授权已保存`),n()}catch(e){x(e)}finally{E(!1)}}},initValues:{resource_type:o},children:[(0,j.jsx)(p.Select,{field:`user_id`,label:`用户`,filter:!0,optionList:e.map(e=>({value:e.id,label:e.display_name||e.username})),rules:[{required:!0,message:`请选择用户`}]}),(0,j.jsx)(p.Select,{field:`resource_type`,label:`资源类型`,optionList:M.map(([e,t])=>({value:e,label:t})),onChange:e=>{s(e),_([]),d(``),m(0)}}),(0,j.jsx)(p.Slot,{label:`按名称或 ID 搜索`,children:(0,j.jsx)(u,{"aria-label":`搜索资源`,value:c,onChange:e=>{d(e),m(0)}})}),(0,j.jsxs)(p.Slot,{label:`选择资源`,children:[(0,j.jsxs)(i,{wrap:!0,children:[(0,j.jsx)(l,{size:`small`,disabled:f===0||k.loading,onClick:()=>m(e=>Math.max(0,e-20)),children:`上一页`}),(0,j.jsxs)(r.Text,{type:`tertiary`,children:[f+P.length,` / `,N?.total??`—`]}),(0,j.jsx)(l,{size:`small`,disabled:!N?.has_more||k.loading,onClick:()=>m(e=>e+20),children:`下一页`})]}),(0,j.jsx)(h,{multiple:!0,style:{width:`100%`,marginTop:8},loading:k.loading,value:g.map(([e])=>e),"aria-label":`选择资源`,optionList:[...F].map(([e,t])=>({value:e,label:t})),onChange:e=>_((e||[]).map(e=>[e,F.get(e)||e]))})]}),(0,j.jsx)(p.TextArea,{field:`ids`,label:`手动输入资源 ID`,placeholder:`多个 ID 用空格或换行分隔`,rows:2}),(0,j.jsx)(C,{error:v||k.error})]})})}var{Text:P}=r;function F({value:e=[],options:t,onChange:n}){let r=(0,A.useMemo)(()=>{let e=new Map;return t.forEach(t=>{let[n]=t.split(`:`);e.has(n)||e.set(n,[]),e.get(n).push(t)}),[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0]))},[t]);return(0,j.jsx)(`div`,{style:{maxHeight:320,overflow:`auto`,border:`1px solid var(--semi-color-border)`,borderRadius:8,padding:12},children:r.map(([t,r])=>(0,j.jsxs)(`div`,{style:{marginBottom:10},children:[(0,j.jsx)(P,{type:`tertiary`,style:{fontSize:12,textTransform:`uppercase`},children:t}),(0,j.jsx)(`div`,{style:{display:`flex`,flexWrap:`wrap`,gap:8,marginTop:4},children:r.map(t=>(0,j.jsx)(s,{checked:e.includes(t),onChange:r=>{let i=new Set(e);r.target.checked?i.add(t):i.delete(t),n([...i])},children:t.split(`:`)[1]},t))})]},t))})}function I(){let e=_(),{hasPermission:t}=v(),n=t(`rbac:write`),[r,s]=(0,A.useState)(`roles`),[u,h]=(0,A.useState)(null),[T,M]=(0,A.useState)(null),[I,L]=(0,A.useState)(!1),[R,z]=(0,A.useState)(!1),B=b(()=>y.get(`/rbac/metadata`),[]),V=b(()=>y.get(`/rbac/roles`),[]),H=b(()=>y.get(`/rbac/users`),[]),U=b(()=>y.get(`/rbac/resource-assignments`),[]),W=B.data?.permissions?Object.keys(B.data.permissions):[],G=Array.isArray(V.data?.roles)?V.data.roles:[],K=Array.isArray(H.data?.users)?H.data.users:[],q=Array.isArray(U.data?.assignments)?U.data.assignments:[],J=G.map(e=>({value:e.id,label:e.name})),Y=new Map(G.map(e=>[e.id,e.name])),X=new Map(K.map(e=>[e.id,e.display_name||e.username])),Z=async()=>{let e=await u.form.validate();z(!0);try{let t={name:e.name.trim(),description:e.description||``,scope:e.scope||``,permissions:u.permissions||[]};u.role?.id?await y.put(`/rbac/roles/${encodeURIComponent(u.role.id)}`,t):await y.post(`/rbac/roles`,t),O(`角色已保存`),h(null),V.reload(),B.reload()}catch(e){x(e,`保存角色失败`)}finally{z(!1)}},Q=async()=>{let e=await T.form.validate();z(!0);try{let t={display_name:e.display_name||``,enabled:e.enabled!==!1,roles:e.roles||[]};T.user?.id?(e.password&&(t.password=e.password),await y.put(`/rbac/users/${encodeURIComponent(T.user.id)}`,t)):await y.post(`/rbac/users`,{...t,username:e.username.trim(),password:e.password}),O(`用户已保存`),M(null),H.reload()}catch(e){x(e,`保存用户失败`)}finally{z(!1)}},$=e=>k({title:`删除角色「${e.name}」?`,onOk:async()=>{await y.del(`/rbac/roles/${encodeURIComponent(e.id)}`),O(`已删除`),V.reload()}}),ee=e=>k({title:`删除用户「${e.username}」?`,onOk:async()=>{await y.del(`/rbac/users/${encodeURIComponent(e.id)}`),O(`已删除`),H.reload()}}),te=e=>k({title:`删除该资源授权?`,content:`${e.resourceType||``} ${e.resourceId||``}`,onOk:async()=>{await y.del(`/rbac/resource-assignments/${encodeURIComponent(e.id)}`),O(`已删除`),U.reload()}});return(0,j.jsxs)(`div`,{children:[(0,j.jsx)(E,{title:e(`auth.rbacTitle`,null,`平台权限`),description:`平台账号、角色与资源授权;角色决定接口权限键,资源授权决定可见数据范围。`,extra:(0,j.jsx)(l,{icon:(0,j.jsx)(m,{}),onClick:()=>{V.reload(),H.reload(),U.reload(),B.reload()},children:`刷新`})}),(0,j.jsxs)(d,{type:`line`,activeKey:r,onChange:s,children:[(0,j.jsx)(d.TabPane,{itemKey:`roles`,tab:`角色权限(${G.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,j.jsx)(f,{}),onClick:()=>h({role:null,permissions:[],form:{}}),children:`新建角色`}),children:[(0,j.jsx)(C,{error:V.error,onRetry:()=>V.reload()}),(0,j.jsx)(D,{columns:[{title:`角色`,dataIndex:`name`,render:(e,t)=>(0,j.jsxs)(i,{vertical:!0,spacing:0,align:`start`,children:[(0,j.jsx)(P,{strong:!0,children:e}),(0,j.jsx)(P,{type:`tertiary`,children:t.description||`—`})]})},{title:`数据范围`,dataIndex:`scope`,width:130,render:e=>e?(0,j.jsx)(o,{size:`small`,children:e}):`—`},{title:`权限数`,dataIndex:`permissions`,width:100,render:e=>Array.isArray(e)?e.length:0},{title:`系统内置`,dataIndex:`is_system`,width:100,render:e=>e?(0,j.jsx)(o,{size:`small`,color:`blue`,children:`是`}):`否`},{title:`操作`,width:160,render:(e,t)=>(0,j.jsxs)(i,{children:[n&&!t.is_system&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,j.jsx)(c,{}),onClick:()=>h({role:t,permissions:t.permissions||[],form:{}}),children:`编辑`}),n&&!t.is_system&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>$(t)})]})}],dataSource:G,rowKey:`id`,loading:V.loading,pagination:{pageSize:20}})]})}),(0,j.jsx)(d.TabPane,{itemKey:`users`,tab:`平台用户(${K.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,j.jsx)(f,{}),onClick:()=>M({user:null,form:{}}),children:`新建用户`}),children:[(0,j.jsx)(C,{error:H.error,onRetry:()=>H.reload()}),(0,j.jsx)(D,{columns:[{title:`用户名`,dataIndex:`username`,render:(e,t)=>(0,j.jsxs)(i,{vertical:!0,spacing:0,align:`start`,children:[(0,j.jsx)(P,{strong:!0,children:e}),(0,j.jsx)(P,{type:`tertiary`,children:t.display_name||`—`})]})},{title:`角色`,dataIndex:`roles`,width:260,render:e=>Array.isArray(e)&&e.length?(0,j.jsx)(i,{wrap:!0,spacing:4,children:e.map(e=>(0,j.jsx)(o,{size:`small`,children:Y.get(e)||e},e))}):`—`},{title:`状态`,dataIndex:`enabled`,width:100,render:e=>e===!1?(0,j.jsx)(o,{size:`small`,color:`grey`,children:`停用`}):(0,j.jsx)(o,{size:`small`,color:`green`,children:`启用`})},{title:`操作`,width:160,render:(e,t)=>(0,j.jsxs)(i,{children:[n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,j.jsx)(c,{}),onClick:()=>M({user:t,form:{}}),children:`编辑`}),n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>ee(t)})]})}],dataSource:K,rowKey:`id`,loading:H.loading,pagination:{pageSize:20}})]})}),(0,j.jsx)(d.TabPane,{itemKey:`assignments`,tab:`资源授权(${q.length})`,children:(0,j.jsxs)(w,{extra:n&&(0,j.jsx)(l,{theme:`solid`,icon:(0,j.jsx)(f,{}),onClick:()=>L(!0),children:`新增资源授权`}),children:[(0,j.jsx)(C,{error:U.error,onRetry:()=>U.reload()}),(0,j.jsx)(D,{columns:[{title:`资源类型`,dataIndex:`resourceType`,width:140,render:e=>e||`—`},{title:`资源`,dataIndex:`resourceId`,render:(e,t)=>t.resourceLabel||e||`—`},{title:`用户`,dataIndex:`userId`,render:e=>X.get(e)||e||`—`},{title:`创建时间`,dataIndex:`createdAt`,width:180,render:e=>g(e)},{title:`操作`,width:100,render:(e,t)=>n&&(0,j.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,j.jsx)(a,{}),onClick:()=>te(t)})}],dataSource:q,rowKey:`id`,loading:U.loading,pagination:{pageSize:20}})]})})]}),n&&I&&(0,j.jsx)(N,{users:K,onCancel:()=>L(!1),onSaved:()=>{L(!1),U.reload()}}),(0,j.jsx)(S,{title:u?.role?`编辑角色`:`新建角色`,visible:!!u,onCancel:()=>h(null),onOk:Z,confirmLoading:R,width:820,children:u&&(0,j.jsxs)(p,{getFormApi:e=>h(t=>t&&{...t,form:e}),initValues:u.role?{name:u.role.name,description:u.role.description,scope:u.role.scope}:{},children:[(0,j.jsx)(p.Input,{field:`name`,label:`角色名称`,rules:[{required:!0,message:`请输入角色名称`}]}),(0,j.jsx)(p.Input,{field:`description`,label:`描述`}),(0,j.jsx)(p.Select,{field:`scope`,label:`数据范围`,optionList:(B.data?.scopes||[`all`,`assigned`,`own`]).map(e=>({value:e,label:e}))}),(0,j.jsx)(p.Slot,{label:`权限`,children:(0,j.jsx)(F,{value:u.permissions,options:W,onChange:e=>h(t=>({...t,permissions:e}))})})]})},u?.role?.id||`new-rbac-role`),(0,j.jsx)(S,{title:T?.user?`编辑用户`:`新建用户`,visible:!!T,onCancel:()=>M(null),onOk:Q,confirmLoading:R,width:620,children:T&&(0,j.jsxs)(p,{getFormApi:e=>M(t=>t&&{...t,form:e}),initValues:T.user?{username:T.user.username,display_name:T.user.display_name,enabled:T.user.enabled!==!1,roles:T.user.roles||[]}:{enabled:!0,roles:[]},children:[(0,j.jsx)(p.Input,{field:`username`,label:`用户名`,disabled:!!T.user,rules:[{required:!0,message:`请输入用户名`}]}),(0,j.jsx)(p.Input,{field:`display_name`,label:`显示名称`}),(0,j.jsx)(p.Input,{field:`password`,label:T.user?`重置密码(留空不修改)`:`密码`,mode:`password`,rules:T.user?[]:[{required:!0,min:8,message:`至少 8 位`}]}),(0,j.jsx)(p.Select,{field:`roles`,label:`角色`,multiple:!0,optionList:J}),(0,j.jsx)(p.Slot,{label:`启用`,children:(0,j.jsx)(p.Switch,{field:`enabled`})})]})},T?.user?.id||`new-rbac-user`)]})}export{I as default}; \ No newline at end of file diff --git a/web/static/app/assets/plugin-hub-FbKl43dM.js b/web/static/app/assets/plugin-hub-BhSjc1VJ.js similarity index 99% rename from web/static/app/assets/plugin-hub-FbKl43dM.js rename to web/static/app/assets/plugin-hub-BhSjc1VJ.js index a572fcc7..9d1ea7e6 100644 --- a/web/static/app/assets/plugin-hub-FbKl43dM.js +++ b/web/static/app/assets/plugin-hub-BhSjc1VJ.js @@ -1,4 +1,4 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{B as a,Ft as o,G as s,I as c,Lt as l,Mt as u,N as d,P as f,R as p,S as m,U as h,W as g,Wt as _,Zt as v,_t as y,c as b,et as x,ft as S,h as C,l as w,lt as T,m as E,on as D,ot as O,pt as k,q as ee,qt as A,rn as j,rt as te,tt as ne,ut as M,x as re,y as ie,yt as N}from"./semi-65W_4I1v.js";import{B as ae,E as oe,F as P,I as se,L as F,_ as ce,a as I,b as L,c as le,d as R,l as ue,m as de,o as fe,p as pe,r as z,s as me,u as he,x as B,y as ge}from"./index-CAEPLS-g.js";import{r as _e}from"./agent-handoff-DzQOcr38.js";var V=e(t(),1);function ve(e=`op`){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`${e}-${crypto.randomUUID()}`:`${e}-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}var ye={plugin_bearer_required:[`pluginHub.errorBearerRequired`,`需要 Bearer 登录凭据才能访问插件平台`],plugin_invalid_request:[`pluginHub.errorInvalidRequest`,`请求参数不合法,请检查插件 ID(仅限小写字母、数字和连字符)、标题与仓库地址`],plugin_invalid_source:[`pluginHub.errorInvalidSource`,`仅支持公开的 GitHub HTTPS 仓库地址及合法分支/Tag/Commit`],plugin_ambiguous_git_ref:[`pluginHub.errorAmbiguousRef`,`分支与 Tag 同名,请填写完整引用(如 refs/tags/xxx 或 refs/heads/xxx)`],plugin_source_not_found:[`pluginHub.errorSourceNotFound`,`未找到目标仓库或指定版本`],plugin_invalid_manifest:[`pluginHub.errorInvalidManifest`,`插件 Manifest 格式或字段校验未通过`],plugin_github_rate_limited:[`pluginHub.errorRateLimited`,`GitHub API 触发限流,建议配置 plugins.egress.github_token_env 后重试`],plugin_source_unavailable:[`pluginHub.errorSourceUnavailable`,`无法连接上游仓库,请检查网络或插件代理配置`],plugin_manifest_required:[`pluginHub.errorManifestRequired`,`该仓库未自带 csai-plugin.yaml,请先补全 Manifest 草案`],plugin_manifest_source_mismatch:[`pluginHub.errorSourceMismatch`,`Manifest 中的仓库地址或版本与探测结果不一致`],plugin_artifact_not_approved:[`pluginHub.errorArtifactNotApproved`,`当前宿主策略未批准该制品摘要,请联系管理员或核对批准策略`],plugin_operation_conflict:[`pluginHub.errorOperationConflict`,`该插件已有正在执行的变更任务,请等待当前操作完成`],plugin_plan_stale:[`pluginHub.errorPlanStale`,`安装计划已过期或已被消费,请重新生成锁定计划`],plugin_runtime_unavailable:[`pluginHub.errorRuntimeUnavailable`,`插件运行调度器尚未就绪,请稍后重试`],plugin_artifact_unavailable:[`pluginHub.errorArtifactUnavailable`,`未找到适配当前系统架构的可安装制品或镜像`],plugin_llm_binding_invalid:[`pluginHub.errorLLMBindingInvalid`,`所选模型通道无效或与该插件声明的协议不兼容`],plugin_llm_gateway_unavailable:[`pluginHub.errorLLMGatewayUnavailable`,`CSAI 插件模型网关未就绪`],plugin_web_unavailable:[`pluginHub.errorWebUnavailable`,`插件 WebUI 代理未就绪或应用尚未健康启动`],plugin_embed_origin_or_permission_rejected:[`pluginHub.errorEmbedRejected`,`无权访问该插件工作区或请求来源校验未通过`],plugin_record_not_found:[`pluginHub.errorNotFound`,`未找到对应的插件记录或计划已过期`],docker_cli_missing:[`pluginHub.errorDockerCliMissing`,`宿主未安装 Docker CLI / Engine,容器类插件无法启动`],docker_daemon_unavailable:[`pluginHub.errorDockerDaemonUnavailable`,`宿主 Docker 服务未启动,或当前运行用户无权访问 docker.sock`],docker_compose_missing:[`pluginHub.errorDockerComposeMissing`,`宿主缺少 Docker Compose v2 插件`],docker_engine_unsupported:[`pluginHub.errorDockerEngineUnsupported`,`宿主 Docker Engine 版本过低或不满足隔离档位要求`],docker_socket_missing:[`pluginHub.errorDockerSocketMissing`,`容器内未挂载 /var/run/docker.sock`],git_missing:[`pluginHub.errorGitMissing`,`宿主未安装 Git 工具`],plugin_install_failed:[`pluginHub.errorInstallFailed`,`插件安装失败,请查看运行日志或交给 Agent 排错修复`]};function H(e,t,n){let r=ye[typeof t==`string`?t:t?.payload?.error||(typeof t?.message==`string`?t.message:``)];return r?e(r[0],null,r[1]):(typeof t==`string`?t:t?.message)||n||e(`common.loadFailed`,null,`操作失败`)}function be({driver:e,probe:t,hostOS:n,hostArch:r,pluginTitle:i}){return[`请帮我在当前 CyberStrikeAI 宿主机上安装并配置插件平台缺少的运行驱动「${e}」。`,``,`### 当前诊断信息`,`- 宿主机平台:${n||`unknown`}/${r||`unknown`}`,`- 缺少驱动:${e}`,`- 预检错误码:${t?.code||`unavailable`}`,t?.guidance?`- 官方提示:${t.guidance}`:``,t?.install_command?`- 参考安装命令:\`${t.install_command}\``:``,i?`- 待安装插件:${i}`:``,``,`### 请按以下步骤协助完成`,`1. 先检查当前宿主机系统发行版、当前运行用户、包管理器以及目标依赖(如 Docker / Docker Compose / Git)与服务/权限状态;`,`2. 使用官方软件源或受信任方式安装并启动缺少的依赖(涉及 sudo 或系统变更时请清晰说明并走审批确认);`,"3. 如果安装了 Docker,请同时确认 `dockerd` 已开机自启、Compose v2 可用,并检查当前运行 CyberStrikeAI 的用户是否有权限访问 `/var/run/docker.sock`;","4. 执行验证命令确认驱动已正常可用(例如 `docker version && docker compose version` 或 `git --version`);","5. 完成后告诉我是否需要重启 CyberStrikeAI 服务(例如新增 `docker` 用户组后),以便我回到「能力平台」继续一键安装插件。"].filter(Boolean).join(` +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{B as a,Ft as o,G as s,I as c,Lt as l,Mt as u,N as d,P as f,R as p,S as m,U as h,W as g,Wt as _,Zt as v,_t as y,c as b,et as x,ft as S,h as C,l as w,lt as T,m as E,on as D,ot as O,pt as k,q as ee,qt as A,rn as j,rt as te,tt as ne,ut as M,x as re,y as ie,yt as N}from"./semi-65W_4I1v.js";import{B as ae,E as oe,F as P,I as se,L as F,_ as ce,a as I,b as L,c as le,d as R,l as ue,m as de,o as fe,p as pe,r as z,s as me,u as he,x as B,y as ge}from"./index-DNMXun-U.js";import{r as _e}from"./agent-handoff-DzQOcr38.js";var V=e(t(),1);function ve(e=`op`){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`${e}-${crypto.randomUUID()}`:`${e}-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}var ye={plugin_bearer_required:[`pluginHub.errorBearerRequired`,`需要 Bearer 登录凭据才能访问插件平台`],plugin_invalid_request:[`pluginHub.errorInvalidRequest`,`请求参数不合法,请检查插件 ID(仅限小写字母、数字和连字符)、标题与仓库地址`],plugin_invalid_source:[`pluginHub.errorInvalidSource`,`仅支持公开的 GitHub HTTPS 仓库地址及合法分支/Tag/Commit`],plugin_ambiguous_git_ref:[`pluginHub.errorAmbiguousRef`,`分支与 Tag 同名,请填写完整引用(如 refs/tags/xxx 或 refs/heads/xxx)`],plugin_source_not_found:[`pluginHub.errorSourceNotFound`,`未找到目标仓库或指定版本`],plugin_invalid_manifest:[`pluginHub.errorInvalidManifest`,`插件 Manifest 格式或字段校验未通过`],plugin_github_rate_limited:[`pluginHub.errorRateLimited`,`GitHub API 触发限流,建议配置 plugins.egress.github_token_env 后重试`],plugin_source_unavailable:[`pluginHub.errorSourceUnavailable`,`无法连接上游仓库,请检查网络或插件代理配置`],plugin_manifest_required:[`pluginHub.errorManifestRequired`,`该仓库未自带 csai-plugin.yaml,请先补全 Manifest 草案`],plugin_manifest_source_mismatch:[`pluginHub.errorSourceMismatch`,`Manifest 中的仓库地址或版本与探测结果不一致`],plugin_artifact_not_approved:[`pluginHub.errorArtifactNotApproved`,`当前宿主策略未批准该制品摘要,请联系管理员或核对批准策略`],plugin_operation_conflict:[`pluginHub.errorOperationConflict`,`该插件已有正在执行的变更任务,请等待当前操作完成`],plugin_plan_stale:[`pluginHub.errorPlanStale`,`安装计划已过期或已被消费,请重新生成锁定计划`],plugin_runtime_unavailable:[`pluginHub.errorRuntimeUnavailable`,`插件运行调度器尚未就绪,请稍后重试`],plugin_artifact_unavailable:[`pluginHub.errorArtifactUnavailable`,`未找到适配当前系统架构的可安装制品或镜像`],plugin_llm_binding_invalid:[`pluginHub.errorLLMBindingInvalid`,`所选模型通道无效或与该插件声明的协议不兼容`],plugin_llm_gateway_unavailable:[`pluginHub.errorLLMGatewayUnavailable`,`CSAI 插件模型网关未就绪`],plugin_web_unavailable:[`pluginHub.errorWebUnavailable`,`插件 WebUI 代理未就绪或应用尚未健康启动`],plugin_embed_origin_or_permission_rejected:[`pluginHub.errorEmbedRejected`,`无权访问该插件工作区或请求来源校验未通过`],plugin_record_not_found:[`pluginHub.errorNotFound`,`未找到对应的插件记录或计划已过期`],docker_cli_missing:[`pluginHub.errorDockerCliMissing`,`宿主未安装 Docker CLI / Engine,容器类插件无法启动`],docker_daemon_unavailable:[`pluginHub.errorDockerDaemonUnavailable`,`宿主 Docker 服务未启动,或当前运行用户无权访问 docker.sock`],docker_compose_missing:[`pluginHub.errorDockerComposeMissing`,`宿主缺少 Docker Compose v2 插件`],docker_engine_unsupported:[`pluginHub.errorDockerEngineUnsupported`,`宿主 Docker Engine 版本过低或不满足隔离档位要求`],docker_socket_missing:[`pluginHub.errorDockerSocketMissing`,`容器内未挂载 /var/run/docker.sock`],git_missing:[`pluginHub.errorGitMissing`,`宿主未安装 Git 工具`],plugin_install_failed:[`pluginHub.errorInstallFailed`,`插件安装失败,请查看运行日志或交给 Agent 排错修复`]};function H(e,t,n){let r=ye[typeof t==`string`?t:t?.payload?.error||(typeof t?.message==`string`?t.message:``)];return r?e(r[0],null,r[1]):(typeof t==`string`?t:t?.message)||n||e(`common.loadFailed`,null,`操作失败`)}function be({driver:e,probe:t,hostOS:n,hostArch:r,pluginTitle:i}){return[`请帮我在当前 CyberStrikeAI 宿主机上安装并配置插件平台缺少的运行驱动「${e}」。`,``,`### 当前诊断信息`,`- 宿主机平台:${n||`unknown`}/${r||`unknown`}`,`- 缺少驱动:${e}`,`- 预检错误码:${t?.code||`unavailable`}`,t?.guidance?`- 官方提示:${t.guidance}`:``,t?.install_command?`- 参考安装命令:\`${t.install_command}\``:``,i?`- 待安装插件:${i}`:``,``,`### 请按以下步骤协助完成`,`1. 先检查当前宿主机系统发行版、当前运行用户、包管理器以及目标依赖(如 Docker / Docker Compose / Git)与服务/权限状态;`,`2. 使用官方软件源或受信任方式安装并启动缺少的依赖(涉及 sudo 或系统变更时请清晰说明并走审批确认);`,"3. 如果安装了 Docker,请同时确认 `dockerd` 已开机自启、Compose v2 可用,并检查当前运行 CyberStrikeAI 的用户是否有权限访问 `/var/run/docker.sock`;","4. 执行验证命令确认驱动已正常可用(例如 `docker version && docker compose version` 或 `git --version`);","5. 完成后告诉我是否需要重启 CyberStrikeAI 服务(例如新增 `docker` 用户组后),以便我回到「能力平台」继续一键安装插件。"].filter(Boolean).join(` `)}function xe({install:e,logs:t,hostOS:n,hostArch:r}){let i=(Array.isArray(t)?t:[]).slice(-40).map(e=>`[${e.created_at||``}] ${e.line}`).join(` `);return[`我在 CyberStrikeAI 插件化能力平台中安装/运行插件「${e?.title||e?.plugin_id||`未知插件`}」失败,请帮我排查根因并直接在宿主机上修复缺少的运行环境或依赖。`,``,`### 插件状态与诊断信息`,`- 插件名称:${e?.title||`—`} (${e?.plugin_id||`—`})`,`- 实例 ID:${e?.id||`—`}`,`- 运行驱动:${e?.driver||`—`}`,`- 当前状态:${e?.observed_state||`failed`}`,`- 最近错误码:${e?.last_error_code||`plugin_install_failed`}`,e?.repository?`- 源码仓库:${e.repository}`:``,n?`- 宿主机平台:${n}/${r||``}`:``,``,`### 最近插件脱敏日志`,"```text",i||`(暂无日志输出,请直接检查对应驱动的宿主机运行环境)`,"```",``,`### 请协助完成`,`1. 根据错误码和日志定位失败根因(例如缺少 Docker / Compose / Git / Go / Node.js、dockerd 未启动、docker.sock 权限不足、端口或网络问题等);`,`2. 如果缺少运行环境或依赖,请直接帮我在宿主机上安装并配置就绪(涉及提权或系统改动时按审批确认);`,`3. 验证宿主机依赖已恢复正常,并告诉我接下来回到「能力平台」直接点击重试/启动即可。`].filter(Boolean).join(` `)}function Se(e){switch(String(e||``).toLowerCase()){case`healthy`:return`green`;case`starting`:case`installing`:case`stopping`:return`blue`;case`degraded`:case`cleanup_pending`:return`amber`;case`failed`:return`red`;default:return`grey`}}function Ce(e,t){let n={healthy:[`pluginHub.stateHealthy`,`运行中`],starting:[`pluginHub.stateStarting`,`启动中`],installing:[`pluginHub.stateInstalling`,`安装中`],stopping:[`pluginHub.stateStopping`,`停止中`],stopped:[`pluginHub.stateStopped`,`已停止`],degraded:[`pluginHub.stateDegraded`,`状态异常`],failed:[`pluginHub.stateFailed`,`失败`],cleanup_pending:[`pluginHub.stateCleanupPending`,`待清理`],removed:[`pluginHub.stateRemoved`,`已卸载`]}[String(t||``).toLowerCase()];return n?e(n[0],null,n[1]):t||`—`}function U(e,t){let n={auto:[`pluginHub.driverAuto`,`自动择优(Release → Git → 容器)`],release:[`pluginHub.driverRelease`,`Release 预编译包`],git:[`pluginHub.driverGit`,`Git 源码构建`],container:[`pluginHub.driverContainer`,`Docker / Compose 容器`],compose:[`pluginHub.driverCompose`,`Docker Compose`]}[String(t||``).toLowerCase()];return n?e(n[0],null,n[1]):t||`—`}var W={listCatalog:()=>F.get(`/plugins/catalog`),saveCatalog:e=>F.post(`/plugins/catalog`,e),deleteCatalog:e=>F.del(`/plugins/catalog/${encodeURIComponent(e)}`),restoreCatalog:()=>F.post(`/plugins/catalog/restore`,{}),listInstalls:()=>F.get(`/plugins/installs`),getInstall:e=>F.get(`/plugins/installs/${encodeURIComponent(e)}`),listLLMChannels:()=>F.get(`/plugins/llm/channels`),probes:(e=`standard`)=>F.get(`/plugins/runtime/probes`,{isolation:e}),inspectGit:(e,t)=>F.post(`/plugins/imports/inspect`,{repository:e.trim(),revision:(t||``).trim()}),createPlan:e=>F.post(`/plugins/install-plans`,e),install:({planId:e,planDigest:t,autoBindLLM:n})=>F.post(`/plugins/installs`,{kind:`install`,plan_id:e,plan_digest:t,idempotency_key:ve(`install`),auto_bind_llm:n}),operate:(e,t,n={})=>F.post(`/plugins/installs/${encodeURIComponent(e)}/operations`,{kind:t,idempotency_key:ve(t),...n}),getOperation:e=>F.get(`/plugins/operations/${encodeURIComponent(e)}`),readLogs:(e,t=0,n=100)=>F.get(`/plugins/installs/${encodeURIComponent(e)}/logs`,{after:t,limit:n}),issueEmbedSession:e=>F.post(`/plugins/installs/${encodeURIComponent(e)}/embed-sessions`,{}),patchLLM:(e,t)=>F.patch(`/plugins/installs/${encodeURIComponent(e)}/llm`,t)};function we(e,{after:t=0,onEntry:n,onError:r,onClose:i}={}){let a=new AbortController,o=ae(),s={Accept:`text/event-stream`};o&&(s.Authorization=`Bearer ${o}`);let c=`/api/plugins/installs/${encodeURIComponent(e)}/logs?after=${encodeURIComponent(String(t))}`;return(async()=>{try{let e=await fetch(c,{method:`GET`,headers:s,signal:a.signal});if(e.status===401&&window.dispatchEvent(new CustomEvent(`csai:unauthorized`)),!e.ok||!e.body)throw Error(`HTTP ${e.status}`);let t=e.body.getReader(),r=new TextDecoder,o=``;for(;;){let{done:e,value:i}=await t.read();if(e)break;o+=r.decode(i,{stream:!0});let a;for(;(a=o.indexOf(` diff --git a/web/static/app/assets/project-form-Bm3Gi6Yc.js b/web/static/app/assets/project-form-B7wV5B1p.js similarity index 94% rename from web/static/app/assets/project-form-Bm3Gi6Yc.js rename to web/static/app/assets/project-form-B7wV5B1p.js index 9aa3b749..f3e73496 100644 --- a/web/static/app/assets/project-form-Bm3Gi6Yc.js +++ b/web/static/app/assets/project-form-B7wV5B1p.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,i}from"./semi-65W_4I1v.js";import{F as a,L as o,c as s,l as c,x as l}from"./index-CAEPLS-g.js";var u=e(t(),1),d=e(n(),1),{Text:f}=r,p=120,m=4e3;function h({visible:e,project:t,onCancel:n,onSaved:r}){let h=a(),g=(0,u.useId)(),[_,v]=(0,u.useState)(!1),[y,b]=(0,u.useState)(null),x=!!t?.id;return(0,u.useEffect)(()=>{b(null)},[e,t?.id]),(0,d.jsxs)(s,{visible:e,width:560,closable:!_,closeOnEsc:!_,onCancel:n,cancelButtonProps:{disabled:_},title:x?h(`projects.modalEditTitle`,null,`编辑项目`):h(`projects.modalNewTitle`,null,`新建项目`),formId:g,okText:x?h(`projects.saveChanges`,null,`保存修改`):h(`projects.createProject`,null,`创建项目`),confirmLoading:_,children:[(0,d.jsx)(f,{type:`tertiary`,size:`small`,children:x?h(`projects.modalEditSubtitle`,null,`修改项目名称与描述`):h(`projects.modalNewSubtitle`,null,`创建后可绑定对话,跨会话共享事实黑板`)}),(0,d.jsxs)(i,{id:g,onSubmit:async e=>{if(!_){v(!0),b(null);try{let n={name:e.name.trim(),description:(e.description||``).slice(0,m)},i=x?await o.put(`/projects/${t.id}`,n):await o.post(`/projects`,n);l(x?h(`projects.saved`,null,`已保存`):h(`projects.createProject`,null,`创建项目`)),r?.(i)}catch(e){b(e)}finally{v(!1)}}},initValues:{name:t?.name||``,description:t?.description||``},children:[(0,d.jsx)(i.Input,{id:`${g}-name`,field:`name`,maxLength:p,label:h(`projects.projectName`,null,`项目名称`),placeholder:h(`projects.projectNamePlaceholder`,null,`例如:某客户 Web 渗透`),rules:[{required:!0,whitespace:!0,message:h(`projects.enterProjectName`,null,`请输入项目名称`)}]}),(0,d.jsx)(i.TextArea,{id:`${g}-description`,field:`description`,rows:4,maxCount:m,label:h(`projects.projectDescription`,null,`项目描述`),placeholder:h(`projects.projectDescriptionPlaceholder`,null,`客户/任务备注、协作说明…`),extraText:h(`projects.descriptionLengthHint`,null,`仅供团队成员查阅,Agent 不会读取;需让 Agent 知晓的内容请写入事实黑板`)}),(0,d.jsx)(c,{error:y})]},`${e}-${t?.id||`new`}`)]})}export{h as t}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{G as r,i}from"./semi-65W_4I1v.js";import{F as a,L as o,c as s,l as c,x as l}from"./index-DNMXun-U.js";var u=e(t(),1),d=e(n(),1),{Text:f}=r,p=120,m=4e3;function h({visible:e,project:t,onCancel:n,onSaved:r}){let h=a(),g=(0,u.useId)(),[_,v]=(0,u.useState)(!1),[y,b]=(0,u.useState)(null),x=!!t?.id;return(0,u.useEffect)(()=>{b(null)},[e,t?.id]),(0,d.jsxs)(s,{visible:e,width:560,closable:!_,closeOnEsc:!_,onCancel:n,cancelButtonProps:{disabled:_},title:x?h(`projects.modalEditTitle`,null,`编辑项目`):h(`projects.modalNewTitle`,null,`新建项目`),formId:g,okText:x?h(`projects.saveChanges`,null,`保存修改`):h(`projects.createProject`,null,`创建项目`),confirmLoading:_,children:[(0,d.jsx)(f,{type:`tertiary`,size:`small`,children:x?h(`projects.modalEditSubtitle`,null,`修改项目名称与描述`):h(`projects.modalNewSubtitle`,null,`创建后可绑定对话,跨会话共享事实黑板`)}),(0,d.jsxs)(i,{id:g,onSubmit:async e=>{if(!_){v(!0),b(null);try{let n={name:e.name.trim(),description:(e.description||``).slice(0,m)},i=x?await o.put(`/projects/${t.id}`,n):await o.post(`/projects`,n);l(x?h(`projects.saved`,null,`已保存`):h(`projects.createProject`,null,`创建项目`)),r?.(i)}catch(e){b(e)}finally{v(!1)}}},initValues:{name:t?.name||``,description:t?.description||``},children:[(0,d.jsx)(i.Input,{id:`${g}-name`,field:`name`,maxLength:p,label:h(`projects.projectName`,null,`项目名称`),placeholder:h(`projects.projectNamePlaceholder`,null,`例如:某客户 Web 渗透`),rules:[{required:!0,whitespace:!0,message:h(`projects.enterProjectName`,null,`请输入项目名称`)}]}),(0,d.jsx)(i.TextArea,{id:`${g}-description`,field:`description`,rows:4,maxCount:m,label:h(`projects.projectDescription`,null,`项目描述`),placeholder:h(`projects.projectDescriptionPlaceholder`,null,`客户/任务备注、协作说明…`),extraText:h(`projects.descriptionLengthHint`,null,`仅供团队成员查阅,Agent 不会读取;需让 Agent 知晓的内容请写入事实黑板`)}),(0,d.jsx)(c,{error:y})]},`${e}-${t?.id||`new`}`)]})}export{h as t}; \ No newline at end of file diff --git a/web/static/app/assets/projects-CMt4u2Qr.js b/web/static/app/assets/projects-CfcDnjFh.js similarity index 99% rename from web/static/app/assets/projects-CMt4u2Qr.js rename to web/static/app/assets/projects-CfcDnjFh.js index fb7c488b..f3fb3767 100644 --- a/web/static/app/assets/projects-CMt4u2Qr.js +++ b/web/static/app/assets/projects-CfcDnjFh.js @@ -1,4 +1,4 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{D as a,E as o,G as s,I as c,N as l,P as u,R as d,S as f,U as p,W as m,_ as h,c as g,d as _,ft as v,gt as y,h as b,lt as x,m as S,p as C,ut as w,v as T,y as E}from"./semi-65W_4I1v.js";import{E as D,F as O,I as k,L as A,_ as ee,a as j,b as M,c as N,d as P,f as F,l as te,m as I,n as L,p as R,s as z,t as B,x as V,y as H}from"./index-CAEPLS-g.js";import{t as U}from"./project-form-Bm3Gi6Yc.js";import{a as W,i as ne,n as G,o as K,r as re,t as ie}from"./graph-parents-i1hc3RVG.js";import{t as ae}from"./AssetEditorModal-HZN0Ndjf.js";var q=e(t(),1),oe=[{value:`target`,label:`target(目标)`},{value:`auth`,label:`auth(认证)`},{value:`infra`,label:`infra(基础设施)`},{value:`business`,label:`business(业务)`},{value:`finding`,label:`finding(发现)`},{value:`chain`,label:`chain(攻击链)`},{value:`exploit`,label:`exploit(利用)`},{value:`poc`,label:`poc(POC)`},{value:`note`,label:`note(备注)`}],se={target:`目标`,auth:`认证`,infra:`基础设施`,business:`业务`,finding:`发现`,chain:`攻击链`,exploit:`利用`,poc:`POC`,note:`备注`,vuln:`漏洞`,missing:`缺失`},ce=[{value:`tentative`,label:`待确认`},{value:`confirmed`,label:`已确认`},{value:`deprecated`,label:`已废弃`}],le={confirmed:{label:`已确认`,color:`green`},tentative:{label:`待确认`,color:`amber`},deprecated:{label:`已废弃`,color:`grey`}},ue=[{value:`active`,label:`进行中`},{value:`archived`,label:`已归档`}],J={target:`#2563eb`,auth:`#0891b2`,infra:`#0d9488`,finding:`#d97706`,chain:`#db2777`,exploit:`#7c3aed`,poc:`#7c3aed`,vulnerability:`#dc2626`,note:`#64748b`,missing:`#94a3b8`},de={target:`TARGET · 目标`,auth:`AUTH · 认证`,infra:`INFRA · 基础设施`,finding:`FINDING · 发现`,chain:`CHAIN · 攻击链`,exploit:`EXPLOIT · 利用`,poc:`POC · 验证`,vulnerability:`VULN · 漏洞`,note:`NOTE · 备注`,missing:`MISSING · 缺失`},fe=[`discovered_on`,`depends_on`,`leads_to`,`enables`,`exploits`];function Y(e,t=`操作失败`){if(!e)return t;if(typeof e==`string`)return e;let n=e.payload;if(n&&typeof n==`object`){let e=n.error;if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=typeof e.message==`string`?e.message:``,n=typeof e.code==`string`?e.code:``;if(t)return n?`${t}(${n})`:t}if(typeof n.message==`string`&&n.message)return n.message}return typeof e.message==`string`&&e.message&&e.message!==`[object Object]`?e.message:t}function pe(e,t=`加载失败`){return e?{message:Y(e,t)}:null}function me(e){return!Array.isArray(e)||!e.length?``:e.map(e=>`${e.edge_type||e.type||``}: ${e.source_fact_key||e.from||``}`.trim()).join(` +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{D as a,E as o,G as s,I as c,N as l,P as u,R as d,S as f,U as p,W as m,_ as h,c as g,d as _,ft as v,gt as y,h as b,lt as x,m as S,p as C,ut as w,v as T,y as E}from"./semi-65W_4I1v.js";import{E as D,F as O,I as k,L as A,_ as ee,a as j,b as M,c as N,d as P,f as F,l as te,m as I,n as L,p as R,s as z,t as B,x as V,y as H}from"./index-DNMXun-U.js";import{t as U}from"./project-form-B7wV5B1p.js";import{a as W,i as ne,n as G,o as K,r as re,t as ie}from"./graph-parents-i1hc3RVG.js";import{t as ae}from"./AssetEditorModal-C2UJzIaS.js";var q=e(t(),1),oe=[{value:`target`,label:`target(目标)`},{value:`auth`,label:`auth(认证)`},{value:`infra`,label:`infra(基础设施)`},{value:`business`,label:`business(业务)`},{value:`finding`,label:`finding(发现)`},{value:`chain`,label:`chain(攻击链)`},{value:`exploit`,label:`exploit(利用)`},{value:`poc`,label:`poc(POC)`},{value:`note`,label:`note(备注)`}],se={target:`目标`,auth:`认证`,infra:`基础设施`,business:`业务`,finding:`发现`,chain:`攻击链`,exploit:`利用`,poc:`POC`,note:`备注`,vuln:`漏洞`,missing:`缺失`},ce=[{value:`tentative`,label:`待确认`},{value:`confirmed`,label:`已确认`},{value:`deprecated`,label:`已废弃`}],le={confirmed:{label:`已确认`,color:`green`},tentative:{label:`待确认`,color:`amber`},deprecated:{label:`已废弃`,color:`grey`}},ue=[{value:`active`,label:`进行中`},{value:`archived`,label:`已归档`}],J={target:`#2563eb`,auth:`#0891b2`,infra:`#0d9488`,finding:`#d97706`,chain:`#db2777`,exploit:`#7c3aed`,poc:`#7c3aed`,vulnerability:`#dc2626`,note:`#64748b`,missing:`#94a3b8`},de={target:`TARGET · 目标`,auth:`AUTH · 认证`,infra:`INFRA · 基础设施`,finding:`FINDING · 发现`,chain:`CHAIN · 攻击链`,exploit:`EXPLOIT · 利用`,poc:`POC · 验证`,vulnerability:`VULN · 漏洞`,note:`NOTE · 备注`,missing:`MISSING · 缺失`},fe=[`discovered_on`,`depends_on`,`leads_to`,`enables`,`exploits`];function Y(e,t=`操作失败`){if(!e)return t;if(typeof e==`string`)return e;let n=e.payload;if(n&&typeof n==`object`){let e=n.error;if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=typeof e.message==`string`?e.message:``,n=typeof e.code==`string`?e.code:``;if(t)return n?`${t}(${n})`:t}if(typeof n.message==`string`&&n.message)return n.message}return typeof e.message==`string`&&e.message&&e.message!==`[object Object]`?e.message:t}function pe(e,t=`加载失败`){return e?{message:Y(e,t)}:null}function me(e){return!Array.isArray(e)||!e.length?``:e.map(e=>`${e.edge_type||e.type||``}: ${e.source_fact_key||e.from||``}`.trim()).join(` `)}var X=e(r(),1),{Text:he}=s;function ge({value:e}){let t=le[String(e||``).toLowerCase()]||{label:e||`—`,color:`grey`};return(0,X.jsx)(l,{size:`small`,color:t.color,children:t.label})}function _e({projectId:e,canWrite:t,revision:r=0,onAddFact:i,onEditFact:a,onViewFact:o,onMutated:s}){let f=O(),m=n(),[g,_]=(0,q.useState)(``),y=L(g,300),[b,S]=(0,q.useState)(`all`),[C,T]=(0,q.useState)(`all`),[k,ee]=(0,q.useState)(!0),[N,P]=(0,q.useState)(!1),F=j(()=>A.get(`/projects/${e}/facts`,{limit:200,include_link_counts:`true`,exclude_deprecated:k?`true`:void 0,search:y.trim()||void 0,category:b===`all`?void 0:b,confidence:C===`all`?void 0:C,sparse_only:N?`true`:void 0}),[e,y,b,C,k,N,r]),R=(0,q.useMemo)(()=>Array.isArray(F.data)?F.data:[],[F.data]),B=async t=>{try{await A.post(`/projects/${e}/facts/deprecate`,{fact_key:t.fact_key}),V(f(`projects.saved`,null,`已保存`)),s?s():F.reload({silent:!0})}catch(e){M(Y(e,f(`projects.operationFailed`,null,`操作失败`)))}},U=async t=>{try{await A.post(`/projects/${e}/facts/restore`,{fact_key:t.fact_key,confidence:`tentative`}),V(f(`projects.saved`,null,`已保存`)),s?s():F.reload({silent:!0})}catch(e){M(Y(e,f(`projects.operationFailed`,null,`操作失败`)))}},W=t=>{H({title:f(`projects.deleteForeverTitle`,null,`永久删除`),content:f(`projects.confirmDeleteFact`,null,`删除该事实?`),okText:f(`common.delete`,null,`删除`),onOk:async()=>{try{await A.del(`/projects/${e}/facts/${t.id}`),V(f(`common.delete`,null,`删除`)),s?s():F.reload({silent:!0})}catch(e){M(Y(e,f(`projects.operationFailed`,null,`操作失败`)))}}})},ne=[{title:`fact_key`,dataIndex:`fact_key`,width:230,render:(e,t)=>(0,X.jsxs)(`div`,{className:`project-fact-key`,children:[(0,X.jsx)(`code`,{className:`project-fact-key-chip`,title:e,children:e}),(0,X.jsxs)(`div`,{className:`project-fact-key-meta`,children:[t.pinned&&(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:f(`projects.pinned`,null,`置顶`)}),t.related_vulnerability_id&&(0,X.jsx)(l,{size:`small`,color:`violet`,type:`light`,title:t.related_vulnerability_id,children:f(`projects.relatedVulnIdTitle`,null,`关联漏洞 ID`)})]})]})},{title:f(`projects.category`,null,`分类`),dataIndex:`category`,width:108,render:e=>(0,X.jsx)(l,{size:`small`,color:`cyan`,type:`light`,children:se[String(e||``).toLowerCase()]||e||`—`})},{title:f(`projects.summary`,null,`摘要`),dataIndex:`summary`,render:(e,t)=>(0,X.jsx)(`button`,{type:`button`,className:`project-cell-ellipsis project-link-button`,title:e,onClick:()=>o?.(t.fact_key),children:e||`—`})},{title:f(`projects.linksColumn`,null,`关系`),dataIndex:`link_counts`,width:92,render:e=>{let t=e?.outgoing||0,n=e?.incoming||0;return!t&&!n?(0,X.jsx)(he,{type:`tertiary`,children:`—`}):(0,X.jsxs)(`span`,{className:`project-link-counts`,title:f(`projects.linkCountsTitle`,null,`出边数 / 入边数`),children:[`↑`,t,` ↓`,n]})}},{title:f(`projects.confidence`,null,`置信度`),dataIndex:`confidence`,width:92,render:e=>(0,X.jsx)(ge,{value:e})},{title:f(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:158,render:e=>(0,X.jsx)(he,{size:`small`,children:D(e)})},{title:f(`common.actions`,null,`操作`),dataIndex:`id`,width:224,render:(e,n)=>{let r=String(n.confidence||``).toLowerCase()===`deprecated`;return(0,X.jsxs)(c,{spacing:2,wrap:!0,children:[(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>o?.(n.fact_key),children:f(`projects.details`,null,`详情`)}),n.source_conversation_id?(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>m(`/chat?conversation=${encodeURIComponent(n.source_conversation_id)}`),children:`会话`}):null,(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>a?.(n.fact_key),children:f(`common.edit`,null,`编辑`)}),r?(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>U(n),children:f(`projects.restore`,null,`恢复`)}):(0,X.jsx)(h,{title:f(`projects.confirmDeprecateFact`,{factKey:n.fact_key},`将事实 ${n.fact_key} 标记为已废弃?`),onConfirm:()=>B(n),disabled:!t,children:(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,title:f(`projects.deprecateTitle`,null,`标记为已废弃`),children:f(`projects.deprecate`,null,`废弃`)})}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>W(n),children:f(`common.delete`,null,`删除`)})]})}}];return(0,X.jsxs)(I,{title:f(`projects.tabFacts`,null,`事实黑板`),description:f(`projects.factToolbarHint`,null,`索引仅含 key 与摘要;攻击链 / POC 写在 body,Agent 通过 get_project_fact 复现`),extra:(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),theme:`borderless`,loading:F.loading,onClick:()=>{s?s():F.reload()}}),(0,X.jsx)(d,{type:`primary`,icon:(0,X.jsx)(v,{}),disabled:!t,onClick:i,children:f(`projects.addFact`,null,`添加事实`)})]}),children:[(0,X.jsx)(te,{error:pe(F.error),onRetry:F.reload}),(0,X.jsxs)(`div`,{className:`project-toolbar`,children:[(0,X.jsx)(p,{prefix:(0,X.jsx)(x,{}),value:g,showClear:!0,"aria-label":f(`projects.searchFactsSr`,null,`搜索事实`),placeholder:f(`projects.searchFactsPlaceholder`,null,`搜索 key、摘要、body…`),onChange:e=>_(e),style:{width:260}}),(0,X.jsx)(E,{value:b,onChange:S,style:{width:146},optionList:[{value:`all`,label:f(`projects.all`,null,`全部`)},...oe]}),(0,X.jsx)(E,{value:C,onChange:T,style:{width:128},optionList:[{value:`all`,label:f(`projects.all`,null,`全部`)},...ce]}),(0,X.jsx)(u,{checked:k,onChange:e=>ee(e.target.checked),children:f(`projects.hideDeprecated`,null,`隐藏废弃`)}),(0,X.jsx)(u,{checked:N,onChange:e=>P(e.target.checked),children:f(`projects.sparseOnly`,null,`仅待补全`)})]}),(0,X.jsx)(z,{columns:ne,dataSource:R,rowKey:`id`,loading:F.loading,pagination:{pageSize:20},emptyText:g||b!==`all`||C!==`all`?f(`projects.noMatchingFacts`,null,`无匹配事实,请调整筛选条件`):f(`projects.noFacts`,null,`暂无事实,点击「添加事实」或由 Agent 自动写入`)})]})}var ve={target:0,infra:1,auth:1,finding:2,chain:3,exploit:3,poc:3,vulnerability:4};function ye(e,t,n,r,i){let a=e=>ve[e.type]??5,o=new Map(e.map(e=>[e.id,e])),s=new Set(t.flatMap(e=>[e.source,e.target])),c=[...e].sort((e,t)=>Number(s.has(t.id))-Number(s.has(e.id))||a(e)-a(t)||e.id.localeCompare(t.id)),l,u;if(n){let e=new Set(t.filter(e=>e.source===n).map(e=>e.target));l=[c.filter(t=>t.id!==n&&!e.has(t.id)),[o.get(n)],c.filter(t=>t.id!==n&&e.has(t.id))],u=new Set(t)}else{let n=e=>{let t=a(o.get(e.source)),n=a(o.get(e.target));return 4*Number(t>n)+2*Number(t!==0)+Number(e.confidence===`tentative`)},r=[...t].sort((e,t)=>n(e)-n(t)||e.source.localeCompare(t.source)||e.target.localeCompare(t.target)||(e.type||``).localeCompare(t.type||``)||(e.id||``).localeCompare(t.id||``)),i=ie(r,e=>o.get(e).type===`target`);u=i.parentEdges;let s=new Map(e.map(e=>[e.id,[]]));for(let e of c){let t=i.parents.get(e.id);t&&s.get(t).push(e)}l=[c.filter(e=>!i.parents.has(e.id))];for(let e of l){let t=e.flatMap(e=>s.get(e.id));t.length&&l.push(t)}}let d=new Map,f=Math.max(5,Math.min(23,Math.ceil(Math.sqrt(e.length)*1.18))),p=0;for(let e of l){if(!e.length)continue;let t=Math.ceil(e.length/Math.ceil(e.length/f));for(let n=0;nd.set(e.id,{x:p,y:(t-(a.length-1)/2)*(i+23)})),p+=r+62}p+=22}return{positions:d,parentEdges:u}}var be=.78,xe=340;function Se(e){let t=e.fact_key||e.id;return{key:t,title:(e.summary||e.label!==`—`&&e.label||t).replace(/\s+/g,` `).trim()||t}}function Ce(e,t,n){let r=e.width(),i=e.height(),a=e.nodes(),o=e.elements(),s=e.getFitViewport(o,Math.min(36,r/10,i/10));if(!s)return null;if(s.zoom>1)return{zoom:1,pan:e.getCenterPan(o,1),view:n===`overview`?n:`fitted`};if(n===`overview`||s.zoom>=be)return{...s,view:n===`overview`?n:`fitted`};let{x:c,y:l}=(t?e.$id(t):a.reduce((e,t)=>{let n=t.position(),r=e.position();return n.xMath.max(8,Math.min(e,s));return{width:i,left:a,...r<=e.height()/2?{top:c(r+o)}:{bottom:c(e.height()-r+o)}}}var Te=[{selector:`node`,style:{shape:`round-rectangle`,width:216,height:98,"background-color":`data(color)`,"background-opacity":.13,"border-color":`data(color)`,"border-opacity":.42,"border-width":1.2}},{selector:`node.current`,style:{"background-opacity":.85}},{selector:`edge`,style:{width:2.15,"line-color":`#8197b6`,"target-arrow-color":`#8197b6`,"target-arrow-shape":`triangle`,"arrow-scale":.85,"curve-style":`bezier`,opacity:.73}},{selector:`edge.forward`,style:{"source-endpoint":`50% 0px`,"target-endpoint":`-50% 0px`}},{selector:`edge.backward`,style:{"source-endpoint":`-50% 0px`,"target-endpoint":`50% 0px`}},{selector:`edge.curved`,style:{"curve-style":`unbundled-bezier`,"edge-distances":`endpoints`,"control-point-weights":`0.30 0.70`,"control-point-distances":`data(bend)`}},{selector:`edge.cross-link`,style:{opacity:.28}},{selector:`edge.focused`,style:{width:2.3,opacity:.96}},{selector:`edge[type = "links_vuln"]`,style:{"line-color":`#c96b81`,"target-arrow-color":`#c96b81`}},{selector:`edge[confidence = "tentative"]`,style:{"line-style":`dashed`,"line-dash-pattern":[5,4]}}];function Ee(e,t,n){let{positions:r,parentEdges:i}=ye(e,t,n,216,98),a=new Map(e.map(e=>[e.id,new Set])),o=e=>JSON.stringify([e.source,e.target].sort()),s=new Map;for(let e of t){let t=o(e);s.set(t,(s.get(t)||0)+1)}let c=t.map((e,t)=>{let c=r.get(e.source),l=r.get(e.target),u=l.x-c.x,d=l.y-c.y,f=[];if(n?f.push(`focused`):i.has(e)||f.push(`cross-link`),u!==0){let t=u>0;f.push(t?`forward`:`backward`),a.get(e.source).add(t?`right`:`left`),a.get(e.target).add(t?`left`:`right`),s.get(o(e))===1&&f.push(`curved`)}let p=Math.sign(d*u)*Math.min(Math.abs(d)*.3,60);return{group:`edges`,classes:f.join(` `),data:{...e,id:`edge|${t}|${e.id||``}`,bend:[-p,p]}}});return{ports:a,elements:[...e.map(e=>({group:`nodes`,data:{id:e.id,type:e.type||`note`,color:J[e.type]||J.missing},position:r.get(e.id),classes:e.id===n?`current`:``})),...c]}}function De({nodes:e,edges:t,selectedId:n,onSelect:r,chartRef:i,label:a,errorText:o,typeLabel:s,onFitChange:c}){let l=(0,q.useRef)(null),u=(0,q.useRef)(null),[d,f]=(0,q.useState)([]),[p,m]=(0,q.useState)(null),[h,g]=(0,q.useState)(!1),_=(0,q.useMemo)(()=>new Map(e.map(e=>[e.id,e])),[e]),v=(e,t)=>i.current?.inspect(e,t);(0,q.useEffect)(()=>{let a=l.current,o=u.current,s=!1,d,p,h,_,v=`reading`,y=!1;return f([]),m(null),g(!1),B(async()=>{let{default:e}=await import(`./cytoscape.esm-BPjn7guX.js`);return{default:e}},[]).then(({default:l})=>{if(s)return;let{ports:u,elements:g}=Ee(e,t,n);d=l({container:a,elements:g,style:Te,layout:{name:`preset`,fit:!1},minZoom:.006,maxZoom:3,wheelSensitivity:.2,boxSelectionEnabled:!1,autounselectify:!0,autoungrabify:!0});let b=()=>{cancelAnimationFrame(h),h=requestAnimationFrame(()=>{let t=W(d,{allowCompact:t=>n||e.length<=24||[`target`,`chain`].includes(t.data(`type`))});f(t.map(e=>({...e,ports:u.get(e.id)})))})},x=(e=`reading`)=>{let t=Ce(d,n,e);t&&(y=!0,v=e,m(null),d.viewport({zoom:t.zoom,pan:t.pan}),c(t.view),y=!1,b())},S=(e,t)=>{let n=d.$id(e);t&&n.nonempty()?m({id:e,box:we(d,n)}):t||m(t=>t?.id===e?null:t)};i.current={fit:()=>x(),overview:()=>x(`overview`),zoom:e=>K(d,e),inspect:S},_=ne(o,d),d.on(`viewport`,()=>{y||(v=null),m(null),b()}),d.on(`zoom`,()=>{y||c(`manual`)}),d.on(`mouseover`,`node`,e=>S(e.target.id(),!0)),d.on(`mouseout`,`node`,e=>S(e.target.id(),!1)),d.on(`tap`,`node`,e=>r(e.target.id()));let C=d.width(),w=d.height();p=new ResizeObserver(()=>{d.resize();let e=d.width(),t=d.height();(C!==e||w!==t)&&(v?x(v):d.panBy({x:(e-C)/2,y:(t-w)/2}),C=e,w=t)}),p.observe(a),x()}).catch(()=>{s||g(!0)}),()=>{s=!0,cancelAnimationFrame(h),p?.disconnect(),_?.(),d?.destroy(),i.current=null}},[e,t,n,r,i,c]);let y=p&&_.get(p.id),b=y&&Se(y);return(0,X.jsxs)(`div`,{className:`project-graph-canvas-wrap`,role:`group`,"aria-label":a,children:[(0,X.jsx)(`div`,{ref:l,className:`project-graph-canvas`}),(0,X.jsx)(`div`,{ref:u,className:`graph-node-layer`,children:d.map(e=>{let t=_.get(e.id);if(!t)return null;let{key:i,title:a}=Se(t);return(0,X.jsx)(G,{card:e,id:t.id,title:a,type:t.type,category:s(t.type||`note`),color:J[t.type]||J.missing,factKey:i,ports:e.ports,selected:t.id===n,onSelect:r,onPreview:v},t.id)})}),y&&(0,X.jsxs)(`div`,{className:`project-graph-node-preview`,role:`tooltip`,style:{...p.box,"--graph-node-color":J[y.type]||J.missing},children:[(0,X.jsxs)(`span`,{className:`project-graph-preview-type`,children:[(0,X.jsx)(re,{type:y.type}),s(y.type||`note`)]}),(0,X.jsx)(`strong`,{dir:`auto`,children:b.title}),(0,X.jsx)(`code`,{dir:`auto`,children:b.key})]}),h&&(0,X.jsx)(`div`,{className:`project-graph-overlay`,role:`alert`,children:o})]})}var{Text:Z}=s,Oe=[],ke=e=>e.summary||e.label||e.fact_key||e.id;function Ae({nodes:e,onSelect:t,t:n}){let[r,i]=(0,q.useState)(``),[a,o]=(0,q.useState)(!1),s=(0,q.useId)(),c=r.trim().toLowerCase(),l=(0,q.useMemo)(()=>[...e].sort((e,t)=>(e.fact_key||e.id).localeCompare(t.fact_key||t.id)),[e]),u=(0,q.useMemo)(()=>{if(!c)return l;let e=l.filter(e=>[e.fact_key,e.label,e.summary,e.category].join(` `).toLowerCase().includes(c)),t=e.findIndex(e=>(e.fact_key||e.id).toLowerCase()===c);return t>0&&e.unshift(...e.splice(t,1)),e},[l,c]),d=e=>{t(e),o(!1),i(``)};return(0,X.jsxs)(`div`,{className:`project-graph-search`,onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||o(!1)},children:[(0,X.jsx)(p,{prefix:(0,X.jsx)(x,{}),value:r,showClear:!0,placeholder:n(`projects.graphSearchPlaceholder`,null,`搜索节点…`),"aria-label":n(`projects.graphSearchSr`,null,`搜索节点`),"aria-controls":a?s:void 0,onChange:e=>{i(e),o(!0)},onFocus:()=>o(!0),onClick:()=>o(!0),onKeyDown:e=>{e.key===`Escape`&&a&&o(!1),e.key===`Enter`&&a&&u.length&&!e.nativeEvent.isComposing&&(e.preventDefault(),d(u[0].id))}}),a&&(0,X.jsxs)(`div`,{className:`project-graph-search-results`,id:s,children:[(0,X.jsx)(`div`,{className:`project-graph-search-count`,role:`status`,children:u.length?n(`projects.graphSearchCount`,{count:u.length},`${u.length} 个节点`):n(`projects.graphNoMatches`,null,`未找到匹配节点`)}),u.length>0&&(0,X.jsx)(`ul`,{className:`project-graph-search-list`,children:u.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{className:`project-graph-search-hit`,type:`button`,onClick:()=>d(e.id),children:[(0,X.jsx)(`span`,{title:ke(e),children:ke(e)}),(0,X.jsx)(`code`,{dir:`auto`,children:e.fact_key||e.id})]})},e.id))})]})]})}function je({projectId:e,canWrite:t,revision:n=0,onOpenFact:r,onEditFact:i,onAddFact:a,onChanged:s}){let f=O(),[p,h]=(0,q.useState)(`path`),[g,_]=(0,q.useState)(!0),[b,x]=(0,q.useState)(``),[S,C]=(0,q.useState)(!1),[T,D]=(0,q.useState)(`fitted`),k=(0,q.useRef)(null),ee=(0,q.useRef)(null),N=`${p}:${g}`,P=j(async()=>({scope:N,data:await A.get(`/projects/${e}/fact-graph`,{view:p,exclude_deprecated:g?`1`:`0`})}),[e,N,n]),F=P.data?.scope===N?P.data.data:null,L=F?.nodes||Oe,R=(0,q.useMemo)(()=>new Map(L.map(e=>[e.id,e])),[L]),z=(0,q.useMemo)(()=>(F?.edges||Oe).filter(e=>R.has(e.source)&&R.has(e.target)),[F,R]),B=R.get(b);(0,q.useEffect)(()=>{ee.current&&(ee.current.scrollTop=0)},[B?.id]);let U=(0,q.useMemo)(()=>B?z.filter(e=>e.source===B.id||e.target===B.id):z,[z,B]),W=(0,q.useMemo)(()=>{if(!B)return L;let e=new Set([B.id]);for(let t of U)e.add(t.source),e.add(t.target);return L.filter(t=>e.has(t.id))},[L,B,U]),ne=Object.keys(J).filter(e=>W.some(t=>t.type===e)),G=e=>f(`projects.graphNodeTypes.${e}`,null,de[e]||e),K=(0,q.useCallback)(e=>x(e),[]),ie=j(()=>S?A.get(`/projects/${e}/fact-edges`):Promise.resolve(null),[e,S,n]),ae=()=>{s?s():(P.reload(),S&&ie.reload())},oe=t=>{H({title:f(`projects.graphDeleteEdge`,null,`删边`),content:f(`projects.confirmDeleteGraphEdge`,null,`确定删除此关系边?`),okText:f(`common.delete`,null,`删除`),onOk:async()=>{try{await A.del(`/projects/${e}/fact-edges/${t.id}`),V(f(`projects.graphEdgeDeleteSuccess`,null,`边已删除`)),ae()}catch(e){M(Y(e,f(`projects.graphEdgeDeleteFailed`,null,`删除边失败`)))}}})},se=(e,t)=>f(`projects.graphStats`,{nodes:e,edges:t},`${e} 个节点 · ${t} 条关系`),ce=f(`projects.tabGraph`,null,`攻击路径`),ue={reading:f(`projects.graphReadingHint`,null,`已保留可读字号,拖动画布浏览其他节点。`),overview:f(`projects.graphFullOverviewHint`,null,`悬停预览节点摘要,点选查看详情。`)}[T],fe=B&&B.type!==`missing`&&!B.id.startsWith(`vuln:`);return(0,X.jsxs)(I,{title:ce,className:`project-graph-card`,extra:(0,X.jsxs)(c,{children:[(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:se(L.length,z.length)}),(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),"aria-label":f(`common.refresh`,null,`刷新`),theme:`borderless`,loading:P.loading,onClick:ae})]}),children:[(0,X.jsx)(te,{error:pe(P.error),onRetry:P.reload}),(0,X.jsxs)(`div`,{className:`project-toolbar project-graph-toolbar`,children:[(0,X.jsx)(E,{value:p,"aria-label":f(`projects.graphScope`,null,`关系范围`),onChange:e=>{x(``),h(e)},style:{width:134},optionList:[{value:`path`,label:f(`projects.graphViewPath`,null,`攻击路径`)},{value:`full`,label:f(`projects.graphViewFull`,null,`完整关系`)}]}),(0,X.jsx)(Ae,{nodes:L,onSelect:K,t:f}),(0,X.jsx)(u,{checked:g,onChange:e=>{x(``),_(e.target.checked)},children:f(`projects.hideDeprecated`,null,`隐藏废弃`)}),(0,X.jsx)(d,{className:`project-graph-edges-toggle`,"aria-expanded":S,onClick:()=>C(e=>!e),children:f(`projects.graphEdgesTitle`,null,`关系边`)})]}),L.length>0?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`project-graph-status`,children:[B?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(d,{size:`small`,theme:`light`,type:`primary`,onClick:()=>x(``),children:f(`projects.graphBackToOverview`,null,`返回全图`)}),(0,X.jsx)(Z,{size:`small`,"aria-live":`polite`,children:f(`projects.graphFocus`,{stats:se(W.length,U.length)},`聚焦直接关系 · ${se(W.length,U.length)}`)})]}):null,(!B||ue)&&(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:ue||f(`projects.graphOverviewHint`,null,`点选节点查看直接关系和摘要。`)})]}),(0,X.jsxs)(`div`,{className:`project-graph-layout${B&&W.length<=6?` is-compact`:``}`,children:[(0,X.jsxs)(`div`,{className:`project-graph-viewport`,children:[(0,X.jsx)(De,{nodes:W,edges:U,selectedId:B?.id,onSelect:K,chartRef:k,typeLabel:G,onFitChange:D,label:f(`projects.graphCanvas`,null,`攻击路径画布`),errorText:f(`projects.graphRenderError`,null,`图谱加载失败,请刷新重试。`)}),(0,X.jsxs)(`div`,{className:`project-graph-footer`,children:[(0,X.jsxs)(`div`,{className:`project-graph-legend`,children:[ne.map(e=>(0,X.jsxs)(`span`,{style:{"--graph-node-color":J[e]},children:[(0,X.jsx)(re,{type:e}),G(e)]},e)),U.some(e=>e.confidence===`tentative`)&&(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`i`,{className:`project-graph-legend-dash`,"aria-hidden":`true`}),f(`projects.graphTentativeEdge`,null,`待确认关系`)]})]}),(0,X.jsxs)(c,{spacing:4,wrap:!0,children:[(0,X.jsx)(d,{size:`small`,icon:(0,X.jsx)(y,{}),"aria-label":f(`projects.graphZoomOut`,null,`缩小`),onClick:()=>k.current?.zoom(1/1.3)}),(0,X.jsx)(d,{size:`small`,icon:(0,X.jsx)(v,{}),"aria-label":f(`projects.graphZoomIn`,null,`放大`),onClick:()=>k.current?.zoom(1.3)}),(0,X.jsx)(d,{size:`small`,"aria-pressed":T===`fitted`||T===`reading`,onClick:()=>k.current?.fit(),children:f(`projects.graphFit`,null,`适合画布`)}),(0,X.jsx)(d,{size:`small`,"aria-pressed":T===`overview`,onClick:()=>k.current?.overview(),children:f(`projects.graphFullOverview`,null,`全图总览`)})]})]})]}),B&&(0,X.jsx)(`aside`,{ref:ee,className:`project-graph-side`,"aria-label":f(`projects.graphNodeDetails`,null,`节点详情`),children:(0,X.jsxs)(`div`,{className:`project-detail-stack`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(Z,{strong:!0,children:ke(B)}),(0,X.jsx)(`code`,{className:`project-graph-node-key`,dir:`auto`,children:B.fact_key||B.id}),(0,X.jsxs)(`div`,{className:`project-graph-side-tags`,children:[(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:G(B.type)}),(0,X.jsx)(l,{size:`small`,color:le[B.confidence]?.color||`grey`,children:le[B.confidence]?f(`projects.graphConfidence.${B.confidence}`,null,le[B.confidence].label):B.confidence||`—`})]})]}),fe&&(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{size:`small`,onClick:()=>r(B.fact_key),children:f(`projects.details`,null,`详情`)}),(0,X.jsx)(d,{size:`small`,disabled:!t,onClick:()=>i(B.fact_key),children:f(`common.edit`,null,`编辑`)})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(Z,{strong:!0,size:`small`,children:[f(`projects.graphDirectLinks`,null,`直接关系`),` · `,U.length]}),U.length?(0,X.jsx)(`ul`,{className:`project-graph-neighbors`,children:U.map((e,t)=>{let n=e.source===B.id,r=R.get(n?e.target:e.source);return(0,X.jsxs)(`li`,{children:[(0,X.jsxs)(`div`,{className:`project-graph-edge-meta`,children:[(0,X.jsxs)(`span`,{children:[n?`→`:`←`,` `,n?f(`projects.graphEdgeOutgoing`,null,`出边`):f(`projects.graphEdgeIncoming`,null,`入边`)]}),(0,X.jsx)(`code`,{children:e.type}),e.confidence===`tentative`&&(0,X.jsx)(`span`,{children:f(`projects.graphConfidence.tentative`,null,`待确认`)})]}),(0,X.jsx)(`button`,{type:`button`,className:`project-graph-peer project-link-button`,onClick:()=>K(r.id),title:r.fact_key,children:ke(r)})]},e.id||t)})}):(0,X.jsx)(`div`,{children:(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:f(`projects.graphEdgesEmpty`,null,`暂无关系边`)})})]})]})})]})]}):P.loading?(0,X.jsx)(`div`,{className:`project-graph-loading`,children:(0,X.jsx)(m,{})}):F&&!P.error?(0,X.jsxs)(o,{title:f(`projects.graphEmptyTitle`,null,`构建攻击路径图`),description:f(`projects.graphEmpty`,null,`暂无路径图数据。为 finding/exploit 类事实添加关系边(discovered_on → target/*)后将在此展示。`),style:{padding:40},children:[(0,X.jsxs)(`div`,{className:`project-graph-empty-steps`,children:[(0,X.jsx)(Z,{type:`tertiary`,children:f(`projects.graphEmptyStep1`,null,`添加 target 类事实(目标、域名、入口)`)}),(0,X.jsx)(Z,{type:`tertiary`,children:f(`projects.graphEmptyStep2`,null,`记录 finding / exploit 并在 links 中连边`)}),(0,X.jsx)(Z,{type:`tertiary`,children:f(`projects.graphEmptyStep3`,null,`使用「连边」模式或编辑事实手动补关系`)})]}),(0,X.jsx)(d,{type:`primary`,disabled:!t,onClick:a,children:f(`projects.graphEmptyCta`,null,`添加第一条事实`)})]}):null,S?(0,X.jsxs)(`div`,{className:`project-edge-table`,children:[(0,X.jsx)(te,{error:pe(ie.error),onRetry:()=>ie.reload()}),(ie.data||[]).length?(0,X.jsx)(`ul`,{className:`project-edge-rows`,children:ie.data.map(e=>(0,X.jsxs)(`li`,{className:`project-edge-row`,children:[(0,X.jsx)(`code`,{children:e.source_fact_key}),(0,X.jsx)(`span`,{className:`project-edge-type`,children:e.edge_type}),(0,X.jsx)(`span`,{className:`project-edge-arrow`,children:`→`}),(0,X.jsx)(`code`,{children:e.target_fact_key}),(0,X.jsx)(l,{size:`small`,color:e.confidence===`tentative`?`amber`:`green`,children:(le[e.confidence]||{}).label||e.confidence||`—`}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>oe(e),children:f(`projects.graphDeleteEdge`,null,`删边`)})]},e.id))}):(0,X.jsx)(Z,{type:`tertiary`,size:`small`,children:f(`projects.graphEdgesEmpty`,null,`暂无关系边`)})]}):null]})}var{Text:Me}=s;function Ne({projectId:e,canWrite:t,onChanged:r}){let i=O(),a=n(),{hasPermission:o}=k(),s=o(`chat:write`),u=j(()=>A.get(`/projects/${e}/conversations`,{limit:100}),[e]),f=u.data?.conversations||[],p=t=>{H({title:i(`projects.promoteAttackChain`,null,`沉淀攻击链`),content:i(`projects.confirmPromoteAttackChain`,null,`将该对话的攻击链沉淀到本项目?会创建/更新事实与关系边。`),okText:i(`projects.promoteAttackChain`,null,`沉淀攻击链`),danger:!1,onOk:async()=>{try{let n=await A.post(`/projects/${e}/promote-attack-chain/${t.id}`);V(i(`projects.promoteAttackChainSuccess`,{facts_created:n?.facts_created||0,facts_updated:n?.facts_updated||0,edges_created:n?.edges_created||0},`已沉淀:新建 ${n?.facts_created||0} / 更新 ${n?.facts_updated||0} / 边 ${n?.edges_created||0}`)),u.reload({silent:!0}),r?.()}catch(e){M(Y(e,i(`projects.promoteAttackChainFailed`,null,`沉淀失败`)))}}})},m=e=>{H({title:i(`projects.unbind`,null,`解绑`),content:i(`projects.confirmUnbindConversation`,null,`解除该对话与当前项目的绑定?`),okText:i(`projects.unbind`,null,`解绑`),onOk:async()=>{try{await A.put(`/conversations/${e.id}/project`,{projectId:``}),V(i(`projects.projectUnbound`,null,`已解除项目绑定`)),u.reload({silent:!0}),r?.()}catch(e){M(Y(e,i(`projects.unbindFailed`,null,`解绑失败`)))}}})},h=[{title:i(`projects.titleLabel`,null,`标题`),dataIndex:`title`,render:(e,t)=>(0,X.jsx)(`button`,{type:`button`,className:`project-link-button`,onClick:()=>a(`/chat?conversation=${encodeURIComponent(t.id)}`),title:e||t.id,children:e||i(`projects.untitledConversation`,null,`未命名对话`)})},{title:`ID`,dataIndex:`id`,width:240,render:e=>(0,X.jsx)(Me,{type:`tertiary`,size:`small`,children:(0,X.jsx)(`code`,{children:e})})},{title:i(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:170,render:(e,t)=>(0,X.jsx)(Me,{size:`small`,children:D(e||t.updatedAt||t.created_at||t.createdAt)})},{title:i(`common.actions`,null,`操作`),dataIndex:`id`,width:280,render:(e,n)=>(0,X.jsxs)(c,{spacing:2,wrap:!0,children:[(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>a(`/chat?conversation=${encodeURIComponent(n.id)}`),children:i(`projects.open`,null,`打开`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,title:i(`projects.promoteAttackChainTitle`,null,`将对话攻击链沉淀为项目事实与边`),onClick:()=>p(n),children:i(`projects.promoteAttackChain`,null,`沉淀攻击链`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!s,title:i(`projects.unbindProjectTitle`,null,`解除项目绑定`),onClick:()=>m(n),children:i(`projects.unbind`,null,`解绑`)})]})}];return(0,X.jsxs)(I,{title:i(`projects.tabConversations`,null,`关联对话`),description:i(`projects.boundConversationsHint`,null,`绑定到本项目的对话;点击可打开会话`),extra:(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:f.length}),children:[(0,X.jsx)(te,{error:pe(u.error),onRetry:u.reload}),(0,X.jsx)(z,{columns:h,dataSource:f,rowKey:`id`,loading:u.loading,pagination:{pageSize:10},emptyText:i(`projects.noBoundConversations`,null,`暂无绑定对话;在对话页选择本项目即可关联`),onRefresh:()=>u.reload()})]})}var{Text:Q}=s,Pe={targets:[`https://example.com`],exclude:[`*.cdn.example.com`],notes:`仅授权 Web 应用层测试`};function Fe(e){try{let t=e.trim()?JSON.parse(e):{};return t&&typeof t==`object`&&!Array.isArray(t)?t:null}catch{return null}}function Ie({project:e,canWrite:t,canDelete:n,onChanged:r,onDeleted:i}){let o=O(),s=(0,q.useId)(),[l,u]=(0,q.useState)({name:``,description:``,scope_json:``,lessons_mode:`off`,status:`active`,pinned:!1}),[m,h]=(0,q.useState)(!1);(0,q.useEffect)(()=>{e&&u({name:e.name||``,description:e.description||``,scope_json:e.scope_json||``,lessons_mode:e.lessons_mode||`off`,status:e.status||`active`,pinned:!!e.pinned})},[e]);let g=e=>u(t=>({...t,...e})),v=Fe(l.scope_json),y=v?.constraints??[],x=Array.isArray(y)&&y.every(e=>e&&typeof e==`object`&&!Array.isArray(e)),C=e=>u(t=>{let n=Fe(t.scope_json);return n?{...t,scope_json:JSON.stringify({...n,...e},null,2)}:t}),w=(e,t)=>C({constraints:y.map((n,r)=>r===e?{...n,...t}:n)}),T=[{value:`off`,label:o(`projects.noiseOff`,null,`关闭`)},{value:`quiet`,label:o(`projects.noiseQuiet`,null,`低噪音`)},{value:`balanced`,label:o(`projects.noiseBalanced`,null,`均衡`)},{value:`aggressive`,label:o(`projects.noiseAggressive`,null,`维护窗口`)}],D=[{value:`allow`,label:o(`projects.constraintAllow`,null,`允许`)},{value:`deny`,label:o(`projects.constraintDeny`,null,`禁止`)}],k=()=>{let e=l.scope_json.trim();if(e)try{g({scope_json:JSON.stringify(JSON.parse(e),null,2)})}catch(e){M(o(`projects.invalidJson`,null,`JSON 格式无效`)+`:`+Y(e,``))}},ee=()=>g({scope_json:JSON.stringify(Pe,null,2)}),j=async()=>{let t=l.name.trim();if(!t){M(o(`projects.enterProjectName`,null,`请输入项目名称`));return}let n=l.scope_json.trim();if(n)try{JSON.parse(n)}catch{M(o(`projects.invalidScopeJson`,null,`测试范围 JSON 无效,请先修正或点击「格式化」`));return}h(!0);try{await A.put(`/projects/${e.id}`,{name:t,description:l.description,scope_json:n,...l.lessons_mode===(e.lessons_mode||`off`)?{}:{lessons_mode:l.lessons_mode},...l.status===(e.status||`active`)?{}:{status:l.status},pinned:!!l.pinned}),V(o(`projects.saved`,null,`已保存`)),r?.()}catch(e){M(Y(e,o(`projects.saveFailed`,null,`保存失败`)))}finally{h(!1)}},N=(e?.status||`active`)===`archived`;return e?(0,X.jsxs)(I,{title:o(`projects.settingsIntroTitle`,null,`项目设置`),description:o(`projects.settingsIntroHint`,null,`配置项目元数据与 Agent 授权边界,保存后即时生效于绑定对话。`),extra:(0,X.jsx)(d,{type:`primary`,loading:m,disabled:!t,onClick:j,children:o(`projects.saveSettings`,null,`保存更改`)}),children:[(0,X.jsxs)(`div`,{className:`project-form-grid`,children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.projectName`,null,`项目名称`)}),(0,X.jsx)(p,{value:l.name,disabled:!t,onChange:e=>g({name:e})}),(0,X.jsx)(Q,{type:`tertiary`,size:`small`,children:o(`projects.saveChangesHint`,null,`修改后请点击保存以同步到服务器`)})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.status`,null,`状态`)}),(0,X.jsx)(E,{value:l.status,disabled:!t,optionList:ue,onChange:e=>g({status:e}),style:{width:`100%`}}),(0,X.jsxs)(`div`,{className:`project-switch-row`,children:[(0,X.jsx)(_,{checked:l.pinned,disabled:!t,onChange:e=>g({pinned:e})}),(0,X.jsx)(Q,{size:`small`,children:o(`projects.pinProject`,null,`置顶项目(列表优先显示)`)})]})]})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.projectDescription`,null,`项目描述`)}),(0,X.jsx)(f,{value:l.description,rows:3,maxCount:4e3,disabled:!t,placeholder:o(`projects.editDescriptionPlaceholder`,null,`客户/任务备注、协作说明、联系人…`),onChange:e=>g({description:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsxs)(c,{children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.scopeJsonLabel`,null,`范围 JSON`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:k,children:o(`projects.formatJson`,null,`格式化`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,disabled:!t,onClick:ee,children:o(`projects.example`,null,`示例`)})]}),(0,X.jsx)(f,{value:l.scope_json,rows:8,disabled:!t,placeholder:`{ "targets": ["https://example.com"] }`,onChange:e=>g({scope_json:e})}),(0,X.jsx)(Q,{type:`tertiary`,size:`small`,children:o(`projects.scopeStructuredHint`,null,`范围、排除项和操作约束保存在同一份 JSON。新增目标需明确授权。`)}),!v||!x?(0,X.jsx)(Q,{type:`warning`,size:`small`,children:o(`projects.scopeStructuredInvalid`,null,`请在 JSON 中修正范围对象和操作约束列表。`)}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:o(`projects.scopeConstraints`,null,`操作约束`)}),y.map((e,n)=>(0,X.jsxs)(c,{wrap:!0,children:[(0,X.jsx)(Q,{size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-constraint-${n}`,children:o(`projects.constraintKind`,null,`约束类型`)})}),(0,X.jsx)(b,{type:`button`,"aria-labelledby":`${s}-constraint-${n}`,disabled:!t,value:e.kind,onChange:e=>w(n,{kind:e.target.value}),children:D.map(({value:e,label:t})=>(0,X.jsx)(S,{value:e,children:t},e))}),(0,X.jsx)(p,{"aria-label":o(`projects.constraintText`,null,`约束内容`),value:typeof e.text==`string`?e.text:``,disabled:!t,onChange:e=>w(n,{text:e})}),(0,X.jsx)(Q,{size:`small`,children:e.origin===`goals`?o(`projects.constraintGoals`,null,`目标建议,待人工确认`):o(`projects.constraintHuman`,null,`人工`)}),(0,X.jsx)(d,{size:`small`,disabled:!t,onClick:()=>C({constraints:y.filter((e,t)=>t!==n)}),children:o(`common.delete`,null,`删除`)})]},n)),(0,X.jsx)(d,{size:`small`,disabled:!t,onClick:()=>C({constraints:[...y,{kind:`deny`,text:``,origin:`human`}]}),children:o(`projects.addScopeConstraint`,null,`添加约束`)})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)(Q,{strong:!0,size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-noise`,children:o(`projects.noiseProfile`,null,`噪音档位`)})}),(0,X.jsx)(b,{type:`button`,"aria-labelledby":`${s}-noise`,disabled:!t,value:v.noise_profile||`off`,onChange:e=>C({noise_profile:e.target.value}),children:T.map(({value:e,label:t})=>(0,X.jsx)(S,{value:e,children:t},e))})]})]})]}),(0,X.jsxs)(`div`,{className:`project-switch-row`,children:[(0,X.jsx)(_,{"aria-labelledby":`${s}-lessons`,checked:l.lessons_mode===`shadow`||l.lessons_mode===`inject`,disabled:!t,onChange:e=>g({lessons_mode:e?`shadow`:`off`})}),(0,X.jsx)(Q,{size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-lessons`,children:o(`projects.lessonsMode`,null,`处置经验影子审计`)})}),l.lessons_mode===`shadow`||l.lessons_mode===`inject`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_,{"aria-labelledby":`${s}-lessons-inject`,checked:l.lessons_mode===`inject`,disabled:!t,onChange:e=>g({lessons_mode:e?`inject`:`shadow`})}),(0,X.jsx)(Q,{size:`small`,children:(0,X.jsx)(`span`,{id:`${s}-lessons-inject`,children:o(`projects.lessonsInject`,null,`注入活跃经验到上下文`)})})]}):null]}),(0,X.jsx)(a,{margin:`12px`}),(0,X.jsxs)(`div`,{className:`project-danger-zone`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(Q,{strong:!0,children:o(`projects.dangerZoneTitle`,null,`危险操作`)}),(0,X.jsx)(`div`,{children:(0,X.jsx)(Q,{type:`tertiary`,size:`small`,children:o(`projects.dangerZoneHint`,null,`在项目列表选择「已归档」可查看归档项目。删除项目会永久删除项目记忆。`)})})]}),(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{disabled:!t,onClick:()=>{H({title:N?o(`projects.restoreProjectActive`,null,`恢复为进行中`):o(`projects.archiveProject`,null,`归档`),content:N?o(`projects.confirmRestoreProjectActive`,null,`恢复后,项目记忆与随项目归档的漏洞将重新启用。单独归档的漏洞仍保留在归档列表。`):o(`projects.confirmArchiveProject`,null,`项目记忆和关联漏洞将随项目归档,可从已归档项目中查阅。是否继续?`),okText:o(`common.confirm`,null,`确认`),danger:!N,onOk:async()=>{try{await A.put(`/projects/${e.id}`,{status:N?`active`:`archived`}),V(o(`projects.saved`,null,`已保存`)),r?.()}catch(e){M(Y(e,o(`projects.operationFailed`,null,`操作失败`)))}}})},children:N?o(`projects.restoreProjectActive`,null,`恢复为进行中`):o(`projects.archiveProject`,null,`归档`)}),(0,X.jsx)(d,{type:`danger`,disabled:!n,onClick:()=>{H({title:o(`projects.deleteProject`,null,`删除项目`),content:o(`projects.confirmDeleteProject`,null,`确定删除该项目?事实将一并删除,对话将解除绑定。`),okText:o(`common.delete`,null,`删除`),onOk:async()=>{try{await A.del(`/projects/${e.id}`),V(o(`projects.deleteProject`,null,`删除项目`)),i?.(e.id)}catch(e){M(Y(e,o(`projects.deleteFailed`,null,`删除失败`)))}}})},children:o(`projects.deleteProject`,null,`删除项目`)})]})]})]}):(0,X.jsx)(I,{title:o(`projects.tabSettings`,null,`设置`),children:(0,X.jsx)(Q,{type:`tertiary`,children:o(`projects.selectOrCreateTitle`,null,`选择或创建项目`)})})}var{Text:$}=s,Le={fact_key:``,category:`note`,summary:``,body:``,confidence:`tentative`,pinned:!1,related_vulnerability_id:``,confirmation_note:``,links_text:``};function Re({visible:e,projectId:t,factKey:n,onCancel:r,onSaved:i}){let a=O(),[o,s]=(0,q.useState)(Le),[c,l]=(0,q.useState)(oe),[d,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(``),y=!!n;(0,q.useEffect)(()=>{if(!e||(s(Le),l(oe),v(``),m(!1),g(!1),!n))return;let r=!1;return m(!0),A.get(`/projects/${t}/facts`,{fact_key:n,include_links:`true`}).then(e=>{if(r||!e)return;let t=e.category||`note`;oe.some(e=>e.value===t)||l([...oe,{value:t,label:`${t}(自定义)`}]),v(e.id||``),s({fact_key:e.fact_key||n,category:t,summary:e.summary||``,body:e.body||``,confidence:(e.confidence||`tentative`).toLowerCase(),pinned:!!e.pinned,related_vulnerability_id:e.related_vulnerability_id||``,confirmation_note:e.confirmation_note||``,links_text:me(e.incoming_links)})}).catch(e=>{r||M(Y(e,a(`projects.loadFactFailed`,null,`加载事实失败`)))}).finally(()=>{r||m(!1)}),()=>{r=!0}},[e,t,n]);let b=e=>s(t=>({...t,...e})),x=(0,q.useMemo)(()=>fe.join(`、`),[]);return(0,X.jsxs)(N,{visible:e,title:y?a(`projects.editFact`,null,`编辑事实`):a(`projects.addFact`,null,`添加事实`),onCancel:r,onOk:async()=>{let e=o.fact_key.trim(),n=o.summary.trim(),r=o.confirmation_note.trim();if(!e||!n){M(a(`projects.factKeySummaryRequired`,null,`fact_key 与 summary 必填`));return}if((o.confidence||`tentative`)===`confirmed`&&!r){M(a(`projects.confirmationNoteRequired`,null,`升级为已确认需要审核说明`));return}let s={fact_key:e,category:o.category||`note`,summary:n,body:o.body,confidence:o.confidence||`tentative`,pinned:!!o.pinned,related_vulnerability_id:o.related_vulnerability_id.trim(),confirmation_note:r,links_text:o.links_text};if(y&&!_)M(a(`projects.loadFactFailed`,null,`加载事实失败`));else{g(!0);try{y&&_?await A.put(`/projects/${t}/facts/${_}`,s):await A.post(`/projects/${t}/facts`,s),V(a(`projects.saved`,null,`已保存`)),i?.()}catch(e){M(Y(e,a(`projects.saveFailed`,null,`保存失败`)))}finally{g(!1)}}},okText:y?a(`projects.saveChanges`,null,`保存修改`):a(`projects.saveFact`,null,`保存事实`),cancelText:a(`common.cancel`,null,`取消`),confirmLoading:h,width:720,maskClosable:!1,children:[(0,X.jsx)($,{type:`tertiary`,size:`small`,children:a(`projects.factModalSubtitle`,null,`摘要注入黑板索引;body 沉淀攻击链与 POC,供审计复现(与漏洞记录分工)`)}),(0,X.jsxs)(`div`,{className:`project-form-grid`,children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:`fact_key`}),(0,X.jsx)(p,{value:o.fact_key,disabled:d,placeholder:`target/primary_domain`,onChange:e=>b({fact_key:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.category`,null,`分类`)}),(0,X.jsx)(E,{value:o.category,optionList:c,onChange:e=>b({category:e}),style:{width:`100%`}})]})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.summary`,null,`摘要`)}),(0,X.jsx)(p,{value:o.summary,placeholder:a(`projects.summary`,null,`摘要`)+`:什么 + 在哪 + 如何验证`,onChange:e=>b({summary:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-grid`,children:[(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.confidence`,null,`置信度`)}),(0,X.jsx)(E,{value:o.confidence,optionList:ce,onChange:e=>b({confidence:e}),style:{width:`100%`}})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.relatedVulnIdLabel`,null,`关联漏洞 ID`)}),(0,X.jsx)(p,{value:o.related_vulnerability_id,placeholder:a(`projects.optional`,null,`可选`),onChange:e=>b({related_vulnerability_id:e})})]})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.confirmationNote`,null,`审核说明`)}),(0,X.jsx)(f,{value:o.confirmation_note,rows:3,disabled:o.confidence!==`confirmed`,placeholder:a(`projects.confirmationNotePlaceholder`,null,`说明为何把这条事实标为已确认`),onChange:e=>b({confirmation_note:e})})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:`body`}),(0,X.jsx)(f,{value:o.body,rows:10,placeholder:"## 验证步骤\n1. …\n\n```http\nGET /path HTTP/1.1\n```",onChange:e=>b({body:e})}),(0,X.jsx)($,{type:`tertiary`,size:`small`,children:a(`projects.factBodyRelationsHint`,null,`正文中的 discovered_on 等关系请填写到下方“关系边”字段,才能生成图谱连线。`)})]}),(0,X.jsxs)(`div`,{className:`project-form-field`,children:[(0,X.jsx)($,{strong:!0,size:`small`,children:a(`projects.factLinksLabel`,null,`关系边(from → 本事实)`)}),(0,X.jsx)(f,{value:o.links_text,rows:3,placeholder:a(`projects.factLinksPlaceholder`,null,`discovered_on: target/primary_domain`),onChange:e=>b({links_text:e})}),(0,X.jsxs)($,{type:`tertiary`,size:`small`,children:[a(`projects.factLinksHint`,null,`每行一条:type: source_fact_key(来源 → 当前事实)。`),` `,`常用 type:`,x,`。`]})]}),(0,X.jsx)(u,{checked:o.pinned,onChange:e=>b({pinned:e.target.checked}),children:a(`projects.pinFact`,null,`置顶事实(列表与黑板索引优先)`)})]})}var{Text:ze,Paragraph:Be}=s;function Ve({value:e}){let t=le[String(e||``).toLowerCase()]||{label:e||`—`,color:`grey`};return(0,X.jsx)(l,{size:`small`,color:t.color,children:t.label})}function He({projectId:e,factKey:t,visible:n,canWrite:r,revision:i=0,onClose:a,onEdit:s}){let u=O(),f=j(()=>t?A.get(`/projects/${e}/facts`,{fact_key:t,include_links:`true`}):Promise.resolve(null),[e,t,i]),p=f.data;return(0,X.jsxs)(C,{visible:n,width:640,title:u(`projects.factDetails`,null,`事实详情`),onCancel:a,footer:(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{disabled:!r||!p,onClick:()=>s?.(t),children:u(`common.edit`,null,`编辑`)}),(0,X.jsx)(d,{onClick:a,children:u(`common.close`,null,`关闭`)})]}),children:[(0,X.jsx)(te,{error:pe(f.error),onRetry:f.reload}),p?(0,X.jsxs)(`div`,{className:`project-detail-stack`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:p.fact_key}),(0,X.jsxs)(`div`,{className:`project-graph-side-tags`,children:[(0,X.jsx)(l,{size:`small`,color:`cyan`,type:`light`,children:se[String(p.category||``).toLowerCase()]||p.category||`—`}),(0,X.jsx)(Ve,{value:p.confidence}),p.pinned?(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:u(`projects.pinned`,null,`置顶`)}):null]})]}),(0,X.jsx)(P,{items:[{label:u(`projects.updated`,null,`更新`),value:D(p.updated_at)},{label:u(`projects.confidence`,null,`置信度`),value:(0,X.jsx)(Ve,{value:p.confidence})},p.related_vulnerability_id?{label:u(`projects.relatedVulnIdTitle`,null,`关联漏洞 ID`),value:p.related_vulnerability_id}:null,p.confirmation_note?{label:u(`projects.confirmationNote`,null,`审核说明`),value:p.confirmation_note}:null,p.source_conversation_id?{label:u(`projects.factMetaSourceConversation`,{value:``},`来源对话`),value:p.source_conversation_id}:null]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:u(`projects.summary`,null,`摘要`)}),(0,X.jsx)(Be,{className:`project-fact-summary`,children:p.summary||`—`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:`body`}),p.body?(0,X.jsx)(F,{content:p.body}):(0,X.jsx)(ze,{type:`tertiary`,children:u(`projects.emptyBody`,null,`(无 body)`)})]}),(p.incoming_links||[]).length>0&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:u(`projects.factIncomingLinksLabel`,null,`入边(只读)`)}),(0,X.jsx)(`ul`,{className:`project-link-list`,children:p.incoming_links.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`code`,{children:e.edge_type}),` ← `,(0,X.jsx)(`code`,{children:e.source_fact_key})]},e.id))})]}),(p.outgoing_links||[]).length>0&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(ze,{strong:!0,children:u(`projects.graphEdgeFromSelf`,null,`本节点指出`)}),(0,X.jsx)(`ul`,{className:`project-link-list`,children:p.outgoing_links.map(e=>(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`code`,{children:e.edge_type}),` → `,(0,X.jsx)(`code`,{children:e.target_fact_key})]},e.id))})]})]}):!f.loading&&!f.error?(0,X.jsx)(o,{title:u(`projects.noFacts`,null,`暂无事实`)}):null]})}var{Title:Ue,Text:We,Paragraph:Ge}=s;function Ke({projectId:e,tab:t,refreshToken:r=0,onTabChange:i,onChanged:a,onDeleted:o}){let s=O(),u=n(),{hasPermission:f}=k(),p=f(`project:write`),m=f(`project:delete`),[h,_]=(0,q.useState)(0),[v,y]=(0,q.useState)({visible:!1,factKey:``}),[b,x]=(0,q.useState)(!1),[S,C]=(0,q.useState)(``),T=j(()=>A.get(`/projects/${e}`),[e,h,r]),E=j(()=>A.get(`/projects/${e}/stats`),[e,h,r]),M=(0,q.useCallback)(()=>{_(e=>e+1),a?.()},[a]),N=(0,q.useCallback)(e=>y({visible:!0,factKey:e||``}),[]),P=(0,q.useCallback)(e=>C(e||``),[]),F=(0,q.useMemo)(()=>[{itemKey:`facts`,tab:s(`projects.tabFacts`,null,`事实黑板`)},{itemKey:`graph`,tab:s(`projects.tabGraph`,null,`攻击路径`)},{itemKey:`conversations`,tab:s(`projects.tabConversations`,null,`关联对话`)},{itemKey:`settings`,tab:s(`projects.tabSettings`,null,`设置`)}],[s]),L=[{id:`facts`,label:s(`projects.facts`,null,`事实`),value:E.data?.fact_count??`—`,loading:E.loading},{id:`vulns`,label:s(`projects.vulnerabilityManagement`,null,`漏洞`),value:E.data?.vuln_count??`—`,loading:E.loading},{id:`conversations`,label:s(`projects.tabConversations`,null,`关联对话`),value:E.data?.conversation_count??`—`,loading:E.loading},{id:`sparse`,label:s(`projects.factBodySparse`,null,`待补全`),value:E.data?.sparse_fact_count??`—`,tone:(E.data?.sparse_fact_count||0)>0?`warning`:void 0,loading:E.loading}],R=T.data,z=R?.status===`archived`;return(0,X.jsxs)(`div`,{className:`project-detail`,children:[(0,X.jsxs)(`div`,{className:`project-detail-summary`,children:[(0,X.jsx)(te,{error:pe(T.error),onRetry:T.reload}),(0,X.jsxs)(I,{className:`project-detail-head`,children:[(0,X.jsxs)(`div`,{className:`project-detail-head-main`,children:[(0,X.jsxs)(`div`,{className:`project-detail-title-row`,children:[(0,X.jsx)(Ue,{heading:4,className:`project-detail-title`,children:R?.name||s(`projects.projectNotFound`,null,`项目不存在`)}),R?.pinned?(0,X.jsx)(l,{size:`small`,color:`blue`,children:s(`projects.pinned`,null,`置顶`)}):null,(0,X.jsx)(l,{size:`small`,color:z?`grey`:`green`,children:z?s(`projects.statusArchived`,null,`已归档`):s(`projects.statusActive`,null,`进行中`)})]}),R?.description?(0,X.jsx)(Ge,{className:`project-detail-desc`,children:R.description}):(0,X.jsx)(We,{type:`tertiary`,size:`small`,children:s(`projects.noProjectDescription`,null,`暂无项目描述`)}),(0,X.jsxs)(We,{type:`tertiary`,size:`small`,children:[s(`projects.updatedPrefix`,{time:D(R?.updated_at)},`更新于 ${D(R?.updated_at)}`),` · `,`ID: `,(0,X.jsx)(`code`,{children:e})]})]}),(0,X.jsxs)(c,{wrap:!0,children:[R&&f(`vulnerability:read`)&&(0,X.jsx)(d,{onClick:()=>u(`/vulnerabilities?project_id=${encodeURIComponent(e)}&archived=${z?`true`:`all`}`),children:s(`projects.projectVulnerabilities`,null,`项目漏洞`)}),R&&f(`asset:write`)&&(0,X.jsx)(d,{onClick:()=>x(!0),children:s(`assets.addAsset`,null,`新增资产`)}),R&&f(`asset:read`)&&(0,X.jsx)(d,{onClick:()=>u(`/asset-library?project_id=${encodeURIComponent(e)}`),children:s(`assets.projectAssets`,null,`项目资产`)}),(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),theme:`borderless`,loading:T.loading||E.loading,onClick:()=>{T.reload(),E.reload()}}),(0,X.jsx)(d,{type:`primary`,disabled:!p,onClick:()=>N(``),children:s(`projects.addFactCta`,null,`+ 添加事实`)})]})]}),(0,X.jsx)(ee,{metrics:L,columns:4}),(0,X.jsx)(g,{type:`line`,tabList:F,activeKey:t||`facts`,onChange:e=>i?.(e),className:`project-tabs`})]}),(!t||t===`facts`)&&(0,X.jsx)(_e,{projectId:e,canWrite:p,revision:h,onAddFact:()=>N(``),onEditFact:N,onViewFact:P,onMutated:M}),t===`graph`&&(0,X.jsx)(je,{projectId:e,canWrite:p,revision:h,onOpenFact:P,onEditFact:N,onAddFact:()=>N(``),onChanged:M}),t===`conversations`&&(0,X.jsx)(Ne,{projectId:e,canWrite:p,onChanged:M}),t===`settings`&&(0,X.jsx)(Ie,{project:R,canWrite:p,canDelete:m,onChanged:M,onDeleted:e=>o?.(e)}),b&&R&&f(`asset:write`)&&(0,X.jsx)(ae,{visible:!0,defaultProjectId:e,fixedProject:!0,projects:[R],onClose:()=>x(!1)}),(0,X.jsx)(Re,{visible:v.visible,projectId:e,factKey:v.factKey,onCancel:()=>y({visible:!1,factKey:``}),onSaved:()=>{y({visible:!1,factKey:``}),M()}}),(0,X.jsx)(He,{projectId:e,factKey:S,visible:!!S,canWrite:p,revision:h,onClose:()=>C(``),onEdit:e=>{C(``),N(e)}})]})}var{Text:qe}=s,Je=10;async function Ye(){let[e,t]=await Promise.all([A.get(`/projects`,{limit:500}),A.get(`/projects/dashboard-summary`,{fact_limit:6}).catch(()=>null)]);return{projects:Array.isArray(e?.projects)?e.projects:[],total:e?.total??0,summary:t}}function Xe(){let e=O(),{hasPermission:t}=k(),n=t(`project:write`),r=t(`project:delete`),[a,s]=i(),u=a.get(`id`)||``,f=a.get(`tab`)||`facts`,[m,h]=(0,q.useState)(``),g=L(m,250),[_,y]=(0,q.useState)(`active`),[b,S]=(0,q.useState)(1),[C,N]=(0,q.useState)({visible:!1,project:null}),[P,F]=(0,q.useState)(0),B=j(Ye,[]),W=B.data?.projects||[],ne=B.data?.summary,G=(0,q.useCallback)((e,t)=>{let n=new URLSearchParams(a);e?n.set(`id`,e):n.delete(`id`),t?n.set(`tab`,t):n.delete(`tab`),s(n,{replace:!!e})},[a,s]),K=(0,q.useMemo)(()=>{let e=g.trim().toLowerCase();return W.filter(t=>{let n=t.status||`active`;return _!==`all`&&n!==_?!1:!e||[t.name,t.description,t.id].join(` `).toLowerCase().includes(e)})},[W,g,_]),re=Math.min(b,Math.max(1,Math.ceil(K.length/Je))),ie=K.slice((re-1)*Je,re*Je);(0,q.useEffect)(()=>{!u&&K.length&&G(K[0].id,f)},[u,K,f,G]);let ae=(0,q.useMemo)(()=>W.filter(e=>(e.status||`active`)===`archived`).length,[W]),oe=[{id:`active`,label:e(`projects.statusActive`,null,`进行中`),value:ne?.totals?.active_projects??W.filter(e=>(e.status||`active`)===`active`).length,loading:B.loading},{id:`facts`,label:e(`projects.facts`,null,`事实`),value:ne?.totals?.total_facts??`—`,detail:e(`projects.sharedFactBoard`,null,`共享事实黑板`),loading:B.loading},{id:`total`,label:e(`projects.projectList`,null,`项目列表`),value:B.data?.total??W.length,loading:B.loading},{id:`archived`,label:e(`projects.statusArchived`,null,`已归档`),value:ae,loading:B.loading}],se=t=>{H({title:e(`projects.deleteProject`,null,`删除项目`),content:e(`projects.confirmDeleteProject`,null,`确定删除该项目?事实将一并删除,对话将解除绑定。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await A.del(`/projects/${t.id}`),V(e(`projects.deleteProject`,null,`删除项目`)),u===t.id&&G(``),B.reload({silent:!0}),F(e=>e+1)}catch(t){M(Y(t,e(`projects.deleteFailed`,null,`删除失败`)))}}})},ce=t=>{let n=(t.status||`active`)===`archived`;H({title:n?e(`projects.restoreProjectActive`,null,`恢复为进行中`):e(`projects.archiveProject`,null,`归档`),content:n?e(`projects.confirmRestoreProjectActive`,null,`恢复后,项目记忆与随项目归档的漏洞将重新启用。单独归档的漏洞仍保留在归档列表。`):e(`projects.confirmArchiveProject`,null,`项目记忆和关联漏洞将随项目归档,可从已归档项目中查阅。是否继续?`),okText:e(`common.confirm`,null,`确认`),danger:!n,onOk:async()=>{try{await A.put(`/projects/${t.id}`,{status:n?`active`:`archived`}),V(e(`projects.saved`,null,`已保存`)),B.reload({silent:!0}),F(e=>e+1)}catch(t){M(Y(t,e(`projects.operationFailed`,null,`操作失败`)))}}})},le=[{title:e(`projects.projectName`,null,`项目名称`),dataIndex:`name`,render:(t,n)=>(0,X.jsxs)(`div`,{className:`project-list-name`,children:[(0,X.jsxs)(`div`,{className:`project-list-name-row`,children:[(0,X.jsx)(`span`,{className:`project-list-name-text${n.id===u?` is-active`:``}`,children:t||n.id}),n.pinned?(0,X.jsx)(l,{size:`small`,color:`blue`,type:`light`,children:e(`projects.pinned`,null,`置顶`)}):null]}),n.description?(0,X.jsx)(qe,{type:`tertiary`,size:`small`,className:`project-list-desc`,children:n.description}):null]})},{title:e(`projects.status`,null,`状态`),dataIndex:`status`,width:92,render:t=>{let n=(t||`active`)===`archived`;return(0,X.jsx)(l,{size:`small`,color:n?`grey`:`green`,children:n?e(`projects.statusArchived`,null,`已归档`):e(`projects.statusActive`,null,`进行中`)})}},{title:e(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:150,render:e=>(0,X.jsx)(qe,{type:`tertiary`,size:`small`,children:D(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:176,render:(t,i)=>(0,X.jsxs)(c,{spacing:2,onClick:e=>e.stopPropagation(),children:[(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>N({visible:!0,project:i}),disabled:!n,children:e(`common.edit`,null,`编辑`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>ce(i),disabled:!n,children:(i.status||`active`)===`archived`?e(`projects.restore`,null,`恢复`):e(`projects.archiveProject`,null,`归档`)}),(0,X.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,onClick:()=>se(i),disabled:!r,children:e(`common.delete`,null,`删除`)})]})}];return(0,X.jsxs)(`div`,{className:`project-page`,children:[(0,X.jsx)(R,{title:e(`projects.title`,null,`项目管理`),description:e(`projects.selectOrCreateHint`,null,`项目用于跨对话共享「事实黑板」:目标、环境、认证等信息会在绑定项目的对话中自动注入。`),extra:(0,X.jsxs)(c,{children:[(0,X.jsx)(d,{icon:(0,X.jsx)(w,{}),theme:`borderless`,loading:B.loading,onClick:()=>B.reload(),children:e(`common.refresh`,null,`刷新`)}),(0,X.jsx)(d,{type:`primary`,icon:(0,X.jsx)(v,{}),disabled:!n,onClick:()=>N({visible:!0,project:null}),children:e(`projects.newProjectCta`,null,`+ 新建项目`)})]})}),(0,X.jsx)(te,{error:pe(B.error),onRetry:B.reload}),(0,X.jsx)(ee,{metrics:oe,columns:4}),(0,X.jsxs)(`div`,{className:`project-layout${u&&f===`graph`?` project-layout--graph`:``}`,children:[(0,X.jsxs)(I,{title:e(`projects.projectList`,null,`项目列表`),className:`project-list-card`,bodyClassName:`project-list-body`,extra:(0,X.jsxs)(qe,{type:`tertiary`,size:`small`,children:[K.length,` / `,W.length]}),children:[(0,X.jsxs)(`div`,{className:`project-toolbar project-toolbar--stack`,children:[(0,X.jsx)(p,{prefix:(0,X.jsx)(x,{}),value:m,showClear:!0,placeholder:e(`projects.searchProjectsPlaceholder`,null,`搜索项目…`),onChange:e=>{h(e),S(1)},style:{width:`100%`}}),(0,X.jsx)(E,{value:_,onChange:e=>{y(e),S(1)},style:{width:`100%`},optionList:[{value:`all`,label:e(`projects.all`,null,`全部`)},{value:`active`,label:e(`projects.statusActive`,null,`进行中`)},{value:`archived`,label:e(`projects.statusArchived`,null,`已归档`)}]})]}),(0,X.jsx)(z,{columns:le,dataSource:ie,rowKey:`id`,loading:B.loading,pagination:!1,emptyText:m||W.length>0?e(`projects.noMatchingProjects`,null,`无匹配项目`):e(`projects.noProjects`,null,`暂无项目`),onRow:e=>({onClick:()=>G(e.id,f),style:{cursor:`pointer`}})}),K.length>0&&(0,X.jsx)(`div`,{className:`project-list-pagination`,children:(0,X.jsx)(T,{size:`small`,currentPage:re,pageSize:Je,total:K.length,onPageChange:S})})]}),(0,X.jsx)(`div`,{className:`project-detail-col`,children:u?(0,X.jsx)(Ke,{projectId:u,tab:f,refreshToken:P,onTabChange:e=>G(u,e),onChanged:()=>B.reload({silent:!0}),onDeleted:()=>{G(``),B.reload({silent:!0})}},u):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(I,{title:e(`projects.selectOrCreateTitle`,null,`选择或创建项目`),extra:n?null:(0,X.jsx)(qe,{type:`tertiary`,size:`small`,children:e(`projects.writePermissionDenied`,null,`当前账号仅有只读权限,无法创建或修改项目`)}),children:(0,X.jsx)(`div`,{className:`project-empty-state`,children:(0,X.jsx)(o,{title:e(`projects.noProjectsClickCreate`,null,`暂无项目,点击下方「新建项目」`),description:e(`projects.selectOrCreateHint`,null,`项目用于跨对话共享「事实黑板」:目标、环境、认证等信息会在绑定项目的对话中自动注入。`),style:{padding:24},children:(0,X.jsx)(d,{type:`primary`,disabled:!n,onClick:()=>N({visible:!0,project:null}),children:e(`projects.createFirstProject`,null,`创建第一个项目`)})})})}),(0,X.jsx)(I,{title:e(`projects.sharedFactBoard`,null,`共享事实黑板`),description:e(`projects.factToolbarHint`,null,`索引仅含 key 与摘要;攻击链 / POC 写在 body,Agent 通过 get_project_fact 复现`),children:(ne?.recent_facts||[]).length?(0,X.jsx)(`ul`,{className:`project-recent-facts`,children:ne.recent_facts.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,className:`project-recent-fact`,onClick:()=>G(e.project_id,`facts`),children:[(0,X.jsxs)(`span`,{className:`project-recent-fact-key`,children:[(0,X.jsx)(`code`,{children:e.fact_key}),(0,X.jsx)(l,{size:`small`,color:`cyan`,type:`light`,children:e.project_name||e.project_id})]}),(0,X.jsx)(`span`,{className:`project-recent-fact-summary`,title:e.summary,children:e.summary}),(0,X.jsx)(`span`,{className:`project-recent-fact-time`,children:D(e.updated_at)})]})},e.id))}):(0,X.jsx)(qe,{type:`tertiary`,children:e(`projects.noFacts`,null,`暂无事实`)})})]})})]}),(0,X.jsx)(U,{visible:C.visible,project:C.project,onCancel:()=>N({visible:!1,project:null}),onSaved:e=>{let t=!!C.project;N({visible:!1,project:null}),B.reload({silent:!0}),F(e=>e+1),e?.id&&!t&&G(e.id,`facts`)}})]})}export{Xe as default}; \ No newline at end of file diff --git a/web/static/app/assets/roles-management-DGTD0STX.js b/web/static/app/assets/roles-management-DZI3VXhR.js similarity index 99% rename from web/static/app/assets/roles-management-DGTD0STX.js rename to web/static/app/assets/roles-management-DZI3VXhR.js index b66e3994..054ce49a 100644 --- a/web/static/app/assets/roles-management-DGTD0STX.js +++ b/web/static/app/assets/roles-management-DZI3VXhR.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,E as i,G as a,I as o,Lt as s,N as c,P as l,Pt as u,R as d,S as f,U as p,W as m,d as h,ft as g,h as ee,lt as te,m as _,ut as v,v as ne,y as re}from"./semi-65W_4I1v.js";import{F as y,I as ie,L as b,a as x,b as ae,c as oe,l as S,m as C,n as se,p as w,s as T,x as ce,y as E}from"./index-CAEPLS-g.js";var D=e(t(),1),O=e(n(),1),{Text:k}=a,A=`默认`;function j(e){if(!e||typeof e!=`string`)return``;let t=e.trim(),n=t.match(/^"?\\U([0-9A-F]{8})"?$/i);if(n)try{return String.fromCodePoint(parseInt(n[1],16))}catch{return t}return t}function M(e){return e?.is_external&&e?.external_mcp?`${e.external_mcp}::${e.name}`:e?.name||``}function N(e){if(!Array.isArray(e))return[];let t=new Set,n=[];for(let r of e){let e=String(r||``).trim();e&&!t.has(e)&&(t.add(e),n.push(e))}return n}var P=20;function F({visible:e,role:t,onCancel:n,onSaved:a}){let{hasPermission:s}=ie(),u=s(`mcp:read`)||s(`config:read`),g=s(`workflow:read`),v=!!t,y=t?.name===A,[x,S]=(0,D.useState)(``),[C,w]=(0,D.useState)(``),[T,E]=(0,D.useState)(``),[F,I]=(0,D.useState)(``),[L,R]=(0,D.useState)(``),[z,B]=(0,D.useState)(`auto`),[le,ue]=(0,D.useState)(!0),[V,H]=(0,D.useState)([]),[de,fe]=(0,D.useState)(``),[U,W]=(0,D.useState)(``),[pe,G]=(0,D.useState)(!1),[me,he]=(0,D.useState)([]),[ge,_e]=(0,D.useState)(!1),[K,ve]=(0,D.useState)(``),q=se(K,250),[J,ye]=(0,D.useState)(`all`),[Y,X]=(0,D.useState)(1),[Z,be]=(0,D.useState)([]),[Q,xe]=(0,D.useState)(0),[Se,Ce]=(0,D.useState)(!1),[we,Te]=(0,D.useState)(null);(0,D.useEffect)(()=>{if(!e)return;S(t?.name||``),w(j(t?.icon)),E(t?.description||``),I(t?.user_prompt||``),R(t?.workflow_id||``),B(t?.workflow_policy||`auto`),ue(!t||t.enabled!==!1);let n=N(t?.tools);H(n),fe(n.join(`, `)),W(``),ve(``),ye(`all`),X(1)},[e,t]),(0,D.useEffect)(()=>{if(!e||!g)return;let t=!1;return _e(!0),b.get(`/workflows`,{includeDisabled:`true`}).then(e=>{t||he(Array.isArray(e?.workflows)?e.workflows:[])}).catch(()=>{t||he([])}).finally(()=>{t||_e(!1)}),()=>{t=!0}},[e,g]),(0,D.useEffect)(()=>{X(1)},[q]),(0,D.useEffect)(()=>{if(!e||y||!u||J!==`all`)return;let t=!1;return Ce(!0),Te(null),b.get(`/config/tools`,{page:Y,page_size:P,search:q.trim()||void 0}).then(e=>{t||(be(Array.isArray(e?.tools)?e.tools:[]),xe(Number(e?.total)||0))}).catch(e=>{t||(Te(e),be([]),xe(0))}).finally(()=>{t||Ce(!1)}),()=>{t=!0}},[e,y,u,J,Y,q]);let Ee=(0,D.useMemo)(()=>new Set(V),[V]),De=(0,D.useMemo)(()=>{let e=K.trim().toLowerCase();return e?V.filter(t=>t.toLowerCase().includes(e)):V},[V,K]),Oe=(0,D.useMemo)(()=>{let e=me.map(e=>({value:e.id,label:e.name?`${e.name} (${e.id})`:e.id}));return L&&!e.some(e=>e.value===L)&&e.unshift({value:L,label:L}),e},[me,L]),$=e=>{e&&H(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},ke=()=>{let e=Z.map(M).filter(Boolean);H(t=>N([...t,...e]))},Ae=()=>{let e=new Set(Z.map(M).filter(Boolean));H(t=>t.filter(t=>!e.has(t)))},je=async()=>{let e=x.trim();if(!e)W(`请输入角色名称`);else{W(``),G(!0);try{let n=y?[]:u?V:N(de.split(`,`)),r=String(L||``).trim(),i={name:y?A:e,description:T.trim(),user_prompt:F,icon:C.trim(),tools:n,enabled:!!le};r&&(i.workflow_id=r,i.workflow_policy=z||`auto`,t?.workflow_id===r&&t?.workflow_version&&(i.workflow_version=t.workflow_version)),v?await b.put(`/roles/${encodeURIComponent(t.name)}`,i):await b.post(`/roles`,i),ce(`角色已保存`),a?.()}catch(e){ae(e,`保存角色失败`)}finally{G(!1)}}},Me=j(C)||(y?`🔵`:`👤`);return(0,O.jsx)(oe,{title:v?`编辑角色:${t.name}`:`新建角色`,visible:e,onCancel:n,onOk:je,okText:`保存`,confirmLoading:pe,width:760,children:(0,O.jsxs)(`div`,{className:`cs-role-editor-form`,children:[(0,O.jsxs)(`div`,{className:`cs-role-editor-grid`,children:[(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-name-input`,children:(0,O.jsx)(`span`,{className:`cs-role-field-required`,children:`角色名称`})}),(0,O.jsx)(p,{id:`cs-role-name-input`,value:x,onChange:e=>{S(e),U&&W(``)},disabled:y,placeholder:`例如:Web应用扫描`,validateStatus:U?`error`:`default`}),U&&(0,O.jsx)(k,{type:`danger`,size:`small`,children:U}),y&&(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`默认角色名称不可修改。`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-icon-input`,children:`角色图标`}),(0,O.jsxs)(`div`,{className:`cs-role-icon-input-row`,children:[(0,O.jsx)(`span`,{className:`cs-role-icon-badge`,"aria-hidden":`true`,children:Me}),(0,O.jsx)(p,{id:`cs-role-icon-input`,value:C,onChange:w,placeholder:`Emoji,如 🔍`})]})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-desc-input`,children:`角色描述`}),(0,O.jsx)(p,{id:`cs-role-desc-input`,value:T,onChange:E,placeholder:`简要说明该角色的职责与适用场景`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-prompt-input`,children:`用户提示词`}),(0,O.jsx)(f,{id:`cs-role-prompt-input`,value:F,onChange:I,autosize:{minRows:5,maxRows:14},placeholder:`追加到用户消息前的角色提示词(留空则不额外追加)`})]}),(0,O.jsxs)(`div`,{className:`cs-role-editor-workflow-grid`,children:[(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`绑定工作流`}),g?(0,O.jsx)(re,{value:L||void 0,onChange:e=>{let t=e||``;R(t),t&&!z&&B(`auto`)},optionList:Oe,loading:ge,filter:!0,showClear:!0,placeholder:`不绑定工作流`,style:{width:`100%`}}):(0,O.jsx)(p,{value:L,onChange:R,placeholder:`不绑定工作流(缺少 workflow:read 权限,可手动输入 ID 或留空)`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`工作流策略`}),(0,O.jsx)(re,{value:z||`auto`,onChange:e=>B(e||`auto`),disabled:!L,optionList:[{value:`auto`,label:`自动触发(默认)`},{value:`off`,label:`关闭自动触发`}],style:{width:`100%`}})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`关联工具`}),y?(0,O.jsx)(r,{type:`info`,fullMode:!1,closeIcon:null,title:`默认角色使用所有工具`,description:`默认角色会自动使用 MCP 管理中启用的所有工具,无需单独配置。`}):u?(0,O.jsxs)(`div`,{className:`cs-role-tools-panel`,children:[(0,O.jsxs)(`div`,{className:`cs-role-tools-header`,children:[(0,O.jsx)(o,{wrap:!0,children:V.length>0?(0,O.jsxs)(c,{color:`blue`,children:[`已勾选 `,V.length,` 个工具`]}):(0,O.jsx)(c,{color:`grey`,children:`未限制(默认使用全部已启用工具)`})}),V.length>0&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,onClick:()=>H([]),children:`清空(使用全部)`})]}),V.length>0&&(0,O.jsx)(`div`,{className:`cs-role-tools-selected`,"aria-label":`已勾选工具列表`,children:V.map(e=>(0,O.jsx)(c,{size:`small`,closable:!0,onClose:()=>$(e),children:e},e))}),(0,O.jsxs)(`div`,{className:`cs-role-tools-toolbar`,children:[(0,O.jsx)(p,{prefix:(0,O.jsx)(te,{}),value:K,onChange:ve,placeholder:`搜索工具名称或描述`,showClear:!0,style:{width:240}}),(0,O.jsxs)(o,{wrap:!0,children:[(0,O.jsxs)(ee,{type:`button`,buttonSize:`small`,value:J,onChange:e=>ye(e.target.value),children:[(0,O.jsx)(_,{value:`all`,children:`全部工具`}),(0,O.jsxs)(_,{value:`selected`,children:[`仅已勾选 (`,V.length,`)`]})]}),J===`all`&&Z.length>0&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(d,{size:`small`,onClick:ke,children:`全选本页`}),(0,O.jsx)(d,{size:`small`,onClick:Ae,children:`取消本页`})]})]})]}),J===`all`?(0,O.jsxs)(O.Fragment,{children:[we&&(0,O.jsx)(r,{type:`warning`,fullMode:!1,closeIcon:null,description:`加载工具列表失败,请稍后重试。`}),(0,O.jsx)(m,{spinning:Se,children:(0,O.jsx)(`div`,{className:`cs-role-tools-list`,children:Z.length===0&&!Se?(0,O.jsx)(i,{description:`没有匹配的工具`,style:{padding:24}}):Z.map(e=>{let t=M(e),n=Ee.has(t);return(0,O.jsxs)(`div`,{className:`cs-role-tool-item`,onClick:()=>$(t),children:[(0,O.jsx)(l,{checked:n,onChange:()=>{},onClick:e=>{e.stopPropagation(),$(t)},"aria-label":t}),(0,O.jsxs)(`div`,{className:`cs-role-tool-meta`,children:[(0,O.jsxs)(`div`,{className:`cs-role-tool-head`,children:[(0,O.jsx)(k,{strong:!0,size:`small`,children:e.name}),e.is_external&&e.external_mcp&&(0,O.jsx)(c,{size:`small`,color:`cyan`,children:e.external_mcp}),e.enabled===!1&&(0,O.jsx)(c,{size:`small`,color:`orange`,children:`MCP 未启用`})]}),e.description&&(0,O.jsx)(`span`,{className:`cs-role-tool-desc`,title:e.description,children:e.description})]})]},t)})})}),Q>P&&(0,O.jsxs)(`div`,{className:`cs-role-tools-footer`,children:[(0,O.jsxs)(k,{type:`tertiary`,size:`small`,children:[`共 `,Q,` 个工具`]}),(0,O.jsx)(ne,{size:`small`,total:Q,pageSize:P,currentPage:Y,onPageChange:X})]})]}):(0,O.jsx)(`div`,{className:`cs-role-tools-list`,children:De.length===0?(0,O.jsx)(i,{description:`暂无已勾选工具`,style:{padding:24}}):De.map(e=>(0,O.jsxs)(`div`,{className:`cs-role-tool-item`,onClick:()=>$(e),children:[(0,O.jsx)(l,{checked:!0,onChange:()=>{},onClick:t=>{t.stopPropagation(),$(e)},"aria-label":e}),(0,O.jsx)(`div`,{className:`cs-role-tool-meta`,children:(0,O.jsx)(k,{strong:!0,size:`small`,children:e})})]},e))}),(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`留空工具列表表示不限制(使用 MCP 管理中全部已启用工具);MCP 全局开关请在 MCP 管理中调整。`})]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(p,{value:de,onChange:fe,placeholder:`toolName, mcpName::toolName(留空表示不限制)`}),(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`当前账号缺少工具列表读取权限,可直接按逗号分隔填写工具 key。`})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-switch-row`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(k,{strong:!0,children:`启用此角色`}),(0,O.jsx)(`div`,{className:`cs-role-field-hint`,children:`停用后该角色不会出现在对话角色选择器中。`})]}),(0,O.jsx)(h,{checked:le,onChange:ue,"aria-label":`启用此角色`})]})]})})}var{Text:I}=a;function L(e){return[...e].sort((e,t)=>e?.name===`默认`&&t?.name!==`默认`?-1:t?.name===`默认`&&e?.name!==`默认`?1:String(e?.name||``).localeCompare(String(t?.name||``),`zh-CN`))}function R(){let e=y(),{hasPermission:t}=ie(),n=t(`roles:write`),r=t(`roles:delete`),[i,a]=(0,D.useState)(``),[l,f]=(0,D.useState)(null),m=x(()=>b.get(`/roles`),[]),h=(0,D.useMemo)(()=>{let e=Array.isArray(m.data?.roles)?L(m.data.roles):[];if(!i.trim())return e;let t=i.trim().toLowerCase();return e.filter(e=>[e.name,e.description,e.workflow_id].some(e=>String(e||``).toLowerCase().includes(t)))},[m.data,i]),ee=e=>E({title:`删除角色「${e.name}」?`,content:`已绑定该角色的对话将失去对应提示词与工具配置。`,onOk:async()=>{try{await b.del(`/roles/${encodeURIComponent(e.name)}`),ce(`已删除`),m.reload()}catch(e){ae(e,`删除角色失败`)}}}),_=[{title:`角色`,dataIndex:`name`,render:(e,t)=>{let n=e===A,r=j(t.icon)||(n?`🔵`:`👤`);return(0,O.jsxs)(`div`,{className:`cs-role-name-cell`,children:[(0,O.jsx)(`span`,{className:`cs-role-icon-badge`,"aria-hidden":`true`,children:r}),(0,O.jsxs)(o,{vertical:!0,spacing:0,align:`start`,children:[(0,O.jsxs)(o,{spacing:6,children:[(0,O.jsx)(I,{strong:!0,children:e}),n&&(0,O.jsx)(c,{size:`small`,color:`blue`,children:`默认`}),t.enabled===!1&&(0,O.jsx)(c,{size:`small`,color:`grey`,children:`已停用`})]}),(0,O.jsx)(I,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:460},children:t.description||`—`})]})]})}},{title:`工具`,dataIndex:`tools`,width:260,render:(e,t)=>t.name===`默认`?(0,O.jsx)(I,{type:`tertiary`,children:`全部工具`}):Array.isArray(e)&&e.length?(0,O.jsxs)(o,{wrap:!0,spacing:4,children:[e.slice(0,4).map(e=>(0,O.jsx)(c,{size:`small`,children:e},e)),e.length>4&&(0,O.jsxs)(I,{type:`tertiary`,children:[`+`,e.length-4]})]}):(0,O.jsx)(I,{type:`tertiary`,children:`全部工具`})},{title:`工作流`,dataIndex:`workflow_id`,width:180,render:(e,t)=>e?(0,O.jsxs)(o,{spacing:4,wrap:!0,children:[(0,O.jsx)(I,{children:e}),t.workflow_policy===`off`&&(0,O.jsx)(c,{size:`small`,color:`grey`,children:`关闭自动`})]}):`—`}];return(n||r)&&_.push({title:`操作`,width:150,render:(e,t)=>(0,O.jsxs)(o,{children:[n&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,icon:(0,O.jsx)(u,{}),onClick:()=>f({role:t}),children:`编辑`}),r&&t.name!==`默认`&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,O.jsx)(s,{}),"aria-label":`删除 ${t.name}`,onClick:()=>ee(t)})]})}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(w,{title:e(`roles.title`,null,`角色管理`),description:`角色定义对话的系统提示词、可用工具与绑定工作流。`,extra:(0,O.jsxs)(o,{children:[(0,O.jsx)(d,{icon:(0,O.jsx)(v,{}),onClick:()=>m.reload(),loading:m.loading,children:`刷新`}),n&&(0,O.jsx)(d,{theme:`solid`,type:`primary`,icon:(0,O.jsx)(g,{}),onClick:()=>f({role:null}),children:`新建角色`})]})}),(0,O.jsxs)(C,{title:`角色(${h.length})`,children:[(0,O.jsx)(S,{error:m.error,onRetry:()=>m.reload()}),(0,O.jsx)(T,{columns:_,dataSource:h,rowKey:`name`,loading:m.loading,pagination:{pageSize:20},toolbar:(0,O.jsx)(p,{prefix:(0,O.jsx)(te,{}),value:i,onChange:a,placeholder:`搜索角色名称`,showClear:!0,style:{width:260}})})]}),(0,O.jsx)(F,{visible:!!l,role:l?.role||null,onCancel:()=>f(null),onSaved:()=>{f(null),m.reload()}})]})}export{R as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{B as r,E as i,G as a,I as o,Lt as s,N as c,P as l,Pt as u,R as d,S as f,U as p,W as m,d as h,ft as g,h as ee,lt as te,m as _,ut as v,v as ne,y as re}from"./semi-65W_4I1v.js";import{F as y,I as ie,L as b,a as x,b as ae,c as oe,l as S,m as C,n as se,p as w,s as T,x as ce,y as E}from"./index-DNMXun-U.js";var D=e(t(),1),O=e(n(),1),{Text:k}=a,A=`默认`;function j(e){if(!e||typeof e!=`string`)return``;let t=e.trim(),n=t.match(/^"?\\U([0-9A-F]{8})"?$/i);if(n)try{return String.fromCodePoint(parseInt(n[1],16))}catch{return t}return t}function M(e){return e?.is_external&&e?.external_mcp?`${e.external_mcp}::${e.name}`:e?.name||``}function N(e){if(!Array.isArray(e))return[];let t=new Set,n=[];for(let r of e){let e=String(r||``).trim();e&&!t.has(e)&&(t.add(e),n.push(e))}return n}var P=20;function F({visible:e,role:t,onCancel:n,onSaved:a}){let{hasPermission:s}=ie(),u=s(`mcp:read`)||s(`config:read`),g=s(`workflow:read`),v=!!t,y=t?.name===A,[x,S]=(0,D.useState)(``),[C,w]=(0,D.useState)(``),[T,E]=(0,D.useState)(``),[F,I]=(0,D.useState)(``),[L,R]=(0,D.useState)(``),[z,B]=(0,D.useState)(`auto`),[le,ue]=(0,D.useState)(!0),[V,H]=(0,D.useState)([]),[de,fe]=(0,D.useState)(``),[U,W]=(0,D.useState)(``),[pe,G]=(0,D.useState)(!1),[me,he]=(0,D.useState)([]),[ge,_e]=(0,D.useState)(!1),[K,ve]=(0,D.useState)(``),q=se(K,250),[J,ye]=(0,D.useState)(`all`),[Y,X]=(0,D.useState)(1),[Z,be]=(0,D.useState)([]),[Q,xe]=(0,D.useState)(0),[Se,Ce]=(0,D.useState)(!1),[we,Te]=(0,D.useState)(null);(0,D.useEffect)(()=>{if(!e)return;S(t?.name||``),w(j(t?.icon)),E(t?.description||``),I(t?.user_prompt||``),R(t?.workflow_id||``),B(t?.workflow_policy||`auto`),ue(!t||t.enabled!==!1);let n=N(t?.tools);H(n),fe(n.join(`, `)),W(``),ve(``),ye(`all`),X(1)},[e,t]),(0,D.useEffect)(()=>{if(!e||!g)return;let t=!1;return _e(!0),b.get(`/workflows`,{includeDisabled:`true`}).then(e=>{t||he(Array.isArray(e?.workflows)?e.workflows:[])}).catch(()=>{t||he([])}).finally(()=>{t||_e(!1)}),()=>{t=!0}},[e,g]),(0,D.useEffect)(()=>{X(1)},[q]),(0,D.useEffect)(()=>{if(!e||y||!u||J!==`all`)return;let t=!1;return Ce(!0),Te(null),b.get(`/config/tools`,{page:Y,page_size:P,search:q.trim()||void 0}).then(e=>{t||(be(Array.isArray(e?.tools)?e.tools:[]),xe(Number(e?.total)||0))}).catch(e=>{t||(Te(e),be([]),xe(0))}).finally(()=>{t||Ce(!1)}),()=>{t=!0}},[e,y,u,J,Y,q]);let Ee=(0,D.useMemo)(()=>new Set(V),[V]),De=(0,D.useMemo)(()=>{let e=K.trim().toLowerCase();return e?V.filter(t=>t.toLowerCase().includes(e)):V},[V,K]),Oe=(0,D.useMemo)(()=>{let e=me.map(e=>({value:e.id,label:e.name?`${e.name} (${e.id})`:e.id}));return L&&!e.some(e=>e.value===L)&&e.unshift({value:L,label:L}),e},[me,L]),$=e=>{e&&H(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},ke=()=>{let e=Z.map(M).filter(Boolean);H(t=>N([...t,...e]))},Ae=()=>{let e=new Set(Z.map(M).filter(Boolean));H(t=>t.filter(t=>!e.has(t)))},je=async()=>{let e=x.trim();if(!e)W(`请输入角色名称`);else{W(``),G(!0);try{let n=y?[]:u?V:N(de.split(`,`)),r=String(L||``).trim(),i={name:y?A:e,description:T.trim(),user_prompt:F,icon:C.trim(),tools:n,enabled:!!le};r&&(i.workflow_id=r,i.workflow_policy=z||`auto`,t?.workflow_id===r&&t?.workflow_version&&(i.workflow_version=t.workflow_version)),v?await b.put(`/roles/${encodeURIComponent(t.name)}`,i):await b.post(`/roles`,i),ce(`角色已保存`),a?.()}catch(e){ae(e,`保存角色失败`)}finally{G(!1)}}},Me=j(C)||(y?`🔵`:`👤`);return(0,O.jsx)(oe,{title:v?`编辑角色:${t.name}`:`新建角色`,visible:e,onCancel:n,onOk:je,okText:`保存`,confirmLoading:pe,width:760,children:(0,O.jsxs)(`div`,{className:`cs-role-editor-form`,children:[(0,O.jsxs)(`div`,{className:`cs-role-editor-grid`,children:[(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-name-input`,children:(0,O.jsx)(`span`,{className:`cs-role-field-required`,children:`角色名称`})}),(0,O.jsx)(p,{id:`cs-role-name-input`,value:x,onChange:e=>{S(e),U&&W(``)},disabled:y,placeholder:`例如:Web应用扫描`,validateStatus:U?`error`:`default`}),U&&(0,O.jsx)(k,{type:`danger`,size:`small`,children:U}),y&&(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`默认角色名称不可修改。`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-icon-input`,children:`角色图标`}),(0,O.jsxs)(`div`,{className:`cs-role-icon-input-row`,children:[(0,O.jsx)(`span`,{className:`cs-role-icon-badge`,"aria-hidden":`true`,children:Me}),(0,O.jsx)(p,{id:`cs-role-icon-input`,value:C,onChange:w,placeholder:`Emoji,如 🔍`})]})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-desc-input`,children:`角色描述`}),(0,O.jsx)(p,{id:`cs-role-desc-input`,value:T,onChange:E,placeholder:`简要说明该角色的职责与适用场景`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`label`,{className:`cs-role-field-label`,htmlFor:`cs-role-prompt-input`,children:`用户提示词`}),(0,O.jsx)(f,{id:`cs-role-prompt-input`,value:F,onChange:I,autosize:{minRows:5,maxRows:14},placeholder:`追加到用户消息前的角色提示词(留空则不额外追加)`})]}),(0,O.jsxs)(`div`,{className:`cs-role-editor-workflow-grid`,children:[(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`绑定工作流`}),g?(0,O.jsx)(re,{value:L||void 0,onChange:e=>{let t=e||``;R(t),t&&!z&&B(`auto`)},optionList:Oe,loading:ge,filter:!0,showClear:!0,placeholder:`不绑定工作流`,style:{width:`100%`}}):(0,O.jsx)(p,{value:L,onChange:R,placeholder:`不绑定工作流(缺少 workflow:read 权限,可手动输入 ID 或留空)`})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`工作流策略`}),(0,O.jsx)(re,{value:z||`auto`,onChange:e=>B(e||`auto`),disabled:!L,optionList:[{value:`auto`,label:`自动触发(默认)`},{value:`off`,label:`关闭自动触发`}],style:{width:`100%`}})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-field`,children:[(0,O.jsx)(`span`,{className:`cs-role-field-label`,children:`关联工具`}),y?(0,O.jsx)(r,{type:`info`,fullMode:!1,closeIcon:null,title:`默认角色使用所有工具`,description:`默认角色会自动使用 MCP 管理中启用的所有工具,无需单独配置。`}):u?(0,O.jsxs)(`div`,{className:`cs-role-tools-panel`,children:[(0,O.jsxs)(`div`,{className:`cs-role-tools-header`,children:[(0,O.jsx)(o,{wrap:!0,children:V.length>0?(0,O.jsxs)(c,{color:`blue`,children:[`已勾选 `,V.length,` 个工具`]}):(0,O.jsx)(c,{color:`grey`,children:`未限制(默认使用全部已启用工具)`})}),V.length>0&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,onClick:()=>H([]),children:`清空(使用全部)`})]}),V.length>0&&(0,O.jsx)(`div`,{className:`cs-role-tools-selected`,"aria-label":`已勾选工具列表`,children:V.map(e=>(0,O.jsx)(c,{size:`small`,closable:!0,onClose:()=>$(e),children:e},e))}),(0,O.jsxs)(`div`,{className:`cs-role-tools-toolbar`,children:[(0,O.jsx)(p,{prefix:(0,O.jsx)(te,{}),value:K,onChange:ve,placeholder:`搜索工具名称或描述`,showClear:!0,style:{width:240}}),(0,O.jsxs)(o,{wrap:!0,children:[(0,O.jsxs)(ee,{type:`button`,buttonSize:`small`,value:J,onChange:e=>ye(e.target.value),children:[(0,O.jsx)(_,{value:`all`,children:`全部工具`}),(0,O.jsxs)(_,{value:`selected`,children:[`仅已勾选 (`,V.length,`)`]})]}),J===`all`&&Z.length>0&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(d,{size:`small`,onClick:ke,children:`全选本页`}),(0,O.jsx)(d,{size:`small`,onClick:Ae,children:`取消本页`})]})]})]}),J===`all`?(0,O.jsxs)(O.Fragment,{children:[we&&(0,O.jsx)(r,{type:`warning`,fullMode:!1,closeIcon:null,description:`加载工具列表失败,请稍后重试。`}),(0,O.jsx)(m,{spinning:Se,children:(0,O.jsx)(`div`,{className:`cs-role-tools-list`,children:Z.length===0&&!Se?(0,O.jsx)(i,{description:`没有匹配的工具`,style:{padding:24}}):Z.map(e=>{let t=M(e),n=Ee.has(t);return(0,O.jsxs)(`div`,{className:`cs-role-tool-item`,onClick:()=>$(t),children:[(0,O.jsx)(l,{checked:n,onChange:()=>{},onClick:e=>{e.stopPropagation(),$(t)},"aria-label":t}),(0,O.jsxs)(`div`,{className:`cs-role-tool-meta`,children:[(0,O.jsxs)(`div`,{className:`cs-role-tool-head`,children:[(0,O.jsx)(k,{strong:!0,size:`small`,children:e.name}),e.is_external&&e.external_mcp&&(0,O.jsx)(c,{size:`small`,color:`cyan`,children:e.external_mcp}),e.enabled===!1&&(0,O.jsx)(c,{size:`small`,color:`orange`,children:`MCP 未启用`})]}),e.description&&(0,O.jsx)(`span`,{className:`cs-role-tool-desc`,title:e.description,children:e.description})]})]},t)})})}),Q>P&&(0,O.jsxs)(`div`,{className:`cs-role-tools-footer`,children:[(0,O.jsxs)(k,{type:`tertiary`,size:`small`,children:[`共 `,Q,` 个工具`]}),(0,O.jsx)(ne,{size:`small`,total:Q,pageSize:P,currentPage:Y,onPageChange:X})]})]}):(0,O.jsx)(`div`,{className:`cs-role-tools-list`,children:De.length===0?(0,O.jsx)(i,{description:`暂无已勾选工具`,style:{padding:24}}):De.map(e=>(0,O.jsxs)(`div`,{className:`cs-role-tool-item`,onClick:()=>$(e),children:[(0,O.jsx)(l,{checked:!0,onChange:()=>{},onClick:t=>{t.stopPropagation(),$(e)},"aria-label":e}),(0,O.jsx)(`div`,{className:`cs-role-tool-meta`,children:(0,O.jsx)(k,{strong:!0,size:`small`,children:e})})]},e))}),(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`留空工具列表表示不限制(使用 MCP 管理中全部已启用工具);MCP 全局开关请在 MCP 管理中调整。`})]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(p,{value:de,onChange:fe,placeholder:`toolName, mcpName::toolName(留空表示不限制)`}),(0,O.jsx)(`span`,{className:`cs-role-field-hint`,children:`当前账号缺少工具列表读取权限,可直接按逗号分隔填写工具 key。`})]})]}),(0,O.jsxs)(`div`,{className:`cs-role-switch-row`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(k,{strong:!0,children:`启用此角色`}),(0,O.jsx)(`div`,{className:`cs-role-field-hint`,children:`停用后该角色不会出现在对话角色选择器中。`})]}),(0,O.jsx)(h,{checked:le,onChange:ue,"aria-label":`启用此角色`})]})]})})}var{Text:I}=a;function L(e){return[...e].sort((e,t)=>e?.name===`默认`&&t?.name!==`默认`?-1:t?.name===`默认`&&e?.name!==`默认`?1:String(e?.name||``).localeCompare(String(t?.name||``),`zh-CN`))}function R(){let e=y(),{hasPermission:t}=ie(),n=t(`roles:write`),r=t(`roles:delete`),[i,a]=(0,D.useState)(``),[l,f]=(0,D.useState)(null),m=x(()=>b.get(`/roles`),[]),h=(0,D.useMemo)(()=>{let e=Array.isArray(m.data?.roles)?L(m.data.roles):[];if(!i.trim())return e;let t=i.trim().toLowerCase();return e.filter(e=>[e.name,e.description,e.workflow_id].some(e=>String(e||``).toLowerCase().includes(t)))},[m.data,i]),ee=e=>E({title:`删除角色「${e.name}」?`,content:`已绑定该角色的对话将失去对应提示词与工具配置。`,onOk:async()=>{try{await b.del(`/roles/${encodeURIComponent(e.name)}`),ce(`已删除`),m.reload()}catch(e){ae(e,`删除角色失败`)}}}),_=[{title:`角色`,dataIndex:`name`,render:(e,t)=>{let n=e===A,r=j(t.icon)||(n?`🔵`:`👤`);return(0,O.jsxs)(`div`,{className:`cs-role-name-cell`,children:[(0,O.jsx)(`span`,{className:`cs-role-icon-badge`,"aria-hidden":`true`,children:r}),(0,O.jsxs)(o,{vertical:!0,spacing:0,align:`start`,children:[(0,O.jsxs)(o,{spacing:6,children:[(0,O.jsx)(I,{strong:!0,children:e}),n&&(0,O.jsx)(c,{size:`small`,color:`blue`,children:`默认`}),t.enabled===!1&&(0,O.jsx)(c,{size:`small`,color:`grey`,children:`已停用`})]}),(0,O.jsx)(I,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:460},children:t.description||`—`})]})]})}},{title:`工具`,dataIndex:`tools`,width:260,render:(e,t)=>t.name===`默认`?(0,O.jsx)(I,{type:`tertiary`,children:`全部工具`}):Array.isArray(e)&&e.length?(0,O.jsxs)(o,{wrap:!0,spacing:4,children:[e.slice(0,4).map(e=>(0,O.jsx)(c,{size:`small`,children:e},e)),e.length>4&&(0,O.jsxs)(I,{type:`tertiary`,children:[`+`,e.length-4]})]}):(0,O.jsx)(I,{type:`tertiary`,children:`全部工具`})},{title:`工作流`,dataIndex:`workflow_id`,width:180,render:(e,t)=>e?(0,O.jsxs)(o,{spacing:4,wrap:!0,children:[(0,O.jsx)(I,{children:e}),t.workflow_policy===`off`&&(0,O.jsx)(c,{size:`small`,color:`grey`,children:`关闭自动`})]}):`—`}];return(n||r)&&_.push({title:`操作`,width:150,render:(e,t)=>(0,O.jsxs)(o,{children:[n&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,icon:(0,O.jsx)(u,{}),onClick:()=>f({role:t}),children:`编辑`}),r&&t.name!==`默认`&&(0,O.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,O.jsx)(s,{}),"aria-label":`删除 ${t.name}`,onClick:()=>ee(t)})]})}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(w,{title:e(`roles.title`,null,`角色管理`),description:`角色定义对话的系统提示词、可用工具与绑定工作流。`,extra:(0,O.jsxs)(o,{children:[(0,O.jsx)(d,{icon:(0,O.jsx)(v,{}),onClick:()=>m.reload(),loading:m.loading,children:`刷新`}),n&&(0,O.jsx)(d,{theme:`solid`,type:`primary`,icon:(0,O.jsx)(g,{}),onClick:()=>f({role:null}),children:`新建角色`})]})}),(0,O.jsxs)(C,{title:`角色(${h.length})`,children:[(0,O.jsx)(S,{error:m.error,onRetry:()=>m.reload()}),(0,O.jsx)(T,{columns:_,dataSource:h,rowKey:`name`,loading:m.loading,pagination:{pageSize:20},toolbar:(0,O.jsx)(p,{prefix:(0,O.jsx)(te,{}),value:i,onChange:a,placeholder:`搜索角色名称`,showClear:!0,style:{width:260}})})]}),(0,O.jsx)(F,{visible:!!l,role:l?.role||null,onCancel:()=>f(null),onSaved:()=>{f(null),m.reload()}})]})}export{R as default}; \ No newline at end of file diff --git a/web/static/app/assets/settings-yUhIZhl9.js b/web/static/app/assets/settings-CgtfKueL.js similarity index 99% rename from web/static/app/assets/settings-yUhIZhl9.js rename to web/static/app/assets/settings-CgtfKueL.js index 568e3a9f..0720b4b4 100644 --- a/web/static/app/assets/settings-yUhIZhl9.js +++ b/web/static/app/assets/settings-CgtfKueL.js @@ -1,4 +1,4 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,_ as n,g as r,t as i,y as a}from"./react-QV7DAAIx.js";import{$ as o,B as s,Ft as c,G as l,I as u,L as d,N as f,R as p,S as m,U as h,c as g,d as _,g as v,h as y,j as ee,k as b,lt as x,m as S,on as C,p as w,s as T,ut as E,y as D}from"./semi-65W_4I1v.js";import{D as O,E as k,F as te,I as A,L as j,M,N,P,R as F,S as I,T as L,_ as R,a as z,b as ne,d as B,j as re,l as V,m as H,n as ie,o as U,p as W,s as G,u as K,x as ae,y as oe,z as se}from"./index-CAEPLS-g.js";import{n as ce,r as le,t as ue}from"./model-channel-mQ6lfvSO.js";var q=e(t(),1),J=class extends Error{constructor(e,t){super(t?`第 ${t} 行:${e}`:e),this.name=`YamlError`,this.line=t||0}},de=/^(?:[-?:,\[\]{}#&*!|>'"%@`]|.*[:\s]$|.*\s#|.*[\n\r\t])/,fe=/^(?:true|false|null|~|yes|no|on|off|[-+]?(?:\d+|\d*\.\d+)(?:[eE][-+]?\d+)?)$/i;function pe(e){let t=String(e);return!(t===``||fe.test(t)||/^[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?$/.test(t)||de.test(t)||/^(?:\s)|:(?:\s|$)|[\r\n\t]/.test(t)||/[,[\]{}]/.test(t)||/^[!&*|>@`]/.test(t))}function Y(e){return JSON.stringify(String(e))}function me(e){let t=String(e);return pe(t)?t:Y(t)}function he(e){if(e==null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return Number.isFinite(e)?String(e):Y(String(e));let t=String(e);return pe(t)?t:Y(t)}function ge(e){return e==null||[`string`,`number`,`boolean`].includes(typeof e)}function _e(e,t,n,r){let i=` `.repeat(n),a=me(e);if(ge(t))r.push(`${i}${a}: ${he(t)}`);else if(Array.isArray(t)){if(!t.length){r.push(`${i}${a}: []`);return}r.push(`${i}${a}:`),be(t,n+2,r)}else Object.entries(t).length?(r.push(`${i}${a}:`),ve(t,n+2,r)):r.push(`${i}${a}: {}`)}function ve(e,t,n){for(let[r,i]of Object.entries(e))_e(r,i,t,n)}function ye(e,t,n){let r=` `.repeat(t);if(ge(e)){n.push(`${r}- ${he(e)}`);return}if(Array.isArray(e)){if(!e.length){n.push(`${r}- []`);return}n.push(`${r}-`),be(e,t+2,n);return}let i=Object.entries(e);if(!i.length){n.push(`${r}- {}`);return}let[a,o]=i[0],s=i.slice(1);ge(o)?n.push(`${r}- ${me(a)}: ${he(o)}`):(n.push(`${r}-`),_e(a,o,t+2,n));for(let[e,r]of s)_e(e,r,t+2,n)}function be(e,t,n){for(let r of e)ye(r,t,n)}function xe(e,{header:t}={}){let n=[];if(t){for(let e of String(t).replace(/\r\n?/g,` +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,_ as n,g as r,t as i,y as a}from"./react-QV7DAAIx.js";import{$ as o,B as s,Ft as c,G as l,I as u,L as d,N as f,R as p,S as m,U as h,c as g,d as _,g as v,h as y,j as ee,k as b,lt as x,m as S,on as C,p as w,s as T,ut as E,y as D}from"./semi-65W_4I1v.js";import{D as O,E as k,F as te,I as A,L as j,M,N,P,R as F,S as I,T as L,_ as R,a as z,b as ne,d as B,j as re,l as V,m as H,n as ie,o as U,p as W,s as G,u as K,x as ae,y as oe,z as se}from"./index-DNMXun-U.js";import{n as ce,r as le,t as ue}from"./model-channel-mQ6lfvSO.js";var q=e(t(),1),J=class extends Error{constructor(e,t){super(t?`第 ${t} 行:${e}`:e),this.name=`YamlError`,this.line=t||0}},de=/^(?:[-?:,\[\]{}#&*!|>'"%@`]|.*[:\s]$|.*\s#|.*[\n\r\t])/,fe=/^(?:true|false|null|~|yes|no|on|off|[-+]?(?:\d+|\d*\.\d+)(?:[eE][-+]?\d+)?)$/i;function pe(e){let t=String(e);return!(t===``||fe.test(t)||/^[-+]?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?$/.test(t)||de.test(t)||/^(?:\s)|:(?:\s|$)|[\r\n\t]/.test(t)||/[,[\]{}]/.test(t)||/^[!&*|>@`]/.test(t))}function Y(e){return JSON.stringify(String(e))}function me(e){let t=String(e);return pe(t)?t:Y(t)}function he(e){if(e==null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return Number.isFinite(e)?String(e):Y(String(e));let t=String(e);return pe(t)?t:Y(t)}function ge(e){return e==null||[`string`,`number`,`boolean`].includes(typeof e)}function _e(e,t,n,r){let i=` `.repeat(n),a=me(e);if(ge(t))r.push(`${i}${a}: ${he(t)}`);else if(Array.isArray(t)){if(!t.length){r.push(`${i}${a}: []`);return}r.push(`${i}${a}:`),be(t,n+2,r)}else Object.entries(t).length?(r.push(`${i}${a}:`),ve(t,n+2,r)):r.push(`${i}${a}: {}`)}function ve(e,t,n){for(let[r,i]of Object.entries(e))_e(r,i,t,n)}function ye(e,t,n){let r=` `.repeat(t);if(ge(e)){n.push(`${r}- ${he(e)}`);return}if(Array.isArray(e)){if(!e.length){n.push(`${r}- []`);return}n.push(`${r}-`),be(e,t+2,n);return}let i=Object.entries(e);if(!i.length){n.push(`${r}- {}`);return}let[a,o]=i[0],s=i.slice(1);ge(o)?n.push(`${r}- ${me(a)}: ${he(o)}`):(n.push(`${r}-`),_e(a,o,t+2,n));for(let[e,r]of s)_e(e,r,t+2,n)}function be(e,t,n){for(let r of e)ye(r,t,n)}function xe(e,{header:t}={}){let n=[];if(t){for(let e of String(t).replace(/\r\n?/g,` `).split(` `))n.push(`# ${e}`.trimEnd());n.length&&n.push(``)}return ge(e)?(n.push(he(e)),`${n.join(` `)}\n`):Array.isArray(e)?(e.length?be(e,0,n):n.push(`[]`),`${n.join(` diff --git a/web/static/app/assets/skills-management-g8Njeibz.js b/web/static/app/assets/skills-management-CBXR8d2s.js similarity index 97% rename from web/static/app/assets/skills-management-g8Njeibz.js rename to web/static/app/assets/skills-management-CBXR8d2s.js index f04f3e77..53688a71 100644 --- a/web/static/app/assets/skills-management-g8Njeibz.js +++ b/web/static/app/assets/skills-management-CBXR8d2s.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{C as r,G as i,I as a,Lt as o,R as s,S as c,U as l,ft as u,i as d,lt as f,ut as p}from"./semi-65W_4I1v.js";import{E as m,F as h,I as g,L as _,T as v,a as y,b,c as x,d as S,f as C,l as w,m as T,n as E,p as D,s as O,x as k,y as A}from"./index-CAEPLS-g.js";var j=e(t(),1),M=e(n(),1),{Text:N}=i;function P(){let e=h(),{hasPermission:t}=g(),n=t(`skills:write`),r=t(`skills:delete`),[i,c]=(0,j.useState)(``),S=E(i,300),[C,P]=(0,j.useState)(1),[I,L]=(0,j.useState)(20),[R,z]=(0,j.useState)(null),[B,V]=(0,j.useState)(null),[H,U]=(0,j.useState)(!1),W=y(()=>_.get(`/skills`,{search:S||void 0,limit:I,offset:(C-1)*I}),[S,C,I]),G=Array.isArray(W.data?.skills)?W.data.skills:[],K=Number(W.data?.total||0),q=async()=>{let e=await B.form.validate();U(!0);try{await _.post(`/skills`,{name:e.name.trim(),description:e.description.trim(),content:e.content}),k(`技能已创建`),V(null),W.reload()}catch(e){b(e,`创建技能失败`)}finally{U(!1)}},J=e=>A({title:`删除技能「${e.name}」?`,content:`该技能目录及其全部文件会被移除。`,onOk:async()=>{await _.del(`/skills/${encodeURIComponent(e.id||e.name)}`),k(`已删除`),W.reload()}});return(0,M.jsxs)(`div`,{children:[(0,M.jsx)(D,{title:e(`skills.managementTitle`,null,`技能管理`),description:`技能以目录形式存放在技能根目录,SKILL.md 描述触发条件与用法。`,extra:(0,M.jsxs)(a,{children:[(0,M.jsx)(s,{icon:(0,M.jsx)(p,{}),onClick:()=>W.reload(),loading:W.loading,children:`刷新`}),n&&(0,M.jsx)(s,{theme:`solid`,type:`primary`,icon:(0,M.jsx)(u,{}),onClick:()=>V({form:{}}),children:`新建技能`})]})}),(0,M.jsxs)(T,{title:`技能(${K})`,children:[(0,M.jsx)(w,{error:W.error,onRetry:()=>W.reload()}),(0,M.jsx)(O,{columns:[{title:`技能`,dataIndex:`name`,render:(e,t)=>(0,M.jsxs)(a,{vertical:!0,spacing:0,align:`start`,children:[(0,M.jsx)(N,{strong:!0,children:e||t.id}),(0,M.jsx)(N,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:420},children:t.description})]})},{title:`版本`,dataIndex:`version`,width:100,render:e=>e||`—`},{title:`文件`,dataIndex:`file_count`,width:80,render:e=>String(e??`—`)},{title:`大小`,dataIndex:`file_size`,width:100,render:e=>v(e)},{title:`更新时间`,dataIndex:`mod_time`,width:170,render:e=>e?m(e):`—`},{title:`操作`,width:140,render:(e,t)=>(0,M.jsxs)(a,{children:[(0,M.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>z(t),children:`详情`}),r&&(0,M.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,M.jsx)(o,{}),onClick:()=>J(t)})]})}],dataSource:G,rowKey:e=>e.id||e.name,loading:W.loading,pagination:{currentPage:C,pageSize:I,total:K,onPageChange:P,onPageSizeChange:e=>{L(e),P(1)}},toolbar:(0,M.jsx)(l,{prefix:(0,M.jsx)(f,{}),value:i,onChange:e=>{c(e),P(1)},placeholder:`搜索技能名称或描述`,style:{width:280}})})]}),(0,M.jsx)(x,{title:`新建技能`,visible:!!B,onCancel:()=>V(null),onOk:q,confirmLoading:H,width:720,children:(0,M.jsxs)(d,{getFormApi:e=>V(t=>t&&{...t,form:e}),children:[(0,M.jsx)(d.Input,{field:`name`,label:`目录名`,placeholder:`小写字母、数字、连字符`,rules:[{required:!0,message:`请输入目录名`},{pattern:/^[a-z0-9-]+$/,message:`只允许小写字母、数字与连字符`}]}),(0,M.jsx)(d.Input,{field:`description`,label:`描述`,rules:[{required:!0,message:`请输入描述`}]}),(0,M.jsx)(d.TextArea,{field:`content`,label:`SKILL.md 正文`,rules:[{required:!0,message:`请输入正文`}],autosize:{minRows:10,maxRows:24}})]})},`new-skill`),(0,M.jsx)(F,{skill:R,onClose:()=>z(null),canWrite:n})]})}function F({skill:e,onClose:t,canWrite:n}){let[i,o]=(0,j.useState)([]),[l,u]=(0,j.useState)(``),[d,f]=(0,j.useState)(``),[p,m]=(0,j.useState)(!1),[h,g]=(0,j.useState)(!1);(0,j.useEffect)(()=>{e&&(o([]),u(``),f(``),_.get(`/skills/${encodeURIComponent(e.id||e.name)}/files`).then(e=>o(Array.isArray(e?.files)?e.files:[])).catch(()=>o([])))},[e]);let v=async t=>{m(!0);try{let n=await _.get(`/skills/${encodeURIComponent(e.id||e.name)}/file`,{path:t});u(t),f(n?.content||``)}catch(e){b(e,`读取文件失败`)}finally{m(!1)}},y=async()=>{g(!0);try{await _.put(`/skills/${encodeURIComponent(e.id||e.name)}/file`,{path:l,content:d}),k(`文件已保存`)}catch(e){b(e,`保存文件失败`)}finally{g(!1)}},w=i.map(e=>typeof e==`string`?e:e.path||e.name);return(0,M.jsx)(x,{title:e?.name||`技能详情`,visible:!!e,onCancel:t,width:860,children:e&&(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,M.jsx)(S,{items:[{label:`目录名`,value:e.id||e.dir_name},{label:`版本`,value:e.version||`—`},{label:`路径`,value:e.path},{label:`文件数`,value:e.file_count},{label:`触发词`,value:Array.isArray(e.triggers)?e.triggers.join(`、`):`—`},{label:`标签`,value:Array.isArray(e.tags)?e.tags.join(`、`):`—`}]}),(0,M.jsx)(N,{type:`tertiary`,children:e.description}),(0,M.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`220px minmax(0, 1fr)`,gap:12},children:[(0,M.jsx)(`div`,{style:{border:`1px solid var(--semi-color-border)`,borderRadius:8,maxHeight:420,overflow:`auto`},children:(0,M.jsx)(r,{dataSource:w,renderItem:e=>(0,M.jsx)(r.Item,{main:(0,M.jsx)(N,{size:`small`,ellipsis:{showTooltip:!0},children:e}),onClick:()=>v(e),style:{cursor:`pointer`,background:e===l?`var(--semi-color-primary-light-default)`:void 0}}),emptyContent:`暂无文件`})}),(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,M.jsxs)(a,{children:[(0,M.jsx)(N,{strong:!0,children:l||`选择左侧文件查看内容`}),n&&l&&(0,M.jsx)(s,{size:`small`,loading:h,onClick:y,children:`保存`})]}),l?(0,M.jsx)(c,{value:d,onChange:f,autosize:{minRows:20,maxRows:30},disabled:!n}):(0,M.jsx)(C,{content:e.description||`—`}),p&&(0,M.jsx)(N,{type:`tertiary`,children:`读取中…`})]})]})]})})}export{P as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{C as r,G as i,I as a,Lt as o,R as s,S as c,U as l,ft as u,i as d,lt as f,ut as p}from"./semi-65W_4I1v.js";import{E as m,F as h,I as g,L as _,T as v,a as y,b,c as x,d as S,f as C,l as w,m as T,n as E,p as D,s as O,x as k,y as A}from"./index-DNMXun-U.js";var j=e(t(),1),M=e(n(),1),{Text:N}=i;function P(){let e=h(),{hasPermission:t}=g(),n=t(`skills:write`),r=t(`skills:delete`),[i,c]=(0,j.useState)(``),S=E(i,300),[C,P]=(0,j.useState)(1),[I,L]=(0,j.useState)(20),[R,z]=(0,j.useState)(null),[B,V]=(0,j.useState)(null),[H,U]=(0,j.useState)(!1),W=y(()=>_.get(`/skills`,{search:S||void 0,limit:I,offset:(C-1)*I}),[S,C,I]),G=Array.isArray(W.data?.skills)?W.data.skills:[],K=Number(W.data?.total||0),q=async()=>{let e=await B.form.validate();U(!0);try{await _.post(`/skills`,{name:e.name.trim(),description:e.description.trim(),content:e.content}),k(`技能已创建`),V(null),W.reload()}catch(e){b(e,`创建技能失败`)}finally{U(!1)}},J=e=>A({title:`删除技能「${e.name}」?`,content:`该技能目录及其全部文件会被移除。`,onOk:async()=>{await _.del(`/skills/${encodeURIComponent(e.id||e.name)}`),k(`已删除`),W.reload()}});return(0,M.jsxs)(`div`,{children:[(0,M.jsx)(D,{title:e(`skills.managementTitle`,null,`技能管理`),description:`技能以目录形式存放在技能根目录,SKILL.md 描述触发条件与用法。`,extra:(0,M.jsxs)(a,{children:[(0,M.jsx)(s,{icon:(0,M.jsx)(p,{}),onClick:()=>W.reload(),loading:W.loading,children:`刷新`}),n&&(0,M.jsx)(s,{theme:`solid`,type:`primary`,icon:(0,M.jsx)(u,{}),onClick:()=>V({form:{}}),children:`新建技能`})]})}),(0,M.jsxs)(T,{title:`技能(${K})`,children:[(0,M.jsx)(w,{error:W.error,onRetry:()=>W.reload()}),(0,M.jsx)(O,{columns:[{title:`技能`,dataIndex:`name`,render:(e,t)=>(0,M.jsxs)(a,{vertical:!0,spacing:0,align:`start`,children:[(0,M.jsx)(N,{strong:!0,children:e||t.id}),(0,M.jsx)(N,{type:`tertiary`,ellipsis:{showTooltip:!0},style:{maxWidth:420},children:t.description})]})},{title:`版本`,dataIndex:`version`,width:100,render:e=>e||`—`},{title:`文件`,dataIndex:`file_count`,width:80,render:e=>String(e??`—`)},{title:`大小`,dataIndex:`file_size`,width:100,render:e=>v(e)},{title:`更新时间`,dataIndex:`mod_time`,width:170,render:e=>e?m(e):`—`},{title:`操作`,width:140,render:(e,t)=>(0,M.jsxs)(a,{children:[(0,M.jsx)(s,{size:`small`,theme:`borderless`,onClick:()=>z(t),children:`详情`}),r&&(0,M.jsx)(s,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,M.jsx)(o,{}),onClick:()=>J(t)})]})}],dataSource:G,rowKey:e=>e.id||e.name,loading:W.loading,pagination:{currentPage:C,pageSize:I,total:K,onPageChange:P,onPageSizeChange:e=>{L(e),P(1)}},toolbar:(0,M.jsx)(l,{prefix:(0,M.jsx)(f,{}),value:i,onChange:e=>{c(e),P(1)},placeholder:`搜索技能名称或描述`,style:{width:280}})})]}),(0,M.jsx)(x,{title:`新建技能`,visible:!!B,onCancel:()=>V(null),onOk:q,confirmLoading:H,width:720,children:(0,M.jsxs)(d,{getFormApi:e=>V(t=>t&&{...t,form:e}),children:[(0,M.jsx)(d.Input,{field:`name`,label:`目录名`,placeholder:`小写字母、数字、连字符`,rules:[{required:!0,message:`请输入目录名`},{pattern:/^[a-z0-9-]+$/,message:`只允许小写字母、数字与连字符`}]}),(0,M.jsx)(d.Input,{field:`description`,label:`描述`,rules:[{required:!0,message:`请输入描述`}]}),(0,M.jsx)(d.TextArea,{field:`content`,label:`SKILL.md 正文`,rules:[{required:!0,message:`请输入正文`}],autosize:{minRows:10,maxRows:24}})]})},`new-skill`),(0,M.jsx)(F,{skill:R,onClose:()=>z(null),canWrite:n})]})}function F({skill:e,onClose:t,canWrite:n}){let[i,o]=(0,j.useState)([]),[l,u]=(0,j.useState)(``),[d,f]=(0,j.useState)(``),[p,m]=(0,j.useState)(!1),[h,g]=(0,j.useState)(!1);(0,j.useEffect)(()=>{e&&(o([]),u(``),f(``),_.get(`/skills/${encodeURIComponent(e.id||e.name)}/files`).then(e=>o(Array.isArray(e?.files)?e.files:[])).catch(()=>o([])))},[e]);let v=async t=>{m(!0);try{let n=await _.get(`/skills/${encodeURIComponent(e.id||e.name)}/file`,{path:t});u(t),f(n?.content||``)}catch(e){b(e,`读取文件失败`)}finally{m(!1)}},y=async()=>{g(!0);try{await _.put(`/skills/${encodeURIComponent(e.id||e.name)}/file`,{path:l,content:d}),k(`文件已保存`)}catch(e){b(e,`保存文件失败`)}finally{g(!1)}},w=i.map(e=>typeof e==`string`?e:e.path||e.name);return(0,M.jsx)(x,{title:e?.name||`技能详情`,visible:!!e,onCancel:t,width:860,children:e&&(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:12},children:[(0,M.jsx)(S,{items:[{label:`目录名`,value:e.id||e.dir_name},{label:`版本`,value:e.version||`—`},{label:`路径`,value:e.path},{label:`文件数`,value:e.file_count},{label:`触发词`,value:Array.isArray(e.triggers)?e.triggers.join(`、`):`—`},{label:`标签`,value:Array.isArray(e.tags)?e.tags.join(`、`):`—`}]}),(0,M.jsx)(N,{type:`tertiary`,children:e.description}),(0,M.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`220px minmax(0, 1fr)`,gap:12},children:[(0,M.jsx)(`div`,{style:{border:`1px solid var(--semi-color-border)`,borderRadius:8,maxHeight:420,overflow:`auto`},children:(0,M.jsx)(r,{dataSource:w,renderItem:e=>(0,M.jsx)(r.Item,{main:(0,M.jsx)(N,{size:`small`,ellipsis:{showTooltip:!0},children:e}),onClick:()=>v(e),style:{cursor:`pointer`,background:e===l?`var(--semi-color-primary-light-default)`:void 0}}),emptyContent:`暂无文件`})}),(0,M.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:8},children:[(0,M.jsxs)(a,{children:[(0,M.jsx)(N,{strong:!0,children:l||`选择左侧文件查看内容`}),n&&l&&(0,M.jsx)(s,{size:`small`,loading:h,onClick:y,children:`保存`})]}),l?(0,M.jsx)(c,{value:d,onChange:f,autosize:{minRows:20,maxRows:30},disabled:!n}):(0,M.jsx)(C,{content:e.description||`—`}),p&&(0,M.jsx)(N,{type:`tertiary`,children:`读取中…`})]})]})]})})}export{P as default}; \ No newline at end of file diff --git a/web/static/app/assets/skills-monitor-BUTc0QtL.js b/web/static/app/assets/skills-monitor-Bs5yNZYW.js similarity index 95% rename from web/static/app/assets/skills-monitor-BUTc0QtL.js rename to web/static/app/assets/skills-monitor-Bs5yNZYW.js index 7ebab9e3..0dee86c5 100644 --- a/web/static/app/assets/skills-monitor-BUTc0QtL.js +++ b/web/static/app/assets/skills-monitor-Bs5yNZYW.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{G as t,I as n,Lt as r,R as i,ut as a}from"./semi-65W_4I1v.js";import{D as o,F as s,I as c,L as l,O as u,_ as d,a as f,l as p,m,p as h,s as g,x as _,y as v}from"./index-CAEPLS-g.js";import{t as y}from"./react-QV7DAAIx.js";var b=e(y(),1),{Text:x}=t;function S(){let e=s(),{hasPermission:t}=c(),y=t(`skills:delete`),S=f(()=>l.get(`/skills/stats`),[]),C=Array.isArray(S.data?.stats)?S.data.stats:[],w=Number(S.data?.total_calls||0),T=Number(S.data?.total_success||0),E=w>0?T/w:null,D=()=>v({title:`清空所有技能调用统计?`,content:`只影响统计计数,不删除技能文件。`,onOk:async()=>{await l.del(`/skills/stats`),_(`统计已清空`),S.reload()}}),O=e=>v({title:`清空「${e}」的统计?`,onOk:async()=>{await l.del(`/skills/${encodeURIComponent(e)}/stats`),_(`已清空`),S.reload()}});return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(h,{title:e(`skills.monitorTitle`,null,`技能状态`),description:S.data?.skills_dir?`技能目录:${S.data.skills_dir}`:`统计技能被调用的次数、成功率与最近使用时间。`,extra:(0,b.jsxs)(n,{children:[(0,b.jsx)(i,{icon:(0,b.jsx)(a,{}),onClick:()=>S.reload(),loading:S.loading,children:`刷新`}),y&&(0,b.jsx)(i,{type:`danger`,theme:`light`,onClick:D,children:`清空全部统计`})]})}),(0,b.jsx)(d,{columns:4,metrics:[{id:`skills`,label:`技能总数`,value:o(S.data?.total_skills||0),loading:S.loading},{id:`calls`,label:`调用总数`,value:o(w),loading:S.loading},{id:`success`,label:`成功次数`,value:o(T),loading:S.loading},{id:`rate`,label:`成功率`,value:E===null?`—`:u(E),tone:E!==null&&E<.8?`warning`:`success`,loading:S.loading}]}),(0,b.jsxs)(m,{title:`按技能统计`,children:[(0,b.jsx)(p,{error:S.error,onRetry:()=>S.reload()}),(0,b.jsx)(g,{columns:[{title:`技能`,dataIndex:`skill_name`,render:e=>(0,b.jsx)(x,{strong:!0,children:e})},{title:`调用次数`,dataIndex:`total_calls`,width:120,render:e=>o(e||0)},{title:`成功`,dataIndex:`success_calls`,width:100,render:e=>o(e||0)},{title:`失败`,dataIndex:`failed_calls`,width:100,render:e=>Number(e)>0?(0,b.jsx)(x,{type:`danger`,children:o(e)}):`0`},{title:`最后调用`,dataIndex:`last_call_time`,width:180,render:e=>e||`—`},{title:`操作`,width:110,render:(e,t)=>y&&Number(t.total_calls)>0?(0,b.jsx)(i,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,b.jsx)(r,{}),onClick:()=>O(t.skill_name),children:`清空`}):null}],dataSource:C,rowKey:`skill_name`,loading:S.loading,pagination:{pageSize:20}})]})]})}export{S as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{G as t,I as n,Lt as r,R as i,ut as a}from"./semi-65W_4I1v.js";import{D as o,F as s,I as c,L as l,O as u,_ as d,a as f,l as p,m,p as h,s as g,x as _,y as v}from"./index-DNMXun-U.js";import{t as y}from"./react-QV7DAAIx.js";var b=e(y(),1),{Text:x}=t;function S(){let e=s(),{hasPermission:t}=c(),y=t(`skills:delete`),S=f(()=>l.get(`/skills/stats`),[]),C=Array.isArray(S.data?.stats)?S.data.stats:[],w=Number(S.data?.total_calls||0),T=Number(S.data?.total_success||0),E=w>0?T/w:null,D=()=>v({title:`清空所有技能调用统计?`,content:`只影响统计计数,不删除技能文件。`,onOk:async()=>{await l.del(`/skills/stats`),_(`统计已清空`),S.reload()}}),O=e=>v({title:`清空「${e}」的统计?`,onOk:async()=>{await l.del(`/skills/${encodeURIComponent(e)}/stats`),_(`已清空`),S.reload()}});return(0,b.jsxs)(`div`,{children:[(0,b.jsx)(h,{title:e(`skills.monitorTitle`,null,`技能状态`),description:S.data?.skills_dir?`技能目录:${S.data.skills_dir}`:`统计技能被调用的次数、成功率与最近使用时间。`,extra:(0,b.jsxs)(n,{children:[(0,b.jsx)(i,{icon:(0,b.jsx)(a,{}),onClick:()=>S.reload(),loading:S.loading,children:`刷新`}),y&&(0,b.jsx)(i,{type:`danger`,theme:`light`,onClick:D,children:`清空全部统计`})]})}),(0,b.jsx)(d,{columns:4,metrics:[{id:`skills`,label:`技能总数`,value:o(S.data?.total_skills||0),loading:S.loading},{id:`calls`,label:`调用总数`,value:o(w),loading:S.loading},{id:`success`,label:`成功次数`,value:o(T),loading:S.loading},{id:`rate`,label:`成功率`,value:E===null?`—`:u(E),tone:E!==null&&E<.8?`warning`:`success`,loading:S.loading}]}),(0,b.jsxs)(m,{title:`按技能统计`,children:[(0,b.jsx)(p,{error:S.error,onRetry:()=>S.reload()}),(0,b.jsx)(g,{columns:[{title:`技能`,dataIndex:`skill_name`,render:e=>(0,b.jsx)(x,{strong:!0,children:e})},{title:`调用次数`,dataIndex:`total_calls`,width:120,render:e=>o(e||0)},{title:`成功`,dataIndex:`success_calls`,width:100,render:e=>o(e||0)},{title:`失败`,dataIndex:`failed_calls`,width:100,render:e=>Number(e)>0?(0,b.jsx)(x,{type:`danger`,children:o(e)}):`0`},{title:`最后调用`,dataIndex:`last_call_time`,width:180,render:e=>e||`—`},{title:`操作`,width:110,render:(e,t)=>y&&Number(t.total_calls)>0?(0,b.jsx)(i,{size:`small`,theme:`borderless`,type:`danger`,icon:(0,b.jsx)(r,{}),onClick:()=>O(t.skill_name),children:`清空`}):null}],dataSource:C,rowKey:`skill_name`,loading:S.loading,pagination:{pageSize:20}})]})]})}export{S as default}; \ No newline at end of file diff --git a/web/static/app/assets/tasks-CT27M-Wx.js b/web/static/app/assets/tasks-C9yzz-_n.js similarity index 99% rename from web/static/app/assets/tasks-CT27M-Wx.js rename to web/static/app/assets/tasks-C9yzz-_n.js index 266cde07..cf94f8bd 100644 --- a/web/static/app/assets/tasks-CT27M-Wx.js +++ b/web/static/app/assets/tasks-C9yzz-_n.js @@ -1,2 +1,2 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{G as a,I as o,N as s,P as c,R as l,S as u,U as d,c as ee,ft as f,g as p,lt as m,p as h,ut as g,y as _}from"./semi-65W_4I1v.js";import{E as v,F as y,I as b,L as x,_ as S,a as C,b as w,c as T,d as E,f as te,l as ne,m as D,n as O,p as k,r as re,s as ie,x as A,y as j}from"./index-CAEPLS-g.js";import{t as M}from"./project-options-CMQbwv_U.js";var N=e(t(),1),P={pending:{label:`待执行`,color:`amber`},running:{label:`执行中`,color:`blue`},paused:{label:`已暂停`,color:`grey`},completed:{label:`已完成`,color:`green`},cancelled:{label:`已取消`,color:`grey`}},F={pending:{label:`待执行`,color:`amber`},running:{label:`执行中`,color:`blue`},completed:{label:`已完成`,color:`green`},failed:{label:`失败`,color:`red`},cancelled:{label:`已取消`,color:`grey`},blocked:{label:`受阻`,color:`orange`}},I=[{value:`single`,label:`单代理(Pi SDK)`},{value:`deep`,label:`Deep(DeepAgent)`},{value:`plan_execute`,label:`Plan-Execute`},{value:`supervisor`,label:`Supervisor(专家路由)`}],ae=[{value:``,label:`沿用全局设置`},{value:`off`,label:`关闭审批`},{value:`human`,label:`人工审批`},{value:`audit_agent`,label:`Agent 审批`},{value:`review_edit`,label:`Agent 审查编辑`}],L=[{value:`manual`,label:`手工执行`},{value:`cron`,label:`Cron 调度`}],oe=[{value:`all`,label:`全部状态`},{value:`pending`,label:`待执行`},{value:`running`,label:`执行中`},{value:`paused`,label:`已暂停`},{value:`completed`,label:`已完成`},{value:`cancelled`,label:`已取消`}];function R(e){let t=Array.isArray(e?.tasks)?e.tasks:[],n=t.length,r=t.filter(e=>e.status===`completed`).length,i=t.filter(e=>e.status===`failed`).length,a=t.filter(e=>e.status===`cancelled`).length,o=t.filter(e=>e.status===`blocked`).length,s=t.filter(e=>e.status===`running`).length,c=t.filter(e=>e.status===`pending`).length,l=r+i+a+o;return{total:n,completed:r,failed:i,cancelled:a,blocked:o,running:s,pending:c,done:l,percent:n?Math.round(l/n*100):0}}function se(e){return(I.find(t=>t.value===String(e||`single`))||I[0]).label}function ce(e){let t=P[String(e?.status||``)]||{label:e?.status||`—`,color:`grey`},n=e?.scheduleMode===`cron`&&e?.scheduleEnabled!==!1,r=e?.nextRunAt?new Date(e.nextRunAt):null,i=r&&Number.isFinite(r.getTime())?r.toLocaleString(`zh-CN`,{hour12:!1}):``,a=R(e),o=a.blocked>0?e?.lastRunError||`${a.blocked} 项受阻`:``;if(a.blocked>0&&a.completed===0&&a.failed===0)return{...t,label:`受阻(${a.blocked} 项)`,color:`orange`,sublabel:o};if(n&&e?.status===`completed`){let e=a.failed>0||a.blocked>0;return{...t,label:e?`本轮已结束 · 定时循环中`:`本轮已完成 · 定时循环中`,color:a.failed>0?`red`:a.blocked>0?`orange`:t.color,sublabel:o||(i?`下次执行:${i}`:``),note:`定时队列:子任务已跑完,到点将自动下一轮`}}if(n&&e?.status===`pending`&&i)return{...t,sublabel:`Cron 已排程 · 下次 ${i}`};if(e?.status===`completed`&&a.failed>0){let e=a.blocked>0?`,${a.blocked} 项受阻`:``;return{...t,label:`已结束(${a.failed} 项失败${e})`,color:`red`,sublabel:o}}return e?.status===`completed`&&a.blocked>0?{...t,label:`已结束(${a.blocked} 项受阻)`,color:`orange`,sublabel:o}:{...t,sublabel:``}}function z(e,t){if(!e)return`—`;let n=new Date(e).getTime(),r=t?new Date(t).getTime():Date.now();if(!Number.isFinite(n)||!Number.isFinite(r)||r{if(!e)return;o(U),S(!1);let t=!1;return i(`roles:read`)&&x.get(`/roles`).then(e=>{t||l(Array.isArray(e?.roles)?e.roles:[])}).catch(()=>{t||l([])}),i(`project:read`)&&x.get(`/projects`,{limit:500}).then(e=>{t||f(Array.isArray(e?.projects)?e.projects:[])}).catch(()=>{t||f([])}),()=>{t=!0}},[e,i]),(0,N.useEffect)(()=>{if(!e||!a.projectId||!i(`asset:read`)){m([]),g(null);return}let t=!1;return x.get(`/assets/collections`,{project_id:a.projectId}).then(e=>{t||m(Array.isArray(e?.collections)?e.collections:[])}).catch(()=>{t||m([])}),x.get(`/assets`,{project_id:a.projectId,page:1,page_size:1}).then(e=>{t||g(Number.isFinite(Number(e?.total))?Number(e.total):0)}).catch(()=>{t||g(null)}),()=>{t=!0}},[e,a.projectId,i]);let C=e=>o(t=>({...t,...e}));return(0,V.jsxs)(T,{visible:e,title:r(`batchImportModal.title`,null,`新建任务`),onCancel:t,onOk:async()=>{let e=a.tasksText.split(` +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{G as a,I as o,N as s,P as c,R as l,S as u,U as d,c as ee,ft as f,g as p,lt as m,p as h,ut as g,y as _}from"./semi-65W_4I1v.js";import{E as v,F as y,I as b,L as x,_ as S,a as C,b as w,c as T,d as E,f as te,l as ne,m as D,n as O,p as k,r as re,s as ie,x as A,y as j}from"./index-DNMXun-U.js";import{t as M}from"./project-options-CMQbwv_U.js";var N=e(t(),1),P={pending:{label:`待执行`,color:`amber`},running:{label:`执行中`,color:`blue`},paused:{label:`已暂停`,color:`grey`},completed:{label:`已完成`,color:`green`},cancelled:{label:`已取消`,color:`grey`}},F={pending:{label:`待执行`,color:`amber`},running:{label:`执行中`,color:`blue`},completed:{label:`已完成`,color:`green`},failed:{label:`失败`,color:`red`},cancelled:{label:`已取消`,color:`grey`},blocked:{label:`受阻`,color:`orange`}},I=[{value:`single`,label:`单代理(Pi SDK)`},{value:`deep`,label:`Deep(DeepAgent)`},{value:`plan_execute`,label:`Plan-Execute`},{value:`supervisor`,label:`Supervisor(专家路由)`}],ae=[{value:``,label:`沿用全局设置`},{value:`off`,label:`关闭审批`},{value:`human`,label:`人工审批`},{value:`audit_agent`,label:`Agent 审批`},{value:`review_edit`,label:`Agent 审查编辑`}],L=[{value:`manual`,label:`手工执行`},{value:`cron`,label:`Cron 调度`}],oe=[{value:`all`,label:`全部状态`},{value:`pending`,label:`待执行`},{value:`running`,label:`执行中`},{value:`paused`,label:`已暂停`},{value:`completed`,label:`已完成`},{value:`cancelled`,label:`已取消`}];function R(e){let t=Array.isArray(e?.tasks)?e.tasks:[],n=t.length,r=t.filter(e=>e.status===`completed`).length,i=t.filter(e=>e.status===`failed`).length,a=t.filter(e=>e.status===`cancelled`).length,o=t.filter(e=>e.status===`blocked`).length,s=t.filter(e=>e.status===`running`).length,c=t.filter(e=>e.status===`pending`).length,l=r+i+a+o;return{total:n,completed:r,failed:i,cancelled:a,blocked:o,running:s,pending:c,done:l,percent:n?Math.round(l/n*100):0}}function se(e){return(I.find(t=>t.value===String(e||`single`))||I[0]).label}function ce(e){let t=P[String(e?.status||``)]||{label:e?.status||`—`,color:`grey`},n=e?.scheduleMode===`cron`&&e?.scheduleEnabled!==!1,r=e?.nextRunAt?new Date(e.nextRunAt):null,i=r&&Number.isFinite(r.getTime())?r.toLocaleString(`zh-CN`,{hour12:!1}):``,a=R(e),o=a.blocked>0?e?.lastRunError||`${a.blocked} 项受阻`:``;if(a.blocked>0&&a.completed===0&&a.failed===0)return{...t,label:`受阻(${a.blocked} 项)`,color:`orange`,sublabel:o};if(n&&e?.status===`completed`){let e=a.failed>0||a.blocked>0;return{...t,label:e?`本轮已结束 · 定时循环中`:`本轮已完成 · 定时循环中`,color:a.failed>0?`red`:a.blocked>0?`orange`:t.color,sublabel:o||(i?`下次执行:${i}`:``),note:`定时队列:子任务已跑完,到点将自动下一轮`}}if(n&&e?.status===`pending`&&i)return{...t,sublabel:`Cron 已排程 · 下次 ${i}`};if(e?.status===`completed`&&a.failed>0){let e=a.blocked>0?`,${a.blocked} 项受阻`:``;return{...t,label:`已结束(${a.failed} 项失败${e})`,color:`red`,sublabel:o}}return e?.status===`completed`&&a.blocked>0?{...t,label:`已结束(${a.blocked} 项受阻)`,color:`orange`,sublabel:o}:{...t,sublabel:``}}function z(e,t){if(!e)return`—`;let n=new Date(e).getTime(),r=t?new Date(t).getTime():Date.now();if(!Number.isFinite(n)||!Number.isFinite(r)||r{if(!e)return;o(U),S(!1);let t=!1;return i(`roles:read`)&&x.get(`/roles`).then(e=>{t||l(Array.isArray(e?.roles)?e.roles:[])}).catch(()=>{t||l([])}),i(`project:read`)&&x.get(`/projects`,{limit:500}).then(e=>{t||f(Array.isArray(e?.projects)?e.projects:[])}).catch(()=>{t||f([])}),()=>{t=!0}},[e,i]),(0,N.useEffect)(()=>{if(!e||!a.projectId||!i(`asset:read`)){m([]),g(null);return}let t=!1;return x.get(`/assets/collections`,{project_id:a.projectId}).then(e=>{t||m(Array.isArray(e?.collections)?e.collections:[])}).catch(()=>{t||m([])}),x.get(`/assets`,{project_id:a.projectId,page:1,page_size:1}).then(e=>{t||g(Number.isFinite(Number(e?.total))?Number(e.total):0)}).catch(()=>{t||g(null)}),()=>{t=!0}},[e,a.projectId,i]);let C=e=>o(t=>({...t,...e}));return(0,V.jsxs)(T,{visible:e,title:r(`batchImportModal.title`,null,`新建任务`),onCancel:t,onOk:async()=>{let e=a.tasksText.split(` `).map(e=>e.trim()).filter(Boolean);if(!e.length){w(r(`tasks.noValidTask`,null,`没有有效的任务`));return}if(a.scheduleMode===`cron`){if(!a.cronExpr.trim()){w(r(`batchImportModal.cronExprRequired`,null,`请选择 Cron 调度后填写 Cron 表达式`));return}if(!W.test(a.cronExpr.trim())){w(r(`batchImportModal.cronExprInvalid`,null,`Cron 表达式格式错误,需要 5 段(分 时 日 月 周)`));return}}let t=Number(a.concurrency);(!Number.isFinite(t)||t<1)&&(t=1),t>8&&(t=8),S(!0);try{let i=await x.post(`/batch-tasks`,{title:a.title.trim(),tasks:e,role:a.role||``,projectId:a.projectId||``,collectionId:a.collectionId||``,agentMode:a.agentMode||`single`,hitlPolicy:a.hitlPolicy||``,scheduleMode:a.scheduleMode===`cron`?`cron`:`manual`,cronExpr:a.scheduleMode===`cron`?a.cronExpr.trim():``,concurrency:t,executeNow:!!a.executeNow});A(r(`tasks.batchQueueTitle`,null,`批量任务队列`)),n?.(i)}catch(e){w(B(e,r(`tasks.createBatchQueueFailed`,null,`创建批量任务队列失败`)))}finally{S(!1)}},okText:r(`batchImportModal.createQueue`,null,`创建队列`),cancelText:r(`common.cancel`,null,`取消`),confirmLoading:v,width:760,maskClosable:!1,children:[(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.queueTitle`,null,`任务标题`)}),(0,V.jsx)(d,{value:a.title,maxLength:200,placeholder:r(`batchImportModal.queueTitlePlaceholder`,null,`请输入任务标题(可选,用于标识和筛选)`),onChange:e=>C({title:e})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.role`,null,`角色`)}),(0,V.jsx)(_,{value:a.role,style:{width:`100%`},optionList:[{value:``,label:r(`batchImportModal.defaultRole`,null,`默认`)},...s.map(e=>({value:e.name,label:e.name}))],onChange:e=>C({role:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.roleHint`,null,`选择一个角色,所有任务将使用该角色的配置(提示词和工具)执行。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.project`,null,`所属项目`)}),(0,V.jsx)(_,{value:a.projectId,style:{width:`100%`},optionList:[{value:``,label:r(`batchImportModal.projectNone`,null,`(未绑定)`)},...M(ee,r,{currentId:a.projectId})],onChange:e=>C({projectId:e||``,collectionId:``})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.agentMode`,null,`代理模式`)}),(0,V.jsx)(_,{value:a.agentMode,style:{width:`100%`},optionList:I,onChange:e=>C({agentMode:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.agentModeHint`,null,`与对话页一致:Pi 单代理,或 Deep / Plan-Execute / Supervisor(后三种需已启用多代理)。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:`资产范围`}),p.length?(0,V.jsx)(_,{value:a.collectionId,style:{width:`100%`},disabled:!a.projectId,optionList:[{value:``,label:h==null?`资产库中该项目的全部资产`:`资产库中该项目的全部资产(${h})`},...p.map(e=>({value:e.id,label:`${e.name}(${e.member_count||0})`}))],onChange:e=>C({collectionId:e||``})}):(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:a.projectId?h==null?`资产库中该项目的全部资产`:`资产库中该项目的全部资产(${h})`:`选择项目后,使用资产库里该项目的资产。`}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:`与对话、深度测评共用资产库。只有信息收集保存过检索结果时,才需要从中缩小范围。`})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.tasksList`,null,`任务列表(每行一个任务)`)}),(0,V.jsx)(u,{value:a.tasksText,rows:7,placeholder:r(`batchImportModal.tasksListPlaceholderExample`,null,`请输入任务列表,每行一个任务`),onChange:e=>C({tasksText:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.tasksListHint`,null,`每行输入一个任务指令,系统将按并发池执行这些任务。空行会被自动忽略。`)})]}),(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.hitlPolicy`,null,`工具审批`)}),(0,V.jsx)(_,{value:a.hitlPolicy,style:{width:`100%`},optionList:ae,onChange:e=>C({hitlPolicy:e})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.concurrency`,null,`并发数`)}),(0,V.jsx)(d,{type:`number`,min:1,max:8,value:String(a.concurrency),onChange:e=>C({concurrency:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.concurrencyHint`,null,`同时执行的子任务数量(1-8)。默认 1 为串行;含扫描类工具时建议 1-2。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-grid`,children:[(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.scheduleMode`,null,`调度方式`)}),(0,V.jsx)(_,{value:a.scheduleMode,style:{width:`100%`},optionList:L,onChange:e=>C({scheduleMode:e})})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(H,{strong:!0,size:`small`,children:r(`batchImportModal.cronExpr`,null,`Cron 表达式`)}),(0,V.jsx)(d,{value:a.cronExpr,disabled:a.scheduleMode!==`cron`,placeholder:r(`batchImportModal.cronExprPlaceholder`,null,`例如:0 */2 * * *(每2小时执行一次)`),onChange:e=>C({cronExpr:e})}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.cronExprHint`,null,`采用标准 5 段 Cron:分 时 日 月 周。`)})]})]}),(0,V.jsxs)(`div`,{className:`task-form-field`,children:[(0,V.jsx)(c,{checked:a.executeNow,onChange:e=>C({executeNow:e.target.checked}),children:r(`batchImportModal.executeNow`,null,`创建后立即执行`)}),(0,V.jsx)(H,{type:`tertiary`,size:`small`,children:r(`batchImportModal.executeNowHint`,null,`默认不立即执行;关闭后队列保持待执行,可在需要时手动开始。`)})]})]})}var{Text:G}=a;function K({status:e}){let t=F[String(e||``)]||{label:e||`—`,color:`grey`};return(0,V.jsx)(s,{size:`small`,color:t.color,children:t.label})}function de({queueId:e,visible:t,canWrite:r,canDelete:i,onClose:a,onChanged:c}){let d=y(),ee=n(),[m,_]=(0,N.useState)(0),[b,S]=(0,N.useState)({visible:!1,taskId:``,message:``}),[D,O]=(0,N.useState)({visible:!1,task:null}),k=C(()=>e?x.get(`/batch-tasks/${e}`):Promise.resolve(null),[e,m]),M=k.data?.queue||null,P=(0,N.useMemo)(()=>R(M),[M]);re(()=>{t&&M?.status===`running`&&k.reload({silent:!0})},t&&M?.status===`running`?4e3:0),(0,N.useEffect)(()=>{t&&e&&k.reload({silent:!0})},[t,e]),(0,N.useEffect)(()=>{t||(S({visible:!1,taskId:``,message:``}),O({visible:!1,task:null}))},[t]);let F=()=>{_(e=>e+1),c?.()},L=async(t,n)=>{try{await x.post(`/batch-tasks/${e}/${t}`),A(n),F()}catch(e){w(B(e,n+`失败`))}},oe=()=>L(`start`,`已开始执行`),se=()=>j({title:d(`tasks.statusPaused`,null,`已暂停`),content:d(`tasks.pauseQueueConfirm`,null,`确定要暂停这个批量任务队列吗?当前正在执行的任务将被停止,后续任务将保留待执行状态。`),okText:d(`common.confirm`,null,`确认`),onOk:async()=>{try{await x.post(`/batch-tasks/${e}/pause`),A(d(`tasks.statusPaused`,null,`已暂停`)),F()}catch(e){w(B(e,d(`tasks.pauseQueueFailed`,null,`暂停批量任务失败`)))}}}),H=()=>j({title:d(`tasks.retry`,null,`重试`),content:d(`tasks.rerunQueueConfirm`,null,`确定要重跑一轮吗?所有子任务将被重置为待执行状态并重新开始执行。`),okText:d(`common.confirm`,null,`确认`),onOk:async()=>{try{await x.post(`/batch-tasks/${e}/rerun`),A(d(`tasks.statusRunning`,null,`执行中`)),F()}catch(e){w(B(e,d(`tasks.rerunQueueFailed`,null,`重跑批量任务失败`)))}}}),U=()=>j({title:d(`tasks.deleteQueue`,null,`删除队列`),content:d(`tasks.deleteQueueConfirm`,null,`确定要删除这个批量任务队列吗?此操作不可恢复。`),okText:d(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/batch-tasks/${e}`),A(d(`tasks.deleteQueue`,null,`删除队列`)),c?.(),a?.()}catch(e){w(B(e,d(`tasks.deleteQueueFailed`,null,`删除批量任务队列失败`)))}}}),W=e=>S({visible:!0,taskId:e?.id||``,message:e?.message||``}),ue=async()=>{let t=b.message.trim();if(!t)w(d(`tasks.taskMessageRequired`,null,`任务消息不能为空`));else try{b.taskId?await x.put(`/batch-tasks/${e}/tasks/${b.taskId}`,{message:t}):await x.post(`/batch-tasks/${e}/tasks`,{message:t}),A(d(`common.save`,null,`保存`)),S({visible:!1,taskId:``,message:``}),F()}catch(e){w(B(e,b.taskId?d(`tasks.saveTaskFailed`,null,`保存任务失败`):d(`tasks.addTaskFailed`,null,`添加任务失败`)))}},de=t=>j({title:d(`tasks.runSingleTask`,null,`单条执行`),content:d(`tasks.confirmRunSingleTask`,null,`确定执行该任务?仅运行这一条,完成后队列会自动暂停,不会继续执行其他待执行项。`),okText:d(`common.confirm`,null,`确认`),danger:!1,onOk:async()=>{try{await x.post(`/batch-tasks/${e}/tasks/${t.id}/run`),A(d(`tasks.runSingleTask`,null,`单条执行`)),F()}catch(e){w(B(e,d(`tasks.runSingleTaskFailed`,null,`单条执行失败`)))}}}),q=t=>j({title:d(`common.delete`,null,`删除`),content:d(`tasks.confirmDeleteTask`,null,`确定要删除这个任务吗?`),okText:d(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/batch-tasks/${e}/tasks/${t.id}`),A(d(`common.delete`,null,`删除`)),F()}catch(e){w(B(e,d(`tasks.deleteTaskFailed`,null,`删除任务失败`)))}}}),J=e=>!!(r&&M&&e.status!==`running`&&M.status!==`running`&&[`pending`,`paused`,`completed`,`cancelled`].includes(M.status)),fe=[{title:`#`,dataIndex:`id`,width:58,render:(e,t)=>{let n=(M?.tasks||[]).findIndex(e=>e.id===t.id);return(0,V.jsx)(G,{type:`tertiary`,size:`small`,children:n+1})}},{title:d(`tasks.title`,null,`任务`),dataIndex:`message`,render:(e,t)=>(0,V.jsx)(`span`,{className:`task-cell-message`,title:e,children:e||d(`tasks.taskIncomplete`,null,`任务信息不完整`)})},{title:d(`projects.status`,null,`状态`),dataIndex:`status`,width:96,render:e=>(0,V.jsx)(K,{status:e})},{title:d(`tasks.duration`,null,`执行时长`),dataIndex:`startedAt`,width:110,render:(e,t)=>(0,V.jsx)(G,{size:`small`,children:e?z(e,t.completedAt):`—`})},{title:d(`common.actions`,null,`操作`),dataIndex:`id`,width:210,render:(e,t)=>(0,V.jsxs)(o,{spacing:2,wrap:!0,children:[(0,V.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>O({visible:!0,task:t}),children:`结果`}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!r,onClick:()=>W(t),children:d(`common.edit`,null,`编辑`)}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!J(t),title:d(`tasks.runSingleTaskUnavailable`,null,`队列或任务执行中,暂无法单条执行`),onClick:()=>de(t),children:d(`tasks.runSingleTask`,null,`单条执行`)}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!i,onClick:()=>q(t),children:d(`common.delete`,null,`删除`)})]})}],Y=ce(M),X=M?.scheduleMode===`cron`&&M?.scheduleEnabled!==!1;return(0,V.jsxs)(h,{visible:t,width:900,title:M?M.title||M.id:d(`tasks.batchQueueTitle`,null,`批量任务队列`),onCancel:a,children:[(0,V.jsx)(ne,{error:le(k.error),onRetry:()=>k.reload()}),M?(0,V.jsxs)(`div`,{className:`task-detail-stack`,children:[(0,V.jsxs)(`div`,{className:`task-detail-actions`,children:[(0,V.jsxs)(o,{wrap:!0,children:[(0,V.jsx)(l,{type:`primary`,disabled:!r||M.status===`running`,onClick:oe,children:`开始执行`}),(0,V.jsx)(l,{disabled:!r||M.status!==`running`,onClick:se,children:`暂停`}),(0,V.jsx)(l,{disabled:!r||![`completed`,`cancelled`].includes(M.status),onClick:H,children:d(`tasks.retry`,null,`重试`)}),(0,V.jsx)(l,{icon:(0,V.jsx)(g,{}),theme:`borderless`,onClick:()=>k.reload()})]}),(0,V.jsxs)(o,{children:[(0,V.jsx)(l,{icon:(0,V.jsx)(f,{}),disabled:!r,onClick:()=>W(null),children:`添加任务`}),(0,V.jsx)(l,{type:`danger`,disabled:!i,onClick:U,children:d(`tasks.deleteQueue`,null,`删除队列`)})]})]}),(0,V.jsxs)(`div`,{className:`task-progress-block`,children:[(0,V.jsxs)(`div`,{className:`task-progress-head`,children:[(0,V.jsx)(s,{size:`small`,color:Y.color,children:Y.label}),Y.sublabel?(0,V.jsx)(G,{type:`tertiary`,size:`small`,children:Y.sublabel}):null]}),(0,V.jsx)(p,{percent:P.percent,showInfo:!0,stroke:`var(--semi-color-primary)`}),(0,V.jsxs)(`div`,{className:`task-progress-legend`,children:[(0,V.jsxs)(`span`,{children:[d(`tasks.totalLabel`,null,`总计`),` `,P.total]}),(0,V.jsxs)(`span`,{children:[d(`tasks.pendingLabel`,null,`待执行`),` `,P.pending]}),(0,V.jsxs)(`span`,{children:[d(`tasks.runningLabel`,null,`执行中`),` `,P.running]}),(0,V.jsxs)(`span`,{children:[d(`tasks.completedLabel`,null,`已完成`),` `,P.completed]}),(0,V.jsxs)(`span`,{children:[d(`tasks.failedLabel`,null,`失败`),` `,P.failed]}),(0,V.jsxs)(`span`,{children:[d(`tasks.cancelledLabel`,null,`已取消`),` `,P.cancelled]}),(0,V.jsxs)(`span`,{children:[`受阻 `,P.blocked]})]}),(0,V.jsx)(G,{type:`tertiary`,size:`small`,children:X?d(`tasks.cronRunningProgressHint`,null,`本轮执行中;下一整轮仍按 Cron 与「下次执行时间」排程`):d(`tasks.finishedProgressHint`,null,`进度表示已结束的任务比例,包含失败和取消,不表示成功率。`)})]}),(0,V.jsx)(E,{columns:3,items:[{label:d(`tasks.queueIdLabel`,null,`队列ID`),value:(0,V.jsx)(`code`,{children:M.id})},{label:d(`tasks.createdTimeLabel`,null,`创建时间`),value:v(M.createdAt)},{label:`Agent 模式`,value:(I.find(e=>e.value===M.agentMode)||I[0]).label},{label:`角色`,value:M.role||d(`batchImportModal.defaultRole`,null,`默认`)},{label:`项目`,value:M.projectId||`—`},{label:d(`batchImportModal.hitlPolicy`,null,`工具审批`),value:(ae.find(e=>e.value===(M.hitlPolicy||``))||ae[0]).label},{label:d(`batchImportModal.concurrency`,null,`并发数`),value:M.concurrency||1},{label:d(`batchImportModal.scheduleMode`,null,`调度方式`),value:M.scheduleMode===`cron`?`Cron ${M.cronExpr||``}${X?``:`(已关闭)`}`:d(`batchImportModal.scheduleModeManual`,null,`手工执行`)},{label:`下一次执行`,value:M.nextRunAt?v(M.nextRunAt):`—`},M.lastRunError?{label:`最近错误`,value:(0,V.jsx)(G,{type:`danger`,size:`small`,children:M.lastRunError})}:null]}),(0,V.jsx)(ie,{columns:fe,dataSource:M.tasks||[],rowKey:`id`,size:`small`,pagination:{pageSize:10},emptyText:d(`tasks.noValidTask`,null,`没有有效的任务`)})]}):null,(0,V.jsx)(T,{visible:b.visible,title:b.taskId?d(`common.edit`,null,`编辑`):`添加任务`,onCancel:()=>S({visible:!1,taskId:``,message:``}),onOk:ue,okText:d(`common.save`,null,`保存`),cancelText:d(`common.cancel`,null,`取消`),width:620,children:(0,V.jsx)(u,{value:b.message,rows:5,placeholder:d(`batchImportModal.tasksListPlaceholder`,null,`请输入任务列表,每行一个任务`),onChange:e=>S(t=>({...t,message:e}))})}),(0,V.jsx)(T,{visible:D.visible,title:D.task?D.task.message:`结果`,onCancel:()=>O({visible:!1,task:null}),footer:(0,V.jsxs)(o,{children:[D.task?.conversationId?(0,V.jsx)(l,{onClick:()=>{let e=D.task.conversationId;O({visible:!1,task:null}),a?.(),ee(`/chat?conversation=${encodeURIComponent(e)}`)},children:d(`tasks.viewConversation`,null,`查看对话`)}):null,(0,V.jsx)(l,{onClick:()=>O({visible:!1,task:null}),children:d(`common.close`,null,`关闭`)})]}),width:720,children:(0,V.jsxs)(`div`,{className:`task-detail-stack`,children:[(0,V.jsx)(E,{columns:2,items:[{label:d(`projects.status`,null,`状态`),value:(0,V.jsx)(K,{status:D.task?.status})},{label:d(`tasks.startedAt`,null,`开始时间`),value:v(D.task?.startedAt)},{label:d(`tasks.completedAt`,null,`完成时间`),value:v(D.task?.completedAt)},{label:d(`tasks.duration`,null,`执行时长`),value:z(D.task?.startedAt,D.task?.completedAt)},D.task?.conversationId?{label:d(`tasks.conversationIdLabel`,null,`对话ID`),value:(0,V.jsx)(`code`,{children:D.task.conversationId})}:null]}),D.task?.error?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(G,{strong:!0,type:`danger`,children:D.task.status===`blocked`?`受阻原因`:d(`tasks.statusFailed`,null,`执行失败`)}),(0,V.jsx)(`pre`,{className:`task-result-pre`,children:D.task.error})]}):null,D.task?.result?(0,V.jsx)(te,{content:D.task.result}):(0,V.jsx)(G,{type:`tertiary`,children:`暂无结果`})]})})]})}var{Text:q}=a,J={running:{label:`执行中`,color:`blue`},cancelling:{label:`取消中`,color:`amber`},cleaning:{label:`清理中`,color:`amber`}};function fe(){let e=y(),t=n(),r=C(()=>x.get(`/agent-loop/tasks`),[]);re(()=>r.reload({silent:!0}),6e3);let i=Array.isArray(r.data?.tasks)?r.data.tasks:[],a=[{title:e(`tasks.title`,null,`任务`),dataIndex:`title`,render:(t,n)=>(0,V.jsxs)(`div`,{className:`task-live-title`,children:[(0,V.jsx)(`span`,{className:`task-cell-message`,title:t||n.message,children:t||n.message||e(`tasks.unnamedTask`,null,`未命名任务`)}),(0,V.jsx)(q,{type:`tertiary`,size:`small`,children:(0,V.jsx)(`code`,{children:n.runId||`—`})})]})},{title:e(`projects.status`,null,`状态`),dataIndex:`status`,width:110,render:e=>{let t=J[String(e||``)]||{label:e||`—`,color:`blue`};return(0,V.jsx)(s,{size:`small`,color:t.color,children:t.label})}},{title:e(`tasks.conversationIdLabel`,null,`对话ID`),dataIndex:`conversationId`,width:230,render:e=>(0,V.jsx)(q,{type:`tertiary`,size:`small`,children:(0,V.jsx)(`code`,{children:e||`—`})})},{title:e(`tasks.startedAt`,null,`开始时间`),dataIndex:`startedAt`,width:165,render:e=>(0,V.jsx)(q,{size:`small`,children:v(e)})},{title:e(`tasks.duration`,null,`执行时长`),dataIndex:`startedAt`,width:110,render:e=>(0,V.jsx)(q,{size:`small`,children:z(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`conversationId`,width:110,render:n=>(0,V.jsx)(o,{children:(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>t(`/chat?conversation=${encodeURIComponent(n)}`),children:e(`tasks.viewConversation`,null,`查看对话`)})})}];return(0,V.jsxs)(D,{title:`${e(`tasks.runningLabel`,null,`执行中`)}任务(Agent Loop)`,description:`当前进程中正在执行的 Agent 任务;每 6 秒自动刷新。`,extra:(0,V.jsx)(l,{icon:(0,V.jsx)(g,{}),theme:`borderless`,loading:r.loading,onClick:()=>r.reload(),children:e(`common.refresh`,null,`刷新`)}),children:[(0,V.jsx)(ne,{error:le(r.error),onRetry:()=>r.reload()}),(0,V.jsx)(ie,{columns:a,dataSource:i,rowKey:e=>e.runId||e.conversationId||`unknown-task`,loading:r.loading,pagination:{pageSize:10},emptyText:e(`tasks.noMatchingTasks`,null,`当前没有符合条件的任务`)})]})}var{Text:Y}=a;function X(){let e=y(),{hasPermission:t}=b(),n=t(`tasks:write`),r=t(`tasks:delete`),[a,c]=i(),u=a.get(`id`)||``,h=a.get(`tab`)||`queues`,[T,E]=(0,N.useState)(1),[te,M]=(0,N.useState)(10),[P,F]=(0,N.useState)(`all`),[I,ae]=(0,N.useState)(``),L=O(I,300),[z,H]=(0,N.useState)(!1),[U,W]=(0,N.useState)(0),G=C(()=>x.get(`/batch-tasks`,{limit:100,page:1}),[U]),K=C(()=>x.get(`/batch-tasks`,{limit:te,page:T,status:P===`all`?void 0:P,keyword:L.trim()||void 0}),[T,te,P,L,U]),q=Array.isArray(K.data?.queues)?K.data.queues:[],J=K.data?.total??0,X=(0,N.useMemo)(()=>(G.data?.queues||[]).some(e=>e.status===`running`),[G.data]);re(()=>{X&&(G.reload({silent:!0}),K.reload({silent:!0}))},X?5e3:0);let Z=(0,N.useCallback)((e,t)=>{let n=new URLSearchParams(a);e?n.set(`id`,e):n.delete(`id`),t?n.set(`tab`,t):n.delete(`tab`),c(n,{replace:!!e})},[a,c]);(0,N.useEffect)(()=>{h!==`queues`&&h!==`live`&&Z(void 0,`queues`)},[h,Z]);let Q=()=>W(e=>e+1),pe=G.data?.queues||[],$=(0,N.useMemo)(()=>{let e=pe.map(R);return{queues:G.data?.total??pe.length,running:pe.filter(e=>e.status===`running`).length,pendingTasks:e.reduce((e,t)=>e+t.pending,0),failedTasks:e.reduce((e,t)=>e+t.failed,0)}},[pe,G.data]),me=async t=>{try{await x.post(`/batch-tasks/${t.id}/start`),A(`已开始执行`),Q()}catch(t){w(B(t,e(`tasks.startBatchQueueFailed`,null,`启动批量任务失败`)))}},he=t=>j({title:e(`tasks.statusPaused`,null,`已暂停`),content:e(`tasks.pauseQueueConfirm`,null,`确定要暂停这个批量任务队列吗?当前正在执行的任务将被停止,后续任务将保留待执行状态。`),okText:e(`common.confirm`,null,`确认`),onOk:async()=>{try{await x.post(`/batch-tasks/${t.id}/pause`),A(e(`tasks.statusPaused`,null,`已暂停`)),Q()}catch(t){w(B(t,e(`tasks.pauseQueueFailed`,null,`暂停批量任务失败`)))}}}),ge=t=>j({title:e(`tasks.retry`,null,`重试`),content:e(`tasks.rerunQueueConfirm`,null,`确定要重跑一轮吗?所有子任务将被重置为待执行状态并重新开始执行。`),okText:e(`common.confirm`,null,`确认`),onOk:async()=>{try{await x.post(`/batch-tasks/${t.id}/rerun`),A(`已开始重跑`),Q()}catch(t){w(B(t,e(`tasks.rerunQueueFailed`,null,`重跑批量任务失败`)))}}}),_e=t=>j({title:e(`tasks.deleteQueue`,null,`删除队列`),content:e(`tasks.deleteQueueConfirm`,null,`确定要删除这个批量任务队列吗?此操作不可恢复。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await x.del(`/batch-tasks/${t.id}`),A(e(`tasks.deleteQueue`,null,`删除队列`)),u===t.id&&Z(void 0,h),Q()}catch(t){w(B(t,e(`tasks.deleteQueueFailed`,null,`删除批量任务队列失败`)))}}}),ve=[{id:`queues`,label:e(`tasks.batchQueueTitle`,null,`批量任务队列`),value:$.queues,loading:G.loading},{id:`running`,label:e(`tasks.runningLabel`,null,`执行中`),value:$.running,tone:$.running?`success`:void 0,loading:G.loading},{id:`pending`,label:e(`tasks.pendingLabel`,null,`待执行`),value:$.pendingTasks,loading:G.loading},{id:`failed`,label:e(`tasks.failedLabel`,null,`失败`),value:$.failedTasks,tone:$.failedTasks?`danger`:void 0,loading:G.loading}],ye=[{title:e(`batchImportModal.queueTitle`,null,`任务标题`),dataIndex:`title`,render:(t,n)=>{let r=ce(n);return(0,V.jsxs)(`button`,{type:`button`,className:`task-queue-name`,onClick:()=>Z(n.id,`queues`),title:n.id,children:[(0,V.jsx)(`span`,{className:`task-queue-title`,children:t||e(`tasks.batchQueueUntitled`,null,`未命名队列`)}),r.sublabel?(0,V.jsx)(`span`,{className:`task-queue-sub`,children:r.sublabel}):null]})}},{title:e(`projects.status`,null,`状态`),dataIndex:`status`,width:170,render:(e,t)=>{let n=ce(t);return(0,V.jsx)(s,{size:`small`,color:n.color,children:n.label})}},{title:`进度`,dataIndex:`progress`,width:190,render:(e,t)=>{let n=R(t);return(0,V.jsxs)(`div`,{className:`task-queue-progress`,children:[(0,V.jsx)(p,{percent:n.percent,showInfo:!1,size:`small`}),(0,V.jsxs)(Y,{type:`tertiary`,size:`small`,children:[n.percent,`%(`,n.done,`/`,n.total,`)`]})]})}},{title:e(`batchImportModal.agentMode`,null,`代理模式`),dataIndex:`agentMode`,width:150,render:e=>(0,V.jsx)(Y,{size:`small`,children:se(e)})},{title:e(`batchImportModal.scheduleMode`,null,`调度方式`),dataIndex:`scheduleMode`,width:128,render:(t,n)=>(0,V.jsx)(Y,{size:`small`,children:t===`cron`?`Cron · ${n.cronExpr||``}`:e(`batchImportModal.scheduleModeManual`,null,`手工执行`)})},{title:e(`tasks.createdTimeLabel`,null,`创建时间`),dataIndex:`createdAt`,width:160,render:e=>(0,V.jsx)(Y,{type:`tertiary`,size:`small`,children:v(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:250,render:(t,i)=>(0,V.jsxs)(o,{spacing:2,wrap:!0,children:[(0,V.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>Z(i.id,`queues`),children:e(`projects.details`,null,`详情`)}),i.status===`running`?(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>he(i),children:e(`tasks.statusPaused`,null,`已暂停`)}):(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>me(i),children:`开始执行`}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n||![`completed`,`cancelled`].includes(i.status),onClick:()=>ge(i),children:e(`tasks.retry`,null,`重试`)}),(0,V.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!r,onClick:()=>_e(i),children:e(`common.delete`,null,`删除`)})]})}];return(0,V.jsxs)(`div`,{className:`task-page`,children:[(0,V.jsx)(k,{title:e(`tasks.title`,null,`任务管理`),description:e(`tasks.pageDesc`,null,`批量任务队列按并发池执行子任务;队列详情可查看进度、单条执行与结果。`),extra:(0,V.jsxs)(o,{children:[(0,V.jsx)(l,{icon:(0,V.jsx)(g,{}),theme:`borderless`,loading:K.loading,onClick:Q,children:e(`common.refresh`,null,`刷新`)}),(0,V.jsx)(l,{type:`primary`,icon:(0,V.jsx)(f,{}),disabled:!n,onClick:()=>H(!0),children:e(`batchImportModal.title`,null,`新建任务`)})]})}),(0,V.jsx)(ne,{error:le(G.error||K.error),onRetry:Q}),(0,V.jsx)(S,{metrics:ve,columns:4}),(0,V.jsx)(ee,{type:`line`,activeKey:h,onChange:e=>Z(void 0,e),tabList:[{itemKey:`queues`,tab:e(`tasks.batchQueueTitle`,null,`批量任务队列`)},{itemKey:`live`,tab:`${e(`tasks.runningLabel`,null,`执行中`)}任务`}],className:`task-tabs`}),h===`live`?(0,V.jsx)(fe,{}):(0,V.jsxs)(D,{title:e(`tasks.batchQueueTitle`,null,`批量任务队列`),description:e(`tasks.finishedProgressHint`,null,`进度表示已结束的任务比例,包含失败和取消,不表示成功率。`),extra:(0,V.jsx)(Y,{type:`tertiary`,size:`small`,children:e(`tasks.taskCount`,{count:J},`共 ${J} 个任务`)}),children:[(0,V.jsxs)(`div`,{className:`task-toolbar`,children:[(0,V.jsx)(d,{prefix:(0,V.jsx)(m,{}),value:I,showClear:!0,placeholder:e(`batchImportModal.queueTitlePlaceholder`,null,`请输入任务标题(可选,用于标识和筛选)`),onChange:e=>{ae(e),E(1)},style:{width:280}}),(0,V.jsx)(_,{value:P,onChange:e=>{F(e),E(1)},style:{width:150},optionList:oe})]}),(0,V.jsx)(ie,{columns:ye,dataSource:q,rowKey:`id`,loading:K.loading,emptyText:P!==`all`||I?e(`tasks.noMatchingTasks`,null,`当前没有符合条件的任务`):e(`tasks.noBatchQueues`,null,`当前没有批量任务队列`),pagination:{currentPage:T,pageSize:te,total:J,onPageChange:e=>E(e),onPageSizeChange:e=>{M(e),E(1)}}})]}),(0,V.jsx)(ue,{visible:z,onCancel:()=>H(!1),onCreated:e=>{H(!1),Q(),e?.queueId&&Z(e.queueId,`queues`)}}),(0,V.jsx)(de,{queueId:u,visible:!!u,canWrite:n,canDelete:r,onClose:()=>Z(void 0,h),onChanged:Q})]})}export{X as default}; \ No newline at end of file diff --git a/web/static/app/assets/tool-guard-gHtviV0M.js b/web/static/app/assets/tool-guard-DY35NYks.js similarity index 99% rename from web/static/app/assets/tool-guard-gHtviV0M.js rename to web/static/app/assets/tool-guard-DY35NYks.js index c709e804..ab29cfba 100644 --- a/web/static/app/assets/tool-guard-gHtviV0M.js +++ b/web/static/app/assets/tool-guard-DY35NYks.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{$ as r,B as i,G as a,I as o,Lt as s,N as c,R as l,S as u,U as d,d as f,en as p,ft as m,j as h,nn as g,ut as _}from"./semi-65W_4I1v.js";import{F as v,I as y,L as b,b as x,l as S,m as C,p as w,x as T,y as E}from"./index-CAEPLS-g.js";var D=e(t(),1),O=200,k=4096;function A(e){return JSON.parse(JSON.stringify(e))}function j(e){if(!e||typeof e.enabled!=`boolean`||e.rules!=null&&!Array.isArray(e.rules))throw Error(`服务端返回的配置格式不正确`);return{enabled:e.enabled,rules:(e.rules||[]).map(e=>({id:String(e.id||``),name:String(e.name||``),enabled:!!e.enabled,pattern:String(e.pattern||``),message:String(e.message||``)}))}}function M(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`rule-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function N(e){return new TextEncoder().encode(String(e||``)).length}function P(e){if(!e)return{index:-1,field:``,message:`请先加载拦截配置`};if(e.rules.length>100)return{index:-1,field:``,message:`最多可配置 100 条拦截规则`};for(let t=0;tO)return{index:t,field:`name`,message:`第 ${t+1} 条规则名称超过 ${O} 字节`};if(N(n.pattern)>k)return{index:t,field:`pattern`,message:`第 ${t+1} 条规则正则超过 ${k} 字节`};if(N(n.message)>k)return{index:t,field:`message`,message:`第 ${t+1} 条规则提醒超过 ${k} 字节`}}return null}function ee(e,t){return!e||!t?!1:JSON.stringify(e)!==JSON.stringify(t)}function F(e){return{enabled:!!e?.enabled,rules:(e?.rules||[]).map(e=>({id:e.id,name:e.name,enabled:!!e.enabled,pattern:e.pattern,message:e.message}))}}function I(e){return{enabled:!0,rules:[{id:e.id,name:e.name,enabled:!0,pattern:e.pattern,message:e.message}]}}var L=e(n(),1),{Text:R}=a,z=`http_request`,B=`{"url": "https://example.gov.cn"}`;function V({config:e,rule:t=null,disabled:n=!1,compact:r=!1}){let a=v(),s=!!t,[f,p]=(0,D.useState)(z),[m,h]=(0,D.useState)(B),[g,_]=(0,D.useState)(!1),[y,x]=(0,D.useState)(null),[C,w]=(0,D.useState)(null),T=async()=>{if(n||g)return;if(w(null),x(null),!s&&!e){w(Error(a(`toolGuard.loadFirst`,null,`请先加载拦截配置`)));return}if(!f.trim()){w(Error(a(`toolGuard.toolRequired`,null,`请填写测试工具名称`)));return}let r;try{if(r=JSON.parse(m),!r||Array.isArray(r)||typeof r!=`object`)throw Error(`not an object`)}catch{w(Error(a(`toolGuard.invalidArguments`,null,`工具参数必须是有效的 JSON 对象`)));return}_(!0);try{let n={config:s?I(t):F(e),toolName:f.trim(),arguments:r},i=await b.post(`/tool-guard/test`,n);if(!i||typeof i.blocked!=`boolean`)throw Error(a(`toolGuard.invalidTestResponse`,null,`服务端返回的测试结果格式不正确`));x(i)}catch(e){w(e)}finally{_(!1)}},E=y?.blocked,O=y?.match,k=!s&&e&&e.enabled===!1;return(0,L.jsxs)(`div`,{className:r?`tool-guard-test tool-guard-test-compact`:`tool-guard-test`,children:[(0,L.jsxs)(o,{vertical:!0,spacing:6,align:`start`,children:[(0,L.jsx)(R,{strong:!0,children:s?a(`toolGuard.testScopeSingle`,{name:t.name||a(`toolGuard.unnamedRule`,null,`未命名规则`)},`单条验证:${t.name||`未命名规则`}`):a(`toolGuard.testScopeAll`,null,`全部规则验证`)}),(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:s?a(`toolGuard.testSingleHint`,null,`仅验证本条规则,忽略总开关和规则启停;不保存、不执行工具。`):a(`toolGuard.testAllHint`,null,`按当前顺序与启停状态验证全部规则,不保存、不执行工具。`)})]}),(0,L.jsxs)(`div`,{className:`tool-guard-test-form`,children:[(0,L.jsxs)(`label`,{className:`tool-guard-field`,children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testTool`,null,`工具名称`)}),(0,L.jsx)(d,{value:f,onChange:e=>{p(e),x(null)},placeholder:`http_request`})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testArguments`,null,`工具参数(JSON 对象)`)}),(0,L.jsx)(u,{value:m,onChange:e=>{h(e),x(null)},rows:3,spellCheck:!1,className:`tool-guard-args`})]})]}),(0,L.jsx)(l,{theme:`solid`,type:`primary`,loading:g,disabled:n,onClick:T,className:`tool-guard-test-run`,children:g?a(`toolGuard.testing`,null,`验证中…`):a(`toolGuard.test`,null,`测试匹配`)}),(0,L.jsx)(S,{error:C}),y&&(0,L.jsxs)(`div`,{className:`tool-guard-test-result ${E?`is-blocked`:`is-pass`}`,children:[(0,L.jsxs)(o,{spacing:8,wrap:!0,children:[(0,L.jsx)(c,{color:E?`red`:k?`grey`:`green`,size:`small`,children:E?`blocked`:`passed`}),(0,L.jsx)(R,{strong:!0,children:s?E?a(`toolGuard.singleMatched`,null,`本条规则匹配成功`):a(`toolGuard.singleNotMatched`,null,`本条规则未匹配`):E?a(`toolGuard.blocked`,null,`已命中规则:将阻止调用`):k?a(`toolGuard.disabledResult`,null,`调用拦截已关闭:此配置不会阻止调用`):a(`toolGuard.notBlocked`,null,`未命中已启用的规则`)})]}),s&&(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.singleResultHint`,null,`这是单条规则验证结果,实际拦截还取决于总开关、规则启停和匹配顺序。`)}),E&&O&&(0,L.jsxs)(`div`,{className:`tool-guard-match`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedRule`,null,`命中规则`)}),(0,L.jsx)(`div`,{children:O.ruleName||O.ruleId||`—`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedText`,null,`匹配文本`)}),(0,L.jsx)(`pre`,{children:O.matchedText||`—`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedMessage`,null,`返回的拦截提醒`)}),(0,L.jsx)(`div`,{children:O.message||`—`})]})]})]}),!y&&!C&&(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testReadyHint`,null,`点击「测试匹配」,在这里查看验证结果。`)}),s===!1&&!y&&!C&&k&&(0,L.jsx)(i,{type:`info`,bordered:!0,closeIcon:null,description:a(`toolGuard.disabledResult`,null,`调用拦截已关闭:此配置不会阻止调用`)})]})}var{Text:H}=a;function U({rule:e,index:t,total:n,canWrite:r,canTest:i,onChange:a,onDelete:c,onMove:m}){let h=v();return(0,L.jsxs)(`div`,{className:`tool-guard-rule-body`,children:[(0,L.jsxs)(`div`,{className:`tool-guard-rule-toolbar`,children:[(0,L.jsxs)(o,{spacing:8,children:[(0,L.jsx)(f,{size:`small`,checked:e.enabled,disabled:!r,onChange:e=>a({enabled:e}),"aria-label":h(`toolGuard.ruleEnabled`,null,`启用`)}),(0,L.jsx)(H,{size:`small`,type:`tertiary`,children:e.enabled?h(`toolGuard.ruleOn`,null,`已启用`):h(`toolGuard.ruleOff`,null,`已停用`)})]}),(0,L.jsxs)(o,{spacing:6,children:[(0,L.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,L.jsx)(p,{}),disabled:!r||t===0,onClick:()=>m(-1),children:h(`toolGuard.moveUp`,null,`上移`)}),(0,L.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,L.jsx)(g,{}),disabled:!r||t===n-1,onClick:()=>m(1),children:h(`toolGuard.moveDown`,null,`下移`)}),(0,L.jsx)(l,{size:`small`,type:`danger`,theme:`borderless`,icon:(0,L.jsx)(s,{}),disabled:!r,onClick:c,children:h(`toolGuard.deleteRule`,null,`删除`)})]})]}),(0,L.jsxs)(`div`,{className:`tool-guard-editor-grid`,children:[(0,L.jsxs)(`label`,{className:`tool-guard-field`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.ruleName`,null,`规则名称`)}),(0,L.jsx)(d,{value:e.name,maxLength:200,disabled:!r,onChange:e=>a({name:e}),placeholder:h(`toolGuard.ruleName`,null,`规则名称`)})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.pattern`,null,`匹配正则(RE2)`)}),(0,L.jsx)(u,{value:e.pattern,rows:3,spellCheck:!1,disabled:!r,onChange:e=>a({pattern:e}),className:`tool-guard-mono`,placeholder:`(?i)(169\\\\.254\\\\.169\\\\.254|metadata\\\\.google\\\\.internal)`})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.message`,null,`拦截提醒`)}),(0,L.jsx)(u,{value:e.message,rows:2,disabled:!r,onChange:e=>a({message:e}),placeholder:h(`toolGuard.defaultPreview`,null,`命中后使用默认拦截提醒`)}),(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.messageHint`,null,`拦截提醒可使用 {match}(匹配文本)、{tool}(工具名称)、{rule}(规则名称)。`)})]})]}),(0,L.jsx)(V,{config:null,rule:e,compact:!0,disabled:!i})]})}var{Text:W}=a;function G(){let e=v(),{hasPermission:t}=y(),n=t(`config:read`),i=t(`config:write`),[a,s]=(0,D.useState)(null),[u,d]=(0,D.useState)(null),[p,g]=(0,D.useState)(``),[O,k]=(0,D.useState)(n),[N,I]=(0,D.useState)(null),[R,z]=(0,D.useState)(null),[B,H]=(0,D.useState)(!1),[G,K]=(0,D.useState)(!1),[q,J]=(0,D.useState)([]),Y=(0,D.useCallback)(async()=>{if(n){k(!0),I(null),K(!1);try{let e=await b.raw(`/tool-guard`),t=e.headers.get(`ETag`)||``,n=j(await e.json());s(n),d(A(n)),g(t)}catch(e){I(e)}finally{k(!1)}}},[n]);(0,D.useEffect)(()=>{Y()},[Y]);let X=(0,D.useMemo)(()=>ee(a,u),[a,u]),Z=a?.rules?.length||0,Q=a?.rules?.filter(e=>e.enabled).length||0,$=()=>{X?E({title:e(`toolGuard.reloadTitle`,null,`重新加载拦截配置`),content:e(`toolGuard.reloadConfirm`,null,`当前有未保存修改,重新加载会丢弃这些修改。确认继续?`),okText:e(`common.confirm`,null,`确定`),onOk:Y}):Y()},te=(e,t)=>{i&&(s(n=>({...n,rules:n.rules.map((n,r)=>r===e?{...n,...t}:n)})),z(null))},ne=()=>{if(!i||!a)return;if(a.rules.length>=100){x(e(`toolGuard.tooManyRules`,null,`最多可配置 100 条拦截规则`));return}let t=M();s(n=>({...n,rules:[...n.rules,{id:t,name:``,enabled:!0,pattern:``,message:e(`toolGuard.defaultMessage`,null,`识别到 {match},调用被规则「{rule}」拦截。请检查目标与操作后重试。`)}]})),J(e=>[...e,t]),z(null)},re=e=>{i&&a&&(s(t=>({...t,rules:t.rules.filter((t,n)=>n!==e)})),z(null))},ie=(e,t)=>{if(!i||!a)return;let n=e+t;n<0||n>=a.rules.length||(s(t=>{let r=[...t.rules],[i]=r.splice(e,1);return r.splice(n,0,i),{...t,rules:r}}),z(null))};return n?(0,L.jsxs)(`div`,{className:`tool-guard-page`,children:[(0,L.jsx)(w,{title:e(`toolGuard.title`,null,`调用拦截`),description:e(`toolGuard.description`,null,`在 MCP 工具执行前检查工具名称和参数,命中规则立即阻止调用。人机协同审批和工具白名单不会跳过此检查。`),extra:(0,L.jsxs)(o,{children:[(0,L.jsx)(c,{size:`small`,color:X?`amber`:`green`,children:B?e(`toolGuard.loading`,null,`处理中…`):X?e(`toolGuard.unsaved`,null,`有未保存修改`):e(`toolGuard.savedState`,null,`已与服务端同步`)}),(0,L.jsx)(l,{onClick:()=>{i&&u&&(s(A(u)),z(null),K(!1))},disabled:!i||!X||B,children:e(`toolGuard.reset`,null,`撤销修改`)}),(0,L.jsx)(l,{icon:(0,L.jsx)(_,{}),onClick:$,loading:O,disabled:B,children:e(`common.refresh`,null,`刷新`)}),(0,L.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,L.jsx)(r,{}),loading:B,disabled:!i||!X,onClick:async()=>{if(!i||!a||!X)return;let t=P(a);if(t){if(z(Error(t.message)),t.index>=0){let e=a.rules[t.index];e&&J(t=>t.includes(e.id)?t:[...t,e.id])}}else if(!p)z(Error(e(`toolGuard.versionRequired`,null,`缺少调用拦截配置版本,请刷新页面后重试。`)));else{H(!0),z(null),K(!1);try{let t=await b.raw(`/tool-guard`,{method:`PUT`,body:F(a),headers:{"If-Match":p}}),n=t.headers.get(`ETag`)||p,r=j(await t.json());s(r),d(A(r)),g(n),T(e(`toolGuard.saveSuccess`,null,`调用拦截配置已保存,后续工具调用将使用新配置。`))}catch(t){let n=t?.payload?.code;n===`tool_guard_conflict`||n===`tool_guard_version_required`?(K(!0),z(Error(t.message))):z(t),x(t,e(`toolGuard.saveFailed`,null,`保存失败`))}finally{H(!1)}}},children:e(`toolGuard.save`,null,`保存并生效`)})]})}),O&&!a&&(0,L.jsx)(C,{title:e(`toolGuard.loading`,null,`处理中…`),children:(0,L.jsx)(W,{type:`tertiary`,children:`…`})}),(0,L.jsx)(S,{error:N,onRetry:Y}),(0,L.jsx)(S,{error:R,onRetry:G?$:void 0}),a&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(C,{title:e(`toolGuard.policyTitle`,null,`拦截策略`),description:e(`toolGuard.enableHint`,null,`在工具执行前检查风险,修改后保存生效。`),children:(0,L.jsxs)(`div`,{className:`tool-guard-policy`,children:[(0,L.jsxs)(o,{spacing:10,align:`center`,children:[(0,L.jsx)(f,{checked:a.enabled,disabled:!i||B,onChange:e=>{s(t=>({...t,enabled:e})),z(null)},"aria-label":e(`toolGuard.enabled`,null,`启用调用拦截`)}),(0,L.jsx)(W,{strong:!0,children:e(`toolGuard.enabled`,null,`启用调用拦截`)}),(0,L.jsx)(c,{size:`small`,color:a.enabled?`green`:`grey`,children:a.enabled?e(`toolGuard.protectionOn`,null,`调用拦截已开启`):e(`toolGuard.protectionOff`,null,`调用拦截已关闭`)}),(0,L.jsx)(c,{size:`small`,color:`blue`,children:e(`toolGuard.ruleCount`,{enabled:Q,total:Z},`${Q} / ${Z} 条规则已启用`)})]}),(0,L.jsx)(W,{type:`tertiary`,size:`small`,children:e(`toolGuard.scopeHint`,null,`正则仅检查调用中可见的文本;不会解析 IP 归属、重定向目标或工具读取的文件内容。`)})]})}),(0,L.jsxs)(C,{title:e(`toolGuard.rulesTitle`,null,`拦截规则`),description:e(`toolGuard.rulesHint`,null,`按顺序匹配已启用的规则,使用首条命中规则的提醒。正则采用 RE2 语法,保存和试运行时由服务端校验。`),extra:(0,L.jsx)(l,{icon:(0,L.jsx)(m,{}),disabled:!i||B||Z>=100,onClick:ne,children:e(`toolGuard.addRule`,null,`添加规则`)}),children:[Z===0&&(0,L.jsx)(W,{type:`tertiary`,children:e(`toolGuard.emptyRules`,null,`暂无规则。添加规则后保存,即可启用对应的拦截措施。`)}),Z>0&&(0,L.jsx)(h,{activeKey:q,onChange:e=>J([].concat(e)),keepDOM:!1,children:a.rules.map((t,n)=>(0,L.jsx)(h.Panel,{itemKey:t.id,header:(0,L.jsxs)(o,{spacing:8,align:`center`,children:[(0,L.jsx)(`span`,{className:`tool-guard-rule-number`,children:String(n+1).padStart(2,`0`)}),(0,L.jsx)(W,{strong:!0,children:t.name.trim()||e(`toolGuard.unnamedRule`,null,`未命名规则`)}),(0,L.jsx)(c,{size:`small`,color:t.enabled?`green`:`grey`,children:t.enabled?e(`toolGuard.ruleOn`,null,`已启用`):e(`toolGuard.ruleOff`,null,`已停用`)}),(()=>{let n=u?.rules?.find(e=>e.id===t.id);return n?JSON.stringify(n)===JSON.stringify(t)?null:(0,L.jsx)(c,{size:`small`,color:`amber`,children:e(`toolGuard.ruleModified`,null,`已修改`)}):(0,L.jsx)(c,{size:`small`,color:`blue`,children:e(`toolGuard.ruleNew`,null,`新增`)})})()]}),children:(0,L.jsx)(U,{rule:t,index:n,total:Z,canWrite:i&&!B,canTest:!B,onChange:e=>te(n,e),onDelete:()=>re(n),onMove:e=>ie(n,e)})},t.id))}),(0,L.jsx)(W,{type:`tertiary`,size:`small`,children:e(`toolGuard.listHint`,null,`点击规则查看和编辑,按列表顺序匹配。`)})]}),(0,L.jsx)(C,{title:e(`toolGuard.testTitle`,null,`全部规则验证`),description:e(`toolGuard.testHint`,null,`使用页面上的当前配置(包括未保存修改),仅检查匹配结果,不执行任何工具。`),children:(0,L.jsx)(V,{config:a,disabled:B})})]})]}):(0,L.jsxs)(`div`,{className:`tool-guard-page`,children:[(0,L.jsx)(w,{title:e(`toolGuard.title`,null,`调用拦截`)}),(0,L.jsx)(S,{error:Error(e(`toolGuard.noPermission`,null,`当前账号缺少 config:read 权限,无法读取拦截配置。`))})]})}export{G as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{$ as r,B as i,G as a,I as o,Lt as s,N as c,R as l,S as u,U as d,d as f,en as p,ft as m,j as h,nn as g,ut as _}from"./semi-65W_4I1v.js";import{F as v,I as y,L as b,b as x,l as S,m as C,p as w,x as T,y as E}from"./index-DNMXun-U.js";var D=e(t(),1),O=200,k=4096;function A(e){return JSON.parse(JSON.stringify(e))}function j(e){if(!e||typeof e.enabled!=`boolean`||e.rules!=null&&!Array.isArray(e.rules))throw Error(`服务端返回的配置格式不正确`);return{enabled:e.enabled,rules:(e.rules||[]).map(e=>({id:String(e.id||``),name:String(e.name||``),enabled:!!e.enabled,pattern:String(e.pattern||``),message:String(e.message||``)}))}}function M(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`rule-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function N(e){return new TextEncoder().encode(String(e||``)).length}function P(e){if(!e)return{index:-1,field:``,message:`请先加载拦截配置`};if(e.rules.length>100)return{index:-1,field:``,message:`最多可配置 100 条拦截规则`};for(let t=0;tO)return{index:t,field:`name`,message:`第 ${t+1} 条规则名称超过 ${O} 字节`};if(N(n.pattern)>k)return{index:t,field:`pattern`,message:`第 ${t+1} 条规则正则超过 ${k} 字节`};if(N(n.message)>k)return{index:t,field:`message`,message:`第 ${t+1} 条规则提醒超过 ${k} 字节`}}return null}function ee(e,t){return!e||!t?!1:JSON.stringify(e)!==JSON.stringify(t)}function F(e){return{enabled:!!e?.enabled,rules:(e?.rules||[]).map(e=>({id:e.id,name:e.name,enabled:!!e.enabled,pattern:e.pattern,message:e.message}))}}function I(e){return{enabled:!0,rules:[{id:e.id,name:e.name,enabled:!0,pattern:e.pattern,message:e.message}]}}var L=e(n(),1),{Text:R}=a,z=`http_request`,B=`{"url": "https://example.gov.cn"}`;function V({config:e,rule:t=null,disabled:n=!1,compact:r=!1}){let a=v(),s=!!t,[f,p]=(0,D.useState)(z),[m,h]=(0,D.useState)(B),[g,_]=(0,D.useState)(!1),[y,x]=(0,D.useState)(null),[C,w]=(0,D.useState)(null),T=async()=>{if(n||g)return;if(w(null),x(null),!s&&!e){w(Error(a(`toolGuard.loadFirst`,null,`请先加载拦截配置`)));return}if(!f.trim()){w(Error(a(`toolGuard.toolRequired`,null,`请填写测试工具名称`)));return}let r;try{if(r=JSON.parse(m),!r||Array.isArray(r)||typeof r!=`object`)throw Error(`not an object`)}catch{w(Error(a(`toolGuard.invalidArguments`,null,`工具参数必须是有效的 JSON 对象`)));return}_(!0);try{let n={config:s?I(t):F(e),toolName:f.trim(),arguments:r},i=await b.post(`/tool-guard/test`,n);if(!i||typeof i.blocked!=`boolean`)throw Error(a(`toolGuard.invalidTestResponse`,null,`服务端返回的测试结果格式不正确`));x(i)}catch(e){w(e)}finally{_(!1)}},E=y?.blocked,O=y?.match,k=!s&&e&&e.enabled===!1;return(0,L.jsxs)(`div`,{className:r?`tool-guard-test tool-guard-test-compact`:`tool-guard-test`,children:[(0,L.jsxs)(o,{vertical:!0,spacing:6,align:`start`,children:[(0,L.jsx)(R,{strong:!0,children:s?a(`toolGuard.testScopeSingle`,{name:t.name||a(`toolGuard.unnamedRule`,null,`未命名规则`)},`单条验证:${t.name||`未命名规则`}`):a(`toolGuard.testScopeAll`,null,`全部规则验证`)}),(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:s?a(`toolGuard.testSingleHint`,null,`仅验证本条规则,忽略总开关和规则启停;不保存、不执行工具。`):a(`toolGuard.testAllHint`,null,`按当前顺序与启停状态验证全部规则,不保存、不执行工具。`)})]}),(0,L.jsxs)(`div`,{className:`tool-guard-test-form`,children:[(0,L.jsxs)(`label`,{className:`tool-guard-field`,children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testTool`,null,`工具名称`)}),(0,L.jsx)(d,{value:f,onChange:e=>{p(e),x(null)},placeholder:`http_request`})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testArguments`,null,`工具参数(JSON 对象)`)}),(0,L.jsx)(u,{value:m,onChange:e=>{h(e),x(null)},rows:3,spellCheck:!1,className:`tool-guard-args`})]})]}),(0,L.jsx)(l,{theme:`solid`,type:`primary`,loading:g,disabled:n,onClick:T,className:`tool-guard-test-run`,children:g?a(`toolGuard.testing`,null,`验证中…`):a(`toolGuard.test`,null,`测试匹配`)}),(0,L.jsx)(S,{error:C}),y&&(0,L.jsxs)(`div`,{className:`tool-guard-test-result ${E?`is-blocked`:`is-pass`}`,children:[(0,L.jsxs)(o,{spacing:8,wrap:!0,children:[(0,L.jsx)(c,{color:E?`red`:k?`grey`:`green`,size:`small`,children:E?`blocked`:`passed`}),(0,L.jsx)(R,{strong:!0,children:s?E?a(`toolGuard.singleMatched`,null,`本条规则匹配成功`):a(`toolGuard.singleNotMatched`,null,`本条规则未匹配`):E?a(`toolGuard.blocked`,null,`已命中规则:将阻止调用`):k?a(`toolGuard.disabledResult`,null,`调用拦截已关闭:此配置不会阻止调用`):a(`toolGuard.notBlocked`,null,`未命中已启用的规则`)})]}),s&&(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.singleResultHint`,null,`这是单条规则验证结果,实际拦截还取决于总开关、规则启停和匹配顺序。`)}),E&&O&&(0,L.jsxs)(`div`,{className:`tool-guard-match`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedRule`,null,`命中规则`)}),(0,L.jsx)(`div`,{children:O.ruleName||O.ruleId||`—`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedText`,null,`匹配文本`)}),(0,L.jsx)(`pre`,{children:O.matchedText||`—`})]}),(0,L.jsxs)(`div`,{children:[(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.matchedMessage`,null,`返回的拦截提醒`)}),(0,L.jsx)(`div`,{children:O.message||`—`})]})]})]}),!y&&!C&&(0,L.jsx)(R,{type:`tertiary`,size:`small`,children:a(`toolGuard.testReadyHint`,null,`点击「测试匹配」,在这里查看验证结果。`)}),s===!1&&!y&&!C&&k&&(0,L.jsx)(i,{type:`info`,bordered:!0,closeIcon:null,description:a(`toolGuard.disabledResult`,null,`调用拦截已关闭:此配置不会阻止调用`)})]})}var{Text:H}=a;function U({rule:e,index:t,total:n,canWrite:r,canTest:i,onChange:a,onDelete:c,onMove:m}){let h=v();return(0,L.jsxs)(`div`,{className:`tool-guard-rule-body`,children:[(0,L.jsxs)(`div`,{className:`tool-guard-rule-toolbar`,children:[(0,L.jsxs)(o,{spacing:8,children:[(0,L.jsx)(f,{size:`small`,checked:e.enabled,disabled:!r,onChange:e=>a({enabled:e}),"aria-label":h(`toolGuard.ruleEnabled`,null,`启用`)}),(0,L.jsx)(H,{size:`small`,type:`tertiary`,children:e.enabled?h(`toolGuard.ruleOn`,null,`已启用`):h(`toolGuard.ruleOff`,null,`已停用`)})]}),(0,L.jsxs)(o,{spacing:6,children:[(0,L.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,L.jsx)(p,{}),disabled:!r||t===0,onClick:()=>m(-1),children:h(`toolGuard.moveUp`,null,`上移`)}),(0,L.jsx)(l,{size:`small`,theme:`borderless`,icon:(0,L.jsx)(g,{}),disabled:!r||t===n-1,onClick:()=>m(1),children:h(`toolGuard.moveDown`,null,`下移`)}),(0,L.jsx)(l,{size:`small`,type:`danger`,theme:`borderless`,icon:(0,L.jsx)(s,{}),disabled:!r,onClick:c,children:h(`toolGuard.deleteRule`,null,`删除`)})]})]}),(0,L.jsxs)(`div`,{className:`tool-guard-editor-grid`,children:[(0,L.jsxs)(`label`,{className:`tool-guard-field`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.ruleName`,null,`规则名称`)}),(0,L.jsx)(d,{value:e.name,maxLength:200,disabled:!r,onChange:e=>a({name:e}),placeholder:h(`toolGuard.ruleName`,null,`规则名称`)})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.pattern`,null,`匹配正则(RE2)`)}),(0,L.jsx)(u,{value:e.pattern,rows:3,spellCheck:!1,disabled:!r,onChange:e=>a({pattern:e}),className:`tool-guard-mono`,placeholder:`(?i)(169\\\\.254\\\\.169\\\\.254|metadata\\\\.google\\\\.internal)`})]}),(0,L.jsxs)(`label`,{className:`tool-guard-field tool-guard-field-wide`,children:[(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.message`,null,`拦截提醒`)}),(0,L.jsx)(u,{value:e.message,rows:2,disabled:!r,onChange:e=>a({message:e}),placeholder:h(`toolGuard.defaultPreview`,null,`命中后使用默认拦截提醒`)}),(0,L.jsx)(H,{type:`tertiary`,size:`small`,children:h(`toolGuard.messageHint`,null,`拦截提醒可使用 {match}(匹配文本)、{tool}(工具名称)、{rule}(规则名称)。`)})]})]}),(0,L.jsx)(V,{config:null,rule:e,compact:!0,disabled:!i})]})}var{Text:W}=a;function G(){let e=v(),{hasPermission:t}=y(),n=t(`config:read`),i=t(`config:write`),[a,s]=(0,D.useState)(null),[u,d]=(0,D.useState)(null),[p,g]=(0,D.useState)(``),[O,k]=(0,D.useState)(n),[N,I]=(0,D.useState)(null),[R,z]=(0,D.useState)(null),[B,H]=(0,D.useState)(!1),[G,K]=(0,D.useState)(!1),[q,J]=(0,D.useState)([]),Y=(0,D.useCallback)(async()=>{if(n){k(!0),I(null),K(!1);try{let e=await b.raw(`/tool-guard`),t=e.headers.get(`ETag`)||``,n=j(await e.json());s(n),d(A(n)),g(t)}catch(e){I(e)}finally{k(!1)}}},[n]);(0,D.useEffect)(()=>{Y()},[Y]);let X=(0,D.useMemo)(()=>ee(a,u),[a,u]),Z=a?.rules?.length||0,Q=a?.rules?.filter(e=>e.enabled).length||0,$=()=>{X?E({title:e(`toolGuard.reloadTitle`,null,`重新加载拦截配置`),content:e(`toolGuard.reloadConfirm`,null,`当前有未保存修改,重新加载会丢弃这些修改。确认继续?`),okText:e(`common.confirm`,null,`确定`),onOk:Y}):Y()},te=(e,t)=>{i&&(s(n=>({...n,rules:n.rules.map((n,r)=>r===e?{...n,...t}:n)})),z(null))},ne=()=>{if(!i||!a)return;if(a.rules.length>=100){x(e(`toolGuard.tooManyRules`,null,`最多可配置 100 条拦截规则`));return}let t=M();s(n=>({...n,rules:[...n.rules,{id:t,name:``,enabled:!0,pattern:``,message:e(`toolGuard.defaultMessage`,null,`识别到 {match},调用被规则「{rule}」拦截。请检查目标与操作后重试。`)}]})),J(e=>[...e,t]),z(null)},re=e=>{i&&a&&(s(t=>({...t,rules:t.rules.filter((t,n)=>n!==e)})),z(null))},ie=(e,t)=>{if(!i||!a)return;let n=e+t;n<0||n>=a.rules.length||(s(t=>{let r=[...t.rules],[i]=r.splice(e,1);return r.splice(n,0,i),{...t,rules:r}}),z(null))};return n?(0,L.jsxs)(`div`,{className:`tool-guard-page`,children:[(0,L.jsx)(w,{title:e(`toolGuard.title`,null,`调用拦截`),description:e(`toolGuard.description`,null,`在 MCP 工具执行前检查工具名称和参数,命中规则立即阻止调用。人机协同审批和工具白名单不会跳过此检查。`),extra:(0,L.jsxs)(o,{children:[(0,L.jsx)(c,{size:`small`,color:X?`amber`:`green`,children:B?e(`toolGuard.loading`,null,`处理中…`):X?e(`toolGuard.unsaved`,null,`有未保存修改`):e(`toolGuard.savedState`,null,`已与服务端同步`)}),(0,L.jsx)(l,{onClick:()=>{i&&u&&(s(A(u)),z(null),K(!1))},disabled:!i||!X||B,children:e(`toolGuard.reset`,null,`撤销修改`)}),(0,L.jsx)(l,{icon:(0,L.jsx)(_,{}),onClick:$,loading:O,disabled:B,children:e(`common.refresh`,null,`刷新`)}),(0,L.jsx)(l,{theme:`solid`,type:`primary`,icon:(0,L.jsx)(r,{}),loading:B,disabled:!i||!X,onClick:async()=>{if(!i||!a||!X)return;let t=P(a);if(t){if(z(Error(t.message)),t.index>=0){let e=a.rules[t.index];e&&J(t=>t.includes(e.id)?t:[...t,e.id])}}else if(!p)z(Error(e(`toolGuard.versionRequired`,null,`缺少调用拦截配置版本,请刷新页面后重试。`)));else{H(!0),z(null),K(!1);try{let t=await b.raw(`/tool-guard`,{method:`PUT`,body:F(a),headers:{"If-Match":p}}),n=t.headers.get(`ETag`)||p,r=j(await t.json());s(r),d(A(r)),g(n),T(e(`toolGuard.saveSuccess`,null,`调用拦截配置已保存,后续工具调用将使用新配置。`))}catch(t){let n=t?.payload?.code;n===`tool_guard_conflict`||n===`tool_guard_version_required`?(K(!0),z(Error(t.message))):z(t),x(t,e(`toolGuard.saveFailed`,null,`保存失败`))}finally{H(!1)}}},children:e(`toolGuard.save`,null,`保存并生效`)})]})}),O&&!a&&(0,L.jsx)(C,{title:e(`toolGuard.loading`,null,`处理中…`),children:(0,L.jsx)(W,{type:`tertiary`,children:`…`})}),(0,L.jsx)(S,{error:N,onRetry:Y}),(0,L.jsx)(S,{error:R,onRetry:G?$:void 0}),a&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(C,{title:e(`toolGuard.policyTitle`,null,`拦截策略`),description:e(`toolGuard.enableHint`,null,`在工具执行前检查风险,修改后保存生效。`),children:(0,L.jsxs)(`div`,{className:`tool-guard-policy`,children:[(0,L.jsxs)(o,{spacing:10,align:`center`,children:[(0,L.jsx)(f,{checked:a.enabled,disabled:!i||B,onChange:e=>{s(t=>({...t,enabled:e})),z(null)},"aria-label":e(`toolGuard.enabled`,null,`启用调用拦截`)}),(0,L.jsx)(W,{strong:!0,children:e(`toolGuard.enabled`,null,`启用调用拦截`)}),(0,L.jsx)(c,{size:`small`,color:a.enabled?`green`:`grey`,children:a.enabled?e(`toolGuard.protectionOn`,null,`调用拦截已开启`):e(`toolGuard.protectionOff`,null,`调用拦截已关闭`)}),(0,L.jsx)(c,{size:`small`,color:`blue`,children:e(`toolGuard.ruleCount`,{enabled:Q,total:Z},`${Q} / ${Z} 条规则已启用`)})]}),(0,L.jsx)(W,{type:`tertiary`,size:`small`,children:e(`toolGuard.scopeHint`,null,`正则仅检查调用中可见的文本;不会解析 IP 归属、重定向目标或工具读取的文件内容。`)})]})}),(0,L.jsxs)(C,{title:e(`toolGuard.rulesTitle`,null,`拦截规则`),description:e(`toolGuard.rulesHint`,null,`按顺序匹配已启用的规则,使用首条命中规则的提醒。正则采用 RE2 语法,保存和试运行时由服务端校验。`),extra:(0,L.jsx)(l,{icon:(0,L.jsx)(m,{}),disabled:!i||B||Z>=100,onClick:ne,children:e(`toolGuard.addRule`,null,`添加规则`)}),children:[Z===0&&(0,L.jsx)(W,{type:`tertiary`,children:e(`toolGuard.emptyRules`,null,`暂无规则。添加规则后保存,即可启用对应的拦截措施。`)}),Z>0&&(0,L.jsx)(h,{activeKey:q,onChange:e=>J([].concat(e)),keepDOM:!1,children:a.rules.map((t,n)=>(0,L.jsx)(h.Panel,{itemKey:t.id,header:(0,L.jsxs)(o,{spacing:8,align:`center`,children:[(0,L.jsx)(`span`,{className:`tool-guard-rule-number`,children:String(n+1).padStart(2,`0`)}),(0,L.jsx)(W,{strong:!0,children:t.name.trim()||e(`toolGuard.unnamedRule`,null,`未命名规则`)}),(0,L.jsx)(c,{size:`small`,color:t.enabled?`green`:`grey`,children:t.enabled?e(`toolGuard.ruleOn`,null,`已启用`):e(`toolGuard.ruleOff`,null,`已停用`)}),(()=>{let n=u?.rules?.find(e=>e.id===t.id);return n?JSON.stringify(n)===JSON.stringify(t)?null:(0,L.jsx)(c,{size:`small`,color:`amber`,children:e(`toolGuard.ruleModified`,null,`已修改`)}):(0,L.jsx)(c,{size:`small`,color:`blue`,children:e(`toolGuard.ruleNew`,null,`新增`)})})()]}),children:(0,L.jsx)(U,{rule:t,index:n,total:Z,canWrite:i&&!B,canTest:!B,onChange:e=>te(n,e),onDelete:()=>re(n),onMove:e=>ie(n,e)})},t.id))}),(0,L.jsx)(W,{type:`tertiary`,size:`small`,children:e(`toolGuard.listHint`,null,`点击规则查看和编辑,按列表顺序匹配。`)})]}),(0,L.jsx)(C,{title:e(`toolGuard.testTitle`,null,`全部规则验证`),description:e(`toolGuard.testHint`,null,`使用页面上的当前配置(包括未保存修改),仅检查匹配结果,不执行任何工具。`),children:(0,L.jsx)(V,{config:a,disabled:B})})]})]}):(0,L.jsxs)(`div`,{className:`tool-guard-page`,children:[(0,L.jsx)(w,{title:e(`toolGuard.title`,null,`调用拦截`)}),(0,L.jsx)(S,{error:Error(e(`toolGuard.noPermission`,null,`当前账号缺少 config:read 权限,无法读取拦截配置。`))})]})}export{G as default}; \ No newline at end of file diff --git a/web/static/app/assets/vulnerabilities-CXGKZewN.js b/web/static/app/assets/vulnerabilities-BRH58_rp.js similarity index 99% rename from web/static/app/assets/vulnerabilities-CXGKZewN.js rename to web/static/app/assets/vulnerabilities-BRH58_rp.js index 878fdb0c..4465acbc 100644 --- a/web/static/app/assets/vulnerabilities-CXGKZewN.js +++ b/web/static/app/assets/vulnerabilities-BRH58_rp.js @@ -1,2 +1,2 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{G as a,I as o,Lt as s,N as c,Ot as l,Pt as u,R as d,U as f,W as p,a as m,c as h,ft as g,h as _,i as v,j as y,lt as b,m as x,p as ee,pt as te,s as ne,ut as re,y as S}from"./semi-65W_4I1v.js";import{C as ie,E as C,F as ae,I as oe,L as w,R as se,S as ce,_ as le,a as ue,b as T,c as E,d as de,f as D,h as O,l as fe,m as pe,n as me,o as k,p as A,s as j,v as he,x as M,y as ge,z as N}from"./index-CAEPLS-g.js";import{r as _e}from"./retest-EzTZPjnQ.js";import{t as P}from"./project-options-CMQbwv_U.js";var F=e(t(),1),ve=[`critical`,`high`,`medium`,`low`,`info`],I=[`open`,`confirmed`,`fixed`,`ignored`,`false_positive`],ye=[`q`,`severity`,`status`,`archived`,`project_id`,`conversation_tag`,`task_tag`,`assessment_id`],be=[10,20,50,100],xe={critical:`dashboard.severityCritical`,high:`dashboard.severityHigh`,medium:`dashboard.severityMedium`,low:`dashboard.severityLow`,info:`dashboard.severityInfo`},Se={open:`vulnerabilityPage.statusOpen`,confirmed:`vulnerabilityPage.statusConfirmed`,fixed:`vulnerabilityPage.statusFixed`,ignored:`vulnerabilityPage.statusIgnored`,false_positive:`vulnerabilityPage.statusFalsePositive`},Ce={open:`待处理`,confirmed:`已确认`,fixed:`已修复`,ignored:`已忽略`,false_positive:`误报`},L={retest:`复测结果`,retest_started:`复测分支已创建`,merge:`归并上报`,split:`拆分归并组`,detach:`解除关联`},R=[{value:``,key:`vulnerabilityPage.sortDefault`,fallback:`默认顺序`},{value:`severity`,key:`vulnerabilityPage.sortSeverity`,fallback:`高危优先`},{value:`latest`,key:`vulnerabilityPage.sortLatest`,fallback:`创建时间:最新优先`},{value:`oldest`,key:`vulnerabilityPage.sortOldest`,fallback:`创建时间:最早优先`}];function we(e,t){if(!t)return`—`;let n=xe[t];return n?e(n,null,ie[t]||t):String(t)}function z(e,t){if(!t)return`—`;let n=Se[t];return n?e(n,null,Ce[t]||t):String(t)}function Te(e,t){return t?e(`vulnerabilityPage.history_${t}`,null,L[t]||t):`—`}function Ee(e){return ve.map(t=>({value:t,label:we(e,t)}))}function B(e){return I.map(t=>({value:t,label:z(e,t)}))}function De(e){return R.map(t=>({value:t.value,label:e(t.key,null,t.fallback)}))}function Oe(e){let t={};return ye.forEach(n=>{let r=String(e?.[n]??``).trim();r&&(t[n]=r)}),t}function ke(e){let t=Oe(e);return delete t.severity,t}function Ae(e){return ye.some(t=>String(e?.[t]??``).trim()!==``)}function je(e,t){let n=Number(e)||0,r=Number(t)||0;return r>0?Math.round(n/r*100):0}function Me(e){return String(e?.target||``).trim()}function V(e){return(Array.isArray(e?.targets)?e.targets:[]).map(e=>e?.host).find(Boolean)||e?.target_host||e?.target_domain||``}function H(e){if(!e)return`—`;let t=e.host||e.id||`—`;return e.port?`${t}:${e.port}`:t}function U(e,t=8){let n=String(e||``);return n.length>t?`${n.slice(0,t)}…`:n}function Ne(e,t){let n=new Blob([t],{type:`text/markdown;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);return i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3),e}var W=e(r(),1);function G(e,t){return[{value:``,label:e},...t]}function Pe({t:e,filters:t,options:n,projectOptions:r,hasGroupFilters:i,onChange:a,onReset:o}){let s=(0,F.useId)(),[c,l]=(0,F.useState)(t.q),u=me(c,380),p=(0,F.useRef)(t.q);(0,F.useEffect)(()=>{u!==p.current&&(p.current=u,a(`q`,u))},[u,a]),(0,F.useEffect)(()=>{t.q!==p.current&&(p.current=t.q,l(t.q))},[t.q]);let m=Array.isArray(n?.conversation_tags)?n.conversation_tags:[],h=Array.isArray(n?.task_tags)?n.task_tags:[],g=Array.isArray(n?.assessment_ids)?n.assessment_ids:[];return(0,W.jsxs)(`div`,{className:`vulnerability-filter-bar`,children:[(0,W.jsx)(f,{className:`vulnerability-filter-search`,prefix:(0,W.jsx)(b,{}),value:c,showClear:!0,placeholder:e(`vulnerabilityPage.searchKeyword`,null,`搜索标题、描述、类型、目标…`),"aria-label":e(`vulnerabilityPage.searchKeyword`,null,`搜索标题、描述、类型、目标…`),onChange:e=>l(e)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.severity,placeholder:e(`vulnerabilityPage.severity`,null,`严重程度`),optionList:G(e(`vulnerabilityPage.allSeverities`,null,`全部级别`),Ee(e)),onChange:e=>a(`severity`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.status,placeholder:e(`vulnerabilityPage.status`,null,`状态`),optionList:G(e(`dashboard.allStatuses`,null,`全部状态`),B(e)),onChange:e=>a(`status`,e||``)}),(0,W.jsx)(`span`,{id:s,hidden:!0,children:e(`vulnerabilityPage.archiveStatus`,null,`归档状态`)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.archived,"aria-labelledby":s,optionList:[{value:``,label:e(`vulnerabilityPage.unarchived`,null,`未归档`)},{value:`true`,label:e(`projects.statusArchived`,null,`已归档`)},{value:`all`,label:e(`vulnerabilityPage.allArchiveStates`,null,`全部归档状态`)}],onChange:e=>a(`archived`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select vulnerability-filter-select--wide`,value:t.project_id,placeholder:e(`vulnerabilityPage.detailProject`,null,`所属项目`),filter:!0,optionList:G(e(`vulnerabilityPage.allProjects`,null,`全部项目`),r),onChange:e=>a(`project_id`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.conversation_tag,placeholder:e(`vulnerabilityPage.conversationTag`,null,`来源(对话标签)`),filter:!0,optionList:G(e(`vulnerabilityPage.allSources`,null,`全部来源`),m.map(e=>({value:e,label:e}))),onChange:e=>a(`conversation_tag`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.task_tag,placeholder:e(`vulnerabilityPage.taskTag`,null,`任务标签`),filter:!0,optionList:G(e(`vulnerabilityPage.allTaskTags`,null,`全部任务标签`),h.map(e=>({value:e,label:e}))),onChange:e=>a(`task_tag`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.assessment_id,placeholder:e(`vulnerabilityPage.assessmentTask`,null,`深度测评`),filter:!0,optionList:G(e(`vulnerabilityPage.allAssessments`,null,`全部测评`),g.map(e=>({value:e,label:U(e,12)}))),onChange:e=>a(`assessment_id`,e||``)}),(0,W.jsx)(`div`,{className:`vulnerability-filter-actions`,children:(0,W.jsx)(d,{icon:(0,W.jsx)(re,{}),theme:`borderless`,disabled:!Ae(t)&&!t.sort&&!i,onClick:o,children:e(`vulnerabilityPage.clearAll`,null,`重置全部`)})})]})}var{Text:K}=a,Fe={critical:`red`,high:`orange`,medium:`amber`,low:`blue`,info:`grey`};function Ie(e,t){return t.key.startsWith(`task:`)?e(`vulnerabilityPage.viewTaskGroup`,{id:t.label||t.key.slice(5)}):t.label?t.label:t.key.startsWith(`host:`)?e(`vulnerabilityPage.unknownHost`):t.key.startsWith(`queue:`)?e(`vulnerabilityPage.taskQueueGroup`,{id:t.key.slice(6)}):t.key.startsWith(`assessment:`)?t.key.slice(11):e(`vulnerabilityPage.viewNoTask`)}function Le(e,t){let n=Ie(e,t),r=!!t.children?.length;return{key:t.key,value:t.key,label:(0,W.jsxs)(`span`,{className:`vulnerability-group-node`,children:[(0,W.jsx)(`span`,{className:r?`vulnerability-group-name vulnerability-group-name--parent`:`vulnerability-group-name`,title:n,children:n}),(0,W.jsx)(c,{size:`small`,color:`grey`,children:t.count})]}),children:t.children?.map(t=>Le(e,t))}}function Re({t:e,mode:t,groups:n,selection:r,loading:i,search:a,onSearch:o,onSelect:s}){let[c,u]=(0,F.useState)(a),d=t===`task`,h=e(d?`vulnerabilityPage.viewTask`:`vulnerabilityPage.viewHost`),g=e(d?`vulnerabilityPage.taskSearch`:`vulnerabilityPage.hostSearch`),{treeData:_,expandedKeys:v}=(0,F.useMemo)(()=>({treeData:[{key:`all`,value:`all`,label:e(d?`vulnerabilityPage.allTasks`:`vulnerabilityPage.allHosts`)},...n.map(t=>Le(e,t))],expandedKeys:n.filter(e=>e.children?.length).map(e=>e.key)}),[e,n,d]);return(0,F.useEffect)(()=>u(a),[a]),(0,F.useEffect)(()=>{if(c.trim()===a)return;let e=setTimeout(()=>o(c.trim()),350);return()=>clearTimeout(e)},[c,a,o]),(0,W.jsxs)(`aside`,{className:`vulnerability-group-sidebar`,"aria-label":h,children:[(0,W.jsx)(K,{strong:!0,children:h}),(0,W.jsx)(f,{prefix:(0,W.jsx)(b,{}),"aria-label":g,placeholder:g,value:c,showClear:!0,onChange:u}),(0,W.jsxs)(p,{spinning:i,wrapperClassName:`vulnerability-group-scroll`,children:[(0,W.jsx)(m,{"aria-label":h,treeData:_,value:r||`all`,onSelect:e=>s(e===`all`?``:e),expandedKeys:v,expandIcon:({className:e})=>(0,W.jsx)(`span`,{className:e,"aria-hidden":`true`,children:(0,W.jsx)(l,{size:`small`})}),expandAction:!1,blockNode:!0}),!n.length&&!i&&(0,W.jsx)(K,{className:`vulnerability-group-empty`,type:`tertiary`,size:`small`,children:e(`vulnerabilityPage.noMatchingGroups`)})]})]})}function ze({t:e,group:t}){return(0,W.jsxs)(`div`,{className:`vulnerability-group-overview`,children:[(0,W.jsx)(K,{strong:!0,className:`vulnerability-group-name`,children:Ie(e,t)}),(0,W.jsxs)(`div`,{className:`vulnerability-group-badges`,children:[ve.filter(e=>t.severities?.[e]).map(n=>(0,W.jsxs)(c,{color:Fe[n],children:[we(e,n),` `,t.severities[n]]},n)),(0,W.jsx)(c,{color:`grey`,children:e(`vulnerabilityPage.groupPending`,{count:t.pending})})]})]})}var{Text:Be}=a;function Ve({record:e}){let t=[e.conversation_tag,e.task_tag].filter(Boolean);return t.length?(0,W.jsx)(`span`,{className:`vulnerability-source-tags`,children:t.map(e=>(0,W.jsx)(c,{size:`small`,color:`blue`,type:`light`,children:e},e))}):e.conversation_id?(0,W.jsx)(Be,{type:`tertiary`,className:`vulnerability-inline-code`,title:e.conversation_id,children:U(e.conversation_id,10)}):(0,W.jsx)(Be,{type:`tertiary`,children:`—`})}function He({t:e,data:t,loading:n,page:r,pageSize:i,total:a,selection:o,onSelectionChange:s,onOpen:c,onEdit:l,onArchive:u,onDelete:f,onDownload:p,sort:m,onSort:h,canWrite:g,canDelete:_,onPageChange:v,onPageSizeChange:y,toolbar:b,onRefresh:x}){let ee=[{title:e(`vulnerabilityPage.tableTitle`,null,`漏洞名称`),dataIndex:`title`,render:(t,n)=>(0,W.jsxs)(`div`,{className:`vulnerability-title-cell`,children:[(0,W.jsx)(`span`,{className:`vulnerability-title-text`,title:n.title,children:n.title||`—`}),(0,W.jsxs)(`span`,{className:`vulnerability-title-meta`,children:[n.type||`—`,n.case_id?` · ${e(`vulnerabilityPage.mergedRecord`,null,`已归并`)}`:``,n.assessment_id?` · ${e(`vulnerabilityPage.assessmentTask`,null,`深度测评`)}`:``,n.archived?` · ${e(`projects.statusArchived`,null,`已归档`)}`:``]})]})},{title:e(`vulnerabilityPage.tableSeverity`,null,`严重度`),dataIndex:`severity`,width:92,render:e=>(0,W.jsx)(O,{severity:e})},{title:e(`vulnerabilityPage.tableStatus`,null,`状态`),dataIndex:`status`,width:100,render:t=>(0,W.jsx)(he,{status:t,label:z(e,t)})},{title:e(`vulnerabilityPage.detailTarget`,null,`目标 / 宿主`),dataIndex:`target`,width:220,render:(e,t)=>{let n=Me(t),r=Array.isArray(t.targets)&&t.targets.length?t.targets.map(e=>e?.host).filter(Boolean).join(`, `):``;return(0,W.jsxs)(`div`,{className:`vulnerability-target-cell`,children:[(0,W.jsx)(`span`,{className:`vulnerability-target-text`,title:n||r,children:n||r||`—`}),n&&r&&r!==n?(0,W.jsx)(`span`,{className:`vulnerability-target-host`,title:r,children:r}):null]})}},{title:e(`vulnerabilityPage.tableSource`,null,`来源`),dataIndex:`conversation_tag`,width:170,render:(e,t)=>(0,W.jsx)(Ve,{record:t})},{title:e(`vulnerabilityPage.tableDate`,null,`创建时间`),dataIndex:`created_at`,width:180,render:e=>(0,W.jsx)(`span`,{className:`vulnerability-time`,children:C(e)})},{title:e(`vulnerabilityPage.tableActions`,null,`操作`),dataIndex:`id`,width:g?250:200,render:(t,n)=>(0,W.jsxs)(`div`,{className:`vulnerability-row-actions`,children:[(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),c(n.id)},children:e(`vulnerabilityPage.rowView`,null,`详情`)}),(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),p(n)},children:e(`vulnerabilityPage.tableDownload`,null,`下载`)}),g&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),l(n)},children:e(`common.edit`,null,`编辑`)}),g&&!n.project_archived&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),u(n)},children:n.archived?e(`projects.restore`,null,`恢复`):e(`projects.archiveProject`,null,`归档`)}),_&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,onClick:e=>{e.stopPropagation(),f(n)},children:e(`common.delete`,null,`删除`)})]})}],te=b?(0,W.jsxs)(`div`,{className:`vulnerability-table-toolbar`,children:[b,(0,W.jsx)(S,{className:`vulnerability-sort-select`,size:`small`,value:m,optionList:De(e),onChange:e=>h(e||``)})]}):null;return(0,W.jsx)(j,{columns:ee,dataSource:Array.isArray(t)?t:[],loading:n,rowKey:`id`,toolbar:te,onRefresh:x,emptyText:e(`vulnerabilityPage.noRecords`,null,`暂无漏洞记录`),scroll:{x:1200},rowSelection:_?{selectedRowKeys:o,onChange:e=>s(Array.isArray(e)?e:[])}:void 0,onRow:e=>({onClick:t=>{t.target?.closest?.(`button, a, input, label, .semi-checkbox`)||c(e.id)}}),pagination:{currentPage:r,pageSize:i,total:Number(a)||0,showSizeChanger:!0,pageSizeOpts:be,onPageChange:e=>v(Number(e)),onPageSizeChange:e=>y(Number(e))}})}var{Text:Ue}=a,We=2e4;function Ge(e,t){let n=t(`vulnerabilityRetest.defaultPrompt`,null,`请帮我对漏洞 {{vulnerability_id}} 进行验证,确认是否已修复。完成后更新该漏洞状态。`),r=String(e?.retest_notes||``).trim();return r?`${n}\n\n${t(`vulnerabilityRetest.guidanceHeading`,null,`验证方式(来自漏洞记录的复测方式):`)}\n${r}`:n}function Ke({visible:e,vuln:t,onClose:r}){let i=ae(),a=n(),o=(0,F.useId)(),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(null);return(0,F.useEffect)(()=>{u(null)},[e,t?.id]),(0,W.jsxs)(E,{visible:e,width:640,closable:!s,closeOnEsc:!s,onCancel:s?void 0:r,cancelButtonProps:{disabled:s},title:i(`vulnerabilityRetest.title`,null,`复测漏洞`),formId:o,okText:i(`vulnerabilityRetest.confirm`,null,`确认并开始复测`),confirmLoading:s,children:[(0,W.jsx)(Ue,{strong:!0,children:t?.title}),(0,W.jsx)(Ue,{type:`tertiary`,size:`small`,children:i(`vulnerabilityRetest.hint`,null,`每次确认都会从原始对话创建独立分支,继承原项目和历史,可继续多轮验证。`)}),(0,W.jsxs)(v,{id:o,onSubmit:async e=>{if(!s&&t?.id){c(!0),u(null);try{let n=await w.post(`/vulnerabilities/${encodeURIComponent(t.id)}/retest`,{prompt:String(e.prompt||``).trim()});_e(n.conversation.id,n.prompt),r?.(),a(`/chat?conversation=${encodeURIComponent(n.conversation.id)}`)}catch(e){u(e)}finally{c(!1)}}},initValues:{prompt:Ge(t,i)},children:[(0,W.jsx)(v.TextArea,{id:`${o}-prompt`,field:`prompt`,rows:8,maxCount:We,autosize:!0,label:i(`vulnerabilityRetest.promptLabel`,null,`复测提示词`),extraText:i(`vulnerabilityRetest.placeholderHint`,null,`占位符发送时自动替换,也支持在后续对话中手动输入。`),rules:[{required:!0,whitespace:!0,message:i(`vulnerabilityRetest.promptRequired`,null,`请输入复测提示词。`)}]}),(0,W.jsx)(fe,{error:l})]},`${e}-${t?.id||``}`)]})}var{Text:q,Paragraph:J}=a;function Y({title:e,extra:t,children:n}){return(0,W.jsxs)(`section`,{className:`vulnerability-section`,children:[(0,W.jsxs)(`div`,{className:`vulnerability-section-head`,children:[(0,W.jsx)(`span`,{className:`vulnerability-section-title`,children:e}),t]}),(0,W.jsx)(`div`,{className:`vulnerability-section-body`,children:n})]})}function X({vulnerability:e}){let t=n(),[r,i]=(0,F.useState)([]);return(0,F.useEffect)(()=>{if(!e?.project_id||!e?.id){i([]);return}let t=!1;return w.get(`/projects/${e.project_id}/facts`,{related_vulnerability_id:e.id,limit:20}).then(e=>{t||i(Array.isArray(e)?e:[])}).catch(()=>{t||i([])}),()=>{t=!0}},[e?.project_id,e?.id]),r.length?(0,W.jsx)(Y,{title:`同一项目事实`,children:r.map(e=>(0,W.jsxs)(`div`,{className:`vulnerability-history-item`,children:[(0,W.jsx)(q,{children:e.summary||e.fact_key}),e.source_conversation_id?(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>t(`/chat?conversation=${encodeURIComponent(e.source_conversation_id)}`),children:`打开来源会话`}):null]},e.id))}):null}function Z({title:e,content:t,code:n}){let r=String(t??``).trim();return r?n?(0,W.jsx)(Y,{title:e,extra:(0,W.jsx)(k,{text:r,size:`small`}),children:(0,W.jsx)(`pre`,{className:`vulnerability-code`,children:r})}):(0,W.jsx)(Y,{title:e,children:(0,W.jsx)(D,{content:r})}):null}function qe({visible:e,vulnId:t,refreshKey:r,onClose:i,onEdit:a,onArchive:l,onDelete:f,onOpenVuln:m,canWrite:g,canDelete:v,t:b,projectNames:S}){let ie=n(),[ae,oe]=(0,F.useState)(`overview`),[ce,le]=(0,F.useState)(`docx`),[E,D]=(0,F.useState)(!1),[pe,me]=(0,F.useState)(!1),k=ue(()=>w.get(`/vulnerabilities/${encodeURIComponent(t)}/context`),[t,r,e],{skip:!e||!t});(0,F.useEffect)(()=>{oe(`overview`),le(`docx`)},[t]);let A=k.data?.vulnerability?.id===t?k.data:null,j=A?.vulnerability||null,ge=Array.isArray(A?.history)?A.history:[],N=Array.isArray(A?.members)?A.members:[],_e=Array.isArray(A?.assets)?A.assets:[],P=j?.project_id?S?.[j.project_id]||j.project_id:``,ve=e=>{e&&ie(`/chat?conversation=${encodeURIComponent(e)}`)},I=async()=>{if(j&&!E){D(!0);try{let e=await se(`/vulnerabilities/${encodeURIComponent(j.id)}/download`,{query:{format:ce}});M(`${b(`vulnerabilityPage.downloadOkTitle`,null,`下载成功`)}${e?` · ${e}`:``}`)}catch(e){T(e,b(`vulnerabilityPage.downloadFailed`,null,`下载失败`))}finally{D(!1)}}},ye=j?[{label:b(`vulnerabilityPage.detailVulnId`,null,`漏洞ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.id})},{label:b(`vulnerabilityPage.tableSeverity`,null,`严重度`),value:(0,W.jsx)(O,{severity:j.severity})},{label:b(`vulnerabilityPage.status`,null,`状态`),value:(0,W.jsx)(he,{status:j.status,label:z(b,j.status)})},j.type?{label:b(`vulnerabilityPage.detailType`,null,`类型`),value:j.type}:null,j.target?{label:b(`vulnerabilityPage.detailTarget`,null,`目标`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.target})}:null,V(j)&&V(j)!==j.target?{label:b(`vulnerabilityPage.detailHost`,null,`宿主`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:V(j)})}:null,{label:b(`vulnerabilityPage.detailProject`,null,`所属项目`),value:P||b(`vulnerabilityPage.projectUnbound`,null,`未绑定项目`)},j.conversation_tag?{label:b(`vulnerabilityPage.detailConversationTag`,null,`对话标签`),value:j.conversation_tag}:null,j.conversation_id?{label:b(`vulnerabilityPage.detailConversationId`,null,`会话ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.conversation_id})}:null,j.task_tag?{label:b(`vulnerabilityPage.detailTaskTag`,null,`任务标签`),value:j.task_tag}:null,j.task_id?{label:b(`vulnerabilityPage.detailTaskId`,null,`任务ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.task_id})}:null,j.task_queue_id?{label:b(`vulnerabilityPage.detailTaskQueueId`,null,`任务队列ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.task_queue_id})}:null,j.case_id?{label:b(`vulnerabilityPage.mergedRecord`,null,`已归并`),value:j.case_title||U(j.case_id,12)}:null,j.assessment_id?{label:b(`vulnerabilityPage.assessmentTask`,null,`深度测评`),value:j.assessment_name||U(j.assessment_id,12)}:null,{label:b(`vulnerabilityMd.labelCreated`,null,`创建时间`),value:C(j.created_at)},{label:b(`vulnerabilityMd.labelUpdated`,null,`更新时间`),value:C(j.updated_at)}].filter(Boolean):[],be=Array.isArray(j?.targets)?j.targets:[];return(0,W.jsxs)(ee,{className:`vulnerability-detail-drawer`,visible:e,onCancel:i,width:720,title:(0,W.jsxs)(`div`,{className:`vulnerability-drawer-title`,children:[(0,W.jsx)(`span`,{className:`vulnerability-drawer-title-text`,title:j?.title,children:j?.title||b(`vulnerabilityPage.inspectorTitle`,null,`漏洞工作台`)}),j&&(0,W.jsxs)(`span`,{className:`vulnerability-drawer-meta`,children:[(0,W.jsx)(O,{severity:j.severity}),(0,W.jsx)(he,{status:j.status,label:z(b,j.status)}),j.archived&&(0,W.jsx)(c,{size:`small`,color:`grey`,children:j.project_archived?b(`vulnerabilityPage.archivedWithProject`,null,`随项目归档`):b(`projects.statusArchived`,null,`已归档`)}),j.type?(0,W.jsx)(q,{type:`tertiary`,children:j.type}):null]})]}),footer:(0,W.jsxs)(o,{wrap:!0,children:[(0,W.jsx)(d,{onClick:i,children:b(`common.close`,null,`关闭`)}),(0,W.jsx)(d,{icon:(0,W.jsx)(re,{}),onClick:()=>k.reload(),loading:k.loading,children:b(`common.refresh`,null,`刷新`)}),g&&(0,W.jsx)(d,{theme:`solid`,type:`primary`,icon:(0,W.jsx)(te,{}),disabled:!j||!j.conversation_id,onClick:()=>me(!0),children:b(`vulnerabilityRetest.button`,null,`复测`)}),g&&(0,W.jsx)(d,{icon:(0,W.jsx)(u,{}),disabled:!j,onClick:()=>a(j),children:b(`common.edit`,null,`编辑`)}),g&&j&&!j.project_archived&&(0,W.jsx)(d,{onClick:()=>l(j),children:j.archived?b(`projects.restore`,null,`恢复`):b(`projects.archiveProject`,null,`归档`)}),v&&(0,W.jsx)(d,{type:`danger`,icon:(0,W.jsx)(s,{}),disabled:!j,onClick:()=>f(j),children:b(`common.delete`,null,`删除`)})]}),children:[(0,W.jsx)(fe,{error:k.error,onRetry:k.reload}),!k.error&&!j&&(0,W.jsx)(`div`,{className:`vulnerability-drawer-loading`,children:(0,W.jsx)(p,{size:`large`})}),j&&(0,W.jsxs)(h,{type:`line`,activeKey:ae,onChange:e=>oe(e),children:[(0,W.jsxs)(h.TabPane,{tab:b(`vulnerabilityPage.inspector_overview`,null,`概览`),itemKey:`overview`,children:[(0,W.jsx)(de,{items:ye,columns:2}),j.fingerprint?(0,W.jsx)(Z,{title:b(`vulnerabilityPage.fingerprint`,null,`确定性指纹`),content:j.fingerprint,code:!0}):null,j.quality?(0,W.jsx)(Z,{title:b(`vulnerabilityPage.qualityReview`,null,`五维对抗复核`),content:[`可达性:${j.quality.reachability||`—`}`,`前置条件:${j.quality.preconditions||`—`}`,`可复现性:${j.quality.reproducibility||`—`}`,`范围:${j.quality.scope||`—`}`,`影响:${j.quality.impact||`—`}`,`对照组可达:${j.quality.control_reachable?`是`:`否`}`,`机理已失效:${j.quality.mechanism_invalid?`是`:`否`}`,j.quality.blocked_by?`受阻:${j.quality.blocked_by}`:``].filter(Boolean).join(` +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,g as n,t as r,y as i}from"./react-QV7DAAIx.js";import{G as a,I as o,Lt as s,N as c,Ot as l,Pt as u,R as d,U as f,W as p,a as m,c as h,ft as g,h as _,i as v,j as y,lt as b,m as x,p as ee,pt as te,s as ne,ut as re,y as S}from"./semi-65W_4I1v.js";import{C as ie,E as C,F as ae,I as oe,L as w,R as se,S as ce,_ as le,a as ue,b as T,c as E,d as de,f as D,h as O,l as fe,m as pe,n as me,o as k,p as A,s as j,v as he,x as M,y as ge,z as N}from"./index-DNMXun-U.js";import{r as _e}from"./retest-EzTZPjnQ.js";import{t as P}from"./project-options-CMQbwv_U.js";var F=e(t(),1),ve=[`critical`,`high`,`medium`,`low`,`info`],I=[`open`,`confirmed`,`fixed`,`ignored`,`false_positive`],ye=[`q`,`severity`,`status`,`archived`,`project_id`,`conversation_tag`,`task_tag`,`assessment_id`],be=[10,20,50,100],xe={critical:`dashboard.severityCritical`,high:`dashboard.severityHigh`,medium:`dashboard.severityMedium`,low:`dashboard.severityLow`,info:`dashboard.severityInfo`},Se={open:`vulnerabilityPage.statusOpen`,confirmed:`vulnerabilityPage.statusConfirmed`,fixed:`vulnerabilityPage.statusFixed`,ignored:`vulnerabilityPage.statusIgnored`,false_positive:`vulnerabilityPage.statusFalsePositive`},Ce={open:`待处理`,confirmed:`已确认`,fixed:`已修复`,ignored:`已忽略`,false_positive:`误报`},L={retest:`复测结果`,retest_started:`复测分支已创建`,merge:`归并上报`,split:`拆分归并组`,detach:`解除关联`},R=[{value:``,key:`vulnerabilityPage.sortDefault`,fallback:`默认顺序`},{value:`severity`,key:`vulnerabilityPage.sortSeverity`,fallback:`高危优先`},{value:`latest`,key:`vulnerabilityPage.sortLatest`,fallback:`创建时间:最新优先`},{value:`oldest`,key:`vulnerabilityPage.sortOldest`,fallback:`创建时间:最早优先`}];function we(e,t){if(!t)return`—`;let n=xe[t];return n?e(n,null,ie[t]||t):String(t)}function z(e,t){if(!t)return`—`;let n=Se[t];return n?e(n,null,Ce[t]||t):String(t)}function Te(e,t){return t?e(`vulnerabilityPage.history_${t}`,null,L[t]||t):`—`}function Ee(e){return ve.map(t=>({value:t,label:we(e,t)}))}function B(e){return I.map(t=>({value:t,label:z(e,t)}))}function De(e){return R.map(t=>({value:t.value,label:e(t.key,null,t.fallback)}))}function Oe(e){let t={};return ye.forEach(n=>{let r=String(e?.[n]??``).trim();r&&(t[n]=r)}),t}function ke(e){let t=Oe(e);return delete t.severity,t}function Ae(e){return ye.some(t=>String(e?.[t]??``).trim()!==``)}function je(e,t){let n=Number(e)||0,r=Number(t)||0;return r>0?Math.round(n/r*100):0}function Me(e){return String(e?.target||``).trim()}function V(e){return(Array.isArray(e?.targets)?e.targets:[]).map(e=>e?.host).find(Boolean)||e?.target_host||e?.target_domain||``}function H(e){if(!e)return`—`;let t=e.host||e.id||`—`;return e.port?`${t}:${e.port}`:t}function U(e,t=8){let n=String(e||``);return n.length>t?`${n.slice(0,t)}…`:n}function Ne(e,t){let n=new Blob([t],{type:`text/markdown;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);return i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3),e}var W=e(r(),1);function G(e,t){return[{value:``,label:e},...t]}function Pe({t:e,filters:t,options:n,projectOptions:r,hasGroupFilters:i,onChange:a,onReset:o}){let s=(0,F.useId)(),[c,l]=(0,F.useState)(t.q),u=me(c,380),p=(0,F.useRef)(t.q);(0,F.useEffect)(()=>{u!==p.current&&(p.current=u,a(`q`,u))},[u,a]),(0,F.useEffect)(()=>{t.q!==p.current&&(p.current=t.q,l(t.q))},[t.q]);let m=Array.isArray(n?.conversation_tags)?n.conversation_tags:[],h=Array.isArray(n?.task_tags)?n.task_tags:[],g=Array.isArray(n?.assessment_ids)?n.assessment_ids:[];return(0,W.jsxs)(`div`,{className:`vulnerability-filter-bar`,children:[(0,W.jsx)(f,{className:`vulnerability-filter-search`,prefix:(0,W.jsx)(b,{}),value:c,showClear:!0,placeholder:e(`vulnerabilityPage.searchKeyword`,null,`搜索标题、描述、类型、目标…`),"aria-label":e(`vulnerabilityPage.searchKeyword`,null,`搜索标题、描述、类型、目标…`),onChange:e=>l(e)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.severity,placeholder:e(`vulnerabilityPage.severity`,null,`严重程度`),optionList:G(e(`vulnerabilityPage.allSeverities`,null,`全部级别`),Ee(e)),onChange:e=>a(`severity`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.status,placeholder:e(`vulnerabilityPage.status`,null,`状态`),optionList:G(e(`dashboard.allStatuses`,null,`全部状态`),B(e)),onChange:e=>a(`status`,e||``)}),(0,W.jsx)(`span`,{id:s,hidden:!0,children:e(`vulnerabilityPage.archiveStatus`,null,`归档状态`)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.archived,"aria-labelledby":s,optionList:[{value:``,label:e(`vulnerabilityPage.unarchived`,null,`未归档`)},{value:`true`,label:e(`projects.statusArchived`,null,`已归档`)},{value:`all`,label:e(`vulnerabilityPage.allArchiveStates`,null,`全部归档状态`)}],onChange:e=>a(`archived`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select vulnerability-filter-select--wide`,value:t.project_id,placeholder:e(`vulnerabilityPage.detailProject`,null,`所属项目`),filter:!0,optionList:G(e(`vulnerabilityPage.allProjects`,null,`全部项目`),r),onChange:e=>a(`project_id`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.conversation_tag,placeholder:e(`vulnerabilityPage.conversationTag`,null,`来源(对话标签)`),filter:!0,optionList:G(e(`vulnerabilityPage.allSources`,null,`全部来源`),m.map(e=>({value:e,label:e}))),onChange:e=>a(`conversation_tag`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.task_tag,placeholder:e(`vulnerabilityPage.taskTag`,null,`任务标签`),filter:!0,optionList:G(e(`vulnerabilityPage.allTaskTags`,null,`全部任务标签`),h.map(e=>({value:e,label:e}))),onChange:e=>a(`task_tag`,e||``)}),(0,W.jsx)(S,{className:`vulnerability-filter-select`,value:t.assessment_id,placeholder:e(`vulnerabilityPage.assessmentTask`,null,`深度测评`),filter:!0,optionList:G(e(`vulnerabilityPage.allAssessments`,null,`全部测评`),g.map(e=>({value:e,label:U(e,12)}))),onChange:e=>a(`assessment_id`,e||``)}),(0,W.jsx)(`div`,{className:`vulnerability-filter-actions`,children:(0,W.jsx)(d,{icon:(0,W.jsx)(re,{}),theme:`borderless`,disabled:!Ae(t)&&!t.sort&&!i,onClick:o,children:e(`vulnerabilityPage.clearAll`,null,`重置全部`)})})]})}var{Text:K}=a,Fe={critical:`red`,high:`orange`,medium:`amber`,low:`blue`,info:`grey`};function Ie(e,t){return t.key.startsWith(`task:`)?e(`vulnerabilityPage.viewTaskGroup`,{id:t.label||t.key.slice(5)}):t.label?t.label:t.key.startsWith(`host:`)?e(`vulnerabilityPage.unknownHost`):t.key.startsWith(`queue:`)?e(`vulnerabilityPage.taskQueueGroup`,{id:t.key.slice(6)}):t.key.startsWith(`assessment:`)?t.key.slice(11):e(`vulnerabilityPage.viewNoTask`)}function Le(e,t){let n=Ie(e,t),r=!!t.children?.length;return{key:t.key,value:t.key,label:(0,W.jsxs)(`span`,{className:`vulnerability-group-node`,children:[(0,W.jsx)(`span`,{className:r?`vulnerability-group-name vulnerability-group-name--parent`:`vulnerability-group-name`,title:n,children:n}),(0,W.jsx)(c,{size:`small`,color:`grey`,children:t.count})]}),children:t.children?.map(t=>Le(e,t))}}function Re({t:e,mode:t,groups:n,selection:r,loading:i,search:a,onSearch:o,onSelect:s}){let[c,u]=(0,F.useState)(a),d=t===`task`,h=e(d?`vulnerabilityPage.viewTask`:`vulnerabilityPage.viewHost`),g=e(d?`vulnerabilityPage.taskSearch`:`vulnerabilityPage.hostSearch`),{treeData:_,expandedKeys:v}=(0,F.useMemo)(()=>({treeData:[{key:`all`,value:`all`,label:e(d?`vulnerabilityPage.allTasks`:`vulnerabilityPage.allHosts`)},...n.map(t=>Le(e,t))],expandedKeys:n.filter(e=>e.children?.length).map(e=>e.key)}),[e,n,d]);return(0,F.useEffect)(()=>u(a),[a]),(0,F.useEffect)(()=>{if(c.trim()===a)return;let e=setTimeout(()=>o(c.trim()),350);return()=>clearTimeout(e)},[c,a,o]),(0,W.jsxs)(`aside`,{className:`vulnerability-group-sidebar`,"aria-label":h,children:[(0,W.jsx)(K,{strong:!0,children:h}),(0,W.jsx)(f,{prefix:(0,W.jsx)(b,{}),"aria-label":g,placeholder:g,value:c,showClear:!0,onChange:u}),(0,W.jsxs)(p,{spinning:i,wrapperClassName:`vulnerability-group-scroll`,children:[(0,W.jsx)(m,{"aria-label":h,treeData:_,value:r||`all`,onSelect:e=>s(e===`all`?``:e),expandedKeys:v,expandIcon:({className:e})=>(0,W.jsx)(`span`,{className:e,"aria-hidden":`true`,children:(0,W.jsx)(l,{size:`small`})}),expandAction:!1,blockNode:!0}),!n.length&&!i&&(0,W.jsx)(K,{className:`vulnerability-group-empty`,type:`tertiary`,size:`small`,children:e(`vulnerabilityPage.noMatchingGroups`)})]})]})}function ze({t:e,group:t}){return(0,W.jsxs)(`div`,{className:`vulnerability-group-overview`,children:[(0,W.jsx)(K,{strong:!0,className:`vulnerability-group-name`,children:Ie(e,t)}),(0,W.jsxs)(`div`,{className:`vulnerability-group-badges`,children:[ve.filter(e=>t.severities?.[e]).map(n=>(0,W.jsxs)(c,{color:Fe[n],children:[we(e,n),` `,t.severities[n]]},n)),(0,W.jsx)(c,{color:`grey`,children:e(`vulnerabilityPage.groupPending`,{count:t.pending})})]})]})}var{Text:Be}=a;function Ve({record:e}){let t=[e.conversation_tag,e.task_tag].filter(Boolean);return t.length?(0,W.jsx)(`span`,{className:`vulnerability-source-tags`,children:t.map(e=>(0,W.jsx)(c,{size:`small`,color:`blue`,type:`light`,children:e},e))}):e.conversation_id?(0,W.jsx)(Be,{type:`tertiary`,className:`vulnerability-inline-code`,title:e.conversation_id,children:U(e.conversation_id,10)}):(0,W.jsx)(Be,{type:`tertiary`,children:`—`})}function He({t:e,data:t,loading:n,page:r,pageSize:i,total:a,selection:o,onSelectionChange:s,onOpen:c,onEdit:l,onArchive:u,onDelete:f,onDownload:p,sort:m,onSort:h,canWrite:g,canDelete:_,onPageChange:v,onPageSizeChange:y,toolbar:b,onRefresh:x}){let ee=[{title:e(`vulnerabilityPage.tableTitle`,null,`漏洞名称`),dataIndex:`title`,render:(t,n)=>(0,W.jsxs)(`div`,{className:`vulnerability-title-cell`,children:[(0,W.jsx)(`span`,{className:`vulnerability-title-text`,title:n.title,children:n.title||`—`}),(0,W.jsxs)(`span`,{className:`vulnerability-title-meta`,children:[n.type||`—`,n.case_id?` · ${e(`vulnerabilityPage.mergedRecord`,null,`已归并`)}`:``,n.assessment_id?` · ${e(`vulnerabilityPage.assessmentTask`,null,`深度测评`)}`:``,n.archived?` · ${e(`projects.statusArchived`,null,`已归档`)}`:``]})]})},{title:e(`vulnerabilityPage.tableSeverity`,null,`严重度`),dataIndex:`severity`,width:92,render:e=>(0,W.jsx)(O,{severity:e})},{title:e(`vulnerabilityPage.tableStatus`,null,`状态`),dataIndex:`status`,width:100,render:t=>(0,W.jsx)(he,{status:t,label:z(e,t)})},{title:e(`vulnerabilityPage.detailTarget`,null,`目标 / 宿主`),dataIndex:`target`,width:220,render:(e,t)=>{let n=Me(t),r=Array.isArray(t.targets)&&t.targets.length?t.targets.map(e=>e?.host).filter(Boolean).join(`, `):``;return(0,W.jsxs)(`div`,{className:`vulnerability-target-cell`,children:[(0,W.jsx)(`span`,{className:`vulnerability-target-text`,title:n||r,children:n||r||`—`}),n&&r&&r!==n?(0,W.jsx)(`span`,{className:`vulnerability-target-host`,title:r,children:r}):null]})}},{title:e(`vulnerabilityPage.tableSource`,null,`来源`),dataIndex:`conversation_tag`,width:170,render:(e,t)=>(0,W.jsx)(Ve,{record:t})},{title:e(`vulnerabilityPage.tableDate`,null,`创建时间`),dataIndex:`created_at`,width:180,render:e=>(0,W.jsx)(`span`,{className:`vulnerability-time`,children:C(e)})},{title:e(`vulnerabilityPage.tableActions`,null,`操作`),dataIndex:`id`,width:g?250:200,render:(t,n)=>(0,W.jsxs)(`div`,{className:`vulnerability-row-actions`,children:[(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),c(n.id)},children:e(`vulnerabilityPage.rowView`,null,`详情`)}),(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),p(n)},children:e(`vulnerabilityPage.tableDownload`,null,`下载`)}),g&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),l(n)},children:e(`common.edit`,null,`编辑`)}),g&&!n.project_archived&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:e=>{e.stopPropagation(),u(n)},children:n.archived?e(`projects.restore`,null,`恢复`):e(`projects.archiveProject`,null,`归档`)}),_&&(0,W.jsx)(d,{size:`small`,theme:`borderless`,type:`danger`,onClick:e=>{e.stopPropagation(),f(n)},children:e(`common.delete`,null,`删除`)})]})}],te=b?(0,W.jsxs)(`div`,{className:`vulnerability-table-toolbar`,children:[b,(0,W.jsx)(S,{className:`vulnerability-sort-select`,size:`small`,value:m,optionList:De(e),onChange:e=>h(e||``)})]}):null;return(0,W.jsx)(j,{columns:ee,dataSource:Array.isArray(t)?t:[],loading:n,rowKey:`id`,toolbar:te,onRefresh:x,emptyText:e(`vulnerabilityPage.noRecords`,null,`暂无漏洞记录`),scroll:{x:1200},rowSelection:_?{selectedRowKeys:o,onChange:e=>s(Array.isArray(e)?e:[])}:void 0,onRow:e=>({onClick:t=>{t.target?.closest?.(`button, a, input, label, .semi-checkbox`)||c(e.id)}}),pagination:{currentPage:r,pageSize:i,total:Number(a)||0,showSizeChanger:!0,pageSizeOpts:be,onPageChange:e=>v(Number(e)),onPageSizeChange:e=>y(Number(e))}})}var{Text:Ue}=a,We=2e4;function Ge(e,t){let n=t(`vulnerabilityRetest.defaultPrompt`,null,`请帮我对漏洞 {{vulnerability_id}} 进行验证,确认是否已修复。完成后更新该漏洞状态。`),r=String(e?.retest_notes||``).trim();return r?`${n}\n\n${t(`vulnerabilityRetest.guidanceHeading`,null,`验证方式(来自漏洞记录的复测方式):`)}\n${r}`:n}function Ke({visible:e,vuln:t,onClose:r}){let i=ae(),a=n(),o=(0,F.useId)(),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)(null);return(0,F.useEffect)(()=>{u(null)},[e,t?.id]),(0,W.jsxs)(E,{visible:e,width:640,closable:!s,closeOnEsc:!s,onCancel:s?void 0:r,cancelButtonProps:{disabled:s},title:i(`vulnerabilityRetest.title`,null,`复测漏洞`),formId:o,okText:i(`vulnerabilityRetest.confirm`,null,`确认并开始复测`),confirmLoading:s,children:[(0,W.jsx)(Ue,{strong:!0,children:t?.title}),(0,W.jsx)(Ue,{type:`tertiary`,size:`small`,children:i(`vulnerabilityRetest.hint`,null,`每次确认都会从原始对话创建独立分支,继承原项目和历史,可继续多轮验证。`)}),(0,W.jsxs)(v,{id:o,onSubmit:async e=>{if(!s&&t?.id){c(!0),u(null);try{let n=await w.post(`/vulnerabilities/${encodeURIComponent(t.id)}/retest`,{prompt:String(e.prompt||``).trim()});_e(n.conversation.id,n.prompt),r?.(),a(`/chat?conversation=${encodeURIComponent(n.conversation.id)}`)}catch(e){u(e)}finally{c(!1)}}},initValues:{prompt:Ge(t,i)},children:[(0,W.jsx)(v.TextArea,{id:`${o}-prompt`,field:`prompt`,rows:8,maxCount:We,autosize:!0,label:i(`vulnerabilityRetest.promptLabel`,null,`复测提示词`),extraText:i(`vulnerabilityRetest.placeholderHint`,null,`占位符发送时自动替换,也支持在后续对话中手动输入。`),rules:[{required:!0,whitespace:!0,message:i(`vulnerabilityRetest.promptRequired`,null,`请输入复测提示词。`)}]}),(0,W.jsx)(fe,{error:l})]},`${e}-${t?.id||``}`)]})}var{Text:q,Paragraph:J}=a;function Y({title:e,extra:t,children:n}){return(0,W.jsxs)(`section`,{className:`vulnerability-section`,children:[(0,W.jsxs)(`div`,{className:`vulnerability-section-head`,children:[(0,W.jsx)(`span`,{className:`vulnerability-section-title`,children:e}),t]}),(0,W.jsx)(`div`,{className:`vulnerability-section-body`,children:n})]})}function X({vulnerability:e}){let t=n(),[r,i]=(0,F.useState)([]);return(0,F.useEffect)(()=>{if(!e?.project_id||!e?.id){i([]);return}let t=!1;return w.get(`/projects/${e.project_id}/facts`,{related_vulnerability_id:e.id,limit:20}).then(e=>{t||i(Array.isArray(e)?e:[])}).catch(()=>{t||i([])}),()=>{t=!0}},[e?.project_id,e?.id]),r.length?(0,W.jsx)(Y,{title:`同一项目事实`,children:r.map(e=>(0,W.jsxs)(`div`,{className:`vulnerability-history-item`,children:[(0,W.jsx)(q,{children:e.summary||e.fact_key}),e.source_conversation_id?(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>t(`/chat?conversation=${encodeURIComponent(e.source_conversation_id)}`),children:`打开来源会话`}):null]},e.id))}):null}function Z({title:e,content:t,code:n}){let r=String(t??``).trim();return r?n?(0,W.jsx)(Y,{title:e,extra:(0,W.jsx)(k,{text:r,size:`small`}),children:(0,W.jsx)(`pre`,{className:`vulnerability-code`,children:r})}):(0,W.jsx)(Y,{title:e,children:(0,W.jsx)(D,{content:r})}):null}function qe({visible:e,vulnId:t,refreshKey:r,onClose:i,onEdit:a,onArchive:l,onDelete:f,onOpenVuln:m,canWrite:g,canDelete:v,t:b,projectNames:S}){let ie=n(),[ae,oe]=(0,F.useState)(`overview`),[ce,le]=(0,F.useState)(`docx`),[E,D]=(0,F.useState)(!1),[pe,me]=(0,F.useState)(!1),k=ue(()=>w.get(`/vulnerabilities/${encodeURIComponent(t)}/context`),[t,r,e],{skip:!e||!t});(0,F.useEffect)(()=>{oe(`overview`),le(`docx`)},[t]);let A=k.data?.vulnerability?.id===t?k.data:null,j=A?.vulnerability||null,ge=Array.isArray(A?.history)?A.history:[],N=Array.isArray(A?.members)?A.members:[],_e=Array.isArray(A?.assets)?A.assets:[],P=j?.project_id?S?.[j.project_id]||j.project_id:``,ve=e=>{e&&ie(`/chat?conversation=${encodeURIComponent(e)}`)},I=async()=>{if(j&&!E){D(!0);try{let e=await se(`/vulnerabilities/${encodeURIComponent(j.id)}/download`,{query:{format:ce}});M(`${b(`vulnerabilityPage.downloadOkTitle`,null,`下载成功`)}${e?` · ${e}`:``}`)}catch(e){T(e,b(`vulnerabilityPage.downloadFailed`,null,`下载失败`))}finally{D(!1)}}},ye=j?[{label:b(`vulnerabilityPage.detailVulnId`,null,`漏洞ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.id})},{label:b(`vulnerabilityPage.tableSeverity`,null,`严重度`),value:(0,W.jsx)(O,{severity:j.severity})},{label:b(`vulnerabilityPage.status`,null,`状态`),value:(0,W.jsx)(he,{status:j.status,label:z(b,j.status)})},j.type?{label:b(`vulnerabilityPage.detailType`,null,`类型`),value:j.type}:null,j.target?{label:b(`vulnerabilityPage.detailTarget`,null,`目标`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.target})}:null,V(j)&&V(j)!==j.target?{label:b(`vulnerabilityPage.detailHost`,null,`宿主`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:V(j)})}:null,{label:b(`vulnerabilityPage.detailProject`,null,`所属项目`),value:P||b(`vulnerabilityPage.projectUnbound`,null,`未绑定项目`)},j.conversation_tag?{label:b(`vulnerabilityPage.detailConversationTag`,null,`对话标签`),value:j.conversation_tag}:null,j.conversation_id?{label:b(`vulnerabilityPage.detailConversationId`,null,`会话ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.conversation_id})}:null,j.task_tag?{label:b(`vulnerabilityPage.detailTaskTag`,null,`任务标签`),value:j.task_tag}:null,j.task_id?{label:b(`vulnerabilityPage.detailTaskId`,null,`任务ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.task_id})}:null,j.task_queue_id?{label:b(`vulnerabilityPage.detailTaskQueueId`,null,`任务队列ID`),value:(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.task_queue_id})}:null,j.case_id?{label:b(`vulnerabilityPage.mergedRecord`,null,`已归并`),value:j.case_title||U(j.case_id,12)}:null,j.assessment_id?{label:b(`vulnerabilityPage.assessmentTask`,null,`深度测评`),value:j.assessment_name||U(j.assessment_id,12)}:null,{label:b(`vulnerabilityMd.labelCreated`,null,`创建时间`),value:C(j.created_at)},{label:b(`vulnerabilityMd.labelUpdated`,null,`更新时间`),value:C(j.updated_at)}].filter(Boolean):[],be=Array.isArray(j?.targets)?j.targets:[];return(0,W.jsxs)(ee,{className:`vulnerability-detail-drawer`,visible:e,onCancel:i,width:720,title:(0,W.jsxs)(`div`,{className:`vulnerability-drawer-title`,children:[(0,W.jsx)(`span`,{className:`vulnerability-drawer-title-text`,title:j?.title,children:j?.title||b(`vulnerabilityPage.inspectorTitle`,null,`漏洞工作台`)}),j&&(0,W.jsxs)(`span`,{className:`vulnerability-drawer-meta`,children:[(0,W.jsx)(O,{severity:j.severity}),(0,W.jsx)(he,{status:j.status,label:z(b,j.status)}),j.archived&&(0,W.jsx)(c,{size:`small`,color:`grey`,children:j.project_archived?b(`vulnerabilityPage.archivedWithProject`,null,`随项目归档`):b(`projects.statusArchived`,null,`已归档`)}),j.type?(0,W.jsx)(q,{type:`tertiary`,children:j.type}):null]})]}),footer:(0,W.jsxs)(o,{wrap:!0,children:[(0,W.jsx)(d,{onClick:i,children:b(`common.close`,null,`关闭`)}),(0,W.jsx)(d,{icon:(0,W.jsx)(re,{}),onClick:()=>k.reload(),loading:k.loading,children:b(`common.refresh`,null,`刷新`)}),g&&(0,W.jsx)(d,{theme:`solid`,type:`primary`,icon:(0,W.jsx)(te,{}),disabled:!j||!j.conversation_id,onClick:()=>me(!0),children:b(`vulnerabilityRetest.button`,null,`复测`)}),g&&(0,W.jsx)(d,{icon:(0,W.jsx)(u,{}),disabled:!j,onClick:()=>a(j),children:b(`common.edit`,null,`编辑`)}),g&&j&&!j.project_archived&&(0,W.jsx)(d,{onClick:()=>l(j),children:j.archived?b(`projects.restore`,null,`恢复`):b(`projects.archiveProject`,null,`归档`)}),v&&(0,W.jsx)(d,{type:`danger`,icon:(0,W.jsx)(s,{}),disabled:!j,onClick:()=>f(j),children:b(`common.delete`,null,`删除`)})]}),children:[(0,W.jsx)(fe,{error:k.error,onRetry:k.reload}),!k.error&&!j&&(0,W.jsx)(`div`,{className:`vulnerability-drawer-loading`,children:(0,W.jsx)(p,{size:`large`})}),j&&(0,W.jsxs)(h,{type:`line`,activeKey:ae,onChange:e=>oe(e),children:[(0,W.jsxs)(h.TabPane,{tab:b(`vulnerabilityPage.inspector_overview`,null,`概览`),itemKey:`overview`,children:[(0,W.jsx)(de,{items:ye,columns:2}),j.fingerprint?(0,W.jsx)(Z,{title:b(`vulnerabilityPage.fingerprint`,null,`确定性指纹`),content:j.fingerprint,code:!0}):null,j.quality?(0,W.jsx)(Z,{title:b(`vulnerabilityPage.qualityReview`,null,`五维对抗复核`),content:[`可达性:${j.quality.reachability||`—`}`,`前置条件:${j.quality.preconditions||`—`}`,`可复现性:${j.quality.reproducibility||`—`}`,`范围:${j.quality.scope||`—`}`,`影响:${j.quality.impact||`—`}`,`对照组可达:${j.quality.control_reachable?`是`:`否`}`,`机理已失效:${j.quality.mechanism_invalid?`是`:`否`}`,j.quality.blocked_by?`受阻:${j.quality.blocked_by}`:``].filter(Boolean).join(` `)}):null,(0,W.jsx)(Z,{title:b(`vulnerabilityMd.headingDescription`,null,`描述`),content:j.description}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailImpact`,null,`影响`),content:j.impact}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailRecommendation`,null,`修复建议`),content:j.recommendation})]}),(0,W.jsxs)(h.TabPane,{tab:b(`vulnerabilityPage.inspector_evidence`,null,`复现与证据`),itemKey:`evidence`,children:[(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailPreconditions`,null,`前置条件`),content:j.preconditions}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailReproductionSteps`,null,`复现步骤`),content:j.reproduction_steps}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailEvidence`,null,`证据 / POC`),content:j.evidence,code:!0}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailRetestNotes`,null,`复测方式`),content:j.retest_notes}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailRetestLog`,null,`复测记录`),content:j.retest_log,code:!0}),(0,W.jsx)(X,{vulnerability:j}),(0,W.jsx)(Y,{title:b(`vulnerabilityPage.inspector_history`,null,`处置历史`),children:ge.length?(0,W.jsx)(ne,{children:ge.map((e,t)=>(0,W.jsx)(ne.Item,{time:C(e.created_at),type:e.kind===`retest`?`success`:`default`,children:(0,W.jsxs)(`div`,{className:`vulnerability-history-item`,children:[(0,W.jsxs)(`div`,{className:`vulnerability-history-head`,children:[(0,W.jsx)(q,{strong:!0,children:Te(b,e.kind)}),e.status?(0,W.jsx)(he,{status:e.status,label:z(b,e.status)}):null,e.actor?(0,W.jsx)(q,{type:`tertiary`,children:e.actor}):null]}),e.evidence?(0,W.jsx)(`pre`,{className:`vulnerability-code`,children:e.evidence}):null,e.snapshot?(0,W.jsx)(y,{className:`vulnerability-snapshot`,children:(0,W.jsxs)(y.Panel,{header:b(`vulnerabilityPage.retestSnapshot`,null,`复测时的证据快照`),itemKey:`snapshot`,children:[(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailReproductionSteps`,null,`复现步骤`),content:e.snapshot.reproduction_steps}),(0,W.jsx)(Z,{title:b(`vulnerabilityPage.detailEvidence`,null,`证据 / POC`),content:e.snapshot.evidence,code:!0})]})}):null,e.conversation_id?(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>ve(e.conversation_id),children:b(`vulnerabilityPage.openRetestChat`,null,`打开复测对话`)}):null]})},`${e.kind}-${e.created_at}-${t}`))}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.noHistory`,null,`暂无结构化处置记录`)})})]}),(0,W.jsxs)(h.TabPane,{tab:b(`vulnerabilityPage.detailRelations`,null,`关联`),itemKey:`relations`,children:[(0,W.jsx)(Y,{title:b(`vulnerabilityPage.detailProject`,null,`所属项目`),children:j.project_id?(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(q,{children:P}),(0,W.jsx)(q,{type:`tertiary`,className:`vulnerability-inline-code`,children:j.project_id})]}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.projectUnbound`,null,`未绑定项目`)})}),(0,W.jsx)(Y,{title:b(`vulnerabilityPage.affectedTargets`,null,`受影响目标`),children:be.length?(0,W.jsx)(`ul`,{className:`vulnerability-related-list`,children:be.map(e=>(0,W.jsxs)(`li`,{className:`vulnerability-related-item`,children:[(0,W.jsx)(q,{strong:!0,children:e.host||e.domain||e.raw}),e.raw&&e.raw!==e.host?(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:e.raw}):null]},`${e.raw}-${e.host}`))}):(0,W.jsx)(J,{type:`tertiary`,children:j.target||`—`})}),(0,W.jsx)(Y,{title:b(`vulnerabilityPage.linkedAssets`,null,`资产库匹配`),children:_e.length?(0,W.jsx)(`ul`,{className:`vulnerability-related-list`,children:_e.map(e=>(0,W.jsxs)(`li`,{className:`vulnerability-related-item`,children:[(0,W.jsx)(q,{strong:!0,children:H(e)}),(0,W.jsx)(q,{type:`tertiary`,className:`vulnerability-inline-code`,children:U(e.id,12)})]},e.id||`${e.host}-${e.port}`))}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.noLinkedAssets`,null,`未匹配到资产库记录`)})}),(0,W.jsxs)(Y,{title:b(`vulnerabilityPage.detailConversationId`,null,`会话`),children:[j.conversation_id?(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.conversation_id}),(0,W.jsx)(d,{size:`small`,theme:`borderless`,onClick:()=>ve(j.conversation_id),children:b(`vulnerabilityPage.openConversation`,null,`查看对话`)})]}):(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityPage.standaloneRecord`,null,`独立记录(无关联会话)`)}),j.task_id||j.task_queue_id?(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(q,{type:`tertiary`,children:b(`vulnerabilityPage.detailTaskId`,null,`任务ID`)}),(0,W.jsx)(`span`,{className:`vulnerability-inline-code`,children:j.task_id||j.task_queue_id})]}):null]}),j.assessment_id?(0,W.jsx)(Y,{title:b(`vulnerabilityPage.assessmentTask`,null,`深度测评`),children:(0,W.jsxs)(`div`,{className:`vulnerability-related-row`,children:[(0,W.jsx)(q,{children:j.assessment_name||U(j.assessment_id,12)}),j.assessment_step_title?(0,W.jsx)(q,{type:`tertiary`,children:j.assessment_step_title}):null]})}):null,N.length?(0,W.jsx)(Y,{title:j.case_title||b(`vulnerabilityPage.mergedRecord`,null,`已归并`),children:(0,W.jsx)(`div`,{className:`vulnerability-member-list`,children:N.map(e=>(0,W.jsxs)(d,{size:`small`,theme:`borderless`,disabled:e.id===j.id,onClick:()=>m(e.id),children:[e.title,` · `,z(b,e.status)]},e.id))})}):null]}),(0,W.jsx)(h.TabPane,{tab:b(`vulnerabilityDownload.title`,null,`下载报告`),itemKey:`download`,children:(0,W.jsxs)(`div`,{className:`vulnerability-download-panel`,children:[(0,W.jsx)(J,{type:`tertiary`,children:b(`vulnerabilityDownload.hint`,null,`请选择下载格式`)}),(0,W.jsxs)(_,{value:ce,onChange:e=>le(e.target.value),children:[(0,W.jsx)(x,{value:`docx`,children:b(`vulnerabilityDownload.word`,null,`Word(.docx)`)}),(0,W.jsx)(x,{value:`md`,children:b(`vulnerabilityDownload.markdown`,null,`Markdown(.md)`)})]}),(0,W.jsx)(d,{theme:`solid`,type:`primary`,loading:E,onClick:I,children:b(`vulnerabilityDownload.download`,null,`下载漏洞报告`)}),(0,W.jsx)(q,{type:`tertiary`,children:b(`vulnerabilityPage.downloadHint`,null,`报告由服务端按当前记录生成,包含描述、证据与修复建议。`)})]})})]}),(0,W.jsx)(Ke,{visible:pe,vuln:j,onClose:()=>me(!1)})]})}var{Text:Q}=a,Je={title:``,severity:``,status:`open`,type:``,target:``,project_id:``,conversation_id:``,conversation_tag:``,task_tag:``,description:``,preconditions:``,reproduction_steps:``,evidence:``,impact:``,recommendation:``,retest_notes:``};function Ye(e){return e?{title:e.title||``,severity:e.severity||``,status:e.status||`open`,type:e.type||``,target:e.target||``,project_id:e.project_id||``,conversation_id:e.conversation_id||``,conversation_tag:e.conversation_tag||``,task_tag:e.task_tag||``,description:e.description||``,preconditions:e.preconditions||``,reproduction_steps:e.reproduction_steps||``,evidence:e.evidence||``,impact:e.impact||``,recommendation:e.recommendation||``,retest_notes:e.retest_notes||``}:{...Je}}function $(e){return String(e??``).trim()}function Xe({visible:e,vulnId:t,t:n,projects:r,onClose:i,onSaved:a}){let o=!!t,[s,c]=(0,F.useState)(null),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(null),[m,h]=(0,F.useState)({...Je}),[g,_]=(0,F.useState)(``);(0,F.useEffect)(()=>{if(!e)return;if(f(null),!t){_(``);return}let n=!1;return w.get(`/vulnerabilities/${encodeURIComponent(t)}`).then(e=>{n||(h(Ye(e)),_(t))}).catch(e=>{n||f(e)}),()=>{n=!0}},[e,t]);let y=!o||g===t,b=o?m:{...Je},x=P(r,n,{currentId:b.project_id}),ee=async()=>{if(!s||l)return;let e;try{e=await s.validate()}catch{return}let r={title:$(e.title),severity:e.severity,status:e.status||`open`,type:$(e.type),target:$(e.target),description:e.description||``,preconditions:e.preconditions||``,reproduction_steps:e.reproduction_steps||``,evidence:e.evidence||``,impact:e.impact||``,recommendation:e.recommendation||``,retest_notes:e.retest_notes||``,project_id:$(e.project_id),conversation_tag:$(e.conversation_tag),task_tag:$(e.task_tag)};o||(r.conversation_id=$(e.conversation_id)),u(!0);try{let e=o?await w.put(`/vulnerabilities/${encodeURIComponent(t)}`,r):await w.post(`/vulnerabilities`,r);a?.(e)}catch(e){T(e,n(`vulnerabilityPage.saveFailed`,null,`保存失败`))}finally{u(!1)}};return(0,W.jsx)(E,{title:o?n(`vulnerability.editVuln`,null,`编辑漏洞`):n(`vulnerability.addVuln`,null,`添加漏洞`),visible:e,onCancel:i,onOk:ee,confirmLoading:l,okText:n(`common.save`,null,`保存`),cancelText:n(`common.cancel`,null,`取消`),width:780,children:e?d?(0,W.jsx)(Q,{type:`danger`,children:N(d,n(`vulnerabilityPage.fetchFailed`,null,`获取漏洞失败`))}):y?(0,W.jsx)(v,{initValues:b,getFormApi:c,labelPosition:`top`,onSubmit:ee,children:(0,W.jsxs)(`div`,{className:`vulnerability-form-grid`,children:[(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.Input,{field:`title`,label:n(`vulnerabilityModal.title`,null,`标题`),placeholder:n(`vulnerabilityModal.titlePlaceholder`,null,`/api/login 存在 SQL 注入`),rules:[{required:!0,message:n(`vulnerabilityModal.titleRequired`,null,`请填写漏洞标题`)}],maxLength:500})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Select,{field:`severity`,label:n(`vulnerabilityModal.severity`,null,`严重程度`),placeholder:n(`vulnerabilityModal.pleaseSelect`,null,`请选择`),style:{width:`100%`},optionList:Ee(n),rules:[{required:!0,message:n(`vulnerabilityModal.severityRequired`,null,`请选择严重程度`)}]})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Select,{field:`status`,label:n(`vulnerabilityModal.status`,null,`状态`),style:{width:`100%`},optionList:B(n)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`target`,label:n(`vulnerabilityModal.target`,null,`目标`),placeholder:n(`vulnerabilityModal.targetPlaceholder`,null,`精确到 URL/IP:端口/接口路径/参数名`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`type`,label:n(`vulnerabilityModal.type`,null,`漏洞类型`),placeholder:n(`vulnerabilityModal.typePlaceholder`,null,`如:SQL注入、XSS、CSRF等`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Select,{field:`project_id`,label:n(`vulnerabilityModal.project`,null,`所属项目`),placeholder:n(`vulnerabilityModal.projectNone`,null,`(未绑定)`),style:{width:`100%`},filter:!0,optionList:[{value:``,label:n(`vulnerabilityModal.projectNone`,null,`(未绑定)`)},...x]})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`conversation_id`,label:n(`vulnerabilityModal.conversationId`,null,`会话ID`),placeholder:n(`vulnerabilityModal.conversationIdPlaceholder`,null,`可选:输入已有会话ID,留空可独立添加漏洞`),disabled:o})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`conversation_tag`,label:n(`vulnerabilityModal.conversationTag`,null,`对话标签`),placeholder:n(`vulnerabilityModal.conversationTagPlaceholder`,null,`如:红队演练A、客户A周报`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field`,children:(0,W.jsx)(v.Input,{field:`task_tag`,label:n(`vulnerabilityModal.taskTag`,null,`任务标签`),placeholder:n(`vulnerabilityModal.taskTagPlaceholder`,null,`如:批量扫描Q2、专项复测`)})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`description`,label:n(`vulnerabilityModal.description`,null,`描述`),placeholder:n(`vulnerabilityModal.descriptionPlaceholder`,null,`说明漏洞摘要、触发点、异常现象和为什么可被利用。`),autosize:{minRows:3,maxRows:8}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`preconditions`,label:n(`vulnerabilityModal.preconditions`,null,`前置条件`),placeholder:n(`vulnerabilityModal.preconditionsPlaceholder`,null,`登录状态、权限、账号、Header/Cookie、特定数据、环境/版本;无则写无。`),autosize:{minRows:2,maxRows:6}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`reproduction_steps`,label:n(`vulnerabilityModal.reproductionSteps`,null,`复现步骤`),placeholder:n(`vulnerabilityModal.reproductionStepsPlaceholder`,null,`按 1/2/3 编号,写清入口、参数、payload、执行命令、观察点。`),autosize:{minRows:3,maxRows:10}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`evidence`,label:n(`vulnerabilityModal.evidence`,null,`证据 / POC`),placeholder:n(`vulnerabilityModal.evidencePlaceholder`,null,`原始请求/响应、curl/工具命令、截图说明、日志、回连记录等。`),autosize:{minRows:3,maxRows:10}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`impact`,label:n(`vulnerabilityModal.impact`,null,`影响`),placeholder:n(`vulnerabilityModal.impactPlaceholder`,null,`结合已验证事实说明实际影响,例如越权读取哪些数据。`),autosize:{minRows:2,maxRows:6}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`recommendation`,label:n(`vulnerabilityModal.recommendation`,null,`修复建议`),placeholder:n(`vulnerabilityModal.recommendationPlaceholder`,null,`写具体修复点和复测标准。`),autosize:{minRows:2,maxRows:8}})}),(0,W.jsx)(`div`,{className:`vulnerability-field vulnerability-field--full`,children:(0,W.jsx)(v.TextArea,{field:`retest_notes`,label:n(`vulnerabilityModal.retestNotes`,null,`复测方式`),placeholder:n(`vulnerabilityModal.retestNotesPlaceholder`,null,`修复后如何验证漏洞已关闭,包括应返回的状态码、错误信息或访问控制结果。`),autosize:{minRows:2,maxRows:6}})})]})},o?`${t}-${g}`:`new`):(0,W.jsx)(`div`,{className:`vulnerability-modal-loading`,children:(0,W.jsx)(p,{size:`large`})}):null})}var{Text:Ze}=a,Qe={none:`viewList`,host:`viewHost`,task:`viewTask`},$e=[];function et(){let e=ae(),{hasPermission:t}=oe(),[n,r]=i(),a=(0,F.useMemo)(()=>({q:n.get(`q`)||``,severity:n.get(`severity`)||``,status:n.get(`status`)||``,archived:[`true`,`all`].includes(n.get(`archived`))?n.get(`archived`):``,project_id:n.get(`project_id`)||``,conversation_tag:n.get(`conversation_tag`)||``,task_tag:n.get(`task_tag`)||``,assessment_id:n.get(`assessment_id`)||``,sort:[`severity`,`latest`,`oldest`].includes(n.get(`sort`))?n.get(`sort`):``}),[n]),o=Math.max(1,Number.parseInt(n.get(`page`)||`1`,10)||1),s=be.includes(Number(n.get(`page_size`)))?Number(n.get(`page_size`)):20,c=(n.get(`id`)||``).trim(),l=n.get(`group_by`),u=l===`host`||l===`task`?l:``,f=u&&n.get(`selection`)||``,p=u===`task`?`task_q`:`host_q`,m=u&&n.get(p)||``,h=m?{[p]:m}:{},v=t(`vulnerability:write`),y=t(`vulnerability:delete`)||v,b=(0,F.useCallback)((e,t={})=>{r(n=>{let r=new URLSearchParams(n);return Object.entries(e).forEach(([e,t])=>{t==null||t===``?r.delete(e):r.set(e,String(t))}),t.resetPage&&r.delete(`page`),r.toString()===n.toString()?n:r},{replace:!0})},[r]),x=(0,F.useCallback)((e,t)=>{b({[e]:t},{resetPage:!0})},[b]),ee=(0,F.useCallback)(()=>{let e={sort:void 0,selection:void 0,host_q:void 0,task_q:void 0};ye.forEach(t=>{e[t]=void 0}),b(e,{resetPage:!0})},[b]),te=(0,F.useCallback)(e=>{b({group_by:e===`none`?void 0:e,selection:void 0,host_q:void 0,task_q:void 0},{resetPage:!0})},[b]),ne=(0,F.useCallback)(e=>{b({selection:e},{resetPage:!0})},[b]),S=(0,F.useCallback)(e=>{b({[p]:e,selection:void 0},{resetPage:!0})},[p,b]),ie=(0,F.useCallback)(e=>b({id:e}),[b]),C=(0,F.useCallback)(()=>b({id:void 0}),[b]),E={...Oe(a),...h,...u?{group_by:u,pagination:`records`,selection:f}:{},...a.sort?{sort:a.sort}:{},summary:`true`,page:o,limit:s},de=JSON.stringify(E),D=ue(async()=>({...await w.get(`/vulnerabilities`,E)||{},__requestKey:de,__groupView:u}),[de]),O=D.data?.__requestKey===de?D.data:null,me=D.data?.__groupView===u&&D.data?.navigation||$e,k=O?.selection?me.flatMap(e=>[e,...e.children||[]]).find(e=>e.key===O.selection):null,j=(0,F.useMemo)(()=>ke(a),[a]),he=JSON.stringify(j),N=ue(()=>w.get(`/vulnerabilities/stats`,j),[he]),[_e,P]=(0,F.useState)(0),I=ue(()=>w.get(`/vulnerabilities/filter-options`,a.archived?{archived:a.archived}:{}),[_e,a.archived]),xe=ue(async()=>{try{let e=await w.get(`/projects`,{limit:500});return Array.isArray(e?.projects)?e.projects:[]}catch{return[]}},[]),Se=(0,F.useMemo)(()=>{let e={};return(xe.data||[]).forEach(t=>{t?.id&&(e[t.id]=t.name||t.id)}),e},[xe.data]),Ce=(0,F.useMemo)(()=>{let e=new Map;return(I.data?.project_ids||[]).forEach(t=>{t&&e.set(t,Se[t]||t)}),a.project_id&&!e.has(a.project_id)&&e.set(a.project_id,Se[a.project_id]||a.project_id),[...e.entries()].map(([e,t])=>({value:e,label:t}))},[I.data,Se,a.project_id]),[L,R]=(0,F.useState)([]),[z,Te]=(0,F.useState)({visible:!1,id:``}),[Ee,B]=(0,F.useState)(0),[De,Me]=(0,F.useState)(!1);(0,F.useEffect)(()=>{R([])},[de]),(0,F.useEffect)(()=>{if(!O)return;let e={},t=Number(O.page);t&&t!==o&&(e.page=t),f&&!O.selection&&(e.selection=void 0),Object.keys(e).length&&b(e)},[O,f,o,b]);let V=D.reload,H=N.reload,U=I.reload,G=(0,F.useCallback)(()=>{V(),H(),U({silent:!0})},[V,H,U]),K=(0,F.useCallback)(e=>{Te({visible:!0,id:e?.id||``})},[]),Fe=(0,F.useCallback)(()=>{Te({visible:!1,id:``}),M(e(`vulnerabilityPage.saveSuccess`,null,`已保存`)),B(e=>e+1),P(e=>e+1),V({silent:!0}),H({silent:!0})},[V,H,e]),Ie=(0,F.useCallback)(async t=>{try{await w.put(`/vulnerabilities/${encodeURIComponent(t.id)}/archive`,{archived:!t.archived}),M(e(`vulnerabilityPage.saveSuccess`,null,`已保存`)),R(e=>e.filter(e=>e!==t.id)),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}catch(t){T(t,e(`vulnerabilityPage.archiveFailed`,null,`更新归档状态失败`))}},[V,H,e]),Le=(0,F.useCallback)(t=>{t?.id&&ge({title:e(`vulnerabilityPage.deleteTitle`,null,`删除漏洞`),content:`${e(`vulnerability.deleteConfirm`,null,`确定要删除此漏洞吗?`)}${t.title?` ${t.title}`:``}`,okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await w.del(`/vulnerabilities/${encodeURIComponent(t.id)}`),M(e(`vulnerabilityPage.deleteSuccess`,null,`已删除`)),c===t.id&&C(),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}catch(t){T(t,e(`vulnerabilityPage.deleteFailed`,null,`删除失败`))}}})},[c,C,V,H,e]),Be=(0,F.useCallback)(()=>{if(!L.length)return;let t=[...L];ge({title:e(`vulnerabilityPage.batchDelete`,null,`批量删除`),content:e(`vulnerabilityPage.batchDeleteConfirm`,{count:t.length},`确定要删除选中的 ${t.length} 条漏洞吗?此操作不可恢复。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{let n=0,r=0;for(let e of t)try{await w.del(`/vulnerabilities/${encodeURIComponent(e)}`),n+=1}catch{r+=1}r?ce(e(`vulnerabilityPage.batchDeletePartial`,{deleted:n,failed:r},`已删除 ${n} 条,${r} 条失败`)):M(e(`vulnerabilityPage.batchDeleteSuccess`,{count:n},`成功删除 ${n} 条漏洞`)),R([]),t.includes(c)&&C(),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}})},[L,c,C,V,H,e]),Ve=(0,F.useCallback)(async()=>{let t=Oe(a);try{let n=await w.get(`/vulnerabilities`,{...t,page:1,limit:1}),r=Number(n?.total)||0;if(!r){ce(e(`vulnerabilityPage.batchDeleteNoResults`,null,`当前筛选条件下没有可删除的漏洞`));return}ge({title:e(`vulnerabilityPage.deleteFilteredTitle`,null,`删除当前筛选结果`),content:e(`vulnerabilityPage.batchDeleteConfirm`,{count:r},`确定要删除当前筛选条件下的 ${r} 条漏洞吗?此操作不可恢复。`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{let n=await w.del(`/vulnerabilities/batch`,{query:t}),i=Number(n?.deleted)||r;M(e(`vulnerabilityPage.batchDeleteSuccess`,{count:i},`成功删除 ${i} 条漏洞`)),R([]),B(e=>e+1),P(e=>e+1),await Promise.all([V({silent:!0}),H({silent:!0})])}catch(t){T(t,e(`vulnerabilityPage.batchDeleteFailed`,null,`批量删除失败`))}}})}catch(t){T(t,e(`vulnerabilityPage.fetchFailed`,null,`获取漏洞失败`))}},[a,V,H,e]),Ue=(0,F.useCallback)(async()=>{if(!De){Me(!0);try{let t=await w.get(`/vulnerabilities/export`,{...Oe(a),...h,mode:`summary`,group_by:`conversation`}),n=Array.isArray(t?.files)?t.files:[];if(!n.length){ce(e(`vulnerabilityPage.exportNoResults`,null,`当前筛选条件下无可导出漏洞`));return}n.forEach((e,t)=>{setTimeout(()=>Ne(e.filename||`vulnerability-export-${t+1}.md`,e.content||``),t*120)}),M(n.length>1?e(`vulnerabilityPage.exportStarted`,{count:n.length},`已开始下载 ${n.length} 份报告`):e(`vulnerabilityPage.exportSuccess`,null,`报告已开始下载`))}catch(t){T(t,e(`vulnerabilityPage.exportFailed`,null,`导出失败`))}finally{Me(!1)}}},[De,a,h,e]),We=(0,F.useCallback)(async t=>{try{let n=await se(`/vulnerabilities/${encodeURIComponent(t.id)}/download`,{query:{format:`docx`}});M(`${e(`vulnerabilityPage.downloadOkTitle`,null,`下载成功`)}${n?` · ${n}`:``}`)}catch(t){T(t,e(`vulnerabilityPage.downloadFailed`,null,`下载失败`))}},[e]),Ge=(0,F.useCallback)(e=>{b({page:String(e)})},[b]),Ke=(0,F.useCallback)(e=>{if(!e||e===s)return;let t=Math.max(1,Math.floor((o-1)*s/e)+1);b({page_size:String(e),page:String(t)})},[o,s,b]),q=N.data||{},J=q.by_severity||{},Y=Number(q.total)||0,X=Number(q.distinct)||0,Z=(0,F.useMemo)(()=>[{id:`total`,label:e(`vulnerabilityPage.statTotal`,null,`总漏洞数`),value:Y,detail:X&&X!==Y?e(`vulnerabilityPage.distinctCount`,{count:X},`${X} 个独立漏洞`):void 0,loading:N.loading,onClick:()=>x(`severity`,``)},...ve.map(t=>{let n=Number(J[t])||0,r=je(n,Y),i=a.severity===t;return{id:t,label:we(e,t),value:n,severity:t,pressed:i,detail:i?`${e(`vulnerabilityPage.filterActive`,null,`已筛选`)} · ${r}%`:`${r}%`,loading:N.loading,onClick:()=>x(`severity`,i?``:t)}})],[e,Y,X,J,N.loading,a.severity,x]),Q=Number(O?.total)||0,Je=Q?(o-1)*s+1:0,Ye=Q?Math.min(o*s,Q):0,$=Q?e(`vulnerabilityPage.recordPagination`,{start:Je,end:Ye,total:Q},`显示 ${Je}–${Ye} / 共 ${Q} 条漏洞`):e(`vulnerabilityPage.noRecords`,null,`暂无漏洞记录`),et=D.error||N.error||I.error,tt=(0,W.jsxs)(`div`,{className:`vulnerability-toolbar-left`,children:[(0,W.jsx)(Ze,{type:`tertiary`,children:O&&L.length?e(`vulnerabilityPage.selectedCount`,{count:L.length},`已选 ${L.length} 项`):$}),y&&(0,W.jsx)(d,{size:`small`,type:`danger`,theme:`light`,disabled:!O||!L.length,onClick:Be,children:e(`vulnerabilityPage.batchDelete`,null,`批量删除`)}),y&&!f&&!m&&Ae(a)&&(0,W.jsx)(d,{size:`small`,type:`danger`,theme:`borderless`,onClick:Ve,children:e(`vulnerabilityPage.deleteFiltered`,null,`删除筛选结果`)})]});return(0,W.jsxs)(`div`,{className:`vulnerability-page`,children:[(0,W.jsx)(A,{title:e(`vulnerability.title`,null,`漏洞管理`),description:e(`vulnerabilityPage.workspaceSubtitle`,null,`资产、上报与处置进展`),extra:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(d,{icon:(0,W.jsx)(re,{}),onClick:G,loading:D.loading,children:e(`common.refresh`,null,`刷新`)}),(0,W.jsx)(d,{onClick:Ue,loading:De,children:e(f?`vulnerabilityPage.exportAllGroups`:`vulnerabilityPage.batchExport`)}),v&&(0,W.jsx)(d,{theme:`solid`,type:`primary`,icon:(0,W.jsx)(g,{}),onClick:()=>K(null),children:e(`vulnerability.addVuln`,null,`添加漏洞`)})]})}),(0,W.jsx)(le,{metrics:Z,columns:6}),(0,W.jsx)(fe,{error:et,onRetry:G}),(0,W.jsxs)(pe,{className:`vulnerability-list-card`,title:e(`vulnerabilityPage.listTitle`,null,`漏洞记录`),extra:(0,W.jsx)(_,{"aria-label":e(`vulnerabilityPage.viewLabel`),type:`button`,value:u||`none`,options:Object.entries(Qe).map(([t,n])=>({value:t,label:e(`vulnerabilityPage.${n}`)})),onChange:e=>te(e.target.value)}),children:[(0,W.jsx)(Pe,{t:e,filters:a,options:I.data,projectOptions:Ce,hasGroupFilters:!!(f||m),onChange:x,onReset:ee}),(0,W.jsxs)(`div`,{className:u?`vulnerability-group-layout`:void 0,children:[u&&(0,W.jsx)(Re,{t:e,mode:u,groups:me,selection:f,search:m,loading:D.loading,onSearch:S,onSelect:ne},u),(0,W.jsxs)(`div`,{className:`vulnerability-group-results`,children:[k&&(0,W.jsx)(ze,{t:e,group:k}),(0,W.jsx)(He,{t:e,data:O?.vulnerabilities,loading:D.loading,page:o,pageSize:s,total:Q,selection:O?L:[],onSelectionChange:R,onOpen:ie,onEdit:K,onArchive:Ie,onDelete:Le,onDownload:We,sort:a.sort,onSort:e=>x(`sort`,e),canWrite:v,canDelete:y,onPageChange:Ge,onPageSizeChange:Ke,toolbar:tt,onRefresh:G})]})]})]}),(0,W.jsx)(qe,{visible:!!c,vulnId:c,refreshKey:Ee,onClose:C,onOpenVuln:ie,onEdit:K,onArchive:Ie,onDelete:Le,canWrite:v,canDelete:y,t:e,projectNames:Se}),(0,W.jsx)(Xe,{visible:z.visible,vulnId:z.id,t:e,projects:xe.data,onClose:()=>Te({visible:!1,id:``}),onSaved:Fe})]})}export{et as default}; \ No newline at end of file diff --git a/web/static/app/assets/webshell-CXOTGht5.js b/web/static/app/assets/webshell-CE6Yp5FY.js similarity index 99% rename from web/static/app/assets/webshell-CXOTGht5.js rename to web/static/app/assets/webshell-CE6Yp5FY.js index a5446a9d..c0bcff17 100644 --- a/web/static/app/assets/webshell-CXOTGht5.js +++ b/web/static/app/assets/webshell-CE6Yp5FY.js @@ -1,2 +1,2 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{E as i,G as a,I as o,N as s,R as c,S as l,U as u,W as d,c as f,ct as p,ft as m,i as h,lt as g,ut as _}from"./semi-65W_4I1v.js";import{E as v,F as y,I as b,L as x,S,a as C,b as w,c as T,f as E,l as ee,n as te,o as D,p as O,s as k,u as ne,x as A,y as j}from"./index-CAEPLS-g.js";import{t as M}from"./project-options-CMQbwv_U.js";var N=e(t(),1);function P(e){return x.get(`/webshell/connections`,e)}function F(e){return x.post(`/webshell/connections`,e)}function re(e,t){return x.put(`/webshell/connections/${encodeURIComponent(e)}`,t)}function ie(e){return x.del(`/webshell/connections/${encodeURIComponent(e)}`)}function ae(e){return x.get(`/webshell/connections/${encodeURIComponent(e)}/state`)}function oe(e,t){return x.put(`/webshell/connections/${encodeURIComponent(e)}/state`,{state:t})}function I({connection:e,command:t}){return x.post(`/webshell/exec`,{connection_id:e.id,url:e.url,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,command:t})}function L({connection:e,action:t,path:n,targetPath:r,content:i,chunkIndex:a}){let o={connection_id:e.id,url:e.url,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,action:t};return n!==void 0&&(o.path=n),r!==void 0&&(o.target_path=r),i!==void 0&&(o.content=i),a!==void 0&&(o.chunk_index=a),x.post(`/webshell/file`,o)}function se(e){return x.get(`/webshell/connections/${encodeURIComponent(e)}/ai-conversations`)}function R(e){return x.get(`/webshell/connections/${encodeURIComponent(e)}/ai-history`)}function z(e){return x.get(`/conversations/${encodeURIComponent(e)}`,{include_process_details:0})}async function ce(){try{let e=await x.get(`/projects`,{limit:200});return Array.isArray(e?.projects)?e.projects:[]}catch{return[]}}function le(){return`__CSAI_PROBE_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}__`}async function ue(e){let t=le(),n=await I({connection:e,command:`echo ${t}`});return{ok:!!n?.ok&&String(n?.output||``).includes(t),output:n?.output||``,error:n?.error||``}}var B=e(n(),1),{Text:V}=a,H=[{value:`php`,label:`PHP`},{value:`asp`,label:`ASP`},{value:`aspx`,label:`ASPX`},{value:`jsp`,label:`JSP`},{value:`custom`,label:`自定义`}],U=[{value:`post`,label:`POST`},{value:`get`,label:`GET`}],W=[{value:`auto`,label:`自动检测`},{value:`utf-8`,label:`UTF-8`},{value:`gbk`,label:`GBK(中文 Windows)`},{value:`gb18030`,label:`GB18030`}],G=[{value:`auto`,label:`自动(按 Shell 类型推断)`},{value:`linux`,label:`Linux / Unix`},{value:`windows`,label:`Windows`}];function K(e){return e?{url:e.url||``,password:e.password||``,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,remark:e.remark||``,project_id:e.project_id||``}:{url:``,password:``,type:`php`,method:`post`,cmd_param:``,encoding:`auto`,os:`auto`,remark:``,project_id:``}}function de({visible:e,record:t,projects:n,submitting:r,onCancel:i,onSubmit:a}){let s=y(),[l,u]=(0,N.useState)(null),[d,f]=(0,N.useState)(!1);return(0,B.jsx)(T,{visible:e,title:t?s(`webshell.editConnectionTitle`,null,`编辑连接`):s(`webshell.addConnection`,null,`添加连接`),footer:(0,B.jsxs)(o,{children:[(0,B.jsx)(c,{onClick:async()=>{let e=l?.getValues?.()||{},n=String(e.url||``).trim();if(!n)S(s(`webshell.url`,null,`请填写 Shell 地址`));else if(e.password===`********`)S(s(`webshell.testNoExpectedOutput`,null,`已保存口令不可用于新建测试,请填写口令`));else{f(!0);try{let r=await ue({id:t?.id||``,url:n,password:e.password||``,type:e.type||`php`,method:e.method||`post`,cmdParam:e.cmd_param||``,encoding:e.encoding||`auto`,os:e.os||`auto`});r.ok?A(s(`webshell.testSuccess`,null,`连通性正常,Shell 可访问`)):w(r.error||s(`webshell.testFailed`,null,`连通性测试失败`))}catch(e){w(e,s(`webshell.testFailed`,null,`连通性测试失败`))}finally{f(!1)}}},loading:d,children:s(`webshell.testConnectivity`,null,`测试连通性`)}),(0,B.jsx)(c,{onClick:i,children:s(`webshell.cancelEdit`,null,`取消`)}),(0,B.jsx)(c,{theme:`solid`,type:`primary`,loading:r,onClick:()=>l?.submitForm(),children:t?s(`webshell.saveFile`,null,`保存`):s(`webshell.addConnection`,null,`添加连接`)})]}),width:600,onCancel:i,children:(0,B.jsxs)(h,{initValues:K(t),onSubmit:e=>{a({url:String(e.url||``).trim(),password:e.password||``,type:e.type||`php`,method:e.method||`post`,cmd_param:String(e.cmd_param||``).trim(),encoding:e.encoding||`auto`,os:e.os||`auto`,remark:String(e.remark||``).trim(),project_id:e.project_id||``})},getFormApi:u,labelPosition:`top`,children:[(0,B.jsx)(h.Input,{field:`url`,label:s(`webshell.url`,null,`Shell 地址`),placeholder:`http(s)://target.com/shell.php`,rules:[{required:!0,message:s(`webshell.url`,null,`请填写 Shell 地址`)}]}),(0,B.jsx)(h.Input,{field:`password`,label:s(`webshell.password`,null,`连接密码/密钥`),placeholder:s(`webshell.passwordPlaceholder`,null,`如冰蝎/蚁剑的连接密码`)}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Select,{field:`type`,label:s(`webshell.type`,null,`Shell 类型`),optionList:H,style:{width:`100%`}}),(0,B.jsx)(h.Select,{field:`method`,label:s(`webshell.method`,null,`请求方式`),optionList:U,style:{width:`100%`}})]}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Input,{field:`cmd_param`,label:s(`webshell.cmdParam`,null,`命令参数名`),placeholder:`cmd`}),(0,B.jsx)(h.Select,{field:`encoding`,label:s(`webshell.encoding`,null,`响应编码`),optionList:W,style:{width:`100%`}})]}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Select,{field:`os`,label:s(`webshell.os`,null,`目标系统`),optionList:G,style:{width:`100%`}}),(0,B.jsx)(h.Select,{field:`project_id`,label:s(`webshell.project`,null,`所属项目`),optionList:M(n,s,{currentId:t?.project_id||``}),showClear:!0,style:{width:`100%`},placeholder:`可选`})]}),(0,B.jsx)(h.Input,{field:`remark`,label:s(`webshell.remark`,null,`备注`),placeholder:s(`webshell.remarkPlaceholder`,null,`便于识别的备注名`)}),(0,B.jsx)(V,{type:`tertiary`,size:`small`,children:s(`webshell.encodingHint`,null,`中文 Windows 目标若出现乱码,请切换为 GBK 或 GB18030`)})]},t?.id||`new`)})}var q={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11};function fe(e,t,n){if(!e||!t||!n)return``;let r=String(n).trim();if(/^\d{4}$/.test(r))return`${r} ${e} ${t}`;let i=new Date,a=i.getFullYear();if(/^\d{1,2}:\d{2}$/.test(r)){let n=q[e],o=parseInt(t,10);return n!=null&&!Number.isNaN(o)&&new Date(a,n,o).getTime()>i.getTime()&&--a,`${a} ${e} ${t} ${r}`}return`${e} ${t} ${r}`}function J(e){if(!e)return``;let t=e.charAt(0);return{d:`dir`,"-":`file`,l:`link`,c:`char`,b:`block`,s:`socket`,p:`pipe`}[t]||t}function Y(e){let t=String(e||``).match(/^(\d{4}[/-]\d{1,2}[/-]\d{1,2})\s+(\d{1,2}:\d{2})(?:\s*(AM|PM))?\s+(<[^>]+>|[\d,]+)\s+(.+?)\s*$/i);if(!t)return null;let n=(t[4]||``).trim(),r=(t[5]||``).trim();if(!r||r===`.`||r===`..`)return null;let i=/^<(dir|junction|symlinkd)>$/i.test(n);return{name:r,isDir:i,size:i?``:n.replace(/,/g,``),mtime:`${t[1]} ${t[2]}${t[3]?` ${t[3].toUpperCase()}`:``}`.trim(),mode:i?`d`:`-`,owner:``,group:``,type:i?`dir`:`file`}}var X=[/^(total|总计)\s+\d+$/i,/^(驱动器|卷的序列号是|volume in drive|volume serial number is|directory of)/i,/^[A-Za-z]:\\.*\s+的目录$/i,/^\d+\s+(个文件|file\(s\))\s+[\d,]+\s+(字节|bytes?)$/i,/^\d+\s+(个目录|dir\(s\))\s+[\d,]+\s+(可用字节|bytes free)$/i,/^[^>\n]*>\s*dir(?:\s|$)/i];function pe(e){let t=String(e||``).split(/\n/).filter(e=>e.trim()),n=[];for(let e of t){let t=e.trim();if(X.some(e=>e.test(t)))continue;let r=e.match(/^(\S+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d+)\s+([A-Za-z]{3})\s+(\d{1,2})\s+(\S+)\s+(.+)$/);if(r){let t=(r[9]||``).trim();if(t===`.`||t===`..`)continue;n.push({name:t,isDir:r[1].startsWith(`d`),size:r[5],mode:r[1],mtime:fe(r[6],r[7],r[8]),owner:r[3],group:r[4],type:J(r[1]),line:e});continue}let i=Y(e);if(i){n.push({...i,line:e});continue}if(!/^[bcdlps-][rwxStTs-]{9}[+.@]?\s/.test(e))continue;let a=t.split(/\s+/),o=(a.length>=9?a.slice(8).join(` `):a[a.length-1]||``).trim();o&&o!==`.`&&o!==`..`&&n.push({name:o,isDir:e.startsWith(`d`),size:a[4]||``,mode:a[0]||``,owner:a[2]||``,group:a[3]||``,mtime:a[5]&&/^[A-Za-z]{3}$/.test(a[5])?fe(a[5],a[6],a[7]):``,type:J(a[0]),line:e})}return n}function Z(e){let t=String(e??``).trim();return t?(t=t.replace(/\\/g,`/`).replace(/\/{2,}/g,`/`),t.length>1&&(t=t.replace(/\/+$/,``)),/^[A-Za-z]:$/.test(t)?`${t}/`:t||`.`):`.`}function Q(e,t){let n=Z(e);return t?t.startsWith(`/`)||/^[A-Za-z]:/.test(t)||n===`.`?Z(t):Z(n===`/`?`/${t}`:`${n}/${t}`):n}function me(e){let t=Z(e);if(t===`.`||t===`/`||/^[A-Za-z]:\/$/.test(t))return t;let n=t.lastIndexOf(`/`);if(n<0)return`.`;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r}function he(e){let t=Z(e),n=/^[A-Za-z]:/.test(t),r=!n&&t.startsWith(`/`),i=n?t.replace(/^[A-Za-z]:\/?/,``):t.replace(/^\//,``),a=t===`.`||t===`/`||!i?[]:i.split(`/`),o=[{label:n?t.slice(0,2)+`/`:r?`/`:`.`,path:n?`${t.slice(0,2)}/`:r?`/`:`.`}];return a.forEach((e,i)=>{let s=a.slice(0,i+1).join(`/`);o.push({label:e,path:n?`${t.slice(0,2)}/${s}`:r?`/${s}`:s})}),o}var{Text:ge}=a;function _e(e,t){let n=new Blob([t],{type:`application/octet-stream`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e||`download.bin`,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function ve({connection:e,canWrite:t}){let n=y(),[r,i]=(0,N.useState)(`.`),[a,d]=(0,N.useState)(`.`),[f,p]=(0,N.useState)(``),[m,h]=(0,N.useState)([]),[v,b]=(0,N.useState)(!1),[x,C]=(0,N.useState)(null),[E,te]=(0,N.useState)(``),[D,O]=(0,N.useState)({visible:!1,mode:`read`,path:``,content:``,loading:!1}),[M,P]=(0,N.useState)({visible:!1,mode:`mkdir`,title:``,value:``,target:``}),F=(0,N.useCallback)(async t=>{if(!e?.id)return;let n=Z(t??r);b(!0),C(null);try{let t=await L({connection:e,action:`list`,path:n});if(!t?.ok&&t?.error){C(t.error),h([]),p(t.output||``);return}p(t?.output||``),h(pe(t?.output||``)),i(n),d(n)}catch(e){C(e),h([])}finally{b(!1)}},[e,r]);(0,N.useEffect)(()=>{i(`.`),d(`.`),h([]),p(``),F(`.`)},[e?.id]);let re=async t=>{try{let n=await L({connection:e,action:`read`,path:t});return n?.error&&!n?.ok?(w(n.error),null):n?.output??``}catch(e){return w(e),null}},ie=async(e,t)=>{O({visible:!0,mode:t,path:e,content:``,loading:!0});let n=await re(e);O(e=>({...e,content:n??``,loading:!1}))},ae=async()=>{try{let t=await L({connection:e,action:`write`,path:D.path,content:D.content});if(t?.error&&!t?.ok){w(t.error);return}A(n(`webshell.saveFile`,null,`已保存`)),O(e=>({...e,visible:!1})),F(r)}catch(e){w(e)}},oe=async(e,t)=>{let n=await re(e);n!==null&&_e(t,n)},I=t=>{j({title:n(`webshell.deleteFile`,null,`删除文件`),content:t,onOk:async()=>{try{let i=await L({connection:e,action:`delete`,path:t});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.deleteFile`,null,`已删除`)),F(r)}catch(e){w(e)}}})},se=async()=>{let t=String(M.value||``).trim();if(!t)S(n(`webshell.filePath`,null,`请填写路径`));else try{if(M.mode===`mkdir`){let i=await L({connection:e,action:`mkdir`,path:Q(r,t)});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.newDir`,null,`目录已创建`))}else if(M.mode===`create`){let i=await L({connection:e,action:`write`,path:Q(r,t),content:``});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.newFile`,null,`文件已创建`))}else if(M.mode===`rename`){let r=await L({connection:e,action:`rename`,path:M.target,targetPath:Q(me(M.target),t)});if(r?.error&&!r?.ok){w(r.error);return}A(n(`webshell.rename`,null,`已重命名`))}P(e=>({...e,visible:!1})),F(r)}catch(e){w(e)}},R=(0,N.useMemo)(()=>{let e=E.trim().toLowerCase();return e?m.filter(t=>t.name.toLowerCase().includes(e)):m},[m,E]),z=(0,N.useMemo)(()=>he(r),[r]),ce=[{title:n(`webshell.colName`,null,`名称`),dataIndex:`name`,render:(e,t)=>(0,B.jsxs)(`button`,{type:`button`,className:`webshell-file-name ${t.isDir?`is-dir`:`is-file`}`,onClick:()=>t.isDir?F(Q(r,e)):ie(Q(r,e),`read`),title:e,children:[e,t.isDir?`/`:``]})},{title:n(`webshell.colType`,null,`类型`),dataIndex:`type`,width:90},{title:n(`webshell.colSize`,null,`大小`),dataIndex:`size`,width:110},{title:n(`webshell.colModifiedAt`,null,`修改时间`),dataIndex:`mtime`,width:170},{title:n(`webshell.colOwner`,null,`所有者`),dataIndex:`owner`,width:120},{title:n(`webshell.colPerms`,null,`权限`),dataIndex:`mode`,width:130},{title:n(`webshell.moreActions`,null,`操作`),dataIndex:`ops`,width:240,render:(e,i)=>{let a=Q(r,i.name);return(0,B.jsxs)(o,{spacing:4,wrap:!0,children:[i.isDir?(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>F(a),children:n(`webshell.listDir`,null,`打开`)}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>ie(a,`read`),children:n(`webshell.readFile`,null,`读取`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>ie(a,`write`),children:n(`webshell.editFile`,null,`编辑`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>oe(a,i.name),children:n(`webshell.downloadFile`,null,`下载`)})]}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>P({visible:!0,mode:`rename`,title:n(`webshell.rename`,null,`重命名`),value:i.name,target:a}),children:n(`webshell.rename`,null,`重命名`)}),!i.isDir&&(0,B.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>I(a),children:n(`webshell.deleteFile`,null,`删除`)})]})}}];return(0,B.jsxs)(`div`,{className:`webshell-files`,children:[(0,B.jsx)(`div`,{className:`webshell-file-toolbar`,children:(0,B.jsxs)(o,{spacing:8,wrap:!0,children:[(0,B.jsx)(c,{size:`small`,onClick:()=>F(me(r)),children:n(`webshell.parentDir`,null,`上级目录`)}),(0,B.jsx)(c,{size:`small`,icon:(0,B.jsx)(_,{}),onClick:()=>F(r),loading:v,children:n(`webshell.refresh`,null,`刷新`)}),(0,B.jsx)(c,{size:`small`,disabled:!t,onClick:()=>P({visible:!0,mode:`mkdir`,title:n(`webshell.newDir`,null,`新建目录`),value:``,target:``}),children:n(`webshell.newDir`,null,`新建目录`)}),(0,B.jsx)(c,{size:`small`,disabled:!t,onClick:()=>P({visible:!0,mode:`create`,title:n(`webshell.newFile`,null,`新建文件`),value:``,target:``}),children:n(`webshell.newFile`,null,`新建文件`)})]})}),(0,B.jsxs)(`div`,{className:`webshell-file-pathbar`,children:[(0,B.jsx)(ge,{type:`tertiary`,children:n(`webshell.filePath`,null,`当前路径`)}),(0,B.jsx)(u,{value:a,onChange:d,onEnterPress:()=>F(a),size:`small`,className:`webshell-file-path-input`}),(0,B.jsx)(c,{size:`small`,icon:(0,B.jsx)(g,{}),onClick:()=>F(a),children:n(`webshell.listDir`,null,`列出目录`)}),(0,B.jsx)(u,{value:E,onChange:te,placeholder:n(`webshell.filterPlaceholder`,null,`过滤文件名`),size:`small`,className:`webshell-file-filter`})]}),(0,B.jsx)(`nav`,{className:`webshell-breadcrumb`,"aria-label":`breadcrumb`,children:z.map((e,t)=>(0,B.jsxs)(`span`,{className:`webshell-breadcrumb-item`,children:[t>0&&(0,B.jsx)(`span`,{className:`webshell-breadcrumb-sep`,children:`/`}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>F(e.path),title:e.path,children:t===0?n(`webshell.breadcrumbHome`,null,`根`):e.label})]},e.path))}),(0,B.jsx)(ee,{error:x,onRetry:()=>F(r)}),m.length===0&&f.trim()&&!v?(0,B.jsx)(ne,{title:n(`webshell.filePath`,null,`原始输出`),value:f}):(0,B.jsx)(k,{columns:ce,dataSource:R,rowKey:`name`,loading:v,pagination:{pageSize:20},emptyText:n(`webshell.emptyDir`,null,`目录为空`)}),(0,B.jsxs)(T,{visible:D.visible,title:D.mode===`write`?n(`webshell.editFile`,null,`编辑文件`):n(`webshell.readFile`,null,`读取文件`),width:760,onCancel:()=>O(e=>({...e,visible:!1})),footer:(0,B.jsxs)(o,{children:[(0,B.jsx)(c,{onClick:()=>O(e=>({...e,visible:!1})),children:n(`webshell.cancelEdit`,null,`关闭`)}),D.mode===`write`&&(0,B.jsx)(c,{theme:`solid`,type:`primary`,disabled:!t,onClick:ae,children:n(`webshell.saveFile`,null,`保存`)})]}),children:[(0,B.jsx)(`div`,{className:`webshell-editor-path`,children:(0,B.jsx)(s,{size:`small`,children:D.path})}),(0,B.jsx)(l,{value:D.content,onChange:e=>O(t=>({...t,content:e})),autosize:{minRows:12,maxRows:24},disabled:D.mode!==`write`,className:`webshell-editor-area`})]}),(0,B.jsx)(T,{visible:M.visible,title:M.title,width:420,onCancel:()=>P(e=>({...e,visible:!1})),onOk:se,children:(0,B.jsx)(u,{value:M.value,onChange:e=>P(t=>({...t,value:e})),placeholder:M.mode===`rename`?n(`webshell.rename`,null,`新名称`):n(`webshell.filePath`,null,`名称或路径`)})})]})}var ye=0,be=()=>(ye+=1,ye);function xe({connection:e,canWrite:t,onRecordCommand:n}){let r=y(),[i,a]=(0,N.useState)([]),[l,d]=(0,N.useState)(``),[f,m]=(0,N.useState)(!1),h=(0,N.useRef)(null),g=(0,N.useCallback)(e=>{a(t=>[...t,{id:be(),...e}])},[]);(0,N.useEffect)(()=>{a([]),d(``)},[e?.id]),(0,N.useEffect)(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let _=async i=>{let a=String(i??l).trim();if(a){if(!t)S(r(`webshell.webshellWriteRequired`,null,`当前账号没有执行权限`));else{d(``),g({kind:`cmd`,text:a}),n?.(a),m(!0);try{let t=await I({connection:e,command:a});t?.output&&g({kind:`out`,text:t.output}),t?.error&&g({kind:`err`,text:t.error}),!t?.ok&&!t?.error&&g({kind:`err`,text:r(`webshell.execError`,null,`执行失败`)})}catch(e){g({kind:`err`,text:e?.message||r(`webshell.execError`,null,`执行失败`)}),w(e)}finally{m(!1)}}}};return(0,B.jsxs)(`div`,{className:`webshell-terminal`,children:[(0,B.jsx)(`div`,{className:`webshell-terminal-bar`,children:(0,B.jsxs)(o,{spacing:8,children:[(0,B.jsx)(s,{size:`small`,color:f?`amber`:`green`,children:f?r(`webshell.terminalRunning`,null,`执行中`):r(`webshell.terminalIdle`,null,`空闲`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>a([]),children:r(`webshell.clearScreen`,null,`清屏`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:async()=>{let e=i.map(e=>e.kind===`cmd`?`$ ${e.text}`:e.text).join(` +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{E as i,G as a,I as o,N as s,R as c,S as l,U as u,W as d,c as f,ct as p,ft as m,i as h,lt as g,ut as _}from"./semi-65W_4I1v.js";import{E as v,F as y,I as b,L as x,S,a as C,b as w,c as T,f as E,l as ee,n as te,o as D,p as O,s as k,u as ne,x as A,y as j}from"./index-DNMXun-U.js";import{t as M}from"./project-options-CMQbwv_U.js";var N=e(t(),1);function P(e){return x.get(`/webshell/connections`,e)}function F(e){return x.post(`/webshell/connections`,e)}function re(e,t){return x.put(`/webshell/connections/${encodeURIComponent(e)}`,t)}function ie(e){return x.del(`/webshell/connections/${encodeURIComponent(e)}`)}function ae(e){return x.get(`/webshell/connections/${encodeURIComponent(e)}/state`)}function oe(e,t){return x.put(`/webshell/connections/${encodeURIComponent(e)}/state`,{state:t})}function I({connection:e,command:t}){return x.post(`/webshell/exec`,{connection_id:e.id,url:e.url,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,command:t})}function L({connection:e,action:t,path:n,targetPath:r,content:i,chunkIndex:a}){let o={connection_id:e.id,url:e.url,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,action:t};return n!==void 0&&(o.path=n),r!==void 0&&(o.target_path=r),i!==void 0&&(o.content=i),a!==void 0&&(o.chunk_index=a),x.post(`/webshell/file`,o)}function se(e){return x.get(`/webshell/connections/${encodeURIComponent(e)}/ai-conversations`)}function R(e){return x.get(`/webshell/connections/${encodeURIComponent(e)}/ai-history`)}function z(e){return x.get(`/conversations/${encodeURIComponent(e)}`,{include_process_details:0})}async function ce(){try{let e=await x.get(`/projects`,{limit:200});return Array.isArray(e?.projects)?e.projects:[]}catch{return[]}}function le(){return`__CSAI_PROBE_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}__`}async function ue(e){let t=le(),n=await I({connection:e,command:`echo ${t}`});return{ok:!!n?.ok&&String(n?.output||``).includes(t),output:n?.output||``,error:n?.error||``}}var B=e(n(),1),{Text:V}=a,H=[{value:`php`,label:`PHP`},{value:`asp`,label:`ASP`},{value:`aspx`,label:`ASPX`},{value:`jsp`,label:`JSP`},{value:`custom`,label:`自定义`}],U=[{value:`post`,label:`POST`},{value:`get`,label:`GET`}],W=[{value:`auto`,label:`自动检测`},{value:`utf-8`,label:`UTF-8`},{value:`gbk`,label:`GBK(中文 Windows)`},{value:`gb18030`,label:`GB18030`}],G=[{value:`auto`,label:`自动(按 Shell 类型推断)`},{value:`linux`,label:`Linux / Unix`},{value:`windows`,label:`Windows`}];function K(e){return e?{url:e.url||``,password:e.password||``,type:e.type||`php`,method:(e.method||`post`).toLowerCase(),cmd_param:e.cmdParam||``,encoding:e.encoding||`auto`,os:e.os||`auto`,remark:e.remark||``,project_id:e.project_id||``}:{url:``,password:``,type:`php`,method:`post`,cmd_param:``,encoding:`auto`,os:`auto`,remark:``,project_id:``}}function de({visible:e,record:t,projects:n,submitting:r,onCancel:i,onSubmit:a}){let s=y(),[l,u]=(0,N.useState)(null),[d,f]=(0,N.useState)(!1);return(0,B.jsx)(T,{visible:e,title:t?s(`webshell.editConnectionTitle`,null,`编辑连接`):s(`webshell.addConnection`,null,`添加连接`),footer:(0,B.jsxs)(o,{children:[(0,B.jsx)(c,{onClick:async()=>{let e=l?.getValues?.()||{},n=String(e.url||``).trim();if(!n)S(s(`webshell.url`,null,`请填写 Shell 地址`));else if(e.password===`********`)S(s(`webshell.testNoExpectedOutput`,null,`已保存口令不可用于新建测试,请填写口令`));else{f(!0);try{let r=await ue({id:t?.id||``,url:n,password:e.password||``,type:e.type||`php`,method:e.method||`post`,cmdParam:e.cmd_param||``,encoding:e.encoding||`auto`,os:e.os||`auto`});r.ok?A(s(`webshell.testSuccess`,null,`连通性正常,Shell 可访问`)):w(r.error||s(`webshell.testFailed`,null,`连通性测试失败`))}catch(e){w(e,s(`webshell.testFailed`,null,`连通性测试失败`))}finally{f(!1)}}},loading:d,children:s(`webshell.testConnectivity`,null,`测试连通性`)}),(0,B.jsx)(c,{onClick:i,children:s(`webshell.cancelEdit`,null,`取消`)}),(0,B.jsx)(c,{theme:`solid`,type:`primary`,loading:r,onClick:()=>l?.submitForm(),children:t?s(`webshell.saveFile`,null,`保存`):s(`webshell.addConnection`,null,`添加连接`)})]}),width:600,onCancel:i,children:(0,B.jsxs)(h,{initValues:K(t),onSubmit:e=>{a({url:String(e.url||``).trim(),password:e.password||``,type:e.type||`php`,method:e.method||`post`,cmd_param:String(e.cmd_param||``).trim(),encoding:e.encoding||`auto`,os:e.os||`auto`,remark:String(e.remark||``).trim(),project_id:e.project_id||``})},getFormApi:u,labelPosition:`top`,children:[(0,B.jsx)(h.Input,{field:`url`,label:s(`webshell.url`,null,`Shell 地址`),placeholder:`http(s)://target.com/shell.php`,rules:[{required:!0,message:s(`webshell.url`,null,`请填写 Shell 地址`)}]}),(0,B.jsx)(h.Input,{field:`password`,label:s(`webshell.password`,null,`连接密码/密钥`),placeholder:s(`webshell.passwordPlaceholder`,null,`如冰蝎/蚁剑的连接密码`)}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Select,{field:`type`,label:s(`webshell.type`,null,`Shell 类型`),optionList:H,style:{width:`100%`}}),(0,B.jsx)(h.Select,{field:`method`,label:s(`webshell.method`,null,`请求方式`),optionList:U,style:{width:`100%`}})]}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Input,{field:`cmd_param`,label:s(`webshell.cmdParam`,null,`命令参数名`),placeholder:`cmd`}),(0,B.jsx)(h.Select,{field:`encoding`,label:s(`webshell.encoding`,null,`响应编码`),optionList:W,style:{width:`100%`}})]}),(0,B.jsxs)(`div`,{className:`webshell-form-row`,children:[(0,B.jsx)(h.Select,{field:`os`,label:s(`webshell.os`,null,`目标系统`),optionList:G,style:{width:`100%`}}),(0,B.jsx)(h.Select,{field:`project_id`,label:s(`webshell.project`,null,`所属项目`),optionList:M(n,s,{currentId:t?.project_id||``}),showClear:!0,style:{width:`100%`},placeholder:`可选`})]}),(0,B.jsx)(h.Input,{field:`remark`,label:s(`webshell.remark`,null,`备注`),placeholder:s(`webshell.remarkPlaceholder`,null,`便于识别的备注名`)}),(0,B.jsx)(V,{type:`tertiary`,size:`small`,children:s(`webshell.encodingHint`,null,`中文 Windows 目标若出现乱码,请切换为 GBK 或 GB18030`)})]},t?.id||`new`)})}var q={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11};function fe(e,t,n){if(!e||!t||!n)return``;let r=String(n).trim();if(/^\d{4}$/.test(r))return`${r} ${e} ${t}`;let i=new Date,a=i.getFullYear();if(/^\d{1,2}:\d{2}$/.test(r)){let n=q[e],o=parseInt(t,10);return n!=null&&!Number.isNaN(o)&&new Date(a,n,o).getTime()>i.getTime()&&--a,`${a} ${e} ${t} ${r}`}return`${e} ${t} ${r}`}function J(e){if(!e)return``;let t=e.charAt(0);return{d:`dir`,"-":`file`,l:`link`,c:`char`,b:`block`,s:`socket`,p:`pipe`}[t]||t}function Y(e){let t=String(e||``).match(/^(\d{4}[/-]\d{1,2}[/-]\d{1,2})\s+(\d{1,2}:\d{2})(?:\s*(AM|PM))?\s+(<[^>]+>|[\d,]+)\s+(.+?)\s*$/i);if(!t)return null;let n=(t[4]||``).trim(),r=(t[5]||``).trim();if(!r||r===`.`||r===`..`)return null;let i=/^<(dir|junction|symlinkd)>$/i.test(n);return{name:r,isDir:i,size:i?``:n.replace(/,/g,``),mtime:`${t[1]} ${t[2]}${t[3]?` ${t[3].toUpperCase()}`:``}`.trim(),mode:i?`d`:`-`,owner:``,group:``,type:i?`dir`:`file`}}var X=[/^(total|总计)\s+\d+$/i,/^(驱动器|卷的序列号是|volume in drive|volume serial number is|directory of)/i,/^[A-Za-z]:\\.*\s+的目录$/i,/^\d+\s+(个文件|file\(s\))\s+[\d,]+\s+(字节|bytes?)$/i,/^\d+\s+(个目录|dir\(s\))\s+[\d,]+\s+(可用字节|bytes free)$/i,/^[^>\n]*>\s*dir(?:\s|$)/i];function pe(e){let t=String(e||``).split(/\n/).filter(e=>e.trim()),n=[];for(let e of t){let t=e.trim();if(X.some(e=>e.test(t)))continue;let r=e.match(/^(\S+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d+)\s+([A-Za-z]{3})\s+(\d{1,2})\s+(\S+)\s+(.+)$/);if(r){let t=(r[9]||``).trim();if(t===`.`||t===`..`)continue;n.push({name:t,isDir:r[1].startsWith(`d`),size:r[5],mode:r[1],mtime:fe(r[6],r[7],r[8]),owner:r[3],group:r[4],type:J(r[1]),line:e});continue}let i=Y(e);if(i){n.push({...i,line:e});continue}if(!/^[bcdlps-][rwxStTs-]{9}[+.@]?\s/.test(e))continue;let a=t.split(/\s+/),o=(a.length>=9?a.slice(8).join(` `):a[a.length-1]||``).trim();o&&o!==`.`&&o!==`..`&&n.push({name:o,isDir:e.startsWith(`d`),size:a[4]||``,mode:a[0]||``,owner:a[2]||``,group:a[3]||``,mtime:a[5]&&/^[A-Za-z]{3}$/.test(a[5])?fe(a[5],a[6],a[7]):``,type:J(a[0]),line:e})}return n}function Z(e){let t=String(e??``).trim();return t?(t=t.replace(/\\/g,`/`).replace(/\/{2,}/g,`/`),t.length>1&&(t=t.replace(/\/+$/,``)),/^[A-Za-z]:$/.test(t)?`${t}/`:t||`.`):`.`}function Q(e,t){let n=Z(e);return t?t.startsWith(`/`)||/^[A-Za-z]:/.test(t)||n===`.`?Z(t):Z(n===`/`?`/${t}`:`${n}/${t}`):n}function me(e){let t=Z(e);if(t===`.`||t===`/`||/^[A-Za-z]:\/$/.test(t))return t;let n=t.lastIndexOf(`/`);if(n<0)return`.`;if(n===0)return`/`;let r=t.slice(0,n);return/^[A-Za-z]:$/.test(r)?`${r}/`:r}function he(e){let t=Z(e),n=/^[A-Za-z]:/.test(t),r=!n&&t.startsWith(`/`),i=n?t.replace(/^[A-Za-z]:\/?/,``):t.replace(/^\//,``),a=t===`.`||t===`/`||!i?[]:i.split(`/`),o=[{label:n?t.slice(0,2)+`/`:r?`/`:`.`,path:n?`${t.slice(0,2)}/`:r?`/`:`.`}];return a.forEach((e,i)=>{let s=a.slice(0,i+1).join(`/`);o.push({label:e,path:n?`${t.slice(0,2)}/${s}`:r?`/${s}`:s})}),o}var{Text:ge}=a;function _e(e,t){let n=new Blob([t],{type:`application/octet-stream`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e||`download.bin`,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function ve({connection:e,canWrite:t}){let n=y(),[r,i]=(0,N.useState)(`.`),[a,d]=(0,N.useState)(`.`),[f,p]=(0,N.useState)(``),[m,h]=(0,N.useState)([]),[v,b]=(0,N.useState)(!1),[x,C]=(0,N.useState)(null),[E,te]=(0,N.useState)(``),[D,O]=(0,N.useState)({visible:!1,mode:`read`,path:``,content:``,loading:!1}),[M,P]=(0,N.useState)({visible:!1,mode:`mkdir`,title:``,value:``,target:``}),F=(0,N.useCallback)(async t=>{if(!e?.id)return;let n=Z(t??r);b(!0),C(null);try{let t=await L({connection:e,action:`list`,path:n});if(!t?.ok&&t?.error){C(t.error),h([]),p(t.output||``);return}p(t?.output||``),h(pe(t?.output||``)),i(n),d(n)}catch(e){C(e),h([])}finally{b(!1)}},[e,r]);(0,N.useEffect)(()=>{i(`.`),d(`.`),h([]),p(``),F(`.`)},[e?.id]);let re=async t=>{try{let n=await L({connection:e,action:`read`,path:t});return n?.error&&!n?.ok?(w(n.error),null):n?.output??``}catch(e){return w(e),null}},ie=async(e,t)=>{O({visible:!0,mode:t,path:e,content:``,loading:!0});let n=await re(e);O(e=>({...e,content:n??``,loading:!1}))},ae=async()=>{try{let t=await L({connection:e,action:`write`,path:D.path,content:D.content});if(t?.error&&!t?.ok){w(t.error);return}A(n(`webshell.saveFile`,null,`已保存`)),O(e=>({...e,visible:!1})),F(r)}catch(e){w(e)}},oe=async(e,t)=>{let n=await re(e);n!==null&&_e(t,n)},I=t=>{j({title:n(`webshell.deleteFile`,null,`删除文件`),content:t,onOk:async()=>{try{let i=await L({connection:e,action:`delete`,path:t});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.deleteFile`,null,`已删除`)),F(r)}catch(e){w(e)}}})},se=async()=>{let t=String(M.value||``).trim();if(!t)S(n(`webshell.filePath`,null,`请填写路径`));else try{if(M.mode===`mkdir`){let i=await L({connection:e,action:`mkdir`,path:Q(r,t)});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.newDir`,null,`目录已创建`))}else if(M.mode===`create`){let i=await L({connection:e,action:`write`,path:Q(r,t),content:``});if(i?.error&&!i?.ok){w(i.error);return}A(n(`webshell.newFile`,null,`文件已创建`))}else if(M.mode===`rename`){let r=await L({connection:e,action:`rename`,path:M.target,targetPath:Q(me(M.target),t)});if(r?.error&&!r?.ok){w(r.error);return}A(n(`webshell.rename`,null,`已重命名`))}P(e=>({...e,visible:!1})),F(r)}catch(e){w(e)}},R=(0,N.useMemo)(()=>{let e=E.trim().toLowerCase();return e?m.filter(t=>t.name.toLowerCase().includes(e)):m},[m,E]),z=(0,N.useMemo)(()=>he(r),[r]),ce=[{title:n(`webshell.colName`,null,`名称`),dataIndex:`name`,render:(e,t)=>(0,B.jsxs)(`button`,{type:`button`,className:`webshell-file-name ${t.isDir?`is-dir`:`is-file`}`,onClick:()=>t.isDir?F(Q(r,e)):ie(Q(r,e),`read`),title:e,children:[e,t.isDir?`/`:``]})},{title:n(`webshell.colType`,null,`类型`),dataIndex:`type`,width:90},{title:n(`webshell.colSize`,null,`大小`),dataIndex:`size`,width:110},{title:n(`webshell.colModifiedAt`,null,`修改时间`),dataIndex:`mtime`,width:170},{title:n(`webshell.colOwner`,null,`所有者`),dataIndex:`owner`,width:120},{title:n(`webshell.colPerms`,null,`权限`),dataIndex:`mode`,width:130},{title:n(`webshell.moreActions`,null,`操作`),dataIndex:`ops`,width:240,render:(e,i)=>{let a=Q(r,i.name);return(0,B.jsxs)(o,{spacing:4,wrap:!0,children:[i.isDir?(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>F(a),children:n(`webshell.listDir`,null,`打开`)}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>ie(a,`read`),children:n(`webshell.readFile`,null,`读取`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>ie(a,`write`),children:n(`webshell.editFile`,null,`编辑`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>oe(a,i.name),children:n(`webshell.downloadFile`,null,`下载`)})]}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,disabled:!t,onClick:()=>P({visible:!0,mode:`rename`,title:n(`webshell.rename`,null,`重命名`),value:i.name,target:a}),children:n(`webshell.rename`,null,`重命名`)}),!i.isDir&&(0,B.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,disabled:!t,onClick:()=>I(a),children:n(`webshell.deleteFile`,null,`删除`)})]})}}];return(0,B.jsxs)(`div`,{className:`webshell-files`,children:[(0,B.jsx)(`div`,{className:`webshell-file-toolbar`,children:(0,B.jsxs)(o,{spacing:8,wrap:!0,children:[(0,B.jsx)(c,{size:`small`,onClick:()=>F(me(r)),children:n(`webshell.parentDir`,null,`上级目录`)}),(0,B.jsx)(c,{size:`small`,icon:(0,B.jsx)(_,{}),onClick:()=>F(r),loading:v,children:n(`webshell.refresh`,null,`刷新`)}),(0,B.jsx)(c,{size:`small`,disabled:!t,onClick:()=>P({visible:!0,mode:`mkdir`,title:n(`webshell.newDir`,null,`新建目录`),value:``,target:``}),children:n(`webshell.newDir`,null,`新建目录`)}),(0,B.jsx)(c,{size:`small`,disabled:!t,onClick:()=>P({visible:!0,mode:`create`,title:n(`webshell.newFile`,null,`新建文件`),value:``,target:``}),children:n(`webshell.newFile`,null,`新建文件`)})]})}),(0,B.jsxs)(`div`,{className:`webshell-file-pathbar`,children:[(0,B.jsx)(ge,{type:`tertiary`,children:n(`webshell.filePath`,null,`当前路径`)}),(0,B.jsx)(u,{value:a,onChange:d,onEnterPress:()=>F(a),size:`small`,className:`webshell-file-path-input`}),(0,B.jsx)(c,{size:`small`,icon:(0,B.jsx)(g,{}),onClick:()=>F(a),children:n(`webshell.listDir`,null,`列出目录`)}),(0,B.jsx)(u,{value:E,onChange:te,placeholder:n(`webshell.filterPlaceholder`,null,`过滤文件名`),size:`small`,className:`webshell-file-filter`})]}),(0,B.jsx)(`nav`,{className:`webshell-breadcrumb`,"aria-label":`breadcrumb`,children:z.map((e,t)=>(0,B.jsxs)(`span`,{className:`webshell-breadcrumb-item`,children:[t>0&&(0,B.jsx)(`span`,{className:`webshell-breadcrumb-sep`,children:`/`}),(0,B.jsx)(`button`,{type:`button`,onClick:()=>F(e.path),title:e.path,children:t===0?n(`webshell.breadcrumbHome`,null,`根`):e.label})]},e.path))}),(0,B.jsx)(ee,{error:x,onRetry:()=>F(r)}),m.length===0&&f.trim()&&!v?(0,B.jsx)(ne,{title:n(`webshell.filePath`,null,`原始输出`),value:f}):(0,B.jsx)(k,{columns:ce,dataSource:R,rowKey:`name`,loading:v,pagination:{pageSize:20},emptyText:n(`webshell.emptyDir`,null,`目录为空`)}),(0,B.jsxs)(T,{visible:D.visible,title:D.mode===`write`?n(`webshell.editFile`,null,`编辑文件`):n(`webshell.readFile`,null,`读取文件`),width:760,onCancel:()=>O(e=>({...e,visible:!1})),footer:(0,B.jsxs)(o,{children:[(0,B.jsx)(c,{onClick:()=>O(e=>({...e,visible:!1})),children:n(`webshell.cancelEdit`,null,`关闭`)}),D.mode===`write`&&(0,B.jsx)(c,{theme:`solid`,type:`primary`,disabled:!t,onClick:ae,children:n(`webshell.saveFile`,null,`保存`)})]}),children:[(0,B.jsx)(`div`,{className:`webshell-editor-path`,children:(0,B.jsx)(s,{size:`small`,children:D.path})}),(0,B.jsx)(l,{value:D.content,onChange:e=>O(t=>({...t,content:e})),autosize:{minRows:12,maxRows:24},disabled:D.mode!==`write`,className:`webshell-editor-area`})]}),(0,B.jsx)(T,{visible:M.visible,title:M.title,width:420,onCancel:()=>P(e=>({...e,visible:!1})),onOk:se,children:(0,B.jsx)(u,{value:M.value,onChange:e=>P(t=>({...t,value:e})),placeholder:M.mode===`rename`?n(`webshell.rename`,null,`新名称`):n(`webshell.filePath`,null,`名称或路径`)})})]})}var ye=0,be=()=>(ye+=1,ye);function xe({connection:e,canWrite:t,onRecordCommand:n}){let r=y(),[i,a]=(0,N.useState)([]),[l,d]=(0,N.useState)(``),[f,m]=(0,N.useState)(!1),h=(0,N.useRef)(null),g=(0,N.useCallback)(e=>{a(t=>[...t,{id:be(),...e}])},[]);(0,N.useEffect)(()=>{a([]),d(``)},[e?.id]),(0,N.useEffect)(()=>{let e=h.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let _=async i=>{let a=String(i??l).trim();if(a){if(!t)S(r(`webshell.webshellWriteRequired`,null,`当前账号没有执行权限`));else{d(``),g({kind:`cmd`,text:a}),n?.(a),m(!0);try{let t=await I({connection:e,command:a});t?.output&&g({kind:`out`,text:t.output}),t?.error&&g({kind:`err`,text:t.error}),!t?.ok&&!t?.error&&g({kind:`err`,text:r(`webshell.execError`,null,`执行失败`)})}catch(e){g({kind:`err`,text:e?.message||r(`webshell.execError`,null,`执行失败`)}),w(e)}finally{m(!1)}}}};return(0,B.jsxs)(`div`,{className:`webshell-terminal`,children:[(0,B.jsx)(`div`,{className:`webshell-terminal-bar`,children:(0,B.jsxs)(o,{spacing:8,children:[(0,B.jsx)(s,{size:`small`,color:f?`amber`:`green`,children:f?r(`webshell.terminalRunning`,null,`执行中`):r(`webshell.terminalIdle`,null,`空闲`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>a([]),children:r(`webshell.clearScreen`,null,`清屏`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:async()=>{let e=i.map(e=>e.kind===`cmd`?`$ ${e.text}`:e.text).join(` `);try{await navigator.clipboard.writeText(e),A(r(`webshell.terminalCopyOk`,null,`日志已复制`))}catch(e){w(e,r(`webshell.terminalCopyFail`,null,`复制失败`))}},children:r(`webshell.copyTerminalLog`,null,`复制日志`)})]})}),(0,B.jsxs)(`div`,{className:`webshell-terminal-log`,ref:h,children:[(0,B.jsx)(`div`,{className:`webshell-terminal-welcome`,children:r(`webshell.terminalWelcome`,null,`WebShell 虚拟终端 — 输入命令后按回车执行(Ctrl+L 清屏)`)}),i.map(e=>(0,B.jsx)(`pre`,{className:`webshell-terminal-line kind-${e.kind}`,children:e.kind===`cmd`?`$ ${e.text}`:e.text},e.id)),f&&(0,B.jsx)(`div`,{className:`webshell-terminal-pending`,children:r(`webshell.running`,null,`执行中…`)})]}),(0,B.jsxs)(`div`,{className:`webshell-terminal-input`,children:[(0,B.jsx)(u,{value:l,onChange:d,onEnterPress:()=>f?S(r(`webshell.waitFinish`,null,`请等待当前命令执行完成`)):_(),onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`l`&&(e.preventDefault(),a([]))},placeholder:r(`webshell.commandPlaceholder`,null,`输入命令后回车执行`),disabled:f||!t,prefix:`$`}),(0,B.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,B.jsx)(p,{}),loading:f,disabled:!t,onClick:()=>_(),children:r(`webshell.runCommand`,null,`执行`)})]})]})}var{Text:Se}=a;function Ce({history:e,onClear:t,onRemove:n,onRun:r}){let i=y(),a=e.map((e,t)=>({...e,rowId:`${t}-${e.at}`})),s=[{title:i(`webshell.colCommand`,null,`命令`),dataIndex:`command`,render:e=>(0,B.jsx)(`code`,{className:`webshell-history-cmd`,children:e})},{title:i(`webshell.colExecutedAt`,null,`执行时间`),dataIndex:`at`,width:200,render:e=>v(e)},{title:i(`webshell.moreActions`,null,`操作`),dataIndex:`ops`,width:220,render:(e,t)=>(0,B.jsxs)(o,{spacing:4,children:[(0,B.jsx)(D,{text:t.command,label:i(`common.copied`,null,`复制`),size:`small`}),r&&(0,B.jsx)(c,{size:`small`,theme:`borderless`,onClick:()=>r(t.command),children:i(`webshell.rerun`,null,`再执行`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,type:`danger`,onClick:()=>j({title:i(`webshell.deleteHistory`,null,`删除该条历史`),content:t.command,onOk:()=>n(t.rowId)}),children:i(`webshell.deleteFile`,null,`删除`)})]})}];return(0,B.jsxs)(`div`,{className:`webshell-history`,children:[(0,B.jsxs)(`div`,{className:`webshell-history-toolbar`,children:[(0,B.jsx)(Se,{type:`tertiary`,children:i(`webshell.historyHint`,null,`仅记录本连接在当前浏览器执行过的命令`)}),(0,B.jsx)(o,{spacing:8,children:t&&(0,B.jsx)(c,{size:`small`,disabled:!a.length,onClick:()=>t(),children:i(`webshell.clearHistory`,null,`清空历史`)})})]}),(0,B.jsx)(k,{columns:s,dataSource:a,rowKey:`rowId`,pagination:{pageSize:15},emptyText:i(`webshell.noHistory`,null,`暂无命令历史`)})]})}var{Text:we}=a,Te={user:`blue`,assistant:`green`,system:`grey`,tool:`violet`};function Ee({connection:e}){let t=y(),[n,r]=(0,N.useState)([]),[a,o]=(0,N.useState)(``),[l,u]=(0,N.useState)([]),[f,p]=(0,N.useState)(!1),[m,h]=(0,N.useState)(null),g=(0,N.useCallback)(async()=>{if(e?.id){p(!0),h(null);try{let[t,n]=await Promise.all([se(e.id).catch(()=>[]),R(e.id).catch(()=>null)]),i=Array.isArray(t)?t:[];r(i);let a=n?.conversationId||i[0]?.id||``;if(o(a),n?.conversationId)u(Array.isArray(n.messages)?n.messages:[]);else if(a){let e=await z(a).catch(()=>null);u(Array.isArray(e?.messages)?e.messages:[])}else u([])}catch(e){h(e)}finally{p(!1)}}},[e?.id]);(0,N.useEffect)(()=>{g()},[g]);let b=async e=>{if(e){o(e),p(!0);try{let t=await z(e);u(Array.isArray(t?.messages)?t.messages:[])}catch(e){h(e),u([])}finally{p(!1)}}};return(0,B.jsxs)(`div`,{className:`webshell-ai`,children:[(0,B.jsxs)(`div`,{className:`webshell-ai-sidebar`,children:[(0,B.jsxs)(`div`,{className:`webshell-ai-sidebar-head`,children:[(0,B.jsx)(we,{strong:!0,children:t(`webshell.aiPreviousConversation`,null,`之前的对话`)}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,icon:(0,B.jsx)(_,{}),onClick:g,loading:f})]}),n.length===0?(0,B.jsx)(i,{title:t(`webshell.aiNoConversation`,null,`暂无 AI 会话`),description:null,style:{padding:24}}):(0,B.jsx)(`ul`,{className:`webshell-ai-list`,children:n.map(e=>(0,B.jsx)(`li`,{children:(0,B.jsxs)(`button`,{type:`button`,className:`webshell-ai-item ${e.id===a?`is-active`:``}`,onClick:()=>b(e.id),children:[(0,B.jsx)(`span`,{className:`webshell-ai-title`,children:e.title||e.id}),(0,B.jsx)(`span`,{className:`webshell-ai-time`,children:v(e.updatedAt)})]})},e.id))})]}),(0,B.jsxs)(`div`,{className:`webshell-ai-main`,children:[(0,B.jsx)(ee,{error:m,onRetry:g}),f&&(0,B.jsx)(`div`,{className:`webshell-ai-loading`,children:(0,B.jsx)(d,{})}),!f&&l.length===0&&(0,B.jsx)(i,{title:t(`webshell.aiNoMessage`,null,`暂无对话消息`),description:null,style:{padding:48}}),!f&&l.map(e=>(0,B.jsxs)(`div`,{className:`webshell-ai-message`,children:[(0,B.jsxs)(`div`,{className:`webshell-ai-message-head`,children:[(0,B.jsx)(s,{size:`small`,color:Te[e.role]||`grey`,children:e.role||`message`}),(0,B.jsx)(we,{type:`tertiary`,size:`small`,children:v(e.createdAt)})]}),(0,B.jsx)(E,{content:e.content||``})]},e.id||`${e.role}-${e.createdAt}`))]})]})}var{Text:$}=a,De={auto:`自动`,"utf-8":`UTF-8`,gbk:`GBK`,gb18030:`GB18030`};function Oe(e){return e===`online`?`green`:e===`probing`?`amber`:e===`offline`?`red`:`grey`}function ke(){let e=y(),{hasPermission:t}=b(),n=t(`webshell:write`),a=t(`webshell:delete`)||n,[p,h]=r(),v=p.get(`id`)||``,[x,T]=(0,N.useState)(``),E=te(x,250),[D,k]=(0,N.useState)({}),[ne,M]=(0,N.useState)(!1),[I,L]=(0,N.useState)({visible:!1,record:null}),[se,R]=(0,N.useState)(!1),[z,le]=(0,N.useState)([]),[V,H]=(0,N.useState)(``),[U,W]=(0,N.useState)([]),G=(0,N.useRef)(null),{data:K,loading:q,error:fe,reload:J}=C(()=>P(),[]),Y=(0,N.useMemo)(()=>Array.isArray(K)?K:[],[K]);(0,N.useEffect)(()=>{ce().then(le)},[]);let X=(0,N.useMemo)(()=>Y.find(e=>e.id===v)||null,[Y,v]),pe=e=>{let t=new URLSearchParams(p);e?t.set(`id`,e):t.delete(`id`),h(t,{replace:!0})},Z=(0,N.useCallback)(e=>{n&&v&&(G.current&&clearTimeout(G.current),G.current=setTimeout(()=>{oe(v,e).catch(()=>{})},700))},[n,v]);(0,N.useEffect)(()=>{let e=!1;return H(``),W([]),v&&ae(v).then(t=>{if(e)return;let n=t?.state||{};H(typeof n.memo==`string`?n.memo:``),W(Array.isArray(n.commands)?n.commands:[])}).catch(()=>{}),()=>{e=!0}},[v]);let Q=e=>{H(e),Z({memo:e,commands:U})},me=e=>{let t=[...U,{command:e,at:new Date().toISOString()}].slice(-200);W(t),Z({memo:V,commands:t})},he=e=>{let t=U.filter((t,n)=>`${n}-${t.at}`!==e);W(t),Z({memo:V,commands:t})},ge=()=>{j({title:e(`webshell.clearHistory`,null,`清空历史`),content:e(`webshell.clearHistoryConfirm`,null,`确定清空该连接的命令历史?`),onOk:()=>{W([]),Z({memo:V,commands:[]})}})},_e=async e=>{k(t=>({...t,[e.id]:`probing`}));try{let t=await ue(e);return k(n=>({...n,[e.id]:t.ok?`online`:`offline`})),t.ok}catch{return k(t=>({...t,[e.id]:`offline`})),!1}},ye=async()=>{if(!Y.length)S(e(`webshell.probeNoConnections`,null,`暂无可探活连接`));else{M(!0);for(let e of Y)await _e(e);M(!1)}},be=async t=>{R(!0);try{if(I.record?.id)await re(I.record.id,t),A(e(`webshell.toastUpdated`,null,`连接已更新`));else{let n=await F(t);A(e(`webshell.toastCreated`,null,`连接已创建`)),n?.id&&pe(n.id)}L({visible:!1,record:null}),J()}catch(t){w(t,e(`webshell.saveFailed`,null,`保存失败`))}finally{R(!1)}},Se=t=>{j({title:e(`webshell.deleteConfirm`,null,`确定要删除该连接吗?`),content:t.url,onOk:async()=>{try{await ie(t.id),A(e(`webshell.toastDeleted`,null,`连接已删除`)),t.id===v&&pe(``),J()}catch(e){w(e)}}})},we=(0,N.useMemo)(()=>{let e=E.trim().toLowerCase();return e?Y.filter(t=>[t.url,t.remark,t.type,t.id].filter(Boolean).some(t=>String(t).toLowerCase().includes(e))):Y},[Y,E]),Te=[{tab:e(`webshell.tabTerminal`,null,`虚拟终端`),itemKey:`terminal`,children:X?(0,B.jsx)(xe,{connection:X,canWrite:n,onRecordCommand:me}):null},{tab:e(`webshell.tabFileManager`,null,`文件管理`),itemKey:`files`,children:X?(0,B.jsx)(ve,{connection:X,canWrite:n}):null},{tab:e(`webshell.tabHistory`,null,`命令历史`),itemKey:`history`,children:(0,B.jsx)(Ce,{history:U,onRemove:he,onClear:n?ge:null,onRun:e=>X?me(e):null})},{tab:e(`webshell.tabAiSessions`,null,`AI 会话`),itemKey:`ai`,children:X?(0,B.jsx)(Ee,{connection:X}):null},{tab:e(`webshell.tabMemo`,null,`备忘录`),itemKey:`memo`,children:(0,B.jsx)(l,{value:V,onChange:Q,autosize:{minRows:10,maxRows:20},placeholder:e(`webshell.aiMemoPlaceholder`,null,`记录关键命令、测试思路、复现步骤...`),disabled:!n})}];return(0,B.jsxs)(`div`,{className:`webshell-page`,id:`page-webshell`,children:[(0,B.jsx)(O,{title:e(`webshell.title`,null,`WebShell 管理`),description:e(`webshell.pageDesc`,null,`统一管理 WebShell 连接,代理执行命令并浏览目标文件`),extra:[(0,B.jsx)(c,{icon:(0,B.jsx)(_,{}),onClick:J,loading:q,children:e(`webshell.refresh`,null,`刷新`)},`refresh`),(0,B.jsx)(c,{theme:`solid`,type:`primary`,icon:(0,B.jsx)(m,{}),disabled:!n,onClick:()=>L({visible:!0,record:null}),children:e(`webshell.addConnection`,null,`添加连接`)},`add`)]}),(0,B.jsx)(ee,{error:fe,onRetry:J}),(0,B.jsxs)(`div`,{className:`webshell-layout`,children:[(0,B.jsxs)(`aside`,{className:`webshell-sidebar`,children:[(0,B.jsxs)(`div`,{className:`webshell-sidebar-head`,children:[(0,B.jsx)($,{strong:!0,children:e(`webshell.connections`,null,`连接列表`)}),(0,B.jsx)(s,{size:`small`,children:Y.length})]}),(0,B.jsx)(u,{value:x,onChange:T,prefix:(0,B.jsx)(g,{}),placeholder:e(`webshell.searchPlaceholder`,null,`搜索连接...`),size:`small`}),(0,B.jsx)(c,{size:`small`,theme:`borderless`,loading:ne,onClick:ye,disabled:!Y.length,children:e(`webshell.batchProbe`,null,`一键批量探活`)}),(0,B.jsxs)(`div`,{className:`webshell-conn-list`,children:[q&&!Y.length&&(0,B.jsx)(`div`,{className:`webshell-conn-loading`,children:(0,B.jsx)(d,{})}),!q&&we.length===0&&(0,B.jsx)($,{type:`tertiary`,className:`webshell-conn-empty`,children:Y.length?e(`webshell.noMatchConnections`,null,`暂无匹配连接`):e(`webshell.noConnections`,null,`暂无连接,请点击「添加连接」`)}),we.map(t=>(0,B.jsxs)(`button`,{type:`button`,className:`webshell-conn-item ${t.id===v?`is-active`:``}`,onClick:()=>pe(t.id),children:[(0,B.jsx)(`span`,{className:`webshell-conn-url`,title:t.url,children:t.remark||t.url}),(0,B.jsxs)(`span`,{className:`webshell-conn-meta`,children:[(0,B.jsx)(s,{size:`small`,color:`blue`,children:String(t.type||`php`).toUpperCase()}),D[t.id]&&(0,B.jsx)(s,{size:`small`,color:Oe(D[t.id]),children:D[t.id]===`online`?e(`webshell.probeOnline`,null,`在线`):D[t.id]===`probing`?e(`webshell.probeRunning`,null,`探活中`):e(`webshell.probeOffline`,null,`离线`)})]})]},t.id))]})]}),(0,B.jsx)(`section`,{className:`webshell-main`,children:X?(0,B.jsxs)(`div`,{className:`webshell-workspace`,children:[(0,B.jsxs)(`div`,{className:`webshell-workspace-head`,children:[(0,B.jsxs)(`div`,{className:`webshell-workspace-title`,children:[(0,B.jsx)($,{strong:!0,ellipsis:{showTooltip:!0},className:`webshell-workspace-url`,children:X.url}),(0,B.jsxs)(o,{spacing:6,wrap:!0,children:[(0,B.jsx)(s,{size:`small`,color:`blue`,children:String(X.type||`php`).toUpperCase()}),(0,B.jsx)(s,{size:`small`,children:String(X.method||`post`).toUpperCase()}),(0,B.jsx)(s,{size:`small`,children:De[X.encoding]||`自动`}),(0,B.jsx)(s,{size:`small`,children:X.os===`windows`?`Windows`:X.os===`linux`?`Linux`:`OS 自动`}),X.remark&&(0,B.jsx)($,{type:`tertiary`,size:`small`,children:X.remark})]})]}),(0,B.jsxs)(o,{spacing:8,children:[(0,B.jsx)(c,{size:`small`,loading:D[X.id]===`probing`,onClick:()=>_e(X),children:e(`webshell.testConnectivity`,null,`测试连通性`)}),(0,B.jsx)(c,{size:`small`,disabled:!n,onClick:()=>L({visible:!0,record:X}),children:e(`webshell.editConnection`,null,`编辑`)}),(0,B.jsx)(c,{size:`small`,type:`danger`,disabled:!a,onClick:()=>Se(X),children:e(`webshell.deleteFile`,null,`删除`)})]})]}),(0,B.jsx)(f,{type:`line`,defaultActiveKey:`terminal`,className:`webshell-tabs`,items:Te},X.id)]}):(0,B.jsx)(i,{title:e(`webshell.selectOrAdd`,null,`请从左侧选择连接,或添加新的 WebShell 连接`),description:null,style:{padding:64}})})]}),(0,B.jsx)(de,{visible:I.visible,record:I.record,projects:z,submitting:se,onCancel:()=>L({visible:!1,record:null}),onSubmit:be})]})}export{ke as default}; \ No newline at end of file diff --git a/web/static/app/assets/workflows-BnRbScwz.js b/web/static/app/assets/workflows-BgrBtPdj.js similarity index 99% rename from web/static/app/assets/workflows-BnRbScwz.js rename to web/static/app/assets/workflows-BgrBtPdj.js index 3638370a..dd7d28f9 100644 --- a/web/static/app/assets/workflows-BnRbScwz.js +++ b/web/static/app/assets/workflows-BgrBtPdj.js @@ -1 +1 @@ -import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{B as i,G as a,I as o,N as s,P as c,R as l,S as u,U as d,c as f,d as p,ft as m,h,lt as g,m as _,p as v,s as y,u as b,ut as x,x as S}from"./semi-65W_4I1v.js";import{E as C,F as w,I as T,L as E,R as D,_ as ee,a as O,b as k,c as te,d as A,l as j,m as M,n as ne,p as re,r as N,s as P,u as F,x as I,y as L}from"./index-CAEPLS-g.js";var R=e(t(),1),z=[{value:`start`,label:`开始`},{value:`tool`,label:`工具`},{value:`agent`,label:`Agent`},{value:`condition`,label:`条件`},{value:`hitl`,label:`审批`},{value:`output`,label:`输出`},{value:`end`,label:`结束`}],ie=Object.fromEntries(z.map(e=>[e.value,e.label])),B={running:{label:`执行中`,color:`blue`},awaiting_hitl:{label:`等待审批`,color:`amber`},completed:{label:`已完成`,color:`green`},failed:{label:`失败`,color:`red`},cancelled:{label:`已取消`,color:`grey`},pending:{label:`待执行`,color:`amber`}},V={nodes:[{id:`start`,type:`start`,label:`开始`,position:{x:80,y:140},config:{}},{id:`out`,type:`output`,label:`输出`,position:{x:380,y:140},config:{output_key:`result`}}],edges:[{id:`e1`,source:`start`,target:`out`,label:``}],config:{}},H={WFPKG_FILE_REQUIRED:`workflows.package.errors.fileRequired`,WFPKG_FILE_TOO_LARGE:`workflows.package.errors.fileTooLarge`,WFPKG_UNSUPPORTED_FORMAT:`workflows.package.errors.unsupportedFormat`,WFPKG_INVALID_ARCHIVE:`workflows.package.errors.invalidArchive`,WFPKG_INVALID_MANIFEST:`workflows.package.errors.invalidManifest`,WFPKG_CHECKSUM_MISMATCH:`workflows.package.errors.checksumMismatch`,WFPKG_MULTIPLE_WORKFLOWS:`workflows.package.errors.multipleWorkflows`,WFPKG_WORKFLOW_INVALID:`workflows.package.errors.workflowInvalid`,WFPKG_INSPECTION_NOT_FOUND:`workflows.package.errors.inspectionNotFound`,WFPKG_INSPECTION_EXPIRED:`workflows.package.errors.inspectionExpired`,WFPKG_INSPECTION_CONSUMED:`workflows.package.errors.inspectionConsumed`,WFPKG_CONFLICT_CHANGED:`workflows.package.errors.conflictChanged`,WFPKG_ID_CONFLICT:`workflows.package.errors.idConflict`,WFPKG_INVALID_ACTION:`workflows.package.errors.invalidAction`,WFPKG_INVALID_RENAME_ID:`workflows.package.errors.invalidRenameId`,WFPKG_OVERWRITE_CONFIRMATION_REQUIRED:`workflows.package.errors.overwriteConfirmationRequired`,WFPKG_IDEMPOTENCY_KEY_REQUIRED:`workflows.package.errors.idempotencyKeyRequired`,WFPKG_IDEMPOTENCY_KEY_REUSED:`workflows.package.errors.idempotencyKeyReused`,WFPKG_IMPORT_FAILED:`workflows.package.errors.importFailed`},U={create:{label:`创建导入`,hint:`导入后会创建一个新的本地工作流。`},keep_existing:{label:`保留本地版本`,hint:`不修改当前本地工作流;导入记录会保留。`},overwrite:{label:`覆盖本地版本`,hint:`替换名称、描述、图定义和启用状态;需要再次确认。`},rename:{label:`另存为新 ID`,hint:`保留当前本地工作流,并以新的 ID 创建副本。`}},W={none:[`create`],identical:[`keep_existing`],id_conflict:[`keep_existing`,`overwrite`,`rename`]};function G(e){return(W[e]||[]).slice()}function K(e){if(!e||!String(e).trim())return{graph:null,error:`图定义不能为空`};try{let t=JSON.parse(e);return!t||typeof t!=`object`?{graph:null,error:`图定义必须是 JSON 对象`}:{graph:{nodes:Array.isArray(t.nodes)?t.nodes:[],edges:Array.isArray(t.edges)?t.edges:[],config:t.config||{}},error:null}}catch(e){return{graph:null,error:e.message||`JSON 解析失败`}}}function ae(e){let{graph:t,error:n}=K(e);return t?{nodes:t.nodes,edges:t.edges,error:null}:{nodes:[],edges:[],error:n}}function q(e,t=12){let n=String(e||``);if(!n)return`—`;let r=n.startsWith(`sha256:`)?n.slice(7):n;return r.length>t?`${r.slice(0,t)}…`:r}function J(e,t=`操作失败`){if(!e)return t;if(typeof e==`string`)return e;let n=e.payload;if(n&&typeof n==`object`){let e=n.error;if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=typeof e.message==`string`?e.message:``,n=typeof e.code==`string`?e.code:``;if(t)return n?`${t}(${n})`:t}if(typeof n.message==`string`&&n.message)return n.message}return typeof e.message==`string`&&e.message&&e.message!==`[object Object]`?e.message:t}function oe(e,t=`加载失败`){return e?{message:J(e,t)}:null}function se(e){let t=e?.payload?.error;return t&&typeof t==`object`&&typeof t.code==`string`?t.code:``}function ce(e,t){let n=se(e);if(n&&H[n]){let e=t?.(H[n],null,``);if(e)return e}return J(e,`操作未完成,请稍后重试。`)}function le(){let e=typeof globalThis<`u`?globalThis.crypto:null;return!e||typeof e.randomUUID!=`function`?``:e.randomUUID()}var Y=e(n(),1),{Text:X}=a,ue=/^[A-Za-z0-9][A-Za-z0-9_-]*$/,de={id:``,name:``,description:``,version:1,enabled:!0,graph:``};function fe({visible:e,workflow:t,onCancel:n,onSaved:r}){let a=w(),{hasPermission:s}=T(),f=s(`workflow:execute`),[p,m]=(0,R.useState)(de),[h,g]=(0,R.useState)(!1),[_,v]=(0,R.useState)(!1),[y,b]=(0,R.useState)(null),x=!!t?.id;(0,R.useEffect)(()=>{if(e){if(b(null),g(!1),t){let e=t.graph_json||``;try{e=JSON.stringify(JSON.parse(e),null,2)}catch{}m({id:t.id||``,name:t.name||``,description:t.description||``,version:t.version||1,enabled:t.enabled!==!1,graph:e})}else m({...de,graph:JSON.stringify(V,null,2)})}},[e,t]);let C=e=>m(t=>({...t,...e})),D=(0,R.useMemo)(()=>ae(p.graph),[p.graph]);return(0,Y.jsxs)(te,{visible:e,title:x?a(`workflows.metaModalTitle`,null,`工作流信息`):a(`workflows.newGraph`,null,`新建工作流`),onCancel:n,onOk:async()=>{let e=(x?t.id:p.id).trim(),n=p.name.trim();if(!e||!n)k(a(`workflows.idNameRequired`,null,`工作流 ID 和名称不能为空`));else if(!x&&!ue.test(e))k(`工作流 ID 必须以字母或数字开头,仅含字母、数字、下划线、连字符`);else{if(p.graph.trim())try{JSON.parse(p.graph)}catch(e){k(`graph 必须是合法 JSON:${J(e,``)}`);return}g(!0);try{let t={id:e,name:n,description:p.description,version:Number(p.version)||0,enabled:!!p.enabled,graph:p.graph.trim()?JSON.parse(p.graph):void 0},i=x?await E.put(`/workflows/${encodeURIComponent(e)}`,t):await E.post(`/workflows`,t);I(a(`workflows.saved`,null,`工作流已保存`)),r?.(i?.workflow||null)}catch(e){k(J(e,a(`workflows.saveFailed`,null,`保存工作流失败`)))}finally{g(!1)}}},okText:a(`common.save`,null,`保存`),cancelText:a(`common.cancel`,null,`取消`),confirmLoading:h,width:860,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-grid`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaId`,null,`ID`)}),(0,Y.jsx)(d,{value:p.id,disabled:x,placeholder:`web-scan-basic`,onChange:e=>C({id:e})}),(0,Y.jsx)(X,{type:`tertiary`,size:`small`,children:a(`workflows.metaIdHint`,null,`创建后不可修改,用于 API 与角色绑定`)})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaName`,null,`名称`)}),(0,Y.jsx)(d,{value:p.name,placeholder:a(`workflows.namePlaceholder`,null,`基础 Web 扫描`),onChange:e=>C({name:e})})]})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-grid`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaDescription`,null,`描述`)}),(0,Y.jsx)(d,{value:p.description,placeholder:a(`workflows.descriptionPlaceholder`,null,`可选`),onChange:e=>C({description:e})})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-grid workflow-form-grid--tight`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:`版本`}),(0,Y.jsx)(S,{value:p.version,min:0,style:{width:`100%`},onChange:e=>C({version:e||0})})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaEnabled`,null,`启用`)}),(0,Y.jsx)(c,{checked:p.enabled,onChange:e=>C({enabled:e.target.checked}),children:a(`workflows.metaEnabledHint`,null,`禁用后无法被角色自动触发`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsxs)(o,{children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:`graph JSON`}),(0,Y.jsx)(X,{type:`tertiary`,size:`small`,children:D.error?`解析失败:${D.error}`:`${D.nodes.length} 个节点 · ${D.edges.length} 条连线`})]}),(0,Y.jsx)(u,{value:p.graph,rows:16,spellCheck:!1,className:`workflow-graph-input`,placeholder:`{"nodes":[],"edges":[],"config":{}}`,onChange:e=>{C({graph:e}),b(null)}}),(0,Y.jsxs)(o,{wrap:!0,children:[(0,Y.jsx)(l,{size:`small`,onClick:()=>{try{C({graph:JSON.stringify(JSON.parse(p.graph),null,2)}),b(null)}catch(e){k(`${a(`projects.invalidJson`,null,`JSON 格式无效`)}:${J(e,``)}`)}},children:a(`projects.formatJson`,null,`格式化`)}),(0,Y.jsx)(l,{size:`small`,onClick:()=>{C({graph:JSON.stringify(V,null,2)}),b(null)},children:`插入最小模板`}),(0,Y.jsx)(l,{size:`small`,loading:_,disabled:!f,title:f?``:`需要 workflow:execute 权限`,onClick:async()=>{if(!p.graph.trim()){b({type:`danger`,text:a(`workflows.validation.serverFailed`,null,`图定义不能为空`)});return}let e;try{e=JSON.parse(p.graph)}catch(e){b({type:`danger`,text:`JSON 解析失败:${J(e,``)}`});return}v(!0),b(null);try{await E.post(`/workflows/validate`,{graph:e}),b({type:`success`,text:`结构校验通过`})}catch(e){b({type:`danger`,text:J(e,a(`workflows.validation.serverFailed`,null,`后端图校验失败`))})}finally{v(!1)}},children:a(`workflows.validate`,null,`校验图定义`)}),(0,Y.jsxs)(X,{type:`tertiary`,size:`small`,children:[`节点类型:`,z.map(e=>e.label).join(` / `)]})]})]}),y?(0,Y.jsx)(i,{type:y.type,bordered:!0,closeIcon:null,description:y.text,style:{marginTop:12}}):null]})}var{Text:Z}=a;function pe({raw:e}){let t=(0,R.useMemo)(()=>ae(e),[e]);if(t.error)return(0,Y.jsxs)(Z,{type:`danger`,size:`small`,children:[`graph 解析失败:`,t.error]});let n=t.nodes.map(e=>({id:e.id,type:e.type||`tool`,label:e.label||``,config:e.config||{}}));return(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsx)(b,{columns:[{title:`节点`,dataIndex:`id`,width:160,render:e=>(0,Y.jsx)(`code`,{children:e})},{title:`类型`,dataIndex:`type`,width:90,render:e=>(0,Y.jsx)(s,{size:`small`,color:`blue`,type:`light`,children:ie[e]||e})},{title:`名称`,dataIndex:`label`,render:(e,t)=>(0,Y.jsx)(`span`,{className:`workflow-cell-ellipsis`,title:e||t.id,children:e||`—`})}],dataSource:n,rowKey:`id`,size:`small`,pagination:!1,empty:(0,Y.jsx)(Z,{type:`tertiary`,size:`small`,children:`图内没有节点`})}),(0,Y.jsxs)(`div`,{className:`workflow-edge-list`,children:[(0,Y.jsxs)(Z,{strong:!0,size:`small`,children:[`连线(`,t.edges.length,`)`]}),t.edges.length?(0,Y.jsx)(`ul`,{className:`workflow-link-list`,children:t.edges.map((e,t)=>(0,Y.jsxs)(`li`,{children:[(0,Y.jsx)(`code`,{children:e.source}),` → `,(0,Y.jsx)(`code`,{children:e.target}),e.label?(0,Y.jsx)(`span`,{className:`workflow-edge-label`,children:e.label}):null]},e.id||`${e.source}-${e.target}-${t}`))}):(0,Y.jsx)(Z,{type:`tertiary`,size:`small`,children:`暂无连线`})]})]})}function me({workflowId:e,visible:t,canWrite:n,canDelete:r,onClose:i,onEdit:a,onDeleted:c}){let u=w(),[d,f]=(0,R.useState)(!1),p=O(()=>e?E.get(`/workflows/${encodeURIComponent(e)}`):Promise.resolve(null),[e]),m=p.data?.workflow||null;return(0,R.useEffect)(()=>{t&&e&&p.reload({silent:!0})},[t,e]),(0,Y.jsxs)(v,{visible:t,width:760,title:m?m.name||m.id:u(`workflows.metaModalTitle`,null,`工作流信息`),onCancel:i,footer:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{disabled:!n||!m,onClick:()=>a?.(m),children:u(`common.edit`,null,`编辑`)}),(0,Y.jsx)(l,{loading:d,disabled:!m,onClick:async()=>{if(m){f(!0);try{await D(`/workflows/${encodeURIComponent(m.id)}/package`,{filename:`${m.id}.csapkg.zip`}),I(u(`workflows.package.export`,null,`导出`))}catch(e){k(J(e,u(`workflows.package.errors.exportFailed`,null,`导出失败,请稍后重试。`)))}finally{f(!1)}}},children:u(`workflows.package.export`,null,`导出`)}),(0,Y.jsx)(l,{type:`danger`,disabled:!r||!m,onClick:()=>L({title:u(`workflows.deleteWorkflow`,null,`删除工作流`),content:u(`workflows.confirmDelete`,{id:m?.id},`确定删除工作流 ${m?.id}?`),okText:u(`common.delete`,null,`删除`),onOk:async()=>{try{await E.del(`/workflows/${encodeURIComponent(m.id)}`),I(u(`workflows.deleted`,null,`工作流已删除`)),c?.(m.id)}catch(e){k(J(e,u(`workflows.deleteFailed`,null,`删除工作流失败`)))}}}),children:u(`workflows.deleteWorkflow`,null,`删除工作流`)}),(0,Y.jsx)(l,{onClick:i,children:u(`common.close`,null,`关闭`)})]}),children:[(0,Y.jsx)(j,{error:oe(p.error),onRetry:()=>p.reload()}),m?(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsxs)(`div`,{className:`workflow-detail-tags`,children:[(0,Y.jsx)(s,{size:`small`,color:m.enabled?`green`:`grey`,children:m.enabled?u(`workflows.statusEnabled`,null,`启用`):u(`workflows.statusDisabled`,null,`禁用`)}),m.validation_error?(0,Y.jsx)(s,{size:`small`,color:`red`,children:u(`workflows.statusInvalid`,null,`校验未通过`)}):(0,Y.jsx)(s,{size:`small`,color:`green`,type:`light`,children:`结构有效`}),(0,Y.jsxs)(Z,{type:`tertiary`,size:`small`,children:[`版本 `,m.version||0]})]}),m.validation_error?(0,Y.jsx)(j,{error:{message:m.validation_error}}):null,(0,Y.jsx)(A,{columns:2,items:[{label:u(`workflows.metaId`,null,`ID`),value:(0,Y.jsx)(`code`,{children:m.id})},{label:u(`workflows.metaName`,null,`名称`),value:m.name||`—`},{label:u(`workflows.updated`,null,`更新`),value:C(m.updated_at)},{label:`创建`,value:C(m.created_at)},{label:u(`workflows.metaDescription`,null,`描述`),value:m.description||`—`}]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(Z,{strong:!0,children:u(`workflows.nodeProperties`,null,`节点属性`)}),(0,Y.jsx)(pe,{raw:m.graph_json})]}),(0,Y.jsx)(F,{value:m.graph_json?he(m.graph_json):{},title:`graph JSON`,collapsed:!0})]}):null]})}function he(e){try{return JSON.parse(e)}catch{return{raw:e}}}var{Text:Q}=a;function ge(e){let t=B[String(e||``)]||{label:e||`—`,color:`grey`};return(0,Y.jsx)(s,{size:`small`,color:t.color,children:t.label})}function _e({runId:e,visible:t,canExecute:n,onClose:r,onChanged:i}){let a=w(),[s,c]=(0,R.useState)(``),[d,f]=(0,R.useState)(!1),p=O(()=>e?E.get(`/workflows/runs/${encodeURIComponent(e)}`):Promise.resolve(null),[e]),m=O(()=>e?E.get(`/workflows/runs/${encodeURIComponent(e)}/replay`):Promise.resolve(null),[e]),h=p.data?.run||null;(0,R.useEffect)(()=>{t&&e&&(p.reload({silent:!0}),m.reload({silent:!0}))},[t,e]);let g=p.data?.nodeRuns||[],_=m.data?.steps||[],b=t=>L({title:t?`通过审批`:`拒绝审批`,content:t?`确认通过该工作流的审批节点并继续执行?`:`确认拒绝该工作流的审批节点?运行将以失败结束。`,okText:a(`common.confirm`,null,`确认`),danger:!t,onOk:async()=>{f(!0);try{await E.post(`/workflows/runs/${encodeURIComponent(e)}/resume`,{approved:t,comment:s}),I(t?`已通过审批`:`已拒绝审批`),c(``),p.reload({silent:!0}),m.reload({silent:!0}),i?.()}catch(e){k(J(e,`审批提交失败`))}finally{f(!1)}}});return(0,Y.jsxs)(v,{visible:t,width:820,title:a(`workflows.dryRunTrace`,null,`运行轨迹`),onCancel:r,footer:(0,Y.jsxs)(o,{children:[h?.status===`awaiting_hitl`&&n?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(u,{value:s,rows:1,placeholder:`审批备注(可选)`,onChange:e=>c(e),style:{width:240}}),(0,Y.jsx)(l,{type:`primary`,loading:d,onClick:()=>b(!0),children:`通过`}),(0,Y.jsx)(l,{type:`danger`,loading:d,onClick:()=>b(!1),children:`拒绝`})]}):null,(0,Y.jsx)(l,{onClick:r,children:a(`common.close`,null,`关闭`)})]}),children:[(0,Y.jsx)(j,{error:oe(p.error),onRetry:()=>p.reload()}),h?(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsxs)(`div`,{className:`workflow-detail-tags`,children:[ge(h.status),(0,Y.jsxs)(Q,{type:`tertiary`,size:`small`,children:[`运行 `,(0,Y.jsx)(`code`,{children:q(h.id,16)})]})]}),(0,Y.jsx)(A,{columns:2,items:[{label:`工作流`,value:(0,Y.jsx)(`code`,{children:h.workflow_id})},{label:`版本`,value:h.workflow_version??`—`},{label:`会话`,value:h.conversation_id||`—`},{label:`项目`,value:h.project_id||`—`},{label:`开始时间`,value:C(h.started_at)},{label:`结束时间`,value:C(h.finished_at)},h.pending_hitl_node_id?{label:`待审批节点`,value:(0,Y.jsx)(`code`,{children:h.pending_hitl_node_id})}:null,h.error?{label:`错误`,value:(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:h.error})}:null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,children:[`节点执行记录(`,g.length,`)`]}),(0,Y.jsx)(y,{className:`workflow-timeline`,children:g.length?g.map(e=>(0,Y.jsx)(y.Item,{time:C(e.started_at),type:e.status===`failed`?`error`:e.status===`completed`?`success`:`ongoing`,children:(0,Y.jsxs)(`div`,{className:`workflow-timeline-item`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`code`,{children:e.node_id}),` `,ge(e.status)]}),e.error?(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:e.error}):null,e.output_json?(0,Y.jsx)(F,{value:ve(e.output_json),title:`output`,collapsed:!0}):null]})},e.id)):(0,Y.jsx)(Q,{type:`tertiary`,size:`small`,children:`暂无节点执行记录`})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,children:[a(`workflows.dryRunTrace`,null,`回放轨迹`),`(`,_.length,` 步)`]}),(0,Y.jsx)(y,{className:`workflow-timeline`,children:_.length?_.map(e=>(0,Y.jsx)(y.Item,{time:C(e.startedAt),type:e.status===`failed`?`error`:e.status===`completed`?`success`:`ongoing`,children:(0,Y.jsxs)(`div`,{className:`workflow-timeline-item`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,size:`small`,children:[`#`,e.step]}),` `,(0,Y.jsx)(`code`,{children:e.nodeId}),` `,ge(e.status)]}),e.error?(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:e.error}):null,(0,Y.jsx)(F,{value:{input:e.input,output:e.output},title:`step`,collapsed:!0})]})},e.nodeRunId||`${e.step}-${e.nodeId}`)):(0,Y.jsx)(Q,{type:`tertiary`,size:`small`,children:a(`workflows.dryRunNoTrace`,null,`暂无轨迹`)})})]}),(0,Y.jsx)(F,{value:h,title:`run`,collapsed:!0})]}):null]})}function ve(e){try{return JSON.parse(e)}catch{return{raw:e}}}var{Text:ye}=a;function be({canExecute:e}){let t=w(),[n,i]=r(),a=n.get(`run`)||``,c=O(()=>E.get(`/workflows/runs/pending`),[]);N(()=>c.reload({silent:!0}),15e3);let u=Array.isArray(c.data?.runs)?c.data.runs:[],d=e=>{let t=new URLSearchParams(n);e?t.set(`run`,e):t.delete(`run`),i(t,{replace:!0})},f=[{title:`运行`,dataIndex:`id`,width:190,render:e=>(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>d(e),children:(0,Y.jsx)(`code`,{children:q(e,14)})})},{title:`工作流`,dataIndex:`workflow_id`,width:200,render:e=>(0,Y.jsx)(ye,{size:`small`,children:(0,Y.jsx)(`code`,{children:e})})},{title:`会话`,dataIndex:`conversation_id`,width:220,render:e=>(0,Y.jsx)(ye,{type:`tertiary`,size:`small`,children:(0,Y.jsx)(`code`,{children:e||`—`})})},{title:t(`projects.status`,null,`状态`),dataIndex:`status`,width:110,render:e=>{let t=B[String(e||``)]||{label:e||`—`,color:`grey`};return(0,Y.jsx)(s,{size:`small`,color:t.color,children:t.label})}},{title:`待审批节点`,dataIndex:`pending_hitl_node_id`,width:160,render:e=>e?(0,Y.jsx)(`code`,{children:e}):(0,Y.jsx)(ye,{type:`tertiary`,children:`—`})},{title:`开始时间`,dataIndex:`started_at`,width:165,render:e=>(0,Y.jsx)(ye,{size:`small`,children:C(e)})},{title:t(`common.actions`,null,`操作`),dataIndex:`id`,width:120,render:e=>(0,Y.jsx)(o,{children:(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>d(e),children:t(`projects.details`,null,`详情`)})})}];return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(M,{title:t(`workflows.runsPending`,null,`待审批运行`),description:`等待审批(awaiting_hitl)的工作流运行,每 15 秒自动刷新。${e?` 可直接在此通过或拒绝。`:``}`,extra:(0,Y.jsx)(l,{icon:(0,Y.jsx)(x,{}),theme:`borderless`,loading:c.loading,onClick:()=>c.reload(),children:t(`common.refresh`,null,`刷新`)}),children:[(0,Y.jsx)(j,{error:oe(c.error),onRetry:()=>c.reload()}),(0,Y.jsx)(P,{columns:f,dataSource:u,rowKey:`id`,loading:c.loading,pagination:{pageSize:10},emptyText:`当前没有等待审批的工作流运行`})]}),(0,Y.jsx)(_e,{runId:a,visible:!!a,canExecute:e,onClose:()=>d(``),onChanged:()=>c.reload({silent:!0})})]})}var{Text:$,Paragraph:xe}=a,Se=10485760;function Ce(e){let t=String(e||``).replace(/^data:[^;]+;base64,/,``).replace(/\s+/g,``);if(!t)throw Error(`粘贴内容为空`);let n=atob(t),r=new Uint8Array(n.length);for(let e=0;e{e||(f(null),m(``),v(``),b(null),S(``),D(``),O(!1),N(``),F(null),j(!1),ne(!1))},[e]);let L=y?.conflict?.state||``,z=(0,R.useMemo)(()=>G(L),[L]),ie=()=>{v(``);try{let e=Ce(p);if(e.size>Se){v(r(`workflows.package.errors.fileTooLarge`,null,`文件超过 10 MiB 限制,请选择更小的本地包。`));return}f(e),b(null),F(null)}catch(e){v(`Base64 解码失败:${J(e,``)}`)}},B=e=>{let t=e.target.files&&e.target.files[0];v(``),N(``),F(null),b(null),t?t.size>Se?(v(r(`workflows.package.errors.fileTooLarge`,null,`文件超过 10 MiB 限制,请选择更小的本地包。`)),f(null)):f(t):f(null)},V=async()=>{if(!a)v(r(`workflows.package.errors.fileRequired`,null,`请选择本地工作流包后再预检。`));else{j(!0),N(``),F(null);try{let e=new FormData;e.append(`file`,a,a.name||`workflow.csapkg.zip`);let t=(await E.post(`/workflow-package-inspections`,e))?.inspection||null;b(t);let n=G(t?.conflict?.state||``);S(n[0]||``),D(``),O(!1)}catch(e){N(ce(e,r))}finally{j(!1)}}},H=async()=>{if(!y?.id){N(r(`workflows.package.resolution.needInspection`,null,`请先选择本地包并完成预检。`));return}if(!x){N(r(`workflows.package.errors.invalidAction`,null,`导入处理方式无效,请重新选择。`));return}if(x===`rename`&&!T.trim()){N(r(`workflows.package.errors.invalidRenameId`,null,`请输入可用的新工作流 ID。`));return}if(x===`overwrite`&&!ee){N(r(`workflows.package.errors.overwriteConfirmationRequired`,null,`请勾选确认后再覆盖本地工作流。`));return}let e=le();if(!e)N(r(`workflows.package.errors.idempotencyKeyRequired`,null,`浏览器无法生成导入请求标识,请刷新页面后重试。`));else{ne(!0),N(``);try{let t=await E.post(`/workflow-package-imports`,{inspection_id:y.id,resolution:{action:x,new_workflow_id:x===`rename`?T.trim():``},confirm_overwrite:x===`overwrite`},{headers:{"Idempotency-Key":e}});F(t?.import||null),I(r(`workflows.package.result.complete`,null,`导入已完成。`)),n?.(t?.import||null)}catch(e){N(ce(e,r))}finally{ne(!1)}}},W=L===`identical`?r(`workflows.package.conflict.identical`,null,`检测到同 ID 且内容相同的本地工作流;本次将跳过导入。`):L===`id_conflict`?r(`workflows.package.conflict.idConflict`,null,`检测到同 ID 但内容不同的本地工作流。默认保留本地版本。`):L===`none`?r(`workflows.package.conflict.none`,null,`未发现同 ID 的本地工作流,可创建导入。`):``,K=y?.workflow;return(0,Y.jsxs)(te,{visible:e,title:r(`workflows.package.title`,null,`导入本地包`),onCancel:t,width:760,maskClosable:!k&&!M,footer:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{onClick:t,children:r(`common.close`,null,`关闭`)}),(0,Y.jsx)(l,{type:`primary`,loading:k,disabled:!!P,onClick:V,children:k?r(`workflows.package.inspecting`,null,`正在安全预检…`):r(`workflows.package.inspect`,null,`上传并预检`)}),(0,Y.jsx)(l,{type:`primary`,loading:M,disabled:!y||!!P||!x,onClick:H,children:r(`workflows.package.confirmImport`,null,`确认导入`)})]}),children:[(0,Y.jsxs)(xe,{type:`tertiary`,size:`small`,children:[r(`workflows.package.preflightHint`,null,`先检查包内容与冲突,再由你确认是否导入`),` · `,r(`workflows.package.fileHint`,null,`仅支持单个 .csapkg.zip,文件不得超过 10 MiB。`)]}),(0,Y.jsxs)(`div`,{className:`workflow-package-block`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.stepInspection`,null,`上传与预检`)}),(0,Y.jsxs)(`div`,{className:`workflow-package-file-row`,children:[(0,Y.jsx)(`input`,{type:`file`,accept:`.zip,application/zip`,className:`workflow-file-input`,onChange:B,"aria-label":r(`workflows.package.selectFile`,null,`选择本地包`)}),(0,Y.jsx)($,{type:`tertiary`,size:`small`,children:a?`${a.name} · ${(a.size/1024).toFixed(1)} KiB`:r(`workflows.package.noFile`,null,`未选择文件`)}),a?(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>{f(null),b(null),F(null)},children:r(`workflows.package.removeFile`,null,`移除文件`)}):null]}),(0,Y.jsx)(u,{value:p,rows:3,placeholder:`或粘贴工作流包 base64(.csapkg.zip)`,onChange:e=>m(e)}),(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{size:`small`,onClick:ie,disabled:!p.trim(),children:`使用粘贴内容`}),g?(0,Y.jsx)($,{type:`danger`,size:`small`,children:g}):null]})]}),re?(0,Y.jsx)(i,{type:`danger`,bordered:!0,closeIcon:null,description:re,className:`workflow-package-banner`}):null,y?(0,Y.jsxs)(`div`,{className:`workflow-package-block`,children:[(0,Y.jsxs)(`div`,{className:`workflow-package-summary-head`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.summary.title`,null,`预检结果`)}),(0,Y.jsx)(s,{size:`small`,color:`green`,children:r(`workflows.package.summary.passed`,null,`校验通过`)})]}),(0,Y.jsx)(i,{type:L===`id_conflict`?`warning`:`success`,bordered:!0,closeIcon:null,description:W,className:`workflow-package-banner`}),(0,Y.jsx)(A,{columns:2,items:[{label:r(`workflows.package.summary.workflowName`,null,`工作流名称`),value:K?.name||`—`},{label:r(`workflows.package.summary.sourceId`,null,`源工作流 ID`),value:(0,Y.jsx)(`code`,{children:K?.source_id||`—`})},{label:r(`workflows.package.summary.sourceRevision`,null,`源版本`),value:K?.source_revision??`—`},{label:r(`workflows.package.summary.graphSize`,null,`图规模`),value:`${K?.node_count||0} 节点 · ${K?.edge_count||0} 连线`},{label:r(`workflows.package.summary.contentHash`,null,`内容摘要`),value:q(K?.content_hash)},{label:r(`workflows.package.summary.expiresAt`,null,`预检有效期`),value:C(y.expires_at)}]}),(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.resolutionTitle`,null,`处理方式`)}),(0,Y.jsx)(h,{value:x,onChange:e=>{S(e.target.value),O(!1)},direction:`vertical`,children:z.map(e=>(0,Y.jsx)(_,{value:e,children:(0,Y.jsxs)(`span`,{className:`workflow-package-action`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:U[e]?.label||e}),(0,Y.jsx)($,{type:`tertiary`,size:`small`,children:U[e]?.hint||``})]})},e))}),x===`rename`?(0,Y.jsx)(d,{value:T,placeholder:r(`workflows.package.resolution.newWorkflowIdPlaceholder`,null,`例如:web-scan-basic-copy`),onChange:e=>D(e)}):null,x===`overwrite`?(0,Y.jsxs)(`div`,{className:`workflow-package-overwrite`,children:[(0,Y.jsx)(i,{type:`warning`,bordered:!0,closeIcon:null,description:r(`workflows.package.overwriteWarning`,null,`覆盖将替换名称、描述、图定义和启用状态。本期不提供回滚。`)}),(0,Y.jsx)(c,{checked:ee,onChange:e=>O(e.target.checked),children:r(`workflows.package.overwriteCheck`,null,`我已确认覆盖当前本地工作流`)})]}):null]}):null,P?(0,Y.jsx)(i,{type:`success`,bordered:!0,closeIcon:null,className:`workflow-package-banner`,description:r(we[P.result]||`workflows.package.result.complete`,null,`导入已完成。`)}):null]})}var{Text:Ee}=a;async function De(){let[e,t]=await Promise.all([E.get(`/workflows`,{includeDisabled:`true`}),E.get(`/workflows/runs/pending`).catch(()=>null)]);return{workflows:Array.isArray(e?.workflows)?e.workflows:[],pendingRuns:Array.isArray(t?.runs)?t.runs:[]}}function Oe(){let e=w(),{hasPermission:t}=T(),n=t(`workflow:write`),i=t(`workflow:delete`),a=t(`workflow:execute`),[c,u]=r(),h=c.get(`id`)||``,_=c.get(`tab`)||`list`,[v,y]=(0,R.useState)(``),b=ne(v,250),[S,te]=(0,R.useState)(!0),[A,N]=(0,R.useState)({visible:!1,workflow:null}),[F,z]=(0,R.useState)(!1),[ie,B]=(0,R.useState)(0),V=O(De,[ie]),H=V.data?.workflows||[],U=V.data?.pendingRuns||[],W=(0,R.useCallback)((e,t)=>{let n=new URLSearchParams(c);e?n.set(`id`,e):n.delete(`id`),t?n.set(`tab`,t):n.delete(`tab`),t&&t!==`runs`&&n.delete(`run`),u(n,{replace:!!e})},[c,u]),G=()=>B(e=>e+1),K=(0,R.useMemo)(()=>{let e=b.trim().toLowerCase();return H.filter(t=>!S&&t.enabled===!1?!1:!e||[t.id,t.name,t.description].join(` `).toLowerCase().includes(e))},[H,b,S]),q=H.filter(e=>!!e.validation_error).length,se=H.filter(e=>e.enabled).length,ce=[{id:`total`,label:e(`workflows.processLibrary`,null,`工作流列表`),value:H.length,loading:V.loading},{id:`enabled`,label:e(`workflows.statusEnabled`,null,`启用`),value:se,tone:`success`,loading:V.loading},{id:`invalid`,label:e(`workflows.statusInvalid`,null,`校验未通过`),value:q,tone:q?`danger`:void 0,loading:V.loading},{id:`pending`,label:e(`workflows.runsPending`,null,`待审批运行`),value:U.length,tone:U.length?`warning`:void 0,loading:V.loading}],le=async t=>{try{await D(`/workflows/${encodeURIComponent(t.id)}/package`,{filename:`${t.id}.csapkg.zip`}),I(e(`workflows.package.export`,null,`导出`))}catch(t){k(J(t,e(`workflows.package.errors.exportFailed`,null,`导出失败,请稍后重试。`)))}},X=t=>L({title:e(`workflows.deleteWorkflow`,null,`删除工作流`),content:e(`workflows.confirmDelete`,{id:t.id},`确定删除工作流 ${t.id}?`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await E.del(`/workflows/${encodeURIComponent(t.id)}`),I(e(`workflows.deleted`,null,`工作流已删除`)),h===t.id&&W(void 0,_),G()}catch(t){k(J(t,e(`workflows.deleteFailed`,null,`删除工作流失败`)))}}}),ue=[{title:e(`workflows.metaName`,null,`名称`),dataIndex:`name`,render:(t,n)=>{let r=ae(n.graph_json);return(0,Y.jsxs)(`button`,{type:`button`,className:`workflow-name-button`,onClick:()=>W(n.id,`list`),title:n.id,children:[(0,Y.jsx)(`span`,{className:`workflow-name-text`,children:t||e(`workflows.untitled`,null,`未命名工作流`)}),(0,Y.jsxs)(`span`,{className:`workflow-name-sub`,children:[(0,Y.jsx)(`code`,{children:n.id}),` · `,r.error?`图解析失败`:`${r.nodes.length} 节点 / ${r.edges.length} 连线`]})]})}},{title:e(`projects.status`,null,`状态`),dataIndex:`enabled`,width:150,render:(t,n)=>(0,Y.jsxs)(o,{spacing:4,wrap:!0,children:[(0,Y.jsx)(s,{size:`small`,color:t?`green`:`grey`,children:t?e(`workflows.statusEnabled`,null,`启用`):e(`workflows.statusDisabled`,null,`禁用`)}),n.validation_error?(0,Y.jsx)(s,{size:`small`,color:`red`,children:e(`workflows.statusInvalid`,null,`校验未通过`)}):null]})},{title:`版本`,dataIndex:`version`,width:80,render:e=>(0,Y.jsxs)(Ee,{size:`small`,children:[`v`,e??0]})},{title:e(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:165,render:e=>(0,Y.jsx)(Ee,{type:`tertiary`,size:`small`,children:C(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:260,render:(t,r)=>(0,Y.jsxs)(o,{spacing:2,wrap:!0,children:[(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>W(r.id,`list`),children:e(`projects.details`,null,`详情`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>N({visible:!0,workflow:r}),children:e(`common.edit`,null,`编辑`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>le(r),children:e(`workflows.package.export`,null,`导出`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!i,onClick:()=>X(r),children:e(`common.delete`,null,`删除`)})]})}];return(0,Y.jsxs)(`div`,{className:`workflow-page`,children:[(0,Y.jsx)(re,{title:e(`workflows.title`,null,`工作流`),description:e(`workflows.processLibraryHint`,null,`工作流定义由节点与连线组成,可被角色或对话按需触发。`),extra:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{icon:(0,Y.jsx)(x,{}),theme:`borderless`,loading:V.loading,onClick:G,children:e(`common.refresh`,null,`刷新`)}),(0,Y.jsx)(l,{disabled:!n,onClick:()=>z(!0),children:e(`workflows.package.importLocal`,null,`导入本地包`)}),(0,Y.jsx)(l,{type:`primary`,icon:(0,Y.jsx)(m,{}),disabled:!n,onClick:()=>N({visible:!0,workflow:null}),children:e(`workflows.newGraph`,null,`新建工作流`)})]})}),(0,Y.jsx)(j,{error:oe(V.error),onRetry:G}),(0,Y.jsx)(ee,{metrics:ce,columns:4}),(0,Y.jsx)(f,{type:`line`,activeKey:_,onChange:e=>W(void 0,e),tabList:[{itemKey:`list`,tab:e(`workflows.processLibrary`,null,`工作流列表`)},{itemKey:`runs`,tab:e(`workflows.runsPending`,null,`运行历史`)}],className:`workflow-tabs`}),_===`runs`?(0,Y.jsx)(be,{canExecute:a}):(0,Y.jsxs)(M,{title:e(`workflows.processLibrary`,null,`工作流列表`),description:e(`workflows.metaIdHint`,null,`创建后不可修改,用于 API 与角色绑定`),extra:(0,Y.jsxs)(Ee,{type:`tertiary`,size:`small`,children:[K.length,` / `,H.length]}),children:[(0,Y.jsxs)(`div`,{className:`workflow-toolbar`,children:[(0,Y.jsx)(d,{prefix:(0,Y.jsx)(g,{}),value:v,showClear:!0,placeholder:e(`workflows.searchPlaceholder`,null,`搜索工作流…`),onChange:e=>y(e),style:{width:260}}),(0,Y.jsxs)(o,{spacing:6,children:[(0,Y.jsx)(p,{checked:S,onChange:te,size:`small`}),(0,Y.jsx)(Ee,{size:`small`,children:`显示已禁用`})]})]}),(0,Y.jsx)(P,{columns:ue,dataSource:K,rowKey:`id`,loading:V.loading,pagination:{pageSize:10},emptyText:e(`workflows.emptyList`,null,`暂无工作流`)})]}),(0,Y.jsx)(fe,{visible:A.visible,workflow:A.workflow,onCancel:()=>N({visible:!1,workflow:null}),onSaved:e=>{N({visible:!1,workflow:null}),G(),e?.id&&W(e.id,`list`)}}),(0,Y.jsx)(me,{workflowId:h,visible:!!h,canWrite:n,canDelete:i,onClose:()=>W(void 0,_),onEdit:e=>{e&&(W(void 0,_),N({visible:!0,workflow:e}))},onDeleted:()=>{W(void 0,_),G()}}),(0,Y.jsx)(Te,{visible:F,onCancel:()=>z(!1),onImported:()=>G()})]})}export{Oe as default}; \ No newline at end of file +import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n,y as r}from"./react-QV7DAAIx.js";import{B as i,G as a,I as o,N as s,P as c,R as l,S as u,U as d,c as f,d as p,ft as m,h,lt as g,m as _,p as v,s as y,u as b,ut as x,x as S}from"./semi-65W_4I1v.js";import{E as C,F as w,I as T,L as E,R as D,_ as ee,a as O,b as k,c as te,d as A,l as j,m as M,n as ne,p as re,r as N,s as P,u as F,x as I,y as L}from"./index-DNMXun-U.js";var R=e(t(),1),z=[{value:`start`,label:`开始`},{value:`tool`,label:`工具`},{value:`agent`,label:`Agent`},{value:`condition`,label:`条件`},{value:`hitl`,label:`审批`},{value:`output`,label:`输出`},{value:`end`,label:`结束`}],ie=Object.fromEntries(z.map(e=>[e.value,e.label])),B={running:{label:`执行中`,color:`blue`},awaiting_hitl:{label:`等待审批`,color:`amber`},completed:{label:`已完成`,color:`green`},failed:{label:`失败`,color:`red`},cancelled:{label:`已取消`,color:`grey`},pending:{label:`待执行`,color:`amber`}},V={nodes:[{id:`start`,type:`start`,label:`开始`,position:{x:80,y:140},config:{}},{id:`out`,type:`output`,label:`输出`,position:{x:380,y:140},config:{output_key:`result`}}],edges:[{id:`e1`,source:`start`,target:`out`,label:``}],config:{}},H={WFPKG_FILE_REQUIRED:`workflows.package.errors.fileRequired`,WFPKG_FILE_TOO_LARGE:`workflows.package.errors.fileTooLarge`,WFPKG_UNSUPPORTED_FORMAT:`workflows.package.errors.unsupportedFormat`,WFPKG_INVALID_ARCHIVE:`workflows.package.errors.invalidArchive`,WFPKG_INVALID_MANIFEST:`workflows.package.errors.invalidManifest`,WFPKG_CHECKSUM_MISMATCH:`workflows.package.errors.checksumMismatch`,WFPKG_MULTIPLE_WORKFLOWS:`workflows.package.errors.multipleWorkflows`,WFPKG_WORKFLOW_INVALID:`workflows.package.errors.workflowInvalid`,WFPKG_INSPECTION_NOT_FOUND:`workflows.package.errors.inspectionNotFound`,WFPKG_INSPECTION_EXPIRED:`workflows.package.errors.inspectionExpired`,WFPKG_INSPECTION_CONSUMED:`workflows.package.errors.inspectionConsumed`,WFPKG_CONFLICT_CHANGED:`workflows.package.errors.conflictChanged`,WFPKG_ID_CONFLICT:`workflows.package.errors.idConflict`,WFPKG_INVALID_ACTION:`workflows.package.errors.invalidAction`,WFPKG_INVALID_RENAME_ID:`workflows.package.errors.invalidRenameId`,WFPKG_OVERWRITE_CONFIRMATION_REQUIRED:`workflows.package.errors.overwriteConfirmationRequired`,WFPKG_IDEMPOTENCY_KEY_REQUIRED:`workflows.package.errors.idempotencyKeyRequired`,WFPKG_IDEMPOTENCY_KEY_REUSED:`workflows.package.errors.idempotencyKeyReused`,WFPKG_IMPORT_FAILED:`workflows.package.errors.importFailed`},U={create:{label:`创建导入`,hint:`导入后会创建一个新的本地工作流。`},keep_existing:{label:`保留本地版本`,hint:`不修改当前本地工作流;导入记录会保留。`},overwrite:{label:`覆盖本地版本`,hint:`替换名称、描述、图定义和启用状态;需要再次确认。`},rename:{label:`另存为新 ID`,hint:`保留当前本地工作流,并以新的 ID 创建副本。`}},W={none:[`create`],identical:[`keep_existing`],id_conflict:[`keep_existing`,`overwrite`,`rename`]};function G(e){return(W[e]||[]).slice()}function K(e){if(!e||!String(e).trim())return{graph:null,error:`图定义不能为空`};try{let t=JSON.parse(e);return!t||typeof t!=`object`?{graph:null,error:`图定义必须是 JSON 对象`}:{graph:{nodes:Array.isArray(t.nodes)?t.nodes:[],edges:Array.isArray(t.edges)?t.edges:[],config:t.config||{}},error:null}}catch(e){return{graph:null,error:e.message||`JSON 解析失败`}}}function ae(e){let{graph:t,error:n}=K(e);return t?{nodes:t.nodes,edges:t.edges,error:null}:{nodes:[],edges:[],error:n}}function q(e,t=12){let n=String(e||``);if(!n)return`—`;let r=n.startsWith(`sha256:`)?n.slice(7):n;return r.length>t?`${r.slice(0,t)}…`:r}function J(e,t=`操作失败`){if(!e)return t;if(typeof e==`string`)return e;let n=e.payload;if(n&&typeof n==`object`){let e=n.error;if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=typeof e.message==`string`?e.message:``,n=typeof e.code==`string`?e.code:``;if(t)return n?`${t}(${n})`:t}if(typeof n.message==`string`&&n.message)return n.message}return typeof e.message==`string`&&e.message&&e.message!==`[object Object]`?e.message:t}function oe(e,t=`加载失败`){return e?{message:J(e,t)}:null}function se(e){let t=e?.payload?.error;return t&&typeof t==`object`&&typeof t.code==`string`?t.code:``}function ce(e,t){let n=se(e);if(n&&H[n]){let e=t?.(H[n],null,``);if(e)return e}return J(e,`操作未完成,请稍后重试。`)}function le(){let e=typeof globalThis<`u`?globalThis.crypto:null;return!e||typeof e.randomUUID!=`function`?``:e.randomUUID()}var Y=e(n(),1),{Text:X}=a,ue=/^[A-Za-z0-9][A-Za-z0-9_-]*$/,de={id:``,name:``,description:``,version:1,enabled:!0,graph:``};function fe({visible:e,workflow:t,onCancel:n,onSaved:r}){let a=w(),{hasPermission:s}=T(),f=s(`workflow:execute`),[p,m]=(0,R.useState)(de),[h,g]=(0,R.useState)(!1),[_,v]=(0,R.useState)(!1),[y,b]=(0,R.useState)(null),x=!!t?.id;(0,R.useEffect)(()=>{if(e){if(b(null),g(!1),t){let e=t.graph_json||``;try{e=JSON.stringify(JSON.parse(e),null,2)}catch{}m({id:t.id||``,name:t.name||``,description:t.description||``,version:t.version||1,enabled:t.enabled!==!1,graph:e})}else m({...de,graph:JSON.stringify(V,null,2)})}},[e,t]);let C=e=>m(t=>({...t,...e})),D=(0,R.useMemo)(()=>ae(p.graph),[p.graph]);return(0,Y.jsxs)(te,{visible:e,title:x?a(`workflows.metaModalTitle`,null,`工作流信息`):a(`workflows.newGraph`,null,`新建工作流`),onCancel:n,onOk:async()=>{let e=(x?t.id:p.id).trim(),n=p.name.trim();if(!e||!n)k(a(`workflows.idNameRequired`,null,`工作流 ID 和名称不能为空`));else if(!x&&!ue.test(e))k(`工作流 ID 必须以字母或数字开头,仅含字母、数字、下划线、连字符`);else{if(p.graph.trim())try{JSON.parse(p.graph)}catch(e){k(`graph 必须是合法 JSON:${J(e,``)}`);return}g(!0);try{let t={id:e,name:n,description:p.description,version:Number(p.version)||0,enabled:!!p.enabled,graph:p.graph.trim()?JSON.parse(p.graph):void 0},i=x?await E.put(`/workflows/${encodeURIComponent(e)}`,t):await E.post(`/workflows`,t);I(a(`workflows.saved`,null,`工作流已保存`)),r?.(i?.workflow||null)}catch(e){k(J(e,a(`workflows.saveFailed`,null,`保存工作流失败`)))}finally{g(!1)}}},okText:a(`common.save`,null,`保存`),cancelText:a(`common.cancel`,null,`取消`),confirmLoading:h,width:860,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-grid`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaId`,null,`ID`)}),(0,Y.jsx)(d,{value:p.id,disabled:x,placeholder:`web-scan-basic`,onChange:e=>C({id:e})}),(0,Y.jsx)(X,{type:`tertiary`,size:`small`,children:a(`workflows.metaIdHint`,null,`创建后不可修改,用于 API 与角色绑定`)})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaName`,null,`名称`)}),(0,Y.jsx)(d,{value:p.name,placeholder:a(`workflows.namePlaceholder`,null,`基础 Web 扫描`),onChange:e=>C({name:e})})]})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-grid`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaDescription`,null,`描述`)}),(0,Y.jsx)(d,{value:p.description,placeholder:a(`workflows.descriptionPlaceholder`,null,`可选`),onChange:e=>C({description:e})})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-grid workflow-form-grid--tight`,children:[(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:`版本`}),(0,Y.jsx)(S,{value:p.version,min:0,style:{width:`100%`},onChange:e=>C({version:e||0})})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:a(`workflows.metaEnabled`,null,`启用`)}),(0,Y.jsx)(c,{checked:p.enabled,onChange:e=>C({enabled:e.target.checked}),children:a(`workflows.metaEnabledHint`,null,`禁用后无法被角色自动触发`)})]})]})]}),(0,Y.jsxs)(`div`,{className:`workflow-form-field`,children:[(0,Y.jsxs)(o,{children:[(0,Y.jsx)(X,{strong:!0,size:`small`,children:`graph JSON`}),(0,Y.jsx)(X,{type:`tertiary`,size:`small`,children:D.error?`解析失败:${D.error}`:`${D.nodes.length} 个节点 · ${D.edges.length} 条连线`})]}),(0,Y.jsx)(u,{value:p.graph,rows:16,spellCheck:!1,className:`workflow-graph-input`,placeholder:`{"nodes":[],"edges":[],"config":{}}`,onChange:e=>{C({graph:e}),b(null)}}),(0,Y.jsxs)(o,{wrap:!0,children:[(0,Y.jsx)(l,{size:`small`,onClick:()=>{try{C({graph:JSON.stringify(JSON.parse(p.graph),null,2)}),b(null)}catch(e){k(`${a(`projects.invalidJson`,null,`JSON 格式无效`)}:${J(e,``)}`)}},children:a(`projects.formatJson`,null,`格式化`)}),(0,Y.jsx)(l,{size:`small`,onClick:()=>{C({graph:JSON.stringify(V,null,2)}),b(null)},children:`插入最小模板`}),(0,Y.jsx)(l,{size:`small`,loading:_,disabled:!f,title:f?``:`需要 workflow:execute 权限`,onClick:async()=>{if(!p.graph.trim()){b({type:`danger`,text:a(`workflows.validation.serverFailed`,null,`图定义不能为空`)});return}let e;try{e=JSON.parse(p.graph)}catch(e){b({type:`danger`,text:`JSON 解析失败:${J(e,``)}`});return}v(!0),b(null);try{await E.post(`/workflows/validate`,{graph:e}),b({type:`success`,text:`结构校验通过`})}catch(e){b({type:`danger`,text:J(e,a(`workflows.validation.serverFailed`,null,`后端图校验失败`))})}finally{v(!1)}},children:a(`workflows.validate`,null,`校验图定义`)}),(0,Y.jsxs)(X,{type:`tertiary`,size:`small`,children:[`节点类型:`,z.map(e=>e.label).join(` / `)]})]})]}),y?(0,Y.jsx)(i,{type:y.type,bordered:!0,closeIcon:null,description:y.text,style:{marginTop:12}}):null]})}var{Text:Z}=a;function pe({raw:e}){let t=(0,R.useMemo)(()=>ae(e),[e]);if(t.error)return(0,Y.jsxs)(Z,{type:`danger`,size:`small`,children:[`graph 解析失败:`,t.error]});let n=t.nodes.map(e=>({id:e.id,type:e.type||`tool`,label:e.label||``,config:e.config||{}}));return(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsx)(b,{columns:[{title:`节点`,dataIndex:`id`,width:160,render:e=>(0,Y.jsx)(`code`,{children:e})},{title:`类型`,dataIndex:`type`,width:90,render:e=>(0,Y.jsx)(s,{size:`small`,color:`blue`,type:`light`,children:ie[e]||e})},{title:`名称`,dataIndex:`label`,render:(e,t)=>(0,Y.jsx)(`span`,{className:`workflow-cell-ellipsis`,title:e||t.id,children:e||`—`})}],dataSource:n,rowKey:`id`,size:`small`,pagination:!1,empty:(0,Y.jsx)(Z,{type:`tertiary`,size:`small`,children:`图内没有节点`})}),(0,Y.jsxs)(`div`,{className:`workflow-edge-list`,children:[(0,Y.jsxs)(Z,{strong:!0,size:`small`,children:[`连线(`,t.edges.length,`)`]}),t.edges.length?(0,Y.jsx)(`ul`,{className:`workflow-link-list`,children:t.edges.map((e,t)=>(0,Y.jsxs)(`li`,{children:[(0,Y.jsx)(`code`,{children:e.source}),` → `,(0,Y.jsx)(`code`,{children:e.target}),e.label?(0,Y.jsx)(`span`,{className:`workflow-edge-label`,children:e.label}):null]},e.id||`${e.source}-${e.target}-${t}`))}):(0,Y.jsx)(Z,{type:`tertiary`,size:`small`,children:`暂无连线`})]})]})}function me({workflowId:e,visible:t,canWrite:n,canDelete:r,onClose:i,onEdit:a,onDeleted:c}){let u=w(),[d,f]=(0,R.useState)(!1),p=O(()=>e?E.get(`/workflows/${encodeURIComponent(e)}`):Promise.resolve(null),[e]),m=p.data?.workflow||null;return(0,R.useEffect)(()=>{t&&e&&p.reload({silent:!0})},[t,e]),(0,Y.jsxs)(v,{visible:t,width:760,title:m?m.name||m.id:u(`workflows.metaModalTitle`,null,`工作流信息`),onCancel:i,footer:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{disabled:!n||!m,onClick:()=>a?.(m),children:u(`common.edit`,null,`编辑`)}),(0,Y.jsx)(l,{loading:d,disabled:!m,onClick:async()=>{if(m){f(!0);try{await D(`/workflows/${encodeURIComponent(m.id)}/package`,{filename:`${m.id}.csapkg.zip`}),I(u(`workflows.package.export`,null,`导出`))}catch(e){k(J(e,u(`workflows.package.errors.exportFailed`,null,`导出失败,请稍后重试。`)))}finally{f(!1)}}},children:u(`workflows.package.export`,null,`导出`)}),(0,Y.jsx)(l,{type:`danger`,disabled:!r||!m,onClick:()=>L({title:u(`workflows.deleteWorkflow`,null,`删除工作流`),content:u(`workflows.confirmDelete`,{id:m?.id},`确定删除工作流 ${m?.id}?`),okText:u(`common.delete`,null,`删除`),onOk:async()=>{try{await E.del(`/workflows/${encodeURIComponent(m.id)}`),I(u(`workflows.deleted`,null,`工作流已删除`)),c?.(m.id)}catch(e){k(J(e,u(`workflows.deleteFailed`,null,`删除工作流失败`)))}}}),children:u(`workflows.deleteWorkflow`,null,`删除工作流`)}),(0,Y.jsx)(l,{onClick:i,children:u(`common.close`,null,`关闭`)})]}),children:[(0,Y.jsx)(j,{error:oe(p.error),onRetry:()=>p.reload()}),m?(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsxs)(`div`,{className:`workflow-detail-tags`,children:[(0,Y.jsx)(s,{size:`small`,color:m.enabled?`green`:`grey`,children:m.enabled?u(`workflows.statusEnabled`,null,`启用`):u(`workflows.statusDisabled`,null,`禁用`)}),m.validation_error?(0,Y.jsx)(s,{size:`small`,color:`red`,children:u(`workflows.statusInvalid`,null,`校验未通过`)}):(0,Y.jsx)(s,{size:`small`,color:`green`,type:`light`,children:`结构有效`}),(0,Y.jsxs)(Z,{type:`tertiary`,size:`small`,children:[`版本 `,m.version||0]})]}),m.validation_error?(0,Y.jsx)(j,{error:{message:m.validation_error}}):null,(0,Y.jsx)(A,{columns:2,items:[{label:u(`workflows.metaId`,null,`ID`),value:(0,Y.jsx)(`code`,{children:m.id})},{label:u(`workflows.metaName`,null,`名称`),value:m.name||`—`},{label:u(`workflows.updated`,null,`更新`),value:C(m.updated_at)},{label:`创建`,value:C(m.created_at)},{label:u(`workflows.metaDescription`,null,`描述`),value:m.description||`—`}]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(Z,{strong:!0,children:u(`workflows.nodeProperties`,null,`节点属性`)}),(0,Y.jsx)(pe,{raw:m.graph_json})]}),(0,Y.jsx)(F,{value:m.graph_json?he(m.graph_json):{},title:`graph JSON`,collapsed:!0})]}):null]})}function he(e){try{return JSON.parse(e)}catch{return{raw:e}}}var{Text:Q}=a;function ge(e){let t=B[String(e||``)]||{label:e||`—`,color:`grey`};return(0,Y.jsx)(s,{size:`small`,color:t.color,children:t.label})}function _e({runId:e,visible:t,canExecute:n,onClose:r,onChanged:i}){let a=w(),[s,c]=(0,R.useState)(``),[d,f]=(0,R.useState)(!1),p=O(()=>e?E.get(`/workflows/runs/${encodeURIComponent(e)}`):Promise.resolve(null),[e]),m=O(()=>e?E.get(`/workflows/runs/${encodeURIComponent(e)}/replay`):Promise.resolve(null),[e]),h=p.data?.run||null;(0,R.useEffect)(()=>{t&&e&&(p.reload({silent:!0}),m.reload({silent:!0}))},[t,e]);let g=p.data?.nodeRuns||[],_=m.data?.steps||[],b=t=>L({title:t?`通过审批`:`拒绝审批`,content:t?`确认通过该工作流的审批节点并继续执行?`:`确认拒绝该工作流的审批节点?运行将以失败结束。`,okText:a(`common.confirm`,null,`确认`),danger:!t,onOk:async()=>{f(!0);try{await E.post(`/workflows/runs/${encodeURIComponent(e)}/resume`,{approved:t,comment:s}),I(t?`已通过审批`:`已拒绝审批`),c(``),p.reload({silent:!0}),m.reload({silent:!0}),i?.()}catch(e){k(J(e,`审批提交失败`))}finally{f(!1)}}});return(0,Y.jsxs)(v,{visible:t,width:820,title:a(`workflows.dryRunTrace`,null,`运行轨迹`),onCancel:r,footer:(0,Y.jsxs)(o,{children:[h?.status===`awaiting_hitl`&&n?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(u,{value:s,rows:1,placeholder:`审批备注(可选)`,onChange:e=>c(e),style:{width:240}}),(0,Y.jsx)(l,{type:`primary`,loading:d,onClick:()=>b(!0),children:`通过`}),(0,Y.jsx)(l,{type:`danger`,loading:d,onClick:()=>b(!1),children:`拒绝`})]}):null,(0,Y.jsx)(l,{onClick:r,children:a(`common.close`,null,`关闭`)})]}),children:[(0,Y.jsx)(j,{error:oe(p.error),onRetry:()=>p.reload()}),h?(0,Y.jsxs)(`div`,{className:`workflow-detail-stack`,children:[(0,Y.jsxs)(`div`,{className:`workflow-detail-tags`,children:[ge(h.status),(0,Y.jsxs)(Q,{type:`tertiary`,size:`small`,children:[`运行 `,(0,Y.jsx)(`code`,{children:q(h.id,16)})]})]}),(0,Y.jsx)(A,{columns:2,items:[{label:`工作流`,value:(0,Y.jsx)(`code`,{children:h.workflow_id})},{label:`版本`,value:h.workflow_version??`—`},{label:`会话`,value:h.conversation_id||`—`},{label:`项目`,value:h.project_id||`—`},{label:`开始时间`,value:C(h.started_at)},{label:`结束时间`,value:C(h.finished_at)},h.pending_hitl_node_id?{label:`待审批节点`,value:(0,Y.jsx)(`code`,{children:h.pending_hitl_node_id})}:null,h.error?{label:`错误`,value:(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:h.error})}:null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,children:[`节点执行记录(`,g.length,`)`]}),(0,Y.jsx)(y,{className:`workflow-timeline`,children:g.length?g.map(e=>(0,Y.jsx)(y.Item,{time:C(e.started_at),type:e.status===`failed`?`error`:e.status===`completed`?`success`:`ongoing`,children:(0,Y.jsxs)(`div`,{className:`workflow-timeline-item`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`code`,{children:e.node_id}),` `,ge(e.status)]}),e.error?(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:e.error}):null,e.output_json?(0,Y.jsx)(F,{value:ve(e.output_json),title:`output`,collapsed:!0}):null]})},e.id)):(0,Y.jsx)(Q,{type:`tertiary`,size:`small`,children:`暂无节点执行记录`})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,children:[a(`workflows.dryRunTrace`,null,`回放轨迹`),`(`,_.length,` 步)`]}),(0,Y.jsx)(y,{className:`workflow-timeline`,children:_.length?_.map(e=>(0,Y.jsx)(y.Item,{time:C(e.startedAt),type:e.status===`failed`?`error`:e.status===`completed`?`success`:`ongoing`,children:(0,Y.jsxs)(`div`,{className:`workflow-timeline-item`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(Q,{strong:!0,size:`small`,children:[`#`,e.step]}),` `,(0,Y.jsx)(`code`,{children:e.nodeId}),` `,ge(e.status)]}),e.error?(0,Y.jsx)(Q,{type:`danger`,size:`small`,children:e.error}):null,(0,Y.jsx)(F,{value:{input:e.input,output:e.output},title:`step`,collapsed:!0})]})},e.nodeRunId||`${e.step}-${e.nodeId}`)):(0,Y.jsx)(Q,{type:`tertiary`,size:`small`,children:a(`workflows.dryRunNoTrace`,null,`暂无轨迹`)})})]}),(0,Y.jsx)(F,{value:h,title:`run`,collapsed:!0})]}):null]})}function ve(e){try{return JSON.parse(e)}catch{return{raw:e}}}var{Text:ye}=a;function be({canExecute:e}){let t=w(),[n,i]=r(),a=n.get(`run`)||``,c=O(()=>E.get(`/workflows/runs/pending`),[]);N(()=>c.reload({silent:!0}),15e3);let u=Array.isArray(c.data?.runs)?c.data.runs:[],d=e=>{let t=new URLSearchParams(n);e?t.set(`run`,e):t.delete(`run`),i(t,{replace:!0})},f=[{title:`运行`,dataIndex:`id`,width:190,render:e=>(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>d(e),children:(0,Y.jsx)(`code`,{children:q(e,14)})})},{title:`工作流`,dataIndex:`workflow_id`,width:200,render:e=>(0,Y.jsx)(ye,{size:`small`,children:(0,Y.jsx)(`code`,{children:e})})},{title:`会话`,dataIndex:`conversation_id`,width:220,render:e=>(0,Y.jsx)(ye,{type:`tertiary`,size:`small`,children:(0,Y.jsx)(`code`,{children:e||`—`})})},{title:t(`projects.status`,null,`状态`),dataIndex:`status`,width:110,render:e=>{let t=B[String(e||``)]||{label:e||`—`,color:`grey`};return(0,Y.jsx)(s,{size:`small`,color:t.color,children:t.label})}},{title:`待审批节点`,dataIndex:`pending_hitl_node_id`,width:160,render:e=>e?(0,Y.jsx)(`code`,{children:e}):(0,Y.jsx)(ye,{type:`tertiary`,children:`—`})},{title:`开始时间`,dataIndex:`started_at`,width:165,render:e=>(0,Y.jsx)(ye,{size:`small`,children:C(e)})},{title:t(`common.actions`,null,`操作`),dataIndex:`id`,width:120,render:e=>(0,Y.jsx)(o,{children:(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>d(e),children:t(`projects.details`,null,`详情`)})})}];return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(M,{title:t(`workflows.runsPending`,null,`待审批运行`),description:`等待审批(awaiting_hitl)的工作流运行,每 15 秒自动刷新。${e?` 可直接在此通过或拒绝。`:``}`,extra:(0,Y.jsx)(l,{icon:(0,Y.jsx)(x,{}),theme:`borderless`,loading:c.loading,onClick:()=>c.reload(),children:t(`common.refresh`,null,`刷新`)}),children:[(0,Y.jsx)(j,{error:oe(c.error),onRetry:()=>c.reload()}),(0,Y.jsx)(P,{columns:f,dataSource:u,rowKey:`id`,loading:c.loading,pagination:{pageSize:10},emptyText:`当前没有等待审批的工作流运行`})]}),(0,Y.jsx)(_e,{runId:a,visible:!!a,canExecute:e,onClose:()=>d(``),onChanged:()=>c.reload({silent:!0})})]})}var{Text:$,Paragraph:xe}=a,Se=10485760;function Ce(e){let t=String(e||``).replace(/^data:[^;]+;base64,/,``).replace(/\s+/g,``);if(!t)throw Error(`粘贴内容为空`);let n=atob(t),r=new Uint8Array(n.length);for(let e=0;e{e||(f(null),m(``),v(``),b(null),S(``),D(``),O(!1),N(``),F(null),j(!1),ne(!1))},[e]);let L=y?.conflict?.state||``,z=(0,R.useMemo)(()=>G(L),[L]),ie=()=>{v(``);try{let e=Ce(p);if(e.size>Se){v(r(`workflows.package.errors.fileTooLarge`,null,`文件超过 10 MiB 限制,请选择更小的本地包。`));return}f(e),b(null),F(null)}catch(e){v(`Base64 解码失败:${J(e,``)}`)}},B=e=>{let t=e.target.files&&e.target.files[0];v(``),N(``),F(null),b(null),t?t.size>Se?(v(r(`workflows.package.errors.fileTooLarge`,null,`文件超过 10 MiB 限制,请选择更小的本地包。`)),f(null)):f(t):f(null)},V=async()=>{if(!a)v(r(`workflows.package.errors.fileRequired`,null,`请选择本地工作流包后再预检。`));else{j(!0),N(``),F(null);try{let e=new FormData;e.append(`file`,a,a.name||`workflow.csapkg.zip`);let t=(await E.post(`/workflow-package-inspections`,e))?.inspection||null;b(t);let n=G(t?.conflict?.state||``);S(n[0]||``),D(``),O(!1)}catch(e){N(ce(e,r))}finally{j(!1)}}},H=async()=>{if(!y?.id){N(r(`workflows.package.resolution.needInspection`,null,`请先选择本地包并完成预检。`));return}if(!x){N(r(`workflows.package.errors.invalidAction`,null,`导入处理方式无效,请重新选择。`));return}if(x===`rename`&&!T.trim()){N(r(`workflows.package.errors.invalidRenameId`,null,`请输入可用的新工作流 ID。`));return}if(x===`overwrite`&&!ee){N(r(`workflows.package.errors.overwriteConfirmationRequired`,null,`请勾选确认后再覆盖本地工作流。`));return}let e=le();if(!e)N(r(`workflows.package.errors.idempotencyKeyRequired`,null,`浏览器无法生成导入请求标识,请刷新页面后重试。`));else{ne(!0),N(``);try{let t=await E.post(`/workflow-package-imports`,{inspection_id:y.id,resolution:{action:x,new_workflow_id:x===`rename`?T.trim():``},confirm_overwrite:x===`overwrite`},{headers:{"Idempotency-Key":e}});F(t?.import||null),I(r(`workflows.package.result.complete`,null,`导入已完成。`)),n?.(t?.import||null)}catch(e){N(ce(e,r))}finally{ne(!1)}}},W=L===`identical`?r(`workflows.package.conflict.identical`,null,`检测到同 ID 且内容相同的本地工作流;本次将跳过导入。`):L===`id_conflict`?r(`workflows.package.conflict.idConflict`,null,`检测到同 ID 但内容不同的本地工作流。默认保留本地版本。`):L===`none`?r(`workflows.package.conflict.none`,null,`未发现同 ID 的本地工作流,可创建导入。`):``,K=y?.workflow;return(0,Y.jsxs)(te,{visible:e,title:r(`workflows.package.title`,null,`导入本地包`),onCancel:t,width:760,maskClosable:!k&&!M,footer:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{onClick:t,children:r(`common.close`,null,`关闭`)}),(0,Y.jsx)(l,{type:`primary`,loading:k,disabled:!!P,onClick:V,children:k?r(`workflows.package.inspecting`,null,`正在安全预检…`):r(`workflows.package.inspect`,null,`上传并预检`)}),(0,Y.jsx)(l,{type:`primary`,loading:M,disabled:!y||!!P||!x,onClick:H,children:r(`workflows.package.confirmImport`,null,`确认导入`)})]}),children:[(0,Y.jsxs)(xe,{type:`tertiary`,size:`small`,children:[r(`workflows.package.preflightHint`,null,`先检查包内容与冲突,再由你确认是否导入`),` · `,r(`workflows.package.fileHint`,null,`仅支持单个 .csapkg.zip,文件不得超过 10 MiB。`)]}),(0,Y.jsxs)(`div`,{className:`workflow-package-block`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.stepInspection`,null,`上传与预检`)}),(0,Y.jsxs)(`div`,{className:`workflow-package-file-row`,children:[(0,Y.jsx)(`input`,{type:`file`,accept:`.zip,application/zip`,className:`workflow-file-input`,onChange:B,"aria-label":r(`workflows.package.selectFile`,null,`选择本地包`)}),(0,Y.jsx)($,{type:`tertiary`,size:`small`,children:a?`${a.name} · ${(a.size/1024).toFixed(1)} KiB`:r(`workflows.package.noFile`,null,`未选择文件`)}),a?(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>{f(null),b(null),F(null)},children:r(`workflows.package.removeFile`,null,`移除文件`)}):null]}),(0,Y.jsx)(u,{value:p,rows:3,placeholder:`或粘贴工作流包 base64(.csapkg.zip)`,onChange:e=>m(e)}),(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{size:`small`,onClick:ie,disabled:!p.trim(),children:`使用粘贴内容`}),g?(0,Y.jsx)($,{type:`danger`,size:`small`,children:g}):null]})]}),re?(0,Y.jsx)(i,{type:`danger`,bordered:!0,closeIcon:null,description:re,className:`workflow-package-banner`}):null,y?(0,Y.jsxs)(`div`,{className:`workflow-package-block`,children:[(0,Y.jsxs)(`div`,{className:`workflow-package-summary-head`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.summary.title`,null,`预检结果`)}),(0,Y.jsx)(s,{size:`small`,color:`green`,children:r(`workflows.package.summary.passed`,null,`校验通过`)})]}),(0,Y.jsx)(i,{type:L===`id_conflict`?`warning`:`success`,bordered:!0,closeIcon:null,description:W,className:`workflow-package-banner`}),(0,Y.jsx)(A,{columns:2,items:[{label:r(`workflows.package.summary.workflowName`,null,`工作流名称`),value:K?.name||`—`},{label:r(`workflows.package.summary.sourceId`,null,`源工作流 ID`),value:(0,Y.jsx)(`code`,{children:K?.source_id||`—`})},{label:r(`workflows.package.summary.sourceRevision`,null,`源版本`),value:K?.source_revision??`—`},{label:r(`workflows.package.summary.graphSize`,null,`图规模`),value:`${K?.node_count||0} 节点 · ${K?.edge_count||0} 连线`},{label:r(`workflows.package.summary.contentHash`,null,`内容摘要`),value:q(K?.content_hash)},{label:r(`workflows.package.summary.expiresAt`,null,`预检有效期`),value:C(y.expires_at)}]}),(0,Y.jsx)($,{strong:!0,size:`small`,children:r(`workflows.package.resolutionTitle`,null,`处理方式`)}),(0,Y.jsx)(h,{value:x,onChange:e=>{S(e.target.value),O(!1)},direction:`vertical`,children:z.map(e=>(0,Y.jsx)(_,{value:e,children:(0,Y.jsxs)(`span`,{className:`workflow-package-action`,children:[(0,Y.jsx)($,{strong:!0,size:`small`,children:U[e]?.label||e}),(0,Y.jsx)($,{type:`tertiary`,size:`small`,children:U[e]?.hint||``})]})},e))}),x===`rename`?(0,Y.jsx)(d,{value:T,placeholder:r(`workflows.package.resolution.newWorkflowIdPlaceholder`,null,`例如:web-scan-basic-copy`),onChange:e=>D(e)}):null,x===`overwrite`?(0,Y.jsxs)(`div`,{className:`workflow-package-overwrite`,children:[(0,Y.jsx)(i,{type:`warning`,bordered:!0,closeIcon:null,description:r(`workflows.package.overwriteWarning`,null,`覆盖将替换名称、描述、图定义和启用状态。本期不提供回滚。`)}),(0,Y.jsx)(c,{checked:ee,onChange:e=>O(e.target.checked),children:r(`workflows.package.overwriteCheck`,null,`我已确认覆盖当前本地工作流`)})]}):null]}):null,P?(0,Y.jsx)(i,{type:`success`,bordered:!0,closeIcon:null,className:`workflow-package-banner`,description:r(we[P.result]||`workflows.package.result.complete`,null,`导入已完成。`)}):null]})}var{Text:Ee}=a;async function De(){let[e,t]=await Promise.all([E.get(`/workflows`,{includeDisabled:`true`}),E.get(`/workflows/runs/pending`).catch(()=>null)]);return{workflows:Array.isArray(e?.workflows)?e.workflows:[],pendingRuns:Array.isArray(t?.runs)?t.runs:[]}}function Oe(){let e=w(),{hasPermission:t}=T(),n=t(`workflow:write`),i=t(`workflow:delete`),a=t(`workflow:execute`),[c,u]=r(),h=c.get(`id`)||``,_=c.get(`tab`)||`list`,[v,y]=(0,R.useState)(``),b=ne(v,250),[S,te]=(0,R.useState)(!0),[A,N]=(0,R.useState)({visible:!1,workflow:null}),[F,z]=(0,R.useState)(!1),[ie,B]=(0,R.useState)(0),V=O(De,[ie]),H=V.data?.workflows||[],U=V.data?.pendingRuns||[],W=(0,R.useCallback)((e,t)=>{let n=new URLSearchParams(c);e?n.set(`id`,e):n.delete(`id`),t?n.set(`tab`,t):n.delete(`tab`),t&&t!==`runs`&&n.delete(`run`),u(n,{replace:!!e})},[c,u]),G=()=>B(e=>e+1),K=(0,R.useMemo)(()=>{let e=b.trim().toLowerCase();return H.filter(t=>!S&&t.enabled===!1?!1:!e||[t.id,t.name,t.description].join(` `).toLowerCase().includes(e))},[H,b,S]),q=H.filter(e=>!!e.validation_error).length,se=H.filter(e=>e.enabled).length,ce=[{id:`total`,label:e(`workflows.processLibrary`,null,`工作流列表`),value:H.length,loading:V.loading},{id:`enabled`,label:e(`workflows.statusEnabled`,null,`启用`),value:se,tone:`success`,loading:V.loading},{id:`invalid`,label:e(`workflows.statusInvalid`,null,`校验未通过`),value:q,tone:q?`danger`:void 0,loading:V.loading},{id:`pending`,label:e(`workflows.runsPending`,null,`待审批运行`),value:U.length,tone:U.length?`warning`:void 0,loading:V.loading}],le=async t=>{try{await D(`/workflows/${encodeURIComponent(t.id)}/package`,{filename:`${t.id}.csapkg.zip`}),I(e(`workflows.package.export`,null,`导出`))}catch(t){k(J(t,e(`workflows.package.errors.exportFailed`,null,`导出失败,请稍后重试。`)))}},X=t=>L({title:e(`workflows.deleteWorkflow`,null,`删除工作流`),content:e(`workflows.confirmDelete`,{id:t.id},`确定删除工作流 ${t.id}?`),okText:e(`common.delete`,null,`删除`),onOk:async()=>{try{await E.del(`/workflows/${encodeURIComponent(t.id)}`),I(e(`workflows.deleted`,null,`工作流已删除`)),h===t.id&&W(void 0,_),G()}catch(t){k(J(t,e(`workflows.deleteFailed`,null,`删除工作流失败`)))}}}),ue=[{title:e(`workflows.metaName`,null,`名称`),dataIndex:`name`,render:(t,n)=>{let r=ae(n.graph_json);return(0,Y.jsxs)(`button`,{type:`button`,className:`workflow-name-button`,onClick:()=>W(n.id,`list`),title:n.id,children:[(0,Y.jsx)(`span`,{className:`workflow-name-text`,children:t||e(`workflows.untitled`,null,`未命名工作流`)}),(0,Y.jsxs)(`span`,{className:`workflow-name-sub`,children:[(0,Y.jsx)(`code`,{children:n.id}),` · `,r.error?`图解析失败`:`${r.nodes.length} 节点 / ${r.edges.length} 连线`]})]})}},{title:e(`projects.status`,null,`状态`),dataIndex:`enabled`,width:150,render:(t,n)=>(0,Y.jsxs)(o,{spacing:4,wrap:!0,children:[(0,Y.jsx)(s,{size:`small`,color:t?`green`:`grey`,children:t?e(`workflows.statusEnabled`,null,`启用`):e(`workflows.statusDisabled`,null,`禁用`)}),n.validation_error?(0,Y.jsx)(s,{size:`small`,color:`red`,children:e(`workflows.statusInvalid`,null,`校验未通过`)}):null]})},{title:`版本`,dataIndex:`version`,width:80,render:e=>(0,Y.jsxs)(Ee,{size:`small`,children:[`v`,e??0]})},{title:e(`projects.updated`,null,`更新`),dataIndex:`updated_at`,width:165,render:e=>(0,Y.jsx)(Ee,{type:`tertiary`,size:`small`,children:C(e)})},{title:e(`common.actions`,null,`操作`),dataIndex:`id`,width:260,render:(t,r)=>(0,Y.jsxs)(o,{spacing:2,wrap:!0,children:[(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>W(r.id,`list`),children:e(`projects.details`,null,`详情`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,disabled:!n,onClick:()=>N({visible:!0,workflow:r}),children:e(`common.edit`,null,`编辑`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,onClick:()=>le(r),children:e(`workflows.package.export`,null,`导出`)}),(0,Y.jsx)(l,{size:`small`,theme:`borderless`,type:`danger`,disabled:!i,onClick:()=>X(r),children:e(`common.delete`,null,`删除`)})]})}];return(0,Y.jsxs)(`div`,{className:`workflow-page`,children:[(0,Y.jsx)(re,{title:e(`workflows.title`,null,`工作流`),description:e(`workflows.processLibraryHint`,null,`工作流定义由节点与连线组成,可被角色或对话按需触发。`),extra:(0,Y.jsxs)(o,{children:[(0,Y.jsx)(l,{icon:(0,Y.jsx)(x,{}),theme:`borderless`,loading:V.loading,onClick:G,children:e(`common.refresh`,null,`刷新`)}),(0,Y.jsx)(l,{disabled:!n,onClick:()=>z(!0),children:e(`workflows.package.importLocal`,null,`导入本地包`)}),(0,Y.jsx)(l,{type:`primary`,icon:(0,Y.jsx)(m,{}),disabled:!n,onClick:()=>N({visible:!0,workflow:null}),children:e(`workflows.newGraph`,null,`新建工作流`)})]})}),(0,Y.jsx)(j,{error:oe(V.error),onRetry:G}),(0,Y.jsx)(ee,{metrics:ce,columns:4}),(0,Y.jsx)(f,{type:`line`,activeKey:_,onChange:e=>W(void 0,e),tabList:[{itemKey:`list`,tab:e(`workflows.processLibrary`,null,`工作流列表`)},{itemKey:`runs`,tab:e(`workflows.runsPending`,null,`运行历史`)}],className:`workflow-tabs`}),_===`runs`?(0,Y.jsx)(be,{canExecute:a}):(0,Y.jsxs)(M,{title:e(`workflows.processLibrary`,null,`工作流列表`),description:e(`workflows.metaIdHint`,null,`创建后不可修改,用于 API 与角色绑定`),extra:(0,Y.jsxs)(Ee,{type:`tertiary`,size:`small`,children:[K.length,` / `,H.length]}),children:[(0,Y.jsxs)(`div`,{className:`workflow-toolbar`,children:[(0,Y.jsx)(d,{prefix:(0,Y.jsx)(g,{}),value:v,showClear:!0,placeholder:e(`workflows.searchPlaceholder`,null,`搜索工作流…`),onChange:e=>y(e),style:{width:260}}),(0,Y.jsxs)(o,{spacing:6,children:[(0,Y.jsx)(p,{checked:S,onChange:te,size:`small`}),(0,Y.jsx)(Ee,{size:`small`,children:`显示已禁用`})]})]}),(0,Y.jsx)(P,{columns:ue,dataSource:K,rowKey:`id`,loading:V.loading,pagination:{pageSize:10},emptyText:e(`workflows.emptyList`,null,`暂无工作流`)})]}),(0,Y.jsx)(fe,{visible:A.visible,workflow:A.workflow,onCancel:()=>N({visible:!1,workflow:null}),onSaved:e=>{N({visible:!1,workflow:null}),G(),e?.id&&W(e.id,`list`)}}),(0,Y.jsx)(me,{workflowId:h,visible:!!h,canWrite:n,canDelete:i,onClose:()=>W(void 0,_),onEdit:e=>{e&&(W(void 0,_),N({visible:!0,workflow:e}))},onDeleted:()=>{W(void 0,_),G()}}),(0,Y.jsx)(Te,{visible:F,onCancel:()=>z(!1),onImported:()=>G()})]})}export{Oe as default}; \ No newline at end of file diff --git a/web/static/app/index.html b/web/static/app/index.html index df1b4481..80523778 100644 --- a/web/static/app/index.html +++ b/web/static/app/index.html @@ -18,7 +18,7 @@ } catch (error) { /* first paint fallback */ } })(); - +