feat: LLM-based schedule generation

This commit is contained in:
2026-05-17 15:40:13 +09:00
parent 864f118a9b
commit 90214cec5c
6 changed files with 433 additions and 120 deletions

View File

@@ -4,25 +4,63 @@ import { InMemoryMemoryStore, Persona } from '../src';
describe('Persona schedules and availability', () => {
it('creates tomorrow as a ten-minute daily schedule and persists it in memory', async () => {
const memory = new InMemoryMemoryStore();
const persona = new Persona('Mina', 'Mina works weekdays and studies at night.', { memory, now: '2026-05-01T10:00:00.000Z' });
const persona = new Persona('Mina', 'Mina works weekdays and studies at night.', {
memory,
now: '2026-05-01T10:00:00.000Z',
models: {
schedule: {
async generateDailySchedule() {
return [
{ startTime: '00:00', endTime: '07:00', activity: 'sleep', title: 'Sleep', availabilityMode: 'offline' as const },
{ startTime: '07:00', endTime: '09:00', activity: 'morning routine', title: 'Morning routine', availabilityMode: 'online' as const },
{ startTime: '09:00', endTime: '18:00', activity: 'deep work', title: 'Deep work', availabilityMode: 'do-not-disturb' as const },
{ startTime: '18:00', endTime: '24:00', activity: 'free time', title: 'Free time', availabilityMode: 'online' as const },
];
},
async generateMonthlySchedule() {
return [];
},
},
},
});
const space = await persona.ready();
const entries = await persona.createDailySchedule('2026-05-01T10:00:00.000Z', 'Keep a normal work day.');
expect(entries).toHaveLength(144);
expect(entries).toHaveLength(4);
expect(entries[0]).toMatchObject({
spaceId: space.id,
startAt: '2026-05-02T00:00:00.000Z',
endAt: '2026-05-02T00:10:00.000Z',
endAt: '2026-05-02T07:00:00.000Z',
granularity: 'ten-minute',
activity: 'sleep',
});
expect(entries.at(-1)?.endAt).toBe('2026-05-03T00:00:00.000Z');
await expect(memory.listScheduleEntries(space.id, '2026-05-02T00:00:00.000Z', '2026-05-03T00:00:00.000Z')).resolves.toHaveLength(144);
await expect(
memory.listScheduleEntries(space.id, '2026-05-02T00:00:00.000Z', '2026-05-03T00:00:00.000Z'),
).resolves.toHaveLength(4);
});
it('derives online, do-not-disturb, and offline availability from the in-memory schedule window', async () => {
const memory = new InMemoryMemoryStore();
const persona = new Persona('Mina', 'Mina works weekdays and studies at night.', { memory, now: '2026-05-01T10:00:00.000Z' });
const persona = new Persona('Mina', 'Mina works weekdays and studies at night.', {
memory,
now: '2026-05-01T10:00:00.000Z',
models: {
schedule: {
async generateDailySchedule() {
return [
{ startTime: '00:00', endTime: '07:00', activity: 'sleep', title: 'Sleep', availabilityMode: 'offline' as const },
{ startTime: '07:00', endTime: '09:00', activity: 'morning routine', title: 'Morning routine', availabilityMode: 'online' as const },
{ startTime: '09:00', endTime: '18:00', activity: 'deep work', title: 'Deep work', availabilityMode: 'do-not-disturb' as const },
];
},
async generateMonthlySchedule() {
return [];
},
},
},
});
await persona.ready();
await persona.createDailySchedule('2026-05-01T10:00:00.000Z', 'Keep a normal work day.');
@@ -30,21 +68,46 @@ describe('Persona schedules and availability', () => {
expect(availability.windowStartAt).toBe('2026-05-01T00:00:00.000Z');
expect(availability.windowEndAt).toBe('2026-05-03T00:00:00.000Z');
expect(new Set(availability.ranges.map((range) => range.mode))).toEqual(new Set(['offline', 'online', 'do-not-disturb']));
expect(availability.ranges.find((range) => range.mode === 'offline')?.startAt).toBe('2026-05-02T00:00:00.000Z');
expect(new Set(availability.ranges.map((range) => range.mode))).toEqual(
new Set(['offline', 'online', 'do-not-disturb']),
);
expect(availability.ranges.find((range) => range.mode === 'offline')?.startAt).toBe(
'2026-05-02T00:00:00.000Z',
);
});
it('prunes schedule entries before a caller-provided cutoff', async () => {
const memory = new InMemoryMemoryStore();
const persona = new Persona('Mina', 'Mina works weekdays.', { memory, now: '2026-05-01T10:00:00.000Z' });
const persona = new Persona('Mina', 'Mina works weekdays.', {
memory,
now: '2026-05-01T10:00:00.000Z',
models: {
schedule: {
async generateDailySchedule() {
return [
{ startTime: '00:00', endTime: '06:00', activity: 'sleep', title: 'Sleep', availabilityMode: 'offline' as const },
{ startTime: '06:00', endTime: '12:00', activity: 'work', title: 'Work', availabilityMode: 'do-not-disturb' as const },
{ startTime: '12:00', endTime: '18:00', activity: 'study', title: 'Study', availabilityMode: 'do-not-disturb' as const },
{ startTime: '18:00', endTime: '24:00', activity: 'rest', title: 'Rest', availabilityMode: 'online' as const },
];
},
async generateMonthlySchedule() {
return [];
},
},
},
});
const space = await persona.ready();
await persona.createDailySchedule('2026-05-01T10:00:00.000Z', 'Keep a normal work day.');
const deleted = await persona.deleteSchedulesBefore('2026-05-02T12:00:00.000Z');
expect(deleted).toBe(72);
await expect(memory.listScheduleEntries(space.id, '2026-05-02T00:00:00.000Z', '2026-05-03T00:00:00.000Z')).resolves.toHaveLength(72);
expect(deleted).toBe(2);
await expect(
memory.listScheduleEntries(space.id, '2026-05-02T00:00:00.000Z', '2026-05-03T00:00:00.000Z'),
).resolves.toHaveLength(2);
const deletionFacts = await memory.findFacts(space.id, ['persona.schedule.deleted']);
expect(deletionFacts[0]?.metadata?.['deleted']).toBe(72);
expect(deletionFacts[0]?.metadata?.['deleted']).toBe(2);
});
});