chore: initial commit
Laimiao agent v2 service: agent orchestration, sessions, billing, gateway client, skills catalog, auth, config, plus tests.
This commit is contained in:
commit
6ec9778d45
53 files changed
+12340
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import "dotenv/config";
|
||||
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { loadConfig } from "../src/config.js";
|
||||
import { createLogger } from "../src/logger.js";
|
||||
import { MySqlSessionContextStore } from "../src/sessions/context_store.js";
|
||||
|
||||
const config = loadConfig();
|
||||
const logger = createLogger(config.logLevel);
|
||||
const dryRun = process.argv.includes("--dry-run");
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const store = new MySqlSessionContextStore(config.mysql, logger);
|
||||
await store.init();
|
||||
|
||||
let migrated = 0;
|
||||
let skipped = 0;
|
||||
if (!existsSync(config.piSessionsDir)) {
|
||||
console.log("no pi session dir, nothing to migrate");
|
||||
await store.close();
|
||||
return;
|
||||
}
|
||||
|
||||
for (const file of readdirSync(config.piSessionsDir)) {
|
||||
if (!file.endsWith(".jsonl")) continue;
|
||||
const match = file.match(/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl$/);
|
||||
const sessionId = match?.[1] ?? file.replace(/^.*?_/, "").replace(/\.jsonl$/, "");
|
||||
if (!sessionId) {
|
||||
skipped += 1;
|
||||
continue;
|
||||
}
|
||||
const content = readFileSync(join(config.piSessionsDir, file));
|
||||
if (!dryRun) await store.save(sessionId, content);
|
||||
migrated += 1;
|
||||
}
|
||||
|
||||
console.log(`${dryRun ? "[dry-run] " : ""}migrated contexts=${migrated} skipped=${skipped}`);
|
||||
await store.close();
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error("context migration failed:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in new issue
Block a user