@zhin.js/adapter-napcat 0.1.13 → 0.1.14
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/CHANGELOG.md +13 -0
- package/README.md +121 -0
- package/client/NapCatManagement.tsx +113 -0
- package/client/index.tsx +11 -0
- package/client/tsconfig.json +7 -0
- package/client/utils/api.ts +30 -0
- package/dist/index.js +27 -0
- package/lib/agent-prompt.d.ts +3 -0
- package/lib/agent-prompt.d.ts.map +1 -0
- package/lib/agent-prompt.js +107 -0
- package/lib/agent-prompt.js.map +1 -0
- package/lib/bot-base.d.ts +6 -1
- package/lib/bot-base.d.ts.map +1 -1
- package/lib/bot-base.js +35 -1
- package/lib/bot-base.js.map +1 -1
- package/lib/bot-http.d.ts +1 -0
- package/lib/bot-http.d.ts.map +1 -1
- package/lib/bot-http.js +22 -0
- package/lib/bot-http.js.map +1 -1
- package/lib/bot-ws-client.d.ts +2 -0
- package/lib/bot-ws-client.d.ts.map +1 -1
- package/lib/bot-ws-client.js +32 -0
- package/lib/bot-ws-client.js.map +1 -1
- package/lib/bot-ws-server.d.ts +1 -0
- package/lib/bot-ws-server.d.ts.map +1 -1
- package/lib/bot-ws-server.js +14 -0
- package/lib/bot-ws-server.js.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +22 -1
- package/lib/index.js.map +1 -1
- package/lib/napcat-inbound.d.ts +21 -0
- package/lib/napcat-inbound.d.ts.map +1 -0
- package/lib/napcat-inbound.js +55 -0
- package/lib/napcat-inbound.js.map +1 -0
- package/lib/onebot-get-msg.d.ts +3 -0
- package/lib/onebot-get-msg.d.ts.map +1 -0
- package/lib/onebot-get-msg.js +27 -0
- package/lib/onebot-get-msg.js.map +1 -0
- package/lib/routes.d.ts +4 -0
- package/lib/routes.d.ts.map +1 -0
- package/lib/routes.js +61 -0
- package/lib/routes.js.map +1 -0
- package/lib/types.d.ts +18 -0
- package/lib/types.d.ts.map +1 -1
- package/lib/typing-indicator.d.ts +46 -0
- package/lib/typing-indicator.d.ts.map +1 -0
- package/lib/typing-indicator.js +138 -0
- package/lib/typing-indicator.js.map +1 -0
- package/package.json +19 -5
- package/plugin.yml +1 -1
- package/src/agent-prompt.ts +115 -0
- package/src/bot-base.ts +36 -1
- package/src/bot-http.ts +18 -0
- package/src/bot-ws-client.ts +34 -0
- package/src/bot-ws-server.ts +15 -0
- package/src/index.ts +41 -2
- package/src/napcat-inbound.ts +57 -0
- package/src/onebot-get-msg.ts +33 -0
- package/src/routes.ts +61 -0
- package/src/types.ts +13 -0
- package/src/typing-indicator.ts +196 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onebot-get-msg.js","sourceRoot":"","sources":["../src/onebot-get-msg.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,yBAAyB,CACvC,SAAiB,EACjB,IAAa;IAEb,MAAM,MAAM,GACV,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAE,IAAgC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5E,IAAI,OAAO,GAAoC,EAAE,CAAC;IAClD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,GAAG,MAAM,CAAC,OAA2B,CAAC;IAC/C,CAAC;SAAM,IAAI,OAAO,MAAM,CAAC,WAAW,KAAK,QAAQ,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACxE,OAAO,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;IAChC,IAAI,MAAsC,CAAC;IAC3C,IAAI,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAC/C,MAAM,CAAC,GAAG,SAAoC,CAAC;QAC/C,MAAM,GAAG;YACP,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC;YAC3B,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;SACzC,CAAC;IACJ,CAAC;IAED,OAAO;QACL,SAAS;QACT,MAAM;QACN,OAAO;QACP,GAAG,EAAE,OAAO,MAAM,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;QAC5E,IAAI,EAAE,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;KAChE,CAAC;AACJ,CAAC"}
|
package/lib/routes.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,IAAI,CAyD1E"}
|
package/lib/routes.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export function registerRoutes(router, napcat) {
|
|
2
|
+
router.get('/api/napcat/bots', async (ctx) => {
|
|
3
|
+
try {
|
|
4
|
+
const bots = Array.from(napcat.bots.values());
|
|
5
|
+
if (bots.length === 0) {
|
|
6
|
+
ctx.body = { success: true, data: [], message: '暂无 NapCat 机器人实例' };
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const result = await Promise.all(bots.map(async (bot) => {
|
|
10
|
+
try {
|
|
11
|
+
const connection = bot.$config.connection ?? 'ws';
|
|
12
|
+
const base = {
|
|
13
|
+
name: bot.$config.name,
|
|
14
|
+
connected: bot.$connected || false,
|
|
15
|
+
connection,
|
|
16
|
+
status: bot.$connected ? 'online' : 'offline',
|
|
17
|
+
lastActivity: new Date().toISOString(),
|
|
18
|
+
};
|
|
19
|
+
if (bot.$connected) {
|
|
20
|
+
try {
|
|
21
|
+
const friends = await bot.getFriendList();
|
|
22
|
+
const groups = await bot.getGroupList();
|
|
23
|
+
base.friendCount = Array.isArray(friends) ? friends.length : 0;
|
|
24
|
+
base.groupCount = Array.isArray(groups) ? groups.length : 0;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
base.friendCount = 0;
|
|
28
|
+
base.groupCount = 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
base.friendCount = 0;
|
|
33
|
+
base.groupCount = 0;
|
|
34
|
+
}
|
|
35
|
+
return base;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return {
|
|
39
|
+
name: bot.$config.name,
|
|
40
|
+
connected: false,
|
|
41
|
+
connection: 'unknown',
|
|
42
|
+
status: 'error',
|
|
43
|
+
friendCount: 0,
|
|
44
|
+
groupCount: 0,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
ctx.body = { success: true, data: result, timestamp: new Date().toISOString() };
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
ctx.status = 500;
|
|
52
|
+
ctx.body = {
|
|
53
|
+
success: false,
|
|
54
|
+
error: 'NAPCAT_API_ERROR',
|
|
55
|
+
message: '获取机器人数据失败',
|
|
56
|
+
details: process.env.NODE_ENV === 'development' ? error.message : undefined,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,c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2,28 @@
|
|
|
2
2
|
* NapCat 适配器类型定义
|
|
3
3
|
* 覆盖 OneBot11 标准 + go-cqhttp 扩展 + NapCat 独有 API
|
|
4
4
|
*/
|
|
5
|
+
export interface TypingIndicatorConfig {
|
|
6
|
+
/** 是否启用(默认 true) */
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
/** 默认表情 ID */
|
|
9
|
+
defaultEmoji?: string;
|
|
10
|
+
/** 私聊配置 */
|
|
11
|
+
privateConfig?: {
|
|
12
|
+
type?: 'message' | 'typing';
|
|
13
|
+
message?: string;
|
|
14
|
+
};
|
|
15
|
+
/** 群聊配置 */
|
|
16
|
+
groupConfig?: {
|
|
17
|
+
type?: 'reaction';
|
|
18
|
+
emoji?: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
5
21
|
export interface NapCatConfigBase {
|
|
6
22
|
context: 'napcat';
|
|
7
23
|
name: string;
|
|
8
24
|
access_token?: string;
|
|
25
|
+
/** Typing Indicator 配置 */
|
|
26
|
+
typingIndicator?: TypingIndicatorConfig;
|
|
9
27
|
}
|
|
10
28
|
/** 正向 WebSocket */
|
|
11
29
|
export interface NapCatWsClientConfig extends NapCatConfigBase {
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,QAAQ,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,qBAAqB;IACpC,oBAAoB;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW;IACX,aAAa,CAAC,EA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,CAAC;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC;CAC1F;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NapCat Typing Indicator 集成
|
|
3
|
+
*
|
|
4
|
+
* 群聊:set_msg_emoji_like(表情回应)
|
|
5
|
+
* 私聊:set_input_status(输入状态)或短暂提示消息
|
|
6
|
+
*/
|
|
7
|
+
import type { NapCatBotBase } from './bot-base.js';
|
|
8
|
+
import { type TypingIndicatorConfig, type TypingIndicator } from '@zhin.js/agent';
|
|
9
|
+
export interface NapCatTypingIndicatorConfig {
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
defaultEmoji: string;
|
|
12
|
+
autoRemove: boolean;
|
|
13
|
+
removeDelay: number;
|
|
14
|
+
privateConfig?: Partial<TypingIndicatorConfig>;
|
|
15
|
+
groupConfig?: Partial<TypingIndicatorConfig>;
|
|
16
|
+
}
|
|
17
|
+
export declare class NapCatTypingIndicatorManager {
|
|
18
|
+
private manager;
|
|
19
|
+
private config;
|
|
20
|
+
private bot;
|
|
21
|
+
private currentOptions?;
|
|
22
|
+
constructor(bot: NapCatBotBase, config?: Partial<NapCatTypingIndicatorConfig>);
|
|
23
|
+
private registerAdapter;
|
|
24
|
+
start(options: {
|
|
25
|
+
messageId?: string;
|
|
26
|
+
sessionId: string;
|
|
27
|
+
userId?: string;
|
|
28
|
+
groupId?: string;
|
|
29
|
+
sceneType: 'private' | 'group';
|
|
30
|
+
}): Promise<TypingIndicator>;
|
|
31
|
+
stop(options: {
|
|
32
|
+
sessionId: string;
|
|
33
|
+
userId?: string;
|
|
34
|
+
groupId?: string;
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
stopAll(): Promise<void>;
|
|
37
|
+
updateConfig(config: Partial<NapCatTypingIndicatorConfig>): void;
|
|
38
|
+
getConfig(): NapCatTypingIndicatorConfig;
|
|
39
|
+
}
|
|
40
|
+
declare module './bot-base.js' {
|
|
41
|
+
interface NapCatBotBase {
|
|
42
|
+
$typingIndicator?: NapCatTypingIndicatorManager;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export declare function enableTypingIndicator(bot: NapCatBotBase, config?: Partial<NapCatTypingIndicatorConfig>): NapCatTypingIndicatorManager;
|
|
46
|
+
//# sourceMappingURL=typing-indicator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typing-indicator.d.ts","sourceRoot":"","sources":["../src/typing-indicator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAIL,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAExB,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa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|
+
*
|
|
4
|
+
* 群聊:set_msg_emoji_like(表情回应)
|
|
5
|
+
* 私聊:set_input_status(输入状态)或短暂提示消息
|
|
6
|
+
*/
|
|
7
|
+
import { TypingIndicatorManager, ReactionTypingIndicatorAdapter, } from '@zhin.js/agent';
|
|
8
|
+
const DEFAULT_CONFIG = {
|
|
9
|
+
enabled: true,
|
|
10
|
+
defaultEmoji: '128516',
|
|
11
|
+
autoRemove: true,
|
|
12
|
+
removeDelay: 5000,
|
|
13
|
+
privateConfig: {
|
|
14
|
+
type: 'message',
|
|
15
|
+
message: '正在思考中...',
|
|
16
|
+
autoRemove: true,
|
|
17
|
+
removeDelay: 3000,
|
|
18
|
+
},
|
|
19
|
+
groupConfig: {
|
|
20
|
+
type: 'reaction',
|
|
21
|
+
emoji: '128516',
|
|
22
|
+
autoRemove: true,
|
|
23
|
+
removeDelay: 5000,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export class NapCatTypingIndicatorManager {
|
|
27
|
+
manager;
|
|
28
|
+
config;
|
|
29
|
+
bot;
|
|
30
|
+
currentOptions;
|
|
31
|
+
constructor(bot, config = {}) {
|
|
32
|
+
this.bot = bot;
|
|
33
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
34
|
+
this.manager = new TypingIndicatorManager({
|
|
35
|
+
type: 'reaction',
|
|
36
|
+
emoji: this.config.defaultEmoji,
|
|
37
|
+
autoRemove: this.config.autoRemove,
|
|
38
|
+
removeDelay: this.config.removeDelay,
|
|
39
|
+
});
|
|
40
|
+
this.registerAdapter();
|
|
41
|
+
}
|
|
42
|
+
registerAdapter() {
|
|
43
|
+
const adapter = new ReactionTypingIndicatorAdapter(async (messageId, emoji) => {
|
|
44
|
+
return await this.bot.$addReaction(messageId, emoji);
|
|
45
|
+
}, async (messageId, reactionId) => {
|
|
46
|
+
await this.bot.$removeReaction(messageId, reactionId);
|
|
47
|
+
}, async (sessionId, content) => {
|
|
48
|
+
try {
|
|
49
|
+
const options = this.currentOptions;
|
|
50
|
+
if (!options)
|
|
51
|
+
return null;
|
|
52
|
+
if (options.sceneType === 'group' && options.groupId) {
|
|
53
|
+
return await this.bot.$sendMessage({
|
|
54
|
+
type: 'group',
|
|
55
|
+
id: options.groupId,
|
|
56
|
+
context: 'napcat',
|
|
57
|
+
bot: this.bot.$id,
|
|
58
|
+
content: [{ type: 'text', data: { text: content } }],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else if (options.userId) {
|
|
62
|
+
return await this.bot.$sendMessage({
|
|
63
|
+
type: 'private',
|
|
64
|
+
id: options.userId,
|
|
65
|
+
context: 'napcat',
|
|
66
|
+
bot: this.bot.$id,
|
|
67
|
+
content: [{ type: 'text', data: { text: content } }],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}, async (messageId) => {
|
|
76
|
+
try {
|
|
77
|
+
await this.bot.$recallMessage(messageId);
|
|
78
|
+
}
|
|
79
|
+
catch { /* ignore */ }
|
|
80
|
+
});
|
|
81
|
+
this.manager.registerAdapter(adapter);
|
|
82
|
+
}
|
|
83
|
+
async start(options) {
|
|
84
|
+
this.bot.logger.debug('[NapCat:TypingIndicator] start called', {
|
|
85
|
+
enabled: this.config.enabled,
|
|
86
|
+
sceneType: options.sceneType,
|
|
87
|
+
});
|
|
88
|
+
if (!this.config.enabled) {
|
|
89
|
+
return {
|
|
90
|
+
start: async () => { },
|
|
91
|
+
stop: async () => { },
|
|
92
|
+
isActive: () => false,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
this.currentOptions = options;
|
|
96
|
+
const config = options.sceneType === 'group'
|
|
97
|
+
? this.config.groupConfig
|
|
98
|
+
: this.config.privateConfig;
|
|
99
|
+
const typingOptions = {
|
|
100
|
+
messageId: options.messageId,
|
|
101
|
+
sessionId: options.sessionId,
|
|
102
|
+
userId: options.userId,
|
|
103
|
+
groupId: options.groupId,
|
|
104
|
+
platform: 'napcat',
|
|
105
|
+
botId: this.bot.$id,
|
|
106
|
+
sceneType: options.sceneType,
|
|
107
|
+
};
|
|
108
|
+
return await this.manager.start(typingOptions, config);
|
|
109
|
+
}
|
|
110
|
+
async stop(options) {
|
|
111
|
+
const typingOptions = {
|
|
112
|
+
sessionId: options.sessionId,
|
|
113
|
+
userId: options.userId,
|
|
114
|
+
groupId: options.groupId,
|
|
115
|
+
platform: 'napcat',
|
|
116
|
+
botId: this.bot.$id,
|
|
117
|
+
sceneType: 'private',
|
|
118
|
+
};
|
|
119
|
+
await this.manager.stop(typingOptions);
|
|
120
|
+
this.currentOptions = undefined;
|
|
121
|
+
}
|
|
122
|
+
async stopAll() {
|
|
123
|
+
await this.manager.stopAll();
|
|
124
|
+
}
|
|
125
|
+
updateConfig(config) {
|
|
126
|
+
this.config = { ...this.config, ...config };
|
|
127
|
+
}
|
|
128
|
+
getConfig() {
|
|
129
|
+
return { ...this.config };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export function enableTypingIndicator(bot, config) {
|
|
133
|
+
if (!bot.$typingIndicator) {
|
|
134
|
+
bot.$typingIndicator = new NapCatTypingIndicatorManager(bot, config);
|
|
135
|
+
}
|
|
136
|
+
return bot.$typingIndicator;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=typing-indicator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typing-indicator.js","sourceRoot":"","sources":["../src/typing-indicator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,sBAAsB,EACtB,8BAA8B,GAI/B,MAAM,gBAAgB,CAAC;AAWxB,MAAM,cAAc,GAAgC;IAClD,OAAO,EAAE,IAAI;IACb,YAAY,EAAE,QAAQ;IACtB,UAAU,EAAE,IAAI;IAChB,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE;QACb,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,UAAU;QACn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E,SAAS;SACrB,CAAC;QACF,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACvC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED,YAAY,CAAC,MAA4C;QACvD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IAC9C,CAAC;IAED,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF;AAQD,MAAM,UAAU,qBAAqB,CACnC,GAAkB,EAClB,MAA6C;IAE7C,IAAI,CAAE,GAAW,CAAC,gBAAgB,EAAE,CAAC;QAClC,GAAW,CAAC,gBAAgB,GAAG,IAAI,4BAA4B,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChF,CAAC;IACD,OAAQ,GAAW,CAAC,gBAAgB,CAAC;AACvC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-napcat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Zhin.js adapter for NapCatQQ (OneBot11 superset with go-cqhttp & NapCat extensions)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"src",
|
|
17
17
|
"lib",
|
|
18
|
+
"client",
|
|
19
|
+
"dist",
|
|
18
20
|
"skills",
|
|
19
21
|
"plugin.yml",
|
|
20
22
|
"README.md",
|
|
@@ -48,16 +50,28 @@
|
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
52
|
"@types/node": "^25.9.1",
|
|
53
|
+
"@types/react": "^19.2.15",
|
|
54
|
+
"@types/react-dom": "^19.2.3",
|
|
51
55
|
"@types/ws": "^8.18.1",
|
|
56
|
+
"lucide-react": "^1.17.0",
|
|
52
57
|
"typescript": "^6.0.3",
|
|
53
|
-
"zhin.js": "1.0.
|
|
54
|
-
"@zhin.js/
|
|
58
|
+
"@zhin.js/cli": "1.0.82",
|
|
59
|
+
"@zhin.js/console": "3.0.5",
|
|
60
|
+
"zhin.js": "1.0.86"
|
|
55
61
|
},
|
|
56
62
|
"peerDependencies": {
|
|
57
|
-
"zhin.js": "1.
|
|
58
|
-
"@zhin.js/http": "1.0.
|
|
63
|
+
"@zhin.js/agent": "0.1.26",
|
|
64
|
+
"@zhin.js/http": "1.0.79",
|
|
65
|
+
"@zhin.js/console": "3.0.5",
|
|
66
|
+
"zhin.js": "1.0.86"
|
|
59
67
|
},
|
|
60
68
|
"peerDependenciesMeta": {
|
|
69
|
+
"@zhin.js/agent": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
72
|
+
"@zhin.js/console": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
61
75
|
"@zhin.js/http": {
|
|
62
76
|
"optional": true
|
|
63
77
|
}
|
package/plugin.yml
CHANGED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AgentPromptBuildContext,
|
|
3
|
+
AgentPromptContributor,
|
|
4
|
+
AgentPromptSection,
|
|
5
|
+
AgentTool,
|
|
6
|
+
} from 'zhin.js';
|
|
7
|
+
import { filterTools } from 'zhin.js';
|
|
8
|
+
|
|
9
|
+
function isNapCatDelegatedTask(query: string, goal: string): boolean {
|
|
10
|
+
const text = `${query} ${goal}`;
|
|
11
|
+
if (/\bnapcat\b|napcat_|mcp_napcat/i.test(text)) return true;
|
|
12
|
+
if (/戳一戳|poke|表情回应|emoji.*reaction/i.test(text)) return true;
|
|
13
|
+
if (/精华消息|essence|群公告|group.*notice/i.test(text)) return true;
|
|
14
|
+
if (/AI语音|ai.*record|tts|文字转语音/i.test(text)) return true;
|
|
15
|
+
if (/群文件|upload.*file|群签到|group.*sign/i.test(text)) return true;
|
|
16
|
+
if (/合并转发|forward.*msg|转发消息/i.test(text)) return true;
|
|
17
|
+
if (/点赞/.test(text) && /qq|好友|\d{5,}/i.test(text)) return true;
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function selectNapCatDeferredTools(
|
|
22
|
+
query: string,
|
|
23
|
+
goal: string,
|
|
24
|
+
deferredCatalog: AgentTool[],
|
|
25
|
+
maxTools: number,
|
|
26
|
+
): AgentTool[] {
|
|
27
|
+
const pool = deferredCatalog.filter(
|
|
28
|
+
t => !t.name.startsWith('mcp_filesystem') && !t.name.startsWith('mcp_memory_'),
|
|
29
|
+
);
|
|
30
|
+
const napcatTools = pool.filter(t => t.name.startsWith('napcat_'));
|
|
31
|
+
const pinned: AgentTool[] = [];
|
|
32
|
+
const preferOrder = [
|
|
33
|
+
'napcat_send_poke',
|
|
34
|
+
'napcat_set_emoji_reaction',
|
|
35
|
+
'napcat_send_like',
|
|
36
|
+
'napcat_set_essence_msg',
|
|
37
|
+
'napcat_send_group_notice',
|
|
38
|
+
'napcat_ai_tts',
|
|
39
|
+
];
|
|
40
|
+
for (const name of preferOrder) {
|
|
41
|
+
const t = napcatTools.find(x => x.name === name);
|
|
42
|
+
if (t) pinned.push(t);
|
|
43
|
+
}
|
|
44
|
+
for (const t of napcatTools) {
|
|
45
|
+
if (pinned.length >= maxTools) break;
|
|
46
|
+
if (!pinned.some(p => p.name === t.name)) pinned.push(t);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const extra = filterTools(query, pool, { maxTools, minScore: 0.08 })
|
|
50
|
+
.filter(t => !pinned.some(p => p.name === t.name));
|
|
51
|
+
|
|
52
|
+
const merged: AgentTool[] = [...pinned];
|
|
53
|
+
for (const t of extra) {
|
|
54
|
+
if (merged.length >= maxTools) break;
|
|
55
|
+
merged.push(t);
|
|
56
|
+
}
|
|
57
|
+
return merged.slice(0, maxTools);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const ORCHESTRATOR_NAPCAT = [
|
|
61
|
+
'On napcat/QQ: use run_deferred_task with tool_query "napcat_send_poke" or "napcat_set_emoji_reaction".',
|
|
62
|
+
'NapCat supports: poke, emoji reaction, forward msg, essence, group notice, AI TTS, OCR, group files.',
|
|
63
|
+
'Skip tool_search when the user clearly asks for QQ-specific features like poke, reaction, or group management.',
|
|
64
|
+
].join('\n');
|
|
65
|
+
|
|
66
|
+
const WORKER_NAPCAT = [
|
|
67
|
+
'- Use `napcat_send_poke` for poke/戳一戳.',
|
|
68
|
+
'- Use `napcat_set_emoji_reaction` for emoji reaction/表情回应.',
|
|
69
|
+
'- Use `napcat_send_like` for friend like/点赞.',
|
|
70
|
+
'- Use `napcat_ai_tts` for AI voice/AI语音.',
|
|
71
|
+
'- Use `napcat_set_essence_msg` / `napcat_delete_essence_msg` for essence messages.',
|
|
72
|
+
'- Use `napcat_send_group_notice` for group announcements.',
|
|
73
|
+
'- Do NOT use mcp_filesystem_* or explore node_modules for QQ tasks.',
|
|
74
|
+
].join('\n');
|
|
75
|
+
|
|
76
|
+
export function createNapCatAgentPromptContributor(): AgentPromptContributor {
|
|
77
|
+
return {
|
|
78
|
+
platform: 'napcat',
|
|
79
|
+
|
|
80
|
+
async buildSections(ctx: AgentPromptBuildContext): Promise<AgentPromptSection[] | null> {
|
|
81
|
+
if (ctx.slot === 'orchestrator') {
|
|
82
|
+
if (!ctx.toolSearch) return null;
|
|
83
|
+
return [{
|
|
84
|
+
id: 'platform.napcat.orchestrator',
|
|
85
|
+
title: '## napcat / QQ',
|
|
86
|
+
body: ORCHESTRATOR_NAPCAT,
|
|
87
|
+
priority: 50,
|
|
88
|
+
}];
|
|
89
|
+
}
|
|
90
|
+
if (ctx.slot === 'deferred_worker') {
|
|
91
|
+
const query = ctx.deferred?.toolQuery ?? ctx.deferred?.goal ?? '';
|
|
92
|
+
const goal = ctx.deferred?.goal ?? '';
|
|
93
|
+
if (!isNapCatDelegatedTask(query, goal)) return null;
|
|
94
|
+
return [{
|
|
95
|
+
id: 'platform.napcat.deferred_worker',
|
|
96
|
+
title: '## napcat / QQ(本任务)',
|
|
97
|
+
body: WORKER_NAPCAT,
|
|
98
|
+
priority: 50,
|
|
99
|
+
}];
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
matchesDeferredTask(ctx: AgentPromptBuildContext): boolean {
|
|
105
|
+
const query = ctx.deferred?.toolQuery ?? ctx.deferred?.goal ?? ctx.userMessagePreview ?? '';
|
|
106
|
+
const goal = ctx.deferred?.goal ?? ctx.userMessagePreview ?? '';
|
|
107
|
+
return isNapCatDelegatedTask(query, goal);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
selectDeferredTools(query, goal, catalog, maxTools) {
|
|
111
|
+
if (!isNapCatDelegatedTask(query, goal)) return null;
|
|
112
|
+
return selectNapCatDeferredTools(query, goal, catalog, maxTools);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
package/src/bot-base.ts
CHANGED
|
@@ -10,12 +10,16 @@ import {
|
|
|
10
10
|
segment,
|
|
11
11
|
Notice,
|
|
12
12
|
Request,
|
|
13
|
+
type QuotedMessagePayload,
|
|
13
14
|
} from 'zhin.js';
|
|
15
|
+
import { parseOneBotGetMsgResponse } from './onebot-get-msg.js';
|
|
14
16
|
import type { NapCatBotConfig, NapCatMessageEvent, MessageSegment, ApiResponse } from './types.js';
|
|
15
17
|
import type { NapCatAdapter } from './adapter.js';
|
|
18
|
+
import { InboundMessageDeduper, isSelfMessage, normalizeMessage, resolveSideEventDedupeKey } from './napcat-inbound.js';
|
|
16
19
|
|
|
17
20
|
export abstract class NapCatBotBase extends EventEmitter implements Bot<NapCatBotConfig, NapCatMessageEvent> {
|
|
18
21
|
$connected = false;
|
|
22
|
+
protected readonly inboundDeduper = new InboundMessageDeduper();
|
|
19
23
|
|
|
20
24
|
get logger() { return this.adapter.plugin.logger; }
|
|
21
25
|
get $id() { return this.$config.name; }
|
|
@@ -33,6 +37,10 @@ export abstract class NapCatBotBase extends EventEmitter implements Bot<NapCatBo
|
|
|
33
37
|
// ══════════════════════════════════════════════════════════════════
|
|
34
38
|
|
|
35
39
|
$formatMessage(ev: NapCatMessageEvent): Message<NapCatMessageEvent> {
|
|
40
|
+
const content = normalizeMessage(ev.message);
|
|
41
|
+
const quoteId = Message.quoteIdFromContent(content);
|
|
42
|
+
Message.alignReplySegments(content, quoteId);
|
|
43
|
+
|
|
36
44
|
const message = Message.from(ev, {
|
|
37
45
|
$id: ev.message_id.toString(),
|
|
38
46
|
$adapter: 'napcat',
|
|
@@ -46,7 +54,8 @@ export abstract class NapCatBotBase extends EventEmitter implements Bot<NapCatBo
|
|
|
46
54
|
id: (ev.group_id || ev.user_id).toString(),
|
|
47
55
|
type: ev.group_id ? 'group' : 'private',
|
|
48
56
|
},
|
|
49
|
-
$content:
|
|
57
|
+
$content: content,
|
|
58
|
+
$quote_id: quoteId,
|
|
50
59
|
$raw: ev.raw_message,
|
|
51
60
|
$timestamp: ev.time,
|
|
52
61
|
$recall: async () => { await this.deleteMsg(ev.message_id); },
|
|
@@ -83,6 +92,18 @@ export abstract class NapCatBotBase extends EventEmitter implements Bot<NapCatBo
|
|
|
83
92
|
await this.deleteMsg(parseInt(id));
|
|
84
93
|
}
|
|
85
94
|
|
|
95
|
+
async $addReaction(messageId: string, emojiId: string): Promise<string> {
|
|
96
|
+
await this.setMsgEmojiLike(parseInt(messageId), emojiId);
|
|
97
|
+
return `reaction:${messageId}:${emojiId}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async $removeReaction(messageId: string, _reactionId: string): Promise<void> {
|
|
101
|
+
// NapCat 的 set_msg_emoji_like 是 toggle 行为,再调一次即取消
|
|
102
|
+
const parts = _reactionId.split(':');
|
|
103
|
+
const emojiId = parts[2] || parts[0];
|
|
104
|
+
await this.setMsgEmojiLike(parseInt(messageId), emojiId);
|
|
105
|
+
}
|
|
106
|
+
|
|
86
107
|
// ══════════════════════════════════════════════════════════════════
|
|
87
108
|
// 事件分发
|
|
88
109
|
// ══════════════════════════════════════════════════════════════════
|
|
@@ -102,12 +123,18 @@ export abstract class NapCatBotBase extends EventEmitter implements Bot<NapCatBo
|
|
|
102
123
|
}
|
|
103
124
|
|
|
104
125
|
private handleMessage(ev: NapCatMessageEvent): void {
|
|
126
|
+
if (isSelfMessage(ev)) return;
|
|
127
|
+
const msgId = ev.message_id.toString();
|
|
128
|
+
if (!this.inboundDeduper.shouldProcess(msgId)) return;
|
|
129
|
+
ev.message = normalizeMessage(ev.message);
|
|
105
130
|
const message = this.$formatMessage(ev);
|
|
106
131
|
this.adapter.emit('message.receive', message);
|
|
107
132
|
this.logger.debug(`${this.$id} recv ${message.$channel.type}(${message.$channel.id}):${segment.raw(message.$content)}`);
|
|
108
133
|
}
|
|
109
134
|
|
|
110
135
|
private handleNotice(event: any): void {
|
|
136
|
+
const dedupeKey = resolveSideEventDedupeKey(event, 'notice');
|
|
137
|
+
if (!this.inboundDeduper.shouldProcess(dedupeKey)) return;
|
|
111
138
|
const noticeTypeMap: Record<string, string> = {
|
|
112
139
|
group_increase: 'group_member_increase',
|
|
113
140
|
group_decrease: 'group_member_decrease',
|
|
@@ -152,6 +179,8 @@ export abstract class NapCatBotBase extends EventEmitter implements Bot<NapCatBo
|
|
|
152
179
|
}
|
|
153
180
|
|
|
154
181
|
private handleRequest(event: any): void {
|
|
182
|
+
const dedupeKey = resolveSideEventDedupeKey(event, 'request');
|
|
183
|
+
if (!this.inboundDeduper.shouldProcess(dedupeKey)) return;
|
|
155
184
|
const typeMap: Record<string, string> = {
|
|
156
185
|
friend: 'friend_add',
|
|
157
186
|
group: event.sub_type === 'invite' ? 'group_invite' : 'group_add',
|
|
@@ -199,6 +228,12 @@ export abstract class NapCatBotBase extends EventEmitter implements Bot<NapCatBo
|
|
|
199
228
|
}
|
|
200
229
|
async deleteMsg(messageId: number) { return this.callApi('delete_msg', { message_id: messageId }); }
|
|
201
230
|
async getMsg(messageId: number) { return this.callApi('get_msg', { message_id: messageId }); }
|
|
231
|
+
|
|
232
|
+
async $getMsg(messageId: string): Promise<QuotedMessagePayload> {
|
|
233
|
+
const idParam = /^\d+$/.test(messageId) ? Number(messageId) : messageId;
|
|
234
|
+
const data = await this.callApi('get_msg', { message_id: idParam });
|
|
235
|
+
return parseOneBotGetMsgResponse(messageId, data);
|
|
236
|
+
}
|
|
202
237
|
async getForwardMsg(id: string) { return this.callApi('get_forward_msg', { id }); }
|
|
203
238
|
async sendLike(userId: number, times = 1) { return this.callApi('send_like', { user_id: userId, times }); }
|
|
204
239
|
|
package/src/bot-http.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { NapCatHttpConfig, ApiResponse } from './types.js';
|
|
|
9
9
|
import type { NapCatAdapter } from './adapter.js';
|
|
10
10
|
import { registerFetchRoute, type Router, type RouterContext } from '@zhin.js/http/router';
|
|
11
11
|
import * as crypto from 'crypto';
|
|
12
|
+
import { enableTypingIndicator } from './typing-indicator.js';
|
|
12
13
|
|
|
13
14
|
export class NapCatHttpBot extends NapCatBotBase {
|
|
14
15
|
private pollTimer?: NodeJS.Timeout;
|
|
@@ -24,11 +25,13 @@ export class NapCatHttpBot extends NapCatBotBase {
|
|
|
24
25
|
await this.checkConnection();
|
|
25
26
|
this.startPoll();
|
|
26
27
|
this.$connected = true;
|
|
28
|
+
this.initTypingIndicator();
|
|
27
29
|
this.logger.info(formatCompact({ bot: this.$id, mode: 'http' }));
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
async $disconnect(): Promise<void> {
|
|
31
33
|
if (this.pollTimer) { clearInterval(this.pollTimer); this.pollTimer = undefined; }
|
|
34
|
+
this.inboundDeduper.clear();
|
|
32
35
|
this.$connected = false;
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -54,9 +57,12 @@ export class NapCatHttpBot extends NapCatBotBase {
|
|
|
54
57
|
|
|
55
58
|
if (this.$config.access_token) {
|
|
56
59
|
const sig = ctx.get('x-signature');
|
|
60
|
+
const authHeader = ctx.get('authorization');
|
|
57
61
|
if (sig) {
|
|
58
62
|
const expected = 'sha1=' + crypto.createHmac('sha1', this.$config.access_token).update(JSON.stringify(body)).digest('hex');
|
|
59
63
|
if (sig !== expected) { ctx.status = 403; ctx.body = { error: 'signature mismatch' }; return; }
|
|
64
|
+
} else if (authHeader) {
|
|
65
|
+
if (authHeader !== `Bearer ${this.$config.access_token}`) { ctx.status = 403; ctx.body = { error: 'auth failed' }; return; }
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
|
|
@@ -88,4 +94,16 @@ export class NapCatHttpBot extends NapCatBotBase {
|
|
|
88
94
|
}
|
|
89
95
|
}, interval);
|
|
90
96
|
}
|
|
97
|
+
|
|
98
|
+
private initTypingIndicator(): void {
|
|
99
|
+
const tiConfig = (this.$config as any).typingIndicator;
|
|
100
|
+
if (tiConfig && tiConfig.enabled !== false) {
|
|
101
|
+
enableTypingIndicator(this, {
|
|
102
|
+
enabled: true,
|
|
103
|
+
defaultEmoji: tiConfig.defaultEmoji || '128516',
|
|
104
|
+
autoRemove: true,
|
|
105
|
+
removeDelay: 5000,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
91
109
|
}
|