This commit is contained in:
Sean Goedecke
2025-08-05 01:52:46 +00:00
parent aaf9c5af33
commit ea4e7d8bb9
3 changed files with 42 additions and 4 deletions

42
dist/index.js generated vendored
View File

@@ -52047,6 +52047,41 @@ function parseTemplateVariables(input) {
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
*/
@@ -52106,14 +52141,17 @@ async function run() {
try {
const promptFilePath = coreExports.getInput('prompt-file');
const inputVariables = coreExports.getInput('input');
const fileInputVariables = coreExports.getInput('file_input');
let promptConfig = undefined;
let systemPrompt = undefined;
let prompt = undefined;
// Check if we're using a prompt YAML file
if (promptFilePath && isPromptYamlFile(promptFilePath)) {
coreExports.info('Using prompt YAML file format');
// Parse template variables
const templateVariables = parseTemplateVariables(inputVariables);
// Parse template variables from both string inputs and file-based inputs
const stringVars = parseTemplateVariables(inputVariables);
const fileVars = parseFileTemplateVariables(fileInputVariables);
const templateVariables = { ...stringVars, ...fileVars };
// Load and process prompt file
promptConfig = loadPromptFile(promptFilePath, templateVariables);
}

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -65,7 +65,7 @@ export function parseFileTemplateVariables(fileInput: string): TemplateVariables
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'}`
`Failed to read file for template variable '${key}' at path '${filePath}': ${err instanceof Error ? err.message : 'Unknown error'}`,
)
}
}