mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:41:24 +00:00
refactor(src): split oversized modules
This commit is contained in:
@@ -2,8 +2,6 @@ import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import JSON5 from "json5";
|
||||
|
||||
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import { resolveOAuthDir, resolveStateDir } from "../config/paths.js";
|
||||
@@ -16,6 +14,15 @@ import {
|
||||
DEFAULT_MAIN_KEY,
|
||||
normalizeAgentId,
|
||||
} from "../routing/session-key.js";
|
||||
import {
|
||||
ensureDir,
|
||||
existsDir,
|
||||
fileExists,
|
||||
isLegacyWhatsAppAuthFile,
|
||||
readSessionStoreJson5,
|
||||
type SessionEntryLike,
|
||||
safeReadDir,
|
||||
} from "./state-migrations.fs.js";
|
||||
|
||||
export type LegacyStateDetection = {
|
||||
targetAgentId: string;
|
||||
@@ -42,11 +49,6 @@ export type LegacyStateDetection = {
|
||||
preview: string[];
|
||||
};
|
||||
|
||||
type SessionEntryLike = { sessionId?: string; updatedAt?: number } & Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
|
||||
type MigrationLogger = {
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
@@ -54,56 +56,6 @@ type MigrationLogger = {
|
||||
|
||||
let autoMigrateChecked = false;
|
||||
|
||||
function safeReadDir(dir: string): fs.Dirent[] {
|
||||
try {
|
||||
return fs.readdirSync(dir, { withFileTypes: true });
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function existsDir(dir: string): boolean {
|
||||
try {
|
||||
return fs.existsSync(dir) && fs.statSync(dir).isDirectory();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function ensureDir(dir: string) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
|
||||
function fileExists(p: string): boolean {
|
||||
try {
|
||||
return fs.existsSync(p) && fs.statSync(p).isFile();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isLegacyWhatsAppAuthFile(name: string): boolean {
|
||||
if (name === "creds.json" || name === "creds.json.bak") return true;
|
||||
if (!name.endsWith(".json")) return false;
|
||||
return /^(app-state-sync|session|sender-key|pre-key)-/.test(name);
|
||||
}
|
||||
|
||||
function readSessionStoreJson5(storePath: string): {
|
||||
store: Record<string, SessionEntryLike>;
|
||||
ok: boolean;
|
||||
} {
|
||||
try {
|
||||
const raw = fs.readFileSync(storePath, "utf-8");
|
||||
const parsed = JSON5.parse(raw);
|
||||
if (parsed && typeof parsed === "object") {
|
||||
return { store: parsed as Record<string, SessionEntryLike>, ok: true };
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
return { store: {}, ok: false };
|
||||
}
|
||||
|
||||
function isSurfaceGroupKey(key: string): boolean {
|
||||
return key.includes(":group:") || key.includes(":channel:");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user