maitrang04's picture
Upload 91 files
d125a03 verified
import { sql } from "drizzle-orm";
import { pgTable, text, varchar, integer, boolean, timestamp, real } from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod";
import { z } from "zod";
// AI Agent schema
export const agents = pgTable("agents", {
id: varchar("id").primaryKey().default(sql`gen_random_uuid()`),
name: text("name").notNull(),
status: text("status").notNull().default("active"), // active, waiting, issue
activeCallCount: integer("active_call_count").notNull().default(0),
});
export const insertAgentSchema = createInsertSchema(agents).omit({ id: true });
export type InsertAgent = z.infer<typeof insertAgentSchema>;
export type Agent = typeof agents.$inferSelect;
// Call schema
export const calls = pgTable("calls", {
id: varchar("id").primaryKey().default(sql`gen_random_uuid()`),
agentId: varchar("agent_id").notNull(),
customerId: varchar("customer_id").notNull(),
status: text("status").notNull().default("active"), // active, on-hold, completed
duration: integer("duration").notNull().default(0), // in seconds
startTime: timestamp("start_time").notNull().defaultNow(),
currentSpeaker: text("current_speaker").notNull().default("ai"), // ai, customer
sentimentScore: real("sentiment_score").notNull().default(0.5),
upsellAttempts: integer("upsell_attempts").notNull().default(0),
upsellSuccess: boolean("upsell_success").notNull().default(false),
});
export const insertCallSchema = createInsertSchema(calls).omit({ id: true });
export type InsertCall = z.infer<typeof insertCallSchema>;
export type Call = typeof calls.$inferSelect;
// Transcript message schema
export const transcriptMessages = pgTable("transcript_messages", {
id: varchar("id").primaryKey().default(sql`gen_random_uuid()`),
callId: varchar("call_id").notNull(),
speaker: text("speaker").notNull(), // ai, customer
content: text("content").notNull(),
timestamp: timestamp("timestamp").notNull().defaultNow(),
});
export const insertTranscriptMessageSchema = createInsertSchema(transcriptMessages).omit({ id: true });
export type InsertTranscriptMessage = z.infer<typeof insertTranscriptMessageSchema>;
export type TranscriptMessage = typeof transcriptMessages.$inferSelect;
// Customer schema
export const customers = pgTable("customers", {
id: varchar("id").primaryKey().default(sql`gen_random_uuid()`),
name: text("name").notNull(),
email: text("email").notNull(),
isVip: boolean("is_vip").notNull().default(false),
engagementScore: real("engagement_score").notNull().default(50),
purchaseHistory: integer("purchase_history").notNull().default(0), // total purchases count
totalSpend: real("total_spend").notNull().default(0),
});
export const insertCustomerSchema = createInsertSchema(customers).omit({ id: true });
export type InsertCustomer = z.infer<typeof insertCustomerSchema>;
export type Customer = typeof customers.$inferSelect;
// Personalized offer schema
export const offers = pgTable("offers", {
id: varchar("id").primaryKey().default(sql`gen_random_uuid()`),
customerId: varchar("customer_id").notNull(),
title: text("title").notNull(),
description: text("description").notNull(),
discount: real("discount").notNull().default(0),
priority: integer("priority").notNull().default(1),
});
export const insertOfferSchema = createInsertSchema(offers).omit({ id: true });
export type InsertOffer = z.infer<typeof insertOfferSchema>;
export type Offer = typeof offers.$inferSelect;
// KPI summary type (not stored, computed)
export type KPISummary = {
totalCalls: number;
averageDuration: number;
upsellSuccessRate: number;
aiHandledPercentage: number;
activeAgents: number;
waitingAgents: number;
issueAgents: number;
};
// Alert type
export type Alert = {
id: string;
level: "info" | "warning" | "critical";
message: string;
timestamp: Date;
};
// Timeline event type
export type TimelineEvent = {
id: string;
callId: string;
type: "call_start" | "upsell_attempt" | "sentiment_change" | "transfer" | "call_end";
description: string;
timestamp: Date;
};
// Users table (keeping for auth compatibility)
export const users = pgTable("users", {
id: varchar("id").primaryKey().default(sql`gen_random_uuid()`),
username: text("username").notNull().unique(),
password: text("password").notNull(),
});
export const insertUserSchema = createInsertSchema(users).pick({
username: true,
password: true,
});
export type InsertUser = z.infer<typeof insertUserSchema>;
export type User = typeof users.$inferSelect;