@@ -111,16 +111,42 @@ const { z } = require('zod');
111
111
}
112
112
} ) ;
113
113
console . log ( 'template_res' , template_res ) ;
114
- // check if we have none ':pre' code blocks (must run after the template)
115
114
// add results from template_res.data obj schema to additional_context object
116
115
additional_context = { ...additional_context , ...{
117
116
schema :template_res . data
118
117
} } ;
118
+ // check if we have none ':pre' code blocks (must run after the template)
119
+ for ( const block of code_blocks ) {
120
+ // if block.lang doesn't end with ':pre'
121
+ if ( ! block . lang . endsWith ( ':pre' ) ) {
122
+ // if block.lang contains 'js'
123
+ if ( block . lang . includes ( 'js' ) ) {
124
+ const code_executed = await code_helper . executeNode ( additional_context , block . code ) ;
125
+ // if code_executed is an object
126
+ if ( typeof code_executed === 'object' ) {
127
+ console . log ( 'adding context from post js code block' , code_executed ) ;
128
+ additional_context = { ...additional_context , ...code_executed } ;
129
+ }
130
+ }
131
+ }
132
+ }
133
+ //
134
+ } else if ( action_or_question . data . is_question ) {
135
+ // 2) if the input is a question, run the question to the model with the 'default-template' and return the response
136
+ const question = new code2prompt ( {
137
+ path : currentWorkingDirectory ,
138
+ template : path . join ( actionsDirectory , 'default.md' ) ,
139
+ extensions : [ ] ,
140
+ ignore : [ "**/node_modules/**" , "**/*.png" , "**/*.jpg" , "**/*.gif" , "**/package-lock.json" , "**/.env" , "**/.gitignore" , "**/LICENSE" ] ,
141
+ OPENAI_KEY : process . env . OPENAI_KEY
142
+ } ) ;
143
+ const response = await question . request ( argv . input ) ;
144
+ console . log ( 'response:\n' , response . data ) ;
145
+ } else {
146
+ console . log ( 'The input is not an action or a question.. exiting..' ) ;
147
+ console . log ( `Processing input: ${ argv . input } ` , currentWorkingDirectory , userOS ) ;
148
+ console . log ( `Actions directory: ${ actionsDirectory } ` ) ;
119
149
}
120
- // 2) if the input is a question, run the question to the model with the 'default-template' and return the response
121
-
122
- console . log ( `Processing input: ${ argv . input } ` , currentWorkingDirectory , userOS ) ;
123
- console . log ( `Actions directory: ${ actionsDirectory } ` ) ;
124
150
if ( argv . debug ) {
125
151
console . log ( 'Debug mode is on' ) ;
126
152
}
0 commit comments