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

View File

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