






















11import fs from "node:fs/promises";
2-import { stringEnum } from "openclaw/plugin-sdk/channel-actions";
2+import { optionalFiniteNumberSchema, stringEnum } from "openclaw/plugin-sdk/channel-actions";
33import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
4+import { readFiniteNumberParam } from "openclaw/plugin-sdk/param-readers";
45import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
56import { Type } from "typebox";
67import type { Static } from "typebox";
@@ -82,20 +83,16 @@ const DiffsToolSchema = Type.Object(
8283fileFormat: Type.Optional(
8384stringEnum(DIFF_OUTPUT_FORMATS, { description: "Rendered file format: png or pdf." }),
8485),
85-fileScale: Type.Optional(
86-Type.Number({
87-description: "Optional rendered-file device scale factor override (1-4).",
88-minimum: 1,
89-maximum: 4,
90-}),
91-),
92-fileMaxWidth: Type.Optional(
93-Type.Number({
94-description: "Optional rendered-file max width in CSS pixels (640-2400).",
95-minimum: 640,
96-maximum: 2400,
97-}),
98-),
86+fileScale: optionalFiniteNumberSchema({
87+description: "Optional rendered-file device scale factor override (1-4).",
88+minimum: 1,
89+maximum: 4,
90+}),
91+fileMaxWidth: optionalFiniteNumberSchema({
92+description: "Optional rendered-file max width in CSS pixels (640-2400).",
93+minimum: 640,
94+maximum: 2400,
95+}),
9996/** @deprecated Use fileQuality. */
10097imageQuality: Type.Optional(
10198stringEnum(DIFF_IMAGE_QUALITY_PRESETS, {
@@ -111,33 +108,27 @@ const DiffsToolSchema = Type.Object(
111108}),
112109),
113110/** @deprecated Use fileScale. */
114-imageScale: Type.Optional(
115-Type.Number({
116-description: "Deprecated alias for fileScale.",
117-deprecated: true,
118-minimum: 1,
119-maximum: 4,
120-}),
121-),
111+imageScale: optionalFiniteNumberSchema({
112+description: "Deprecated alias for fileScale.",
113+deprecated: true,
114+minimum: 1,
115+maximum: 4,
116+}),
122117/** @deprecated Use fileMaxWidth. */
123-imageMaxWidth: Type.Optional(
124-Type.Number({
125-description: "Deprecated alias for fileMaxWidth.",
126-deprecated: true,
127-minimum: 640,
128-maximum: 2400,
129-}),
130-),
118+imageMaxWidth: optionalFiniteNumberSchema({
119+description: "Deprecated alias for fileMaxWidth.",
120+deprecated: true,
121+minimum: 640,
122+maximum: 2400,
123+}),
131124expandUnchanged: Type.Optional(
132125Type.Boolean({ description: "Expand unchanged sections instead of collapsing them." }),
133126),
134-ttlSeconds: Type.Optional(
135-Type.Number({
136-description: "Artifact lifetime in seconds. Default: 1800. Maximum: 21600.",
137-minimum: 1,
138-maximum: 21_600,
139-}),
140-),
127+ttlSeconds: optionalFiniteNumberSchema({
128+description: "Artifact lifetime in seconds. Default: 1800. Maximum: 21600.",
129+minimum: 1,
130+maximum: 21_600,
131+}),
141132baseUrl: Type.Optional(
142133Type.String({
143134description:
@@ -171,21 +162,30 @@ export function createDiffsTool(params: {
171162parameters: DiffsToolSchema,
172163execute: async (_toolCallId, rawParams) => {
173164const toolParams = rawParams as DiffsToolRawParams;
165+const rawRecord = rawParams as Record<string, unknown>;
174166const artifactContext = buildArtifactContext(params.context);
175167const input = normalizeDiffInput(toolParams);
176168const mode = normalizeMode(toolParams.mode, params.defaults.mode);
177169const theme = normalizeTheme(toolParams.theme, params.defaults.theme);
178170const layout = normalizeLayout(toolParams.layout, params.defaults.layout);
179171const expandUnchanged = toolParams.expandUnchanged === true;
180-const ttlMs = normalizeTtlMs(toolParams.ttlSeconds ?? params.defaults.ttlSeconds);
172+const ttlSeconds =
173+readFiniteNumberParam(rawRecord, "ttlSeconds") ?? params.defaults.ttlSeconds;
174+const fileScale =
175+readFiniteNumberParam(rawRecord, "fileScale") ??
176+readFiniteNumberParam(rawRecord, "imageScale");
177+const fileMaxWidth =
178+readFiniteNumberParam(rawRecord, "fileMaxWidth") ??
179+readFiniteNumberParam(rawRecord, "imageMaxWidth");
180+const ttlMs = normalizeTtlMs(ttlSeconds);
181181const image = resolveDiffImageRenderOptions({
182182defaults: params.defaults,
183183fileFormat: normalizeOutputFormat(
184184toolParams.fileFormat ?? toolParams.imageFormat ?? toolParams.format,
185185),
186186fileQuality: normalizeFileQuality(toolParams.fileQuality ?? toolParams.imageQuality),
187-fileScale: toolParams.fileScale ?? toolParams.imageScale,
188-fileMaxWidth: toolParams.fileMaxWidth ?? toolParams.imageMaxWidth,
187+ fileScale,
188+ fileMaxWidth,
189189});
190190const renderTarget = resolveRenderTarget(mode);
191191此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。