koishi-plugin-isthattrue 0.1.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -0
- package/lib/agents/index.d.ts +3 -0
- package/lib/agents/mainAgent.d.ts +30 -0
- package/lib/agents/searchAgent.d.ts +53 -0
- package/lib/agents/subSearchAgent.d.ts +21 -0
- package/lib/agents/verifyAgent.d.ts +37 -0
- package/lib/config.d.ts +45 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +1393 -0
- package/lib/services/anspire.d.ts +30 -0
- package/lib/services/chatluna.d.ts +48 -0
- package/lib/services/chatlunaSearch.d.ts +38 -0
- package/lib/services/grok.d.ts +32 -0
- package/lib/services/kimi.d.ts +22 -0
- package/lib/services/messageParser.d.ts +38 -0
- package/lib/services/tavily.d.ts +30 -0
- package/lib/services/zhipu.d.ts +22 -0
- package/lib/types.d.ts +98 -0
- package/lib/utils/prompts.d.ts +75 -0
- package/lib/utils/url.d.ts +11 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# koishi-plugin-isthattrue
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/koishi-plugin-isthattrue)
|
|
4
|
+
|
|
5
|
+
事实核查插件 - 使用多 Agent LLM 架构验证消息真实性
|
|
6
|
+
|
|
7
|
+
## 功能特点
|
|
8
|
+
|
|
9
|
+
- 多 Agent 协作:主控 Agent 编排任务,子搜索 Agent 并行检索
|
|
10
|
+
- 多搜索源支持:Tavily、Anspire、Kimi、智谱、Chatluna Search
|
|
11
|
+
- 支持文本和图片内容(OCR 识别)
|
|
12
|
+
- 可引用消息进行核查
|
|
13
|
+
- 输出判定结果:TRUE / FALSE / PARTIALLY_TRUE / UNCERTAIN
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install koishi-plugin-isthattrue
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 依赖
|
|
22
|
+
|
|
23
|
+
- [koishi-plugin-chatluna](https://github.com/ChatLunaLab/chatluna) - LLM 服务接入
|
|
24
|
+
|
|
25
|
+
## 使用方法
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
tof [内容] # 核查指定内容
|
|
29
|
+
tof # 引用一条消息后使用,核查被引用的消息
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
别名:`鉴定`、`核查`
|
|
33
|
+
|
|
34
|
+
## 配置说明
|
|
35
|
+
|
|
36
|
+
### 模型配置
|
|
37
|
+
|
|
38
|
+
| 配置项 | 说明 | 推荐 |
|
|
39
|
+
|--------|------|------|
|
|
40
|
+
| mainModel | 主控 Agent 模型,用于编排和最终判决 | Gemini-3-Flash |
|
|
41
|
+
| subSearchModel | 子搜索 Agent 模型,用于深度搜索 | Grok-4-1 |
|
|
42
|
+
|
|
43
|
+
### 搜索 API 配置
|
|
44
|
+
|
|
45
|
+
| 配置项 | 说明 |
|
|
46
|
+
|--------|------|
|
|
47
|
+
| tavilyApiKey | Tavily API Key(可选) |
|
|
48
|
+
| anspireApiKey | Anspire API Key(可选) |
|
|
49
|
+
| kimiApiKey | Kimi API Key(可选) |
|
|
50
|
+
| zhipuApiKey | 智谱 API Key(可选) |
|
|
51
|
+
| chatlunaSearchModel | Chatluna Search 使用的模型 |
|
|
52
|
+
| enableChatlunaSearch | 启用 Chatluna 搜索集成 |
|
|
53
|
+
| chatlunaSearchDiversifyModel | 搜索关键词多样化模型 |
|
|
54
|
+
|
|
55
|
+
### Agent 配置
|
|
56
|
+
|
|
57
|
+
| 配置项 | 默认值 | 说明 |
|
|
58
|
+
|--------|--------|------|
|
|
59
|
+
| timeout | 60000 | 单次请求超时时间(毫秒) |
|
|
60
|
+
| maxRetries | 2 | 失败重试次数 |
|
|
61
|
+
|
|
62
|
+
### 其他设置
|
|
63
|
+
|
|
64
|
+
| 配置项 | 默认值 | 说明 |
|
|
65
|
+
|--------|--------|------|
|
|
66
|
+
| verbose | false | 显示详细验证过程 |
|
|
67
|
+
| outputFormat | auto | 输出格式(auto/markdown/plain) |
|
|
68
|
+
| useForwardMessage | true | 使用合并转发消息展示详情(仅 QQ) |
|
|
69
|
+
| bypassProxy | false | 绕过系统代理 |
|
|
70
|
+
| logLLMDetails | false | 打印 LLM 请求详情(调试用) |
|
|
71
|
+
|
|
72
|
+
## 工作流程
|
|
73
|
+
|
|
74
|
+
1. 用户发送 `tof` 命令(可引用消息或直接输入内容)
|
|
75
|
+
2. MessageParser 提取文本和图片,如有图片则进行 OCR
|
|
76
|
+
3. 主控 Agent 分析内容,生成搜索计划
|
|
77
|
+
4. 子搜索 Agent 并行执行多源搜索
|
|
78
|
+
5. 主控 Agent 综合搜索结果,输出最终判定
|
|
79
|
+
|
|
80
|
+
## 架构
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
src/
|
|
84
|
+
├── index.ts # 插件入口,注册 tof 命令
|
|
85
|
+
├── config.ts # 配置 Schema
|
|
86
|
+
├── types.ts # TypeScript 类型定义
|
|
87
|
+
├── agents/
|
|
88
|
+
│ ├── mainAgent.ts # 主控 Agent(编排 + 判决)
|
|
89
|
+
│ └── subSearchAgent.ts # 子搜索 Agent(多源检索)
|
|
90
|
+
├── services/
|
|
91
|
+
│ ├── chatluna.ts # Chatluna LLM 适配器
|
|
92
|
+
│ ├── chatlunaSearch.ts # Chatluna Search 集成
|
|
93
|
+
│ ├── messageParser.ts # 消息解析(文本/图片)
|
|
94
|
+
│ ├── tavily.ts # Tavily 搜索
|
|
95
|
+
│ ├── anspire.ts # Anspire 搜索
|
|
96
|
+
│ ├── kimi.ts # Kimi 搜索
|
|
97
|
+
│ └── zhipu.ts # 智谱搜索
|
|
98
|
+
└── utils/
|
|
99
|
+
└── prompts.ts # LLM Prompt 模板
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { Config } from '../config';
|
|
3
|
+
import { VerificationResult, MessageContent } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* 主控 Agent
|
|
6
|
+
* 流程:并行搜索 (Chatluna + Grok) -> URL处理 -> Gemini判决
|
|
7
|
+
*/
|
|
8
|
+
export declare class MainAgent {
|
|
9
|
+
private ctx;
|
|
10
|
+
private config;
|
|
11
|
+
private subSearchAgent;
|
|
12
|
+
private chatlunaSearchAgent;
|
|
13
|
+
private verifyAgent;
|
|
14
|
+
private chatluna;
|
|
15
|
+
private messageParser;
|
|
16
|
+
private logger;
|
|
17
|
+
constructor(ctx: Context, config: Config);
|
|
18
|
+
/**
|
|
19
|
+
* 执行完整的核查流程
|
|
20
|
+
*/
|
|
21
|
+
verify(content: MessageContent): Promise<VerificationResult>;
|
|
22
|
+
/**
|
|
23
|
+
* 带超时的 Promise 包装
|
|
24
|
+
*/
|
|
25
|
+
private withTimeout;
|
|
26
|
+
/**
|
|
27
|
+
* 从图片中提取描述(用于纯图片输入场景)
|
|
28
|
+
*/
|
|
29
|
+
private extractImageDescription;
|
|
30
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { Config } from '../config';
|
|
3
|
+
import { SearchResult } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* 搜索Agent
|
|
6
|
+
* 负责从特定角度搜索和收集信息
|
|
7
|
+
*/
|
|
8
|
+
export declare class SearchAgent {
|
|
9
|
+
private ctx;
|
|
10
|
+
private config;
|
|
11
|
+
private id;
|
|
12
|
+
private perspective;
|
|
13
|
+
private model;
|
|
14
|
+
private chatluna;
|
|
15
|
+
constructor(ctx: Context, config: Config, agentIndex: number, model: string);
|
|
16
|
+
/**
|
|
17
|
+
* 执行搜索
|
|
18
|
+
*/
|
|
19
|
+
search(content: string): Promise<SearchResult>;
|
|
20
|
+
/**
|
|
21
|
+
* 解析Agent响应的JSON
|
|
22
|
+
*/
|
|
23
|
+
private parseResponse;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 搜索Agent管理器
|
|
27
|
+
* 负责创建和协调多个搜索Agent
|
|
28
|
+
*/
|
|
29
|
+
export declare class SearchAgentManager {
|
|
30
|
+
private ctx;
|
|
31
|
+
private config;
|
|
32
|
+
private agents;
|
|
33
|
+
private tavilyAgent;
|
|
34
|
+
private anspireAgent;
|
|
35
|
+
private kimiAgent;
|
|
36
|
+
private zhipuAgent;
|
|
37
|
+
private chatlunaSearchAgent;
|
|
38
|
+
private logger;
|
|
39
|
+
constructor(ctx: Context, config: Config);
|
|
40
|
+
private initAgents;
|
|
41
|
+
/**
|
|
42
|
+
* 并行执行所有Agent的搜索
|
|
43
|
+
*/
|
|
44
|
+
searchAll(content: string): Promise<SearchResult[]>;
|
|
45
|
+
/**
|
|
46
|
+
* 带超时的Promise包装 (LLM Agent)
|
|
47
|
+
*/
|
|
48
|
+
private withTimeout;
|
|
49
|
+
/**
|
|
50
|
+
* 带超时的Promise包装 (通用)
|
|
51
|
+
*/
|
|
52
|
+
private withTimeoutGeneric;
|
|
53
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { Config } from '../config';
|
|
3
|
+
import { SearchResult } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* 子搜索 Agent
|
|
6
|
+
* 专门负责深度搜索(主要使用 Grok,擅长 X/Twitter 搜索)
|
|
7
|
+
* 独立搜索,不依赖其他搜索结果
|
|
8
|
+
*/
|
|
9
|
+
export declare class SubSearchAgent {
|
|
10
|
+
private ctx;
|
|
11
|
+
private config;
|
|
12
|
+
private chatluna;
|
|
13
|
+
private logger;
|
|
14
|
+
constructor(ctx: Context, config: Config);
|
|
15
|
+
/**
|
|
16
|
+
* 执行深度搜索
|
|
17
|
+
* @param claim 原始声明文本
|
|
18
|
+
*/
|
|
19
|
+
deepSearch(claim: string): Promise<SearchResult>;
|
|
20
|
+
private parseResponse;
|
|
21
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { Config } from '../config';
|
|
3
|
+
import { SearchResult, VerificationResult, MessageContent } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* 验证Agent
|
|
6
|
+
* 负责综合搜索结果并做出最终判决
|
|
7
|
+
*/
|
|
8
|
+
export declare class VerifyAgent {
|
|
9
|
+
private ctx;
|
|
10
|
+
private config;
|
|
11
|
+
private chatluna;
|
|
12
|
+
private logger;
|
|
13
|
+
constructor(ctx: Context, config: Config);
|
|
14
|
+
/**
|
|
15
|
+
* 执行验证判决
|
|
16
|
+
* @param originalContent 原始消息内容
|
|
17
|
+
* @param searchResults 搜索结果
|
|
18
|
+
* @param images 可选的图片 base64 列表(多模态验证)
|
|
19
|
+
*/
|
|
20
|
+
verify(originalContent: MessageContent, searchResults: SearchResult[], images?: string[]): Promise<VerificationResult>;
|
|
21
|
+
/**
|
|
22
|
+
* 解析验证响应
|
|
23
|
+
*/
|
|
24
|
+
private parseVerifyResponse;
|
|
25
|
+
/**
|
|
26
|
+
* 标准化判决结果
|
|
27
|
+
*/
|
|
28
|
+
private normalizeVerdict;
|
|
29
|
+
/**
|
|
30
|
+
* 从文本中提取判决
|
|
31
|
+
*/
|
|
32
|
+
private extractVerdictFromText;
|
|
33
|
+
/**
|
|
34
|
+
* 汇总所有来源
|
|
35
|
+
*/
|
|
36
|
+
private aggregateSources;
|
|
37
|
+
}
|
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Schema } from 'koishi';
|
|
2
|
+
/**
|
|
3
|
+
* 插件配置 Schema
|
|
4
|
+
*/
|
|
5
|
+
export interface Config {
|
|
6
|
+
/** 主控 Agent 模型 - 用于最终判决 (推荐 Gemini-3-Flash) */
|
|
7
|
+
mainModel: string;
|
|
8
|
+
/** 子搜索 Agent 模型 - 用于深度搜索 (推荐 Grok) */
|
|
9
|
+
subSearchModel: string;
|
|
10
|
+
/** Tavily API Key */
|
|
11
|
+
tavilyApiKey: string;
|
|
12
|
+
/** Anspire API Key */
|
|
13
|
+
anspireApiKey: string;
|
|
14
|
+
/** Kimi API Key */
|
|
15
|
+
kimiApiKey: string;
|
|
16
|
+
/** 智谱 API Key */
|
|
17
|
+
zhipuApiKey: string;
|
|
18
|
+
/** Chatluna Search 使用的模型 */
|
|
19
|
+
chatlunaSearchModel: string;
|
|
20
|
+
/** 启用 Chatluna 搜索集成 */
|
|
21
|
+
enableChatlunaSearch: boolean;
|
|
22
|
+
/** 搜索关键词多样化模型 */
|
|
23
|
+
chatlunaSearchDiversifyModel: string;
|
|
24
|
+
/** 超时时间(毫秒) */
|
|
25
|
+
timeout: number;
|
|
26
|
+
/** 最大重试次数 */
|
|
27
|
+
maxRetries: number;
|
|
28
|
+
/** 是否显示详细过程 */
|
|
29
|
+
verbose: boolean;
|
|
30
|
+
/** 输出格式 */
|
|
31
|
+
outputFormat: 'auto' | 'markdown' | 'plain';
|
|
32
|
+
/** 是否使用合并转发消息 */
|
|
33
|
+
useForwardMessage: boolean;
|
|
34
|
+
/** 合并转发最大节点数,超过则回退普通消息 */
|
|
35
|
+
forwardMaxNodes: number;
|
|
36
|
+
/** 合并转发总字符数上限,超过则回退普通消息 */
|
|
37
|
+
forwardMaxTotalChars: number;
|
|
38
|
+
/** 合并转发单节点字符数上限 */
|
|
39
|
+
forwardMaxSegmentChars: number;
|
|
40
|
+
/** 是否绕过代理 */
|
|
41
|
+
bypassProxy: boolean;
|
|
42
|
+
/** 是否打印 LLM 请求体和响应 */
|
|
43
|
+
logLLMDetails: boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare const Config: Schema<Config>;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Context } from 'koishi';
|
|
2
|
+
import { Config } from './config';
|
|
3
|
+
export declare const name = "isthattrue";
|
|
4
|
+
export declare const inject: string[];
|
|
5
|
+
export declare const usage = "\n## \u4E8B\u5B9E\u6838\u67E5\u63D2\u4EF6\n\n\u4F7F\u7528\u591AAgent\u67B6\u6784\u5BF9\u6D88\u606F\u8FDB\u884C\u4E8B\u5B9E\u6838\u67E5\u9A8C\u8BC1\u3002\n\n### \u4F7F\u7528\u65B9\u6CD5\n\n1. \u5F15\u7528\u4E00\u6761\u9700\u8981\u9A8C\u8BC1\u7684\u6D88\u606F\n2. \u53D1\u9001 `tof` \u6307\u4EE4\n3. \u7B49\u5F85\u9A8C\u8BC1\u7ED3\u679C\n\n### \u5DE5\u4F5C\u6D41\u7A0B\n\n1. **\u89E3\u6790\u9636\u6BB5**: \u63D0\u53D6\u5F15\u7528\u6D88\u606F\u4E2D\u7684\u6587\u672C\u548C\u56FE\u7247\n2. **\u641C\u7D22\u9636\u6BB5**: \u591A\u4E2AAgent\u5E76\u884C\u4ECE\u4E0D\u540C\u89D2\u5EA6\u641C\u7D22\u4FE1\u606F\n3. **\u9A8C\u8BC1\u9636\u6BB5**: \u7EFC\u5408\u641C\u7D22\u7ED3\u679C\uFF0C\u7531\u4F4E\u5E7B\u89C9\u7387LLM\u505A\u51FA\u5224\u51B3\n\n### \u5224\u51B3\u7C7B\u522B\n\n- \u2705 **\u771F\u5B9E**: \u6709\u5145\u5206\u53EF\u9760\u8BC1\u636E\u652F\u6301\n- \u274C **\u865A\u5047**: \u6709\u5145\u5206\u53EF\u9760\u8BC1\u636E\u53CD\u9A73\n- \u26A0\uFE0F **\u90E8\u5206\u771F\u5B9E**: \u58F0\u660E\u4E2D\u90E8\u5206\u5185\u5BB9\u5C5E\u5B9E\n- \u2753 **\u65E0\u6CD5\u786E\u5B9A**: \u8BC1\u636E\u4E0D\u8DB3\u6216\u76F8\u4E92\u77DB\u76FE\n";
|
|
6
|
+
export { Config } from './config';
|
|
7
|
+
export declare function apply(ctx: Context, config: Config): void;
|