diff --git a/8cbc_backend/bun.lock b/8cbc_backend/bun.lock index 961ccf56..30f2b374 100644 --- a/8cbc_backend/bun.lock +++ b/8cbc_backend/bun.lock @@ -1,5 +1,6 @@ { "lockfileVersion": 1, + "configVersion": 0, "workspaces": { "": { "name": "8cbc_backend", diff --git a/8cbc_backend/controllers/calls/calls.controller.ts b/8cbc_backend/controllers/calls/calls.controller.ts index 31d9efcd..7687f0a8 100644 --- a/8cbc_backend/controllers/calls/calls.controller.ts +++ b/8cbc_backend/controllers/calls/calls.controller.ts @@ -228,11 +228,17 @@ const CallsController = () => { "Other", ]), reason: z.string().optional(), + aiSolutionsSummary: z.string().optional(), + escalationReason: z.string().optional(), + conversationContext: z.string().optional(), }).pick({ slotId: true, phoneNumber: true, category: true, reason: true, + aiSolutionsSummary: true, + escalationReason: true, + conversationContext: true, }); // Create Slot diff --git a/8cbc_backend/database/schema.ts b/8cbc_backend/database/schema.ts index 0d91c848..b36b392b 100644 --- a/8cbc_backend/database/schema.ts +++ b/8cbc_backend/database/schema.ts @@ -442,6 +442,10 @@ export const callBookingsTable = pgTable("call_bookings", { reason: text("reason"), status: callStatusEnum("status").notNull().default("Pending"), assignedAgentId: integer("assigned_agent_id").references(() => usersTable.id), + // AI Context Handoff fields (invisible to customer, visible to support agents) + aiSolutionsSummary: text("ai_solutions_summary"), // What the AI tried + escalationReason: text("escalation_reason"), // Why AI couldn't resolve + conversationContext: text("conversation_context"), // Key context for agent createdAt: timestamp("created_at").defaultNow().notNull(), updatedAt: timestamp("updated_at").defaultNow().notNull(), }); diff --git a/8cbc_backend/drizzle/0017_next_whirlwind.sql b/8cbc_backend/drizzle/0017_next_whirlwind.sql new file mode 100644 index 00000000..44cdd81a --- /dev/null +++ b/8cbc_backend/drizzle/0017_next_whirlwind.sql @@ -0,0 +1,3 @@ +ALTER TABLE "call_bookings" ADD COLUMN "ai_solutions_summary" text;--> statement-breakpoint +ALTER TABLE "call_bookings" ADD COLUMN "escalation_reason" text;--> statement-breakpoint +ALTER TABLE "call_bookings" ADD COLUMN "conversation_context" text; \ No newline at end of file diff --git a/8cbc_backend/drizzle/meta/0017_snapshot.json b/8cbc_backend/drizzle/meta/0017_snapshot.json new file mode 100644 index 00000000..2d805021 --- /dev/null +++ b/8cbc_backend/drizzle/meta/0017_snapshot.json @@ -0,0 +1,2520 @@ +{ + "id": "c0c3f7d0-230b-4362-8c79-18172f78cb04", + "prevId": "03286c91-6ef2-4b3d-b4ad-801b0626c43f", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.bank_accounts": { + "name": "bank_accounts", + "schema": "", + "columns": { + "account_id": { + "name": "account_id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "bank_accounts_account_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "account_type": { + "name": "account_type", + "type": "account_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "account_number": { + "name": "account_number", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "balance": { + "name": "balance", + "type": "numeric(15, 2)", + "primaryKey": false, + "notNull": true, + "default": "'0.00'" + }, + "interest_rate": { + "name": "interest_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "perks": { + "name": "perks", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "term_length_months": { + "name": "term_length_months", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "start_date": { + "name": "start_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "maturity_date": { + "name": "maturity_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "withdrawal_allowed": { + "name": "withdrawal_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_bank_accounts_user_id": { + "name": "idx_bank_accounts_user_id", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_bank_accounts_user_created_at": { + "name": "idx_bank_accounts_user_created_at", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "bank_accounts_user_id_users_id_fk": { + "name": "bank_accounts_user_id_users_id_fk", + "tableFrom": "bank_accounts", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "bank_accounts_account_number_unique": { + "name": "bank_accounts_account_number_unique", + "nullsNotDistinct": false, + "columns": [ + "account_number" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.branch": { + "name": "branch", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "branch_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "max_capacity": { + "name": "max_capacity", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.call_analysis": { + "name": "call_analysis", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "call_analysis_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "call_record_id": { + "name": "call_record_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "resolution_summary": { + "name": "resolution_summary", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "customer_sentiment": { + "name": "customer_sentiment", + "type": "sentiment", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "issue_resolved": { + "name": "issue_resolved", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "action_items": { + "name": "action_items", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "key_topics": { + "name": "key_topics", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "could_ai_resolve": { + "name": "could_ai_resolve", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "ai_improvement_notes": { + "name": "ai_improvement_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "uq_call_analysis_call_record_id": { + "name": "uq_call_analysis_call_record_id", + "columns": [ + { + "expression": "call_record_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_call_analysis_sentiment": { + "name": "idx_call_analysis_sentiment", + "columns": [ + { + "expression": "customer_sentiment", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "call_analysis_call_record_id_call_records_id_fk": { + "name": "call_analysis_call_record_id_call_records_id_fk", + "tableFrom": "call_analysis", + "tableTo": "call_records", + "columnsFrom": [ + "call_record_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.call_booking_history": { + "name": "call_booking_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "call_booking_history_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "booking_id": { + "name": "booking_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "change_type": { + "name": "change_type", + "type": "call_booking_change_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "old_value": { + "name": "old_value", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "new_value": { + "name": "new_value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "changed_by": { + "name": "changed_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_call_booking_history_booking_id": { + "name": "idx_call_booking_history_booking_id", + "columns": [ + { + "expression": "booking_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_call_booking_history_changed_by": { + "name": "idx_call_booking_history_changed_by", + "columns": [ + { + "expression": "changed_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_call_booking_history_booking_created": { + "name": "idx_call_booking_history_booking_created", + "columns": [ + { + "expression": "booking_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "call_booking_history_booking_id_call_bookings_id_fk": { + "name": "call_booking_history_booking_id_call_bookings_id_fk", + "tableFrom": "call_booking_history", + "tableTo": "call_bookings", + "columnsFrom": [ + "booking_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "call_booking_history_changed_by_users_id_fk": { + "name": "call_booking_history_changed_by_users_id_fk", + "tableFrom": "call_booking_history", + "tableTo": "users", + "columnsFrom": [ + "changed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.call_bookings": { + "name": "call_bookings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "call_bookings_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "slot_id": { + "name": "slot_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "phone_number": { + "name": "phone_number", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "call_category", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "call_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'Pending'" + }, + "assigned_agent_id": { + "name": "assigned_agent_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "ai_solutions_summary": { + "name": "ai_solutions_summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "escalation_reason": { + "name": "escalation_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "conversation_context": { + "name": "conversation_context", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "call_bookings_user_id_users_id_fk": { + "name": "call_bookings_user_id_users_id_fk", + "tableFrom": "call_bookings", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "call_bookings_slot_id_call_slots_id_fk": { + "name": "call_bookings_slot_id_call_slots_id_fk", + "tableFrom": "call_bookings", + "tableTo": "call_slots", + "columnsFrom": [ + "slot_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "call_bookings_assigned_agent_id_users_id_fk": { + "name": "call_bookings_assigned_agent_id_users_id_fk", + "tableFrom": "call_bookings", + "tableTo": "users", + "columnsFrom": [ + "assigned_agent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.call_records": { + "name": "call_records", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "call_records_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "booking_id": { + "name": "booking_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "twilio_call_sid": { + "name": "twilio_call_sid", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "recording_url": { + "name": "recording_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recording_sid": { + "name": "recording_sid", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "recording_duration_seconds": { + "name": "recording_duration_seconds", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "analysis_status": { + "name": "analysis_status", + "type": "analysis_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "transcript": { + "name": "transcript", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_call_records_booking_id": { + "name": "idx_call_records_booking_id", + "columns": [ + { + "expression": "booking_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "uq_call_records_twilio_call_sid": { + "name": "uq_call_records_twilio_call_sid", + "columns": [ + { + "expression": "twilio_call_sid", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "call_records_booking_id_call_bookings_id_fk": { + "name": "call_records_booking_id_call_bookings_id_fk", + "tableFrom": "call_records", + "tableTo": "call_bookings", + "columnsFrom": [ + "booking_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.call_slots": { + "name": "call_slots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "call_slots_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "start_time": { + "name": "start_time", + "type": "time", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cards": { + "name": "cards", + "schema": "", + "columns": { + "card_id": { + "name": "card_id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "cards_card_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "account_id": { + "name": "account_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "card_number": { + "name": "card_number", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "card_type": { + "name": "card_type", + "type": "card_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "expiration_date": { + "name": "expiration_date", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "cvv": { + "name": "cvv", + "type": "char(3)", + "primaryKey": false, + "notNull": true + }, + "card_status": { + "name": "card_status", + "type": "card_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'Active'" + }, + "daily_limit": { + "name": "daily_limit", + "type": "numeric(15, 2)", + "primaryKey": false, + "notNull": false + }, + "pin_hash": { + "name": "pin_hash", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "contactless_enabled": { + "name": "contactless_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "issued_branch": { + "name": "issued_branch", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "nickname": { + "name": "nickname", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_cards_account_id": { + "name": "idx_cards_account_id", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cards_account_id_bank_accounts_account_id_fk": { + "name": "cards_account_id_bank_accounts_account_id_fk", + "tableFrom": "cards", + "tableTo": "bank_accounts", + "columnsFrom": [ + "account_id" + ], + "columnsTo": [ + "account_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "cards_card_number_unique": { + "name": "cards_card_number_unique", + "nullsNotDistinct": false, + "columns": [ + "card_number" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.fraud_reports": { + "name": "fraud_reports", + "schema": "", + "columns": { + "report_id": { + "name": "report_id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "fraud_reports_report_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "reporter_id": { + "name": "reporter_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "transaction_id": { + "name": "transaction_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "reason": { + "name": "reason", + "type": "fraud_report_reason", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "fraud_report_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'Open'" + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "handled_by": { + "name": "handled_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "resolution_notes": { + "name": "resolution_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resolved_at": { + "name": "resolved_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_fraud_reports_reporter_id": { + "name": "idx_fraud_reports_reporter_id", + "columns": [ + { + "expression": "reporter_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_fraud_reports_status": { + "name": "idx_fraud_reports_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_fraud_reports_handled_by": { + "name": "idx_fraud_reports_handled_by", + "columns": [ + { + "expression": "handled_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "fraud_reports_reporter_id_users_id_fk": { + "name": "fraud_reports_reporter_id_users_id_fk", + "tableFrom": "fraud_reports", + "tableTo": "users", + "columnsFrom": [ + "reporter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "fraud_reports_transaction_id_transactions_transaction_id_fk": { + "name": "fraud_reports_transaction_id_transactions_transaction_id_fk", + "tableFrom": "fraud_reports", + "tableTo": "transactions", + "columnsFrom": [ + "transaction_id" + ], + "columnsTo": [ + "transaction_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "fraud_reports_account_id_bank_accounts_account_id_fk": { + "name": "fraud_reports_account_id_bank_accounts_account_id_fk", + "tableFrom": "fraud_reports", + "tableTo": "bank_accounts", + "columnsFrom": [ + "account_id" + ], + "columnsTo": [ + "account_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "fraud_reports_handled_by_users_id_fk": { + "name": "fraud_reports_handled_by_users_id_fk", + "tableFrom": "fraud_reports", + "tableTo": "users", + "columnsFrom": [ + "handled_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "fraud_reports_transaction_id_unique": { + "name": "fraud_reports_transaction_id_unique", + "nullsNotDistinct": false, + "columns": [ + "transaction_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.internal_knowledge_base": { + "name": "internal_knowledge_base", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "internal_knowledge_base_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "source_call_id": { + "name": "source_call_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(500)", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "embedding": { + "name": "embedding", + "type": "vector(1536)", + "primaryKey": false, + "notNull": false + }, + "learning_type": { + "name": "learning_type", + "type": "learning_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "category_id": { + "name": "category_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "numeric(3, 2)", + "primaryKey": false, + "notNull": true + }, + "reviewed": { + "name": "reviewed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "reviewed_by": { + "name": "reviewed_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "reviewed_at": { + "name": "reviewed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_internal_kb_category": { + "name": "idx_internal_kb_category", + "columns": [ + { + "expression": "category_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_internal_kb_learning_type": { + "name": "idx_internal_kb_learning_type", + "columns": [ + { + "expression": "learning_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "internal_kb_embedding_idx": { + "name": "internal_kb_embedding_idx", + "columns": [ + { + "expression": "embedding", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": {} + } + }, + "foreignKeys": { + "internal_knowledge_base_source_call_id_call_records_id_fk": { + "name": "internal_knowledge_base_source_call_id_call_records_id_fk", + "tableFrom": "internal_knowledge_base", + "tableTo": "call_records", + "columnsFrom": [ + "source_call_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "internal_knowledge_base_category_id_knowledge_base_categories_id_fk": { + "name": "internal_knowledge_base_category_id_knowledge_base_categories_id_fk", + "tableFrom": "internal_knowledge_base", + "tableTo": "knowledge_base_categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "internal_knowledge_base_reviewed_by_users_id_fk": { + "name": "internal_knowledge_base_reviewed_by_users_id_fk", + "tableFrom": "internal_knowledge_base", + "tableTo": "users", + "columnsFrom": [ + "reviewed_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.knowledge_base_categories": { + "name": "knowledge_base_categories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "knowledge_base_categories_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "knowledge_base_categories_slug_unique": { + "name": "knowledge_base_categories_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.knowledge_base": { + "name": "knowledge_base", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "knowledge_base_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "title": { + "name": "title", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "varchar", + "primaryKey": false, + "notNull": false + }, + "category_id": { + "name": "category_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "embedding": { + "name": "embedding", + "type": "vector(1536)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "embeddingIndex": { + "name": "embeddingIndex", + "columns": [ + { + "expression": "embedding", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": {} + }, + "idx_knowledge_base_category": { + "name": "idx_knowledge_base_category", + "columns": [ + { + "expression": "category_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "knowledge_base_category_id_knowledge_base_categories_id_fk": { + "name": "knowledge_base_category_id_knowledge_base_categories_id_fk", + "tableFrom": "knowledge_base", + "tableTo": "knowledge_base_categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.loans": { + "name": "loans", + "schema": "", + "columns": { + "loan_id": { + "name": "loan_id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "loans_loan_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "loan_type": { + "name": "loan_type", + "type": "loan_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "account_number": { + "name": "account_number", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "principal": { + "name": "principal", + "type": "numeric(15, 2)", + "primaryKey": false, + "notNull": true + }, + "remaining_balance": { + "name": "remaining_balance", + "type": "numeric(15, 2)", + "primaryKey": false, + "notNull": true + }, + "monthly_installment": { + "name": "monthly_installment", + "type": "numeric(15, 2)", + "primaryKey": false, + "notNull": true + }, + "installment_due_day": { + "name": "installment_due_day", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "next_installment_due_date": { + "name": "next_installment_due_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "late_fee_percent": { + "name": "late_fee_percent", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": true, + "default": "'10.00'" + }, + "total_installments": { + "name": "total_installments", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "completed_installments": { + "name": "completed_installments", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "term_length_months": { + "name": "term_length_months", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "tenure_years": { + "name": "tenure_years", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "start_date": { + "name": "start_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "maturity_date": { + "name": "maturity_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "interest_rate": { + "name": "interest_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": true + }, + "application_status": { + "name": "application_status", + "type": "application_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'PendingApproval'" + }, + "rejection_reason": { + "name": "rejection_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "loans_account_number_bank_accounts_account_number_fk": { + "name": "loans_account_number_bank_accounts_account_number_fk", + "tableFrom": "loans", + "tableTo": "bank_accounts", + "columnsFrom": [ + "account_number" + ], + "columnsTo": [ + "account_number" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.refresh_tokens": { + "name": "refresh_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "refresh_tokens_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "userId": { + "name": "userId", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tokenHash": { + "name": "tokenHash", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "expiresAt": { + "name": "expiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "refresh_tokens_userId_users_id_fk": { + "name": "refresh_tokens_userId_users_id_fk", + "tableFrom": "refresh_tokens", + "tableTo": "users", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.saved_recipients": { + "name": "saved_recipients", + "schema": "", + "columns": { + "recipient_id": { + "name": "recipient_id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "saved_recipients_recipient_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "owner_id": { + "name": "owner_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "recipient_name": { + "name": "recipient_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "nickname": { + "name": "nickname", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "account_number": { + "name": "account_number", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_saved_recipients_owner": { + "name": "idx_saved_recipients_owner", + "columns": [ + { + "expression": "owner_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "uq_saved_recipients_owner_account": { + "name": "uq_saved_recipients_owner_account", + "columns": [ + { + "expression": "owner_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "account_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "saved_recipients_owner_id_users_id_fk": { + "name": "saved_recipients_owner_id_users_id_fk", + "tableFrom": "saved_recipients", + "tableTo": "users", + "columnsFrom": [ + "owner_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.transaction_categories": { + "name": "transaction_categories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "byDefault", + "name": "transaction_categories_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "transaction_categories_name_unique": { + "name": "transaction_categories_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.transactions": { + "name": "transactions", + "schema": "", + "columns": { + "transaction_id": { + "name": "transaction_id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "transactions_transaction_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "from_account_id": { + "name": "from_account_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "to_account_id": { + "name": "to_account_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "card_id": { + "name": "card_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "initiator_id": { + "name": "initiator_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "amount": { + "name": "amount", + "type": "numeric(15, 2)", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "transaction_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "category_id": { + "name": "category_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "transaction_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'Active'" + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "merchant_name": { + "name": "merchant_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_transactions_from_account_created_at": { + "name": "idx_transactions_from_account_created_at", + "columns": [ + { + "expression": "from_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_transactions_to_account_created_at": { + "name": "idx_transactions_to_account_created_at", + "columns": [ + { + "expression": "to_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_transactions_initiator_id": { + "name": "idx_transactions_initiator_id", + "columns": [ + { + "expression": "initiator_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_transactions_card_id": { + "name": "idx_transactions_card_id", + "columns": [ + { + "expression": "card_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "transactions_from_account_id_bank_accounts_account_id_fk": { + "name": "transactions_from_account_id_bank_accounts_account_id_fk", + "tableFrom": "transactions", + "tableTo": "bank_accounts", + "columnsFrom": [ + "from_account_id" + ], + "columnsTo": [ + "account_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "transactions_to_account_id_bank_accounts_account_id_fk": { + "name": "transactions_to_account_id_bank_accounts_account_id_fk", + "tableFrom": "transactions", + "tableTo": "bank_accounts", + "columnsFrom": [ + "to_account_id" + ], + "columnsTo": [ + "account_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "transactions_card_id_cards_card_id_fk": { + "name": "transactions_card_id_cards_card_id_fk", + "tableFrom": "transactions", + "tableTo": "cards", + "columnsFrom": [ + "card_id" + ], + "columnsTo": [ + "card_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "transactions_initiator_id_users_id_fk": { + "name": "transactions_initiator_id_users_id_fk", + "tableFrom": "transactions", + "tableTo": "users", + "columnsFrom": [ + "initiator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "transactions_category_id_transaction_categories_id_fk": { + "name": "transactions_category_id_transaction_categories_id_fk", + "tableFrom": "transactions", + "tableTo": "transaction_categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "users_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "phoneNumber": { + "name": "phoneNumber", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "dateOfBirth": { + "name": "dateOfBirth", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "user_type": { + "name": "user_type", + "type": "user_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'customer'" + } + }, + "indexes": { + "idx_users_email": { + "name": "idx_users_email", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_users_phone": { + "name": "idx_users_phone", + "columns": [ + { + "expression": "phoneNumber", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.account_type": { + "name": "account_type", + "schema": "public", + "values": [ + "Savings", + "Current", + "FixedDeposit" + ] + }, + "public.analysis_status": { + "name": "analysis_status", + "schema": "public", + "values": [ + "pending", + "processing", + "completed", + "failed" + ] + }, + "public.application_status": { + "name": "application_status", + "schema": "public", + "values": [ + "PendingApproval", + "Accepted", + "Rejected" + ] + }, + "public.call_booking_change_type": { + "name": "call_booking_change_type", + "schema": "public", + "values": [ + "status_change", + "agent_assigned", + "agent_unassigned" + ] + }, + "public.call_category": { + "name": "call_category", + "schema": "public", + "values": [ + "General Inquiry", + "Technical Support", + "Billing", + "Fraud Report", + "Loan Inquiry", + "Other" + ] + }, + "public.call_status": { + "name": "call_status", + "schema": "public", + "values": [ + "Pending", + "Confirmed", + "Processing", + "Completed", + "NoShow", + "Cancelled" + ] + }, + "public.card_status": { + "name": "card_status", + "schema": "public", + "values": [ + "Active", + "Inactive", + "Blocked", + "Cancelled", + "Lost", + "Stolen" + ] + }, + "public.card_type": { + "name": "card_type", + "schema": "public", + "values": [ + "Debit", + "Credit", + "Prepaid" + ] + }, + "public.fraud_report_reason": { + "name": "fraud_report_reason", + "schema": "public", + "values": [ + "NotMine", + "WrongAmount", + "ChargedTwice", + "NotReceived", + "Other" + ] + }, + "public.fraud_report_status": { + "name": "fraud_report_status", + "schema": "public", + "values": [ + "Open", + "UnderReview", + "Resolved", + "Dismissed" + ] + }, + "public.learning_type": { + "name": "learning_type", + "schema": "public", + "values": [ + "resolution_pattern", + "knowledge_gap", + "policy_clarification", + "procedure" + ] + }, + "public.loan_type": { + "name": "loan_type", + "schema": "public", + "values": [ + "Personal Loan", + "Home Loan", + "Car Loan", + "Student Loan" + ] + }, + "public.sentiment": { + "name": "sentiment", + "schema": "public", + "values": [ + "positive", + "neutral", + "negative", + "frustrated" + ] + }, + "public.transaction_status": { + "name": "transaction_status", + "schema": "public", + "values": [ + "Active", + "Pending", + "Reversed", + "Cancelled", + "Failed" + ] + }, + "public.transaction_type": { + "name": "transaction_type", + "schema": "public", + "values": [ + "Deposit", + "Withdraw", + "Transfer", + "Interest", + "Fee", + "Other" + ] + }, + "public.user_type": { + "name": "user_type", + "schema": "public", + "values": [ + "customer", + "customer_support", + "administrator" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/8cbc_backend/drizzle/meta/_journal.json b/8cbc_backend/drizzle/meta/_journal.json index 4943984f..75ec34d7 100644 --- a/8cbc_backend/drizzle/meta/_journal.json +++ b/8cbc_backend/drizzle/meta/_journal.json @@ -120,6 +120,13 @@ "when": 1768877740286, "tag": "0016_adorable_onslaught", "breakpoints": true + }, + { + "idx": 17, + "version": "7", + "when": 1769793591976, + "tag": "0017_next_whirlwind", + "breakpoints": true } ] } \ No newline at end of file diff --git a/8cbc_backend/services/langchain/execution/operations.ts b/8cbc_backend/services/langchain/execution/operations.ts index 9f904256..91e015ca 100644 --- a/8cbc_backend/services/langchain/execution/operations.ts +++ b/8cbc_backend/services/langchain/execution/operations.ts @@ -277,6 +277,9 @@ export const executeScheduleCall = async ( category: (response.category as "General Inquiry" | "Technical Support" | "Billing" | "Fraud Report" | "Loan Inquiry" | "Other") || "General Inquiry", reason: response.reason || null, phoneNumber: response.phoneNumber ?? "", + aiSolutionsSummary: response.aiSolutionsSummary || null, + escalationReason: response.escalationReason || null, + conversationContext: response.conversationContext || null, }); if (!booking || !booking.slot) { diff --git a/8cbc_backend/services/langchain/modal.types.ts b/8cbc_backend/services/langchain/modal.types.ts index d8a0dda6..0f251e12 100644 --- a/8cbc_backend/services/langchain/modal.types.ts +++ b/8cbc_backend/services/langchain/modal.types.ts @@ -35,6 +35,10 @@ export const ScheduleCallOperationConfirmation = z.object({ suggestedDetails: z.string().optional(), suggestedDate: z.string().optional(), suggestedTime: z.string().optional(), + // AI Context fields + aiSolutionsSummary: z.string().optional(), + escalationReason: z.string().optional(), + conversationContext: z.string().optional(), }); export const CancelCallOperationConfirmation = z.object({ diff --git a/8cbc_backend/services/langchain/system-prompt.ts b/8cbc_backend/services/langchain/system-prompt.ts index b395ed14..361d4f5b 100644 --- a/8cbc_backend/services/langchain/system-prompt.ts +++ b/8cbc_backend/services/langchain/system-prompt.ts @@ -50,7 +50,7 @@ When modifications occurred: - **get_saved_recipients**: Retrieve all saved recipients for the user, showing nicknames, account numbers, and when they were added ### Support and Scheduling -- **schedule_call**: Trigger a modal for the user to schedule a call with a bank representative. Use this when the user expresses interest in speaking with someone, scheduling a call, or needs human assistance that the AI cannot provide. Only prefill date/time if the user explicitly mentioned them. Suggested details should only be provided if the user has already mentioned a specific, banking-related reason. Irrelevant reasons must be rejected. If the user cancels the scheduling, acknowledge it politely and ask if there is anything else you can help with. +- **schedule_call**: Trigger a modal for the user to schedule a call with a bank representative. Use this when the user expresses interest in speaking with someone, scheduling a call, or needs human assistance that the AI cannot provide. Only prefill date/time if the user explicitly mentioned them. Suggested details should only be provided if the user has already mentioned a specific, banking-related reason. Irrelevant reasons must be rejected. If the user cancels the scheduling, acknowledge it politely and ask if there is anything else you can help with. **Important**: When escalating, you MUST provide AI context fields (aiSolutionsSummary, escalationReason, conversationContext) to help the human agent - these are invisible to the customer but critical for efficient handoff. - **get_scheduled_calls**: Retrieve a list of all scheduled calls for the user. Use this when you need to know the details of their calls (like the ID for cancellation). - **view_scheduled_calls**: Trigger a modal for the user to view all their scheduled calls. Use this when the user wants to see their upcoming calls or manage them visually. When you use this tool, a modal will appear on the user's screen. Acknowledge this briefly (e.g., "I've pulled up your scheduled calls for you.") and then wait for the user to respond. - **cancel_call**: Trigger a modal for the user to cancel an existing scheduled call. Use this when the user expresses a desire to cancel a specific call. You must provide the call ID, which you can get from **get_scheduled_calls**. @@ -321,6 +321,29 @@ When escalating: - If the user provides NO reason or a vague reason (e.g., "just help", "I want to talk"), do **NOT** fill any details field in the tool. Let the user fill it in the modal. - Only pre-fill details if the user has provided a clear, relevant, and detailed banking-related reason. - **Date & Time**: Only prefill date and time if the user explicitly mentioned them. Otherwise, leave them empty for the user to select in the modal. + +### AI Context Handoff (REQUIRED when escalating) + +When using schedule_call, you MUST provide context to help the human agent understand the situation. These fields are invisible to the customer but critical for efficient support: + +1. **aiSolutionsSummary** (REQUIRED): Summarize what you tried before escalating: + - Tools used (e.g., "Searched knowledge base for 'card replacement', checked account status") + - Information retrieved and shared with user + - Answers or partial solutions provided + - Example: "Searched knowledge base for fraud dispute process. Provided user with general dispute timeline. Could not find specific policy for international transactions." + +2. **escalationReason** (REQUIRED): Explain why you couldn't resolve this: + - What specific capability or information is missing + - Why human judgment is needed + - Examples: "Requires manual identity verification", "Policy exception needed for transaction over limit", "User reports unauthorized access - needs security team review", "Complex dispute requiring account investigation" + +3. **conversationContext** (REQUIRED): Include key details the agent needs: + - Relevant account numbers or transaction IDs mentioned + - Specific amounts, dates, or reference numbers + - User's main concern or complaint in their words + - Any urgency indicators + - Example: "User concerned about 3 unauthorized transactions totaling $450 on 2024-01-15. Transaction IDs: TXN-123, TXN-124, TXN-125. Card ending 4532. User noticed charges this morning, card is still in possession." + - Use the **schedule_call** tool to present the booking modal. - **Post-Confirmation**: Once the user completes the booking in the modal and the tool returns a "success" result, acknowledge it briefly and naturally. Do NOT repeat the pre-tool dialogue about opening the form. - **Cancellation Handling**: If the user cancels the scheduling modal, acknowledge it politely (e.g., "No problem, I've closed the scheduling form. Is there anything else I can help you with?"). diff --git a/8cbc_backend/services/langchain/tools/call.tools.ts b/8cbc_backend/services/langchain/tools/call.tools.ts index 647b5f14..1cdf9200 100644 --- a/8cbc_backend/services/langchain/tools/call.tools.ts +++ b/8cbc_backend/services/langchain/tools/call.tools.ts @@ -15,6 +15,9 @@ export interface ScheduleCallArgs { details?: string; date?: string; time?: string; + aiSolutionsSummary?: string; + escalationReason?: string; + conversationContext?: string; } export interface CancelCallArgs { @@ -51,6 +54,9 @@ export const buildScheduleCallConfirmation = async ( suggestedDetails: args.details, suggestedDate: args.date, suggestedTime: suggestedTime, + aiSolutionsSummary: args.aiSolutionsSummary, + escalationReason: args.escalationReason, + conversationContext: args.conversationContext, }; }; @@ -128,6 +134,24 @@ export const createScheduleCallTool = () => { .describe( "The suggested time for the call (HH:mm:ss, e.g. '09:00:00' or '14:30:00'). Only provide if the user explicitly mentioned a time.", ), + aiSolutionsSummary: z + .string() + .optional() + .describe( + "Summary of what the AI tried before escalating (tools used, info retrieved, answers given)", + ), + escalationReason: z + .string() + .optional() + .describe( + "Why AI couldn't resolve (e.g., 'requires identity verification', 'needs fraud investigation')", + ), + conversationContext: z + .string() + .optional() + .describe( + "Key context for support agent (account IDs, transaction details, specific concerns)", + ), }), }, ); diff --git a/8cbc_backend/services/realtime/realtime.config.ts b/8cbc_backend/services/realtime/realtime.config.ts index cc38d5b1..d9dade55 100644 --- a/8cbc_backend/services/realtime/realtime.config.ts +++ b/8cbc_backend/services/realtime/realtime.config.ts @@ -63,6 +63,15 @@ When to close modals: - Examples: user says "never mind", "cancel that", "close it", or the conversation moves to a completely different topic - Do NOT close modals while the user is still interacting with them or discussing related topics +## Escalating to Human Support + +When scheduling a call for the user, you MUST provide context to help the human agent: +- aiSolutionsSummary: What you tried (tools used, information provided) +- escalationReason: Why you couldn't resolve this (e.g., "Requires identity verification.", "Needs fraud investigation.") +- conversationContext: Key details like account numbers, transaction IDs, amounts, dates, and the user's specific concern + +These fields are invisible to the customer but critical for efficient handoff to the support agent. + ## Error Handling If something goes wrong: diff --git a/8cbc_frontend/app/(admin)/admin/page.tsx b/8cbc_frontend/app/(admin)/admin/page.tsx index 8416e500..3386c9ec 100644 --- a/8cbc_frontend/app/(admin)/admin/page.tsx +++ b/8cbc_frontend/app/(admin)/admin/page.tsx @@ -177,7 +177,7 @@ const AdminDashboard = () => { if (!statistics) return []; const monthData = statistics.resolutionMetrics.monthlyStatuses?.find((m) => m.month === currentMonthKey); const statusDist = monthData?.statusDistribution || statistics.resolutionMetrics.statusDistribution; - + return Object.entries(statusDist).map(([name, value]) => ({ name, value: value as number, @@ -266,7 +266,7 @@ const AdminDashboard = () => { }, { icon: BarChart3, - title: "View statistics", + title: "View call statistics", description: "Analyze call performance and customer support metrics", href: "/admin/calls-statistics", }, diff --git a/8cbc_frontend/bun.lock b/8cbc_frontend/bun.lock index 10dbf5b5..57138ff1 100644 --- a/8cbc_frontend/bun.lock +++ b/8cbc_frontend/bun.lock @@ -1,5 +1,6 @@ { "lockfileVersion": 1, + "configVersion": 0, "workspaces": { "": { "name": "8cbc_frontend", diff --git a/8cbc_frontend/components/bookings/CallDetailsPanel.tsx b/8cbc_frontend/components/bookings/CallDetailsPanel.tsx index e5b8f2cb..0d72af67 100644 --- a/8cbc_frontend/components/bookings/CallDetailsPanel.tsx +++ b/8cbc_frontend/components/bookings/CallDetailsPanel.tsx @@ -12,7 +12,7 @@ import { import { Card } from "@/components/ui/card"; import { Separator } from "@/components/ui/separator"; import { Button } from "@/components/ui/button"; -import { History, FileText, Copy, Check, User2 } from "lucide-react"; +import { History, FileText, Copy, Check, User2, Bot } from "lucide-react"; import Image from "next/image"; import Agent8 from "@/public/chatbot.svg"; import { useScreenSize } from "@/hooks/useScreenSize"; @@ -244,6 +244,39 @@ const CallDetailsPanelContent = ({
{bookingData.status}
+ + {(bookingData.aiSolutionsSummary || bookingData.escalationReason || bookingData.conversationContext) && ( + <> +What AI Tried
+{bookingData.aiSolutionsSummary}
+Escalation Reason
+{bookingData.escalationReason}
+Conversation Context
+{bookingData.conversationContext}
+