

























@@ -17,8 +17,13 @@ import { createSubsystemLogger } from "../../logging/subsystem.js";
1717import { collectEnabledInsecureOrDangerousFlags } from "../../security/dangerous-config-flags.js";
1818import { isRecord as isPlainObject } from "../../shared/record-coerce.js";
1919import { normalizeOptionalString, readStringValue } from "../../shared/string-coerce.js";
20-import { stringEnum } from "../schema/typebox.js";
21-import { type AnyAgentTool, jsonResult, readStringParam } from "./common.js";
20+import { optionalNonNegativeIntegerSchema, stringEnum } from "../schema/typebox.js";
21+import {
22+type AnyAgentTool,
23+jsonResult,
24+readNonNegativeIntegerParam,
25+readStringParam,
26+} from "./common.js";
2227import { callGatewayTool, readGatewayCallOptions } from "./gateway.js";
23282429const log = createSubsystemLogger("gateway-tool");
@@ -337,7 +342,7 @@ const GATEWAY_ACTIONS = [
337342const GatewayToolSchema = Type.Object({
338343action: stringEnum(GATEWAY_ACTIONS),
339344// restart
340-delayMs: Type.Optional(Type.Number()),
345+delayMs: optionalNonNegativeIntegerSchema(),
341346reason: Type.Optional(Type.String()),
342347continuationMessage: Type.Optional(Type.String()),
343348// config.get, config.schema.lookup, config.apply, update.run
@@ -352,7 +357,7 @@ const GatewayToolSchema = Type.Object({
352357// config.apply, config.patch, update.run
353358sessionKey: Type.Optional(Type.String()),
354359note: Type.Optional(Type.String()),
355-restartDelayMs: Type.Optional(Type.Number()),
360+restartDelayMs: optionalNonNegativeIntegerSchema(),
356361});
357362// NOTE: We intentionally avoid top-level `allOf`/`anyOf`/`oneOf` conditionals here:
358363// - OpenAI rejects tool schemas that include these keywords at the *top-level*.
@@ -379,10 +384,7 @@ export function createGatewayTool(opts?: {
379384const sessionKey =
380385normalizeOptionalString(params.sessionKey) ??
381386normalizeOptionalString(opts?.agentSessionKey);
382-const delayMs =
383-typeof params.delayMs === "number" && Number.isFinite(params.delayMs)
384- ? Math.floor(params.delayMs)
385- : undefined;
387+const delayMs = readNonNegativeIntegerParam(params, "delayMs");
386388const reason = normalizeOptionalString(params.reason)?.slice(0, 200);
387389const note = normalizeOptionalString(params.note);
388390const continuationMessage = normalizeOptionalString(params.continuationMessage);
@@ -437,10 +439,7 @@ export function createGatewayTool(opts?: {
437439normalizeOptionalString(params.sessionKey) ??
438440normalizeOptionalString(opts?.agentSessionKey);
439441const note = normalizeOptionalString(params.note);
440-const restartDelayMs =
441-typeof params.restartDelayMs === "number" && Number.isFinite(params.restartDelayMs)
442- ? Math.floor(params.restartDelayMs)
443- : undefined;
442+const restartDelayMs = readNonNegativeIntegerParam(params, "restartDelayMs");
444443return { sessionKey, note, restartDelayMs };
445444};
446445此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。