feat: add activated property to BrainItem
This commit is contained in:
@@ -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,21 +531,23 @@ 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 =
|
||||||
? `Currently (around ${now.toTimeString().slice(0, 5)}):\n${currentSlots
|
currentSlots.length > 0
|
||||||
.map(
|
? `Currently (around ${now.toTimeString().slice(0, 5)}):\n${currentSlots
|
||||||
(s) =>
|
.map(
|
||||||
` ${s.start}-${s.end} ${s.activity}${s.notes ? ` (${s.notes})` : ""}`,
|
(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)`;
|
.join("\n")}`
|
||||||
|
: `Currently (${dateKey} ${now.toTimeString().slice(0, 5)}): (no matching slot in today's schedule)`;
|
||||||
|
|
||||||
const days: { label: string; date: Date }[] = [
|
const days: { label: string; date: Date }[] = [
|
||||||
{
|
{
|
||||||
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 };
|
||||||
|
|||||||
@@ -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> {
|
||||||
|
|||||||
Reference in New Issue
Block a user