@@ -10,87 +10,66 @@ import (
1010func generateCustomJobToolDefinition (jobName string , jobConfig * SafeJobConfig ) map [string ]any {
1111 safeOutputsConfigLog .Printf ("Generating tool definition for custom job: %s" , jobName )
1212
13- // Build the tool definition
14- tool := map [ string ] any {
15- "name" : jobName ,
13+ description := jobConfig . Description
14+ if description == "" {
15+ description = fmt . Sprintf ( "Execute the %s custom job" , jobName )
1616 }
1717
18- // Add description if present
19- if jobConfig .Description != "" {
20- tool ["description" ] = jobConfig .Description
21- } else {
22- // Provide a default description if none is specified
23- tool ["description" ] = fmt .Sprintf ("Execute the %s custom job" , jobName )
24- }
25-
26- // Build the input schema
2718 inputSchema := map [string ]any {
28- "type" : "object" ,
29- "properties" : make (map [string ]any ),
19+ "type" : "object" ,
20+ "properties" : make (map [string ]any ),
21+ "additionalProperties" : false ,
3022 }
3123
32- // Track required fields
3324 var requiredFields []string
25+ properties := inputSchema ["properties" ].(map [string ]any )
3426
35- // Add each input to the schema
36- if len (jobConfig .Inputs ) > 0 {
37- properties := inputSchema ["properties" ].(map [string ]any )
27+ for inputName , inputDef := range jobConfig .Inputs {
28+ property := map [string ]any {}
3829
39- for inputName , inputDef := range jobConfig .Inputs {
40- property := map [string ]any {}
41-
42- // Add description
43- if inputDef .Description != "" {
44- property ["description" ] = inputDef .Description
45- }
46-
47- // Convert type to JSON Schema type
48- switch inputDef .Type {
49- case "choice" :
50- // Choice inputs are strings with enum constraints
51- property ["type" ] = "string"
52- if len (inputDef .Options ) > 0 {
53- property ["enum" ] = inputDef .Options
54- }
55- case "boolean" :
56- property ["type" ] = "boolean"
57- case "number" :
58- property ["type" ] = "number"
59- case "string" , "" :
60- // Default to string if type is not specified
61- property ["type" ] = "string"
62- default :
63- // For any unknown type, default to string
64- property ["type" ] = "string"
65- }
30+ if inputDef .Description != "" {
31+ property ["description" ] = inputDef .Description
32+ }
6633
67- // Add default value if present
68- if inputDef .Default != nil {
69- property ["default" ] = inputDef .Default
34+ // Convert type to JSON Schema type
35+ switch inputDef .Type {
36+ case "choice" :
37+ // Choice inputs are strings with enum constraints
38+ property ["type" ] = "string"
39+ if len (inputDef .Options ) > 0 {
40+ property ["enum" ] = inputDef .Options
7041 }
42+ case "boolean" :
43+ property ["type" ] = "boolean"
44+ case "number" :
45+ property ["type" ] = "number"
46+ default :
47+ // "string", empty string, or any unknown type defaults to string
48+ property ["type" ] = "string"
49+ }
7150
72- // Track required fields
73- if inputDef .Required {
74- requiredFields = append (requiredFields , inputName )
75- }
51+ if inputDef .Default != nil {
52+ property ["default" ] = inputDef .Default
53+ }
7654
77- properties [inputName ] = property
55+ if inputDef .Required {
56+ requiredFields = append (requiredFields , inputName )
7857 }
58+
59+ properties [inputName ] = property
7960 }
8061
81- // Add required fields array if any inputs are required
8262 if len (requiredFields ) > 0 {
8363 sort .Strings (requiredFields )
8464 inputSchema ["required" ] = requiredFields
8565 }
8666
87- // Prevent additional properties to maintain schema strictness
88- inputSchema ["additionalProperties" ] = false
89-
90- tool ["inputSchema" ] = inputSchema
91-
9267 safeOutputsConfigLog .Printf ("Generated tool definition for %s with %d inputs, %d required" ,
9368 jobName , len (jobConfig .Inputs ), len (requiredFields ))
9469
95- return tool
70+ return map [string ]any {
71+ "name" : jobName ,
72+ "description" : description ,
73+ "inputSchema" : inputSchema ,
74+ }
9675}
0 commit comments