import { sqliteTable, text, integer, uniqueIndex, index } from "drizzle-orm/sqlite-core"; // ============ AgentToolType ENUM ============ export const AgentToolTypes = ["fetch"] as const; export type AgentToolType = (typeof AgentToolTypes)[number]; // ============ AgentToolStatus ENUM ============ export const AgentToolLogStatuses = ["success", "error", "timeout"] as const; export type AgentToolLogStatus = (typeof AgentToolLogStatuses)[number]; // ============ AgentTool(工具定义表)============ export const agentTools = sqliteTable( "agent_tools", { id: text("id").primaryKey(), name: text("name", { length: 50 }).notNull(), slug: text("slug", { length: 50 }).notNull(), description: text("description").notNull(), type: text("type", { length: 30 }).notNull(), config: text("config").notNull(), enabled: integer("enabled").default(1).notNull(), sortOrder: integer("sort_order").default(0).notNull(), createdAt: integer("created_at", { mode: "timestamp_ms" }) .defaultNow() .notNull(), updatedAt: integer("updated_at", { mode: "timestamp_ms" }) .defaultNow() .$onUpdate(() => new Date()) .notNull(), }, (table) => [ uniqueIndex("agent_tools_slug_idx").on(table.slug), index("agent_tools_enabled_idx").on(table.enabled), ], ); // ============ AgentToolLog(工具执行日志表)============ export const agentToolLogs = sqliteTable( "agent_tool_logs", { id: integer("id").primaryKey({ autoIncrement: true }), toolId: text("tool_id").notNull(), toolSlug: text("tool_slug", { length: 50 }).notNull(), userId: integer("user_id"), input: text("input").notNull(), output: text("output"), status: text("status", { length: 20 }).notNull(), errorMessage: text("error_message"), durationMs: integer("duration_ms").notNull(), createdAt: integer("created_at", { mode: "timestamp_ms" }) .defaultNow() .notNull(), }, (table) => [ index("agent_tool_logs_tool_id_idx").on(table.toolId), index("agent_tool_logs_created_at_idx").on(table.createdAt), ], );