@xmoxmo/bncr 0.5.0 → 0.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmoxmo/bncr",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/channel.ts CHANGED
@@ -2354,7 +2354,7 @@ class BncrBridgeRuntime {
2354
2354
  // 严谨目标解析:
2355
2355
  // 1) 标准 to 仅认 Bncr:<platform>:0:<userId> / Bncr:<platform>:<groupId>:0
2356
2356
  // 2) 仍接受 strict sessionKey 作为内部兼容输入
2357
- // 3) 输入侧额外兼容 Bncr:<platform>:user:<userId> / Bncr:<platform>:group:<groupId>
2357
+ // 3) 输入侧额外兼容 Bncr:<platform>:User:<userId> / Bncr:<platform>:Group:<groupId>
2358
2358
  // 4) 其他旧格式直接失败,并输出标准格式提示日志
2359
2359
  resolveVerifiedTarget(
2360
2360
  rawTarget: string,
@@ -428,6 +428,15 @@ export function formatDisplayScope(route: BncrRoute): string {
428
428
  return `Bncr:${platform}:0:${userId}`;
429
429
  }
430
430
 
431
+ export function formatHumanDisplayScope(route: BncrRoute): string {
432
+ const platform = asTargetString(route?.platform).trim();
433
+ const groupId = asTargetString(route?.groupId || '0').trim() || '0';
434
+ const userId = asTargetString(route?.userId || '0').trim() || '0';
435
+ if (groupId !== '0') return `Bncr:${platform}:Group:${groupId}`;
436
+ if (userId !== '0') return `Bncr:${platform}:User:${userId}`;
437
+ return formatDisplayScope(route);
438
+ }
439
+
431
440
  export function buildDisplayScopeCandidates(route: BncrRoute): string[] {
432
441
  const candidates = [formatDisplayScope(route)].filter(Boolean);
433
442
  return Array.from(new Set(candidates.map((x) => asTargetString(x).trim()).filter(Boolean)));
@@ -1,4 +1,5 @@
1
1
  import { emitBncrLogLine } from '../../core/logging.ts';
2
+ import { formatHumanDisplayScope, parseRouteFromDisplayScope } from '../../core/targets.ts';
2
3
  import type { OpenClawChannelRuntimeContext } from '../../openclaw/channel-runtime-contracts.ts';
3
4
  import {
4
5
  recordBncrSessionMetaFromInbound,
@@ -7,12 +8,8 @@ import {
7
8
 
8
9
  function formatBncrSessionLabel(displayTo: string): string {
9
10
  const raw = String(displayTo || '').trim();
10
- const parts = raw.split(':');
11
- if (parts.length === 4 && parts[0] === 'Bncr') {
12
- const [, platform, groupId, userId] = parts;
13
- if (platform && groupId && groupId !== '0') return `Bncr:${platform}:Group:${groupId}`;
14
- if (platform && userId && userId !== '0') return `Bncr:${platform}:User:${userId}`;
15
- }
11
+ const route = parseRouteFromDisplayScope(raw);
12
+ if (route) return formatHumanDisplayScope(route);
16
13
  return raw;
17
14
  }
18
15
 
@@ -1,6 +1,6 @@
1
1
  import type { ChatType } from 'openclaw/plugin-sdk/core';
2
2
  import { BNCR_DEFAULT_ACCOUNT_ID, normalizeAccountId } from '../core/accounts.ts';
3
- import { formatDisplayScope, parseExplicitTarget } from '../core/targets.ts';
3
+ import { formatHumanDisplayScope, parseExplicitTarget } from '../core/targets.ts';
4
4
  import type { BncrRoute } from '../core/types.ts';
5
5
  import { asSanitizedString } from '../core/value-sanitize.ts';
6
6
  import { resolveBncrOutboundSessionRoute } from '../messaging/outbound/session-route.ts';
@@ -11,12 +11,7 @@ import {
11
11
  import type { BncrChannelConfigRoot } from './channel-runtime-types.ts';
12
12
 
13
13
  function formatBncrHumanDisplay(route: BncrRoute): string {
14
- const platform = asSanitizedString(route?.platform).trim();
15
- const groupId = asSanitizedString(route?.groupId).trim();
16
- const userId = asSanitizedString(route?.userId).trim();
17
- if (platform && groupId && groupId !== '0') return `Bncr:${platform}:Group:${groupId}`;
18
- if (platform && userId && userId !== '0') return `Bncr:${platform}:User:${userId}`;
19
- return formatDisplayScope(route);
14
+ return formatHumanDisplayScope(route);
20
15
  }
21
16
 
22
17
  type BncrMessagingRuntimeBridge = {
@@ -95,11 +95,11 @@ export function createBncrTargetRuntime(runtime: {
95
95
  if (!route) {
96
96
  runtime.logWarn(
97
97
  'target',
98
- `invalid raw=${raw} accountId=${acc} reason=unparseable-or-unknown canonicalTo=Bncr:<platform>:0:<userId>|Bncr:<platform>:<groupId>:0 acceptedAliases=Bncr:<platform>:user:<userId>|Bncr:<platform>:group:<groupId> standardSessionKey=agent:<agentId>:bncr:<direct|group>:<hex(scope)>`,
98
+ `invalid raw=${raw} accountId=${acc} reason=unparseable-or-unknown canonicalTo=Bncr:<platform>:0:<userId>|Bncr:<platform>:<groupId>:0 acceptedAliases=Bncr:<platform>:User:<userId>|Bncr:<platform>:Group:<groupId> standardSessionKey=agent:<agentId>:bncr:<direct|group>:<hex(scope)>`,
99
99
  { debugOnly: true },
100
100
  );
101
101
  throw new Error(
102
- `bncr invalid target(canonical: Bncr:<platform>:0:<userId> | Bncr:<platform>:<groupId>:0; aliases: Bncr:<platform>:user:<userId> | Bncr:<platform>:group:<groupId>): ${raw}`,
102
+ `bncr invalid target(canonical: Bncr:<platform>:0:<userId> | Bncr:<platform>:<groupId>:0; aliases: Bncr:<platform>:User:<userId> | Bncr:<platform>:Group:<groupId>): ${raw}`,
103
103
  );
104
104
  }
105
105