mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-29 16:54:30 +00:00
refactor(auto-reply): reuse abort session-entry resolver
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
isAbortRequestText,
|
||||
isAbortTrigger,
|
||||
resetAbortMemoryForTest,
|
||||
resolveSessionEntryForKey,
|
||||
setAbortMemory,
|
||||
tryFastAbortFromMessage,
|
||||
} from "./abort.js";
|
||||
@@ -128,6 +129,18 @@ describe("abort detection", () => {
|
||||
expect(getAbortMemory("session-2104")).toBe(true);
|
||||
});
|
||||
|
||||
it("resolves session entry when key exists in store", () => {
|
||||
const store = {
|
||||
"session-1": { sessionId: "abc", updatedAt: 0 },
|
||||
} as const;
|
||||
expect(resolveSessionEntryForKey(store, "session-1")).toEqual({
|
||||
entry: store["session-1"],
|
||||
key: "session-1",
|
||||
});
|
||||
expect(resolveSessionEntryForKey(store, "session-2")).toEqual({});
|
||||
expect(resolveSessionEntryForKey(undefined, "session-1")).toEqual({});
|
||||
});
|
||||
|
||||
it("fast-aborts even when text commands are disabled", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-abort-"));
|
||||
const storePath = path.join(root, "sessions.json");
|
||||
|
||||
@@ -102,7 +102,7 @@ export function formatAbortReplyText(stoppedSubagents?: number): string {
|
||||
return `⚙️ Agent was aborted. Stopped ${stoppedSubagents} ${label}.`;
|
||||
}
|
||||
|
||||
function resolveSessionEntryForKey(
|
||||
export function resolveSessionEntryForKey(
|
||||
store: Record<string, SessionEntry> | undefined,
|
||||
sessionKey: string | undefined,
|
||||
) {
|
||||
|
||||
@@ -12,26 +12,13 @@ import { normalizeUsageDisplay, resolveResponseUsageMode } from "../thinking.js"
|
||||
import {
|
||||
formatAbortReplyText,
|
||||
isAbortTrigger,
|
||||
resolveSessionEntryForKey,
|
||||
setAbortMemory,
|
||||
stopSubagentsForRequester,
|
||||
} from "./abort.js";
|
||||
import type { CommandHandler } from "./commands-types.js";
|
||||
import { clearSessionQueues } from "./queue.js";
|
||||
|
||||
function resolveSessionEntryForKey(
|
||||
store: Record<string, SessionEntry> | undefined,
|
||||
sessionKey: string | undefined,
|
||||
) {
|
||||
if (!store || !sessionKey) {
|
||||
return {};
|
||||
}
|
||||
const direct = store[sessionKey];
|
||||
if (direct) {
|
||||
return { entry: direct, key: sessionKey };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
function resolveAbortTarget(params: {
|
||||
ctx: { CommandTargetSessionKey?: string | null };
|
||||
sessionKey?: string;
|
||||
|
||||
Reference in New Issue
Block a user