VoidBot/packages/core/src/void-self-state-loader.ts

34 lines
901 B
TypeScript
Raw Normal View History

2026-05-05 13:42:41 +01:00
import {
type GuildContext,
type SourceMessage,
type VoidSelfStateContext,
} from "@voidbot/shared";
import { buildVoidSelfStateContext } from "./void-self-state-projection";
import { loadVoidSelfStateTypedDocuments } from "./void-self-state-service";
2026-05-05 13:42:41 +01:00
export interface LoadVoidSelfStateOptions {
recentMessages?: SourceMessage[];
guildContext?: GuildContext;
}
export async function loadVoidSelfState(
statePath: string,
2026-05-05 13:42:41 +01:00
options: LoadVoidSelfStateOptions = {},
): Promise<VoidSelfStateContext | undefined> {
try {
const typedProjection = await loadVoidSelfStateTypedDocuments({ canonicalPath: statePath });
return buildVoidSelfStateContext(typedProjection, {
sourcePath: statePath,
...options,
});
} catch (error) {
const code = (error as NodeJS.ErrnoException).code;
if (code === "ENOENT") {
return undefined;
}
throw error;
}
2026-05-05 13:42:41 +01:00
}