@xmoxmo/bncr 0.3.5 → 0.3.7

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 (164) hide show
  1. package/README.md +5 -0
  2. package/dist/index.js +28 -5
  3. package/index.ts +55 -721
  4. package/package.json +8 -4
  5. package/scripts/check-pack.mjs +93 -18
  6. package/scripts/check-register-drift.mjs +35 -13
  7. package/scripts/selfcheck.mjs +80 -11
  8. package/src/bootstrap/channel-plugin-runtime.ts +81 -0
  9. package/src/bootstrap/cli.ts +97 -0
  10. package/src/bootstrap/register-runtime-gateway.ts +129 -0
  11. package/src/bootstrap/register-runtime-helpers.ts +140 -0
  12. package/src/bootstrap/register-runtime-singleton.ts +137 -0
  13. package/src/bootstrap/register-runtime.ts +201 -0
  14. package/src/bootstrap/runtime-discovery.ts +187 -0
  15. package/src/bootstrap/runtime-loader.ts +54 -0
  16. package/src/channel.ts +1590 -4967
  17. package/src/core/accounts.ts +23 -4
  18. package/src/core/dead-letter-diagnostics.ts +37 -5
  19. package/src/core/diagnostics.ts +31 -15
  20. package/src/core/downlink-health.ts +3 -11
  21. package/src/core/extended-diagnostics.ts +78 -36
  22. package/src/core/file-transfer-payloads.ts +1 -1
  23. package/src/core/logging.ts +1 -0
  24. package/src/core/outbox-enqueue.ts +13 -2
  25. package/src/core/outbox-entry-builders.ts +2 -0
  26. package/src/core/outbox-summary.ts +75 -3
  27. package/src/core/permissions.ts +15 -2
  28. package/src/core/persisted-outbox-entry.ts +21 -6
  29. package/src/core/policy.ts +45 -4
  30. package/src/core/probe.ts +3 -15
  31. package/src/core/register-trace.ts +3 -3
  32. package/src/core/status.ts +43 -4
  33. package/src/core/targets.ts +216 -205
  34. package/src/core/types.ts +221 -0
  35. package/src/core/value-sanitize.ts +29 -0
  36. package/src/messaging/inbound/commands.ts +147 -172
  37. package/src/messaging/inbound/context-facts.ts +4 -2
  38. package/src/messaging/inbound/contracts.ts +70 -0
  39. package/src/messaging/inbound/dispatch-prep.ts +303 -0
  40. package/src/messaging/inbound/dispatch.ts +49 -462
  41. package/src/messaging/inbound/gate.ts +18 -5
  42. package/src/messaging/inbound/last-route.ts +10 -4
  43. package/src/messaging/inbound/media-url-download.ts +109 -0
  44. package/src/messaging/inbound/native-command-runtime.ts +225 -0
  45. package/src/messaging/inbound/parse.ts +2 -1
  46. package/src/messaging/inbound/remote-media.ts +49 -0
  47. package/src/messaging/inbound/reply-config.ts +16 -4
  48. package/src/messaging/inbound/reply-dispatch.ts +162 -0
  49. package/src/messaging/inbound/runtime-compat.ts +31 -10
  50. package/src/messaging/inbound/session-label.ts +15 -7
  51. package/src/messaging/inbound/turn-context.ts +131 -0
  52. package/src/messaging/outbound/actions.ts +24 -10
  53. package/src/messaging/outbound/diagnostics-debug-builders.ts +365 -0
  54. package/src/messaging/outbound/diagnostics.ts +31 -355
  55. package/src/messaging/outbound/durable-message-adapter.ts +20 -16
  56. package/src/messaging/outbound/durable-queue-adapter.ts +20 -7
  57. package/src/messaging/outbound/media.ts +24 -13
  58. package/src/messaging/outbound/reply-enqueue-media.ts +181 -0
  59. package/src/messaging/outbound/reply-enqueue.ts +57 -134
  60. package/src/messaging/outbound/send-params.ts +3 -0
  61. package/src/messaging/outbound/send.ts +19 -10
  62. package/src/messaging/outbound/session-route.ts +18 -3
  63. package/src/openclaw/channel-runtime-contracts.ts +76 -0
  64. package/src/openclaw/config-runtime.ts +13 -7
  65. package/src/openclaw/inbound-session-runtime.ts +7 -3
  66. package/src/openclaw/ingress-runtime.ts +17 -27
  67. package/src/openclaw/reply-runtime.ts +54 -59
  68. package/src/openclaw/routing-runtime.ts +35 -18
  69. package/src/openclaw/runtime-surface.ts +156 -12
  70. package/src/openclaw/sdk-helpers.ts +8 -1
  71. package/src/openclaw/session-route-runtime.ts +12 -12
  72. package/src/plugin/ack-outbox-runtime-group.ts +264 -0
  73. package/src/plugin/bridge-ack-facade.ts +137 -0
  74. package/src/plugin/bridge-connection-facade.ts +111 -0
  75. package/src/plugin/bridge-diagnostics-facade.ts +23 -0
  76. package/src/plugin/bridge-drain-facade.ts +98 -0
  77. package/src/plugin/bridge-extended-diagnostics-facade.ts +149 -0
  78. package/src/plugin/bridge-file-transfer-push-facade.ts +140 -0
  79. package/src/plugin/bridge-lifecycle.ts +156 -0
  80. package/src/plugin/bridge-media-facade.ts +241 -0
  81. package/src/plugin/bridge-outbox-facade.ts +182 -0
  82. package/src/plugin/bridge-runtime-helpers.ts +266 -0
  83. package/src/plugin/bridge-runtime-snapshots.ts +104 -0
  84. package/src/plugin/bridge-runtime-surface-facade.ts +8 -0
  85. package/src/plugin/bridge-status-facade.ts +76 -0
  86. package/src/plugin/bridge-status-worker-facade.ts +72 -0
  87. package/src/plugin/bridge-support-runtime.ts +137 -0
  88. package/src/plugin/bridge-surface-handlers-group.ts +242 -0
  89. package/src/plugin/bridge-surface-helpers.ts +28 -0
  90. package/src/plugin/capabilities.ts +1 -3
  91. package/src/plugin/channel-components.ts +289 -0
  92. package/src/plugin/channel-inbound-helpers.ts +149 -0
  93. package/src/plugin/channel-plugin-bridge-group.ts +129 -0
  94. package/src/plugin/channel-plugin-surface-group.ts +202 -0
  95. package/src/plugin/channel-runtime-builders-delivery.ts +513 -0
  96. package/src/plugin/channel-runtime-builders-status.ts +331 -0
  97. package/src/plugin/channel-runtime-builders.ts +25 -0
  98. package/src/plugin/channel-runtime-constants.ts +40 -0
  99. package/src/plugin/channel-runtime-types.ts +146 -0
  100. package/src/plugin/channel-send-runtime-group.ts +37 -0
  101. package/src/plugin/channel-send.ts +226 -0
  102. package/src/plugin/channel-utils.ts +102 -0
  103. package/src/plugin/config.ts +24 -3
  104. package/src/plugin/connection-handlers-helpers.ts +254 -0
  105. package/src/plugin/connection-handlers.ts +440 -0
  106. package/src/plugin/connection-state-helpers.ts +159 -0
  107. package/src/plugin/connection-state-runtime-group.ts +51 -0
  108. package/src/plugin/connection-state.ts +527 -0
  109. package/src/plugin/diagnostics-handlers.ts +211 -0
  110. package/src/plugin/error-message.ts +15 -0
  111. package/src/plugin/file-ack-runtime.ts +284 -0
  112. package/src/plugin/file-inbound-abort.ts +112 -0
  113. package/src/plugin/file-inbound-chunk.ts +146 -0
  114. package/src/plugin/file-inbound-complete.ts +153 -0
  115. package/src/plugin/file-inbound-handlers.ts +19 -0
  116. package/src/plugin/file-inbound-init.ts +122 -0
  117. package/src/plugin/file-inbound-runtime.ts +51 -0
  118. package/src/plugin/file-inbound-state.ts +62 -0
  119. package/src/plugin/file-transfer-logs.ts +227 -0
  120. package/src/plugin/file-transfer-orchestrator-chunk.ts +135 -0
  121. package/src/plugin/file-transfer-orchestrator.ts +304 -0
  122. package/src/plugin/file-transfer-runtime-group.ts +102 -0
  123. package/src/plugin/file-transfer-send.ts +89 -0
  124. package/src/plugin/file-transfer-setup.ts +206 -0
  125. package/src/plugin/gateway-event-context.ts +41 -0
  126. package/src/plugin/gateway-runtime.ts +14 -4
  127. package/src/plugin/inbound-acceptance.ts +107 -0
  128. package/src/plugin/inbound-handlers.ts +248 -0
  129. package/src/plugin/inbound-surface-handlers-group.ts +152 -0
  130. package/src/plugin/media-dedupe-runtime.ts +90 -0
  131. package/src/plugin/media-orchestrators-runtime-group.ts +316 -0
  132. package/src/plugin/message-ack-runtime.ts +284 -0
  133. package/src/plugin/message-send.ts +16 -6
  134. package/src/plugin/messaging.ts +98 -36
  135. package/src/plugin/outbound.ts +50 -8
  136. package/src/plugin/outbox-ack-logs.ts +136 -0
  137. package/src/plugin/outbox-ack-outcome.ts +128 -0
  138. package/src/plugin/outbox-drain-ack.ts +145 -0
  139. package/src/plugin/outbox-drain-failure.ts +84 -0
  140. package/src/plugin/outbox-drain-loop.ts +554 -0
  141. package/src/plugin/outbox-drain-post-push.ts +159 -0
  142. package/src/plugin/outbox-drain-runtime.ts +141 -0
  143. package/src/plugin/outbox-drain-schedule.ts +116 -0
  144. package/src/plugin/outbox-file-push-flow.ts +69 -0
  145. package/src/plugin/outbox-push-route-runtime-group.ts +81 -0
  146. package/src/plugin/outbox-push.ts +267 -0
  147. package/src/plugin/outbox-route.ts +181 -0
  148. package/src/plugin/outbox-text-push-flow.ts +90 -0
  149. package/src/plugin/runtime-diagnostics-assembler.ts +183 -0
  150. package/src/plugin/runtime-diagnostics-helpers.ts +302 -0
  151. package/src/plugin/runtime-diagnostics-payload-builders.ts +171 -0
  152. package/src/plugin/runtime-diagnostics-snapshot.ts +31 -0
  153. package/src/plugin/setup.ts +33 -6
  154. package/src/plugin/state-store.ts +249 -0
  155. package/src/plugin/state-transient-runtime-group.ts +105 -0
  156. package/src/plugin/status-runtime.ts +251 -0
  157. package/src/plugin/status.ts +33 -7
  158. package/src/plugin/target-runtime.ts +141 -0
  159. package/src/plugin/target-status-runtime-group.ts +130 -0
  160. package/src/plugin/transient-state-runtime.ts +82 -0
  161. package/src/runtime/outbound-ack-timeout.ts +5 -3
  162. package/src/runtime/outbound-flags.ts +24 -8
  163. package/src/runtime/status-snapshots.ts +36 -7
  164. package/src/runtime/status-worker.ts +34 -4
@@ -0,0 +1,72 @@
1
+ import type { BncrConnection } from '../core/types.ts';
2
+ import type { ChannelAccountWorkerHandle } from '../runtime/status-worker.ts';
3
+ import {
4
+ buildStatusWorkerActiveConnections,
5
+ buildStatusWorkerLastEventAt,
6
+ } from './bridge-surface-helpers.ts';
7
+
8
+ export function createBncrBridgeStatusWorkerFacade(runtime: {
9
+ workers: Map<string, ChannelAccountWorkerHandle>;
10
+ bridgeId: string;
11
+ isOnline: (accountId: string) => boolean;
12
+ hasRecentInboundReachability: (accountId: string) => boolean;
13
+ lastActivityByAccount: Map<string, number>;
14
+ lastInboundByAccount: Map<string, number>;
15
+ lastOutboundByAccount: Map<string, number>;
16
+ getActiveConnectionKey: (accountId: string) => string | null;
17
+ connectionsValues: () => Iterable<BncrConnection>;
18
+ buildStatusMeta: (accountId: string) => {
19
+ pending?: number;
20
+ pendingAdmissionsCount?: number;
21
+ pendingAdmissions?: unknown[];
22
+ deadLetter?: number;
23
+ lastSessionScope?: string | null;
24
+ lastSessionAt?: number | null;
25
+ lastSessionAgo?: string | null;
26
+ lastActivityAt?: number | null;
27
+ lastActivityAgo?: string | null;
28
+ lastInboundAt?: number | null;
29
+ lastInboundAgo?: string | null;
30
+ lastOutboundAt?: number | null;
31
+ lastOutboundAgo?: string | null;
32
+ diagnostics?: Record<string, unknown>;
33
+ };
34
+ logInfo: (scope: string | undefined, message: string, options?: { debugOnly?: boolean }) => void;
35
+ logInfoDedup: (
36
+ scope: string | undefined,
37
+ message: string,
38
+ options: { key: string; sig: string; debugOnly?: boolean; windowMs?: number },
39
+ ) => void;
40
+ }) {
41
+ return {
42
+ workers: runtime.workers,
43
+ bridgeId: runtime.bridgeId,
44
+ hooks: {
45
+ isOnline: (accountId: string) => runtime.isOnline(accountId),
46
+ hasRecentInboundReachability: (accountId: string) =>
47
+ runtime.hasRecentInboundReachability(accountId),
48
+ getLastActivityAt: (accountId: string, previous: { lastEventAt?: number | null }) =>
49
+ buildStatusWorkerLastEventAt({
50
+ accountId,
51
+ previous,
52
+ lastActivityByAccount: runtime.lastActivityByAccount,
53
+ lastInboundByAccount: runtime.lastInboundByAccount,
54
+ lastOutboundByAccount: runtime.lastOutboundByAccount,
55
+ }),
56
+ getActiveConnectionKey: (accountId: string) => runtime.getActiveConnectionKey(accountId),
57
+ getActiveConnections: (accountId: string) =>
58
+ buildStatusWorkerActiveConnections({
59
+ accountId,
60
+ connections: runtime.connectionsValues(),
61
+ }),
62
+ buildStatusMeta: (accountId: string) => runtime.buildStatusMeta(accountId),
63
+ logInfo: (scope: string | undefined, message: string, options?: { debugOnly?: boolean }) =>
64
+ runtime.logInfo(scope, message, options),
65
+ logInfoDedup: (
66
+ scope: string | undefined,
67
+ message: string,
68
+ options: { key: string; sig: string; debugOnly?: boolean; windowMs?: number },
69
+ ) => runtime.logInfoDedup(scope, message, options),
70
+ },
71
+ };
72
+ }
@@ -0,0 +1,137 @@
1
+ import { asSanitizedString } from '../core/value-sanitize.ts';
2
+ import type { BncrChannelConfigRoot } from './channel-runtime-types.ts';
3
+
4
+ export function createBridgeSupportRuntime(args: {
5
+ isStopped: () => boolean;
6
+ hasSaveTimer: () => boolean;
7
+ setSaveTimer: (timer: NodeJS.Timeout | null) => void;
8
+ flushState: () => Promise<void>;
9
+ normalizeAccountId: (accountId: string) => string;
10
+ getCounterValue: (map: Map<string, number>, accountId: string) => number;
11
+ getRuntimeConfig: () => unknown;
12
+ channelId: string;
13
+ readCurrentCanonicalAgentId: () => string | null;
14
+ resolveAgentRoute: (args: {
15
+ cfg: BncrChannelConfigRoot;
16
+ channel: string;
17
+ accountId: string;
18
+ peer?: unknown;
19
+ }) => { agentId?: unknown } | null;
20
+ readCachedCanonicalAgentId: () => string | null;
21
+ writeCachedCanonicalAgentId: (agentId: string) => void;
22
+ logInfo: (scope: string, message: string, options?: { debugOnly?: boolean }) => void;
23
+ logWarn: (scope: string, message: string, options?: { debugOnly?: boolean }) => void;
24
+ readDebugVerbose: () => boolean;
25
+ writeDebugVerbose: (value: boolean) => void;
26
+ }) {
27
+ const scheduleSave = () => {
28
+ if (args.isStopped()) return;
29
+ if (args.hasSaveTimer()) return;
30
+ args.setSaveTimer(
31
+ setTimeout(() => {
32
+ args.setSaveTimer(null);
33
+ if (args.isStopped()) return;
34
+ void args.flushState();
35
+ }, 300),
36
+ );
37
+ };
38
+
39
+ const incrementCounter = (map: Map<string, number>, accountId: string) => {
40
+ const acc = args.normalizeAccountId(accountId);
41
+ map.set(acc, args.getCounterValue(map, acc) + 1);
42
+ };
43
+
44
+ const getCounter = (map: Map<string, number>, accountId: string): number => {
45
+ return args.getCounterValue(map, args.normalizeAccountId(accountId));
46
+ };
47
+
48
+ const refreshDebugFlagFromConfig = async (options?: { forceLog?: boolean }) => {
49
+ try {
50
+ const cfg = args.getRuntimeConfig() as {
51
+ channels?: Record<string, { debug?: { verbose?: unknown } }>;
52
+ };
53
+ const raw = cfg?.channels?.[args.channelId]?.debug?.verbose;
54
+ const next = typeof raw === 'boolean' ? raw : false;
55
+ const changed = next !== args.readDebugVerbose();
56
+ args.writeDebugVerbose(next);
57
+ if (changed || options?.forceLog) {
58
+ args.logInfo('debug', `verbose=${next}`, { debugOnly: true });
59
+ }
60
+ } catch {
61
+ // ignore config read errors
62
+ }
63
+ };
64
+
65
+ const syncDebugFlag = async () => {
66
+ await refreshDebugFlagFromConfig();
67
+ };
68
+
69
+ const tryResolveBindingAgentId = (resolveArgs: {
70
+ cfg: BncrChannelConfigRoot;
71
+ accountId: string;
72
+ peer?: unknown;
73
+ channelId?: string;
74
+ }): string | null => {
75
+ try {
76
+ const resolved = args.resolveAgentRoute({
77
+ cfg: resolveArgs.cfg,
78
+ channel: resolveArgs.channelId || args.channelId,
79
+ accountId: args.normalizeAccountId(resolveArgs.accountId),
80
+ peer: resolveArgs.peer,
81
+ });
82
+ const agentId = asSanitizedString(resolved?.agentId || '').trim();
83
+ return agentId || null;
84
+ } catch {
85
+ return null;
86
+ }
87
+ };
88
+
89
+ const initializeCanonicalAgentId = (cfg: BncrChannelConfigRoot) => {
90
+ if (args.readCachedCanonicalAgentId()) return;
91
+ const agentId = tryResolveBindingAgentId({
92
+ cfg,
93
+ accountId: 'Primary',
94
+ channelId: args.channelId,
95
+ peer: { kind: 'direct', id: 'bootstrap' },
96
+ });
97
+ if (!agentId) return;
98
+ args.writeCachedCanonicalAgentId(agentId);
99
+ };
100
+
101
+ const ensureCanonicalAgentId = (resolveArgs: {
102
+ cfg: BncrChannelConfigRoot;
103
+ accountId: string;
104
+ peer?: unknown;
105
+ channelId?: string;
106
+ }) => {
107
+ const cached = args.readCachedCanonicalAgentId();
108
+ if (cached) return cached;
109
+
110
+ const agentId = tryResolveBindingAgentId(resolveArgs);
111
+ if (agentId) {
112
+ args.writeCachedCanonicalAgentId(agentId);
113
+ return agentId;
114
+ }
115
+
116
+ args.writeCachedCanonicalAgentId('main');
117
+ args.logWarn(
118
+ 'target',
119
+ 'binding agent unresolved; fallback to main for current process lifetime',
120
+ {
121
+ debugOnly: true,
122
+ },
123
+ );
124
+ return 'main';
125
+ };
126
+
127
+ return {
128
+ scheduleSave,
129
+ incrementCounter,
130
+ getCounter,
131
+ refreshDebugFlagFromConfig,
132
+ syncDebugFlag,
133
+ tryResolveBindingAgentId,
134
+ initializeCanonicalAgentId,
135
+ ensureCanonicalAgentId,
136
+ };
137
+ }
@@ -0,0 +1,242 @@
1
+ import type { GatewayRequestHandlerOptions } from 'openclaw/plugin-sdk/core';
2
+ import type { BncrExtendedDiagnostics } from '../core/extended-diagnostics.ts';
3
+ import type {
4
+ BncrAccountRuntimeSnapshot,
5
+ buildIntegratedDiagnostics as buildIntegratedDiagnosticsFromRuntime,
6
+ } from '../core/status.ts';
7
+ import type {
8
+ BncrDeadLetterDiagnosticsSummary,
9
+ BncrDownlinkHealthSummary,
10
+ FileSendTransferState,
11
+ OutboxEntry,
12
+ } from '../core/types.ts';
13
+ import type { BncrRuntimeFlags } from '../runtime/outbound-flags.ts';
14
+ import {
15
+ createBncrBridgeDiagnosticsHandlersComponent,
16
+ createBncrConnectionHandlersComponent,
17
+ } from './channel-components.ts';
18
+ import type { ConnectionQueueCounters } from './connection-handlers.ts';
19
+
20
+ type DiagnosticsRuntimeStatusInput = Parameters<typeof buildIntegratedDiagnosticsFromRuntime>[0] & {
21
+ running: boolean | undefined;
22
+ channelRoot: string;
23
+ };
24
+
25
+ type DiagnosticsComponentRuntime = Parameters<
26
+ typeof createBncrBridgeDiagnosticsHandlersComponent
27
+ >[0];
28
+ type ConnectionComponentRuntime = Parameters<typeof createBncrConnectionHandlersComponent>[0];
29
+ type DiagnosticsExtendedArgs = Parameters<
30
+ DiagnosticsComponentRuntime['buildExtendedDiagnostics']
31
+ >[1];
32
+
33
+ export function createBncrBridgeSurfaceHandlersGroup(runtime: {
34
+ bridgeId: string;
35
+ gatewayPid: number;
36
+ pushEvent: string;
37
+ bridgeVersion: number;
38
+ getApi: DiagnosticsComponentRuntime['getApi'];
39
+ channelId: string;
40
+ asString: (value: unknown, fallback?: string) => string;
41
+ now: () => number;
42
+ finiteNonNegativeNumberOrNull: (value: unknown) => number | null;
43
+ syncDebugFlag: () => Promise<void>;
44
+ logInfo: (scope: string, message: string, options?: { debugOnly?: boolean }) => void;
45
+ logWarn: (scope: string, message: string, options?: { debugOnly?: boolean }) => void;
46
+ normalizeAccountId: (value: string) => string;
47
+ pluginRoot: string;
48
+ buildAccountQueueCounters: (accountId: string) => ConnectionQueueCounters;
49
+ buildExtendedDiagnostics: (
50
+ accountId: string,
51
+ args?: DiagnosticsExtendedArgs,
52
+ ) => BncrExtendedDiagnostics;
53
+ buildRuntimeFlags: (accountId: string) => BncrRuntimeFlags;
54
+ buildRuntimeStatusInput: (
55
+ accountId: string,
56
+ overrides: {
57
+ running: boolean;
58
+ invalidOutboxSessionKeys?: number;
59
+ legacyAccountResidue?: number;
60
+ },
61
+ ) => DiagnosticsRuntimeStatusInput;
62
+ getAccountRuntimeSnapshot: (
63
+ accountId: string,
64
+ runtimeStatusInput: DiagnosticsRuntimeStatusInput,
65
+ ) => BncrAccountRuntimeSnapshot;
66
+ buildIntegratedDiagnostics: (
67
+ accountId: string,
68
+ runtimeStatusInput: DiagnosticsRuntimeStatusInput,
69
+ ) => ReturnType<typeof buildIntegratedDiagnosticsFromRuntime>;
70
+ buildDownlinkHealth: (accountId: string) => BncrDownlinkHealthSummary;
71
+ isPrimaryConnection: (accountId: string, clientId?: string) => boolean;
72
+ acceptConnection: () => { leaseId: string; connectionEpoch: number; acceptedAt: number };
73
+ refreshLiveConnectionState: (args: {
74
+ accountId: string;
75
+ connId: string;
76
+ clientId?: string;
77
+ outboundReady: boolean;
78
+ preferredForOutbound: boolean;
79
+ inboundOnly: boolean;
80
+ context: GatewayRequestHandlerOptions['context'];
81
+ }) => void;
82
+ flushOnConnect: (accountId: string) => void;
83
+ flushOnActivity: (accountId: string) => void;
84
+ shouldIgnoreStaleEvent: (args: {
85
+ kind:
86
+ | 'inbound'
87
+ | 'activity'
88
+ | 'ack'
89
+ | 'file.init'
90
+ | 'file.chunk'
91
+ | 'file.complete'
92
+ | 'file.abort';
93
+ payload: { leaseId?: string; connectionEpoch?: number };
94
+ accountId: string;
95
+ connId: string;
96
+ clientId?: string;
97
+ }) => boolean;
98
+ incrementConnectEvents: (accountId: string) => void;
99
+ incrementActivityEvents: (accountId: string) => void;
100
+ incrementAckEvents: (accountId: string) => void;
101
+ markLastActivityAt: () => void;
102
+ markLastAckAt: () => void;
103
+ messageAckWaiterCount: () => number;
104
+ fileAckWaiterCount: () => number;
105
+ prepareAckHandling: (args: {
106
+ params: GatewayRequestHandlerOptions['params'];
107
+ respond: GatewayRequestHandlerOptions['respond'];
108
+ client: GatewayRequestHandlerOptions['client'];
109
+ context: GatewayRequestHandlerOptions['context'];
110
+ }) => ReturnType<ConnectionComponentRuntime['prepareAckHandling']>;
111
+ handleAckOutcome: (
112
+ args: {
113
+ params: GatewayRequestHandlerOptions['params'];
114
+ respond: GatewayRequestHandlerOptions['respond'];
115
+ } & NonNullable<ReturnType<ConnectionComponentRuntime['prepareAckHandling']>>,
116
+ ) => void;
117
+ fileSendTransfers: Map<string, FileSendTransferState>;
118
+ hasFileAckWaiter: (key: string) => boolean;
119
+ fileAckKey: (transferId: string, stage: string, chunkIndex?: number) => string;
120
+ observeLease: (
121
+ kind:
122
+ | 'connect'
123
+ | 'inbound'
124
+ | 'activity'
125
+ | 'ack'
126
+ | 'file.init'
127
+ | 'file.chunk'
128
+ | 'file.complete'
129
+ | 'file.abort',
130
+ payload: { leaseId?: string; connectionEpoch?: number },
131
+ ) => { stale: boolean };
132
+ tryAdoptTransferOwner: (args: {
133
+ accountId: string;
134
+ transfer: FileSendTransferState | undefined;
135
+ connId: string;
136
+ clientId?: string;
137
+ }) => boolean;
138
+ refreshAcceptedFileTransferLiveState: (args: {
139
+ accountId: string;
140
+ connId: string;
141
+ clientId?: string;
142
+ context: GatewayRequestHandlerOptions['context'];
143
+ }) => void;
144
+ resolveFileAck: (args: {
145
+ transferId: string;
146
+ stage: string;
147
+ chunkIndex?: number;
148
+ payload: {
149
+ ok: boolean;
150
+ transferId: string;
151
+ stage: string;
152
+ path: string;
153
+ errorCode: string;
154
+ errorMessage: string;
155
+ };
156
+ ok: boolean;
157
+ }) => void;
158
+ countInvalidOutboxSessionKeys: (accountId: string) => number;
159
+ countLegacyAccountResidue: (accountId: string) => number;
160
+ activeConnectionCount: (accountId: string) => number;
161
+ getMessageAckWaiterCount: () => number;
162
+ getFileAckWaiterCount: () => number;
163
+ filterDeadLetterEntries: (args: {
164
+ accountId: string;
165
+ reason: string | null;
166
+ olderThan: number | null;
167
+ }) => OutboxEntry[];
168
+ listDeadLetterEntries: () => OutboxEntry[];
169
+ buildDeadLetterDiagnostics: (accountId: string) => BncrDeadLetterDiagnosticsSummary;
170
+ replaceDeadLetterEntries: (nextEntries: OutboxEntry[]) => void;
171
+ scheduleSave: () => void;
172
+ logDeadLetterSummary: (accountId: string, args: { force: boolean; source: string }) => void;
173
+ }) {
174
+ const connectionHandlers = createBncrConnectionHandlersComponent({
175
+ bridgeId: runtime.bridgeId,
176
+ gatewayPid: runtime.gatewayPid,
177
+ pushEvent: runtime.pushEvent,
178
+ bridgeVersion: runtime.bridgeVersion,
179
+ asString: runtime.asString,
180
+ now: runtime.now,
181
+ finiteNonNegativeNumberOrNull: runtime.finiteNonNegativeNumberOrNull,
182
+ syncDebugFlag: runtime.syncDebugFlag,
183
+ logInfo: runtime.logInfo,
184
+ logWarn: runtime.logWarn,
185
+ normalizeAccountId: runtime.normalizeAccountId,
186
+ buildAccountQueueCounters: runtime.buildAccountQueueCounters,
187
+ buildExtendedDiagnostics: runtime.buildExtendedDiagnostics,
188
+ buildRuntimeFlags: runtime.buildRuntimeFlags,
189
+ isPrimaryConnection: runtime.isPrimaryConnection,
190
+ acceptConnection: runtime.acceptConnection,
191
+ refreshLiveConnectionState: runtime.refreshLiveConnectionState,
192
+ flushOnConnect: runtime.flushOnConnect,
193
+ flushOnActivity: runtime.flushOnActivity,
194
+ shouldIgnoreStaleEvent: runtime.shouldIgnoreStaleEvent,
195
+ incrementConnectEvents: runtime.incrementConnectEvents,
196
+ incrementActivityEvents: runtime.incrementActivityEvents,
197
+ incrementAckEvents: runtime.incrementAckEvents,
198
+ markLastActivityAt: runtime.markLastActivityAt,
199
+ markLastAckAt: runtime.markLastAckAt,
200
+ messageAckWaiterCount: runtime.messageAckWaiterCount,
201
+ fileAckWaiterCount: runtime.fileAckWaiterCount,
202
+ prepareAckHandling: runtime.prepareAckHandling,
203
+ handleAckOutcome: runtime.handleAckOutcome,
204
+ fileSendTransfers: runtime.fileSendTransfers,
205
+ hasFileAckWaiter: runtime.hasFileAckWaiter,
206
+ fileAckKey: runtime.fileAckKey,
207
+ observeLease: runtime.observeLease,
208
+ tryAdoptTransferOwner: runtime.tryAdoptTransferOwner,
209
+ refreshAcceptedFileTransferLiveState: runtime.refreshAcceptedFileTransferLiveState,
210
+ resolveFileAck: runtime.resolveFileAck,
211
+ });
212
+
213
+ const diagnosticsHandlers = createBncrBridgeDiagnosticsHandlersComponent({
214
+ getApi: runtime.getApi,
215
+ channelId: runtime.channelId,
216
+ asString: runtime.asString,
217
+ now: runtime.now,
218
+ countInvalidOutboxSessionKeys: runtime.countInvalidOutboxSessionKeys,
219
+ countLegacyAccountResidue: runtime.countLegacyAccountResidue,
220
+ pluginRoot: runtime.pluginRoot,
221
+ buildRuntimeStatusInput: runtime.buildRuntimeStatusInput,
222
+ getAccountRuntimeSnapshot: runtime.getAccountRuntimeSnapshot,
223
+ buildIntegratedDiagnostics: runtime.buildIntegratedDiagnostics,
224
+ buildExtendedDiagnostics: runtime.buildExtendedDiagnostics,
225
+ buildDownlinkHealth: runtime.buildDownlinkHealth,
226
+ buildRuntimeFlags: runtime.buildRuntimeFlags,
227
+ activeConnectionCount: runtime.activeConnectionCount,
228
+ getMessageAckWaiterCount: runtime.getMessageAckWaiterCount,
229
+ getFileAckWaiterCount: runtime.getFileAckWaiterCount,
230
+ filterDeadLetterEntries: runtime.filterDeadLetterEntries,
231
+ listDeadLetterEntries: runtime.listDeadLetterEntries,
232
+ buildDeadLetterDiagnostics: runtime.buildDeadLetterDiagnostics,
233
+ replaceDeadLetterEntries: runtime.replaceDeadLetterEntries,
234
+ scheduleSave: runtime.scheduleSave,
235
+ logDeadLetterSummary: runtime.logDeadLetterSummary,
236
+ });
237
+
238
+ return {
239
+ connectionHandlers,
240
+ diagnosticsHandlers,
241
+ };
242
+ }
@@ -0,0 +1,28 @@
1
+ // Aggregated bridge runtime helper entrypoint.
2
+ //
3
+ // The helpers are grouped by concern so snapshot shaping, delivery-facing
4
+ // runtime adapters, and support runtime ownership stay readable without
5
+ // changing import sites.
6
+
7
+ export {
8
+ buildBridgeDrainTriggers,
9
+ buildBridgeLifecycleMarkers,
10
+ buildBridgeRuntimeStatusInput,
11
+ buildBridgeStatusProjectionRuntime,
12
+ buildChannelSendTargetRuntime,
13
+ buildFlushBestEffortError,
14
+ buildFlushOnActivityArgs,
15
+ buildFlushOnConnectArgs,
16
+ buildInboundSurfaceActivityRuntime,
17
+ buildInboundSurfaceConnectionRuntime,
18
+ } from './bridge-runtime-helpers.ts';
19
+
20
+ export {
21
+ buildConnectionRuntimeSnapshot,
22
+ buildOutboundRuntimeSnapshot,
23
+ buildRegisterRuntimeSnapshot,
24
+ buildStatusWorkerActiveConnections,
25
+ buildStatusWorkerLastEventAt,
26
+ } from './bridge-runtime-snapshots.ts';
27
+
28
+ export { createBridgeSupportRuntime } from './bridge-support-runtime.ts';
@@ -1,7 +1,5 @@
1
- import type { ChatType } from 'openclaw/plugin-sdk';
2
-
3
1
  export const BNCR_CHANNEL_CAPABILITIES = {
4
- chatTypes: ['direct'] as ChatType[],
2
+ chatTypes: ['direct'] as ('direct' | 'group' | 'thread')[],
5
3
  media: true,
6
4
  reply: true,
7
5
  nativeCommands: true,