import { bigint, index, jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
import { agents } from "./agents.js";
import { organizations } from "./organizations.js";
export const agentRuntimeState = pgTable("agent_runtime_state", {
    agentId: uuid("agent_id").primaryKey().references(() => agents.id),
    orgId: uuid("org_id").notNull().references(() => organizations.id),
    agentRuntimeType: text("agent_runtime_type").notNull(),
    sessionId: text("session_id"),
    stateJson: jsonb("state_json").$type().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.orgId, table.agentId),
    companyUpdatedIdx: index("agent_runtime_state_company_updated_idx").on(table.orgId, table.updatedAt),
}));
//# sourceMappingURL=agent_runtime_state.js.map