@triflux/remote 10.0.1 → 10.25.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/hub/pipe.mjs +239 -121
- package/hub/public/dashboard.html +68 -7
- package/hub/server.mjs +2181 -701
- package/hub/store-adapter.mjs +101 -37
- package/hub/store.mjs +356 -153
- package/hub/team/agent-map.json +26 -7
- package/hub/team/ansi.mjs +245 -146
- package/hub/team/backend.mjs +84 -17
- package/hub/team/build-worker-prompt.mjs +42 -0
- package/hub/team/check-mcp-hub.mjs +49 -0
- package/hub/team/claude-daemon-control.mjs +219 -0
- package/hub/team/claude-native-bridge.mjs +784 -0
- package/hub/team/claude-session-projection.mjs +65 -0
- package/hub/team/cli/commands/attach.mjs +57 -37
- package/hub/team/cli/commands/control.mjs +29 -8
- package/hub/team/cli/commands/debug.mjs +95 -74
- package/hub/team/cli/commands/focus.mjs +80 -53
- package/hub/team/cli/commands/interrupt.mjs +18 -6
- package/hub/team/cli/commands/kill.mjs +16 -5
- package/hub/team/cli/commands/list.mjs +31 -24
- package/hub/team/cli/commands/send.mjs +19 -6
- package/hub/team/cli/commands/start/index.mjs +154 -33
- package/hub/team/cli/commands/start/parse-args.mjs +89 -12
- package/hub/team/cli/commands/start/start-headless.mjs +127 -37
- package/hub/team/cli/commands/start/start-in-process.mjs +50 -40
- package/hub/team/cli/commands/start/start-mux.mjs +122 -73
- package/hub/team/cli/commands/start/start-wt.mjs +86 -69
- package/hub/team/cli/commands/status.mjs +43 -14
- package/hub/team/cli/commands/stop.mjs +11 -4
- package/hub/team/cli/commands/task.mjs +8 -3
- package/hub/team/cli/commands/tasks.mjs +13 -13
- package/hub/team/cli/index.mjs +2 -2
- package/hub/team/cli/manifest.mjs +38 -8
- package/hub/team/cli/render.mjs +52 -30
- package/hub/team/cli/services/attach-fallback.mjs +74 -54
- package/hub/team/cli/services/hub-client.mjs +45 -17
- package/hub/team/cli/services/member-selector.mjs +37 -30
- package/hub/team/cli/services/native-control.mjs +144 -116
- package/hub/team/cli/services/runtime-mode.mjs +55 -1
- package/hub/team/cli/services/state-store.mjs +66 -9
- package/hub/team/cli/services/task-model.mjs +40 -30
- package/hub/team/codex-review.mjs +521 -0
- package/hub/team/conductor-mesh-bridge.mjs +25 -24
- package/hub/team/conductor-registry.mjs +121 -0
- package/hub/team/conductor.mjs +1379 -671
- package/hub/team/consensus-meta.mjs +176 -0
- package/hub/team/dashboard-anchor.mjs +4 -5
- package/hub/team/dashboard-layout.mjs +3 -1
- package/hub/team/dashboard-open.mjs +21 -119
- package/hub/team/dashboard.mjs +76 -28
- package/hub/team/event-log.mjs +18 -10
- package/hub/team/execution-mode.mjs +241 -0
- package/hub/team/extract-completion-payload.mjs +110 -0
- package/hub/team/git-preflight.mjs +286 -0
- package/hub/team/handoff.mjs +49 -18
- package/hub/team/headless-bridge-session.mjs +17 -0
- package/hub/team/headless.mjs +2065 -1156
- package/hub/team/health-probe.mjs +232 -69
- package/hub/team/launcher-template.mjs +23 -13
- package/hub/team/lead-control.mjs +91 -4
- package/hub/team/mcp-selector.mjs +145 -0
- package/hub/team/native-supervisor.mjs +90 -26
- package/hub/team/native.mjs +74 -35
- package/hub/team/nativeProxy.mjs +184 -113
- package/hub/team/notify.mjs +147 -78
- package/hub/team/orchestrator.mjs +173 -161
- package/hub/team/pane.mjs +43 -15
- package/hub/team/process-cleanup.mjs +69 -25
- package/hub/team/psmux.mjs +1067 -264
- package/hub/team/recovery-store.mjs +149 -0
- package/hub/team/remote-probe.mjs +69 -53
- package/hub/team/remote-session.mjs +131 -59
- package/hub/team/remote-watcher.mjs +62 -34
- package/hub/team/retry-state-machine.mjs +267 -0
- package/hub/team/routing.mjs +51 -25
- package/hub/team/runtime-strategy.mjs +200 -0
- package/hub/team/schemas/worker-completion.json +39 -0
- package/hub/team/sentinel-capture.mjs +127 -0
- package/hub/team/session-sync.mjs +153 -6
- package/hub/team/session.mjs +605 -611
- package/hub/team/shared.mjs +13 -13
- package/hub/team/staleState.mjs +72 -30
- package/hub/team/swarm-cli.mjs +390 -0
- package/hub/team/swarm-hypervisor.mjs +1526 -198
- package/hub/team/swarm-intent.mjs +216 -0
- package/hub/team/swarm-locks.mjs +140 -25
- package/hub/team/swarm-planner.mjs +121 -21
- package/hub/team/swarm-preflight.mjs +317 -0
- package/hub/team/swarm-reconciler.mjs +128 -23
- package/hub/team/synapse-cli.mjs +458 -0
- package/hub/team/synapse-http.mjs +60 -0
- package/hub/team/synapse-registry.mjs +329 -0
- package/hub/team/terminal-opener.mjs +216 -0
- package/hub/team/tui-core.mjs +288 -0
- package/hub/team/tui-lite.mjs +234 -146
- package/hub/team/tui-remote-adapter.mjs +21 -37
- package/hub/team/tui-synapse.mjs +223 -0
- package/hub/team/tui-viewer.mjs +104 -45
- package/hub/team/tui-widgets.mjs +262 -0
- package/hub/team/tui.mjs +936 -449
- package/hub/team/worker-completion-validator.mjs +84 -0
- package/hub/team/worker-sandbox.mjs +93 -0
- package/hub/team/worker-signal.mjs +263 -0
- package/hub/team/worker-signal.types.d.ts +52 -0
- package/hub/team/worktree-lifecycle.mjs +518 -64
- package/hub/team/wt-manager.mjs +297 -26
- package/hub/tools.mjs +474 -252
- package/hub/tray.mjs +411 -368
- package/hub/workers/claude-worker.mjs +162 -118
- package/hub/workers/codex-app-server-worker.mjs +1015 -0
- package/hub/workers/codex-mcp.mjs +724 -507
- package/hub/workers/delegator-mcp.mjs +663 -337
- package/hub/workers/factory.mjs +100 -21
- package/hub/workers/gemini-worker.mjs +179 -86
- package/hub/workers/interface.mjs +23 -2
- package/hub/workers/lib/jsonrpc-stdio.mjs +463 -0
- package/hub/workers/worker-utils.mjs +22 -16
- package/package.json +4 -3
- package/scripts/lib/agent-json.mjs +27 -0
- package/scripts/lib/async.mjs +174 -0
- package/scripts/lib/claudemd-scanner.mjs +223 -0
- package/scripts/lib/cli-agy.mjs +62 -0
- package/scripts/lib/cli-claude.mjs +78 -0
- package/scripts/lib/cli-codex.mjs +199 -0
- package/scripts/lib/cli-gemini.mjs +67 -0
- package/scripts/lib/codex-recovery.sh +50 -0
- package/scripts/lib/context.mjs +67 -0
- package/scripts/lib/cross-review-utils.mjs +59 -0
- package/scripts/lib/doctor-env-checks.mjs +121 -0
- package/scripts/lib/dynamic-route-cli.mjs +107 -0
- package/scripts/lib/env-probe.mjs +269 -0
- package/scripts/lib/env.mjs +14 -0
- package/scripts/lib/gemini-profiles.mjs +119 -0
- package/scripts/lib/handoff.mjs +187 -0
- package/scripts/lib/hook-utils.mjs +16 -0
- package/scripts/lib/hub.mjs +48 -0
- package/scripts/lib/keyword-rules.mjs +195 -0
- package/scripts/lib/logger.mjs +105 -0
- package/scripts/lib/mcp-filter.mjs +883 -0
- package/scripts/lib/mcp-gateway-servers.mjs +70 -0
- package/scripts/lib/mcp-guard-engine.mjs +2120 -0
- package/scripts/lib/mcp-health.mjs +773 -0
- package/scripts/lib/mcp-manifest.mjs +89 -0
- package/scripts/lib/mcp-server-catalog.mjs +355 -0
- package/scripts/lib/pid.mjs +63 -0
- package/scripts/lib/process-utils.mjs +26 -0
- package/scripts/lib/psmux-info.mjs +179 -0
- package/scripts/lib/quota.mjs +47 -0
- package/scripts/lib/remote-spawn-transfer.mjs +226 -0
- package/scripts/lib/skill-state.mjs +220 -0
- package/scripts/lib/skill-template.mjs +375 -0
- package/scripts/lib/team.mjs +75 -0
- package/scripts/lib/timeout.mjs +66 -0
- package/scripts/lib/tmp.mjs +26 -0
- package/scripts/lib/toml.mjs +113 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// hub/team/sentinel-capture.mjs — stdout sentinel-framed payload capture (#125)
|
|
2
|
+
//
|
|
3
|
+
// Workers emit completion payloads delimited by `<<<TFX_COMPLETION_BEGIN>>>`
|
|
4
|
+
// and `<<<TFX_COMPLETION_END>>>` (see swarm-hypervisor.mjs buildWorkerPrompt
|
|
5
|
+
// appendix). conductor.mjs feeds every stdout chunk through `push()`. After the
|
|
6
|
+
// child exits, `snapshot()` returns the captured slice (BEGIN..END inclusive)
|
|
7
|
+
// for `extractCompletionPayload`.
|
|
8
|
+
//
|
|
9
|
+
// Why this lives outside the 16 KiB stdoutTail buffer:
|
|
10
|
+
// payloads with large `commits_made` arrays can exceed 16 KiB and a sliding
|
|
11
|
+
// tail would head-truncate the BEGIN marker, leading to silent fallback to
|
|
12
|
+
// brace-scan and an incorrect inner-object extraction (#115 Codex Finding 2).
|
|
13
|
+
//
|
|
14
|
+
// Pure module — no I/O, no timers — so it can be unit-tested directly.
|
|
15
|
+
|
|
16
|
+
export const SENTINEL_BEGIN = "<<<TFX_COMPLETION_BEGIN>>>";
|
|
17
|
+
export const SENTINEL_END = "<<<TFX_COMPLETION_END>>>";
|
|
18
|
+
|
|
19
|
+
const DEFAULT_MAX_BYTES = 1 << 20; // 1 MiB safety cap on captured region
|
|
20
|
+
|
|
21
|
+
// Per the worker prompt appendix, both markers must appear alone on their own
|
|
22
|
+
// line. Substring matches inside log lines / debug echoes must NOT trigger
|
|
23
|
+
// capture or terminate it. We treat `\n`, `\r`, and string boundaries (start
|
|
24
|
+
// or end of buffer) as line edges so Windows `\r\n` works without special-casing.
|
|
25
|
+
function isLineEdgeChar(ch) {
|
|
26
|
+
return ch === "\n" || ch === "\r";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function findStandaloneMarker(text, marker, fromIdx = 0) {
|
|
30
|
+
let from = fromIdx;
|
|
31
|
+
while (from <= text.length - marker.length) {
|
|
32
|
+
const idx = text.indexOf(marker, from);
|
|
33
|
+
if (idx === -1) return -1;
|
|
34
|
+
const before = idx === 0 || isLineEdgeChar(text[idx - 1]);
|
|
35
|
+
const afterIdx = idx + marker.length;
|
|
36
|
+
const after = afterIdx === text.length || isLineEdgeChar(text[afterIdx]);
|
|
37
|
+
if (before && after) return idx;
|
|
38
|
+
from = idx + 1;
|
|
39
|
+
}
|
|
40
|
+
return -1;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Streaming sentinel capture state machine.
|
|
45
|
+
*
|
|
46
|
+
* @param {object} [opts]
|
|
47
|
+
* @param {number} [opts.maxBytes=1048576] safety cap on the captured region.
|
|
48
|
+
* If the capture grows past this and head-truncation removes the BEGIN
|
|
49
|
+
* marker, `isOverflow()` becomes true so the conductor can deterministically
|
|
50
|
+
* reject instead of falling back to brace-scan on a runaway payload
|
|
51
|
+
* (Codex R1 MEDIUM finding).
|
|
52
|
+
* @returns {{push: (text: string) => void, snapshot: () => string,
|
|
53
|
+
* isActive: () => boolean, isComplete: () => boolean,
|
|
54
|
+
* isOverflow: () => boolean}}
|
|
55
|
+
*/
|
|
56
|
+
export function createSentinelCapture({ maxBytes = DEFAULT_MAX_BYTES } = {}) {
|
|
57
|
+
let capturing = false;
|
|
58
|
+
let capture = "";
|
|
59
|
+
let overlap = "";
|
|
60
|
+
let done = false;
|
|
61
|
+
let overflowed = false;
|
|
62
|
+
|
|
63
|
+
// Boundary overlap covers the marker length plus one extra byte so we can
|
|
64
|
+
// verify the line-edge character that precedes BEGIN across chunk seams.
|
|
65
|
+
const overlapWindow = SENTINEL_BEGIN.length;
|
|
66
|
+
|
|
67
|
+
function maybeFlagOverflow() {
|
|
68
|
+
if (findStandaloneMarker(capture, SENTINEL_BEGIN) === -1) {
|
|
69
|
+
overflowed = true;
|
|
70
|
+
done = true;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function push(text) {
|
|
77
|
+
if (done || typeof text !== "string" || text.length === 0) return;
|
|
78
|
+
|
|
79
|
+
if (!capturing) {
|
|
80
|
+
const search = overlap + text;
|
|
81
|
+
const idx = findStandaloneMarker(search, SENTINEL_BEGIN);
|
|
82
|
+
if (idx !== -1) {
|
|
83
|
+
capturing = true;
|
|
84
|
+
capture = search.slice(idx);
|
|
85
|
+
overlap = "";
|
|
86
|
+
if (capture.length > maxBytes) {
|
|
87
|
+
capture = capture.slice(-maxBytes);
|
|
88
|
+
if (maybeFlagOverflow()) return;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
overlap = search.slice(-overlapWindow);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
capture += text;
|
|
96
|
+
if (capture.length > maxBytes) {
|
|
97
|
+
capture = capture.slice(-maxBytes);
|
|
98
|
+
if (maybeFlagOverflow()) return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Stop capturing once the standalone-line END marker is seen. Trim to the
|
|
103
|
+
// first BEGIN..END pair so a worker that re-emitted (retry, debug log)
|
|
104
|
+
// doesn't bloat the snapshot.
|
|
105
|
+
const endIdx = findStandaloneMarker(capture, SENTINEL_END);
|
|
106
|
+
if (endIdx !== -1) {
|
|
107
|
+
done = true;
|
|
108
|
+
capture = capture.slice(0, endIdx + SENTINEL_END.length);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
push,
|
|
114
|
+
snapshot() {
|
|
115
|
+
return capture;
|
|
116
|
+
},
|
|
117
|
+
isActive() {
|
|
118
|
+
return capturing && !done;
|
|
119
|
+
},
|
|
120
|
+
isComplete() {
|
|
121
|
+
return done && !overflowed;
|
|
122
|
+
},
|
|
123
|
+
isOverflow() {
|
|
124
|
+
return overflowed;
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import { readState } from "@triflux/core/hub/state.mjs";
|
|
2
|
+
|
|
1
3
|
const DEFAULT_TIMEOUT_MS = 2500;
|
|
4
|
+
const DEFAULT_HEADLESS_POLL_MS = 1000;
|
|
2
5
|
|
|
3
6
|
function resolveFetch(fetchImpl) {
|
|
4
7
|
if (typeof fetchImpl === "function") return fetchImpl;
|
|
5
|
-
if (typeof globalThis.fetch === "function")
|
|
8
|
+
if (typeof globalThis.fetch === "function")
|
|
9
|
+
return globalThis.fetch.bind(globalThis);
|
|
6
10
|
return null;
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
function normalizeHubBaseUrl(hubUrl) {
|
|
10
|
-
return String(hubUrl || "")
|
|
14
|
+
return String(hubUrl || "")
|
|
15
|
+
.replace(/\/+$/, "")
|
|
16
|
+
.replace(/\/mcp$/, "");
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
function safeAbortSignal(timeoutMs) {
|
|
@@ -15,6 +21,55 @@ function safeAbortSignal(timeoutMs) {
|
|
|
15
21
|
return AbortSignal.timeout(timeoutMs);
|
|
16
22
|
}
|
|
17
23
|
|
|
24
|
+
function isPidAlive(pid) {
|
|
25
|
+
const resolvedPid = Number(pid);
|
|
26
|
+
if (!Number.isFinite(resolvedPid) || resolvedPid <= 0) return false;
|
|
27
|
+
try {
|
|
28
|
+
process.kill(resolvedPid, 0);
|
|
29
|
+
return true;
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function resolveHeadlessHubUrl(hubUrl) {
|
|
36
|
+
const normalized = normalizeHubBaseUrl(hubUrl);
|
|
37
|
+
if (normalized) return normalized;
|
|
38
|
+
|
|
39
|
+
const stateUrl = normalizeHubBaseUrl(readState()?.url);
|
|
40
|
+
if (stateUrl) return stateUrl;
|
|
41
|
+
|
|
42
|
+
const envHubUrl = normalizeHubBaseUrl(process.env.TFX_HUB_URL);
|
|
43
|
+
if (envHubUrl) return envHubUrl;
|
|
44
|
+
|
|
45
|
+
const envPort = Number(process.env.TFX_HUB_PORT || "27888");
|
|
46
|
+
const port = Number.isFinite(envPort) && envPort > 0 ? envPort : 27888;
|
|
47
|
+
return `http://127.0.0.1:${port}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function hasLiveHubState() {
|
|
51
|
+
const state = readState();
|
|
52
|
+
return !!normalizeHubBaseUrl(state?.url) && isPidAlive(state?.pid);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function toHeadlessSessionAgentId(sessionName) {
|
|
56
|
+
const normalizedSessionName = String(sessionName || "").trim();
|
|
57
|
+
return normalizedSessionName ? `session:${normalizedSessionName}` : "";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function dispatchHeadlessCommand(command, callbacks) {
|
|
61
|
+
const callbackMap = {
|
|
62
|
+
pause: callbacks.onPause,
|
|
63
|
+
resume: callbacks.onResume,
|
|
64
|
+
abort: callbacks.onAbort,
|
|
65
|
+
reassign: callbacks.onReassign,
|
|
66
|
+
};
|
|
67
|
+
const handler = callbackMap[command?.command];
|
|
68
|
+
if (typeof handler === "function") {
|
|
69
|
+
await handler(command);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
18
73
|
async function safeJson(res) {
|
|
19
74
|
try {
|
|
20
75
|
return await res.json();
|
|
@@ -24,8 +79,13 @@ async function safeJson(res) {
|
|
|
24
79
|
}
|
|
25
80
|
|
|
26
81
|
function normalizeLeadCommandMessage(message) {
|
|
27
|
-
const payload =
|
|
28
|
-
|
|
82
|
+
const payload =
|
|
83
|
+
message?.payload && typeof message.payload === "object"
|
|
84
|
+
? message.payload
|
|
85
|
+
: {};
|
|
86
|
+
const command = String(payload.command || "")
|
|
87
|
+
.trim()
|
|
88
|
+
.toLowerCase();
|
|
29
89
|
if (!command) return null;
|
|
30
90
|
return {
|
|
31
91
|
messageId: message.id || null,
|
|
@@ -79,7 +139,9 @@ export async function subscribeToLeadCommands({
|
|
|
79
139
|
});
|
|
80
140
|
|
|
81
141
|
const body = await safeJson(res);
|
|
82
|
-
const messages = Array.isArray(body?.data?.messages)
|
|
142
|
+
const messages = Array.isArray(body?.data?.messages)
|
|
143
|
+
? body.data.messages
|
|
144
|
+
: [];
|
|
83
145
|
const commands = messages
|
|
84
146
|
.filter((message) => message?.topic === "lead.control")
|
|
85
147
|
.map(normalizeLeadCommandMessage)
|
|
@@ -108,6 +170,90 @@ export async function subscribeToLeadCommands({
|
|
|
108
170
|
}
|
|
109
171
|
}
|
|
110
172
|
|
|
173
|
+
export function createHeadlessControlSubscriber(
|
|
174
|
+
sessionName,
|
|
175
|
+
{
|
|
176
|
+
onPause,
|
|
177
|
+
onResume,
|
|
178
|
+
onAbort,
|
|
179
|
+
onReassign,
|
|
180
|
+
hubUrl,
|
|
181
|
+
pollIntervalMs = DEFAULT_HEADLESS_POLL_MS,
|
|
182
|
+
maxMessages = 10,
|
|
183
|
+
autoAck = true,
|
|
184
|
+
timeoutMs = DEFAULT_TIMEOUT_MS,
|
|
185
|
+
fetchImpl,
|
|
186
|
+
} = {},
|
|
187
|
+
) {
|
|
188
|
+
const sessionAgentId = toHeadlessSessionAgentId(sessionName);
|
|
189
|
+
if (!sessionAgentId) {
|
|
190
|
+
return { stop() {} };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const explicitHubUrl =
|
|
194
|
+
normalizeHubBaseUrl(hubUrl) || normalizeHubBaseUrl(process.env.TFX_HUB_URL);
|
|
195
|
+
if (!explicitHubUrl && !hasLiveHubState()) {
|
|
196
|
+
return { stop() {} };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const resolvedHubUrl = explicitHubUrl || resolveHeadlessHubUrl(hubUrl);
|
|
200
|
+
const callbacks = { onPause, onResume, onAbort, onReassign };
|
|
201
|
+
const intervalMs = Math.max(
|
|
202
|
+
50,
|
|
203
|
+
Number(pollIntervalMs) || DEFAULT_HEADLESS_POLL_MS,
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
let stopped = false;
|
|
207
|
+
let timer = null;
|
|
208
|
+
let pending = false;
|
|
209
|
+
|
|
210
|
+
const stop = () => {
|
|
211
|
+
stopped = true;
|
|
212
|
+
if (timer) clearTimeout(timer);
|
|
213
|
+
timer = null;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const scheduleNext = () => {
|
|
217
|
+
if (stopped) return;
|
|
218
|
+
timer = setTimeout(tick, intervalMs);
|
|
219
|
+
if (typeof timer?.unref === "function") timer.unref();
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const tick = async () => {
|
|
223
|
+
if (stopped || pending) {
|
|
224
|
+
scheduleNext();
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
pending = true;
|
|
229
|
+
try {
|
|
230
|
+
const result = await subscribeToLeadCommands({
|
|
231
|
+
hubUrl: resolvedHubUrl,
|
|
232
|
+
agentId: sessionAgentId,
|
|
233
|
+
maxMessages,
|
|
234
|
+
autoAck,
|
|
235
|
+
timeoutMs,
|
|
236
|
+
fetchImpl,
|
|
237
|
+
onCommand: async (command) => {
|
|
238
|
+
await dispatchHeadlessCommand(command, callbacks);
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
if (!result?.ok && result?.error === "LEAD_COMMAND_SUBSCRIBE_FAILED") {
|
|
243
|
+
stop();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
} finally {
|
|
247
|
+
pending = false;
|
|
248
|
+
scheduleNext();
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
void tick();
|
|
253
|
+
|
|
254
|
+
return { stop };
|
|
255
|
+
}
|
|
256
|
+
|
|
111
257
|
export async function getTeamStatus({
|
|
112
258
|
hubUrl,
|
|
113
259
|
scope = "hub",
|
|
@@ -127,7 +273,8 @@ export async function getTeamStatus({
|
|
|
127
273
|
return { ok: false, error: "HUB_URL_REQUIRED" };
|
|
128
274
|
}
|
|
129
275
|
|
|
130
|
-
const normalizedMethod =
|
|
276
|
+
const normalizedMethod =
|
|
277
|
+
String(method || "GET").toUpperCase() === "POST" ? "POST" : "GET";
|
|
131
278
|
const statusScope = String(scope || "hub").trim() || "hub";
|
|
132
279
|
|
|
133
280
|
let endpoint = `${hubBase}/bridge/status`;
|