chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -101,8 +101,7 @@ function pickLatestLegacyDirectEntry(
|
||||
}
|
||||
|
||||
function normalizeSessionEntry(entry: SessionEntryLike): SessionEntry | null {
|
||||
const sessionId =
|
||||
typeof entry.sessionId === "string" ? entry.sessionId : null;
|
||||
const sessionId = typeof entry.sessionId === "string" ? entry.sessionId : null;
|
||||
if (!sessionId) return null;
|
||||
const updatedAt =
|
||||
typeof entry.updatedAt === "number" && Number.isFinite(entry.updatedAt)
|
||||
@@ -153,12 +152,7 @@ export async function detectLegacyStateMigrations(params: {
|
||||
|
||||
const sessionsLegacyDir = path.join(stateDir, "sessions");
|
||||
const sessionsLegacyStorePath = path.join(sessionsLegacyDir, "sessions.json");
|
||||
const sessionsTargetDir = path.join(
|
||||
stateDir,
|
||||
"agents",
|
||||
targetAgentId,
|
||||
"sessions",
|
||||
);
|
||||
const sessionsTargetDir = path.join(stateDir, "agents", targetAgentId, "sessions");
|
||||
const sessionsTargetStorePath = path.join(sessionsTargetDir, "sessions.json");
|
||||
const legacySessionEntries = safeReadDir(sessionsLegacyDir);
|
||||
const hasLegacySessions =
|
||||
@@ -169,11 +163,7 @@ export async function detectLegacyStateMigrations(params: {
|
||||
const targetAgentDir = path.join(stateDir, "agents", targetAgentId, "agent");
|
||||
const hasLegacyAgentDir = existsDir(legacyAgentDir);
|
||||
|
||||
const targetWhatsAppAuthDir = path.join(
|
||||
oauthDir,
|
||||
"whatsapp",
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
);
|
||||
const targetWhatsAppAuthDir = path.join(oauthDir, "whatsapp", DEFAULT_ACCOUNT_ID);
|
||||
const hasLegacyWhatsAppAuth =
|
||||
fileExists(path.join(oauthDir, "creds.json")) &&
|
||||
!fileExists(path.join(targetWhatsAppAuthDir, "creds.json"));
|
||||
@@ -186,9 +176,7 @@ export async function detectLegacyStateMigrations(params: {
|
||||
preview.push(`- Agent dir: ${legacyAgentDir} → ${targetAgentDir}`);
|
||||
}
|
||||
if (hasLegacyWhatsAppAuth) {
|
||||
preview.push(
|
||||
`- WhatsApp auth: ${oauthDir} → ${targetWhatsAppAuthDir} (keep oauth.json)`,
|
||||
);
|
||||
preview.push(`- WhatsApp auth: ${oauthDir} → ${targetWhatsAppAuthDir} (keep oauth.json)`);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -277,9 +265,7 @@ async function migrateLegacySessions(
|
||||
normalized[key] = normalizedEntry;
|
||||
}
|
||||
await saveSessionStore(detected.sessions.targetStorePath, normalized);
|
||||
changes.push(
|
||||
`Merged sessions store → ${detected.sessions.targetStorePath}`,
|
||||
);
|
||||
changes.push(`Merged sessions store → ${detected.sessions.targetStorePath}`);
|
||||
}
|
||||
|
||||
const entries = safeReadDir(detected.sessions.legacyDir);
|
||||
@@ -291,9 +277,7 @@ async function migrateLegacySessions(
|
||||
if (fileExists(to)) continue;
|
||||
try {
|
||||
fs.renameSync(from, to);
|
||||
changes.push(
|
||||
`Moved ${entry.name} → agents/${detected.targetAgentId}/sessions`,
|
||||
);
|
||||
changes.push(`Moved ${entry.name} → agents/${detected.targetAgentId}/sessions`);
|
||||
} catch (err) {
|
||||
warnings.push(`Failed moving ${from}: ${String(err)}`);
|
||||
}
|
||||
@@ -310,9 +294,7 @@ async function migrateLegacySessions(
|
||||
}
|
||||
|
||||
removeDirIfEmpty(detected.sessions.legacyDir);
|
||||
const legacyLeft = safeReadDir(detected.sessions.legacyDir).filter((e) =>
|
||||
e.isFile(),
|
||||
);
|
||||
const legacyLeft = safeReadDir(detected.sessions.legacyDir).filter((e) => e.isFile());
|
||||
if (legacyLeft.length > 0) {
|
||||
const backupDir = `${detected.sessions.legacyDir}.legacy-${now()}`;
|
||||
try {
|
||||
@@ -343,9 +325,7 @@ export async function migrateLegacyAgentDir(
|
||||
if (fs.existsSync(to)) continue;
|
||||
try {
|
||||
fs.renameSync(from, to);
|
||||
changes.push(
|
||||
`Moved agent file ${entry.name} → agents/${detected.targetAgentId}/agent`,
|
||||
);
|
||||
changes.push(`Moved agent file ${entry.name} → agents/${detected.targetAgentId}/agent`);
|
||||
} catch (err) {
|
||||
warnings.push(`Failed moving ${from}: ${String(err)}`);
|
||||
}
|
||||
@@ -408,16 +388,8 @@ export async function runLegacyStateMigrations(params: {
|
||||
const agentDir = await migrateLegacyAgentDir(detected, now);
|
||||
const whatsappAuth = await migrateLegacyWhatsAppAuth(detected);
|
||||
return {
|
||||
changes: [
|
||||
...sessions.changes,
|
||||
...agentDir.changes,
|
||||
...whatsappAuth.changes,
|
||||
],
|
||||
warnings: [
|
||||
...sessions.warnings,
|
||||
...agentDir.warnings,
|
||||
...whatsappAuth.warnings,
|
||||
],
|
||||
changes: [...sessions.changes, ...agentDir.changes, ...whatsappAuth.changes],
|
||||
warnings: [...sessions.warnings, ...agentDir.warnings, ...whatsappAuth.warnings],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -475,17 +447,11 @@ export async function autoMigrateLegacyState(params: {
|
||||
|
||||
const logger = params.log ?? createSubsystemLogger("state-migrations");
|
||||
if (changes.length > 0) {
|
||||
logger.info(
|
||||
`Auto-migrated legacy state:\n${changes
|
||||
.map((entry) => `- ${entry}`)
|
||||
.join("\n")}`,
|
||||
);
|
||||
logger.info(`Auto-migrated legacy state:\n${changes.map((entry) => `- ${entry}`).join("\n")}`);
|
||||
}
|
||||
if (warnings.length > 0) {
|
||||
logger.warn(
|
||||
`Legacy state migration warnings:\n${warnings
|
||||
.map((entry) => `- ${entry}`)
|
||||
.join("\n")}`,
|
||||
`Legacy state migration warnings:\n${warnings.map((entry) => `- ${entry}`).join("\n")}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user