@evomap/evolver 1.90.0 → 2.0.0-beta.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/README.md +27 -564
- package/bin/evolver-llm-proxy.js +3 -0
- package/bin/evolver-mcp.js +2 -0
- package/bin/evolver-proxy.js +3 -0
- package/bin/evolver.js +4 -0
- package/index.js +1 -3670
- package/package.json +32 -62
- package/CONTRIBUTING.md +0 -19
- package/LICENSE +0 -641
- package/README.ja-JP.md +0 -521
- package/README.ko-KR.md +0 -520
- package/README.zh-CN.md +0 -531
- package/SKILL.md +0 -365
- package/assets/cover.png +0 -0
- package/assets/gep/genes.seed.json +0 -496
- package/conformance/savings-core/constants.json +0 -30
- package/conformance/savings-core/golden-vectors.json +0 -333
- package/scripts/a2a_export.js +0 -63
- package/scripts/a2a_ingest.js +0 -79
- package/scripts/a2a_promote.js +0 -118
- package/scripts/analyze_by_skill.js +0 -121
- package/scripts/build_binaries.js +0 -479
- package/scripts/check-changelog.js +0 -166
- package/scripts/extract_log.js +0 -85
- package/scripts/generate_history.js +0 -75
- package/scripts/gep_append_event.js +0 -96
- package/scripts/gep_personality_report.js +0 -234
- package/scripts/human_report.js +0 -147
- package/scripts/recall-verify-report.js +0 -234
- package/scripts/recover_loop.js +0 -61
- package/scripts/refresh_stars_badge.js +0 -168
- package/scripts/seed-merchants.js +0 -91
- package/scripts/skill2recipes.js +0 -118
- package/scripts/suggest_version.js +0 -89
- package/scripts/validate-modules.js +0 -38
- package/scripts/validate-suite.js +0 -78
- package/src/adapters/claudeCode.js +0 -194
- package/src/adapters/codex.js +0 -216
- package/src/adapters/cursor.js +0 -91
- package/src/adapters/hookAdapter.js +0 -469
- package/src/adapters/kiro.js +0 -195
- package/src/adapters/opencode.js +0 -326
- package/src/adapters/scripts/_lockPaths.js +0 -74
- package/src/adapters/scripts/_memoryFiltering.js +0 -35
- package/src/adapters/scripts/_runtimePaths.js +0 -440
- package/src/adapters/scripts/evolver-session-end.js +0 -321
- package/src/adapters/scripts/evolver-session-start.js +0 -587
- package/src/adapters/scripts/evolver-signal-detect.js +0 -98
- package/src/adapters/scripts/evolver-task-recall.js +0 -173
- package/src/atp/atpExecute.js +0 -283
- package/src/atp/atpTaskPickup.js +0 -233
- package/src/atp/autoBuyer.js +0 -382
- package/src/atp/autoDeliver.js +0 -215
- package/src/atp/cli.js +0 -354
- package/src/atp/cliAutobuyPrompt.js +0 -154
- package/src/atp/consumerAgent.js +0 -157
- package/src/atp/defaultHandler.js +0 -69
- package/src/atp/heartbeatSignalsHandler.js +0 -254
- package/src/atp/hubClient.js +0 -317
- package/src/atp/index.js +0 -38
- package/src/atp/merchantAgent.js +0 -118
- package/src/atp/protocol.js +0 -41
- package/src/atp/questionComposer.js +0 -133
- package/src/atp/serviceHelper.js +0 -92
- package/src/canary.js +0 -13
- package/src/config.js +0 -351
- package/src/evolve/guards.js +0 -1
- package/src/evolve/pipeline/collect.js +0 -1
- package/src/evolve/pipeline/dispatch.js +0 -1
- package/src/evolve/pipeline/enrich.js +0 -1
- package/src/evolve/pipeline/hub.js +0 -1
- package/src/evolve/pipeline/select.js +0 -1
- package/src/evolve/pipeline/signals.js +0 -1
- package/src/evolve/utils.js +0 -1
- package/src/evolve.js +0 -1
- package/src/experiment/agentRunner.js +0 -229
- package/src/experiment/cli.js +0 -159
- package/src/experiment/comparison.js +0 -233
- package/src/experiment/metrics.js +0 -75
- package/src/forceUpdate.js +0 -991
- package/src/gep/a2a.js +0 -173
- package/src/gep/a2aProtocol.js +0 -1
- package/src/gep/analyzer.js +0 -35
- package/src/gep/antiAbuseTelemetry.js +0 -1
- package/src/gep/assetCallLog.js +0 -197
- package/src/gep/assetStore.js +0 -723
- package/src/gep/assets.js +0 -36
- package/src/gep/autoDistillConv.js +0 -1
- package/src/gep/autoDistillLlm.js +0 -1
- package/src/gep/bridge.js +0 -138
- package/src/gep/candidateEval.js +0 -1
- package/src/gep/candidates.js +0 -1
- package/src/gep/claimNudge.js +0 -121
- package/src/gep/cliContracts.js +0 -1190
- package/src/gep/contentHash.js +0 -1
- package/src/gep/conversationDistiller.js +0 -1
- package/src/gep/conversationSniffer.js +0 -1
- package/src/gep/crypto.js +0 -1
- package/src/gep/curriculum.js +0 -1
- package/src/gep/deviceId.js +0 -1
- package/src/gep/directoryClient.js +0 -115
- package/src/gep/envFingerprint.js +0 -1
- package/src/gep/epigenetics.js +0 -1
- package/src/gep/execBridge.js +0 -1
- package/src/gep/executionTrace.js +0 -291
- package/src/gep/explore.js +0 -1
- package/src/gep/featureFlags.js +0 -121
- package/src/gep/gitOps.js +0 -265
- package/src/gep/hash.js +0 -1
- package/src/gep/hostErrorClassifier.js +0 -34
- package/src/gep/hubFetch.js +0 -1
- package/src/gep/hubReview.js +0 -1
- package/src/gep/hubSearch.js +0 -1
- package/src/gep/hubVerify.js +0 -1
- package/src/gep/idleScheduler.js +0 -400
- package/src/gep/issueReporter.js +0 -416
- package/src/gep/learningSignals.js +0 -1
- package/src/gep/llmReview.js +0 -92
- package/src/gep/localStateAwareness.js +0 -243
- package/src/gep/mailboxTransport.js +0 -119
- package/src/gep/memoryGraph.js +0 -1
- package/src/gep/memoryGraphAdapter.js +0 -1
- package/src/gep/mutation.js +0 -1
- package/src/gep/narrativeMemory.js +0 -1
- package/src/gep/oauthLogin.js +0 -181
- package/src/gep/openPRRegistry.js +0 -1
- package/src/gep/paths.js +0 -522
- package/src/gep/personality.js +0 -1
- package/src/gep/policyCheck.js +0 -1
- package/src/gep/portable.js +0 -103
- package/src/gep/privacyClient.js +0 -235
- package/src/gep/prompt.js +0 -1
- package/src/gep/questionGenerator.js +0 -518
- package/src/gep/recallInject.js +0 -1
- package/src/gep/recallVerifier.js +0 -1
- package/src/gep/reflection.js +0 -1
- package/src/gep/sanitize.js +0 -264
- package/src/gep/savingsCore.js +0 -1
- package/src/gep/schemas/capsule.js +0 -170
- package/src/gep/schemas/gene.js +0 -154
- package/src/gep/schemas/index.js +0 -8
- package/src/gep/schemas/protocol.js +0 -51
- package/src/gep/schemas/task.js +0 -74
- package/src/gep/selector.js +0 -1
- package/src/gep/selfPR.js +0 -469
- package/src/gep/signals.js +0 -776
- package/src/gep/skill2gep.js +0 -1056
- package/src/gep/skill2gepAudit.js +0 -303
- package/src/gep/skill2recipes.js +0 -511
- package/src/gep/skillDistiller.js +0 -1
- package/src/gep/skillPublisher.js +0 -358
- package/src/gep/solidify.js +0 -1
- package/src/gep/strategy.js +0 -1
- package/src/gep/taskReceiver.js +0 -575
- package/src/gep/tokenSavings.js +0 -1
- package/src/gep/trajectoryExport.js +0 -1
- package/src/gep/validationReport.js +0 -55
- package/src/gep/validator/index.js +0 -411
- package/src/gep/validator/reporter.js +0 -210
- package/src/gep/validator/sandboxExecutor.js +0 -480
- package/src/gep/validator/stakeBootstrap.js +0 -357
- package/src/gep/workspaceKeychain.js +0 -1
- package/src/ops/cleanup.js +0 -80
- package/src/ops/commentary.js +0 -60
- package/src/ops/health_check.js +0 -104
- package/src/ops/index.js +0 -11
- package/src/ops/innovation.js +0 -67
- package/src/ops/lifecycle.js +0 -798
- package/src/ops/self_repair.js +0 -76
- package/src/ops/skills_monitor.js +0 -147
- package/src/ops/trigger.js +0 -33
- package/src/proxy/clientSettings.js +0 -405
- package/src/proxy/envelope.js +0 -59
- package/src/proxy/extensions/dmHandler.js +0 -45
- package/src/proxy/extensions/sessionHandler.js +0 -141
- package/src/proxy/extensions/skillUpdater.js +0 -64
- package/src/proxy/extensions/traceControl.js +0 -1
- package/src/proxy/index.js +0 -1395
- package/src/proxy/inject.js +0 -1
- package/src/proxy/lifecycle/manager.js +0 -1568
- package/src/proxy/mailbox/state.js +0 -207
- package/src/proxy/mailbox/store.js +0 -602
- package/src/proxy/router/cache_passthrough.js +0 -26
- package/src/proxy/router/features.js +0 -84
- package/src/proxy/router/gemini_route.js +0 -154
- package/src/proxy/router/messages_route.js +0 -535
- package/src/proxy/router/model_router.js +0 -113
- package/src/proxy/router/models_route.js +0 -52
- package/src/proxy/router/ollama_route.js +0 -103
- package/src/proxy/router/responses_route.js +0 -170
- package/src/proxy/router/vertex_route.js +0 -110
- package/src/proxy/server/http.js +0 -363
- package/src/proxy/server/routes.js +0 -558
- package/src/proxy/server/settings.js +0 -115
- package/src/proxy/sync/engine.js +0 -179
- package/src/proxy/sync/inbound.js +0 -211
- package/src/proxy/sync/outbound.js +0 -361
- package/src/proxy/task/monitor.js +0 -131
- package/src/proxy/trace/extractor.js +0 -1
- package/src/proxy/trace/usage.js +0 -1
- package/src/solo/breaker.js +0 -25
- package/src/solo/gitGuard.js +0 -65
- package/src/webui/client/clientJs/assets.js +0 -111
- package/src/webui/client/clientJs/bootstrap.js +0 -92
- package/src/webui/client/clientJs/common.js +0 -77
- package/src/webui/client/clientJs/i18n.js +0 -366
- package/src/webui/client/clientJs/index.js +0 -35
- package/src/webui/client/clientJs/interactions.js +0 -351
- package/src/webui/client/clientJs/overview.js +0 -152
- package/src/webui/client/clientJs/personality.js +0 -285
- package/src/webui/client/clientJs/pipelines.js +0 -330
- package/src/webui/client/indexHtml.js +0 -221
- package/src/webui/client/static.js +0 -23
- package/src/webui/client/stylesCss.js +0 -639
- package/src/webui/client/vendor/README.md +0 -15
- package/src/webui/client/vendor/echarts.min.js +0 -45
- package/src/webui/index.js +0 -14
- package/src/webui/observer/assets.js +0 -146
- package/src/webui/observer/index.js +0 -37
- package/src/webui/observer/interactions.js +0 -127
- package/src/webui/observer/jsonl.js +0 -75
- package/src/webui/observer/paths.js +0 -46
- package/src/webui/observer/personality.js +0 -43
- package/src/webui/observer/pipelineEvents.js +0 -58
- package/src/webui/observer/redact.js +0 -63
- package/src/webui/observer/runs.js +0 -356
- package/src/webui/observer/safety.js +0 -57
- package/src/webui/observer/skills.js +0 -70
- package/src/webui/observer/status.js +0 -71
- package/src/webui/server/http.js +0 -138
- package/src/webui/server/routes.js +0 -41
package/src/proxy/sync/engine.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { OutboundSync } = require('./outbound');
|
|
4
|
-
const { InboundSync, DEFAULT_POLL_INTERVAL_ACTIVE, DEFAULT_POLL_INTERVAL_IDLE } = require('./inbound');
|
|
5
|
-
const { AuthError } = require('../lifecycle/manager');
|
|
6
|
-
|
|
7
|
-
const DEFAULT_OUTBOUND_INTERVAL = 5_000;
|
|
8
|
-
const IDLE_THRESHOLD = 5 * 60_000;
|
|
9
|
-
|
|
10
|
-
class SyncEngine {
|
|
11
|
-
constructor({ store, hubUrl, getHeaders, logger, onInboundReceived, onAuthError, onOutboundFlushed }) {
|
|
12
|
-
this.store = store;
|
|
13
|
-
this.hubUrl = hubUrl;
|
|
14
|
-
this.logger = logger || console;
|
|
15
|
-
this.getHeaders = getHeaders;
|
|
16
|
-
this.onInboundReceived = onInboundReceived || null;
|
|
17
|
-
this.onAuthError = onAuthError || null;
|
|
18
|
-
this.onOutboundFlushed = onOutboundFlushed || null;
|
|
19
|
-
|
|
20
|
-
this.outbound = new OutboundSync({ store, hubUrl, getHeaders, logger });
|
|
21
|
-
this.inbound = new InboundSync({ store, hubUrl, getHeaders, logger });
|
|
22
|
-
|
|
23
|
-
this._outTimer = null;
|
|
24
|
-
this._inTimer = null;
|
|
25
|
-
this._running = false;
|
|
26
|
-
this._lastActivity = Date.now();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
start() {
|
|
30
|
-
if (this._running) return;
|
|
31
|
-
this._running = true;
|
|
32
|
-
this._lastActivity = Date.now();
|
|
33
|
-
this._scheduleOutbound(500);
|
|
34
|
-
this._scheduleInbound(1_000);
|
|
35
|
-
this.logger.log('[sync] engine started');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
stop() {
|
|
39
|
-
this._running = false;
|
|
40
|
-
if (this._outTimer) { clearTimeout(this._outTimer); this._outTimer = null; }
|
|
41
|
-
if (this._inTimer) { clearTimeout(this._inTimer); this._inTimer = null; }
|
|
42
|
-
this.logger.log('[sync] engine stopped');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
notifyNewOutbound() {
|
|
46
|
-
this._lastActivity = Date.now();
|
|
47
|
-
if (this._running && !this._outPending) {
|
|
48
|
-
if (this._outTimer) clearTimeout(this._outTimer);
|
|
49
|
-
this._scheduleOutbound(100);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
_isIdle() {
|
|
54
|
-
return (Date.now() - this._lastActivity) > IDLE_THRESHOLD;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async _handleAuthError(source) {
|
|
58
|
-
this.logger.error(`[sync] auth error from ${source}, triggering re-authentication`);
|
|
59
|
-
if (typeof this.onAuthError === 'function') {
|
|
60
|
-
try { await this.onAuthError(); } catch (e) {
|
|
61
|
-
this.logger.error(`[sync] onAuthError callback failed: ${e.message}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
_scheduleOutbound(delayMs) {
|
|
67
|
-
if (!this._running) return;
|
|
68
|
-
this._outTimer = setTimeout(async () => {
|
|
69
|
-
// Defence-in-depth: a throw from this.outbound.flush(),
|
|
70
|
-
// this.store.countPending(), or any post-flush bookkeeping used
|
|
71
|
-
// to escape the setTimeout callback. Node logs the unhandled
|
|
72
|
-
// rejection and the next setTimeout was never armed — the
|
|
73
|
-
// outbound sync loop silently died until the process restarted,
|
|
74
|
-
// while `_running` stayed true (no signal to the caller).
|
|
75
|
-
//
|
|
76
|
-
// Mirrors the heartbeat-loop fix in PR #147 (issue #544): wrap
|
|
77
|
-
// the whole tick, schedule the next iteration in `finally` so a
|
|
78
|
-
// surprise throw cannot park the loop.
|
|
79
|
-
let nextDelay = DEFAULT_OUTBOUND_INTERVAL;
|
|
80
|
-
let hubRetryAfterMs = 0;
|
|
81
|
-
try {
|
|
82
|
-
if (!this._running) return;
|
|
83
|
-
this._outPending = true;
|
|
84
|
-
try {
|
|
85
|
-
const result = await this.outbound.flush();
|
|
86
|
-
if (result.sent > 0) this._lastActivity = Date.now();
|
|
87
|
-
if (result.retryAfterMs > 0) hubRetryAfterMs = result.retryAfterMs;
|
|
88
|
-
if ((result.sent > 0 || result.dropped > 0) && typeof this.onOutboundFlushed === 'function') {
|
|
89
|
-
try { this.onOutboundFlushed(result); } catch (e) {
|
|
90
|
-
this.logger.warn?.('[sync] onOutboundFlushed callback failed:', e.message);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
} catch (err) {
|
|
94
|
-
if (err instanceof AuthError) {
|
|
95
|
-
await this._handleAuthError('outbound');
|
|
96
|
-
} else {
|
|
97
|
-
this.logger.error(`[sync] outbound error: ${err.message}`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
this._outPending = false;
|
|
101
|
-
if (hubRetryAfterMs > 0) {
|
|
102
|
-
nextDelay = Math.max(1_000, hubRetryAfterMs);
|
|
103
|
-
} else {
|
|
104
|
-
try {
|
|
105
|
-
const pending = this.store.countPending({ direction: 'outbound' });
|
|
106
|
-
if (pending > 0) nextDelay = 1_000;
|
|
107
|
-
} catch (err) {
|
|
108
|
-
// countPending threw (corrupt store, FS hiccup): keep the
|
|
109
|
-
// default cadence rather than parking the loop.
|
|
110
|
-
this.logger.error(`[sync] countPending threw (non-fatal): ${err && err.message}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
} catch (err) {
|
|
114
|
-
// Anything that escaped the inner blocks above. Log and let
|
|
115
|
-
// finally re-arm the timer.
|
|
116
|
-
this.logger.error(`[sync] outbound tick threw (non-fatal): ${err && err.message}`);
|
|
117
|
-
this._outPending = false;
|
|
118
|
-
} finally {
|
|
119
|
-
if (this._running) this._scheduleOutbound(nextDelay);
|
|
120
|
-
}
|
|
121
|
-
}, delayMs);
|
|
122
|
-
if (this._outTimer.unref) this._outTimer.unref();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
_scheduleInbound(delayMs) {
|
|
126
|
-
if (!this._running) return;
|
|
127
|
-
this._inTimer = setTimeout(async () => {
|
|
128
|
-
// Same defence-in-depth pattern as _scheduleOutbound: a throw
|
|
129
|
-
// from inbound.pull / ackDelivered / _isIdle used to escape the
|
|
130
|
-
// setTimeout callback and silently park the inbound loop.
|
|
131
|
-
let nextDelay = DEFAULT_POLL_INTERVAL_ACTIVE;
|
|
132
|
-
let hubRetryAfterMs = 0;
|
|
133
|
-
try {
|
|
134
|
-
if (!this._running) return;
|
|
135
|
-
try {
|
|
136
|
-
const result = await this.inbound.pull();
|
|
137
|
-
if (result.retryAfterMs > 0) {
|
|
138
|
-
hubRetryAfterMs = result.retryAfterMs;
|
|
139
|
-
} else if (result.received > 0) {
|
|
140
|
-
this._lastActivity = Date.now();
|
|
141
|
-
if (typeof this.onInboundReceived === 'function') {
|
|
142
|
-
try { this.onInboundReceived(result.received); } catch (e) {
|
|
143
|
-
this.logger.warn?.('[sync] onInboundReceived callback failed:', e.message);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (!hubRetryAfterMs) {
|
|
148
|
-
const ack = await this.inbound.ackDelivered();
|
|
149
|
-
if (ack.retryAfterMs > 0) hubRetryAfterMs = ack.retryAfterMs;
|
|
150
|
-
}
|
|
151
|
-
} catch (err) {
|
|
152
|
-
if (err instanceof AuthError) {
|
|
153
|
-
await this._handleAuthError('inbound');
|
|
154
|
-
} else {
|
|
155
|
-
this.logger.error(`[sync] inbound error: ${err.message}`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (hubRetryAfterMs > 0) {
|
|
159
|
-
nextDelay = Math.max(1_000, hubRetryAfterMs);
|
|
160
|
-
} else {
|
|
161
|
-
try {
|
|
162
|
-
nextDelay = this._isIdle()
|
|
163
|
-
? DEFAULT_POLL_INTERVAL_IDLE
|
|
164
|
-
: DEFAULT_POLL_INTERVAL_ACTIVE;
|
|
165
|
-
} catch (err) {
|
|
166
|
-
this.logger.error(`[sync] _isIdle threw (non-fatal): ${err && err.message}`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
} catch (err) {
|
|
170
|
-
this.logger.error(`[sync] inbound tick threw (non-fatal): ${err && err.message}`);
|
|
171
|
-
} finally {
|
|
172
|
-
if (this._running) this._scheduleInbound(nextDelay);
|
|
173
|
-
}
|
|
174
|
-
}, delayMs);
|
|
175
|
-
if (this._inTimer.unref) this._inTimer.unref();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
module.exports = { SyncEngine, DEFAULT_OUTBOUND_INTERVAL };
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { PROXY_PROTOCOL_VERSION } = require('../mailbox/store');
|
|
4
|
-
const { AuthError } = require('../lifecycle/manager');
|
|
5
|
-
const {
|
|
6
|
-
drainHubResponse,
|
|
7
|
-
hubFetch,
|
|
8
|
-
hubUnreachableBackoffMs,
|
|
9
|
-
isHubUnreachableError,
|
|
10
|
-
readHubResponseJson,
|
|
11
|
-
readHubResponseText,
|
|
12
|
-
sanitizeHubResponseForLog,
|
|
13
|
-
throwIfHubUnreachableResponse,
|
|
14
|
-
} = require('../../gep/hubFetch');
|
|
15
|
-
|
|
16
|
-
const DEFAULT_POLL_INTERVAL_ACTIVE = 10_000;
|
|
17
|
-
const DEFAULT_POLL_INTERVAL_IDLE = 60_000;
|
|
18
|
-
|
|
19
|
-
function toInboundStoreMessage(m, channel) {
|
|
20
|
-
return {
|
|
21
|
-
id: m.id,
|
|
22
|
-
type: m.type,
|
|
23
|
-
payload: m.payload,
|
|
24
|
-
channel,
|
|
25
|
-
priority: m.priority || 'normal',
|
|
26
|
-
refId: m.ref_id,
|
|
27
|
-
expiresAt: m.expires_at,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
class InboundSync {
|
|
32
|
-
constructor({ store, hubUrl, getHeaders, logger }) {
|
|
33
|
-
this.store = store;
|
|
34
|
-
this.hubUrl = hubUrl;
|
|
35
|
-
this.logger = logger || console;
|
|
36
|
-
this.getHeaders = getHeaders;
|
|
37
|
-
this._hubUnreachableFailures = 0;
|
|
38
|
-
this._hubUnreachableUntil = 0;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
_hubUnreachableWaitMs() {
|
|
42
|
-
return Math.max(0, this._hubUnreachableUntil - Date.now());
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
_recordHubReachable() {
|
|
46
|
-
this._hubUnreachableFailures = 0;
|
|
47
|
-
this._hubUnreachableUntil = 0;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
_recordHubUnreachable(err) {
|
|
51
|
-
this._hubUnreachableFailures += 1;
|
|
52
|
-
const retryAfterMs = hubUnreachableBackoffMs(this._hubUnreachableFailures);
|
|
53
|
-
this._hubUnreachableUntil = Date.now() + retryAfterMs;
|
|
54
|
-
this.logger.warn?.(
|
|
55
|
-
`[inbound] Hub unreachable; backing off for ${Math.ceil(retryAfterMs / 1000)}s: ` +
|
|
56
|
-
`${err && err.message || err}`
|
|
57
|
-
);
|
|
58
|
-
return retryAfterMs;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async pull(channel = 'evomap-hub', limit = 50) {
|
|
62
|
-
const waitMs = this._hubUnreachableWaitMs();
|
|
63
|
-
if (waitMs > 0) {
|
|
64
|
-
return {
|
|
65
|
-
received: 0,
|
|
66
|
-
error: 'hub_unreachable_backoff',
|
|
67
|
-
hubUnreachable: true,
|
|
68
|
-
retryAfterMs: waitMs,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const cursorKey = `${channel}:inbound_cursor`;
|
|
73
|
-
const cursor = this.store.getCursor(cursorKey);
|
|
74
|
-
|
|
75
|
-
const endpoint = `${this.hubUrl}/a2a/mailbox/inbound`;
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
const senderId = this.store.getState('node_id');
|
|
79
|
-
const res = await hubFetch(endpoint, {
|
|
80
|
-
method: 'POST',
|
|
81
|
-
headers: this.getHeaders(),
|
|
82
|
-
body: JSON.stringify({ sender_id: senderId, proxy_protocol_version: PROXY_PROTOCOL_VERSION, cursor, limit }),
|
|
83
|
-
signal: AbortSignal.timeout(35_000),
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
await throwIfHubUnreachableResponse(res, 'inbound pull');
|
|
87
|
-
this._recordHubReachable();
|
|
88
|
-
|
|
89
|
-
if (res.status === 403 || res.status === 401) {
|
|
90
|
-
const errText = await readHubResponseText(res).catch(() => 'unknown');
|
|
91
|
-
throw new AuthError(`Hub ${res.status}: ${sanitizeHubResponseForLog(errText)}`, res.status);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!res.ok) {
|
|
95
|
-
const errText = await readHubResponseText(res).catch(() => 'unknown');
|
|
96
|
-
throw new Error(`Hub returned ${res.status}: ${sanitizeHubResponseForLog(errText)}`);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const data = await readHubResponseJson(res);
|
|
100
|
-
const messages = data.messages || [];
|
|
101
|
-
let stored = 0;
|
|
102
|
-
let dropped = 0;
|
|
103
|
-
|
|
104
|
-
if (messages.length > 0) {
|
|
105
|
-
for (const m of messages) {
|
|
106
|
-
try {
|
|
107
|
-
this.store.writeInbound(toInboundStoreMessage(m, channel));
|
|
108
|
-
stored++;
|
|
109
|
-
} catch (err) {
|
|
110
|
-
if (err && err.code === 'MAILBOX_JSONL_LINE_TOO_LARGE') {
|
|
111
|
-
dropped++;
|
|
112
|
-
const msgId = m && m.id ? String(m.id) : '(missing id)';
|
|
113
|
-
this.logger.warn?.(`[inbound] dropped oversized inbound message ${msgId}: ${err.message}`);
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
throw err;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (data.next_cursor) {
|
|
122
|
-
this.store.setCursor(cursorKey, data.next_cursor);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const result = { received: stored, cursor: data.next_cursor || cursor };
|
|
126
|
-
if (dropped > 0) result.dropped = dropped;
|
|
127
|
-
return result;
|
|
128
|
-
} catch (err) {
|
|
129
|
-
if (err instanceof AuthError) throw err;
|
|
130
|
-
if (isHubUnreachableError(err)) {
|
|
131
|
-
const retryAfterMs = this._recordHubUnreachable(err);
|
|
132
|
-
return {
|
|
133
|
-
received: 0,
|
|
134
|
-
error: 'hub_unreachable',
|
|
135
|
-
hubUnreachable: true,
|
|
136
|
-
retryAfterMs,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
this.logger.error(`[inbound] pull failed: ${err.message}`);
|
|
140
|
-
return { received: 0, error: err.message };
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async ackDelivered(channel = 'evomap-hub') {
|
|
145
|
-
const waitMs = this._hubUnreachableWaitMs();
|
|
146
|
-
if (waitMs > 0) {
|
|
147
|
-
return {
|
|
148
|
-
acked: 0,
|
|
149
|
-
error: 'hub_unreachable_backoff',
|
|
150
|
-
hubUnreachable: true,
|
|
151
|
-
retryAfterMs: waitMs,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const delivered = this.store.list({
|
|
156
|
-
type: '%',
|
|
157
|
-
direction: 'inbound',
|
|
158
|
-
status: 'delivered',
|
|
159
|
-
limit: 100,
|
|
160
|
-
}).filter(m => m.channel === channel);
|
|
161
|
-
|
|
162
|
-
if (delivered.length === 0) return { acked: 0 };
|
|
163
|
-
|
|
164
|
-
const endpoint = `${this.hubUrl}/a2a/mailbox/ack`;
|
|
165
|
-
|
|
166
|
-
try {
|
|
167
|
-
const senderId = this.store.getState('node_id');
|
|
168
|
-
// Round-8 (§21.5): drain the response body so the undici long-poll
|
|
169
|
-
// dispatcher pool is not leaked one socket per ack. ackDelivered
|
|
170
|
-
// is called every inbound poll cycle (default 1-10s); the
|
|
171
|
-
// pre-round-8 code captured no reference to res and never called
|
|
172
|
-
// .json()/.text()/body.cancel(), so each ack pinned a socket
|
|
173
|
-
// until GC. After a few minutes of activity the strict-pool was
|
|
174
|
-
// exhausted and proxy-mode heartbeats hung on next acquire --
|
|
175
|
-
// matches the "alive once then dead" user symptom in proxy mode.
|
|
176
|
-
const res = await hubFetch(endpoint, {
|
|
177
|
-
method: 'POST',
|
|
178
|
-
headers: this.getHeaders(),
|
|
179
|
-
body: JSON.stringify({ sender_id: senderId, message_ids: delivered.map(m => m.id) }),
|
|
180
|
-
signal: AbortSignal.timeout(10_000),
|
|
181
|
-
});
|
|
182
|
-
await throwIfHubUnreachableResponse(res, 'inbound ack');
|
|
183
|
-
this._recordHubReachable();
|
|
184
|
-
if (res.status === 403 || res.status === 401) {
|
|
185
|
-
const errText = await readHubResponseText(res).catch(() => 'unknown');
|
|
186
|
-
throw new AuthError(`Hub ${res.status}: ${sanitizeHubResponseForLog(errText)}`, res.status);
|
|
187
|
-
}
|
|
188
|
-
if (!res.ok) {
|
|
189
|
-
const errText = await readHubResponseText(res).catch(() => 'unknown');
|
|
190
|
-
throw new Error(`Hub returned ${res.status}: ${sanitizeHubResponseForLog(errText)}`);
|
|
191
|
-
}
|
|
192
|
-
await drainHubResponse(res);
|
|
193
|
-
return { acked: delivered.length };
|
|
194
|
-
} catch (err) {
|
|
195
|
-
if (err instanceof AuthError) throw err;
|
|
196
|
-
if (isHubUnreachableError(err)) {
|
|
197
|
-
const retryAfterMs = this._recordHubUnreachable(err);
|
|
198
|
-
return {
|
|
199
|
-
acked: 0,
|
|
200
|
-
error: 'hub_unreachable',
|
|
201
|
-
hubUnreachable: true,
|
|
202
|
-
retryAfterMs,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
this.logger.error(`[inbound] ack failed: ${err.message}`);
|
|
206
|
-
return { acked: 0, error: err.message };
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
module.exports = { InboundSync, DEFAULT_POLL_INTERVAL_ACTIVE, DEFAULT_POLL_INTERVAL_IDLE };
|