Skip to content

feat(ai): add manual generation and reconcile endpoints #2758

Description

@poboll

背景

在 Core v10/v13 的 AI 模块里,后台已经有摘要、精读、翻译、翻译词表等能力,但这些能力主要依赖正常的内容创建/更新事件触发。

如果内容是通过数据库迁移、脚本导入、直接 SQL/ORM 写入等方式进入数据库,正常 domain event 会被绕过,导致:

  • 搜索索引没有对应文档,文章在搜索或后台检索中不可见;
  • AI 摘要、精读、翻译不会自动入队;
  • 现有按 AI 记录分组的列表接口只能看到“已经生成过 AI 记录”的文章,无法列出完全没有 AI 记录的孤儿文章;
  • 翻译词表原本只从最近的手记采集 mood/weather,历史手记里的词条可能无法被补齐。

这会让迁移或数据库直写后的恢复流程比较困难。

建议方案

我这边已经在 fork 上实现了一个比较小的后端补充方案,主要思路是:

  1. 不把“孤儿文章”塞进原有 grouped/list 接口,而是为 AI 模块增加 candidates 接口。这样后台前端可以列出所有可处理文章/字段,包括还没有任何 AI 记录的对象。
  2. 复用已有搜索重建能力,不在 AI 模块重复实现搜索孤儿修复逻辑。
  3. 新增一个 POST /ai/reconcile 作为数据库直写/迁移后的恢复入口,默认只重建搜索索引;只有显式传入 features 时才会触发昂贵的 AI 补偿任务。
  4. 为摘要、精读、翻译、翻译词表统一支持手动全量/批量补做,必要时支持 force 重做。

已实现分支

Compare:
master...poboll:codex/ai-manual-actions

Fork branch:
https://github.com/poboll/mxspace-c/tree/codex/ai-manual-actions

包含两个提交:

  • feat(ai): add manual summary and insights tasks
  • feat(ai): add reconcile and translation candidates

主要接口变化

  • Summary

    • POST /ai/summaries/task/batch
    • POST /ai/summaries/task/all
    • GET /ai/summaries/candidates
  • Insights

    • POST /ai/insights/task/batch
    • POST /ai/insights/task/all
    • GET /ai/insights/candidates
  • Translation

    • POST /ai/translations/task/batch
    • POST /ai/translations/task/all
    • GET /ai/translations/candidates
    • force support for manual regeneration
  • Translation entries

    • GET /ai/translations/entries/candidates
    • POST /ai/translations/entries/generate supports force
    • note mood/weather collection now scans all visible notes instead of only recent notes
  • Reconcile

    • POST /ai/reconcile
    • default: rebuild search documents only
    • optional features: summary, insights, translation, translation-entries
    • optional force, targetLanguages, translationEntryKeyPaths

验证

已在 fork 分支本地通过:

pnpm -C apps/core exec vitest run test/src/modules/ai/ai.controller.faux.e2e.spec.ts test/src/modules/ai/ai-translation.service.spec.ts test/src/modules/ai/translation-entry.service.spec.ts test/src/modules/ai/ai-summary.service.spec.ts test/src/modules/ai/ai-insights.service.spec.ts test/src/modules/ai/ai-public-sse-controllers.spec.ts
pnpm -C apps/core run typecheck

备注

我尝试创建 Pull Request 时 GitHub 返回权限错误:

GraphQL: poboll does not have the correct permissions to execute `CreatePullRequest` (createPullRequest)

所以先把实现分支和 compare 链接放在 issue 里,方便维护者确认方案或直接拉取分支。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions