Skip to content

Commit 87aa319

Browse files
authored
fix(export): preserve explicit trajectory session keys (#83308)
1 parent 567fe29 commit 87aa319

2 files changed

Lines changed: 48 additions & 7 deletions

File tree

src/commands/export-trajectory.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,32 @@ describe("exportTrajectoryCommand", () => {
5757
expect(runtime.exit).toHaveBeenCalledWith(1);
5858
});
5959

60+
it("preserves direct options when an encoded request omits them", async () => {
61+
const runtime = createRuntime();
62+
const requestJsonBase64 = Buffer.from(
63+
JSON.stringify({ output: "/tmp/export.json" }),
64+
"utf8",
65+
).toString("base64url");
66+
67+
await exportTrajectoryCommand(
68+
{
69+
requestJsonBase64,
70+
sessionKey: "agent:main:telegram:direct:123",
71+
store: "/tmp/direct-store.json",
72+
},
73+
runtime,
74+
);
75+
76+
expect(mocks.resolveDefaultSessionStorePath).not.toHaveBeenCalled();
77+
expect(mocks.loadSessionStore).toHaveBeenCalledWith("/tmp/direct-store.json", {
78+
skipCache: true,
79+
});
80+
expect(runtime.error).toHaveBeenCalledWith(
81+
"Session not found: agent:main:telegram:direct:123. Run openclaw sessions to see available sessions.",
82+
);
83+
expect(runtime.exit).toHaveBeenCalledWith(1);
84+
});
85+
6086
it("points missing session users at the sessions command", async () => {
6187
const runtime = createRuntime();
6288

src/commands/export-trajectory.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,28 @@ function decodeExportTrajectoryRequest(encoded: string): Partial<ExportTrajector
5656
throw new Error("Encoded trajectory export request must be a JSON object");
5757
}
5858
const request = decoded as EncodedExportTrajectoryRequest;
59-
return {
60-
sessionKey: readOptionalString(request.sessionKey) ?? "",
61-
output: readOptionalString(request.output),
62-
store: readOptionalString(request.store),
63-
agent: readOptionalString(request.agent),
64-
workspace: readOptionalString(request.workspace),
65-
};
59+
const opts: Partial<ExportTrajectoryCommandOptions> = {};
60+
const sessionKey = readOptionalString(request.sessionKey);
61+
if (sessionKey !== undefined) {
62+
opts.sessionKey = sessionKey;
63+
}
64+
const output = readOptionalString(request.output);
65+
if (output !== undefined) {
66+
opts.output = output;
67+
}
68+
const store = readOptionalString(request.store);
69+
if (store !== undefined) {
70+
opts.store = store;
71+
}
72+
const agent = readOptionalString(request.agent);
73+
if (agent !== undefined) {
74+
opts.agent = agent;
75+
}
76+
const workspace = readOptionalString(request.workspace);
77+
if (workspace !== undefined) {
78+
opts.workspace = workspace;
79+
}
80+
return opts;
6681
}
6782

6883
function resolveExportTrajectoryOptions(

0 commit comments

Comments
 (0)