mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-10 00:11:19 +00:00
fix(sdk): honor session send timeouts
This commit is contained in:
parent
84a36057e9
commit
7d658dfd97
2 changed files with 18 additions and 4 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue