MCPcopy Create free account
hub / github.com/SKaplanOfficial/Raycast-PromptLab / loadFileContents

Function loadFileContents

src/hooks/useFiles.ts:183–209  ·  view source on GitHub ↗
(selection: { paths: string[]; csv: string })

Source from the content-addressed store, hash-verified

181 };
182
183 const loadFileContents = async (selection: { paths: string[]; csv: string }) => {
184 // Raise an error if too few files are selected
185 if (selection.paths.length < (options.minNumFiles || 0)) {
186 setError(ERRORTYPE.MIN_SELECTION_NOT_MET);
187 setIsLoading(false);
188 return;
189 }
190
191 await revalidateAdvancedSettings();
192
193 let model = options.model ? models.find((m) => m.name == options.model) : undefined;
194 if (!model) model = models.find((m) => m.isDefault) || models[0];
195 const maxCharacters = model ? parseInt(model.lengthLimit) : 3000;
196
197 const fileData: { [key: string]: string; contents: string } = {
198 contents: "",
199 };
200 for (const [index, filepath] of selection.paths.entries()) {
201 // Init. file contents with file name as header
202 const currentData = await getFileContent(filepath, options, index, maxCharacters, advancedSettings);
203 fileData.contents = filterString(fileData.contents + "\n" + currentData.contents, maxCharacters);
204 Object.assign(fileData, currentData);
205 }
206
207 setFileContents(fileData);
208 return fileData;
209 };
210
211 const revalidate = async () => {
212 const selection = await loadSelection();

Callers 1

revalidateFunction · 0.85

Calls 3

filterStringFunction · 0.90
getFileContentFunction · 0.85

Tested by

no test coverage detected