Krish2606 commited on
Commit
bccff66
Β·
1 Parent(s): a38ea02

Fix: robust DB fallback to SQLite, mobile CSS, back button, conversation dark mode

Browse files
backend/app.py CHANGED
@@ -69,24 +69,42 @@ CORS(app, supports_credentials=True)
69
 
70
  # Test database connection and fallback to SQLite if connection fails
71
  db_url = app.config.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///personaflow.db')
72
- if db_url.startswith('postgresql'):
 
73
  try:
74
  from sqlalchemy import create_engine, text
75
- print(f"[Database] Testing connection to: {db_url.split('@')[-1] if '@' in db_url else db_url}")
76
- test_engine = create_engine(db_url)
77
  with test_engine.connect() as conn:
78
  conn.execute(text("SELECT 1"))
 
79
  print("[Database] PostgreSQL connection successful.")
 
80
  except Exception as e:
81
  print(f"[Database] PostgreSQL connection failed: {e}")
82
  print("[Database] Falling back to local SQLite database...")
83
  app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///personaflow.db'
 
 
84
 
85
  db.init_app(app)
86
 
87
- # Create tables
88
  with app.app_context():
89
- db.create_all()
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
  # ============================================================================
92
  # Kokoro TTS β€” Initialize once at startup (singleton)
 
69
 
70
  # Test database connection and fallback to SQLite if connection fails
71
  db_url = app.config.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///personaflow.db')
72
+ _using_postgres = False
73
+ if db_url.startswith('postgresql') or db_url.startswith('postgres'):
74
  try:
75
  from sqlalchemy import create_engine, text
76
+ print(f"[Database] Testing connection to: {db_url.split('@')[-1] if '@' in db_url else '(local)'}")
77
+ test_engine = create_engine(db_url, connect_args={"connect_timeout": 5})
78
  with test_engine.connect() as conn:
79
  conn.execute(text("SELECT 1"))
80
+ test_engine.dispose()
81
  print("[Database] PostgreSQL connection successful.")
82
+ _using_postgres = True
83
  except Exception as e:
84
  print(f"[Database] PostgreSQL connection failed: {e}")
85
  print("[Database] Falling back to local SQLite database...")
86
  app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///personaflow.db'
87
+ else:
88
+ print(f"[Database] Using SQLite database.")
89
 
90
  db.init_app(app)
91
 
92
+ # Create tables β€” with a second fallback in case create_all itself fails
93
  with app.app_context():
94
+ try:
95
+ db.create_all()
96
+ print("[Database] Tables created/verified successfully.")
97
+ except Exception as e:
98
+ if _using_postgres:
99
+ print(f"[Database] db.create_all() failed on PostgreSQL: {e}")
100
+ print("[Database] Falling back to SQLite and retrying...")
101
+ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///personaflow.db'
102
+ # Re-initialize with SQLite
103
+ db.init_app(app)
104
+ db.create_all()
105
+ print("[Database] Tables created successfully on SQLite fallback.")
106
+ else:
107
+ raise
108
 
109
  # ============================================================================
110
  # Kokoro TTS β€” Initialize once at startup (singleton)
frontend/css/styles.css CHANGED
@@ -4766,6 +4766,193 @@ tr:hover td {
4766
  }
4767
  }
4768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4769
  /* ============================================================================
4770
  Mobile Navigation and Responsiveness
4771
  ============================================================================ */
@@ -4929,6 +5116,106 @@ tr:hover td {
4929
  .flex-responsive > div {
4930
  width: 100% !important;
4931
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4932
  }
4933
 
4934
  @media (max-width: 576px) {
@@ -4965,6 +5252,48 @@ tr:hover td {
4965
  white-space: normal !important;
4966
  word-break: break-word;
4967
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4968
  }
4969
 
4970
  /* ============================================================================
@@ -4996,10 +5325,15 @@ tr:hover td {
4996
  @media (max-width: 768px) {
4997
  .search-input-wrapper {
4998
  max-width: 140px;
 
4999
  }
5000
 
5001
  .search-input-wrapper:focus-within {
5002
  max-width: 100% !important;
5003
- flex: 1 0 auto;
 
 
 
 
5004
  }
5005
  }
 
4766
  }
4767
  }
4768
 
4769
+ /* ============================================================================
4770
+ Conversations List
4771
+ ============================================================================ */
4772
+ .conv-list-container {
4773
+ display: flex;
4774
+ flex-direction: column;
4775
+ gap: 0.75rem;
4776
+ }
4777
+
4778
+ .conv-list-item {
4779
+ display: flex;
4780
+ align-items: center;
4781
+ gap: 1rem;
4782
+ padding: 1.25rem 1.5rem;
4783
+ background: var(--card-bg);
4784
+ border: 1px solid var(--border-color);
4785
+ border-radius: var(--border-radius-lg);
4786
+ box-shadow: var(--card-shadow);
4787
+ transition: all var(--transition-fast);
4788
+ cursor: default;
4789
+ }
4790
+
4791
+ .conv-list-item:hover {
4792
+ box-shadow: var(--card-shadow-lg);
4793
+ border-color: rgba(99, 102, 241, 0.2);
4794
+ }
4795
+
4796
+ .conv-avatar {
4797
+ width: 48px;
4798
+ height: 48px;
4799
+ border-radius: 50%;
4800
+ display: flex;
4801
+ align-items: center;
4802
+ justify-content: center;
4803
+ color: white;
4804
+ font-weight: 700;
4805
+ font-size: 1.25rem;
4806
+ flex-shrink: 0;
4807
+ }
4808
+
4809
+ .conv-info {
4810
+ flex: 1;
4811
+ min-width: 0;
4812
+ }
4813
+
4814
+ .conv-name {
4815
+ font-weight: 600;
4816
+ color: var(--gray-900);
4817
+ font-size: 0.9375rem;
4818
+ display: flex;
4819
+ align-items: center;
4820
+ flex-wrap: wrap;
4821
+ gap: 0.25rem;
4822
+ }
4823
+
4824
+ .conv-meta {
4825
+ font-size: 0.8125rem;
4826
+ color: var(--gray-500);
4827
+ margin-top: 0.25rem;
4828
+ }
4829
+
4830
+ .conv-date {
4831
+ text-align: right;
4832
+ flex-shrink: 0;
4833
+ white-space: nowrap;
4834
+ }
4835
+
4836
+ .conv-view-btn {
4837
+ flex-shrink: 0;
4838
+ }
4839
+
4840
+ .conv-menu-wrapper {
4841
+ position: relative;
4842
+ flex-shrink: 0;
4843
+ }
4844
+
4845
+ .conv-menu-btn {
4846
+ background: none;
4847
+ border: none;
4848
+ color: var(--gray-400);
4849
+ cursor: pointer;
4850
+ padding: 0.5rem;
4851
+ border-radius: 50%;
4852
+ transition: all var(--transition-fast);
4853
+ font-size: 1rem;
4854
+ width: 36px;
4855
+ height: 36px;
4856
+ display: flex;
4857
+ align-items: center;
4858
+ justify-content: center;
4859
+ }
4860
+
4861
+ .conv-menu-btn:hover {
4862
+ background: var(--gray-100);
4863
+ color: var(--gray-700);
4864
+ }
4865
+
4866
+ .conv-dropdown-menu {
4867
+ display: none;
4868
+ position: absolute;
4869
+ right: 0;
4870
+ top: 100%;
4871
+ margin-top: 0.25rem;
4872
+ background: var(--card-bg);
4873
+ border: 1px solid var(--border-color);
4874
+ border-radius: var(--border-radius);
4875
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
4876
+ z-index: 100;
4877
+ min-width: 180px;
4878
+ overflow: hidden;
4879
+ }
4880
+
4881
+ .conv-dropdown-menu.open {
4882
+ display: block;
4883
+ }
4884
+
4885
+ .conv-dropdown-item {
4886
+ display: flex;
4887
+ align-items: center;
4888
+ gap: 0.75rem;
4889
+ width: 100%;
4890
+ padding: 0.75rem 1rem;
4891
+ background: none;
4892
+ border: none;
4893
+ color: var(--gray-700);
4894
+ font-size: 0.875rem;
4895
+ cursor: pointer;
4896
+ transition: background var(--transition-fast);
4897
+ text-align: left;
4898
+ }
4899
+
4900
+ .conv-dropdown-item:hover {
4901
+ background: var(--gray-50);
4902
+ }
4903
+
4904
+ .conv-dropdown-item.danger {
4905
+ color: var(--error);
4906
+ }
4907
+
4908
+ .conv-dropdown-item.danger:hover {
4909
+ background: var(--error-light);
4910
+ }
4911
+
4912
+ .conv-dropdown-item i {
4913
+ width: 16px;
4914
+ text-align: center;
4915
+ font-size: 0.8125rem;
4916
+ }
4917
+
4918
+ /* Dark mode β€” Conversations */
4919
+ [data-theme="dark"] .conv-list-item {
4920
+ background: var(--card-bg);
4921
+ border-color: rgba(255, 255, 255, 0.06);
4922
+ }
4923
+
4924
+ [data-theme="dark"] .conv-list-item:hover {
4925
+ border-color: rgba(99, 102, 241, 0.25);
4926
+ box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
4927
+ }
4928
+
4929
+ [data-theme="dark"] .conv-menu-btn:hover {
4930
+ background: rgba(255, 255, 255, 0.08);
4931
+ color: var(--gray-800);
4932
+ }
4933
+
4934
+ [data-theme="dark"] .conv-dropdown-menu {
4935
+ background: #1e2132;
4936
+ border-color: rgba(255, 255, 255, 0.1);
4937
+ box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
4938
+ }
4939
+
4940
+ [data-theme="dark"] .conv-dropdown-item {
4941
+ color: var(--gray-800);
4942
+ }
4943
+
4944
+ [data-theme="dark"] .conv-dropdown-item:hover {
4945
+ background: rgba(255, 255, 255, 0.06);
4946
+ }
4947
+
4948
+ [data-theme="dark"] .conv-dropdown-item.danger {
4949
+ color: #f87171;
4950
+ }
4951
+
4952
+ [data-theme="dark"] .conv-dropdown-item.danger:hover {
4953
+ background: rgba(239, 68, 68, 0.1);
4954
+ }
4955
+
4956
  /* ============================================================================
4957
  Mobile Navigation and Responsiveness
4958
  ============================================================================ */
 
5116
  .flex-responsive > div {
5117
  width: 100% !important;
5118
  }
5119
+
5120
+ /* Chat Page β€” Full viewport on mobile */
5121
+ .chat-container {
5122
+ height: calc(100vh - 5.5rem) !important;
5123
+ border-radius: 0 !important;
5124
+ }
5125
+
5126
+ .chat-header {
5127
+ padding: 0.75rem 1rem 0.75rem 1rem !important;
5128
+ gap: 0.5rem !important;
5129
+ }
5130
+
5131
+ .chat-messages {
5132
+ padding: 1rem !important;
5133
+ }
5134
+
5135
+ .chat-input-container {
5136
+ padding: 0.75rem !important;
5137
+ }
5138
+
5139
+ /* All Buttons β€” Mobile Touch Targets */
5140
+ .btn {
5141
+ min-height: 44px !important;
5142
+ font-size: 0.875rem !important;
5143
+ }
5144
+
5145
+ .btn-sm {
5146
+ min-height: 36px !important;
5147
+ }
5148
+
5149
+ /* Form controls full width on mobile */
5150
+ .form-select {
5151
+ width: 100% !important;
5152
+ }
5153
+
5154
+ /* Agent Card Grid β€” full width */
5155
+ .agents-grid {
5156
+ grid-template-columns: 1fr !important;
5157
+ }
5158
+
5159
+ /* Filter/search bar β€” stack vertically */
5160
+ .card .flex.items-center.gap-4 {
5161
+ flex-direction: column !important;
5162
+ align-items: stretch !important;
5163
+ gap: 0.75rem !important;
5164
+ }
5165
+
5166
+ .card .flex.items-center.gap-2 {
5167
+ width: 100% !important;
5168
+ }
5169
+
5170
+ .card .view-toggle {
5171
+ margin-left: 0 !important;
5172
+ align-self: flex-end !important;
5173
+ }
5174
+
5175
+ /* Report cards β€” single column */
5176
+ .reports-grid {
5177
+ grid-template-columns: 1fr !important;
5178
+ }
5179
+
5180
+ /* Modal β€” near full screen on mobile */
5181
+ .modal {
5182
+ width: 95vw !important;
5183
+ max-width: none !important;
5184
+ max-height: 90vh !important;
5185
+ margin: 5vh auto !important;
5186
+ }
5187
+
5188
+ /* Page title β€” smaller on mobile */
5189
+ .page-title {
5190
+ font-size: 1.5rem !important;
5191
+ }
5192
+
5193
+ .page-subtitle {
5194
+ font-size: 0.8125rem !important;
5195
+ }
5196
+
5197
+ /* Conversation list β€” compact on mobile */
5198
+ .conv-list-item {
5199
+ flex-wrap: wrap !important;
5200
+ padding: 1rem !important;
5201
+ gap: 0.75rem !important;
5202
+ }
5203
+
5204
+ .conv-info {
5205
+ flex: 1 1 calc(100% - 70px) !important;
5206
+ min-width: 0 !important;
5207
+ }
5208
+
5209
+ .conv-date {
5210
+ order: 4 !important;
5211
+ text-align: left !important;
5212
+ flex-basis: auto !important;
5213
+ }
5214
+
5215
+ .conv-view-btn {
5216
+ order: 5 !important;
5217
+ margin-left: auto !important;
5218
+ }
5219
  }
5220
 
5221
  @media (max-width: 576px) {
 
5252
  white-space: normal !important;
5253
  word-break: break-word;
5254
  }
5255
+
5256
+ /* Extra-small: tighten main content */
5257
+ .main-content {
5258
+ padding: 4.5rem 0.5rem 1rem 0.5rem !important;
5259
+ }
5260
+
5261
+ /* Page header buttons β€” full width stack */
5262
+ .page-header > div:last-child {
5263
+ width: 100% !important;
5264
+ }
5265
+
5266
+ .page-header .btn {
5267
+ flex: 1 !important;
5268
+ justify-content: center !important;
5269
+ }
5270
+
5271
+ /* Agent icon smaller on tiny phones */
5272
+ .agent-icon {
5273
+ width: 48px !important;
5274
+ height: 48px !important;
5275
+ font-size: 1.5rem !important;
5276
+ }
5277
+
5278
+ /* Chat β€” reduce header agent info */
5279
+ .chat-agent-name {
5280
+ font-size: 0.875rem !important;
5281
+ max-width: 140px;
5282
+ overflow: hidden;
5283
+ text-overflow: ellipsis;
5284
+ white-space: nowrap;
5285
+ }
5286
+
5287
+ /* Tabs β€” smaller text on tiny screens */
5288
+ .tabs .tab {
5289
+ font-size: 0.75rem !important;
5290
+ padding: 0.5rem 0.75rem !important;
5291
+ }
5292
+
5293
+ /* Cards β€” less padding */
5294
+ .card {
5295
+ padding: 1rem !important;
5296
+ }
5297
  }
5298
 
5299
  /* ============================================================================
 
5325
  @media (max-width: 768px) {
5326
  .search-input-wrapper {
5327
  max-width: 140px;
5328
+ transition: max-width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
5329
  }
5330
 
5331
  .search-input-wrapper:focus-within {
5332
  max-width: 100% !important;
5333
+ flex: 1 1 100%;
5334
+ }
5335
+
5336
+ .search-expandable:focus {
5337
+ box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
5338
  }
5339
  }
frontend/js/pages/agent-detail.js CHANGED
@@ -44,6 +44,9 @@ const AgentDetailPage = {
44
  container.innerHTML = `
45
  <div class="page-header">
46
  <div class="flex items-center gap-4">
 
 
 
47
  <div class="agent-icon" style="width: 64px; height: 64px; background: ${this.agent.color}; font-size: 2rem; display: flex; align-items: center; justify-content: center; color: white;">${App.getAgentIconHtml(this.agent.icon)}</div>
48
  <div>
49
  <h1 class="page-title">${this.agent.name}</h1>
 
44
  container.innerHTML = `
45
  <div class="page-header">
46
  <div class="flex items-center gap-4">
47
+ <button class="btn btn-icon btn-secondary" onclick="Router.back()" title="Go Back">
48
+ <i class="fas fa-arrow-left"></i>
49
+ </button>
50
  <div class="agent-icon" style="width: 64px; height: 64px; background: ${this.agent.color}; font-size: 2rem; display: flex; align-items: center; justify-content: center; color: white;">${App.getAgentIconHtml(this.agent.icon)}</div>
51
  <div>
52
  <h1 class="page-title">${this.agent.name}</h1>
frontend/js/pages/reports.js CHANGED
@@ -199,7 +199,9 @@ const ReportDetailPage = {
199
 
200
  container.innerHTML = `
201
  <div class="page-header" style="max-width: 800px; margin: 0 auto;">
202
- <button class="btn btn-secondary" onclick="Router.back()">← Back to Reports</button>
 
 
203
  </div>
204
 
205
  <div class="report-modal-card">
 
199
 
200
  container.innerHTML = `
201
  <div class="page-header" style="max-width: 800px; margin: 0 auto;">
202
+ <button class="btn btn-secondary" onclick="Router.back()">
203
+ <i class="fas fa-arrow-left"></i> Back to Reports
204
+ </button>
205
  </div>
206
 
207
  <div class="report-modal-card">
frontend/js/router.js CHANGED
@@ -28,7 +28,7 @@ const Router = {
28
  currentRoute: null,
29
  params: {},
30
  historyStack: [],
31
- _backTimeout: null,
32
 
33
  /**
34
  * Initialize router
@@ -144,12 +144,13 @@ const Router = {
144
  * Go back
145
  */
146
  back() {
147
- if (this._backTimeout) return;
148
- this._backTimeout = setTimeout(() => { this._backTimeout = null; }, 300);
 
149
 
150
  if (this.historyStack.length > 1) {
151
  this.historyStack.pop(); // Remove current route
152
- const previousHash = this.historyStack.pop(); // Get previous route
153
  window.location.hash = previousHash;
154
  } else {
155
  window.location.hash = '#/dashboard';
 
28
  currentRoute: null,
29
  params: {},
30
  historyStack: [],
31
+ _lastBackTime: 0,
32
 
33
  /**
34
  * Initialize router
 
144
  * Go back
145
  */
146
  back() {
147
+ const now = Date.now();
148
+ if (now - this._lastBackTime < 300) return;
149
+ this._lastBackTime = now;
150
 
151
  if (this.historyStack.length > 1) {
152
  this.historyStack.pop(); // Remove current route
153
+ const previousHash = this.historyStack[this.historyStack.length - 1]; // Peek previous (don't pop β€” handleRoute will see it's already top)
154
  window.location.hash = previousHash;
155
  } else {
156
  window.location.hash = '#/dashboard';