( ide: IDE, dir: string, fileExtType?: "yaml" | "markdown", )
| 48 | } |
| 49 | |
| 50 | async function getDefinitionFilesInDir( |
| 51 | ide: IDE, |
| 52 | dir: string, |
| 53 | fileExtType?: "yaml" | "markdown", |
| 54 | ): Promise<{ path: string; content: string }[]> { |
| 55 | try { |
| 56 | const exists = await ide.fileExists(dir); |
| 57 | |
| 58 | if (!exists) { |
| 59 | return []; |
| 60 | } |
| 61 | |
| 62 | const overrideDefaultIgnores = ignore() |
| 63 | .add( |
| 64 | DEFAULT_IGNORE_FILETYPES.filter( |
| 65 | (t) => t !== "config.yaml" && t !== "config.yml", |
| 66 | ), |
| 67 | ) |
| 68 | .add(DEFAULT_IGNORE_DIRS); |
| 69 | |
| 70 | const uris = await walkDir(dir, ide, { |
| 71 | overrideDefaultIgnores, |
| 72 | source: "get assistant files", |
| 73 | }); |
| 74 | let assistantFilePaths: string[]; |
| 75 | if (fileExtType === "yaml") { |
| 76 | assistantFilePaths = uris.filter( |
| 77 | (p) => p.endsWith(".yaml") || p.endsWith(".yml"), |
| 78 | ); |
| 79 | } else if (fileExtType === "markdown") { |
| 80 | assistantFilePaths = uris.filter((p) => p.endsWith(".md")); |
| 81 | } else { |
| 82 | assistantFilePaths = uris.filter( |
| 83 | (p) => p.endsWith(".yaml") || p.endsWith(".yml") || p.endsWith(".md"), |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | const results = assistantFilePaths.map(async (uri) => { |
| 88 | const content = await ide.readFile(uri); // make a try catch |
| 89 | return { path: uri, content }; |
| 90 | }); |
| 91 | return Promise.all(results); |
| 92 | } catch (e) { |
| 93 | console.error(e); |
| 94 | return []; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | export interface LoadAssistantFilesOptions { |
| 99 | includeGlobal: boolean; |
no test coverage detected