@zhin.js/adapter-onebot12 1.0.1 → 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 (90) hide show
  1. package/CHANGELOG.md +855 -0
  2. package/README.md +59 -69
  3. package/adapters/onebot12.js +50 -0
  4. package/adapters/onebot12.ts +64 -0
  5. package/commands/endpoint/add/[id].js +3 -0
  6. package/commands/endpoint/add/[id].ts +3 -0
  7. package/commands/endpoint/list.js +3 -0
  8. package/commands/endpoint/list.ts +3 -0
  9. package/commands/endpoint/remove/[id].js +3 -0
  10. package/commands/endpoint/remove/[id].ts +3 -0
  11. package/lib/client.d.ts +20 -0
  12. package/lib/client.js +33 -0
  13. package/lib/content-port.d.ts +4 -0
  14. package/lib/content-port.js +45 -0
  15. package/lib/endpoint-management.d.ts +16 -0
  16. package/lib/endpoint-management.js +47 -0
  17. package/lib/index.d.ts +10 -19
  18. package/lib/index.js +7 -27
  19. package/lib/onebot12-endpoint-commands.d.ts +1 -0
  20. package/lib/onebot12-endpoint-commands.js +25 -0
  21. package/lib/onebot12-runtime-state.d.ts +1 -0
  22. package/lib/onebot12-runtime-state.js +6 -0
  23. package/lib/protocol.d.ts +173 -0
  24. package/lib/protocol.js +415 -0
  25. package/lib/side-event-dispatch.d.ts +7 -0
  26. package/lib/side-event-dispatch.js +36 -0
  27. package/lib/webhook.d.ts +23 -0
  28. package/lib/webhook.js +161 -0
  29. package/lib/ws-endpoint.d.ts +22 -0
  30. package/lib/ws-endpoint.js +255 -0
  31. package/lib/ws-types.d.ts +16 -0
  32. package/lib/ws-types.js +1 -0
  33. package/lib/wss-auth.d.ts +2 -0
  34. package/lib/wss-auth.js +16 -0
  35. package/lib/wss-endpoint.d.ts +25 -0
  36. package/lib/wss-endpoint.js +222 -0
  37. package/package.json +63 -17
  38. package/plugin.js +14 -0
  39. package/schema.json +102 -0
  40. package/src/client.ts +81 -0
  41. package/src/content-port.ts +49 -0
  42. package/src/endpoint-management.ts +73 -0
  43. package/src/index.ts +64 -37
  44. package/src/onebot12-endpoint-commands.ts +24 -0
  45. package/src/onebot12-runtime-state.ts +7 -0
  46. package/src/protocol.ts +574 -0
  47. package/src/side-event-dispatch.ts +48 -0
  48. package/src/webhook.ts +223 -0
  49. package/src/ws-endpoint.ts +321 -0
  50. package/src/ws-types.ts +19 -0
  51. package/src/wss-auth.ts +17 -0
  52. package/src/wss-endpoint.ts +278 -0
  53. package/lib/adapter.d.ts +0 -18
  54. package/lib/adapter.d.ts.map +0 -1
  55. package/lib/adapter.js +0 -41
  56. package/lib/adapter.js.map +0 -1
  57. package/lib/api.d.ts +0 -14
  58. package/lib/api.d.ts.map +0 -1
  59. package/lib/api.js +0 -34
  60. package/lib/api.js.map +0 -1
  61. package/lib/endpoint-webhook.d.ts +0 -25
  62. package/lib/endpoint-webhook.d.ts.map +0 -1
  63. package/lib/endpoint-webhook.js +0 -118
  64. package/lib/endpoint-webhook.js.map +0 -1
  65. package/lib/endpoint-ws.d.ts +0 -26
  66. package/lib/endpoint-ws.d.ts.map +0 -1
  67. package/lib/endpoint-ws.js +0 -210
  68. package/lib/endpoint-ws.js.map +0 -1
  69. package/lib/endpoint-wss.d.ts +0 -26
  70. package/lib/endpoint-wss.d.ts.map +0 -1
  71. package/lib/endpoint-wss.js +0 -187
  72. package/lib/endpoint-wss.js.map +0 -1
  73. package/lib/index.d.ts.map +0 -1
  74. package/lib/index.js.map +0 -1
  75. package/lib/types.d.ts +0 -77
  76. package/lib/types.d.ts.map +0 -1
  77. package/lib/types.js +0 -5
  78. package/lib/types.js.map +0 -1
  79. package/lib/utils.d.ts +0 -45
  80. package/lib/utils.d.ts.map +0 -1
  81. package/lib/utils.js +0 -60
  82. package/lib/utils.js.map +0 -1
  83. package/src/adapter.ts +0 -54
  84. package/src/api.ts +0 -48
  85. package/src/endpoint-webhook.ts +0 -130
  86. package/src/endpoint-ws.ts +0 -222
  87. package/src/endpoint-wss.ts +0 -202
  88. package/src/types.ts +0 -86
  89. package/src/utils.ts +0 -87
  90. /package/{skills/onebot12/SKILL.md → agent/skills/onebot12.md} +0 -0
package/src/index.ts CHANGED
@@ -1,40 +1,67 @@
1
- /**
2
- * OneBot 12 适配器入口:单一适配器,支持正向 WS / Webhook / 反向 WS
3
- * 协议文档 https://12.onebot.dev/
4
- */
5
- import { usePlugin, type Plugin, type Context } from 'zhin.js';
6
- import type { Router } from '@zhin.js/host-router';
7
- import { OneBot12Adapter } from './adapter.js';
1
+ export {
2
+ buildSendMessageParams,
3
+ buildWsConnectOptions,
4
+ callOneBot12Action,
5
+ formatInboundContent,
6
+ formatOutboundSegments,
7
+ getChannelId,
8
+ isBotMentioned,
9
+ isMessageEvent,
10
+ mediaRefToOneBot12Fields,
11
+ mediaRefToOneBot12UploadParams,
12
+ onebot12InboundConversation,
13
+ resolveOneBot12Config,
14
+ senderNickname,
15
+ senderUserId,
16
+ uploadOneBot12MediaSegments,
17
+ type OneBot12ActionRequest,
18
+ type OneBot12ActionResponse,
19
+ type OneBot12AdapterConfig,
20
+ type OneBot12CallAction,
21
+ type OneBot12ConfigBase,
22
+ type OneBot12EndpointConfig,
23
+ type OneBot12Event,
24
+ type OneBot12HttpOptions,
25
+ type OneBot12Segment,
26
+ type OneBot12Self,
27
+ type OneBot12WebhookConfig,
28
+ type OneBot12WireSegment,
29
+ type OneBot12WsConfig,
30
+ type OneBot12WssConfig,
31
+ type ResolvedOneBot12Config,
32
+ } from './protocol.js';
8
33
 
9
- export * from './types.js';
10
- export { callOneBot12Action } from './api.js';
11
- export * from './utils.js';
12
- export { OneBot12WsClient } from './endpoint-ws.js';
13
- export { OneBot12WebhookEndpoint } from './endpoint-webhook.js';
14
- export { OneBot12WssServer } from './endpoint-wss.js';
15
- export { OneBot12Adapter, type OneBot12Bot } from './adapter.js';
34
+ export {
35
+ OneBot12WebhookEndpoint,
36
+ type OneBot12WebhookEndpointOptions,
37
+ } from './webhook.js';
16
38
 
17
- declare module 'zhin.js' {
18
- namespace Plugin {
19
- interface Contexts {
20
- router: import('@zhin.js/host-router').Router;
21
- }
22
- }
23
- interface Adapters {
24
- onebot12: OneBot12Adapter;
25
- }
26
- }
39
+ export {
40
+ OneBot12WsEndpoint,
41
+ type OneBot12WsEndpointOptions,
42
+ } from './ws-endpoint.js';
27
43
 
28
- const { provide } = usePlugin();
29
- provide({
30
- name: 'onebot12',
31
- description: 'OneBot 12 协议适配器(正向 WS / Webhook / 反向 WS)',
32
- mounted: async (p: Plugin) => {
33
- const adapter = new OneBot12Adapter(p);
34
- await adapter.start();
35
- return adapter;
36
- },
37
- dispose: async (adapter: OneBot12Adapter) => {
38
- await adapter.stop();
39
- },
40
- } as unknown as Context<'onebot12'>);
44
+ export {
45
+ OneBot12WssEndpoint,
46
+ type OneBot12WssEndpointOptions,
47
+ } from './wss-endpoint.js';
48
+
49
+ export type { OneBot12WsSocket, OneBot12WsCreateOptions } from './ws-types.js';
50
+
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';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * `onebot12.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 { onebot12RuntimeStateToken } from './onebot12-runtime-state.js';
8
+
9
+ export const onebot12EndpointCommands = createEndpointCommands({
10
+ adapterKey: 'onebot12',
11
+ adapterDisplayName: 'OneBot 12',
12
+ fields: [
13
+ { key: 'url', description: 'OneBot 实现 WebSocket URL(connection: ws 必填)' },
14
+ { key: 'path', description: 'HTTP/WS 路径(webhook / reverse-wss)' },
15
+ { key: 'api_url', description: 'HTTP action 端点(connection: webhook 出站必填)' },
16
+ { key: 'access_token', env: true, description: 'OneBot access token' },
17
+ ],
18
+ running: (use) => use(onebot12RuntimeStateToken).endpoints.values(),
19
+ describeEntry: (entry) => {
20
+ if (entry.url) return `url: ${String(entry.url)}`;
21
+ if (entry.path) return `path: ${String(entry.path)}`;
22
+ return '';
23
+ },
24
+ }, defineCommand);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * OneBot12 插件实例的运行时状态:adapter create() 注册的 endpoint 列表。
3
+ * 由 plugin.ts setup() provide,adapter create 与 `onebot12.endpoint` 命令共享(同一 owner generation)。
4
+ */
5
+ import { defineEndpointRuntimeStateToken } from 'zhin.js/adapter';
6
+
7
+ export const onebot12RuntimeStateToken = defineEndpointRuntimeStateToken('onebot12');