feat: add activated property to BrainItem

This commit is contained in:
2026-06-28 22:59:02 +09:00
parent 3ec508bf99
commit 3cac93d97c
2 changed files with 27 additions and 25 deletions

View File

@@ -142,7 +142,9 @@ export class Brain {
let twoDaysAgoSchedule: DailySchedule | null = null; let twoDaysAgoSchedule: DailySchedule | null = null;
if (twoDaysAgoStored) { if (twoDaysAgoStored) {
try { try {
twoDaysAgoSchedule = JSON.parse(twoDaysAgoStored.content) as DailySchedule; twoDaysAgoSchedule = JSON.parse(
twoDaysAgoStored.content,
) as DailySchedule;
} catch { } catch {
twoDaysAgoSchedule = null; twoDaysAgoSchedule = null;
} }
@@ -222,7 +224,9 @@ export class Brain {
let twoMonthsAgoSchedule: MonthlySchedule | null = null; let twoMonthsAgoSchedule: MonthlySchedule | null = null;
if (twoMonthsAgoStored) { if (twoMonthsAgoStored) {
try { try {
twoMonthsAgoSchedule = JSON.parse(twoMonthsAgoStored.content) as MonthlySchedule; twoMonthsAgoSchedule = JSON.parse(
twoMonthsAgoStored.content,
) as MonthlySchedule;
} catch { } catch {
twoMonthsAgoSchedule = null; twoMonthsAgoSchedule = null;
} }
@@ -527,7 +531,8 @@ export class Brain {
private async buildScheduleBlock(now: Date): Promise<string> { private async buildScheduleBlock(now: Date): Promise<string> {
const dateKey = formatDateKey(now); const dateKey = formatDateKey(now);
const currentSlots = await this.getCurrentAndAdjacentSlots(now); const currentSlots = await this.getCurrentAndAdjacentSlots(now);
const currentBlock = currentSlots.length > 0 const currentBlock =
currentSlots.length > 0
? `Currently (around ${now.toTimeString().slice(0, 5)}):\n${currentSlots ? `Currently (around ${now.toTimeString().slice(0, 5)}):\n${currentSlots
.map( .map(
(s) => (s) =>
@@ -541,7 +546,8 @@ export class Brain {
label: "Yesterday", label: "Yesterday",
date: new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1), date: new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1),
}, },
{ label: "Tomorrow", {
label: "Tomorrow",
date: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1), date: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1),
}, },
]; ];
@@ -652,12 +658,15 @@ export class Brain {
description: displayName, description: displayName,
}; };
const brain = new Brain(db, space, { const brainbase: BrainItem = {
brainId, brainId,
spaceName: space.name, spaceName: space.name,
displayName, displayName,
baseSystemPrompt, baseSystemPrompt,
}); activated: true,
};
const brain = new Brain(db, space, brainbase);
await brain.add({ await brain.add({
customId: "persona", customId: "persona",
@@ -665,12 +674,6 @@ export class Brain {
metadata: { kind: "persona", source: "persona-init" }, metadata: { kind: "persona", source: "persona-init" },
}); });
const brainbase: BrainItem = {
brainId,
spaceName: space.name,
displayName,
baseSystemPrompt,
};
await brainManager.saveBrain(brainId, brainbase); await brainManager.saveBrain(brainId, brainbase);
return { brain, description, baseSystemPrompt }; return { brain, description, baseSystemPrompt };

View File

@@ -7,6 +7,7 @@ export interface BrainItem {
spaceName: string; spaceName: string;
displayName: string; displayName: string;
baseSystemPrompt: string; baseSystemPrompt: string;
activated: boolean;
} }
export type BrainList = BrainItem[]; export type BrainList = BrainItem[];
@@ -40,11 +41,9 @@ export class BrainDBManager {
private async writeIndex(list: BrainList): Promise<void> { private async writeIndex(list: BrainList): Promise<void> {
await mkdir(this.root, { recursive: true }); await mkdir(this.root, { recursive: true });
await writeFile( await writeFile(this.indexFile(), JSON.stringify(list, null, 2), {
this.indexFile(), encoding: "utf-8",
JSON.stringify(list, null, 2), });
{ encoding: "utf-8" },
);
} }
private async writeBrain(brain: BrainItem): Promise<void> { private async writeBrain(brain: BrainItem): Promise<void> {