@convo-lang/convo-lang
Version:
The language of AI
40 lines • 1.6 kB
JavaScript
import { getUriProtocol } from "@iyio/common";
import { vfs } from "@iyio/vfs";
export class ConvoVfsImportService {
canImport(path) {
const proto = getUriProtocol(path);
return !proto || proto === 'file';
}
async handleImport(_import) {
const path = _import.targetPath ?? _import.name;
if (path.includes('*')) {
let rOptions;
if (path.includes('**')) {
const [p, f] = path.split('**');
rOptions = f ? { path: p || '/', filter: { endsWith: f } } : undefined;
}
const items = await (rOptions ? vfs().readDirRecursiveAsync(rOptions) : vfs().readDirAsync(path));
return await Promise.all(items.items.filter(i => i.type === 'file').map(async (i) => {
const isConvo = i.name?.toLowerCase().endsWith('.convo');
const file = await vfs().readStringAsync(i.path);
return {
name: i.path,
convo: isConvo ? file : undefined,
content: isConvo ? undefined : file,
filePath: i.path
};
}));
}
else {
const isConvo = _import.name?.toLowerCase().endsWith('.convo');
const file = await vfs().readStringAsync(path);
return {
name: _import.name,
convo: isConvo ? file : undefined,
content: isConvo ? undefined : file,
filePath: path
};
}
}
}
//# sourceMappingURL=ConvoVfsImportService.js.map