@xmoxmo/bncr 0.1.8 → 0.1.9
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/index.ts +1 -3
- package/package.json +1 -1
- package/src/channel.ts +26 -25
- package/src/messaging/inbound/commands.ts +4 -1
package/index.ts
CHANGED
|
@@ -302,9 +302,7 @@ const plugin = {
|
|
|
302
302
|
);
|
|
303
303
|
};
|
|
304
304
|
|
|
305
|
-
debugLog(
|
|
306
|
-
`register begin bridge=${bridge.getBridgeId?.() || 'unknown'} created=${created}`,
|
|
307
|
-
);
|
|
305
|
+
debugLog(`register begin bridge=${bridge.getBridgeId?.() || 'unknown'} created=${created}`);
|
|
308
306
|
if (!created) debugLog('bridge api rebound');
|
|
309
307
|
|
|
310
308
|
const resolveDebug = async () => {
|
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -25,11 +25,8 @@ import {
|
|
|
25
25
|
resolveAccount,
|
|
26
26
|
resolveDefaultDisplayName,
|
|
27
27
|
} from './core/accounts.ts';
|
|
28
|
-
import {
|
|
29
|
-
emitBncrLog,
|
|
30
|
-
emitBncrLogLine,
|
|
31
|
-
} from './core/logging.ts';
|
|
32
28
|
import { BncrConfigSchema } from './core/config-schema.ts';
|
|
29
|
+
import { emitBncrLog, emitBncrLogLine } from './core/logging.ts';
|
|
33
30
|
import { buildBncrPermissionSummary } from './core/permissions.ts';
|
|
34
31
|
import { resolveBncrChannelPolicy } from './core/policy.ts';
|
|
35
32
|
import { probeBncrAccount } from './core/probe.ts';
|
|
@@ -371,10 +368,6 @@ class BncrBridgeRuntime {
|
|
|
371
368
|
return this.bridgeId;
|
|
372
369
|
}
|
|
373
370
|
|
|
374
|
-
private isDebugEnabled() {
|
|
375
|
-
return BNCR_DEBUG_VERBOSE;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
371
|
private logInfo(scope: string | undefined, message: string, options?: { debugOnly?: boolean }) {
|
|
379
372
|
emitBncrLog('info', scope, message, options, () => this.isDebugEnabled());
|
|
380
373
|
}
|
|
@@ -387,9 +380,10 @@ class BncrBridgeRuntime {
|
|
|
387
380
|
emitBncrLog('error', scope, message, options, () => this.isDebugEnabled());
|
|
388
381
|
}
|
|
389
382
|
|
|
390
|
-
|
|
391
383
|
private summarizeTextPreview(raw: string, limit = 8) {
|
|
392
|
-
const compact = asString(raw || '')
|
|
384
|
+
const compact = asString(raw || '')
|
|
385
|
+
.replace(/\s+/g, ' ')
|
|
386
|
+
.trim();
|
|
393
387
|
if (!compact) return '-';
|
|
394
388
|
const chars = Array.from(compact);
|
|
395
389
|
return chars.length > limit ? `${chars.slice(0, Math.max(1, limit)).join('')}…` : compact;
|
|
@@ -648,6 +642,7 @@ class BncrBridgeRuntime {
|
|
|
648
642
|
this.logWarn(
|
|
649
643
|
'stale',
|
|
650
644
|
`observed kind=${kind} lease=${leaseId || '-'} epoch=${connectionEpoch ?? '-'} currentLease=${this.primaryLeaseId || '-'} currentEpoch=${this.connectionEpoch}`,
|
|
645
|
+
{ debugOnly: true },
|
|
651
646
|
);
|
|
652
647
|
return { stale: true, reason: 'mismatch' as const };
|
|
653
648
|
}
|
|
@@ -707,12 +702,7 @@ class BncrBridgeRuntime {
|
|
|
707
702
|
}
|
|
708
703
|
|
|
709
704
|
isDebugEnabled(): boolean {
|
|
710
|
-
|
|
711
|
-
const cfg = (this.api.runtime.config?.get?.() as any) || {};
|
|
712
|
-
return Boolean(cfg?.channels?.[CHANNEL_ID]?.debug?.verbose);
|
|
713
|
-
} catch {
|
|
714
|
-
return false;
|
|
715
|
-
}
|
|
705
|
+
return BNCR_DEBUG_VERBOSE;
|
|
716
706
|
}
|
|
717
707
|
|
|
718
708
|
startService = async (ctx: OpenClawPluginServiceContext, debug?: boolean) => {
|
|
@@ -727,6 +717,10 @@ class BncrBridgeRuntime {
|
|
|
727
717
|
if (typeof debug === 'boolean') BNCR_DEBUG_VERBOSE = debug;
|
|
728
718
|
await this.refreshDebugFlagFromConfig({ forceLog: true });
|
|
729
719
|
const bootDiag = this.buildIntegratedDiagnostics(BNCR_DEFAULT_ACCOUNT_ID);
|
|
720
|
+
this.logInfo(
|
|
721
|
+
'startup',
|
|
722
|
+
`bridge=${this.bridgeId} routes=${bootDiag.regression.totalKnownRoutes}`,
|
|
723
|
+
);
|
|
730
724
|
this.logInfo(
|
|
731
725
|
'debug',
|
|
732
726
|
`service started bridge=${this.bridgeId} diag.ok=${bootDiag.regression.ok} routes=${bootDiag.regression.totalKnownRoutes} pending=${bootDiag.health.pending} dead=${bootDiag.health.deadLetter} debug=${BNCR_DEBUG_VERBOSE}`,
|
|
@@ -768,15 +762,15 @@ class BncrBridgeRuntime {
|
|
|
768
762
|
const changed = next !== BNCR_DEBUG_VERBOSE;
|
|
769
763
|
BNCR_DEBUG_VERBOSE = next;
|
|
770
764
|
if (changed || options?.forceLog) {
|
|
771
|
-
this.logInfo('debug', `verbose=${BNCR_DEBUG_VERBOSE}
|
|
765
|
+
this.logInfo('debug', `verbose=${BNCR_DEBUG_VERBOSE}`, { debugOnly: true });
|
|
772
766
|
}
|
|
773
767
|
} catch {
|
|
774
768
|
// ignore config read errors
|
|
775
769
|
}
|
|
776
770
|
}
|
|
777
771
|
|
|
778
|
-
private syncDebugFlag() {
|
|
779
|
-
|
|
772
|
+
private async syncDebugFlag() {
|
|
773
|
+
await this.refreshDebugFlagFromConfig();
|
|
780
774
|
}
|
|
781
775
|
|
|
782
776
|
private tryResolveBindingAgentId(args: {
|
|
@@ -832,7 +826,11 @@ class BncrBridgeRuntime {
|
|
|
832
826
|
this.canonicalAgentId = 'main';
|
|
833
827
|
this.canonicalAgentSource = 'fallback-main';
|
|
834
828
|
this.canonicalAgentResolvedAt = now();
|
|
835
|
-
this.logWarn(
|
|
829
|
+
this.logWarn(
|
|
830
|
+
'target',
|
|
831
|
+
'binding agent unresolved; fallback to main for current process lifetime',
|
|
832
|
+
{ debugOnly: true },
|
|
833
|
+
);
|
|
836
834
|
return this.canonicalAgentId;
|
|
837
835
|
}
|
|
838
836
|
|
|
@@ -1609,6 +1607,7 @@ class BncrBridgeRuntime {
|
|
|
1609
1607
|
this.logWarn(
|
|
1610
1608
|
'target',
|
|
1611
1609
|
`invalid raw=${raw} accountId=${acc} reason=unparseable-or-unknown standardTo=Bncr:<platform>:<groupId>:<userId>|Bncr:<platform>:<userId> standardSessionKey=agent:<agentId>:bncr:direct:<hex(scope)>`,
|
|
1610
|
+
{ debugOnly: true },
|
|
1612
1611
|
);
|
|
1613
1612
|
throw new Error(
|
|
1614
1613
|
`bncr invalid target(standard: Bncr:<platform>:<groupId>:<userId> | Bncr:<platform>:<userId>): ${raw}`,
|
|
@@ -2283,7 +2282,7 @@ class BncrBridgeRuntime {
|
|
|
2283
2282
|
}
|
|
2284
2283
|
|
|
2285
2284
|
handleConnect = async ({ params, respond, client, context }: GatewayRequestHandlerOptions) => {
|
|
2286
|
-
this.syncDebugFlag();
|
|
2285
|
+
await this.syncDebugFlag();
|
|
2287
2286
|
const accountId = normalizeAccountId(asString(params?.accountId || ''));
|
|
2288
2287
|
const connId = asString(client?.connId || '').trim() || `no-conn-${Date.now()}`;
|
|
2289
2288
|
const clientId = asString((params as any)?.clientId || '').trim() || undefined;
|
|
@@ -2331,7 +2330,7 @@ class BncrBridgeRuntime {
|
|
|
2331
2330
|
};
|
|
2332
2331
|
|
|
2333
2332
|
handleAck = async ({ params, respond, client, context }: GatewayRequestHandlerOptions) => {
|
|
2334
|
-
this.syncDebugFlag();
|
|
2333
|
+
await this.syncDebugFlag();
|
|
2335
2334
|
const accountId = normalizeAccountId(asString(params?.accountId || ''));
|
|
2336
2335
|
const connId = asString(client?.connId || '').trim() || `no-conn-${Date.now()}`;
|
|
2337
2336
|
const clientId = asString((params as any)?.clientId || '').trim() || undefined;
|
|
@@ -2395,7 +2394,7 @@ class BncrBridgeRuntime {
|
|
|
2395
2394
|
};
|
|
2396
2395
|
|
|
2397
2396
|
handleActivity = async ({ params, respond, client, context }: GatewayRequestHandlerOptions) => {
|
|
2398
|
-
this.syncDebugFlag();
|
|
2397
|
+
await this.syncDebugFlag();
|
|
2399
2398
|
const accountId = normalizeAccountId(asString(params?.accountId || ''));
|
|
2400
2399
|
const connId = asString(client?.connId || '').trim() || `no-conn-${Date.now()}`;
|
|
2401
2400
|
const clientId = asString((params as any)?.clientId || '').trim() || undefined;
|
|
@@ -2756,7 +2755,7 @@ class BncrBridgeRuntime {
|
|
|
2756
2755
|
};
|
|
2757
2756
|
|
|
2758
2757
|
handleInbound = async ({ params, respond, client, context }: GatewayRequestHandlerOptions) => {
|
|
2759
|
-
this.syncDebugFlag();
|
|
2758
|
+
await this.syncDebugFlag();
|
|
2760
2759
|
const parsed = parseBncrInboundParams(params);
|
|
2761
2760
|
const {
|
|
2762
2761
|
accountId,
|
|
@@ -2884,7 +2883,7 @@ class BncrBridgeRuntime {
|
|
|
2884
2883
|
error: (msg: string) => emitBncrLogLine('error', msg),
|
|
2885
2884
|
},
|
|
2886
2885
|
}).catch((err) => {
|
|
2887
|
-
this.logError('inbound', `process failed: ${String(err)}
|
|
2886
|
+
this.logError('inbound', `process failed: ${String(err)}`, { debugOnly: true });
|
|
2888
2887
|
});
|
|
2889
2888
|
};
|
|
2890
2889
|
|
|
@@ -2932,6 +2931,7 @@ class BncrBridgeRuntime {
|
|
|
2932
2931
|
};
|
|
2933
2932
|
|
|
2934
2933
|
channelSendText = async (ctx: any) => {
|
|
2934
|
+
await this.syncDebugFlag();
|
|
2935
2935
|
const accountId = normalizeAccountId(ctx.accountId);
|
|
2936
2936
|
const to = asString(ctx.to || '').trim();
|
|
2937
2937
|
|
|
@@ -2970,6 +2970,7 @@ class BncrBridgeRuntime {
|
|
|
2970
2970
|
};
|
|
2971
2971
|
|
|
2972
2972
|
channelSendMedia = async (ctx: any) => {
|
|
2973
|
+
await this.syncDebugFlag();
|
|
2973
2974
|
const accountId = normalizeAccountId(ctx.accountId);
|
|
2974
2975
|
const to = asString(ctx.to || '').trim();
|
|
2975
2976
|
const asVoice = ctx?.asVoice === true;
|
|
@@ -120,7 +120,10 @@ export async function handleBncrNativeCommand(params: {
|
|
|
120
120
|
sessionKey,
|
|
121
121
|
ctx: ctxPayload,
|
|
122
122
|
onRecordError: (err: unknown) => {
|
|
123
|
-
emitBncrLogLine(
|
|
123
|
+
emitBncrLogLine(
|
|
124
|
+
'warn',
|
|
125
|
+
`[bncr] inbound record native command session failed: ${String(err)}`,
|
|
126
|
+
);
|
|
124
127
|
},
|
|
125
128
|
});
|
|
126
129
|
|