mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-07-18 21:21:11 +02:00
add migrate agents script
This commit is contained in:
parent
e40c767336
commit
da20e280f4
3 changed files with 28 additions and 2 deletions
|
|
@ -6,7 +6,8 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"build": "rm -rf dist && tsc",
|
"build": "rm -rf dist && tsc",
|
||||||
"server": "node dist/server.js"
|
"server": "node dist/server.js",
|
||||||
|
"migrate-agents": "node dist/scripts/migrate-agents.js"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,9 @@ export class FSAgentsRepo implements IAgentsRepo {
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(agent: z.infer<typeof Agent>): Promise<void> {
|
async create(agent: z.infer<typeof Agent>): Promise<void> {
|
||||||
await fs.writeFile(path.join(this.agentsDir, `${agent.name}.md`), agent.instructions);
|
const { instructions, ...rest } = agent;
|
||||||
|
const contents = `---\n${stringify(rest)}\n---\n${instructions}`;
|
||||||
|
await fs.writeFile(path.join(this.agentsDir, `${agent.name}.md`), contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, agent: z.infer<typeof UpdateAgentSchema>): Promise<void> {
|
async update(id: string, agent: z.infer<typeof UpdateAgentSchema>): Promise<void> {
|
||||||
|
|
|
||||||
23
apps/cli/src/scripts/migrate-agents.ts
Normal file
23
apps/cli/src/scripts/migrate-agents.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { Agent } from "../agents/agents.js";
|
||||||
|
import { IAgentsRepo } from "../agents/repo.js";
|
||||||
|
import { WorkDir } from "../config/config.js";
|
||||||
|
import container from "../di/container.js";
|
||||||
|
import { glob, readFile } from "node:fs/promises";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
|
const main = async () => {
|
||||||
|
const agentsRepo = container.resolve<IAgentsRepo>("agentsRepo");
|
||||||
|
const matches = await Array.fromAsync(glob("**/*.json", { cwd: path.join(WorkDir, "agents") }));
|
||||||
|
for (const file of matches) {
|
||||||
|
try {
|
||||||
|
const agent = Agent.parse(JSON.parse(await readFile(path.join(WorkDir, "agents", file), "utf8")));
|
||||||
|
await agentsRepo.create(agent);
|
||||||
|
console.error(`migrated agent ${file}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error parsing agent ${file}: ${error instanceof Error ? error.message : String(error)}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
Loading…
Add table
Add a link
Reference in a new issue