(agentId: string)
| 566 | } |
| 567 | |
| 568 | export async function downloadAgent(agentId: string): Promise<void> { |
| 569 | try { |
| 570 | const agent = await getAgent(agentId); |
| 571 | if (!agent) throw new Error(`Agent ${agentId} not found`); |
| 572 | |
| 573 | const code = await getAgentCode(agentId); |
| 574 | if (code === null) throw new Error(`Code for agent ${agentId} not found`); |
| 575 | |
| 576 | const memory = await getAgentMemory(agentId); |
| 577 | |
| 578 | // Create YAML-formatted string directly |
| 579 | const yamlContent = [ |
| 580 | `id: ${agent.id}`, |
| 581 | `name: ${agent.name}`, |
| 582 | `description: ${agent.description}`, |
| 583 | `model_name: ${agent.model_name}`, |
| 584 | `loop_interval_seconds: ${agent.loop_interval_seconds}`, |
| 585 | `system_prompt: |`, |
| 586 | ` ${agent.system_prompt.replace(/\n/g, '\n ')}`, |
| 587 | `code: |`, |
| 588 | ` ${code.replace(/\n/g, '\n ')}`, |
| 589 | memory ? `memory: |` : 'memory: ""', |
| 590 | memory ? ` ${memory.replace(/\n/g, '\n ')}` : '', |
| 591 | ].join('\n'); |
| 592 | |
| 593 | const blob = new Blob([yamlContent], { type: 'application/x-yaml' }); |
| 594 | const url = URL.createObjectURL(blob); |
| 595 | const a = document.createElement('a'); |
| 596 | a.href = url; |
| 597 | a.download = `agent-${agentId}.yaml`; |
| 598 | |
| 599 | document.body.appendChild(a); |
| 600 | a.click(); |
| 601 | |
| 602 | setTimeout(() => { |
| 603 | document.body.removeChild(a); |
| 604 | URL.revokeObjectURL(url); |
| 605 | }, 0); |
| 606 | } catch (error) { |
| 607 | console.error('Failed to download agent:', error); |
| 608 | throw error; |
| 609 | } |
| 610 | } |
no test coverage detected