( filePath: string, prompt: Partial<Prompt>, _functionName?: string, )
| 116 | * @returns Array of prompts generated from the executable. |
| 117 | */ |
| 118 | export async function processExecutableFile( |
| 119 | filePath: string, |
| 120 | prompt: Partial<Prompt>, |
| 121 | _functionName?: string, |
| 122 | ): Promise<Prompt[]> { |
| 123 | // For display purposes, try to read the file if it exists and is a text file |
| 124 | let rawContent = filePath; |
| 125 | const scriptParts = parseScriptParts(filePath); |
| 126 | const firstPart = scriptParts[0]; |
| 127 | |
| 128 | if (firstPart) { |
| 129 | try { |
| 130 | const stats = await fsStat(firstPart); |
| 131 | if (stats.isFile() && stats.size < 1024 * 100) { |
| 132 | // Only read files < 100KB |
| 133 | const content = await readFile(firstPart, 'utf-8'); |
| 134 | // Check if it's likely a text file |
| 135 | if (!/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/.test(content.substring(0, 1000))) { |
| 136 | rawContent = content; |
| 137 | } |
| 138 | } |
| 139 | } catch (_e) { |
| 140 | // Ignore errors, use the path as raw content |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | const label = prompt.label ?? filePath; |
| 145 | |
| 146 | return [ |
| 147 | { |
| 148 | raw: rawContent, |
| 149 | label, |
| 150 | function: (context) => |
| 151 | executablePromptFunction(filePath, { ...context, config: prompt.config }), |
| 152 | config: prompt.config, |
| 153 | }, |
| 154 | ]; |
| 155 | } |
no test coverage detected
searching dependent graphs…