mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:41:25 +00:00
refactor(gateway): share restart request parsing
This commit is contained in:
@@ -38,6 +38,7 @@ import {
|
|||||||
validateConfigSetParams,
|
validateConfigSetParams,
|
||||||
} from "../protocol/index.js";
|
} from "../protocol/index.js";
|
||||||
import { resolveBaseHashParam } from "./base-hash.js";
|
import { resolveBaseHashParam } from "./base-hash.js";
|
||||||
|
import { parseRestartRequestParams } from "./restart-request.js";
|
||||||
import { assertValidParams } from "./validation.js";
|
import { assertValidParams } from "./validation.js";
|
||||||
|
|
||||||
function requireConfigBaseHash(
|
function requireConfigBaseHash(
|
||||||
@@ -152,19 +153,7 @@ function resolveConfigRestartRequest(params: unknown): {
|
|||||||
deliveryContext: ReturnType<typeof extractDeliveryInfo>["deliveryContext"];
|
deliveryContext: ReturnType<typeof extractDeliveryInfo>["deliveryContext"];
|
||||||
threadId: ReturnType<typeof extractDeliveryInfo>["threadId"];
|
threadId: ReturnType<typeof extractDeliveryInfo>["threadId"];
|
||||||
} {
|
} {
|
||||||
const sessionKey =
|
const { sessionKey, note, restartDelayMs } = parseRestartRequestParams(params);
|
||||||
typeof (params as { sessionKey?: unknown }).sessionKey === "string"
|
|
||||||
? (params as { sessionKey?: string }).sessionKey?.trim() || undefined
|
|
||||||
: undefined;
|
|
||||||
const note =
|
|
||||||
typeof (params as { note?: unknown }).note === "string"
|
|
||||||
? (params as { note?: string }).note?.trim() || undefined
|
|
||||||
: undefined;
|
|
||||||
const restartDelayMsRaw = (params as { restartDelayMs?: unknown }).restartDelayMs;
|
|
||||||
const restartDelayMs =
|
|
||||||
typeof restartDelayMsRaw === "number" && Number.isFinite(restartDelayMsRaw)
|
|
||||||
? Math.max(0, Math.floor(restartDelayMsRaw))
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
// Extract deliveryContext + threadId for routing after restart
|
// Extract deliveryContext + threadId for routing after restart
|
||||||
// Supports both :thread: (most channels) and :topic: (Telegram)
|
// Supports both :thread: (most channels) and :topic: (Telegram)
|
||||||
|
|||||||
20
src/gateway/server-methods/restart-request.ts
Normal file
20
src/gateway/server-methods/restart-request.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
export function parseRestartRequestParams(params: unknown): {
|
||||||
|
sessionKey: string | undefined;
|
||||||
|
note: string | undefined;
|
||||||
|
restartDelayMs: number | undefined;
|
||||||
|
} {
|
||||||
|
const sessionKey =
|
||||||
|
typeof (params as { sessionKey?: unknown }).sessionKey === "string"
|
||||||
|
? (params as { sessionKey?: string }).sessionKey?.trim() || undefined
|
||||||
|
: undefined;
|
||||||
|
const note =
|
||||||
|
typeof (params as { note?: unknown }).note === "string"
|
||||||
|
? (params as { note?: string }).note?.trim() || undefined
|
||||||
|
: undefined;
|
||||||
|
const restartDelayMsRaw = (params as { restartDelayMs?: unknown }).restartDelayMs;
|
||||||
|
const restartDelayMs =
|
||||||
|
typeof restartDelayMsRaw === "number" && Number.isFinite(restartDelayMsRaw)
|
||||||
|
? Math.max(0, Math.floor(restartDelayMsRaw))
|
||||||
|
: undefined;
|
||||||
|
return { sessionKey, note, restartDelayMs };
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import { scheduleGatewaySigusr1Restart } from "../../infra/restart.js";
|
|||||||
import { normalizeUpdateChannel } from "../../infra/update-channels.js";
|
import { normalizeUpdateChannel } from "../../infra/update-channels.js";
|
||||||
import { runGatewayUpdate } from "../../infra/update-runner.js";
|
import { runGatewayUpdate } from "../../infra/update-runner.js";
|
||||||
import { validateUpdateRunParams } from "../protocol/index.js";
|
import { validateUpdateRunParams } from "../protocol/index.js";
|
||||||
|
import { parseRestartRequestParams } from "./restart-request.js";
|
||||||
import { assertValidParams } from "./validation.js";
|
import { assertValidParams } from "./validation.js";
|
||||||
|
|
||||||
export const updateHandlers: GatewayRequestHandlers = {
|
export const updateHandlers: GatewayRequestHandlers = {
|
||||||
@@ -17,19 +18,7 @@ export const updateHandlers: GatewayRequestHandlers = {
|
|||||||
if (!assertValidParams(params, validateUpdateRunParams, "update.run", respond)) {
|
if (!assertValidParams(params, validateUpdateRunParams, "update.run", respond)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const sessionKey =
|
const { sessionKey, note, restartDelayMs } = parseRestartRequestParams(params);
|
||||||
typeof (params as { sessionKey?: unknown }).sessionKey === "string"
|
|
||||||
? (params as { sessionKey?: string }).sessionKey?.trim() || undefined
|
|
||||||
: undefined;
|
|
||||||
const note =
|
|
||||||
typeof (params as { note?: unknown }).note === "string"
|
|
||||||
? (params as { note?: string }).note?.trim() || undefined
|
|
||||||
: undefined;
|
|
||||||
const restartDelayMsRaw = (params as { restartDelayMs?: unknown }).restartDelayMs;
|
|
||||||
const restartDelayMs =
|
|
||||||
typeof restartDelayMsRaw === "number" && Number.isFinite(restartDelayMsRaw)
|
|
||||||
? Math.max(0, Math.floor(restartDelayMsRaw))
|
|
||||||
: undefined;
|
|
||||||
const timeoutMsRaw = (params as { timeoutMs?: unknown }).timeoutMs;
|
const timeoutMsRaw = (params as { timeoutMs?: unknown }).timeoutMs;
|
||||||
const timeoutMs =
|
const timeoutMs =
|
||||||
typeof timeoutMsRaw === "number" && Number.isFinite(timeoutMsRaw)
|
typeof timeoutMsRaw === "number" && Number.isFinite(timeoutMsRaw)
|
||||||
|
|||||||
Reference in New Issue
Block a user