MCPcopy
hub / github.com/ModelEngine-Group/nexent / parseAgentImportFile

Function parseAgentImportFile

frontend/lib/agentImportUtils.ts:54–124  ·  view source on GitHub ↗
(
  file: File,
  options: ParseAgentFileOptions = {}
)

Source from the content-addressed store, hash-verified

52 * Returns the parsed ImportAgentData or null if parsing failed
53 */
54export async function parseAgentImportFile(
55 file: File,
56 options: ParseAgentFileOptions = {}
57): Promise<ImportAgentData | null> {
58 const { onFileNotFound, onParseError, onValidationError } = options;
59
60 if (!file.name.endsWith(".json") && !file.name.endsWith(".zip")) {
61 onParseError?.("businessLogic.config.error.invalidFileType");
62 return null;
63 }
64
65 try {
66 let agentData: ImportAgentData;
67
68 if (file.name.endsWith(".zip")) {
69 const zip = await JSZip.loadAsync(file);
70 const agentJsonFile = zip.file("agent.json");
71 if (!agentJsonFile) {
72 onFileNotFound?.("agent.json not found in ZIP");
73 return null;
74 }
75 const content = await agentJsonFile.async("string");
76 try {
77 agentData = JSON.parse(content);
78 } catch {
79 onParseError?.("businessLogic.config.error.invalidFileType");
80 return null;
81 }
82
83 const skills: Array<{ skill_name: string; skill_zip_base64: string }> = [];
84 const skillsFolder = zip.folder("skills");
85 if (skillsFolder) {
86 const skillFiles = Object.keys(zip.files).filter(
87 (name) =>
88 name.startsWith("skills/") && name.toLowerCase().endsWith(".zip")
89 );
90 for (const skillFileName of skillFiles) {
91 const skillZipFile = zip.file(skillFileName);
92 if (skillZipFile) {
93 const skillZipContent = await skillZipFile.async("arraybuffer");
94 const base64 = arrayBufferToBase64(skillZipContent);
95 const skillName = extractSkillNameFromPath(skillFileName);
96 skills.push({
97 skill_name: skillName,
98 skill_zip_base64: base64,
99 });
100 }
101 }
102 }
103 agentData.skills = skills;
104 } else {
105 const fileContent = await file.text();
106 try {
107 agentData = JSON.parse(fileContent);
108 } catch {
109 onParseError?.("businessLogic.config.error.invalidFileType");
110 return null;
111 }

Callers 3

handleImportAgentFunction · 0.90
handleImportAgentFunction · 0.90
openImportWizardWithFileFunction · 0.85

Calls 5

arrayBufferToBase64Function · 0.85
extractSkillNameFromPathFunction · 0.85
textMethod · 0.80
parseMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected