nothumanallowed 15.1.45 → 15.1.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nothumanallowed",
3
- "version": "15.1.45",
3
+ "version": "15.1.47",
4
4
  "description": "NotHumanAllowed — 38 AI agents, 80 tools, Studio (visual agentic workflows). Email, calendar, browser automation, screen capture, canvas, cron/heartbeat, Alexandria E2E messaging, GitHub, Notion, Slack, voice chat, free AI (Liara), 28 languages. Zero-dependency CLI.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/constants.mjs CHANGED
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
5
5
  const __filename = fileURLToPath(import.meta.url);
6
6
  const __dirname = path.dirname(__filename);
7
7
 
8
- export const VERSION = '15.1.45';
8
+ export const VERSION = '15.1.47';
9
9
  export const BASE_URL = 'https://nothumanallowed.com/cli';
10
10
  export const API_BASE = 'https://nothumanallowed.com/api/v1';
11
11
 
@@ -416,6 +416,23 @@ export function register(router) {
416
416
  } catch (e) { sendError(res, 500, e.message); }
417
417
  });
418
418
 
419
+ // POST /api/imap/probe — raw TCP probe of host:port (no TLS, no IMAP).
420
+ // Returns what the server actually sends as the first ~256 bytes, plus a
421
+ // human-readable verdict ("server speaks STARTTLS", "server speaks
422
+ // implicit TLS", "port closed", etc.). Lets the user understand why an
423
+ // IMAP connection fails without needing to read OpenSSL errors.
424
+ router.post('/api/imap/probe', async (req, res) => {
425
+ try {
426
+ const body = await parseBody(req);
427
+ const host = body.imap_host || body.host;
428
+ const port = parseInt(body.imap_port || body.port, 10);
429
+ if (!host || !port) return sendError(res, 400, 'host and port required');
430
+ const { probeImapPort } = await import('../../services/email-imap.mjs');
431
+ const result = await probeImapPort(host, port);
432
+ sendJSON(res, 200, { host, port, ...result });
433
+ } catch (e) { sendError(res, 500, e.message); }
434
+ });
435
+
419
436
  // POST /api/imap/test — dry-run connection test (no DB writes).
420
437
  // Body: { imap_host, imap_port, smtp_host, smtp_port, username, password,
421
438
  // email_address, from_name, sendTest? }
@@ -57,14 +57,22 @@ function notifyIdle(accountId, folder) {
57
57
  for (const h of idleHandlers) { try { h(accountId, folder); } catch {} }
58
58
  }
59
59
 
60
- function createImapClient(label, creds, accountId, secureOverride) {
60
+ function createImapClient(label, creds, accountId, secureOverride, opts = {}) {
61
61
  const port = parseInt(creds.imap_port, 10) || 993;
62
62
  // Default heuristic: 993/465 use implicit TLS, anything else uses STARTTLS.
63
63
  // `secureOverride` lets the auto-fallback path force the opposite mode.
64
64
  const isSecure = typeof secureOverride === 'boolean'
65
65
  ? secureOverride
66
66
  : (port === 993 || port === 465);
67
- const client = new ImapFlow({
67
+ // TLS hardening configurable per attempt. The `legacy` flag drops the
68
+ // minimum TLS version to v1.0 — required by some old / self-hosted IMAP
69
+ // servers (mail.dimensione-server.it, postfix on legacy CentOS, etc.)
70
+ // that still refuse TLS 1.2+ ClientHello.
71
+ const tlsOpts = {
72
+ rejectUnauthorized: false,
73
+ ...(opts.legacy ? { minVersion: 'TLSv1', maxVersion: 'TLSv1.3' } : {}),
74
+ };
75
+ const clientOpts = {
68
76
  host: creds.imap_host,
69
77
  port,
70
78
  secure: isSecure,
@@ -72,12 +80,23 @@ function createImapClient(label, creds, accountId, secureOverride) {
72
80
  logger: false,
73
81
  clientInfo: { name: 'NHA-Mail', version: '1.0.0' },
74
82
  emitLogs: false,
75
- // Bounded timeouts so a misconfigured server doesn't hang the UI.
76
- connectionTimeout: 15000,
77
- greetingTimeout: 10000,
78
- socketTimeout: 60000,
79
- tls: { rejectUnauthorized: false }, // always set — safe for self-signed certs too
80
- });
83
+ // Generous timeouts first sync from a slow server can take a while
84
+ // before it even responds with the greeting. The previous 10s was too
85
+ // tight for ISP-hosted mailservers with throttling on cold connections.
86
+ connectionTimeout: 30000,
87
+ greetingTimeout: 30000,
88
+ socketTimeout: 120000,
89
+ tls: tlsOpts,
90
+ };
91
+ // `plaintext` strategy: connect cleartext AND skip STARTTLS upgrade. For
92
+ // self-hosted servers that advertise STARTTLS but the upgrade itself is
93
+ // broken (the most common cause of "wrong version number" after a
94
+ // successful TCP connect on port 143).
95
+ if (opts.plaintext) {
96
+ clientOpts.disableAutoIdle = true;
97
+ clientOpts.disableSTARTTLS = true;
98
+ }
99
+ const client = new ImapFlow(clientOpts);
81
100
  client.on('error', (err) => {
82
101
  console.error(`[email:imap] ${label} error:`, err.message);
83
102
  if (accountId) syncClients.delete(accountId);
@@ -85,6 +104,54 @@ function createImapClient(label, creds, accountId, secureOverride) {
85
104
  return client;
86
105
  }
87
106
 
107
+ // Raw TCP probe that just opens the socket and reads the first ~256 bytes of
108
+ // whatever the server sends. No TLS handshake, no IMAP protocol. This is the
109
+ // "smoking gun" diagnostic: if the server returns "* OK [CAPABILITY ... STARTTLS ...]"
110
+ // we know STARTTLS is the right mode. If it returns binary garbage starting
111
+ // with 0x16, that's a TLS handshake → we need implicit TLS. If it returns
112
+ // nothing within timeout, the host/port is wrong or firewalled.
113
+ export async function probeImapPort(host, port) {
114
+ const net = await import('net');
115
+ return new Promise((resolve) => {
116
+ const socket = net.createConnection({ host, port, timeout: 10000 });
117
+ let buf = Buffer.alloc(0);
118
+ const done = (verdict) => {
119
+ try { socket.destroy(); } catch {}
120
+ resolve(verdict);
121
+ };
122
+ socket.on('connect', () => {
123
+ // Some servers wait for client greeting before sending anything; we just
124
+ // wait up to 5 more seconds for the server banner.
125
+ setTimeout(() => {
126
+ if (buf.length === 0) done({ ok: true, banner: '', advice: 'tcp-open-silent', message: `Connessione TCP riuscita ma il server non ha inviato banner entro 5s. Probabilmente è un server che parla TLS implicito — prova porta 993.` });
127
+ }, 5000);
128
+ });
129
+ socket.on('data', (chunk) => {
130
+ buf = Buffer.concat([buf, chunk]);
131
+ if (buf.length >= 200) {
132
+ const first = buf[0];
133
+ const text = buf.toString('utf8').slice(0, 200);
134
+ if (first === 0x16 || first === 0x15 || first === 0x14) {
135
+ done({ ok: true, banner: text.replace(/[^\x20-\x7e]/g, '·').slice(0, 100), advice: 'tls-implicit', message: `Il server risponde con un handshake TLS binario. Modalità corretta: TLS IMPLICITO (secure=true). Probabile porta sbagliata se hai messo 143 — prova 993.` });
136
+ } else if (/^\*\s+OK/i.test(text)) {
137
+ const hasStartTls = /STARTTLS/i.test(text);
138
+ done({ ok: true, banner: text.split('\r\n')[0], advice: hasStartTls ? 'starttls' : 'plaintext', message: hasStartTls ? `Server IMAP in chiaro che annuncia STARTTLS. Modalità corretta: STARTTLS (secure=false, upgrade automatico).` : `Server IMAP in CHIARO senza STARTTLS. ATTENZIONE: nessuna crittografia. Solo per LAN o test — usa "plaintext" se vuoi davvero proseguire.` });
139
+ } else {
140
+ done({ ok: true, banner: text.slice(0, 100), advice: 'unknown', message: `Risposta non riconosciuta dal server: ${text.slice(0, 80)}...` });
141
+ }
142
+ }
143
+ });
144
+ socket.on('error', (err) => done({ ok: false, error: err.message, advice: 'connect-error', message: `Impossibile connettersi: ${err.message}. Verifica host e porta.` }));
145
+ socket.on('timeout', () => done({ ok: false, error: 'timeout', advice: 'firewall', message: `Timeout (10s) — host o porta non raggiungibili. Possibili cause: firewall, host sbagliato, oppure il server è offline.` }));
146
+ socket.on('close', () => {
147
+ if (buf.length > 0) {
148
+ const text = buf.toString('utf8').slice(0, 200);
149
+ done({ ok: true, banner: text.slice(0, 100), advice: 'partial', message: `Risposta parziale dal server: ${text.slice(0, 80)}` });
150
+ }
151
+ });
152
+ });
153
+ }
154
+
88
155
  // Match the most common "wrong TLS mode" failure modes from ImapFlow / node
89
156
  // tls. Errors can surface as cleartext OpenSSL output ("wrong version
90
157
  // number"), as ImapFlow strings ("Failed to receive greeting"), or as plain
@@ -99,6 +166,10 @@ function _looksLikeTlsMismatch(err) {
99
166
  // a given server, and ensures the cached `syncClients` entry stays usable.
100
167
  const lastGoodSecure = new Map(); // accountId → boolean
101
168
 
169
+ // Per-account memory of the FULL working profile, not just secure flag.
170
+ // Some servers need legacy TLS — we don't want to re-discover that every sync.
171
+ const lastGoodProfile = new Map(); // accountId → { secure, legacy }
172
+
102
173
  export async function getImapClient(accountId, override) {
103
174
  const existing = syncClients.get(accountId);
104
175
  if (existing?.usable && override === undefined) return existing;
@@ -108,67 +179,125 @@ export async function getImapClient(accountId, override) {
108
179
  if (!creds || !creds.imap_host) throw new Error(`No IMAP credentials for account ${accountId}`);
109
180
  const label = `sync:${accountId.slice(0, 8)}`;
110
181
 
111
- // Pick initial TLS mode: explicit override > remembered-good > port heuristic.
182
+ // Build the candidate list up to 4 strategies, ordered most→least likely:
183
+ // 1. heuristic secure + modern TLS
184
+ // 2. opposite secure + modern TLS
185
+ // 3. heuristic secure + legacy TLS (TLSv1.0+)
186
+ // 4. opposite secure + legacy TLS
187
+ // If a remembered-good profile exists, prepend it so warm syncs are 1 attempt.
112
188
  const port = parseInt(creds.imap_port, 10) || 993;
113
189
  const heuristicSecure = port === 993 || port === 465;
114
- const remembered = lastGoodSecure.get(accountId);
115
- const firstSecure = (typeof override === 'boolean')
116
- ? override
117
- : (typeof remembered === 'boolean' ? remembered : heuristicSecure);
190
+ let strategies;
191
+ if (typeof override === 'boolean') {
192
+ // Explicit override (used by the outer syncAccount retry): obey it
193
+ // exactly, but still try legacy TLS as a fallback within that mode.
194
+ strategies = [
195
+ { secure: override, legacy: false, plaintext: false, why: 'override-modern' },
196
+ { secure: override, legacy: true, plaintext: false, why: 'override-legacy' },
197
+ ];
198
+ } else {
199
+ strategies = [
200
+ { secure: heuristicSecure, legacy: false, plaintext: false, why: 'heuristic-modern' },
201
+ { secure: !heuristicSecure, legacy: false, plaintext: false, why: 'opposite-modern' },
202
+ { secure: heuristicSecure, legacy: true, plaintext: false, why: 'heuristic-legacy' },
203
+ { secure: !heuristicSecure, legacy: true, plaintext: false, why: 'opposite-legacy' },
204
+ // Last-resort plaintext (no encryption): for servers that advertise
205
+ // STARTTLS but the upgrade is broken, OR for explicitly insecure
206
+ // LAN-only servers. Skipped on standard secure ports.
207
+ ...(heuristicSecure ? [] : [{ secure: false, legacy: false, plaintext: true, why: 'plaintext-no-tls' }]),
208
+ ];
209
+ const remembered = lastGoodProfile.get(accountId);
210
+ if (remembered) {
211
+ strategies = [
212
+ { secure: remembered.secure, legacy: !!remembered.legacy, plaintext: !!remembered.plaintext, why: 'remembered' },
213
+ ...strategies.filter(s => !(s.secure === remembered.secure && s.legacy === !!remembered.legacy && !!s.plaintext === !!remembered.plaintext)),
214
+ ];
215
+ }
216
+ }
118
217
 
119
- // First attempt.
120
- let client = createImapClient(label, creds, accountId, firstSecure);
121
- try {
122
- await client.connect();
123
- lastGoodSecure.set(accountId, firstSecure);
124
- } catch (err) {
125
- if (_looksLikeTlsMismatch(err) && override === undefined) {
126
- try { await client.logout(); } catch {}
127
- const fallbackSecure = !firstSecure;
128
- console.warn(`[email:imap] ${label} TLS mismatch (${err.message.slice(0, 100)}). Retrying with secure=${fallbackSecure}`);
129
- client = createImapClient(label, creds, accountId, fallbackSecure);
218
+ const errors = [];
219
+ for (const s of strategies) {
220
+ const client = createImapClient(label, creds, accountId, s.secure, { legacy: s.legacy, plaintext: s.plaintext });
221
+ try {
130
222
  await client.connect();
131
- lastGoodSecure.set(accountId, fallbackSecure);
132
- } else {
133
- throw err;
223
+ lastGoodProfile.set(accountId, { secure: s.secure, legacy: s.legacy, plaintext: s.plaintext });
224
+ if (s.why !== 'remembered' && s.why !== 'heuristic-modern') {
225
+ console.warn(`[email:imap] ${label} connected via ${s.why} (secure=${s.secure}, legacy=${s.legacy}, plaintext=${s.plaintext})`);
226
+ }
227
+ syncClients.set(accountId, client);
228
+ return client;
229
+ } catch (err) {
230
+ errors.push(`${s.why}: ${err.message.slice(0, 120)}`);
231
+ try { await client.logout(); } catch {}
232
+ // If the error is clearly NOT TLS-related (e.g. auth failure, DNS),
233
+ // stop trying — more TLS combos won't help.
234
+ if (!_looksLikeTlsMismatch(err) && !/timeout|hang/i.test(err.message)) {
235
+ throw err;
236
+ }
134
237
  }
135
238
  }
136
- syncClients.set(accountId, client);
137
- return client;
239
+ // Final attempt failed. Run a raw TCP probe so the user can see what the
240
+ // server actually replies (or whether the port is reachable at all), and
241
+ // include that diagnostic in the thrown error.
242
+ let diagnosis = '';
243
+ try {
244
+ const probe = await probeImapPort(creds.imap_host, port);
245
+ diagnosis = `\n\nDIAGNOSI: ${probe.message}${probe.banner ? ` (banner: "${probe.banner}")` : ''}`;
246
+ } catch (probeErr) {
247
+ diagnosis = `\n\nProbe diagnostico fallito: ${probeErr.message}`;
248
+ }
249
+ throw new Error(`IMAP connection failed after ${strategies.length} attempts on ${creds.imap_host}:${port}:\n${errors.join('\n')}${diagnosis}`);
138
250
  }
139
251
 
140
252
  // Dry-run connectivity test used by Settings UI (no DB writes, no persistent
141
- // client). Returns { ok, secure, message }.
253
+ // client). Tries up to 4 TLS-mode combinations and returns the first that
254
+ // works, along with which one. Errors include the full attempt log so the
255
+ // user can paste it back to support if everything failed.
142
256
  export async function testImapConnection(creds) {
143
257
  if (!creds?.imap_host) throw new Error('imap_host required');
144
258
  if (!creds?.username || !creds?.password) throw new Error('Username and password required');
145
259
  const port = parseInt(creds.imap_port, 10) || 993;
146
- const tryConnect = async (secure) => {
147
- const client = createImapClient('test', creds, null, secure);
260
+ const heuristicSecure = port === 993 || port === 465;
261
+ const strategies = [
262
+ { secure: heuristicSecure, legacy: false, plaintext: false, why: 'heuristic-modern' },
263
+ { secure: !heuristicSecure, legacy: false, plaintext: false, why: 'opposite-modern' },
264
+ { secure: heuristicSecure, legacy: true, plaintext: false, why: 'heuristic-legacy' },
265
+ { secure: !heuristicSecure, legacy: true, plaintext: false, why: 'opposite-legacy' },
266
+ ...(heuristicSecure ? [] : [{ secure: false, legacy: false, plaintext: true, why: 'plaintext-no-tls' }]),
267
+ ];
268
+ const errors = [];
269
+ for (const s of strategies) {
270
+ const client = createImapClient('test', creds, null, s.secure, { legacy: s.legacy, plaintext: s.plaintext });
148
271
  try {
149
272
  await client.connect();
150
273
  const list = await client.list();
151
- await client.logout();
152
- return { ok: true, secure, folderCount: list.length };
274
+ try { await client.logout(); } catch {}
275
+ const mode = s.plaintext
276
+ ? 'plaintext (NESSUNA crittografia)'
277
+ : `${s.secure ? 'TLS implicito' : 'STARTTLS'}${s.legacy ? ' (legacy ≥TLSv1.0)' : ''}`;
278
+ return {
279
+ ok: true,
280
+ secure: s.secure,
281
+ legacy: s.legacy,
282
+ plaintext: s.plaintext,
283
+ folderCount: list.length,
284
+ message: `Connesso con modalità: ${mode}`,
285
+ };
153
286
  } catch (err) {
287
+ errors.push(`• ${s.why}: ${err.message.slice(0, 160)}`);
154
288
  try { await client.logout(); } catch {}
155
- throw err;
156
- }
157
- };
158
- const firstSecure = port === 993 || port === 465;
159
- try {
160
- return await tryConnect(firstSecure);
161
- } catch (err) {
162
- if (_looksLikeTlsMismatch(err)) {
163
- try {
164
- const r = await tryConnect(!firstSecure);
165
- return { ...r, message: `Fallback TLS=${!firstSecure} (heuristic was wrong for this server)` };
166
- } catch (err2) {
167
- throw new Error(`IMAP test failed (both TLS modes): ${err.message} / ${err2.message}`);
289
+ if (!_looksLikeTlsMismatch(err) && !/timeout|hang/i.test(err.message)) {
290
+ throw err;
168
291
  }
169
292
  }
170
- throw err;
171
293
  }
294
+ // Probe in fallback so the user gets actionable info.
295
+ let diagnosis = '';
296
+ try {
297
+ const probe = await probeImapPort(creds.imap_host, port);
298
+ diagnosis = `\n\nDIAGNOSI: ${probe.message}${probe.banner ? ` (banner: "${probe.banner}")` : ''}`;
299
+ } catch {}
300
+ throw new Error(`IMAP test failed dopo ${strategies.length} tentativi su ${creds.imap_host}:${port}:\n${errors.join('\n')}${diagnosis}`);
172
301
  }
173
302
 
174
303
  export async function closeImapClient(accountId) {
@@ -414,16 +543,10 @@ const FIRST_SYNC_LIMIT = 0;
414
543
 
415
544
  export async function syncAccount(accountId, opts = {}) {
416
545
  setSyncStatus(accountId, 'syncing', null);
417
- // _retried is set by the recursion below — it forces the *opposite* TLS
418
- // mode on the second attempt so we never spin twice on the same setting.
419
- const tlsOverride = (typeof opts._forceSecure === 'boolean') ? opts._forceSecure : undefined;
420
546
  try {
421
- // Prime the connection with the (optional) explicit TLS mode so any
422
- // cached `syncClients` entry uses it for the whole sync.
423
- if (tlsOverride !== undefined) {
424
- await closeImapClient(accountId);
425
- await getImapClient(accountId, tlsOverride);
426
- }
547
+ // getImapClient does the full 5-strategy TLS discovery internally and
548
+ // remembers the working profile, so the outer retry layer is no longer
549
+ // needed by the time we get a client back, the connection is good.
427
550
  const folders = await listImapFolders(accountId);
428
551
  const priority = ['inbox', 'sent'];
429
552
  const toSync = [
@@ -440,22 +563,11 @@ export async function syncAccount(accountId, opts = {}) {
440
563
  console.log(`[email:sync] ${f.path}: ${result.synced} new messages (total on server: ${result.total})`);
441
564
  } catch (err) {
442
565
  console.warn(`[email:imap] Sync folder ${f.path} failed:`, err.message);
443
- // Per-folder TLS mismatch propagates up so the outer catch can
444
- // restart the whole sync with the opposite secure mode.
445
- if (_looksLikeTlsMismatch(err) && opts._retried !== true) throw err;
446
566
  }
447
567
  }
448
568
  setSyncStatus(accountId, 'idle', null);
449
569
  return { synced: totalSynced };
450
570
  } catch (err) {
451
- if (_looksLikeTlsMismatch(err) && opts._retried !== true) {
452
- const port = parseInt(getAccountCredentials(accountId)?.imap_port, 10) || 993;
453
- const heuristic = port === 993 || port === 465;
454
- const opposite = (typeof tlsOverride === 'boolean') ? !tlsOverride : !heuristic;
455
- console.warn(`[email:imap] sync ${accountId.slice(0, 8)} TLS mismatch — retrying entire sync with secure=${opposite}`);
456
- await closeImapClient(accountId);
457
- return syncAccount(accountId, { ...opts, _retried: true, _forceSecure: opposite });
458
- }
459
571
  setSyncStatus(accountId, 'error', err.message);
460
572
  throw err;
461
573
  }
@@ -650,7 +650,7 @@ ${d}
650
650
  ${e.map(e=>`<div class="section"><div class="agent-header"><span class="icon">${e.icon}</span><div class="agent-name">${e.label}</div></div><div class="section-body"><p>${r(e.output)}</p></div></div>`).join(``)}
651
651
  ${f}
652
652
  <div class="footer">NHA Studio · nothumanallowed.com · ${new Date().getFullYear()}</div>
653
- </body></html>`,m=new Blob([p],{type:`text/html`}),h=URL.createObjectURL(m),g=document.createElement(`a`);g.href=h,g.download=`nha-report-${Date.now()}.html`,g.click(),URL.revokeObjectURL(h);let _=window.open(``,`_blank`,`width=1100,height=800`);_&&(_.document.open(),_.document.write(p),_.document.close(),_.onload=()=>setTimeout(()=>{_.focus(),_.print()},600))},N=t=>{let n=`**Studio Workflow Result**\n\nTask: ${t.task}\n\nAgents: ${t.nodes.map(e=>e.label).join(` → `)}\n\n---\n\n${t.result}`;try{sessionStorage.setItem(`nha_studio_import`,n)}catch{}e(`chat`)},Ce=()=>{if(!u){r(``),a([]),s([]),l(``),S(``),de.current=``,w(null),j.current=null,T(!1),b({in:0,out:0}),v(null),re(!1);try{sessionStorage.removeItem(dt)}catch{}}},we=i.some(e=>e.output||e.status===`running`);return(0,k.jsxs)(`div`,{className:P.root,children:[(0,k.jsxs)(`div`,{className:P.header,children:[(0,k.jsxs)(`div`,{className:P.headerLeft,children:[(0,k.jsx)(`div`,{className:P.title,children:`Studio`}),(0,k.jsx)(`div`,{className:P.subtitle,children:`Multi-agent orchestration · Council deliberation · Geth Consensus`})]}),(0,k.jsxs)(`div`,{className:P.headerActions,children:[y.in+y.out>0&&(0,k.jsxs)(`div`,{className:P.tokenBar,children:[(0,k.jsxs)(`span`,{className:P.tokIn,children:[`↑ `,y.in.toLocaleString()]}),(0,k.jsx)(`span`,{className:P.tokDim,children:` in `}),(0,k.jsxs)(`span`,{className:P.tokOut,children:[`↓ `,y.out.toLocaleString()]}),(0,k.jsx)(`span`,{className:P.tokDim,children:` out`})]}),(0,k.jsxs)(`div`,{style:{position:`relative`},ref:fe,children:[(0,k.jsxs)(`button`,{className:P.sessionsBtn,onClick:()=>h(e=>!e),children:[`Sessions (`,f.length,`)`]}),m&&(0,k.jsx)(`div`,{className:P.sessionsDrawer,children:f.length===0?(0,k.jsx)(`div`,{className:P.noSessions,children:`No saved sessions yet.`}):(0,k.jsxs)(k.Fragment,{children:[f.map(e=>(0,k.jsxs)(`div`,{className:P.sessionItem,children:[(0,k.jsxs)(`div`,{className:P.sessionInfo,onClick:()=>ve(e),children:[(0,k.jsx)(`div`,{className:P.sessionTask,children:e.task.slice(0,80)}),(0,k.jsxs)(`div`,{className:P.sessionMeta,children:[e.ts.slice(0,16),` · `,e.nodes.length,` agents`,e.council?.phase===`done`?` · 🏛️ Council`:``]})]}),(0,k.jsxs)(`div`,{className:P.sessionBtns,children:[(0,k.jsx)(`button`,{className:P.importBtn,onClick:()=>N(e),children:`→ Chat`}),(0,k.jsx)(`button`,{className:P.delSessionBtn,onClick:()=>ye(e.id),children:`✕`})]})]},e.id)),(0,k.jsx)(`div`,{className:P.sessionsFooter,children:(0,k.jsx)(`button`,{className:P.clearAllSessionsBtn,onClick:be,children:`Clear All`})})]})})]}),x&&(0,k.jsx)(`button`,{className:P.canvasToggleBtn,onClick:()=>{re(!0),O(`canvas`)},children:`📊 Panel`}),c&&(0,k.jsx)(`button`,{className:P.pdfBtn,onClick:xe,children:`⬇ PDF / HTML`}),(i.length>0||c||o.length>0)&&!u&&(0,k.jsx)(`button`,{className:P.clearBtn,onClick:Ce,title:`Clear all — start fresh`,children:`✕ Clear`})]})]}),(0,k.jsxs)(`div`,{className:P.inputArea,children:[(0,k.jsxs)(`div`,{className:P.inputRow,children:[(0,k.jsx)(`textarea`,{className:P.taskInput,value:n,onChange:e=>r(e.target.value),placeholder:`Describe your task… e.g. Analyze my emails and create a priority action plan`,rows:4,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),he())}}),(0,k.jsxs)(`div`,{className:P.inputControls,children:[u?(0,k.jsx)(`button`,{className:P.stopBtn,onClick:ge,children:`■ Stop`}):(0,k.jsx)(`button`,{className:P.runBtn,onClick:he,disabled:!n.trim(),children:`Run ▶`}),(0,k.jsxs)(`label`,{className:P.attachBtn,title:`Attach PDF or image`,children:[`📎`,(0,k.jsx)(`input`,{type:`file`,accept:`.pdf,.png,.jpg,.jpeg,.gif,.webp`,style:{display:`none`},onChange:e=>me(e.target.files?.[0])})]})]})]}),g&&(0,k.jsxs)(`div`,{className:P.attachBadge,children:[`📎 `,g.name,(0,k.jsx)(`button`,{className:P.clearAttach,onClick:()=>v(null),children:`✕`})]}),!u&&i.length===0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:P.examples,children:ke.map((e,t)=>(0,k.jsx)(`button`,{className:P.exampleBtn,onClick:()=>r(e),children:e},t))}),(0,k.jsxs)(`div`,{className:P.financeSection,children:[(0,k.jsx)(`div`,{className:P.financeSectionTitle,children:`📈 Finance & Trading Workflows`}),(0,k.jsx)(`div`,{className:P.financePresets,children:De.map((e,t)=>(0,k.jsx)(`button`,{className:P.financeBtn,onClick:()=>{r(e.task),a(e.agents)},children:e.label},t))})]})]})]}),i.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:P.officeSceneWrap,style:{overflow:`hidden`,position:`relative`,height:`180px`},children:(0,k.jsxs)(`div`,{style:{display:`flex`,width:`200%`,height:`100%`,transition:`transform 700ms cubic-bezier(0.22, 1, 0.36, 1)`,transform:C&&C.phase!==`idle`&&C.phase!==`skipped`?`translateX(-50%)`:`translateX(0)`},children:[(0,k.jsx)(`div`,{style:{width:`50%`,height:`100%`,flexShrink:0},children:(0,k.jsx)(Qe,{nodes:i,running:u})}),(0,k.jsx)(`div`,{style:{width:`50%`,height:`100%`,flexShrink:0},children:(0,k.jsx)(rt,{agents:ne.length>0?ne:i,council:C})})]})}),(0,k.jsxs)(`div`,{className:`${P.pipelineWrap} ${u?P.pipelineRunning:``}`,children:[(0,k.jsxs)(`div`,{className:P.pipelineTitle,children:[`Agent Pipeline`,u&&(0,k.jsx)(`span`,{className:P.pipelineLiveTag,children:`● LIVE`})]}),(0,k.jsx)(`div`,{className:P.pipelineNodes,children:i.map((e,t)=>(0,k.jsxs)(`div`,{className:P.pipelineStep,children:[(0,k.jsxs)(`div`,{className:`${P.agentChip} ${P[`chip_${e.status}`]}`,children:[(0,k.jsx)(`span`,{className:P.chipIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.chipLabel,children:e.label}),e.status===`running`&&(0,k.jsxs)(`span`,{className:P.chipDots,children:[(0,k.jsx)(`span`,{className:P.dot1,children:`.`}),(0,k.jsx)(`span`,{className:P.dot2,children:`.`}),(0,k.jsx)(`span`,{className:P.dot3,children:`.`})]}),e.status===`done`&&(0,k.jsx)(`span`,{className:P.chipCheck,children:`✓`}),e.status===`error`&&(0,k.jsx)(`span`,{className:P.chipErr,children:`✗`})]}),t<i.length-1&&(0,k.jsx)(`div`,{className:`${P.arrow} ${u?P.arrowActive:``}`,children:`→`})]},t))}),i.some(e=>e.reason)&&(0,k.jsx)(`div`,{className:P.reasonRow,children:i.map((e,t)=>e.reason?(0,k.jsxs)(`div`,{className:P.reasonChip,title:e.reason,children:[(0,k.jsx)(`span`,{className:P.reasonIcon,children:e.icon}),(0,k.jsxs)(`span`,{className:P.reasonText,children:[e.reason.slice(0,60),e.reason.length>60?`…`:``]})]},t):null)})]})]}),(0,k.jsxs)(`div`,{className:P.body,ref:ue,children:[(o.length>0||we)&&(0,k.jsxs)(`div`,{className:P.twoCol,children:[(0,k.jsxs)(`div`,{className:P.logPanel,children:[(0,k.jsx)(`div`,{className:P.panelTitle,children:`Live Log`}),(0,k.jsx)(`div`,{className:P.logBody,ref:le,children:o.map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.logEntry} ${P[`log_${e.type}`]}`,children:[(0,k.jsx)(`span`,{className:P.logTime,children:e.time}),(0,k.jsx)(`span`,{className:P.logIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.logAgent,children:e.agent}),(0,k.jsx)(`span`,{className:P.logText,children:e.text})]},t))})]}),(0,k.jsx)(`div`,{className:P.liveOutputPanel,children:i.filter(e=>e.output||e.status===`running`).map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.liveBlock} ${e.status===`running`?P.liveBlockActive:``} ${e.status===`done`&&e.output?P.liveBlockClickable:``}`,onClick:()=>e.status===`done`&&e.output?se(e):void 0,children:[(0,k.jsxs)(`div`,{className:P.liveBlockHeader,children:[(0,k.jsx)(`span`,{className:P.liveBlockIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.liveBlockLabel,children:e.label}),e.reason&&(0,k.jsx)(`span`,{className:P.liveBlockReason,title:e.reason,children:`ℹ`}),(0,k.jsx)(`span`,{className:`${P.outputStatus} ${P[`status_${e.status}`]}`,children:e.status}),e.status===`done`&&e.output&&(0,k.jsx)(`span`,{className:P.expandHint,children:`↗ espandi`})]}),e.status===`running`&&(0,k.jsxs)(`div`,{className:P.liveBlockWorking,children:[(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingLabel,children:e.statusLine??`elaborazione in corso`})]}),(0,k.jsx)(`div`,{className:`${P.liveBlockBody} ${e.status===`done`&&e.output?P.liveBlockBodyClamped:``}`,dangerouslySetInnerHTML:{__html:Se(e.output)+(e.status===`running`&&e.output?`<span class="studio-cursor"></span>`:``)}})]},t))})]}),ee&&(0,k.jsxs)(`div`,{className:P.parliamentPrompt,children:[(0,k.jsx)(`div`,{className:P.parliamentPromptIcon,children:`🏛️`}),(0,k.jsxs)(`div`,{className:P.parliamentPromptContent,children:[(0,k.jsx)(`div`,{className:P.parliamentPromptTitle,children:`Attivare il Consiglio?`}),(0,k.jsxs)(`div`,{className:P.parliamentPromptDesc,children:[ne.length,` agenti (`,ne.map(e=>e.label).join(`, `),`) hanno prodotto output. Il Geth Consensus eseguirà cross-reading, refinement e mediazione HERALD per raggiungere un consenso collettivo.`]}),(0,k.jsxs)(`div`,{className:P.parliamentPromptMeta,children:[`Complessità: `,ne.length<=3?`⚡ Rapido (~30s)`:ne.length<=5?`⏱ Medio (~60s)`:`🕐 Lungo (~2min)`,`\xA0· Consigliato per task analitici complessi`]})]}),(0,k.jsxs)(`div`,{className:P.parliamentPromptBtns,children:[(0,k.jsx)(`button`,{className:P.parliamentActivateBtn,onClick:_e,children:`🏛️ Attiva`}),(0,k.jsx)(`button`,{className:P.parliamentSkipBtn,onClick:()=>T(!1),children:`Salta`})]})]}),C&&!ee&&(0,k.jsx)(`div`,{className:P.councilWrapper,children:(0,k.jsx)(vt,{council:C})}),c&&!u&&(0,k.jsxs)(`details`,{className:P.resultAccordion,open:i.length<=1,children:[(0,k.jsxs)(`summary`,{className:P.resultAccordionSummary,children:[`Full Combined Report (`,i.filter(e=>e.output&&e.output!==`(no output)`).length,` agents)`]}),(0,k.jsx)(`div`,{className:P.resultAccordionBody,dangerouslySetInnerHTML:{__html:Se(c)}})]})]}),D&&(0,k.jsxs)(`div`,{className:P.canvasPanel,children:[(0,k.jsxs)(`div`,{className:P.canvasPanelHeader,children:[(0,k.jsxs)(`div`,{className:P.panelTabs,children:[(0,k.jsx)(`button`,{className:`${P.panelTabBtn} ${ie===`canvas`?P.panelTabActive:``}`,onClick:()=>O(`canvas`),children:`📊 Canvas`}),(0,k.jsx)(`button`,{className:`${P.panelTabBtn} ${ie===`browser`?P.panelTabActive:``}`,onClick:()=>O(`browser`),children:`🌐 Browser`})]}),(0,k.jsxs)(`div`,{className:P.canvasPanelActions,children:[ie===`canvas`&&x&&(0,k.jsx)(`button`,{className:P.canvasPanelBtn,onClick:()=>{let e=new Blob([x],{type:`text/html`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`nha-canvas-report.html`,n.click(),URL.revokeObjectURL(t)},children:`⬇ HTML`}),(0,k.jsx)(`button`,{className:P.canvasPanelClose,onClick:()=>re(!1),children:`✕`})]})]}),ie===`canvas`?x?(0,k.jsx)(`iframe`,{className:P.canvasFrame,srcDoc:x,sandbox:`allow-scripts`,title:`Canvas Report`}):(0,k.jsx)(`div`,{className:P.panelEmpty,children:`No canvas report yet. Run a workflow first.`}):(0,k.jsxs)(`div`,{className:P.browserPanel,children:[(0,k.jsxs)(`div`,{className:P.browserBar,children:[(0,k.jsx)(`input`,{className:P.browserInput,value:ae,onChange:e=>A(e.target.value),placeholder:`https://…`,onKeyDown:e=>{e.key===`Enter`&&A(ae)}}),(0,k.jsx)(`button`,{className:P.browserGo,onClick:()=>A(ae),children:`Go`})]}),ae?(0,k.jsx)(`iframe`,{className:P.canvasFrame,src:ae,sandbox:`allow-scripts allow-same-origin allow-forms`,title:`Browser`}):(0,k.jsx)(`div`,{className:P.panelEmpty,children:`Enter a URL above to browse`})]})]}),oe&&(0,k.jsx)(`div`,{className:P.blockModalOverlay,onClick:()=>se(null),children:(0,k.jsxs)(`div`,{className:P.blockModal,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:P.blockModalHeader,children:[(0,k.jsx)(`span`,{className:P.liveBlockIcon,children:oe.icon}),(0,k.jsx)(`span`,{className:P.blockModalTitle,children:oe.label}),(0,k.jsx)(`button`,{className:P.blockModalClose,onClick:()=>se(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:`${P.liveBlockBody} ${P.blockModalBody}`,dangerouslySetInnerHTML:{__html:Se(oe.output)}})]})})]})}var R={root:`_root_13wnr_2`,hero:`_hero_13wnr_12`,heroLeft:`_heroLeft_13wnr_21`,heroDate:`_heroDate_13wnr_22`,heroTitle:`_heroTitle_13wnr_23`,heroVer:`_heroVer_13wnr_24`,heroUptime:`_heroUptime_13wnr_25`,heroWeather:`_heroWeather_13wnr_27`,wIcon:`_wIcon_13wnr_35`,wInfo:`_wInfo_13wnr_36`,wTemp:`_wTemp_13wnr_37`,wCity:`_wCity_13wnr_38`,wDesc:`_wDesc_13wnr_39`,wEmpty:`_wEmpty_13wnr_40`,kpiRow:`_kpiRow_13wnr_43`,kpi:`_kpi_13wnr_43`,kpiNum:`_kpiNum_13wnr_55`,kpiLbl:`_kpiLbl_13wnr_56`,kpiBar:`_kpiBar_13wnr_57`,kpiFill:`_kpiFill_13wnr_58`,liveGrid:`_liveGrid_13wnr_61`,liveCard:`_liveCard_13wnr_67`,liveHdr:`_liveHdr_13wnr_71`,liveMore:`_liveMore_13wnr_79`,liveRow:`_liveRow_13wnr_81`,liveUnread:`_liveUnread_13wnr_89`,liveTitle:`_liveTitle_13wnr_89`,liveTime:`_liveTime_13wnr_91`,liveBody:`_liveBody_13wnr_95`,liveSub:`_liveSub_13wnr_97`,prio:`_prio_13wnr_99`,prio_high:`_prio_high_13wnr_103`,prio_medium:`_prio_medium_13wnr_104`,prio_low:`_prio_low_13wnr_105`,launcher:`_launcher_13wnr_108`,launchGroup:`_launchGroup_13wnr_115`,launchGroupLabel:`_launchGroupLabel_13wnr_117`,launchTiles:`_launchTiles_13wnr_123`,tile:`_tile_13wnr_129`,tileIcon:`_tileIcon_13wnr_143`,tileLabel:`_tileLabel_13wnr_144`},bt=[{view:`chat`,icon:`💬`,label:`Chat`,color:`#38bdf8`,group:`Panoramica`},{view:`plan`,icon:`🗓️`,label:`Daily Plan`,color:`#818cf8`,group:`Panoramica`},{view:`tasks`,icon:`✅`,label:`Tasks`,color:`#4ade80`,group:`Panoramica`},{view:`email`,icon:`📧`,label:`Email`,color:`#f87171`,group:`Google`},{view:`calendar`,icon:`📅`,label:`Calendar`,color:`#fb923c`,group:`Google`},{view:`drive`,icon:`💾`,label:`Drive`,color:`#facc15`,group:`Google`},{view:`contacts`,icon:`👤`,label:`Contacts`,color:`#34d399`,group:`Google`},{view:`notes`,icon:`📝`,label:`Notes`,color:`#a78bfa`,group:`Google`},{view:`onedrive`,icon:`☁️`,label:`OneDrive`,color:`#60a5fa`,group:`Microsoft`},{view:`mstodo`,icon:`📋`,label:`MS Todo`,color:`#38bdf8`,group:`Microsoft`},{view:`github`,icon:`🐙`,label:`GitHub`,color:`#e2e8f0`,group:`Tools`},{view:`notion`,icon:`📓`,label:`Notion`,color:`#94a3b8`,group:`Tools`},{view:`slack`,icon:`💼`,label:`Slack`,color:`#e879f9`,group:`Tools`},{view:`maps`,icon:`🗺️`,label:`Maps`,color:`#2dd4bf`,group:`Tools`},{view:`reminders`,icon:`🔔`,label:`Reminders`,color:`#fbbf24`,group:`Tools`},{view:`birthdays`,icon:`🎂`,label:`Birthdays`,color:`#f472b6`,group:`Tools`},{view:`cron`,icon:`⏰`,label:`Cron`,color:`#fb923c`,group:`Tools`},{view:`screen`,icon:`🖥️`,label:`Screen`,color:`#64748b`,group:`Tools`},{view:`agents`,icon:`🤖`,label:`Agents`,color:`#4ade80`,group:`AI`},{view:`studio`,icon:`🎭`,label:`Studio`,color:`#a78bfa`,group:`AI`},{view:`webcraft`,icon:`🔨`,label:`WebCraft`,color:`#f59e0b`,group:`AI`},{view:`collab`,icon:`🏛️`,label:`Alexandria`,color:`#38bdf8`,group:`AI`},{view:`connectors`,icon:`🔗`,label:`AWF - AutoWorkFlow`,color:`#94a3b8`,group:`Config`},{view:`settings`,icon:`⚙️`,label:`Settings`,color:`#64748b`,group:`Config`}],xt={Sunny:`☀️`,Clear:`☀️`,"Partly Cloudy":`⛅`,"Partly cloudy":`⛅`,Cloudy:`☁️`,Overcast:`☁️`,"Light rain":`🌧️`,Rain:`🌧️`,Drizzle:`🌧️`,"Moderate rain":`🌧️`,"Heavy rain":`🌧️`,Snow:`❄️`,"Light snow":`❄️`,Fog:`🌫️`,Mist:`🌫️`,Thunder:`⚡`,"Thundery outbreaks":`⚡`};function St(e){try{return new Date(e).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,hour12:!1})}catch{return e}}function Ct(e){try{return new Date(e).toLocaleDateString(`en`,{month:`short`,day:`numeric`})}catch{return e}}function wt(){let e=te(e=>e.setView),t=j(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(new Date);(0,_.useEffect)(()=>{let e=setInterval(()=>p(new Date),6e4);return()=>clearInterval(e)},[]),(0,_.useEffect)(()=>{let e=!0,t=t=>n=>{e&&n!=null&&t(n)};E(`/api/tasks`).then(e=>t(r)(e?.tasks??[])),E(`/api/emails?page=0&pageSize=8`).then(e=>t(a)(e?.emails??[])),E(`/api/calendar`).then(e=>t(s)(e?.events??[])),E(`/api/status`).then(t(l));let n=localStorage.getItem(`nha_weather_location`),i=t=>E(`/api/weather?location=${encodeURIComponent(t)}`).then(t=>{e&&t&&t.city&&d(t)});return n?i(n):navigator.geolocation?.getCurrentPosition(e=>i(`${e.coords.latitude.toFixed(4)},${e.coords.longitude.toFixed(4)}`),()=>{},{timeout:6e3}),()=>{e=!1}},[]);let m=n.filter(e=>e.status!==`done`),h=n.filter(e=>e.status===`done`),g=n.length>0?Math.round(h.length/n.length*100):0,v=i.filter(e=>e.isUnread).length,y=f.toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`}),b=[...new Set(bt.map(e=>e.group))];return(0,k.jsxs)(`div`,{className:R.root,children:[(0,k.jsxs)(`div`,{className:R.hero,children:[(0,k.jsxs)(`div`,{className:R.heroLeft,children:[(0,k.jsx)(`div`,{className:R.heroDate,children:y}),(0,k.jsx)(`div`,{className:R.heroTitle,children:c?(0,k.jsxs)(k.Fragment,{children:[`NHA `,(0,k.jsxs)(`span`,{className:R.heroVer,children:[`v`,c.version]}),` · `,(0,k.jsxs)(`span`,{className:R.heroUptime,children:[Math.floor(c.uptime/60),`m uptime`]})]}):`NotHumanAllowed`})]}),(0,k.jsx)(`div`,{className:R.heroWeather,onClick:()=>{let e=prompt(`City or lat,lon:`);e&&(localStorage.setItem(`nha_weather_location`,e),d(null),E(`/api/weather?location=${encodeURIComponent(e)}`).then(e=>{e&&e.city&&d(e)}))},children:u?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`span`,{className:R.wIcon,children:xt[u.desc]??u.icon??`🌡️`}),(0,k.jsxs)(`div`,{className:R.wInfo,children:[(0,k.jsxs)(`span`,{className:R.wTemp,children:[u.tempC,`°C`]}),(0,k.jsxs)(`span`,{className:R.wCity,children:[u.city.split(`,`)[0],u.country?`, ${u.country.slice(0,2).toUpperCase()}`:``]}),(0,k.jsxs)(`span`,{className:R.wDesc,children:[u.desc,` · 💧`,u.humidity,`%`]})]})]}):(0,k.jsxs)(`span`,{className:R.wEmpty,children:[`🌡️ `,t(`dashboard.weather`)]})})]}),(0,k.jsxs)(`div`,{className:R.kpiRow,children:[(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:m.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Pending tasks`}),n.length>0&&(0,k.jsx)(`div`,{className:R.kpiBar,children:(0,k.jsx)(`div`,{className:R.kpiFill,style:{width:`${g}%`}})})]}),(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:v>0?v:i.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:v>0?`Unread emails`:`Emails`})]}),(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:o.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Today's events`})]}),u&&(0,k.jsxs)(`div`,{className:R.kpi,children:[(0,k.jsxs)(`span`,{className:R.kpiNum,children:[u.feelsC,`°`]}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Feels like`})]})]}),(0,k.jsxs)(`div`,{className:R.liveGrid,children:[o.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📅 `,t(`calendar.title`)]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),o.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:R.liveRow,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.liveTime,children:t.isAllDay?`All day`:St(t.start)}),(0,k.jsxs)(`div`,{className:R.liveBody,children:[(0,k.jsx)(`span`,{className:R.liveTitle,children:t.summary}),t.location&&(0,k.jsx)(`span`,{className:R.liveSub,children:t.location})]})]},n))]}),i.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📧 `,t(`email.inbox`)]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),i.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:`${R.liveRow} ${t.isUnread?R.liveUnread:``}`,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.liveTime,children:Ct(t.date)}),(0,k.jsxs)(`div`,{className:R.liveBody,children:[(0,k.jsx)(`span`,{className:R.liveTitle,children:t.subject}),(0,k.jsx)(`span`,{className:R.liveSub,children:t.from})]})]},n))]}),m.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`✅ `,t(`tasks.title`),` · `,h.length,`/`,n.length,` (`,g,`%)`]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),m.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:R.liveRow,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:`${R.prio} ${R[`prio_`+t.priority]}`,children:t.priority[0].toUpperCase()}),(0,k.jsx)(`div`,{className:R.liveBody,children:(0,k.jsx)(`span`,{className:R.liveTitle,children:t.description})})]},n))]})]}),(0,k.jsx)(`div`,{className:R.launcher,children:b.map(t=>(0,k.jsxs)(`div`,{className:R.launchGroup,children:[(0,k.jsx)(`div`,{className:R.launchGroupLabel,children:t}),(0,k.jsx)(`div`,{className:R.launchTiles,children:bt.filter(e=>e.group===t).map(t=>(0,k.jsxs)(`button`,{className:R.tile,onClick:()=>e(t.view),style:{"--tc":t.color},children:[(0,k.jsx)(`span`,{className:R.tileIcon,children:t.icon}),(0,k.jsx)(`span`,{className:R.tileLabel,children:t.label})]},t.view))})]},t))})]})}var Tt={root:`_root_1pldx_1`,loading:`_loading_1pldx_2`,bar:`_bar_1pldx_4`,input:`_input_1pldx_5`,select:`_select_1pldx_6`,addBtn:`_addBtn_1pldx_7`,actions:`_actions_1pldx_10`,clearDone:`_clearDone_1pldx_11`,clearAll:`_clearAll_1pldx_12`,stats:`_stats_1pldx_14`,progress:`_progress_1pldx_15`,progressBar:`_progressBar_1pldx_16`,empty:`_empty_1pldx_18`,task:`_task_1pldx_20`,taskDone:`_taskDone_1pldx_22`,check:`_check_1pldx_23`,checkDone:`_checkDone_1pldx_25`,desc:`_desc_1pldx_26`,del:`_del_1pldx_27`,badge:`_badge_1pldx_30`,badge_high:`_badge_high_1pldx_31`,badge_medium:`_badge_medium_1pldx_32`,badge_low:`_badge_low_1pldx_33`,doneLabel:`_doneLabel_1pldx_35`};function Et(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`medium`),[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=()=>E(`/api/tasks`).then(e=>{n(e?.tasks??[]),i(!1)});(0,_.useEffect)(()=>{f()},[]);let p=async()=>{a.trim()&&(u(!0),await D(`/api/tasks`,{description:a.trim(),priority:s}),o(``),u(!1),f(),d.current?.focus())},m=e=>D(`/api/tasks/${e}/done`,{},`PATCH`).then(f),h=e=>D(`/api/tasks/${e}/delete`,{}).then(f),g=()=>D(`/api/tasks/clear`,{filter:`done`}).then(f),v=()=>{confirm(e(`tasks.deleteTask`))&&D(`/api/tasks/clear`,{filter:`all`}).then(f)},y=t.filter(e=>e.status!==`done`),b=t.filter(e=>e.status===`done`);return r?(0,k.jsxs)(`div`,{className:Tt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:Tt.root,children:[(0,k.jsxs)(`div`,{className:Tt.bar,children:[(0,k.jsx)(`input`,{ref:d,className:Tt.input,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&p(),placeholder:e(`tasks.newTask`)}),(0,k.jsxs)(`select`,{className:Tt.select,value:s,onChange:e=>c(e.target.value),children:[(0,k.jsx)(`option`,{value:`high`,children:`High`}),(0,k.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,k.jsx)(`option`,{value:`low`,children:`Low`})]}),(0,k.jsx)(`button`,{className:Tt.addBtn,onClick:p,disabled:l||!a.trim(),children:l?`…`:`+ `+e(`common.add`)})]}),t.length>0&&(0,k.jsxs)(`div`,{className:Tt.actions,children:[(0,k.jsx)(`button`,{className:Tt.clearDone,onClick:g,children:`Clear completed`}),(0,k.jsx)(`button`,{className:Tt.clearAll,onClick:v,children:`Clear all`})]}),t.length>0&&(0,k.jsxs)(`div`,{className:Tt.stats,children:[y.length,` pending · `,b.length,` done`,t.length>0&&(0,k.jsx)(`span`,{className:Tt.progress,children:(0,k.jsx)(`span`,{className:Tt.progressBar,style:{width:`${Math.round(b.length/t.length*100)}%`}})})]}),y.length===0&&b.length===0&&(0,k.jsx)(`div`,{className:Tt.empty,children:`No tasks yet. Add one above ↑`}),y.map(e=>(0,k.jsxs)(`div`,{className:Tt.task,children:[(0,k.jsx)(`span`,{className:Tt.check,onClick:()=>m(e.id)}),(0,k.jsx)(`span`,{className:Tt.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${Tt.badge} ${Tt[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:Tt.del,onClick:()=>h(e.id),children:`×`})]},e.id)),b.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Tt.doneLabel,children:`Completed`}),b.map(e=>(0,k.jsxs)(`div`,{className:`${Tt.task} ${Tt.taskDone}`,children:[(0,k.jsx)(`span`,{className:`${Tt.check} ${Tt.checkDone}`,onClick:()=>m(e.id),children:`✓`}),(0,k.jsx)(`span`,{className:Tt.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${Tt.badge} ${Tt[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:Tt.del,onClick:()=>h(e.id),children:`×`})]},e.id))]})]})}var z={root:`_root_k5v14_1`,loading:`_loading_k5v14_2`,card:`_card_k5v14_4`,cardTitle:`_cardTitle_k5v14_5`,cardTitleRow:`_cardTitleRow_k5v14_6`,cardSub:`_cardSub_k5v14_7`,connected:`_connected_k5v14_8`,statusMsg:`_statusMsg_k5v14_9`,fields:`_fields_k5v14_11`,field:`_field_k5v14_11`,fieldLabel:`_fieldLabel_k5v14_13`,fieldInput:`_fieldInput_k5v14_14`,saveBtn:`_saveBtn_k5v14_17`,dangerBtn:`_dangerBtn_k5v14_18`,cancelBtn:`_cancelBtn_k5v14_19`,btnRow:`_btnRow_k5v14_20`,keySet:`_keySet_k5v14_22`,keySummary:`_keySummary_k5v14_23`,keySummaryIcon:`_keySummaryIcon_k5v14_24`,nhaFree:`_nhaFree_k5v14_26`,nhaFreeTitle:`_nhaFreeTitle_k5v14_27`,nhaFreeSub:`_nhaFreeSub_k5v14_28`,nhaFreeBtn:`_nhaFreeBtn_k5v14_29`,imapRow:`_imapRow_k5v14_31`,imapName:`_imapName_k5v14_32`,imapMeta:`_imapMeta_k5v14_33`,imapStatus:`_imapStatus_k5v14_34`,imapBtns:`_imapBtns_k5v14_38`,imapSyncBtn:`_imapSyncBtn_k5v14_39`,imapEditBtn:`_imapEditBtn_k5v14_40`,imapDelBtn:`_imapDelBtn_k5v14_41`,emptyImap:`_emptyImap_k5v14_42`,imapForm:`_imapForm_k5v14_44`,imapFormTitle:`_imapFormTitle_k5v14_45`,pwdNote:`_pwdNote_k5v14_46`,pwdRow:`_pwdRow_k5v14_47`,togglePwd:`_togglePwd_k5v14_48`},Dt={id:``,display_name:``,email_address:``,from_name:``,imap_host:``,imap_port:`993`,smtp_host:``,smtp_port:`587`,username:``,password:``};function Ot({id:e,label:t,placeholder:n,value:r,onChange:i,type:a=`text`}){return(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t}),(0,k.jsx)(`input`,{id:e,type:a,placeholder:n,value:r,onChange:e=>i(e.target.value),className:z.fieldInput})]})}function kt(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(``),f=()=>{E(`/api/credentials`).then(e=>t(e?.credentials??[])).catch(()=>t([]))};(0,_.useEffect)(()=>{f()},[]);let p=async()=>{if(!/^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(n)){d(`Name: lettere, cifre, _ — primo carattere non numerico`);return}if(!i.trim()){d(`Value required`);return}l(!0),d(``);try{let e=await D(`/api/credentials`,{name:n,value:i,description:o});e&&!e.ok&&e.error?d(e.error):(r(``),a(``),s(``),f())}finally{l(!1)}},m=async e=>{confirm(`Delete credential "${e}"?`)&&(await fetch(`/api/credentials/${encodeURIComponent(e)}`,{method:`DELETE`}),f())};return(0,k.jsxs)(`div`,{style:{marginTop:16,padding:16,background:`var(--bg2, rgba(15,23,42,0.4))`,border:`1px solid var(--border, rgba(148,163,184,0.18))`,borderRadius:10},children:[(0,k.jsx)(`div`,{style:{fontSize:14,fontWeight:800,marginBottom:4},children:`Credentials Vault 🔐`}),(0,k.jsxs)(`div`,{style:{fontSize:11,opacity:.7,marginBottom:10},children:[`Encrypted secrets (AES-256-GCM, machine-bound key). Reference them in workflow nodes with `,(0,k.jsx)(`code`,{children:"${cred.NAME}"}),`. The raw value never leaves your computer.`]}),e.length>0&&(0,k.jsx)(`div`,{style:{marginBottom:12,border:`1px solid rgba(148,163,184,0.15)`,borderRadius:6},children:e.map(e=>(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`6px 10px`,borderBottom:`1px solid rgba(148,163,184,0.1)`,fontSize:12},children:[(0,k.jsx)(`code`,{style:{background:`rgba(99,102,241,0.12)`,padding:`2px 6px`,borderRadius:4,color:`#a5b4fc`,fontWeight:700},children:e.name}),(0,k.jsx)(`span`,{style:{flex:1,opacity:.7},children:e.description||(0,k.jsx)(`em`,{children:`no description`})}),(0,k.jsx)(`span`,{style:{fontSize:10,opacity:.5},children:new Date(e.updatedAt).toLocaleString()}),e.hasError&&(0,k.jsx)(`span`,{style:{color:`#ef4444`,fontSize:10},children:`⚠ decrypt error`}),(0,k.jsx)(`button`,{onClick:()=>m(e.name),style:{background:`transparent`,border:`none`,cursor:`pointer`,color:`#ef4444`,fontSize:14},children:`✕`})]},e.name))}),(0,k.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:8},children:[(0,k.jsx)(`input`,{placeholder:`NAME (e.g. STRIPE_KEY)`,value:n,onChange:e=>r(e.target.value),style:{padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`,fontFamily:`SF Mono, monospace`}}),(0,k.jsx)(`input`,{placeholder:`Description (optional)`,value:o,onChange:e=>s(e.target.value),style:{padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`}})]}),(0,k.jsx)(`input`,{type:`password`,placeholder:`Value (encrypted at rest)`,value:i,onChange:e=>a(e.target.value),style:{width:`100%`,marginTop:6,padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`}}),u&&(0,k.jsx)(`div`,{style:{color:`#ef4444`,fontSize:11,marginTop:4},children:u}),(0,k.jsx)(`button`,{onClick:p,disabled:c,style:{marginTop:8,padding:`6px 14px`,borderRadius:4,border:`none`,background:`#6366f1`,color:`white`,fontWeight:700,cursor:`pointer`,opacity:c?.5:1},children:c?`Saving…`:`+ Add credential`})]})}function At(){let{setConfig:e}=te(),t=j(),[n,r]=(0,_.useState)({}),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)({name:``,email:``,phone:``,homeAddress:``,workAddress:``,city:``,country:``,company:``,role:``,notes:``}),[C,w]=(0,_.useState)(`nha`),[ee,T]=(0,_.useState)(``),[ne,re]=(0,_.useState)(``),[ie,O]=(0,_.useState)(``),[ae,A]=(0,_.useState)(``),[oe,se]=(0,_.useState)(``),[ce,le]=(0,_.useState)(``),[ue,de]=(0,_.useState)(``),[M,fe]=(0,_.useState)(``),[pe,me]=(0,_.useState)(!1),[he,ge]=(0,_.useState)(``),[_e,ve]=(0,_.useState)(`en`),[ye,be]=(0,_.useState)(`07:00`),[xe,Se]=(0,_.useState)(`18:00`),[N,Ce]=(0,_.useState)(`30`),[we,Te]=(0,_.useState)(`off`),[Ee,P]=(0,_.useState)(``),[De,Oe]=(0,_.useState)(``),[ke,F]=(0,_.useState)(``),[I,Ae]=(0,_.useState)(`agent`),[je,Me]=(0,_.useState)(``),[Ne,Pe]=(0,_.useState)(!0),[Fe,Ie]=(0,_.useState)(!0),[Le,Re]=(0,_.useState)(`3`),[ze,L]=(0,_.useState)(`0.30`),[Be,Ve]=(0,_.useState)(!0),[He,Ue]=(0,_.useState)(!1),[We,Ge]=(0,_.useState)(!1),[Ke,qe]=(0,_.useState)(!1),[Je,Ye]=(0,_.useState)(!1),[Xe,Ze]=(0,_.useState)(!1),[Qe,$e]=(0,_.useState)(!1),[et,tt]=(0,_.useState)(!0),[nt,rt]=(0,_.useState)(``),[it,at]=(0,_.useState)(!1),[ot,st]=(0,_.useState)(!1),[ct,lt]=(0,_.useState)(!0),[ut,dt]=(0,_.useState)(``),[ft,pt]=(0,_.useState)(``),[mt,ht]=(0,_.useState)(``),[gt,_t]=(0,_.useState)(``),[vt,yt]=(0,_.useState)(`common`),[R,bt]=(0,_.useState)(!1),[xt,St]=(0,_.useState)(``);(0,_.useEffect)(()=>{E(`/api/config`).then(t=>{r(t??{});let n=t?.profile??{};S({name:n.name??``,email:n.email??``,phone:n.phone??``,homeAddress:n.homeAddress??``,workAddress:n.workAddress??``,city:n.city??``,country:n.country??``,company:n.company??``,role:n.role??``,notes:n.notes??``}),w(t?.provider??`nha`),ge(t?.model??``),ve(t?.lang??`en`),be(t?.planTime??`07:00`),Se(t?.summaryTime??`18:00`),Ce(String(t?.meetingAlert??`30`)),Te(t?.thinking??`off`),T(``);let i=t?.responder,o=i?.telegram;F(String(o?.botName??``));let s=String(o?.personaMode??`agent`);Ae(s===`persona`||s===`persona-only`||s===`persona+role`?s:`agent`),Me(Array.isArray(o?.allowedChatIds)?o.allowedChatIds.join(`, `):``),Pe(i?.autoRoute!==!1);let c=t?.deliberation;Ie(c?.enabled!==!1),Re(String(c?.rounds??`3`)),L(String(c?.convergence??`0.30`)),Ve(c?.tribunalEnabled!==!1);let l=t?.ops?.proactive;Ue(!!l?.enabled),Ge(!!l?.emailFollowUp),qe(!!l?.meetingPrep),Ye(!!l?.patterns),Ze(!!l?.deadlines);let u=t?.voice;$e(!!u?.preferWhisper),tt(u?.speechSynthesis!==!1),rt(String(u?.language??``));let d=t?.features;at(!!d?.verbose),st(!!d?.immersive),lt(d?.knowledgeEnabled!==!1),dt(``),pt(String(t?.github?.defaultRepo??``)),ht(``),_t(``);let f=t?.microsoft;yt(String(f?.tenantId??`common`));let p=t?.plugins;bt(!!p?.autoRun),St(String(p?.directory??``)),a(!1),t&&e(t)}),Ct()},[]);let Ct=()=>E(`/api/imap/accounts`).then(e=>d(e?.accounts??[])),wt=async(e,t)=>{s(e),await D(`/api/config`,{key:e,value:t}),l(e),s(null),setTimeout(()=>l(null),2e3)},Tt=()=>wt(`profile`,x),Et=()=>{wt(`provider`,C),wt(`model`,he),wt(`thinking`,we),ee&&wt(`key`,ee),ne&&wt(`groq-key`,ne),ie&&wt(`openai-key`,ie),ae&&wt(`gemini-key`,ae),oe&&wt(`deepseek-key`,oe),ce&&wt(`grok-key`,ce),ue&&wt(`mistral-key`,ue),M&&wt(`cohere-key`,M)},At=()=>{wt(`planTime`,ye),wt(`summaryTime`,xe),wt(`meetingAlert`,Number(N))},jt=()=>{v(t(`settings.googleOpening`)),D(`/api/google/auth`,{}).then(e=>{e?.url?(window.open(e.url,`_blank`),v(t(`settings.googleOpened`))):e?.error&&v(t(`common.error`)+`: `+e.error)}).catch(e=>v(t(`common.error`)+`: `+e.message))},Mt=()=>{confirm(t(`settings.disconnectGoogleConfirm`))&&D(`/api/google/revoke`,{}).then(()=>{r(e=>({...e,hasGoogle:!1})),v(t(`common.disconnected`))})},B=()=>{if(!f)return;let e=!!f.id,t={display_name:f.display_name,email_address:f.email_address,from_name:f.from_name,imap_host:f.imap_host,imap_port:Number(f.imap_port),smtp_host:f.smtp_host,smtp_port:Number(f.smtp_port),username:f.username};f.password&&(t.password=f.password),e&&(t.id=f.id),h(`Saving…`),D(e?`/api/imap/accounts/update`:`/api/imap/accounts`,t).then(e=>{e?.ok||e?.id?(h(`Saved!`),p(null),Ct()):h(`Error: `+(e?.error??`Unknown error`))}).catch(e=>h(`Error: `+e.message))},Nt=(e,n)=>{confirm(t(`settings.imapDelete`,{name:n}))&&D(`/api/imap/accounts/delete`,{id:e}).then(()=>Ct())},Pt=e=>{D(`/api/imap/sync`,{accountId:e}).then(()=>setTimeout(Ct,3e3))},Ft=async e=>{if(!f)return;if(!f.password&&!f.id){h(`⚠ Inserisci la password prima di testare.`);return}h(e?`Invio email di prova…`:`Test connessione in corso…`);let t={imap_host:f.imap_host,imap_port:Number(f.imap_port),smtp_host:f.smtp_host,smtp_port:Number(f.smtp_port),username:f.username,password:f.password,email_address:f.email_address,from_name:f.from_name,sendTest:e};try{let e=await D(`/api/imap/test`,t),n=e?.imap,r=e?.smtp,i=[];n?.ok?i.push(`✓ IMAP OK (TLS=${n.secure?`implicit`:`STARTTLS`}, ${n.folderCount??`?`} cartelle)`):i.push(`✗ IMAP errore: ${n?.error??`sconosciuto`}`),r?.ok?r.sent?i.push(`✓ SMTP OK — email di prova inviata a ${f.email_address} (id ${(r.messageId||``).slice(0,24)}…)`):i.push(`✓ SMTP OK (TLS=${r.secure?`implicit`:`STARTTLS`}, auth valida)`):i.push(`✗ SMTP errore: ${r?.error??`sconosciuto`}`),h(i.join(` · `))}catch(e){h(`✗ Test fallito: ${e.message}`)}};if(i)return(0,k.jsxs)(`div`,{className:z.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),t(`common.loading`)]});let It=e=>t(o===e?`common.saving`:c===e?`common.saved`:`common.save`);return(0,k.jsxs)(`div`,{className:z.root,children:[(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.profile`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.profileSub`)}),(0,k.jsx)(`div`,{className:z.fields,children:[[`name`,t(`settings.name`),t(`settings.namePh`)],[`email`,t(`common.email`),t(`settings.emailPh`)],[`phone`,t(`common.phone`),t(`settings.phonePh`)],[`homeAddress`,t(`settings.homeAddress`),t(`settings.homeAddressPh`)],[`workAddress`,t(`settings.workAddress`),t(`settings.workAddressPh`)],[`city`,t(`settings.city`),t(`settings.cityPh`)],[`country`,t(`settings.country`),t(`settings.countryPh`)],[`company`,t(`settings.company`),t(`settings.companyPh`)],[`role`,t(`settings.role`),t(`settings.rolePh`)],[`notes`,t(`settings.notes`),t(`settings.notesPh`)]].map(([e,t,n])=>(0,k.jsx)(Ot,{id:e,label:t,placeholder:n,value:x[e],onChange:t=>S(n=>({...n,[e]:t}))},e))}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:Tt,children:[It(`profile`),` `,t(`settings.saveProfile`)]})]}),(0,k.jsxs)(`div`,{className:z.nhaFree,children:[(0,k.jsx)(`div`,{className:z.nhaFreeTitle,children:t(`settings.nhaFreeTitle`)}),(0,k.jsx)(`div`,{className:z.nhaFreeSub,children:t(`settings.nhaFreeSub`)}),(0,k.jsx)(`button`,{className:z.nhaFreeBtn,onClick:()=>{D(`/api/config`,{updates:[{key:`provider`,value:`nha`},{key:`model`,value:``},{key:`key`,value:``}]}).then(()=>{w(`nha`),ge(``),T(``),l(`nhaFree`),setTimeout(()=>l(null),2e3)})},children:t(c===`nhaFree`?`settings.liaraActivated`:`settings.useLiara`)})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.llmProvider`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.llmProviderSub`)}),(()=>{let e=[];return n.hasApiKey&&e.push(`Anthropic`),n.hasOpenaiKey&&e.push(`OpenAI`),n.hasGeminiKey&&e.push(`Gemini`),n.hasDeepseekKey&&e.push(`DeepSeek`),n.hasGrokKey&&e.push(`Grok`),n.hasMistralKey&&e.push(`Mistral`),n.hasCohereKey&&e.push(`Cohere`),e.length===0?null:(0,k.jsxs)(`div`,{className:z.keySummary,children:[(0,k.jsx)(`span`,{className:z.keySummaryIcon,children:`🔑`}),(0,k.jsxs)(`span`,{children:[`Chiavi configurate: `,(0,k.jsx)(`strong`,{children:e.join(`, `)})]})]})})(),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.provider`)}),(0,k.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`nha`,children:`NHA Free (Liara) — no API key needed`}),(0,k.jsx)(`option`,{value:`anthropic`,children:`Anthropic (Claude)`}),(0,k.jsx)(`option`,{value:`openai`,children:`OpenAI (GPT-4)`}),(0,k.jsx)(`option`,{value:`gemini`,children:`Google (Gemini)`}),(0,k.jsx)(`option`,{value:`deepseek`,children:`DeepSeek`}),(0,k.jsx)(`option`,{value:`grok`,children:`xAI (Grok)`}),(0,k.jsx)(`option`,{value:`mistral`,children:`Mistral`}),(0,k.jsx)(`option`,{value:`cohere`,children:`Cohere`})]})]}),C!==`nha`&&({anthropic:n.hasApiKey,openai:n.hasOpenaiKey,gemini:n.hasGeminiKey,deepseek:n.hasDeepseekKey,grok:n.hasGrokKey,mistral:n.hasMistralKey,cohere:n.hasCohereKey}[C]?(0,k.jsx)(`div`,{className:z.keySet,children:t(`settings.apiKeySet`)}):null),(0,k.jsx)(Ot,{id:`apiKey`,label:t(`settings.apiKey`),placeholder:t(C===`nha`?`settings.apiKeyFreeNote`:`settings.apiKeyPh`),type:`password`,value:ee,onChange:T}),(0,k.jsx)(Ot,{id:`groqKey`,label:`Groq Key (voice / Whisper)`,placeholder:n.hasGroqKey?`✓ configured — leave empty to keep`:`gsk_... (free at console.groq.com/keys) — enables Telegram voice transcription`,type:`password`,value:ne,onChange:re}),(0,k.jsx)(`div`,{style:{marginTop:8,marginBottom:4},children:(0,k.jsxs)(`button`,{type:`button`,onClick:()=>me(!pe),style:{background:`transparent`,border:`none`,color:`var(--accent, #6366f1)`,cursor:`pointer`,fontSize:12,padding:0,fontWeight:600},children:[pe?`▾`:`▸`,` Optional provider keys (OpenAI, Gemini, DeepSeek, Grok, Mistral, Cohere)`]})}),pe&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(Ot,{id:`openaiKey`,label:`OpenAI Key`,placeholder:n.hasOpenaiKey?`✓ configured — leave empty to keep`:`sk-... (platform.openai.com)`,type:`password`,value:ie,onChange:O}),(0,k.jsx)(Ot,{id:`geminiKey`,label:`Gemini Key (Google)`,placeholder:n.hasGeminiKey?`✓ configured — leave empty to keep`:`AIza... (aistudio.google.com)`,type:`password`,value:ae,onChange:A}),(0,k.jsx)(Ot,{id:`deepseekKey`,label:`DeepSeek Key`,placeholder:n.hasDeepseekKey?`✓ configured — leave empty to keep`:`sk-... (platform.deepseek.com)`,type:`password`,value:oe,onChange:se}),(0,k.jsx)(Ot,{id:`grokKey`,label:`Grok Key (X.AI)`,placeholder:n.hasGrokKey?`✓ configured — leave empty to keep`:`xai-... (console.x.ai)`,type:`password`,value:ce,onChange:le}),(0,k.jsx)(Ot,{id:`mistralKey`,label:`Mistral Key`,placeholder:n.hasMistralKey?`✓ configured — leave empty to keep`:`... (console.mistral.ai)`,type:`password`,value:ue,onChange:de}),(0,k.jsx)(Ot,{id:`cohereKey`,label:`Cohere Key`,placeholder:n.hasCohereKey?`✓ configured — leave empty to keep`:`... (dashboard.cohere.com)`,type:`password`,value:M,onChange:fe})]}),(0,k.jsx)(Ot,{id:`model`,label:t(`settings.model`),placeholder:t(`settings.modelPh`),value:he,onChange:ge}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.thinking`)}),(0,k.jsxs)(`select`,{value:we,onChange:e=>Te(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`off`,children:t(`settings.thinkingOff`)}),(0,k.jsx)(`option`,{value:`on`,children:t(`settings.thinkingOn`)})]})]}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:Et,children:[It(`provider`),` `,t(`settings.saveProvider`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.language`)}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.languageLabel`)}),(0,k.jsx)(`select`,{value:_e,onChange:t=>{let r=t.target.value;ve(r),wt(`lang`,r),e({...n,lang:r})},className:z.fieldInput,children:[[`it`,`Italiano`],[`en`,`English`],[`es`,`Español`],[`fr`,`Français`],[`de`,`Deutsch`],[`pt`,`Português`],[`nl`,`Nederlands`],[`pl`,`Polski`],[`ru`,`Русский`],[`zh`,`中文`],[`ja`,`日本語`],[`ko`,`한국어`],[`ar`,`العربية`],[`hi`,`हिन्दी`],[`tr`,`Türkçe`],[`sv`,`Svenska`],[`da`,`Dansk`],[`fi`,`Suomi`],[`cs`,`Čeština`]].map(([e,t])=>(0,k.jsx)(`option`,{value:e,children:t},e))})]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.telegram`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.telegramSub`)}),n.hasTelegram&&(0,k.jsxs)(`div`,{className:z.connected,children:[`Telegram: `,t(`common.connected`)]}),n.hasDiscord&&(0,k.jsxs)(`div`,{className:z.connected,children:[`Discord: `,t(`common.connected`)]}),(0,k.jsx)(Ot,{id:`tgToken`,label:t(`settings.telegramToken`),placeholder:n.hasTelegram?t(`settings.telegramSet`):t(`settings.telegramPh`),type:`password`,value:Ee,onChange:P}),(0,k.jsx)(Ot,{id:`discordToken`,label:t(`settings.discordToken`),placeholder:n.hasDiscord?t(`settings.discordSet`):t(`settings.discordPh`),type:`password`,value:De,onChange:Oe}),(0,k.jsx)(Ot,{id:`botName`,label:`Bot Persona Name`,placeholder:`e.g. Agata — what name the bot uses when replying. Empty = show internal agent name (HERALD/ATHENA/...)`,value:ke,onChange:F}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:`Persona display mode`}),(0,k.jsxs)(`select`,{value:I,onChange:e=>Ae(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`agent`,children:`agent — show internal name [HERALD] (legacy/debug)`}),(0,k.jsx)(`option`,{value:`persona`,children:`persona — show [BotName] only (recommended)`}),(0,k.jsx)(`option`,{value:`persona-only`,children:`persona-only — no prefix at all (most natural)`}),(0,k.jsx)(`option`,{value:`persona+role`,children:`persona+role — [BotName · agent] (power users)`})]})]}),(0,k.jsx)(Ot,{id:`allowedChatIds`,label:`Allowed Chat IDs (Telegram)`,placeholder:`comma-separated numeric chat IDs (empty = anyone can chat with the bot)`,value:je,onChange:Me}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Ne,onChange:e=>Pe(e.target.checked)}),` `,`Auto-route messages to specialist agents (recommended)`]})}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{Ee&&wt(`telegram-bot-token`,Ee),De&&wt(`discord-bot-token`,De),wt(`bot-name`,ke),wt(`persona-mode`,I),wt(`responder.telegram.allowedChatIds`,je.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>Number(e)||e)),wt(`responder-auto-route`,Ne)},children:[It(`telegram-bot-token`),` `,t(`settings.saveBots`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.dailyOps`)}),(0,k.jsx)(Ot,{id:`planTime`,label:t(`settings.planTime`),placeholder:`07:00`,value:ye,onChange:be}),(0,k.jsx)(Ot,{id:`summaryTime`,label:t(`settings.summaryTime`),placeholder:`18:00`,value:xe,onChange:Se}),(0,k.jsx)(Ot,{id:`meetingAlert`,label:t(`settings.meetingAlert`),placeholder:`30`,value:N,onChange:Ce}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:At,children:[It(`planTime`),` `,t(`settings.saveSchedule`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Deliberation (Geth Consensus)`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Multi-round inter-agent reasoning for higher-quality answers`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Fe,onChange:e=>Ie(e.target.checked)}),` `,`Enable deliberation`]})}),(0,k.jsx)(Ot,{id:`delibRounds`,label:`Rounds (1–5)`,placeholder:`3`,value:Le,onChange:Re}),(0,k.jsx)(Ot,{id:`delibConvergence`,label:`Convergence threshold (0–1, lower = stricter)`,placeholder:`0.30`,value:ze,onChange:L}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Be,onChange:e=>Ve(e.target.checked)}),` `,`Tribunal (final HERALD mediation)`]})}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`deliberation`,Fe),wt(`rounds`,Number(Le)),wt(`convergence`,Number(ze)),wt(`tribunal`,Be)},children:[It(`deliberation`),` Save deliberation`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Proactive Intelligence`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`The bot acts on its own initiative (follow-ups, meeting prep, pattern detection)`}),[[`proactive`,`Master switch — enable proactive`,He,Ue],[`proactive-email`,`Email follow-up reminders`,We,Ge],[`proactive-meeting`,`Meeting preparation digests`,Ke,qe],[`proactive-patterns`,`Behavioural pattern detection`,Je,Ye],[`proactive-deadlines`,`Deadline tracking`,Xe,Ze]].map(([e,t,n,r])=>(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),` `,t]})},String(e))),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`proactive`,He),wt(`proactive-email`,We),wt(`proactive-meeting`,Ke),wt(`proactive-patterns`,Je),wt(`proactive-deadlines`,Xe)},children:[It(`proactive`),` Save proactive`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Voice`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Transcription (Whisper via Groq) and text-to-speech`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Qe,onChange:e=>$e(e.target.checked)}),` `,`Prefer Whisper (Groq) over local STT`]})}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:et,onChange:e=>tt(e.target.checked)}),` `,`Speech synthesis (read replies aloud)`]})}),(0,k.jsx)(Ot,{id:`voiceLanguage`,label:`Voice language (BCP 47, e.g. it-IT, en-US)`,placeholder:`empty = use UI language`,value:nt,onChange:rt}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`voice-whisper`,Qe),wt(`voice-speech`,et),nt&&wt(`voice-language`,nt)},children:[It(`voice-whisper`),` Save voice`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Features`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Core behaviour toggles`}),[[`verbose`,`Verbose logging (more diagnostics, more tokens)`,it,at],[`immersive`,`Immersive office scene animation in Studio`,ot,st],[`knowledge`,`Knowledge base (memories + skills retrieval)`,ct,lt]].map(([e,t,n,r])=>(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),` `,t]})},String(e))),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`verbose`,it),wt(`immersive`,ot),wt(`knowledge`,ct)},children:[It(`verbose`),` Save features`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Integration tokens`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`GitHub, Notion, Slack — used by the corresponding tools`}),(0,k.jsx)(Ot,{id:`githubToken`,label:`GitHub Token (PAT)`,placeholder:n.hasGithubToken?`✓ configured — leave empty to keep`:`ghp_... — needs repo + read:org scopes`,type:`password`,value:ut,onChange:dt}),(0,k.jsx)(Ot,{id:`githubRepo`,label:`Default GitHub repo (owner/name)`,placeholder:`acme/website`,value:ft,onChange:pt}),(0,k.jsx)(Ot,{id:`notionToken`,label:`Notion Token (Internal Integration)`,placeholder:n.hasNotionToken?`✓ configured — leave empty to keep`:`secret_...`,type:`password`,value:mt,onChange:ht}),(0,k.jsx)(Ot,{id:`slackToken`,label:`Slack Bot Token (xoxb-)`,placeholder:n.hasSlackToken?`✓ configured — leave empty to keep`:`xoxb-...`,type:`password`,value:gt,onChange:_t}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{ut&&wt(`github-token`,ut),ft&&wt(`github-repo`,ft),mt&&wt(`notion-token`,mt),gt&&wt(`slack-token`,gt)},children:[It(`github-token`),` Save tokens`]})]}),(0,k.jsx)(kt,{}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Advanced`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Plugins, Microsoft tenant ID, runtime extras`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:R,onChange:e=>bt(e.target.checked)}),` `,`Auto-run plugins at startup`]})}),(0,k.jsx)(Ot,{id:`pluginDir`,label:`Plugin directory (absolute path)`,placeholder:`empty = ~/.nha/plugins`,value:xt,onChange:St}),(0,k.jsx)(Ot,{id:`microsoftTenant`,label:`Microsoft Tenant ID`,placeholder:`common (default) | organizations | consumers | <GUID>`,value:vt,onChange:yt}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`plugin-autorun`,R),xt&&wt(`plugin-dir`,xt),wt(`microsoft-tenant`,vt)},children:[It(`plugin-autorun`),` Save advanced`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.googleAccount`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.googleSub`)}),n.hasGoogle&&(0,k.jsxs)(`div`,{className:z.connected,children:[`✅ `,t(`common.connected`),n.googleEmail?` · ${n.googleEmail}`:``]}),(0,k.jsxs)(`div`,{className:z.btnRow,children:[(0,k.jsx)(`button`,{className:z.saveBtn,onClick:jt,children:n.hasGoogle?t(`settings.reconnectGoogle`):t(`settings.connectGoogle`)}),n.hasGoogle&&(0,k.jsx)(`button`,{className:z.dangerBtn,onClick:Mt,children:t(`settings.disconnectGoogle`)})]}),g&&(0,k.jsx)(`div`,{className:z.statusMsg,children:g})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsxs)(`div`,{className:z.cardTitleRow,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.imapAccounts`)}),(0,k.jsx)(`button`,{className:z.saveBtn,onClick:()=>{p({...Dt}),h(``)},children:t(`settings.addAccount`)})]}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.imapSub`)}),u.length===0&&!f&&(0,k.jsx)(`div`,{className:z.emptyImap,children:t(`settings.noImapAccounts`)}),u.map(e=>(0,k.jsxs)(`div`,{className:z.imapRow,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:z.imapName,children:e.display_name}),(0,k.jsxs)(`div`,{className:z.imapMeta,children:[e.email_address,` · `,e.imap_host]}),(0,k.jsxs)(`div`,{className:z.imapStatus,"data-status":e.sync_status,children:[e.sync_status,e.last_sync_at?` · ${t(`email.lastSync`)}: ${e.last_sync_at.slice(0,16)}`:``]})]}),(0,k.jsxs)(`div`,{className:z.imapBtns,children:[(0,k.jsx)(`button`,{className:z.imapSyncBtn,onClick:()=>Pt(e.id),children:t(`settings.sync`)}),(0,k.jsx)(`button`,{className:z.imapEditBtn,onClick:()=>{p({...Dt,id:e.id,display_name:e.display_name,email_address:e.email_address,from_name:e.from_name??``,imap_host:e.imap_host,imap_port:String(e.imap_port??993),smtp_host:e.smtp_host??``,smtp_port:String(e.smtp_port??587),username:e.username??``,password:``}),h(``)},children:t(`common.edit`)}),(0,k.jsx)(`button`,{className:z.imapDelBtn,onClick:()=>Nt(e.id,e.display_name),children:t(`common.delete`)})]})]},e.id)),f&&(0,k.jsxs)(`div`,{className:z.imapForm,children:[(0,k.jsx)(`div`,{className:z.imapFormTitle,children:f.id?t(`settings.editImapAccount`):t(`settings.addImapAccount`)}),[[`display_name`,t(`settings.displayName`),t(`settings.displayNamePh`)],[`email_address`,t(`common.email`),`user@example.com`],[`from_name`,t(`settings.fromName`),t(`settings.fromNamePh`)],[`imap_host`,t(`settings.imapServer`),`e.g. imap.gmail.com`],[`imap_port`,t(`settings.imapPort`),`993`],[`smtp_host`,t(`settings.smtpServer`),`e.g. smtp.gmail.com`],[`smtp_port`,t(`settings.smtpPort`),`587`],[`username`,t(`settings.username`),`user@example.com`]].map(([e,t,n])=>(0,k.jsx)(Ot,{id:`imap_${e}`,label:t,placeholder:n,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t})},e)),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[t(`settings.password`),` `,f.id&&(0,k.jsx)(`span`,{className:z.pwdNote,children:t(`settings.passwordKeep`)})]}),(0,k.jsxs)(`div`,{className:z.pwdRow,children:[(0,k.jsx)(`input`,{type:y?`text`:`password`,placeholder:t(`settings.passwordPh`),value:f.password,onChange:e=>p(t=>t&&{...t,password:e.target.value}),className:z.fieldInput,style:{flex:1}}),(0,k.jsx)(`button`,{className:z.togglePwd,onClick:()=>b(e=>!e),children:t(y?`settings.hide`:`settings.show`)})]})]}),(0,k.jsxs)(`div`,{className:z.btnRow,children:[(0,k.jsx)(`button`,{className:z.saveBtn,onClick:B,children:t(`common.save`)}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>Ft(!1),title:`Verifica IMAP+SMTP senza inviare nulla`,children:`Test connessione`}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>Ft(!0),title:`Invia un'email di prova alla tua casella per verificare il round-trip`,children:`Invia email di prova`}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>p(null),children:t(`common.cancel`)})]}),m&&(0,k.jsx)(`div`,{className:z.statusMsg,style:{whiteSpace:`pre-line`},children:m})]})]})]})}var jt={root:`_root_o07ov_1`,loading:`_loading_o07ov_2`,err:`_err_o07ov_3`,header:`_header_o07ov_4`,title:`_title_o07ov_5`,addBtn:`_addBtn_o07ov_6`,empty:`_empty_o07ov_7`,card:`_card_o07ov_8`,cardToday:`_cardToday_o07ov_9`,icon:`_icon_o07ov_10`,info:`_info_o07ov_11`,name:`_name_o07ov_12`,date:`_date_o07ov_13`,labelToday:`_labelToday_o07ov_14`,labelTomorrow:`_labelTomorrow_o07ov_15`,labelFuture:`_labelFuture_o07ov_16`,editBtn:`_editBtn_o07ov_17`,delBtn:`_delBtn_o07ov_18`,overlay:`_overlay_o07ov_20`,modal:`_modal_o07ov_21`,modalTitle:`_modalTitle_o07ov_22`,label:`_label_o07ov_14`,input:`_input_o07ov_24`,hint:`_hint_o07ov_25`,formErr:`_formErr_o07ov_26`,modalBtns:`_modalBtns_o07ov_27`,cancelBtn:`_cancelBtn_o07ov_28`,saveBtn:`_saveBtn_o07ov_29`};function Mt(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),p=(0,_.useCallback)(()=>{i(!0),E(`/api/birthdays`).then(e=>{e?.error?o(e.error):n(e?.birthdays??[]),i(!1)})},[]);(0,_.useEffect)(()=>{p()},[p]);let m=()=>{c({name:``,date:``}),u(``)},h=e=>{c({name:e.name,date:e.date,contactId:e.contactId}),u(``)},g=async()=>{if(!s)return;if(!s.name.trim()){u(`Name is required`);return}if(!s.date.trim()){u(`Date is required`);return}f(!0);let e=s.date;/^\d{2}-\d{2}$/.test(e)&&(e=`${new Date().getFullYear()}-${e}`),await D(`/api/birthdays`,{name:s.name,date:e,contactId:s.contactId??null,edit:!!s.contactId}),f(!1),c(null),p()},v=e=>{confirm(`Remove birthday for ${e.name}?`)&&D(`/api/birthdays/delete`,{contactId:e.contactId}).then(p)};return r?(0,k.jsxs)(`div`,{className:jt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:jt.err,children:a}):(0,k.jsxs)(`div`,{className:jt.root,children:[(0,k.jsxs)(`div`,{className:jt.header,children:[(0,k.jsx)(`div`,{className:jt.title,children:`Upcoming Birthdays`}),(0,k.jsx)(`button`,{className:jt.addBtn,onClick:m,children:`+ Add Birthday`})]}),t.length===0&&(0,k.jsxs)(`div`,{className:jt.empty,children:[e(`birthdays.noBirthdays`),(0,k.jsx)(`br`,{}),(0,k.jsx)(`small`,{children:`Add one above, or add birthdays to your Google Contacts.`})]}),t.map((t,n)=>{let r=t.daysUntil===0,i=t.daysUntil===1;return(0,k.jsxs)(`div`,{className:`${jt.card} ${r?jt.cardToday:``}`,children:[(0,k.jsx)(`span`,{className:jt.icon,children:`🎂`}),(0,k.jsxs)(`div`,{className:jt.info,children:[(0,k.jsx)(`div`,{className:jt.name,children:t.name}),(0,k.jsx)(`div`,{className:jt.date,children:t.date})]}),(0,k.jsx)(`div`,{className:r?jt.labelToday:i?jt.labelTomorrow:jt.labelFuture,children:r?`TODAY!`:i?`Tomorrow`:`in ${t.daysUntil} days`}),t.contactId&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:jt.editBtn,onClick:()=>h(t),children:e(`common.edit`)}),(0,k.jsx)(`button`,{className:jt.delBtn,onClick:()=>v(t),children:e(`common.delete`)})]})]},n)}),s&&(0,k.jsx)(`div`,{className:jt.overlay,onClick:e=>{e.target===e.currentTarget&&c(null)},children:(0,k.jsxs)(`div`,{className:jt.modal,children:[(0,k.jsx)(`div`,{className:jt.modalTitle,children:s.contactId?`Edit Birthday`:`Add Birthday`}),(0,k.jsx)(`label`,{className:jt.label,children:`Name *`}),(0,k.jsx)(`input`,{className:jt.input,value:s.name,onChange:e=>c(t=>t&&{...t,name:e.target.value}),placeholder:`Contact name`}),(0,k.jsx)(`label`,{className:jt.label,children:`Birthday (MM-DD or YYYY-MM-DD)`}),(0,k.jsx)(`input`,{className:jt.input,value:s.date,onChange:e=>c(t=>t&&{...t,date:e.target.value}),placeholder:`e.g. 03-15 or 1990-03-15`}),(0,k.jsx)(`div`,{className:jt.hint,children:`Birthday will be saved as a Google Calendar event.`}),l&&(0,k.jsx)(`div`,{className:jt.formErr,children:l}),(0,k.jsxs)(`div`,{className:jt.modalBtns,children:[(0,k.jsx)(`button`,{className:jt.cancelBtn,onClick:()=>c(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:jt.saveBtn,onClick:g,disabled:d,children:d?`Saving…`:s.contactId?`Save`:`Add`})]})]})})]})}var B={root:`_root_1z04o_1`,header:`_header_1z04o_3`,title:`_title_1z04o_4`,subtitle:`_subtitle_1z04o_5`,code:`_code_1z04o_6`,addBtn:`_addBtn_1z04o_8`,tabs:`_tabs_1z04o_10`,tab:`_tab_1z04o_10`,tabActive:`_tabActive_1z04o_12`,loading:`_loading_1z04o_14`,err:`_err_1z04o_15`,empty:`_empty_1z04o_17`,emptyIcon:`_emptyIcon_1z04o_18`,emptyTitle:`_emptyTitle_1z04o_19`,emptySub:`_emptySub_1z04o_20`,card:`_card_1z04o_23`,cardDisabled:`_cardDisabled_1z04o_24`,cardTop:`_cardTop_1z04o_25`,cardLeft:`_cardLeft_1z04o_26`,jobName:`_jobName_1z04o_27`,schedule:`_schedule_1z04o_28`,agentBadge:`_agentBadge_1z04o_29`,statusBadge:`_statusBadge_1z04o_30`,statusActive:`_statusActive_1z04o_31`,statusPaused:`_statusPaused_1z04o_32`,jobPrompt:`_jobPrompt_1z04o_33`,jobMeta:`_jobMeta_1z04o_34`,cardActions:`_cardActions_1z04o_35`,runBtn:`_runBtn_1z04o_36`,editBtn:`_editBtn_1z04o_37`,pauseBtn:`_pauseBtn_1z04o_38`,resumeBtn:`_resumeBtn_1z04o_39`,delBtn:`_delBtn_1z04o_40`,templates:`_templates_1z04o_43`,templatesNote:`_templatesNote_1z04o_44`,templateCard:`_templateCard_1z04o_45`,templateLabel:`_templateLabel_1z04o_46`,templatePrompt:`_templatePrompt_1z04o_47`,templateBtns:`_templateBtns_1z04o_48`,scheduleTplBtn:`_scheduleTplBtn_1z04o_49`,runTplBtn:`_runTplBtn_1z04o_50`,formOverlay:`_formOverlay_1z04o_54`,formModal:`_formModal_1z04o_55`,formTitle:`_formTitle_1z04o_56`,label:`_label_1z04o_57`,input:`_input_1z04o_58`,textarea:`_textarea_1z04o_59`,presets:`_presets_1z04o_61`,preset:`_preset_1z04o_61`,presetActive:`_presetActive_1z04o_63`,cronHints:`_cronHints_1z04o_65`,cronHint:`_cronHint_1z04o_65`,formErr:`_formErr_1z04o_70`,formOk:`_formOk_1z04o_71`,formBtns:`_formBtns_1z04o_72`,cancelBtn:`_cancelBtn_1z04o_73`,saveBtn:`_saveBtn_1z04o_74`},Nt=[{label:`Every 15 min`,value:`every 15 minutes`},{label:`Every 30 min`,value:`every 30 minutes`},{label:`Every hour`,value:`every hour`},{label:`Every 6h`,value:`every 6 hours`},{label:`Daily 8am`,value:`every day at 08:00`},{label:`Daily 9am`,value:`every day at 09:00`},{label:`Daily noon`,value:`every day at 12:00`},{label:`Daily 6pm`,value:`every day at 18:00`},{label:`Mon–Fri 9am`,value:`weekdays at 09:00`},{label:`Every Monday`,value:`every monday at 09:00`}],Pt=[{label:`🌅 Morning Briefing`,prompt:`Summarize my unread emails from the last 12 hours, check today's calendar events, list my top 3 priority tasks, and give me a focused action plan for the day.`},{label:`🌆 Evening Review`,prompt:`Review what I accomplished today: check completed tasks, summarize any important emails received, flag unresolved issues, and prepare a priority list for tomorrow.`},{label:`📰 News Digest`,prompt:`Search for the top AI, tech, and finance news from the last 24 hours. Summarize the 5 most important stories with key takeaways and market implications.`},{label:`📈 Market Update`,prompt:`Provide a comprehensive market update: macro environment, major indices performance, top movers, notable events, and key levels to watch. Use herald and mercury agents.`},{label:`🐙 GitHub Monitor`,prompt:`Check my GitHub notifications, summarize open issues and pull requests that need attention, and draft brief responses for the most urgent ones.`},{label:`📊 Weekly Report`,prompt:`Generate a weekly productivity report: tasks completed vs pending, email response rate, upcoming calendar events, and 3 strategic priorities for next week.`},{label:`🔒 Security Scan`,prompt:`Run a security awareness check: scan recent code commits for potential vulnerabilities, check dependency alerts, and summarize any security-related GitHub notifications.`},{label:`🎯 Goal Tracker`,prompt:`Review my tasks and notes for goal progress. Identify what's on track, what's at risk, and suggest one concrete action to unblock the most important goal.`}],Ft=[{label:`0 9 * * 1-5`,desc:`Mon–Fri at 9:00 AM`},{label:`0 */6 * * *`,desc:`Every 6 hours`},{label:`*/30 * * * *`,desc:`Every 30 minutes`},{label:`0 8 * * *`,desc:`Daily at 8:00 AM`},{label:`0 20 * * 5`,desc:`Every Friday at 8 PM`}];function It(){let e=j(),t=te(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)({name:``,schedule:``,prompt:``,agent:``}),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(`jobs`),C=()=>{a(!0),E(`/api/cron`).then(e=>{e?.error?s(e.error):r(e?.jobs??[]),a(!1)}).catch(()=>{r([]),a(!1)})};(0,_.useEffect)(()=>{C()},[]);let w=()=>{d({name:``,schedule:``,prompt:``,agent:``}),h(``),v(``),b(null),l(!0)},ee=e=>{d({name:e.name??``,schedule:e.schedule,prompt:e.prompt??e.command??``,agent:e.agent??``}),h(``),v(``),b(e.id),l(!0)},T=async()=>{if(!u.schedule.trim()){h(`Schedule is required`);return}if(!u.prompt.trim()){h(`Task prompt is required`);return}p(!0),h(``);try{y?await D(`/api/cron/update`,{id:y,schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}):await D(`/api/cron`,{schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}),v(y?`Updated!`:`Job scheduled!`),setTimeout(()=>{v(``),l(!1)},1500),C()}catch(e){h(e.message??`Failed`)}p(!1)},ne=(e,t)=>D(`/api/cron/toggle`,{id:e,enabled:!t}).then(C),re=e=>{confirm(`Delete this scheduled task?`)&&D(`/api/cron/delete`,{id:e}).then(C)},ie=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},O=e=>{d(t=>({...t,prompt:e.prompt,name:e.label.replace(/^[^\s]+\s/,``)})),S(`jobs`),l(!0)};return(0,k.jsxs)(`div`,{className:B.root,children:[(0,k.jsxs)(`div`,{className:B.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:B.title,children:`⏰ Scheduled Tasks`}),(0,k.jsxs)(`div`,{className:B.subtitle,children:[`Automate agents on a recurring schedule. Daemon must be running: `,(0,k.jsx)(`code`,{className:B.code,children:`nha ops start`})]})]}),(0,k.jsx)(`button`,{className:B.addBtn,onClick:w,children:`+ New Task`})]}),(0,k.jsxs)(`div`,{className:B.tabs,children:[(0,k.jsxs)(`button`,{className:`${B.tab} ${x===`jobs`?B.tabActive:``}`,onClick:()=>S(`jobs`),children:[`Jobs (`,n.length,`)`]}),(0,k.jsx)(`button`,{className:`${B.tab} ${x===`templates`?B.tabActive:``}`,onClick:()=>S(`templates`),children:`Templates`})]}),x===`templates`&&(0,k.jsxs)(`div`,{className:B.templates,children:[(0,k.jsx)(`div`,{className:B.templatesNote,children:`Click a template to pre-fill the job form or run it immediately in Chat.`}),Pt.map(t=>(0,k.jsxs)(`div`,{className:B.templateCard,children:[(0,k.jsx)(`div`,{className:B.templateLabel,children:t.label}),(0,k.jsx)(`div`,{className:B.templatePrompt,children:t.prompt}),(0,k.jsxs)(`div`,{className:B.templateBtns,children:[(0,k.jsx)(`button`,{className:B.scheduleTplBtn,onClick:()=>O(t),children:`Schedule`}),(0,k.jsxs)(`button`,{className:B.runTplBtn,onClick:()=>ie(t.prompt),children:[e(`cron.run`),` in Chat →`]})]})]},t.label))]}),x===`jobs`&&(0,k.jsxs)(k.Fragment,{children:[i&&(0,k.jsxs)(`div`,{className:B.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading jobs…`]}),o&&(0,k.jsx)(`div`,{className:B.err,children:o}),!i&&n.length===0&&!c&&(0,k.jsxs)(`div`,{className:B.empty,children:[(0,k.jsx)(`div`,{className:B.emptyIcon,children:`⏰`}),(0,k.jsxs)(`div`,{className:B.emptyTitle,children:[e(`cron.noJobs`),` tasks`]}),(0,k.jsx)(`div`,{className:B.emptySub,children:`Create a job to automate agents on a recurring schedule, or browse the Templates tab for ready-made automation recipes.`}),(0,k.jsx)(`button`,{className:B.addBtn,onClick:w,children:`+ New Task`})]}),n.map(e=>(0,k.jsxs)(`div`,{className:`${B.card} ${e.enabled?``:B.cardDisabled}`,children:[(0,k.jsxs)(`div`,{className:B.cardTop,children:[(0,k.jsxs)(`div`,{className:B.cardLeft,children:[e.name&&(0,k.jsx)(`div`,{className:B.jobName,children:e.name}),(0,k.jsx)(`code`,{className:B.schedule,children:e.schedule}),e.agent&&(0,k.jsx)(`span`,{className:B.agentBadge,children:e.agent}),(0,k.jsx)(`span`,{className:`${B.statusBadge} ${e.enabled?B.statusActive:B.statusPaused}`,children:e.enabled?`active`:`paused`})]}),(0,k.jsxs)(`div`,{className:B.cardActions,children:[(0,k.jsx)(`button`,{className:B.runBtn,onClick:()=>ie(e.prompt??e.command??``),title:`Run now in Chat`,children:`▶`}),(0,k.jsx)(`button`,{className:B.editBtn,onClick:()=>ee(e),children:`Edit`}),(0,k.jsx)(`button`,{className:e.enabled?B.pauseBtn:B.resumeBtn,onClick:()=>ne(e.id,e.enabled),children:e.enabled?`Pause`:`Resume`}),(0,k.jsx)(`button`,{className:B.delBtn,onClick:()=>re(e.id),children:`✕`})]})]}),(0,k.jsx)(`div`,{className:B.jobPrompt,children:e.prompt??e.command}),(0,k.jsxs)(`div`,{className:B.jobMeta,children:[e.runCount!==void 0&&(0,k.jsxs)(`span`,{children:[`ran `,e.runCount,`×`]}),e.lastRun&&(0,k.jsxs)(`span`,{children:[` · last `,new Date(e.lastRun).toLocaleString()]}),e.nextRun&&(0,k.jsxs)(`span`,{children:[` · next `,new Date(e.nextRun).toLocaleString()]})]})]},e.id))]}),c&&(0,k.jsx)(`div`,{className:B.formOverlay,onClick:e=>{e.target===e.currentTarget&&l(!1)},children:(0,k.jsxs)(`div`,{className:B.formModal,children:[(0,k.jsx)(`div`,{className:B.formTitle,children:y?`Edit Scheduled Task`:`New Scheduled Task`}),(0,k.jsx)(`label`,{className:B.label,children:`Name (optional)`}),(0,k.jsx)(`input`,{className:B.input,value:u.name,onChange:e=>d(t=>({...t,name:e.target.value})),placeholder:`e.g. Morning Briefing`}),(0,k.jsx)(`label`,{className:B.label,children:`Schedule *`}),(0,k.jsx)(`div`,{className:B.presets,children:Nt.map(e=>(0,k.jsx)(`button`,{className:`${B.preset} ${u.schedule===e.value?B.presetActive:``}`,onClick:()=>d(t=>({...t,schedule:e.value})),children:e.label},e.value))}),(0,k.jsx)(`input`,{className:B.input,value:u.schedule,onChange:e=>d(t=>({...t,schedule:e.target.value})),placeholder:`every day at 09:00 — or cron syntax: 0 9 * * 1-5`}),(0,k.jsx)(`div`,{className:B.cronHints,children:Ft.map(e=>(0,k.jsxs)(`span`,{className:B.cronHint,onClick:()=>d(t=>({...t,schedule:e.label})),children:[(0,k.jsx)(`code`,{children:e.label}),` `,e.desc]},e.label))}),(0,k.jsx)(`label`,{className:B.label,children:`Task / Prompt *`}),(0,k.jsx)(`textarea`,{className:B.textarea,value:u.prompt,onChange:e=>d(t=>({...t,prompt:e.target.value})),placeholder:`Describe what the agent should do (e.g. Summarize my unread emails and list my 3 top priority tasks)`,rows:4}),(0,k.jsx)(`label`,{className:B.label,children:`Agent (optional — leave blank for auto-routing)`}),(0,k.jsx)(`input`,{className:B.input,value:u.agent,onChange:e=>d(t=>({...t,agent:e.target.value})),placeholder:`e.g. herald, oracle, mercury, EmailAgent, general`}),m&&(0,k.jsx)(`div`,{className:B.formErr,children:m}),g&&(0,k.jsx)(`div`,{className:B.formOk,children:g}),(0,k.jsxs)(`div`,{className:B.formBtns,children:[(0,k.jsx)(`button`,{className:B.cancelBtn,onClick:()=>l(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:B.saveBtn,onClick:T,disabled:f,children:f?`Saving…`:y?`Update`:`Schedule`})]})]})})]})}var Lt={root:`_root_1npv7_1`,loading:`_loading_1npv7_2`,sidebar:`_sidebar_1npv7_4`,newBtn:`_newBtn_1npv7_5`,empty:`_empty_1npv7_6`,noteItem:`_noteItem_1npv7_8`,noteItemActive:`_noteItemActive_1npv7_10`,noteTitle:`_noteTitle_1npv7_11`,noteMeta:`_noteMeta_1npv7_12`,notePreview:`_notePreview_1npv7_13`,noteTags:`_noteTags_1npv7_14`,noteTag:`_noteTag_1npv7_14`,editor:`_editor_1npv7_17`,emptyEditor:`_emptyEditor_1npv7_18`,titleInput:`_titleInput_1npv7_19`,contentArea:`_contentArea_1npv7_21`,editorFooter:`_editorFooter_1npv7_22`,delNoteBtn:`_delNoteBtn_1npv7_23`,cancelBtn:`_cancelBtn_1npv7_24`,saveBtn:`_saveBtn_1npv7_25`};function Rt(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(!1),h=()=>E(`/api/notes`).then(e=>{n(e?.notes??[]),i(!1)});(0,_.useEffect)(()=>{h()},[]);let g=e=>{o(e),c(e.title),u(e.content),m(!1)},v=()=>{o(null),c(``),u(``),m(!0)},y=async()=>{f(!0),p?await D(`/api/notes`,{title:s||`Untitled`,content:l}):a&&await D(`/api/notes/${a.id}`,{title:s,content:l}),f(!1),m(!1),h()},b=(e,t)=>{confirm(`Delete note "${t}"?`)&&D(`/api/notes/${e}/delete`,{}).then(h)};return r?(0,k.jsxs)(`div`,{className:Lt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:Lt.root,children:[(0,k.jsxs)(`div`,{className:Lt.sidebar,children:[(0,k.jsx)(`button`,{className:Lt.newBtn,onClick:v,children:`+ New Note`}),t.length===0&&(0,k.jsx)(`div`,{className:Lt.empty,children:e(`notes.noNotes`)}),t.map(e=>(0,k.jsxs)(`div`,{className:`${Lt.noteItem} ${a?.id===e.id?Lt.noteItemActive:``}`,onClick:()=>g(e),children:[(0,k.jsx)(`div`,{className:Lt.noteTitle,children:e.title||`Untitled`}),(0,k.jsx)(`div`,{className:Lt.noteMeta,children:e.updatedAt?new Date(e.updatedAt).toLocaleDateString():``}),e.content&&(0,k.jsx)(`div`,{className:Lt.notePreview,children:e.content.slice(0,150)}),e.tags&&e.tags.length>0&&(0,k.jsx)(`div`,{className:Lt.noteTags,children:e.tags.map(e=>(0,k.jsx)(`span`,{className:Lt.noteTag,children:e},e))})]},e.id))]}),(0,k.jsx)(`div`,{className:Lt.editor,children:a||p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`input`,{className:Lt.titleInput,value:s,onChange:e=>c(e.target.value),placeholder:`Note title…`}),(0,k.jsx)(`textarea`,{className:Lt.contentArea,value:l,onChange:e=>u(e.target.value),placeholder:`Start writing…`}),(0,k.jsxs)(`div`,{className:Lt.editorFooter,children:[a&&(0,k.jsx)(`button`,{className:Lt.delNoteBtn,onClick:()=>b(a.id,a.title),children:e(`common.delete`)}),(0,k.jsx)(`button`,{className:Lt.cancelBtn,onClick:()=>{o(null),m(!1)},children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:Lt.saveBtn,onClick:y,disabled:d,children:d?`Saving…`:`Save`})]})]}):(0,k.jsx)(`div`,{className:Lt.emptyEditor,children:`Select a note or create a new one`})})]})}var zt={root:`_root_18yos_1`,loading:`_loading_18yos_2`,error:`_error_18yos_3`,toolbar:`_toolbar_18yos_5`,search:`_search_18yos_6`,addBtn:`_addBtn_18yos_7`,count:`_count_18yos_10`,empty:`_empty_18yos_12`,grid:`_grid_18yos_14`,card:`_card_18yos_16`,actions:`_actions_18yos_29`,avatar:`_avatar_18yos_31`,avatarImg:`_avatarImg_18yos_38`,info:`_info_18yos_40`,name:`_name_18yos_41`,row:`_row_18yos_42`,email:`_email_18yos_43`,phone:`_phone_18yos_44`,company:`_company_18yos_45`,birthday:`_birthday_18yos_46`,iconBtn:`_iconBtn_18yos_52`,iconBtnRed:`_iconBtnRed_18yos_58`,overlay:`_overlay_18yos_61`,modal:`_modal_18yos_62`,modalTitle:`_modalTitle_18yos_63`,field:`_field_18yos_64`,label:`_label_18yos_65`,input:`_input_18yos_66`,formStatus:`_formStatus_18yos_67`,formError:`_formError_18yos_68`,modalBtns:`_modalBtns_18yos_69`,cancelBtn:`_cancelBtn_18yos_70`,saveBtn:`_saveBtn_18yos_71`},Bt={name:``,email:``,phone:``,company:``,address:``,notes:``};function Vt(){let e=j(),t=te(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(``),y=(0,_.useRef)(null),b=(e=``)=>{E(e?`/api/contacts?q=${encodeURIComponent(e)}`:`/api/contacts`).then(e=>{r(e?.contacts??[]),a(!1),s(``)}).catch(()=>{s(`Could not load contacts. Run nha google revoke then nha google auth.`),a(!1)})};(0,_.useEffect)(()=>{b()},[]);let x=e=>{l(e),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>b(e),400)},S=()=>{d(null),p({...Bt}),v(``)},C=e=>{d(e),p({name:e.name,email:e.email??``,phone:e.phone??``,company:e.company??``,address:e.address??``,notes:e.notes??``}),v(``)},w=async()=>{if(f?.name){h(!0),v(`Saving…`);try{if(u?.resourceName){let e=await D(`/api/contacts/update`,{resourceName:u.resourceName,fields:f});if(e?.error){v(`Error: `+e.error);return}}else if(u)await D(`/api/contacts/update`,{resourceName:u.id,fields:f});else{let e=await D(`/api/contacts`,f);if(e?.error){v(`Error: `+e.error);return}}v(`Saved!`),setTimeout(()=>{p(null),d(null),b(c)},800)}catch(e){v(`Error: `+e.message)}finally{h(!1)}}},ee=(e,t)=>{e.stopPropagation(),confirm(`Delete "${t.name}"?`)&&D(`/api/contacts/delete`,{resourceName:t.resourceName||t.id}).then(e=>{let t=e;if(t?.error){alert(`Error: `+t.error);return}b(c)})},T=(e,n,r)=>{e.stopPropagation(),t(`chat`),setTimeout(()=>{let e=document.getElementById(`chatInput`);e&&(e.value=`Send an email to ${r} (${n}) about `,e.focus())},300)},ne=e=>(e||`?`).split(` `).map(e=>e[0]).slice(0,2).join(``).toUpperCase();return i?(0,k.jsxs)(`div`,{className:zt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading contacts…`]}):o?(0,k.jsx)(`div`,{className:zt.error,children:o}):(0,k.jsxs)(`div`,{className:zt.root,children:[(0,k.jsxs)(`div`,{className:zt.toolbar,children:[(0,k.jsx)(`input`,{className:zt.search,value:c,onChange:e=>x(e.target.value),placeholder:`Search contacts…`}),n.length>0&&(0,k.jsxs)(`span`,{className:zt.count,children:[n.length,` contact`,n.length===1?``:`s`]}),(0,k.jsx)(`button`,{className:zt.addBtn,onClick:S,children:`+ Add`})]}),n.length===0&&(0,k.jsxs)(`div`,{className:zt.empty,children:[e(`contacts.noContacts`),(0,k.jsx)(`br`,{}),`Add a Google account or add contacts manually.`]}),(0,k.jsx)(`div`,{className:zt.grid,children:n.map(e=>(0,k.jsxs)(`div`,{className:zt.card,onClick:()=>C(e),children:[(0,k.jsx)(`div`,{className:zt.avatar,children:e.photo?(0,k.jsx)(`img`,{src:e.photo,alt:e.name,className:zt.avatarImg}):ne(e.name)}),(0,k.jsxs)(`div`,{className:zt.info,children:[(0,k.jsx)(`div`,{className:zt.name,children:e.name||`(no name)`}),(0,k.jsxs)(`div`,{className:zt.row,children:[e.email&&(0,k.jsx)(`span`,{className:zt.email,children:e.email}),e.phone&&(0,k.jsx)(`span`,{className:zt.phone,children:e.phone}),e.company&&(0,k.jsxs)(`span`,{className:zt.company,children:[e.company,e.title?` · ${e.title}`:``]}),e.birthday&&(0,k.jsxs)(`span`,{className:zt.birthday,children:[`🎂 `,e.birthday]})]})]}),(0,k.jsxs)(`div`,{className:zt.actions,children:[e.email&&(0,k.jsx)(`button`,{className:zt.iconBtn,onClick:t=>T(t,e.email,e.name),title:`Send email via chat`,children:`✉`}),(0,k.jsx)(`button`,{className:zt.iconBtn,onClick:t=>{t.stopPropagation(),C(e)},title:`Edit`,children:`✎`}),(0,k.jsx)(`button`,{className:`${zt.iconBtn} ${zt.iconBtnRed}`,onClick:t=>ee(t,e),title:`Delete`,children:`✕`})]})]},e.id))}),f&&(0,k.jsx)(`div`,{className:zt.overlay,onClick:e=>{e.target===e.currentTarget&&p(null)},children:(0,k.jsxs)(`div`,{className:zt.modal,children:[(0,k.jsx)(`div`,{className:zt.modalTitle,children:u?`Edit Contact`:`New Contact`}),[[`name`,`Name`,`Full name *`],[`email`,`Email`,`user@example.com`],[`phone`,`Phone`,`+1 555 123 4567`],[`company`,`Company`,`Acme Inc`],[`address`,`Address`,`123 Main St, New York`],[`notes`,`Notes`,`Any additional info`]].map(([e,t,n])=>(0,k.jsxs)(`div`,{className:zt.field,children:[(0,k.jsx)(`label`,{className:zt.label,children:t}),(0,k.jsx)(`input`,{className:zt.input,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t.target.value}),placeholder:n,onKeyDown:t=>t.key===`Enter`&&e===`name`&&w()})]},e)),g&&(0,k.jsx)(`div`,{className:g.startsWith(`Error`)?zt.formError:zt.formStatus,children:g}),(0,k.jsxs)(`div`,{className:zt.modalBtns,children:[(0,k.jsx)(`button`,{className:zt.cancelBtn,onClick:()=>p(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:zt.saveBtn,onClick:w,disabled:m||!f.name,children:m?`…`:`Save`})]})]})})]})}var V={root:`_root_1hm4q_2`,topbar:`_topbar_1hm4q_11`,topbarLeft:`_topbarLeft_1hm4q_20`,topbarTitle:`_topbarTitle_1hm4q_21`,topbarSub:`_topbarSub_1hm4q_22`,topbarActions:`_topbarActions_1hm4q_23`,runBtn:`_runBtn_1hm4q_25`,runBtnActive:`_runBtnActive_1hm4q_32`,logBtn:`_logBtn_1hm4q_34`,newWfBtn:`_newWfBtn_1hm4q_41`,body:`_body_1hm4q_50`,sidebar:`_sidebar_1hm4q_53`,sidebarTitle:`_sidebarTitle_1hm4q_61`,sidebarEmpty:`_sidebarEmpty_1hm4q_65`,wfItem:`_wfItem_1hm4q_67`,wfItemActive:`_wfItemActive_1hm4q_78`,wfItemRow:`_wfItemRow_1hm4q_79`,wfItemName:`_wfItemName_1hm4q_80`,wfItemMeta:`_wfItemMeta_1hm4q_81`,wfOn:`_wfOn_1hm4q_82`,wfOff:`_wfOff_1hm4q_83`,wfDelBtn:`_wfDelBtn_1hm4q_84`,canvasArea:`_canvasArea_1hm4q_92`,canvasHeader:`_canvasHeader_1hm4q_94`,wfNameInput:`_wfNameInput_1hm4q_99`,canvasHint:`_canvasHint_1hm4q_106`,portHint:`_portHint_1hm4q_107`,connectHint:`_connectHint_1hm4q_108`,cancelConnectBtn:`_cancelConnectBtn_1hm4q_109`,canvas:`_canvas_1hm4q_92`,canvasConnecting:`_canvasConnecting_1hm4q_122`,canvasSvg:`_canvasSvg_1hm4q_124`,canvasNode:`_canvasNode_1hm4q_134`,canvasNodeSelected:`_canvasNodeSelected_1hm4q_152`,canvasNodeConnecting:`_canvasNodeConnecting_1hm4q_153`,nodeIcon:`_nodeIcon_1hm4q_155`,nodeLabel:`_nodeLabel_1hm4q_156`,nodeConfigPreview:`_nodeConfigPreview_1hm4q_157`,nodeDelBtn:`_nodeDelBtn_1hm4q_159`,portOut:`_portOut_1hm4q_171`,portActive:`_portActive_1hm4q_182`,portIn:`_portIn_1hm4q_184`,pulse:`_pulse_1hm4q_1`,canvasDrop:`_canvasDrop_1hm4q_195`,canvasEmpty:`_canvasEmpty_1hm4q_203`,canvasEmptyIcon:`_canvasEmptyIcon_1hm4q_208`,canvasEmptyTitle:`_canvasEmptyTitle_1hm4q_209`,canvasEmptyDesc:`_canvasEmptyDesc_1hm4q_210`,logPanel:`_logPanel_1hm4q_213`,logHeader:`_logHeader_1hm4q_220`,logTime:`_logTime_1hm4q_226`,logClose:`_logClose_1hm4q_227`,logEmpty:`_logEmpty_1hm4q_228`,logStep:`_logStep_1hm4q_229`,logStepError:`_logStepError_1hm4q_230`,logStepHeader:`_logStepHeader_1hm4q_231`,logStepIcon:`_logStepIcon_1hm4q_232`,logStepLabel:`_logStepLabel_1hm4q_233`,logStepErrBadge:`_logStepErrBadge_1hm4q_234`,logStepErr:`_logStepErr_1hm4q_230`,logStepOutput:`_logStepOutput_1hm4q_236`,rightPanel:`_rightPanel_1hm4q_241`,configPanel:`_configPanel_1hm4q_252`,configHeader:`_configHeader_1hm4q_253`,configClose:`_configClose_1hm4q_254`,configDesc:`_configDesc_1hm4q_255`,configFields:`_configFields_1hm4q_256`,configField:`_configField_1hm4q_256`,configLabel:`_configLabel_1hm4q_258`,configRequired:`_configRequired_1hm4q_259`,configInput:`_configInput_1hm4q_260`,configTextarea:`_configTextarea_1hm4q_267`,zoomControls:`_zoomControls_1hm4q_277`,configHint:`_configHint_1hm4q_303`,configDelete:`_configDelete_1hm4q_305`,palette:`_palette_1hm4q_309`,paletteTitle:`_paletteTitle_1hm4q_310`,paletteTabs:`_paletteTabs_1hm4q_311`,paletteTab:`_paletteTab_1hm4q_311`,paletteTabActive:`_paletteTabActive_1hm4q_317`,paletteNodes:`_paletteNodes_1hm4q_318`,paletteDef:`_paletteDef_1hm4q_320`,paletteDefIcon:`_paletteDefIcon_1hm4q_328`,paletteDefLabel:`_paletteDefLabel_1hm4q_329`,paletteDefDesc:`_paletteDefDesc_1hm4q_330`,paletteFooter:`_paletteFooter_1hm4q_332`,paletteGuide:`_paletteGuide_1hm4q_336`,guideTitle:`_guideTitle_1hm4q_344`,guideStep:`_guideStep_1hm4q_353`,guideNum:`_guideNum_1hm4q_361`,guideTip:`_guideTip_1hm4q_377`,guideCode:`_guideCode_1hm4q_388`},Ht=[{id:`trigger_manual`,type:`trigger`,label:`Manual`,icon:`▶`,color:`#6366f1`,description:`Run manually with optional text input.`,configFields:[{key:`input`,label:`Input text`,placeholder:`Optional initial input`}]},{id:`trigger_cron`,type:`trigger`,label:`Cron`,icon:`⏰`,color:`#fbbf24`,description:`Run on a schedule (cron expression).`,configFields:[{key:`schedule`,label:`Cron expression`,placeholder:`0 8 * * *`,required:!0}]},{id:`trigger_email`,type:`trigger`,label:`New Email`,icon:`📧`,color:`#38bdf8`,description:`Trigger when a new email arrives matching a filter.`,configFields:[{key:`filter`,label:`Gmail filter`,placeholder:`subject:TODO is:unread`}]},{id:`trigger_webhook`,type:`trigger`,label:`Webhook`,icon:`🔗`,color:`#a5b4fc`,description:`Trigger via HTTP POST/GET/PUT/DELETE. URL: http://localhost:3847/api/webhooks/<slug>`,configFields:[{key:`slug`,label:`Slug (URL path)`,placeholder:`my-trigger`,required:!0}]},{id:`action_email`,type:`action`,label:`Send Email`,icon:`✉`,color:`#38bdf8`,description:`Send email via Gmail or IMAP.`,configFields:[{key:`to`,label:`To`,placeholder:`email@example.com`,required:!0},{key:`subject`,label:`Subject`,placeholder:`Subject or {{output}}`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`action_slack`,type:`action`,label:`Slack Message`,icon:`💬`,color:`#818cf8`,description:`Post a message to a Slack channel.`,configFields:[{key:`channel`,label:`Channel`,placeholder:`#general`,required:!0},{key:`text`,label:`Text`,placeholder:`{{output}}`}]},{id:`action_calendar`,type:`action`,label:`Create Event`,icon:`📅`,color:`#4ade80`,description:`Create a Google Calendar event.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`date`,label:`Date (YYYY-MM-DD)`,placeholder:`2025-01-15`},{key:`time`,label:`Time (HH:MM)`,placeholder:`09:00`}]},{id:`action_task`,type:`action`,label:`Create Task`,icon:`✅`,color:`#fbbf24`,description:`Add a task to your task list.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`priority`,label:`Priority`,placeholder:`medium`}]},{id:`action_drive`,type:`action`,label:`Save to Drive`,icon:`💾`,color:`#a78bfa`,description:`Save a text file to Google Drive.`,configFields:[{key:`name`,label:`Filename`,placeholder:`output.txt`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_notion`,type:`action`,label:`Notion Page`,icon:`📋`,color:`#e4e4e7`,description:`Create or update a Notion page.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_github`,type:`action`,label:`GitHub Issue`,icon:`🐙`,color:`#6ee7b7`,description:`Create a GitHub issue.`,configFields:[{key:`repo`,label:`Repo (owner/name)`,placeholder:`user/repo`,required:!0},{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`body`,label:`Body`,placeholder:``}]},{id:`action_webhook`,type:`action`,label:`HTTP Request`,icon:`🌐`,color:`#38bdf8`,description:`Make an HTTP request.`,configFields:[{key:`url`,label:`URL`,placeholder:`https://…`,required:!0},{key:`method`,label:`Method`,placeholder:`POST`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`ai_agent`,type:`ai`,label:`Run Agent`,icon:`🤖`,color:`#818cf8`,description:`Run any of the 38 NHA specialist agents.`,configFields:[{key:`agent`,label:`Agent name`,placeholder:`herald, saber, forge…`,required:!0},{key:`prompt`,label:`Prompt`,placeholder:`Summarize this: {{output}}`,required:!0}]},{id:`ai_summarize`,type:`ai`,label:`Summarize`,icon:`📝`,color:`#a5b4fc`,description:`Summarize text with AI (free via Liara).`,configFields:[{key:`prompt`,label:`Prompt`,placeholder:`Summarize: {{output}}`}]},{id:`ai_classify`,type:`ai`,label:`Classify`,icon:`🏷`,color:`#a5b4fc`,description:`Classify content into categories.`,configFields:[{key:`categories`,label:`Categories (comma-separated)`,placeholder:`urgent, normal, spam`},{key:`prompt`,label:`Prompt`,placeholder:`Classify this email: {{output}}`}]},{id:`ai_extract`,type:`ai`,label:`Extract Data`,icon:`🔍`,color:`#a5b4fc`,description:`Extract structured data from text.`,configFields:[{key:`prompt`,label:`What to extract`,placeholder:`Extract name, email, date from: {{output}}`}]},{id:`ai_translate`,type:`ai`,label:`Translate`,icon:`🌍`,color:`#a5b4fc`,description:`Translate text to another language.`,configFields:[{key:`lang`,label:`Target language`,placeholder:`Italian`,required:!0},{key:`prompt`,label:`Text`,placeholder:`{{output}}`}]},{id:`ai_code`,type:`ai`,label:`Code (JS)`,icon:`💻`,color:`#818cf8`,description:"Execute JavaScript code. Access previous output via `input` variable. Return a value.",configFields:[{key:`code`,label:`JavaScript code`,placeholder:`const data = JSON.parse(input);
653
+ </body></html>`,m=new Blob([p],{type:`text/html`}),h=URL.createObjectURL(m),g=document.createElement(`a`);g.href=h,g.download=`nha-report-${Date.now()}.html`,g.click(),URL.revokeObjectURL(h);let _=window.open(``,`_blank`,`width=1100,height=800`);_&&(_.document.open(),_.document.write(p),_.document.close(),_.onload=()=>setTimeout(()=>{_.focus(),_.print()},600))},N=t=>{let n=`**Studio Workflow Result**\n\nTask: ${t.task}\n\nAgents: ${t.nodes.map(e=>e.label).join(` → `)}\n\n---\n\n${t.result}`;try{sessionStorage.setItem(`nha_studio_import`,n)}catch{}e(`chat`)},Ce=()=>{if(!u){r(``),a([]),s([]),l(``),S(``),de.current=``,w(null),j.current=null,T(!1),b({in:0,out:0}),v(null),re(!1);try{sessionStorage.removeItem(dt)}catch{}}},we=i.some(e=>e.output||e.status===`running`);return(0,k.jsxs)(`div`,{className:P.root,children:[(0,k.jsxs)(`div`,{className:P.header,children:[(0,k.jsxs)(`div`,{className:P.headerLeft,children:[(0,k.jsx)(`div`,{className:P.title,children:`Studio`}),(0,k.jsx)(`div`,{className:P.subtitle,children:`Multi-agent orchestration · Council deliberation · Geth Consensus`})]}),(0,k.jsxs)(`div`,{className:P.headerActions,children:[y.in+y.out>0&&(0,k.jsxs)(`div`,{className:P.tokenBar,children:[(0,k.jsxs)(`span`,{className:P.tokIn,children:[`↑ `,y.in.toLocaleString()]}),(0,k.jsx)(`span`,{className:P.tokDim,children:` in `}),(0,k.jsxs)(`span`,{className:P.tokOut,children:[`↓ `,y.out.toLocaleString()]}),(0,k.jsx)(`span`,{className:P.tokDim,children:` out`})]}),(0,k.jsxs)(`div`,{style:{position:`relative`},ref:fe,children:[(0,k.jsxs)(`button`,{className:P.sessionsBtn,onClick:()=>h(e=>!e),children:[`Sessions (`,f.length,`)`]}),m&&(0,k.jsx)(`div`,{className:P.sessionsDrawer,children:f.length===0?(0,k.jsx)(`div`,{className:P.noSessions,children:`No saved sessions yet.`}):(0,k.jsxs)(k.Fragment,{children:[f.map(e=>(0,k.jsxs)(`div`,{className:P.sessionItem,children:[(0,k.jsxs)(`div`,{className:P.sessionInfo,onClick:()=>ve(e),children:[(0,k.jsx)(`div`,{className:P.sessionTask,children:e.task.slice(0,80)}),(0,k.jsxs)(`div`,{className:P.sessionMeta,children:[e.ts.slice(0,16),` · `,e.nodes.length,` agents`,e.council?.phase===`done`?` · 🏛️ Council`:``]})]}),(0,k.jsxs)(`div`,{className:P.sessionBtns,children:[(0,k.jsx)(`button`,{className:P.importBtn,onClick:()=>N(e),children:`→ Chat`}),(0,k.jsx)(`button`,{className:P.delSessionBtn,onClick:()=>ye(e.id),children:`✕`})]})]},e.id)),(0,k.jsx)(`div`,{className:P.sessionsFooter,children:(0,k.jsx)(`button`,{className:P.clearAllSessionsBtn,onClick:be,children:`Clear All`})})]})})]}),x&&(0,k.jsx)(`button`,{className:P.canvasToggleBtn,onClick:()=>{re(!0),O(`canvas`)},children:`📊 Panel`}),c&&(0,k.jsx)(`button`,{className:P.pdfBtn,onClick:xe,children:`⬇ PDF / HTML`}),(i.length>0||c||o.length>0)&&!u&&(0,k.jsx)(`button`,{className:P.clearBtn,onClick:Ce,title:`Clear all — start fresh`,children:`✕ Clear`})]})]}),(0,k.jsxs)(`div`,{className:P.inputArea,children:[(0,k.jsxs)(`div`,{className:P.inputRow,children:[(0,k.jsx)(`textarea`,{className:P.taskInput,value:n,onChange:e=>r(e.target.value),placeholder:`Describe your task… e.g. Analyze my emails and create a priority action plan`,rows:4,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),he())}}),(0,k.jsxs)(`div`,{className:P.inputControls,children:[u?(0,k.jsx)(`button`,{className:P.stopBtn,onClick:ge,children:`■ Stop`}):(0,k.jsx)(`button`,{className:P.runBtn,onClick:he,disabled:!n.trim(),children:`Run ▶`}),(0,k.jsxs)(`label`,{className:P.attachBtn,title:`Attach PDF or image`,children:[`📎`,(0,k.jsx)(`input`,{type:`file`,accept:`.pdf,.png,.jpg,.jpeg,.gif,.webp`,style:{display:`none`},onChange:e=>me(e.target.files?.[0])})]})]})]}),g&&(0,k.jsxs)(`div`,{className:P.attachBadge,children:[`📎 `,g.name,(0,k.jsx)(`button`,{className:P.clearAttach,onClick:()=>v(null),children:`✕`})]}),!u&&i.length===0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:P.examples,children:ke.map((e,t)=>(0,k.jsx)(`button`,{className:P.exampleBtn,onClick:()=>r(e),children:e},t))}),(0,k.jsxs)(`div`,{className:P.financeSection,children:[(0,k.jsx)(`div`,{className:P.financeSectionTitle,children:`📈 Finance & Trading Workflows`}),(0,k.jsx)(`div`,{className:P.financePresets,children:De.map((e,t)=>(0,k.jsx)(`button`,{className:P.financeBtn,onClick:()=>{r(e.task),a(e.agents)},children:e.label},t))})]})]})]}),i.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:P.officeSceneWrap,style:{overflow:`hidden`,position:`relative`,height:`180px`},children:(0,k.jsxs)(`div`,{style:{display:`flex`,width:`200%`,height:`100%`,transition:`transform 700ms cubic-bezier(0.22, 1, 0.36, 1)`,transform:C&&C.phase!==`idle`&&C.phase!==`skipped`?`translateX(-50%)`:`translateX(0)`},children:[(0,k.jsx)(`div`,{style:{width:`50%`,height:`100%`,flexShrink:0},children:(0,k.jsx)(Qe,{nodes:i,running:u})}),(0,k.jsx)(`div`,{style:{width:`50%`,height:`100%`,flexShrink:0},children:(0,k.jsx)(rt,{agents:ne.length>0?ne:i,council:C})})]})}),(0,k.jsxs)(`div`,{className:`${P.pipelineWrap} ${u?P.pipelineRunning:``}`,children:[(0,k.jsxs)(`div`,{className:P.pipelineTitle,children:[`Agent Pipeline`,u&&(0,k.jsx)(`span`,{className:P.pipelineLiveTag,children:`● LIVE`})]}),(0,k.jsx)(`div`,{className:P.pipelineNodes,children:i.map((e,t)=>(0,k.jsxs)(`div`,{className:P.pipelineStep,children:[(0,k.jsxs)(`div`,{className:`${P.agentChip} ${P[`chip_${e.status}`]}`,children:[(0,k.jsx)(`span`,{className:P.chipIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.chipLabel,children:e.label}),e.status===`running`&&(0,k.jsxs)(`span`,{className:P.chipDots,children:[(0,k.jsx)(`span`,{className:P.dot1,children:`.`}),(0,k.jsx)(`span`,{className:P.dot2,children:`.`}),(0,k.jsx)(`span`,{className:P.dot3,children:`.`})]}),e.status===`done`&&(0,k.jsx)(`span`,{className:P.chipCheck,children:`✓`}),e.status===`error`&&(0,k.jsx)(`span`,{className:P.chipErr,children:`✗`})]}),t<i.length-1&&(0,k.jsx)(`div`,{className:`${P.arrow} ${u?P.arrowActive:``}`,children:`→`})]},t))}),i.some(e=>e.reason)&&(0,k.jsx)(`div`,{className:P.reasonRow,children:i.map((e,t)=>e.reason?(0,k.jsxs)(`div`,{className:P.reasonChip,title:e.reason,children:[(0,k.jsx)(`span`,{className:P.reasonIcon,children:e.icon}),(0,k.jsxs)(`span`,{className:P.reasonText,children:[e.reason.slice(0,60),e.reason.length>60?`…`:``]})]},t):null)})]})]}),(0,k.jsxs)(`div`,{className:P.body,ref:ue,children:[(o.length>0||we)&&(0,k.jsxs)(`div`,{className:P.twoCol,children:[(0,k.jsxs)(`div`,{className:P.logPanel,children:[(0,k.jsx)(`div`,{className:P.panelTitle,children:`Live Log`}),(0,k.jsx)(`div`,{className:P.logBody,ref:le,children:o.map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.logEntry} ${P[`log_${e.type}`]}`,children:[(0,k.jsx)(`span`,{className:P.logTime,children:e.time}),(0,k.jsx)(`span`,{className:P.logIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.logAgent,children:e.agent}),(0,k.jsx)(`span`,{className:P.logText,children:e.text})]},t))})]}),(0,k.jsx)(`div`,{className:P.liveOutputPanel,children:i.filter(e=>e.output||e.status===`running`).map((e,t)=>(0,k.jsxs)(`div`,{className:`${P.liveBlock} ${e.status===`running`?P.liveBlockActive:``} ${e.status===`done`&&e.output?P.liveBlockClickable:``}`,onClick:()=>e.status===`done`&&e.output?se(e):void 0,children:[(0,k.jsxs)(`div`,{className:P.liveBlockHeader,children:[(0,k.jsx)(`span`,{className:P.liveBlockIcon,children:e.icon}),(0,k.jsx)(`span`,{className:P.liveBlockLabel,children:e.label}),e.reason&&(0,k.jsx)(`span`,{className:P.liveBlockReason,title:e.reason,children:`ℹ`}),(0,k.jsx)(`span`,{className:`${P.outputStatus} ${P[`status_${e.status}`]}`,children:e.status}),e.status===`done`&&e.output&&(0,k.jsx)(`span`,{className:P.expandHint,children:`↗ espandi`})]}),e.status===`running`&&(0,k.jsxs)(`div`,{className:P.liveBlockWorking,children:[(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingDot}),(0,k.jsx)(`span`,{className:P.workingLabel,children:e.statusLine??`elaborazione in corso`})]}),(0,k.jsx)(`div`,{className:`${P.liveBlockBody} ${e.status===`done`&&e.output?P.liveBlockBodyClamped:``}`,dangerouslySetInnerHTML:{__html:Se(e.output)+(e.status===`running`&&e.output?`<span class="studio-cursor"></span>`:``)}})]},t))})]}),ee&&(0,k.jsxs)(`div`,{className:P.parliamentPrompt,children:[(0,k.jsx)(`div`,{className:P.parliamentPromptIcon,children:`🏛️`}),(0,k.jsxs)(`div`,{className:P.parliamentPromptContent,children:[(0,k.jsx)(`div`,{className:P.parliamentPromptTitle,children:`Attivare il Consiglio?`}),(0,k.jsxs)(`div`,{className:P.parliamentPromptDesc,children:[ne.length,` agenti (`,ne.map(e=>e.label).join(`, `),`) hanno prodotto output. Il Geth Consensus eseguirà cross-reading, refinement e mediazione HERALD per raggiungere un consenso collettivo.`]}),(0,k.jsxs)(`div`,{className:P.parliamentPromptMeta,children:[`Complessità: `,ne.length<=3?`⚡ Rapido (~30s)`:ne.length<=5?`⏱ Medio (~60s)`:`🕐 Lungo (~2min)`,`\xA0· Consigliato per task analitici complessi`]})]}),(0,k.jsxs)(`div`,{className:P.parliamentPromptBtns,children:[(0,k.jsx)(`button`,{className:P.parliamentActivateBtn,onClick:_e,children:`🏛️ Attiva`}),(0,k.jsx)(`button`,{className:P.parliamentSkipBtn,onClick:()=>T(!1),children:`Salta`})]})]}),C&&!ee&&(0,k.jsx)(`div`,{className:P.councilWrapper,children:(0,k.jsx)(vt,{council:C})}),c&&!u&&(0,k.jsxs)(`details`,{className:P.resultAccordion,open:i.length<=1,children:[(0,k.jsxs)(`summary`,{className:P.resultAccordionSummary,children:[`Full Combined Report (`,i.filter(e=>e.output&&e.output!==`(no output)`).length,` agents)`]}),(0,k.jsx)(`div`,{className:P.resultAccordionBody,dangerouslySetInnerHTML:{__html:Se(c)}})]})]}),D&&(0,k.jsxs)(`div`,{className:P.canvasPanel,children:[(0,k.jsxs)(`div`,{className:P.canvasPanelHeader,children:[(0,k.jsxs)(`div`,{className:P.panelTabs,children:[(0,k.jsx)(`button`,{className:`${P.panelTabBtn} ${ie===`canvas`?P.panelTabActive:``}`,onClick:()=>O(`canvas`),children:`📊 Canvas`}),(0,k.jsx)(`button`,{className:`${P.panelTabBtn} ${ie===`browser`?P.panelTabActive:``}`,onClick:()=>O(`browser`),children:`🌐 Browser`})]}),(0,k.jsxs)(`div`,{className:P.canvasPanelActions,children:[ie===`canvas`&&x&&(0,k.jsx)(`button`,{className:P.canvasPanelBtn,onClick:()=>{let e=new Blob([x],{type:`text/html`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`nha-canvas-report.html`,n.click(),URL.revokeObjectURL(t)},children:`⬇ HTML`}),(0,k.jsx)(`button`,{className:P.canvasPanelClose,onClick:()=>re(!1),children:`✕`})]})]}),ie===`canvas`?x?(0,k.jsx)(`iframe`,{className:P.canvasFrame,srcDoc:x,sandbox:`allow-scripts`,title:`Canvas Report`}):(0,k.jsx)(`div`,{className:P.panelEmpty,children:`No canvas report yet. Run a workflow first.`}):(0,k.jsxs)(`div`,{className:P.browserPanel,children:[(0,k.jsxs)(`div`,{className:P.browserBar,children:[(0,k.jsx)(`input`,{className:P.browserInput,value:ae,onChange:e=>A(e.target.value),placeholder:`https://…`,onKeyDown:e=>{e.key===`Enter`&&A(ae)}}),(0,k.jsx)(`button`,{className:P.browserGo,onClick:()=>A(ae),children:`Go`})]}),ae?(0,k.jsx)(`iframe`,{className:P.canvasFrame,src:ae,sandbox:`allow-scripts allow-same-origin allow-forms`,title:`Browser`}):(0,k.jsx)(`div`,{className:P.panelEmpty,children:`Enter a URL above to browse`})]})]}),oe&&(0,k.jsx)(`div`,{className:P.blockModalOverlay,onClick:()=>se(null),children:(0,k.jsxs)(`div`,{className:P.blockModal,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:P.blockModalHeader,children:[(0,k.jsx)(`span`,{className:P.liveBlockIcon,children:oe.icon}),(0,k.jsx)(`span`,{className:P.blockModalTitle,children:oe.label}),(0,k.jsx)(`button`,{className:P.blockModalClose,onClick:()=>se(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:`${P.liveBlockBody} ${P.blockModalBody}`,dangerouslySetInnerHTML:{__html:Se(oe.output)}})]})})]})}var R={root:`_root_13wnr_2`,hero:`_hero_13wnr_12`,heroLeft:`_heroLeft_13wnr_21`,heroDate:`_heroDate_13wnr_22`,heroTitle:`_heroTitle_13wnr_23`,heroVer:`_heroVer_13wnr_24`,heroUptime:`_heroUptime_13wnr_25`,heroWeather:`_heroWeather_13wnr_27`,wIcon:`_wIcon_13wnr_35`,wInfo:`_wInfo_13wnr_36`,wTemp:`_wTemp_13wnr_37`,wCity:`_wCity_13wnr_38`,wDesc:`_wDesc_13wnr_39`,wEmpty:`_wEmpty_13wnr_40`,kpiRow:`_kpiRow_13wnr_43`,kpi:`_kpi_13wnr_43`,kpiNum:`_kpiNum_13wnr_55`,kpiLbl:`_kpiLbl_13wnr_56`,kpiBar:`_kpiBar_13wnr_57`,kpiFill:`_kpiFill_13wnr_58`,liveGrid:`_liveGrid_13wnr_61`,liveCard:`_liveCard_13wnr_67`,liveHdr:`_liveHdr_13wnr_71`,liveMore:`_liveMore_13wnr_79`,liveRow:`_liveRow_13wnr_81`,liveUnread:`_liveUnread_13wnr_89`,liveTitle:`_liveTitle_13wnr_89`,liveTime:`_liveTime_13wnr_91`,liveBody:`_liveBody_13wnr_95`,liveSub:`_liveSub_13wnr_97`,prio:`_prio_13wnr_99`,prio_high:`_prio_high_13wnr_103`,prio_medium:`_prio_medium_13wnr_104`,prio_low:`_prio_low_13wnr_105`,launcher:`_launcher_13wnr_108`,launchGroup:`_launchGroup_13wnr_115`,launchGroupLabel:`_launchGroupLabel_13wnr_117`,launchTiles:`_launchTiles_13wnr_123`,tile:`_tile_13wnr_129`,tileIcon:`_tileIcon_13wnr_143`,tileLabel:`_tileLabel_13wnr_144`},bt=[{view:`chat`,icon:`💬`,label:`Chat`,color:`#38bdf8`,group:`Panoramica`},{view:`plan`,icon:`🗓️`,label:`Daily Plan`,color:`#818cf8`,group:`Panoramica`},{view:`tasks`,icon:`✅`,label:`Tasks`,color:`#4ade80`,group:`Panoramica`},{view:`email`,icon:`📧`,label:`Email`,color:`#f87171`,group:`Google`},{view:`calendar`,icon:`📅`,label:`Calendar`,color:`#fb923c`,group:`Google`},{view:`drive`,icon:`💾`,label:`Drive`,color:`#facc15`,group:`Google`},{view:`contacts`,icon:`👤`,label:`Contacts`,color:`#34d399`,group:`Google`},{view:`notes`,icon:`📝`,label:`Notes`,color:`#a78bfa`,group:`Google`},{view:`onedrive`,icon:`☁️`,label:`OneDrive`,color:`#60a5fa`,group:`Microsoft`},{view:`mstodo`,icon:`📋`,label:`MS Todo`,color:`#38bdf8`,group:`Microsoft`},{view:`github`,icon:`🐙`,label:`GitHub`,color:`#e2e8f0`,group:`Tools`},{view:`notion`,icon:`📓`,label:`Notion`,color:`#94a3b8`,group:`Tools`},{view:`slack`,icon:`💼`,label:`Slack`,color:`#e879f9`,group:`Tools`},{view:`maps`,icon:`🗺️`,label:`Maps`,color:`#2dd4bf`,group:`Tools`},{view:`reminders`,icon:`🔔`,label:`Reminders`,color:`#fbbf24`,group:`Tools`},{view:`birthdays`,icon:`🎂`,label:`Birthdays`,color:`#f472b6`,group:`Tools`},{view:`cron`,icon:`⏰`,label:`Cron`,color:`#fb923c`,group:`Tools`},{view:`screen`,icon:`🖥️`,label:`Screen`,color:`#64748b`,group:`Tools`},{view:`agents`,icon:`🤖`,label:`Agents`,color:`#4ade80`,group:`AI`},{view:`studio`,icon:`🎭`,label:`Studio`,color:`#a78bfa`,group:`AI`},{view:`webcraft`,icon:`🔨`,label:`WebCraft`,color:`#f59e0b`,group:`AI`},{view:`collab`,icon:`🏛️`,label:`Alexandria`,color:`#38bdf8`,group:`AI`},{view:`connectors`,icon:`🔗`,label:`AWF - AutoWorkFlow`,color:`#94a3b8`,group:`Config`},{view:`settings`,icon:`⚙️`,label:`Settings`,color:`#64748b`,group:`Config`}],xt={Sunny:`☀️`,Clear:`☀️`,"Partly Cloudy":`⛅`,"Partly cloudy":`⛅`,Cloudy:`☁️`,Overcast:`☁️`,"Light rain":`🌧️`,Rain:`🌧️`,Drizzle:`🌧️`,"Moderate rain":`🌧️`,"Heavy rain":`🌧️`,Snow:`❄️`,"Light snow":`❄️`,Fog:`🌫️`,Mist:`🌫️`,Thunder:`⚡`,"Thundery outbreaks":`⚡`};function St(e){try{return new Date(e).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,hour12:!1})}catch{return e}}function Ct(e){try{return new Date(e).toLocaleDateString(`en`,{month:`short`,day:`numeric`})}catch{return e}}function wt(){let e=te(e=>e.setView),t=j(),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(new Date);(0,_.useEffect)(()=>{let e=setInterval(()=>p(new Date),6e4);return()=>clearInterval(e)},[]),(0,_.useEffect)(()=>{let e=!0,t=t=>n=>{e&&n!=null&&t(n)};E(`/api/tasks`).then(e=>t(r)(e?.tasks??[])),E(`/api/emails?page=0&pageSize=8`).then(e=>t(a)(e?.emails??[])),E(`/api/calendar`).then(e=>t(s)(e?.events??[])),E(`/api/status`).then(t(l));let n=localStorage.getItem(`nha_weather_location`),i=t=>E(`/api/weather?location=${encodeURIComponent(t)}`).then(t=>{e&&t&&t.city&&d(t)});return n?i(n):navigator.geolocation?.getCurrentPosition(e=>i(`${e.coords.latitude.toFixed(4)},${e.coords.longitude.toFixed(4)}`),()=>{},{timeout:6e3}),()=>{e=!1}},[]);let m=n.filter(e=>e.status!==`done`),h=n.filter(e=>e.status===`done`),g=n.length>0?Math.round(h.length/n.length*100):0,v=i.filter(e=>e.isUnread).length,y=f.toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`}),b=[...new Set(bt.map(e=>e.group))];return(0,k.jsxs)(`div`,{className:R.root,children:[(0,k.jsxs)(`div`,{className:R.hero,children:[(0,k.jsxs)(`div`,{className:R.heroLeft,children:[(0,k.jsx)(`div`,{className:R.heroDate,children:y}),(0,k.jsx)(`div`,{className:R.heroTitle,children:c?(0,k.jsxs)(k.Fragment,{children:[`NHA `,(0,k.jsxs)(`span`,{className:R.heroVer,children:[`v`,c.version]}),` · `,(0,k.jsxs)(`span`,{className:R.heroUptime,children:[Math.floor(c.uptime/60),`m uptime`]})]}):`NotHumanAllowed`})]}),(0,k.jsx)(`div`,{className:R.heroWeather,onClick:()=>{let e=prompt(`City or lat,lon:`);e&&(localStorage.setItem(`nha_weather_location`,e),d(null),E(`/api/weather?location=${encodeURIComponent(e)}`).then(e=>{e&&e.city&&d(e)}))},children:u?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`span`,{className:R.wIcon,children:xt[u.desc]??u.icon??`🌡️`}),(0,k.jsxs)(`div`,{className:R.wInfo,children:[(0,k.jsxs)(`span`,{className:R.wTemp,children:[u.tempC,`°C`]}),(0,k.jsxs)(`span`,{className:R.wCity,children:[u.city.split(`,`)[0],u.country?`, ${u.country.slice(0,2).toUpperCase()}`:``]}),(0,k.jsxs)(`span`,{className:R.wDesc,children:[u.desc,` · 💧`,u.humidity,`%`]})]})]}):(0,k.jsxs)(`span`,{className:R.wEmpty,children:[`🌡️ `,t(`dashboard.weather`)]})})]}),(0,k.jsxs)(`div`,{className:R.kpiRow,children:[(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:m.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Pending tasks`}),n.length>0&&(0,k.jsx)(`div`,{className:R.kpiBar,children:(0,k.jsx)(`div`,{className:R.kpiFill,style:{width:`${g}%`}})})]}),(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:v>0?v:i.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:v>0?`Unread emails`:`Emails`})]}),(0,k.jsxs)(`div`,{className:R.kpi,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.kpiNum,children:o.length}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Today's events`})]}),u&&(0,k.jsxs)(`div`,{className:R.kpi,children:[(0,k.jsxs)(`span`,{className:R.kpiNum,children:[u.feelsC,`°`]}),(0,k.jsx)(`span`,{className:R.kpiLbl,children:`Feels like`})]})]}),(0,k.jsxs)(`div`,{className:R.liveGrid,children:[o.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📅 `,t(`calendar.title`)]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),o.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:R.liveRow,onClick:()=>e(`calendar`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.liveTime,children:t.isAllDay?`All day`:St(t.start)}),(0,k.jsxs)(`div`,{className:R.liveBody,children:[(0,k.jsx)(`span`,{className:R.liveTitle,children:t.summary}),t.location&&(0,k.jsx)(`span`,{className:R.liveSub,children:t.location})]})]},n))]}),i.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`📧 `,t(`email.inbox`)]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),i.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:`${R.liveRow} ${t.isUnread?R.liveUnread:``}`,onClick:()=>e(`email`),role:`button`,children:[(0,k.jsx)(`span`,{className:R.liveTime,children:Ct(t.date)}),(0,k.jsxs)(`div`,{className:R.liveBody,children:[(0,k.jsx)(`span`,{className:R.liveTitle,children:t.subject}),(0,k.jsx)(`span`,{className:R.liveSub,children:t.from})]})]},n))]}),m.length>0&&(0,k.jsxs)(`div`,{className:R.liveCard,children:[(0,k.jsxs)(`div`,{className:R.liveHdr,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsxs)(`span`,{children:[`✅ `,t(`tasks.title`),` · `,h.length,`/`,n.length,` (`,g,`%)`]}),(0,k.jsx)(`span`,{className:R.liveMore,children:`→`})]}),m.slice(0,5).map((t,n)=>(0,k.jsxs)(`div`,{className:R.liveRow,onClick:()=>e(`tasks`),role:`button`,children:[(0,k.jsx)(`span`,{className:`${R.prio} ${R[`prio_`+t.priority]}`,children:t.priority[0].toUpperCase()}),(0,k.jsx)(`div`,{className:R.liveBody,children:(0,k.jsx)(`span`,{className:R.liveTitle,children:t.description})})]},n))]})]}),(0,k.jsx)(`div`,{className:R.launcher,children:b.map(t=>(0,k.jsxs)(`div`,{className:R.launchGroup,children:[(0,k.jsx)(`div`,{className:R.launchGroupLabel,children:t}),(0,k.jsx)(`div`,{className:R.launchTiles,children:bt.filter(e=>e.group===t).map(t=>(0,k.jsxs)(`button`,{className:R.tile,onClick:()=>e(t.view),style:{"--tc":t.color},children:[(0,k.jsx)(`span`,{className:R.tileIcon,children:t.icon}),(0,k.jsx)(`span`,{className:R.tileLabel,children:t.label})]},t.view))})]},t))})]})}var Tt={root:`_root_1pldx_1`,loading:`_loading_1pldx_2`,bar:`_bar_1pldx_4`,input:`_input_1pldx_5`,select:`_select_1pldx_6`,addBtn:`_addBtn_1pldx_7`,actions:`_actions_1pldx_10`,clearDone:`_clearDone_1pldx_11`,clearAll:`_clearAll_1pldx_12`,stats:`_stats_1pldx_14`,progress:`_progress_1pldx_15`,progressBar:`_progressBar_1pldx_16`,empty:`_empty_1pldx_18`,task:`_task_1pldx_20`,taskDone:`_taskDone_1pldx_22`,check:`_check_1pldx_23`,checkDone:`_checkDone_1pldx_25`,desc:`_desc_1pldx_26`,del:`_del_1pldx_27`,badge:`_badge_1pldx_30`,badge_high:`_badge_high_1pldx_31`,badge_medium:`_badge_medium_1pldx_32`,badge_low:`_badge_low_1pldx_33`,doneLabel:`_doneLabel_1pldx_35`};function Et(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`medium`),[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=()=>E(`/api/tasks`).then(e=>{n(e?.tasks??[]),i(!1)});(0,_.useEffect)(()=>{f()},[]);let p=async()=>{a.trim()&&(u(!0),await D(`/api/tasks`,{description:a.trim(),priority:s}),o(``),u(!1),f(),d.current?.focus())},m=e=>D(`/api/tasks/${e}/done`,{},`PATCH`).then(f),h=e=>D(`/api/tasks/${e}/delete`,{}).then(f),g=()=>D(`/api/tasks/clear`,{filter:`done`}).then(f),v=()=>{confirm(e(`tasks.deleteTask`))&&D(`/api/tasks/clear`,{filter:`all`}).then(f)},y=t.filter(e=>e.status!==`done`),b=t.filter(e=>e.status===`done`);return r?(0,k.jsxs)(`div`,{className:Tt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:Tt.root,children:[(0,k.jsxs)(`div`,{className:Tt.bar,children:[(0,k.jsx)(`input`,{ref:d,className:Tt.input,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>e.key===`Enter`&&p(),placeholder:e(`tasks.newTask`)}),(0,k.jsxs)(`select`,{className:Tt.select,value:s,onChange:e=>c(e.target.value),children:[(0,k.jsx)(`option`,{value:`high`,children:`High`}),(0,k.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,k.jsx)(`option`,{value:`low`,children:`Low`})]}),(0,k.jsx)(`button`,{className:Tt.addBtn,onClick:p,disabled:l||!a.trim(),children:l?`…`:`+ `+e(`common.add`)})]}),t.length>0&&(0,k.jsxs)(`div`,{className:Tt.actions,children:[(0,k.jsx)(`button`,{className:Tt.clearDone,onClick:g,children:`Clear completed`}),(0,k.jsx)(`button`,{className:Tt.clearAll,onClick:v,children:`Clear all`})]}),t.length>0&&(0,k.jsxs)(`div`,{className:Tt.stats,children:[y.length,` pending · `,b.length,` done`,t.length>0&&(0,k.jsx)(`span`,{className:Tt.progress,children:(0,k.jsx)(`span`,{className:Tt.progressBar,style:{width:`${Math.round(b.length/t.length*100)}%`}})})]}),y.length===0&&b.length===0&&(0,k.jsx)(`div`,{className:Tt.empty,children:`No tasks yet. Add one above ↑`}),y.map(e=>(0,k.jsxs)(`div`,{className:Tt.task,children:[(0,k.jsx)(`span`,{className:Tt.check,onClick:()=>m(e.id)}),(0,k.jsx)(`span`,{className:Tt.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${Tt.badge} ${Tt[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:Tt.del,onClick:()=>h(e.id),children:`×`})]},e.id)),b.length>0&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:Tt.doneLabel,children:`Completed`}),b.map(e=>(0,k.jsxs)(`div`,{className:`${Tt.task} ${Tt.taskDone}`,children:[(0,k.jsx)(`span`,{className:`${Tt.check} ${Tt.checkDone}`,onClick:()=>m(e.id),children:`✓`}),(0,k.jsx)(`span`,{className:Tt.desc,onClick:()=>m(e.id),children:e.description}),(0,k.jsx)(`span`,{className:`${Tt.badge} ${Tt[`badge_`+e.priority]}`,children:e.priority}),(0,k.jsx)(`span`,{className:Tt.del,onClick:()=>h(e.id),children:`×`})]},e.id))]})]})}var z={root:`_root_k5v14_1`,loading:`_loading_k5v14_2`,card:`_card_k5v14_4`,cardTitle:`_cardTitle_k5v14_5`,cardTitleRow:`_cardTitleRow_k5v14_6`,cardSub:`_cardSub_k5v14_7`,connected:`_connected_k5v14_8`,statusMsg:`_statusMsg_k5v14_9`,fields:`_fields_k5v14_11`,field:`_field_k5v14_11`,fieldLabel:`_fieldLabel_k5v14_13`,fieldInput:`_fieldInput_k5v14_14`,saveBtn:`_saveBtn_k5v14_17`,dangerBtn:`_dangerBtn_k5v14_18`,cancelBtn:`_cancelBtn_k5v14_19`,btnRow:`_btnRow_k5v14_20`,keySet:`_keySet_k5v14_22`,keySummary:`_keySummary_k5v14_23`,keySummaryIcon:`_keySummaryIcon_k5v14_24`,nhaFree:`_nhaFree_k5v14_26`,nhaFreeTitle:`_nhaFreeTitle_k5v14_27`,nhaFreeSub:`_nhaFreeSub_k5v14_28`,nhaFreeBtn:`_nhaFreeBtn_k5v14_29`,imapRow:`_imapRow_k5v14_31`,imapName:`_imapName_k5v14_32`,imapMeta:`_imapMeta_k5v14_33`,imapStatus:`_imapStatus_k5v14_34`,imapBtns:`_imapBtns_k5v14_38`,imapSyncBtn:`_imapSyncBtn_k5v14_39`,imapEditBtn:`_imapEditBtn_k5v14_40`,imapDelBtn:`_imapDelBtn_k5v14_41`,emptyImap:`_emptyImap_k5v14_42`,imapForm:`_imapForm_k5v14_44`,imapFormTitle:`_imapFormTitle_k5v14_45`,pwdNote:`_pwdNote_k5v14_46`,pwdRow:`_pwdRow_k5v14_47`,togglePwd:`_togglePwd_k5v14_48`},Dt={id:``,display_name:``,email_address:``,from_name:``,imap_host:``,imap_port:`993`,smtp_host:``,smtp_port:`587`,username:``,password:``};function Ot({id:e,label:t,placeholder:n,value:r,onChange:i,type:a=`text`}){return(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t}),(0,k.jsx)(`input`,{id:e,type:a,placeholder:n,value:r,onChange:e=>i(e.target.value),className:z.fieldInput})]})}function kt(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(``),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(``),f=()=>{E(`/api/credentials`).then(e=>t(e?.credentials??[])).catch(()=>t([]))};(0,_.useEffect)(()=>{f()},[]);let p=async()=>{if(!/^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(n)){d(`Name: lettere, cifre, _ — primo carattere non numerico`);return}if(!i.trim()){d(`Value required`);return}l(!0),d(``);try{let e=await D(`/api/credentials`,{name:n,value:i,description:o});e&&!e.ok&&e.error?d(e.error):(r(``),a(``),s(``),f())}finally{l(!1)}},m=async e=>{confirm(`Delete credential "${e}"?`)&&(await fetch(`/api/credentials/${encodeURIComponent(e)}`,{method:`DELETE`}),f())};return(0,k.jsxs)(`div`,{style:{marginTop:16,padding:16,background:`var(--bg2, rgba(15,23,42,0.4))`,border:`1px solid var(--border, rgba(148,163,184,0.18))`,borderRadius:10},children:[(0,k.jsx)(`div`,{style:{fontSize:14,fontWeight:800,marginBottom:4},children:`Credentials Vault 🔐`}),(0,k.jsxs)(`div`,{style:{fontSize:11,opacity:.7,marginBottom:10},children:[`Encrypted secrets (AES-256-GCM, machine-bound key). Reference them in workflow nodes with `,(0,k.jsx)(`code`,{children:"${cred.NAME}"}),`. The raw value never leaves your computer.`]}),e.length>0&&(0,k.jsx)(`div`,{style:{marginBottom:12,border:`1px solid rgba(148,163,184,0.15)`,borderRadius:6},children:e.map(e=>(0,k.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`6px 10px`,borderBottom:`1px solid rgba(148,163,184,0.1)`,fontSize:12},children:[(0,k.jsx)(`code`,{style:{background:`rgba(99,102,241,0.12)`,padding:`2px 6px`,borderRadius:4,color:`#a5b4fc`,fontWeight:700},children:e.name}),(0,k.jsx)(`span`,{style:{flex:1,opacity:.7},children:e.description||(0,k.jsx)(`em`,{children:`no description`})}),(0,k.jsx)(`span`,{style:{fontSize:10,opacity:.5},children:new Date(e.updatedAt).toLocaleString()}),e.hasError&&(0,k.jsx)(`span`,{style:{color:`#ef4444`,fontSize:10},children:`⚠ decrypt error`}),(0,k.jsx)(`button`,{onClick:()=>m(e.name),style:{background:`transparent`,border:`none`,cursor:`pointer`,color:`#ef4444`,fontSize:14},children:`✕`})]},e.name))}),(0,k.jsxs)(`div`,{style:{display:`grid`,gridTemplateColumns:`1fr 1fr`,gap:8},children:[(0,k.jsx)(`input`,{placeholder:`NAME (e.g. STRIPE_KEY)`,value:n,onChange:e=>r(e.target.value),style:{padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`,fontFamily:`SF Mono, monospace`}}),(0,k.jsx)(`input`,{placeholder:`Description (optional)`,value:o,onChange:e=>s(e.target.value),style:{padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`}})]}),(0,k.jsx)(`input`,{type:`password`,placeholder:`Value (encrypted at rest)`,value:i,onChange:e=>a(e.target.value),style:{width:`100%`,marginTop:6,padding:6,borderRadius:4,border:`1px solid rgba(148,163,184,0.2)`,background:`transparent`,color:`inherit`}}),u&&(0,k.jsx)(`div`,{style:{color:`#ef4444`,fontSize:11,marginTop:4},children:u}),(0,k.jsx)(`button`,{onClick:p,disabled:c,style:{marginTop:8,padding:`6px 14px`,borderRadius:4,border:`none`,background:`#6366f1`,color:`white`,fontWeight:700,cursor:`pointer`,opacity:c?.5:1},children:c?`Saving…`:`+ Add credential`})]})}function At(){let{setConfig:e}=te(),t=j(),[n,r]=(0,_.useState)({}),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)({name:``,email:``,phone:``,homeAddress:``,workAddress:``,city:``,country:``,company:``,role:``,notes:``}),[C,w]=(0,_.useState)(`nha`),[ee,T]=(0,_.useState)(``),[ne,re]=(0,_.useState)(``),[ie,O]=(0,_.useState)(``),[ae,A]=(0,_.useState)(``),[oe,se]=(0,_.useState)(``),[ce,le]=(0,_.useState)(``),[ue,de]=(0,_.useState)(``),[M,fe]=(0,_.useState)(``),[pe,me]=(0,_.useState)(!1),[he,ge]=(0,_.useState)(``),[_e,ve]=(0,_.useState)(`en`),[ye,be]=(0,_.useState)(`07:00`),[xe,Se]=(0,_.useState)(`18:00`),[N,Ce]=(0,_.useState)(`30`),[we,Te]=(0,_.useState)(`off`),[Ee,P]=(0,_.useState)(``),[De,Oe]=(0,_.useState)(``),[ke,F]=(0,_.useState)(``),[I,Ae]=(0,_.useState)(`agent`),[je,Me]=(0,_.useState)(``),[Ne,Pe]=(0,_.useState)(!0),[Fe,Ie]=(0,_.useState)(!0),[Le,Re]=(0,_.useState)(`3`),[ze,L]=(0,_.useState)(`0.30`),[Be,Ve]=(0,_.useState)(!0),[He,Ue]=(0,_.useState)(!1),[We,Ge]=(0,_.useState)(!1),[Ke,qe]=(0,_.useState)(!1),[Je,Ye]=(0,_.useState)(!1),[Xe,Ze]=(0,_.useState)(!1),[Qe,$e]=(0,_.useState)(!1),[et,tt]=(0,_.useState)(!0),[nt,rt]=(0,_.useState)(``),[it,at]=(0,_.useState)(!1),[ot,st]=(0,_.useState)(!1),[ct,lt]=(0,_.useState)(!0),[ut,dt]=(0,_.useState)(``),[ft,pt]=(0,_.useState)(``),[mt,ht]=(0,_.useState)(``),[gt,_t]=(0,_.useState)(``),[vt,yt]=(0,_.useState)(`common`),[R,bt]=(0,_.useState)(!1),[xt,St]=(0,_.useState)(``);(0,_.useEffect)(()=>{E(`/api/config`).then(t=>{r(t??{});let n=t?.profile??{};S({name:n.name??``,email:n.email??``,phone:n.phone??``,homeAddress:n.homeAddress??``,workAddress:n.workAddress??``,city:n.city??``,country:n.country??``,company:n.company??``,role:n.role??``,notes:n.notes??``}),w(t?.provider??`nha`),ge(t?.model??``),ve(t?.lang??`en`),be(t?.planTime??`07:00`),Se(t?.summaryTime??`18:00`),Ce(String(t?.meetingAlert??`30`)),Te(t?.thinking??`off`),T(``);let i=t?.responder,o=i?.telegram;F(String(o?.botName??``));let s=String(o?.personaMode??`agent`);Ae(s===`persona`||s===`persona-only`||s===`persona+role`?s:`agent`),Me(Array.isArray(o?.allowedChatIds)?o.allowedChatIds.join(`, `):``),Pe(i?.autoRoute!==!1);let c=t?.deliberation;Ie(c?.enabled!==!1),Re(String(c?.rounds??`3`)),L(String(c?.convergence??`0.30`)),Ve(c?.tribunalEnabled!==!1);let l=t?.ops?.proactive;Ue(!!l?.enabled),Ge(!!l?.emailFollowUp),qe(!!l?.meetingPrep),Ye(!!l?.patterns),Ze(!!l?.deadlines);let u=t?.voice;$e(!!u?.preferWhisper),tt(u?.speechSynthesis!==!1),rt(String(u?.language??``));let d=t?.features;at(!!d?.verbose),st(!!d?.immersive),lt(d?.knowledgeEnabled!==!1),dt(``),pt(String(t?.github?.defaultRepo??``)),ht(``),_t(``);let f=t?.microsoft;yt(String(f?.tenantId??`common`));let p=t?.plugins;bt(!!p?.autoRun),St(String(p?.directory??``)),a(!1),t&&e(t)}),Ct()},[]);let Ct=()=>E(`/api/imap/accounts`).then(e=>d(e?.accounts??[])),wt=async(e,t)=>{s(e),await D(`/api/config`,{key:e,value:t}),l(e),s(null),setTimeout(()=>l(null),2e3)},Tt=()=>wt(`profile`,x),Et=()=>{wt(`provider`,C),wt(`model`,he),wt(`thinking`,we),ee&&wt(`key`,ee),ne&&wt(`groq-key`,ne),ie&&wt(`openai-key`,ie),ae&&wt(`gemini-key`,ae),oe&&wt(`deepseek-key`,oe),ce&&wt(`grok-key`,ce),ue&&wt(`mistral-key`,ue),M&&wt(`cohere-key`,M)},At=()=>{wt(`planTime`,ye),wt(`summaryTime`,xe),wt(`meetingAlert`,Number(N))},jt=()=>{v(t(`settings.googleOpening`)),D(`/api/google/auth`,{}).then(e=>{e?.url?(window.open(e.url,`_blank`),v(t(`settings.googleOpened`))):e?.error&&v(t(`common.error`)+`: `+e.error)}).catch(e=>v(t(`common.error`)+`: `+e.message))},Mt=()=>{confirm(t(`settings.disconnectGoogleConfirm`))&&D(`/api/google/revoke`,{}).then(()=>{r(e=>({...e,hasGoogle:!1})),v(t(`common.disconnected`))})},B=()=>{if(!f)return;let e=!!f.id,t={display_name:f.display_name,email_address:f.email_address,from_name:f.from_name,imap_host:f.imap_host,imap_port:Number(f.imap_port),smtp_host:f.smtp_host,smtp_port:Number(f.smtp_port),username:f.username};f.password&&(t.password=f.password),e&&(t.id=f.id),h(`Saving…`),D(e?`/api/imap/accounts/update`:`/api/imap/accounts`,t).then(e=>{e?.ok||e?.id?(h(`Saved!`),p(null),Ct()):h(`Error: `+(e?.error??`Unknown error`))}).catch(e=>h(`Error: `+e.message))},Nt=(e,n)=>{confirm(t(`settings.imapDelete`,{name:n}))&&D(`/api/imap/accounts/delete`,{id:e}).then(()=>Ct())},Pt=e=>{D(`/api/imap/sync`,{accountId:e}).then(()=>setTimeout(Ct,3e3))},Ft=async()=>{if(f){if(!f.imap_host||!f.imap_port){h(`⚠ Inserisci prima host e porta IMAP.`);return}h(`Diagnostica porta IMAP in corso…`);try{let e=await D(`/api/imap/probe`,{imap_host:f.imap_host,imap_port:Number(f.imap_port)});e?.ok?h(`✓ ${f.imap_host}:${f.imap_port} risponde\n${e.message}${e.banner?`\n\nBanner: ${e.banner}`:``}`):h(`✗ ${f.imap_host}:${f.imap_port} non risponde\n${e?.message??e?.error??`errore sconosciuto`}`)}catch(e){h(`✗ Diagnostica fallita: ${e.message}`)}}},It=async e=>{if(!f)return;if(!f.password&&!f.id){h(`⚠ Inserisci la password prima di testare.`);return}h(e?`Invio email di prova…`:`Test connessione in corso…`);let t={imap_host:f.imap_host,imap_port:Number(f.imap_port),smtp_host:f.smtp_host,smtp_port:Number(f.smtp_port),username:f.username,password:f.password,email_address:f.email_address,from_name:f.from_name,sendTest:e};try{let e=await D(`/api/imap/test`,t),n=e?.imap,r=e?.smtp,i=[];n?.ok?i.push(`✓ IMAP OK (TLS=${n.secure?`implicit`:`STARTTLS`}, ${n.folderCount??`?`} cartelle)`):i.push(`✗ IMAP errore: ${n?.error??`sconosciuto`}`),r?.ok?r.sent?i.push(`✓ SMTP OK — email di prova inviata a ${f.email_address} (id ${(r.messageId||``).slice(0,24)}…)`):i.push(`✓ SMTP OK (TLS=${r.secure?`implicit`:`STARTTLS`}, auth valida)`):i.push(`✗ SMTP errore: ${r?.error??`sconosciuto`}`),h(i.join(` · `))}catch(e){h(`✗ Test fallito: ${e.message}`)}};if(i)return(0,k.jsxs)(`div`,{className:z.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),t(`common.loading`)]});let Lt=e=>t(o===e?`common.saving`:c===e?`common.saved`:`common.save`);return(0,k.jsxs)(`div`,{className:z.root,children:[(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.profile`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.profileSub`)}),(0,k.jsx)(`div`,{className:z.fields,children:[[`name`,t(`settings.name`),t(`settings.namePh`)],[`email`,t(`common.email`),t(`settings.emailPh`)],[`phone`,t(`common.phone`),t(`settings.phonePh`)],[`homeAddress`,t(`settings.homeAddress`),t(`settings.homeAddressPh`)],[`workAddress`,t(`settings.workAddress`),t(`settings.workAddressPh`)],[`city`,t(`settings.city`),t(`settings.cityPh`)],[`country`,t(`settings.country`),t(`settings.countryPh`)],[`company`,t(`settings.company`),t(`settings.companyPh`)],[`role`,t(`settings.role`),t(`settings.rolePh`)],[`notes`,t(`settings.notes`),t(`settings.notesPh`)]].map(([e,t,n])=>(0,k.jsx)(Ot,{id:e,label:t,placeholder:n,value:x[e],onChange:t=>S(n=>({...n,[e]:t}))},e))}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:Tt,children:[Lt(`profile`),` `,t(`settings.saveProfile`)]})]}),(0,k.jsxs)(`div`,{className:z.nhaFree,children:[(0,k.jsx)(`div`,{className:z.nhaFreeTitle,children:t(`settings.nhaFreeTitle`)}),(0,k.jsx)(`div`,{className:z.nhaFreeSub,children:t(`settings.nhaFreeSub`)}),(0,k.jsx)(`button`,{className:z.nhaFreeBtn,onClick:()=>{D(`/api/config`,{updates:[{key:`provider`,value:`nha`},{key:`model`,value:``},{key:`key`,value:``}]}).then(()=>{w(`nha`),ge(``),T(``),l(`nhaFree`),setTimeout(()=>l(null),2e3)})},children:t(c===`nhaFree`?`settings.liaraActivated`:`settings.useLiara`)})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.llmProvider`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.llmProviderSub`)}),(()=>{let e=[];return n.hasApiKey&&e.push(`Anthropic`),n.hasOpenaiKey&&e.push(`OpenAI`),n.hasGeminiKey&&e.push(`Gemini`),n.hasDeepseekKey&&e.push(`DeepSeek`),n.hasGrokKey&&e.push(`Grok`),n.hasMistralKey&&e.push(`Mistral`),n.hasCohereKey&&e.push(`Cohere`),e.length===0?null:(0,k.jsxs)(`div`,{className:z.keySummary,children:[(0,k.jsx)(`span`,{className:z.keySummaryIcon,children:`🔑`}),(0,k.jsxs)(`span`,{children:[`Chiavi configurate: `,(0,k.jsx)(`strong`,{children:e.join(`, `)})]})]})})(),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.provider`)}),(0,k.jsxs)(`select`,{value:C,onChange:e=>w(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`nha`,children:`NHA Free (Liara) — no API key needed`}),(0,k.jsx)(`option`,{value:`anthropic`,children:`Anthropic (Claude)`}),(0,k.jsx)(`option`,{value:`openai`,children:`OpenAI (GPT-4)`}),(0,k.jsx)(`option`,{value:`gemini`,children:`Google (Gemini)`}),(0,k.jsx)(`option`,{value:`deepseek`,children:`DeepSeek`}),(0,k.jsx)(`option`,{value:`grok`,children:`xAI (Grok)`}),(0,k.jsx)(`option`,{value:`mistral`,children:`Mistral`}),(0,k.jsx)(`option`,{value:`cohere`,children:`Cohere`})]})]}),C!==`nha`&&({anthropic:n.hasApiKey,openai:n.hasOpenaiKey,gemini:n.hasGeminiKey,deepseek:n.hasDeepseekKey,grok:n.hasGrokKey,mistral:n.hasMistralKey,cohere:n.hasCohereKey}[C]?(0,k.jsx)(`div`,{className:z.keySet,children:t(`settings.apiKeySet`)}):null),(0,k.jsx)(Ot,{id:`apiKey`,label:t(`settings.apiKey`),placeholder:t(C===`nha`?`settings.apiKeyFreeNote`:`settings.apiKeyPh`),type:`password`,value:ee,onChange:T}),(0,k.jsx)(Ot,{id:`groqKey`,label:`Groq Key (voice / Whisper)`,placeholder:n.hasGroqKey?`✓ configured — leave empty to keep`:`gsk_... (free at console.groq.com/keys) — enables Telegram voice transcription`,type:`password`,value:ne,onChange:re}),(0,k.jsx)(`div`,{style:{marginTop:8,marginBottom:4},children:(0,k.jsxs)(`button`,{type:`button`,onClick:()=>me(!pe),style:{background:`transparent`,border:`none`,color:`var(--accent, #6366f1)`,cursor:`pointer`,fontSize:12,padding:0,fontWeight:600},children:[pe?`▾`:`▸`,` Optional provider keys (OpenAI, Gemini, DeepSeek, Grok, Mistral, Cohere)`]})}),pe&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(Ot,{id:`openaiKey`,label:`OpenAI Key`,placeholder:n.hasOpenaiKey?`✓ configured — leave empty to keep`:`sk-... (platform.openai.com)`,type:`password`,value:ie,onChange:O}),(0,k.jsx)(Ot,{id:`geminiKey`,label:`Gemini Key (Google)`,placeholder:n.hasGeminiKey?`✓ configured — leave empty to keep`:`AIza... (aistudio.google.com)`,type:`password`,value:ae,onChange:A}),(0,k.jsx)(Ot,{id:`deepseekKey`,label:`DeepSeek Key`,placeholder:n.hasDeepseekKey?`✓ configured — leave empty to keep`:`sk-... (platform.deepseek.com)`,type:`password`,value:oe,onChange:se}),(0,k.jsx)(Ot,{id:`grokKey`,label:`Grok Key (X.AI)`,placeholder:n.hasGrokKey?`✓ configured — leave empty to keep`:`xai-... (console.x.ai)`,type:`password`,value:ce,onChange:le}),(0,k.jsx)(Ot,{id:`mistralKey`,label:`Mistral Key`,placeholder:n.hasMistralKey?`✓ configured — leave empty to keep`:`... (console.mistral.ai)`,type:`password`,value:ue,onChange:de}),(0,k.jsx)(Ot,{id:`cohereKey`,label:`Cohere Key`,placeholder:n.hasCohereKey?`✓ configured — leave empty to keep`:`... (dashboard.cohere.com)`,type:`password`,value:M,onChange:fe})]}),(0,k.jsx)(Ot,{id:`model`,label:t(`settings.model`),placeholder:t(`settings.modelPh`),value:he,onChange:ge}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.thinking`)}),(0,k.jsxs)(`select`,{value:we,onChange:e=>Te(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`off`,children:t(`settings.thinkingOff`)}),(0,k.jsx)(`option`,{value:`on`,children:t(`settings.thinkingOn`)})]})]}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:Et,children:[Lt(`provider`),` `,t(`settings.saveProvider`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.language`)}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:t(`settings.languageLabel`)}),(0,k.jsx)(`select`,{value:_e,onChange:t=>{let r=t.target.value;ve(r),wt(`lang`,r),e({...n,lang:r})},className:z.fieldInput,children:[[`it`,`Italiano`],[`en`,`English`],[`es`,`Español`],[`fr`,`Français`],[`de`,`Deutsch`],[`pt`,`Português`],[`nl`,`Nederlands`],[`pl`,`Polski`],[`ru`,`Русский`],[`zh`,`中文`],[`ja`,`日本語`],[`ko`,`한국어`],[`ar`,`العربية`],[`hi`,`हिन्दी`],[`tr`,`Türkçe`],[`sv`,`Svenska`],[`da`,`Dansk`],[`fi`,`Suomi`],[`cs`,`Čeština`]].map(([e,t])=>(0,k.jsx)(`option`,{value:e,children:t},e))})]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.telegram`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.telegramSub`)}),n.hasTelegram&&(0,k.jsxs)(`div`,{className:z.connected,children:[`Telegram: `,t(`common.connected`)]}),n.hasDiscord&&(0,k.jsxs)(`div`,{className:z.connected,children:[`Discord: `,t(`common.connected`)]}),(0,k.jsx)(Ot,{id:`tgToken`,label:t(`settings.telegramToken`),placeholder:n.hasTelegram?t(`settings.telegramSet`):t(`settings.telegramPh`),type:`password`,value:Ee,onChange:P}),(0,k.jsx)(Ot,{id:`discordToken`,label:t(`settings.discordToken`),placeholder:n.hasDiscord?t(`settings.discordSet`):t(`settings.discordPh`),type:`password`,value:De,onChange:Oe}),(0,k.jsx)(Ot,{id:`botName`,label:`Bot Persona Name`,placeholder:`e.g. Agata — what name the bot uses when replying. Empty = show internal agent name (HERALD/ATHENA/...)`,value:ke,onChange:F}),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsx)(`label`,{className:z.fieldLabel,children:`Persona display mode`}),(0,k.jsxs)(`select`,{value:I,onChange:e=>Ae(e.target.value),className:z.fieldInput,children:[(0,k.jsx)(`option`,{value:`agent`,children:`agent — show internal name [HERALD] (legacy/debug)`}),(0,k.jsx)(`option`,{value:`persona`,children:`persona — show [BotName] only (recommended)`}),(0,k.jsx)(`option`,{value:`persona-only`,children:`persona-only — no prefix at all (most natural)`}),(0,k.jsx)(`option`,{value:`persona+role`,children:`persona+role — [BotName · agent] (power users)`})]})]}),(0,k.jsx)(Ot,{id:`allowedChatIds`,label:`Allowed Chat IDs (Telegram)`,placeholder:`comma-separated numeric chat IDs (empty = anyone can chat with the bot)`,value:je,onChange:Me}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Ne,onChange:e=>Pe(e.target.checked)}),` `,`Auto-route messages to specialist agents (recommended)`]})}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{Ee&&wt(`telegram-bot-token`,Ee),De&&wt(`discord-bot-token`,De),wt(`bot-name`,ke),wt(`persona-mode`,I),wt(`responder.telegram.allowedChatIds`,je.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>Number(e)||e)),wt(`responder-auto-route`,Ne)},children:[Lt(`telegram-bot-token`),` `,t(`settings.saveBots`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.dailyOps`)}),(0,k.jsx)(Ot,{id:`planTime`,label:t(`settings.planTime`),placeholder:`07:00`,value:ye,onChange:be}),(0,k.jsx)(Ot,{id:`summaryTime`,label:t(`settings.summaryTime`),placeholder:`18:00`,value:xe,onChange:Se}),(0,k.jsx)(Ot,{id:`meetingAlert`,label:t(`settings.meetingAlert`),placeholder:`30`,value:N,onChange:Ce}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:At,children:[Lt(`planTime`),` `,t(`settings.saveSchedule`)]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Deliberation (Geth Consensus)`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Multi-round inter-agent reasoning for higher-quality answers`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Fe,onChange:e=>Ie(e.target.checked)}),` `,`Enable deliberation`]})}),(0,k.jsx)(Ot,{id:`delibRounds`,label:`Rounds (1–5)`,placeholder:`3`,value:Le,onChange:Re}),(0,k.jsx)(Ot,{id:`delibConvergence`,label:`Convergence threshold (0–1, lower = stricter)`,placeholder:`0.30`,value:ze,onChange:L}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Be,onChange:e=>Ve(e.target.checked)}),` `,`Tribunal (final HERALD mediation)`]})}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`deliberation`,Fe),wt(`rounds`,Number(Le)),wt(`convergence`,Number(ze)),wt(`tribunal`,Be)},children:[Lt(`deliberation`),` Save deliberation`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Proactive Intelligence`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`The bot acts on its own initiative (follow-ups, meeting prep, pattern detection)`}),[[`proactive`,`Master switch — enable proactive`,He,Ue],[`proactive-email`,`Email follow-up reminders`,We,Ge],[`proactive-meeting`,`Meeting preparation digests`,Ke,qe],[`proactive-patterns`,`Behavioural pattern detection`,Je,Ye],[`proactive-deadlines`,`Deadline tracking`,Xe,Ze]].map(([e,t,n,r])=>(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),` `,t]})},String(e))),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`proactive`,He),wt(`proactive-email`,We),wt(`proactive-meeting`,Ke),wt(`proactive-patterns`,Je),wt(`proactive-deadlines`,Xe)},children:[Lt(`proactive`),` Save proactive`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Voice`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Transcription (Whisper via Groq) and text-to-speech`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:Qe,onChange:e=>$e(e.target.checked)}),` `,`Prefer Whisper (Groq) over local STT`]})}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:et,onChange:e=>tt(e.target.checked)}),` `,`Speech synthesis (read replies aloud)`]})}),(0,k.jsx)(Ot,{id:`voiceLanguage`,label:`Voice language (BCP 47, e.g. it-IT, en-US)`,placeholder:`empty = use UI language`,value:nt,onChange:rt}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`voice-whisper`,Qe),wt(`voice-speech`,et),nt&&wt(`voice-language`,nt)},children:[Lt(`voice-whisper`),` Save voice`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Features`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Core behaviour toggles`}),[[`verbose`,`Verbose logging (more diagnostics, more tokens)`,it,at],[`immersive`,`Immersive office scene animation in Studio`,ot,st],[`knowledge`,`Knowledge base (memories + skills retrieval)`,ct,lt]].map(([e,t,n,r])=>(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),` `,t]})},String(e))),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`verbose`,it),wt(`immersive`,ot),wt(`knowledge`,ct)},children:[Lt(`verbose`),` Save features`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Integration tokens`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`GitHub, Notion, Slack — used by the corresponding tools`}),(0,k.jsx)(Ot,{id:`githubToken`,label:`GitHub Token (PAT)`,placeholder:n.hasGithubToken?`✓ configured — leave empty to keep`:`ghp_... — needs repo + read:org scopes`,type:`password`,value:ut,onChange:dt}),(0,k.jsx)(Ot,{id:`githubRepo`,label:`Default GitHub repo (owner/name)`,placeholder:`acme/website`,value:ft,onChange:pt}),(0,k.jsx)(Ot,{id:`notionToken`,label:`Notion Token (Internal Integration)`,placeholder:n.hasNotionToken?`✓ configured — leave empty to keep`:`secret_...`,type:`password`,value:mt,onChange:ht}),(0,k.jsx)(Ot,{id:`slackToken`,label:`Slack Bot Token (xoxb-)`,placeholder:n.hasSlackToken?`✓ configured — leave empty to keep`:`xoxb-...`,type:`password`,value:gt,onChange:_t}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{ut&&wt(`github-token`,ut),ft&&wt(`github-repo`,ft),mt&&wt(`notion-token`,mt),gt&&wt(`slack-token`,gt)},children:[Lt(`github-token`),` Save tokens`]})]}),(0,k.jsx)(kt,{}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:`Advanced`}),(0,k.jsx)(`div`,{className:z.cardSub,children:`Plugins, Microsoft tenant ID, runtime extras`}),(0,k.jsx)(`div`,{className:z.field,children:(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:R,onChange:e=>bt(e.target.checked)}),` `,`Auto-run plugins at startup`]})}),(0,k.jsx)(Ot,{id:`pluginDir`,label:`Plugin directory (absolute path)`,placeholder:`empty = ~/.nha/plugins`,value:xt,onChange:St}),(0,k.jsx)(Ot,{id:`microsoftTenant`,label:`Microsoft Tenant ID`,placeholder:`common (default) | organizations | consumers | <GUID>`,value:vt,onChange:yt}),(0,k.jsxs)(`button`,{className:z.saveBtn,onClick:()=>{wt(`plugin-autorun`,R),xt&&wt(`plugin-dir`,xt),wt(`microsoft-tenant`,vt)},children:[Lt(`plugin-autorun`),` Save advanced`]})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.googleAccount`)}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.googleSub`)}),n.hasGoogle&&(0,k.jsxs)(`div`,{className:z.connected,children:[`✅ `,t(`common.connected`),n.googleEmail?` · ${n.googleEmail}`:``]}),(0,k.jsxs)(`div`,{className:z.btnRow,children:[(0,k.jsx)(`button`,{className:z.saveBtn,onClick:jt,children:n.hasGoogle?t(`settings.reconnectGoogle`):t(`settings.connectGoogle`)}),n.hasGoogle&&(0,k.jsx)(`button`,{className:z.dangerBtn,onClick:Mt,children:t(`settings.disconnectGoogle`)})]}),g&&(0,k.jsx)(`div`,{className:z.statusMsg,children:g})]}),(0,k.jsxs)(`div`,{className:z.card,children:[(0,k.jsxs)(`div`,{className:z.cardTitleRow,children:[(0,k.jsx)(`div`,{className:z.cardTitle,children:t(`settings.imapAccounts`)}),(0,k.jsx)(`button`,{className:z.saveBtn,onClick:()=>{p({...Dt}),h(``)},children:t(`settings.addAccount`)})]}),(0,k.jsx)(`div`,{className:z.cardSub,children:t(`settings.imapSub`)}),u.length===0&&!f&&(0,k.jsx)(`div`,{className:z.emptyImap,children:t(`settings.noImapAccounts`)}),u.map(e=>(0,k.jsxs)(`div`,{className:z.imapRow,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:z.imapName,children:e.display_name}),(0,k.jsxs)(`div`,{className:z.imapMeta,children:[e.email_address,` · `,e.imap_host]}),(0,k.jsxs)(`div`,{className:z.imapStatus,"data-status":e.sync_status,children:[e.sync_status,e.last_sync_at?` · ${t(`email.lastSync`)}: ${e.last_sync_at.slice(0,16)}`:``]})]}),(0,k.jsxs)(`div`,{className:z.imapBtns,children:[(0,k.jsx)(`button`,{className:z.imapSyncBtn,onClick:()=>Pt(e.id),children:t(`settings.sync`)}),(0,k.jsx)(`button`,{className:z.imapEditBtn,onClick:()=>{p({...Dt,id:e.id,display_name:e.display_name,email_address:e.email_address,from_name:e.from_name??``,imap_host:e.imap_host,imap_port:String(e.imap_port??993),smtp_host:e.smtp_host??``,smtp_port:String(e.smtp_port??587),username:e.username??``,password:``}),h(``)},children:t(`common.edit`)}),(0,k.jsx)(`button`,{className:z.imapDelBtn,onClick:()=>Nt(e.id,e.display_name),children:t(`common.delete`)})]})]},e.id)),f&&(0,k.jsxs)(`div`,{className:z.imapForm,children:[(0,k.jsx)(`div`,{className:z.imapFormTitle,children:f.id?t(`settings.editImapAccount`):t(`settings.addImapAccount`)}),[[`display_name`,t(`settings.displayName`),t(`settings.displayNamePh`)],[`email_address`,t(`common.email`),`user@example.com`],[`from_name`,t(`settings.fromName`),t(`settings.fromNamePh`)],[`imap_host`,t(`settings.imapServer`),`e.g. imap.gmail.com`],[`imap_port`,t(`settings.imapPort`),`993`],[`smtp_host`,t(`settings.smtpServer`),`e.g. smtp.gmail.com`],[`smtp_port`,t(`settings.smtpPort`),`587`],[`username`,t(`settings.username`),`user@example.com`]].map(([e,t,n])=>(0,k.jsx)(Ot,{id:`imap_${e}`,label:t,placeholder:n,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t})},e)),(0,k.jsxs)(`div`,{className:z.field,children:[(0,k.jsxs)(`label`,{className:z.fieldLabel,children:[t(`settings.password`),` `,f.id&&(0,k.jsx)(`span`,{className:z.pwdNote,children:t(`settings.passwordKeep`)})]}),(0,k.jsxs)(`div`,{className:z.pwdRow,children:[(0,k.jsx)(`input`,{type:y?`text`:`password`,placeholder:t(`settings.passwordPh`),value:f.password,onChange:e=>p(t=>t&&{...t,password:e.target.value}),className:z.fieldInput,style:{flex:1}}),(0,k.jsx)(`button`,{className:z.togglePwd,onClick:()=>b(e=>!e),children:t(y?`settings.hide`:`settings.show`)})]})]}),(0,k.jsxs)(`div`,{className:z.btnRow,children:[(0,k.jsx)(`button`,{className:z.saveBtn,onClick:B,children:t(`common.save`)}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>It(!1),title:`Verifica IMAP+SMTP senza inviare nulla`,children:`Test connessione`}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>It(!0),title:`Invia un'email di prova alla tua casella per verificare il round-trip`,children:`Invia email di prova`}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:Ft,title:`Diagnostica raw: mostra cosa risponde realmente il server sulla porta indicata`,children:`Diagnostica porta`}),(0,k.jsx)(`button`,{className:z.cancelBtn,onClick:()=>p(null),children:t(`common.cancel`)})]}),m&&(0,k.jsx)(`div`,{className:z.statusMsg,style:{whiteSpace:`pre-line`},children:m})]})]})]})}var jt={root:`_root_o07ov_1`,loading:`_loading_o07ov_2`,err:`_err_o07ov_3`,header:`_header_o07ov_4`,title:`_title_o07ov_5`,addBtn:`_addBtn_o07ov_6`,empty:`_empty_o07ov_7`,card:`_card_o07ov_8`,cardToday:`_cardToday_o07ov_9`,icon:`_icon_o07ov_10`,info:`_info_o07ov_11`,name:`_name_o07ov_12`,date:`_date_o07ov_13`,labelToday:`_labelToday_o07ov_14`,labelTomorrow:`_labelTomorrow_o07ov_15`,labelFuture:`_labelFuture_o07ov_16`,editBtn:`_editBtn_o07ov_17`,delBtn:`_delBtn_o07ov_18`,overlay:`_overlay_o07ov_20`,modal:`_modal_o07ov_21`,modalTitle:`_modalTitle_o07ov_22`,label:`_label_o07ov_14`,input:`_input_o07ov_24`,hint:`_hint_o07ov_25`,formErr:`_formErr_o07ov_26`,modalBtns:`_modalBtns_o07ov_27`,cancelBtn:`_cancelBtn_o07ov_28`,saveBtn:`_saveBtn_o07ov_29`};function Mt(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),p=(0,_.useCallback)(()=>{i(!0),E(`/api/birthdays`).then(e=>{e?.error?o(e.error):n(e?.birthdays??[]),i(!1)})},[]);(0,_.useEffect)(()=>{p()},[p]);let m=()=>{c({name:``,date:``}),u(``)},h=e=>{c({name:e.name,date:e.date,contactId:e.contactId}),u(``)},g=async()=>{if(!s)return;if(!s.name.trim()){u(`Name is required`);return}if(!s.date.trim()){u(`Date is required`);return}f(!0);let e=s.date;/^\d{2}-\d{2}$/.test(e)&&(e=`${new Date().getFullYear()}-${e}`),await D(`/api/birthdays`,{name:s.name,date:e,contactId:s.contactId??null,edit:!!s.contactId}),f(!1),c(null),p()},v=e=>{confirm(`Remove birthday for ${e.name}?`)&&D(`/api/birthdays/delete`,{contactId:e.contactId}).then(p)};return r?(0,k.jsxs)(`div`,{className:jt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):a?(0,k.jsx)(`div`,{className:jt.err,children:a}):(0,k.jsxs)(`div`,{className:jt.root,children:[(0,k.jsxs)(`div`,{className:jt.header,children:[(0,k.jsx)(`div`,{className:jt.title,children:`Upcoming Birthdays`}),(0,k.jsx)(`button`,{className:jt.addBtn,onClick:m,children:`+ Add Birthday`})]}),t.length===0&&(0,k.jsxs)(`div`,{className:jt.empty,children:[e(`birthdays.noBirthdays`),(0,k.jsx)(`br`,{}),(0,k.jsx)(`small`,{children:`Add one above, or add birthdays to your Google Contacts.`})]}),t.map((t,n)=>{let r=t.daysUntil===0,i=t.daysUntil===1;return(0,k.jsxs)(`div`,{className:`${jt.card} ${r?jt.cardToday:``}`,children:[(0,k.jsx)(`span`,{className:jt.icon,children:`🎂`}),(0,k.jsxs)(`div`,{className:jt.info,children:[(0,k.jsx)(`div`,{className:jt.name,children:t.name}),(0,k.jsx)(`div`,{className:jt.date,children:t.date})]}),(0,k.jsx)(`div`,{className:r?jt.labelToday:i?jt.labelTomorrow:jt.labelFuture,children:r?`TODAY!`:i?`Tomorrow`:`in ${t.daysUntil} days`}),t.contactId&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:jt.editBtn,onClick:()=>h(t),children:e(`common.edit`)}),(0,k.jsx)(`button`,{className:jt.delBtn,onClick:()=>v(t),children:e(`common.delete`)})]})]},n)}),s&&(0,k.jsx)(`div`,{className:jt.overlay,onClick:e=>{e.target===e.currentTarget&&c(null)},children:(0,k.jsxs)(`div`,{className:jt.modal,children:[(0,k.jsx)(`div`,{className:jt.modalTitle,children:s.contactId?`Edit Birthday`:`Add Birthday`}),(0,k.jsx)(`label`,{className:jt.label,children:`Name *`}),(0,k.jsx)(`input`,{className:jt.input,value:s.name,onChange:e=>c(t=>t&&{...t,name:e.target.value}),placeholder:`Contact name`}),(0,k.jsx)(`label`,{className:jt.label,children:`Birthday (MM-DD or YYYY-MM-DD)`}),(0,k.jsx)(`input`,{className:jt.input,value:s.date,onChange:e=>c(t=>t&&{...t,date:e.target.value}),placeholder:`e.g. 03-15 or 1990-03-15`}),(0,k.jsx)(`div`,{className:jt.hint,children:`Birthday will be saved as a Google Calendar event.`}),l&&(0,k.jsx)(`div`,{className:jt.formErr,children:l}),(0,k.jsxs)(`div`,{className:jt.modalBtns,children:[(0,k.jsx)(`button`,{className:jt.cancelBtn,onClick:()=>c(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:jt.saveBtn,onClick:g,disabled:d,children:d?`Saving…`:s.contactId?`Save`:`Add`})]})]})})]})}var B={root:`_root_1z04o_1`,header:`_header_1z04o_3`,title:`_title_1z04o_4`,subtitle:`_subtitle_1z04o_5`,code:`_code_1z04o_6`,addBtn:`_addBtn_1z04o_8`,tabs:`_tabs_1z04o_10`,tab:`_tab_1z04o_10`,tabActive:`_tabActive_1z04o_12`,loading:`_loading_1z04o_14`,err:`_err_1z04o_15`,empty:`_empty_1z04o_17`,emptyIcon:`_emptyIcon_1z04o_18`,emptyTitle:`_emptyTitle_1z04o_19`,emptySub:`_emptySub_1z04o_20`,card:`_card_1z04o_23`,cardDisabled:`_cardDisabled_1z04o_24`,cardTop:`_cardTop_1z04o_25`,cardLeft:`_cardLeft_1z04o_26`,jobName:`_jobName_1z04o_27`,schedule:`_schedule_1z04o_28`,agentBadge:`_agentBadge_1z04o_29`,statusBadge:`_statusBadge_1z04o_30`,statusActive:`_statusActive_1z04o_31`,statusPaused:`_statusPaused_1z04o_32`,jobPrompt:`_jobPrompt_1z04o_33`,jobMeta:`_jobMeta_1z04o_34`,cardActions:`_cardActions_1z04o_35`,runBtn:`_runBtn_1z04o_36`,editBtn:`_editBtn_1z04o_37`,pauseBtn:`_pauseBtn_1z04o_38`,resumeBtn:`_resumeBtn_1z04o_39`,delBtn:`_delBtn_1z04o_40`,templates:`_templates_1z04o_43`,templatesNote:`_templatesNote_1z04o_44`,templateCard:`_templateCard_1z04o_45`,templateLabel:`_templateLabel_1z04o_46`,templatePrompt:`_templatePrompt_1z04o_47`,templateBtns:`_templateBtns_1z04o_48`,scheduleTplBtn:`_scheduleTplBtn_1z04o_49`,runTplBtn:`_runTplBtn_1z04o_50`,formOverlay:`_formOverlay_1z04o_54`,formModal:`_formModal_1z04o_55`,formTitle:`_formTitle_1z04o_56`,label:`_label_1z04o_57`,input:`_input_1z04o_58`,textarea:`_textarea_1z04o_59`,presets:`_presets_1z04o_61`,preset:`_preset_1z04o_61`,presetActive:`_presetActive_1z04o_63`,cronHints:`_cronHints_1z04o_65`,cronHint:`_cronHint_1z04o_65`,formErr:`_formErr_1z04o_70`,formOk:`_formOk_1z04o_71`,formBtns:`_formBtns_1z04o_72`,cancelBtn:`_cancelBtn_1z04o_73`,saveBtn:`_saveBtn_1z04o_74`},Nt=[{label:`Every 15 min`,value:`every 15 minutes`},{label:`Every 30 min`,value:`every 30 minutes`},{label:`Every hour`,value:`every hour`},{label:`Every 6h`,value:`every 6 hours`},{label:`Daily 8am`,value:`every day at 08:00`},{label:`Daily 9am`,value:`every day at 09:00`},{label:`Daily noon`,value:`every day at 12:00`},{label:`Daily 6pm`,value:`every day at 18:00`},{label:`Mon–Fri 9am`,value:`weekdays at 09:00`},{label:`Every Monday`,value:`every monday at 09:00`}],Pt=[{label:`🌅 Morning Briefing`,prompt:`Summarize my unread emails from the last 12 hours, check today's calendar events, list my top 3 priority tasks, and give me a focused action plan for the day.`},{label:`🌆 Evening Review`,prompt:`Review what I accomplished today: check completed tasks, summarize any important emails received, flag unresolved issues, and prepare a priority list for tomorrow.`},{label:`📰 News Digest`,prompt:`Search for the top AI, tech, and finance news from the last 24 hours. Summarize the 5 most important stories with key takeaways and market implications.`},{label:`📈 Market Update`,prompt:`Provide a comprehensive market update: macro environment, major indices performance, top movers, notable events, and key levels to watch. Use herald and mercury agents.`},{label:`🐙 GitHub Monitor`,prompt:`Check my GitHub notifications, summarize open issues and pull requests that need attention, and draft brief responses for the most urgent ones.`},{label:`📊 Weekly Report`,prompt:`Generate a weekly productivity report: tasks completed vs pending, email response rate, upcoming calendar events, and 3 strategic priorities for next week.`},{label:`🔒 Security Scan`,prompt:`Run a security awareness check: scan recent code commits for potential vulnerabilities, check dependency alerts, and summarize any security-related GitHub notifications.`},{label:`🎯 Goal Tracker`,prompt:`Review my tasks and notes for goal progress. Identify what's on track, what's at risk, and suggest one concrete action to unblock the most important goal.`}],Ft=[{label:`0 9 * * 1-5`,desc:`Mon–Fri at 9:00 AM`},{label:`0 */6 * * *`,desc:`Every 6 hours`},{label:`*/30 * * * *`,desc:`Every 30 minutes`},{label:`0 8 * * *`,desc:`Daily at 8:00 AM`},{label:`0 20 * * 5`,desc:`Every Friday at 8 PM`}];function It(){let e=j(),t=te(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)({name:``,schedule:``,prompt:``,agent:``}),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(``),[y,b]=(0,_.useState)(null),[x,S]=(0,_.useState)(`jobs`),C=()=>{a(!0),E(`/api/cron`).then(e=>{e?.error?s(e.error):r(e?.jobs??[]),a(!1)}).catch(()=>{r([]),a(!1)})};(0,_.useEffect)(()=>{C()},[]);let w=()=>{d({name:``,schedule:``,prompt:``,agent:``}),h(``),v(``),b(null),l(!0)},ee=e=>{d({name:e.name??``,schedule:e.schedule,prompt:e.prompt??e.command??``,agent:e.agent??``}),h(``),v(``),b(e.id),l(!0)},T=async()=>{if(!u.schedule.trim()){h(`Schedule is required`);return}if(!u.prompt.trim()){h(`Task prompt is required`);return}p(!0),h(``);try{y?await D(`/api/cron/update`,{id:y,schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}):await D(`/api/cron`,{schedule:u.schedule,prompt:u.prompt,agent:u.agent||void 0,name:u.name||void 0}),v(y?`Updated!`:`Job scheduled!`),setTimeout(()=>{v(``),l(!1)},1500),C()}catch(e){h(e.message??`Failed`)}p(!1)},ne=(e,t)=>D(`/api/cron/toggle`,{id:e,enabled:!t}).then(C),re=e=>{confirm(`Delete this scheduled task?`)&&D(`/api/cron/delete`,{id:e}).then(C)},ie=e=>{try{sessionStorage.setItem(`nha_chat_prefill`,e)}catch{}t(`chat`)},O=e=>{d(t=>({...t,prompt:e.prompt,name:e.label.replace(/^[^\s]+\s/,``)})),S(`jobs`),l(!0)};return(0,k.jsxs)(`div`,{className:B.root,children:[(0,k.jsxs)(`div`,{className:B.header,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:B.title,children:`⏰ Scheduled Tasks`}),(0,k.jsxs)(`div`,{className:B.subtitle,children:[`Automate agents on a recurring schedule. Daemon must be running: `,(0,k.jsx)(`code`,{className:B.code,children:`nha ops start`})]})]}),(0,k.jsx)(`button`,{className:B.addBtn,onClick:w,children:`+ New Task`})]}),(0,k.jsxs)(`div`,{className:B.tabs,children:[(0,k.jsxs)(`button`,{className:`${B.tab} ${x===`jobs`?B.tabActive:``}`,onClick:()=>S(`jobs`),children:[`Jobs (`,n.length,`)`]}),(0,k.jsx)(`button`,{className:`${B.tab} ${x===`templates`?B.tabActive:``}`,onClick:()=>S(`templates`),children:`Templates`})]}),x===`templates`&&(0,k.jsxs)(`div`,{className:B.templates,children:[(0,k.jsx)(`div`,{className:B.templatesNote,children:`Click a template to pre-fill the job form or run it immediately in Chat.`}),Pt.map(t=>(0,k.jsxs)(`div`,{className:B.templateCard,children:[(0,k.jsx)(`div`,{className:B.templateLabel,children:t.label}),(0,k.jsx)(`div`,{className:B.templatePrompt,children:t.prompt}),(0,k.jsxs)(`div`,{className:B.templateBtns,children:[(0,k.jsx)(`button`,{className:B.scheduleTplBtn,onClick:()=>O(t),children:`Schedule`}),(0,k.jsxs)(`button`,{className:B.runTplBtn,onClick:()=>ie(t.prompt),children:[e(`cron.run`),` in Chat →`]})]})]},t.label))]}),x===`jobs`&&(0,k.jsxs)(k.Fragment,{children:[i&&(0,k.jsxs)(`div`,{className:B.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading jobs…`]}),o&&(0,k.jsx)(`div`,{className:B.err,children:o}),!i&&n.length===0&&!c&&(0,k.jsxs)(`div`,{className:B.empty,children:[(0,k.jsx)(`div`,{className:B.emptyIcon,children:`⏰`}),(0,k.jsxs)(`div`,{className:B.emptyTitle,children:[e(`cron.noJobs`),` tasks`]}),(0,k.jsx)(`div`,{className:B.emptySub,children:`Create a job to automate agents on a recurring schedule, or browse the Templates tab for ready-made automation recipes.`}),(0,k.jsx)(`button`,{className:B.addBtn,onClick:w,children:`+ New Task`})]}),n.map(e=>(0,k.jsxs)(`div`,{className:`${B.card} ${e.enabled?``:B.cardDisabled}`,children:[(0,k.jsxs)(`div`,{className:B.cardTop,children:[(0,k.jsxs)(`div`,{className:B.cardLeft,children:[e.name&&(0,k.jsx)(`div`,{className:B.jobName,children:e.name}),(0,k.jsx)(`code`,{className:B.schedule,children:e.schedule}),e.agent&&(0,k.jsx)(`span`,{className:B.agentBadge,children:e.agent}),(0,k.jsx)(`span`,{className:`${B.statusBadge} ${e.enabled?B.statusActive:B.statusPaused}`,children:e.enabled?`active`:`paused`})]}),(0,k.jsxs)(`div`,{className:B.cardActions,children:[(0,k.jsx)(`button`,{className:B.runBtn,onClick:()=>ie(e.prompt??e.command??``),title:`Run now in Chat`,children:`▶`}),(0,k.jsx)(`button`,{className:B.editBtn,onClick:()=>ee(e),children:`Edit`}),(0,k.jsx)(`button`,{className:e.enabled?B.pauseBtn:B.resumeBtn,onClick:()=>ne(e.id,e.enabled),children:e.enabled?`Pause`:`Resume`}),(0,k.jsx)(`button`,{className:B.delBtn,onClick:()=>re(e.id),children:`✕`})]})]}),(0,k.jsx)(`div`,{className:B.jobPrompt,children:e.prompt??e.command}),(0,k.jsxs)(`div`,{className:B.jobMeta,children:[e.runCount!==void 0&&(0,k.jsxs)(`span`,{children:[`ran `,e.runCount,`×`]}),e.lastRun&&(0,k.jsxs)(`span`,{children:[` · last `,new Date(e.lastRun).toLocaleString()]}),e.nextRun&&(0,k.jsxs)(`span`,{children:[` · next `,new Date(e.nextRun).toLocaleString()]})]})]},e.id))]}),c&&(0,k.jsx)(`div`,{className:B.formOverlay,onClick:e=>{e.target===e.currentTarget&&l(!1)},children:(0,k.jsxs)(`div`,{className:B.formModal,children:[(0,k.jsx)(`div`,{className:B.formTitle,children:y?`Edit Scheduled Task`:`New Scheduled Task`}),(0,k.jsx)(`label`,{className:B.label,children:`Name (optional)`}),(0,k.jsx)(`input`,{className:B.input,value:u.name,onChange:e=>d(t=>({...t,name:e.target.value})),placeholder:`e.g. Morning Briefing`}),(0,k.jsx)(`label`,{className:B.label,children:`Schedule *`}),(0,k.jsx)(`div`,{className:B.presets,children:Nt.map(e=>(0,k.jsx)(`button`,{className:`${B.preset} ${u.schedule===e.value?B.presetActive:``}`,onClick:()=>d(t=>({...t,schedule:e.value})),children:e.label},e.value))}),(0,k.jsx)(`input`,{className:B.input,value:u.schedule,onChange:e=>d(t=>({...t,schedule:e.target.value})),placeholder:`every day at 09:00 — or cron syntax: 0 9 * * 1-5`}),(0,k.jsx)(`div`,{className:B.cronHints,children:Ft.map(e=>(0,k.jsxs)(`span`,{className:B.cronHint,onClick:()=>d(t=>({...t,schedule:e.label})),children:[(0,k.jsx)(`code`,{children:e.label}),` `,e.desc]},e.label))}),(0,k.jsx)(`label`,{className:B.label,children:`Task / Prompt *`}),(0,k.jsx)(`textarea`,{className:B.textarea,value:u.prompt,onChange:e=>d(t=>({...t,prompt:e.target.value})),placeholder:`Describe what the agent should do (e.g. Summarize my unread emails and list my 3 top priority tasks)`,rows:4}),(0,k.jsx)(`label`,{className:B.label,children:`Agent (optional — leave blank for auto-routing)`}),(0,k.jsx)(`input`,{className:B.input,value:u.agent,onChange:e=>d(t=>({...t,agent:e.target.value})),placeholder:`e.g. herald, oracle, mercury, EmailAgent, general`}),m&&(0,k.jsx)(`div`,{className:B.formErr,children:m}),g&&(0,k.jsx)(`div`,{className:B.formOk,children:g}),(0,k.jsxs)(`div`,{className:B.formBtns,children:[(0,k.jsx)(`button`,{className:B.cancelBtn,onClick:()=>l(!1),children:`Cancel`}),(0,k.jsx)(`button`,{className:B.saveBtn,onClick:T,disabled:f,children:f?`Saving…`:y?`Update`:`Schedule`})]})]})})]})}var Lt={root:`_root_1npv7_1`,loading:`_loading_1npv7_2`,sidebar:`_sidebar_1npv7_4`,newBtn:`_newBtn_1npv7_5`,empty:`_empty_1npv7_6`,noteItem:`_noteItem_1npv7_8`,noteItemActive:`_noteItemActive_1npv7_10`,noteTitle:`_noteTitle_1npv7_11`,noteMeta:`_noteMeta_1npv7_12`,notePreview:`_notePreview_1npv7_13`,noteTags:`_noteTags_1npv7_14`,noteTag:`_noteTag_1npv7_14`,editor:`_editor_1npv7_17`,emptyEditor:`_emptyEditor_1npv7_18`,titleInput:`_titleInput_1npv7_19`,contentArea:`_contentArea_1npv7_21`,editorFooter:`_editorFooter_1npv7_22`,delNoteBtn:`_delNoteBtn_1npv7_23`,cancelBtn:`_cancelBtn_1npv7_24`,saveBtn:`_saveBtn_1npv7_25`};function Rt(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(``),[l,u]=(0,_.useState)(``),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(!1),h=()=>E(`/api/notes`).then(e=>{n(e?.notes??[]),i(!1)});(0,_.useEffect)(()=>{h()},[]);let g=e=>{o(e),c(e.title),u(e.content),m(!1)},v=()=>{o(null),c(``),u(``),m(!0)},y=async()=>{f(!0),p?await D(`/api/notes`,{title:s||`Untitled`,content:l}):a&&await D(`/api/notes/${a.id}`,{title:s,content:l}),f(!1),m(!1),h()},b=(e,t)=>{confirm(`Delete note "${t}"?`)&&D(`/api/notes/${e}/delete`,{}).then(h)};return r?(0,k.jsxs)(`div`,{className:Lt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),e(`common.loading`)]}):(0,k.jsxs)(`div`,{className:Lt.root,children:[(0,k.jsxs)(`div`,{className:Lt.sidebar,children:[(0,k.jsx)(`button`,{className:Lt.newBtn,onClick:v,children:`+ New Note`}),t.length===0&&(0,k.jsx)(`div`,{className:Lt.empty,children:e(`notes.noNotes`)}),t.map(e=>(0,k.jsxs)(`div`,{className:`${Lt.noteItem} ${a?.id===e.id?Lt.noteItemActive:``}`,onClick:()=>g(e),children:[(0,k.jsx)(`div`,{className:Lt.noteTitle,children:e.title||`Untitled`}),(0,k.jsx)(`div`,{className:Lt.noteMeta,children:e.updatedAt?new Date(e.updatedAt).toLocaleDateString():``}),e.content&&(0,k.jsx)(`div`,{className:Lt.notePreview,children:e.content.slice(0,150)}),e.tags&&e.tags.length>0&&(0,k.jsx)(`div`,{className:Lt.noteTags,children:e.tags.map(e=>(0,k.jsx)(`span`,{className:Lt.noteTag,children:e},e))})]},e.id))]}),(0,k.jsx)(`div`,{className:Lt.editor,children:a||p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`input`,{className:Lt.titleInput,value:s,onChange:e=>c(e.target.value),placeholder:`Note title…`}),(0,k.jsx)(`textarea`,{className:Lt.contentArea,value:l,onChange:e=>u(e.target.value),placeholder:`Start writing…`}),(0,k.jsxs)(`div`,{className:Lt.editorFooter,children:[a&&(0,k.jsx)(`button`,{className:Lt.delNoteBtn,onClick:()=>b(a.id,a.title),children:e(`common.delete`)}),(0,k.jsx)(`button`,{className:Lt.cancelBtn,onClick:()=>{o(null),m(!1)},children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:Lt.saveBtn,onClick:y,disabled:d,children:d?`Saving…`:`Save`})]})]}):(0,k.jsx)(`div`,{className:Lt.emptyEditor,children:`Select a note or create a new one`})})]})}var zt={root:`_root_18yos_1`,loading:`_loading_18yos_2`,error:`_error_18yos_3`,toolbar:`_toolbar_18yos_5`,search:`_search_18yos_6`,addBtn:`_addBtn_18yos_7`,count:`_count_18yos_10`,empty:`_empty_18yos_12`,grid:`_grid_18yos_14`,card:`_card_18yos_16`,actions:`_actions_18yos_29`,avatar:`_avatar_18yos_31`,avatarImg:`_avatarImg_18yos_38`,info:`_info_18yos_40`,name:`_name_18yos_41`,row:`_row_18yos_42`,email:`_email_18yos_43`,phone:`_phone_18yos_44`,company:`_company_18yos_45`,birthday:`_birthday_18yos_46`,iconBtn:`_iconBtn_18yos_52`,iconBtnRed:`_iconBtnRed_18yos_58`,overlay:`_overlay_18yos_61`,modal:`_modal_18yos_62`,modalTitle:`_modalTitle_18yos_63`,field:`_field_18yos_64`,label:`_label_18yos_65`,input:`_input_18yos_66`,formStatus:`_formStatus_18yos_67`,formError:`_formError_18yos_68`,modalBtns:`_modalBtns_18yos_69`,cancelBtn:`_cancelBtn_18yos_70`,saveBtn:`_saveBtn_18yos_71`},Bt={name:``,email:``,phone:``,company:``,address:``,notes:``};function Vt(){let e=j(),t=te(e=>e.setView),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(!1),[g,v]=(0,_.useState)(``),y=(0,_.useRef)(null),b=(e=``)=>{E(e?`/api/contacts?q=${encodeURIComponent(e)}`:`/api/contacts`).then(e=>{r(e?.contacts??[]),a(!1),s(``)}).catch(()=>{s(`Could not load contacts. Run nha google revoke then nha google auth.`),a(!1)})};(0,_.useEffect)(()=>{b()},[]);let x=e=>{l(e),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>b(e),400)},S=()=>{d(null),p({...Bt}),v(``)},C=e=>{d(e),p({name:e.name,email:e.email??``,phone:e.phone??``,company:e.company??``,address:e.address??``,notes:e.notes??``}),v(``)},w=async()=>{if(f?.name){h(!0),v(`Saving…`);try{if(u?.resourceName){let e=await D(`/api/contacts/update`,{resourceName:u.resourceName,fields:f});if(e?.error){v(`Error: `+e.error);return}}else if(u)await D(`/api/contacts/update`,{resourceName:u.id,fields:f});else{let e=await D(`/api/contacts`,f);if(e?.error){v(`Error: `+e.error);return}}v(`Saved!`),setTimeout(()=>{p(null),d(null),b(c)},800)}catch(e){v(`Error: `+e.message)}finally{h(!1)}}},ee=(e,t)=>{e.stopPropagation(),confirm(`Delete "${t.name}"?`)&&D(`/api/contacts/delete`,{resourceName:t.resourceName||t.id}).then(e=>{let t=e;if(t?.error){alert(`Error: `+t.error);return}b(c)})},T=(e,n,r)=>{e.stopPropagation(),t(`chat`),setTimeout(()=>{let e=document.getElementById(`chatInput`);e&&(e.value=`Send an email to ${r} (${n}) about `,e.focus())},300)},ne=e=>(e||`?`).split(` `).map(e=>e[0]).slice(0,2).join(``).toUpperCase();return i?(0,k.jsxs)(`div`,{className:zt.loading,children:[(0,k.jsx)(`div`,{className:`spinner`}),`Loading contacts…`]}):o?(0,k.jsx)(`div`,{className:zt.error,children:o}):(0,k.jsxs)(`div`,{className:zt.root,children:[(0,k.jsxs)(`div`,{className:zt.toolbar,children:[(0,k.jsx)(`input`,{className:zt.search,value:c,onChange:e=>x(e.target.value),placeholder:`Search contacts…`}),n.length>0&&(0,k.jsxs)(`span`,{className:zt.count,children:[n.length,` contact`,n.length===1?``:`s`]}),(0,k.jsx)(`button`,{className:zt.addBtn,onClick:S,children:`+ Add`})]}),n.length===0&&(0,k.jsxs)(`div`,{className:zt.empty,children:[e(`contacts.noContacts`),(0,k.jsx)(`br`,{}),`Add a Google account or add contacts manually.`]}),(0,k.jsx)(`div`,{className:zt.grid,children:n.map(e=>(0,k.jsxs)(`div`,{className:zt.card,onClick:()=>C(e),children:[(0,k.jsx)(`div`,{className:zt.avatar,children:e.photo?(0,k.jsx)(`img`,{src:e.photo,alt:e.name,className:zt.avatarImg}):ne(e.name)}),(0,k.jsxs)(`div`,{className:zt.info,children:[(0,k.jsx)(`div`,{className:zt.name,children:e.name||`(no name)`}),(0,k.jsxs)(`div`,{className:zt.row,children:[e.email&&(0,k.jsx)(`span`,{className:zt.email,children:e.email}),e.phone&&(0,k.jsx)(`span`,{className:zt.phone,children:e.phone}),e.company&&(0,k.jsxs)(`span`,{className:zt.company,children:[e.company,e.title?` · ${e.title}`:``]}),e.birthday&&(0,k.jsxs)(`span`,{className:zt.birthday,children:[`🎂 `,e.birthday]})]})]}),(0,k.jsxs)(`div`,{className:zt.actions,children:[e.email&&(0,k.jsx)(`button`,{className:zt.iconBtn,onClick:t=>T(t,e.email,e.name),title:`Send email via chat`,children:`✉`}),(0,k.jsx)(`button`,{className:zt.iconBtn,onClick:t=>{t.stopPropagation(),C(e)},title:`Edit`,children:`✎`}),(0,k.jsx)(`button`,{className:`${zt.iconBtn} ${zt.iconBtnRed}`,onClick:t=>ee(t,e),title:`Delete`,children:`✕`})]})]},e.id))}),f&&(0,k.jsx)(`div`,{className:zt.overlay,onClick:e=>{e.target===e.currentTarget&&p(null)},children:(0,k.jsxs)(`div`,{className:zt.modal,children:[(0,k.jsx)(`div`,{className:zt.modalTitle,children:u?`Edit Contact`:`New Contact`}),[[`name`,`Name`,`Full name *`],[`email`,`Email`,`user@example.com`],[`phone`,`Phone`,`+1 555 123 4567`],[`company`,`Company`,`Acme Inc`],[`address`,`Address`,`123 Main St, New York`],[`notes`,`Notes`,`Any additional info`]].map(([e,t,n])=>(0,k.jsxs)(`div`,{className:zt.field,children:[(0,k.jsx)(`label`,{className:zt.label,children:t}),(0,k.jsx)(`input`,{className:zt.input,value:f[e],onChange:t=>p(n=>n&&{...n,[e]:t.target.value}),placeholder:n,onKeyDown:t=>t.key===`Enter`&&e===`name`&&w()})]},e)),g&&(0,k.jsx)(`div`,{className:g.startsWith(`Error`)?zt.formError:zt.formStatus,children:g}),(0,k.jsxs)(`div`,{className:zt.modalBtns,children:[(0,k.jsx)(`button`,{className:zt.cancelBtn,onClick:()=>p(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:zt.saveBtn,onClick:w,disabled:m||!f.name,children:m?`…`:`Save`})]})]})})]})}var V={root:`_root_1hm4q_2`,topbar:`_topbar_1hm4q_11`,topbarLeft:`_topbarLeft_1hm4q_20`,topbarTitle:`_topbarTitle_1hm4q_21`,topbarSub:`_topbarSub_1hm4q_22`,topbarActions:`_topbarActions_1hm4q_23`,runBtn:`_runBtn_1hm4q_25`,runBtnActive:`_runBtnActive_1hm4q_32`,logBtn:`_logBtn_1hm4q_34`,newWfBtn:`_newWfBtn_1hm4q_41`,body:`_body_1hm4q_50`,sidebar:`_sidebar_1hm4q_53`,sidebarTitle:`_sidebarTitle_1hm4q_61`,sidebarEmpty:`_sidebarEmpty_1hm4q_65`,wfItem:`_wfItem_1hm4q_67`,wfItemActive:`_wfItemActive_1hm4q_78`,wfItemRow:`_wfItemRow_1hm4q_79`,wfItemName:`_wfItemName_1hm4q_80`,wfItemMeta:`_wfItemMeta_1hm4q_81`,wfOn:`_wfOn_1hm4q_82`,wfOff:`_wfOff_1hm4q_83`,wfDelBtn:`_wfDelBtn_1hm4q_84`,canvasArea:`_canvasArea_1hm4q_92`,canvasHeader:`_canvasHeader_1hm4q_94`,wfNameInput:`_wfNameInput_1hm4q_99`,canvasHint:`_canvasHint_1hm4q_106`,portHint:`_portHint_1hm4q_107`,connectHint:`_connectHint_1hm4q_108`,cancelConnectBtn:`_cancelConnectBtn_1hm4q_109`,canvas:`_canvas_1hm4q_92`,canvasConnecting:`_canvasConnecting_1hm4q_122`,canvasSvg:`_canvasSvg_1hm4q_124`,canvasNode:`_canvasNode_1hm4q_134`,canvasNodeSelected:`_canvasNodeSelected_1hm4q_152`,canvasNodeConnecting:`_canvasNodeConnecting_1hm4q_153`,nodeIcon:`_nodeIcon_1hm4q_155`,nodeLabel:`_nodeLabel_1hm4q_156`,nodeConfigPreview:`_nodeConfigPreview_1hm4q_157`,nodeDelBtn:`_nodeDelBtn_1hm4q_159`,portOut:`_portOut_1hm4q_171`,portActive:`_portActive_1hm4q_182`,portIn:`_portIn_1hm4q_184`,pulse:`_pulse_1hm4q_1`,canvasDrop:`_canvasDrop_1hm4q_195`,canvasEmpty:`_canvasEmpty_1hm4q_203`,canvasEmptyIcon:`_canvasEmptyIcon_1hm4q_208`,canvasEmptyTitle:`_canvasEmptyTitle_1hm4q_209`,canvasEmptyDesc:`_canvasEmptyDesc_1hm4q_210`,logPanel:`_logPanel_1hm4q_213`,logHeader:`_logHeader_1hm4q_220`,logTime:`_logTime_1hm4q_226`,logClose:`_logClose_1hm4q_227`,logEmpty:`_logEmpty_1hm4q_228`,logStep:`_logStep_1hm4q_229`,logStepError:`_logStepError_1hm4q_230`,logStepHeader:`_logStepHeader_1hm4q_231`,logStepIcon:`_logStepIcon_1hm4q_232`,logStepLabel:`_logStepLabel_1hm4q_233`,logStepErrBadge:`_logStepErrBadge_1hm4q_234`,logStepErr:`_logStepErr_1hm4q_230`,logStepOutput:`_logStepOutput_1hm4q_236`,rightPanel:`_rightPanel_1hm4q_241`,configPanel:`_configPanel_1hm4q_252`,configHeader:`_configHeader_1hm4q_253`,configClose:`_configClose_1hm4q_254`,configDesc:`_configDesc_1hm4q_255`,configFields:`_configFields_1hm4q_256`,configField:`_configField_1hm4q_256`,configLabel:`_configLabel_1hm4q_258`,configRequired:`_configRequired_1hm4q_259`,configInput:`_configInput_1hm4q_260`,configTextarea:`_configTextarea_1hm4q_267`,zoomControls:`_zoomControls_1hm4q_277`,configHint:`_configHint_1hm4q_303`,configDelete:`_configDelete_1hm4q_305`,palette:`_palette_1hm4q_309`,paletteTitle:`_paletteTitle_1hm4q_310`,paletteTabs:`_paletteTabs_1hm4q_311`,paletteTab:`_paletteTab_1hm4q_311`,paletteTabActive:`_paletteTabActive_1hm4q_317`,paletteNodes:`_paletteNodes_1hm4q_318`,paletteDef:`_paletteDef_1hm4q_320`,paletteDefIcon:`_paletteDefIcon_1hm4q_328`,paletteDefLabel:`_paletteDefLabel_1hm4q_329`,paletteDefDesc:`_paletteDefDesc_1hm4q_330`,paletteFooter:`_paletteFooter_1hm4q_332`,paletteGuide:`_paletteGuide_1hm4q_336`,guideTitle:`_guideTitle_1hm4q_344`,guideStep:`_guideStep_1hm4q_353`,guideNum:`_guideNum_1hm4q_361`,guideTip:`_guideTip_1hm4q_377`,guideCode:`_guideCode_1hm4q_388`},Ht=[{id:`trigger_manual`,type:`trigger`,label:`Manual`,icon:`▶`,color:`#6366f1`,description:`Run manually with optional text input.`,configFields:[{key:`input`,label:`Input text`,placeholder:`Optional initial input`}]},{id:`trigger_cron`,type:`trigger`,label:`Cron`,icon:`⏰`,color:`#fbbf24`,description:`Run on a schedule (cron expression).`,configFields:[{key:`schedule`,label:`Cron expression`,placeholder:`0 8 * * *`,required:!0}]},{id:`trigger_email`,type:`trigger`,label:`New Email`,icon:`📧`,color:`#38bdf8`,description:`Trigger when a new email arrives matching a filter.`,configFields:[{key:`filter`,label:`Gmail filter`,placeholder:`subject:TODO is:unread`}]},{id:`trigger_webhook`,type:`trigger`,label:`Webhook`,icon:`🔗`,color:`#a5b4fc`,description:`Trigger via HTTP POST/GET/PUT/DELETE. URL: http://localhost:3847/api/webhooks/<slug>`,configFields:[{key:`slug`,label:`Slug (URL path)`,placeholder:`my-trigger`,required:!0}]},{id:`action_email`,type:`action`,label:`Send Email`,icon:`✉`,color:`#38bdf8`,description:`Send email via Gmail or IMAP.`,configFields:[{key:`to`,label:`To`,placeholder:`email@example.com`,required:!0},{key:`subject`,label:`Subject`,placeholder:`Subject or {{output}}`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`action_slack`,type:`action`,label:`Slack Message`,icon:`💬`,color:`#818cf8`,description:`Post a message to a Slack channel.`,configFields:[{key:`channel`,label:`Channel`,placeholder:`#general`,required:!0},{key:`text`,label:`Text`,placeholder:`{{output}}`}]},{id:`action_calendar`,type:`action`,label:`Create Event`,icon:`📅`,color:`#4ade80`,description:`Create a Google Calendar event.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`date`,label:`Date (YYYY-MM-DD)`,placeholder:`2025-01-15`},{key:`time`,label:`Time (HH:MM)`,placeholder:`09:00`}]},{id:`action_task`,type:`action`,label:`Create Task`,icon:`✅`,color:`#fbbf24`,description:`Add a task to your task list.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`priority`,label:`Priority`,placeholder:`medium`}]},{id:`action_drive`,type:`action`,label:`Save to Drive`,icon:`💾`,color:`#a78bfa`,description:`Save a text file to Google Drive.`,configFields:[{key:`name`,label:`Filename`,placeholder:`output.txt`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_notion`,type:`action`,label:`Notion Page`,icon:`📋`,color:`#e4e4e7`,description:`Create or update a Notion page.`,configFields:[{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_github`,type:`action`,label:`GitHub Issue`,icon:`🐙`,color:`#6ee7b7`,description:`Create a GitHub issue.`,configFields:[{key:`repo`,label:`Repo (owner/name)`,placeholder:`user/repo`,required:!0},{key:`title`,label:`Title`,placeholder:`{{output}}`,required:!0},{key:`body`,label:`Body`,placeholder:``}]},{id:`action_webhook`,type:`action`,label:`HTTP Request`,icon:`🌐`,color:`#38bdf8`,description:`Make an HTTP request.`,configFields:[{key:`url`,label:`URL`,placeholder:`https://…`,required:!0},{key:`method`,label:`Method`,placeholder:`POST`},{key:`body`,label:`Body`,placeholder:`{{output}}`}]},{id:`ai_agent`,type:`ai`,label:`Run Agent`,icon:`🤖`,color:`#818cf8`,description:`Run any of the 38 NHA specialist agents.`,configFields:[{key:`agent`,label:`Agent name`,placeholder:`herald, saber, forge…`,required:!0},{key:`prompt`,label:`Prompt`,placeholder:`Summarize this: {{output}}`,required:!0}]},{id:`ai_summarize`,type:`ai`,label:`Summarize`,icon:`📝`,color:`#a5b4fc`,description:`Summarize text with AI (free via Liara).`,configFields:[{key:`prompt`,label:`Prompt`,placeholder:`Summarize: {{output}}`}]},{id:`ai_classify`,type:`ai`,label:`Classify`,icon:`🏷`,color:`#a5b4fc`,description:`Classify content into categories.`,configFields:[{key:`categories`,label:`Categories (comma-separated)`,placeholder:`urgent, normal, spam`},{key:`prompt`,label:`Prompt`,placeholder:`Classify this email: {{output}}`}]},{id:`ai_extract`,type:`ai`,label:`Extract Data`,icon:`🔍`,color:`#a5b4fc`,description:`Extract structured data from text.`,configFields:[{key:`prompt`,label:`What to extract`,placeholder:`Extract name, email, date from: {{output}}`}]},{id:`ai_translate`,type:`ai`,label:`Translate`,icon:`🌍`,color:`#a5b4fc`,description:`Translate text to another language.`,configFields:[{key:`lang`,label:`Target language`,placeholder:`Italian`,required:!0},{key:`prompt`,label:`Text`,placeholder:`{{output}}`}]},{id:`ai_code`,type:`ai`,label:`Code (JS)`,icon:`💻`,color:`#818cf8`,description:"Execute JavaScript code. Access previous output via `input` variable. Return a value.",configFields:[{key:`code`,label:`JavaScript code`,placeholder:`const data = JSON.parse(input);
654
654
  return data.map(x => x.name).join(", ");`,type:`textarea`}]},{id:`logic_if`,type:`logic`,label:`If / Condition`,icon:`🔀`,color:`#f59e0b`,description:`Branch based on a condition. Outputs to "true" or "false" path.`,configFields:[{key:`condition`,label:`Condition (JS expression)`,placeholder:`{{output}}.includes("urgent")`,required:!0}],outputs:[`true`,`false`]},{id:`logic_switch`,type:`logic`,label:`Switch`,icon:`🔄`,color:`#f59e0b`,description:`Route to different paths based on value. Add cases as comma-separated values.`,configFields:[{key:`expression`,label:`Expression`,placeholder:`{{output}}`,required:!0},{key:`cases`,label:`Cases (comma-separated)`,placeholder:`urgent, normal, spam`,required:!0}]},{id:`logic_loop`,type:`logic`,label:`Loop / For Each`,icon:`🔁`,color:`#f59e0b`,description:`Iterate over items. Input should be JSON array or newline-separated text.`,configFields:[{key:`separator`,label:`Separator`,placeholder:`\\n (newline) or , (comma)`}]},{id:`logic_merge`,type:`logic`,label:`Merge`,icon:`🔗`,color:`#f59e0b`,description:`Merge outputs from multiple branches into one.`,configFields:[{key:`mode`,label:`Mode`,placeholder:`concat`,type:`select`,options:[`concat`,`json_array`,`first_non_empty`]}]},{id:`logic_delay`,type:`logic`,label:`Delay`,icon:`⏳`,color:`#f59e0b`,description:`Wait before continuing.`,configFields:[{key:`seconds`,label:`Seconds`,placeholder:`5`,required:!0}]},{id:`logic_error`,type:`logic`,label:`Error Handler`,icon:`🛡`,color:`#ef4444`,description:`Catch errors from previous nodes. Configure retry count and fallback behavior.`,configFields:[{key:`retries`,label:`Max retries`,placeholder:`3`},{key:`fallback`,label:`Fallback output`,placeholder:`Default value if all retries fail`}]},{id:`logic_subworkflow`,type:`logic`,label:`Subworkflow`,icon:`🪆`,color:`#a855f7`,description:`Run another workflow inline. Output of the sub becomes this node's output. Max nesting depth 5.`,configFields:[{key:`workflowId`,label:`Target workflow ID`,placeholder:`wf_abc123`,required:!0},{key:`inputMapping`,label:`Input expression`,placeholder:`{{output}} (default)`}]},{id:`action_browser`,type:`action`,label:`Open URL`,icon:`🌐`,color:`#60a5fa`,description:`Open a URL in headless browser and extract text content.`,configFields:[{key:`url`,label:`URL`,placeholder:`https://example.com or {{output}}`,required:!0}]},{id:`action_file_read`,type:`action`,label:`Read File`,icon:`📖`,color:`#4ade80`,description:`Read a file from the filesystem.`,configFields:[{key:`path`,label:`File path`,placeholder:`/path/to/file.txt`,required:!0}]},{id:`action_file_write`,type:`action`,label:`Write File`,icon:`📝`,color:`#4ade80`,description:`Write content to a file.`,configFields:[{key:`path`,label:`File path`,placeholder:`/path/to/output.txt`,required:!0},{key:`content`,label:`Content`,placeholder:`{{output}}`}]},{id:`action_contact`,type:`action`,label:`Find Contact`,icon:`👤`,color:`#38bdf8`,description:`Search Google Contacts by name or email.`,configFields:[{key:`query`,label:`Search query`,placeholder:`John or john@example.com`,required:!0}]},{id:`action_screen`,type:`action`,label:`Screenshot`,icon:`📸`,color:`#c084fc`,description:`Take a screenshot of the screen.`,configFields:[]},{id:`action_maps`,type:`action`,label:`Maps Directions`,icon:`🗺`,color:`#4ade80`,description:`Get directions between two locations.`,configFields:[{key:`from`,label:`From`,placeholder:`Milan`,required:!0},{key:`to`,label:`To`,placeholder:`Rome`,required:!0}]},{id:`action_notify`,type:`action`,label:`Notification`,icon:`🔔`,color:`#fbbf24`,description:`Send a system notification or Telegram message.`,configFields:[{key:`message`,label:`Message`,placeholder:`{{output}}`,required:!0},{key:`channel`,label:`Channel`,placeholder:`telegram or system`,type:`select`,options:[`system`,`telegram`]}]}],Ut=Object.fromEntries(Ht.map(e=>[e.id,e])),Wt=90,Gt=72;function Kt(){return`n_${Date.now()}_${Math.random().toString(36).slice(2,6)}`}function qt(e,t){return{x:e.x+(t===`out`?Wt:0),y:e.y+Gt/2}}function Jt(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(`trigger`),[g,v]=(0,_.useState)(1),[y,b]=(0,_.useState)({x:0,y:0}),x=(0,_.useRef)(!1),S=(0,_.useRef)({x:0,y:0,px:0,py:0}),C=(0,_.useRef)(null),w=(0,_.useRef)(null),ee=(0,_.useRef)(null),T=(0,_.useCallback)(async()=>{let e=(await E(`/api/workflows`).catch(()=>null))?.workflows??[];t(e),r(t=>t?e.find(e=>e.id===t.id)??e[0]??null:e[0]??null)},[]);(0,_.useEffect)(()=>{T()},[T]);let te=(0,_.useCallback)(async e=>{r(e),t(t=>t.map(t=>t.id===e.id?e:t)),await D(`/api/workflows/${e.id}`,e,`PUT`).catch(()=>null)},[]),ne=async()=>{let e={id:`wf_${Date.now()}`,name:`New Workflow`,enabled:!1,nodes:[],edges:[],nodeDefs:Ht},n=(await D(`/api/workflows`,e).catch(()=>null))?.workflow??e;t(e=>[...e,n]),r(n),a(null),d([]),p(!1)},re=async e=>{confirm(`Delete this workflow?`)&&(await D(`/api/workflows/${e}`,{},`DELETE`).catch(()=>null),T())},ie=(0,_.useCallback)(e=>{e.preventDefault();let t=w.current;if(!t||!n)return;let r=ee.current.getBoundingClientRect(),i=Math.round((e.clientX-r.left-Wt/2)/20)*20,o=Math.round((e.clientY-r.top-Gt/2)/20)*20,s={id:Kt(),defId:t,x:Math.max(0,i),y:Math.max(0,o),config:{}};te({...n,nodes:[...n.nodes,s]}),a(s.id),w.current=null},[n,te]),O=(0,_.useCallback)((e,t)=>{if(e.stopPropagation(),o){o!==t&&n&&(n.edges.some(e=>e.from===o&&e.to===t)||te({...n,edges:[...n.edges,{from:o,to:t}]})),s(null);return}a(t);let r=n?.nodes.find(e=>e.id===t);r&&(C.current={id:t,ox:e.clientX-r.x,oy:e.clientY-r.y})},[o,n,te]),ae=(0,_.useCallback)(e=>{if(!C.current||!n)return;let{id:t,ox:i,oy:a}=C.current,o=e.clientX-i,s=e.clientY-a,c=Math.max(0,Math.round(o/20)*20),l=Math.max(0,Math.round(s/20)*20);r(e=>e&&{...e,nodes:e.nodes.map(e=>e.id===t?{...e,x:c,y:l}:e)})},[n]),A=(0,_.useCallback)(()=>{if(!C.current||!n){C.current=null;return}n.nodes.find(e=>e.id===C.current.id)&&te(n),C.current=null},[n,te]),oe=(0,_.useCallback)(e=>{n&&(te({...n,nodes:n.nodes.filter(t=>t.id!==e),edges:n.edges.filter(t=>t.from!==e&&t.to!==e)}),a(null))},[n,te]),se=(0,_.useCallback)((e,t)=>{n&&te({...n,edges:n.edges.filter(n=>!(n.from===e&&n.to===t))})},[n,te]),ce=(0,_.useCallback)((e,i,a)=>{if(!n)return;let o={...n,nodes:n.nodes.map(t=>t.id===e?{...t,config:{...t.config,[i]:a}}:t)};r(o),t(e=>e.map(e=>e.id===o.id?o:e))},[n]),le=(0,_.useCallback)(()=>{n&&te(n)},[n,te]),ue=async()=>{if(!(!n||c)){l(!0),p(!0),d([]);try{let e={...n,nodeDefs:Ht};await D(`/api/workflows/${n.id}`,e,`PUT`).catch(()=>null),d((await D(`/api/workflows/${n.id}/run`,{}))?.steps??[]),T()}catch(e){d([{nodeId:`__error`,nodeLabel:`Error`,nodeIcon:`❌`,output:``,error:e.message}])}finally{l(!1)}}},de=async e=>{let i={...e,enabled:!e.enabled};await D(`/api/workflows/${e.id}`,i,`PUT`).catch(()=>null),t(t=>t.map(t=>t.id===e.id?i:t)),n?.id===e.id&&r(i)},j=n?.nodes.find(e=>e.id===i)??null,M=j?Ut[j.defId]:null;return(0,k.jsxs)(`div`,{className:V.root,children:[(0,k.jsxs)(`div`,{className:V.topbar,children:[(0,k.jsxs)(`div`,{className:V.topbarLeft,children:[(0,k.jsx)(`span`,{className:V.topbarTitle,children:`AWF - AutoWorkFlow`}),(0,k.jsx)(`span`,{className:V.topbarSub,children:`Visual workflow automation · 80 tools · 38 AI agents · free AI via Liara`})]}),(0,k.jsxs)(`div`,{className:V.topbarActions,children:[n&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:`${V.runBtn} ${c?V.runBtnActive:``}`,onClick:ue,disabled:c||n.nodes.length===0,children:c?`⏳ Running…`:`▶ Run`}),(0,k.jsx)(`button`,{className:V.logBtn,onClick:()=>p(e=>!e),children:f?`Hide Log`:`📋 Log`})]}),(0,k.jsx)(`button`,{className:V.newWfBtn,onClick:ne,children:`+ New Workflow`})]})]}),(0,k.jsxs)(`div`,{className:V.body,children:[(0,k.jsxs)(`div`,{className:V.sidebar,children:[(0,k.jsx)(`div`,{className:V.sidebarTitle,children:`Workflows`}),e.length===0&&(0,k.jsxs)(`div`,{className:V.sidebarEmpty,children:[`No workflows yet.`,(0,k.jsx)(`br`,{}),`Click "New Workflow" to start.`]}),e.map(e=>(0,k.jsxs)(`div`,{className:`${V.wfItem} ${n?.id===e.id?V.wfItemActive:``}`,onClick:()=>{r(e),a(null),d(e.lastRun?.steps??[]),p(!1)},children:[(0,k.jsxs)(`div`,{className:V.wfItemRow,children:[(0,k.jsx)(`span`,{className:V.wfItemName,children:e.name}),(0,k.jsx)(`button`,{className:e.enabled?V.wfOn:V.wfOff,onClick:t=>{t.stopPropagation(),de(e)},children:e.enabled?`ON`:`OFF`})]}),(0,k.jsxs)(`div`,{className:V.wfItemMeta,children:[e.nodes.length,` nodes · `,e.edges.length,` edges`,e.lastRun&&(0,k.jsxs)(`span`,{children:[` · ran `,new Date(e.lastRun.at).toLocaleTimeString()]})]}),(0,k.jsx)(`button`,{className:V.wfDelBtn,onClick:t=>{t.stopPropagation(),re(e.id)},children:`✕`})]},e.id))]}),(0,k.jsx)(`div`,{className:V.canvasArea,children:n?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:V.canvasHeader,children:[(0,k.jsx)(`input`,{className:V.wfNameInput,value:n.name,onChange:e=>r(t=>t&&{...t,name:e.target.value}),onBlur:()=>n&&te(n)}),o?(0,k.jsxs)(`span`,{className:V.connectHint,children:[`Click a target node to connect · `,(0,k.jsx)(`button`,{className:V.cancelConnectBtn,onClick:()=>s(null),children:`Cancel`})]}):(0,k.jsxs)(`span`,{className:V.canvasHint,children:[`Drag nodes from palette · Click `,(0,k.jsx)(`span`,{className:V.portHint,children:`▶`}),` to connect · Drag nodes to reposition`]})]}),(0,k.jsxs)(`div`,{ref:ee,className:`${V.canvas} ${o?V.canvasConnecting:``}`,onMouseMove:e=>{if(x.current){b({x:S.current.px+(e.clientX-S.current.x),y:S.current.py+(e.clientY-S.current.y)});return}ae(e)},onMouseDown:e=>{e.button===1&&(e.preventDefault(),x.current=!0,S.current={x:e.clientX,y:e.clientY,px:y.x,py:y.y})},onMouseUp:()=>{x.current=!1,A()},onMouseLeave:()=>{x.current=!1,A()},onWheel:e=>{if(e.preventDefault(),e.ctrlKey||e.metaKey){let t=e.deltaY>0?-.1:.1;v(e=>Math.max(.3,Math.min(2,e+t)))}else b(t=>({x:t.x-e.deltaX,y:t.y-e.deltaY}))},onDragOver:e=>e.preventDefault(),onDrop:ie,onClick:()=>{o||a(null)},children:[(0,k.jsxs)(`div`,{className:V.zoomControls,children:[(0,k.jsx)(`button`,{onClick:()=>v(e=>Math.min(2,e+.1)),children:`+`}),(0,k.jsxs)(`span`,{children:[Math.round(g*100),`%`]}),(0,k.jsx)(`button`,{onClick:()=>v(e=>Math.max(.3,e-.1)),children:`−`}),(0,k.jsx)(`button`,{onClick:()=>{v(1),b({x:0,y:0})},children:`⊙`})]}),(0,k.jsxs)(`div`,{style:{transform:`translate(${y.x}px, ${y.y}px) scale(${g})`,transformOrigin:`0 0`,position:`absolute`,inset:0},children:[(0,k.jsx)(`svg`,{className:V.canvasSvg,children:n.edges.map((e,t)=>{let r=n.nodes.find(t=>t.id===e.from),i=n.nodes.find(t=>t.id===e.to);if(!r||!i)return null;let a=qt(r,`out`),o=qt(i,`in`),s=(a.x+o.x)/2;return(0,k.jsxs)(`g`,{children:[(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`var(--green3)`,strokeWidth:`2`,fill:`none`,strokeDasharray:`6,3`,opacity:`0.8`}),(0,k.jsx)(`path`,{d:`M${a.x},${a.y} C${s},${a.y} ${s},${o.y} ${o.x},${o.y}`,stroke:`transparent`,strokeWidth:`12`,fill:`none`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),se(e.from,e.to)}}),(0,k.jsx)(`circle`,{cx:s,cy:(a.y+o.y)/2,r:`7`,fill:`var(--bg2)`,stroke:`var(--border)`,strokeWidth:`1.5`,style:{cursor:`pointer`},onClick:t=>{t.stopPropagation(),se(e.from,e.to)}}),(0,k.jsx)(`text`,{x:s,y:(a.y+o.y)/2+4,textAnchor:`middle`,fill:`var(--dim)`,fontSize:`9`,style:{cursor:`pointer`,pointerEvents:`none`},children:`✕`})]},t)})}),n.nodes.map(e=>{let t=Ut[e.defId];if(!t)return null;let n=i===e.id,r=o===e.id;return(0,k.jsxs)(`div`,{className:`${V.canvasNode} ${n?V.canvasNodeSelected:``} ${r?V.canvasNodeConnecting:``}`,style:{left:e.x,top:e.y,borderColor:t.color+(n?`ff`:`88`),background:t.color+`18`},onMouseDown:t=>O(t,e.id),onClick:e=>e.stopPropagation(),children:[(0,k.jsx)(`button`,{className:V.nodeDelBtn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),oe(e.id)},children:`✕`}),(0,k.jsx)(`span`,{className:V.nodeIcon,children:t.icon}),(0,k.jsx)(`span`,{className:V.nodeLabel,style:{color:t.color},children:t.label}),Object.values(e.config).filter(Boolean).slice(0,1).map((e,t)=>(0,k.jsx)(`span`,{className:V.nodeConfigPreview,children:String(e).slice(0,14)},t)),(0,k.jsx)(`button`,{className:`${V.portOut} ${r?V.portActive:``}`,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),s(t=>t===e.id?null:e.id)},title:`Connect from here`,children:`▶`}),o&&o!==e.id&&(0,k.jsx)(`button`,{className:V.portIn,onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),O(t,e.id)},title:`Connect here`,children:`◀`})]},e.id)}),n.nodes.length===0&&(0,k.jsx)(`div`,{className:V.canvasDrop,children:`Drag nodes from the right panel and drop here`})]})]}),f&&(0,k.jsxs)(`div`,{className:V.logPanel,children:[(0,k.jsxs)(`div`,{className:V.logHeader,children:[(0,k.jsx)(`span`,{children:`Run Log`}),n.lastRun&&(0,k.jsx)(`span`,{className:V.logTime,children:new Date(n.lastRun.at).toLocaleString()}),(0,k.jsx)(`button`,{className:V.logClose,onClick:()=>p(!1),children:`✕`})]}),u.length===0&&(0,k.jsx)(`div`,{className:V.logEmpty,children:c?`Running…`:`No run results yet.`}),u.map((e,t)=>(0,k.jsxs)(`div`,{className:`${V.logStep} ${e.error?V.logStepError:``}`,children:[(0,k.jsxs)(`div`,{className:V.logStepHeader,children:[(0,k.jsx)(`span`,{className:V.logStepIcon,children:e.nodeIcon}),(0,k.jsx)(`span`,{className:V.logStepLabel,children:e.nodeLabel}),e.error&&(0,k.jsx)(`span`,{className:V.logStepErrBadge,children:`ERROR`})]}),e.error&&(0,k.jsx)(`div`,{className:V.logStepErr,children:e.error}),e.output&&(0,k.jsx)(`div`,{className:V.logStepOutput,dangerouslySetInnerHTML:{__html:Se(e.output.slice(0,500))}})]},t))]})]}):(0,k.jsxs)(`div`,{className:V.canvasEmpty,children:[(0,k.jsx)(`div`,{className:V.canvasEmptyIcon,children:`🔗`}),(0,k.jsx)(`div`,{className:V.canvasEmptyTitle,children:`Select or create a workflow`}),(0,k.jsxs)(`div`,{className:V.canvasEmptyDesc,children:[`Drag nodes from the right panel onto the canvas.`,(0,k.jsx)(`br`,{}),`Connect them by clicking the `,(0,k.jsx)(`span`,{className:V.portHint,children:`▶`}),` output port then the target node.`,(0,k.jsx)(`br`,{}),`Run with one click — all 80 NHA tools already authenticated.`]}),(0,k.jsx)(`button`,{className:V.newWfBtn,onClick:ne,children:`+ New Workflow`})]})}),(0,k.jsx)(`div`,{className:V.rightPanel,children:j&&M?(0,k.jsxs)(`div`,{className:V.configPanel,children:[(0,k.jsxs)(`div`,{className:V.configHeader,children:[(0,k.jsxs)(`span`,{style:{color:M.color},children:[M.icon,` `,M.label]}),(0,k.jsx)(`button`,{className:V.configClose,onClick:()=>a(null),children:`✕`})]}),(0,k.jsx)(`div`,{className:V.configDesc,children:M.description}),(0,k.jsx)(`div`,{className:V.configFields,children:(M.configFields??[]).map(e=>(0,k.jsxs)(`div`,{className:V.configField,children:[(0,k.jsxs)(`label`,{className:V.configLabel,children:[e.label,e.required&&(0,k.jsx)(`span`,{className:V.configRequired,children:`*`})]}),e.type===`textarea`?(0,k.jsx)(`textarea`,{className:V.configTextarea,value:j.config[e.key]??``,placeholder:e.placeholder??``,onChange:t=>ce(j.id,e.key,t.target.value),onBlur:le,rows:4}):e.type===`select`&&e.options?(0,k.jsx)(`select`,{className:V.configInput,value:j.config[e.key]??e.options[0]??``,onChange:t=>{ce(j.id,e.key,t.target.value),le()},children:e.options.map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))}):(0,k.jsx)(`input`,{className:V.configInput,value:j.config[e.key]??``,placeholder:e.placeholder??``,onChange:t=>ce(j.id,e.key,t.target.value),onBlur:le}),(e.placeholder?.includes(`{{`)??!1)&&(0,k.jsxs)(`div`,{className:V.configHint,children:[`Use `,(0,k.jsx)(`code`,{children:`{{output}}`}),` to pass previous node result`]})]},e.key))}),(0,k.jsx)(`button`,{className:V.configDelete,onClick:()=>oe(j.id),children:`Delete node`})]}):(0,k.jsxs)(`div`,{className:V.palette,children:[(0,k.jsx)(`div`,{className:V.paletteTitle,children:`Node Palette`}),(0,k.jsx)(`div`,{className:V.paletteTabs,children:[{id:`trigger`,label:`Triggers`,color:`#fbbf24`},{id:`action`,label:`Actions`,color:`#38bdf8`},{id:`ai`,label:`AI`,color:`#a5b4fc`},{id:`logic`,label:`Logic`,color:`#f59e0b`}].map(e=>(0,k.jsx)(`button`,{className:`${V.paletteTab} ${m===e.id?V.paletteTabActive:``}`,style:m===e.id?{borderColor:e.color,color:e.color}:{},onClick:()=>h(e.id),children:e.label},e.id))}),(0,k.jsx)(`div`,{className:V.paletteNodes,children:Ht.filter(e=>e.type===m).map(e=>(0,k.jsxs)(`div`,{className:V.paletteDef,style:{borderColor:e.color+`44`,background:e.color+`14`},draggable:!0,onDragStart:()=>{w.current=e.id},onDragEnd:()=>{w.current=null},children:[(0,k.jsx)(`span`,{className:V.paletteDefIcon,children:e.icon}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:V.paletteDefLabel,style:{color:e.color},children:e.label}),(0,k.jsx)(`div`,{className:V.paletteDefDesc,children:e.description})]})]},e.id))}),(0,k.jsxs)(`div`,{className:V.paletteGuide,children:[(0,k.jsx)(`div`,{className:V.guideTitle,children:`How to use AWF`}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`1`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Create`}),` a workflow with "+ New Workflow"`]})]}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`2`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` a Trigger node (e.g. Manual, Cron) onto the canvas`]})]}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`3`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Drag`}),` Action or AI nodes to chain operations`]})]}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`4`}),(0,k.jsxs)(`span`,{children:[`Click the `,(0,k.jsx)(`strong`,{style:{color:`var(--green3)`},children:`▶`}),` port on a node then click the next to `,(0,k.jsx)(`strong`,{children:`connect`}),` them`]})]}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`5`}),(0,k.jsxs)(`span`,{children:[(0,k.jsx)(`strong`,{children:`Click`}),` a node to configure it — use `,(0,k.jsx)(`code`,{className:V.guideCode,children:`{{output}}`}),` to pass the previous result`]})]}),(0,k.jsxs)(`div`,{className:V.guideStep,children:[(0,k.jsx)(`span`,{className:V.guideNum,children:`6`}),(0,k.jsxs)(`span`,{children:[`Press `,(0,k.jsx)(`strong`,{children:`▶ Run`}),` to execute · toggle `,(0,k.jsx)(`strong`,{children:`ON`}),` to run automatically (cron/webhook)`]})]}),(0,k.jsxs)(`div`,{className:V.guideTip,children:[(0,k.jsx)(`strong`,{children:`Tip:`}),` Click an edge to delete it. Drag nodes on the canvas to reposition. All 80 NHA tools are pre-authenticated — no extra setup.`]}),(0,k.jsxs)(`div`,{className:V.guideTip,children:[(0,k.jsx)(`strong`,{children:`AI nodes`}),` use Liara (free) by default. They receive `,(0,k.jsx)(`code`,{className:V.guideCode,children:`{{output}}`}),` from the previous step automatically.`]})]})]})})]})]})}var H={root:`_root_1ssbe_1`,sidebar:`_sidebar_1ssbe_12`,sidebarSection:`_sidebarSection_1ssbe_23`,sidebarLabel:`_sidebarLabel_1ssbe_28`,accountSelect:`_accountSelect_1ssbe_36`,sidebarCompose:`_sidebarCompose_1ssbe_46`,composeBtn:`_composeBtn_1ssbe_51`,folderList:`_folderList_1ssbe_63`,folderItem:`_folderItem_1ssbe_69`,folderActive:`_folderActive_1ssbe_82`,badge:`_badge_1ssbe_88`,labelHeader:`_labelHeader_1ssbe_103`,addLabelBtn:`_addLabelBtn_1ssbe_114`,newLabelRow:`_newLabelRow_1ssbe_123`,newLabelInput:`_newLabelInput_1ssbe_129`,newLabelSave:`_newLabelSave_1ssbe_139`,labelDot:`_labelDot_1ssbe_150`,syncArea:`_syncArea_1ssbe_158`,syncBtn:`_syncBtn_1ssbe_163`,messageList:`_messageList_1ssbe_175`,listHeader:`_listHeader_1ssbe_185`,searchInput:`_searchInput_1ssbe_194`,searchBtn:`_searchBtn_1ssbe_204`,listBody:`_listBody_1ssbe_214`,listLoading:`_listLoading_1ssbe_219`,noMessages:`_noMessages_1ssbe_224`,msgRow:`_msgRow_1ssbe_231`,msgUnread:`_msgUnread_1ssbe_242`,msgActive:`_msgActive_1ssbe_247`,msgTop:`_msgTop_1ssbe_251`,msgFrom:`_msgFrom_1ssbe_257`,msgDate:`_msgDate_1ssbe_270`,msgSubject:`_msgSubject_1ssbe_277`,msgPreview:`_msgPreview_1ssbe_289`,listFooter:`_listFooter_1ssbe_300`,loadMoreBtn:`_loadMoreBtn_1ssbe_311`,pane:`_pane_1ssbe_322`,emptyPane:`_emptyPane_1ssbe_330`,readingPane:`_readingPane_1ssbe_337`,paneToolbar:`_paneToolbar_1ssbe_344`,paneActions:`_paneActions_1ssbe_354`,replyBtn:`_replyBtn_1ssbe_360`,fwdBtn:`_fwdBtn_1ssbe_371`,trashBtn:`_trashBtn_1ssbe_371`,starBtn:`_starBtn_1ssbe_371`,aiBtn:`_aiBtn_1ssbe_384`,labelSelect:`_labelSelect_1ssbe_394`,paneHeader:`_paneHeader_1ssbe_403`,paneSubject:`_paneSubject_1ssbe_409`,paneMeta:`_paneMeta_1ssbe_416`,attachments:`_attachments_1ssbe_424`,attachLink:`_attachLink_1ssbe_431`,paneBody:`_paneBody_1ssbe_441`,bodyFrame:`_bodyFrame_1ssbe_447`,bodyText:`_bodyText_1ssbe_455`,composePane:`_composePane_1ssbe_465`,composeTitle:`_composeTitle_1ssbe_474`,composeField:`_composeField_1ssbe_483`,templateRow:`_templateRow_1ssbe_495`,templateToggle:`_templateToggle_1ssbe_500`,templateDrop:`_templateDrop_1ssbe_510`,templateItem:`_templateItem_1ssbe_524`,templateSubject:`_templateSubject_1ssbe_534`,composeBody:`_composeBody_1ssbe_540`,composeActions:`_composeActions_1ssbe_556`,sendBtn:`_sendBtn_1ssbe_563`,cancelBtn:`_cancelBtn_1ssbe_574`,compStatus:`_compStatus_1ssbe_584`,ok:`_ok_1ssbe_585`,err:`_err_1ssbe_586`},Yt=[{id:`INBOX`,name:`Inbox`,icon:`✉`},{id:`SENT`,name:`Sent`,icon:`→`},{id:`DRAFTS`,name:`Drafts`,icon:`📄`},{id:`SPAM`,name:`Spam`,icon:`🛡`},{id:`TRASH`,name:`Trash`,icon:`🗑`}],Xt=[{name:`Product Promo`,subject:`Discover our offer on [PRODUCT]`},{name:`Monthly Newsletter`,subject:`[COMPANY] Newsletter — [MONTH] [YEAR]`},{name:`Commercial Follow-up`,subject:`Following our conversation — [TOPIC]`},{name:`Offer / Quote`,subject:`Offer [NUMBER] — [SUBJECT]`},{name:`Event Invitation`,subject:`You are invited: [EVENT NAME] — [DATE]`},{name:`Customer Thank You`,subject:`Thank you for your trust, [NAME]`}];function Zt(e){return e?e.slice(0,10):``}function Qt(e){if(!e)return``;try{let t=typeof e==`string`?JSON.parse(e):e;return Array.isArray(t)?t.map(e=>e.name?`${e.name} <${e.address}>`:e.address||``).join(`, `):String(e)}catch{return String(e)}}function $t(){let e=j(),t=te(e=>e.setView),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(`google`),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(`INBOX`),[m,h]=(0,_.useState)([]),[g,v]=(0,_.useState)(0),[y,b]=(0,_.useState)(0),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(null),[ee,T]=(0,_.useState)(!1),[ne,re]=(0,_.useState)(!1),[ie,O]=(0,_.useState)(``),[ae,A]=(0,_.useState)(``),[oe,se]=(0,_.useState)(0),[ce,le]=(0,_.useState)(!1),[ue,de]=(0,_.useState)({}),[M,fe]=(0,_.useState)(``),[pe,me]=(0,_.useState)(``),[he,ge]=(0,_.useState)(``),[_e,ve]=(0,_.useState)(``),[ye,be]=(0,_.useState)(``),[xe,Se]=(0,_.useState)(!1),[N,Ce]=(0,_.useState)(``),[we,Te]=(0,_.useState)(!1),Ee=(0,_.useRef)(null),P=(0,_.useRef)(0);(0,_.useEffect)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle)),E(`/api/imap/accounts`).then(e=>{let t=(e?.accounts??[]).filter(e=>e.id!==`google`);a(t);let n=localStorage.getItem(`nha-email-account-type`),r=localStorage.getItem(`nha-email-account-id`);n===`google`?De(`google`,`google`):n===`imap`&&r&&t.some(e=>e.id===r)?De(r,`imap`):t.length>0?De(t[0].id,`imap`):De(`google`,`google`)})},[]);let De=(e,t)=>{s(e),l(t),p(t===`google`?`INBOX`:null),localStorage.setItem(`nha-email-account-type`,t),localStorage.setItem(`nha-email-account-id`,e),h([]),b(0),S(null),w(null),t===`imap`?E(`/api/imap/labels?accountId=${e}`).then(t=>{let n=t?.labels??[];d(n);let r=n.find(e=>e.system_type===`inbox`)?.id??null;p(r),Oe(e,r,0,``)}):(d([]),ke(`INBOX`,``))},Oe=(e,t,n,r)=>{let i=++P.current;T(!0);let a=`/api/imap/messages?accountId=${encodeURIComponent(e)}&limit=50&offset=${n}`;t&&(a+=`&labelId=${encodeURIComponent(t)}`),r&&(a+=`&search=${encodeURIComponent(r)}`),E(a).then(e=>{i===P.current&&(h(n===0?e?.messages??[]:t=>[...t,...e?.messages??[]]),v(e?.total??0),T(!1))}).catch(()=>{i===P.current&&T(!1)})},ke=(e,t)=>{T(!0);let n=e||`INBOX`;E(`/api/emails?folder=${encodeURIComponent(n)}&page=0&pageSize=50${t?`&search=${encodeURIComponent(t)}`:``}`).then(e=>{if(e?.authRequired){h([]),v(0),T(!1);return}let t=e?.emails??[];if(t.length>0){let e=t.map(e=>({id:e.id,subject:e.subject,from_name:e.from,from_address:e.from,internal_date:e.date,body_preview:e.snippet,is_read:!e.isUnread,is_starred:!1,has_attachments:!1,_google:!0}));h(e),v(e.length),n===`INBOX`&&se(e.filter(e=>!e.is_read).length)}else h([]),v(0);T(!1)}).catch(()=>{h([]),T(!1)})},F=()=>{O(ae),b(0),h([]),c===`imap`&&o?Oe(o,f,0,ae):ke(f||`INBOX`,ae)},I=e=>{S(e),le(!1),re(!0),c===`google`?E(`/api/imap/message?id=${encodeURIComponent(e)}`).then(t=>{t?.message&&(t.message.body_text||t.message.body_html)?(w({...t.message,id:e,_google:!0}),h(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),re(!1)):D(`/api/email/read`,{messageId:e}).then(t=>{if(t?.message){let n=t.message;w({...t.message,body_text:n.body||n.body_text,body_html:n.body_html,from_address:n.from||n.from_address,id:e,_google:!0}),h(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),D(`/api/email/mark-read`,{messageId:e}).catch(()=>{})}re(!1)}).catch(()=>re(!1))}).catch(()=>re(!1)):E(`/api/imap/message?id=${encodeURIComponent(e)}`).then(t=>{w(t?.message??null),h(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),re(!1)}).catch(()=>re(!1))},Ae=(e={})=>{le(!0),de(e),fe(e.to??``),me(``),ge(e.subject??``),ve(e.type===`forward`&&e.body?`\n\n---------- Forwarded message ----------\n${e.body}`:``),be(``),Se(!1),S(null),w(null)},je=async()=>{if(!M.trim()){be(`Recipient required`);return}be(`Sending…`);try{if(c===`imap`&&o){let e=await D(`/api/imap/send`,{accountId:o,to:M.trim(),cc:pe.trim()||void 0,subject:he.trim(),bodyHtml:_e.replace(/\n/g,`<br>`),bodyText:_e,inReplyTo:ue.inReplyTo||void 0});e?.ok?(be(`Sent!`),setTimeout(()=>le(!1),800)):be(e?.error??`Error`)}else{let e=await D(`/api/email/send`,{to:M.trim(),subject:he.trim(),body:_e});e?.ok||e?.id?(be(`Sent!`),setTimeout(()=>le(!1),800)):be(e?.error??`Error`)}}catch(e){be(e.message??`Error`)}},Me=e=>{confirm(`Move to trash? Email stays on the server.`)&&D(`/api/imap/trash`,{messageId:e}).then(()=>{h(t=>t.filter(t=>t.id!==e)),w(null),S(null)})},Ne=(e,t)=>{D(`/api/imap/mark-starred`,{messageId:e,isStarred:t}).then(()=>{C?.id===e&&w(e=>e&&{...e,is_starred:t})})},Pe=(e,t)=>{t&&D(`/api/imap/labels/assign`,{messageId:e,labelId:t})},Fe=()=>{!N.trim()||!o||D(`/api/imap/labels`,{accountId:o,name:N.trim()}).then(()=>{Te(!1),Ce(``),E(`/api/imap/labels?accountId=${o}`).then(e=>d(e?.labels??[]))})},Ie=()=>{o&&c===`imap`&&D(`/api/imap/sync/${o}`,{})},Le=()=>{if(c===`google`){T(!0);let e=f||`INBOX`,t=m.length+50;E(`/api/emails?folder=${encodeURIComponent(e)}&page=0&pageSize=${t}`).then(e=>{let t=(e?.emails??[]).map(e=>({id:e.id,subject:e.subject,from_name:e.from,from_address:e.from,internal_date:e.date,body_preview:e.snippet,is_read:!e.isUnread,is_starred:!1,has_attachments:!1,_google:!0}));h(t),v(t.length),T(!1)}).catch(()=>T(!1))}else{let e=y+50;b(e),o&&Oe(o,f,e,ie)}};return(0,k.jsxs)(`div`,{className:H.root,children:[(0,k.jsxs)(`div`,{className:H.sidebar,children:[(0,k.jsxs)(`div`,{className:H.sidebarSection,children:[(0,k.jsx)(`div`,{className:H.sidebarLabel,children:`Account`}),(0,k.jsxs)(`select`,{className:H.accountSelect,value:c===`google`?`google`:`imap:${o}`,onChange:e=>{let t=e.target.value;t===`google`?De(`google`,`google`):t.startsWith(`imap:`)&&De(t.slice(5),`imap`)},children:[n&&(0,k.jsx)(`option`,{value:`google`,children:`Google (Gmail)`}),i.map(e=>(0,k.jsx)(`option`,{value:`imap:${e.id}`,children:e.display_name||e.email_address},e.id)),!n&&i.length===0&&(0,k.jsx)(`option`,{value:``,children:`No accounts — add in Settings`})]})]}),(0,k.jsx)(`div`,{className:H.sidebarCompose,children:(0,k.jsx)(`button`,{className:H.composeBtn,onClick:()=>Ae(),children:`+ Compose`})}),(0,k.jsx)(`div`,{className:H.folderList,children:c===`google`?Yt.map(e=>(0,k.jsxs)(`div`,{className:`${H.folderItem} ${f===e.id?H.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),ke(e.id,ie)},children:[(0,k.jsx)(`span`,{children:e.icon}),(0,k.jsx)(`span`,{children:e.name}),e.id===`INBOX`&&oe>0&&(0,k.jsx)(`span`,{className:H.badge,children:oe})]},e.id)):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:H.labelHeader,children:[(0,k.jsx)(`span`,{children:`Labels`}),(0,k.jsx)(`button`,{className:H.addLabelBtn,onClick:()=>Te(e=>!e),children:`+`})]}),we&&(0,k.jsxs)(`div`,{className:H.newLabelRow,children:[(0,k.jsx)(`input`,{className:H.newLabelInput,value:N,onChange:e=>Ce(e.target.value),placeholder:`Label name`,onKeyDown:e=>e.key===`Enter`&&Fe()}),(0,k.jsx)(`button`,{className:H.newLabelSave,onClick:Fe,children:`+`})]}),u.map(e=>(0,k.jsxs)(`div`,{className:`${H.folderItem} ${f===e.id?H.folderActive:``}`,onClick:()=>{p(e.id),h([]),b(0),o&&Oe(o,e.id,0,ie)},children:[(0,k.jsx)(`span`,{className:H.labelDot,style:{background:e.color??`var(--dim)`}}),(0,k.jsx)(`span`,{children:e.name}),e.system_type===`inbox`&&e.unread_count?(0,k.jsx)(`span`,{className:H.badge,children:e.unread_count}):null]},e.id))]})}),c===`imap`&&o&&(0,k.jsx)(`div`,{className:H.syncArea,children:(0,k.jsx)(`button`,{className:H.syncBtn,onClick:Ie,children:`Sync now`})}),c===`google`&&(0,k.jsx)(`div`,{className:H.syncArea,children:(0,k.jsx)(`button`,{className:H.syncBtn,onClick:()=>{h([]),ke(f||`INBOX`,``)},children:`Refresh`})})]}),(0,k.jsxs)(`div`,{className:H.messageList,children:[(0,k.jsxs)(`div`,{className:H.listHeader,children:[(0,k.jsx)(`input`,{className:H.searchInput,value:ae,onChange:e=>A(e.target.value),placeholder:`Search…`,onKeyDown:e=>e.key===`Enter`&&F()}),(0,k.jsx)(`button`,{className:H.searchBtn,onClick:F,children:`Go`})]}),(0,k.jsxs)(`div`,{className:H.listBody,children:[ee&&(0,k.jsx)(`div`,{className:H.listLoading,children:(0,k.jsx)(`div`,{className:`spinner`})}),!ee&&m.length===0&&(0,k.jsx)(`div`,{className:H.noMessages,children:`No messages`}),m.map(e=>(0,k.jsxs)(`div`,{className:`${H.msgRow} ${e.id===x?H.msgActive:``} ${e.is_read?``:H.msgUnread}`,onClick:()=>I(e.id),children:[(0,k.jsxs)(`div`,{className:H.msgTop,children:[(0,k.jsx)(`span`,{className:H.msgFrom,children:e.from_name||e.from_address||``}),(0,k.jsx)(`span`,{className:H.msgDate,children:Zt(e.internal_date)})]}),(0,k.jsx)(`div`,{className:H.msgSubject,children:e.subject||`(no subject)`}),(0,k.jsx)(`div`,{className:H.msgPreview,children:(e.body_preview||``).slice(0,80)})]},e.id))]}),(0,k.jsxs)(`div`,{className:H.listFooter,children:[(0,k.jsxs)(`span`,{children:[g,` messages`]}),c===`imap`&&m.length<g&&(0,k.jsx)(`button`,{className:H.loadMoreBtn,onClick:Le,children:`Load more`}),c===`google`&&m.length>=50&&(0,k.jsx)(`button`,{className:H.loadMoreBtn,onClick:Le,disabled:ee,children:ee?`Loading...`:`Scarica altre`})]})]}),(0,k.jsx)(`div`,{className:H.pane,children:(()=>{if(ce)return(0,k.jsxs)(`div`,{className:H.composePane,children:[(0,k.jsx)(`div`,{className:H.composeTitle,children:e(`email.compose`)}),(0,k.jsx)(`input`,{className:H.composeField,value:M,onChange:e=>fe(e.target.value),placeholder:`To`}),(0,k.jsx)(`input`,{className:H.composeField,value:pe,onChange:e=>me(e.target.value),placeholder:`Cc`}),(0,k.jsx)(`input`,{className:H.composeField,value:he,onChange:e=>ge(e.target.value),placeholder:`Subject`}),(0,k.jsxs)(`div`,{className:H.templateRow,children:[(0,k.jsx)(`button`,{className:H.templateToggle,onClick:()=>Se(e=>!e),children:`📄 Templates`}),xe&&(0,k.jsx)(`div`,{className:H.templateDrop,children:Xt.map((e,t)=>(0,k.jsxs)(`div`,{className:H.templateItem,onClick:()=>{ge(t=>t||e.subject),Se(!1)},children:[(0,k.jsx)(`strong`,{children:e.name}),(0,k.jsx)(`div`,{className:H.templateSubject,children:e.subject})]},t))})]}),(0,k.jsx)(`textarea`,{className:H.composeBody,value:_e,onChange:e=>ve(e.target.value),placeholder:`Write your message…`}),(0,k.jsxs)(`div`,{className:H.composeActions,children:[(0,k.jsx)(`button`,{className:H.sendBtn,onClick:je,children:e(`email.send_ok`)}),(0,k.jsx)(`button`,{className:H.cancelBtn,onClick:()=>le(!1),children:`Discard`}),ye&&(0,k.jsx)(`span`,{className:`${H.compStatus} ${ye===`Sent!`?H.ok:H.err}`,children:ye})]})]});if(ne)return(0,k.jsx)(`div`,{className:H.emptyPane,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!C)return(0,k.jsx)(`div`,{className:H.emptyPane,children:`Select a message`});let n=Qt(C.to_addresses);return(0,k.jsxs)(`div`,{className:H.readingPane,children:[(0,k.jsx)(`div`,{className:H.paneToolbar,children:(0,k.jsxs)(`div`,{className:H.paneActions,children:[(0,k.jsx)(`button`,{className:H.replyBtn,onClick:()=>Ae({to:C.from_address,subject:`Re: ${C.subject??``}`,inReplyTo:C.message_id??C.id,replyTo:C.id,type:`reply`}),children:e(`email.reply`)}),(0,k.jsx)(`button`,{className:H.fwdBtn,onClick:()=>Ae({subject:`Fwd: ${C.subject??``}`,type:`forward`,body:C.body_text??C.body_preview??``}),children:`Forward`}),!C._google&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{className:H.trashBtn,onClick:()=>Me(C.id),children:`🗑`}),(0,k.jsx)(`button`,{className:H.starBtn,onClick:()=>Ne(C.id,!C.is_starred),children:C.is_starred?`★`:`☆`}),u.length>0&&(0,k.jsxs)(`select`,{className:H.labelSelect,defaultValue:``,onChange:e=>Pe(C.id,e.target.value),children:[(0,k.jsx)(`option`,{value:``,children:`+ Label`}),u.map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,k.jsx)(`button`,{className:H.aiBtn,onClick:()=>t(`chat`),children:`Ask AI`})]})}),(0,k.jsxs)(`div`,{className:H.paneHeader,children:[(0,k.jsx)(`div`,{className:H.paneSubject,children:C.subject||`(no subject)`}),(0,k.jsxs)(`div`,{className:H.paneMeta,children:[(0,k.jsx)(`strong`,{children:`From:`}),` `,C.from_name&&C.from_name!==C.from_address?`${C.from_name} <${C.from_address}>`:C.from_address]}),(0,k.jsxs)(`div`,{className:H.paneMeta,children:[(0,k.jsx)(`strong`,{children:`To:`}),` `,n]}),(0,k.jsxs)(`div`,{className:H.paneMeta,children:[(0,k.jsx)(`strong`,{children:`Date:`}),` `,C.internal_date]}),C.attachments&&C.attachments.length>0&&(0,k.jsx)(`div`,{className:H.attachments,children:C.attachments.map((e,t)=>(0,k.jsxs)(`a`,{className:H.attachLink,href:`/api/imap/attachment?messageId=${encodeURIComponent(C.id)}&partId=${encodeURIComponent(e.part_id??``)}&accountId=${encodeURIComponent(o??``)}`,download:e.filename??`attachment`,children:[`📎 `,e.filename??`attachment`,` (`,Math.round((e.size_bytes??0)/1024),`KB)`]},t))})]}),(0,k.jsx)(`div`,{className:H.paneBody,children:C.body_html?(0,k.jsx)(`iframe`,{ref:Ee,sandbox:`allow-same-origin`,className:H.bodyFrame,srcDoc:C.body_html,title:`Email body`}):(0,k.jsx)(`pre`,{className:H.bodyText,children:C.body_text??C.body_preview??`(empty)`})})]})})()})]})}var U={root:`_root_7ur7d_1`,center:`_center_7ur7d_9`,noGoogle:`_noGoogle_7ur7d_16`,noGoogleIcon:`_noGoogleIcon_7ur7d_25`,noGoogleTitle:`_noGoogleTitle_7ur7d_26`,noGoogleSub:`_noGoogleSub_7ur7d_27`,connectBtn:`_connectBtn_7ur7d_29`,calCol:`_calCol_7ur7d_41`,navRow:`_navRow_7ur7d_49`,navBtn:`_navBtn_7ur7d_57`,monthTitle:`_monthTitle_7ur7d_70`,dayHeaders:`_dayHeaders_7ur7d_78`,dayHeader:`_dayHeader_7ur7d_78`,weekend:`_weekend_7ur7d_94`,grid:`_grid_7ur7d_96`,cell:`_cell_7ur7d_105`,emptyCell:`_emptyCell_7ur7d_119`,weekendCell:`_weekendCell_7ur7d_121`,todayCell:`_todayCell_7ur7d_122`,activeCell:`_activeCell_7ur7d_123`,hasEvtsCell:`_hasEvtsCell_7ur7d_124`,holidayCell:`_holidayCell_7ur7d_125`,dayNum:`_dayNum_7ur7d_127`,todayNum:`_todayNum_7ur7d_134`,weekendNum:`_weekendNum_7ur7d_135`,evtPills:`_evtPills_7ur7d_137`,evtPill:`_evtPill_7ur7d_137`,holidayPill:`_holidayPill_7ur7d_158`,morePill:`_morePill_7ur7d_160`,loadingBar:`_loadingBar_7ur7d_166`,detailCol:`_detailCol_7ur7d_175`,detailHeader:`_detailHeader_7ur7d_187`,detailDate:`_detailDate_7ur7d_197`,addEvtBtn:`_addEvtBtn_7ur7d_203`,noEvts:`_noEvts_7ur7d_218`,selectDay:`_selectDay_7ur7d_225`,evtCard:`_evtCard_7ur7d_233`,evtTop:`_evtTop_7ur7d_246`,evtTime:`_evtTime_7ur7d_253`,evtBtns:`_evtBtns_7ur7d_259`,editBtn:`_editBtn_7ur7d_265`,delBtn:`_delBtn_7ur7d_278`,readOnly:`_readOnly_7ur7d_291`,evtTitle:`_evtTitle_7ur7d_300`,evtLoc:`_evtLoc_7ur7d_306`,evtMeta:`_evtMeta_7ur7d_307`,attendees:`_attendees_7ur7d_309`,attendee:`_attendee_7ur7d_309`,evtDesc:`_evtDesc_7ur7d_320`,joinBtn:`_joinBtn_7ur7d_330`,gcalLink:`_gcalLink_7ur7d_337`,overlay:`_overlay_7ur7d_344`,formCard:`_formCard_7ur7d_354`,formTitle:`_formTitle_7ur7d_368`,formLabel:`_formLabel_7ur7d_375`,formInput:`_formInput_7ur7d_381`,formTextarea:`_formTextarea_7ur7d_394`,formError:`_formError_7ur7d_410`,formBtns:`_formBtns_7ur7d_415`,cancelFormBtn:`_cancelFormBtn_7ur7d_422`,saveFormBtn:`_saveFormBtn_7ur7d_432`};function en(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function tn(e,t,n){let r=new Date;return r.getFullYear()===e&&r.getMonth()===t&&r.getDate()===n}function nn(e){if(!e)return``;let t=new Date(e);return isNaN(t.getTime())?e.slice(11,16):t.toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`})}function rn(){let e=j(),t=te(e=>e.setView),[n,r]=(0,_.useState)(null),i=new Date,[a,o]=(0,_.useState)(i.getFullYear()),[s,c]=(0,_.useState)(i.getMonth()),[l,u]=(0,_.useState)({}),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(!1);(0,_.useEffect)(()=>{E(`/api/config`).then(e=>r(!!e?.hasGoogle))},[]);let S=(0,_.useCallback)((e,t)=>{let n=`${e}-${String(t+1).padStart(2,`0`)}`;f(!0),E(`/api/calendar?month=${n}`).then(e=>{e?.byDate&&u(t=>({...t,...e.byDate})),f(!1)}).catch(()=>f(!1))},[]);(0,_.useEffect)(()=>{n&&S(a,s)},[n,a,s,S]);let C=e=>{E(`/api/calendar?date=${e}`).then(t=>{u(n=>({...n,[e]:t?.events??[]}))})},w=(e,t,n)=>{confirm(`Delete this event?`)&&D(`/api/calendar/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{},`DELETE`).then(()=>C(n))},ee=e=>{g({title:``,start:`${e}T09:00`,end:`${e}T10:00`,location:``,description:``,isEdit:!1}),y(``)},T=(e,t)=>{let n=e.start?e.start.slice(0,16):`${t}T09:00`,r=e.end?e.end.slice(0,16):`${t}T10:00`;g({id:e.id,calId:e.calendarId??`primary`,title:e.summary,start:n,end:r,location:e.location??``,description:e.description??``,isEdit:!0}),y(``)},ne=async()=>{if(h){if(!h.title.trim()){y(`Title is required`);return}x(!0);try{if(h.isEdit&&h.id){let e=h.calId??`primary`;await D(`/api/calendar/${encodeURIComponent(e)}/${encodeURIComponent(h.id)}`,{summary:h.title,start:h.start,end:h.end,location:h.location||void 0,description:h.description||void 0},`PATCH`)}else{let e=h.start.split(`T`)[0];await D(`/api/calendar`,{summary:h.title,start:h.start,end:h.end,location:h.location||void 0,description:h.description||void 0,date:e})}let e=h.start.split(`T`)[0];C(e),g(null)}catch(e){y(`Error: `+(e.message??`Unknown`))}finally{x(!1)}}};if(n===null)return(0,k.jsx)(`div`,{className:U.center,children:(0,k.jsx)(`div`,{className:`spinner`})});if(!n)return(0,k.jsx)(`div`,{className:U.center,children:(0,k.jsxs)(`div`,{className:U.noGoogle,children:[(0,k.jsx)(`div`,{className:U.noGoogleIcon,children:`📅`}),(0,k.jsx)(`div`,{className:U.noGoogleTitle,children:`Calendar`}),(0,k.jsx)(`div`,{className:U.noGoogleSub,children:`Connect your Google account to view and manage calendar events.`}),(0,k.jsx)(`button`,{className:U.connectBtn,onClick:()=>t(`settings`),children:`Connect Google →`})]})});let re=new Date(a,s,1).getDay(),ie=new Date(a,s+1,0).getDate(),O=new Date(a,s,1).toLocaleDateString(`en`,{month:`long`,year:`numeric`}),ae=(re+6)%7,A=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],oe=p?l[p]??[]:[];return(0,k.jsxs)(`div`,{className:U.root,children:[(0,k.jsxs)(`div`,{className:U.calCol,children:[(0,k.jsxs)(`div`,{className:U.navRow,children:[(0,k.jsx)(`button`,{className:U.navBtn,onClick:()=>{let e=s-1;e<0?(o(e=>e-1),c(11)):c(e)},children:`←`}),(0,k.jsx)(`div`,{className:U.monthTitle,children:O}),(0,k.jsx)(`button`,{className:U.navBtn,onClick:()=>{let e=s+1;e>11?(o(e=>e+1),c(0)):c(e)},children:`→`})]}),(0,k.jsx)(`div`,{className:U.dayHeaders,children:A.map((e,t)=>(0,k.jsx)(`div`,{className:`${U.dayHeader} ${t>=5?U.weekend:``}`,children:e},e))}),(0,k.jsxs)(`div`,{className:U.grid,children:[Array.from({length:ae}).map((e,t)=>(0,k.jsx)(`div`,{className:`${U.cell} ${U.emptyCell} ${t>=5?U.weekendCell:``}`},`e${t}`)),Array.from({length:ie}).map((e,t)=>{let n=t+1,r=en(a,s,n),i=tn(a,s,n),o=l[r]??[],c=o.length,u=(ae+n-1)%7>=5,d=o.some(e=>e._isHoliday||e.readOnly),f=p===r;return(0,k.jsxs)(`div`,{className:`${U.cell} ${i?U.todayCell:u?U.weekendCell:``} ${f?U.activeCell:``} ${d?U.holidayCell:c>0?U.hasEvtsCell:``}`,onClick:()=>m(r),children:[(0,k.jsx)(`div`,{className:`${U.dayNum} ${i?U.todayNum:u?U.weekendNum:``}`,children:n}),c>0&&(0,k.jsxs)(`div`,{className:U.evtPills,children:[o.slice(0,2).map((e,t)=>(0,k.jsx)(`div`,{className:`${U.evtPill} ${e._isHoliday||e.readOnly?U.holidayPill:``}`,children:e.summary},t)),c>2&&(0,k.jsxs)(`div`,{className:U.morePill,children:[`+`,c-2]})]})]},r)})]}),d&&(0,k.jsx)(`div`,{className:U.loadingBar,children:`Loading events…`})]}),(0,k.jsx)(`div`,{className:U.detailCol,children:p?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:U.detailHeader,children:[(0,k.jsx)(`div`,{className:U.detailDate,children:new Date(p+`T12:00:00`).toLocaleDateString(`en`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),(0,k.jsx)(`button`,{className:U.addEvtBtn,onClick:()=>ee(p),children:`+ Add Event`})]}),oe.length===0?(0,k.jsx)(`div`,{className:U.noEvts,children:`No events on this day`}):oe.map((t,n)=>{let r=t.isAllDay?`All day`:`${nn(t.start)} - ${nn(t.end)}`,i=t.calendarId??`primary`;return(0,k.jsxs)(`div`,{className:U.evtCard,children:[(0,k.jsxs)(`div`,{className:U.evtTop,children:[(0,k.jsx)(`div`,{className:U.evtTime,children:r}),t.id&&!t.readOnly&&(0,k.jsxs)(`div`,{className:U.evtBtns,children:[(0,k.jsx)(`button`,{className:U.editBtn,onClick:()=>T(t,p),children:`Edit`}),(0,k.jsx)(`button`,{className:U.delBtn,onClick:()=>w(i,t.id,p),children:e(`common.delete`)})]}),t.readOnly&&(0,k.jsx)(`span`,{className:U.readOnly,children:`read-only`})]}),(0,k.jsx)(`div`,{className:U.evtTitle,children:t.summary}),t.location&&(0,k.jsxs)(`div`,{className:U.evtLoc,children:[`📍 `,t.location]}),t.organizer&&(0,k.jsxs)(`div`,{className:U.evtMeta,children:[`Organizer: `,t.organizer]}),t.attendees&&t.attendees.length>0&&(0,k.jsxs)(`div`,{className:U.attendees,children:[(0,k.jsx)(`div`,{className:U.evtMeta,children:`Attendees:`}),t.attendees.map((e,t)=>(0,k.jsxs)(`div`,{className:U.attendee,"data-status":e.responseStatus,children:[e.name||e.email,` (`,e.responseStatus,`)`]},t))]}),t.description&&(0,k.jsx)(`div`,{className:U.evtDesc,children:t.description}),t.hangoutLink&&(0,k.jsx)(`a`,{className:U.joinBtn,href:t.hangoutLink,target:`_blank`,rel:`noreferrer`,children:`Join Video Call`}),t.htmlLink&&(0,k.jsx)(`a`,{className:U.gcalLink,href:t.htmlLink,target:`_blank`,rel:`noreferrer`,children:`Open in Google Calendar`})]},n)})]}):(0,k.jsxs)(`div`,{className:U.selectDay,children:[`Click a day to see events, edit or delete them.`,(0,k.jsx)(`br`,{}),(0,k.jsx)(`br`,{}),`Use `,(0,k.jsx)(`strong`,{children:`+ Add Event`}),` to create a new event — it syncs with Google Calendar.`]})}),h&&(0,k.jsx)(`div`,{className:U.overlay,onClick:e=>{e.target===e.currentTarget&&g(null)},children:(0,k.jsxs)(`div`,{className:U.formCard,children:[(0,k.jsx)(`div`,{className:U.formTitle,children:h.isEdit?`Edit Event`:`New Event`}),(0,k.jsx)(`label`,{className:U.formLabel,children:`Title *`}),(0,k.jsx)(`input`,{className:U.formInput,value:h.title,onChange:e=>g(t=>t&&{...t,title:e.target.value}),placeholder:`Event title`}),(0,k.jsx)(`label`,{className:U.formLabel,children:`Start`}),(0,k.jsx)(`input`,{className:U.formInput,type:`datetime-local`,value:h.start,onChange:e=>g(t=>t&&{...t,start:e.target.value})}),(0,k.jsx)(`label`,{className:U.formLabel,children:`End`}),(0,k.jsx)(`input`,{className:U.formInput,type:`datetime-local`,value:h.end,onChange:e=>g(t=>t&&{...t,end:e.target.value})}),(0,k.jsx)(`label`,{className:U.formLabel,children:`Location`}),(0,k.jsx)(`input`,{className:U.formInput,value:h.location,onChange:e=>g(t=>t&&{...t,location:e.target.value}),placeholder:`Optional`}),(0,k.jsx)(`label`,{className:U.formLabel,children:`Description`}),(0,k.jsx)(`textarea`,{className:U.formTextarea,value:h.description,onChange:e=>g(t=>t&&{...t,description:e.target.value})}),v&&(0,k.jsx)(`div`,{className:U.formError,children:v}),(0,k.jsxs)(`div`,{className:U.formBtns,children:[(0,k.jsx)(`button`,{className:U.cancelFormBtn,onClick:()=>g(null),children:e(`common.cancel`)}),(0,k.jsx)(`button`,{className:U.saveFormBtn,onClick:ne,disabled:b,children:b?`Saving…`:h.isEdit?`Save Changes`:`Create Event`})]})]})})]})}var W={root:`_root_1tngw_1`,gridSection:`_gridSection_1tngw_9`,gridHeader:`_gridHeader_1tngw_14`,headerRow:`_headerRow_1tngw_21`,search:`_search_1tngw_23`,createBtn:`_createBtn_1tngw_34`,catTabs:`_catTabs_1tngw_41`,catTab:`_catTab_1tngw_41`,catActive:`_catActive_1tngw_48`,grid:`_grid_1tngw_9`,agentCard:`_agentCard_1tngw_59`,agentActive:`_agentActive_1tngw_66`,agentCardTop:`_agentCardTop_1tngw_68`,agentIcon:`_agentIcon_1tngw_69`,agentActions:`_agentActions_1tngw_70`,agentEditBtn:`_agentEditBtn_1tngw_71`,agentDelBtn:`_agentDelBtn_1tngw_71`,agentLabel:`_agentLabel_1tngw_74`,agentDesc:`_agentDesc_1tngw_75`,agentCat:`_agentCat_1tngw_76`,loading:`_loading_1tngw_78`,chatArea:`_chatArea_1tngw_81`,emptyChat:`_emptyChat_1tngw_88`,emptyChatHint:`_emptyChatHint_1tngw_98`,chatPanel:`_chatPanel_1tngw_101`,chatHeader:`_chatHeader_1tngw_111`,chatIcon:`_chatIcon_1tngw_118`,chatHeaderInfo:`_chatHeaderInfo_1tngw_119`,chatAgentName:`_chatAgentName_1tngw_120`,chatAgentDesc:`_chatAgentDesc_1tngw_121`,closeChat:`_closeChat_1tngw_122`,chatMessages:`_chatMessages_1tngw_125`,chatEmpty:`_chatEmpty_1tngw_130`,chatMsg:`_chatMsg_1tngw_132`,msgUser:`_msgUser_1tngw_136`,msgAgent:`_msgAgent_1tngw_137`,thinking:`_thinking_1tngw_139`,dot:`_dot_1tngw_140`,dotPulse:`_dotPulse_1tngw_1`,chatInput:`_chatInput_1tngw_146`,chatTools:`_chatTools_1tngw_147`,toolBtn:`_toolBtn_1tngw_148`,toolBtnActive:`_toolBtnActive_1tngw_156`,attachBar:`_attachBar_1tngw_158`,attachClear:`_attachClear_1tngw_163`,chatInputRow:`_chatInputRow_1tngw_165`,chatTextarea:`_chatTextarea_1tngw_166`,sendBtn:`_sendBtn_1tngw_173`,orchBar:`_orchBar_1tngw_181`,orchLabel:`_orchLabel_1tngw_192`,orchRow:`_orchRow_1tngw_193`,orchInput:`_orchInput_1tngw_194`,orchBtn:`_orchBtn_1tngw_201`,orchSynthesis:`_orchSynthesis_1tngw_208`,orchSynthHeader:`_orchSynthHeader_1tngw_214`,orchSynthSpinner:`_orchSynthSpinner_1tngw_220`,blink:`_blink_1tngw_1`,orchSynthBody:`_orchSynthBody_1tngw_222`,modalOverlay:`_modalOverlay_1tngw_230`,modal:`_modal_1tngw_230`,modalTitle:`_modalTitle_1tngw_232`,formField:`_formField_1tngw_233`,formLabel:`_formLabel_1tngw_234`,formInput:`_formInput_1tngw_235`,formTextarea:`_formTextarea_1tngw_236`,formError:`_formError_1tngw_237`,modalBtns:`_modalBtns_1tngw_238`,cancelBtn:`_cancelBtn_1tngw_239`,modalSaveBtn:`_modalSaveBtn_1tngw_240`},an={saber:{icon:`🛡`},zero:{icon:`🔍`},ade:{icon:`🔬`},heimdall:{icon:`🔒`},cassandra:{icon:`⚠`},sauron:{icon:`👁`},jarvis:{icon:`💻`},forge:{icon:`⚙`},pipe:{icon:`🔧`},shell:{icon:`📟`},glitch:{icon:`🐛`},hermes:{icon:`🔗`},babel:{icon:`🌎`},shogun:{icon:`☸`},flux:{icon:`🔄`},cron:{icon:`⏰`},atlas:{icon:`🗺`},oracle:{icon:`📊`},logos:{icon:`🧮`},navi:{icon:`🧭`},edi:{icon:`📈`},mercury:{icon:`🌐`},tempest:{icon:`⛈`},cartographer:{icon:`🌍`},scheherazade:{icon:`✍`},quill:{icon:`📝`},muse:{icon:`🎨`},murasaki:{icon:`🖌`},echo:{icon:`📡`},polyglot:{icon:`🗣`},prometheus:{icon:`🔥`},herald:{icon:`📢`},veritas:{icon:`✓`},athena:{icon:`🧠`},conductor:{icon:`🎼`},link:{icon:`🔌`},macro:{icon:`⚡`},epicure:{icon:`🍽`}};function on(e){let t=e.card??e,n=(t.name||t.displayName||t.agentName||e.name||``).toLowerCase().replace(/\s+/g,`-`),r=an[n],i=t.displayName||t.agentName||t.name||e.displayName||n,a=t.tagline||t.description||e.tagline||``,o=t.category||e.category||`Other`;return{id:n,icon:r?.icon??t.icon??`🤖`,label:i,description:a,category:o,isCustom:o===`custom`,systemPrompt:e.systemPrompt}}function sn(e){return{agent:e,history:[],streaming:!1,input:``,attachedFile:null,attachedImage:null,voiceActive:!1}}function cn(){let e=j(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(!0),[a,o]=(0,_.useState)(``),[s,c]=(0,_.useState)(`All`),[l,u]=(0,_.useState)([]),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(`create`),[w,ee]=(0,_.useState)(``),[T,te]=(0,_.useState)(!1),ne=(0,_.useRef)(new Map),re=(0,_.useRef)(new Map),O=(0,_.useRef)(new Map),ae=(0,_.useRef)(new Map),A=(0,_.useRef)(new Map),oe=(0,_.useRef)(null),se=()=>{E(`/api/agents`).then(e=>{n((e?.agents??[]).map(on)),i(!1)}).catch(()=>i(!1))};(0,_.useEffect)(()=>{se()},[]);let ce=[`All`,...Array.from(new Set(t.map(e=>e.category))).sort()],le=t.filter(e=>{let t=s===`All`||e.category===s,n=a.toLowerCase();return t&&(!n||e.label.toLowerCase().includes(n)||e.description.toLowerCase().includes(n))}),ue=e=>{u(t=>{let n=t.findIndex(t=>t.agent.id===e.id);return n>=0?(re.current.get(e.id)?.abort(),re.current.delete(e.id),t.filter((e,t)=>t!==n)):[...t,sn(e)]})},de=e=>{re.current.get(e)?.abort(),re.current.delete(e),u(t=>t.filter(t=>t.agent.id!==e))},M=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,...t}:n))},fe=(e,t)=>{u(n=>n.map(n=>n.agent.id===e?{...n,history:[...n.history,t]}:n))},pe=(e,t)=>{u(n=>n.map(n=>{if(n.agent.id!==e)return n;let r=[...n.history];return r[r.length-1]={...r[r.length-1],content:t},{...n,history:r}}))},me=async(e,t,n,r)=>{let i=e.agent.id;if(!t.trim()&&!n&&!r)return;fe(i,{role:`user`,content:n?(t?t+` `:``)+`[File: ${n.name}]`:r?(t?t+` `:``)+`[Image: ${r.name}]`:t}),M(i,{streaming:!0,input:``,attachedFile:null,attachedImage:null});let a=e.history.slice(-20);if(n||r){try{let e={message:t||`Analyze this`,agent:i};n?.isPDF&&n.base64?(e.pdfBase64=n.base64,e.pdfName=n.name):n?.content&&(e.fileContent=n.content,e.fileName=n.name),r?.base64&&(e.imageBase64=r.base64,e.imageMimeType=r.mimeType??`image/jpeg`);let a=await D(`/api/chat`,e);fe(i,{role:`assistant`,content:a?.response||a?.content||``})}catch{fe(i,{role:`assistant`,content:`Error sending attachment.`})}M(i,{streaming:!1});return}fe(i,{role:`assistant`,content:``,streaming:!0});let o=new AbortController;re.current.set(i,o);let s=``;try{await ie(`/api/chat/stream`,{message:t,agent:i,history:a,_agentSystemPrompt:e.agent.systemPrompt},e=>{s+=e,pe(i,s);let t=O.current.get(i);t&&(t.scrollTop=t.scrollHeight)},o.signal)}catch{}finally{M(i,{streaming:!1}),re.current.delete(i)}},he=async()=>{let e=d.trim();if(!e||p||l.length===0)return;f(``),m(!0),g(``);let t=[];if(await Promise.all(l.map(async n=>{let r=n.agent.id;fe(r,{role:`user`,content:e}),M(r,{streaming:!0});let i=``,a=new AbortController;re.current.set(r,a),fe(r,{role:`assistant`,content:``,streaming:!0});try{await ie(`/api/chat/stream`,{message:e,agent:r,history:n.history.slice(-20),_agentSystemPrompt:n.agent.systemPrompt},e=>{i+=e,pe(r,i);let t=O.current.get(r);t&&(t.scrollTop=t.scrollHeight)},a.signal)}catch{}finally{M(r,{streaming:!1}),re.current.delete(r)}t.push({agentId:r,agentLabel:n.agent.label,icon:n.agent.icon,content:i})})),m(!1),t.length<2)return;y(!0);let n=t.map(e=>`## ${e.icon} ${e.agentLabel}\n${e.content}`).join(`
655
655
 
656
656
  ---
@@ -8,7 +8,7 @@
8
8
  <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
9
9
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10
10
  <title>NHA — NotHumanAllowed</title>
11
- <script type="module" crossorigin src="/assets/index-DTy-ohQm.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-BAw59tZG.js"></script>
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-DnJMrYkq.css">
13
13
  </head>
14
14
  <body>