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