@zhin.js/adapter-onebot11 1.0.98 → 1.1.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.
Files changed (83) hide show
  1. package/CHANGELOG.md +650 -3
  2. package/README.md +58 -368
  3. package/adapters/onebot11.js +40 -0
  4. package/adapters/onebot11.ts +53 -0
  5. package/agent/PERMITS.md +14 -0
  6. package/{skills/onebot11/SKILL.md → agent/skills/onebot11.md} +4 -4
  7. package/agent/tools/set_title.ts +24 -0
  8. package/commands/endpoint/add/[id].js +3 -0
  9. package/commands/endpoint/add/[id].ts +3 -0
  10. package/commands/endpoint/list.js +3 -0
  11. package/commands/endpoint/list.ts +3 -0
  12. package/commands/endpoint/remove/[id].js +3 -0
  13. package/commands/endpoint/remove/[id].ts +3 -0
  14. package/lib/client.d.ts +20 -0
  15. package/lib/client.js +30 -0
  16. package/lib/content-port.d.ts +4 -0
  17. package/lib/content-port.js +63 -0
  18. package/lib/endpoint-management.d.ts +15 -0
  19. package/lib/endpoint-management.js +47 -0
  20. package/lib/index.d.ts +10 -16
  21. package/lib/index.js +7 -53
  22. package/lib/onebot11-endpoint-commands.d.ts +1 -0
  23. package/lib/onebot11-endpoint-commands.js +24 -0
  24. package/lib/onebot11-runtime-state.d.ts +1 -0
  25. package/lib/onebot11-runtime-state.js +6 -0
  26. package/lib/protocol.d.ts +160 -0
  27. package/lib/protocol.js +316 -0
  28. package/lib/side-event-dispatch.d.ts +7 -0
  29. package/lib/side-event-dispatch.js +36 -0
  30. package/lib/ws-endpoint.d.ts +22 -0
  31. package/lib/ws-endpoint.js +209 -0
  32. package/lib/ws-transport.d.ts +13 -0
  33. package/lib/ws-transport.js +71 -0
  34. package/lib/ws-types.d.ts +18 -0
  35. package/lib/ws-types.js +1 -0
  36. package/lib/wss-auth.d.ts +2 -0
  37. package/lib/wss-auth.js +16 -0
  38. package/lib/wss-endpoint.d.ts +25 -0
  39. package/lib/wss-endpoint.js +173 -0
  40. package/package.json +69 -22
  41. package/plugin.js +18 -0
  42. package/schema.json +97 -0
  43. package/src/client.ts +78 -0
  44. package/src/content-port.ts +66 -0
  45. package/src/endpoint-management.ts +72 -0
  46. package/src/index.ts +62 -65
  47. package/src/onebot11-endpoint-commands.ts +23 -0
  48. package/src/onebot11-runtime-state.ts +7 -0
  49. package/src/protocol.ts +459 -0
  50. package/src/side-event-dispatch.ts +48 -0
  51. package/src/ws-endpoint.ts +272 -0
  52. package/src/ws-transport.ts +100 -0
  53. package/src/ws-types.ts +21 -0
  54. package/src/wss-auth.ts +17 -0
  55. package/src/wss-endpoint.ts +228 -0
  56. package/lib/adapter.d.ts +0 -32
  57. package/lib/adapter.d.ts.map +0 -1
  58. package/lib/adapter.js +0 -92
  59. package/lib/adapter.js.map +0 -1
  60. package/lib/bot-ws-client.d.ts +0 -40
  61. package/lib/bot-ws-client.d.ts.map +0 -1
  62. package/lib/bot-ws-client.js +0 -397
  63. package/lib/bot-ws-client.js.map +0 -1
  64. package/lib/bot-ws-server.d.ts +0 -42
  65. package/lib/bot-ws-server.d.ts.map +0 -1
  66. package/lib/bot-ws-server.js +0 -344
  67. package/lib/bot-ws-server.js.map +0 -1
  68. package/lib/index.d.ts.map +0 -1
  69. package/lib/index.js.map +0 -1
  70. package/lib/onebot-get-msg.d.ts +0 -3
  71. package/lib/onebot-get-msg.d.ts.map +0 -1
  72. package/lib/onebot-get-msg.js +0 -27
  73. package/lib/onebot-get-msg.js.map +0 -1
  74. package/lib/types.d.ts +0 -54
  75. package/lib/types.d.ts.map +0 -1
  76. package/lib/types.js +0 -5
  77. package/lib/types.js.map +0 -1
  78. package/plugin.yml +0 -3
  79. package/src/adapter.ts +0 -104
  80. package/src/bot-ws-client.ts +0 -421
  81. package/src/bot-ws-server.ts +0 -382
  82. package/src/onebot-get-msg.ts +0 -33
  83. package/src/types.ts +0 -58
package/lib/client.js ADDED
@@ -0,0 +1,30 @@
1
+ import { OneBotV11Client, } from '@imhelper/onebot-v11';
2
+ import { EventFactory } from 'imhelper';
3
+ import { defineEndpointClient, forwardEndpointClientEvents, } from 'zhin.js/adapter';
4
+ export { OneBotV11Client as Onebot11Client } from '@imhelper/onebot-v11';
5
+ export function createOnebot11EndpointClient(config, request) {
6
+ return new OneBotV11Client({
7
+ baseUrl: config.connection === 'ws'
8
+ ? config.url.replace(/^ws(s?):/, 'http$1:')
9
+ : 'http://localhost',
10
+ selfId: config.id,
11
+ accessToken: config.access_token,
12
+ receiveMode: 'manual',
13
+ call: request,
14
+ });
15
+ }
16
+ export async function callOnebot11Client(client, action, params) {
17
+ const response = await client.call(action, params);
18
+ if (response.status !== 'ok') {
19
+ throw new Error(`OneBot 11 API ${action}: retcode=${response.retcode}${response.message ? ` ${response.message}` : ''}`);
20
+ }
21
+ return response.data;
22
+ }
23
+ const onebot11ClientEventNames = Object.freeze([
24
+ ...EventFactory.getSupportedEventTypes(),
25
+ 'event',
26
+ ]);
27
+ export function forwardOnebot11ClientEvents(client, receive) {
28
+ return forwardEndpointClientEvents(client, onebot11ClientEventNames, receive);
29
+ }
30
+ export const onebot11Client = defineEndpointClient('onebot11');
@@ -0,0 +1,4 @@
1
+ import type { EndpointContentPort } from 'zhin.js/adapter';
2
+ type CallApi = (action: string, params?: Record<string, unknown>) => Promise<unknown>;
3
+ export declare function createOneBot11ContentPort(callApi: CallApi): EndpointContentPort;
4
+ export {};
@@ -0,0 +1,63 @@
1
+ import { toCanonicalSegments } from '@zhin.js/core';
2
+ export function createOneBot11ContentPort(callApi) {
3
+ return Object.freeze({
4
+ async resolve(reference, context) {
5
+ try {
6
+ context.signal.throwIfAborted();
7
+ if (reference.kind === 'media') {
8
+ return reference.media.kind === 'file'
9
+ ? Object.freeze({ status: 'unsupported', code: 'onebot11_opaque_media' })
10
+ : Object.freeze({ status: 'resolved', reference, value: reference.media });
11
+ }
12
+ if (reference.kind === 'message') {
13
+ const row = await callApi('get_msg', { message_id: reference.message.id });
14
+ context.signal.throwIfAborted();
15
+ const segments = normalizeSegments(row.message ?? row.raw_message);
16
+ const sender = row.sender;
17
+ const value = Object.freeze({
18
+ ref: reference.message,
19
+ ...(sender?.user_id != null ? { actor: Object.freeze({
20
+ id: String(sender.user_id),
21
+ ...(sender.nickname ? { displayName: String(sender.nickname) } : {}),
22
+ }) } : {}),
23
+ segments,
24
+ timestamp: toMillis(row.time),
25
+ });
26
+ return Object.freeze({ status: 'resolved', reference, value });
27
+ }
28
+ const raw = await callApi('get_forward_msg', { id: reference.forwardId });
29
+ context.signal.throwIfAborted();
30
+ const nodes = Array.isArray(raw.messages) ? raw.messages.slice(0, context.maxEntries) : [];
31
+ const value = Object.freeze(nodes.map((node) => {
32
+ const row = node;
33
+ const sender = row.sender;
34
+ return Object.freeze({
35
+ ...(sender?.user_id != null ? { actor: Object.freeze({
36
+ id: String(sender.user_id),
37
+ ...(sender.nickname ? { displayName: String(sender.nickname) } : {}),
38
+ }) } : {}),
39
+ timestamp: toMillis(row.time),
40
+ segments: normalizeSegments(row.content ?? row.message),
41
+ });
42
+ }));
43
+ return Object.freeze({ status: 'resolved', reference, value, truncated: nodes.length >= context.maxEntries });
44
+ }
45
+ catch (error) {
46
+ if (context.signal.aborted)
47
+ return Object.freeze({ status: 'expired', code: 'turn_aborted' });
48
+ return Object.freeze({ status: 'failed', code: 'onebot11_content_resolution_failed', message: error instanceof Error ? error.message : String(error) });
49
+ }
50
+ },
51
+ });
52
+ }
53
+ function normalizeSegments(value) {
54
+ if (Array.isArray(value))
55
+ return Object.freeze(toCanonicalSegments(value));
56
+ return Object.freeze([{ type: 'text', data: Object.freeze({ text: String(value ?? '') }) }]);
57
+ }
58
+ function toMillis(value) {
59
+ const time = Number(value);
60
+ if (!Number.isFinite(time))
61
+ return Date.now();
62
+ return time < 10_000_000_000 ? time * 1000 : time;
63
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * OneBot11 endpoint management 语义端口(Console 社交面 RPC 消费,见
3
+ * packages/im/adapter/src/endpoint-management.ts)。
4
+ *
5
+ * 归一化取舍:
6
+ * - friend → {user_id:number, nickname, remark: remark ?? ''}
7
+ * - group → {group_id:number, name: group_name ?? name}
8
+ * - 群成员列表保持 OneBot11 原生形状,仅保证数组
9
+ */
10
+ import type { EndpointManagement } from 'zhin.js/adapter';
11
+ /** 管理面只依赖 endpoint 的 callApi(ws/wss 两种传输各自实现)。 */
12
+ export interface OneBot11ManagementCaller {
13
+ callApi(action: string, params?: Record<string, unknown>): Promise<unknown>;
14
+ }
15
+ export declare function createOneBot11EndpointManagement(endpoint: OneBot11ManagementCaller): EndpointManagement;
@@ -0,0 +1,47 @@
1
+ export function createOneBot11EndpointManagement(endpoint) {
2
+ return Object.freeze({
3
+ async listFriends() {
4
+ const data = await endpoint.callApi('get_friend_list');
5
+ return toArray(data).map((value) => {
6
+ const friend = asRecord(value);
7
+ return {
8
+ user_id: toNumberId(friend.user_id, 'user_id'),
9
+ nickname: String(friend.nickname ?? ''),
10
+ remark: String(friend.remark ?? ''),
11
+ };
12
+ });
13
+ },
14
+ async listGroups() {
15
+ const data = await endpoint.callApi('get_group_list');
16
+ return toArray(data).map((value) => {
17
+ const group = asRecord(value);
18
+ return {
19
+ group_id: toNumberId(group.group_id, 'group_id'),
20
+ name: String(group.group_name ?? group.name ?? ''),
21
+ };
22
+ });
23
+ },
24
+ async listGroupMembers(groupId) {
25
+ const data = await endpoint.callApi('get_group_member_list', {
26
+ group_id: toNumberId(groupId, 'group_id'),
27
+ });
28
+ return toArray(data);
29
+ },
30
+ });
31
+ }
32
+ function asRecord(value) {
33
+ return value !== null && typeof value === 'object'
34
+ ? value
35
+ : {};
36
+ }
37
+ function toArray(value) {
38
+ return Array.isArray(value) ? value : [];
39
+ }
40
+ /** console RPC 传入的 gid/uid 可能是字符串,统一收敛为数字。 */
41
+ function toNumberId(value, label) {
42
+ const n = Number(value);
43
+ if (!Number.isFinite(n) || String(value ?? '').trim() === '') {
44
+ throw new TypeError(`onebot11 ${label} 必须是数字: ${String(value)}`);
45
+ }
46
+ return n;
47
+ }
package/lib/index.d.ts CHANGED
@@ -1,16 +1,10 @@
1
- import { OneBot11Adapter } from './adapter.js';
2
- export * from './types.js';
3
- export { OneBot11WsClient } from './bot-ws-client.js';
4
- export { OneBot11WsServer } from './bot-ws-server.js';
5
- export { OneBot11Adapter, type OneBot11Bot } from './adapter.js';
6
- declare module 'zhin.js' {
7
- namespace Plugin {
8
- interface Contexts {
9
- router: import('@zhin.js/host-router').Router;
10
- }
11
- }
12
- interface Adapters {
13
- onebot11: OneBot11Adapter;
14
- }
15
- }
16
- //# sourceMappingURL=index.d.ts.map
1
+ export { buildSendAction, buildWsConnectOptions, extractQuoteId, formatInboundContent, formatInboundMetadata, formatOutboundSegments, getChannelId, isMessageEvent, isOneBot11BotMentioned, mediaRefToOneBotFile, onebot11InboundConversation, resolveOneBot11Config, senderDisplayName, senderNickname, senderUserId, type OneBot11ActionRequest, type OneBot11ActionResponse, type OneBot11AdapterConfig, type OneBot11ConfigBase, type OneBot11EndpointConfig, type OneBot11Event, type OneBot11Segment, type OneBot11Sender, type OneBot11WireSegment, type OneBot11WsConfig, type OneBot11WssConfig, type ResolvedOneBot11Config, } from './protocol.js';
2
+ export { OneBot11WsEndpoint, type OneBot11WsEndpointOptions, } from './ws-endpoint.js';
3
+ export { OneBot11WssEndpoint, type OneBot11WssEndpointOptions, } from './wss-endpoint.js';
4
+ export type { OneBot11WsSocket, OneBot11WsCreateOptions } from './ws-types.js';
5
+ export { callOneBot11WsAction, decodeWsPayload, handleOneBot11WsMessage, rejectAllPending, startOneBot11Heartbeat, } from './ws-transport.js';
6
+ export { verifyOneBotAccessToken } from './wss-auth.js';
7
+ export { Onebot11Client, onebot11Client, type Onebot11ClientEventMap, } from './client.js';
8
+ export type { OneBotV11ActionUrlResolver, OneBotV11AdapterConfig as ImHelperOneBotV11AdapterConfig, OneBotV11Call, OneBotV11ClientConfig, OneBotV11Event as ImHelperOneBotV11Event, OneBotV11Response, } from '@imhelper/onebot-v11';
9
+ export { ProtocolError } from '@imhelper/onebot-v11';
10
+ export type { ProtocolErrorKind, ProtocolErrorOptions } from 'imhelper';
package/lib/index.js CHANGED
@@ -1,53 +1,7 @@
1
- /**
2
- * OneBot11 适配器入口:单一适配器,支持正向 WS / 反向 WS(connection: ws | wss)
3
- */
4
- import { usePlugin, createGroupManagementTools } from 'zhin.js';
5
- import { OneBot11Adapter } from './adapter.js';
6
- export * from './types.js';
7
- export { OneBot11WsClient } from './bot-ws-client.js';
8
- export { OneBot11WsServer } from './bot-ws-server.js';
9
- export { OneBot11Adapter } from './adapter.js';
10
- const plugin = usePlugin();
11
- const { provide, useContext } = plugin;
12
- provide({
13
- name: 'onebot11',
14
- description: 'OneBot11 协议适配器(正向 WS / 反向 WS)',
15
- mounted: async (p) => {
16
- const adapter = new OneBot11Adapter(p);
17
- await adapter.start();
18
- return adapter;
19
- },
20
- dispose: async (adapter) => {
21
- await adapter.stop();
22
- },
23
- });
24
- useContext('tool', 'onebot11', (toolService, onebot11) => {
25
- const groupTools = createGroupManagementTools(onebot11, 'onebot11');
26
- const disposers = groupTools.map(t => toolService.addTool(t, plugin.name));
27
- // Platform-specific tool: set title
28
- disposers.push(toolService.addTool({
29
- name: 'onebot11_set_title',
30
- description: '设置 QQ 群成员的专属头衔。只有群主才能设置。',
31
- parameters: {
32
- type: 'object',
33
- properties: {
34
- bot: { type: 'string', description: 'Bot 名称' },
35
- group_id: { type: 'number', description: '目标群号' },
36
- user_id: { type: 'number', description: '目标成员 QQ号' },
37
- title: { type: 'string', description: '头衔文字' },
38
- },
39
- required: ['bot', 'group_id', 'user_id', 'title'],
40
- },
41
- platforms: ['onebot11'],
42
- tags: ['onebot11'],
43
- execute: async (args) => {
44
- const bot = onebot11.bots.get(args.bot);
45
- if (!bot)
46
- throw new Error(`Bot ${args.bot} 不存在`);
47
- const success = await bot.setTitle(args.group_id, args.user_id, args.title);
48
- return { success, message: success ? `已将 ${args.user_id} 的头衔设为 "${args.title}"` : '设置失败' };
49
- },
50
- }, plugin.name));
51
- return () => disposers.forEach(d => d());
52
- });
53
- //# sourceMappingURL=index.js.map
1
+ export { buildSendAction, buildWsConnectOptions, extractQuoteId, formatInboundContent, formatInboundMetadata, formatOutboundSegments, getChannelId, isMessageEvent, isOneBot11BotMentioned, mediaRefToOneBotFile, onebot11InboundConversation, resolveOneBot11Config, senderDisplayName, senderNickname, senderUserId, } from './protocol.js';
2
+ export { OneBot11WsEndpoint, } from './ws-endpoint.js';
3
+ export { OneBot11WssEndpoint, } from './wss-endpoint.js';
4
+ export { callOneBot11WsAction, decodeWsPayload, handleOneBot11WsMessage, rejectAllPending, startOneBot11Heartbeat, } from './ws-transport.js';
5
+ export { verifyOneBotAccessToken } from './wss-auth.js';
6
+ export { Onebot11Client, onebot11Client, } from './client.js';
7
+ export { ProtocolError } from '@imhelper/onebot-v11';
@@ -0,0 +1 @@
1
+ export declare const onebot11EndpointCommands: import("@zhin.js/adapter").EndpointCommands<Readonly<import("@zhin.js/command").CommandDefinition<unknown, unknown, import("@zhin.js/command").CommandMessage, string | undefined>>>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * `onebot11.endpoint` 命令族:由 @zhin.js/adapter 的 createEndpointCommands 套件生成。
3
+ * commands/endpoint/ 下的 list / add / remove 直接默认导出这三项。
4
+ */
5
+ import { createEndpointCommands } from 'zhin.js/adapter';
6
+ import { defineCommand } from 'zhin.js/command';
7
+ import { onebot11RuntimeStateToken } from './onebot11-runtime-state.js';
8
+ export const onebot11EndpointCommands = createEndpointCommands({
9
+ adapterKey: 'onebot11',
10
+ adapterDisplayName: 'OneBot 11',
11
+ fields: [
12
+ { key: 'url', description: 'OneBot 实现 WebSocket URL(connection: ws 必填)' },
13
+ { key: 'path', description: 'reverse-wss 路径(connection: wss)' },
14
+ { key: 'access_token', env: true, description: 'OneBot access token' },
15
+ ],
16
+ running: (use) => use(onebot11RuntimeStateToken).endpoints.values(),
17
+ describeEntry: (entry) => {
18
+ if (entry.url)
19
+ return `url: ${String(entry.url)}`;
20
+ if (entry.path)
21
+ return `path: ${String(entry.path)}`;
22
+ return '';
23
+ },
24
+ }, defineCommand);
@@ -0,0 +1 @@
1
+ export declare const onebot11RuntimeStateToken: import("zhin.js").Token<import("@zhin.js/adapter").EndpointRuntimeState>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * OneBot11 插件实例的运行时状态:adapter create() 注册的 endpoint 列表。
3
+ * 由 plugin.ts setup() provide,adapter create 与 `onebot11.endpoint` 命令共享(同一 owner generation)。
4
+ */
5
+ import { defineEndpointRuntimeStateToken } from 'zhin.js/adapter';
6
+ export const onebot11RuntimeStateToken = defineEndpointRuntimeStateToken('onebot11');
@@ -0,0 +1,160 @@
1
+ /**
2
+ * OneBot 11 protocol helpers (no legacy Adapter/Endpoint / segment-mapper).
3
+ * Canonicalization is owned by gateway/core before endpoint.send.
4
+ * Spec: https://github.com/botuniverse/onebot-11
5
+ */
6
+ import { type MediaRef } from '@zhin.js/core';
7
+ import type { ConversationRef } from '@zhin.js/im-contract';
8
+ /** Transitional legacy endpoint row (`endpoints[]` with `context: onebot11`). */
9
+ export interface OneBot11LegacyEndpointRow {
10
+ readonly context?: string;
11
+ readonly connection?: 'ws' | 'wss';
12
+ /** Legacy alias: `type: 'ws' | 'ws_reverse'` */
13
+ readonly type?: string;
14
+ readonly id?: string;
15
+ readonly access_token?: string;
16
+ readonly url?: string;
17
+ readonly path?: string;
18
+ readonly reconnect_interval?: number;
19
+ readonly heartbeat_interval?: number;
20
+ }
21
+ /** Plugin Runtime owner config (`plugins.<instanceKey>` / schema.json). */
22
+ export interface OneBot11AdapterConfig {
23
+ readonly connection?: 'ws' | 'wss';
24
+ readonly id?: string;
25
+ readonly access_token?: string;
26
+ readonly url?: string;
27
+ readonly path?: string;
28
+ readonly reconnect_interval?: number;
29
+ readonly heartbeat_interval?: number;
30
+ /** Transitional: legacy root `endpoints[]` with `context: onebot11`. */
31
+ readonly endpoints?: ReadonlyArray<OneBot11LegacyEndpointRow>;
32
+ }
33
+ export interface OneBot11ConfigBase {
34
+ readonly context: 'onebot11';
35
+ readonly id: string;
36
+ readonly access_token?: string;
37
+ }
38
+ /** 正向 WebSocket:应用连 OneBot 实现的 WS 服务器 */
39
+ export interface OneBot11WsConfig extends OneBot11ConfigBase {
40
+ readonly connection: 'ws';
41
+ readonly url: string;
42
+ readonly reconnect_interval: number;
43
+ readonly heartbeat_interval: number;
44
+ }
45
+ /** 反向 WebSocket(slice 1 deferred — needs httpHostToken) */
46
+ export interface OneBot11WssConfig extends OneBot11ConfigBase {
47
+ readonly connection: 'wss';
48
+ readonly path: string;
49
+ readonly heartbeat_interval: number;
50
+ }
51
+ export type ResolvedOneBot11Config = OneBot11WsConfig | OneBot11WssConfig;
52
+ export type OneBot11EndpointConfig = ResolvedOneBot11Config;
53
+ export interface OneBot11Sender {
54
+ readonly role?: string;
55
+ readonly nickname?: string;
56
+ readonly card?: string;
57
+ readonly title?: string;
58
+ }
59
+ export interface OneBot11Segment {
60
+ type: string;
61
+ data?: Record<string, unknown>;
62
+ }
63
+ export interface OneBot11Event {
64
+ post_type: string;
65
+ self_id?: number | string;
66
+ message_type?: string;
67
+ sub_type?: string;
68
+ message_id?: number | string;
69
+ user_id?: number | string;
70
+ group_id?: number | string;
71
+ sender?: OneBot11Sender;
72
+ message?: OneBot11Segment[];
73
+ raw_message?: string;
74
+ time?: number;
75
+ notice_type?: string;
76
+ request_type?: string;
77
+ [key: string]: unknown;
78
+ }
79
+ export interface OneBot11ActionRequest {
80
+ action: string;
81
+ params: Record<string, unknown>;
82
+ echo?: string;
83
+ }
84
+ export interface OneBot11ActionResponse {
85
+ status: 'ok' | 'failed';
86
+ retcode: number;
87
+ data?: unknown;
88
+ message?: string;
89
+ echo?: string;
90
+ }
91
+ export interface OneBot11WireSegment {
92
+ readonly type: string;
93
+ readonly data?: Record<string, unknown>;
94
+ }
95
+ export declare function resolveOneBot11Config(config?: OneBot11AdapterConfig): ResolvedOneBot11Config;
96
+ /** 判断是否为消息事件(post_type=message) */
97
+ export declare function isMessageEvent(ev: OneBot11Event): ev is OneBot11Event & {
98
+ message_id: number | string;
99
+ };
100
+ /** 从事件得到场景 id:私聊 user_id,群 group_id */
101
+ export declare function getChannelId(ev: OneBot11Event): string;
102
+ /**
103
+ * 入站归一化 → ConversationRef:OneBot 11 `group` 消息 → kind 'group',
104
+ * 其余(private 及带 group_id 的非 private 事件按群处理)→ kind 'private'。
105
+ * OneBot 11 无 guild/temp 容器概念,不填 parent。
106
+ */
107
+ export declare function onebot11InboundConversation(endpointKey: string, ev: OneBot11Event): ConversationRef;
108
+ /** Build inbound text for OutboundMessageService.receive */
109
+ export declare function formatInboundContent(ev: OneBot11Event): string;
110
+ export declare function senderDisplayName(ev: OneBot11Event): string;
111
+ /**
112
+ * Runtime Message.sender 必须是用户 ID(agent bridge 用它与 endpointMaster 比对)。
113
+ * user_id 缺失时兜底为空串,绝不回退到显示名。
114
+ */
115
+ export declare function senderUserId(ev: OneBot11Event): string;
116
+ /** 显示名(群名片优先)放 metadata.nickname;没有则返回 undefined,不写该字段。 */
117
+ export declare function senderNickname(ev: OneBot11Event): string | undefined;
118
+ /**
119
+ * 回复引用 id:优先取 message 数组中的 {type:'reply', data:{id}} 段;
120
+ * 兼容部分实现把 reply 放在事件顶层(标量或带 message_id 的对象)。
121
+ */
122
+ export declare function extractQuoteId(ev: OneBot11Event): string | undefined;
123
+ /** 扫描 message 段中的 at,qq 等于本机 uin(self_id)即视为被 @;`qq:'all'`(@全体)不算。 */
124
+ export declare function isOneBot11BotMentioned(input: {
125
+ readonly selfId: string | undefined;
126
+ readonly message?: readonly OneBot11Segment[];
127
+ }): boolean;
128
+ /** Inbound fields extracted from an event for gateway.receive (ws / wss 两个 endpoint 共用). */
129
+ export interface OneBot11InboundFields {
130
+ readonly metadata: Readonly<Record<string, unknown>>;
131
+ readonly endpointId: string;
132
+ readonly mentioned: boolean;
133
+ readonly replyTo: {
134
+ readonly id: string;
135
+ } | undefined;
136
+ }
137
+ /** 构造 gateway.receive 的 metadata 与提升字段(ws / wss 两个 endpoint 共用)。 */
138
+ export declare function formatInboundMetadata(ev: OneBot11Event, endpoint: string): OneBot11InboundFields;
139
+ /**
140
+ * canonical MediaRef → OneBot `file` 参数:url 直传、base64 → `base64://`、
141
+ * 本地路径 → `file://`(路径在 OneBot 实现侧解析)、kind=file 不透明引用原样透传。
142
+ */
143
+ export declare function mediaRefToOneBotFile(media: MediaRef): string;
144
+ /**
145
+ * Wire-encode an already-rendered outbound payload into OneBot 11 message segments.
146
+ * 入参假定已经 core `normalizeOutboundPayload` 归一为 canonical Segment[];
147
+ * 媒体段只消费 canonical `data.media`(无 MediaRef 的媒体段 warn + 丢弃),
148
+ * 其余 wire 形状段(at / 平台扩展段)原样透传。
149
+ */
150
+ export declare function formatOutboundSegments(payload: unknown): OneBot11Segment[];
151
+ export declare function buildSendAction(conversation: ConversationRef, message: OneBot11Segment[]): {
152
+ action: string;
153
+ params: Record<string, unknown>;
154
+ };
155
+ /** Build WS connect URL + headers (access_token via Bearer + query). */
156
+ export declare function buildWsConnectOptions(config: OneBot11WsConfig): {
157
+ readonly url: string;
158
+ readonly headers: Record<string, string>;
159
+ readonly safeUrl: string;
160
+ };