mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 16:44:33 +00:00
Cron: normalize cron.add inputs + align channels (#256)
* fix: harden cron add and align channels * fix: keep cron tool id params --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -2,6 +2,13 @@ import { Type } from "@sinclair/typebox";
|
||||
|
||||
import { type AnyAgentTool, jsonResult, readStringParam } from "./common.js";
|
||||
import { callGatewayTool, type GatewayCallOptions } from "./gateway.js";
|
||||
import { CronAddParamsSchema } from "../../gateway/protocol/schema.js";
|
||||
import {
|
||||
normalizeCronJobCreate,
|
||||
normalizeCronJobPatch,
|
||||
} from "../../cron/normalize.js";
|
||||
|
||||
const CronJobPatchSchema = Type.Partial(CronAddParamsSchema);
|
||||
|
||||
const CronToolSchema = Type.Union([
|
||||
Type.Object({
|
||||
@@ -22,7 +29,7 @@ const CronToolSchema = Type.Union([
|
||||
gatewayUrl: Type.Optional(Type.String()),
|
||||
gatewayToken: Type.Optional(Type.String()),
|
||||
timeoutMs: Type.Optional(Type.Number()),
|
||||
job: Type.Object({}, { additionalProperties: true }),
|
||||
job: CronAddParamsSchema,
|
||||
}),
|
||||
Type.Object({
|
||||
action: Type.Literal("update"),
|
||||
@@ -30,7 +37,7 @@ const CronToolSchema = Type.Union([
|
||||
gatewayToken: Type.Optional(Type.String()),
|
||||
timeoutMs: Type.Optional(Type.Number()),
|
||||
id: Type.String(),
|
||||
patch: Type.Object({}, { additionalProperties: true }),
|
||||
patch: CronJobPatchSchema,
|
||||
}),
|
||||
Type.Object({
|
||||
action: Type.Literal("remove"),
|
||||
@@ -97,8 +104,9 @@ export function createCronTool(): AnyAgentTool {
|
||||
if (!params.job || typeof params.job !== "object") {
|
||||
throw new Error("job required");
|
||||
}
|
||||
const job = normalizeCronJobCreate(params.job) ?? params.job;
|
||||
return jsonResult(
|
||||
await callGatewayTool("cron.add", gatewayOpts, params.job),
|
||||
await callGatewayTool("cron.add", gatewayOpts, job),
|
||||
);
|
||||
}
|
||||
case "update": {
|
||||
@@ -106,10 +114,11 @@ export function createCronTool(): AnyAgentTool {
|
||||
if (!params.patch || typeof params.patch !== "object") {
|
||||
throw new Error("patch required");
|
||||
}
|
||||
const patch = normalizeCronJobPatch(params.patch) ?? params.patch;
|
||||
return jsonResult(
|
||||
await callGatewayTool("cron.update", gatewayOpts, {
|
||||
id,
|
||||
patch: params.patch,
|
||||
patch,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user