@zhin.js/adapter-onebot12 5.0.13 → 6.0.1

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.
@@ -3,26 +3,37 @@
3
3
  */
4
4
  import WebSocket from 'ws';
5
5
  import { clearTimeout } from 'node:timers';
6
- import { createEndpointLifecycle, } from 'zhin.js/adapter';
6
+ import { ClientEndpoint, 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';
10
10
  import { receiveOneBot12SideEvent } from './side-event-dispatch.js';
11
11
  import { createOneBot12ContentPort } from './content-port.js';
12
+ import { callOnebot12Client, createOnebot12EndpointClient, forwardOnebot12ClientEvents } from './client.js';
12
13
  import { WS_OPEN, } from './ws-types.js';
13
- export class OneBot12WsEndpoint {
14
+ export class OneBot12WsEndpoint extends ClientEndpoint {
15
+ client;
14
16
  #logger;
15
17
  #options;
16
- management = createOneBot12EndpointManagement(this);
17
- content = createOneBot12ContentPort((action, params) => this.callApi(action, params));
18
+ management;
19
+ control = createRecallEndpointControl((id) => this.recallMessage(id));
20
+ content;
18
21
  #lifecycle;
19
22
  #ws;
20
23
  #requestId = 0;
21
24
  #pending = new Map();
22
- #open = false;
23
25
  constructor(options) {
26
+ super();
24
27
  this.#logger = getAdapterLogger('onebot12', options.config.id);
25
28
  this.#options = options;
29
+ this.client = createOnebot12EndpointClient(options.config, (action, params) => this.#callAction(action, params ?? {}));
30
+ const callApi = (action, params) => callOnebot12Client(this.client, action, params);
31
+ this.management = createOneBot12EndpointManagement({ callApi });
32
+ this.content = createOneBot12ContentPort(callApi);
33
+ this.bindClientEvents((receive) => forwardOnebot12ClientEvents(this.client, receive), (name, payload) => {
34
+ if (name === 'event')
35
+ this.#admitRaw(payload);
36
+ }, (_name, error) => this.#warnPlatformEvent(error));
26
37
  const { config } = options;
27
38
  this.#lifecycle = createEndpointLifecycle({
28
39
  name: config.id,
@@ -56,14 +67,8 @@ export class OneBot12WsEndpoint {
56
67
  throw err;
57
68
  }
58
69
  }
59
- open() {
60
- this.#open = true;
61
- }
62
- close() {
63
- this.#open = false;
64
- }
65
70
  async stop() {
66
- this.#open = false;
71
+ this.close();
67
72
  // 基座负责:清重连/心跳定时器、强关 ws、唤醒 stop-during-connect 竞态
68
73
  await this.#lifecycle.stop();
69
74
  for (const [, pending] of this.#pending) {
@@ -74,7 +79,7 @@ export class OneBot12WsEndpoint {
74
79
  this.#ws = undefined;
75
80
  }
76
81
  async send({ conversation, payload }) {
77
- const materialized = await uploadOneBot12MediaSegments(payload, (action, params) => this.callApi(action, params), (error) => {
82
+ const materialized = await uploadOneBot12MediaSegments(payload, (action, params) => callOnebot12Client(this.client, action, params), (error) => {
78
83
  this.#logger.warn(formatCompact({
79
84
  op: 'onebot12_upload_failed',
80
85
  endpoint: this.#options.config.id,
@@ -83,7 +88,7 @@ export class OneBot12WsEndpoint {
83
88
  });
84
89
  const message = formatOutboundSegments(materialized);
85
90
  const params = buildSendMessageParams(conversation, message);
86
- const data = await this.#callAction('send_message', params);
91
+ const data = await callOnebot12Client(this.client, 'send_message', params);
87
92
  const messageId = data?.message_id ?? '';
88
93
  this.#logger.debug(formatCompact({
89
94
  op: 'onebot12_send',
@@ -97,25 +102,18 @@ export class OneBot12WsEndpoint {
97
102
  async recallMessage(messageId) {
98
103
  if (!messageId)
99
104
  return;
100
- await this.#callAction('delete_message', { message_id: messageId });
101
- }
102
- /** Public API for management surface / callers. */
103
- callApi(action, params = {}) {
104
- return this.#callAction(action, params);
105
+ await callOnebot12Client(this.client, 'delete_message', { message_id: messageId });
105
106
  }
106
- /** Test / internal: admit a parsed event when the endpoint is open. */
107
- admit(ev) {
108
- if (!this.#open)
109
- return;
107
+ #admitRaw(ev) {
110
108
  if (!isMessageEvent(ev)) {
111
- receiveOneBot12SideEvent(this.#options.sideEvents, this.#options.config.id, this, ev, this.#logger);
109
+ receiveOneBot12SideEvent((name, payload) => this.emit(name, payload), this.#options.config.id, { callApi: (action, params) => callOnebot12Client(this.client, action, params) }, ev, this.#logger);
112
110
  return;
113
111
  }
114
112
  const conversation = onebot12InboundConversation(String(this.#options.id), ev);
115
113
  const content = formatInboundContent(ev);
116
114
  const nickname = senderNickname(ev);
117
115
  const mentioned = isBotMentioned(ev);
118
- void this.#options.gateway.receive({
116
+ void this.emit('message.receive', {
119
117
  conversation,
120
118
  message: { conversation, id: ev.message_id },
121
119
  content,
@@ -140,6 +138,12 @@ export class OneBot12WsEndpoint {
140
138
  }));
141
139
  });
142
140
  }
141
+ #warnPlatformEvent(error) {
142
+ this.#logger.warn(formatCompact({
143
+ op: 'onebot12_platform_event_failed',
144
+ error: error instanceof Error ? error.message : String(error),
145
+ }));
146
+ }
143
147
  async #connect(handle) {
144
148
  const { url, headers, safeUrl } = buildWsConnectOptions(this.#options.config);
145
149
  const create = this.#options.createWebSocket
@@ -219,14 +223,11 @@ export class OneBot12WsEndpoint {
219
223
  if (pending) {
220
224
  this.#pending.delete(resp.echo);
221
225
  clearTimeout(pending.timeout);
222
- if (resp.status === 'ok')
223
- pending.resolve(resp.data);
224
- else
225
- pending.reject(new Error(`OneBot12 retcode=${resp.retcode}: ${resp.message}`));
226
+ pending.resolve(resp);
226
227
  }
227
228
  return;
228
229
  }
229
- this.admit(msg);
230
+ this.client.ingest(msg);
230
231
  }
231
232
  catch (error) {
232
233
  this.#logger.warn(formatCompact({
@@ -1,27 +1,25 @@
1
- import type { EndpointInstance, EndpointManagement, EndpointSendRequest } from 'zhin.js/adapter';
2
- import type { MessageGateway, SideEventGateway } from '@zhin.js/core/runtime';
1
+ /**
2
+ * OneBot12 reverse WSS endpoint — accepts inbound WebSocket from OneBot implementation.
3
+ */
4
+ import { ClientEndpoint, type EndpointControl, type EndpointManagement, type EndpointSendRequest } from 'zhin.js/adapter';
3
5
  import type { HttpHost } from '@zhin.js/host-http';
4
6
  import type { CapabilityId } from 'zhin.js';
5
- import { type OneBot12Event, type OneBot12WssConfig } from './protocol.js';
7
+ import { type OneBot12WssConfig } from './protocol.js';
8
+ import { type Onebot12Client } from './client.js';
6
9
  export interface OneBot12WssEndpointOptions {
7
10
  readonly id: CapabilityId;
8
- readonly gateway: MessageGateway;
9
- readonly sideEvents?: SideEventGateway;
10
11
  readonly http: HttpHost;
11
12
  readonly config: OneBot12WssConfig;
12
13
  }
13
- export declare class OneBot12WssEndpoint implements EndpointInstance {
14
+ export declare class OneBot12WssEndpoint extends ClientEndpoint<Onebot12Client> {
14
15
  #private;
16
+ readonly client: Onebot12Client;
15
17
  readonly management: EndpointManagement;
18
+ readonly control: EndpointControl;
16
19
  readonly content: import("@zhin.js/adapter").EndpointContentPort;
17
20
  constructor(options: OneBot12WssEndpointOptions);
18
21
  start(): Promise<void>;
19
- open(): void;
20
- close(): void;
21
22
  stop(): Promise<void>;
22
23
  send({ conversation, payload }: EndpointSendRequest): Promise<string>;
23
24
  recallMessage(messageId: string): Promise<void>;
24
- /** Public API for management surface / callers. */
25
- callApi(action: string, params?: Record<string, unknown>): Promise<unknown>;
26
- admit(ev: OneBot12Event): void;
27
25
  }
@@ -1,34 +1,46 @@
1
1
  /**
2
2
  * OneBot12 reverse WSS endpoint — accepts inbound WebSocket from OneBot implementation.
3
3
  */
4
- import { clearInterval } from 'node:timers';
4
+ import { ClientEndpoint, createEndpointLifecycle, createRecallEndpointControl, } from 'zhin.js/adapter';
5
5
  import { formatCompact, getAdapterLogger } from '@zhin.js/logger';
6
6
  import { createOneBot12EndpointManagement } from './endpoint-management.js';
7
7
  import { buildSendMessageParams, formatInboundContent, formatOutboundSegments, isBotMentioned, isMessageEvent, onebot12InboundConversation, senderNickname, senderUserId, uploadOneBot12MediaSegments, } from './protocol.js';
8
8
  import { receiveOneBot12SideEvent } from './side-event-dispatch.js';
9
9
  import { createOneBot12ContentPort } from './content-port.js';
10
+ import { callOnebot12Client, createOnebot12EndpointClient, forwardOnebot12ClientEvents } from './client.js';
10
11
  import { verifyOneBotAccessToken } from './wss-auth.js';
11
12
  import { WS_OPEN } from './ws-types.js';
12
- export class OneBot12WssEndpoint {
13
+ export class OneBot12WssEndpoint extends ClientEndpoint {
14
+ client;
13
15
  #logger;
14
16
  #options;
15
- management = createOneBot12EndpointManagement(this);
16
- content = createOneBot12ContentPort((action, params) => this.callApi(action, params));
17
+ management;
18
+ control = createRecallEndpointControl((id) => this.recallMessage(id));
19
+ content;
17
20
  #ws;
18
21
  #wsRelease;
19
- #heartbeatTimer;
22
+ #lifecycle;
20
23
  #requestId = 0;
21
24
  #pending = new Map();
22
- #open = false;
23
- #started = false;
24
25
  constructor(options) {
26
+ super();
25
27
  this.#logger = getAdapterLogger('onebot12', options.config.id);
26
28
  this.#options = options;
29
+ this.#lifecycle = createEndpointLifecycle({
30
+ name: options.config.id,
31
+ reconnect: false,
32
+ heartbeat: { intervalMs: options.config.heartbeat_interval },
33
+ });
34
+ this.client = createOnebot12EndpointClient(options.config, (action, params) => this.#callAction(action, params ?? {}));
35
+ const callApi = (action, params) => callOnebot12Client(this.client, action, params);
36
+ this.management = createOneBot12EndpointManagement({ callApi });
37
+ this.content = createOneBot12ContentPort(callApi);
38
+ this.bindClientEvents((receive) => forwardOnebot12ClientEvents(this.client, receive), (name, payload) => {
39
+ if (name === 'event')
40
+ this.#admitRaw(payload);
41
+ }, (_name, error) => this.#warnPlatformEvent(error));
27
42
  }
28
43
  async start() {
29
- if (this.#started)
30
- return;
31
- this.#started = true;
32
44
  if (!this.#options.config.access_token) {
33
45
  // wss 模式未配 access_token 时任何连接都会被放行(verifyOneBotAccessToken 直接 return true)
34
46
  this.#logger.warn(formatCompact({
@@ -38,9 +50,22 @@ export class OneBot12WssEndpoint {
38
50
  error: 'missing access_token',
39
51
  }));
40
52
  }
41
- const handle = this.#options.http.ws(this.#options.config.path);
42
- this.#wsRelease = handle.onConnection((connection) => {
43
- this.#acceptConnection(connection);
53
+ await this.#lifecycle.start(async (lifecycleHandle) => {
54
+ const handle = this.#options.http.ws(this.#options.config.path);
55
+ this.#wsRelease = handle.onConnection((connection) => {
56
+ this.#acceptConnection(connection);
57
+ });
58
+ lifecycleHandle.onForceClose(() => {
59
+ this.#wsRelease?.();
60
+ this.#wsRelease = undefined;
61
+ try {
62
+ this.#ws?.close();
63
+ }
64
+ catch {
65
+ /* ignore */
66
+ }
67
+ this.#ws = undefined;
68
+ });
44
69
  });
45
70
  this.#logger.info(formatCompact({
46
71
  op: 'listen',
@@ -49,38 +74,17 @@ export class OneBot12WssEndpoint {
49
74
  path: this.#options.config.path,
50
75
  }));
51
76
  }
52
- open() {
53
- this.#open = true;
54
- }
55
- close() {
56
- this.#open = false;
57
- }
58
77
  async stop() {
59
- this.#open = false;
60
- this.#wsRelease?.();
61
- this.#wsRelease = undefined;
62
- if (this.#heartbeatTimer) {
63
- clearInterval(this.#heartbeatTimer);
64
- this.#heartbeatTimer = undefined;
65
- }
78
+ this.close();
79
+ await this.#lifecycle.stop();
66
80
  for (const [, pending] of this.#pending) {
67
81
  clearTimeout(pending.timeout);
68
82
  pending.reject(new Error('连接已关闭'));
69
83
  }
70
84
  this.#pending.clear();
71
- if (this.#ws) {
72
- try {
73
- this.#ws.close();
74
- }
75
- catch {
76
- /* ignore */
77
- }
78
- this.#ws = undefined;
79
- }
80
- this.#started = false;
81
85
  }
82
86
  async send({ conversation, payload }) {
83
- const materialized = await uploadOneBot12MediaSegments(payload, (action, params) => this.callApi(action, params), (error) => {
87
+ const materialized = await uploadOneBot12MediaSegments(payload, (action, params) => callOnebot12Client(this.client, action, params), (error) => {
84
88
  this.#logger.warn(formatCompact({
85
89
  op: 'onebot12_upload_failed',
86
90
  endpoint: this.#options.config.id,
@@ -89,29 +93,23 @@ export class OneBot12WssEndpoint {
89
93
  });
90
94
  const message = formatOutboundSegments(materialized);
91
95
  const params = buildSendMessageParams(conversation, message);
92
- const data = await this.#callAction('send_message', params);
96
+ const data = await callOnebot12Client(this.client, 'send_message', params);
93
97
  return data?.message_id ?? '';
94
98
  }
95
99
  async recallMessage(messageId) {
96
100
  if (!messageId)
97
101
  return;
98
- await this.#callAction('delete_message', { message_id: messageId });
102
+ await callOnebot12Client(this.client, 'delete_message', { message_id: messageId });
99
103
  }
100
- /** Public API for management surface / callers. */
101
- callApi(action, params = {}) {
102
- return this.#callAction(action, params);
103
- }
104
- admit(ev) {
105
- if (!this.#open)
106
- return;
104
+ #admitRaw(ev) {
107
105
  if (!isMessageEvent(ev)) {
108
- receiveOneBot12SideEvent(this.#options.sideEvents, this.#options.config.id, this, ev, this.#logger);
106
+ receiveOneBot12SideEvent((name, payload) => this.emit(name, payload), this.#options.config.id, { callApi: (action, params) => callOnebot12Client(this.client, action, params) }, ev, this.#logger);
109
107
  return;
110
108
  }
111
109
  const conversation = onebot12InboundConversation(String(this.#options.id), ev);
112
110
  const nickname = senderNickname(ev);
113
111
  const mentioned = isBotMentioned(ev);
114
- void this.#options.gateway.receive({
112
+ void this.emit('message.receive', {
115
113
  conversation,
116
114
  message: { conversation, id: ev.message_id },
117
115
  content: formatInboundContent(ev),
@@ -136,6 +134,12 @@ export class OneBot12WssEndpoint {
136
134
  }));
137
135
  });
138
136
  }
137
+ #warnPlatformEvent(error) {
138
+ this.#logger.warn(formatCompact({
139
+ op: 'onebot12_platform_event_failed',
140
+ error: error instanceof Error ? error.message : String(error),
141
+ }));
142
+ }
139
143
  #acceptConnection(connection) {
140
144
  if (!verifyOneBotAccessToken(this.#options.config.access_token, connection.request)) {
141
145
  connection.socket.close(4003, 'Unauthorized');
@@ -151,17 +155,17 @@ export class OneBot12WssEndpoint {
151
155
  }
152
156
  }
153
157
  this.#ws = socket;
154
- this.#startHeartbeat();
158
+ this.#lifecycle.startHeartbeat(() => {
159
+ this.#callAction('get_status', {}).catch(() => { });
160
+ });
155
161
  socket.on('message', (data) => {
162
+ this.#lifecycle.notifyHeartbeatAck();
156
163
  this.#onMessage(data);
157
164
  });
158
165
  socket.on('close', () => {
159
166
  if (this.#ws === socket) {
160
167
  this.#ws = undefined;
161
- if (this.#heartbeatTimer) {
162
- clearInterval(this.#heartbeatTimer);
163
- this.#heartbeatTimer = undefined;
164
- }
168
+ this.#lifecycle.stopHeartbeat();
165
169
  }
166
170
  });
167
171
  this.#logger.debug(formatCompact({
@@ -186,14 +190,11 @@ export class OneBot12WssEndpoint {
186
190
  if (pending) {
187
191
  this.#pending.delete(resp.echo);
188
192
  clearTimeout(pending.timeout);
189
- if (resp.status === 'ok')
190
- pending.resolve(resp.data);
191
- else
192
- pending.reject(new Error(`OneBot12 retcode=${resp.retcode}: ${resp.message}`));
193
+ pending.resolve(resp);
193
194
  }
194
195
  return;
195
196
  }
196
- this.admit(msg);
197
+ this.client.ingest(msg);
197
198
  }
198
199
  catch (error) {
199
200
  this.#logger.warn(formatCompact({
@@ -218,11 +219,4 @@ export class OneBot12WssEndpoint {
218
219
  this.#ws.send(JSON.stringify(req));
219
220
  });
220
221
  }
221
- #startHeartbeat() {
222
- if (this.#heartbeatTimer)
223
- clearInterval(this.#heartbeatTimer);
224
- this.#heartbeatTimer = setInterval(() => {
225
- this.#callAction('get_status', {}).catch(() => { });
226
- }, this.#options.config.heartbeat_interval);
227
- }
228
222
  }
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.1",
4
4
  "description": "Zhin.js OneBot 12 adapter for Plugin Runtime (WebSocket client)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -39,26 +39,29 @@
39
39
  "directory": "plugins/adapters/onebot12"
40
40
  },
41
41
  "dependencies": {
42
+ "@imhelper/onebot-v12": "1.0.7",
43
+ "imhelper": "1.0.7",
42
44
  "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",
45
+ "@zhin.js/adapter": "1.2.1",
46
+ "@zhin.js/core": "1.5.14",
47
+ "@zhin.js/feature-kit": "1.0.13",
48
+ "@zhin.js/host-http": "1.0.13",
46
49
  "@zhin.js/im-contract": "1.0.4",
47
- "@zhin.js/logger": "1.0.76"
50
+ "@zhin.js/logger": "1.0.77"
48
51
  },
49
52
  "devDependencies": {
50
53
  "@types/node": "^26.1.2",
51
54
  "@types/ws": "^8.18.1",
52
55
  "typescript": "^6.0.3",
53
56
  "vitest": "^4.1.10",
54
- "@zhin.js/host-http": "1.0.11",
55
- "zhin.js": "6.0.12"
57
+ "@zhin.js/host-http": "1.0.13",
58
+ "zhin.js": "6.0.14"
56
59
  },
57
60
  "peerDependencies": {
58
- "@zhin.js/adapter": "1.1.11",
59
- "@zhin.js/command": "1.0.15",
60
- "@zhin.js/core": "1.5.12",
61
- "zhin.js": "6.0.12"
61
+ "@zhin.js/adapter": "1.2.1",
62
+ "@zhin.js/command": "1.0.16",
63
+ "@zhin.js/core": "1.5.14",
64
+ "zhin.js": "6.0.14"
62
65
  },
63
66
  "peerDependenciesMeta": {
64
67
  "@zhin.js/command": {
package/src/client.ts ADDED
@@ -0,0 +1,81 @@
1
+ import {
2
+ OneBotV12Client,
3
+ type OneBotV12Event as ImHelperOneBot12Event,
4
+ type OneBotV12Response,
5
+ } from '@imhelper/onebot-v12';
6
+ import { EventFactory, type EventMap, type ImHelperEventMap } from 'imhelper';
7
+ import {
8
+ defineEndpointClient,
9
+ forwardEndpointClientEvents,
10
+ type ClientEventPayloads,
11
+ } from 'zhin.js/adapter';
12
+ import type { ResolvedOneBot12Config } from './protocol.js';
13
+
14
+ export { OneBotV12Client as Onebot12Client } from '@imhelper/onebot-v12';
15
+
16
+ export type Onebot12ApiCall = (
17
+ action: string,
18
+ params?: Record<string, unknown>,
19
+ ) => Promise<OneBotV12Response>;
20
+
21
+ type Onebot12ClientEvents = ImHelperEventMap<
22
+ string,
23
+ ImHelperOneBot12Event,
24
+ EventMap<string>
25
+ >;
26
+ export type Onebot12ClientEventMap = ClientEventPayloads<Onebot12ClientEvents>;
27
+
28
+ export function createOnebot12EndpointClient(
29
+ config: ResolvedOneBot12Config,
30
+ request: Onebot12ApiCall,
31
+ ): OneBotV12Client {
32
+ const baseUrl = config.connection === 'ws'
33
+ ? config.url.replace(/^ws(s?):/, 'http$1:')
34
+ : config.connection === 'webhook' && config.api_url
35
+ ? config.api_url
36
+ : 'http://localhost';
37
+ return new OneBotV12Client({
38
+ baseUrl,
39
+ selfId: config.id,
40
+ accessToken: config.access_token,
41
+ receiveMode: 'manual',
42
+ call: request,
43
+ });
44
+ }
45
+
46
+ export async function callOnebot12Client<T = unknown>(
47
+ client: OneBotV12Client,
48
+ action: string,
49
+ params?: Record<string, unknown>,
50
+ ): Promise<T | undefined> {
51
+ const response: OneBotV12Response<T> = await client.call<T>(action, params);
52
+ if (response.status !== 'ok') {
53
+ throw new Error(
54
+ `OneBot 12 API ${action}: retcode=${response.retcode}${response.message ? ` ${response.message}` : ''}`,
55
+ );
56
+ }
57
+ return response.data;
58
+ }
59
+
60
+ const onebot12ClientEventNames = Object.freeze([
61
+ ...EventFactory.getSupportedEventTypes<string>(),
62
+ 'event',
63
+ ]);
64
+
65
+ export function forwardOnebot12ClientEvents(
66
+ client: OneBotV12Client,
67
+ receive: (name: string, payload: unknown) => void,
68
+ ): () => void {
69
+ return forwardEndpointClientEvents(client, onebot12ClientEventNames, receive);
70
+ }
71
+
72
+ declare module '@zhin.js/feature-kit' {
73
+ interface AdapterClientRegistry {
74
+ readonly onebot12: {
75
+ readonly client: OneBotV12Client;
76
+ readonly events: Onebot12ClientEventMap;
77
+ };
78
+ }
79
+ }
80
+
81
+ export const onebot12Client = defineEndpointClient<OneBotV12Client, Onebot12ClientEventMap>('onebot12');
package/src/index.ts CHANGED
@@ -49,3 +49,19 @@ export {
49
49
  export type { OneBot12WsSocket, OneBot12WsCreateOptions } from './ws-types.js';
50
50
 
51
51
  export { verifyOneBotAccessToken } from './wss-auth.js';
52
+ export {
53
+ Onebot12Client,
54
+ onebot12Client,
55
+ type Onebot12ClientEventMap,
56
+ } from './client.js';
57
+
58
+ export type {
59
+ OneBotV12ActionUrlResolver,
60
+ OneBotV12AdapterConfig as ImHelperOneBotV12AdapterConfig,
61
+ OneBotV12Call,
62
+ OneBotV12ClientConfig,
63
+ OneBotV12Event as ImHelperOneBotV12Event,
64
+ OneBotV12Response,
65
+ } from '@imhelper/onebot-v12';
66
+ export { ProtocolError } from '@imhelper/onebot-v12';
67
+ export type { ProtocolErrorKind, ProtocolErrorOptions } from 'imhelper';
package/src/protocol.ts CHANGED
@@ -78,7 +78,7 @@ export interface OneBot12Event {
78
78
  type: 'meta' | 'message' | 'notice' | 'request';
79
79
  detail_type: string;
80
80
  sub_type: string;
81
- self?: OneBot12Self;
81
+ self: OneBot12Self;
82
82
  message_id?: string;
83
83
  message?: OneBot12Segment[];
84
84
  alt_message?: string;
@@ -226,7 +226,7 @@ export function onebot12InboundConversation(endpointKey: string, ev: OneBot12Eve
226
226
  };
227
227
  }
228
228
 
229
- /** Build inbound text for MessageGateway.receive */
229
+ /** Build inbound text for OutboundMessageService.receive */
230
230
  export function formatInboundContent(ev: OneBot12Event): string {
231
231
  if (Array.isArray(ev.message)) {
232
232
  return ev.message
@@ -1,5 +1,5 @@
1
1
  import { receiveOneBotLikeSideEvent } from '@zhin.js/core';
2
- import type { SideEventGateway } from '@zhin.js/core/runtime';
2
+ import type { EndpointEventEmitter } from 'zhin.js/adapter';
3
3
  import { formatCompact, type getAdapterLogger } from '@zhin.js/logger';
4
4
  import type { OneBot12Event } from './protocol.js';
5
5
 
@@ -8,19 +8,19 @@ export interface OneBot12SideEventCaller {
8
8
  }
9
9
 
10
10
  export function receiveOneBot12SideEvent(
11
- sideEvents: SideEventGateway | undefined,
11
+ emit: EndpointEventEmitter,
12
12
  endpointKey: string,
13
13
  caller: OneBot12SideEventCaller,
14
14
  raw: OneBot12Event,
15
15
  logger: ReturnType<typeof getAdapterLogger>,
16
16
  ): void {
17
- if (!sideEvents) return;
17
+ if (!emit) return;
18
18
  const record = raw as Record<string, unknown>;
19
19
  const eventType = String(record.type ?? record.post_type ?? '');
20
20
  const detailType = String(record.detail_type ?? '');
21
21
  const isRequest = eventType === 'request' || eventType.startsWith('request.');
22
22
  const isFriend = detailType.includes('friend') || String(record.request_type ?? '') === 'friend';
23
- void receiveOneBotLikeSideEvent(sideEvents, {
23
+ void receiveOneBotLikeSideEvent(emit, {
24
24
  adapter: 'onebot12',
25
25
  endpointKey,
26
26
  platform: 'onebot',