fix(sdk): honor session send timeouts

This commit is contained in:
Vincent Koc 2026-06-20 06:18:09 +02:00
parent 84a36057e9
commit 7d658dfd97
No known key found for this signature in database
2 changed files with 18 additions and 4 deletions

View file

@ -695,7 +695,14 @@ export class Session {
async send(input: string | Omit<SessionSendParams, "key">): Promise<Run> {
const params: SessionSendParams =
typeof input === "string" ? { key: this.key, message: input } : { ...input, key: this.key };
const raw = await this.client.request("sessions.send", params, { expectFinal: true });
const timeoutMs = normalizeTimeoutMs(params.timeoutMs);
if (timeoutMs !== undefined) {
params.timeoutMs = timeoutMs;
}
const raw = await this.client.request("sessions.send", params, {
expectFinal: true,
...(timeoutMs !== undefined ? { timeoutMs: timeoutMs === 0 ? null : timeoutMs } : {}),
});
const record = asRecord(raw);
const runId = readOptionalString(record.runId);
if (!runId) {

View file

@ -1339,9 +1339,11 @@ describe("OpenClaw SDK", () => {
const oc = new OpenClaw({ transport });
const session = await oc.sessions.create({ key: "session-main" });
const run = await session.send({ message: "continue", thinking: "medium" });
const run = await session.send({ message: "continue", thinking: "medium", timeoutMs: 1_500 });
const noTimeoutRun = await session.send({ message: "continue without timeout", timeoutMs: 0 });
expect(run.id).toBe("run_session");
expect(noTimeoutRun.id).toBe("run_session");
expect(transport.calls).toEqual([
{
method: "sessions.create",
@ -1350,8 +1352,13 @@ describe("OpenClaw SDK", () => {
},
{
method: "sessions.send",
options: { expectFinal: true },
params: { key: "session-main", message: "continue", thinking: "medium" },
options: { expectFinal: true, timeoutMs: 1_500 },
params: { key: "session-main", message: "continue", thinking: "medium", timeoutMs: 1_500 },
},
{
method: "sessions.send",
options: { expectFinal: true, timeoutMs: null },
params: { key: "session-main", message: "continue without timeout", timeoutMs: 0 },
},
]);
});