feat: add generation source handling for task creation and updates
All checks were successful
Build And Publish Production Image / Build And Publish Production Image (push) Successful in 50s

This commit is contained in:
2026-03-28 15:35:49 -03:00
parent ea54858165
commit 58c3a54d4a
14 changed files with 268 additions and 14 deletions

View File

@@ -39,6 +39,7 @@ const taskOne: EntityTaskResponse = {
prompt: 'Summarize jokes',
scheduleCron: '0 9 * * 1',
emailLookback: 'last_week',
generationSource: 'openai',
active: true,
createdAt: '2026-03-26T10:00:00Z',
}
@@ -50,6 +51,7 @@ const taskTwo: EntityTaskResponse = {
prompt: 'Escalate sandwich policy',
scheduleCron: '0 11 1 * *',
emailLookback: 'last_month',
generationSource: 'llama',
active: false,
createdAt: '2026-03-26T11:00:00Z',
}
@@ -72,6 +74,7 @@ const previewTask = {
prompt: 'Draft an absurdly official update about disappearing crackers.',
scheduleCron: '15 10 * * 2',
emailLookback: 'last_week' as const,
generationSource: 'openai' as const,
}
describe('tasksApi', () => {
@@ -143,6 +146,7 @@ describe('tasksApi', () => {
prompt: 'Ask about ceremonial coffee',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_day',
generationSource: 'openai',
})
expect(createdTask).toEqual(
@@ -157,6 +161,7 @@ describe('tasksApi', () => {
prompt: 'Ask about ceremonial coffee',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_day',
generationSource: 'openai',
})
})
@@ -168,6 +173,7 @@ describe('tasksApi', () => {
prompt: 'Ask about ceremonial coffee',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_day',
generationSource: 'llama',
},
})
@@ -177,6 +183,7 @@ describe('tasksApi', () => {
prompt: 'Ask about ceremonial coffee',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_day',
generationSource: 'llama',
})
expect(updatedTask).toEqual({
@@ -185,6 +192,7 @@ describe('tasksApi', () => {
prompt: 'Ask about ceremonial coffee',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_day',
generationSource: 'llama',
})
expect(mockedApiClient.put).toHaveBeenCalledWith('/v1/tasks/task-1', {
entityId: 'entity-1',
@@ -192,6 +200,7 @@ describe('tasksApi', () => {
prompt: 'Ask about ceremonial coffee',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_day',
generationSource: 'llama',
})
})

View File

@@ -50,6 +50,7 @@ describe('CreateTaskPage', () => {
expect(screen.getByLabelText(/task name/i)).toBeInTheDocument()
expect(screen.queryByLabelText(/task prompt/i)).not.toBeInTheDocument()
expect(screen.getByLabelText(/^Generation Source$/i)).toHaveValue('openai')
expect(screen.getByLabelText(/^Email Period$/i)).toBeInTheDocument()
expect(screen.getByLabelText(/^Minute$/i)).toBeInTheDocument()
expect(screen.getByLabelText(/^Hour$/i)).toBeInTheDocument()
@@ -68,6 +69,7 @@ describe('CreateTaskPage', () => {
prompt: '',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_week',
generationSource: 'openai',
active: false,
createdAt: '2026-03-26T10:00:00Z',
})
@@ -78,6 +80,7 @@ describe('CreateTaskPage', () => {
prompt: '',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_week',
generationSource: 'openai',
active: false,
createdAt: '2026-03-26T10:00:00Z',
})
@@ -118,6 +121,7 @@ describe('CreateTaskPage', () => {
prompt: '',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_week',
generationSource: 'openai',
})
)
expect(tasksApi.inactivateTask).toHaveBeenCalledWith('task-2')

View File

@@ -57,6 +57,7 @@ const mockTask = {
prompt: 'Summarize jokes',
scheduleCron: '0 9 * * 1',
emailLookback: 'last_week' as const,
generationSource: 'openai' as const,
active: true,
createdAt: '2026-03-26T10:00:00Z',
}
@@ -77,7 +78,7 @@ describe('EditTaskPage', () => {
vi.mocked(tasksApi.getTask).mockResolvedValue(mockTask)
vi.mocked(tasksApi.buildTaskPreviewPrompt).mockImplementation(
(entity, task) =>
`PROMPT FOR ${entity.name}: ${task.name} | ${task.prompt} | ${task.scheduleCron} | ${task.emailLookback}`
`PROMPT FOR ${entity.name}: ${task.name} | ${task.prompt} | ${task.scheduleCron} | ${task.emailLookback} | ${task.generationSource}`
)
vi.mocked(tasksApi.activateTask).mockResolvedValue({ ...mockTask, active: true })
vi.mocked(tasksApi.inactivateTask).mockResolvedValue({ ...mockTask, active: false })
@@ -97,6 +98,7 @@ describe('EditTaskPage', () => {
expect(screen.getByRole('heading', { name: /edit task/i })).toBeInTheDocument()
expect(screen.getByLabelText(/task name/i)).toHaveValue('Weekly Check-in')
expect(screen.getByLabelText(/task prompt/i)).toHaveValue('Summarize jokes')
expect(screen.getByLabelText(/^Generation Source$/i)).toHaveValue('openai')
expect(screen.getByLabelText(/^Email Period$/i)).toHaveValue('last_week')
expect(screen.getByLabelText(/^Minute$/i)).toHaveValue('0')
expect(screen.getByLabelText(/^Hour$/i)).toHaveValue('9')
@@ -124,6 +126,7 @@ describe('EditTaskPage', () => {
prompt: 'Ask about ceremonial coffee',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_day',
generationSource: 'llama',
})
const { queryClient } = renderPage()
@@ -137,13 +140,16 @@ describe('EditTaskPage', () => {
fireEvent.change(screen.getByLabelText(/^Email Period$/i), {
target: { value: 'last_day' },
})
fireEvent.change(screen.getByLabelText(/^Generation Source$/i), {
target: { value: 'llama' },
})
fireEvent.click(screen.getByRole('button', { name: /Weekdays/i }))
fireEvent.change(screen.getByLabelText(/^Hour$/i), { target: { value: '8' } })
expect(screen.getByText(/Final Prompt/i)).toBeInTheDocument()
expect(
screen.getByText(
'PROMPT FOR Entity A: Daily Check-in | Ask about ceremonial coffee | 0 8 * * 1-5 | last_day'
'PROMPT FOR Entity A: Daily Check-in | Ask about ceremonial coffee | 0 8 * * 1-5 | last_day | llama'
)
).toBeInTheDocument()
@@ -159,6 +165,7 @@ describe('EditTaskPage', () => {
prompt: 'Ask about ceremonial coffee',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_day',
generationSource: 'llama',
})
)
expect(vi.mocked(tasksApi.generateTaskPreview).mock.calls[0][0]).toEqual('task-1')
@@ -171,6 +178,7 @@ describe('EditTaskPage', () => {
prompt: 'Ask about ceremonial coffee',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_day',
generationSource: 'llama',
}),
})
)
@@ -186,6 +194,7 @@ describe('EditTaskPage', () => {
prompt: 'Ask about ceremonial coffee',
scheduleCron: '0 8 * * 1-5',
emailLookback: 'last_day',
generationSource: 'llama',
})
expect(invalidateQueriesSpy).toHaveBeenCalledWith({ queryKey: ['entity-tasks', 'entity-1'] })
expect(invalidateQueriesSpy).toHaveBeenCalledWith({ queryKey: ['entity-task', 'task-1'] })

View File

@@ -120,6 +120,7 @@ describe('EntityDetailPage', () => {
prompt: 'Summarize jokes',
scheduleCron: '0 9 * * 1',
emailLookback: 'last_week',
generationSource: 'openai',
active: true,
createdAt: '2026-03-26T10:00:00Z',
},
@@ -165,6 +166,7 @@ describe('EntityDetailPage', () => {
prompt: 'Archive the sandwich minutes',
scheduleCron: '0 9 * * 1',
emailLookback: 'last_week',
generationSource: 'llama',
active: false,
createdAt: '2026-03-26T10:00:00Z',
},

View File

@@ -2,6 +2,7 @@ import type { VirtualEntityResponse } from './entitiesApi'
import apiClient from './apiClient'
export type EmailLookback = 'last_day' | 'last_week' | 'last_month'
export type GenerationSource = 'openai' | 'llama'
export interface EntityTaskResponse {
id: string
@@ -10,6 +11,7 @@ export interface EntityTaskResponse {
prompt: string
scheduleCron: string
emailLookback: EmailLookback
generationSource: GenerationSource
active: boolean
createdAt: string
}
@@ -20,6 +22,7 @@ export interface EntityTaskCreateDto {
prompt: string
scheduleCron: string
emailLookback: EmailLookback
generationSource: GenerationSource
}
export type EntityTaskUpdateDto = EntityTaskCreateDto

View File

@@ -6,12 +6,14 @@ import {
createTask,
inactivateTask,
type EmailLookback,
type GenerationSource,
} from '../api/tasksApi'
interface TaskFormState {
name: string
scheduleCron: string
emailLookback: EmailLookback
generationSource: GenerationSource
}
interface CronParts {
@@ -72,6 +74,7 @@ const DEFAULT_TASK_FORM: TaskFormState = {
name: '',
scheduleCron: buildCron(DEFAULT_CRON_PARTS),
emailLookback: 'last_week',
generationSource: 'openai',
}
export default function CreateTaskPage() {
@@ -151,6 +154,7 @@ export default function CreateTaskPage() {
prompt: '',
scheduleCron: taskForm.scheduleCron,
emailLookback: taskForm.emailLookback,
generationSource: taskForm.generationSource,
})
}}
>
@@ -167,6 +171,26 @@ export default function CreateTaskPage() {
/>
</div>
<div>
<label htmlFor="task-generation-source" className="text-sm font-medium text-slate-200">
Generation Source
</label>
<select
id="task-generation-source"
value={taskForm.generationSource}
onChange={(event) =>
setTaskForm((prev) => ({
...prev,
generationSource: event.target.value as GenerationSource,
}))
}
className="mt-1 w-full rounded-md border border-slate-700 bg-slate-900 px-3 py-2 text-sm text-slate-100"
>
<option value="openai">OpenAI</option>
<option value="llama">Llama</option>
</select>
</div>
<div>
<label htmlFor="task-lookback" className="text-sm font-medium text-slate-200">
Email Period

View File

@@ -13,6 +13,7 @@ import {
inactivateTask,
updateTask,
type EmailLookback,
type GenerationSource,
} from '../api/tasksApi'
interface TaskFormState {
@@ -20,6 +21,7 @@ interface TaskFormState {
prompt: string
scheduleCron: string
emailLookback: EmailLookback
generationSource: GenerationSource
}
interface CronParts {
@@ -97,6 +99,7 @@ const DEFAULT_TASK_FORM: TaskFormState = {
prompt: '',
scheduleCron: buildCron(DEFAULT_CRON_PARTS),
emailLookback: 'last_week',
generationSource: 'openai',
}
async function invalidateTaskQueries(
@@ -164,6 +167,7 @@ export default function EditTaskPage() {
prompt: task.prompt,
scheduleCron: task.scheduleCron,
emailLookback: task.emailLookback,
generationSource: task.generationSource,
})
}, [task])
@@ -175,6 +179,7 @@ export default function EditTaskPage() {
prompt: data.prompt,
scheduleCron: data.scheduleCron,
emailLookback: data.emailLookback,
generationSource: data.generationSource,
}),
onSuccess: async () => {
await invalidateTaskQueries(queryClient, entityId, taskId)
@@ -236,8 +241,16 @@ export default function EditTaskPage() {
prompt: taskForm.prompt,
scheduleCron: taskForm.scheduleCron,
emailLookback: taskForm.emailLookback,
generationSource: taskForm.generationSource,
}),
[entityId, taskForm.emailLookback, taskForm.name, taskForm.prompt, taskForm.scheduleCron]
[
entityId,
taskForm.emailLookback,
taskForm.generationSource,
taskForm.name,
taskForm.prompt,
taskForm.scheduleCron,
]
)
const finalPrompt = useMemo(() => {
@@ -352,6 +365,26 @@ export default function EditTaskPage() {
/>
</div>
<div>
<label htmlFor="task-generation-source" className="text-sm font-medium text-slate-200">
Generation Source
</label>
<select
id="task-generation-source"
value={taskForm.generationSource}
onChange={(event) =>
setTaskForm((prev) => ({
...prev,
generationSource: event.target.value as GenerationSource,
}))
}
className="mt-1 w-full rounded-md border border-slate-700 bg-slate-900 px-3 py-2 text-sm text-slate-100"
>
<option value="openai">OpenAI</option>
<option value="llama">Llama</option>
</select>
</div>
<div>
<label htmlFor="task-lookback" className="text-sm font-medium text-slate-200">
Email Period