Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

1.6 KB
Raw Blame
import { cli, Strategy } from '@jackwener/opencli/registry';
import { EmptyResultError } from '@jackwener/opencli/errors';
import {
    DEEPSEEK_DOMAIN,
    MESSAGE_SELECTOR,
    ensureOnDeepSeek,
    getVisibleMessages,
    parseDeepSeekConversationId,
} from './utils.js';

export const detailCommand = cli({
    site: 'deepseek',
    name: 'detail',
    access: 'read',
    description: 'Read a specific DeepSeek conversation by ID',
    domain: DEEPSEEK_DOMAIN,
    strategy: Strategy.COOKIE,
    browser: true,
    siteSession: 'persistent',
    navigateBefore: false,
    args: [
        { name: 'id', required: true, positional: true, help: 'Conversation ID (UUID) or full /a/chat/s/<id> URL' },
    ],
    columns: ['Role', 'Text'],
    func: async (page, kwargs) => {
        const id = parseDeepSeekConversationId(kwargs.id);
        await ensureOnDeepSeek(page);
        await page.goto(`https://chat.deepseek.com/a/chat/s/${id}`);
        // Wait for at least one rendered bubble instead of a fixed 5 s sleep.
        // Empty / invalid conversations fall through to the EmptyResultError
        // below.
        try {
            await page.wait({ selector: MESSAGE_SELECTOR, timeout: 10 });
        } catch {
            // No bubble mounted within 10 s; treated as empty by the check below.
        }
        const messages = await getVisibleMessages(page);
        if (messages.length === 0) {
            throw new EmptyResultError(
                'deepseek detail',
                `No visible messages found for conversation ${id}. Verify the ID is correct and that you are logged in.`,
            );
        }
        return messages;
    },
});