import { useState } from 'react' import { AlertTriangle, CheckCircle2, KeyRound, Trash2 } from 'lucide-react' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { useClearCookie, useCookieStatus, useSetCookie } from '@/hooks/useMonitor' import { useCurrentPlatform } from '@/hooks/usePlatform' import { formatDateTime, formatRelative } from '@/lib/monitorFormat' /** * Cookie health for unattended runs. * * The expiry signal that matters is `last_ok_at` (the last run that actually * authenticated), not `updated_at`: a cookie can be saved long ago and still be * working, or be fresh and already rejected. */ export function CookiePanel() { const { capability, platform } = useCurrentPlatform() // Scoped to the selected platform: each keeps its own login. const { data: status } = useCookieStatus() const setCookie = useSetCookie() const clearCookie = useClearCookie() const [draft, setDraft] = useState('') const [editing, setEditing] = useState(false) const showForm = !status?.present || editing const label = capability?.label ?? platform return (
{/* 标题要和扫码面板区分开:这个是"存进库里、每轮注入子进程"的 cookie, 那个是"写进浏览器 profile、CDP 模式复用"的登录态。两者是不同机制、 也都能同时算"登录着",都叫「登录态」就分不清在说哪一个。 */} {label} Cookie(定时任务用) {status?.present ? ( 已配置 ) : ( 未配置 )}
{status?.present && !editing && ( <> )}
{status?.present && !editing && (
长度 {status.length} 保存于 {formatDateTime(status.updated_at)} 最近成功 {status.last_ok_at ? ( <> {formatRelative(status.last_ok_at)} ) : ( <> 尚无成功记录 )}
)} {showForm && (

定时监控需要长期有效的登录态。在浏览器登录{label}后,从开发者工具复制完整 Cookie 粘贴到此处(需包含 web_session、 a1、 webId)。 Cookie 通常数周后失效,届时任务会提示重新粘贴。该 Cookie 只用于{label}。