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
All checks were successful
Build And Publish Production Image / Build And Publish Production Image (push) Successful in 50s
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.condado.newsletter.dto
|
package com.condado.newsletter.dto
|
||||||
|
|
||||||
import com.condado.newsletter.model.EntityTask
|
import com.condado.newsletter.model.EntityTask
|
||||||
|
import com.condado.newsletter.model.TaskGenerationSource
|
||||||
import jakarta.validation.constraints.NotBlank
|
import jakarta.validation.constraints.NotBlank
|
||||||
import jakarta.validation.constraints.NotNull
|
import jakarta.validation.constraints.NotNull
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
@@ -11,7 +12,8 @@ data class EntityTaskCreateDto(
|
|||||||
@field:NotBlank val name: String,
|
@field:NotBlank val name: String,
|
||||||
val prompt: String,
|
val prompt: String,
|
||||||
@field:NotBlank val scheduleCron: String,
|
@field:NotBlank val scheduleCron: String,
|
||||||
@field:NotBlank val emailLookback: String
|
@field:NotBlank val emailLookback: String,
|
||||||
|
val generationSource: TaskGenerationSource = TaskGenerationSource.LLAMA
|
||||||
)
|
)
|
||||||
|
|
||||||
data class EntityTaskUpdateDto(
|
data class EntityTaskUpdateDto(
|
||||||
@@ -19,7 +21,8 @@ data class EntityTaskUpdateDto(
|
|||||||
@field:NotBlank val name: String,
|
@field:NotBlank val name: String,
|
||||||
@field:NotBlank val prompt: String,
|
@field:NotBlank val prompt: String,
|
||||||
@field:NotBlank val scheduleCron: String,
|
@field:NotBlank val scheduleCron: String,
|
||||||
@field:NotBlank val emailLookback: String
|
@field:NotBlank val emailLookback: String,
|
||||||
|
val generationSource: TaskGenerationSource? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
data class EntityTaskResponseDto(
|
data class EntityTaskResponseDto(
|
||||||
@@ -29,6 +32,7 @@ data class EntityTaskResponseDto(
|
|||||||
val prompt: String,
|
val prompt: String,
|
||||||
val scheduleCron: String,
|
val scheduleCron: String,
|
||||||
val emailLookback: String,
|
val emailLookback: String,
|
||||||
|
val generationSource: TaskGenerationSource,
|
||||||
val active: Boolean,
|
val active: Boolean,
|
||||||
val createdAt: LocalDateTime?
|
val createdAt: LocalDateTime?
|
||||||
) {
|
) {
|
||||||
@@ -41,6 +45,7 @@ data class EntityTaskResponseDto(
|
|||||||
prompt = task.prompt,
|
prompt = task.prompt,
|
||||||
scheduleCron = task.scheduleCron,
|
scheduleCron = task.scheduleCron,
|
||||||
emailLookback = task.emailLookback,
|
emailLookback = task.emailLookback,
|
||||||
|
generationSource = task.generationSource,
|
||||||
active = task.active,
|
active = task.active,
|
||||||
createdAt = task.createdAt
|
createdAt = task.createdAt
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.condado.newsletter.model
|
|||||||
import jakarta.persistence.CascadeType
|
import jakarta.persistence.CascadeType
|
||||||
import jakarta.persistence.Column
|
import jakarta.persistence.Column
|
||||||
import jakarta.persistence.Entity
|
import jakarta.persistence.Entity
|
||||||
|
import jakarta.persistence.EnumType
|
||||||
|
import jakarta.persistence.Enumerated
|
||||||
import jakarta.persistence.FetchType
|
import jakarta.persistence.FetchType
|
||||||
import jakarta.persistence.GeneratedValue
|
import jakarta.persistence.GeneratedValue
|
||||||
import jakarta.persistence.GenerationType
|
import jakarta.persistence.GenerationType
|
||||||
@@ -37,6 +39,10 @@ class EntityTask(
|
|||||||
@Column(name = "email_lookback", nullable = false)
|
@Column(name = "email_lookback", nullable = false)
|
||||||
val emailLookback: String,
|
val emailLookback: String,
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(name = "generation_source", nullable = false)
|
||||||
|
val generationSource: TaskGenerationSource = TaskGenerationSource.LLAMA,
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
val active: Boolean = true,
|
val active: Boolean = true,
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.condado.newsletter.model
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue
|
||||||
|
|
||||||
|
enum class TaskGenerationSource(
|
||||||
|
@get:JsonValue val value: String
|
||||||
|
) {
|
||||||
|
OPENAI("openai"),
|
||||||
|
LLAMA("llama");
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
@JsonCreator
|
||||||
|
fun from(value: String): TaskGenerationSource =
|
||||||
|
entries.firstOrNull { it.value.equals(value, ignoreCase = true) }
|
||||||
|
?: throw IllegalArgumentException("Invalid generationSource: $value")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,6 +47,7 @@ class EntityTaskService(
|
|||||||
prompt = dto.prompt,
|
prompt = dto.prompt,
|
||||||
scheduleCron = dto.scheduleCron,
|
scheduleCron = dto.scheduleCron,
|
||||||
emailLookback = dto.emailLookback,
|
emailLookback = dto.emailLookback,
|
||||||
|
generationSource = dto.generationSource,
|
||||||
active = true
|
active = true
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -66,6 +67,7 @@ class EntityTaskService(
|
|||||||
prompt = dto.prompt,
|
prompt = dto.prompt,
|
||||||
scheduleCron = dto.scheduleCron,
|
scheduleCron = dto.scheduleCron,
|
||||||
emailLookback = dto.emailLookback,
|
emailLookback = dto.emailLookback,
|
||||||
|
generationSource = dto.generationSource ?: existing.generationSource,
|
||||||
active = existing.active,
|
active = existing.active,
|
||||||
createdAt = existing.createdAt
|
createdAt = existing.createdAt
|
||||||
).apply { id = existing.id }
|
).apply { id = existing.id }
|
||||||
@@ -83,6 +85,7 @@ class EntityTaskService(
|
|||||||
prompt = existing.prompt,
|
prompt = existing.prompt,
|
||||||
scheduleCron = existing.scheduleCron,
|
scheduleCron = existing.scheduleCron,
|
||||||
emailLookback = existing.emailLookback,
|
emailLookback = existing.emailLookback,
|
||||||
|
generationSource = existing.generationSource,
|
||||||
active = false,
|
active = false,
|
||||||
createdAt = existing.createdAt
|
createdAt = existing.createdAt
|
||||||
).apply { id = existing.id }
|
).apply { id = existing.id }
|
||||||
@@ -100,6 +103,7 @@ class EntityTaskService(
|
|||||||
prompt = existing.prompt,
|
prompt = existing.prompt,
|
||||||
scheduleCron = existing.scheduleCron,
|
scheduleCron = existing.scheduleCron,
|
||||||
emailLookback = existing.emailLookback,
|
emailLookback = existing.emailLookback,
|
||||||
|
generationSource = existing.generationSource,
|
||||||
active = true,
|
active = true,
|
||||||
createdAt = existing.createdAt
|
createdAt = existing.createdAt
|
||||||
).apply { id = existing.id }
|
).apply { id = existing.id }
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.condado.newsletter.service
|
|||||||
import com.condado.newsletter.dto.GeneratedMessageHistoryResponseDto
|
import com.condado.newsletter.dto.GeneratedMessageHistoryResponseDto
|
||||||
import com.condado.newsletter.dto.TaskPreviewGenerateRequestDto
|
import com.condado.newsletter.dto.TaskPreviewGenerateRequestDto
|
||||||
import com.condado.newsletter.model.GeneratedMessageHistory
|
import com.condado.newsletter.model.GeneratedMessageHistory
|
||||||
|
import com.condado.newsletter.model.TaskGenerationSource
|
||||||
import com.condado.newsletter.repository.EntityTaskRepository
|
import com.condado.newsletter.repository.EntityTaskRepository
|
||||||
import com.condado.newsletter.repository.GeneratedMessageHistoryRepository
|
import com.condado.newsletter.repository.GeneratedMessageHistoryRepository
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
@@ -16,7 +17,8 @@ import java.util.UUID
|
|||||||
class TaskGeneratedMessageService(
|
class TaskGeneratedMessageService(
|
||||||
private val generatedMessageHistoryRepository: GeneratedMessageHistoryRepository,
|
private val generatedMessageHistoryRepository: GeneratedMessageHistoryRepository,
|
||||||
private val entityTaskRepository: EntityTaskRepository,
|
private val entityTaskRepository: EntityTaskRepository,
|
||||||
private val llamaPreviewService: LlamaPreviewService
|
private val llamaPreviewService: LlamaPreviewService,
|
||||||
|
private val aiService: AiService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/** Lists persisted generated messages for a task. */
|
/** Lists persisted generated messages for a task. */
|
||||||
@@ -25,15 +27,19 @@ class TaskGeneratedMessageService(
|
|||||||
.findAllByTask_IdOrderByCreatedAtDesc(taskId)
|
.findAllByTask_IdOrderByCreatedAtDesc(taskId)
|
||||||
.map { GeneratedMessageHistoryResponseDto.from(it) }
|
.map { GeneratedMessageHistoryResponseDto.from(it) }
|
||||||
|
|
||||||
/**
|
/** Generates a new message with the task-selected provider, persists it, and returns it. */
|
||||||
* Generates a new message using local Llama, persists it, and returns it.
|
|
||||||
*/
|
|
||||||
@Transactional
|
@Transactional
|
||||||
fun generateAndSave(taskId: UUID, request: TaskPreviewGenerateRequestDto): GeneratedMessageHistoryResponseDto {
|
fun generateAndSave(taskId: UUID, request: TaskPreviewGenerateRequestDto): GeneratedMessageHistoryResponseDto {
|
||||||
val task = entityTaskRepository.findById(taskId)
|
val task = entityTaskRepository.findById(taskId)
|
||||||
.orElseThrow { IllegalArgumentException("Task not found: $taskId") }
|
.orElseThrow { IllegalArgumentException("Task not found: $taskId") }
|
||||||
val prompt = buildPrompt(request)
|
val prompt = buildPrompt(request)
|
||||||
val generatedContent = llamaPreviewService.generate(prompt)
|
val generatedContent = when (task.generationSource) {
|
||||||
|
TaskGenerationSource.LLAMA -> llamaPreviewService.generate(prompt)
|
||||||
|
TaskGenerationSource.OPENAI -> {
|
||||||
|
val parsed = aiService.generate(prompt)
|
||||||
|
"SUBJECT: ${parsed.subject}\nBODY:\n${parsed.body}"
|
||||||
|
}
|
||||||
|
}
|
||||||
val nextLabel = "Message #${generatedMessageHistoryRepository.countByTask_Id(taskId) + 1}"
|
val nextLabel = "Message #${generatedMessageHistoryRepository.countByTask_Id(taskId) + 1}"
|
||||||
|
|
||||||
val saved = generatedMessageHistoryRepository.save(
|
val saved = generatedMessageHistoryRepository.save(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.condado.newsletter.scheduler.EntityScheduler
|
|||||||
import com.condado.newsletter.service.JwtService
|
import com.condado.newsletter.service.JwtService
|
||||||
import com.ninjasquad.springmockk.MockkBean
|
import com.ninjasquad.springmockk.MockkBean
|
||||||
import jakarta.servlet.http.Cookie
|
import jakarta.servlet.http.Cookie
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.AfterEach
|
import org.junit.jupiter.api.AfterEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
@@ -15,6 +16,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
|
|||||||
import org.springframework.boot.test.context.SpringBootTest
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.test.web.servlet.MockMvc
|
import org.springframework.test.web.servlet.MockMvc
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
|
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
|
||||||
@@ -56,7 +58,8 @@ class EntityTaskControllerTest {
|
|||||||
"name": "Morning Blast",
|
"name": "Morning Blast",
|
||||||
"prompt": "",
|
"prompt": "",
|
||||||
"scheduleCron": "0 8 * * 1-5",
|
"scheduleCron": "0 8 * * 1-5",
|
||||||
"emailLookback": "last_week"
|
"emailLookback": "last_week",
|
||||||
|
"generationSource": "openai"
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
@@ -70,5 +73,96 @@ class EntityTaskControllerTest {
|
|||||||
.andExpect(jsonPath("$.entityId").value(entity.id.toString()))
|
.andExpect(jsonPath("$.entityId").value(entity.id.toString()))
|
||||||
.andExpect(jsonPath("$.name").value("Morning Blast"))
|
.andExpect(jsonPath("$.name").value("Morning Blast"))
|
||||||
.andExpect(jsonPath("$.prompt").value(""))
|
.andExpect(jsonPath("$.prompt").value(""))
|
||||||
|
.andExpect(jsonPath("$.generationSource").value("openai"))
|
||||||
|
|
||||||
|
val persisted = entityTaskRepository.findAll().first()
|
||||||
|
assertThat(persisted.generationSource.value).isEqualTo("openai")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun should_updateTaskAndPersistGenerationSource_when_validRequestProvided() {
|
||||||
|
val entity = virtualEntityRepository.save(
|
||||||
|
VirtualEntity(
|
||||||
|
name = "Entity B",
|
||||||
|
email = "entity-b@condado.com",
|
||||||
|
jobTitle = "Ops"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val createdPayload = """
|
||||||
|
{
|
||||||
|
"entityId": "${entity.id}",
|
||||||
|
"name": "Task One",
|
||||||
|
"prompt": "Initial prompt",
|
||||||
|
"scheduleCron": "0 8 * * 1-5",
|
||||||
|
"emailLookback": "last_week",
|
||||||
|
"generationSource": "openai"
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
val createdResult = mockMvc.perform(
|
||||||
|
post("/api/v1/tasks")
|
||||||
|
.cookie(authCookie())
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content(createdPayload)
|
||||||
|
)
|
||||||
|
.andExpect(status().isCreated)
|
||||||
|
.andReturn()
|
||||||
|
|
||||||
|
val taskId = com.jayway.jsonpath.JsonPath.read<String>(createdResult.response.contentAsString, "$.id")
|
||||||
|
|
||||||
|
val updatePayload = """
|
||||||
|
{
|
||||||
|
"entityId": "${entity.id}",
|
||||||
|
"name": "Task One Updated",
|
||||||
|
"prompt": "Updated prompt",
|
||||||
|
"scheduleCron": "0 10 * * 1-5",
|
||||||
|
"emailLookback": "last_day",
|
||||||
|
"generationSource": "llama"
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
mockMvc.perform(
|
||||||
|
put("/api/v1/tasks/$taskId")
|
||||||
|
.cookie(authCookie())
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content(updatePayload)
|
||||||
|
)
|
||||||
|
.andExpect(status().isOk)
|
||||||
|
.andExpect(jsonPath("$.name").value("Task One Updated"))
|
||||||
|
.andExpect(jsonPath("$.generationSource").value("llama"))
|
||||||
|
|
||||||
|
val persisted = entityTaskRepository.findById(java.util.UUID.fromString(taskId)).orElseThrow()
|
||||||
|
assertThat(persisted.generationSource.value).isEqualTo("llama")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun should_returnBadRequest_when_generationSourceIsInvalid() {
|
||||||
|
val entity = virtualEntityRepository.save(
|
||||||
|
VirtualEntity(
|
||||||
|
name = "Entity C",
|
||||||
|
email = "entity-c@condado.com",
|
||||||
|
jobTitle = "Ops"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val payload = """
|
||||||
|
{
|
||||||
|
"entityId": "${entity.id}",
|
||||||
|
"name": "Morning Blast",
|
||||||
|
"prompt": "Prompt",
|
||||||
|
"scheduleCron": "0 8 * * 1-5",
|
||||||
|
"emailLookback": "last_week",
|
||||||
|
"generationSource": "invalid-provider"
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
mockMvc.perform(
|
||||||
|
post("/api/v1/tasks")
|
||||||
|
.cookie(authCookie())
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content(payload)
|
||||||
|
)
|
||||||
|
.andExpect(status().isBadRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,8 @@ import com.condado.newsletter.dto.TaskPreviewGenerateRequestDto
|
|||||||
import com.condado.newsletter.dto.TaskPreviewTaskDto
|
import com.condado.newsletter.dto.TaskPreviewTaskDto
|
||||||
import com.condado.newsletter.model.EntityTask
|
import com.condado.newsletter.model.EntityTask
|
||||||
import com.condado.newsletter.model.GeneratedMessageHistory
|
import com.condado.newsletter.model.GeneratedMessageHistory
|
||||||
|
import com.condado.newsletter.model.ParsedAiResponse
|
||||||
|
import com.condado.newsletter.model.TaskGenerationSource
|
||||||
import com.condado.newsletter.model.VirtualEntity
|
import com.condado.newsletter.model.VirtualEntity
|
||||||
import com.condado.newsletter.repository.EntityTaskRepository
|
import com.condado.newsletter.repository.EntityTaskRepository
|
||||||
import com.condado.newsletter.repository.GeneratedMessageHistoryRepository
|
import com.condado.newsletter.repository.GeneratedMessageHistoryRepository
|
||||||
@@ -21,15 +23,17 @@ class TaskGeneratedMessageServiceTest {
|
|||||||
private val generatedMessageHistoryRepository: GeneratedMessageHistoryRepository = mockk()
|
private val generatedMessageHistoryRepository: GeneratedMessageHistoryRepository = mockk()
|
||||||
private val entityTaskRepository: EntityTaskRepository = mockk()
|
private val entityTaskRepository: EntityTaskRepository = mockk()
|
||||||
private val llamaPreviewService: LlamaPreviewService = mockk()
|
private val llamaPreviewService: LlamaPreviewService = mockk()
|
||||||
|
private val aiService: AiService = mockk()
|
||||||
|
|
||||||
private val service = TaskGeneratedMessageService(
|
private val service = TaskGeneratedMessageService(
|
||||||
generatedMessageHistoryRepository = generatedMessageHistoryRepository,
|
generatedMessageHistoryRepository = generatedMessageHistoryRepository,
|
||||||
entityTaskRepository = entityTaskRepository,
|
entityTaskRepository = entityTaskRepository,
|
||||||
llamaPreviewService = llamaPreviewService
|
llamaPreviewService = llamaPreviewService,
|
||||||
|
aiService = aiService
|
||||||
)
|
)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun should_generateAndPersistMessage_when_generateAndSaveCalled() {
|
fun should_useLlamaProvider_when_taskGenerationSourceIsLlama() {
|
||||||
val taskId = UUID.randomUUID()
|
val taskId = UUID.randomUUID()
|
||||||
val entity = VirtualEntity(name = "Entity", email = "e@x.com", jobTitle = "Ops").apply { id = UUID.randomUUID() }
|
val entity = VirtualEntity(name = "Entity", email = "e@x.com", jobTitle = "Ops").apply { id = UUID.randomUUID() }
|
||||||
val task = EntityTask(
|
val task = EntityTask(
|
||||||
@@ -37,7 +41,8 @@ class TaskGeneratedMessageServiceTest {
|
|||||||
name = "Task",
|
name = "Task",
|
||||||
prompt = "Prompt",
|
prompt = "Prompt",
|
||||||
scheduleCron = "0 9 * * 1",
|
scheduleCron = "0 9 * * 1",
|
||||||
emailLookback = "last_week"
|
emailLookback = "last_week",
|
||||||
|
generationSource = TaskGenerationSource.LLAMA
|
||||||
).apply { id = taskId }
|
).apply { id = taskId }
|
||||||
val captured = slot<GeneratedMessageHistory>()
|
val captured = slot<GeneratedMessageHistory>()
|
||||||
|
|
||||||
@@ -59,9 +64,40 @@ class TaskGeneratedMessageServiceTest {
|
|||||||
assertThat(captured.captured.task.id).isEqualTo(taskId)
|
assertThat(captured.captured.task.id).isEqualTo(taskId)
|
||||||
|
|
||||||
verify(exactly = 1) { llamaPreviewService.generate(any()) }
|
verify(exactly = 1) { llamaPreviewService.generate(any()) }
|
||||||
|
verify(exactly = 0) { aiService.generate(any()) }
|
||||||
verify(exactly = 1) { generatedMessageHistoryRepository.save(any()) }
|
verify(exactly = 1) { generatedMessageHistoryRepository.save(any()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun should_useOpenAiProvider_when_taskGenerationSourceIsOpenai() {
|
||||||
|
val taskId = UUID.randomUUID()
|
||||||
|
val entity = VirtualEntity(name = "Entity", email = "e@x.com", jobTitle = "Ops").apply { id = UUID.randomUUID() }
|
||||||
|
val task = EntityTask(
|
||||||
|
virtualEntity = entity,
|
||||||
|
name = "Task",
|
||||||
|
prompt = "Prompt",
|
||||||
|
scheduleCron = "0 9 * * 1",
|
||||||
|
emailLookback = "last_week",
|
||||||
|
generationSource = TaskGenerationSource.OPENAI
|
||||||
|
).apply { id = taskId }
|
||||||
|
val captured = slot<GeneratedMessageHistory>()
|
||||||
|
|
||||||
|
every { aiService.generate(any()) } returns ParsedAiResponse(subject = "Open Subject", body = "Open Body")
|
||||||
|
every { entityTaskRepository.findById(taskId) } returns java.util.Optional.of(task)
|
||||||
|
every { generatedMessageHistoryRepository.countByTask_Id(taskId) } returns 0
|
||||||
|
every { generatedMessageHistoryRepository.save(capture(captured)) } answers {
|
||||||
|
captured.captured.apply {
|
||||||
|
id = UUID.fromString("00000000-0000-0000-0000-000000000001")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val response = service.generateAndSave(taskId, sampleRequest())
|
||||||
|
|
||||||
|
assertThat(response.content).isEqualTo("SUBJECT: Open Subject\nBODY:\nOpen Body")
|
||||||
|
verify(exactly = 1) { aiService.generate(any()) }
|
||||||
|
verify(exactly = 0) { llamaPreviewService.generate(any()) }
|
||||||
|
}
|
||||||
|
|
||||||
private fun sampleRequest() = TaskPreviewGenerateRequestDto(
|
private fun sampleRequest() = TaskPreviewGenerateRequestDto(
|
||||||
entity = TaskPreviewEntityDto(
|
entity = TaskPreviewEntityDto(
|
||||||
id = UUID.randomUUID().toString(),
|
id = UUID.randomUUID().toString(),
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ const taskOne: EntityTaskResponse = {
|
|||||||
prompt: 'Summarize jokes',
|
prompt: 'Summarize jokes',
|
||||||
scheduleCron: '0 9 * * 1',
|
scheduleCron: '0 9 * * 1',
|
||||||
emailLookback: 'last_week',
|
emailLookback: 'last_week',
|
||||||
|
generationSource: 'openai',
|
||||||
active: true,
|
active: true,
|
||||||
createdAt: '2026-03-26T10:00:00Z',
|
createdAt: '2026-03-26T10:00:00Z',
|
||||||
}
|
}
|
||||||
@@ -50,6 +51,7 @@ const taskTwo: EntityTaskResponse = {
|
|||||||
prompt: 'Escalate sandwich policy',
|
prompt: 'Escalate sandwich policy',
|
||||||
scheduleCron: '0 11 1 * *',
|
scheduleCron: '0 11 1 * *',
|
||||||
emailLookback: 'last_month',
|
emailLookback: 'last_month',
|
||||||
|
generationSource: 'llama',
|
||||||
active: false,
|
active: false,
|
||||||
createdAt: '2026-03-26T11:00:00Z',
|
createdAt: '2026-03-26T11:00:00Z',
|
||||||
}
|
}
|
||||||
@@ -72,6 +74,7 @@ const previewTask = {
|
|||||||
prompt: 'Draft an absurdly official update about disappearing crackers.',
|
prompt: 'Draft an absurdly official update about disappearing crackers.',
|
||||||
scheduleCron: '15 10 * * 2',
|
scheduleCron: '15 10 * * 2',
|
||||||
emailLookback: 'last_week' as const,
|
emailLookback: 'last_week' as const,
|
||||||
|
generationSource: 'openai' as const,
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('tasksApi', () => {
|
describe('tasksApi', () => {
|
||||||
@@ -143,6 +146,7 @@ describe('tasksApi', () => {
|
|||||||
prompt: 'Ask about ceremonial coffee',
|
prompt: 'Ask about ceremonial coffee',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_day',
|
emailLookback: 'last_day',
|
||||||
|
generationSource: 'openai',
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(createdTask).toEqual(
|
expect(createdTask).toEqual(
|
||||||
@@ -157,6 +161,7 @@ describe('tasksApi', () => {
|
|||||||
prompt: 'Ask about ceremonial coffee',
|
prompt: 'Ask about ceremonial coffee',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_day',
|
emailLookback: 'last_day',
|
||||||
|
generationSource: 'openai',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -168,6 +173,7 @@ describe('tasksApi', () => {
|
|||||||
prompt: 'Ask about ceremonial coffee',
|
prompt: 'Ask about ceremonial coffee',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_day',
|
emailLookback: 'last_day',
|
||||||
|
generationSource: 'llama',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -177,6 +183,7 @@ describe('tasksApi', () => {
|
|||||||
prompt: 'Ask about ceremonial coffee',
|
prompt: 'Ask about ceremonial coffee',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_day',
|
emailLookback: 'last_day',
|
||||||
|
generationSource: 'llama',
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(updatedTask).toEqual({
|
expect(updatedTask).toEqual({
|
||||||
@@ -185,6 +192,7 @@ describe('tasksApi', () => {
|
|||||||
prompt: 'Ask about ceremonial coffee',
|
prompt: 'Ask about ceremonial coffee',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_day',
|
emailLookback: 'last_day',
|
||||||
|
generationSource: 'llama',
|
||||||
})
|
})
|
||||||
expect(mockedApiClient.put).toHaveBeenCalledWith('/v1/tasks/task-1', {
|
expect(mockedApiClient.put).toHaveBeenCalledWith('/v1/tasks/task-1', {
|
||||||
entityId: 'entity-1',
|
entityId: 'entity-1',
|
||||||
@@ -192,6 +200,7 @@ describe('tasksApi', () => {
|
|||||||
prompt: 'Ask about ceremonial coffee',
|
prompt: 'Ask about ceremonial coffee',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_day',
|
emailLookback: 'last_day',
|
||||||
|
generationSource: 'llama',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ describe('CreateTaskPage', () => {
|
|||||||
|
|
||||||
expect(screen.getByLabelText(/task name/i)).toBeInTheDocument()
|
expect(screen.getByLabelText(/task name/i)).toBeInTheDocument()
|
||||||
expect(screen.queryByLabelText(/task prompt/i)).not.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(/^Email Period$/i)).toBeInTheDocument()
|
||||||
expect(screen.getByLabelText(/^Minute$/i)).toBeInTheDocument()
|
expect(screen.getByLabelText(/^Minute$/i)).toBeInTheDocument()
|
||||||
expect(screen.getByLabelText(/^Hour$/i)).toBeInTheDocument()
|
expect(screen.getByLabelText(/^Hour$/i)).toBeInTheDocument()
|
||||||
@@ -68,6 +69,7 @@ describe('CreateTaskPage', () => {
|
|||||||
prompt: '',
|
prompt: '',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_week',
|
emailLookback: 'last_week',
|
||||||
|
generationSource: 'openai',
|
||||||
active: false,
|
active: false,
|
||||||
createdAt: '2026-03-26T10:00:00Z',
|
createdAt: '2026-03-26T10:00:00Z',
|
||||||
})
|
})
|
||||||
@@ -78,6 +80,7 @@ describe('CreateTaskPage', () => {
|
|||||||
prompt: '',
|
prompt: '',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_week',
|
emailLookback: 'last_week',
|
||||||
|
generationSource: 'openai',
|
||||||
active: false,
|
active: false,
|
||||||
createdAt: '2026-03-26T10:00:00Z',
|
createdAt: '2026-03-26T10:00:00Z',
|
||||||
})
|
})
|
||||||
@@ -118,6 +121,7 @@ describe('CreateTaskPage', () => {
|
|||||||
prompt: '',
|
prompt: '',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_week',
|
emailLookback: 'last_week',
|
||||||
|
generationSource: 'openai',
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
expect(tasksApi.inactivateTask).toHaveBeenCalledWith('task-2')
|
expect(tasksApi.inactivateTask).toHaveBeenCalledWith('task-2')
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ const mockTask = {
|
|||||||
prompt: 'Summarize jokes',
|
prompt: 'Summarize jokes',
|
||||||
scheduleCron: '0 9 * * 1',
|
scheduleCron: '0 9 * * 1',
|
||||||
emailLookback: 'last_week' as const,
|
emailLookback: 'last_week' as const,
|
||||||
|
generationSource: 'openai' as const,
|
||||||
active: true,
|
active: true,
|
||||||
createdAt: '2026-03-26T10:00:00Z',
|
createdAt: '2026-03-26T10:00:00Z',
|
||||||
}
|
}
|
||||||
@@ -77,7 +78,7 @@ describe('EditTaskPage', () => {
|
|||||||
vi.mocked(tasksApi.getTask).mockResolvedValue(mockTask)
|
vi.mocked(tasksApi.getTask).mockResolvedValue(mockTask)
|
||||||
vi.mocked(tasksApi.buildTaskPreviewPrompt).mockImplementation(
|
vi.mocked(tasksApi.buildTaskPreviewPrompt).mockImplementation(
|
||||||
(entity, task) =>
|
(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.activateTask).mockResolvedValue({ ...mockTask, active: true })
|
||||||
vi.mocked(tasksApi.inactivateTask).mockResolvedValue({ ...mockTask, active: false })
|
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.getByRole('heading', { name: /edit task/i })).toBeInTheDocument()
|
||||||
expect(screen.getByLabelText(/task name/i)).toHaveValue('Weekly Check-in')
|
expect(screen.getByLabelText(/task name/i)).toHaveValue('Weekly Check-in')
|
||||||
expect(screen.getByLabelText(/task prompt/i)).toHaveValue('Summarize jokes')
|
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(/^Email Period$/i)).toHaveValue('last_week')
|
||||||
expect(screen.getByLabelText(/^Minute$/i)).toHaveValue('0')
|
expect(screen.getByLabelText(/^Minute$/i)).toHaveValue('0')
|
||||||
expect(screen.getByLabelText(/^Hour$/i)).toHaveValue('9')
|
expect(screen.getByLabelText(/^Hour$/i)).toHaveValue('9')
|
||||||
@@ -124,6 +126,7 @@ describe('EditTaskPage', () => {
|
|||||||
prompt: 'Ask about ceremonial coffee',
|
prompt: 'Ask about ceremonial coffee',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_day',
|
emailLookback: 'last_day',
|
||||||
|
generationSource: 'llama',
|
||||||
})
|
})
|
||||||
|
|
||||||
const { queryClient } = renderPage()
|
const { queryClient } = renderPage()
|
||||||
@@ -137,13 +140,16 @@ describe('EditTaskPage', () => {
|
|||||||
fireEvent.change(screen.getByLabelText(/^Email Period$/i), {
|
fireEvent.change(screen.getByLabelText(/^Email Period$/i), {
|
||||||
target: { value: 'last_day' },
|
target: { value: 'last_day' },
|
||||||
})
|
})
|
||||||
|
fireEvent.change(screen.getByLabelText(/^Generation Source$/i), {
|
||||||
|
target: { value: 'llama' },
|
||||||
|
})
|
||||||
fireEvent.click(screen.getByRole('button', { name: /Weekdays/i }))
|
fireEvent.click(screen.getByRole('button', { name: /Weekdays/i }))
|
||||||
fireEvent.change(screen.getByLabelText(/^Hour$/i), { target: { value: '8' } })
|
fireEvent.change(screen.getByLabelText(/^Hour$/i), { target: { value: '8' } })
|
||||||
|
|
||||||
expect(screen.getByText(/Final Prompt/i)).toBeInTheDocument()
|
expect(screen.getByText(/Final Prompt/i)).toBeInTheDocument()
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(
|
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()
|
).toBeInTheDocument()
|
||||||
|
|
||||||
@@ -159,6 +165,7 @@ describe('EditTaskPage', () => {
|
|||||||
prompt: 'Ask about ceremonial coffee',
|
prompt: 'Ask about ceremonial coffee',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_day',
|
emailLookback: 'last_day',
|
||||||
|
generationSource: 'llama',
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
expect(vi.mocked(tasksApi.generateTaskPreview).mock.calls[0][0]).toEqual('task-1')
|
expect(vi.mocked(tasksApi.generateTaskPreview).mock.calls[0][0]).toEqual('task-1')
|
||||||
@@ -171,6 +178,7 @@ describe('EditTaskPage', () => {
|
|||||||
prompt: 'Ask about ceremonial coffee',
|
prompt: 'Ask about ceremonial coffee',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_day',
|
emailLookback: 'last_day',
|
||||||
|
generationSource: 'llama',
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -186,6 +194,7 @@ describe('EditTaskPage', () => {
|
|||||||
prompt: 'Ask about ceremonial coffee',
|
prompt: 'Ask about ceremonial coffee',
|
||||||
scheduleCron: '0 8 * * 1-5',
|
scheduleCron: '0 8 * * 1-5',
|
||||||
emailLookback: 'last_day',
|
emailLookback: 'last_day',
|
||||||
|
generationSource: 'llama',
|
||||||
})
|
})
|
||||||
expect(invalidateQueriesSpy).toHaveBeenCalledWith({ queryKey: ['entity-tasks', 'entity-1'] })
|
expect(invalidateQueriesSpy).toHaveBeenCalledWith({ queryKey: ['entity-tasks', 'entity-1'] })
|
||||||
expect(invalidateQueriesSpy).toHaveBeenCalledWith({ queryKey: ['entity-task', 'task-1'] })
|
expect(invalidateQueriesSpy).toHaveBeenCalledWith({ queryKey: ['entity-task', 'task-1'] })
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ describe('EntityDetailPage', () => {
|
|||||||
prompt: 'Summarize jokes',
|
prompt: 'Summarize jokes',
|
||||||
scheduleCron: '0 9 * * 1',
|
scheduleCron: '0 9 * * 1',
|
||||||
emailLookback: 'last_week',
|
emailLookback: 'last_week',
|
||||||
|
generationSource: 'openai',
|
||||||
active: true,
|
active: true,
|
||||||
createdAt: '2026-03-26T10:00:00Z',
|
createdAt: '2026-03-26T10:00:00Z',
|
||||||
},
|
},
|
||||||
@@ -165,6 +166,7 @@ describe('EntityDetailPage', () => {
|
|||||||
prompt: 'Archive the sandwich minutes',
|
prompt: 'Archive the sandwich minutes',
|
||||||
scheduleCron: '0 9 * * 1',
|
scheduleCron: '0 9 * * 1',
|
||||||
emailLookback: 'last_week',
|
emailLookback: 'last_week',
|
||||||
|
generationSource: 'llama',
|
||||||
active: false,
|
active: false,
|
||||||
createdAt: '2026-03-26T10:00:00Z',
|
createdAt: '2026-03-26T10:00:00Z',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { VirtualEntityResponse } from './entitiesApi'
|
|||||||
import apiClient from './apiClient'
|
import apiClient from './apiClient'
|
||||||
|
|
||||||
export type EmailLookback = 'last_day' | 'last_week' | 'last_month'
|
export type EmailLookback = 'last_day' | 'last_week' | 'last_month'
|
||||||
|
export type GenerationSource = 'openai' | 'llama'
|
||||||
|
|
||||||
export interface EntityTaskResponse {
|
export interface EntityTaskResponse {
|
||||||
id: string
|
id: string
|
||||||
@@ -10,6 +11,7 @@ export interface EntityTaskResponse {
|
|||||||
prompt: string
|
prompt: string
|
||||||
scheduleCron: string
|
scheduleCron: string
|
||||||
emailLookback: EmailLookback
|
emailLookback: EmailLookback
|
||||||
|
generationSource: GenerationSource
|
||||||
active: boolean
|
active: boolean
|
||||||
createdAt: string
|
createdAt: string
|
||||||
}
|
}
|
||||||
@@ -20,6 +22,7 @@ export interface EntityTaskCreateDto {
|
|||||||
prompt: string
|
prompt: string
|
||||||
scheduleCron: string
|
scheduleCron: string
|
||||||
emailLookback: EmailLookback
|
emailLookback: EmailLookback
|
||||||
|
generationSource: GenerationSource
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EntityTaskUpdateDto = EntityTaskCreateDto
|
export type EntityTaskUpdateDto = EntityTaskCreateDto
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ import {
|
|||||||
createTask,
|
createTask,
|
||||||
inactivateTask,
|
inactivateTask,
|
||||||
type EmailLookback,
|
type EmailLookback,
|
||||||
|
type GenerationSource,
|
||||||
} from '../api/tasksApi'
|
} from '../api/tasksApi'
|
||||||
|
|
||||||
interface TaskFormState {
|
interface TaskFormState {
|
||||||
name: string
|
name: string
|
||||||
scheduleCron: string
|
scheduleCron: string
|
||||||
emailLookback: EmailLookback
|
emailLookback: EmailLookback
|
||||||
|
generationSource: GenerationSource
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CronParts {
|
interface CronParts {
|
||||||
@@ -72,6 +74,7 @@ const DEFAULT_TASK_FORM: TaskFormState = {
|
|||||||
name: '',
|
name: '',
|
||||||
scheduleCron: buildCron(DEFAULT_CRON_PARTS),
|
scheduleCron: buildCron(DEFAULT_CRON_PARTS),
|
||||||
emailLookback: 'last_week',
|
emailLookback: 'last_week',
|
||||||
|
generationSource: 'openai',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CreateTaskPage() {
|
export default function CreateTaskPage() {
|
||||||
@@ -151,6 +154,7 @@ export default function CreateTaskPage() {
|
|||||||
prompt: '',
|
prompt: '',
|
||||||
scheduleCron: taskForm.scheduleCron,
|
scheduleCron: taskForm.scheduleCron,
|
||||||
emailLookback: taskForm.emailLookback,
|
emailLookback: taskForm.emailLookback,
|
||||||
|
generationSource: taskForm.generationSource,
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -167,6 +171,26 @@ export default function CreateTaskPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</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>
|
<div>
|
||||||
<label htmlFor="task-lookback" className="text-sm font-medium text-slate-200">
|
<label htmlFor="task-lookback" className="text-sm font-medium text-slate-200">
|
||||||
Email Period
|
Email Period
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
inactivateTask,
|
inactivateTask,
|
||||||
updateTask,
|
updateTask,
|
||||||
type EmailLookback,
|
type EmailLookback,
|
||||||
|
type GenerationSource,
|
||||||
} from '../api/tasksApi'
|
} from '../api/tasksApi'
|
||||||
|
|
||||||
interface TaskFormState {
|
interface TaskFormState {
|
||||||
@@ -20,6 +21,7 @@ interface TaskFormState {
|
|||||||
prompt: string
|
prompt: string
|
||||||
scheduleCron: string
|
scheduleCron: string
|
||||||
emailLookback: EmailLookback
|
emailLookback: EmailLookback
|
||||||
|
generationSource: GenerationSource
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CronParts {
|
interface CronParts {
|
||||||
@@ -97,6 +99,7 @@ const DEFAULT_TASK_FORM: TaskFormState = {
|
|||||||
prompt: '',
|
prompt: '',
|
||||||
scheduleCron: buildCron(DEFAULT_CRON_PARTS),
|
scheduleCron: buildCron(DEFAULT_CRON_PARTS),
|
||||||
emailLookback: 'last_week',
|
emailLookback: 'last_week',
|
||||||
|
generationSource: 'openai',
|
||||||
}
|
}
|
||||||
|
|
||||||
async function invalidateTaskQueries(
|
async function invalidateTaskQueries(
|
||||||
@@ -164,6 +167,7 @@ export default function EditTaskPage() {
|
|||||||
prompt: task.prompt,
|
prompt: task.prompt,
|
||||||
scheduleCron: task.scheduleCron,
|
scheduleCron: task.scheduleCron,
|
||||||
emailLookback: task.emailLookback,
|
emailLookback: task.emailLookback,
|
||||||
|
generationSource: task.generationSource,
|
||||||
})
|
})
|
||||||
}, [task])
|
}, [task])
|
||||||
|
|
||||||
@@ -175,6 +179,7 @@ export default function EditTaskPage() {
|
|||||||
prompt: data.prompt,
|
prompt: data.prompt,
|
||||||
scheduleCron: data.scheduleCron,
|
scheduleCron: data.scheduleCron,
|
||||||
emailLookback: data.emailLookback,
|
emailLookback: data.emailLookback,
|
||||||
|
generationSource: data.generationSource,
|
||||||
}),
|
}),
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
await invalidateTaskQueries(queryClient, entityId, taskId)
|
await invalidateTaskQueries(queryClient, entityId, taskId)
|
||||||
@@ -236,8 +241,16 @@ export default function EditTaskPage() {
|
|||||||
prompt: taskForm.prompt,
|
prompt: taskForm.prompt,
|
||||||
scheduleCron: taskForm.scheduleCron,
|
scheduleCron: taskForm.scheduleCron,
|
||||||
emailLookback: taskForm.emailLookback,
|
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(() => {
|
const finalPrompt = useMemo(() => {
|
||||||
@@ -352,6 +365,26 @@ export default function EditTaskPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</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>
|
<div>
|
||||||
<label htmlFor="task-lookback" className="text-sm font-medium text-slate-200">
|
<label htmlFor="task-lookback" className="text-sm font-medium text-slate-200">
|
||||||
Email Period
|
Email Period
|
||||||
|
|||||||
Reference in New Issue
Block a user