Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
83 lines
2.4 KiB
JavaScript
83 lines
2.4 KiB
JavaScript
"use strict";
|
|
|
|
const { TERMINAL_OUTPUT_PORT_CHANNEL } = require("../bridges/terminalOutputChannel.cjs");
|
|
const {
|
|
hasPluginPipelineIngressMarker,
|
|
} = require("./terminalDataBacklog.cjs");
|
|
|
|
function createTerminalOutputPortRegistry(options = {}) {
|
|
const {
|
|
ipcRenderer,
|
|
deliverToListeners,
|
|
filterData = null,
|
|
closedTerminalDataSessions = new Set(),
|
|
onPortError = console.error,
|
|
onDrain = null,
|
|
} = options;
|
|
const ports = new Map();
|
|
|
|
function closeSession(sessionId) {
|
|
const port = ports.get(sessionId);
|
|
if (!port) return;
|
|
try {
|
|
port.close?.();
|
|
} catch {
|
|
// Ignore close races while replacing or closing output ports.
|
|
}
|
|
ports.delete(sessionId);
|
|
}
|
|
|
|
function registerPort(sessionId, port) {
|
|
if (!sessionId || !port) return;
|
|
closeSession(sessionId);
|
|
ports.set(sessionId, port);
|
|
port.onmessage = (event) => {
|
|
const message = event?.data || {};
|
|
const targetSessionId = message.sessionId || sessionId;
|
|
if (message.kind === "drain" && message.requestId) {
|
|
onDrain?.(targetSessionId, message.requestId);
|
|
return;
|
|
}
|
|
if (closedTerminalDataSessions.has(targetSessionId)) return;
|
|
if (!message.data && !hasPluginPipelineIngressMarker(message.meta)) return;
|
|
try {
|
|
const filtered = typeof filterData === "function"
|
|
? filterData(targetSessionId, message.data, message)
|
|
: message.data;
|
|
const data = filtered && typeof filtered === "object" && "data" in filtered
|
|
? filtered.data
|
|
: filtered;
|
|
const meta = filtered && typeof filtered === "object" && "data" in filtered
|
|
? filtered.meta
|
|
: message.meta;
|
|
if (data || hasPluginPipelineIngressMarker(meta)) {
|
|
deliverToListeners?.(targetSessionId, data ?? "", meta);
|
|
}
|
|
} catch (err) {
|
|
onPortError("Terminal output port callback failed", err);
|
|
}
|
|
};
|
|
}
|
|
|
|
function register() {
|
|
ipcRenderer?.on?.(TERMINAL_OUTPUT_PORT_CHANNEL, (event, payload) => {
|
|
registerPort(payload?.sessionId, event?.ports?.[0]);
|
|
});
|
|
}
|
|
|
|
return {
|
|
register,
|
|
closeSession,
|
|
closeAll() {
|
|
for (const sessionId of Array.from(ports.keys())) {
|
|
closeSession(sessionId);
|
|
}
|
|
},
|
|
hasSessionForTest: (sessionId) => ports.has(sessionId),
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
createTerminalOutputPortRegistry,
|
|
};
|