mirror of
https://github.com/kennethnym/freya
synced 2026-07-05 15:31:14 +01:00
feat: add agent response scheduler
This commit is contained in:
@@ -48,6 +48,15 @@ const bytea = customType<{ data: Buffer }>({
|
||||
},
|
||||
})
|
||||
|
||||
export const ConversationResponseStateStatus = {
|
||||
Pending: "pending",
|
||||
Running: "running",
|
||||
Failed: "failed",
|
||||
} as const
|
||||
|
||||
export type ConversationResponseStateStatus =
|
||||
(typeof ConversationResponseStateStatus)[keyof typeof ConversationResponseStateStatus]
|
||||
|
||||
export const userSources = pgTable(
|
||||
"user_sources",
|
||||
{
|
||||
@@ -146,6 +155,38 @@ export const conversationEntries = pgTable(
|
||||
],
|
||||
)
|
||||
|
||||
export const conversationResponseState = pgTable(
|
||||
"conversation_response_state",
|
||||
{
|
||||
conversationId: uuid("conversation_id")
|
||||
.primaryKey()
|
||||
.references(() => conversations.id, { onDelete: "cascade" }),
|
||||
status: text("status")
|
||||
.$type<ConversationResponseStateStatus>()
|
||||
.notNull()
|
||||
.default(ConversationResponseStateStatus.Pending),
|
||||
pendingSinceEntryId: uuid("pending_since_entry_id")
|
||||
.notNull()
|
||||
.references(() => conversationEntries.id, { onDelete: "cascade" }),
|
||||
maxWaitUntil: timestamp("max_wait_until").notNull(),
|
||||
runningSince: timestamp("running_since"),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at")
|
||||
.notNull()
|
||||
.defaultNow()
|
||||
.$onUpdate(() => new Date()),
|
||||
},
|
||||
(t) => [
|
||||
index("conversation_response_state_status_max_wait_until_idx").on(t.status, t.maxWaitUntil),
|
||||
index("conversation_response_state_running_since_idx").on(t.runningSince),
|
||||
index("conversation_response_state_pending_since_entry_id_idx").on(t.pendingSinceEntryId),
|
||||
check(
|
||||
"conversation_response_state_status_check",
|
||||
sql`${t.status} in ('pending', 'running', 'failed')`,
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// FREYA — reminders source storage
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user