web: add globalSeq to AgentEvent and spawnAgentSubscribeProcess helper
This commit is contained in:
parent
0f28afd59b
commit
a6dab967a2
@ -10,6 +10,7 @@ export type AgentEvent = {
|
||||
stream?: string;
|
||||
data?: Record<string, unknown>;
|
||||
seq?: number;
|
||||
globalSeq?: number;
|
||||
ts?: number;
|
||||
sessionKey?: string;
|
||||
status?: string;
|
||||
@ -198,6 +199,43 @@ export function spawnAgentProcess(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn a subscribe-only agent child process that tails a session key's events.
|
||||
* Uses the same runtime/env wiring as spawnAgentProcess.
|
||||
*/
|
||||
export function spawnAgentSubscribeProcess(
|
||||
sessionKey: string,
|
||||
afterSeq = 0,
|
||||
): ReturnType<typeof spawn> {
|
||||
const root = resolvePackageRoot();
|
||||
|
||||
const devScript = join(root, "scripts", "run-node.mjs");
|
||||
const prodScript = join(root, "openclaw.mjs");
|
||||
const scriptPath = existsSync(devScript) ? devScript : prodScript;
|
||||
|
||||
const args = [
|
||||
scriptPath,
|
||||
"agent",
|
||||
"--stream-json",
|
||||
"--subscribe-session-key",
|
||||
sessionKey,
|
||||
"--after-seq",
|
||||
String(Math.max(0, Number.isFinite(afterSeq) ? afterSeq : 0)),
|
||||
];
|
||||
|
||||
const profile = getEffectiveProfile();
|
||||
const workspace = resolveWorkspaceRoot();
|
||||
return spawn("node", args, {
|
||||
cwd: root,
|
||||
env: {
|
||||
...process.env,
|
||||
...(profile ? { OPENCLAW_PROFILE: profile } : {}),
|
||||
...(workspace ? { OPENCLAW_WORKSPACE: workspace } : {}),
|
||||
},
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a flat output object from the agent's tool result so the frontend
|
||||
* can render tool output text, exit codes, etc.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user