mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 21:10:48 +00:00
Share opt-in, reversible privacy masking through main-owned policy and conversation maps across Catty, integrated agents, and External MCP. Restore managed arguments before validation, approval, and execution; fail closed on retired policy state. Add shared settings, documentation, boundary and lifecycle regressions. Validated with deterministic regressions, production desktop smoke, clean Codex review and passing cross-platform CI. Closes #3620
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
"use strict";
|
|
|
|
function createSessionService(ctx = {}) {
|
|
const { invokeSessionAgent, validateClose, beforeClose, afterClose, onClosed } = ctx;
|
|
|
|
async function close(params = {}, options = {}) {
|
|
if (!params.sessionId || typeof params.sessionId !== "string") {
|
|
return { ok: false, error: "sessionId is required." };
|
|
}
|
|
if (!options.skipValidation && typeof validateClose === "function") {
|
|
const validation = validateClose(params);
|
|
if (validation && validation.ok === false) return validation;
|
|
}
|
|
if (typeof invokeSessionAgent !== "function") {
|
|
return { ok: false, error: "Session close bridge is unavailable." };
|
|
}
|
|
|
|
let result;
|
|
let closed = false;
|
|
try {
|
|
await beforeClose?.(params);
|
|
options.beforeExecute?.();
|
|
result = await invokeSessionAgent("session.close", { sessionId: params.sessionId });
|
|
if (result?.ok !== false) {
|
|
await onClosed?.(params.sessionId);
|
|
closed = true;
|
|
}
|
|
return result;
|
|
} finally {
|
|
await afterClose?.(params, {
|
|
closed,
|
|
notFound: /\bwas not found\b/i.test(result?.error || ""),
|
|
result,
|
|
});
|
|
}
|
|
}
|
|
|
|
return {
|
|
close: (params = {}, executionContext = {}) => close(params, {
|
|
beforeExecute: executionContext.beforeExecute,
|
|
}),
|
|
closeTracked: (params = {}) => close(params, { skipValidation: true }),
|
|
};
|
|
}
|
|
|
|
module.exports = { createSessionService };
|