Files
letta-code/src/cli/startupFlagValidation.ts
2026-02-25 18:29:56 -08:00

38 lines
1.1 KiB
TypeScript

export interface FlagConflictCheck {
when: unknown;
message: string;
}
export function validateFlagConflicts(options: {
guard: unknown;
checks: FlagConflictCheck[];
}): void {
const { guard, checks } = options;
if (!guard) {
return;
}
const firstConflict = checks.find((check) => Boolean(check.when));
if (firstConflict) {
throw new Error(firstConflict.message);
}
}
export function validateConversationDefaultRequiresAgent(options: {
specifiedConversationId: string | null | undefined;
specifiedAgentId: string | null | undefined;
forceNew: boolean | null | undefined;
}): void {
const { specifiedConversationId, specifiedAgentId, forceNew } = options;
if (specifiedConversationId === "default" && !specifiedAgentId && !forceNew) {
throw new Error("--conv default requires --agent <agent-id>");
}
}
export function validateRegistryHandleOrThrow(handle: string): void {
const normalized = handle.startsWith("@") ? handle.slice(1) : handle;
const parts = normalized.split("/");
if (parts.length !== 2 || !parts[0] || !parts[1]) {
throw new Error(`Invalid registry handle "${handle}"`);
}
}