@zhin.js/core 1.1.38 → 1.1.40

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 (52) hide show
  1. package/lib/built/ai-access.d.ts +2 -2
  2. package/lib/built/ai-access.js +4 -4
  3. package/lib/built/ai-outbound/types.d.ts +1 -1
  4. package/lib/built/ai-trigger.d.ts +1 -1
  5. package/lib/built/ai-trigger.js +17 -10
  6. package/lib/built/interactive-segments/action.d.ts +3 -3
  7. package/lib/built/interactive-segments/action.js +1 -1
  8. package/lib/built/message-enrich.d.ts +19 -22
  9. package/lib/built/message-enrich.js +47 -42
  10. package/lib/built/tool-access.d.ts +2 -2
  11. package/lib/built/tool-access.js +2 -2
  12. package/lib/im-scene.d.ts +4 -3
  13. package/lib/im-scene.js +9 -9
  14. package/lib/im-session-id.d.ts +20 -12
  15. package/lib/im-session-id.js +8 -8
  16. package/lib/index.d.ts +2 -1
  17. package/lib/index.js +1 -1
  18. package/lib/message.d.ts +1 -29
  19. package/lib/message.js +1 -27
  20. package/lib/notice.d.ts +34 -32
  21. package/lib/notice.js +21 -7
  22. package/lib/plugin-runtime/im/contracts.d.ts +23 -1
  23. package/lib/plugin-runtime/im/contracts.js +4 -1
  24. package/lib/plugin-runtime/im/conversation-runtime.js +22 -31
  25. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +6 -1
  26. package/lib/plugin-runtime/im/endpoint-runtime.js +27 -5
  27. package/lib/plugin-runtime/im/inbound-runtime.d.ts +2 -2
  28. package/lib/plugin-runtime/im/inbound-runtime.js +58 -29
  29. package/lib/plugin-runtime/im/index.d.ts +3 -0
  30. package/lib/plugin-runtime/im/index.js +3 -0
  31. package/lib/plugin-runtime/im/message-dispatcher.js +28 -4
  32. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +1 -1
  33. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +54 -12
  34. package/lib/plugin-runtime/im/outbound-renderer.js +1 -1
  35. package/lib/plugin-runtime/im/outbound-segments.d.ts +2 -0
  36. package/lib/plugin-runtime/im/outbound-segments.js +8 -0
  37. package/lib/plugin-runtime/im/public-api.d.ts +1 -1
  38. package/lib/plugin-runtime/im/runtime-middleware.js +1 -1
  39. package/lib/request.d.ts +27 -35
  40. package/lib/request.js +14 -6
  41. package/lib/side-event/base.d.ts +64 -43
  42. package/lib/side-event/base.js +66 -19
  43. package/lib/side-event/dispatch.js +40 -38
  44. package/lib/side-event/normalize.d.ts +9 -8
  45. package/lib/side-event/normalize.js +9 -8
  46. package/lib/side-event/types.d.ts +3 -6
  47. package/lib/side-event/types.js +0 -5
  48. package/lib/system-event.d.ts +17 -11
  49. package/lib/system-event.js +8 -6
  50. package/lib/types.d.ts +3 -2
  51. package/lib/utils.d.ts +1 -1
  52. package/package.json +10 -10
@@ -1,6 +1,3 @@
1
- import { Notice } from '../notice.js';
2
- import { Request } from '../request.js';
3
- import { SystemEvent } from '../system-event.js';
4
1
  import { parseSideEventName } from './base.js';
5
2
  import { KOOK_NOTICE_PARTS_MAP, ONEBOT_NOTICE_PARTS_MAP, SLACK_NOTICE_PARTS_MAP } from './types.js';
6
3
  /** 去重用:notice / request 无稳定 id 时组合键 */
@@ -34,7 +31,7 @@ function resolveEssenceNoticeParts(subType) {
34
31
  : { scene_type: 'group', sub_type: 'essence_delete' };
35
32
  }
36
33
  /**
37
- * 将平台原始 notice_type 映射为标准 `$scene_type` + `$sub_type`。
34
+ * 将平台原始 notice_type 映射为标准 `scene_type` + `sub_type`。
38
35
  */
39
36
  export function mapNoticeParts(platform, raw, options) {
40
37
  const subType = options?.sub_type;
@@ -52,6 +49,9 @@ export function mapNoticeParts(platform, raw, options) {
52
49
  if (raw === 'essence') {
53
50
  return resolveEssenceNoticeParts(subType);
54
51
  }
52
+ if (platform === 'icqq' && (raw === 'group' || raw === 'friend') && subType) {
53
+ return ONEBOT_NOTICE_PARTS_MAP[`${raw}.${subType}`] ?? { scene_type: raw, sub_type: subType };
54
+ }
55
55
  if (ONEBOT_NOTICE_PARTS_MAP[raw]) {
56
56
  return ONEBOT_NOTICE_PARTS_MAP[raw];
57
57
  }
@@ -76,7 +76,7 @@ export function mapNoticeParts(platform, raw, options) {
76
76
  return { scene_type: platform, sub_type: raw };
77
77
  }
78
78
  /**
79
- * 将平台原始 request_type 映射为标准 `$scene_type` + `$sub_type`。
79
+ * 将平台原始 request_type 映射为标准 `scene_type` + `sub_type`。
80
80
  */
81
81
  export function mapRequestParts(_platform, raw, subType) {
82
82
  if (raw === 'friend' || raw.startsWith('friend')) {
@@ -100,12 +100,13 @@ export function senderFromId(id, name) {
100
100
  const s = String(id);
101
101
  return { id: s, name: name ?? s };
102
102
  }
103
+ /** Keep native fields under metadata; never mutate or flatten the platform event. */
103
104
  export function buildNotice(input, format) {
104
- return Notice.from(input, format);
105
+ return Object.freeze({ ...format, metadata: Object.freeze({ ...input }) });
105
106
  }
106
107
  export function buildRequest(input, format) {
107
- return Request.from(input, format);
108
+ return Object.freeze({ ...format, metadata: Object.freeze({ ...input }) });
108
109
  }
109
110
  export function buildSystem(input, format) {
110
- return SystemEvent.from(input, format);
111
+ return Object.freeze({ ...format, metadata: Object.freeze({ ...input }) });
111
112
  }
@@ -1,9 +1,6 @@
1
- /**
2
- * Side Event 标准类型。
3
- * 运行时 `$type` 仅存命名空间(`notice` / `request` / `system`);
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';
@@ -1,8 +1,3 @@
1
- /**
2
- * Side Event 标准类型。
3
- * 运行时 `$type` 仅存命名空间(`notice` / `request` / `system`);
4
- * 完整名由 `${$type}.${$scene_type}.${$sub_type}` 组合。
5
- */
6
1
  /** OneBot / icqq 等平台 notice_type 原始值 → 标准 scene_type + sub_type */
7
2
  export const ONEBOT_NOTICE_PARTS_MAP = {
8
3
  group_increase: { scene_type: 'group', sub_type: 'member_increase' },
@@ -1,14 +1,20 @@
1
- import type { SideEventBase } from './side-event/base.js';
2
- /**
3
- * 系统/登录侧事件(扫码、滑块、掉线等)。
4
- * `$scene_type`:`login` / `offline` / `online` 等;
5
- * `$sub_type`:`qrcode` / `slider` / `device` / `kickoff` / `network` 等。
6
- */
7
- export interface SystemEventBase extends SideEventBase {
8
- $adapter: string;
9
- $type: 'system';
1
+ import type { ComposedSystemName } from './side-event/types.js';
2
+ import { RuntimeEndpointEvent, type IncomingEndpointEvent, type EndpointEventBase, type EndpointEventContext } from './side-event/base.js';
3
+ export type { ComposedSystemName, SystemKind } from './side-event/types.js';
4
+ export type { IncomingEndpointEvent, EndpointEventBase } from './side-event/base.js';
5
+ export interface IncomingSystemEvent extends IncomingEndpointEvent {
6
+ readonly type: 'system';
7
+ readonly name: ComposedSystemName;
8
+ }
9
+ export interface SystemEventBase extends EndpointEventBase {
10
+ readonly type: 'system';
11
+ readonly name: ComposedSystemName;
10
12
  }
11
13
  export type SystemEvent<T extends object = {}> = SystemEventBase & T;
12
- export declare namespace SystemEvent {
13
- function from<T extends object>(input: T, format: SystemEventBase): SystemEvent<T>;
14
+ /** @internal Endpoint lifecycle signals do not imply a conversation. */
15
+ export declare class RuntimeSystemEvent extends RuntimeEndpointEvent implements SystemEventBase {
16
+ readonly type: 'system';
17
+ readonly name: ComposedSystemName;
18
+ constructor(input: IncomingSystemEvent, context: EndpointEventContext);
14
19
  }
20
+ export declare const SystemEvent: typeof RuntimeSystemEvent;
@@ -1,7 +1,9 @@
1
- export var SystemEvent;
2
- (function (SystemEvent) {
3
- function from(input, format) {
4
- return Object.assign(input, format);
1
+ import { RuntimeEndpointEvent } from './side-event/base.js';
2
+ /** @internal Endpoint lifecycle signals do not imply a conversation. */
3
+ export class RuntimeSystemEvent extends RuntimeEndpointEvent {
4
+ constructor(input, context) {
5
+ super(input, context);
6
+ Object.freeze(this);
5
7
  }
6
- SystemEvent.from = from;
7
- })(SystemEvent || (SystemEvent = {}));
8
+ }
9
+ export const SystemEvent = RuntimeSystemEvent;
package/lib/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { MessageChannel, Message, MessageComponent } from './message.js';
1
+ import type { MessageChannel, MessageComponent } from './message.js';
2
+ import type { Message } from './plugin-runtime/im/contracts.js';
2
3
  import { SystemLog } from './models/system-log.js';
3
4
  import { User } from './models/user.js';
4
5
  export type { SenderRole } from "./built/roles.js";
@@ -237,7 +238,7 @@ export interface Tool<TArgs extends Record<string, any> = Record<string, any>> {
237
238
  * @param message 通讯上下文(入站 Message 或合成 Message)
238
239
  * @returns 执行结果
239
240
  */
240
- execute: (args: TArgs, message?: Message<any>) => MaybePromise<ToolResult>;
241
+ execute: (args: TArgs, message?: Message) => MaybePromise<ToolResult>;
241
242
  /** 工具来源标识(自动填充:adapter:xxx / plugin:xxx) */
242
243
  source?: string;
243
244
  /** 工具标签(用于分类和过滤) */
package/lib/utils.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
  export { evaluate, execute, getValueWithRuntime, compiler, remove, isEmpty, Time, supportedPluginExtensions, resolveEntry, sleep, } from '@zhin.js/kernel';
8
8
  import { MessageMiddleware, SendContent } from "./types.js";
9
- import { Message } from "./message.js";
9
+ import type { Message } from "./plugin-runtime/im/contracts.js";
10
10
  import { KeyboardSegment } from "./built/interactive-segments/keyboard-segment.js";
11
11
  import { ButtonSpec, type KeyboardRowInput } from "./built/interactive-segments/button-spec.js";
12
12
  import type { ButtonData, KeyboardFallback } from "./built/interactive-segments/types.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/core",
3
- "version": "1.1.38",
3
+ "version": "1.1.40",
4
4
  "description": "Zhin机器人核心框架",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -68,27 +68,27 @@
68
68
  "dependencies": {
69
69
  "qrcode": "^1.5.4",
70
70
  "segment-matcher": "^1.0.5",
71
- "@zhin.js/adapter": "1.1.15",
72
- "@zhin.js/component": "1.1.2",
71
+ "@zhin.js/adapter": "1.1.16",
72
+ "@zhin.js/command": "1.1.4",
73
+ "@zhin.js/component": "1.1.3",
73
74
  "@zhin.js/database": "1.1.2",
74
75
  "@zhin.js/handler": "1.1.2",
75
- "@zhin.js/im-contract": "1.1.2",
76
+ "@zhin.js/im-contract": "1.1.3",
76
77
  "@zhin.js/interaction": "1.1.0",
77
- "@zhin.js/kernel": "1.1.1",
78
+ "@zhin.js/kernel": "1.1.2",
78
79
  "@zhin.js/logger": "1.1.1",
79
- "@zhin.js/middleware": "1.1.2",
80
- "@zhin.js/permission": "1.1.2",
81
- "@zhin.js/command": "1.1.2",
80
+ "@zhin.js/middleware": "1.1.3",
81
+ "@zhin.js/permission": "1.1.3",
82
82
  "@zhin.js/plugin-runtime": "1.1.11",
83
83
  "@zhin.js/schedule-feature": "1.1.2",
84
- "@zhin.js/schema": "1.1.0"
84
+ "@zhin.js/schema": "1.1.1"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@types/node": "^26.1.2",
88
88
  "@types/qrcode": "^1.5.6",
89
89
  "ajv": "8.18.0",
90
90
  "typescript": "^6.0.3",
91
- "@zhin.js/ai": "1.1.35"
91
+ "@zhin.js/ai": "1.1.36"
92
92
  },
93
93
  "repository": {
94
94
  "type": "git",