MCPcopy
hub / github.com/promptfoo/promptfoo / parseFileUrl

Function parseFileUrl

src/util/functions/loadFunction.ts:106–134  ·  view source on GitHub ↗
(fileUrl: string)

Source from the content-addressed store, hash-verified

104 * @returns The file path and optional function name
105 */
106export function parseFileUrl(fileUrl: string): { filePath: string; functionName?: string } {
107 if (!fileUrl.startsWith('file://')) {
108 throw new Error('URL must start with file://');
109 }
110
111 const urlWithoutProtocol = fileUrl.slice('file://'.length);
112 const lastColonIndex = urlWithoutProtocol.lastIndexOf(':');
113
114 if (lastColonIndex > 1) {
115 const candidateFilePath = urlWithoutProtocol.slice(0, lastColonIndex);
116
117 // Only executable function files support a :functionName suffix. This preserves
118 // colons that are part of a valid file or directory name on POSIX systems.
119 if (!isJavascriptFile(candidateFilePath) && !candidateFilePath.endsWith('.py')) {
120 return {
121 filePath: normalizeFilePath(urlWithoutProtocol),
122 };
123 }
124
125 return {
126 filePath: normalizeFilePath(candidateFilePath),
127 functionName: urlWithoutProtocol.slice(lastColonIndex + 1),
128 };
129 }
130
131 return {
132 filePath: normalizeFilePath(urlWithoutProtocol),
133 };
134}

Callers 15

prepareTestCaseForEvalFunction · 0.90
parseFileAuthReferenceFunction · 0.90
loadExternalFunctionMethod · 0.90
loadExternalFunctionMethod · 0.90
loadExternalFunctionMethod · 0.90
loadExternalFunctionFunction · 0.90
loadExternalFunctionMethod · 0.90
loadExternalFunctionMethod · 0.90
loadExternalFunctionMethod · 0.90
loadRubricPromptFunction · 0.90

Calls 2

isJavascriptFileFunction · 0.90
normalizeFilePathFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…