@zhin.js/adapter-onebot12 5.0.13 → 6.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @zhin.js/adapter-onebot12
2
2
 
3
+ ## 6.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - f2c532f: Expose exact per-Endpoint message operations through one validated Adapter capability model, route Core control calls through declared active capabilities, and connect existing recall, edit, reaction, and typing implementations across platform adapters.
8
+ - Updated dependencies [b10d058]
9
+ - Updated dependencies [f2c532f]
10
+ - @zhin.js/host-http@1.0.12
11
+ - @zhin.js/adapter@1.2.0
12
+ - @zhin.js/core@1.5.13
13
+ - zhin.js@6.0.13
14
+
3
15
  ## 5.0.13
4
16
 
5
17
  ### Patch Changes
@@ -15,6 +15,7 @@ export { OneBot12WsEndpoint } from "../lib/ws-endpoint.js";
15
15
  export { OneBot12WssEndpoint } from "../lib/wss-endpoint.js";
16
16
  export default defineAdapter({
17
17
  capabilities: ['inbound', 'outbound'],
18
+ operations: ['recall'],
18
19
  // 媒体段经 upload_file 物化为 file_id(spec 正式投递);上传失败降级扩展字段透传。
19
20
  // 无卡片交互面,交互段降级纯文本。
20
21
  segments: {
@@ -29,6 +29,7 @@ declare module '@zhin.js/core' {
29
29
 
30
30
  export default defineAdapter<OneBot12AdapterConfig>({
31
31
  capabilities: ['inbound', 'outbound'],
32
+ operations: ['recall'],
32
33
  // 媒体段经 upload_file 物化为 file_id(spec 正式投递);上传失败降级扩展字段透传。
33
34
  // 无卡片交互面,交互段降级纯文本。
34
35
  segments: {
package/lib/webhook.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { EndpointInstance, EndpointManagement, EndpointSendRequest } from 'zhin.js/adapter';
1
+ import { type EndpointControl, type EndpointInstance, type EndpointManagement, type EndpointSendRequest } from 'zhin.js/adapter';
2
2
  import type { MessageGateway, SideEventGateway } from '@zhin.js/core/runtime';
3
3
  import type { HttpHost } from '@zhin.js/host-http';
4
4
  import type { CapabilityId } from 'zhin.js';
@@ -14,6 +14,7 @@ export interface OneBot12WebhookEndpointOptions {
14
14
  export declare class OneBot12WebhookEndpoint implements EndpointInstance {
15
15
  #private;
16
16
  readonly management: EndpointManagement;
17
+ readonly control: EndpointControl;
17
18
  readonly content: import("@zhin.js/adapter").EndpointContentPort;
18
19
  constructor(options: OneBot12WebhookEndpointOptions);
19
20
  start(): Promise<void>;
@@ -21,6 +22,7 @@ export declare class OneBot12WebhookEndpoint implements EndpointInstance {
21
22
  close(): void;
22
23
  stop(): Promise<void>;
23
24
  send({ conversation, payload }: EndpointSendRequest): Promise<string>;
25
+ recallMessage(messageId: string): Promise<void>;
24
26
  /** Public API for management surface / callers;webhook 模式走 api_url。 */
25
27
  callApi(action: string, params?: Record<string, unknown>): Promise<unknown>;
26
28
  admit(ev: OneBot12Event): void;
package/lib/webhook.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { createRecallEndpointControl, } from 'zhin.js/adapter';
1
2
  import { formatCompact, getLogger } from '@zhin.js/logger';
2
3
  import { createOneBot12EndpointManagement } from './endpoint-management.js';
3
4
  import { buildSendMessageParams, callOneBot12Action, formatInboundContent, formatOutboundSegments, isBotMentioned, isMessageEvent, onebot12InboundConversation, senderNickname, senderUserId, uploadOneBot12MediaSegments, } from './protocol.js';
@@ -8,6 +9,7 @@ const logger = getLogger('onebot12');
8
9
  export class OneBot12WebhookEndpoint {
9
10
  #options;
10
11
  management = createOneBot12EndpointManagement(this);
12
+ control = createRecallEndpointControl((id) => this.recallMessage(id));
11
13
  content = createOneBot12ContentPort((action, params) => this.callApi(action, params));
12
14
  #callAction;
13
15
  #routeReleases = [];
@@ -72,6 +74,11 @@ export class OneBot12WebhookEndpoint {
72
74
  }));
73
75
  return messageId;
74
76
  }
77
+ async recallMessage(messageId) {
78
+ if (!messageId)
79
+ return;
80
+ await this.callApi('delete_message', { message_id: messageId });
81
+ }
75
82
  /** Public API for management surface / callers;webhook 模式走 api_url。 */
76
83
  async callApi(action, params = {}) {
77
84
  const apiUrl = this.#options.config.api_url;
@@ -1,4 +1,4 @@
1
- import { type EndpointInstance, type EndpointManagement, type EndpointSendRequest } from 'zhin.js/adapter';
1
+ import { type EndpointControl, type EndpointInstance, type EndpointManagement, type EndpointSendRequest } from 'zhin.js/adapter';
2
2
  import type { MessageGateway, SideEventGateway } from '@zhin.js/core/runtime';
3
3
  import type { CapabilityId } from 'zhin.js';
4
4
  import { type OneBot12Event, type OneBot12WsConfig } from './protocol.js';
@@ -13,6 +13,7 @@ export interface OneBot12WsEndpointOptions {
13
13
  export declare class OneBot12WsEndpoint implements EndpointInstance {
14
14
  #private;
15
15
  readonly management: EndpointManagement;
16
+ readonly control: EndpointControl;
16
17
  readonly content: import("@zhin.js/adapter").EndpointContentPort;
17
18
  constructor(options: OneBot12WsEndpointOptions);
18
19
  start(): Promise<void>;
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import WebSocket from 'ws';
5
5
  import { clearTimeout } from 'node:timers';
6
- import { createEndpointLifecycle, } from 'zhin.js/adapter';
6
+ import { createRecallEndpointControl, createEndpointLifecycle, } from 'zhin.js/adapter';
7
7
  import { formatCompact, getAdapterLogger } from '@zhin.js/logger';
8
8
  import { createOneBot12EndpointManagement } from './endpoint-management.js';
9
9
  import { buildSendMessageParams, buildWsConnectOptions, formatInboundContent, formatOutboundSegments, isBotMentioned, isMessageEvent, onebot12InboundConversation, senderNickname, senderUserId, uploadOneBot12MediaSegments, } from './protocol.js';
@@ -14,6 +14,7 @@ export class OneBot12WsEndpoint {
14
14
  #logger;
15
15
  #options;
16
16
  management = createOneBot12EndpointManagement(this);
17
+ control = createRecallEndpointControl((id) => this.recallMessage(id));
17
18
  content = createOneBot12ContentPort((action, params) => this.callApi(action, params));
18
19
  #lifecycle;
19
20
  #ws;
@@ -1,4 +1,4 @@
1
- import type { EndpointInstance, EndpointManagement, EndpointSendRequest } from 'zhin.js/adapter';
1
+ import { type EndpointControl, type EndpointInstance, type EndpointManagement, type EndpointSendRequest } from 'zhin.js/adapter';
2
2
  import type { MessageGateway, SideEventGateway } from '@zhin.js/core/runtime';
3
3
  import type { HttpHost } from '@zhin.js/host-http';
4
4
  import type { CapabilityId } from 'zhin.js';
@@ -13,6 +13,7 @@ export interface OneBot12WssEndpointOptions {
13
13
  export declare class OneBot12WssEndpoint implements EndpointInstance {
14
14
  #private;
15
15
  readonly management: EndpointManagement;
16
+ readonly control: EndpointControl;
16
17
  readonly content: import("@zhin.js/adapter").EndpointContentPort;
17
18
  constructor(options: OneBot12WssEndpointOptions);
18
19
  start(): Promise<void>;
@@ -2,6 +2,7 @@
2
2
  * OneBot12 reverse WSS endpoint — accepts inbound WebSocket from OneBot implementation.
3
3
  */
4
4
  import { clearInterval } from 'node:timers';
5
+ import { createRecallEndpointControl, } from 'zhin.js/adapter';
5
6
  import { formatCompact, getAdapterLogger } from '@zhin.js/logger';
6
7
  import { createOneBot12EndpointManagement } from './endpoint-management.js';
7
8
  import { buildSendMessageParams, formatInboundContent, formatOutboundSegments, isBotMentioned, isMessageEvent, onebot12InboundConversation, senderNickname, senderUserId, uploadOneBot12MediaSegments, } from './protocol.js';
@@ -13,6 +14,7 @@ export class OneBot12WssEndpoint {
13
14
  #logger;
14
15
  #options;
15
16
  management = createOneBot12EndpointManagement(this);
17
+ control = createRecallEndpointControl((id) => this.recallMessage(id));
16
18
  content = createOneBot12ContentPort((action, params) => this.callApi(action, params));
17
19
  #ws;
18
20
  #wsRelease;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/adapter-onebot12",
3
- "version": "5.0.13",
3
+ "version": "6.0.0",
4
4
  "description": "Zhin.js OneBot 12 adapter for Plugin Runtime (WebSocket client)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -40,9 +40,9 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "ws": "^8.21.1",
43
- "@zhin.js/adapter": "1.1.11",
44
- "@zhin.js/core": "1.5.12",
45
- "@zhin.js/host-http": "1.0.11",
43
+ "@zhin.js/adapter": "1.2.0",
44
+ "@zhin.js/core": "1.5.13",
45
+ "@zhin.js/host-http": "1.0.12",
46
46
  "@zhin.js/im-contract": "1.0.4",
47
47
  "@zhin.js/logger": "1.0.76"
48
48
  },
@@ -51,14 +51,14 @@
51
51
  "@types/ws": "^8.18.1",
52
52
  "typescript": "^6.0.3",
53
53
  "vitest": "^4.1.10",
54
- "@zhin.js/host-http": "1.0.11",
55
- "zhin.js": "6.0.12"
54
+ "@zhin.js/host-http": "1.0.12",
55
+ "zhin.js": "6.0.13"
56
56
  },
57
57
  "peerDependencies": {
58
- "@zhin.js/adapter": "1.1.11",
58
+ "@zhin.js/adapter": "1.2.0",
59
59
  "@zhin.js/command": "1.0.15",
60
- "@zhin.js/core": "1.5.12",
61
- "zhin.js": "6.0.12"
60
+ "@zhin.js/core": "1.5.13",
61
+ "zhin.js": "6.0.13"
62
62
  },
63
63
  "peerDependenciesMeta": {
64
64
  "@zhin.js/command": {
package/src/webhook.ts CHANGED
@@ -2,7 +2,13 @@
2
2
  * OneBot12 HTTP webhook endpoint — POST inbound + api_url outbound.
3
3
  */
4
4
  import type { IncomingMessage, ServerResponse } from 'node:http';
5
- import type { EndpointInstance, EndpointManagement, EndpointSendRequest } from 'zhin.js/adapter';
5
+ import {
6
+ createRecallEndpointControl,
7
+ type EndpointControl,
8
+ type EndpointInstance,
9
+ type EndpointManagement,
10
+ type EndpointSendRequest,
11
+ } from 'zhin.js/adapter';
6
12
  import type { MessageGateway, SideEventGateway } from '@zhin.js/core/runtime';
7
13
  import type { HttpHost, HttpRouteRegistration } from '@zhin.js/host-http';
8
14
  import { formatCompact, getLogger } from '@zhin.js/logger';
@@ -40,6 +46,7 @@ export interface OneBot12WebhookEndpointOptions {
40
46
  export class OneBot12WebhookEndpoint implements EndpointInstance {
41
47
  readonly #options: OneBot12WebhookEndpointOptions;
42
48
  readonly management: EndpointManagement = createOneBot12EndpointManagement(this);
49
+ readonly control: EndpointControl = createRecallEndpointControl((id) => this.recallMessage(id));
43
50
  readonly content = createOneBot12ContentPort((action, params) => this.callApi(action, params));
44
51
  readonly #callAction: typeof callOneBot12Action;
45
52
  #routeReleases: HttpRouteRegistration[] = [];
@@ -113,6 +120,11 @@ export class OneBot12WebhookEndpoint implements EndpointInstance {
113
120
  return messageId;
114
121
  }
115
122
 
123
+ async recallMessage(messageId: string): Promise<void> {
124
+ if (!messageId) return;
125
+ await this.callApi('delete_message', { message_id: messageId });
126
+ }
127
+
116
128
  /** Public API for management surface / callers;webhook 模式走 api_url。 */
117
129
  async callApi(action: string, params: Record<string, unknown> = {}): Promise<unknown> {
118
130
  const apiUrl = this.#options.config.api_url;
@@ -4,8 +4,10 @@
4
4
  import WebSocket from 'ws';
5
5
  import { clearTimeout } from 'node:timers';
6
6
  import {
7
+ createRecallEndpointControl,
7
8
  createEndpointLifecycle,
8
9
  type EndpointConnectHandle,
10
+ type EndpointControl,
9
11
  type EndpointInstance,
10
12
  type EndpointLifecycle,
11
13
  type EndpointManagement,
@@ -55,6 +57,7 @@ export class OneBot12WsEndpoint implements EndpointInstance {
55
57
 
56
58
  readonly #options: OneBot12WsEndpointOptions;
57
59
  readonly management: EndpointManagement = createOneBot12EndpointManagement(this);
60
+ readonly control: EndpointControl = createRecallEndpointControl((id) => this.recallMessage(id));
58
61
  readonly content = createOneBot12ContentPort((action, params) => this.callApi(action, params));
59
62
  readonly #lifecycle: EndpointLifecycle;
60
63
  #ws?: OneBot12WsSocket;
@@ -2,7 +2,13 @@
2
2
  * OneBot12 reverse WSS endpoint — accepts inbound WebSocket from OneBot implementation.
3
3
  */
4
4
  import { clearInterval } from 'node:timers';
5
- import type { EndpointInstance, EndpointManagement, EndpointSendRequest } from 'zhin.js/adapter';
5
+ import {
6
+ createRecallEndpointControl,
7
+ type EndpointControl,
8
+ type EndpointInstance,
9
+ type EndpointManagement,
10
+ type EndpointSendRequest,
11
+ } from 'zhin.js/adapter';
6
12
  import type { MessageGateway, SideEventGateway } from '@zhin.js/core/runtime';
7
13
  import type { HttpHost, WsConnection } from '@zhin.js/host-http';
8
14
  import { formatCompact, getAdapterLogger } from '@zhin.js/logger';
@@ -41,6 +47,7 @@ export class OneBot12WssEndpoint implements EndpointInstance {
41
47
 
42
48
  readonly #options: OneBot12WssEndpointOptions;
43
49
  readonly management: EndpointManagement = createOneBot12EndpointManagement(this);
50
+ readonly control: EndpointControl = createRecallEndpointControl((id) => this.recallMessage(id));
44
51
  readonly content = createOneBot12ContentPort((action, params) => this.callApi(action, params));
45
52
  #ws?: OneBot12WsSocket;
46
53
  #wsRelease?: () => void;