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);
|
||||
});
|
||||
@@ -0,0 +1,73 @@
|
||||
import "dotenv/config";
|
||||
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { loadConfig } from "../src/config.js";
|
||||
import { createLogger } from "../src/logger.js";
|
||||
import { MySqlSessionStore } from "../src/sessions/mysql_store.js";
|
||||
import type { SessionMessage, SessionMeta } from "../src/sessions/store.js";
|
||||
|
||||
interface SessionIndexFile {
|
||||
sessions?: Record<string, SessionMeta>;
|
||||
}
|
||||
|
||||
const config = loadConfig();
|
||||
const logger = createLogger(config.logLevel);
|
||||
const dryRun = process.argv.includes("--dry-run");
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const store = new MySqlSessionStore(config.mysql, logger);
|
||||
await store.init();
|
||||
|
||||
let sessionCount = 0;
|
||||
let messageCount = 0;
|
||||
let skipped = 0;
|
||||
|
||||
if (existsSync(config.sessionsFile)) {
|
||||
const parsed = JSON.parse(readFileSync(config.sessionsFile, "utf8")) as SessionIndexFile;
|
||||
const sessions = Object.values(parsed.sessions ?? {});
|
||||
for (const meta of sessions) {
|
||||
if (!meta.session_id) {
|
||||
skipped += 1;
|
||||
continue;
|
||||
}
|
||||
if (!dryRun) await store.upsertSession(meta);
|
||||
sessionCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (existsSync(config.messagesDir)) {
|
||||
for (const file of readdirSync(config.messagesDir)) {
|
||||
if (!file.endsWith(".jsonl")) continue;
|
||||
const sessionId = file.slice(0, -".jsonl".length);
|
||||
const lines = readFileSync(join(config.messagesDir, file), "utf8").split("\n");
|
||||
for (const line of lines) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) continue;
|
||||
let message: SessionMessage;
|
||||
try {
|
||||
message = JSON.parse(trimmed) as SessionMessage;
|
||||
} catch {
|
||||
skipped += 1;
|
||||
continue;
|
||||
}
|
||||
if (!message.id || !message.session_id) {
|
||||
message.id = message.id || `${sessionId}-${messageCount}`;
|
||||
message.session_id = message.session_id || sessionId;
|
||||
}
|
||||
if (!dryRun) await store.insertMessage(message);
|
||||
messageCount += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(
|
||||
`${dryRun ? "[dry-run] " : ""}migrated sessions=${sessionCount} messages=${messageCount} skipped=${skipped}`,
|
||||
);
|
||||
await store.close();
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error("migration failed:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in new issue
Block a user