package
This commit is contained in:
+40
-2
@@ -52047,6 +52047,41 @@ function parseTemplateVariables(input) {
|
|||||||
throw new Error(`Failed to parse template variables: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
throw new Error(`Failed to parse template variables: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Parse file-based template variables from YAML input string. The YAML should map
|
||||||
|
* variable names to file paths. File contents are read and returned as variables.
|
||||||
|
*/
|
||||||
|
function parseFileTemplateVariables(fileInput) {
|
||||||
|
if (!fileInput.trim()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const parsed = load(fileInput);
|
||||||
|
if (typeof parsed !== 'object' || parsed === null) {
|
||||||
|
throw new Error('File template variables must be a YAML object');
|
||||||
|
}
|
||||||
|
const result = {};
|
||||||
|
for (const [key, value] of Object.entries(parsed)) {
|
||||||
|
if (typeof value !== 'string') {
|
||||||
|
throw new Error(`File template variable '${key}' must be a string file path`);
|
||||||
|
}
|
||||||
|
const filePath = value;
|
||||||
|
if (!fs.existsSync(filePath)) {
|
||||||
|
throw new Error(`File for template variable '${key}' was not found: ${filePath}`);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
result[key] = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
throw new Error(`Failed to read file for template variable '${key}' at path '${filePath}': ${err instanceof Error ? err.message : 'Unknown error'}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
throw new Error(`Failed to parse file template variables: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Replace template variables in text using {{variable}} syntax
|
* Replace template variables in text using {{variable}} syntax
|
||||||
*/
|
*/
|
||||||
@@ -52106,14 +52141,17 @@ async function run() {
|
|||||||
try {
|
try {
|
||||||
const promptFilePath = coreExports.getInput('prompt-file');
|
const promptFilePath = coreExports.getInput('prompt-file');
|
||||||
const inputVariables = coreExports.getInput('input');
|
const inputVariables = coreExports.getInput('input');
|
||||||
|
const fileInputVariables = coreExports.getInput('file_input');
|
||||||
let promptConfig = undefined;
|
let promptConfig = undefined;
|
||||||
let systemPrompt = undefined;
|
let systemPrompt = undefined;
|
||||||
let prompt = undefined;
|
let prompt = undefined;
|
||||||
// Check if we're using a prompt YAML file
|
// Check if we're using a prompt YAML file
|
||||||
if (promptFilePath && isPromptYamlFile(promptFilePath)) {
|
if (promptFilePath && isPromptYamlFile(promptFilePath)) {
|
||||||
coreExports.info('Using prompt YAML file format');
|
coreExports.info('Using prompt YAML file format');
|
||||||
// Parse template variables
|
// Parse template variables from both string inputs and file-based inputs
|
||||||
const templateVariables = parseTemplateVariables(inputVariables);
|
const stringVars = parseTemplateVariables(inputVariables);
|
||||||
|
const fileVars = parseFileTemplateVariables(fileInputVariables);
|
||||||
|
const templateVariables = { ...stringVars, ...fileVars };
|
||||||
// Load and process prompt file
|
// Load and process prompt file
|
||||||
promptConfig = loadPromptFile(promptFilePath, templateVariables);
|
promptConfig = loadPromptFile(promptFilePath, templateVariables);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -65,7 +65,7 @@ export function parseFileTemplateVariables(fileInput: string): TemplateVariables
|
|||||||
result[key] = fs.readFileSync(filePath, 'utf-8')
|
result[key] = fs.readFileSync(filePath, 'utf-8')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to read file for template variable '${key}' at path '${filePath}': ${err instanceof Error ? err.message : 'Unknown error'}`
|
`Failed to read file for template variable '${key}' at path '${filePath}': ${err instanceof Error ? err.message : 'Unknown error'}`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user