MCPcopy Create free account
hub / github.com/Roy3838/Observer / importAgentFromFile

Function importAgentFromFile

app/src/utils/agent_database.ts:474–510  ·  view source on GitHub ↗
(file: File)

Source from the content-addressed store, hash-verified

472 * @returns A promise that resolves to the imported agent
473 */
474export async function importAgentFromFile(file: File): Promise<CompleteAgent> {
475 return new Promise((resolve, reject) => {
476 const reader = new FileReader();
477
478 reader.onload = async (event) => {
479 try {
480 const content = event.target?.result as string;
481 const agentData = yaml.load(content) as AgentExport;
482
483 if (!agentData.id || !agentData.name || !agentData.code) {
484 throw new Error('Invalid agent file format. Missing required fields.');
485 }
486
487 const agent: CompleteAgent = {
488 id: agentData.id,
489 name: agentData.name,
490 description: agentData.description || '',
491 model_name: agentData.model_name,
492 system_prompt: agentData.system_prompt,
493 loop_interval_seconds: agentData.loop_interval_seconds,
494 only_on_significant_change: agentData.only_on_significant_change,
495 classification: agentData.classification
496 };
497
498 await saveAgent(agent, agentData.code);
499 await updateAgentMemory(agent.id, agentData.memory || '');
500
501 resolve(agent);
502 } catch (error) {
503 reject(error);
504 }
505 };
506
507 reader.onerror = () => reject(new Error('Failed to read file'));
508 reader.readAsText(file);
509 });
510}
511
512/**
513 * Import multiple agents from files

Callers 1

importAgentsFromFilesFunction · 0.85

Calls 3

saveAgentFunction · 0.85
updateAgentMemoryFunction · 0.85
loadMethod · 0.45

Tested by

no test coverage detected