mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 17:20:45 +00:00
refactor(gateway-tool): share write metadata parsing
This commit is contained in:
@@ -138,6 +138,24 @@ export function createGatewayTool(opts?: {
|
|||||||
: undefined;
|
: undefined;
|
||||||
const gatewayOpts = { gatewayUrl, gatewayToken, timeoutMs };
|
const gatewayOpts = { gatewayUrl, gatewayToken, timeoutMs };
|
||||||
|
|
||||||
|
const resolveGatewayWriteMeta = (): {
|
||||||
|
sessionKey: string | undefined;
|
||||||
|
note: string | undefined;
|
||||||
|
restartDelayMs: number | undefined;
|
||||||
|
} => {
|
||||||
|
const sessionKey =
|
||||||
|
typeof params.sessionKey === "string" && params.sessionKey.trim()
|
||||||
|
? params.sessionKey.trim()
|
||||||
|
: opts?.agentSessionKey?.trim() || undefined;
|
||||||
|
const note =
|
||||||
|
typeof params.note === "string" && params.note.trim() ? params.note.trim() : undefined;
|
||||||
|
const restartDelayMs =
|
||||||
|
typeof params.restartDelayMs === "number" && Number.isFinite(params.restartDelayMs)
|
||||||
|
? Math.floor(params.restartDelayMs)
|
||||||
|
: undefined;
|
||||||
|
return { sessionKey, note, restartDelayMs };
|
||||||
|
};
|
||||||
|
|
||||||
const resolveConfigWriteParams = async (): Promise<{
|
const resolveConfigWriteParams = async (): Promise<{
|
||||||
raw: string;
|
raw: string;
|
||||||
baseHash: string;
|
baseHash: string;
|
||||||
@@ -154,17 +172,7 @@ export function createGatewayTool(opts?: {
|
|||||||
if (!baseHash) {
|
if (!baseHash) {
|
||||||
throw new Error("Missing baseHash from config snapshot.");
|
throw new Error("Missing baseHash from config snapshot.");
|
||||||
}
|
}
|
||||||
const sessionKey =
|
return { raw, baseHash, ...resolveGatewayWriteMeta() };
|
||||||
typeof params.sessionKey === "string" && params.sessionKey.trim()
|
|
||||||
? params.sessionKey.trim()
|
|
||||||
: opts?.agentSessionKey?.trim() || undefined;
|
|
||||||
const note =
|
|
||||||
typeof params.note === "string" && params.note.trim() ? params.note.trim() : undefined;
|
|
||||||
const restartDelayMs =
|
|
||||||
typeof params.restartDelayMs === "number" && Number.isFinite(params.restartDelayMs)
|
|
||||||
? Math.floor(params.restartDelayMs)
|
|
||||||
: undefined;
|
|
||||||
return { raw, baseHash, sessionKey, note, restartDelayMs };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (action === "config.get") {
|
if (action === "config.get") {
|
||||||
@@ -200,16 +208,7 @@ export function createGatewayTool(opts?: {
|
|||||||
return jsonResult({ ok: true, result });
|
return jsonResult({ ok: true, result });
|
||||||
}
|
}
|
||||||
if (action === "update.run") {
|
if (action === "update.run") {
|
||||||
const sessionKey =
|
const { sessionKey, note, restartDelayMs } = resolveGatewayWriteMeta();
|
||||||
typeof params.sessionKey === "string" && params.sessionKey.trim()
|
|
||||||
? params.sessionKey.trim()
|
|
||||||
: opts?.agentSessionKey?.trim() || undefined;
|
|
||||||
const note =
|
|
||||||
typeof params.note === "string" && params.note.trim() ? params.note.trim() : undefined;
|
|
||||||
const restartDelayMs =
|
|
||||||
typeof params.restartDelayMs === "number" && Number.isFinite(params.restartDelayMs)
|
|
||||||
? Math.floor(params.restartDelayMs)
|
|
||||||
: undefined;
|
|
||||||
const updateGatewayOpts = {
|
const updateGatewayOpts = {
|
||||||
...gatewayOpts,
|
...gatewayOpts,
|
||||||
timeoutMs: timeoutMs ?? DEFAULT_UPDATE_TIMEOUT_MS,
|
timeoutMs: timeoutMs ?? DEFAULT_UPDATE_TIMEOUT_MS,
|
||||||
|
|||||||
Reference in New Issue
Block a user