@zhin.js/adapter-onebot12 1.1.20 → 1.1.21

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,32 @@
1
1
  # @zhin.js/adapter-onebot12
2
2
 
3
+ ## 1.1.21
4
+
5
+ ### Patch Changes
6
+
7
+ - af8f803: Use the current Endpoint's platform profile for Agent account identity, with per-field configured fallbacks and scoped, identity-approved profile tools. Keep SOUL first-person and independent of account names. Profile ports preserve the source Client, cancellation, truthful update outcomes and private image authority.
8
+
9
+ Adapter Feature API 2.1 and Tool Feature API 1.1 describe the additive profile requirements; new Core, official adapters and generated plugins declare the corresponding floors. Existing compatible API-2.0/API-1.0 plugins remain accepted by the newer providers. npm releases remain patch.
10
+
11
+ Private IM assets now bind to the full canonical conversation and principal. Existing IM asset records that contain only the earlier lossy hash remain on disk until their original expiry, but cannot be safely rebound; recapture them. No automatic file deletion, platform profile mutation or workspace SOUL rewrite occurs during upgrade.
12
+
13
+ - Updated dependencies [b88e988]
14
+ - Updated dependencies [f78eb84]
15
+ - Updated dependencies [c15cef9]
16
+ - Updated dependencies [b0c02a2]
17
+ - Updated dependencies [af8f803]
18
+ - Updated dependencies [26fda97]
19
+ - Updated dependencies [976886c]
20
+ - Updated dependencies [032dc96]
21
+ - @zhin.js/adapter@1.1.27
22
+ - @zhin.js/client@1.1.23
23
+ - @zhin.js/im-contract@1.1.10
24
+ - @zhin.js/core@1.1.55
25
+ - @zhin.js/page@1.1.13
26
+ - @zhin.js/host-http@1.1.13
27
+ - @zhin.js/feature-kit@1.1.11
28
+ - @zhin.js/skill@1.1.12
29
+
3
30
  ## 1.1.20
4
31
 
5
32
  ### Patch Changes
package/lib/protocol.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { EndpointProfileConfiguration } from 'zhin.js/adapter';
1
2
  /**
2
3
  * OneBot 12 protocol helpers (no legacy Adapter/Endpoint / segment-mapper).
3
4
  * Canonicalization is owned by gateway/core before endpoint.send.
@@ -5,7 +6,7 @@
5
6
  */
6
7
  import { type MediaRef, type ConversationRef } from '@zhin.js/im-contract';
7
8
  /** One endpoint config after AdapterIndex expands `plugins.<instanceKey>.endpoints`. */
8
- export interface OneBot12EndpointConfig {
9
+ export interface OneBot12EndpointConfig extends EndpointProfileConfiguration {
9
10
  readonly platform: string;
10
11
  readonly userId: string;
11
12
  readonly connection?: 'ws' | 'webhook' | 'wss';
@@ -0,0 +1,9 @@
1
+ import type { EndpointProfile, PendingRpcRequest } from 'zhin.js/adapter';
2
+ interface Onebot12SelfProfileOptions {
3
+ readonly call: (request: PendingRpcRequest) => Promise<unknown>;
4
+ readonly accountId: string;
5
+ readonly reportAccount: (id: string) => void;
6
+ }
7
+ /** The protocol caller already binds self={platform,user_id}; validate the returned account too. */
8
+ export declare function createOnebot12SelfProfile({ call, accountId, reportAccount }: Onebot12SelfProfileOptions): EndpointProfile;
9
+ export {};
@@ -0,0 +1,16 @@
1
+ /** The protocol caller already binds self={platform,user_id}; validate the returned account too. */
2
+ export function createOnebot12SelfProfile({ call, accountId, reportAccount }) {
3
+ return Object.freeze({
4
+ writableFields: Object.freeze([]),
5
+ async read({ signal }) {
6
+ const self = await call({ action: 'get_self_info', signal });
7
+ if (self?.user_id !== accountId)
8
+ throw new Error('OneBot12 returned another account profile');
9
+ const nickname = self.user_displayname || self.user_name;
10
+ if (typeof nickname !== 'string')
11
+ throw new Error('OneBot12 returned an incomplete self profile');
12
+ reportAccount(self.user_id);
13
+ return { nickname };
14
+ },
15
+ });
16
+ }
package/lib/webhook.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { createOnebot12SelfProfile } from './self-profile.js';
1
2
  import { acceptHttpIngress } from 'imhelper';
2
3
  import { createEndpointSpecification, endpointSpec, createRecallEndpointControl, } from 'zhin.js/adapter';
3
4
  import { formatCompact, getLogger } from '@zhin.js/logger';
@@ -32,6 +33,7 @@ export class OneBot12WebhookEndpoint extends Onebot12Client {
32
33
  close: () => { this.#open = false; }, stop: () => this.#stop(),
33
34
  send: request => this.#send(request),
34
35
  management: this.#management, control: this.#control, content: this.#content,
36
+ profile: createOnebot12SelfProfile({ call: callApi, accountId: options.config.userId, reportAccount: id => this[endpointSpec].reportSelfUserId(id) }),
35
37
  });
36
38
  this.#releaseClientEvents = forwardOnebot12ClientEvents(this, (name, payload) => {
37
39
  void this[endpointSpec].events.run(() => {
@@ -1,3 +1,4 @@
1
+ import { createOnebot12SelfProfile } from './self-profile.js';
1
2
  /**
2
3
  * OneBot12 WS client endpoint — outbound connect to OneBot implementation.
3
4
  */
@@ -42,6 +43,7 @@ export class OneBot12WsEndpoint extends Onebot12Client {
42
43
  send: request => this.#send(request),
43
44
  get transportState() { return readTransportState(); },
44
45
  management: this.#management, control: this.#control, content: this.#content,
46
+ profile: createOnebot12SelfProfile({ call: callApi, accountId: options.config.userId, reportAccount: id => this[endpointSpec].reportSelfUserId(id) }),
45
47
  });
46
48
  this.#releaseClientEvents = forwardOnebot12ClientEvents(this, (name, payload) => {
47
49
  void this[endpointSpec].events.run(() => {
@@ -1,3 +1,4 @@
1
+ import { createOnebot12SelfProfile } from './self-profile.js';
1
2
  /**
2
3
  * OneBot12 reverse WSS endpoint — accepts inbound WebSocket from OneBot implementation.
3
4
  */
@@ -49,6 +50,7 @@ export class OneBot12WssEndpoint extends Onebot12Client {
49
50
  send: request => this.#send(request),
50
51
  get transportState() { return readTransportState(); },
51
52
  management: this.#management, control: this.#control, content: this.#content,
53
+ profile: createOnebot12SelfProfile({ call: callApi, accountId: options.config.userId, reportAccount: id => this[endpointSpec].reportSelfUserId(id) }),
52
54
  });
53
55
  this.#releaseClientEvents = forwardOnebot12ClientEvents(this, (name, payload) => {
54
56
  void this[endpointSpec].events.run(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/adapter-onebot12",
3
- "version": "1.1.20",
3
+ "version": "1.1.21",
4
4
  "description": "Zhin.js OneBot 12 adapter for Plugin Runtime (WebSocket client)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -42,30 +42,30 @@
42
42
  "@imhelper/onebot-v12": "1.0.7",
43
43
  "imhelper": "1.0.7",
44
44
  "ws": "^8.21.1",
45
- "@zhin.js/adapter": "1.1.26",
46
- "@zhin.js/client": "1.1.22",
45
+ "@zhin.js/adapter": "1.1.27",
46
+ "@zhin.js/client": "1.1.23",
47
47
  "@zhin.js/console-contract": "1.1.3",
48
- "@zhin.js/core": "1.1.54",
49
- "@zhin.js/feature-kit": "1.1.10",
50
- "@zhin.js/host-http": "1.1.12",
51
- "@zhin.js/im-contract": "1.1.9",
48
+ "@zhin.js/core": "1.1.55",
49
+ "@zhin.js/feature-kit": "1.1.11",
50
+ "@zhin.js/host-http": "1.1.13",
51
+ "@zhin.js/im-contract": "1.1.10",
52
52
  "@zhin.js/logger": "1.1.2",
53
- "@zhin.js/page": "1.1.12",
54
- "@zhin.js/skill": "1.1.11"
53
+ "@zhin.js/page": "1.1.13",
54
+ "@zhin.js/skill": "1.1.12"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/node": "^26.1.2",
58
58
  "@types/ws": "^8.18.1",
59
59
  "typescript": "^6.0.3",
60
60
  "vitest": "^4.1.10",
61
- "@zhin.js/host-http": "1.1.12",
62
- "zhin.js": "1.1.19"
61
+ "@zhin.js/host-http": "1.1.13",
62
+ "zhin.js": "1.1.20"
63
63
  },
64
64
  "peerDependencies": {
65
- "@zhin.js/adapter": "^1.1.26",
66
- "@zhin.js/command": "^1.1.12",
67
- "@zhin.js/core": "^1.1.54",
68
- "zhin.js": "^1.1.19"
65
+ "@zhin.js/adapter": "^1.1.27",
66
+ "@zhin.js/command": "^1.1.13",
67
+ "@zhin.js/core": "^1.1.55",
68
+ "zhin.js": "^1.1.20"
69
69
  },
70
70
  "peerDependenciesMeta": {
71
71
  "@zhin.js/command": {
@@ -96,7 +96,7 @@
96
96
  "features": [
97
97
  {
98
98
  "package": "@zhin.js/adapter",
99
- "api": "^2.0.0"
99
+ "api": "^2.1.0"
100
100
  },
101
101
  {
102
102
  "package": "@zhin.js/command",
package/schema.json CHANGED
@@ -131,6 +131,27 @@
131
131
  "type": "string",
132
132
  "minLength": 1,
133
133
  "description": "Selected OneBot12 bot user ID"
134
+ },
135
+ "nickname": {
136
+ "type": [
137
+ "string",
138
+ "null"
139
+ ],
140
+ "description": "账号昵称兜底",
141
+ "x-i18n": {
142
+ "en": {
143
+ "description": "Fallback account nickname"
144
+ }
145
+ }
146
+ },
147
+ "profile": {
148
+ "$ref": "#/$defs/selfProfileFallback",
149
+ "description": "账号资料兜底",
150
+ "x-i18n": {
151
+ "en": {
152
+ "description": "Fallback account profile"
153
+ }
154
+ }
134
155
  }
135
156
  },
136
157
  "required": [
@@ -154,9 +175,93 @@
154
175
  "description": "Command prefix. The default empty string allows unprefixed commands; '/' requires a leading slash. Each endpoints[i] can override it."
155
176
  }
156
177
  }
178
+ },
179
+ "nickname": {
180
+ "type": [
181
+ "string",
182
+ "null"
183
+ ],
184
+ "description": "账号昵称兜底",
185
+ "x-i18n": {
186
+ "en": {
187
+ "description": "Fallback account nickname"
188
+ }
189
+ }
190
+ },
191
+ "profile": {
192
+ "$ref": "#/$defs/selfProfileFallback",
193
+ "description": "账号资料兜底",
194
+ "x-i18n": {
195
+ "en": {
196
+ "description": "Fallback account profile"
197
+ }
198
+ }
157
199
  }
158
200
  },
159
201
  "required": [
160
202
  "endpoints"
161
- ]
203
+ ],
204
+ "$defs": {
205
+ "selfProfileFallback": {
206
+ "type": "object",
207
+ "additionalProperties": false,
208
+ "properties": {
209
+ "gender": {
210
+ "type": [
211
+ "string",
212
+ "null"
213
+ ],
214
+ "enum": [
215
+ "male",
216
+ "female",
217
+ "other",
218
+ "unknown",
219
+ null
220
+ ]
221
+ },
222
+ "age": {
223
+ "type": [
224
+ "integer",
225
+ "null"
226
+ ],
227
+ "minimum": 0
228
+ },
229
+ "birthday": {
230
+ "type": [
231
+ "string",
232
+ "null"
233
+ ],
234
+ "pattern": "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$"
235
+ },
236
+ "signature": {
237
+ "type": [
238
+ "string",
239
+ "null"
240
+ ]
241
+ },
242
+ "avatar": {
243
+ "type": [
244
+ "string",
245
+ "null"
246
+ ],
247
+ "pattern": "^(https?://[^\\s/?#]+(?:[/?#].*)?|)$"
248
+ },
249
+ "interests": {
250
+ "type": [
251
+ "array",
252
+ "null"
253
+ ],
254
+ "items": {
255
+ "type": "string"
256
+ }
257
+ },
258
+ "bio": {
259
+ "type": [
260
+ "string",
261
+ "null"
262
+ ]
263
+ }
264
+ }
265
+ }
266
+ }
162
267
  }
package/src/protocol.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { EndpointProfileConfiguration } from 'zhin.js/adapter';
1
2
  import { readOnebot12Response } from './response.js';
2
3
  /**
3
4
  * OneBot 12 protocol helpers (no legacy Adapter/Endpoint / segment-mapper).
@@ -10,7 +11,7 @@ import { formatCompact, getLogger } from '@zhin.js/logger';
10
11
  const logger = getLogger('onebot12');
11
12
 
12
13
  /** One endpoint config after AdapterIndex expands `plugins.<instanceKey>.endpoints`. */
13
- export interface OneBot12EndpointConfig {
14
+ export interface OneBot12EndpointConfig extends EndpointProfileConfiguration {
14
15
  readonly platform: string;
15
16
  readonly userId: string;
16
17
  readonly connection?: 'ws' | 'webhook' | 'wss';
@@ -0,0 +1,22 @@
1
+ import type { EndpointProfile, PendingRpcRequest } from 'zhin.js/adapter';
2
+
3
+ interface Onebot12SelfProfileOptions {
4
+ readonly call: (request: PendingRpcRequest) => Promise<unknown>;
5
+ readonly accountId: string;
6
+ readonly reportAccount: (id: string) => void;
7
+ }
8
+
9
+ /** The protocol caller already binds self={platform,user_id}; validate the returned account too. */
10
+ export function createOnebot12SelfProfile({ call, accountId, reportAccount }: Onebot12SelfProfileOptions): EndpointProfile {
11
+ return Object.freeze<EndpointProfile>({
12
+ writableFields: Object.freeze([]),
13
+ async read({ signal }) {
14
+ const self = await call({ action: 'get_self_info', signal }) as { user_id?: string; user_name?: string; user_displayname?: string } | undefined;
15
+ if (self?.user_id !== accountId) throw new Error('OneBot12 returned another account profile');
16
+ const nickname = self.user_displayname || self.user_name;
17
+ if (typeof nickname !== 'string') throw new Error('OneBot12 returned an incomplete self profile');
18
+ reportAccount(self.user_id);
19
+ return { nickname };
20
+ },
21
+ });
22
+ }
package/src/webhook.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { createOnebot12SelfProfile } from './self-profile.js';
1
2
  import { acceptHttpIngress } from 'imhelper';
2
3
  /**
3
4
  * OneBot12 HTTP webhook endpoint — POST inbound + api_url outbound.
@@ -71,6 +72,7 @@ export class OneBot12WebhookEndpoint extends Onebot12Client implements Endpoint
71
72
  close: () => { this.#open = false; }, stop: () => this.#stop(),
72
73
  send: request => this.#send(request),
73
74
  management: this.#management, control: this.#control, content: this.#content,
75
+ profile: createOnebot12SelfProfile({ call: callApi, accountId: options.config.userId, reportAccount: id => this[endpointSpec].reportSelfUserId(id) }),
74
76
  });
75
77
  this.#releaseClientEvents = forwardOnebot12ClientEvents(this, (name, payload) => {
76
78
  void this[endpointSpec].events.run(() => {
@@ -1,3 +1,4 @@
1
+ import { createOnebot12SelfProfile } from './self-profile.js';
1
2
  /**
2
3
  * OneBot12 WS client endpoint — outbound connect to OneBot implementation.
3
4
  */
@@ -85,6 +86,7 @@ export class OneBot12WsEndpoint extends Onebot12Client implements Endpoint {
85
86
  send: request => this.#send(request),
86
87
  get transportState() { return readTransportState(); },
87
88
  management: this.#management, control: this.#control, content: this.#content,
89
+ profile: createOnebot12SelfProfile({ call: callApi, accountId: options.config.userId, reportAccount: id => this[endpointSpec].reportSelfUserId(id) }),
88
90
  });
89
91
  this.#releaseClientEvents = forwardOnebot12ClientEvents(this, (name, payload) => {
90
92
  void this[endpointSpec].events.run(() => {
@@ -1,3 +1,4 @@
1
+ import { createOnebot12SelfProfile } from './self-profile.js';
1
2
  /**
2
3
  * OneBot12 reverse WSS endpoint — accepts inbound WebSocket from OneBot implementation.
3
4
  */
@@ -85,6 +86,7 @@ export class OneBot12WssEndpoint extends Onebot12Client implements Endpoint {
85
86
  send: request => this.#send(request),
86
87
  get transportState() { return readTransportState(); },
87
88
  management: this.#management, control: this.#control, content: this.#content,
89
+ profile: createOnebot12SelfProfile({ call: callApi, accountId: options.config.userId, reportAccount: id => this[endpointSpec].reportSelfUserId(id) }),
88
90
  });
89
91
  this.#releaseClientEvents = forwardOnebot12ClientEvents(this, (name, payload) => {
90
92
  void this[endpointSpec].events.run(() => {