@xmoxmo/bncr 0.3.6 → 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.
- package/README.md +5 -0
- package/dist/index.js +28 -5
- package/index.ts +55 -721
- package/package.json +8 -4
- package/scripts/check-pack.mjs +93 -18
- package/scripts/check-register-drift.mjs +35 -13
- package/scripts/selfcheck.mjs +80 -11
- package/src/bootstrap/channel-plugin-runtime.ts +81 -0
- package/src/bootstrap/cli.ts +97 -0
- package/src/bootstrap/register-runtime-gateway.ts +129 -0
- package/src/bootstrap/register-runtime-helpers.ts +140 -0
- package/src/bootstrap/register-runtime-singleton.ts +137 -0
- package/src/bootstrap/register-runtime.ts +201 -0
- package/src/bootstrap/runtime-discovery.ts +187 -0
- package/src/bootstrap/runtime-loader.ts +54 -0
- package/src/channel.ts +1590 -4967
- package/src/core/accounts.ts +23 -4
- package/src/core/dead-letter-diagnostics.ts +37 -5
- package/src/core/diagnostics.ts +31 -15
- package/src/core/downlink-health.ts +3 -11
- package/src/core/extended-diagnostics.ts +78 -36
- package/src/core/file-transfer-payloads.ts +1 -1
- package/src/core/logging.ts +1 -0
- package/src/core/outbox-enqueue.ts +13 -2
- package/src/core/outbox-entry-builders.ts +2 -0
- package/src/core/outbox-summary.ts +75 -3
- package/src/core/permissions.ts +15 -2
- package/src/core/persisted-outbox-entry.ts +21 -6
- package/src/core/policy.ts +45 -4
- package/src/core/probe.ts +3 -15
- package/src/core/register-trace.ts +3 -3
- package/src/core/status.ts +43 -4
- package/src/core/targets.ts +216 -205
- package/src/core/types.ts +221 -0
- package/src/core/value-sanitize.ts +29 -0
- package/src/messaging/inbound/commands.ts +147 -172
- package/src/messaging/inbound/context-facts.ts +4 -2
- package/src/messaging/inbound/contracts.ts +70 -0
- package/src/messaging/inbound/dispatch-prep.ts +303 -0
- package/src/messaging/inbound/dispatch.ts +49 -462
- package/src/messaging/inbound/gate.ts +18 -5
- package/src/messaging/inbound/last-route.ts +10 -4
- package/src/messaging/inbound/media-url-download.ts +109 -0
- package/src/messaging/inbound/native-command-runtime.ts +225 -0
- package/src/messaging/inbound/parse.ts +2 -1
- package/src/messaging/inbound/remote-media.ts +49 -0
- package/src/messaging/inbound/reply-config.ts +16 -4
- package/src/messaging/inbound/reply-dispatch.ts +162 -0
- package/src/messaging/inbound/runtime-compat.ts +31 -10
- package/src/messaging/inbound/session-label.ts +15 -7
- package/src/messaging/inbound/turn-context.ts +131 -0
- package/src/messaging/outbound/actions.ts +24 -10
- package/src/messaging/outbound/diagnostics-debug-builders.ts +365 -0
- package/src/messaging/outbound/diagnostics.ts +31 -355
- package/src/messaging/outbound/durable-message-adapter.ts +20 -16
- package/src/messaging/outbound/durable-queue-adapter.ts +20 -7
- package/src/messaging/outbound/media.ts +24 -13
- package/src/messaging/outbound/reply-enqueue-media.ts +181 -0
- package/src/messaging/outbound/reply-enqueue.ts +46 -155
- package/src/messaging/outbound/send-params.ts +3 -0
- package/src/messaging/outbound/send.ts +19 -10
- package/src/messaging/outbound/session-route.ts +18 -3
- package/src/openclaw/channel-runtime-contracts.ts +76 -0
- package/src/openclaw/config-runtime.ts +13 -7
- package/src/openclaw/inbound-session-runtime.ts +7 -3
- package/src/openclaw/ingress-runtime.ts +17 -27
- package/src/openclaw/reply-runtime.ts +54 -59
- package/src/openclaw/routing-runtime.ts +35 -18
- package/src/openclaw/runtime-surface.ts +156 -12
- package/src/openclaw/sdk-helpers.ts +8 -1
- package/src/openclaw/session-route-runtime.ts +12 -12
- package/src/plugin/ack-outbox-runtime-group.ts +264 -0
- package/src/plugin/bridge-ack-facade.ts +137 -0
- package/src/plugin/bridge-connection-facade.ts +111 -0
- package/src/plugin/bridge-diagnostics-facade.ts +23 -0
- package/src/plugin/bridge-drain-facade.ts +98 -0
- package/src/plugin/bridge-extended-diagnostics-facade.ts +149 -0
- package/src/plugin/bridge-file-transfer-push-facade.ts +140 -0
- package/src/plugin/bridge-lifecycle.ts +156 -0
- package/src/plugin/bridge-media-facade.ts +241 -0
- package/src/plugin/bridge-outbox-facade.ts +182 -0
- package/src/plugin/bridge-runtime-helpers.ts +266 -0
- package/src/plugin/bridge-runtime-snapshots.ts +104 -0
- package/src/plugin/bridge-runtime-surface-facade.ts +8 -0
- package/src/plugin/bridge-status-facade.ts +76 -0
- package/src/plugin/bridge-status-worker-facade.ts +72 -0
- package/src/plugin/bridge-support-runtime.ts +137 -0
- package/src/plugin/bridge-surface-handlers-group.ts +242 -0
- package/src/plugin/bridge-surface-helpers.ts +28 -0
- package/src/plugin/capabilities.ts +1 -3
- package/src/plugin/channel-components.ts +289 -0
- package/src/plugin/channel-inbound-helpers.ts +149 -0
- package/src/plugin/channel-plugin-bridge-group.ts +129 -0
- package/src/plugin/channel-plugin-surface-group.ts +202 -0
- package/src/plugin/channel-runtime-builders-delivery.ts +513 -0
- package/src/plugin/channel-runtime-builders-status.ts +331 -0
- package/src/plugin/channel-runtime-builders.ts +25 -0
- package/src/plugin/channel-runtime-constants.ts +40 -0
- package/src/plugin/channel-runtime-types.ts +146 -0
- package/src/plugin/channel-send-runtime-group.ts +37 -0
- package/src/plugin/channel-send.ts +226 -0
- package/src/plugin/channel-utils.ts +102 -0
- package/src/plugin/config.ts +24 -3
- package/src/plugin/connection-handlers-helpers.ts +254 -0
- package/src/plugin/connection-handlers.ts +440 -0
- package/src/plugin/connection-state-helpers.ts +159 -0
- package/src/plugin/connection-state-runtime-group.ts +51 -0
- package/src/plugin/connection-state.ts +527 -0
- package/src/plugin/diagnostics-handlers.ts +211 -0
- package/src/plugin/error-message.ts +15 -0
- package/src/plugin/file-ack-runtime.ts +284 -0
- package/src/plugin/file-inbound-abort.ts +112 -0
- package/src/plugin/file-inbound-chunk.ts +146 -0
- package/src/plugin/file-inbound-complete.ts +153 -0
- package/src/plugin/file-inbound-handlers.ts +19 -0
- package/src/plugin/file-inbound-init.ts +122 -0
- package/src/plugin/file-inbound-runtime.ts +51 -0
- package/src/plugin/file-inbound-state.ts +62 -0
- package/src/plugin/file-transfer-logs.ts +227 -0
- package/src/plugin/file-transfer-orchestrator-chunk.ts +135 -0
- package/src/plugin/file-transfer-orchestrator.ts +304 -0
- package/src/plugin/file-transfer-runtime-group.ts +102 -0
- package/src/plugin/file-transfer-send.ts +89 -0
- package/src/plugin/file-transfer-setup.ts +206 -0
- package/src/plugin/gateway-event-context.ts +41 -0
- package/src/plugin/gateway-runtime.ts +14 -4
- package/src/plugin/inbound-acceptance.ts +107 -0
- package/src/plugin/inbound-handlers.ts +248 -0
- package/src/plugin/inbound-surface-handlers-group.ts +152 -0
- package/src/plugin/media-dedupe-runtime.ts +90 -0
- package/src/plugin/media-orchestrators-runtime-group.ts +316 -0
- package/src/plugin/message-ack-runtime.ts +284 -0
- package/src/plugin/message-send.ts +16 -6
- package/src/plugin/messaging.ts +98 -36
- package/src/plugin/outbound.ts +50 -8
- package/src/plugin/outbox-ack-logs.ts +136 -0
- package/src/plugin/outbox-ack-outcome.ts +128 -0
- package/src/plugin/outbox-drain-ack.ts +145 -0
- package/src/plugin/outbox-drain-failure.ts +84 -0
- package/src/plugin/outbox-drain-loop.ts +554 -0
- package/src/plugin/outbox-drain-post-push.ts +159 -0
- package/src/plugin/outbox-drain-runtime.ts +141 -0
- package/src/plugin/outbox-drain-schedule.ts +116 -0
- package/src/plugin/outbox-file-push-flow.ts +69 -0
- package/src/plugin/outbox-push-route-runtime-group.ts +81 -0
- package/src/plugin/outbox-push.ts +267 -0
- package/src/plugin/outbox-route.ts +181 -0
- package/src/plugin/outbox-text-push-flow.ts +90 -0
- package/src/plugin/runtime-diagnostics-assembler.ts +183 -0
- package/src/plugin/runtime-diagnostics-helpers.ts +302 -0
- package/src/plugin/runtime-diagnostics-payload-builders.ts +171 -0
- package/src/plugin/runtime-diagnostics-snapshot.ts +31 -0
- package/src/plugin/setup.ts +33 -6
- package/src/plugin/state-store.ts +249 -0
- package/src/plugin/state-transient-runtime-group.ts +105 -0
- package/src/plugin/status-runtime.ts +251 -0
- package/src/plugin/status.ts +33 -7
- package/src/plugin/target-runtime.ts +141 -0
- package/src/plugin/target-status-runtime-group.ts +130 -0
- package/src/plugin/transient-state-runtime.ts +82 -0
- package/src/runtime/outbound-ack-timeout.ts +5 -3
- package/src/runtime/outbound-flags.ts +24 -8
- package/src/runtime/status-snapshots.ts +36 -7
- package/src/runtime/status-worker.ts +34 -4
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { BncrRoute, OutboxEntry } from '../core/types.ts';
|
|
2
|
+
import {
|
|
3
|
+
buildOutboxAckDebugInfo,
|
|
4
|
+
buildOutboxScheduleDebugInfo,
|
|
5
|
+
} from '../messaging/outbound/diagnostics.ts';
|
|
6
|
+
import { computeOutboxRetryWait } from '../messaging/outbound/queue-selectors.ts';
|
|
7
|
+
import {
|
|
8
|
+
OUTBOUND_SCHEDULE_SOURCE,
|
|
9
|
+
type OutboundScheduleSource,
|
|
10
|
+
} from '../messaging/outbound/reasons.ts';
|
|
11
|
+
import type { RetryRerouteDecision } from '../messaging/outbound/retry-policy.ts';
|
|
12
|
+
import { applyBncrRetryRerouteDecisionToEntry } from '../runtime/outbox-transitions.ts';
|
|
13
|
+
|
|
14
|
+
export type BncrOutboxDrainAckRuntime = {
|
|
15
|
+
bridgeId: string;
|
|
16
|
+
pushEvent: string;
|
|
17
|
+
now: () => number;
|
|
18
|
+
defaultAckTimeoutMs: number;
|
|
19
|
+
adaptiveAckTimeoutEnabled: boolean;
|
|
20
|
+
outboxSize: () => number;
|
|
21
|
+
formatDisplayScope: (route: BncrRoute) => string;
|
|
22
|
+
isFileTransferEntry: (entry: OutboxEntry) => boolean;
|
|
23
|
+
setOutboxEntry: (messageId: string, entry: OutboxEntry) => void;
|
|
24
|
+
scheduleSave: () => void;
|
|
25
|
+
moveToDeadLetter: (entry: OutboxEntry, reason: string) => void;
|
|
26
|
+
recordAckTimeoutTelemetry: (accountId: string) => void;
|
|
27
|
+
logInfo: (scope: string, message: string, options?: { debugOnly?: boolean }) => void;
|
|
28
|
+
logOutboxAckReroute: (args: {
|
|
29
|
+
accountId: string;
|
|
30
|
+
entry: OutboxEntry;
|
|
31
|
+
requireAck: boolean;
|
|
32
|
+
currentConnId: string;
|
|
33
|
+
availableConnIds: string[];
|
|
34
|
+
decision: Extract<RetryRerouteDecision, { kind: 'retry' }>;
|
|
35
|
+
localNextDelay: number | null;
|
|
36
|
+
ackTimeoutMs?: number | null;
|
|
37
|
+
}) => void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export function createBncrOutboxDrainAck(runtime: BncrOutboxDrainAckRuntime) {
|
|
41
|
+
const logAckWaitStart = (args: {
|
|
42
|
+
entry: OutboxEntry;
|
|
43
|
+
requireAck: boolean;
|
|
44
|
+
ackTimeoutMs?: number | null;
|
|
45
|
+
onlineNow: boolean;
|
|
46
|
+
recentInboundReachable: boolean;
|
|
47
|
+
}) => {
|
|
48
|
+
runtime.logInfo(
|
|
49
|
+
'outbox',
|
|
50
|
+
`ack wait-start ${JSON.stringify(
|
|
51
|
+
buildOutboxAckDebugInfo({
|
|
52
|
+
messageId: args.entry.messageId,
|
|
53
|
+
accountId: args.entry.accountId,
|
|
54
|
+
sessionKey: args.entry.sessionKey,
|
|
55
|
+
to: runtime.formatDisplayScope(args.entry.route),
|
|
56
|
+
kind: runtime.isFileTransferEntry(args.entry) ? 'file-transfer' : undefined,
|
|
57
|
+
requireAck: args.requireAck,
|
|
58
|
+
ackResult: 'timeout',
|
|
59
|
+
ackStage: 'message',
|
|
60
|
+
ackOutcome: 'waiting',
|
|
61
|
+
ackTimeoutMs: args.ackTimeoutMs || runtime.defaultAckTimeoutMs,
|
|
62
|
+
adaptiveAckTimeoutEnabled: runtime.adaptiveAckTimeoutEnabled,
|
|
63
|
+
onlineNow: args.onlineNow,
|
|
64
|
+
recentInboundReachable: args.recentInboundReachable,
|
|
65
|
+
connIds: args.entry.lastPushConnId ? [args.entry.lastPushConnId] : [],
|
|
66
|
+
ownerConnId: args.entry.lastPushConnId,
|
|
67
|
+
ownerClientId: args.entry.lastPushClientId,
|
|
68
|
+
event: runtime.pushEvent,
|
|
69
|
+
}),
|
|
70
|
+
)}`,
|
|
71
|
+
{ debugOnly: true },
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const handleAckTimeoutReroute = (args: {
|
|
76
|
+
accountId: string;
|
|
77
|
+
entry: OutboxEntry;
|
|
78
|
+
requireAck: boolean;
|
|
79
|
+
currentConnId: string;
|
|
80
|
+
availableConnIds: string[];
|
|
81
|
+
decision:
|
|
82
|
+
| { kind: 'dead-letter'; terminalReason: string; [key: string]: unknown }
|
|
83
|
+
| Extract<RetryRerouteDecision, { kind: 'retry' }>;
|
|
84
|
+
localNextDelay: number | null;
|
|
85
|
+
ackTimeoutMs?: number | null;
|
|
86
|
+
updateMinOutboxDelay: (current: number | null, next: number | null) => number | null;
|
|
87
|
+
}) => {
|
|
88
|
+
if (args.decision.kind === 'dead-letter') {
|
|
89
|
+
runtime.logInfo(
|
|
90
|
+
'outbox ack fatal',
|
|
91
|
+
`mid=${args.entry.messageId}|q=${runtime.outboxSize()}|err=${args.decision.terminalReason}`,
|
|
92
|
+
);
|
|
93
|
+
runtime.moveToDeadLetter(args.entry, args.decision.terminalReason);
|
|
94
|
+
return { kind: 'dead-letter' as const, localNextDelay: args.localNextDelay };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const nextEntry = applyBncrRetryRerouteDecisionToEntry(args.entry, args.decision);
|
|
98
|
+
runtime.setOutboxEntry(args.entry.messageId, nextEntry);
|
|
99
|
+
runtime.scheduleSave();
|
|
100
|
+
if (args.requireAck) runtime.recordAckTimeoutTelemetry(args.accountId);
|
|
101
|
+
const wait = computeOutboxRetryWait(args.decision.nextAttemptAt, runtime.now());
|
|
102
|
+
const localNextDelay = args.updateMinOutboxDelay(args.localNextDelay, wait);
|
|
103
|
+
runtime.logOutboxAckReroute({
|
|
104
|
+
accountId: args.accountId,
|
|
105
|
+
entry: nextEntry,
|
|
106
|
+
requireAck: args.requireAck,
|
|
107
|
+
currentConnId: args.currentConnId,
|
|
108
|
+
availableConnIds: args.availableConnIds,
|
|
109
|
+
decision: args.decision,
|
|
110
|
+
localNextDelay,
|
|
111
|
+
ackTimeoutMs: args.ackTimeoutMs,
|
|
112
|
+
});
|
|
113
|
+
return { kind: 'retry' as const, nextEntry, wait, localNextDelay };
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const logSchedule = (args: {
|
|
117
|
+
accountId: string;
|
|
118
|
+
messageId: string;
|
|
119
|
+
wait: number;
|
|
120
|
+
localNextDelay: number | null;
|
|
121
|
+
source: OutboundScheduleSource;
|
|
122
|
+
}) => {
|
|
123
|
+
runtime.logInfo(
|
|
124
|
+
'outbox',
|
|
125
|
+
`schedule ${JSON.stringify(
|
|
126
|
+
buildOutboxScheduleDebugInfo({
|
|
127
|
+
bridgeId: runtime.bridgeId,
|
|
128
|
+
accountId: args.accountId,
|
|
129
|
+
messageId: args.messageId,
|
|
130
|
+
source: args.source,
|
|
131
|
+
wait: args.wait,
|
|
132
|
+
localNextDelay: args.localNextDelay,
|
|
133
|
+
}),
|
|
134
|
+
)}`,
|
|
135
|
+
{ debugOnly: true },
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
logAckWaitStart,
|
|
141
|
+
handleAckTimeoutReroute,
|
|
142
|
+
logSchedule,
|
|
143
|
+
scheduleSource: OUTBOUND_SCHEDULE_SOURCE,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { OutboxEntry } from '../core/types.ts';
|
|
2
|
+
import { computeOutboxRetryWait } from '../messaging/outbound/queue-selectors.ts';
|
|
3
|
+
import { OUTBOUND_SCHEDULE_SOURCE } from '../messaging/outbound/reasons.ts';
|
|
4
|
+
import { computePushFailureDecision } from '../messaging/outbound/retry-policy.ts';
|
|
5
|
+
import { applyBncrPushFailureDecisionToEntry } from '../runtime/outbox-transitions.ts';
|
|
6
|
+
|
|
7
|
+
type UpdateMinOutboxDelay = (current: number | null, candidate: number | null) => number | null;
|
|
8
|
+
|
|
9
|
+
type BncrOutboxDrainScheduleRuntime = {
|
|
10
|
+
scheduleAccountWait: (args: {
|
|
11
|
+
accountId: string;
|
|
12
|
+
messageId?: string;
|
|
13
|
+
source: string;
|
|
14
|
+
wait: number;
|
|
15
|
+
localNextDelay: number | null;
|
|
16
|
+
updateMinOutboxDelay: UpdateMinOutboxDelay;
|
|
17
|
+
}) => number | null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type BncrOutboxDrainFailureRuntime = {
|
|
21
|
+
backoffMs: (retryCount: number) => number;
|
|
22
|
+
outbox: Map<string, OutboxEntry>;
|
|
23
|
+
isPrePushGuardDeferral: (entry: OutboxEntry) => boolean;
|
|
24
|
+
moveToDeadLetter: (entry: OutboxEntry, reason: string) => void;
|
|
25
|
+
scheduleSave: () => void;
|
|
26
|
+
outboxDrainSchedule: BncrOutboxDrainScheduleRuntime;
|
|
27
|
+
maxRetry: number;
|
|
28
|
+
prePushGuardRetryDelayMs: number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function createBncrOutboxDrainFailure(runtime: BncrOutboxDrainFailureRuntime) {
|
|
32
|
+
return function handleFailedDrainEntry(args: {
|
|
33
|
+
accountId: string;
|
|
34
|
+
entry: OutboxEntry;
|
|
35
|
+
localNextDelay: number | null;
|
|
36
|
+
attemptedAt: number;
|
|
37
|
+
updateMinOutboxDelay: UpdateMinOutboxDelay;
|
|
38
|
+
}): { action: 'continue' | 'break'; localNextDelay: number | null } {
|
|
39
|
+
const { accountId, entry, attemptedAt, updateMinOutboxDelay } = args;
|
|
40
|
+
let { localNextDelay } = args;
|
|
41
|
+
|
|
42
|
+
if (runtime.isPrePushGuardDeferral(entry)) {
|
|
43
|
+
const wait = runtime.prePushGuardRetryDelayMs;
|
|
44
|
+
localNextDelay = runtime.outboxDrainSchedule.scheduleAccountWait({
|
|
45
|
+
accountId,
|
|
46
|
+
messageId: entry.messageId,
|
|
47
|
+
source: OUTBOUND_SCHEDULE_SOURCE.PRE_PUSH_GUARD_WAIT,
|
|
48
|
+
wait,
|
|
49
|
+
localNextDelay,
|
|
50
|
+
updateMinOutboxDelay,
|
|
51
|
+
});
|
|
52
|
+
return { action: 'break', localNextDelay };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const decision = computePushFailureDecision(
|
|
56
|
+
{
|
|
57
|
+
nowMs: attemptedAt,
|
|
58
|
+
maxRetry: runtime.maxRetry,
|
|
59
|
+
currentRetryCount: entry.retryCount,
|
|
60
|
+
lastError: entry.lastError,
|
|
61
|
+
},
|
|
62
|
+
{ backoffMs: runtime.backoffMs },
|
|
63
|
+
);
|
|
64
|
+
if (decision.kind === 'dead-letter') {
|
|
65
|
+
runtime.moveToDeadLetter(entry, decision.terminalReason);
|
|
66
|
+
return { action: 'continue', localNextDelay };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const nextEntry = applyBncrPushFailureDecisionToEntry(entry, decision);
|
|
70
|
+
runtime.outbox.set(entry.messageId, nextEntry);
|
|
71
|
+
runtime.scheduleSave();
|
|
72
|
+
|
|
73
|
+
const wait = computeOutboxRetryWait(decision.nextAttemptAt, attemptedAt);
|
|
74
|
+
localNextDelay = runtime.outboxDrainSchedule.scheduleAccountWait({
|
|
75
|
+
accountId,
|
|
76
|
+
messageId: entry.messageId,
|
|
77
|
+
source: OUTBOUND_SCHEDULE_SOURCE.PUSH_FAIL_WAIT,
|
|
78
|
+
wait,
|
|
79
|
+
localNextDelay,
|
|
80
|
+
updateMinOutboxDelay,
|
|
81
|
+
});
|
|
82
|
+
return { action: 'break', localNextDelay };
|
|
83
|
+
};
|
|
84
|
+
}
|