@zhin.js/core 1.1.54 → 1.1.56

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.
Files changed (40) hide show
  1. package/lib/built/interaction-messages.d.ts +1 -1
  2. package/lib/index.d.ts +3 -0
  3. package/lib/index.js +1 -0
  4. package/lib/jsx/message-tags.d.ts +3 -3
  5. package/lib/jsx/message-tags.js +3 -0
  6. package/lib/plugin-runtime/im/captured-endpoint-operation.d.ts +5 -1
  7. package/lib/plugin-runtime/im/command-menu-navigation.d.ts +1 -1
  8. package/lib/plugin-runtime/im/command-menu-navigation.js +2 -1
  9. package/lib/plugin-runtime/im/contracts.d.ts +8 -1
  10. package/lib/plugin-runtime/im/contracts.js +20 -1
  11. package/lib/plugin-runtime/im/conversation-runtime.d.ts +2 -0
  12. package/lib/plugin-runtime/im/conversation-runtime.js +41 -4
  13. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +4 -1
  14. package/lib/plugin-runtime/im/endpoint-runtime.js +38 -2
  15. package/lib/plugin-runtime/im/im-runtime.js +12 -4
  16. package/lib/plugin-runtime/im/inbound-runtime.d.ts +8 -1
  17. package/lib/plugin-runtime/im/inbound-runtime.js +1 -0
  18. package/lib/plugin-runtime/im/index.d.ts +2 -0
  19. package/lib/plugin-runtime/im/index.js +1 -0
  20. package/lib/plugin-runtime/im/message-dispatcher.js +2 -1
  21. package/lib/plugin-runtime/im/operation-resources.d.ts +15 -0
  22. package/lib/plugin-runtime/im/operation-resources.js +2 -0
  23. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +16 -2
  24. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +49 -14
  25. package/lib/plugin-runtime/im/outbound-segments.d.ts +1 -1
  26. package/lib/plugin-runtime/im/outbound-segments.js +2 -20
  27. package/lib/plugin-runtime/im/progressive-reply.d.ts +52 -0
  28. package/lib/plugin-runtime/im/progressive-reply.js +495 -0
  29. package/lib/plugin-runtime/im/runtime-middleware.d.ts +2 -0
  30. package/lib/plugin-runtime/im/runtime-middleware.js +5 -0
  31. package/lib/side-event/index.d.ts +0 -1
  32. package/lib/side-event/index.js +0 -1
  33. package/lib/side-event/normalize.d.ts +0 -28
  34. package/lib/side-event/normalize.js +0 -100
  35. package/lib/side-event/scene-events.js +1 -1
  36. package/lib/side-event/types.d.ts +0 -6
  37. package/lib/side-event/types.js +1 -57
  38. package/package.json +15 -15
  39. package/lib/side-event/dispatch.d.ts +0 -15
  40. package/lib/side-event/dispatch.js +0 -168
@@ -28,7 +28,7 @@ export const SCENE_EVENT_TEXT_MAX = 40;
28
28
  export function isSceneEvent(event) {
29
29
  return SCENE_EVENT_TYPES.includes(event.type);
30
30
  }
31
- /** OneBot 等平台以 user_id 0 表示「全员」。 */
31
+ /** 部分平台以 user_id 0 表示「全员」。 */
32
32
  const WHOLE_SCENE_IDS = new Set(['0', 'all']);
33
33
  /**
34
34
  * 事件优先级;不是场景事件时返回 undefined。
@@ -12,9 +12,3 @@ export interface SideEventParts {
12
12
  scene_type: string;
13
13
  sub_type: string;
14
14
  }
15
- /** OneBot / icqq 等平台 notice_type 原始值 → 标准 scene_type + sub_type */
16
- export declare const ONEBOT_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
17
- /** KOOK extra.type 原始值 → 标准 scene_type + sub_type */
18
- export declare const KOOK_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
19
- /** Slack event type 原始值 → 标准 scene_type + sub_type */
20
- export declare const SLACK_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
@@ -1,57 +1 @@
1
- /** OneBot / icqq 等平台 notice_type 原始值 → 标准 scene_type + sub_type */
2
- export const ONEBOT_NOTICE_PARTS_MAP = {
3
- group_increase: { scene_type: 'group', sub_type: 'member_increase' },
4
- group_decrease: { scene_type: 'group', sub_type: 'member_decrease' },
5
- group_admin: { scene_type: 'group', sub_type: 'admin_change' },
6
- group_ban: { scene_type: 'group', sub_type: 'ban' },
7
- group_recall: { scene_type: 'group', sub_type: 'recall' },
8
- friend_recall: { scene_type: 'friend', sub_type: 'recall' },
9
- friend_add: { scene_type: 'friend', sub_type: 'increase' },
10
- group_upload: { scene_type: 'group', sub_type: 'upload' },
11
- group_transfer: { scene_type: 'group', sub_type: 'transfer' },
12
- group_card: { scene_type: 'group', sub_type: 'card_change' },
13
- group_msg_emoji_like: { scene_type: 'group', sub_type: 'emoji_reaction' },
14
- 'group.increase': { scene_type: 'group', sub_type: 'member_increase' },
15
- 'group.decrease': { scene_type: 'group', sub_type: 'member_decrease' },
16
- 'group.admin': { scene_type: 'group', sub_type: 'admin_change' },
17
- 'group.ban': { scene_type: 'group', sub_type: 'ban' },
18
- 'group.recall': { scene_type: 'group', sub_type: 'recall' },
19
- 'friend.increase': { scene_type: 'friend', sub_type: 'increase' },
20
- 'friend.decrease': { scene_type: 'friend', sub_type: 'recall' },
21
- 'friend.recall': { scene_type: 'friend', sub_type: 'recall' },
22
- // icqq: notice_type=group + sub_type(#996 状态感知补齐)
23
- 'group.poke': { scene_type: 'group', sub_type: 'poke' },
24
- 'group.reaction': { scene_type: 'group', sub_type: 'emoji_reaction' },
25
- 'group.transfer': { scene_type: 'group', sub_type: 'transfer' },
26
- 'group.card': { scene_type: 'group', sub_type: 'card_change' },
27
- 'group.notice': { scene_type: 'group', sub_type: 'notice_updated' },
28
- group_notice: { scene_type: 'group', sub_type: 'notice_updated' },
29
- };
30
- /** KOOK extra.type 原始值 → 标准 scene_type + sub_type */
31
- export const KOOK_NOTICE_PARTS_MAP = {
32
- joined_guild: { scene_type: 'group', sub_type: 'member_increase' },
33
- exited_guild: { scene_type: 'group', sub_type: 'member_decrease' },
34
- deleted_message: { scene_type: 'group', sub_type: 'recall' },
35
- deleted_private_message: { scene_type: 'friend', sub_type: 'recall' },
36
- added_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
37
- deleted_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
38
- private_added_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
39
- private_deleted_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
40
- };
41
- /** Slack event type 原始值 → 标准 scene_type + sub_type */
42
- export const SLACK_NOTICE_PARTS_MAP = {
43
- member_joined_channel: { scene_type: 'group', sub_type: 'member_increase' },
44
- member_left_channel: { scene_type: 'group', sub_type: 'member_decrease' },
45
- reaction_added: { scene_type: 'group', sub_type: 'emoji_reaction' },
46
- reaction_removed: { scene_type: 'group', sub_type: 'emoji_reaction' },
47
- message_deleted: { scene_type: 'group', sub_type: 'recall' },
48
- channel_archive: { scene_type: 'slack', sub_type: 'channel_archive' },
49
- channel_unarchive: { scene_type: 'slack', sub_type: 'channel_unarchive' },
50
- channel_rename: { scene_type: 'slack', sub_type: 'channel_rename' },
51
- channel_created: { scene_type: 'slack', sub_type: 'channel_created' },
52
- channel_deleted: { scene_type: 'slack', sub_type: 'channel_deleted' },
53
- pin_added: { scene_type: 'slack', sub_type: 'pin_added' },
54
- pin_removed: { scene_type: 'slack', sub_type: 'pin_removed' },
55
- app_home_opened: { scene_type: 'slack', sub_type: 'app_home_opened' },
56
- team_join: { scene_type: 'friend', sub_type: 'increase' },
57
- };
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/core",
3
- "version": "1.1.54",
3
+ "version": "1.1.56",
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.26",
61
- "@zhin.js/command": "1.1.12",
62
- "@zhin.js/component": "1.1.11",
63
- "@zhin.js/database": "1.1.5",
64
- "@zhin.js/handler": "1.1.10",
65
- "@zhin.js/im-contract": "1.1.9",
60
+ "@zhin.js/command": "1.1.14",
61
+ "@zhin.js/component": "1.1.13",
62
+ "@zhin.js/adapter": "1.1.28",
63
+ "@zhin.js/handler": "1.1.12",
64
+ "@zhin.js/im-contract": "1.1.11",
65
+ "@zhin.js/database": "1.1.6",
66
66
  "@zhin.js/interaction": "1.1.2",
67
67
  "@zhin.js/kernel": "1.1.5",
68
68
  "@zhin.js/logger": "1.1.2",
69
- "@zhin.js/middleware": "1.1.11",
70
- "@zhin.js/permission": "1.1.10",
71
- "@zhin.js/plugin-runtime": "1.1.18",
72
- "@zhin.js/schedule-feature": "1.1.10",
69
+ "@zhin.js/middleware": "1.1.13",
70
+ "@zhin.js/permission": "1.1.12",
71
+ "@zhin.js/plugin-runtime": "1.1.20",
72
+ "@zhin.js/schedule-feature": "1.1.12",
73
73
  "@zhin.js/schema": "1.1.4",
74
- "@zhin.js/jsx": "1.1.8",
75
- "@zhin.js/feature-kit": "1.1.10"
74
+ "@zhin.js/jsx": "1.1.10",
75
+ "@zhin.js/feature-kit": "1.1.12"
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.49"
82
+ "@zhin.js/ai": "1.1.51"
83
83
  },
84
84
  "repository": {
85
85
  "type": "git",
@@ -108,7 +108,7 @@
108
108
  "features": [
109
109
  {
110
110
  "package": "@zhin.js/adapter",
111
- "api": "^2.0.0"
111
+ "api": "^2.1.0"
112
112
  },
113
113
  {
114
114
  "package": "@zhin.js/command",
@@ -1,15 +0,0 @@
1
- import type { EndpointEventEmitter } from '@zhin.js/adapter';
2
- import { type OneBotLikeRawEvent, type SideEventPlatform } from './normalize.js';
3
- export interface OneBotLikeSideEventInput {
4
- readonly adapter: string;
5
- readonly endpointKey: string;
6
- readonly platform?: SideEventPlatform;
7
- readonly raw: OneBotLikeRawEvent;
8
- readonly approve?: (flag: string, remark?: string) => void | Promise<void>;
9
- readonly reject?: (flag: string, reason?: string) => void | Promise<void>;
10
- }
11
- /**
12
- * Normalize OneBot / icqq-style notice|request|meta payloads and feed Endpoint.emit().
13
- * Returns which kind was dispatched, or null when the payload is not a side event.
14
- */
15
- export declare function receiveOneBotLikeSideEvent(emit: EndpointEventEmitter, input: OneBotLikeSideEventInput): Promise<'notice' | 'request' | 'system' | null>;
@@ -1,168 +0,0 @@
1
- import { composeSideEventName, sideEventConversation } from './base.js';
2
- import { buildNotice, buildRequest, buildSystem, mapNoticeParts, mapRequestParts, resolveSideEventDedupeKey, senderFromId, } from './normalize.js';
3
- /**
4
- * Normalize OneBot / icqq-style notice|request|meta payloads and feed Endpoint.emit().
5
- * Returns which kind was dispatched, or null when the payload is not a side event.
6
- */
7
- export async function receiveOneBotLikeSideEvent(emit, input) {
8
- const raw = input.raw;
9
- const platform = input.platform ?? 'onebot';
10
- const postType = String(raw.post_type ?? raw.type ?? '');
11
- if (postType === 'notice' || postType.startsWith('notice.')) {
12
- const noticeType = String(raw.notice_type ?? (postType.replace(/^notice\.?/, '') || 'unknown'));
13
- const parts = mapNoticeParts(platform, noticeType, {
14
- sub_type: raw.sub_type != null ? String(raw.sub_type) : undefined,
15
- is_group: raw.group_id != null,
16
- });
17
- const id = resolveSideEventDedupeKey(raw, 'notice');
18
- const memberEvent = ['member_increase', 'member_decrease', 'ban', 'admin_change'].includes(parts.sub_type);
19
- const actorId = raw.operator_id
20
- ?? (!memberEvent ? raw.user_id : undefined);
21
- const targetId = memberEvent
22
- ? raw.user_id
23
- : parts.sub_type === 'poke'
24
- ? raw.target_id ?? raw.self_id
25
- : raw.user_id != null && String(raw.user_id) !== String(raw.operator_id ?? '')
26
- ? raw.user_id
27
- : undefined;
28
- const notice = buildNotice(raw, {
29
- id,
30
- clientAdapter: input.adapter,
31
- endpointId: input.endpointKey,
32
- type: 'notice',
33
- conversation: oneBotConversation(parts.scene_type, raw),
34
- name: composeSideEventName('notice', parts.scene_type, parts.sub_type),
35
- actor: senderFromId(actorId),
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),
41
- timestamp: toMillis(raw.time),
42
- ...(raw.message_id != null
43
- ? { messageId: String(raw.message_id) }
44
- // icqq 群表情回应只给被回应消息的 seq
45
- : parts.sub_type === 'emoji_reaction' && raw.seq != null ? { messageId: `seq:${String(raw.seq)}` } : {}),
46
- ...(raw.emoji_id != null || raw.code != null
47
- ? { reaction: String(raw.emoji_id ?? raw.code) }
48
- : parts.sub_type === 'emoji_reaction' && raw.id != null ? { reaction: String(raw.id) } : {}),
49
- ...(parts.sub_type === 'emoji_reaction'
50
- ? {
51
- operation: raw.set === false || /delete|remove/i.test(String(raw.sub_type ?? noticeType))
52
- ? 'removed'
53
- : 'added',
54
- }
55
- : {}),
56
- ...(raw.duration != null ? { durationSeconds: Math.max(0, Number(raw.duration) || 0) } : {}),
57
- ...(parts.sub_type === 'admin_change'
58
- ? { role: 'admin', enabled: typeof raw.set === 'boolean' ? raw.set : String(raw.sub_type ?? '') === 'set' }
59
- : {}),
60
- ...sideEventValue(parts.sub_type, raw),
61
- });
62
- await emit('notice.receive', notice);
63
- return 'notice';
64
- }
65
- if (postType === 'request' || postType.startsWith('request.')) {
66
- const requestType = String(raw.request_type ?? (postType.replace(/^request\.?/, '') || 'friend'));
67
- const parts = mapRequestParts(platform, requestType, raw.sub_type != null ? String(raw.sub_type) : undefined);
68
- const flag = raw.flag != null ? String(raw.flag) : '';
69
- const id = flag || resolveSideEventDedupeKey(raw, 'request');
70
- const actor = senderFromId(raw.user_id);
71
- if (!actor)
72
- return null;
73
- const approve = input.approve;
74
- const reject = input.reject;
75
- let active = true;
76
- const actions = new Set();
77
- const requireActiveAction = () => {
78
- if (!active)
79
- throw new Error('Request action port expired with its generation operation');
80
- };
81
- const runAction = (action) => {
82
- requireActiveAction();
83
- const operation = Promise.resolve().then(action);
84
- actions.add(operation);
85
- void operation.then(() => actions.delete(operation), () => actions.delete(operation));
86
- return operation;
87
- };
88
- const request = buildRequest(raw, {
89
- id,
90
- clientAdapter: input.adapter,
91
- endpointId: input.endpointKey,
92
- type: 'request',
93
- conversation: oneBotConversation(parts.scene_type, raw),
94
- name: composeSideEventName('request', parts.scene_type, parts.sub_type),
95
- actor,
96
- comment: raw.comment != null ? String(raw.comment) : undefined,
97
- timestamp: toMillis(raw.time),
98
- async $approve(remark) {
99
- if (!approve || !flag)
100
- throw new Error('Request approve is not available');
101
- await runAction(() => approve(flag, remark));
102
- },
103
- async $reject(reason) {
104
- if (!reject || !flag)
105
- throw new Error('Request reject is not available');
106
- await runAction(() => reject(flag, reason));
107
- },
108
- });
109
- try {
110
- await emit('request.receive', request);
111
- }
112
- finally {
113
- active = false;
114
- await Promise.allSettled([...actions]);
115
- }
116
- return 'request';
117
- }
118
- if (postType === 'meta_event'
119
- || postType === 'meta'
120
- || postType.startsWith('meta.')
121
- || postType.startsWith('system.')) {
122
- const metaType = String(raw.meta_event_type
123
- ?? raw.detail_type
124
- ?? (postType.replace(/^(meta_event|meta|system)\.?/, '') || 'unknown'));
125
- const subType = raw.sub_type != null ? String(raw.sub_type) : undefined;
126
- const name = postType.startsWith('system.')
127
- ? (postType.split('.').length === 2 ? composeSideEventName(postType, subType) : postType)
128
- : composeSideEventName('system', metaType, subType);
129
- const system = buildSystem(raw, {
130
- id: `system:${toMillis(raw.time)}_${metaType}_${subType ?? ''}`,
131
- clientAdapter: input.adapter,
132
- endpointId: input.endpointKey,
133
- type: 'system',
134
- name,
135
- timestamp: toMillis(raw.time),
136
- });
137
- await emit('system.receive', system);
138
- return 'system';
139
- }
140
- return null;
141
- }
142
- /** 名片/头衔/备注的新值或公告正文:只取短文本(≤40 字),不带原始结构。 */
143
- function sideEventValue(subType, raw) {
144
- const pick = (...values) => values.find((value) => typeof value === 'string');
145
- const value = subType === 'card_change' ? pick(raw.card_new, raw.card)
146
- : subType === 'title_change' ? pick(raw.title)
147
- : subType === 'remark_change' ? pick(raw.remark)
148
- : subType === 'notice_updated' ? pick(raw.content, raw.text, raw.msg)
149
- : undefined;
150
- if (typeof value !== 'string')
151
- return {};
152
- // eslint-disable-next-line no-control-regex
153
- const flat = value.replace(/[\u0000-\u001f\u007f]+/g, ' ').replace(/\s+/g, ' ').trim();
154
- return { value: flat.length > 40 ? `${flat.slice(0, 39)}…` : flat };
155
- }
156
- function oneBotConversation(sceneType, raw) {
157
- const id = sceneType === 'group' ? raw.group_id
158
- : sceneType === 'channel' ? raw.channel_id
159
- : sceneType === 'private' || sceneType === 'friend' ? raw.user_id
160
- : undefined;
161
- return sideEventConversation(sceneType, id == null ? '' : String(id));
162
- }
163
- function toMillis(time) {
164
- const seconds = Number(time);
165
- return Number.isFinite(seconds) && seconds > 0
166
- ? (seconds < 1e12 ? seconds * 1000 : seconds)
167
- : Date.now();
168
- }