@amd-gaia/agent-ui 0.25.2 → 0.25.3-rc.1

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.
@@ -0,0 +1 @@
1
+ import{a as e}from"./apiBase-CS6zLsJY.js";var t={name:`message-square`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]};t.node;var n=e(t),r={name:`zap`,size:24,node:[[`path`,{d:`M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z`,key:`1v7up4`}]]};r.node;var i=e(r);export{n,i as t};
package/dist/index.html CHANGED
@@ -8,10 +8,10 @@
8
8
  <meta name="theme-color" content="#1A1917" />
9
9
  <link rel="icon" type="image/png" href="./favicon.png" />
10
10
  <title>GAIA Agent UI</title>
11
- <script type="module" crossorigin src="./assets/index-Fhiym-Jy.js"></script>
11
+ <script type="module" crossorigin src="./assets/index-Ck42TJHO.js"></script>
12
12
  <link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-XKyaHtl9.js">
13
13
  <link rel="modulepreload" crossorigin href="./assets/apiBase-CS6zLsJY.js">
14
- <link rel="stylesheet" crossorigin href="./assets/index-BK59gm9q.css">
14
+ <link rel="stylesheet" crossorigin href="./assets/index-C-EM_5yl.css">
15
15
  </head>
16
16
  <body>
17
17
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amd-gaia/agent-ui",
3
- "version": "0.25.2",
3
+ "version": "0.25.3-rc.1",
4
4
  "type": "module",
5
5
  "productName": "GAIA Agent UI",
6
6
  "description": "Chat with the GAIA agent - local and private by default on AMD Ryzen AI, cloud models when you choose them",
@@ -176,6 +176,10 @@ let mainWindowRef = null;
176
176
  /** Asks before an update restart would cut off running work (set by init). */
177
177
  let confirmRestartRef = null;
178
178
  let checkInProgress = false;
179
+ // The user asked for this download, so it may install on quit with auto-update off.
180
+ let installRequested = false;
181
+ // The file was unreadable at launch, so a pin it holds was never loaded.
182
+ let pinUnknown = false;
179
183
  let scheduledTimeout = null;
180
184
  let initialCheckTimeout = null;
181
185
  let ipcHandlersRegistered = false;
@@ -224,7 +228,7 @@ function _loadPin() {
224
228
  const cfg = JSON.parse(raw);
225
229
  return cfg.pinnedVersion || null;
226
230
  } catch (err) {
227
- log("warn", "Failed to read version pin — treating as unpinned:", err && err.message);
231
+ log("warn", "Failed to read version pin — update checks pause until the file is fixed:", err && err.message);
228
232
  return null;
229
233
  }
230
234
  }
@@ -253,6 +257,41 @@ function _loadAutoUpdate() {
253
257
  }
254
258
  }
255
259
 
260
+ /**
261
+ * Re-read the shared settings before acting on them: the Terminal UI can turn
262
+ * auto-update off while this app runs, and that must stop the next download.
263
+ */
264
+ function _refreshPreferences() {
265
+ const loaded = _loadAutoUpdate();
266
+ setState({
267
+ autoUpdate: loaded.autoUpdate,
268
+ includePrereleases: loaded.includePrereleases,
269
+ configError: loaded.error,
270
+ });
271
+ if (pinUnknown && !loaded.error) {
272
+ pinUnknown = false;
273
+ const pin = _loadPin();
274
+ if (pin) {
275
+ log("info", `Settings file readable again — honouring its pin to ${pin}`);
276
+ setState({ pinnedVersion: pin });
277
+ if (autoUpdaterRef) {
278
+ autoUpdaterRef.setFeedURL({
279
+ provider: "generic",
280
+ url: `https://github.com/amd/gaia/releases/download/${pin}/`,
281
+ });
282
+ }
283
+ }
284
+ }
285
+ _applyInstallPolicy();
286
+ }
287
+
288
+ function _applyInstallPolicy() {
289
+ if (!autoUpdaterRef) return;
290
+ autoUpdaterRef.autoDownload = state.autoUpdate && !state.pinnedVersion;
291
+ autoUpdaterRef.autoInstallOnAppQuit = state.autoUpdate || installRequested;
292
+ autoUpdaterRef.allowPrerelease = _prereleasesAllowed();
293
+ }
294
+
256
295
  /** "0.25.2-rc.3" → true. A candidate build keeps being offered candidates. */
257
296
  function _isPrereleaseVersion(version) {
258
297
  return typeof version === "string" && /^\d+\.\d+\.\d+-/.test(version);
@@ -286,6 +325,10 @@ function _savePin(pinnedVersion) {
286
325
  */
287
326
  function _writeConfig(patch) {
288
327
  fs.mkdirSync(path.dirname(UPDATE_CONFIG_PATH), { recursive: true });
328
+ _withConfigLock(() => _mergeConfig(patch));
329
+ }
330
+
331
+ function _mergeConfig(patch) {
289
332
  let existing = {};
290
333
  if (fs.existsSync(UPDATE_CONFIG_PATH)) {
291
334
  try {
@@ -303,9 +346,85 @@ function _writeConfig(patch) {
303
346
  );
304
347
  }
305
348
  }
306
- const tmp = `${UPDATE_CONFIG_PATH}.tmp`;
307
- fs.writeFileSync(tmp, JSON.stringify({ ...existing, ...patch }, null, 2), "utf8");
308
- fs.renameSync(tmp, UPDATE_CONFIG_PATH);
349
+ const tmp = `${UPDATE_CONFIG_PATH}.${process.pid}.tmp`;
350
+ try {
351
+ fs.writeFileSync(tmp, JSON.stringify({ ...existing, ...patch }, null, 2), "utf8");
352
+ fs.renameSync(tmp, UPDATE_CONFIG_PATH);
353
+ } finally {
354
+ fs.rmSync(tmp, { force: true });
355
+ }
356
+ }
357
+
358
+ // The Terminal UI (tui/internal/update/config.go) honours the same lock file,
359
+ // so neither app's read-modify-write drops the other's change.
360
+ // Short: the wait blocks the main process. The Terminal UI holds it for milliseconds.
361
+ const LOCK_WAIT_MS = 500;
362
+ const LOCK_STALE_MS = 10000;
363
+
364
+ function _withConfigLock(fn) {
365
+ const lock = `${UPDATE_CONFIG_PATH}.lock`;
366
+ const deadline = Date.now() + LOCK_WAIT_MS;
367
+ for (;;) {
368
+ let openErr;
369
+ try {
370
+ fs.closeSync(fs.openSync(lock, "wx"));
371
+ break;
372
+ } catch (err) {
373
+ // Windows reports a lock still being deleted as EPERM/EACCES.
374
+ if (!err || !["EEXIST", "EPERM", "EACCES"].includes(err.code)) throw err;
375
+ openErr = err;
376
+ }
377
+ let stat = null;
378
+ try {
379
+ stat = fs.statSync(lock);
380
+ } catch (err) {
381
+ if (err.code !== "ENOENT") throw err;
382
+ }
383
+ if (!stat && openErr.code !== "EEXIST" && process.platform !== "win32") {
384
+ throw new Error(
385
+ `Cannot save update settings: ${path.dirname(UPDATE_CONFIG_PATH)} does not allow new files ` +
386
+ `(${openErr.message}) — fix its permissions.`
387
+ );
388
+ }
389
+ let staleErr = null;
390
+ if (stat && Date.now() - stat.mtimeMs > LOCK_STALE_MS) {
391
+ // Left by a crashed app. Two takers racing on the same stale lock can
392
+ // both get in; rare enough to accept for a settings file.
393
+ const aside = `${lock}.${process.pid}.stale`;
394
+ try {
395
+ fs.renameSync(lock, aside);
396
+ fs.rmSync(aside, { force: true });
397
+ continue;
398
+ } catch (err) {
399
+ if (err.code === "ENOENT") continue;
400
+ if (!["EPERM", "EACCES"].includes(err.code)) throw err;
401
+ staleErr = err;
402
+ }
403
+ }
404
+ if (Date.now() > deadline) {
405
+ if (staleErr) {
406
+ throw new Error(
407
+ `Cannot remove ${lock}, left by a GAIA app that stopped (${staleErr.message}) — fix the ` +
408
+ `permissions of ${path.dirname(UPDATE_CONFIG_PATH)} or delete the lock file by hand.`
409
+ );
410
+ }
411
+ if (!stat) {
412
+ throw new Error(
413
+ `Cannot lock ${UPDATE_CONFIG_PATH} (${openErr.message}) — check the permissions of ` +
414
+ `${path.dirname(UPDATE_CONFIG_PATH)}.`
415
+ );
416
+ }
417
+ throw new Error(
418
+ `${UPDATE_CONFIG_PATH} is busy (another GAIA app holds ${lock}) — try again in a moment.`
419
+ );
420
+ }
421
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
422
+ }
423
+ try {
424
+ return fn();
425
+ } finally {
426
+ fs.rmSync(lock, { force: true });
427
+ }
309
428
  }
310
429
 
311
430
  // ── Forward-update feed resolution (issue #1724) ────────────────────────────────
@@ -386,7 +505,7 @@ function _compareVersions(a, b) {
386
505
  function _platformManifest() {
387
506
  if (process.platform === "win32") return "latest.yml";
388
507
  if (process.platform === "darwin") return "latest-mac.yml";
389
- return "latest-linux.yml";
508
+ return process.arch === "arm64" ? "latest-linux-arm64.yml" : "latest-linux.yml";
390
509
  }
391
510
 
392
511
  /**
@@ -474,7 +593,7 @@ function _platformAssetPattern() {
474
593
  if (process.platform === "win32") return /setup\.exe$/i;
475
594
  if (process.platform === "darwin") return /\.zip$/i;
476
595
  // Linux: AppImage (deb is apt-managed, electron-updater can't downgrade it)
477
- return /\.AppImage$/i;
596
+ return process.arch === "arm64" ? /(arm64|aarch64)\.AppImage$/i : /(x86_64|amd64)\.AppImage$/i;
478
597
  }
479
598
 
480
599
  function _releaseHasPlatformAsset(release) {
@@ -605,7 +724,8 @@ async function installVersion(tag) {
605
724
  }
606
725
  setState({ pinnedVersion: tag });
607
726
  // A pin always stops background downloads; this one is downloaded below.
608
- autoUpdaterRef.autoDownload = false;
727
+ installRequested = true;
728
+ _applyInstallPolicy();
609
729
 
610
730
  checkInProgress = true;
611
731
  try {
@@ -691,9 +811,10 @@ function clearPin() {
691
811
  log("warn", "Failed to clear pin file:", err && err.message);
692
812
  }
693
813
  setState({ pinnedVersion: null });
814
+ installRequested = false;
694
815
 
695
816
  if (autoUpdaterRef) {
696
- autoUpdaterRef.autoDownload = state.autoUpdate;
817
+ _applyInstallPolicy();
697
818
  autoUpdaterRef.allowDowngrade = false;
698
819
  // Restore the forward channel (overrides any generic/tagged rollback feed
699
820
  // set by installVersion); unconfigured means GitHub releases.
@@ -721,10 +842,7 @@ async function setAutoUpdate(enabled) {
721
842
  );
722
843
  }
723
844
  setState({ autoUpdate: enabled });
724
- if (autoUpdaterRef) {
725
- autoUpdaterRef.autoDownload = enabled && !state.pinnedVersion;
726
- autoUpdaterRef.allowPrerelease = _prereleasesAllowed();
727
- }
845
+ _applyInstallPolicy();
728
846
  log("info", `Auto-update ${enabled ? "enabled" : "disabled"}`);
729
847
  // Turning it on with an update already offered means "install it".
730
848
  if (enabled && !state.pinnedVersion && state.status === STATES.AVAILABLE) {
@@ -765,11 +883,15 @@ async function downloadUpdate() {
765
883
  );
766
884
  }
767
885
  log("info", `User asked to install ${state.version}`);
886
+ installRequested = true;
887
+ _applyInstallPolicy();
768
888
  setState({ status: STATES.DOWNLOADING, progress: 0, error: null });
769
889
  try {
770
890
  await autoUpdaterRef.downloadUpdate();
771
891
  } catch (err) {
772
892
  const message = (err && err.message) || String(err);
893
+ installRequested = false;
894
+ _applyInstallPolicy();
773
895
  setState({ status: STATES.ERROR, error: message });
774
896
  throw new Error(`Downloading GAIA ${state.version || ""} failed: ${message}`);
775
897
  }
@@ -808,6 +930,12 @@ async function checkForUpdates() {
808
930
  log("info", "Skipping check — another check is already in progress");
809
931
  return;
810
932
  }
933
+ _refreshPreferences();
934
+ if (state.configError) {
935
+ // An unreadable file may hold a pin; checking anyway could offer past it.
936
+ setState({ status: STATES.ERROR, error: state.configError });
937
+ return;
938
+ }
811
939
  checkInProgress = true;
812
940
  setState({ status: STATES.CHECKING, error: null });
813
941
  try {
@@ -1070,6 +1198,7 @@ function init(mainWindow, options = {}) {
1070
1198
  state.autoUpdate = loaded.autoUpdate;
1071
1199
  state.includePrereleases = loaded.includePrereleases;
1072
1200
  state.configError = loaded.error;
1201
+ pinUnknown = Boolean(loaded.error);
1073
1202
 
1074
1203
  // Lazy-load Electron and electron-updater. Any failure here is logged
1075
1204
  // and the updater stays in `idle` — we never crash the app.
@@ -1093,6 +1222,8 @@ function init(mainWindow, options = {}) {
1093
1222
  app: electron.app,
1094
1223
  };
1095
1224
  autoUpdaterRef = electronUpdater.autoUpdater;
1225
+ // The Terminal UI may have turned auto-update off since the last check.
1226
+ electron.app.on("before-quit", _refreshPreferences);
1096
1227
 
1097
1228
  // Record the running version for getState() / listReleases().
1098
1229
  try {
@@ -1113,11 +1244,9 @@ function init(mainWindow, options = {}) {
1113
1244
  try {
1114
1245
  // Off by default; a pin always suppresses it so the scheduled forward-only
1115
1246
  // check cannot silently download/install a newer version (AC2).
1116
- autoUpdaterRef.autoDownload = !savedPin && state.autoUpdate;
1117
- autoUpdaterRef.autoInstallOnAppQuit = true;
1247
+ _applyInstallPolicy();
1118
1248
  autoUpdaterRef.disableWebInstaller = true;
1119
1249
  autoUpdaterRef.allowDowngrade = false;
1120
- autoUpdaterRef.allowPrerelease = _prereleasesAllowed();
1121
1250
 
1122
1251
  autoUpdaterRef.logger = {
1123
1252
  info: (m) => log("info", String(m)),
@@ -1184,6 +1313,7 @@ function destroy() {
1184
1313
  scheduledTimeout = null;
1185
1314
  }
1186
1315
  unregisterIpcHandlers();
1316
+ if (electronApi) electronApi.app.removeListener("before-quit", _refreshPreferences);
1187
1317
  mainWindowRef = null;
1188
1318
  // Keep `initialized` true — calling init() again after destroy() is not a
1189
1319
  // supported lifecycle and we'd need to re-wire electron-updater events
@@ -1,4 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{a as t,n,o as r,r as i}from"./apiBase-CS6zLsJY.js";import{$ as a,B as o,Ft as s,H as c,It as l,Pt as ee,Q as te,Qt as u,Rt as ne,U as re,V as ie,Vt as d,W as f,Wt as ae,Y as p,Z as oe,_t as se,cn as ce,dn as le,en as ue,fn as m,ft as de,lt as fe,ot as pe,q as me,st as h,t as g,vt as he}from"./index-Fhiym-Jy.js";var _={name:`circle-stop`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`rect`,{x:`9`,y:`9`,width:`6`,height:`6`,rx:`1`,key:`1ssd4o`}]],aliases:[`stop-circle`]};_.node;var v=t(_),y={name:`link-2`,size:24,node:[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]};y.node;var ge=t(y),b={name:`loader`,size:24,node:[[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m16.2 7.8 2.9-2.9`,key:`r700ao`}],[`path`,{d:`M18 12h4`,key:`wj9ykh`}],[`path`,{d:`m16.2 16.2 2.9 2.9`,key:`1bxg5t`}],[`path`,{d:`M12 18v4`,key:`jadmvz`}],[`path`,{d:`m4.9 19.1 2.9-2.9`,key:`bwix9q`}],[`path`,{d:`M2 12h4`,key:`j09sii`}],[`path`,{d:`m4.9 4.9 2.9 2.9`,key:`giyufr`}]]};b.node;var _e=t(b),x={name:`refresh-ccw`,size:24,node:[[`path`,{d:`M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`14sxne`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16`,key:`1hlbsb`}],[`path`,{d:`M16 16h5v5`,key:`ccwih5`}]]};x.node;var ve=t(x),S=e(r(),1),C=n();function ye(e){let[t,...n]=e.replace(/^RAG indexing failed for [^:]+:\s*/,``).trim().split(`
2
- `);return{summary:t.trim(),more:n.join(`
3
- `).trim()}}function be(e,t){let n=t.skipped??0,r=[];if(t.indexed>0?r.push(`Indexed ${t.indexed} file${t.indexed===1?``:`s`} from "${e}".`):t.failed===0&&r.push(`"${e}" has no documents GAIA can index.`),n>0&&r.push(`Skipped ${n} file${n===1?``:`s`} of a type GAIA doesn't index.`),t.failed>0){let e=t.errors[0]?` ${t.errors[0].split(`
4
- `)[0]}`:``;r.push(`${t.failed} file${t.failed===1?``:`s`} couldn't be indexed.${e}`)}return r.push(`Subfolders aren't included.`),r.join(` `)}function xe(e){let t=Math.floor((Date.now()-e)/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Se(e){try{let t=new Date(e);if(isNaN(t.getTime()))return``;let n=new Date().getTime()-t.getTime(),r=Math.floor(n/1e3),i=Math.floor(r/60),a=Math.floor(i/60),o=Math.floor(a/24);return r<60?`just now`:i<60?`${i}m ago`:a<24?`${a}h ago`:o===1?`yesterday`:o<7?`${o}d ago`:t.toLocaleDateString(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`})}catch{return``}}function Ce(e){try{let t=new Date(e);return isNaN(t.getTime())?``:t.toLocaleString(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,second:`2-digit`})}catch{return``}}function w(){let{documents:e,setDocuments:t,setShowDocLibrary:n,setShowFileBrowser:r,currentSessionId:_,sessions:y,updateSessionInList:b,draftDocumentIds:x,addDraftDocuments:w,removeDraftDocument:T}=s(),E=y.find(e=>e.id===_)??null,[D,we]=(0,S.useState)(_?`chat`:`next`),O=D===`chat`?_:null,k=`“${E?.title||`Untitled chat`}”`,[A,j]=(0,S.useState)(``),Te=(0,S.useCallback)(()=>n(!1),[n]);ee(!0,Te);let M=(0,S.useRef)(null);f(M,!0);let[Ee,N]=(0,S.useState)(!1),[P,F]=(0,S.useState)(!1),[De,I]=(0,S.useState)(``),[L,R]=(0,S.useState)(``),[z,B]=(0,S.useState)(null),[V,H]=(0,S.useState)(null),[U,W]=(0,S.useState)(new Set),G=(0,S.useRef)(new Map),[,Oe]=(0,S.useState)(0);(0,S.useEffect)(()=>{i.doc.info(`Loading document library...`);let e=i.doc.time();h().then(n=>{let r=n.documents||[];t(r),i.doc.timed(`Loaded ${r.length} document(s), ${n.total_chunks||0} chunks, ${n.total_size_bytes||0} bytes total`,e)}).catch(e=>{i.doc.error(`Failed to load documents`,e),t([])})},[t]);let K=e.some(e=>e.indexing_status===`indexing`||e.indexing_status===`pending`);(0,S.useEffect)(()=>{if(!K)return;let e=s.getState().documents;for(let t of e)(t.indexing_status===`indexing`||t.indexing_status===`pending`)&&!G.current.has(t.id)&&G.current.set(t.id,Date.now());let n=!1,r=setInterval(async()=>{if(Oe(e=>e+1),!n){n=!0;try{let e=s.getState().documents.filter(e=>e.indexing_status===`indexing`||e.indexing_status===`pending`);for(let n of e)try{let e=await a(n.id);if(e.indexing_status!==`indexing`&&e.indexing_status!==`pending`){G.current.delete(n.id);let e=await h();t(e.documents||[]);break}}catch{}}finally{n=!1}}},2e3);return()=>clearInterval(r)},[K,t]),(0,S.useEffect)(()=>{let t=new Set(e.filter(e=>e.indexing_status===`indexing`||e.indexing_status===`pending`).map(e=>e.id));for(let e of G.current.keys())t.has(e)||G.current.delete(e)},[e]),(0,S.useEffect)(()=>{let e=setInterval(async()=>{try{let e=(await h()).documents||[],n=s.getState().documents;(e.length!==n.length||e.some((e,t)=>{let r=n.find(t=>t.id===e.id);return!r||r.indexing_status!==e.indexing_status||r.indexed_at!==e.indexed_at||r.chunk_count!==e.chunk_count}))&&(t(e),i.doc.debug(`Document list refreshed (server-side changes detected)`))}catch{}},15e3);return()=>clearInterval(e)},[t]);let ke=e.reduce((e,t)=>e+t.file_size,0),q=e.reduce((e,t)=>e+t.chunk_count,0),J=(0,S.useCallback)(async(e,t)=>{if(!O){w([e]),j(`${t} will be attached to your next new chat.`),i.doc.info(`"${t}" will be attached to the next new chat`);return}await p(O,e);let n=s.getState().sessions.find(e=>e.id===O)?.document_ids??[];n.includes(e)||b(O,{document_ids:[...n,e]}),j(`Attached ${t} to ${k}.`),i.doc.info(`Attached "${t}" to session ${O}`)},[O,k,b,w]),Y=(0,S.useCallback)(async(e,t)=>{if(e.length===0)return;if(!O){w(e),i.doc.info(`"${t}" will be attached to the next new chat`);return}let n=[];for(let t of e)try{await p(O,t),n.push(t)}catch(e){i.doc.warn(`Could not attach document to session: ${e}`)}let r=s.getState().sessions.find(e=>e.id===O)?.document_ids??[],a=n.filter(e=>!r.includes(e));a.length>0&&b(O,{document_ids:[...r,...a]}),i.doc.info(`Attached "${t}" to session ${O}`)},[O,b,w]),X=(0,S.useCallback)(async(e,n,r)=>{let a=e.includes(`.`)?`.`+e.split(`.`).pop()?.toLowerCase():``,o=a&&!re(a)?c(a)?.message??`The file type "${a}" is not supported for indexing.`:null;if(o&&!r){i.doc.warn(`Unsupported file type: ${e} (${a})`),B({filename:e,error:o});return}i.doc.info(`Indexing document: ${e}`);let s=i.doc.time();F(!0),I(`Indexing ${e}...`),B(null),H(null),j(``);try{let r=await n();if(i.doc.timed(`Indexed "${e}": ${r?.chunk_count||`?`} chunks`,s),r?.id)try{await J(r.id,r.filename||e)}catch(t){i.doc.error(`Could not attach "${e}" to ${k}`,t),B({filename:e,error:`Indexed, but not attached to ${k}: ${t instanceof Error?t.message:t}`})}let a=await h();t(a.documents||[]),I(``)}catch(t){let{httpStatus:n,reason:a}=t??{};if(a===`is_folder`&&r){await r();return}i.doc.error(`Failed to index "${e}"`,t);let s=n===400&&o?o:t instanceof Error?t.message:`Upload failed`;B({filename:e,error:s,status:n,kind:a}),I(``)}finally{F(!1)}},[J,k,t]),Z=(0,S.useCallback)(async(e,n)=>{i.doc.info(`"${e}" is a folder; indexing its documents`),I(`Indexing the documents in ${n}...`);try{let r=await pe(e,!1);await Y(r.documents.map(e=>e.id).filter(Boolean),n),H(be(n,r));let i=await h();t(i.documents||[])}catch(t){i.doc.error(`Failed to index folder "${e}"`,t);let r=t instanceof Error?t.message:`Folder indexing failed`,{httpStatus:a}=t??{};B({filename:n,error:r,status:a})}finally{I(``)}},[Y,t]),Q=(0,S.useCallback)(async(e,t)=>{await X(t,()=>he(e),()=>Z(e,t))},[X,Z]),$=(0,S.useCallback)(async e=>{await X(e.name,()=>se(e))},[X]),Ae=(0,S.useCallback)(async e=>{e.preventDefault(),N(!1);let t=Array.from(e.dataTransfer.files);i.doc.info(`Dropped ${t.length} file(s) into Document Library`);for(let e of t)await $(e)},[$]),je=(0,S.useCallback)(async n=>{let r=e.find(e=>e.id===n);i.doc.info(`Deleting document: ${r?.filename||n}`);try{await te(n),G.current.delete(n),T(n),t(e.filter(e=>e.id!==n)),i.doc.info(`Deleted document: ${r?.filename||n}`)}catch(e){i.doc.error(`Failed to delete document: ${r?.filename||n}`,e)}},[e,t,T]),Me=(0,S.useCallback)(async(e,t)=>{i.doc.info(`Opening folder for: ${e}`);try{await fe(e,!0)}catch(e){i.doc.error(`Failed to open folder for: ${t}`,e)}},[]),Ne=(0,S.useCallback)(async n=>{let r=e.find(e=>e.id===n);i.doc.info(`Cancelling indexing for: ${r?.filename||n}`);try{await oe(n),G.current.delete(n);let e=await h();t(e.documents||[]),i.doc.info(`Cancelled indexing for: ${r?.filename||n}`)}catch(e){i.doc.error(`Failed to cancel indexing: ${r?.filename||n}`,e)}},[e,t]),Pe=(0,S.useCallback)(async n=>{if(U.has(n))return;let r=e.find(e=>e.id===n);i.doc.info(`Reindexing document: ${r?.filename||n}`),W(e=>new Set(e).add(n));try{await de(n),i.doc.info(`Reindex complete for: ${r?.filename||n}`)}catch(e){let t=e instanceof Error?e.message:String(e);i.doc.error(`Reindex failed for: ${r?.filename||n}`,e),B({filename:r?.filename||n,error:t})}finally{try{let e=await h();t(e.documents||[])}catch(e){i.doc.error(`Failed to refresh documents after reindex`,e)}W(e=>{let t=new Set(e);return t.delete(n),t})}},[e,t,U]),Fe=(0,S.useCallback)(async t=>{let n=e.find(e=>e.id===t)?.filename||t;j(``);try{await J(t,n)}catch(e){i.doc.error(`Failed to attach ${n} to ${k}`,e),B({filename:n,error:`Not attached to ${k}: ${e instanceof Error?e.message:e}`})}},[e,J,k]),Ie=(0,S.useCallback)(async e=>{if(e.preventDefault(),!L.trim())return;let t=L.trim();i.doc.info(`Indexing from path input: ${t}`),await Q(t,t.replace(/[\\/]+$/,``).split(/[\\/]/).pop()||`file`),R(``)},[L,Q]),Le=e=>{let t=e.indexing_status||`complete`,n=G.current.get(e.id),r=e.indexed_at?Se(e.indexed_at):``,i=e.indexed_at?Ce(e.indexed_at):``;switch(t){case`indexing`:case`pending`:return(0,C.jsxs)(`div`,{className:`doc-indexing-status`,children:[(0,C.jsxs)(`div`,{className:`doc-indexing-bar`,children:[(0,C.jsx)(`div`,{className:`doc-indexing-bar-track`,children:(0,C.jsx)(`div`,{className:`doc-indexing-bar-fill`})}),(0,C.jsxs)(`span`,{className:`doc-indexing-label`,children:[(0,C.jsx)(_e,{size:12,className:`doc-spin`}),`Indexing`,n?` (${xe(n)})`:`...`]})]}),(0,C.jsxs)(`button`,{className:`btn-cancel`,onClick:t=>{t.stopPropagation(),Ne(e.id)},title:`Cancel indexing`,"aria-label":`Cancel indexing ${e.filename}`,children:[(0,C.jsx)(v,{size:14}),`Cancel`]})]});case`failed`:{let t=e.error_kind?o[e.error_kind]:void 0,n=e.last_error?ye(e.last_error):null;return(0,C.jsxs)(`div`,{className:`doc-failure`,children:[(0,C.jsxs)(`div`,{className:`doc-indexing-status`,children:[(0,C.jsxs)(`span`,{className:`doc-status-badge doc-status-failed`,title:e.last_error||void 0,"aria-label":e.last_error?`Failed: ${e.last_error}`:`Indexing failed`,children:[(0,C.jsx)(m,{size:12}),` `,t?`Can't be read`:`Failed`]}),(0,C.jsxs)(`button`,{className:t?`btn-retry btn-retry-quiet`:`btn-retry`,onClick:t=>{t.stopPropagation(),Pe(e.id)},title:t?`Retry indexing (fix the file first, or this fails again)`:`Retry indexing`,"aria-label":`Retry indexing ${e.filename}`,disabled:U.has(e.id),children:[(0,C.jsx)(ve,{size:t?12:14}),U.has(e.id)?`Retrying…`:`Retry`]})]}),t&&(0,C.jsx)(`p`,{className:`doc-failure-hint`,children:t}),n&&(n.more?(0,C.jsxs)(`details`,{className:`doc-failure-reason`,children:[(0,C.jsx)(`summary`,{children:n.summary}),(0,C.jsx)(`p`,{children:n.more})]}):(0,C.jsx)(`p`,{className:`doc-failure-reason`,children:n.summary})),!n&&!t&&(0,C.jsx)(`p`,{className:`doc-failure-reason`,children:`GAIA didn't record why. Retry to see the error.`})]})}case`cancelled`:return(0,C.jsxs)(`span`,{className:`doc-status-badge doc-status-cancelled`,children:[(0,C.jsx)(v,{size:12}),` Cancelled`]});case`missing`:return(0,C.jsxs)(`span`,{className:`doc-status-badge doc-status-missing`,children:[(0,C.jsx)(m,{size:12}),` File missing`]});default:return(0,C.jsxs)(`span`,{className:`doc-meta`,children:[g(e.file_size),` · `,e.chunk_count,` chunk`,e.chunk_count===1?``:`s`,r&&(0,C.jsxs)(`span`,{className:`doc-timestamp`,title:`Indexed: ${i}`,children:[(0,C.jsx)(ce,{size:10}),r]})]})}};return(0,C.jsx)(`div`,{ref:M,className:`modal-overlay`,onClick:()=>n(!1),role:`dialog`,"aria-modal":`true`,"aria-label":`Document library`,children:(0,C.jsxs)(`div`,{className:`modal-panel doc-modal`,onClick:e=>e.stopPropagation(),children:[(0,C.jsxs)(`div`,{className:`modal-header`,children:[(0,C.jsx)(`h3`,{children:`Document library`}),(0,C.jsx)(`button`,{className:`btn-icon`,onClick:()=>n(!1),"aria-label":`Close document library`,children:(0,C.jsx)(l,{size:18})})]}),(0,C.jsxs)(`div`,{className:`modal-body`,children:[(0,C.jsxs)(`div`,{className:`doc-target`,children:[_?(0,C.jsxs)(`label`,{className:`doc-target-choice`,children:[`Add documents to`,(0,C.jsxs)(`select`,{value:D,onChange:e=>{we(e.target.value),j(``)},children:[(0,C.jsxs)(`option`,{value:`chat`,children:[`This chat: `,k]}),(0,C.jsx)(`option`,{value:`next`,children:`Your next new chat`})]})]}):(0,C.jsx)(`span`,{children:`Documents you add here are attached to your next new chat.`}),(0,C.jsx)(`span`,{className:`doc-target-hint`,children:`A chat searches only the documents attached to it.`})]}),(0,C.jsx)(`div`,{className:`drop-zone ${Ee?`drag-over`:``} ${P?`uploading`:``}`,onDragOver:e=>{e.preventDefault(),N(!0)},onDragLeave:()=>N(!1),onDrop:Ae,children:P?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{className:`upload-spinner`}),(0,C.jsx)(`p`,{children:De})]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(ne,{size:32,strokeWidth:1.5}),(0,C.jsx)(`p`,{children:`Drop files here to index`}),(0,C.jsx)(`span`,{className:`drop-hint`,children:`PDF, TXT, MD, code files, and 50+ formats`})]})}),(0,C.jsxs)(`form`,{className:`path-input-form`,onSubmit:Ie,children:[(0,C.jsx)(u,{size:16,className:`path-icon`}),(0,C.jsx)(`input`,{type:`text`,className:`path-input`,value:L,onChange:e=>R(e.target.value),placeholder:`Or enter a file or folder path: ${me()}`,"aria-label":`File path to index`}),(0,C.jsx)(`button`,{type:`submit`,className:`btn-secondary`,disabled:!L.trim()||P,children:`Index`}),(0,C.jsxs)(`button`,{type:`button`,className:`btn-secondary`,onClick:()=>{n(!1),r(!0)},title:`Browse files on this computer`,children:[(0,C.jsx)(ae,{size:14}),`Browse files`]})]}),A&&(0,C.jsx)(`p`,{className:`doc-target-notice`,role:`status`,children:A}),z&&(0,C.jsx)(ie,{filename:z.filename,error:z.error,status:z.status,kind:z.kind,onDismiss:()=>B(null)}),V&&(0,C.jsxs)(`div`,{className:`doc-folder-notice`,role:`status`,children:[(0,C.jsx)(le,{size:14}),(0,C.jsx)(`span`,{children:V}),(0,C.jsx)(`button`,{className:`btn-icon-sm`,onClick:()=>H(null),"aria-label":`Dismiss folder indexing result`,children:(0,C.jsx)(l,{size:12})})]}),e.length>0&&(0,C.jsxs)(`div`,{className:`doc-stats`,children:[(0,C.jsxs)(`span`,{children:[e.length,` document`,e.length===1?``:`s`]}),(0,C.jsx)(`span`,{children:`·`}),(0,C.jsxs)(`span`,{children:[q,` chunk`,q===1?``:`s`]}),(0,C.jsx)(`span`,{children:`·`}),(0,C.jsx)(`span`,{children:g(ke)})]}),(0,C.jsxs)(`div`,{className:`doc-list`,children:[e.length===0&&!P&&(0,C.jsxs)(`div`,{className:`empty-docs`,children:[(0,C.jsx)(ue,{size:32,strokeWidth:1}),(0,C.jsx)(`p`,{children:`No documents indexed yet`}),(0,C.jsx)(`span`,{children:`Drop files above or enter a file path`})]}),e.map(e=>(0,C.jsxs)(`div`,{className:`doc-row ${e.indexing_status===`indexing`?`doc-row-indexing`:``}`,children:[(0,C.jsxs)(`div`,{className:`doc-info`,children:[(0,C.jsx)(`span`,{className:`doc-name`,children:e.filename}),Le(e)]}),(0,C.jsxs)(`div`,{className:`doc-row-actions`,children:[e.filepath&&(0,C.jsx)(`button`,{className:`btn-icon-sm doc-open-folder`,onClick:()=>Me(e.filepath,e.filename),title:`Open folder: ${e.filepath}`,"aria-label":`Open containing folder for ${e.filename}`,children:(0,C.jsx)(u,{size:14})}),e.indexing_status===`complete`&&!(O?E?.document_ids?.includes(e.id):x.includes(e.id))&&(0,C.jsx)(`button`,{className:`btn-icon-sm doc-attach`,onClick:()=>Fe(e.id),title:O?`Use in ${k}`:`Use in your next chat`,"aria-label":O?`Attach ${e.filename} to ${k}`:`Attach ${e.filename} to your next chat`,children:(0,C.jsx)(ge,{size:14})}),e.indexing_status!==`indexing`&&e.indexing_status!==`pending`&&(0,C.jsx)(`button`,{className:`btn-icon-sm doc-delete`,onClick:()=>je(e.id),title:`Remove`,"aria-label":`Remove ${e.filename}`,children:(0,C.jsx)(d,{size:14})})]})]},e.id))]})]})]})})}export{w as DocumentLibrary};
@@ -1,4 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{a as t,n,o as r,r as i}from"./apiBase-CS6zLsJY.js";import{$t as a,Ft as o,H as s,It as c,Jt as l,Pt as u,Qt as d,Rt as f,U as p,V as ee,W as te,Wt as ne,X as re,Y as m,Zt as h,_n as ie,dt as ae,en as g,in as _,mn as oe,ot as se,pt as ce,st as v,t as le,tn as ue,vn as de,vt as y}from"./index-Fhiym-Jy.js";var b={name:`code`,size:24,node:[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]};b.node;var x=t(b),S={name:`hard-drive`,size:24,node:[[`path`,{d:`M10 16h.01`,key:`1bzywj`}],[`path`,{d:`M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`18tbho`}],[`path`,{d:`M21.946 12.013H2.054`,key:`zqlbp7`}],[`path`,{d:`M6 16h.01`,key:`1pmjb7`}]]};S.node;var fe=t(S),C={name:`house`,size:24,node:[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`r6nss1`}]],aliases:[`home`]};C.node;var w=t(C),T={name:`table`,size:24,node:[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`M3 15h18`,key:`5xshup`}]]};T.node;var E=t(T),D=e(r(),1),O=n();function pe(e){if(e.type===`folder`)return(0,O.jsx)(h,{size:16});let t=(e.extension||``).toLowerCase();return[`.csv`,`.xlsx`,`.xls`,`.tsv`].includes(t)?(0,O.jsx)(E,{size:16}):[`.py`,`.js`,`.ts`,`.java`,`.c`,`.cpp`,`.go`,`.rs`].includes(t)?(0,O.jsx)(x,{size:16}):[`.pdf`,`.doc`,`.docx`,`.txt`,`.md`].includes(t)?(0,O.jsx)(g,{size:16}):(0,O.jsx)(a,{size:16})}function me(e){if(!e)return``;let t=new Date(e),n=new Date,r=n.getTime()-t.getTime(),i=Math.floor(r/36e5);if(i<1)return`Just now`;if(i<24)return`${i}h ago`;let a=Math.floor(i/24);return a<7?`${a}d ago`:t.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:t.getFullYear()===n.getFullYear()?void 0:`numeric`})}function he(e){if(e.length===0)return``;let[t,...n]=e;return n.length>0?`${t} (+${n.length} more)`:t}function ge(e){switch(e){case`home`:return(0,O.jsx)(w,{size:14});case`desktop`:return(0,O.jsx)(l,{size:14});case`documents`:return(0,O.jsx)(g,{size:14});case`download`:return(0,O.jsx)(_,{size:14});default:return(0,O.jsx)(h,{size:14})}}var _e=[{label:`All Files`,value:``},{label:`Documents`,value:`pdf,doc,docx,txt,md`},{label:`Spreadsheets`,value:`csv,xlsx,xls,tsv`},{label:`Code`,value:`py,js,ts,java,c,cpp,go,rs,rb,sh`},{label:`Data`,value:`json,xml,yaml,yml,csv,tsv`}];async function k(e,t,n,r){let a=[],s=[];for(let t of e){let e=t.includes(`.`)?`.`+t.split(`.`).pop()?.toLowerCase():``;e&&!p(e)?s.push(t):a.push(t)}let c=[],l=[],u=0,d=``,f=new Set(t.filter(e=>e.type===`folder`).map(e=>e.path));for(let e of a)try{if(f.has(e)){let t=await se(e),n=[];t.documents.forEach(e=>{e.id&&n.push(e.id)}),n.length>0&&(n.forEach(e=>c.push(e)),l.push(e))}else{let t=await y(e);t?.id&&(c.push(t.id),l.push(e))}}catch(e){u++,d=e instanceof Error?e.message:`Unknown error`}if(n&&c.length>0){let e=[];for(let t of c)try{await m(n,t),e.push(t)}catch(e){i.doc.warn(`Could not attach document to session: ${e}`)}let t=o.getState().sessions.find(e=>e.id===n)?.document_ids??[],a=e.filter(e=>!t.includes(e));a.length>0&&r(n,{document_ids:[...t,...a]})}else c.length>0&&o.getState().addDraftDocuments(c);if(c.length>0)try{let e=await v();o.getState().setDocuments(e.documents||[])}catch(e){i.doc.error(`Could not refresh the document list after indexing`,e)}return{docIds:c,supported:a,succeededFiles:l,unsupported:s,failed:u,lastError:d}}var A=e=>e.startsWith(`.`);function j({onStartChat:e}){let{setShowFileBrowser:t,currentSessionId:n,updateSessionInList:r,setPendingPrompt:a}=o(),l=(0,D.useCallback)(()=>t(!1),[t]);u(!0,l);let m=(0,D.useRef)(null);te(m,!0);let[h,g]=(0,D.useState)(``),[_,se]=(0,D.useState)(null),[v,y]=(0,D.useState)([]),[b,x]=(0,D.useState)([]),[S,C]=(0,D.useState)(!1),[w,T]=(0,D.useState)(null),[E,j]=(0,D.useState)(!1),[M,N]=(0,D.useState)(``),[P,F]=(0,D.useState)(null),[I,L]=(0,D.useState)([]),[ve,ye]=(0,D.useState)(!1),[R,z]=(0,D.useState)(!1),[B,be]=(0,D.useState)(``),[V,H]=(0,D.useState)(new Set),[U,W]=(0,D.useState)(null),[xe,G]=(0,D.useState)(!1),[Se,K]=(0,D.useState)(new Set),[Ce,q]=(0,D.useState)(null),J=(0,D.useRef)(null),[Y,X]=(0,D.useState)(null),Z=(0,D.useCallback)(async e=>{C(!0),T(null),F(null),N(``),L([]);try{let t=await re(e);g(t.current_path),se(t.parent_path),y(t.entries),t.quick_links.length>0&&x(t.quick_links),i.ui.info(`Browsing: ${t.current_path} (${t.entries.length} items)`)}catch(e){let t=e instanceof Error?e.message:`Failed to load directory`;T(t),i.ui.error(`Browse failed`,e)}finally{C(!1)}},[]);(0,D.useEffect)(()=>{Z()},[Z]),(0,D.useEffect)(()=>()=>{J.current&&clearTimeout(J.current)},[]);let we=(0,D.useCallback)(async()=>{if(!M.trim())F(null),L([]);else{z(!0),T(null);try{let e=await ce(M.trim(),B||void 0,30);F(e.results),L(e.searched_locations??[]),ye(e.truncated===!0),i.ui.info(`Search "${M}": ${e.total} results`)}catch(e){let t=e instanceof Error?e.message:`Search failed`;T(t),i.ui.error(`Search failed`,e)}finally{z(!1)}}},[M,B]),Te=e=>{e.key===`Enter`&&we()},Ee=(0,D.useCallback)(e=>{e.type===`folder`&&(Z(e.path),H(new Set),W(null))},[Z]),De=(0,D.useCallback)(async e=>{G(!0);try{let t=await ae(e);W(t)}catch(e){i.ui.error(`Preview failed`,e)}finally{G(!1)}},[]),Oe=(0,D.useCallback)(e=>{H(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ke=(0,D.useCallback)(async()=>{if(V.size===0)return;let e=Array.from(V);if(X(null),!e.some(e=>{let t=e.includes(`.`)?`.`+e.split(`.`).pop()?.toLowerCase():``;return!t||p(t)})){let t=e[0],n=t.lastIndexOf(`.`),r=n>0?t.slice(n).toLowerCase():``,i=s(r);X({filename:e.length===1?t.split(/[\\/]/).pop()||t:`${e.length} files`,error:i?i.message:`File type "${r}" is not supported for indexing.`})}else{K(new Set(e)),q(`Indexing ${e.length} file(s)...`);try{let t=await k(e,v,n,r);if(t.failed>0)q(`Done: ${t.docIds.length} indexed, ${t.failed} failed`),X({filename:`${t.failed} file(s)`,error:t.lastError||`Indexing failed for some files`});else{let e=t.unsupported.length>0?` (${t.unsupported.length} skipped — unsupported type)`:``;q(`Successfully indexed ${t.docIds.length} file(s)${e}`)}J.current&&clearTimeout(J.current),J.current=setTimeout(()=>q(null),5e3),H(new Set)}catch(t){i.doc.error(`Index selected failed`,t),X({filename:e.length===1?e[0].split(/[\\/]/).pop()||e[0]:`${e.length} files`,error:t instanceof Error?t.message:`An unexpected error occurred.`})}finally{K(new Set)}}},[V,n,r,v]),Q=(0,D.useRef)(!1),Ae=(0,D.useCallback)(async()=>{if(V.size===0||Q.current)return;Q.current=!0;let o=Array.from(V);X(null),K(new Set(o)),q(`Indexing ${o.length} file(s) for analysis...`);try{let i=await k(o,v,n,r);if(i.supported.length===0){let e=o[0].lastIndexOf(`.`),t=e>0?o[0].slice(e).toLowerCase():``,n=s(t);X({filename:o.length===1?o[0].split(/[\\/]/).pop()||o[0]:`${o.length} files`,error:n?.message??`File type "${t}" is not supported for indexing.`});return}if(i.docIds.length===0){X({filename:i.supported.length===1?i.supported[0].split(/[\\/]/).pop()||i.supported[0]:`${i.supported.length} files`,error:`Failed to index selected file(s). Please try again.`});return}i.failed>0&&q(`Warning: ${i.failed} file(s) failed to index and will be excluded.`);let c=(i.succeededFiles.length>0?i.succeededFiles:i.supported).map(e=>e.split(/[\\/]/).pop()||e),l=c.length===1?`Please analyze this document for me: ${c[0]}`:`Please analyze these documents for me:\n${c.map(e=>`- ${e}`).join(`
2
- `)}`;n?a({sessionId:n,text:l}):await e(l),t(!1),H(new Set)}catch(e){i.doc.error(`Ask Agent failed`,e),X({filename:o.length===1?o[0].split(/[\\/]/).pop()||o[0]:`${o.length} files`,error:e instanceof Error?e.message:`An unexpected error occurred.`})}finally{Q.current=!1,K(new Set),q(null)}},[V,n,r,v,a,t,e]),je=h?h.replace(/\\/g,`/`).split(`/`).filter(Boolean):[],Me=je.map((e,t)=>({label:e,path:je.slice(0,t+1).join(`/`)+(t===0&&e.includes(`:`)?`/`:``)})),Ne=he(I),Pe=v.filter(e=>!A(e.name)),$=P?P.map(e=>({name:e.name,path:e.path,type:`file`,size:e.size,extension:e.extension||``,modified:e.modified||``})):E?v:Pe,Fe=v.length-Pe.length;return(0,D.useEffect)(()=>{E||P||H(e=>{let t=[...e].filter(e=>!A(e.split(/[\\/]/).pop()??``));return t.length===e.size?e:new Set(t)})},[E,P]),(0,O.jsx)(`div`,{ref:m,className:`modal-overlay`,onClick:()=>t(!1),role:`dialog`,"aria-modal":`true`,"aria-label":`File browser`,children:(0,O.jsxs)(`div`,{className:`modal-panel file-browser-modal ${U?`has-preview`:``}`,onClick:e=>e.stopPropagation(),children:[(0,O.jsxs)(`div`,{className:`modal-header`,children:[(0,O.jsxs)(`h3`,{children:[(0,O.jsx)(d,{size:18}),` File browser`]}),(0,O.jsx)(`button`,{className:`btn-icon`,onClick:()=>t(!1),"aria-label":`Close`,children:(0,O.jsx)(c,{size:18})})]}),(0,O.jsxs)(`div`,{className:`file-browser-body`,children:[(0,O.jsx)(`div`,{className:`fb-quick-links`,children:b.map(e=>(0,O.jsxs)(`button`,{className:`fb-quick-link`,onClick:()=>Z(e.path),title:e.path,children:[ge(e.icon),(0,O.jsx)(`span`,{children:e.name})]},e.path))}),(0,O.jsxs)(`div`,{className:`fb-search-bar`,children:[(0,O.jsxs)(`div`,{className:`fb-search-input-wrap`,children:[(0,O.jsx)(ne,{size:14,className:`fb-search-icon`}),(0,O.jsx)(`input`,{type:`text`,className:`fb-search-input`,placeholder:`Search files on your PC...`,value:M,onChange:e=>N(e.target.value),onKeyDown:Te,"aria-label":`Search files`}),M&&(0,O.jsx)(`button`,{className:`fb-search-clear`,onClick:()=>{N(``),F(null),L([])},"aria-label":`Clear search`,children:(0,O.jsx)(c,{size:12})})]}),(0,O.jsx)(`select`,{className:`fb-type-filter`,value:B,onChange:e=>be(e.target.value),"aria-label":`File type filter`,children:_e.map(e=>(0,O.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,O.jsx)(`button`,{className:`fb-search-btn`,onClick:we,disabled:!M.trim()||R,children:R?`Searching...`:`Search`})]}),!P&&(0,O.jsxs)(`div`,{className:`fb-pathbar`,children:[(0,O.jsxs)(`div`,{className:`fb-breadcrumb`,children:[(0,O.jsx)(`button`,{className:`fb-crumb`,onClick:()=>Z(`/`),children:(0,O.jsx)(fe,{size:12})}),Me.map((e,t)=>(0,O.jsxs)(`span`,{className:`fb-crumb-item`,children:[(0,O.jsx)(oe,{size:12,className:`fb-crumb-sep`}),(0,O.jsx)(`button`,{className:`fb-crumb`,onClick:()=>Z(e.path),children:e.label})]},t)),_&&(0,O.jsx)(`button`,{className:`fb-up-btn`,onClick:()=>Z(_),title:`Go up`,children:(0,O.jsx)(de,{size:14})})]}),(0,O.jsxs)(`label`,{className:`fb-hidden-toggle`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>j(e.target.checked)}),`Show hidden`]})]}),P&&(0,O.jsxs)(`div`,{className:`fb-search-header`,children:[(0,O.jsxs)(`div`,{className:`fb-search-summary`,children:[(0,O.jsxs)(`span`,{children:[`Found `,P.length,` result(s) for "`,M,`"`]}),Ne&&(0,O.jsxs)(`span`,{className:`fb-search-scope`,title:I.join(`
3
- `),children:[`Searching in: `,(0,O.jsx)(`code`,{children:Ne})]}),ve&&(0,O.jsx)(`span`,{children:`Search stopped early, so some matches may be missing. Try a more specific name.`})]}),(0,O.jsx)(`button`,{className:`fb-back-btn`,onClick:()=>{F(null),N(``),L([])},children:`Back to browsing`})]}),w&&(0,O.jsx)(`div`,{className:`fb-error`,children:w}),(0,O.jsxs)(`div`,{className:`fb-content`,children:[(0,O.jsxs)(`div`,{className:`fb-file-list`,children:[S&&(0,O.jsx)(`div`,{className:`fb-loading`,children:`Loading...`}),!S&&$.length===0&&(0,O.jsx)(`div`,{className:`fb-empty`,children:P?`No files found`:Fe>0?`Only hidden items here. Turn on Show hidden to see them.`:`This folder is empty`}),!S&&$.map(e=>{let t=e.extension||(e.name.includes(`.`)?`.`+e.name.split(`.`).pop()?.toLowerCase():``),n=e.type===`file`&&t&&!p(t),r=n?s(t):null;return(0,O.jsxs)(`div`,{className:`fb-entry ${e.type} ${V.has(e.path)?`selected`:``} ${n?`unsupported`:``}`,onClick:()=>e.type===`folder`?Ee(e):Oe(e.path),onDoubleClick:()=>e.type===`folder`?Ee(e):void 0,title:n?`${r?.label||`This`} file type cannot be indexed`:e.path,children:[(0,O.jsx)(`input`,{type:`checkbox`,className:`fb-entry-checkbox`,checked:V.has(e.path),onChange:()=>Oe(e.path),onClick:e=>e.stopPropagation(),"aria-label":`Select ${e.name}`}),(0,O.jsx)(`span`,{className:`fb-entry-icon`,children:pe(e)}),(0,O.jsx)(`span`,{className:`fb-entry-name`,title:e.path,children:e.name}),n&&(0,O.jsx)(`span`,{className:`fb-unsupported-badge`,children:`Not indexable`}),e.type===`file`&&(0,O.jsx)(`button`,{type:`button`,className:`fb-entry-preview-btn`,onClick:t=>{t.stopPropagation(),De(e.path)},"aria-label":`Preview ${e.name}`,title:`Preview file`,children:(0,O.jsx)(ue,{size:14})}),(0,O.jsx)(`span`,{className:`fb-entry-size`,children:e.type===`file`?le(e.size):``}),(0,O.jsx)(`span`,{className:`fb-entry-date`,children:me(e.modified)})]},e.path)})]}),U&&(0,O.jsxs)(`div`,{className:`fb-preview`,children:[(0,O.jsxs)(`div`,{className:`fb-preview-header`,children:[(0,O.jsx)(`span`,{className:`fb-preview-name`,children:U.name}),(0,O.jsx)(`button`,{className:`btn-icon-sm`,onClick:()=>W(null),"aria-label":`Close preview`,children:(0,O.jsx)(c,{size:14})})]}),(0,O.jsxs)(`div`,{className:`fb-preview-meta`,children:[(0,O.jsx)(`span`,{children:U.size_display}),U.total_lines&&(0,O.jsxs)(`span`,{children:[U.total_lines,` lines`]}),U.columns&&(0,O.jsxs)(`span`,{children:[U.columns.length,` columns`]}),U.row_count!==null&&(0,O.jsxs)(`span`,{children:[U.row_count,` rows`]})]}),U.columns&&(0,O.jsxs)(`div`,{className:`fb-preview-columns`,children:[(0,O.jsx)(`strong`,{children:`Columns:`}),` `,U.columns.join(`, `)]}),xe?(0,O.jsx)(`div`,{className:`fb-preview-loading`,children:`Loading preview...`}):U.is_text&&U.preview_lines.length>0?(0,O.jsx)(`pre`,{className:`fb-preview-content`,children:U.preview_lines.slice(0,30).join(`
4
- `)}):(0,O.jsx)(`div`,{className:`fb-preview-binary`,children:`Binary file - no preview available`})]})]}),Y&&(0,O.jsx)(ee,{filename:Y.filename,error:Y.error,onDismiss:()=>X(null)}),(0,O.jsxs)(`div`,{className:`fb-actions`,children:[(0,O.jsx)(`div`,{className:`fb-selection-info`,children:V.size>0?`${V.size} item(s) selected`:`Select files to index or analyze`}),Ce&&(0,O.jsx)(`span`,{className:`fb-index-status`,children:Ce}),(0,O.jsxs)(`div`,{className:`fb-action-btns`,children:[(0,O.jsxs)(`button`,{className:`fb-action-btn secondary`,onClick:ke,disabled:V.size===0||Se.size>0,title:`Index selected files for RAG search`,children:[(0,O.jsx)(f,{size:14}),`Index Selected`]}),(0,O.jsxs)(`button`,{className:`fb-action-btn primary`,onClick:Ae,disabled:V.size===0||Se.size>0,title:`Index and send selected files to the chat agent for analysis`,children:[(0,O.jsx)(ie,{size:14}),`Ask Agent`]})]})]})]})]})})}export{j as FileBrowser};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{a as t,n,o as r,r as i}from"./apiBase-CS6zLsJY.js";import{t as a}from"./message-square-CLnmengs.js";import{A as o,Bt as s,C as c,D as ee,E as te,F as l,Ft as ne,Gt as re,Ht as ie,I as ae,It as oe,Kt as se,L as ce,Lt as u,M as le,N as ue,O as de,P as fe,Pt as d,R as pe,S as me,T as f,Vt as he,W as ge,Wt as _e,Xt as ve,_ as ye,_n as be,an as xe,b as Se,c as Ce,cn as we,d as Te,dn as Ee,f as De,g as Oe,h as ke,hn as Ae,j as je,k as Me,l as Ne,ln as Pe,m as Fe,mn as Ie,on as Le,p as Re,qt as ze,s as Be,sn as Ve,t as He,tn as Ue,u as We,v as Ge,w as Ke,x as qe,y as Je,z as p,zt as m}from"./index-Fhiym-Jy.js";var Ye={name:`arrow-left`,size:24,node:[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]};Ye.node;var Xe=t(Ye),h={name:`chevron-left`,size:24,node:[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]};h.node;var Ze=t(h),Qe={name:`git-merge`,size:24,node:[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]};Qe.node;var $e=t(Qe),g={name:`shield-off`,size:24,node:[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]};g.node;var et=t(g),tt={name:`shield`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}]]};tt.node;var nt=t(tt),rt={name:`target`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`6`,key:`1vlfrh`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}]]};rt.node;var it=t(rt),at={name:`trending-up`,size:24,node:[[`path`,{d:`M16 7h6v6`,key:`box55l`}],[`path`,{d:`m22 7-8.5 8.5-5-5L2 17`,key:`1t1m79`}]]};at.node;var ot=t(at),st={name:`user`,size:24,node:[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]};st.node;var ct=t(st),lt={name:`zap`,size:24,node:[[`path`,{d:`M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z`,key:`1v7up4`}]]};lt.node;var ut=t(lt),_=e(r(),1),v=n(),dt=[{title:`Preferences`,categories:[`preference`]},{title:`About you`,categories:[`fact`,`profile`,`skill`]},{title:`Reminders`,categories:[`reminder`]},{title:`Notes`,categories:[`note`]}];function ft(e){switch(e){case`user`:return`You added this`;case`tool`:return`You asked GAIA to remember this`;case`llm_extract`:return`Picked up in a chat`;case`consolidation`:return`From an older chat`;case`inferred`:return`From your profile setup`;case`discovery`:return`Found on this PC during profile setup`;default:return`Saved`}}function y(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return``;let n=Math.floor((Date.now()-t.getTime())/864e5);return n<=0?`today`:n===1?`yesterday`:n<30?`${n} days ago`:t.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function pt(e,t=new Date){let n=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e),r=n?new Date(+n[1],n[2]-1,+n[3]):new Date(e);if(Number.isNaN(r.getTime()))return null;let i=r.getHours()===0&&r.getMinutes()===0&&r.getSeconds()===0,a=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime(),o=i?r.getTime()<a:r.getTime()<t.getTime(),s=r.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`numeric`,...r.getFullYear()===t.getFullYear()?{}:{year:`numeric`},...i?{}:{hour:`numeric`,minute:`2-digit`}});return{text:`${o?`Was due`:`Due`} ${s}`,past:o}}function mt({memoryEnabled:e,reloadKey:t,onChanged:n,onOpenAdvanced:r,showToast:a}){let[o,s]=(0,_.useState)(null),[c,ee]=(0,_.useState)(null),[te,l]=(0,_.useState)(null),[ne,re]=(0,_.useState)(``),[ie,ae]=(0,_.useState)([]),[oe,ce]=(0,_.useState)(new Set),[u,le]=(0,_.useState)(``),[ue,de]=(0,_.useState)(`fact`),[fe,d]=(0,_.useState)(null),pe=(0,_.useRef)(0),f=(0,_.useCallback)(async()=>{let e=++pe.current;try{let t=await me({about_user:!0,include_sensitive:!0,sort_by:`updated_at`,order:`desc`,limit:200});if(e!==pe.current)return;s(t.items),ee(null)}catch(t){if(e!==pe.current)return;i.system.warn(`Failed to load what GAIA knows about the user`,t),ee(t instanceof Error?t.message:String(t))}},[]);(0,_.useEffect)(()=>{f()},[f,t]);let ge=(0,_.useCallback)(async e=>{let t=ne.trim();if(!t||t===e.content)l(null);else{d(e.id);try{await ye(e.id,{content:t}),l(null),a(`Updated`,`success`),await f(),n()}catch(e){i.system.error(`Failed to edit memory`,e),a(`Couldn't save the change: ${e instanceof Error?e.message:e}`,`error`)}finally{d(null)}}},[ne,f,n,a]),_e=(0,_.useCallback)(async e=>{d(e.id);try{await Oe(e.id),pe.current++,s(t=>(t??[]).filter(t=>t.id!==e.id)),ae(t=>[e,...t]),n()}catch(e){i.system.error(`Failed to forget memory`,e),a(`Couldn't forget that: ${e instanceof Error?e.message:e}`,`error`)}finally{d(null)}},[n,a]),ve=(0,_.useCallback)(async e=>{d(e.id);try{await Fe({content:e.content,category:e.category,domain:e.domain??void 0,context:e.context,entity:e.entity??void 0,sensitive:e.sensitive,due_at:e.due_at??void 0}),ae(t=>t.filter(t=>t.id!==e.id)),await f(),n()}catch(e){i.system.error(`Failed to restore memory`,e),a(`Couldn't restore it: ${e instanceof Error?e.message:e}`,`error`)}finally{d(null)}},[f,n,a]),be=(0,_.useCallback)(async()=>{let e=u.trim();if(e){d(`new`);try{await Fe({content:e,category:ue}),le(``),a(`Saved`,`success`),await f(),n()}catch(e){i.system.error(`Failed to add memory`,e),a(`Couldn't save it: ${e instanceof Error?e.message:e}`,`error`)}finally{d(null)}}},[u,ue,f,n,a]);if(!e)return(0,v.jsxs)(`div`,{className:`mem-about`,children:[(0,v.jsx)(`h2`,{className:`mem-about-title`,children:`What GAIA knows about you`}),(0,v.jsxs)(`div`,{className:`mem-about-empty`,children:[(0,v.jsx)(`p`,{children:`Memory is off, so GAIA isn't saving anything about you.`}),(0,v.jsx)(`button`,{className:`btn-secondary`,onClick:r,children:`Turn it on in Advanced`})]})]});let xe=dt.map(e=>({...e,rows:(o??[]).filter(t=>e.categories.includes(t.category))})).filter(e=>e.rows.length>0);return(0,v.jsxs)(`div`,{className:`mem-about`,children:[(0,v.jsx)(`h2`,{className:`mem-about-title`,children:`What GAIA knows about you`}),(0,v.jsx)(`p`,{className:`mem-about-intro`,children:`GAIA uses these in every chat. Edit anything that's wrong, or forget it so GAIA stops using it.`}),(0,v.jsxs)(`form`,{className:`mem-about-add`,onSubmit:e=>{e.preventDefault(),be()},children:[(0,v.jsx)(`input`,{className:`mem-input`,placeholder:`Tell GAIA something about you, e.g. “I prefer short answers”`,"aria-label":`Something GAIA should know about you`,value:u,onChange:e=>le(e.target.value)}),(0,v.jsxs)(`select`,{className:`mem-select`,"aria-label":`Kind`,value:ue,onChange:e=>de(e.target.value),children:[(0,v.jsx)(`option`,{value:`fact`,children:`About you`}),(0,v.jsx)(`option`,{value:`preference`,children:`Preference`}),(0,v.jsx)(`option`,{value:`reminder`,children:`Reminder`}),(0,v.jsx)(`option`,{value:`note`,children:`Note`})]}),(0,v.jsxs)(`button`,{className:`btn-primary`,type:`submit`,disabled:!u.trim()||fe===`new`,children:[(0,v.jsx)(se,{size:14}),` Add`]})]}),ie.map(e=>(0,v.jsxs)(`div`,{className:`mem-about-forgotten`,role:`status`,children:[(0,v.jsxs)(`span`,{children:[`Forgotten: `,e.sensitive?`a sensitive memory`:`“${e.content}”`,` — GAIA won't learn it again from old chats.`]}),(0,v.jsxs)(`button`,{className:`mem-about-link`,disabled:fe===e.id,onClick:()=>ve(e),children:[(0,v.jsx)(m,{size:12}),` Undo`]})]},e.id)),c?(0,v.jsxs)(`div`,{className:`mem-about-empty`,children:[(0,v.jsxs)(`p`,{children:[`Couldn't load your memories: `,c]}),(0,v.jsx)(`button`,{className:`btn-secondary`,onClick:f,children:`Try again`})]}):o===null?(0,v.jsxs)(`div`,{className:`mem-loading`,children:[(0,v.jsx)(`div`,{className:`mem-spinner`}),` Loading…`]}):xe.length===0?(0,v.jsxs)(`div`,{className:`mem-about-empty`,children:[(0,v.jsx)(`p`,{children:`GAIA hasn't saved anything about you yet.`}),(0,v.jsx)(`p`,{className:`mem-about-hint`,children:`Tell it in a chat (“remember that I live in Calgary”) or add something above.`})]}):xe.map(e=>(0,v.jsxs)(`section`,{className:`mem-about-group`,"aria-label":e.title,children:[(0,v.jsx)(`h3`,{className:`mem-about-group-title`,children:e.title}),(0,v.jsx)(`ul`,{className:`mem-about-list`,children:e.rows.map(e=>{let t=e.sensitive&&!oe.has(e.id),n=e.due_at?pt(e.due_at):null;return(0,v.jsx)(`li`,{className:`mem-about-item`,children:te===e.id?(0,v.jsxs)(`form`,{className:`mem-about-edit`,onSubmit:t=>{t.preventDefault(),ge(e)},children:[(0,v.jsx)(`textarea`,{className:`mem-input`,"aria-label":`Edit memory`,rows:2,autoFocus:!0,value:ne,onChange:e=>re(e.target.value),onKeyDown:t=>{t.key===`Escape`&&(t.stopPropagation(),l(null)),t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ge(e))}}),(0,v.jsxs)(`div`,{className:`mem-about-edit-actions`,children:[(0,v.jsx)(`button`,{className:`btn-primary`,type:`submit`,disabled:fe===e.id,children:`Save`}),(0,v.jsx)(`button`,{className:`btn-secondary`,type:`button`,onClick:()=>l(null),children:`Cancel`})]})]}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`div`,{className:`mem-about-text`,children:[t?(0,v.jsxs)(`button`,{className:`mem-about-link`,onClick:()=>ce(t=>new Set(t).add(e.id)),children:[(0,v.jsx)(Ue,{size:12}),` Sensitive — show`]}):e.content,n&&(0,v.jsx)(`span`,{className:`mem-about-due${n.past?` is-overdue`:``}`,children:n.text}),(0,v.jsxs)(`span`,{className:`mem-about-meta`,children:[ft(e.source),` · `,y(e.updated_at)]})]}),(0,v.jsxs)(`div`,{className:`mem-about-actions`,children:[(0,v.jsx)(`button`,{className:`mem-about-btn`,"aria-label":`Edit: ${t?`sensitive memory`:e.content}`,title:`Edit`,onClick:()=>{l(e.id),re(e.content)},children:(0,v.jsx)(ze,{size:14})}),(0,v.jsxs)(`button`,{className:`mem-about-btn mem-about-btn-remove`,"aria-label":`Forget: ${t?`sensitive memory`:e.content}`,title:`Forget`,disabled:fe===e.id,onClick:()=>_e(e),children:[(0,v.jsx)(he,{size:14}),` Forget`]})]})]})},e.id)})})]},e.title))]})}function ht(e){if(!e)return`—`;try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n={month:`short`,day:`numeric`};return t.getFullYear()!==new Date().getFullYear()&&(n.year=`numeric`),t.toLocaleDateString(void 0,n)}catch{return`—`}}function b(e){if(!e)return``;try{let t=new Date(e);return isNaN(t.getTime())?``:t.toLocaleString(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}catch{return``}}function x(e){if(!e)return`—`;try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n=Date.now(),r=t.getTime()-n,i=Math.abs(r),a=Math.floor(i/1e3),o=Math.floor(i/6e4),s=Math.floor(i/36e5),c=Math.floor(i/864e5);return r<0?a<5?`just now`:a<60?`${a}s ago`:s===0?`${o}m ago`:c===0?`${s}h ago`:c===1?`yesterday`:c<30?`${c}d ago`:b(e):a<5?`now`:a<60?`in ${a}s`:s===0?`in ${o}m`:c===0?`in ${s}h`:c===1?`tomorrow`:c<30?`in ${c}d`:b(e)}catch{return`—`}}function gt(e){return e<1e3?`${Math.round(e)}ms`:`${(e/1e3).toFixed(1)}s`}function _t(e){try{return new Date(e).getTime()<Date.now()}catch{return!1}}function vt(e){return e>=.7?`high`:e>=.4?`medium`:`low`}function yt(e){return e>=.9?`high`:e>=.7?`medium`:`low`}function bt(e,t){let n=ht(e),r=ht(t);return n===`—`&&r===`—`?``:n===r?n:`${n} \u2013 ${r}`}function xt(e){if(e.length===0)return 0;let t=new Date().toISOString().slice(0,10),n=e.find(e=>e.date===t);return n?n.knowledge_added:0}var St=[`fact`,`preference`,`error`,`skill`,`note`,`reminder`],Ct={work:`blue`,technical:`purple`,personal:`green`,general:`gray`};function wt(){let{setShowMemoryDashboard:e,sessions:t,setCurrentSession:n}=ne(),r=(0,_.useMemo)(()=>new Map(t.map(e=>[e.id,e.title])),[t]),Ue=e=>r.get(e)||`${e.slice(0,8)}...`,[m,Ye]=(0,_.useState)(null),[h,Qe]=(0,_.useState)([]),[g,tt]=(0,_.useState)(null),[rt,at]=(0,_.useState)([]),[st,lt]=(0,_.useState)([]),[dt,ft]=(0,_.useState)([]),[y,pt]=(0,_.useState)(null),[ht,wt]=(0,_.useState)([]),[Tt,Et]=(0,_.useState)(!0),[Dt,Ot]=(0,_.useState)(null),[kt,At]=(0,_.useState)(null),[jt,S]=(0,_.useState)(!1),[Mt,Nt]=(0,_.useState)(null),[Pt,Ft]=(0,_.useState)([]),It=(0,_.useRef)(0),[C,Lt]=(0,_.useState)([]),[Rt,zt]=(0,_.useState)(``),[Bt,Vt]=(0,_.useState)(``),[Ht,Ut]=(0,_.useState)(``),[w,Wt]=(0,_.useState)(`updated_at`),[Gt,Kt]=(0,_.useState)(`desc`),[T,E]=(0,_.useState)(0),[qt,Jt]=(0,_.useState)(!1),[Yt,Xt]=(0,_.useState)(``),[Zt,Qt]=(0,_.useState)(null),$t=(0,_.useRef)(null),[D,en]=(0,_.useState)(null),[tn,O]=(0,_.useState)(!1),[k,nn]=(0,_.useState)(null),[A,j]=(0,_.useState)({content:``,category:`fact`,domain:``,context:`global`,entity:``,sensitive:!1,due_at:``}),[rn,an]=(0,_.useState)(new Set),[M,on]=(0,_.useState)(!1),[sn,cn]=(0,_.useState)(!1),[ln,un]=(0,_.useState)(!1),[N,P]=(0,_.useState)(!1),[dn,fn]=(0,_.useState)(!1),[F,pn]=(0,_.useState)(null),[mn,hn]=(0,_.useState)(!1),[I,L]=(0,_.useState)(null),[R,gn]=(0,_.useState)(`about`),[_n,vn]=(0,_.useState)(0),[yn,bn]=(0,_.useState)([]),[xn,Sn]=(0,_.useState)(null),[Cn,wn]=(0,_.useState)(!1),[Tn,En]=(0,_.useState)(null),[Dn,On]=(0,_.useState)(null),[kn,An]=(0,_.useState)(!1),[jn,Mn]=(0,_.useState)({title:``,description:``,priority:`medium`}),[z,B]=(0,_.useState)(`idle`),[Nn,V]=(0,_.useState)([]),[H,U]=(0,_.useState)([]),[Pn,Fn]=(0,_.useState)(null),In=(0,_.useRef)(null),Ln=(0,_.useRef)(null),[W,G]=(0,_.useState)(`idle`),[Rn,K]=(0,_.useState)([]),[q,J]=(0,_.useState)([]),[zn,Bn]=(0,_.useState)(null),[Vn,Hn]=(0,_.useState)(!1),Un=(0,_.useRef)(null),Wn=(0,_.useRef)(null),[Gn,Kn]=(0,_.useState)(30),[qn,Jn]=(0,_.useState)(!1),[Yn,Xn]=(0,_.useState)(!1),[Zn,Qn]=(0,_.useState)(!1),[$n,er]=(0,_.useState)(!1),[tr,nr]=(0,_.useState)(!1),[rr,ir]=(0,_.useState)(!1),ar=(0,_.useRef)(null),or=(0,_.useRef)(null),sr=(0,_.useRef)(null),Y=(0,_.useCallback)((e,t=`info`)=>{let n=++It.current;Ft(r=>[...r,{id:n,text:e,type:t}]),setTimeout(()=>{Ft(e=>e.filter(e=>e.id!==n))},4e3)},[]);(0,_.useEffect)(()=>{if(!jt)return;let e=e=>{or.current&&!or.current.contains(e.target)&&S(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[jt]),d(!0,()=>{I?L(null):dn?fn(!1):mn?hn(!1):D?en(null):jt?S(!1):tn||k?(O(!1),nn(null)):Mt?Nt(null):e(!1)}),ge(sr,!!I),(0,_.useEffect)(()=>{if(!I)return;let e=sr.current;if(!e)return;let t=document.activeElement;return e.focus(),()=>{t?.focus()}},[I]);let cr=(0,_.useCallback)(async()=>{try{let e=await te();Ye(e)}catch(e){i.system.warn(`Failed to load memory stats`,e)}},[]),lr=(0,_.useCallback)(async()=>{try{let e=await c(Gn);Qe(e)}catch(e){i.system.warn(`Failed to load memory activity`,e)}},[Gn]),X=(0,_.useCallback)(async()=>{try{let e=await me({category:C.length>0?C:void 0,context:Rt||void 0,entity:Bt||void 0,search:Ht||void 0,sort_by:w,order:Gt,offset:T,limit:15,include_sensitive:!0,include_superseded:qt});tt(e)}catch(e){i.system.warn(`Failed to load knowledge`,e)}},[C,Rt,Bt,Ht,w,Gt,T,qt]),ur=(0,_.useCallback)(async()=>{try{let e=await ee();at(e)}catch(e){i.system.warn(`Failed to load tool summary`,e)}},[]),dr=(0,_.useCallback)(async()=>{try{let e=await Ke(20);lt(e)}catch(e){i.system.warn(`Failed to load conversations`,e)}},[]),fr=(0,_.useCallback)(async()=>{try{let e=await de(7);ft(e)}catch(e){i.system.warn(`Failed to load upcoming items`,e)}},[]),Z=(0,_.useCallback)(async()=>{try{let e=await Je();pt(e)}catch(e){i.system.warn(`Failed to load embedding coverage`,e)}},[]),pr=(0,_.useCallback)(async()=>{try{let e=await Se();wt(e||[])}catch(e){i.system.warn(`Failed to load entities`,e)}},[]),mr=(0,_.useCallback)(async()=>{try{let e=await f();cn(e.mcp_memory_enabled),on(e.memory_enabled),un(e.system_discovery_consent)}catch(e){i.system.warn(`Failed to load memory settings`,e)}},[]),hr=(0,_.useCallback)(async()=>{wn(!0);try{let[e,t]=await Promise.all([Me(),qe()]);bn(e.goals),Sn(t)}catch(e){i.system.warn(`Failed to load goals`,e)}finally{wn(!1)}},[]),gr=(0,_.useCallback)(async(e,t)=>{try{await e()}catch(e){i.system.error(t,e),Y(`${t}: ${e instanceof Error?e.message:e}`,`error`);return}hr()},[hr,Y]);(0,_.useEffect)(()=>{if(!Dn)return;let e=setTimeout(()=>On(null),3e3);return()=>clearTimeout(e)},[Dn]);let Q=(0,_.useCallback)(async()=>{Et(!0),Ot(null);try{await Promise.all([cr(),lr(),X(),ur(),dr(),fr(),Z(),pr(),mr(),hr()]),vn(e=>e+1)}catch(e){Ot(`Failed to load memory data. Is the backend running?`),i.system.error(`Memory dashboard load failed`,e)}finally{Et(!1)}},[cr,lr,X,ur,dr,fr,Z,pr,mr,hr]);(0,_.useEffect)(()=>{Q()},[Q]),(0,_.useEffect)(()=>{X()},[X]);let _r=(0,_.useRef)(!0);(0,_.useEffect)(()=>{_r.current?_r.current=!1:lr()},[lr]);let vr=(0,_.useCallback)(e=>{Ut(e),ir(!0),ar.current&&clearTimeout(ar.current),ar.current=setTimeout(()=>{E(0),ir(!1)},300)},[]),yr=(0,_.useCallback)(()=>{X(),cr(),Z(),fr(),pr()},[X,cr,Z,fr,pr]),$=(0,_.useCallback)(()=>{yr(),vn(e=>e+1)},[yr]),br=(0,_.useCallback)(async()=>{if(A.content.trim())try{let e=await Fe({content:A.content,category:A.category,domain:A.domain||void 0,context:A.context,entity:A.entity||void 0,sensitive:A.sensitive,due_at:A.due_at||void 0});O(!1),j({content:``,category:`fact`,domain:``,context:`global`,entity:``,sensitive:!1,due_at:``}),$(),i.ui.info(`Created new knowledge entry`),e?.embedded===!1?Y(e.embed_error??`Saved, but not embedded`,`error`):Y(`Memory created successfully`,`success`)}catch(e){i.system.error(`Failed to create knowledge`,e),Y(`Failed to create memory`,`error`)}},[A,$,Y]),xr=(0,_.useCallback)(async()=>{if(k&&A.content.trim())try{let e=await ye(k,{content:A.content,category:A.category,domain:A.domain||void 0,context:A.context,entity:A.entity||void 0,sensitive:A.sensitive,due_at:A.due_at||void 0});nn(null),j({content:``,category:`fact`,domain:``,context:`global`,entity:``,sensitive:!1,due_at:``}),$(),i.ui.info(`Updated knowledge ${k}`),e?.embedded===!1?Y(e.embed_error??`Saved, but not embedded`,`error`):Y(`Memory updated`,`success`)}catch(e){i.system.error(`Failed to update knowledge`,e),Y(`Failed to update memory`,`error`)}},[k,A,$,Y]),Sr=(0,_.useCallback)(async e=>{if(F!==e)pn(e);else{pn(null);try{await Oe(e),$(),i.ui.info(`Deleted knowledge ${e}`),Y(`Memory deleted`,`info`)}catch(e){i.system.error(`Failed to delete knowledge`,e),Y(`Failed to delete memory`,`error`)}}},[F,$,Y]);(0,_.useEffect)(()=>{if(!F)return;let e=setTimeout(()=>pn(null),3e3);return()=>clearTimeout(e)},[F]);let Cr=(0,_.useCallback)(async e=>{try{await ye(e.id,{sensitive:!e.sensitive}),X(),i.ui.info(`Toggled sensitive for ${e.id}: ${!e.sensitive}`),Y(e.sensitive?`Unmarked as sensitive`:`Marked as sensitive`,`info`)}catch(e){i.system.error(`Failed to toggle sensitive`,e),Y(`Failed to toggle sensitive flag`,`error`)}},[X,Y]),wr=(0,_.useCallback)(e=>{nn(e.id),O(!1),j({content:e.content,category:e.category,domain:e.domain||``,context:e.context,entity:e.entity||``,sensitive:e.sensitive,due_at:e.due_at||``})},[]),Tr=(0,_.useCallback)(e=>{navigator.clipboard.writeText(e).catch(()=>{}),i.ui.info(`Copied knowledge ID: ${e}`),Y(`ID copied to clipboard`,`info`)},[Y]),Er=(0,_.useCallback)(e=>{Xt(e),$t.current&&clearTimeout($t.current),e.trim()?$t.current=setTimeout(async()=>{try{let t=await pe(e.trim(),20);Qt(t)}catch(e){i.system.warn(`Conversation search failed`,e)}},300):Qt(null)},[]),Dr=(0,_.useCallback)(async e=>{try{let t=await Ge(e);en({sessionId:e,turns:t})}catch(e){i.system.error(`Failed to load conversation detail`,e)}},[]),Or=(0,_.useCallback)(e=>{Lt(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),E(0)},[]),kr=(0,_.useCallback)(e=>{w===e?Kt(e=>e===`desc`?`asc`:`desc`):(Wt(e),Kt(`desc`)),E(0)},[w]),Ar=(0,_.useCallback)(async()=>{Jn(!0),S(!1);try{let e=await De();await Q(),Y(`Consolidated ${e.consolidated??0} sessions, extracted ${e.extracted_items??0} items`,`success`)}catch(e){i.system.error(`Failed to consolidate sessions`,e),Y(`Failed to consolidate sessions`,`error`)}finally{Jn(!1)}},[Q,Y]),jr=(0,_.useCallback)(async()=>{Xn(!0),S(!1);try{let e=await le();await Z(),Y(`Backfilled ${e.backfilled??0} embeddings${e.total_without?` (${e.total_without} were missing)`:``}`,`success`)}catch(e){i.system.error(`Failed to rebuild embeddings`,e),Y(`Failed to rebuild embeddings`,`error`)}finally{Xn(!1)}},[Z,Y]),Mr=(0,_.useCallback)(async()=>{Qn(!0),S(!1);try{let e=await fe();await Q(),Y(`Checked ${e.pairs_checked??0} pairs: ${e.reinforced??0} reinforced, ${e.contradicted??0} contradicted`,`success`)}catch(e){i.system.error(`Failed to reconcile memory`,e),Y(`Failed to reconcile memory`,`error`)}finally{Qn(!1)}},[Q,Y]),Nr=(0,_.useCallback)(async()=>{er(!0),S(!1);try{await ue(),await Q(),Y(`FTS indexes rebuilt successfully`,`success`)}catch(e){i.system.error(`Failed to rebuild FTS index`,e),Y(`Failed to rebuild FTS indexes`,`error`)}finally{er(!1)}},[Q,Y]),Pr=(0,_.useCallback)(async()=>{nr(!0),S(!1);try{let e=await l();await Q(),e.skipped?Y(`System context collection is disabled — enable it in settings`,`error`):Y(`System context refreshed: ${e.stored} facts updated`,`success`)}catch(e){i.system.error(`Failed to refresh system context`,e),Y(`Failed to refresh system context`,`error`)}finally{nr(!1)}},[Q,Y]),Fr=qn||Yn||Zn||$n||tr,Ir=(0,_.useCallback)(()=>{B(`running`),V([]),U([]),Fn(null);let e=o();Ln.current=e,e.onmessage=t=>{try{let n=JSON.parse(t.data);if(n.type===`log`)V(e=>[...e,{text:n.message,kind:`log`}]);else if(n.type===`finding`){let e=n.item;V(t=>[...t,{text:` Found: ${e.content}`,kind:`finding`}]),U(t=>[...t,{...e,_checked:!0}])}else n.type===`error`?V(e=>[...e,{text:` Error: ${n.message}`,kind:`error`}]):n.type===`done`&&(e.close(),Ln.current=null,V(e=>[...e,{text:`Done. ${n.total??0} items discovered.`,kind:`log`}]),B(`review`))}catch{V(e=>[...e,{text:`Failed to parse event data.`,kind:`error`}])}},e.onerror=()=>{e.close(),Ln.current=null,V(e=>[...e,{text:`Connection error. Is the GAIA server running?`,kind:`error`}]),U(e=>(B(e.length>0?`review`:`idle`),e))}},[]),Lr=(0,_.useCallback)(async()=>{let e=H.filter(e=>e._checked);if(e.length!==0){B(`saving`);try{let t=e.map(({_checked:e,...t})=>t),n=await We(t);Fn(n.stored),B(`done`),$(),Y(`Saved ${n.stored} items to memory`,`success`)}catch(e){i.system.error(`Failed to commit discovery items`,e),Y(`Failed to save discovery items`,`error`),B(`review`)}}},[H,$,Y]),Rr=(0,_.useCallback)(()=>{G(`running`),K([]),J([]),Bn(null);let e=je(Vn);Wn.current=e,e.onmessage=t=>{try{let n=JSON.parse(t.data);if(n.type===`log`)K(e=>[...e,{text:n.message,kind:`log`}]);else if(n.type===`insight`){let e=n.item;K(t=>[...t,{text:` Insight: ${e.content}`,kind:`finding`}]),J(t=>[...t,{...e,_checked:!0}])}else n.type===`error`?K(e=>[...e,{text:` Error: ${n.message}`,kind:`error`}]):n.type===`done`&&(e.close(),Wn.current=null,K(e=>[...e,{text:`Done. ${n.total??0} insights generated.`,kind:`log`}]),G(`review`))}catch{K(e=>[...e,{text:`Failed to parse event data.`,kind:`error`}])}},e.onerror=()=>{e.close(),Wn.current=null,K(e=>[...e,{text:`Connection error. Is Lemonade Server running?`,kind:`error`}]),J(e=>(G(e.length>0?`review`:`idle`),e))}},[Vn]),zr=(0,_.useCallback)(async()=>{let e=q.filter(e=>e._checked);if(e.length!==0){G(`saving`);try{let t=e.map(({_checked:e,...t})=>t),n=await Te(t);Bn(n.stored),G(`done`),$(),Y(`Saved ${n.stored} insights to memory`,`success`)}catch(e){i.system.error(`Failed to commit inference insights`,e),Y(`Failed to save inference insights`,`error`),G(`review`)}}},[q,$,Y]);(0,_.useEffect)(()=>{In.current&&(In.current.scrollTop=In.current.scrollHeight)},[Nn]),(0,_.useEffect)(()=>{Un.current&&(Un.current.scrollTop=Un.current.scrollHeight)},[Rn]),(0,_.useEffect)(()=>()=>{Ln.current&&=(Ln.current.close(),null),Wn.current&&=(Wn.current.close(),null)},[]);let Br=e=>w===e?(0,v.jsx)(`span`,{className:`mem-sort-arrow`,children:Gt===`desc`?`↓`:`↑`}):null,Vr=Math.max(1,...h.map(e=>e.conversations+e.tool_calls+e.knowledge_added+e.errors)),Hr=m?.knowledge?.by_context?Object.keys(m.knowledge.by_context):[];return(0,v.jsxs)(`div`,{className:`memory-dashboard-page`,children:[(0,v.jsxs)(`div`,{className:`memory-dashboard-header`,children:[(0,v.jsxs)(`div`,{className:`memory-dashboard-header-left`,children:[(0,v.jsx)(`button`,{className:`btn-icon settings-back-btn`,onClick:()=>e(!1),"aria-label":`Back`,children:(0,v.jsx)(Xe,{size:18})}),(0,v.jsxs)(`h1`,{children:[`Memory `,(0,v.jsx)(`span`,{style:{fontSize:11,fontWeight:600,color:`var(--accent-yellow)`,background:`var(--accent-yellow-dim)`,padding:`2px 8px`,borderRadius:4,marginLeft:8,verticalAlign:`middle`,letterSpacing:`0.5px`},children:`BETA`})]})]}),(0,v.jsxs)(`div`,{className:`memory-dashboard-header-actions`,children:[R===`advanced`&&(0,v.jsxs)(v.Fragment,{children:[y&&y.total_items>0&&(0,v.jsxs)(`div`,{className:`mem-embedding-coverage`,title:`${y.with_embedding} of ${y.total_items} entries embedded`,children:[(0,v.jsx)(`div`,{className:`mem-embedding-bar`,children:(0,v.jsx)(`div`,{className:`mem-embedding-fill`,style:{width:`${Math.round(y.coverage_pct)}%`}})}),(0,v.jsxs)(`span`,{className:`mem-embedding-label`,children:[Math.round(y.coverage_pct),`% embedded`]})]}),(0,v.jsxs)(`div`,{className:`mem-maintenance-wrap`,ref:or,children:[(0,v.jsxs)(`button`,{className:`btn-icon ${Fr?`mem-spinning`:``}`,onClick:()=>S(e=>!e),title:`Maintenance actions`,"aria-label":`Maintenance actions`,"aria-expanded":jt,children:[Fr?(0,v.jsx)(`div`,{className:`mem-spinner-sm`}):(0,v.jsx)(xe,{size:16}),(0,v.jsx)(Ae,{size:10,style:{marginLeft:2}})]}),jt&&(0,v.jsxs)(`div`,{className:`mem-maintenance-menu`,role:`menu`,children:[(0,v.jsxs)(`button`,{className:`mem-maintenance-item`,onClick:Ar,disabled:qn,role:`menuitem`,children:[(0,v.jsx)($e,{size:14}),qn?`Consolidating...`:`Consolidate Sessions`]}),(0,v.jsxs)(`button`,{className:`mem-maintenance-item`,onClick:jr,disabled:Yn,role:`menuitem`,children:[(0,v.jsx)(ut,{size:14}),Yn?`Rebuilding...`:`Rebuild Embeddings`]}),(0,v.jsxs)(`button`,{className:`mem-maintenance-item`,onClick:Mr,disabled:Zn,role:`menuitem`,children:[(0,v.jsx)(Ee,{size:14}),Zn?`Reconciling...`:`Reconcile Memory`]}),(0,v.jsx)(`div`,{className:`mem-maintenance-divider`}),(0,v.jsxs)(`button`,{className:`mem-maintenance-item`,onClick:Pr,disabled:tr,role:`menuitem`,children:[(0,v.jsx)(re,{size:14}),tr?`Refreshing...`:`Refresh System Context`]}),(0,v.jsx)(`div`,{className:`mem-maintenance-divider`}),(0,v.jsxs)(`button`,{className:`mem-maintenance-item`,onClick:Nr,disabled:$n,role:`menuitem`,children:[(0,v.jsx)(_e,{size:14}),$n?`Rebuilding...`:`Rebuild FTS Indexes`]})]})]})]}),(0,v.jsx)(`button`,{className:`btn-icon`,onClick:Q,title:`Refresh`,"aria-label":`Refresh dashboard`,children:(0,v.jsx)(re,{size:16})})]})]}),(0,v.jsxs)(`div`,{className:`mem-tab-bar`,role:`tablist`,children:[(0,v.jsxs)(`button`,{className:`mem-tab-btn${R===`about`?` mem-tab-active`:``}`,onClick:()=>gn(`about`),role:`tab`,"aria-selected":R===`about`,children:[(0,v.jsx)(ct,{size:14}),` About you`]}),(0,v.jsxs)(`button`,{className:`mem-tab-btn${R===`goals`?` mem-tab-active`:``}`,onClick:()=>{gn(`goals`),hr()},role:`tab`,"aria-selected":R===`goals`,children:[(0,v.jsx)(it,{size:14}),` Goals`,xn&&(xn.goals.pending_approval??0)>0&&(0,v.jsx)(`span`,{className:`mem-tab-badge`,children:xn.goals.pending_approval})]}),(0,v.jsxs)(`button`,{className:`mem-tab-btn${R===`profile`?` mem-tab-active`:``}`,onClick:()=>gn(`profile`),role:`tab`,"aria-selected":R===`profile`,children:[(0,v.jsx)(ie,{size:14}),` Profile setup`]}),(0,v.jsxs)(`button`,{className:`mem-tab-btn${R===`advanced`?` mem-tab-active`:``}`,onClick:()=>gn(`advanced`),role:`tab`,"aria-selected":R===`advanced`,children:[(0,v.jsx)(be,{size:14}),` Advanced`]})]}),(0,v.jsxs)(`div`,{className:`memory-dashboard-body`,children:[R===`about`&&(0,v.jsx)(mt,{memoryEnabled:M,reloadKey:_n,onChanged:yr,onOpenAdvanced:()=>gn(`advanced`),showToast:Y}),R===`advanced`&&(0,v.jsx)(v.Fragment,{children:Tt&&!m?(0,v.jsxs)(`div`,{className:`mem-loading`,children:[(0,v.jsx)(`div`,{className:`mem-spinner`}),`Loading memory data...`]}):Dt?(0,v.jsxs)(`div`,{className:`mem-empty`,children:[(0,v.jsx)(`div`,{className:`mem-empty-icon`,children:(0,v.jsx)(s,{size:32})}),(0,v.jsx)(`p`,{children:Dt}),(0,v.jsxs)(`button`,{className:`btn-secondary`,onClick:Q,style:{marginTop:12},children:[(0,v.jsx)(re,{size:14}),` Retry`]})]}):(0,v.jsxs)(v.Fragment,{children:[!M&&(0,v.jsxs)(`div`,{className:`mem-empty-state`,style:{margin:`40px 0`},children:[(0,v.jsx)(`div`,{className:`mem-empty-icon`,style:{opacity:.5},children:(0,v.jsx)(nt,{size:32})}),(0,v.jsx)(`p`,{style:{color:`var(--text-secondary)`,fontSize:14},children:`Memory is off. Turn it on in Settings below to let GAIA remember what you tell it.`})]}),M&&(0,v.jsxs)(v.Fragment,{children:[m?.embedding_error&&(0,v.jsxs)(`div`,{className:`mem-advanced-error`,role:`alert`,children:[(0,v.jsx)(s,{size:14}),` `,m.embedding_error]}),(0,v.jsxs)(`div`,{className:`mem-stat-cards`,children:[(0,v.jsxs)(`div`,{className:`mem-stat-card`,"data-accent":`purple`,children:[(0,v.jsx)(`div`,{className:`mem-stat-value`,children:m?.knowledge?.total??0}),(0,v.jsx)(`div`,{className:`mem-stat-label`,children:`Stored`}),(0,v.jsx)(`div`,{className:`mem-stat-sub`,children:(()=>{let e=xt(h);return e>0?`+${e} today`:m?.knowledge?.by_category?Object.entries(m.knowledge.by_category).slice(0,3).map(([e,t])=>`${t} ${e}${t===1?``:`s`}`).join(`, `):`No entries`})()})]}),(0,v.jsxs)(`div`,{className:`mem-stat-card`,"data-accent":`gold`,children:[(0,v.jsx)(`div`,{className:`mem-stat-value`,children:m?.knowledge?.total_retrievals??0}),(0,v.jsx)(`div`,{className:`mem-stat-label`,children:`Retrieved`}),(0,v.jsx)(`div`,{className:`mem-stat-sub`,children:m?.knowledge?.total&&m?.knowledge?.total_retrievals?`avg ${(m.knowledge.total_retrievals/m.knowledge.total).toFixed(1)}x per memory`:`No recalls yet`})]}),(0,v.jsxs)(`div`,{className:`mem-stat-card`,"data-accent":`blue`,children:[(0,v.jsx)(`div`,{className:`mem-stat-value`,children:m?.conversations?.total_sessions??0}),(0,v.jsx)(`div`,{className:`mem-stat-label`,children:`Sessions`}),(0,v.jsx)(`div`,{className:`mem-stat-sub`,children:bt(m?.conversations?.first_session??null,m?.conversations?.last_session??null)||`${m?.conversations?.total_turns??0} total turns`})]}),(0,v.jsxs)(`div`,{className:`mem-stat-card`,"data-accent":`green`,children:[(0,v.jsx)(`div`,{className:`mem-stat-value`,children:m?.tools?.total_calls??0}),(0,v.jsx)(`div`,{className:`mem-stat-label`,children:`Tool Calls`}),(0,v.jsxs)(`div`,{className:`mem-stat-sub`,title:`Memory tools (remember, recall, ...) are not logged`,children:[m?.tools?.unique_tools??0,` tools, excl. memory`]})]}),(0,v.jsxs)(`div`,{className:`mem-stat-card`,"data-accent":`red`,children:[(0,v.jsx)(`div`,{className:`mem-stat-value`,children:m?.tools?.overall_success_rate!=null&&(m.tools.total_calls??0)>0?`${Math.round(m.tools.overall_success_rate*100)}%`:`—`}),(0,v.jsx)(`div`,{className:`mem-stat-label`,children:`Success Rate`}),(0,v.jsx)(`div`,{className:`mem-stat-sub`,children:(m?.tools?.total_calls??0)>0?`${m?.tools?.total_errors??0} errors`:`No tool calls yet`})]})]}),(0,v.jsxs)(`div`,{className:`mem-section`,children:[(0,v.jsxs)(`div`,{className:`mem-section-title mem-section-title-row`,children:[(0,v.jsxs)(`span`,{className:`mem-section-title-left`,children:[(0,v.jsx)(ot,{size:14}),` Activity`]}),(0,v.jsx)(`div`,{className:`mem-range-tabs`,role:`group`,"aria-label":`Activity range`,children:[1,7,30].map(e=>(0,v.jsx)(`button`,{className:`mem-range-tab${Gn===e?` active`:``}`,onClick:()=>Kn(e),children:e===1?`1D`:e===7?`7D`:`30D`},e))})]}),h.length>0?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`div`,{className:`mem-activity-chart`,children:h.map((e,t)=>{let n=e.conversations+e.tool_calls+e.knowledge_added+e.errors,r=t===0||t===h.length-1||t%7==0,i=new Date(e.date+`T00:00:00`).toLocaleDateString(void 0,{month:`short`,day:`numeric`});return(0,v.jsxs)(`div`,{className:`mem-activity-bar-group`,onMouseEnter:()=>At(t),onMouseLeave:()=>At(null),children:[e.errors>0&&(0,v.jsx)(`div`,{className:`mem-activity-bar errors`,style:{height:`${e.errors/Vr*100}%`}}),e.knowledge_added>0&&(0,v.jsx)(`div`,{className:`mem-activity-bar knowledge`,style:{height:`${e.knowledge_added/Vr*100}%`}}),e.tool_calls>0&&(0,v.jsx)(`div`,{className:`mem-activity-bar tool_calls`,style:{height:`${e.tool_calls/Vr*100}%`}}),e.conversations>0&&(0,v.jsx)(`div`,{className:`mem-activity-bar conversations`,style:{height:`${e.conversations/Vr*100}%`}}),r&&(0,v.jsx)(`span`,{className:`mem-activity-date-label`,children:i}),kt===t&&n>0&&(0,v.jsxs)(`div`,{className:`mem-activity-tooltip`,children:[(0,v.jsx)(`strong`,{children:i}),(0,v.jsx)(`br`,{}),e.conversations>0&&(0,v.jsxs)(v.Fragment,{children:[e.conversations,` conversations`,(0,v.jsx)(`br`,{})]}),e.tool_calls>0&&(0,v.jsxs)(v.Fragment,{children:[e.tool_calls,` tool calls`,(0,v.jsx)(`br`,{})]}),e.knowledge_added>0&&(0,v.jsxs)(v.Fragment,{children:[e.knowledge_added,` learned`,(0,v.jsx)(`br`,{})]}),e.errors>0&&(0,v.jsxs)(v.Fragment,{children:[e.errors,` errors`]})]})]},e.date)})}),(0,v.jsxs)(`div`,{className:`mem-activity-legend`,children:[(0,v.jsxs)(`span`,{className:`mem-activity-legend-item`,children:[(0,v.jsx)(`span`,{className:`mem-activity-legend-dot conversations`}),` Conversations`]}),(0,v.jsxs)(`span`,{className:`mem-activity-legend-item`,children:[(0,v.jsx)(`span`,{className:`mem-activity-legend-dot tool_calls`}),` Tool Calls`]}),(0,v.jsxs)(`span`,{className:`mem-activity-legend-item`,children:[(0,v.jsx)(`span`,{className:`mem-activity-legend-dot knowledge`}),` Knowledge`]}),(0,v.jsxs)(`span`,{className:`mem-activity-legend-item`,children:[(0,v.jsx)(`span`,{className:`mem-activity-legend-dot errors`}),` Errors`]})]})]}):(0,v.jsxs)(`div`,{className:`mem-empty`,children:[(0,v.jsx)(`div`,{className:`mem-empty-icon`,children:(0,v.jsx)(ot,{size:28})}),(0,v.jsx)(`p`,{children:`No activity data yet`})]})]}),(0,v.jsxs)(`div`,{className:`mem-section`,children:[(0,v.jsxs)(`div`,{className:`mem-section-title mem-section-title-row`,children:[(0,v.jsxs)(`span`,{className:`mem-section-title-left`,children:[(0,v.jsx)(be,{size:14}),` Knowledge Browser`,g&&g.total>0&&(0,v.jsx)(`span`,{className:`mem-section-count`,children:g.total})]}),!tn&&!k&&(0,v.jsxs)(`button`,{className:`mem-section-add-btn`,onClick:()=>O(!0),title:`Add a memory entry`,children:[(0,v.jsx)(se,{size:13}),` Add`]})]}),(0,v.jsxs)(`div`,{className:`mem-filters`,children:[(0,v.jsxs)(`div`,{className:`mem-category-pills`,role:`group`,"aria-label":`Filter by category`,children:[St.map(e=>(0,v.jsx)(`button`,{className:`mem-category-pill ${e}${C.includes(e)?` active`:``}`,onClick:()=>Or(e),"aria-pressed":C.includes(e),children:e},e)),C.length>0&&(0,v.jsx)(`button`,{className:`mem-category-pill clear`,onClick:()=>{Lt([]),E(0)},"aria-label":`Clear category filters`,children:`✕ Clear`})]}),(0,v.jsxs)(`select`,{className:`mem-filter-select`,value:Rt,onChange:e=>{zt(e.target.value),E(0)},"aria-label":`Filter by context`,children:[(0,v.jsx)(`option`,{value:``,children:`All Contexts`}),Hr.map(e=>(0,v.jsx)(`option`,{value:e,children:e},e))]}),(0,v.jsxs)(`select`,{className:`mem-filter-select`,value:Bt,onChange:e=>{Vt(e.target.value),E(0)},"aria-label":`Filter by entity`,children:[(0,v.jsx)(`option`,{value:``,children:`All Entities`}),ht.map(e=>(0,v.jsxs)(`option`,{value:e.entity,children:[e.entity,` (`,e.count,`)`]},e.entity))]}),(0,v.jsxs)(`div`,{className:`mem-filter-search-wrap`,children:[rr?(0,v.jsx)(`div`,{className:`mem-spinner-sm search-icon`,style:{width:12,height:12,borderWidth:1.5}}):(0,v.jsx)(_e,{size:13,className:`search-icon`}),(0,v.jsx)(`input`,{className:`mem-filter-search`,type:`text`,placeholder:`Search memories...`,value:Ht,onChange:e=>vr(e.target.value),"aria-label":`Search memories`})]}),(0,v.jsxs)(`label`,{className:`mem-filter-toggle`,title:`Show entries that have been superseded by newer versions`,children:[(0,v.jsx)(`input`,{type:`checkbox`,checked:qt,onChange:e=>Jt(e.target.checked)}),(0,v.jsx)(`span`,{children:`Superseded`})]})]}),(tn||k)&&(0,v.jsxs)(`div`,{className:`mem-inline-form`,children:[(0,v.jsxs)(`div`,{className:`mem-inline-form-row`,children:[(0,v.jsx)(`label`,{children:`Content`}),(0,v.jsx)(`textarea`,{value:A.content,onChange:e=>j(t=>({...t,content:e.target.value})),placeholder:`What should the agent remember?`})]}),(0,v.jsxs)(`div`,{className:`mem-inline-form-row`,children:[(0,v.jsx)(`label`,{children:`Category`}),(0,v.jsx)(`select`,{value:A.category,onChange:e=>j(t=>({...t,category:e.target.value})),children:St.map(e=>(0,v.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),(0,v.jsxs)(`div`,{className:`mem-inline-form-row`,children:[(0,v.jsx)(`label`,{children:`Context`}),(0,v.jsx)(`input`,{type:`text`,value:A.context,onChange:e=>j(t=>({...t,context:e.target.value})),placeholder:`global`})]}),(0,v.jsxs)(`div`,{className:`mem-inline-form-row`,children:[(0,v.jsx)(`label`,{children:`Domain`}),(0,v.jsx)(`input`,{type:`text`,value:A.domain,onChange:e=>j(t=>({...t,domain:e.target.value})),placeholder:`e.g., python, frontend`})]}),(0,v.jsxs)(`div`,{className:`mem-inline-form-row`,children:[(0,v.jsx)(`label`,{children:`Entity`}),(0,v.jsx)(`input`,{type:`text`,value:A.entity,onChange:e=>j(t=>({...t,entity:e.target.value})),placeholder:`e.g., person:sarah_chen`})]}),(0,v.jsxs)(`div`,{className:`mem-inline-form-row`,children:[(0,v.jsx)(`label`,{children:`Due At`}),(0,v.jsx)(`input`,{type:`text`,value:A.due_at,onChange:e=>j(t=>({...t,due_at:e.target.value})),placeholder:`ISO 8601 (e.g., 2026-03-25T09:00:00-07:00)`})]}),(0,v.jsxs)(`div`,{className:`mem-inline-form-row`,children:[(0,v.jsx)(`label`,{children:`Sensitive`}),(0,v.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:6,cursor:`pointer`,fontSize:12},children:[(0,v.jsx)(`input`,{type:`checkbox`,checked:A.sensitive,onChange:e=>j(t=>({...t,sensitive:e.target.checked}))}),`Mark as sensitive (excluded from system prompt)`]})]}),(0,v.jsxs)(`div`,{className:`mem-inline-form-actions`,children:[(0,v.jsx)(`button`,{className:`btn-secondary`,onClick:()=>{O(!1),nn(null)},children:`Cancel`}),(0,v.jsx)(`button`,{className:`btn-primary`,onClick:k?xr:br,style:{padding:`8px 20px`,fontSize:13},children:k?`Update`:`Save`})]})]}),g&&g.items.length>0?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`div`,{style:{overflowX:`auto`},children:(0,v.jsxs)(`table`,{className:`mem-knowledge-table`,children:[(0,v.jsx)(`thead`,{children:(0,v.jsxs)(`tr`,{children:[(0,v.jsxs)(`th`,{onClick:()=>kr(`category`),className:w===`category`?`sorted`:``,children:[`Category`,Br(`category`)]}),(0,v.jsx)(`th`,{children:`Content`}),(0,v.jsxs)(`th`,{onClick:()=>kr(`context`),className:w===`context`?`sorted`:``,children:[`Context`,Br(`context`)]}),(0,v.jsx)(`th`,{children:`Entity`}),(0,v.jsxs)(`th`,{onClick:()=>kr(`confidence`),className:w===`confidence`?`sorted`:``,children:[`Confidence`,Br(`confidence`)]}),(0,v.jsx)(`th`,{children:`Source`}),(0,v.jsxs)(`th`,{onClick:()=>kr(`updated_at`),className:w===`updated_at`?`sorted`:``,children:[`Updated`,Br(`updated_at`)]}),(0,v.jsxs)(`th`,{onClick:()=>kr(`created_at`),className:w===`created_at`?`sorted`:``,children:[`Created`,Br(`created_at`)]}),(0,v.jsx)(`th`,{children:`Due`}),(0,v.jsx)(`th`,{className:`mem-actions-cell`})]})}),(0,v.jsx)(`tbody`,{children:g.items.map(e=>{let t=Mt===e.id,n=e.has_embedding;return(0,v.jsxs)(_.Fragment,{children:[(0,v.jsxs)(`tr`,{className:`${e.superseded_by?`mem-superseded-row`:``} ${t?`mem-expanded-row`:``}`,onClick:()=>Nt(t?null:e.id),onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),Nt(t?null:e.id))},tabIndex:0,role:`row`,"aria-expanded":t,style:{cursor:`pointer`},children:[(0,v.jsx)(`td`,{children:(0,v.jsx)(`span`,{className:`mem-cat-badge ${e.category}`,children:e.category})}),(0,v.jsx)(`td`,{children:(0,v.jsxs)(`div`,{className:`mem-content-cell`,title:e.content,children:[n!==void 0&&(0,v.jsx)(`span`,{className:`mem-embed-dot ${n?`embedded`:`missing`}`,title:n?`Embedded`:`Embedding missing`,children:(0,v.jsx)(Pe,{size:6,fill:`currentColor`})}),e.sensitive&&(0,v.jsx)(`span`,{className:`mem-sensitive-badge`,title:`Sensitive`,children:(0,v.jsx)(nt,{size:11})}),(0,v.jsx)(`span`,{className:e.sensitive&&!rn.has(e.id)?`mem-sensitive-blur`:e.superseded_by?`mem-superseded-text`:``,onClick:t=>{e.sensitive&&(t.stopPropagation(),an(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}))},children:e.content})]})}),(0,v.jsx)(`td`,{children:(0,v.jsx)(`span`,{className:`mem-date-cell`,children:e.context})}),(0,v.jsx)(`td`,{children:e.entity?(0,v.jsx)(`span`,{className:`mem-entity-link`,onClick:t=>{t.stopPropagation(),Vt(e.entity),E(0)},title:`Filter by ${e.entity}`,children:e.entity}):(0,v.jsx)(`span`,{className:`mem-date-cell`,children:`—`})}),(0,v.jsx)(`td`,{children:(0,v.jsxs)(`div`,{className:`mem-confidence`,children:[(0,v.jsx)(`div`,{className:`mem-confidence-bar`,children:(0,v.jsx)(`div`,{className:`mem-confidence-fill ${vt(e.confidence)}`,style:{width:`${e.confidence*100}%`}})}),e.confidence.toFixed(2)]})}),(0,v.jsx)(`td`,{children:(0,v.jsx)(`span`,{className:`mem-date-cell`,children:e.source||`—`})}),(0,v.jsx)(`td`,{children:(0,v.jsx)(`span`,{className:`mem-date-cell`,title:b(e.updated_at),children:x(e.updated_at)})}),(0,v.jsx)(`td`,{children:(0,v.jsx)(`span`,{className:`mem-date-cell`,title:b(e.created_at),children:x(e.created_at)})}),(0,v.jsx)(`td`,{children:e.due_at?(0,v.jsx)(`span`,{className:`mem-due-badge ${_t(e.due_at)?`overdue`:`upcoming`}`,title:b(e.due_at),children:x(e.due_at)}):(0,v.jsx)(`span`,{className:`mem-due-badge none`,children:`—`})}),(0,v.jsx)(`td`,{className:`mem-actions-cell`,children:(0,v.jsxs)(`div`,{className:`mem-row-actions`,onClick:e=>e.stopPropagation(),children:[(0,v.jsx)(`button`,{className:`mem-row-action-btn`,onClick:()=>wr(e),title:`Edit`,children:(0,v.jsx)(ze,{size:13})}),(0,v.jsx)(`button`,{className:`mem-row-action-btn`,onClick:()=>Cr(e),title:e.sensitive?`Unmark sensitive`:`Mark sensitive`,children:e.sensitive?(0,v.jsx)(et,{size:13}):(0,v.jsx)(nt,{size:13})}),(0,v.jsx)(`button`,{className:`mem-row-action-btn`,onClick:()=>Tr(e.id),title:`Copy ID`,children:(0,v.jsx)(Ve,{size:13})}),(0,v.jsx)(`button`,{className:`mem-row-action-btn delete${F===e.id?` is-confirm`:``}`,onClick:()=>Sr(e.id),title:F===e.id?`Click again to delete`:`Delete`,"aria-label":F===e.id?`Confirm delete memory`:`Delete memory`,children:F===e.id?(0,v.jsx)(`span`,{className:`mem-row-delete-label`,children:`Delete?`}):(0,v.jsx)(he,{size:13})})]})})]}),t&&(0,v.jsx)(`tr`,{className:`mem-detail-row`,children:(0,v.jsx)(`td`,{colSpan:10,children:(0,v.jsxs)(`div`,{className:`mem-detail-panel`,children:[(0,v.jsxs)(`div`,{className:`mem-detail-grid`,children:[(0,v.jsxs)(`div`,{className:`mem-detail-field`,children:[(0,v.jsx)(`span`,{className:`mem-detail-label`,children:`ID`}),(0,v.jsx)(`span`,{className:`mem-detail-value`,children:e.id})]}),(0,v.jsxs)(`div`,{className:`mem-detail-field`,children:[(0,v.jsx)(`span`,{className:`mem-detail-label`,children:`Domain`}),(0,v.jsx)(`span`,{className:`mem-detail-value`,children:e.domain||`—`})]}),(0,v.jsxs)(`div`,{className:`mem-detail-field`,children:[(0,v.jsx)(`span`,{className:`mem-detail-label`,children:`Source`}),(0,v.jsx)(`span`,{className:`mem-detail-value`,children:e.source||`—`})]}),(0,v.jsxs)(`div`,{className:`mem-detail-field`,children:[(0,v.jsx)(`span`,{className:`mem-detail-label`,children:`Use Count`}),(0,v.jsx)(`span`,{className:`mem-detail-value`,children:e.use_count??0})]}),(0,v.jsxs)(`div`,{className:`mem-detail-field`,children:[(0,v.jsx)(`span`,{className:`mem-detail-label`,children:`Created`}),(0,v.jsx)(`span`,{className:`mem-detail-value`,children:b(e.created_at)})]}),(0,v.jsxs)(`div`,{className:`mem-detail-field`,children:[(0,v.jsx)(`span`,{className:`mem-detail-label`,children:`Updated`}),(0,v.jsx)(`span`,{className:`mem-detail-value`,children:b(e.updated_at)})]}),(0,v.jsxs)(`div`,{className:`mem-detail-field`,children:[(0,v.jsx)(`span`,{className:`mem-detail-label`,children:`Last Used`}),(0,v.jsx)(`span`,{className:`mem-detail-value`,children:b(e.last_used)})]}),(0,v.jsxs)(`div`,{className:`mem-detail-field`,children:[(0,v.jsx)(`span`,{className:`mem-detail-label`,children:`Reminded At`}),(0,v.jsx)(`span`,{className:`mem-detail-value`,children:b(e.reminded_at)})]}),e.superseded_by&&(0,v.jsxs)(`div`,{className:`mem-detail-field`,children:[(0,v.jsx)(`span`,{className:`mem-detail-label`,children:`Superseded By`}),(0,v.jsx)(`span`,{className:`mem-detail-value mem-detail-chain`,children:e.superseded_by})]}),e.metadata&&(0,v.jsxs)(`div`,{className:`mem-detail-field mem-detail-full`,children:[(0,v.jsx)(`span`,{className:`mem-detail-label`,children:`Metadata`}),(0,v.jsx)(`span`,{className:`mem-detail-value`,children:typeof e.metadata==`object`?JSON.stringify(e.metadata,null,2):e.metadata})]})]}),(0,v.jsxs)(`div`,{className:`mem-detail-content-full`,children:[(0,v.jsx)(`span`,{className:`mem-detail-label`,children:`Full Content`}),(0,v.jsx)(`div`,{className:`mem-detail-content-text`,children:e.content})]})]})})})]},e.id)})})]})}),(0,v.jsxs)(`div`,{className:`mem-pagination`,children:[(0,v.jsxs)(`span`,{children:[T+1,`–`,Math.min(T+15,g.total),` of `,g.total]}),(0,v.jsxs)(`div`,{className:`mem-pagination-btns`,children:[(0,v.jsx)(`button`,{type:`button`,className:`mem-page-btn`,"aria-label":`Previous page`,disabled:T===0,onClick:()=>E(Math.max(0,T-15)),children:(0,v.jsx)(Ze,{size:14})}),(0,v.jsx)(`button`,{type:`button`,className:`mem-page-btn`,"aria-label":`Next page`,disabled:T+15>=g.total,onClick:()=>E(T+15),children:(0,v.jsx)(Ie,{size:14})})]})]})]}):(0,v.jsxs)(`div`,{className:`mem-empty`,children:[(0,v.jsx)(`div`,{className:`mem-empty-icon`,children:(0,v.jsx)(be,{size:28})}),(0,v.jsx)(`p`,{children:Ht||C.length>0||Rt||Bt?`No matching memories`:`No memories stored yet`})]})]}),(0,v.jsxs)(`div`,{className:`mem-two-col`,children:[(0,v.jsxs)(`div`,{className:`mem-section`,children:[(0,v.jsxs)(`div`,{className:`mem-section-title`,children:[(0,v.jsx)(u,{size:14}),` Tool Performance`,(0,v.jsx)(`span`,{className:`mem-section-note`,title:`remember, recall, update_memory, forget and search_past_conversations are not logged`,children:`excludes memory tools`})]}),rt.length>0?(0,v.jsx)(`div`,{style:{overflowX:`auto`},children:(0,v.jsxs)(`table`,{className:`mem-tool-table`,children:[(0,v.jsx)(`thead`,{children:(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{children:`Tool`}),(0,v.jsx)(`th`,{children:`Calls`}),(0,v.jsx)(`th`,{children:`Success`}),(0,v.jsx)(`th`,{children:`Denied`}),(0,v.jsx)(`th`,{children:`Avg Time`}),(0,v.jsx)(`th`,{children:`Last Used`}),(0,v.jsx)(`th`,{children:`Last Error`})]})}),(0,v.jsx)(`tbody`,{children:rt.map(e=>(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`td`,{children:(0,v.jsx)(`span`,{className:`mem-tool-name`,children:e.tool_name})}),(0,v.jsx)(`td`,{children:e.total_calls}),(0,v.jsx)(`td`,{children:(0,v.jsxs)(`div`,{className:`mem-confidence`,children:[(0,v.jsx)(`div`,{className:`mem-confidence-bar`,style:{width:40},children:(0,v.jsx)(`div`,{className:`mem-confidence-fill ${yt(e.success_rate)}`,style:{width:`${e.success_rate*100}%`}})}),(0,v.jsxs)(`span`,{className:`mem-success-rate ${yt(e.success_rate)}`,children:[Math.round(e.success_rate*100),`%`]})]})}),(0,v.jsx)(`td`,{children:e.denied_count??0}),(0,v.jsx)(`td`,{children:gt(e.avg_duration_ms)}),(0,v.jsx)(`td`,{children:(0,v.jsx)(`span`,{className:`mem-date-cell`,title:b(e.last_used),children:x(e.last_used)})}),(0,v.jsx)(`td`,{children:(0,v.jsx)(`span`,{className:`mem-tool-error`,title:e.last_error||``,children:e.last_error||`—`})})]},e.tool_name))})]})}):(0,v.jsxs)(`div`,{className:`mem-empty`,children:[(0,v.jsx)(`div`,{className:`mem-empty-icon`,children:(0,v.jsx)(u,{size:28})}),(0,v.jsx)(`p`,{children:`No tool calls recorded yet`})]})]}),(0,v.jsxs)(`div`,{className:`mem-section`,children:[(0,v.jsxs)(`div`,{className:`mem-section-title`,children:[(0,v.jsx)(we,{size:14}),` Upcoming & Overdue`]}),dt.length>0?(0,v.jsx)(`div`,{className:`mem-temporal-list`,children:dt.map(e=>{let t=_t(e.due_at);return(0,v.jsxs)(`div`,{className:`mem-temporal-item ${t?`overdue`:`upcoming`}`,children:[(0,v.jsx)(`span`,{className:`mem-temporal-icon`,children:t?(0,v.jsx)(s,{size:16}):(0,v.jsx)(we,{size:16})}),(0,v.jsxs)(`div`,{className:`mem-temporal-content`,children:[(0,v.jsx)(`div`,{className:`mem-temporal-text`,children:e.content}),(0,v.jsxs)(`div`,{className:`mem-temporal-date`,children:[t?`OVERDUE`:`Due`,`: `,x(e.due_at),e.context!==`global`&&` \u00B7 ${e.context}`]})]})]},e.id)})}):(0,v.jsxs)(`div`,{className:`mem-empty`,children:[(0,v.jsx)(`div`,{className:`mem-empty-icon`,children:(0,v.jsx)(Ee,{size:28})}),(0,v.jsx)(`p`,{children:`Nothing upcoming or overdue`})]})]})]}),(0,v.jsxs)(`div`,{className:`mem-section`,children:[(0,v.jsxs)(`div`,{className:`mem-section-title`,children:[(0,v.jsx)(a,{size:14}),` Conversation History`]}),(0,v.jsxs)(`div`,{className:`mem-conv-search`,children:[(0,v.jsx)(_e,{size:13,className:`search-icon`}),(0,v.jsx)(`input`,{type:`text`,placeholder:`Search conversations...`,value:Yt,onChange:e=>Er(e.target.value),"aria-label":`Search conversations`}),Yt&&(0,v.jsx)(`button`,{className:`mem-search-clear`,onClick:()=>{Xt(``),Qt(null)},"aria-label":`Clear search`,children:(0,v.jsx)(oe,{size:12})})]}),Zt===null?st.length>0?(0,v.jsx)(`div`,{className:`mem-conv-list`,children:st.map(e=>(0,v.jsxs)(`div`,{className:`mem-conv-item`,onClick:()=>Dr(e.session_id),children:[(0,v.jsxs)(`div`,{className:`mem-conv-info`,children:[(0,v.jsxs)(`div`,{className:`mem-conv-session-id`,children:[Ue(e.session_id),e.consolidated&&(0,v.jsx)(`span`,{className:`mem-consolidated-badge`,title:`Consolidated`,children:(0,v.jsx)($e,{size:11})})]}),e.first_message&&(0,v.jsx)(`div`,{className:`mem-conv-preview`,children:e.first_message})]}),(0,v.jsxs)(`div`,{className:`mem-conv-meta`,children:[(0,v.jsxs)(`span`,{children:[e.turn_count,` turns`]}),(0,v.jsx)(`span`,{children:x(e.last_activity)})]})]},e.session_id))}):(0,v.jsxs)(`div`,{className:`mem-empty`,children:[(0,v.jsx)(`div`,{className:`mem-empty-icon`,children:(0,v.jsx)(a,{size:28})}),(0,v.jsx)(`p`,{children:`No conversation history in memory`})]}):Zt.length>0?(0,v.jsx)(`div`,{className:`mem-conv-list`,children:Zt.map(e=>(0,v.jsxs)(`div`,{className:`mem-conv-item`,onClick:()=>Dr(e.session_id),children:[(0,v.jsxs)(`div`,{className:`mem-conv-info`,children:[(0,v.jsxs)(`div`,{className:`mem-conv-session-id`,children:[(0,v.jsx)(`span`,{className:`mem-conv-turn-role ${e.role}`,children:e.role}),` `,Ue(e.session_id)]}),(0,v.jsx)(`div`,{className:`mem-conv-preview`,children:e.content})]}),(0,v.jsx)(`div`,{className:`mem-conv-meta`,children:(0,v.jsx)(`span`,{children:x(e.timestamp)})})]},e.id))}):(0,v.jsx)(`div`,{className:`mem-empty`,children:(0,v.jsxs)(`p`,{children:[`No conversations match “`,Yt,`”`]})})]}),D&&(0,v.jsxs)(`div`,{className:`mem-conv-detail-overlay`,children:[(0,v.jsxs)(`div`,{className:`mem-conv-detail-header`,children:[(0,v.jsx)(`h2`,{children:Ue(D.sessionId)}),(0,v.jsxs)(`div`,{className:`mem-conv-detail-actions`,children:[r.has(D.sessionId)&&(0,v.jsx)(`button`,{className:`btn-secondary`,onClick:()=>n(D.sessionId),children:`Open chat`}),(0,v.jsx)(`button`,{className:`btn-icon`,onClick:()=>en(null),"aria-label":`Close conversation`,children:(0,v.jsx)(oe,{size:16})})]})]}),(0,v.jsxs)(`div`,{className:`mem-conv-detail-body`,children:[D.turns.map(e=>(0,v.jsxs)(`div`,{className:`mem-conv-turn`,children:[(0,v.jsxs)(`div`,{className:`mem-conv-turn-header`,children:[(0,v.jsx)(`div`,{className:`mem-conv-turn-role ${e.role}`,children:e.role}),(0,v.jsx)(`span`,{className:`mem-conv-turn-time`,title:b(e.timestamp),children:x(e.timestamp)})]}),(0,v.jsx)(`div`,{className:`mem-conv-turn-content`,children:e.content})]},e.id)),D.turns.length===0&&(0,v.jsx)(`div`,{className:`mem-empty`,children:`No turns found`})]})]})]}),(0,v.jsxs)(`div`,{className:`mem-section`,children:[(0,v.jsxs)(`div`,{className:`mem-section-title`,children:[(0,v.jsx)(nt,{size:14}),` Settings `,(0,v.jsx)(`span`,{style:{fontSize:10,fontWeight:600,color:`var(--accent-yellow)`,background:`var(--accent-yellow-dim)`,padding:`1px 6px`,borderRadius:4,marginLeft:6,verticalAlign:`middle`,letterSpacing:`0.5px`},children:`BETA`})]}),(0,v.jsxs)(`div`,{className:`mem-setting-row`,children:[(0,v.jsxs)(`div`,{className:`mem-setting-info`,children:[(0,v.jsx)(`span`,{className:`mem-setting-label`,children:`Memory enabled`}),(0,v.jsx)(`span`,{className:`mem-setting-desc`,children:`When disabled, no knowledge or conversation data is stored during any session (global incognito).`})]}),(0,v.jsx)(`button`,{className:`mem-toggle${M?` mem-toggle-on`:``}`,disabled:N,onClick:async()=>{if(!M)L(`memory`);else{P(!0);try{let e=await p({memory_enabled:!1});on(e.memory_enabled)}catch(e){i.system.warn(`Failed to disable memory`,e)}finally{P(!1)}}},"aria-pressed":M,"aria-label":`Memory is ${M?`enabled`:`disabled`}`,children:M?`On`:`Off`})]}),I&&(()=>{let e={memory:{title:`Enable Agent Memory?`,description:`Agent memory is a work-in-progress. By enabling it:`,bullets:[[`Conversations and facts are stored `,`locally on this machine`],[`Stored data `,`may be lost`,` during updates`],[`You can disable it at any time from this settings panel`]],buttonLabel:`Enable Memory`,onConfirm:async()=>{let e=await p({memory_enabled:!0});on(e.memory_enabled),Y(`Memory enabled`,`info`)}},mcp:{title:`Enable MCP Memory Access?`,description:`This exposes memory data to external MCP clients:`,bullets:[[`MCP clients can `,`read your stored memories`,` (read-only)`],[`Requires an `,`MCP server restart`,` to take effect`],[`Intended for debugging and troubleshooting only`]],buttonLabel:`Enable MCP Access`,onConfirm:async()=>{let e=await p({mcp_memory_enabled:!0});cn(e.mcp_memory_enabled),Y(`MCP memory access enabled`,`info`)}},discovery:{title:`Enable System Discovery?`,description:`This scans your system to personalize responses:`,bullets:[[`Collects `,`hardware, software, and environment`,` information`],[`Scans files, git repos, browser history, and SSH config`],[`All data stays `,`local on this machine`]],buttonLabel:`Enable Discovery`,onConfirm:async()=>{let e=await p({system_discovery_consent:!0});if(un(e.system_discovery_consent),e.system_context_error)Y(`System discovery enabled but scan failed: ${e.system_context_error}`,`error`);else{let t=e.system_context_refresh?.stored??0;Y(`System discovery enabled — ${t} system facts collected`,`info`)}Q()}}}[I];return(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`div`,{"aria-hidden":`true`,style:{position:`fixed`,inset:0,background:`var(--bg-modal-overlay)`,zIndex:9998,backdropFilter:`blur(4px)`},onClick:()=>L(null)}),(0,v.jsxs)(`div`,{ref:sr,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`mem-beta-confirm-title`,"aria-describedby":`mem-beta-confirm-desc`,tabIndex:-1,style:{position:`fixed`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,zIndex:9999,background:`var(--bg-card)`,border:`1px solid var(--border)`,borderRadius:12,padding:`28px 32px`,maxWidth:420,width:`90vw`,boxShadow:`var(--shadow-lg)`},children:[(0,v.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10,marginBottom:16},children:[(0,v.jsx)(`span`,{style:{fontSize:11,fontWeight:700,color:`var(--accent-yellow)`,background:`var(--accent-yellow-dim)`,padding:`3px 10px`,borderRadius:4,letterSpacing:`0.5px`},children:`BETA`}),(0,v.jsx)(`h2`,{id:`mem-beta-confirm-title`,style:{fontSize:16,fontWeight:600,color:`var(--text-primary)`},children:e.title})]}),(0,v.jsx)(`p`,{id:`mem-beta-confirm-desc`,style:{fontSize:13,lineHeight:1.6,color:`var(--text-secondary)`,margin:`0 0 8px`},children:e.description}),(0,v.jsx)(`ul`,{style:{fontSize:13,lineHeight:1.7,color:`var(--text-secondary)`,margin:`0 0 24px`,paddingLeft:20},children:e.bullets.map((e,t)=>(0,v.jsx)(`li`,{children:e.map((e,t)=>t%2==1?(0,v.jsx)(`strong`,{style:{color:`var(--text-primary)`},children:e},t):(0,v.jsx)(`span`,{children:e},t))},t))}),(0,v.jsxs)(`div`,{style:{display:`flex`,justifyContent:`flex-end`,gap:10},children:[(0,v.jsx)(`button`,{className:`btn-secondary`,onClick:()=>L(null),style:{padding:`8px 20px`,fontSize:13,borderRadius:6},children:`Cancel`}),(0,v.jsx)(`button`,{disabled:N,onClick:async()=>{P(!0);try{await e.onConfirm()}catch(e){i.system.warn(`Failed to update setting`,e),Y(`Failed to update setting. Please try again.`,`error`)}finally{P(!1),L(null)}},style:{padding:`8px 24px`,fontSize:13,fontWeight:600,borderRadius:6,border:`none`,cursor:`pointer`,background:`var(--accent-fill)`,color:`var(--accent-fill-text)`},children:e.buttonLabel})]})]})]})})(),(0,v.jsxs)(`div`,{className:`mem-setting-row`,children:[(0,v.jsxs)(`div`,{className:`mem-setting-info`,children:[(0,v.jsx)(`span`,{className:`mem-setting-label`,children:`MCP memory access`}),(0,v.jsx)(`span`,{className:`mem-setting-desc`,children:`Expose read-only memory tools to MCP clients (for debug/troubleshooting). Requires MCP server restart.`})]}),(0,v.jsx)(`button`,{className:`mem-toggle${sn?` mem-toggle-on`:``}`,disabled:N,onClick:async()=>{if(!sn)L(`mcp`);else{P(!0);try{let e=await p({mcp_memory_enabled:!1});cn(e.mcp_memory_enabled)}catch(e){i.system.warn(`Failed to update memory settings`,e)}finally{P(!1)}}},"aria-label":`Toggle MCP memory access`,"aria-pressed":sn,children:sn?`On`:`Off`})]}),(0,v.jsxs)(`div`,{className:`mem-setting-row`,children:[(0,v.jsxs)(`div`,{className:`mem-setting-info`,children:[(0,v.jsx)(`span`,{className:`mem-setting-label`,children:`System discovery`}),(0,v.jsx)(`span`,{className:`mem-setting-desc`,children:`Allow GAIA to scan your system for hardware, software, and environment information to personalize responses.`})]}),(0,v.jsx)(`button`,{className:`mem-toggle${ln?` mem-toggle-on`:``}`,disabled:N,onClick:async()=>{if(!ln)L(`discovery`);else{P(!0);try{let e=await p({system_discovery_consent:!1});un(e.system_discovery_consent)}catch(e){i.system.warn(`Failed to update system discovery setting`,e)}finally{P(!1)}}},"aria-label":`Toggle system discovery`,"aria-pressed":ln,children:ln?`On`:`Off`})]}),(0,v.jsxs)(`div`,{className:`mem-setting-row mem-setting-row-danger`,children:[(0,v.jsxs)(`div`,{className:`mem-setting-info`,children:[(0,v.jsx)(`span`,{className:`mem-setting-label`,children:`Re-initialize memory`}),(0,v.jsx)(`span`,{className:`mem-setting-desc`,children:`Wipe all memories, conversations, and tool logs, then re-collect system information. This cannot be undone.`})]}),mn?(0,v.jsxs)(`div`,{className:`mem-delete-confirm`,children:[(0,v.jsx)(`span`,{className:`mem-delete-confirm-label`,children:`Are you sure?`}),(0,v.jsx)(`button`,{className:`mem-btn-danger`,disabled:N,onClick:async()=>{P(!0);try{let e=await ae();e.system_context.error?Y(e.system_context.error,`error`):Y(`Re-initialized: cleared ${e.cleared.knowledge} entries, restored ${e.system_context.stored} system facts`,`info`),Q()}catch(e){i.system.warn(`Failed to reinitialize memory`,e),Y(`Failed to re-initialize memory`,`error`)}finally{P(!1),hn(!1)}},children:`Yes, re-initialize`}),(0,v.jsx)(`button`,{className:`btn-secondary`,onClick:()=>hn(!1),style:{padding:`6px 14px`,fontSize:12},children:`Cancel`})]}):(0,v.jsx)(`button`,{className:`mem-btn-danger`,disabled:N,onClick:()=>hn(!0),children:`Re-initialize`})]}),(0,v.jsxs)(`div`,{className:`mem-setting-row mem-setting-row-danger`,children:[(0,v.jsxs)(`div`,{className:`mem-setting-info`,children:[(0,v.jsx)(`span`,{className:`mem-setting-label`,children:`Delete all memories`}),(0,v.jsx)(`span`,{className:`mem-setting-desc`,children:`Permanently wipe all knowledge entries, conversation history, and tool logs. This cannot be undone.`})]}),dn?(0,v.jsxs)(`div`,{className:`mem-delete-confirm`,children:[(0,v.jsx)(`span`,{className:`mem-delete-confirm-label`,children:`Are you sure?`}),(0,v.jsx)(`button`,{className:`mem-btn-danger`,disabled:N,onClick:async()=>{P(!0);try{let e=await Ne();Y(`Deleted ${e.knowledge} knowledge entries, ${e.conversations} conversations`,`info`),Q()}catch(e){i.system.warn(`Failed to clear memory`,e),Y(`Failed to clear memory`,`error`)}finally{P(!1),fn(!1)}},children:`Yes, delete all`}),(0,v.jsx)(`button`,{className:`btn-secondary`,onClick:()=>fn(!1),style:{padding:`6px 14px`,fontSize:12},children:`Cancel`})]}):(0,v.jsx)(`button`,{className:`mem-btn-danger`,disabled:N,onClick:()=>fn(!0),children:`Delete All`})]})]}),m&&(0,v.jsxs)(`div`,{className:`mem-db-footer`,children:[(0,v.jsxs)(`span`,{children:[`Database: `,He(m.db_size_bytes),m.knowledge?.avg_confidence!=null&&` \u00B7 Avg confidence: ${m.knowledge.avg_confidence.toFixed(2)}`]}),(0,v.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8},children:[m.knowledge?.entity_count!=null&&m.knowledge.entity_count>0&&(0,v.jsxs)(`span`,{children:[m.knowledge.entity_count,` entities`]}),m.knowledge?.sensitive_count!=null&&m.knowledge.sensitive_count>0&&(0,v.jsxs)(`span`,{children:[(0,v.jsx)(nt,{size:10}),` `,m.knowledge.sensitive_count,` sensitive`]})]})]})]})}),R===`profile`&&(0,v.jsxs)(`div`,{className:`mem-profile-grid`,children:[(0,v.jsxs)(`div`,{className:`mem-profile-card`,children:[(0,v.jsxs)(`div`,{className:`mem-profile-card-title`,children:[(0,v.jsx)(Le,{size:16}),` System Discovery`]}),(0,v.jsx)(`p`,{className:`mem-profile-desc`,children:`Scan your system to discover apps, projects, and usage patterns.`}),(0,v.jsx)(`button`,{className:`btn-primary mem-profile-run-btn`,disabled:z===`running`||z===`saving`,onClick:Ir,children:z===`running`?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`div`,{className:`mem-spinner-sm`}),` Running...`]}):`Run Discovery`}),Nn.length>0&&(0,v.jsx)(`div`,{className:`mem-log`,ref:In,children:Nn.map((e,t)=>(0,v.jsx)(`div`,{className:`mem-log-line ${e.kind}`,children:e.text},t))}),(z===`review`||z===`saving`||z===`done`)&&H.length>0&&(0,v.jsxs)(`div`,{className:`mem-review-section`,children:[(0,v.jsx)(`div`,{className:`mem-review-header`,children:`Review & Save`}),(0,v.jsx)(`div`,{className:`mem-review-list`,children:H.map((e,t)=>(0,v.jsxs)(`label`,{className:`mem-review-item`,children:[(0,v.jsx)(`input`,{type:`checkbox`,checked:e._checked,disabled:z===`saving`||z===`done`,onChange:()=>{U(e=>e.map((e,n)=>n===t?{...e,_checked:!e._checked}:e))}}),(0,v.jsx)(`span`,{className:`mem-review-content`,children:e.content}),(0,v.jsx)(`span`,{className:`mem-source-badge`,children:e._source_name||e.category}),(0,v.jsxs)(`span`,{className:`mem-conf-badge`,children:[Math.round(e.confidence*100),`%`]})]},t))}),(0,v.jsxs)(`div`,{className:`mem-review-actions`,children:[(0,v.jsx)(`button`,{className:`btn-primary`,disabled:z===`saving`||z===`done`||H.filter(e=>e._checked).length===0,onClick:Lr,children:z===`saving`?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`div`,{className:`mem-spinner-sm`}),` Saving...`]}):`Save Selected (${H.filter(e=>e._checked).length})`}),(0,v.jsxs)(`span`,{className:`mem-review-select-links`,children:[(0,v.jsx)(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>U(e=>e.map(e=>({...e,_checked:!0}))),children:`Select All`}),` / `,(0,v.jsx)(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>U(e=>e.map(e=>({...e,_checked:!1}))),children:`None`})]})]})]}),z===`done`&&Pn!==null&&(0,v.jsxs)(`div`,{className:`mem-profile-success`,children:[(0,v.jsx)(Ee,{size:14}),` Saved `,Pn,` items to memory`]}),z===`review`&&H.length===0&&(0,v.jsx)(`div`,{className:`mem-profile-empty`,children:`No items discovered.`})]}),(0,v.jsxs)(`div`,{className:`mem-profile-card`,children:[(0,v.jsxs)(`div`,{className:`mem-profile-card-title`,children:[(0,v.jsx)(ie,{size:16}),` AI Profile Inference`]}),(0,v.jsx)(`p`,{className:`mem-profile-desc`,children:`Use the local LLM to generate profile insights from your data.`}),(0,v.jsx)(`p`,{className:`mem-profile-note`,children:`Requires Lemonade Server running.`}),(0,v.jsxs)(`label`,{className:`mem-profile-checkbox`,children:[(0,v.jsx)(`input`,{type:`checkbox`,checked:Vn,onChange:e=>Hn(e.target.checked),disabled:W===`running`||W===`saving`}),`Include browser history`]}),(0,v.jsx)(`button`,{className:`btn-primary mem-profile-run-btn`,disabled:W===`running`||W===`saving`,onClick:Rr,children:W===`running`?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`div`,{className:`mem-spinner-sm`}),` Running...`]}):`Run Inference`}),Rn.length>0&&(0,v.jsx)(`div`,{className:`mem-log`,ref:Un,children:Rn.map((e,t)=>(0,v.jsx)(`div`,{className:`mem-log-line ${e.kind}`,children:e.text},t))}),(W===`review`||W===`saving`||W===`done`)&&q.length>0&&(0,v.jsxs)(`div`,{className:`mem-review-section`,children:[(0,v.jsx)(`div`,{className:`mem-review-header`,children:`Review & Save`}),(0,v.jsx)(`div`,{className:`mem-review-list`,children:q.map((e,t)=>(0,v.jsxs)(`label`,{className:`mem-review-item`,children:[(0,v.jsx)(`input`,{type:`checkbox`,checked:e._checked,disabled:W===`saving`||W===`done`,onChange:()=>{J(e=>e.map((e,n)=>n===t?{...e,_checked:!e._checked}:e))}}),(0,v.jsx)(`span`,{className:`mem-review-content`,children:e.content}),(0,v.jsx)(`span`,{className:`mem-domain-badge ${Ct[e.domain]||`gray`}`,children:e.domain}),(0,v.jsxs)(`span`,{className:`mem-conf-badge`,children:[Math.round(e.confidence*100),`%`]})]},t))}),(0,v.jsxs)(`div`,{className:`mem-review-actions`,children:[(0,v.jsx)(`button`,{className:`btn-primary`,disabled:W===`saving`||W===`done`||q.filter(e=>e._checked).length===0,onClick:zr,children:W===`saving`?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`div`,{className:`mem-spinner-sm`}),` Saving...`]}):`Save Selected (${q.filter(e=>e._checked).length})`}),(0,v.jsxs)(`span`,{className:`mem-review-select-links`,children:[(0,v.jsx)(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>J(e=>e.map(e=>({...e,_checked:!0}))),children:`Select All`}),` / `,(0,v.jsx)(`button`,{type:`button`,className:`mem-link-btn`,onClick:()=>J(e=>e.map(e=>({...e,_checked:!1}))),children:`None`})]})]})]}),W===`done`&&zn!==null&&(0,v.jsxs)(`div`,{className:`mem-profile-success`,children:[(0,v.jsx)(Ee,{size:14}),` Saved `,zn,` insights to memory`]}),W===`review`&&q.length===0&&(0,v.jsx)(`div`,{className:`mem-profile-empty`,children:`No insights generated.`})]})]}),R===`goals`&&(0,v.jsxs)(`div`,{className:`mem-goals-tab`,children:[(0,v.jsx)(`div`,{className:`mem-goals-stats-row`,children:[`queued`,`in_progress`,`completed`,`failed`].map(e=>(0,v.jsxs)(`div`,{className:`mem-goals-stat-pill mem-goal-status-${e.replace(`_`,`-`)}`,children:[(0,v.jsx)(`span`,{className:`mem-goals-stat-n`,children:xn?.goals[e]??0}),(0,v.jsx)(`span`,{className:`mem-goals-stat-label`,children:e.replace(`_`,` `)})]},e))}),yn.filter(e=>e.status===`pending_approval`).length>0&&(0,v.jsxs)(`div`,{className:`mem-goals-approval-banner`,children:[(0,v.jsxs)(`div`,{className:`mem-goals-approval-title`,children:[(0,v.jsx)(ut,{size:14}),` Agent suggested `,yn.filter(e=>e.status===`pending_approval`).length,` goal(s) — review before execution`]}),yn.filter(e=>e.status===`pending_approval`).map(e=>(0,v.jsxs)(`div`,{className:`mem-goals-approval-item`,children:[(0,v.jsxs)(`div`,{className:`mem-goals-approval-text`,children:[(0,v.jsx)(`strong`,{children:e.title}),(0,v.jsx)(`span`,{children:e.description})]}),(0,v.jsxs)(`div`,{className:`mem-goals-approval-actions`,children:[(0,v.jsx)(`button`,{className:`btn-danger-sm`,onClick:()=>gr(()=>ce(e.id),`Couldn't reject the goal`),children:`Reject`}),(0,v.jsx)(`button`,{className:`btn-secondary`,onClick:()=>gr(()=>Be(e.id),`Couldn't accept the goal`),children:`Accept`})]})]},e.id))]}),(0,v.jsx)(`div`,{className:`mem-goals-toolbar`,children:(0,v.jsxs)(`button`,{className:`btn-primary`,onClick:()=>An(e=>!e),children:[(0,v.jsx)(se,{size:14}),` New Goal`]})}),kn&&(0,v.jsxs)(`div`,{className:`mem-goals-add-form`,children:[(0,v.jsx)(`input`,{className:`mem-input`,placeholder:`Goal title`,value:jn.title,onChange:e=>Mn(t=>({...t,title:e.target.value}))}),(0,v.jsx)(`textarea`,{className:`mem-input`,placeholder:`Description — what should the agent work toward?`,rows:2,value:jn.description,onChange:e=>Mn(t=>({...t,description:e.target.value}))}),(0,v.jsxs)(`div`,{className:`mem-goals-form-row`,children:[(0,v.jsxs)(`select`,{className:`mem-select`,value:jn.priority,onChange:e=>Mn(t=>({...t,priority:e.target.value})),children:[(0,v.jsx)(`option`,{value:`low`,children:`Low priority`}),(0,v.jsx)(`option`,{value:`medium`,children:`Medium priority`}),(0,v.jsx)(`option`,{value:`high`,children:`High priority`})]}),(0,v.jsx)(`button`,{className:`btn-primary`,onClick:()=>{jn.title.trim()&&gr(async()=>{await Re(jn),Mn({title:``,description:``,priority:`medium`}),An(!1)},`Couldn't create the goal`)},children:`Create`}),(0,v.jsx)(`button`,{className:`btn-secondary`,onClick:()=>An(!1),children:`Cancel`})]})]}),Cn?(0,v.jsxs)(`div`,{className:`mem-loading`,children:[(0,v.jsx)(`div`,{className:`mem-spinner`}),` Loading goals...`]}):yn.filter(e=>e.status!==`pending_approval`&&e.status!==`rejected`).length===0?(0,v.jsxs)(`div`,{className:`mem-empty`,children:[(0,v.jsx)(`div`,{className:`mem-empty-icon`,children:(0,v.jsx)(it,{size:32})}),(0,v.jsx)(`p`,{children:`No goals yet. Create one or let the agent suggest goals in autonomous mode.`})]}):(0,v.jsx)(`div`,{className:`mem-goals-list`,children:yn.filter(e=>e.status!==`pending_approval`&&e.status!==`rejected`).map(e=>(0,v.jsxs)(`div`,{className:`mem-goal-card mem-goal-status-${e.status.replace(`_`,`-`)}`,children:[(0,v.jsxs)(`div`,{className:`mem-goal-header`,role:`button`,tabIndex:0,"aria-expanded":Tn===e.id,onClick:()=>En(t=>t===e.id?null:e.id),onKeyDown:t=>{t.target===t.currentTarget&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),En(t=>t===e.id?null:e.id))},children:[(0,v.jsxs)(`div`,{className:`mem-goal-header-left`,children:[(0,v.jsx)(`span`,{className:`mem-goal-status-dot status-${e.status.replace(`_`,`-`)}`}),(0,v.jsx)(`span`,{className:`mem-goal-title`,children:e.title}),(0,v.jsx)(`span`,{className:`mem-goal-priority mem-priority-${e.priority}`,children:e.priority}),e.source!==`user`&&(0,v.jsxs)(`span`,{className:`mem-goal-source-badge`,children:[(0,v.jsx)(ut,{size:10}),` `,e.source.replace(`_`,` `)]})]}),(0,v.jsxs)(`div`,{className:`mem-goal-header-right`,children:[(0,v.jsxs)(`span`,{className:`mem-goal-task-count`,children:[(0,v.jsx)(ve,{size:12}),e.tasks.filter(e=>e.status===`completed`).length,`/`,e.tasks.length]}),e.status===`queued`&&(0,v.jsx)(`button`,{className:`mem-goal-action-btn mem-goal-cancel-btn`,onClick:t=>{t.stopPropagation(),gr(()=>Ce(e.id),`Couldn't cancel the goal`)},children:`Cancel`}),Dn===e.id?(0,v.jsx)(`button`,{className:`mem-goal-action-btn mem-goal-delete-btn mem-goal-delete-confirm`,onClick:t=>{t.stopPropagation(),On(null),gr(()=>ke(e.id),`Couldn't delete the goal`)},children:`Delete?`}):(0,v.jsx)(`button`,{className:`mem-goal-action-btn mem-goal-delete-btn`,"aria-label":`Delete goal ${e.title}`,onClick:t=>{t.stopPropagation(),On(e.id)},children:(0,v.jsx)(he,{size:12})}),(0,v.jsx)(Ae,{size:14,className:Tn===e.id?`mem-chevron-open`:``})]})]}),Tn===e.id&&(0,v.jsxs)(`div`,{className:`mem-goal-body`,children:[e.description&&(0,v.jsx)(`p`,{className:`mem-goal-desc`,children:e.description}),e.progress_notes&&(0,v.jsx)(`p`,{className:`mem-goal-progress`,children:e.progress_notes}),e.tasks.length>0?(0,v.jsx)(`div`,{className:`mem-task-list`,children:e.tasks.map(e=>(0,v.jsxs)(`div`,{className:`mem-task-row mem-task-status-${e.status}`,children:[(0,v.jsx)(`span`,{className:`mem-task-dot status-${e.status}`}),(0,v.jsx)(`span`,{className:`mem-task-desc`,children:e.description}),(0,v.jsx)(`span`,{className:`mem-task-status-label`,children:e.status}),e.result&&(0,v.jsx)(`span`,{className:`mem-task-result`,children:e.result})]},e.id))}):(0,v.jsx)(`p`,{className:`mem-goal-no-tasks`,children:`No tasks yet — the agent will break this down when it starts.`})]})]},e.id))})]})]}),Pt.length>0&&(0,v.jsx)(`div`,{className:`mem-toast-container`,"aria-live":`polite`,children:Pt.map(e=>(0,v.jsxs)(`div`,{className:`mem-toast mem-toast-${e.type}`,role:`status`,children:[e.type===`success`&&(0,v.jsx)(Ee,{size:14}),e.type===`error`&&(0,v.jsx)(s,{size:14}),e.type===`info`&&(0,v.jsx)(be,{size:14}),(0,v.jsx)(`span`,{children:e.text})]},e.id))})]})}export{wt as MemoryDashboard};
@@ -1 +0,0 @@
1
- .schedule-modal{flex-direction:column;width:640px;max-height:80vh;display:flex}.schedule-modal .modal-body{flex:1;overflow-y:auto}.schedule-create-form{flex-direction:column;gap:10px;margin-bottom:20px;display:flex}.schedule-field{flex-direction:column;gap:4px;display:flex}.schedule-field-label{font-size:var(--fs-label);color:var(--text-secondary);font-weight:600}.schedule-form-row{gap:8px;display:flex}.schedule-form-row input{border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--bg-input);color:var(--text-primary);font-size:13px;font-family:var(--font-sans);flex:1;padding:8px 12px}.schedule-form-row input:focus{border-color:var(--accent);outline:none}.schedule-form-row input::placeholder{color:var(--text-muted)}.schedule-prompt-input{border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--bg-input);width:100%;color:var(--text-primary);font-size:13px;font-family:var(--font-sans);resize:vertical;min-height:60px;padding:8px 12px}.schedule-prompt-input:focus{border-color:var(--accent);outline:none}.schedule-prompt-input::placeholder{color:var(--text-muted)}.schedule-create-actions{justify-content:flex-end;gap:8px;display:flex}.schedule-form-error{color:var(--accent);margin-top:-4px;font-size:12px}.schedule-section{margin-bottom:20px}.schedule-section:last-child{margin-bottom:0}.schedule-section h4{font-size:var(--fs-label);color:var(--text-muted);margin-bottom:10px;font-weight:700}.schedule-empty{color:var(--text-muted);text-align:center;padding:24px 12px;font-size:13px}.schedule-list{flex-direction:column;gap:6px;display:flex}.schedule-card{border-radius:var(--radius-sm);background:var(--bg-secondary);border:1px solid var(--border-light);cursor:pointer;transition:background var(--duration-fast) var(--ease);flex-direction:column;padding:10px 12px;display:flex}.schedule-card:hover{background:var(--bg-hover)}.schedule-card.selected{border-color:var(--accent);background:var(--bg-hover)}.schedule-card.just-ran{animation:schedule-flash var(--duration-pulse) var(--ease)}@keyframes schedule-flash{0%{border-color:var(--accent-green)}to{border-color:var(--border-light)}}.schedule-card-header{justify-content:space-between;align-items:center;gap:8px;display:flex}.schedule-card-name{text-overflow:ellipsis;white-space:nowrap;flex:1;font-size:13px;font-weight:600;overflow:hidden}.schedule-card-status{font-size:var(--fs-caption);text-transform:capitalize;border-radius:var(--radius-sm);padding:2px 8px;font-weight:600}.schedule-card-status.active{color:var(--accent-green);background:color-mix(in srgb, var(--accent-green) 10%, transparent)}.schedule-card-status.paused{color:var(--accent-yellow);background:color-mix(in srgb, var(--accent-yellow) 10%, transparent)}.schedule-card-status.cancelled{color:var(--text-muted);background:var(--bg-tertiary)}.schedule-card-meta{color:var(--text-secondary);align-items:center;gap:12px;margin-top:6px;font-size:12px;display:flex}.schedule-card-error{border-left:2px solid var(--danger);background:color-mix(in srgb, var(--danger) 8%, transparent);color:var(--text-primary);white-space:pre-wrap;overflow-wrap:anywhere;margin-top:6px;padding:6px 8px;font-size:12px}.schedule-card-prompt{color:var(--text-secondary);text-overflow:ellipsis;white-space:nowrap;margin-top:4px;font-size:12px;overflow:hidden}.schedule-card-actions{gap:4px;margin-top:8px;display:flex}.schedule-card-actions .btn-sm{border-radius:var(--radius-sm);border:1px solid var(--border);background:var(--bg-tertiary);color:var(--text-primary);cursor:pointer;transition:background var(--duration-fast) var(--ease);padding:3px 10px;font-size:11px}.schedule-card-actions .btn-sm:hover{background:var(--bg-active)}.schedule-card-actions .btn-sm.chat{color:var(--accent-blue);border-color:var(--accent-blue)}.schedule-card-actions .btn-sm.chat:hover{background:color-mix(in srgb, var(--accent-blue) 10%, transparent)}.schedule-card-actions .btn-sm.danger{color:var(--accent);border-color:var(--accent)}.schedule-card-actions .btn-sm.danger:hover{background:color-mix(in srgb, var(--danger) 10%, transparent)}.schedule-results{border-top:1px solid var(--border);margin-top:16px;padding-top:14px}.schedule-results h4{font-size:var(--fs-label);color:var(--text-muted);margin-bottom:10px;font-weight:700}.schedule-results-list{flex-direction:column;gap:6px;max-height:200px;display:flex;overflow-y:auto}.schedule-result-item{border-radius:var(--radius-sm);background:var(--bg-tertiary);padding:8px 10px;font-size:12px}.schedule-result-time{color:var(--text-muted);font-family:var(--font-sans);font-size:var(--fs-caption);font-variant-numeric:tabular-nums;margin-bottom:4px}.schedule-result-content{color:var(--text-primary);white-space:pre-wrap;word-break:break-word;max-height:60px;overflow-y:auto}.schedule-result-error{color:var(--accent)}.schedule-results-empty{color:var(--text-muted);text-align:center;padding:12px;font-size:12px}.schedule-nl-input{border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--bg-input);width:100%;color:var(--text-primary);font-size:13px;font-family:var(--font-sans);resize:vertical;min-height:50px;padding:10px 12px}.schedule-nl-input:focus{border-color:var(--accent);outline:none}.schedule-nl-input::placeholder{color:var(--text-muted)}.schedule-parsed-preview{border-radius:var(--radius-sm);border:1px solid var(--border-light);background:var(--bg-tertiary);padding:10px 12px;font-size:12px}.schedule-parsed-preview.valid{border-color:var(--accent-green);background:color-mix(in srgb, var(--accent-green) 5%, transparent)}.schedule-parsed-preview.invalid{border-color:var(--accent);background:color-mix(in srgb, var(--danger) 5%, transparent)}.schedule-parsed-loading{color:var(--text-muted);font-style:italic}.schedule-parsed-description{color:var(--text-primary);margin-bottom:4px;font-weight:600}.schedule-parsed-hint{color:var(--text-secondary);margin-bottom:4px}.schedule-parsed-next{color:var(--text-secondary);margin-bottom:6px;font-size:11px}.schedule-parsed-details{flex-wrap:wrap;gap:8px;display:flex}.schedule-parsed-tag{border-radius:var(--radius-sm);background:var(--bg-secondary);border:1px solid var(--border);color:var(--text-secondary);align-items:center;gap:4px;padding:2px 8px;font-size:11px;display:inline-flex}.schedule-field-missing{box-shadow:0 0 0 1px color-mix(in srgb, var(--accent-yellow) 30%, transparent);border-color:var(--accent-yellow)!important}
@@ -1,2 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{a as t,n,o as r,r as i}from"./apiBase-CS6zLsJY.js";import{t as a}from"./message-square-CLnmengs.js";import{Ft as o,It as s,Kt as c,Pt as l,Vt as u,W as d,cn as f,n as p,ut as m}from"./index-Fhiym-Jy.js";var h={name:`pause`,size:24,node:[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]};h.node;var g=t(h),_={name:`play`,size:24,node:[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]};_.node;var v=t(_),y=e(r(),1),b=n(),x=8e3;function S(e,t){if(!e)return`never`;let n=new Date(e),r=(t||new Date).getTime()-n.getTime(),i=Math.floor(r/1e3);if(i<0){let e=Math.abs(i);if(e<60)return`in ${e}s`;let t=Math.floor(e/60);if(t<60)return`in ${t}m`;let n=Math.floor(t/60);return n<24?`in ${n}h`:`in ${Math.floor(n/24)}d`}if(i<60)return`just now`;let a=Math.floor(i/60);if(a<60)return`${a}m ago`;let o=Math.floor(a/60);return o<24?`${o}h ago`:n.toLocaleDateString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function C(e,t){if(!e)return`never`;let n=S(e,t),r=new Date(e);return r.getTime()<=(t||new Date).getTime()?n:`${r.toLocaleString(void 0,{weekday:`short`,hour:`numeric`,minute:`2-digit`})} (${n})`}function w(e){if(!e)return!1;let t=new Date(e).getTime()-Date.now();return t>0&&t<6e4}function T(e){let[t,n]=e.split(`:`).map(Number),r=t>=12?`PM`:`AM`;return`${t===0?12:t>12?t-12:t}:${n.toString().padStart(2,`0`)} ${r}`}function E(e){let t=e>=12?`PM`:`AM`;return`${e===0?12:e>12?e-12:e} ${t}`}function D(e){let t=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];return e.length===5&&!e.includes(5)&&!e.includes(6)?`Weekdays`:e.length===2&&e.includes(5)&&e.includes(6)?`Weekends`:e.length===7?`Every day`:e.map(e=>t[e]).join(`, `)}function O({schedule:e}){let{selectedSchedule:t,selectSchedule:n,updateScheduleStatus:r,deleteSchedule:s,results:c,resultsLoading:l,loadSchedules:d,loadResults:m}=p(),{setCurrentSession:h,setShowSchedules:_}=o(),T=t===e.name,[E,D]=(0,y.useState)(!1),O=(0,y.useRef)(null),k=(0,y.useCallback)(()=>{O.current&&=(clearTimeout(O.current),null)},[]);(0,y.useEffect)(()=>k,[k]);let[A,j]=(0,y.useState)(()=>new Date),M=(0,y.useRef)(null);(0,y.useEffect)(()=>{let t=e.status===`active`&&w(e.next_run_at);return t&&!M.current?M.current=setInterval(()=>{j(new Date),e.next_run_at&&new Date(e.next_run_at).getTime()<=Date.now()&&d()},1e3):!t&&M.current&&(clearInterval(M.current),M.current=null),()=>{M.current&&=(clearInterval(M.current),null)}},[e.status,e.next_run_at,d]);let N=(0,y.useRef)(e.last_run_at);(0,y.useEffect)(()=>{T&&e.last_run_at!==N.current&&(N.current=e.last_run_at,m(e.name))},[T,e.last_run_at,e.name,m]);let P=e.last_run_at&&Date.now()-new Date(e.last_run_at).getTime()<5e3,F=(0,y.useCallback)(t=>{t.stopPropagation();let n=e.status===`active`?`paused`:`active`;i.ui.info(`Schedule "${e.name}": ${e.status} -> ${n}`),r(e.name,n)},[e.name,e.status,r]),I=(0,y.useCallback)(t=>{t.stopPropagation(),k(),E?(i.ui.info(`Deleting schedule "${e.name}"`),s(e.name)):(D(!0),O.current=setTimeout(()=>{O.current=null,D(!1)},x))},[e.name,E,s,k]),L=(0,y.useCallback)(t=>{t.stopPropagation(),e.session_id&&(i.ui.info(`Opening chat session for schedule "${e.name}"`),h(e.session_id),_(!1))},[e.session_id,e.name,h,_]);return(0,b.jsxs)(`div`,{className:`schedule-card ${T?`selected`:``} ${P?`just-ran`:``}`,onClick:()=>n(T?null:e.name),children:[(0,b.jsxs)(`div`,{className:`schedule-card-header`,children:[(0,b.jsx)(`span`,{className:`schedule-card-name`,children:e.name}),(0,b.jsx)(`span`,{className:`schedule-card-status ${e.status}`,children:e.status})]}),(0,b.jsx)(`div`,{className:`schedule-card-prompt`,children:e.prompt}),(0,b.jsxs)(`div`,{className:`schedule-card-meta`,children:[(0,b.jsxs)(`span`,{title:e.description,children:[(0,b.jsx)(f,{size:11}),` `,e.description]}),(0,b.jsxs)(`span`,{children:[`Runs: `,e.run_count]}),e.error_count>0&&(0,b.jsxs)(`span`,{children:[`Errors: `,e.error_count]}),(0,b.jsxs)(`span`,{children:[`Last: `,S(e.last_run_at)]}),(0,b.jsxs)(`span`,{children:[`Next: `,C(e.next_run_at,A)]})]}),e.last_error&&(0,b.jsxs)(`div`,{className:`schedule-card-error`,children:[`Last run failed: `,e.last_error]}),(0,b.jsxs)(`div`,{className:`schedule-card-actions`,children:[e.session_id&&(0,b.jsxs)(`button`,{className:`btn-sm chat`,onClick:L,title:`Open chat session`,children:[(0,b.jsx)(a,{size:11}),` Open Chat`]}),(0,b.jsx)(`button`,{className:`btn-sm`,onClick:F,title:e.status===`active`?`Pause`:`Resume`,children:e.status===`active`?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(g,{size:11}),` Pause`]}):(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(v,{size:11}),` Resume`]})}),(0,b.jsxs)(`button`,{className:`btn-sm danger`,onClick:I,title:`Delete`,children:[(0,b.jsx)(u,{size:11}),` `,E?`Confirm?`:`Delete`]})]}),T&&(0,b.jsxs)(`div`,{className:`schedule-results`,children:[(0,b.jsx)(`h4`,{children:`Execution history`}),l?(0,b.jsx)(`p`,{className:`schedule-results-empty`,children:`Loading...`}):c.length===0?(0,b.jsx)(`p`,{className:`schedule-results-empty`,children:`No executions yet`}):(0,b.jsx)(`div`,{className:`schedule-results-list`,children:c.map(e=>(0,b.jsxs)(`div`,{className:`schedule-result-item`,children:[(0,b.jsx)(`div`,{className:`schedule-result-time`,children:S(e.executed_at)}),e.error?(0,b.jsx)(`div`,{className:`schedule-result-content schedule-result-error`,children:e.error}):(0,b.jsx)(`div`,{className:`schedule-result-content`,children:e.result||`(no output)`})]},e.id))})]})]})}function k(){let{setShowSchedules:e}=o(),{schedules:t,loading:n,error:r,loadSchedules:a,createSchedule:u}=p(),h=(0,y.useCallback)(()=>e(!1),[e]);l(!0,h);let g=(0,y.useRef)(null);d(g,!0);let[_,v]=(0,y.useState)(!1),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(``),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(null),[N,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(!1),[L,R]=(0,y.useState)(null),z=(0,y.useId)(),B=`${z}-when`,V=`${z}-when-error`,H=`${z}-name`,U=`${z}-prompt`,W=!N&&j!==null&&!j.valid,G=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!x.trim())M(null);else return G.current&&clearTimeout(G.current),G.current=window.setTimeout(async()=>{P(!0);try{let e=await m(x);M(e)}catch{M(null)}finally{P(!1)}},400),()=>{G.current&&clearTimeout(G.current)}},[x]);let K=(0,y.useRef)(null);(0,y.useEffect)(()=>(i.ui.info(`Schedule Manager opened`),a(),K.current=window.setInterval(()=>a(),5e3),()=>{K.current&&clearInterval(K.current)}),[a]);let q=x.trim()&&C.trim()&&k.trim()&&(j===null||j.valid),J=(0,y.useCallback)(async()=>{if(q){I(!0),R(null);try{await u(C.trim(),x.trim(),k.trim()),S(``),w(``),A(``),M(null),v(!1),i.ui.info(`Schedule "${C}" created`)}catch(e){let t=e instanceof Error?e.message:`Failed to create schedule`;R(t)}finally{I(!1)}}},[q,C,x,k,u]);return(0,b.jsx)(`div`,{ref:g,className:`modal-overlay`,onClick:()=>e(!1),role:`dialog`,"aria-modal":`true`,"aria-label":`Scheduled tasks`,children:(0,b.jsxs)(`div`,{className:`modal-panel schedule-modal`,onClick:e=>e.stopPropagation(),children:[(0,b.jsxs)(`div`,{className:`modal-header`,children:[(0,b.jsx)(`h3`,{children:`Scheduled tasks`}),(0,b.jsx)(`button`,{className:`btn-icon`,onClick:()=>e(!1),"aria-label":`Close schedule manager`,children:(0,b.jsx)(s,{size:18})})]}),(0,b.jsxs)(`div`,{className:`modal-body`,children:[(0,b.jsx)(`section`,{className:`schedule-section`,children:_?(0,b.jsxs)(`div`,{className:`schedule-create-form`,children:[(0,b.jsxs)(`div`,{className:`schedule-field`,children:[(0,b.jsx)(`label`,{className:`schedule-field-label`,htmlFor:B,children:`When to run`}),(0,b.jsx)(`textarea`,{id:B,className:`schedule-nl-input`,placeholder:`Describe your schedule in natural language...
2
- Examples: "every 30m", "daily at 9pm", "every hour from 8am to 6pm on weekdays"`,value:x,onChange:e=>S(e.target.value),"aria-invalid":W,"aria-describedby":W?V:void 0,autoFocus:!0,rows:2})]}),(j||N)&&(0,b.jsx)(`div`,{className:`schedule-parsed-preview ${j?.valid?`valid`:`invalid`}`,"aria-live":`polite`,children:N?(0,b.jsx)(`span`,{className:`schedule-parsed-loading`,children:`Parsing...`}):j?(0,b.jsxs)(b.Fragment,{children:[j.valid?(0,b.jsx)(`div`,{className:`schedule-parsed-description`,children:j.description}):(0,b.jsxs)(`div`,{id:V,children:[(0,b.jsx)(`div`,{className:`schedule-parsed-description`,children:`GAIA didn't understand that schedule.`}),(0,b.jsx)(`div`,{className:`schedule-parsed-hint`,children:j.description})]}),j.valid&&j.next_run_at&&(0,b.jsxs)(`div`,{className:`schedule-parsed-next`,children:[`Next run: `,new Date(j.next_run_at).toLocaleString()]}),j.valid&&(0,b.jsxs)(`div`,{className:`schedule-parsed-details`,children:[j.time_of_day&&(0,b.jsxs)(`span`,{className:`schedule-parsed-tag`,children:[(0,b.jsx)(f,{size:10}),` `,T(j.time_of_day)]}),j.start_hour!=null&&j.end_hour!=null&&(0,b.jsxs)(`span`,{className:`schedule-parsed-tag`,children:[(0,b.jsx)(f,{size:10}),` `,E(j.start_hour),` - `,E(j.end_hour)]}),j.days_of_week&&(0,b.jsx)(`span`,{className:`schedule-parsed-tag`,children:D(j.days_of_week)})]})]}):null}),(0,b.jsxs)(`div`,{className:`schedule-field`,children:[(0,b.jsx)(`label`,{className:`schedule-field-label`,htmlFor:H,children:`Name`}),(0,b.jsx)(`div`,{className:`schedule-form-row`,children:(0,b.jsx)(`input`,{id:H,type:`text`,placeholder:`Schedule name (e.g. daily-summary)`,value:C,onChange:e=>w(e.target.value),className:!C.trim()&&x.trim()?`schedule-field-missing`:``})})]}),(0,b.jsxs)(`div`,{className:`schedule-field`,children:[(0,b.jsx)(`label`,{className:`schedule-field-label`,htmlFor:U,children:`Prompt`}),(0,b.jsx)(`textarea`,{id:U,className:`schedule-prompt-input ${!k.trim()&&x.trim()?`schedule-field-missing`:``}`,placeholder:`Prompt to execute on each run...`,value:k,onChange:e=>A(e.target.value)})]}),L&&(0,b.jsx)(`p`,{className:`schedule-form-error`,children:L}),(0,b.jsxs)(`div`,{className:`schedule-create-actions`,children:[(0,b.jsx)(`button`,{className:`btn-secondary`,onClick:()=>{v(!1),R(null),M(null),S(``),w(``),A(``)},children:`Cancel`}),(0,b.jsx)(`button`,{className:`btn-primary`,onClick:J,disabled:!q||F,children:F?`Creating...`:`Create Schedule`})]})]}):(0,b.jsxs)(`button`,{className:`btn-primary`,onClick:()=>v(!0),children:[(0,b.jsx)(c,{size:14}),` New schedule`]})}),(0,b.jsxs)(`section`,{className:`schedule-section`,children:[(0,b.jsx)(`h4`,{children:`Active schedules`}),n?(0,b.jsx)(`p`,{className:`schedule-empty`,children:`Loading schedules...`}):r?(0,b.jsx)(`p`,{className:`schedule-empty`,children:r}):t.length===0?(0,b.jsx)(`p`,{className:`schedule-empty`,children:`No scheduled tasks yet. Create one to get started.`}):(0,b.jsx)(`div`,{className:`schedule-list`,children:t.map(e=>(0,b.jsx)(O,{schedule:e},e.id))})]})]})]})})}export{k as ScheduleManager};