@@ -5,8 +5,8 @@ const Table = require("@saltcorn/data/models/table");
5
5
const Field = require ( "@saltcorn/data/models/field" ) ;
6
6
const { apply, removeAllWhiteSpace } = require ( "@saltcorn/data/utils" ) ;
7
7
const { getActionConfigFields } = require ( "@saltcorn/data/plugin-helper" ) ;
8
- const { a, pre, script, div } = require ( "@saltcorn/markup/tags" ) ;
9
- const { fieldProperties } = require ( "../common" ) ;
8
+ const { a, pre, script, div, code } = require ( "@saltcorn/markup/tags" ) ;
9
+ const { fieldProperties, getPromptFromTemplate } = require ( "../common" ) ;
10
10
11
11
class GenerateJsAction {
12
12
static title = "Generate JavaScript Action" ;
@@ -16,9 +16,9 @@ class GenerateJsAction {
16
16
static async json_schema ( ) {
17
17
return {
18
18
type : "object" ,
19
- required : [ "code " , "action_name" ] ,
19
+ required : [ "action_javascript_code " , "action_name" ] ,
20
20
properties : {
21
- code : {
21
+ action_javascript_code : {
22
22
description : "JavaScript code that constitutes the action" ,
23
23
type : "string" ,
24
24
} ,
@@ -28,8 +28,7 @@ class GenerateJsAction {
28
28
type : "string" ,
29
29
} ,
30
30
action_description : {
31
- description :
32
- "A description of the purpose of the action." ,
31
+ description : "A description of the purpose of the action." ,
33
32
type : "string" ,
34
33
} ,
35
34
when_trigger : {
@@ -46,6 +45,38 @@ class GenerateJsAction {
46
45
} ,
47
46
} ;
48
47
}
48
+ static async system_prompt ( ) {
49
+ const partPrompt = await getPromptFromTemplate ( "action-builder.txt" , "" ) ;
50
+ return (
51
+ `Use the generate_js_action to generate actions based on JavaScript code. ` +
52
+ partPrompt
53
+ ) ;
54
+ }
55
+ static render_html ( {
56
+ action_javascript_code,
57
+ action_name,
58
+ action_description,
59
+ when_trigger,
60
+ trigger_table,
61
+ } ) {
62
+ return (
63
+ div ( { class : "mb-3" } ,
64
+ `${ action_name } ${ when_trigger ? `: ${ when_trigger } ` : "" } ${
65
+ trigger_table ? ` on ${ trigger_table } ` : ""
66
+ } `
67
+ ) + pre ( code ( action_javascript_code ) )
68
+ ) ;
69
+ }
70
+ static async execute (
71
+ {
72
+ action_javascript_code,
73
+ action_name,
74
+ action_description,
75
+ when_trigger,
76
+ trigger_table,
77
+ } ,
78
+ req
79
+ ) { }
49
80
}
50
81
51
82
module . exports = GenerateJsAction ;
0 commit comments