@zhin.js/core 1.5.15 → 1.6.0
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 +78 -195
- package/lib/ai-completion-contract.d.ts +135 -0
- package/lib/ai-completion-contract.js +69 -0
- package/lib/built/ai-access.d.ts +2 -21
- package/lib/built/ai-access.js +1 -46
- package/lib/built/ai-outbound/index.d.ts +0 -2
- package/lib/built/ai-outbound/index.js +0 -2
- package/lib/built/ai-outbound/prompt.d.ts +2 -0
- package/lib/built/ai-outbound/prompt.js +2 -0
- package/lib/built/ai-outbound/types.d.ts +1 -10
- package/lib/built/ai-trigger.d.ts +39 -78
- package/lib/built/ai-trigger.js +3 -254
- package/lib/built/common-adapter-tools.d.ts +21 -6
- package/lib/built/common-adapter-tools.js +28 -17
- package/lib/built/generic-segment-mapper.js +4 -1
- package/lib/built/html-segment-fallback.d.ts +6 -7
- package/lib/built/html-segment-fallback.js +1 -16
- package/lib/built/html-to-text.d.ts +0 -3
- package/lib/built/html-to-text.js +131 -40
- package/lib/built/interaction-messages.d.ts +1 -0
- package/lib/built/interaction-messages.js +30 -0
- package/lib/built/interactive-segments/action.d.ts +3 -4
- package/lib/built/interactive-segments/action.js +2 -5
- package/lib/built/interactive-segments/index.d.ts +0 -2
- package/lib/built/interactive-segments/index.js +0 -2
- package/lib/built/interactive-segments/keyboard-segment.d.ts +0 -1
- package/lib/built/interactive-segments/keyboard-segment.js +0 -1
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +0 -1
- package/lib/built/interactive-segments/onebot-keyboard.js +0 -2
- package/lib/built/interactive-segments/resolve.d.ts +2 -3
- package/lib/built/interactive-segments/resolve.js +21 -14
- package/lib/built/interactive-segments/types.d.ts +2 -7
- package/lib/built/interactive-segments/types.js +22 -2
- package/lib/built/login-assist.d.ts +13 -11
- package/lib/built/login-assist.js +32 -26
- package/lib/built/message-enrich.d.ts +24 -27
- package/lib/built/message-enrich.js +53 -49
- package/lib/built/outbound-content-arrays.d.ts +4 -0
- package/lib/built/outbound-content-arrays.js +32 -0
- package/lib/built/outbound-media-trust.d.ts +46 -0
- package/lib/built/outbound-media-trust.js +245 -0
- package/lib/built/outbound-media-utils.d.ts +5 -3
- package/lib/built/outbound-media-utils.js +5 -3
- package/lib/built/readable-link.d.ts +4 -0
- package/lib/built/readable-link.js +32 -0
- package/lib/built/rich-segments/markdown-to-text.d.ts +1 -2
- package/lib/built/rich-segments/markdown-to-text.js +141 -17
- package/lib/built/roles.d.ts +141 -12
- package/lib/built/roles.js +253 -52
- package/lib/built/segment-contract/assert.js +8 -2
- package/lib/built/segment-contract/delivery.js +1 -0
- package/lib/built/segment-contract/index.d.ts +3 -3
- package/lib/built/segment-contract/index.js +2 -2
- package/lib/built/segment-contract/json-schema.d.ts +39 -5
- package/lib/built/segment-contract/json-schema.js +207 -24
- package/lib/built/segment-contract/preview.js +8 -1
- package/lib/built/segment-contract/text.js +1 -1
- package/lib/built/segment-contract/types.d.ts +2 -2
- package/lib/built/segment-contract/validate.d.ts +1553 -224
- package/lib/built/segment-contract/validate.js +39 -3
- package/lib/built/tool-access.d.ts +5 -0
- package/lib/built/tool-access.js +17 -0
- package/lib/built/user-interaction.d.ts +5 -4
- package/lib/built/user-interaction.js +64 -52
- package/lib/errors.d.ts +1 -18
- package/lib/errors.js +1 -26
- package/lib/feature/command-public-api.d.ts +5 -0
- package/lib/feature/command-public-api.js +5 -0
- package/lib/feature/command.d.ts +2 -0
- package/lib/feature/command.js +1 -0
- package/lib/feature/component.d.ts +1 -0
- package/lib/feature/component.js +1 -0
- package/lib/feature/handler.d.ts +13 -7
- package/lib/feature/handler.js +2 -1
- package/lib/feature/middleware-public-api.d.ts +6 -0
- package/lib/feature/middleware-public-api.js +6 -0
- package/lib/feature/middleware.d.ts +22 -2
- package/lib/feature/middleware.js +7 -2
- package/lib/im-scene.d.ts +4 -3
- package/lib/im-scene.js +9 -9
- package/lib/im-session-id.d.ts +20 -12
- package/lib/im-session-id.js +8 -8
- package/lib/index.d.ts +19 -48
- package/lib/index.js +14 -41
- package/lib/jsx/intrinsic-elements.d.ts +83 -0
- package/lib/jsx/message-renderer.d.ts +13 -0
- package/lib/jsx/message-renderer.js +128 -0
- package/lib/jsx/message-tags.d.ts +133 -0
- package/lib/jsx/message-tags.js +50 -0
- package/lib/jsx-dev-runtime.d.ts +2 -2
- package/lib/jsx-dev-runtime.js +1 -2
- package/lib/jsx-runtime.d.ts +2 -12
- package/lib/jsx-runtime.js +1 -10
- package/lib/jsx.d.ts +6 -30
- package/lib/jsx.js +3 -93
- package/lib/message.d.ts +0 -40
- package/lib/message.js +1 -27
- package/lib/models/system-log.d.ts +0 -2
- package/lib/models/system-log.js +1 -8
- package/lib/models/user.d.ts +0 -2
- package/lib/models/user.js +1 -7
- package/lib/notice.d.ts +38 -33
- package/lib/notice.js +23 -7
- package/lib/plugin-runtime/im/command-feedback.d.ts +59 -0
- package/lib/plugin-runtime/im/command-feedback.js +148 -0
- package/lib/plugin-runtime/im/contracts.d.ts +217 -32
- package/lib/plugin-runtime/im/contracts.js +141 -23
- package/lib/plugin-runtime/im/conversation-runtime.d.ts +42 -0
- package/lib/plugin-runtime/im/conversation-runtime.js +451 -0
- package/lib/plugin-runtime/im/endpoint-runtime.d.ts +89 -0
- package/lib/plugin-runtime/im/endpoint-runtime.js +381 -0
- package/lib/plugin-runtime/im/feature-gate.d.ts +21 -0
- package/lib/plugin-runtime/im/feature-gate.js +88 -0
- package/lib/plugin-runtime/im/host/component-host-installer.d.ts +2 -0
- package/lib/plugin-runtime/im/host/component-host-installer.js +14 -0
- package/lib/plugin-runtime/im/host/conversation-migration.d.ts +5 -0
- package/lib/plugin-runtime/im/host/conversation-migration.js +75 -0
- package/lib/plugin-runtime/im/host/database-config.d.ts +10 -0
- package/lib/plugin-runtime/im/host/database-config.js +114 -0
- package/lib/plugin-runtime/im/host/database-host-installer.d.ts +29 -0
- package/lib/plugin-runtime/im/host/database-host-installer.js +442 -0
- package/lib/plugin-runtime/im/host/database-state.d.ts +9 -0
- package/lib/plugin-runtime/im/host/database-state.js +91 -0
- package/lib/plugin-runtime/im/host/index.d.ts +8 -0
- package/lib/plugin-runtime/im/host/index.js +8 -0
- package/lib/plugin-runtime/im/host/locale-host-installer.d.ts +3 -0
- package/lib/plugin-runtime/im/host/locale-host-installer.js +60 -0
- package/lib/plugin-runtime/im/host/outbound-host-installer.d.ts +8 -0
- package/lib/plugin-runtime/im/host/outbound-host-installer.js +153 -0
- package/lib/plugin-runtime/im/host/sender-enrichment.d.ts +34 -0
- package/lib/plugin-runtime/im/host/sender-enrichment.js +82 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +40 -111
- package/lib/plugin-runtime/im/im-runtime.js +234 -1059
- package/lib/plugin-runtime/im/inbound-dedup.d.ts +84 -0
- package/lib/plugin-runtime/im/inbound-dedup.js +322 -0
- package/lib/plugin-runtime/im/inbound-origin.d.ts +150 -0
- package/lib/plugin-runtime/im/inbound-origin.js +183 -0
- package/lib/plugin-runtime/im/inbound-runtime.d.ts +59 -0
- package/lib/plugin-runtime/im/inbound-runtime.js +478 -0
- package/lib/plugin-runtime/im/inbound-spine.d.ts +196 -0
- package/lib/plugin-runtime/im/inbound-spine.js +335 -0
- package/lib/plugin-runtime/im/index.d.ts +15 -4
- package/lib/plugin-runtime/im/index.js +11 -4
- package/lib/plugin-runtime/im/interaction-runtime.d.ts +50 -0
- package/lib/plugin-runtime/im/interaction-runtime.js +390 -0
- package/lib/plugin-runtime/im/interactive-router.d.ts +81 -0
- package/lib/plugin-runtime/im/interactive-router.js +382 -0
- package/lib/plugin-runtime/im/message-diagnostics.d.ts +70 -0
- package/lib/plugin-runtime/im/message-diagnostics.js +182 -0
- package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -4
- package/lib/plugin-runtime/im/message-dispatcher.js +138 -20
- package/lib/plugin-runtime/im/message-events.d.ts +85 -0
- package/lib/plugin-runtime/im/message-events.js +113 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +39 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.js +450 -0
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +52 -3
- package/lib/plugin-runtime/im/outbound-renderer.js +188 -8
- package/lib/plugin-runtime/im/outbound-segments.d.ts +29 -5
- package/lib/plugin-runtime/im/outbound-segments.js +130 -36
- package/lib/plugin-runtime/im/progressive-reply.d.ts +58 -0
- package/lib/plugin-runtime/im/progressive-reply.js +501 -0
- package/lib/plugin-runtime/im/public-api.d.ts +1 -1
- package/lib/request.d.ts +27 -36
- package/lib/request.js +14 -6
- package/lib/side-event/base.d.ts +64 -44
- package/lib/side-event/base.js +72 -19
- package/lib/side-event/index.d.ts +1 -1
- package/lib/side-event/index.js +1 -1
- package/lib/side-event/normalize.d.ts +7 -38
- package/lib/side-event/normalize.js +4 -109
- package/lib/side-event/scene-events.d.ts +40 -0
- package/lib/side-event/scene-events.js +147 -0
- package/lib/side-event/types.d.ts +4 -13
- package/lib/side-event/types.js +1 -55
- package/lib/system-event.d.ts +17 -12
- package/lib/system-event.js +8 -6
- package/lib/types.d.ts +23 -167
- package/lib/utils.d.ts +50 -33
- package/lib/utils.js +12 -185
- package/lib/venue/contracts.d.ts +21 -0
- package/lib/venue/contracts.js +3 -0
- package/lib/venue/floor-controller.d.ts +11 -0
- package/lib/venue/floor-controller.js +63 -0
- package/lib/venue/index.d.ts +13 -0
- package/lib/venue/index.js +11 -0
- package/lib/venue/membership-port.d.ts +23 -0
- package/lib/venue/membership-port.js +141 -0
- package/lib/venue/projector.d.ts +38 -0
- package/lib/venue/projector.js +45 -0
- package/lib/venue/registry.d.ts +16 -0
- package/lib/venue/registry.js +63 -0
- package/lib/venue/router.d.ts +19 -0
- package/lib/venue/router.js +101 -0
- package/lib/venue/send-limiter.d.ts +17 -0
- package/lib/venue/send-limiter.js +73 -0
- package/lib/venue/validator.d.ts +6 -0
- package/lib/venue/validator.js +160 -0
- package/package.json +24 -50
- package/lib/adapter.d.ts +0 -145
- package/lib/adapter.js +0 -377
- package/lib/built/adapter-process.d.ts +0 -58
- package/lib/built/adapter-process.js +0 -128
- package/lib/built/agent-preset.d.ts +0 -64
- package/lib/built/agent-preset.js +0 -79
- package/lib/built/ai-outbound/adapter-access.d.ts +0 -3
- package/lib/built/ai-outbound/adapter-access.js +0 -9
- package/lib/built/ai-outbound/extensions/qq-message.d.ts +0 -3
- package/lib/built/ai-outbound/extensions/qq-message.js +0 -23
- package/lib/built/authorization.d.ts +0 -10
- package/lib/built/authorization.js +0 -76
- package/lib/built/command.d.ts +0 -72
- package/lib/built/command.js +0 -105
- package/lib/built/component.d.ts +0 -67
- package/lib/built/component.js +0 -97
- package/lib/built/config.d.ts +0 -98
- package/lib/built/config.js +0 -372
- package/lib/built/connect-endpoint-instance.d.ts +0 -17
- package/lib/built/connect-endpoint-instance.js +0 -42
- package/lib/built/database.d.ts +0 -68
- package/lib/built/database.js +0 -106
- package/lib/built/dispatcher.d.ts +0 -141
- package/lib/built/dispatcher.js +0 -383
- package/lib/built/endpoint-commands.d.ts +0 -3
- package/lib/built/endpoint-commands.js +0 -99
- package/lib/built/endpoint-lifecycle-service.d.ts +0 -28
- package/lib/built/endpoint-lifecycle-service.js +0 -242
- package/lib/built/endpoint-lifecycle.d.ts +0 -27
- package/lib/built/endpoint-lifecycle.js +0 -36
- package/lib/built/endpoint-manager.d.ts +0 -34
- package/lib/built/html-renderer-loader.d.ts +0 -13
- package/lib/built/html-renderer-loader.js +0 -33
- package/lib/built/inbound-pipeline.d.ts +0 -37
- package/lib/built/inbound-pipeline.js +0 -63
- package/lib/built/inbound-runner.d.ts +0 -22
- package/lib/built/inbound-runner.js +0 -34
- package/lib/built/interactive-segment-contract.d.ts +0 -6
- package/lib/built/interactive-segment-contract.js +0 -9
- package/lib/built/interactive-segments/fallback-store.d.ts +0 -29
- package/lib/built/interactive-segments/fallback-store.js +0 -63
- package/lib/built/interactive-segments/handlers.d.ts +0 -16
- package/lib/built/interactive-segments/handlers.js +0 -74
- package/lib/built/introspection-format.d.ts +0 -10
- package/lib/built/introspection-format.js +0 -28
- package/lib/built/management-command-guard.d.ts +0 -15
- package/lib/built/management-command-guard.js +0 -25
- package/lib/built/message-filter.d.ts +0 -176
- package/lib/built/message-filter.js +0 -239
- package/lib/built/optional-peer-import.d.ts +0 -3
- package/lib/built/optional-peer-import.js +0 -33
- package/lib/built/outbound-media-contract.d.ts +0 -22
- package/lib/built/outbound-media-contract.js +0 -10
- package/lib/built/permission.d.ts +0 -51
- package/lib/built/permission.js +0 -99
- package/lib/built/permit-check.d.ts +0 -7
- package/lib/built/permit-check.js +0 -35
- package/lib/built/permit-parse.d.ts +0 -16
- package/lib/built/permit-parse.js +0 -32
- package/lib/built/platform-permit.d.ts +0 -20
- package/lib/built/platform-permit.js +0 -91
- package/lib/built/queue-im-field-contract.d.ts +0 -32
- package/lib/built/queue-im-field-contract.js +0 -67
- package/lib/built/rich-segments/adapter-policies.d.ts +0 -9
- package/lib/built/rich-segments/adapter-policies.js +0 -27
- package/lib/built/rich-segments/base.d.ts +0 -11
- package/lib/built/rich-segments/base.js +0 -24
- package/lib/built/rich-segments/builtins.d.ts +0 -4
- package/lib/built/rich-segments/builtins.js +0 -40
- package/lib/built/rich-segments/capabilities.d.ts +0 -6
- package/lib/built/rich-segments/capabilities.js +0 -38
- package/lib/built/rich-segments/html-segment.d.ts +0 -15
- package/lib/built/rich-segments/html-segment.js +0 -62
- package/lib/built/rich-segments/index.d.ts +0 -13
- package/lib/built/rich-segments/index.js +0 -13
- package/lib/built/rich-segments/markdown-segment.d.ts +0 -14
- package/lib/built/rich-segments/markdown-segment.js +0 -58
- package/lib/built/rich-segments/qrcode-segment.d.ts +0 -18
- package/lib/built/rich-segments/qrcode-segment.js +0 -73
- package/lib/built/rich-segments/registry.d.ts +0 -16
- package/lib/built/rich-segments/registry.js +0 -52
- package/lib/built/rich-segments/resolve.d.ts +0 -5
- package/lib/built/rich-segments/resolve.js +0 -87
- package/lib/built/rich-segments/tts-segment.d.ts +0 -13
- package/lib/built/rich-segments/tts-segment.js +0 -51
- package/lib/built/rich-segments/types.d.ts +0 -79
- package/lib/built/rich-segments/types.js +0 -17
- package/lib/built/runtime-io.d.ts +0 -9
- package/lib/built/runtime-io.js +0 -67
- package/lib/built/schedule.d.ts +0 -54
- package/lib/built/schedule.js +0 -112
- package/lib/built/schema-endpoint-manager.d.ts +0 -17
- package/lib/built/schema-endpoint-manager.js +0 -73
- package/lib/built/schema-feature.d.ts +0 -77
- package/lib/built/schema-feature.js +0 -130
- package/lib/built/skill.d.ts +0 -120
- package/lib/built/skill.js +0 -151
- package/lib/built/speech-loader.d.ts +0 -14
- package/lib/built/speech-loader.js +0 -32
- package/lib/built/tool.d.ts +0 -151
- package/lib/built/tool.js +0 -388
- package/lib/command.d.ts +0 -50
- package/lib/command.js +0 -106
- package/lib/component.d.ts +0 -26
- package/lib/component.js +0 -583
- package/lib/endpoint-capabilities.d.ts +0 -46
- package/lib/endpoint-capabilities.js +0 -55
- package/lib/endpoint.d.ts +0 -19
- package/lib/endpoint.js +0 -3
- package/lib/host-plugin-registry.d.ts +0 -8
- package/lib/host-plugin-registry.js +0 -12
- package/lib/plugin-context.d.ts +0 -27
- package/lib/plugin-context.js +0 -64
- package/lib/plugin-runtime/im/interactive.d.ts +0 -26
- package/lib/plugin-runtime/im/interactive.js +0 -46
- package/lib/plugin-runtime/im/login-assist-host.d.ts +0 -6
- package/lib/plugin-runtime/im/login-assist-host.js +0 -6
- package/lib/plugin-runtime/im/message-bus.d.ts +0 -38
- package/lib/plugin-runtime/im/message-bus.js +0 -40
- package/lib/plugin-runtime/im/service-tokens.d.ts +0 -18
- package/lib/plugin-runtime/im/service-tokens.js +0 -13
- package/lib/plugin.d.ts +0 -268
- package/lib/plugin.js +0 -583
- package/lib/schema-interaction.d.ts +0 -117
- package/lib/schema-interaction.js +0 -247
- package/lib/side-event/dispatch.d.ts +0 -15
- package/lib/side-event/dispatch.js +0 -140
- package/lib/tool-zod.d.ts +0 -43
- package/lib/tool-zod.js +0 -184
- /package/lib/{built/endpoint-manager.js → jsx/intrinsic-elements.js} +0 -0
package/lib/side-event/base.d.ts
CHANGED
|
@@ -1,52 +1,72 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
/** Canonical relation fields populated by the Adapter boundary. */
|
|
29
|
-
$message_id?: string;
|
|
30
|
-
$reaction?: string;
|
|
31
|
-
$operation?: 'added' | 'removed';
|
|
32
|
-
$duration_seconds?: number;
|
|
33
|
-
$role?: string;
|
|
34
|
-
$enabled?: boolean;
|
|
1
|
+
import type { ConversationRef, EndpointRef } from '@zhin.js/im-contract';
|
|
2
|
+
import type { ConversationAddress, MessageSenderRef } from '../plugin-runtime/im/contracts.js';
|
|
3
|
+
/** Shared Endpoint event data, with no assumption about chat or participants. */
|
|
4
|
+
export interface IncomingEndpointEvent {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly type: 'notice' | 'request' | 'system';
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly endpointId?: string;
|
|
9
|
+
readonly clientAdapter?: string;
|
|
10
|
+
readonly timestamp: number;
|
|
11
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
35
12
|
}
|
|
36
|
-
/**
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
13
|
+
/** Identity and lifetime shared by all canonical Endpoint event views. */
|
|
14
|
+
export interface EndpointEventBase extends IncomingEndpointEvent {
|
|
15
|
+
readonly endpoint: EndpointRef;
|
|
16
|
+
readonly generation: number;
|
|
17
|
+
readonly $client: unknown;
|
|
18
|
+
}
|
|
19
|
+
/** Adapter-normalized Notice/Request data. System events do not inherit this contract. */
|
|
20
|
+
export interface IncomingSideEvent extends IncomingEndpointEvent {
|
|
21
|
+
readonly type: 'notice' | 'request';
|
|
22
|
+
readonly conversation?: ConversationAddress;
|
|
23
|
+
readonly actor?: MessageSenderRef;
|
|
24
|
+
readonly target?: MessageSenderRef;
|
|
25
|
+
}
|
|
26
|
+
export interface SideEventBase extends IncomingSideEvent, Omit<EndpointEventBase, 'type'> {
|
|
27
|
+
readonly conversation?: ConversationRef;
|
|
28
|
+
}
|
|
29
|
+
/** @internal Context captured by one generation-owned ingress operation. */
|
|
30
|
+
export interface EndpointEventContext {
|
|
31
|
+
readonly endpoint: EndpointRef;
|
|
32
|
+
readonly generation: number;
|
|
33
|
+
readonly client: () => unknown;
|
|
34
|
+
}
|
|
35
|
+
/** @internal Endpoint identity/lifetime only; SystemEvent has no chat fields. */
|
|
36
|
+
export declare class RuntimeEndpointEvent implements EndpointEventBase {
|
|
37
|
+
#private;
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly type: IncomingEndpointEvent['type'];
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly endpoint: EndpointRef;
|
|
42
|
+
readonly endpointId?: string;
|
|
43
|
+
readonly clientAdapter?: string;
|
|
44
|
+
readonly timestamp: number;
|
|
45
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
46
|
+
readonly generation: number;
|
|
47
|
+
constructor(input: IncomingEndpointEvent, context: EndpointEventContext);
|
|
48
|
+
get $client(): unknown;
|
|
49
|
+
}
|
|
50
|
+
/** @internal Shared Notice/Request data view. */
|
|
51
|
+
export declare class RuntimeSideEvent extends RuntimeEndpointEvent implements SideEventBase {
|
|
52
|
+
readonly type: IncomingSideEvent['type'];
|
|
53
|
+
readonly conversation?: ConversationRef;
|
|
54
|
+
readonly actor?: MessageSenderRef;
|
|
55
|
+
readonly target?: MessageSenderRef;
|
|
56
|
+
constructor(input: IncomingSideEvent, context: EndpointEventContext);
|
|
57
|
+
}
|
|
58
|
+
export declare function composeSideEventName(type: string, sceneType?: string, subType?: string): string;
|
|
59
|
+
/** The full semantic event name is the only event-name authority. */
|
|
60
|
+
export declare function formatSideEventName(event: Pick<IncomingEndpointEvent, 'name'>): string;
|
|
61
|
+
export declare function matchesSideEventName(event: Pick<IncomingEndpointEvent, 'name'>, fullName: string): boolean;
|
|
43
62
|
export declare function parseSideEventName(fullName: string): {
|
|
44
63
|
type: string;
|
|
45
64
|
scene_type?: string;
|
|
46
65
|
sub_type?: string;
|
|
47
66
|
};
|
|
48
|
-
/**
|
|
49
|
-
export declare function
|
|
67
|
+
/** Map known platform scene domains; non-conversation events have no send target. */
|
|
68
|
+
export declare function sideEventConversation(sceneType: string | undefined, id: string): ConversationAddress | undefined;
|
|
69
|
+
export declare function sideEventSendChannel(event: Pick<IncomingSideEvent, 'conversation'>): {
|
|
50
70
|
id: string;
|
|
51
71
|
type: 'group' | 'private' | 'channel';
|
|
52
|
-
};
|
|
72
|
+
} | undefined;
|
package/lib/side-event/base.js
CHANGED
|
@@ -1,30 +1,83 @@
|
|
|
1
|
-
|
|
1
|
+
import { normalizePlatformStanding } from '@zhin.js/im-contract';
|
|
2
|
+
/** @internal Endpoint identity/lifetime only; SystemEvent has no chat fields. */
|
|
3
|
+
export class RuntimeEndpointEvent {
|
|
4
|
+
id;
|
|
5
|
+
type;
|
|
6
|
+
name;
|
|
7
|
+
endpoint;
|
|
8
|
+
endpointId;
|
|
9
|
+
clientAdapter;
|
|
10
|
+
timestamp;
|
|
11
|
+
metadata;
|
|
12
|
+
generation;
|
|
13
|
+
#client;
|
|
14
|
+
constructor(input, context) {
|
|
15
|
+
if (!input.name.startsWith(`${input.type}.`)) {
|
|
16
|
+
throw new TypeError('Event name must belong to its event type');
|
|
17
|
+
}
|
|
18
|
+
this.id = input.id;
|
|
19
|
+
this.type = input.type;
|
|
20
|
+
this.name = input.name;
|
|
21
|
+
this.endpoint = Object.freeze({ ...context.endpoint });
|
|
22
|
+
this.endpointId = input.endpointId;
|
|
23
|
+
this.clientAdapter = input.clientAdapter ?? context.endpoint.adapter;
|
|
24
|
+
this.timestamp = input.timestamp;
|
|
25
|
+
this.metadata = Object.freeze({ ...input.metadata });
|
|
26
|
+
this.generation = context.generation;
|
|
27
|
+
this.#client = context.client;
|
|
28
|
+
}
|
|
29
|
+
get $client() { return this.#client(); }
|
|
30
|
+
}
|
|
31
|
+
/** @internal Shared Notice/Request data view. */
|
|
32
|
+
export class RuntimeSideEvent extends RuntimeEndpointEvent {
|
|
33
|
+
conversation;
|
|
34
|
+
actor;
|
|
35
|
+
target;
|
|
36
|
+
constructor(input, context) {
|
|
37
|
+
super(input, context);
|
|
38
|
+
this.conversation = input.conversation ? Object.freeze({
|
|
39
|
+
...input.conversation,
|
|
40
|
+
...(input.conversation.parent ? { parent: Object.freeze({ ...input.conversation.parent }) } : {}),
|
|
41
|
+
endpoint: this.endpoint,
|
|
42
|
+
}) : undefined;
|
|
43
|
+
this.actor = freezeSender(input.actor);
|
|
44
|
+
this.target = freezeSender(input.target);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Side-event actors carry the Adapter's normalized platform standing only (ADR 0056 §1). */
|
|
48
|
+
function freezeSender(sender) {
|
|
49
|
+
if (!sender)
|
|
50
|
+
return undefined;
|
|
51
|
+
const platform = normalizePlatformStanding(sender.platform);
|
|
52
|
+
return Object.freeze({
|
|
53
|
+
id: sender.id,
|
|
54
|
+
...(sender.name !== undefined ? { name: sender.name } : {}),
|
|
55
|
+
...(platform ? { platform } : {}),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
2
58
|
export function composeSideEventName(type, sceneType, subType) {
|
|
3
|
-
return [type, sceneType, subType].filter(
|
|
59
|
+
return [type, sceneType, subType].filter(Boolean).join('.');
|
|
4
60
|
}
|
|
5
|
-
/**
|
|
61
|
+
/** The full semantic event name is the only event-name authority. */
|
|
6
62
|
export function formatSideEventName(event) {
|
|
7
|
-
return
|
|
63
|
+
return event.name;
|
|
8
64
|
}
|
|
9
|
-
/** 判断 Side Event 是否匹配完整类型名(如 `notice.group.member_increase`) */
|
|
10
65
|
export function matchesSideEventName(event, fullName) {
|
|
11
|
-
return
|
|
66
|
+
return event.name === fullName;
|
|
12
67
|
}
|
|
13
|
-
/** 解析完整类型名为三段 */
|
|
14
68
|
export function parseSideEventName(fullName) {
|
|
15
69
|
const parts = fullName.split('.');
|
|
16
|
-
return {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
70
|
+
return { type: parts[0] ?? '', scene_type: parts[1], sub_type: parts.slice(2).join('.') || undefined };
|
|
71
|
+
}
|
|
72
|
+
/** Map known platform scene domains; non-conversation events have no send target. */
|
|
73
|
+
export function sideEventConversation(sceneType, id) {
|
|
74
|
+
if (!id)
|
|
75
|
+
return undefined;
|
|
76
|
+
const kind = sceneType === 'friend' ? 'private' : sceneType;
|
|
77
|
+
return kind === 'private' || kind === 'group' || kind === 'channel'
|
|
78
|
+
? Object.freeze({ kind, id })
|
|
79
|
+
: undefined;
|
|
21
80
|
}
|
|
22
|
-
/** 将 Side Event 场景映射为 IM 发送通道(group-suite 等消费者用) */
|
|
23
81
|
export function sideEventSendChannel(event) {
|
|
24
|
-
|
|
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' };
|
|
82
|
+
return event.conversation ? { id: event.conversation.id, type: event.conversation.kind } : undefined;
|
|
30
83
|
}
|
package/lib/side-event/index.js
CHANGED
|
@@ -1,42 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { type ComposedNoticeName, type ComposedRequestName, type SideEventParts } from './types.js';
|
|
5
|
-
export type SideEventPlatform = 'onebot' | 'icqq' | 'napcat' | 'kook' | (string & {});
|
|
6
|
-
export interface OneBotLikeRawEvent {
|
|
7
|
-
notice_type?: string;
|
|
8
|
-
request_type?: string;
|
|
9
|
-
sub_type?: string;
|
|
10
|
-
group_id?: number | string;
|
|
11
|
-
user_id?: number | string;
|
|
12
|
-
operator_id?: number | string;
|
|
13
|
-
flag?: string;
|
|
14
|
-
time?: number;
|
|
15
|
-
self_id?: number | string;
|
|
16
|
-
[key: string]: unknown;
|
|
17
|
-
}
|
|
18
|
-
/** 去重用:notice / request 无稳定 id 时组合键 */
|
|
19
|
-
export declare function resolveSideEventDedupeKey(data: OneBotLikeRawEvent, kind: 'notice' | 'request'): string;
|
|
20
|
-
/**
|
|
21
|
-
* 将平台原始 notice_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
22
|
-
*/
|
|
23
|
-
export declare function mapNoticeParts(platform: SideEventPlatform, raw: string, options?: {
|
|
24
|
-
sub_type?: string;
|
|
25
|
-
is_group?: boolean;
|
|
26
|
-
notify_handler?: (subType: string | undefined, isGroup: boolean) => SideEventParts;
|
|
27
|
-
}): SideEventParts;
|
|
28
|
-
/**
|
|
29
|
-
* 将平台原始 request_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
30
|
-
*/
|
|
31
|
-
export declare function mapRequestParts(_platform: SideEventPlatform, raw: string, subType?: string): SideEventParts;
|
|
32
|
-
/** 组合完整 Notice 类型名(兼容旧 API) */
|
|
33
|
-
export declare function mapNoticeType(platform: SideEventPlatform, raw: string, options?: Parameters<typeof mapNoticeParts>[2]): ComposedNoticeName;
|
|
34
|
-
/** 组合完整 Request 类型名(兼容旧 API) */
|
|
35
|
-
export declare function mapRequestType(platform: SideEventPlatform, raw: string, subType?: string): ComposedRequestName;
|
|
1
|
+
import type { IncomingNotice } from '../notice.js';
|
|
2
|
+
import type { IncomingRequest } from '../request.js';
|
|
3
|
+
import type { IncomingSystemEvent } from '../system-event.js';
|
|
36
4
|
export declare function senderFromId(id: unknown, name?: string): {
|
|
37
5
|
id: string;
|
|
38
6
|
name: string;
|
|
39
7
|
} | undefined;
|
|
40
|
-
|
|
41
|
-
export declare function
|
|
42
|
-
export declare function
|
|
8
|
+
/** Keep native fields under metadata; never mutate or flatten the platform event. */
|
|
9
|
+
export declare function buildNotice<T extends object>(input: T, format: Omit<IncomingNotice, 'metadata'>): IncomingNotice;
|
|
10
|
+
export declare function buildRequest<T extends object>(input: T, format: Omit<IncomingRequest, 'metadata'>): IncomingRequest;
|
|
11
|
+
export declare function buildSystem<T extends object>(input: T, format: Omit<IncomingSystemEvent, 'metadata'>): IncomingSystemEvent;
|
|
@@ -1,121 +1,16 @@
|
|
|
1
|
-
import { Notice } from '../notice.js';
|
|
2
|
-
import { Request } from '../request.js';
|
|
3
|
-
import { SystemEvent } from '../system-event.js';
|
|
4
|
-
import { composeSideEventName, parseSideEventName, } from './base.js';
|
|
5
|
-
import { KOOK_NOTICE_PARTS_MAP, ONEBOT_NOTICE_PARTS_MAP, SLACK_NOTICE_PARTS_MAP } from './types.js';
|
|
6
|
-
/** 去重用:notice / request 无稳定 id 时组合键 */
|
|
7
|
-
export function resolveSideEventDedupeKey(data, kind) {
|
|
8
|
-
if (data.flag != null && String(data.flag) !== '') {
|
|
9
|
-
return `${kind}:${data.flag}`;
|
|
10
|
-
}
|
|
11
|
-
const time = data.time ?? 0;
|
|
12
|
-
const type = data.notice_type ?? data.request_type ?? kind;
|
|
13
|
-
const scope = data.group_id ?? data.user_id ?? '';
|
|
14
|
-
const sub = data.sub_type ?? '';
|
|
15
|
-
return `${kind}:${time}_${type}_${scope}_${sub}`;
|
|
16
|
-
}
|
|
17
|
-
function resolveNotifyNoticeParts(subType, isGroup) {
|
|
18
|
-
if (subType === 'poke') {
|
|
19
|
-
return isGroup
|
|
20
|
-
? { scene_type: 'group', sub_type: 'poke' }
|
|
21
|
-
: { scene_type: 'friend', sub_type: 'poke' };
|
|
22
|
-
}
|
|
23
|
-
if (subType === 'input_status')
|
|
24
|
-
return { scene_type: 'notify', sub_type: 'input_status' };
|
|
25
|
-
if (subType === 'title')
|
|
26
|
-
return { scene_type: 'notify', sub_type: 'title_change' };
|
|
27
|
-
if (subType === 'profile_like')
|
|
28
|
-
return { scene_type: 'notify', sub_type: 'profile_like' };
|
|
29
|
-
return { scene_type: 'notify', sub_type: subType ?? 'unknown' };
|
|
30
|
-
}
|
|
31
|
-
function resolveEssenceNoticeParts(subType) {
|
|
32
|
-
return subType === 'add'
|
|
33
|
-
? { scene_type: 'group', sub_type: 'essence_add' }
|
|
34
|
-
: { scene_type: 'group', sub_type: 'essence_delete' };
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* 将平台原始 notice_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
38
|
-
*/
|
|
39
|
-
export function mapNoticeParts(platform, raw, options) {
|
|
40
|
-
const subType = options?.sub_type;
|
|
41
|
-
const isGroup = options?.is_group ?? false;
|
|
42
|
-
if (platform === 'kook') {
|
|
43
|
-
return KOOK_NOTICE_PARTS_MAP[raw] ?? { scene_type: 'kook', sub_type: raw };
|
|
44
|
-
}
|
|
45
|
-
if (platform === 'slack') {
|
|
46
|
-
return SLACK_NOTICE_PARTS_MAP[raw] ?? { scene_type: 'slack', sub_type: raw };
|
|
47
|
-
}
|
|
48
|
-
if (raw === 'notify') {
|
|
49
|
-
const handler = options?.notify_handler ?? resolveNotifyNoticeParts;
|
|
50
|
-
return handler(subType, isGroup);
|
|
51
|
-
}
|
|
52
|
-
if (raw === 'essence') {
|
|
53
|
-
return resolveEssenceNoticeParts(subType);
|
|
54
|
-
}
|
|
55
|
-
if (ONEBOT_NOTICE_PARTS_MAP[raw]) {
|
|
56
|
-
return ONEBOT_NOTICE_PARTS_MAP[raw];
|
|
57
|
-
}
|
|
58
|
-
if (raw.startsWith('notice.')) {
|
|
59
|
-
const parsed = parseSideEventName(raw);
|
|
60
|
-
if (parsed.scene_type && parsed.sub_type) {
|
|
61
|
-
return { scene_type: parsed.scene_type, sub_type: parsed.sub_type };
|
|
62
|
-
}
|
|
63
|
-
const suffix = raw.slice('notice.'.length).replace(/\./g, '_');
|
|
64
|
-
if (ONEBOT_NOTICE_PARTS_MAP[suffix])
|
|
65
|
-
return ONEBOT_NOTICE_PARTS_MAP[suffix];
|
|
66
|
-
return { scene_type: parsed.scene_type ?? 'unknown', sub_type: parsed.sub_type ?? suffix };
|
|
67
|
-
}
|
|
68
|
-
if (platform === 'icqq' || platform === 'onebot' || platform === 'napcat') {
|
|
69
|
-
const dotted = raw.replace(/_/g, '.');
|
|
70
|
-
const parsed = parseSideEventName(`notice.${dotted}`);
|
|
71
|
-
return {
|
|
72
|
-
scene_type: parsed.scene_type ?? dotted.split('.')[0] ?? 'unknown',
|
|
73
|
-
sub_type: parsed.sub_type ?? (dotted.split('.').slice(1).join('.') || raw),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return { scene_type: platform, sub_type: raw };
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* 将平台原始 request_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
80
|
-
*/
|
|
81
|
-
export function mapRequestParts(_platform, raw, subType) {
|
|
82
|
-
if (raw === 'friend' || raw.startsWith('friend')) {
|
|
83
|
-
return { scene_type: 'friend', sub_type: 'add' };
|
|
84
|
-
}
|
|
85
|
-
if (raw === 'group' || raw.startsWith('group')) {
|
|
86
|
-
return { scene_type: 'group', sub_type: subType === 'invite' ? 'invite' : 'add' };
|
|
87
|
-
}
|
|
88
|
-
if (raw.startsWith('request.')) {
|
|
89
|
-
const parsed = parseSideEventName(raw);
|
|
90
|
-
return {
|
|
91
|
-
scene_type: parsed.scene_type ?? 'unknown',
|
|
92
|
-
sub_type: parsed.sub_type ?? 'unknown',
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return { scene_type: raw, sub_type: subType ?? 'unknown' };
|
|
96
|
-
}
|
|
97
|
-
/** 组合完整 Notice 类型名(兼容旧 API) */
|
|
98
|
-
export function mapNoticeType(platform, raw, options) {
|
|
99
|
-
const parts = mapNoticeParts(platform, raw, options);
|
|
100
|
-
return composeSideEventName('notice', parts.scene_type, parts.sub_type);
|
|
101
|
-
}
|
|
102
|
-
/** 组合完整 Request 类型名(兼容旧 API) */
|
|
103
|
-
export function mapRequestType(platform, raw, subType) {
|
|
104
|
-
const parts = mapRequestParts(platform, raw, subType);
|
|
105
|
-
return composeSideEventName('request', parts.scene_type, parts.sub_type);
|
|
106
|
-
}
|
|
107
1
|
export function senderFromId(id, name) {
|
|
108
2
|
if (id == null || id === '')
|
|
109
3
|
return undefined;
|
|
110
4
|
const s = String(id);
|
|
111
5
|
return { id: s, name: name ?? s };
|
|
112
6
|
}
|
|
7
|
+
/** Keep native fields under metadata; never mutate or flatten the platform event. */
|
|
113
8
|
export function buildNotice(input, format) {
|
|
114
|
-
return
|
|
9
|
+
return Object.freeze({ ...format, metadata: Object.freeze({ ...input }) });
|
|
115
10
|
}
|
|
116
11
|
export function buildRequest(input, format) {
|
|
117
|
-
return
|
|
12
|
+
return Object.freeze({ ...format, metadata: Object.freeze({ ...input }) });
|
|
118
13
|
}
|
|
119
14
|
export function buildSystem(input, format) {
|
|
120
|
-
return
|
|
15
|
+
return Object.freeze({ ...format, metadata: Object.freeze({ ...input }) });
|
|
121
16
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 状态感知(#996):社交事件的优先级与极短摘要。
|
|
3
|
+
*
|
|
4
|
+
* 只读 `conversation_events` 中已归一化的事件;**从不**把平台原始 JSON 交给模型。
|
|
5
|
+
* - 高优先:禁言/解禁、入群申请、成员进出、公告变更、戳 Bot —— 可独立唤醒回合;
|
|
6
|
+
* - 低优先:表情回应、名片/头衔/备注变更、人与人之间的戳一戳 —— 只挂到下一轮的 `[Scene events]` 摘要。
|
|
7
|
+
*/
|
|
8
|
+
import type { ActorRef, ConversationEvent } from '@zhin.js/im-contract';
|
|
9
|
+
export type SceneEventPriority = 'high' | 'low';
|
|
10
|
+
/** 场景事件类型(`message.created` / `message.recalled` 不在此列)。 */
|
|
11
|
+
export declare const SCENE_EVENT_TYPES: readonly ["member.muted", "member.unmuted", "member.joined", "member.left", "member.role_changed", "scene.join_requested", "scene.notice_updated", "conversation.poked", "message.reaction_changed", "member.card_changed", "member.title_changed", "member.remark_changed"];
|
|
12
|
+
export type SceneEventType = typeof SCENE_EVENT_TYPES[number];
|
|
13
|
+
export type SceneConversationEvent = Extract<ConversationEvent, {
|
|
14
|
+
type: SceneEventType;
|
|
15
|
+
}>;
|
|
16
|
+
/** 只在 `[Scene events]` 中出现、不进入旧的 conversation context 块的新类型(避免重复注入与落库)。 */
|
|
17
|
+
export declare const SCENE_ONLY_EVENT_TYPES: ReadonlySet<ConversationEvent['type']>;
|
|
18
|
+
/** 单条摘要的上限(字符)。整段 `[Scene events]` 另有总上限。 */
|
|
19
|
+
export declare const SCENE_EVENT_SUMMARY_MAX = 60;
|
|
20
|
+
/** 公告/申请附言等用户文本在事件里保存的上限。 */
|
|
21
|
+
export declare const SCENE_EVENT_TEXT_MAX = 40;
|
|
22
|
+
export declare function isSceneEvent(event: ConversationEvent): event is SceneConversationEvent;
|
|
23
|
+
/**
|
|
24
|
+
* 事件优先级;不是场景事件时返回 undefined。
|
|
25
|
+
* `selfIds` 为 Bot 在该平台的账号候选,用来判断「戳的是不是 Bot」。
|
|
26
|
+
*/
|
|
27
|
+
export declare function sceneEventPriority(event: ConversationEvent, selfIds?: ReadonlySet<string>): SceneEventPriority | undefined;
|
|
28
|
+
/** 截断并清理用户文本:去掉换行/控制字符,只留一行。 */
|
|
29
|
+
export declare function clipSceneText(value: unknown, max?: number): string;
|
|
30
|
+
export interface SceneEventSummaryOptions {
|
|
31
|
+
/** Bot 账号候选:目标为 Bot 时写成 `you`。 */
|
|
32
|
+
readonly selfIds?: ReadonlySet<string>;
|
|
33
|
+
/** 关系称呼(如 `ai_user_relations` 中的昵称);返回空时退回平台显示名。 */
|
|
34
|
+
readonly nameOf?: (actor: ActorRef) => string | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 一条事件的极短英文摘要(≤ {@link SCENE_EVENT_SUMMARY_MAX} 字符)。不是场景事件时返回空串。
|
|
38
|
+
* 摘要只含称呼、动作与截断后的短文本;没有分数、没有原始字段。
|
|
39
|
+
*/
|
|
40
|
+
export declare function summarizeSceneEvent(event: ConversationEvent, options?: SceneEventSummaryOptions): string;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/** 场景事件类型(`message.created` / `message.recalled` 不在此列)。 */
|
|
2
|
+
export const SCENE_EVENT_TYPES = Object.freeze([
|
|
3
|
+
'member.muted',
|
|
4
|
+
'member.unmuted',
|
|
5
|
+
'member.joined',
|
|
6
|
+
'member.left',
|
|
7
|
+
'member.role_changed',
|
|
8
|
+
'scene.join_requested',
|
|
9
|
+
'scene.notice_updated',
|
|
10
|
+
'conversation.poked',
|
|
11
|
+
'message.reaction_changed',
|
|
12
|
+
'member.card_changed',
|
|
13
|
+
'member.title_changed',
|
|
14
|
+
'member.remark_changed',
|
|
15
|
+
]);
|
|
16
|
+
/** 只在 `[Scene events]` 中出现、不进入旧的 conversation context 块的新类型(避免重复注入与落库)。 */
|
|
17
|
+
export const SCENE_ONLY_EVENT_TYPES = new Set([
|
|
18
|
+
'scene.join_requested',
|
|
19
|
+
'scene.notice_updated',
|
|
20
|
+
'member.card_changed',
|
|
21
|
+
'member.title_changed',
|
|
22
|
+
'member.remark_changed',
|
|
23
|
+
]);
|
|
24
|
+
/** 单条摘要的上限(字符)。整段 `[Scene events]` 另有总上限。 */
|
|
25
|
+
export const SCENE_EVENT_SUMMARY_MAX = 60;
|
|
26
|
+
/** 公告/申请附言等用户文本在事件里保存的上限。 */
|
|
27
|
+
export const SCENE_EVENT_TEXT_MAX = 40;
|
|
28
|
+
export function isSceneEvent(event) {
|
|
29
|
+
return SCENE_EVENT_TYPES.includes(event.type);
|
|
30
|
+
}
|
|
31
|
+
/** 部分平台以 user_id 0 表示「全员」。 */
|
|
32
|
+
const WHOLE_SCENE_IDS = new Set(['0', 'all']);
|
|
33
|
+
/**
|
|
34
|
+
* 事件优先级;不是场景事件时返回 undefined。
|
|
35
|
+
* `selfIds` 为 Bot 在该平台的账号候选,用来判断「戳的是不是 Bot」。
|
|
36
|
+
*/
|
|
37
|
+
export function sceneEventPriority(event, selfIds = new Set()) {
|
|
38
|
+
switch (event.type) {
|
|
39
|
+
case 'member.muted':
|
|
40
|
+
case 'member.unmuted':
|
|
41
|
+
case 'member.joined':
|
|
42
|
+
case 'member.left':
|
|
43
|
+
case 'scene.join_requested':
|
|
44
|
+
case 'scene.notice_updated':
|
|
45
|
+
return 'high';
|
|
46
|
+
case 'conversation.poked':
|
|
47
|
+
return event.target && selfIds.has(String(event.target.id)) ? 'high' : 'low';
|
|
48
|
+
case 'member.role_changed':
|
|
49
|
+
case 'message.reaction_changed':
|
|
50
|
+
case 'member.card_changed':
|
|
51
|
+
case 'member.title_changed':
|
|
52
|
+
case 'member.remark_changed':
|
|
53
|
+
return 'low';
|
|
54
|
+
default:
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** 截断并清理用户文本:去掉换行/控制字符,只留一行。 */
|
|
59
|
+
export function clipSceneText(value, max = SCENE_EVENT_TEXT_MAX) {
|
|
60
|
+
if (typeof value !== 'string')
|
|
61
|
+
return '';
|
|
62
|
+
// eslint-disable-next-line no-control-regex
|
|
63
|
+
const flat = value.replace(/[\u0000-\u001f\u007f]+/g, ' ').replace(/\s+/g, ' ').trim();
|
|
64
|
+
return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
|
|
65
|
+
}
|
|
66
|
+
function nameOf(actor, options) {
|
|
67
|
+
if (!actor)
|
|
68
|
+
return 'someone';
|
|
69
|
+
const id = String(actor.id);
|
|
70
|
+
if (options.selfIds?.has(id))
|
|
71
|
+
return 'you';
|
|
72
|
+
if (WHOLE_SCENE_IDS.has(id))
|
|
73
|
+
return 'everyone';
|
|
74
|
+
const name = options.nameOf?.(actor)?.trim() || actor.displayName?.trim() || id;
|
|
75
|
+
return clipSceneText(name, 16) || id;
|
|
76
|
+
}
|
|
77
|
+
function formatDuration(seconds) {
|
|
78
|
+
if (!seconds || seconds <= 0)
|
|
79
|
+
return '';
|
|
80
|
+
if (seconds < 60)
|
|
81
|
+
return ` ${seconds}s`;
|
|
82
|
+
if (seconds < 3600)
|
|
83
|
+
return ` ${Math.round(seconds / 60)}m`;
|
|
84
|
+
if (seconds < 86400)
|
|
85
|
+
return ` ${Math.round(seconds / 3600)}h`;
|
|
86
|
+
return ` ${Math.round(seconds / 86400)}d`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 一条事件的极短英文摘要(≤ {@link SCENE_EVENT_SUMMARY_MAX} 字符)。不是场景事件时返回空串。
|
|
90
|
+
* 摘要只含称呼、动作与截断后的短文本;没有分数、没有原始字段。
|
|
91
|
+
*/
|
|
92
|
+
export function summarizeSceneEvent(event, options = {}) {
|
|
93
|
+
const by = (actor) => (actor ? ` by ${nameOf(actor, options)}` : '');
|
|
94
|
+
let text;
|
|
95
|
+
switch (event.type) {
|
|
96
|
+
case 'member.muted':
|
|
97
|
+
text = WHOLE_SCENE_IDS.has(String(event.member.id))
|
|
98
|
+
? `mute-all on${by(event.actor)}`
|
|
99
|
+
: `${nameOf(event.member, options)} muted${formatDuration(event.durationSeconds)}${by(event.actor)}`;
|
|
100
|
+
break;
|
|
101
|
+
case 'member.unmuted':
|
|
102
|
+
text = WHOLE_SCENE_IDS.has(String(event.member.id))
|
|
103
|
+
? `mute-all off${by(event.actor)}`
|
|
104
|
+
: `${nameOf(event.member, options)} unmuted${by(event.actor)}`;
|
|
105
|
+
break;
|
|
106
|
+
case 'member.joined':
|
|
107
|
+
text = `${nameOf(event.member, options)} joined`;
|
|
108
|
+
break;
|
|
109
|
+
case 'member.left':
|
|
110
|
+
text = event.reason === 'removed'
|
|
111
|
+
? `${nameOf(event.member, options)} removed${by(event.actor)}`
|
|
112
|
+
: `${nameOf(event.member, options)} left`;
|
|
113
|
+
break;
|
|
114
|
+
case 'member.role_changed':
|
|
115
|
+
text = `${nameOf(event.member, options)} ${event.enabled ? 'became' : 'is no longer'} ${event.role}`;
|
|
116
|
+
break;
|
|
117
|
+
case 'scene.join_requested': {
|
|
118
|
+
const comment = clipSceneText(event.comment, 24);
|
|
119
|
+
text = event.invite
|
|
120
|
+
? `${nameOf(event.actor, options)} invites you to join`
|
|
121
|
+
: `${nameOf(event.actor, options)} asks to join${comment ? `: "${comment}"` : ''}`;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case 'scene.notice_updated': {
|
|
125
|
+
const body = clipSceneText(event.text, 30);
|
|
126
|
+
text = `notice updated${by(event.actor)}${body ? `: "${body}"` : ''}`;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case 'conversation.poked':
|
|
130
|
+
text = `${nameOf(event.actor, options)} poked ${nameOf(event.target, options)}`;
|
|
131
|
+
break;
|
|
132
|
+
case 'message.reaction_changed':
|
|
133
|
+
text = `${nameOf(event.actor, options)} ${event.operation === 'removed' ? 'removed' : 'reacted'} ${clipSceneText(event.reaction, 8)}`;
|
|
134
|
+
break;
|
|
135
|
+
case 'member.card_changed':
|
|
136
|
+
case 'member.title_changed':
|
|
137
|
+
case 'member.remark_changed': {
|
|
138
|
+
const field = event.type === 'member.card_changed' ? 'card' : event.type === 'member.title_changed' ? 'title' : 'remark';
|
|
139
|
+
const value = clipSceneText(event.value, 16);
|
|
140
|
+
text = `${nameOf(event.member, options)} ${field} → ${value ? `"${value}"` : '(cleared)'}`;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
default:
|
|
144
|
+
return '';
|
|
145
|
+
}
|
|
146
|
+
return clipSceneText(text, SCENE_EVENT_SUMMARY_MAX);
|
|
147
|
+
}
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* 完整名由 `${$type}.${$scene_type}.${$sub_type}` 组合。
|
|
5
|
-
*/
|
|
6
|
-
export type SideEventKind = 'notice' | 'request' | 'system';
|
|
1
|
+
/** Semantic names for independent Notice, Request and SystemEvent contracts. */
|
|
2
|
+
export type SideEventKind = 'notice' | 'request';
|
|
3
|
+
export type EndpointEventKind = SideEventKind | 'system';
|
|
7
4
|
export type NoticeKind = 'notice';
|
|
8
5
|
export type RequestKind = 'request';
|
|
9
6
|
export type SystemKind = 'system';
|
|
10
7
|
/** 完整组合名(测试 / 文档 / 消费者匹配用) */
|
|
11
|
-
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 & {});
|
|
8
|
+
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.title_change' | 'notice.group.remark_change' | 'notice.group.notice_updated' | 'notice.group.essence_add' | 'notice.group.essence_delete' | 'notice.friend.recall' | 'notice.friend.increase' | 'notice.friend.decrease' | 'notice.friend.poke' | 'notice.endpoint.lifecycle' | (string & {});
|
|
12
9
|
export type ComposedRequestName = 'request.friend.add' | 'request.group.add' | 'request.group.invite' | (string & {});
|
|
13
10
|
export type ComposedSystemName = 'system.login.qrcode' | 'system.login.slider' | 'system.login.device' | 'system.login.error' | 'system.login.auth' | 'system.offline' | 'system.offline.network' | 'system.offline.kickoff' | 'system.online' | (string & {});
|
|
14
11
|
export interface SideEventParts {
|
|
15
12
|
scene_type: string;
|
|
16
13
|
sub_type: string;
|
|
17
14
|
}
|
|
18
|
-
/** OneBot / icqq 等平台 notice_type 原始值 → 标准 scene_type + sub_type */
|
|
19
|
-
export declare const ONEBOT_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
|
|
20
|
-
/** KOOK extra.type 原始值 → 标准 scene_type + sub_type */
|
|
21
|
-
export declare const KOOK_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
|
|
22
|
-
/** Slack event type 原始值 → 标准 scene_type + sub_type */
|
|
23
|
-
export declare const SLACK_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
|