1+ import {
2+ optionalFiniteNumberSchema ,
3+ optionalNonNegativeIntegerSchema ,
4+ optionalPositiveIntegerSchema ,
5+ stringEnum ,
6+ } from "openclaw/plugin-sdk/channel-actions" ;
17import { Type } from "typebox" ;
28
39export const CANVAS_ACTIONS = [
@@ -12,30 +18,23 @@ export const CANVAS_ACTIONS = [
1218
1319export const CANVAS_SNAPSHOT_FORMATS = [ "png" , "jpg" , "jpeg" ] as const ;
1420
15- function stringEnum < T extends readonly string [ ] > ( values : T ) {
16- return Type . Unsafe < T [ number ] > ( {
17- type : "string" ,
18- enum : [ ...values ] ,
19- } ) ;
20- }
21-
2221export const CanvasToolSchema = Type . Object ( {
2322 action : stringEnum ( CANVAS_ACTIONS ) ,
2423 gatewayUrl : Type . Optional ( Type . String ( ) ) ,
2524 gatewayToken : Type . Optional ( Type . String ( ) ) ,
26- timeoutMs : Type . Optional ( Type . Number ( ) ) ,
25+ timeoutMs : optionalPositiveIntegerSchema ( ) ,
2726 node : Type . Optional ( Type . String ( ) ) ,
2827 target : Type . Optional ( Type . String ( ) ) ,
29- x : Type . Optional ( Type . Number ( ) ) ,
30- y : Type . Optional ( Type . Number ( ) ) ,
31- width : Type . Optional ( Type . Number ( ) ) ,
32- height : Type . Optional ( Type . Number ( ) ) ,
28+ x : optionalFiniteNumberSchema ( ) ,
29+ y : optionalFiniteNumberSchema ( ) ,
30+ width : optionalFiniteNumberSchema ( ) ,
31+ height : optionalFiniteNumberSchema ( ) ,
3332 url : Type . Optional ( Type . String ( ) ) ,
3433 javaScript : Type . Optional ( Type . String ( ) ) ,
3534 outputFormat : Type . Optional ( stringEnum ( CANVAS_SNAPSHOT_FORMATS ) ) ,
36- maxWidth : Type . Optional ( Type . Number ( ) ) ,
37- quality : Type . Optional ( Type . Number ( ) ) ,
38- delayMs : Type . Optional ( Type . Number ( ) ) ,
35+ maxWidth : optionalPositiveIntegerSchema ( ) ,
36+ quality : optionalFiniteNumberSchema ( { minimum : 0 , maximum : 1 } ) ,
37+ delayMs : optionalNonNegativeIntegerSchema ( ) ,
3938 jsonl : Type . Optional ( Type . String ( ) ) ,
4039 jsonlPath : Type . Optional ( Type . String ( ) ) ,
4140} ) ;
0 commit comments