@zhin.js/core 1.1.51 → 1.1.52
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/lib/built/segment-contract/json-schema.js +1 -1
- package/lib/plugin-runtime/im/group-rule-violation.d.ts +47 -0
- package/lib/plugin-runtime/im/group-rule-violation.js +10 -0
- package/lib/plugin-runtime/im/index.d.ts +1 -0
- package/lib/plugin-runtime/im/index.js +1 -0
- package/lib/plugin-runtime/im/outbound-segments.d.ts +5 -0
- package/lib/plugin-runtime/im/outbound-segments.js +9 -0
- package/lib/side-event/dispatch.js +5 -1
- package/lib/side-event/normalize.js +4 -1
- package/package.json +9 -9
|
@@ -111,7 +111,7 @@ export const outboundSegmentJsonSchema = {
|
|
|
111
111
|
name: { type: 'string' },
|
|
112
112
|
}, ['media'])),
|
|
113
113
|
strictBranch('reply', dataObject({
|
|
114
|
-
message_id: { type: 'string', description: '被引用消息的平台消息 id' },
|
|
114
|
+
message_id: { type: 'string', description: '被引用消息的平台消息 id,或消息头里的 m<n> 别名' },
|
|
115
115
|
}, ['message_id'])),
|
|
116
116
|
strictBranch('forward', dataObject({
|
|
117
117
|
forward_id: { type: 'string' },
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ConversationRef } from '@zhin.js/im-contract';
|
|
2
|
+
/** 插件可上报的违规类型(`flood` 由宿主本地检测,不经插件)。 @public */
|
|
3
|
+
export type GroupRuleViolationTrigger = 'advertising' | 'abuse';
|
|
4
|
+
/** @public */
|
|
5
|
+
export interface GroupRuleViolationReport {
|
|
6
|
+
/** 违规消息所在的群会话(`kind` 必须是 `group`)。 */
|
|
7
|
+
readonly conversation: ConversationRef;
|
|
8
|
+
readonly memberId: string;
|
|
9
|
+
readonly memberName?: string;
|
|
10
|
+
/** 入站消息上的平台角色(群主 / 管理员豁免)。 */
|
|
11
|
+
readonly memberRoles?: readonly unknown[];
|
|
12
|
+
readonly trigger: GroupRuleViolationTrigger;
|
|
13
|
+
/** 原消息发出时间(毫秒)。 */
|
|
14
|
+
readonly sentAt: number;
|
|
15
|
+
readonly messageId?: string;
|
|
16
|
+
/** 命中证据(原文摘录)。 */
|
|
17
|
+
readonly evidence?: readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* 入群不久即发广告:不按阶梯,直接出一张踢人审批卡(每次人批,绝不自动踢)。
|
|
20
|
+
* 只对 `advertising` 生效。
|
|
21
|
+
*/
|
|
22
|
+
readonly newcomer?: boolean;
|
|
23
|
+
/** `remind` / `warn` 档的附加动作:撤回原消息(调用方绑定到这条原消息)。 */
|
|
24
|
+
readonly recall?: () => Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `handled`:执行器已按规则处理(含被控制面 / 豁免 / 冷却跳过),调用方不得再自行提醒或处罚。
|
|
28
|
+
* `no_rule`:该群该类型没有可用规则,调用方可退回只提醒 / 警告。
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export type GroupRuleViolationOutcome = 'handled' | 'no_rule';
|
|
32
|
+
/** 迁移结果:`created` 新建了待确认规则;`exists` 该群该类型已有规则(任意状态);`unavailable` 规则存储不可用。 @public */
|
|
33
|
+
export type GroupRuleDefaultOutcome = 'created' | 'exists' | 'unavailable';
|
|
34
|
+
/** @public */
|
|
35
|
+
export interface GroupRuleViolationSink {
|
|
36
|
+
report(violation: GroupRuleViolationReport): Promise<GroupRuleViolationOutcome>;
|
|
37
|
+
/**
|
|
38
|
+
* 迁移:该群该类型还没有任何规则时,按默认模板(提醒 → 警告 → 禁言 600 秒,冷静期 30 分钟)
|
|
39
|
+
* 生成一条 `pending` 规则并在群里出预览卡,等群主 / 管理员确认一次。已有任意状态的规则则不动。
|
|
40
|
+
*/
|
|
41
|
+
ensureDefaultRule(input: Readonly<{
|
|
42
|
+
conversation: ConversationRef;
|
|
43
|
+
trigger: GroupRuleViolationTrigger;
|
|
44
|
+
}>): Promise<GroupRuleDefaultOutcome>;
|
|
45
|
+
}
|
|
46
|
+
/** @public */
|
|
47
|
+
export declare const groupRuleViolationToken: import("@zhin.js/plugin-runtime").Token<GroupRuleViolationSink>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 群管违规上报(ADR 0039 §5,切片 E)。
|
|
3
|
+
*
|
|
4
|
+
* content-moderation 等插件只负责「判定违规」,「判定后做什么」交给 Agent host 的群规执行器:
|
|
5
|
+
* 按该群生效规则的阶梯执行提醒 / 警告 / 禁言(以规则批准作硬闸批准)/ 建议踢人(每次人批出卡)。
|
|
6
|
+
* Agent host 在根作用域提供本 token;未装 Agent(没有本资源)时插件只能提醒 / 警告,不能禁言或踢人。
|
|
7
|
+
*/
|
|
8
|
+
import { createToken } from '@zhin.js/plugin-runtime';
|
|
9
|
+
/** @public */
|
|
10
|
+
export const groupRuleViolationToken = createToken('zhin.im.group-rule-violations');
|
|
@@ -6,6 +6,7 @@ export { isMessageOrigin, roomMembershipToken } from './inbound-origin.js';
|
|
|
6
6
|
export type { MessageOrigin, RoomInboundRouteInput, RoomMembershipPort, RoomRouteDecision, } from './inbound-origin.js';
|
|
7
7
|
export * from './im-runtime.js';
|
|
8
8
|
export * from './login-assist-host.js';
|
|
9
|
+
export * from './group-rule-violation.js';
|
|
9
10
|
export * from './member-welcome.js';
|
|
10
11
|
export * from './message-bus.js';
|
|
11
12
|
export * from './message-dispatcher.js';
|
|
@@ -4,6 +4,7 @@ export * from './ingress-route.js';
|
|
|
4
4
|
export { isMessageOrigin, roomMembershipToken } from './inbound-origin.js';
|
|
5
5
|
export * from './im-runtime.js';
|
|
6
6
|
export * from './login-assist-host.js';
|
|
7
|
+
export * from './group-rule-violation.js';
|
|
7
8
|
export * from './member-welcome.js';
|
|
8
9
|
export * from './message-bus.js';
|
|
9
10
|
export * from './message-dispatcher.js';
|
|
@@ -64,6 +64,11 @@ export declare function isOutboundSegment(value: unknown): value is OutboundSegm
|
|
|
64
64
|
export declare function resolveOutboundInteractivePolicy(adapter: CapabilityId, snapshot: RuntimeSnapshot): InteractivePolicy;
|
|
65
65
|
/** Read declared support from this operation's snapshot without requiring live admission. */
|
|
66
66
|
export declare function resolveOutboundSupportedSegments(adapter: CapabilityId, snapshot: RuntimeSnapshot): readonly string[] | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* ADR 0038 §5: the adapter declares `liveDanmaku`, so its inbound messages are
|
|
69
|
+
* live-stream danmaku the Agent answers one window at a time.
|
|
70
|
+
*/
|
|
71
|
+
export declare function adapterDeclaresLiveDanmaku(adapter: CapabilityId, snapshot: RuntimeSnapshot): boolean;
|
|
67
72
|
/**
|
|
68
73
|
* What a model may author for this endpoint: every segment type the outbound
|
|
69
74
|
* projection would deliver rather than reject (markdown and keyboards outside the
|
|
@@ -79,6 +79,15 @@ export function resolveOutboundSupportedSegments(adapter, snapshot) {
|
|
|
79
79
|
const segments = slot.definition.segments;
|
|
80
80
|
return Array.isArray(segments?.supported) && segments.supported.every(type => typeof type === 'string') ? segments.supported : undefined;
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* ADR 0038 §5: the adapter declares `liveDanmaku`, so its inbound messages are
|
|
84
|
+
* live-stream danmaku the Agent answers one window at a time.
|
|
85
|
+
*/
|
|
86
|
+
export function adapterDeclaresLiveDanmaku(adapter, snapshot) {
|
|
87
|
+
const slot = snapshot.capabilities.get(adapter) ?? snapshot.capabilities.get(baseSlotCapabilityId(adapter));
|
|
88
|
+
const capabilities = slot?.definition?.capabilities;
|
|
89
|
+
return Array.isArray(capabilities) && capabilities.includes('liveDanmaku');
|
|
90
|
+
}
|
|
82
91
|
/**
|
|
83
92
|
* What a model may author for this endpoint: every segment type the outbound
|
|
84
93
|
* projection would deliver rather than reject (markdown and keyboards outside the
|
|
@@ -33,7 +33,11 @@ export async function receiveOneBotLikeSideEvent(emit, input) {
|
|
|
33
33
|
conversation: oneBotConversation(parts.scene_type, raw),
|
|
34
34
|
name: composeSideEventName('notice', parts.scene_type, parts.sub_type),
|
|
35
35
|
actor: senderFromId(actorId),
|
|
36
|
-
target: senderFromId(targetId
|
|
36
|
+
target: senderFromId(targetId,
|
|
37
|
+
// icqq/OneBot 入群通知携带新成员昵称;无则保持缺省(不在 core 内发起网络查询)
|
|
38
|
+
parts.sub_type === 'member_increase' && typeof raw.nickname === 'string' && raw.nickname.trim()
|
|
39
|
+
? raw.nickname.trim()
|
|
40
|
+
: undefined),
|
|
37
41
|
timestamp: toMillis(raw.time),
|
|
38
42
|
...(raw.message_id != null
|
|
39
43
|
? { messageId: String(raw.message_id) }
|
|
@@ -9,7 +9,10 @@ export function resolveSideEventDedupeKey(data, kind) {
|
|
|
9
9
|
const type = data.notice_type ?? data.request_type ?? kind;
|
|
10
10
|
const scope = data.group_id ?? data.user_id ?? '';
|
|
11
11
|
const sub = data.sub_type ?? '';
|
|
12
|
-
|
|
12
|
+
// 群事件的 scope 是群号:不带成员和操作人时,同一群的两次入群(平台不给 time 时尤甚)会撞成同一个键,后一次被当重复丢掉。
|
|
13
|
+
const member = data.group_id != null ? (data.user_id ?? '') : '';
|
|
14
|
+
const operator = data.operator_id ?? '';
|
|
15
|
+
return `${kind}:${time}_${type}_${scope}_${sub}_${member}_${operator}`;
|
|
13
16
|
}
|
|
14
17
|
function resolveNotifyNoticeParts(subType, isGroup) {
|
|
15
18
|
if (subType === 'poke') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.52",
|
|
4
4
|
"description": "Zhin机器人核心框架",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -57,29 +57,29 @@
|
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"qrcode": "^1.5.4",
|
|
59
59
|
"segment-matcher": "^1.0.5",
|
|
60
|
-
"@zhin.js/adapter": "1.1.23",
|
|
61
60
|
"@zhin.js/command": "1.1.11",
|
|
61
|
+
"@zhin.js/adapter": "1.1.24",
|
|
62
62
|
"@zhin.js/component": "1.1.10",
|
|
63
|
-
"@zhin.js/handler": "1.1.9",
|
|
64
|
-
"@zhin.js/im-contract": "1.1.7",
|
|
65
63
|
"@zhin.js/database": "1.1.5",
|
|
64
|
+
"@zhin.js/handler": "1.1.9",
|
|
65
|
+
"@zhin.js/im-contract": "1.1.8",
|
|
66
66
|
"@zhin.js/interaction": "1.1.2",
|
|
67
67
|
"@zhin.js/kernel": "1.1.5",
|
|
68
|
-
"@zhin.js/logger": "1.1.2",
|
|
69
68
|
"@zhin.js/middleware": "1.1.10",
|
|
69
|
+
"@zhin.js/logger": "1.1.2",
|
|
70
70
|
"@zhin.js/plugin-runtime": "1.1.17",
|
|
71
|
-
"@zhin.js/permission": "1.1.9",
|
|
72
71
|
"@zhin.js/schedule-feature": "1.1.9",
|
|
72
|
+
"@zhin.js/jsx": "1.1.7",
|
|
73
73
|
"@zhin.js/schema": "1.1.4",
|
|
74
|
-
"@zhin.js/
|
|
75
|
-
"@zhin.js/
|
|
74
|
+
"@zhin.js/feature-kit": "1.1.9",
|
|
75
|
+
"@zhin.js/permission": "1.1.9"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/node": "^26.1.2",
|
|
79
79
|
"@types/qrcode": "^1.5.6",
|
|
80
80
|
"ajv": "8.18.0",
|
|
81
81
|
"typescript": "^6.0.3",
|
|
82
|
-
"@zhin.js/ai": "1.1.
|
|
82
|
+
"@zhin.js/ai": "1.1.47"
|
|
83
83
|
},
|
|
84
84
|
"repository": {
|
|
85
85
|
"type": "git",
|