@zhin.js/core 1.3.3 → 1.3.5
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 +12 -0
- package/lib/adapter.js +2 -2
- package/lib/built/ai-outbound/parse.js +26 -12
- package/lib/built/authorization.js +2 -2
- package/lib/built/component.d.ts +1 -2
- package/lib/built/component.js +1 -1
- package/lib/built/database.d.ts +1 -2
- package/lib/built/database.js +1 -1
- package/lib/built/dispatcher.d.ts +1 -1
- package/lib/built/endpoint-lifecycle-service.js +2 -1
- package/lib/built/endpoint-lifecycle.js +4 -3
- package/lib/built/html-to-text.js +15 -14
- package/lib/built/inbound-pipeline.d.ts +1 -1
- package/lib/built/inbound-pipeline.js +1 -1
- package/lib/built/interactive-segments/action.js +16 -1
- package/lib/built/message-enrich.d.ts +1 -1
- package/lib/built/permit-check.d.ts +1 -1
- package/lib/built/platform-permit.js +35 -10
- package/lib/built/schedule.d.ts +1 -2
- package/lib/built/schedule.js +1 -1
- package/lib/component.js +28 -11
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/notice.d.ts +15 -58
- package/lib/notice.js +1 -3
- package/lib/plugin-runtime/im/contracts.d.ts +71 -0
- package/lib/plugin-runtime/im/contracts.js +55 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +70 -0
- package/lib/plugin-runtime/im/im-runtime.js +299 -0
- package/lib/plugin-runtime/im/index.d.ts +5 -0
- package/lib/plugin-runtime/im/index.js +5 -0
- package/lib/plugin-runtime/im/message-dispatcher.d.ts +7 -0
- package/lib/plugin-runtime/im/message-dispatcher.js +26 -0
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +6 -0
- package/lib/plugin-runtime/im/outbound-renderer.js +31 -0
- package/lib/plugin-runtime/im/outbound-segments.d.ts +22 -0
- package/lib/plugin-runtime/im/outbound-segments.js +59 -0
- package/lib/plugin.d.ts +2 -4
- package/lib/plugin.js +12 -8
- package/lib/request.d.ts +16 -59
- package/lib/request.js +0 -3
- package/lib/side-event/base.d.ts +45 -0
- package/lib/side-event/base.js +30 -0
- package/lib/side-event/index.d.ts +3 -0
- package/lib/side-event/index.js +3 -0
- package/lib/side-event/normalize.d.ts +40 -0
- package/lib/side-event/normalize.js +117 -0
- package/lib/side-event/types.d.ts +25 -0
- package/lib/side-event/types.js +55 -0
- package/package.json +15 -5
package/lib/request.d.ts
CHANGED
|
@@ -1,84 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import type { MaybePromise } from './types.js';
|
|
2
|
+
import type { Adapters } from './adapter.js';
|
|
3
|
+
import type { RequestKind } from './side-event/types.js';
|
|
4
|
+
import type { SideEventBase } from './side-event/base.js';
|
|
5
|
+
export type { RequestKind, ComposedRequestName, RequestType } from './side-event/types.js';
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* 常见 IM 请求事件分类:
|
|
7
|
-
* - friend_add: 好友添加请求
|
|
8
|
-
* - group_add: 主动申请入群
|
|
9
|
-
* - group_invite: 邀请入群请求
|
|
10
|
-
*
|
|
11
|
-
* 适配器可自行扩展更多子类型
|
|
12
|
-
*/
|
|
13
|
-
export type RequestType = 'friend_add' | 'group_add' | 'group_invite' | (string & {});
|
|
14
|
-
/**
|
|
15
|
-
* 请求频道信息
|
|
16
|
-
*/
|
|
17
|
-
export interface RequestChannel {
|
|
18
|
-
id: string;
|
|
19
|
-
type: 'group' | 'private' | 'channel';
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* 请求基础结构
|
|
23
|
-
*
|
|
24
|
-
* 与 MessageBase / NoticeBase 同构设计。
|
|
25
|
-
* 核心区别:Request 提供 `$approve()` 和 `$reject()` 方法,用于快速处理请求。
|
|
7
|
+
* 请求基础结构 — 继承 SideEventBase,附加审批方法。
|
|
26
8
|
*
|
|
27
9
|
* @example
|
|
28
10
|
* ```typescript
|
|
29
|
-
* // 适配器中格式化请求
|
|
30
11
|
* const request = Request.from(rawEvent, {
|
|
31
12
|
* $id: rawEvent.flag,
|
|
32
13
|
* $adapter: 'icqq',
|
|
33
14
|
* $endpoint: endpointId,
|
|
34
|
-
* $type: '
|
|
35
|
-
* $
|
|
36
|
-
* $
|
|
15
|
+
* $type: 'request',
|
|
16
|
+
* $scene_id: groupId,
|
|
17
|
+
* $scene_type: 'group',
|
|
18
|
+
* $sub_type: 'invite',
|
|
19
|
+
* $actor: { id: userId, name: '邀请者' },
|
|
37
20
|
* $comment: '请求加群消息',
|
|
38
21
|
* $timestamp: Date.now(),
|
|
39
22
|
* $approve: async (remark?) => { await api.approve(flag, remark); },
|
|
40
23
|
* $reject: async (reason?) => { await api.reject(flag, reason); },
|
|
41
24
|
* });
|
|
25
|
+
* // formatSideEventName(request) === 'request.group.invite'
|
|
42
26
|
* this.adapter.emit('request.receive', request);
|
|
43
27
|
* ```
|
|
44
28
|
*/
|
|
45
|
-
export interface RequestBase {
|
|
46
|
-
/** 请求唯一 ID / flag(平台提供的请求标识,用于后续处理) */
|
|
47
|
-
$id: string;
|
|
48
|
-
/** 适配器名称 */
|
|
29
|
+
export interface RequestBase extends SideEventBase {
|
|
49
30
|
$adapter: keyof Adapters;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
$type: RequestType;
|
|
54
|
-
/** 请求子类型 */
|
|
55
|
-
$subType?: string;
|
|
56
|
-
/** 请求发生的频道/群/会话 */
|
|
57
|
-
$channel: RequestChannel;
|
|
58
|
-
/** 请求发送者 */
|
|
59
|
-
$sender: MessageSender;
|
|
60
|
-
/** 请求附言/验证消息 */
|
|
31
|
+
$type: RequestKind;
|
|
32
|
+
/** 主参与者(必填) */
|
|
33
|
+
$actor: NonNullable<SideEventBase['$actor']>;
|
|
61
34
|
$comment?: string;
|
|
62
|
-
/** 请求时间戳 */
|
|
63
|
-
$timestamp: number;
|
|
64
|
-
/**
|
|
65
|
-
* 同意请求
|
|
66
|
-
* @param remark 备注信息(如好友备注)
|
|
67
|
-
*/
|
|
68
35
|
$approve(remark?: string): MaybePromise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* 拒绝请求
|
|
71
|
-
* @param reason 拒绝原因
|
|
72
|
-
*/
|
|
73
36
|
$reject(reason?: string): MaybePromise<void>;
|
|
74
37
|
}
|
|
75
|
-
/**
|
|
76
|
-
* 完整请求类型,支持平台原始数据扩展
|
|
77
|
-
*/
|
|
78
38
|
export type Request<T extends object = {}> = RequestBase & T;
|
|
79
39
|
export declare namespace Request {
|
|
80
|
-
/**
|
|
81
|
-
* 工具方法:合并自定义字段与基础请求结构
|
|
82
|
-
*/
|
|
83
40
|
function from<T extends object>(input: T, format: RequestBase): Request<T>;
|
|
84
41
|
}
|
package/lib/request.js
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Adapters } from '../adapter.js';
|
|
2
|
+
import type { MessageSender } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Side Event 共享基础结构(Notice 与 Request 共用)。
|
|
5
|
+
* 字段统一为 `$foo_bar` 命名。
|
|
6
|
+
*
|
|
7
|
+
* 完整事件名:`${$type}.${$scene_type}.${$sub_type}`(见 `formatSideEventName`)。
|
|
8
|
+
*/
|
|
9
|
+
export interface SideEventBase {
|
|
10
|
+
/** 平台侧去重键 / flag(非 DB 行 id) */
|
|
11
|
+
$id: string;
|
|
12
|
+
$adapter: keyof Adapters;
|
|
13
|
+
$endpoint: string;
|
|
14
|
+
/** 命名空间:`notice` 或 `request` */
|
|
15
|
+
$type: string;
|
|
16
|
+
/** 平台场景 ID(群号、用户号、频道 ID 等) */
|
|
17
|
+
$scene_id: string;
|
|
18
|
+
/** 场景域(如 group、friend、channel、endpoint) */
|
|
19
|
+
$scene_type?: string;
|
|
20
|
+
/** 动作子类型(如 member_increase、add、poke) */
|
|
21
|
+
$sub_type?: string;
|
|
22
|
+
/** 主参与者(原 Notice.$operator / Request.$sender) */
|
|
23
|
+
$actor?: MessageSender;
|
|
24
|
+
/** 被操作对象 */
|
|
25
|
+
$target?: MessageSender;
|
|
26
|
+
/** 毫秒时间戳 */
|
|
27
|
+
$timestamp: number;
|
|
28
|
+
}
|
|
29
|
+
/** 组合 Side Event 完整类型名 */
|
|
30
|
+
export declare function composeSideEventName(type: string, sceneType: string | undefined, subType: string | undefined): string;
|
|
31
|
+
/** 从 Side Event 字段生成完整类型名 */
|
|
32
|
+
export declare function formatSideEventName(event: Pick<SideEventBase, '$type' | '$scene_type' | '$sub_type'>): string;
|
|
33
|
+
/** 判断 Side Event 是否匹配完整类型名(如 `notice.group.member_increase`) */
|
|
34
|
+
export declare function matchesSideEventName(event: Pick<SideEventBase, '$type' | '$scene_type' | '$sub_type'>, fullName: string): boolean;
|
|
35
|
+
/** 解析完整类型名为三段 */
|
|
36
|
+
export declare function parseSideEventName(fullName: string): {
|
|
37
|
+
type: string;
|
|
38
|
+
scene_type?: string;
|
|
39
|
+
sub_type?: string;
|
|
40
|
+
};
|
|
41
|
+
/** 将 Side Event 场景映射为 IM 发送通道(group-suite 等消费者用) */
|
|
42
|
+
export declare function sideEventSendChannel(event: Pick<SideEventBase, '$scene_type' | '$scene_id'>): {
|
|
43
|
+
id: string;
|
|
44
|
+
type: 'group' | 'private' | 'channel';
|
|
45
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** 组合 Side Event 完整类型名 */
|
|
2
|
+
export function composeSideEventName(type, sceneType, subType) {
|
|
3
|
+
return [type, sceneType, subType].filter((p) => !!p).join('.');
|
|
4
|
+
}
|
|
5
|
+
/** 从 Side Event 字段生成完整类型名 */
|
|
6
|
+
export function formatSideEventName(event) {
|
|
7
|
+
return composeSideEventName(event.$type, event.$scene_type, event.$sub_type);
|
|
8
|
+
}
|
|
9
|
+
/** 判断 Side Event 是否匹配完整类型名(如 `notice.group.member_increase`) */
|
|
10
|
+
export function matchesSideEventName(event, fullName) {
|
|
11
|
+
return formatSideEventName(event) === fullName;
|
|
12
|
+
}
|
|
13
|
+
/** 解析完整类型名为三段 */
|
|
14
|
+
export function parseSideEventName(fullName) {
|
|
15
|
+
const parts = fullName.split('.');
|
|
16
|
+
return {
|
|
17
|
+
type: parts[0] ?? '',
|
|
18
|
+
scene_type: parts[1],
|
|
19
|
+
sub_type: parts.slice(2).join('.') || undefined,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** 将 Side Event 场景映射为 IM 发送通道(group-suite 等消费者用) */
|
|
23
|
+
export function sideEventSendChannel(event) {
|
|
24
|
+
const domain = event.$scene_type ?? 'private';
|
|
25
|
+
if (domain === 'group')
|
|
26
|
+
return { id: event.$scene_id, type: 'group' };
|
|
27
|
+
if (domain === 'channel')
|
|
28
|
+
return { id: event.$scene_id, type: 'channel' };
|
|
29
|
+
return { id: event.$scene_id, type: 'private' };
|
|
30
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Notice, type NoticeBase } from '../notice.js';
|
|
2
|
+
import { Request, type RequestBase } from '../request.js';
|
|
3
|
+
import { type ComposedNoticeName, type ComposedRequestName, type SideEventParts } from './types.js';
|
|
4
|
+
export type SideEventPlatform = 'onebot' | 'icqq' | 'napcat' | 'kook' | (string & {});
|
|
5
|
+
export interface OneBotLikeRawEvent {
|
|
6
|
+
notice_type?: string;
|
|
7
|
+
request_type?: string;
|
|
8
|
+
sub_type?: string;
|
|
9
|
+
group_id?: number | string;
|
|
10
|
+
user_id?: number | string;
|
|
11
|
+
operator_id?: number | string;
|
|
12
|
+
flag?: string;
|
|
13
|
+
time?: number;
|
|
14
|
+
self_id?: number | string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** 去重用:notice / request 无稳定 id 时组合键 */
|
|
18
|
+
export declare function resolveSideEventDedupeKey(data: OneBotLikeRawEvent, kind: 'notice' | 'request'): string;
|
|
19
|
+
/**
|
|
20
|
+
* 将平台原始 notice_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
21
|
+
*/
|
|
22
|
+
export declare function mapNoticeParts(platform: SideEventPlatform, raw: string, options?: {
|
|
23
|
+
sub_type?: string;
|
|
24
|
+
is_group?: boolean;
|
|
25
|
+
notify_handler?: (subType: string | undefined, isGroup: boolean) => SideEventParts;
|
|
26
|
+
}): SideEventParts;
|
|
27
|
+
/**
|
|
28
|
+
* 将平台原始 request_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
29
|
+
*/
|
|
30
|
+
export declare function mapRequestParts(_platform: SideEventPlatform, raw: string, subType?: string): SideEventParts;
|
|
31
|
+
/** 组合完整 Notice 类型名(兼容旧 API) */
|
|
32
|
+
export declare function mapNoticeType(platform: SideEventPlatform, raw: string, options?: Parameters<typeof mapNoticeParts>[2]): ComposedNoticeName;
|
|
33
|
+
/** 组合完整 Request 类型名(兼容旧 API) */
|
|
34
|
+
export declare function mapRequestType(platform: SideEventPlatform, raw: string, subType?: string): ComposedRequestName;
|
|
35
|
+
export declare function senderFromId(id: unknown, name?: string): {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
} | undefined;
|
|
39
|
+
export declare function buildNotice<T extends object>(input: T, format: NoticeBase): Notice<T>;
|
|
40
|
+
export declare function buildRequest<T extends object>(input: T, format: RequestBase): Request<T>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Notice } from '../notice.js';
|
|
2
|
+
import { Request } from '../request.js';
|
|
3
|
+
import { composeSideEventName, parseSideEventName, } from './base.js';
|
|
4
|
+
import { KOOK_NOTICE_PARTS_MAP, ONEBOT_NOTICE_PARTS_MAP, SLACK_NOTICE_PARTS_MAP } from './types.js';
|
|
5
|
+
/** 去重用:notice / request 无稳定 id 时组合键 */
|
|
6
|
+
export function resolveSideEventDedupeKey(data, kind) {
|
|
7
|
+
if (data.flag != null && String(data.flag) !== '') {
|
|
8
|
+
return `${kind}:${data.flag}`;
|
|
9
|
+
}
|
|
10
|
+
const time = data.time ?? 0;
|
|
11
|
+
const type = data.notice_type ?? data.request_type ?? kind;
|
|
12
|
+
const scope = data.group_id ?? data.user_id ?? '';
|
|
13
|
+
const sub = data.sub_type ?? '';
|
|
14
|
+
return `${kind}:${time}_${type}_${scope}_${sub}`;
|
|
15
|
+
}
|
|
16
|
+
function resolveNotifyNoticeParts(subType, isGroup) {
|
|
17
|
+
if (subType === 'poke') {
|
|
18
|
+
return isGroup
|
|
19
|
+
? { scene_type: 'group', sub_type: 'poke' }
|
|
20
|
+
: { scene_type: 'friend', sub_type: 'poke' };
|
|
21
|
+
}
|
|
22
|
+
if (subType === 'input_status')
|
|
23
|
+
return { scene_type: 'notify', sub_type: 'input_status' };
|
|
24
|
+
if (subType === 'title')
|
|
25
|
+
return { scene_type: 'notify', sub_type: 'title_change' };
|
|
26
|
+
if (subType === 'profile_like')
|
|
27
|
+
return { scene_type: 'notify', sub_type: 'profile_like' };
|
|
28
|
+
return { scene_type: 'notify', sub_type: subType ?? 'unknown' };
|
|
29
|
+
}
|
|
30
|
+
function resolveEssenceNoticeParts(subType) {
|
|
31
|
+
return subType === 'add'
|
|
32
|
+
? { scene_type: 'group', sub_type: 'essence_add' }
|
|
33
|
+
: { scene_type: 'group', sub_type: 'essence_delete' };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 将平台原始 notice_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
37
|
+
*/
|
|
38
|
+
export function mapNoticeParts(platform, raw, options) {
|
|
39
|
+
const subType = options?.sub_type;
|
|
40
|
+
const isGroup = options?.is_group ?? false;
|
|
41
|
+
if (platform === 'kook') {
|
|
42
|
+
return KOOK_NOTICE_PARTS_MAP[raw] ?? { scene_type: 'kook', sub_type: raw };
|
|
43
|
+
}
|
|
44
|
+
if (platform === 'slack') {
|
|
45
|
+
return SLACK_NOTICE_PARTS_MAP[raw] ?? { scene_type: 'slack', sub_type: raw };
|
|
46
|
+
}
|
|
47
|
+
if (raw === 'notify') {
|
|
48
|
+
const handler = options?.notify_handler ?? resolveNotifyNoticeParts;
|
|
49
|
+
return handler(subType, isGroup);
|
|
50
|
+
}
|
|
51
|
+
if (raw === 'essence') {
|
|
52
|
+
return resolveEssenceNoticeParts(subType);
|
|
53
|
+
}
|
|
54
|
+
if (ONEBOT_NOTICE_PARTS_MAP[raw]) {
|
|
55
|
+
return ONEBOT_NOTICE_PARTS_MAP[raw];
|
|
56
|
+
}
|
|
57
|
+
if (raw.startsWith('notice.')) {
|
|
58
|
+
const parsed = parseSideEventName(raw);
|
|
59
|
+
if (parsed.scene_type && parsed.sub_type) {
|
|
60
|
+
return { scene_type: parsed.scene_type, sub_type: parsed.sub_type };
|
|
61
|
+
}
|
|
62
|
+
const suffix = raw.slice('notice.'.length).replace(/\./g, '_');
|
|
63
|
+
if (ONEBOT_NOTICE_PARTS_MAP[suffix])
|
|
64
|
+
return ONEBOT_NOTICE_PARTS_MAP[suffix];
|
|
65
|
+
return { scene_type: parsed.scene_type ?? 'unknown', sub_type: parsed.sub_type ?? suffix };
|
|
66
|
+
}
|
|
67
|
+
if (platform === 'icqq' || platform === 'onebot' || platform === 'napcat') {
|
|
68
|
+
const dotted = raw.replace(/_/g, '.');
|
|
69
|
+
const parsed = parseSideEventName(`notice.${dotted}`);
|
|
70
|
+
return {
|
|
71
|
+
scene_type: parsed.scene_type ?? dotted.split('.')[0] ?? 'unknown',
|
|
72
|
+
sub_type: parsed.sub_type ?? (dotted.split('.').slice(1).join('.') || raw),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return { scene_type: platform, sub_type: raw };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 将平台原始 request_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
79
|
+
*/
|
|
80
|
+
export function mapRequestParts(_platform, raw, subType) {
|
|
81
|
+
if (raw === 'friend' || raw.startsWith('friend')) {
|
|
82
|
+
return { scene_type: 'friend', sub_type: 'add' };
|
|
83
|
+
}
|
|
84
|
+
if (raw === 'group' || raw.startsWith('group')) {
|
|
85
|
+
return { scene_type: 'group', sub_type: subType === 'invite' ? 'invite' : 'add' };
|
|
86
|
+
}
|
|
87
|
+
if (raw.startsWith('request.')) {
|
|
88
|
+
const parsed = parseSideEventName(raw);
|
|
89
|
+
return {
|
|
90
|
+
scene_type: parsed.scene_type ?? 'unknown',
|
|
91
|
+
sub_type: parsed.sub_type ?? 'unknown',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return { scene_type: raw, sub_type: subType ?? 'unknown' };
|
|
95
|
+
}
|
|
96
|
+
/** 组合完整 Notice 类型名(兼容旧 API) */
|
|
97
|
+
export function mapNoticeType(platform, raw, options) {
|
|
98
|
+
const parts = mapNoticeParts(platform, raw, options);
|
|
99
|
+
return composeSideEventName('notice', parts.scene_type, parts.sub_type);
|
|
100
|
+
}
|
|
101
|
+
/** 组合完整 Request 类型名(兼容旧 API) */
|
|
102
|
+
export function mapRequestType(platform, raw, subType) {
|
|
103
|
+
const parts = mapRequestParts(platform, raw, subType);
|
|
104
|
+
return composeSideEventName('request', parts.scene_type, parts.sub_type);
|
|
105
|
+
}
|
|
106
|
+
export function senderFromId(id, name) {
|
|
107
|
+
if (id == null || id === '')
|
|
108
|
+
return undefined;
|
|
109
|
+
const s = String(id);
|
|
110
|
+
return { id: s, name: name ?? s };
|
|
111
|
+
}
|
|
112
|
+
export function buildNotice(input, format) {
|
|
113
|
+
return Notice.from(input, format);
|
|
114
|
+
}
|
|
115
|
+
export function buildRequest(input, format) {
|
|
116
|
+
return Request.from(input, format);
|
|
117
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side Event 标准类型。
|
|
3
|
+
* 运行时 `$type` 仅存命名空间(`notice` / `request`);
|
|
4
|
+
* 完整名由 `${$type}.${$scene_type}.${$sub_type}` 组合。
|
|
5
|
+
*/
|
|
6
|
+
export type SideEventKind = 'notice' | 'request';
|
|
7
|
+
export type NoticeKind = 'notice';
|
|
8
|
+
export type RequestKind = 'request';
|
|
9
|
+
/** 完整组合名(测试 / 文档 / 消费者匹配用) */
|
|
10
|
+
export type ComposedNoticeName = 'notice.group.member_increase' | 'notice.group.member_decrease' | 'notice.group.admin_change' | 'notice.group.ban' | 'notice.group.recall' | 'notice.group.poke' | 'notice.group.transfer' | 'notice.group.upload' | 'notice.group.emoji_reaction' | 'notice.group.card_change' | 'notice.group.essence_add' | 'notice.group.essence_delete' | 'notice.friend.recall' | 'notice.friend.increase' | 'notice.friend.poke' | 'notice.endpoint.lifecycle' | (string & {});
|
|
11
|
+
export type ComposedRequestName = 'request.friend.add' | 'request.group.add' | 'request.group.invite' | (string & {});
|
|
12
|
+
/** @deprecated 使用 ComposedNoticeName + formatSideEventName */
|
|
13
|
+
export type NoticeType = ComposedNoticeName;
|
|
14
|
+
/** @deprecated 使用 ComposedRequestName + formatSideEventName */
|
|
15
|
+
export type RequestType = ComposedRequestName;
|
|
16
|
+
export interface SideEventParts {
|
|
17
|
+
scene_type: string;
|
|
18
|
+
sub_type: string;
|
|
19
|
+
}
|
|
20
|
+
/** OneBot / icqq 等平台 notice_type 原始值 → 标准 scene_type + sub_type */
|
|
21
|
+
export declare const ONEBOT_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
|
|
22
|
+
/** KOOK extra.type 原始值 → 标准 scene_type + sub_type */
|
|
23
|
+
export declare const KOOK_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
|
|
24
|
+
/** Slack event type 原始值 → 标准 scene_type + sub_type */
|
|
25
|
+
export declare const SLACK_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side Event 标准类型。
|
|
3
|
+
* 运行时 `$type` 仅存命名空间(`notice` / `request`);
|
|
4
|
+
* 完整名由 `${$type}.${$scene_type}.${$sub_type}` 组合。
|
|
5
|
+
*/
|
|
6
|
+
/** OneBot / icqq 等平台 notice_type 原始值 → 标准 scene_type + sub_type */
|
|
7
|
+
export const ONEBOT_NOTICE_PARTS_MAP = {
|
|
8
|
+
group_increase: { scene_type: 'group', sub_type: 'member_increase' },
|
|
9
|
+
group_decrease: { scene_type: 'group', sub_type: 'member_decrease' },
|
|
10
|
+
group_admin: { scene_type: 'group', sub_type: 'admin_change' },
|
|
11
|
+
group_ban: { scene_type: 'group', sub_type: 'ban' },
|
|
12
|
+
group_recall: { scene_type: 'group', sub_type: 'recall' },
|
|
13
|
+
friend_recall: { scene_type: 'friend', sub_type: 'recall' },
|
|
14
|
+
friend_add: { scene_type: 'friend', sub_type: 'increase' },
|
|
15
|
+
group_upload: { scene_type: 'group', sub_type: 'upload' },
|
|
16
|
+
group_transfer: { scene_type: 'group', sub_type: 'transfer' },
|
|
17
|
+
group_card: { scene_type: 'group', sub_type: 'card_change' },
|
|
18
|
+
group_msg_emoji_like: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
19
|
+
'group.increase': { scene_type: 'group', sub_type: 'member_increase' },
|
|
20
|
+
'group.decrease': { scene_type: 'group', sub_type: 'member_decrease' },
|
|
21
|
+
'group.admin': { scene_type: 'group', sub_type: 'admin_change' },
|
|
22
|
+
'group.ban': { scene_type: 'group', sub_type: 'ban' },
|
|
23
|
+
'group.recall': { scene_type: 'group', sub_type: 'recall' },
|
|
24
|
+
'friend.increase': { scene_type: 'friend', sub_type: 'increase' },
|
|
25
|
+
'friend.decrease': { scene_type: 'friend', sub_type: 'recall' },
|
|
26
|
+
'friend.recall': { scene_type: 'friend', sub_type: 'recall' },
|
|
27
|
+
};
|
|
28
|
+
/** KOOK extra.type 原始值 → 标准 scene_type + sub_type */
|
|
29
|
+
export const KOOK_NOTICE_PARTS_MAP = {
|
|
30
|
+
joined_guild: { scene_type: 'group', sub_type: 'member_increase' },
|
|
31
|
+
exited_guild: { scene_type: 'group', sub_type: 'member_decrease' },
|
|
32
|
+
deleted_message: { scene_type: 'group', sub_type: 'recall' },
|
|
33
|
+
deleted_private_message: { scene_type: 'friend', sub_type: 'recall' },
|
|
34
|
+
added_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
35
|
+
deleted_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
36
|
+
private_added_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
37
|
+
private_deleted_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
38
|
+
};
|
|
39
|
+
/** Slack event type 原始值 → 标准 scene_type + sub_type */
|
|
40
|
+
export const SLACK_NOTICE_PARTS_MAP = {
|
|
41
|
+
member_joined_channel: { scene_type: 'group', sub_type: 'member_increase' },
|
|
42
|
+
member_left_channel: { scene_type: 'group', sub_type: 'member_decrease' },
|
|
43
|
+
reaction_added: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
44
|
+
reaction_removed: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
45
|
+
message_deleted: { scene_type: 'group', sub_type: 'recall' },
|
|
46
|
+
channel_archive: { scene_type: 'slack', sub_type: 'channel_archive' },
|
|
47
|
+
channel_unarchive: { scene_type: 'slack', sub_type: 'channel_unarchive' },
|
|
48
|
+
channel_rename: { scene_type: 'slack', sub_type: 'channel_rename' },
|
|
49
|
+
channel_created: { scene_type: 'slack', sub_type: 'channel_created' },
|
|
50
|
+
channel_deleted: { scene_type: 'slack', sub_type: 'channel_deleted' },
|
|
51
|
+
pin_added: { scene_type: 'slack', sub_type: 'pin_added' },
|
|
52
|
+
pin_removed: { scene_type: 'slack', sub_type: 'pin_removed' },
|
|
53
|
+
app_home_opened: { scene_type: 'slack', sub_type: 'app_home_opened' },
|
|
54
|
+
team_join: { scene_type: 'friend', sub_type: 'increase' },
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/core",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "Zhin机器人核心框架",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
"development": "./src/built/queue-im-field-contract.ts",
|
|
22
22
|
"import": "./lib/built/queue-im-field-contract.js"
|
|
23
23
|
},
|
|
24
|
+
"./runtime": {
|
|
25
|
+
"types": "./lib/plugin-runtime/im/index.d.ts",
|
|
26
|
+
"development": "./src/plugin-runtime/im/index.ts",
|
|
27
|
+
"import": "./lib/plugin-runtime/im/index.js"
|
|
28
|
+
},
|
|
24
29
|
"./jsx": {
|
|
25
30
|
"types": "./lib/jsx.d.ts",
|
|
26
31
|
"development": "./src/jsx.ts",
|
|
@@ -45,9 +50,14 @@
|
|
|
45
50
|
"segment-matcher": "^1.0.5",
|
|
46
51
|
"smol-toml": "^1.7.0",
|
|
47
52
|
"yaml": "^2.9.0",
|
|
48
|
-
"@zhin.js/
|
|
49
|
-
"@zhin.js/
|
|
50
|
-
"@zhin.js/
|
|
53
|
+
"@zhin.js/adapter": "1.0.1",
|
|
54
|
+
"@zhin.js/command": "1.0.1",
|
|
55
|
+
"@zhin.js/component": "1.0.1",
|
|
56
|
+
"@zhin.js/kernel": "1.0.4",
|
|
57
|
+
"@zhin.js/logger": "1.0.75",
|
|
58
|
+
"@zhin.js/middleware": "1.0.1",
|
|
59
|
+
"@zhin.js/plugin-runtime": "1.0.1",
|
|
60
|
+
"@zhin.js/database": "1.0.77",
|
|
51
61
|
"@zhin.js/schema": "1.0.71"
|
|
52
62
|
},
|
|
53
63
|
"peerDependencies": {
|
|
@@ -62,7 +72,7 @@
|
|
|
62
72
|
"@types/node": "^26.1.0",
|
|
63
73
|
"@types/qrcode": "^1.5.5",
|
|
64
74
|
"typescript": "^6.0.3",
|
|
65
|
-
"@zhin.js/ai": "1.4.
|
|
75
|
+
"@zhin.js/ai": "1.4.5"
|
|
66
76
|
},
|
|
67
77
|
"repository": {
|
|
68
78
|
"type": "git",
|