好的,我最终复用了目前可用(但在我们的社区中未使用)且已随 Discourse 一起发布的辅助功能。
| 位置 | 设置 | 设置为 | 重命中标签(自定义 → 文本) |
|---|---|---|---|
| Ask AI(帖子/主题) | ai_helper_translator_agent | 自定义搜索代理 | discourse_ai.ai_helper.prompts.translate → 自定义搜索标签 |
| 编辑器翻译 | ai_helper_markdown_tables_agent | 内置翻译代理 | discourse_ai.ai_helper.prompts.markdown_table → 翻译 |
| 编辑器 Markdown 格式化器 | ai_helper_smart_dates_agent | Markdown 格式化代理(已移动) | discourse_ai.ai_helper.prompts.replace_dates → 格式化为 Markdown |
然后是两段代码片段:
javascripts/discourse/api-initializers/ai-helper-slots.gjs
import { apiInitializer } from "discourse/lib/api";
const AI_HELPER_ICONS = {
translate: "ph-dt-magnifying-glass", // 用于论坛搜索代理
markdown_table: "ph-dt-translate", // 编辑器:内置翻译
replace_dates: "ph-dt-markdown", // 编辑器:Markdown 格式化
};
export default apiInitializer((api) => {
api.getCurrentUser()?.ai_helper_prompts?.forEach((prompt) => {
prompt.icon = AI_HELPER_ICONS[prompt.name] ?? prompt.icon;
});
});
common.scss
.ai-composer-helper-menu ul.ai-helper-options li[data-value="translate"] {
display: none;
}
注意,我正在使用自定义 Phosphor 图标集;新图标可以打包到 Font Awesome、Material 或任何其他图标集中。