/** * 自动发现 token,按以下优先级依次尝试: * * 1. chrome.storage(扩展缓存,最快,无网络请求) * 2. chrome.cookies API(扩展专属) * 3. /api/v0/users/current API(同域场景最可靠,除非 skipApi=true) * 4. document.cookie 解析 * 5. window 全局变量 * * 任一策略成功即立即返回。 */ export declare function autoDiscover(options?: AutoDiscoverOptions): Promise; export declare interface AutoDiscoverOptions { /** * API 基础 URL,默认 'https://chat.deepseek.com' */ baseUrl?: string; /** * 跳过 API 调用策略。 * 扩展 Background Service Worker 通常无法直接调用页面 API,应设为 true */ skipApi?: boolean; } /** * 将 token 缓存到 chrome.storage.local * 在扩展 Background 的 webRequest 监听器中调用,后续可通过 autoDiscover() 快速读取 */ export declare function cacheTokenToExtensionStorage(token: string): void; export declare interface ChatMessage { message_id: number; parent_id: number | null; role: MessageRole; thinking_enabled: boolean; ban_edit: boolean; ban_regenerate: boolean; status: MessageStatus; incomplete_message: string | null; accumulated_token_usage: number; feedback: FeedbackType; search_enabled: boolean; fragments: Fragment[]; has_pending_fragment: boolean; auto_continue: boolean; } export declare interface ChatSession { id: string; title: string | null; title_type: TitleType; pinned: boolean; model_type: ModelType; updated_at: number; inserted_at?: number; seq_id?: number; agent?: string; version?: number; current_message_id?: number | null; is_empty?: boolean; } /** 点击「开启新对话」按钮 */ export declare function clickNewChat(): boolean; /** 点击发送按钮 */ export declare function clickSend(): boolean; export declare interface ContinueParams { sessionId: string; messageId: number; continueType?: 'auto' | 'manual'; fallbackToResume?: boolean; } export declare type CredentialSource = 'api' | 'cookie' | 'extension-cookie' | 'extension-storage' | 'page-global' | 'manual'; declare const CSS_2: { readonly root: "#root"; readonly themeRoot: ".ds-theme"; readonly mainLayout: ".c3ecdb44"; readonly sidebar: ".b8812f16.a2f3d50e"; readonly mainContent: "._7780f2e"; readonly chatScrollArea: "._765a5cd.ds-scroll-area"; readonly chatContent: "._2be88ba"; /** 侧边栏顶部区域(含 logo SVG + 折叠按钮) */ readonly sidebarHeader: "._262baab"; /** DeepSeek logo SVG 的直接父容器 */ readonly logoWrap: ".e066abb8"; /** logo SVG 元素本身 */ readonly logoSvg: ".e066abb8 svg"; /** 聊天页顶部整条 navbar(含会话名 + 模式徽章 + 分享按钮) */ readonly chatNavbar: ".f8d1e4c0"; /** 会话名 + 模式徽章的左侧组合容器 */ readonly chatNavLeft: "._9fcbeda._7ee190f"; /** 顶部可编辑会话标题(tabindex="0") */ readonly chatSessionTitle: ".afa34042.e0a1edb7.e37a04e4._5a50d80"; /** 模式徽章容器(含闪电图标 + "快速模式"/"专家模式" 文字) */ readonly modeBadgeWrap: ".c03d486a"; /** 模式徽章文字 span */ readonly modeBadgeText: "._46a12ab"; /** 顶部右侧分享/导出区域 */ readonly chatNavRight: "._1aa2651"; readonly newChatBtn: "._5a8ac7a"; readonly collapseBtn: "._7d1f5e2.ds-icon-button"; readonly sessionScrollArea: "._3586175.ds-scroll-area"; /** 会话列表分组标签的外层容器(含"今天"/"昨天"等分组 label) */ readonly sessionGroupWrap: "._3098d02"; /** 分组 label 文字("今天"、"昨天"、"上个月"…) */ readonly sessionGroupLabel: ".f3d18f6a"; /** 单条会话 链接 */ readonly sessionLink: "a._546d736[href*=\"/a/chat/s/\"]"; /** 活跃(当前选中)会话链接(额外 active 类) */ readonly sessionLinkActive: "a._546d736.b64fb9ae"; /** 会话标题文字 */ readonly sessionTitle: ".c08e6e93"; /** 会话悬停时出现的操作按钮区(更多/删除/重命名) */ readonly sessionActions: "._254829d"; /** 侧边栏底部用户区 */ readonly userArea: "._2afd28d"; /** 用户头像首字母圆圈 */ readonly userAvatar: ".ede5bc47"; /** 用户邮箱文字 */ readonly userEmail: "._9d8da05"; /** 用户区展开菜单图标 */ readonly userMenuIcon: "._39cc453"; readonly messageList: ".ds-virtual-list-visible-items"; readonly userBubble: "._9663006._2c189bc"; readonly userBubbleText: ".fbb737a4"; readonly aiBubble: "._4f9bf79.d7dc56a8"; readonly aiMarkdown: ".ds-markdown"; /** AI 消息底部操作栏(复制/重新生成/反馈等按钮) */ readonly aiActionBar: "._0a3d93b"; /** AI 操作栏左侧按钮组 */ readonly aiActionBarLeft: "._965abe9"; /** 思考块可折叠外层容器 */ readonly thinkingOuter: "._74c0879"; /** 思考块标题行("已思考 N 秒") */ readonly thinkingTitle: "._245c867"; /** 思考块内容区(展开后可见) */ readonly thinkingContent: ".e1675d8b.ds-think-content"; /** 搜索结果汇总卡片(含来源图标 + "N 个网页"文字) */ readonly searchResultCard: ".f93f59e4"; /** 来源站点图标列表容器 */ readonly searchSourceIcons: "._287b564"; /** 单个来源站点图标容器 */ readonly searchSourceIcon: "._8e95474.site_logo_back"; /** 来源站点图标 */ readonly searchSourceImg: "._8e95474 .site_logo_img"; /** 引用角标 (正文中的 [1][2] 上标) */ readonly citationMark: ".ds-markdown-cite"; /** 文件附件外层容器 */ readonly fileAttachWrap: "._789aea7"; /** 文件名行 */ readonly fileAttachName: ".f3a54b52"; /** 文件内容/图片预览区 */ readonly fileAttachBody: "._7e13492"; /** 文件大小/类型徽章 */ readonly fileAttachMeta: "._5119742.dc832104"; readonly inputArea: "._020ab5b"; /** 输入框滚动容器 */ readonly inputScrollWrap: "._24fad49"; readonly textarea: "textarea._27c9245"; readonly textareaFallback: "textarea[placeholder*=\"DeepSeek\"]"; /** 输入区工具栏(含深度思考/联网搜索/上传/发送按钮) */ readonly inputToolbar: ".ec4f5d61"; readonly sendBtn: "._52c986b.bd74640a"; readonly uploadBtn: ".f02f0e25.ds-icon-button--l"; readonly toggleBtn: ".ds-atom-button.ds-toggle-button.ds-toggle-button--md"; readonly modeRadio: "[role=\"radio\"]"; readonly toggleSelected: "ds-toggle-button--selected"; readonly sendBtnDisabled: "ds-icon-button--disabled"; readonly modeActive: "_31a22b0"; /** 当前活跃会话 link 的额外类 */ readonly sessionActive: "b64fb9ae"; }; export { CSS_2 as CSS } export declare class DeepSeekDriver { private _token; private readonly _wasmUrl; private readonly _baseUrl; private readonly _skipApiDiscover; constructor(options?: DeepSeekDriverOptions); private resolveToken; /** 获取当前登录用户信息,并自动缓存 token */ getCurrentUser(): Promise; /** 手动设置 token */ setToken(token: string): void; /** 获取当前缓存的 token */ getToken(): string | undefined; /** 创建新会话 */ createSession(): Promise; /** 获取会话列表(分页) */ listSessions(cursor?: SessionListCursor, count?: number): Promise; /** 获取所有会话(自动翻页) */ listAllSessions(): Promise; /** 重命名会话 */ renameSession(chatSessionId: string, title: string): Promise<{ chat_session_updated_at: number; title: string; }>; /** 删除会话 */ deleteSession(chatSessionId: string): Promise; /** 删除全部会话 */ deleteAllSessions(): Promise; /** 置顶/取消置顶会话 */ pinSession(chatSessionId: string, pinned: boolean): Promise<{ chat_session_updated_at: number; }>; /** 获取历史消息 */ getHistoryMessages(chatSessionId: string): Promise; /** 发送消息,返回 AsyncIterator 逐 token 流式输出 */ sendMessage(params: SendMessageParams): AsyncGenerator; private _sendMessage; /** 编辑消息,返回 SSE 流 */ editMessage(params: EditMessageParams): AsyncGenerator; private _editMessage; /** 重新生成,返回 SSE 流 */ regenerate(params: RegenerateParams): AsyncGenerator; private _regenerate; /** 续写 */ continueMessage(params: ContinueParams): Promise; /** 消息反馈(点赞/踩/取消) */ messageFeedback(chatSessionId: string, messageId: number, feedbackType: FeedbackType): Promise; /** 上传文件,自动轮询直到处理完成,返回文件信息(含 id) */ uploadFile(file: File | Blob, options?: UploadOptions): Promise; /** 获取文件状态 */ fetchFile(fileId: string): Promise; /** 批量获取文件状态 */ fetchFiles(fileIds: string[]): Promise; /** 轮询文件状态直到成功 */ pollFileStatus(fileId: string): Promise; /** 获取主要客户端设置 */ getMainSettings(deviceId?: string): Promise; /** 获取模型配置列表 */ getModelConfigs(deviceId?: string): Promise; /** * 快速发送消息并返回完整响应文本 * @param sessionId 会话 ID * @param prompt 用户消息 * @param opts 可选参数 */ chat(sessionId: string, prompt: string, opts?: { modelType?: ModelType; thinkingEnabled?: boolean; searchEnabled?: boolean; parentMessageId?: number | null; refFileIds?: string[]; }): Promise<{ thinking: string; response: string; }>; /** 释放内部 Web Worker 资源 */ destroy(): void; } export declare interface DeepSeekDriverOptions { /** Bearer token,可手动传入;不传则由 resolveToken() 自动发现 */ token?: string; /** * 官方 PoW WASM 文件 URL,默认 './sha3_wasm_bg.wasm' * WASM 加载失败时自动回退到纯 JS 实现 */ wasmUrl?: string; /** API 基础 URL,默认 'https://chat.deepseek.com' */ baseUrl?: string; /** * 是否跳过自动发现中的 API 调用策略(/api/v0/users/current) * 浏览器扩展 Background Service Worker 无法直接调用页面 API 时应设为 true * 默认 false */ skipApiDiscover?: boolean; } /** * 通用事件代理:在 root 上监听冒泡事件,当事件来源匹配 selector 时触发 cb * @returns unsubscribe 函数 */ export declare function delegate(selector: string, eventType: K, cb: DelegateHandler, root?: Element | Document): () => void; declare type DelegateHandler = (e: HTMLElementEventMap[K], target: HTMLElement) => void; /** 销毁内部 Worker,释放资源 */ export declare function destroyPowWorker(): void; /** * 停止并销毁所有内部 MutationObserver(全局 teardown) * 适用于卸载脚本或测试清理 */ export declare function disconnectAll(): void; /** * 自动发现模块 * * 支持两种使用场景: * * 1. 浏览器扩展(Extension) * - 通过 chrome.cookies API 读取 deepseek.com 域的认证 Cookie * - 通过 chrome.webRequest 拦截请求头提取 token,缓存到 chrome.storage * - 通过 chrome.storage 读取扩展自身缓存的 token * * 2. 普通前端/页面注入脚本(同域) * - 直接调用 /api/v0/users/current(fetch 自动携带 Cookie,天然鉴权) * - 从 document.cookie 解析认证字段 * - 从 window 全局变量读取(window.__DS_TOKEN__ 等,如存在) */ export declare interface DiscoveredCredentials { token: string; source: CredentialSource; } /** * 策略1:同域 API 调用(最可靠) * 适用:页面注入脚本、用户脚本、Content Script * fetch 自动携带当前页面 Cookie,无需传 token */ export declare function discoverViaApi(baseUrl?: string): Promise; /** * 策略2:document.cookie 解析 * DeepSeek 可能在 Cookie 中存有 userToken 等认证字段 */ export declare function discoverViaCookie(): DiscoveredCredentials | null; /** * 策略3:chrome.cookies API(扩展专属) * 需要 manifest.json 中声明: * "permissions": ["cookies"] * "host_permissions": ["https://chat.deepseek.com/*"] */ export declare function discoverViaExtensionCookies(url?: string): Promise; /** * 策略4:chrome.storage(扩展自身缓存) * 扩展在拦截到 API 请求头时,可将 token 存入 chrome.storage.local * 之后通过此策略快速读取,无需重复调用 API */ export declare function discoverViaExtensionStorage(): Promise; /** * 策略5:页面全局变量 * 某些页面或注入环境会将 token 挂载到 window 全局对象上 */ export declare function discoverViaPageGlobal(): DiscoveredCredentials | null; export declare interface DoneEvent { type: 'done'; autoResume: boolean; } export declare interface EditMessageParams { chatSessionId: string; messageId: number; prompt: string; searchEnabled?: boolean; thinkingEnabled?: boolean; } /** * 从请求头数组中提取 Bearer token * * 在扩展 Background 的 webRequest.onBeforeSendHeaders 监听器中使用: * @example * ```js * chrome.webRequest.onBeforeSendHeaders.addListener( * (details) => { * const token = extractTokenFromRequestHeaders(details.requestHeaders) * if (token) cacheTokenToExtensionStorage(token) * }, * { urls: ['https://chat.deepseek.com/api/*'] }, * ['requestHeaders'] * ) * ``` */ export declare function extractTokenFromRequestHeaders(headers?: Array<{ name: string; value?: string; }>): string | null; export declare type FeedbackType = 'GOOD' | 'BAD' | null; export declare function fetchHifTokens(): Promise; export declare interface FileAttachInfo { /** 文件名 */ name: string; /** 文件大小/类型描述(如 "TXT 43B") */ meta: string; } export declare type FileStatus = 'PENDING' | 'SUCCESS' | 'FAILED' | 'uploaded' | 'processing' | 'processed' | 'ready' | 'failed'; export declare interface Fragment { id: number; type: FragmentType; content: string | null; references?: unknown[]; stage_id?: number; elapsed_secs?: number | null; status?: string; queries?: SearchQuery[]; results?: SearchResult[]; } export declare type FragmentType = 'REQUEST' | 'RESPONSE' | 'THINKING' | 'THINK' | 'SEARCH'; /** 获取当前激活(高亮)的会话链接元素 */ export declare function getActiveSessionLink(): HTMLAnchorElement | null; /** 获取顶部 chat 导航栏元素(含会话名 + 模式徽章 + 分享按钮) */ export declare function getChatNavbar(): HTMLElement | null; /** 获取顶部右侧分享/导出区域 */ export declare function getChatNavRight(): HTMLElement | null; /** 获取顶部会话标题元素(可编辑) */ export declare function getChatSessionTitle(): HTMLElement | null; /** 获取顶部会话标题文字 */ export declare function getChatSessionTitleText(): string | null; /** 获取页面所有引用角标元素 */ export declare function getCitationMarks(): NodeListOf; /** 获取当前会话 ID(从 URL 提取) */ export declare function getCurrentSessionId(): string | null; /** 获取当前页面所有文件附件信息 */ export declare function getFileAttachments(): FileAttachInfo[]; /** 获取输入框 */ export declare function getInputTextarea(): HTMLTextAreaElement | null; /** 获取 DeepSeek logo SVG 元素 */ export declare function getLogoSvg(): SVGElement | null; /** 获取 logo 的直接父容器 */ export declare function getLogoWrap(): HTMLElement | null; /** 读取当前页面中所有消息气泡(按 DOM 顺序,50ms 内重复调用命中缓存) */ export declare function getMessages(): MessageItem[]; /** 获取当前模式徽章文字(如 "快速模式"、"专家模式") */ export declare function getModeBadgeText(): string | null; /** 获取当前 AI 消息中的联网搜索来源信息(最后一条,或全部) */ export declare function getSearchSourceInfo(): SearchSourceInfo[]; /** 获取所有会话分组标签元素("今天"、"昨天"…) */ export declare function getSessionGroupLabels(): NodeListOf; /** 读取侧边栏会话列表(50ms 内重复调用命中缓存) * @param limit 最多返回条数,默认不限 */ export declare function getSessionList(limit?: number): SessionListItem[]; /** 获取侧边栏顶部区域(含 logo + 折叠按钮) */ export declare function getSidebarHeader(): HTMLElement | null; /** 获取当前主题 */ export declare function getTheme(): 'dark' | 'light' | 'unknown'; /** 获取页面中所有思考块的信息 */ export declare function getThinkingBlocks(): ThinkingBlockInfo[]; /** 获取用户头像首字母元素 */ export declare function getUserAvatar(): HTMLElement | null; /** 获取用户头像首字母文字 */ export declare function getUserAvatarText(): string | null; /** 获取页面显示的当前用户邮箱 */ export declare function getUserEmail(): string | null; declare interface HifTokens { leim?: string; dliq?: string; } export declare interface HistoryMessagesResult { chat_session: ChatSession; chat_messages: ChatMessage[]; cache_control: string; cache_reset_at: number; } /** 当前是否运行在 chat.deepseek.com 同域页面中 */ export declare function isDeepSeekPage(): boolean; /** 当前是否运行在浏览器扩展上下文(Background / Content Script) */ export declare function isExtensionContext(): boolean; /** 获取当前智能搜索是否开启 */ export declare function isSearchEnabled(): boolean; /** 检查指定会话链接是否为当前激活会话 */ export declare function isSessionActive(link: HTMLAnchorElement): boolean; /** 获取当前深度思考是否开启 */ export declare function isThinkingEnabled(): boolean; export declare interface MainSettings { pow_prefetch?: boolean; pow_prefetch_count?: number; completion_request_timeout_ms?: number; search_state_on_launch?: string; sse_auto_resume_timeout?: number; [key: string]: unknown; } export declare interface MessageItem { role: 'user' | 'assistant'; content: string; } export declare type MessageRole = 'USER' | 'ASSISTANT'; export declare type MessageStatus = 'WIP' | 'FINISHED' | 'INCOMPLETE' | 'INTERRUPTED' | 'CONTENT_FILTER'; export declare interface ModelConfig { model_type: ModelType; name: string; input_character_limit: number; think_feature?: Record; search_feature?: Record; file_feature?: { support_file_exts: string[]; max_upload_file_size: number; max_input_file_count: number; }; } export declare type ModelType = 'default' | 'expert' | 'vision'; /** * 监听输入框内容变化 * @param delay 防抖延迟 ms,默认 0(不防抖) * @returns unsubscribe 函数 */ export declare function onInputChange(cb: (value: string) => void, delay?: number): () => void; /** * 监听 AI 回复生成完成(操作按钮栏出现时触发) * @returns unsubscribe 函数 */ export declare function onMessageDone(cb: (el: HTMLElement) => void): () => void; /** * 监听 AI 消息内容流式更新(生成中持续触发,节流 100ms) * @returns unsubscribe 函数 */ export declare function onMessageUpdate(cb: (el: HTMLElement) => void): () => void; /** * 监听「开启新对话」按钮点击 * @returns unsubscribe 函数 */ export declare function onNewChat(cb: () => void): () => void; /** * 监听新消息到来(用户或 AI 任意一条) * @returns unsubscribe 函数 */ export declare function onNewMessage(cb: (msg: { role: 'user' | 'assistant'; el: HTMLElement; }) => void): () => void; /** * 监听发送按钮点击 * @returns unsubscribe 函数 */ export declare function onSendClick(cb: () => void): () => void; /** * 监听会话切换(URL pathname 变化) * @returns unsubscribe 函数 */ export declare function onSessionChange(cb: (sessionId: string | null) => void): () => void; /** * 监听侧边栏会话列表变化(新增/删除/重命名会话) * @returns unsubscribe 函数 */ export declare function onSessionListChange(cb: (sessions: SessionListItem[]) => void): () => void; export declare function parseSSEStream(stream: ReadableStream): AsyncGenerator; /** * 运行时替换某个选择器,用于应对 DeepSeek 版本更新 * @example patchSelector('sendBtn', '._newSendBtn') */ export declare function patchSelector(key: SelectorKey, selector: string): void; export declare interface PowChallenge { algorithm: string; challenge: string; salt: string; signature: string; difficulty: number; expire_at: number; expire_after: number; target_path: string; } /** * 查询单个元素,未找到返回 null */ export declare function query(key: SelectorKey, root?: ParentNode): T | null; /** * 查询所有匹配元素 */ export declare function queryAll(key: SelectorKey, root?: ParentNode): NodeListOf; /** * 用原始选择器字符串查询所有(不经过映射表) */ export declare function queryAllRaw(selector: string, root?: ParentNode): NodeListOf; /** * 用原始选择器字符串查询(不经过映射表) */ export declare function queryRaw(selector: string, root?: ParentNode): T | null; export declare interface ReadyEvent { type: 'ready'; requestMessageId: number; responseMessageId: number; modelType: ModelType; } export declare interface RegenerateParams { chatSessionId: string; childMessageId: number; searchEnabled?: boolean; thinkingEnabled?: boolean; userOptions?: unknown; } export declare interface ResponseDeltaEvent { type: 'response'; content: string; } export declare interface SearchEvent { type: 'search'; queries?: SearchQuery[]; results?: SearchResult[]; status?: string; } export declare interface SearchQuery { query: string; } export declare interface SearchResult { url: string; title: string; snippet: string; cite_index: number; published_at: number; site_icon?: string; site_name?: string; query_indexes?: number[]; } export declare interface SearchSourceInfo { /** 来源图标图片 URL */ iconUrl: string | null; /** 来源数量文字("5 个网页") */ countText: string; } /** * 获取某个语义键对应的 CSS 选择器字符串(优先使用运行时覆盖值) */ export declare function sel(key: SelectorKey): string; /** 切换模式:快速/专家 */ export declare function selectMode(mode: 'default' | 'expert'): boolean; export declare type SelectorKey = keyof typeof CSS_2; export declare interface SendMessageParams { chatSessionId: string; prompt: string; parentMessageId?: number | null; modelType?: ModelType | null; thinkingEnabled?: boolean; searchEnabled?: boolean; refFileIds?: string[]; preempt?: boolean; } export declare interface SessionListCursor { pinned?: boolean; updated_at?: number; } export declare interface SessionListItem { id: string; title: string; href: string; } export declare interface SessionListResult { chat_sessions: ChatSession[]; has_more: boolean; } /** 设置输入框文字(触发 React 合成事件) */ export declare function setInputText(text: string): boolean; /** 切换主题 */ export declare function setTheme(theme: 'dark' | 'light'): void; export declare function solvePow(token: string, targetPath: string, wasmUrl?: string, baseUrl?: string): Promise; export declare interface StatusEvent { type: 'status'; status: MessageStatus; } export declare type StreamEvent = ReadyEvent | ThinkingDeltaEvent | ResponseDeltaEvent | SearchEvent | StatusEvent | TitleEvent | DoneEvent; export declare interface ThinkingBlockInfo { /** 思考时长文字,如 "已思考(用时 3 秒)" */ title: string; /** 思考内容文字 */ content: string; /** 是否已展开 */ isExpanded: boolean; } export declare interface ThinkingDeltaEvent { type: 'thinking'; content: string; elapsedSecs?: number; } export declare interface TitleEvent { type: 'title'; title: string; } export declare type TitleType = 'SYSTEM' | 'USER' | 'WIP'; /** 切换智能搜索按钮(智能搜索 = 第二个 toggle) */ export declare function toggleSearch(enabled?: boolean): boolean; /** 折叠/展开侧边栏 */ export declare function toggleSidebar(): boolean; /** 切换深度思考按钮(深度思考 = 第一个 toggle) */ export declare function toggleThinking(enabled?: boolean): boolean; /** 点击展开/折叠指定思考块(默认第一个) */ export declare function toggleThinkingBlock(index?: number): boolean; export declare interface UploadedFile { id: string; status: FileStatus; file_name: string; from_share?: boolean; file_size: number; model_kind?: string; token_usage: number | null; error_code: string | null; inserted_at?: number; is_image: boolean; audit_result: unknown; signed_path?: string; } export declare interface UploadOptions { thinkingEnabled?: boolean; modelType?: string; } export declare interface UserInfo { id: string; token: string; email: string; mobile_number: string; area_code: string; status: number; } export { }