mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
TUI: honor explicit session key in global scope
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveFinalAssistantText } from "./tui.js";
|
||||
import { resolveFinalAssistantText, resolveTuiSessionKey } from "./tui.js";
|
||||
|
||||
describe("resolveFinalAssistantText", () => {
|
||||
it("falls back to streamed text when final text is empty", () => {
|
||||
@@ -15,3 +15,35 @@ describe("resolveFinalAssistantText", () => {
|
||||
).toBe("All done");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveTuiSessionKey", () => {
|
||||
it("uses global only as the default when scope is global", () => {
|
||||
expect(
|
||||
resolveTuiSessionKey({
|
||||
raw: "",
|
||||
sessionScope: "global",
|
||||
currentAgentId: "main",
|
||||
sessionMainKey: "agent:main:main",
|
||||
}),
|
||||
).toBe("global");
|
||||
expect(
|
||||
resolveTuiSessionKey({
|
||||
raw: "test123",
|
||||
sessionScope: "global",
|
||||
currentAgentId: "main",
|
||||
sessionMainKey: "agent:main:main",
|
||||
}),
|
||||
).toBe("agent:main:test123");
|
||||
});
|
||||
|
||||
it("keeps explicit agent-prefixed keys unchanged", () => {
|
||||
expect(
|
||||
resolveTuiSessionKey({
|
||||
raw: "agent:ops:incident",
|
||||
sessionScope: "global",
|
||||
currentAgentId: "main",
|
||||
sessionMainKey: "agent:main:main",
|
||||
}),
|
||||
).toBe("agent:ops:incident");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -77,6 +77,31 @@ export function createEditorSubmitHandler(params: {
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveTuiSessionKey(params: {
|
||||
raw?: string;
|
||||
sessionScope: SessionScope;
|
||||
currentAgentId: string;
|
||||
sessionMainKey: string;
|
||||
}) {
|
||||
const trimmed = (params.raw ?? "").trim();
|
||||
if (!trimmed) {
|
||||
if (params.sessionScope === "global") {
|
||||
return "global";
|
||||
}
|
||||
return buildAgentMainSessionKey({
|
||||
agentId: params.currentAgentId,
|
||||
mainKey: params.sessionMainKey,
|
||||
});
|
||||
}
|
||||
if (trimmed === "global" || trimmed === "unknown") {
|
||||
return trimmed;
|
||||
}
|
||||
if (trimmed.startsWith("agent:")) {
|
||||
return trimmed;
|
||||
}
|
||||
return `agent:${params.currentAgentId}:${trimmed}`;
|
||||
}
|
||||
|
||||
export async function runTui(opts: TuiOptions) {
|
||||
const config = loadConfig();
|
||||
const initialSessionInput = (opts.session ?? "").trim();
|
||||
@@ -298,23 +323,12 @@ export async function runTui(opts: TuiOptions) {
|
||||
};
|
||||
|
||||
const resolveSessionKey = (raw?: string) => {
|
||||
const trimmed = (raw ?? "").trim();
|
||||
if (sessionScope === "global") {
|
||||
return "global";
|
||||
}
|
||||
if (!trimmed) {
|
||||
return buildAgentMainSessionKey({
|
||||
agentId: currentAgentId,
|
||||
mainKey: sessionMainKey,
|
||||
});
|
||||
}
|
||||
if (trimmed === "global" || trimmed === "unknown") {
|
||||
return trimmed;
|
||||
}
|
||||
if (trimmed.startsWith("agent:")) {
|
||||
return trimmed;
|
||||
}
|
||||
return `agent:${currentAgentId}:${trimmed}`;
|
||||
return resolveTuiSessionKey({
|
||||
raw,
|
||||
sessionScope,
|
||||
currentAgentId,
|
||||
sessionMainKey,
|
||||
});
|
||||
};
|
||||
|
||||
currentSessionKey = resolveSessionKey(initialSessionInput);
|
||||
|
||||
Reference in New Issue
Block a user