Add agent runtime DB schemas and expand shared types
New schemas: agent_runtime_state, agent_wakeup_requests, heartbeat_run_events. New migrations for runtime tables. Expand heartbeat types with run events, wakeup reasons, and adapter state. Add live event types. Update agent schema and shared constants. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
28
packages/db/src/schema/agent_runtime_state.ts
Normal file
28
packages/db/src/schema/agent_runtime_state.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { pgTable, uuid, text, timestamp, jsonb, bigint, index } from "drizzle-orm/pg-core";
|
||||
import { agents } from "./agents.js";
|
||||
import { companies } from "./companies.js";
|
||||
|
||||
export const agentRuntimeState = pgTable(
|
||||
"agent_runtime_state",
|
||||
{
|
||||
agentId: uuid("agent_id").primaryKey().references(() => agents.id),
|
||||
companyId: uuid("company_id").notNull().references(() => companies.id),
|
||||
adapterType: text("adapter_type").notNull(),
|
||||
sessionId: text("session_id"),
|
||||
stateJson: jsonb("state_json").$type<Record<string, unknown>>().notNull().default({}),
|
||||
lastRunId: uuid("last_run_id"),
|
||||
lastRunStatus: text("last_run_status"),
|
||||
totalInputTokens: bigint("total_input_tokens", { mode: "number" }).notNull().default(0),
|
||||
totalOutputTokens: bigint("total_output_tokens", { mode: "number" }).notNull().default(0),
|
||||
totalCachedInputTokens: bigint("total_cached_input_tokens", { mode: "number" }).notNull().default(0),
|
||||
totalCostCents: bigint("total_cost_cents", { mode: "number" }).notNull().default(0),
|
||||
lastError: text("last_error"),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(table) => ({
|
||||
companyAgentIdx: index("agent_runtime_state_company_agent_idx").on(table.companyId, table.agentId),
|
||||
companyUpdatedIdx: index("agent_runtime_state_company_updated_idx").on(table.companyId, table.updatedAt),
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user