@amd-gaia/agent-ui 0.26.0-rc.13 → 0.26.0-rc.16

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.
@@ -1 +1 @@
1
- import{q as e}from"./useT-B4DSIvt0.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};
1
+ import{q as e}from"./useT-C5NQKA1s.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
@@ -12,11 +12,11 @@
12
12
  <meta name="apple-mobile-web-app-capable" content="yes" />
13
13
  <meta name="apple-mobile-web-app-title" content="GAIA" />
14
14
  <title>GAIA Agent UI</title>
15
- <script type="module" crossorigin src="./assets/index-BGIyiDas.js"></script>
15
+ <script type="module" crossorigin src="./assets/index-C9wJG-Eh.js"></script>
16
16
  <link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-XKyaHtl9.js">
17
- <link rel="modulepreload" crossorigin href="./assets/useT-B4DSIvt0.js">
18
- <link rel="modulepreload" crossorigin href="./assets/api-Dz-kUmy_.js">
19
- <link rel="stylesheet" crossorigin href="./assets/index-JCP-qf3I.css">
17
+ <link rel="modulepreload" crossorigin href="./assets/useT-C5NQKA1s.js">
18
+ <link rel="modulepreload" crossorigin href="./assets/api--I_306zc.js">
19
+ <link rel="stylesheet" crossorigin href="./assets/index-CvE1q_in.css">
20
20
  </head>
21
21
  <body>
22
22
  <div id="root"></div>
package/dist/sw.js CHANGED
@@ -9,7 +9,7 @@
9
9
  // never sees a stale UI or stale data.
10
10
 
11
11
  const CACHE_PREFIX = 'gaia-assets-';
12
- const CACHE_NAME = CACHE_PREFIX + '0.26.0rc13-c141887ac32ba4ad';
12
+ const CACHE_NAME = CACHE_PREFIX + '0.26.0rc16-a33528253d4bb622';
13
13
  const ASSETS_PATH = new URL('assets/', self.registration.scope).pathname;
14
14
 
15
15
  self.addEventListener('install', () => {
package/main.cjs CHANGED
@@ -86,6 +86,7 @@ const _inSafeMode = _crashCount >= SAFE_MODE_THRESHOLD;
86
86
  // Services (loaded after app.whenReady)
87
87
  const TrayManager = require("./services/tray-manager.cjs");
88
88
  const { probeTrayHost } = require("./services/tray-host.cjs");
89
+ const { installAppImageLauncher } = require("./services/appimage-launcher.cjs");
89
90
  const { appIconPath, appUserModelId } = require("./services/app-icon.cjs");
90
91
  const {
91
92
  attachWindowGuards,
@@ -1229,6 +1230,15 @@ app.whenReady().then(async () => {
1229
1230
  // The window, and the tray that keeps a closed one reachable, come before
1230
1231
  // anything that can take time, so an install runs in plain sight.
1231
1232
  titleDownloadSaveDialogs();
1233
+ // Before the window: the desktop ties a window to its launcher when it appears.
1234
+ if (app.isPackaged) {
1235
+ try {
1236
+ const launcher = installAppImageLauncher();
1237
+ if (launcher.status === "written") console.log(`[main] Wrote the AppImage launcher ${launcher.entry}`);
1238
+ } catch (err) {
1239
+ console.error(`[main] ${err.message}`);
1240
+ }
1241
+ }
1232
1242
  createWindow();
1233
1243
  initializeServices();
1234
1244
  engineInstall = createEngineInstall({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amd-gaia/agent-ui",
3
- "version": "0.26.0-rc.13",
3
+ "version": "0.26.0-rc.16",
4
4
  "type": "module",
5
5
  "productName": "GAIA Agent UI",
6
6
  "desktopName": "gaia-desktop.desktop",
@@ -0,0 +1,116 @@
1
+ // Copyright(C) 2026 Advanced Micro Devices, Inc. All rights reserved.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * A launcher for GAIA run as an AppImage.
6
+ *
7
+ * An AppImage installs nothing, so the desktop has no `.desktop` file to tie
8
+ * GAIA's window to: GNOME lists it without a name or icon, and the app grid
9
+ * has nothing to reopen it from. The `.deb` installs that file; here GAIA
10
+ * writes its own into the user's applications folder on launch.
11
+ */
12
+
13
+ const fs = require("fs");
14
+ const os = require("os");
15
+ const path = require("path");
16
+ const { notificationIconPath } = require("./app-icon.cjs");
17
+
18
+ // The window's app_id / WM_CLASS comes from the same package.json field.
19
+ const DESKTOP_FILE = require("../package.json").desktopName;
20
+ const APP_ID = DESKTOP_FILE.replace(/\.desktop$/, "");
21
+ /** Marks an entry as GAIA's own, so one the user or a tool wrote is never replaced. */
22
+ const OWNED = "X-GAIA-AppImage=true";
23
+
24
+ /**
25
+ * A path as one quoted Exec= argument: the Desktop Entry spec escapes " ` $ \
26
+ * inside the quotes, then escapes every backslash again as a string value.
27
+ */
28
+ function desktopExecArg(file) {
29
+ // "%" starts a field code (%f, %u…) anywhere in Exec=, so it is doubled.
30
+ const quoted = `"${file.replace(/%/g, "%%").replace(/["`$\\]/g, (c) => `\\${c}`)}"`;
31
+ return quoted.replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
32
+ }
33
+
34
+ /** A path as a plain string value (Icon=, TryExec=): "\" and a newline are escaped. */
35
+ function desktopString(file) {
36
+ return file.replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
37
+ }
38
+
39
+ /** Whether `dir` is `root` or inside it. */
40
+ function isInside(dir, root) {
41
+ const rel = path.relative(path.resolve(root), path.resolve(dir));
42
+ return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
43
+ }
44
+
45
+ function launcherPaths(env, home) {
46
+ const dataHome = env.XDG_DATA_HOME || path.join(home, ".local", "share");
47
+ return {
48
+ entry: path.join(dataHome, "applications", DESKTOP_FILE),
49
+ icon: path.join(dataHome, "icons", "hicolor", "256x256", "apps", `${APP_ID}.png`),
50
+ };
51
+ }
52
+
53
+ function entryText(appImage, icon) {
54
+ return [
55
+ "[Desktop Entry]",
56
+ "Type=Application",
57
+ "Name=GAIA",
58
+ "Comment=Privacy-first agentic AI interface for AMD Ryzen AI",
59
+ `Exec=${desktopExecArg(appImage)}`,
60
+ // Hides the entry once the AppImage is deleted or moved.
61
+ `TryExec=${desktopString(appImage)}`,
62
+ `Icon=${desktopString(icon)}`,
63
+ "Terminal=false",
64
+ "Categories=Development;Utility;",
65
+ `StartupWMClass=${APP_ID}`,
66
+ OWNED,
67
+ "",
68
+ ].join("\n");
69
+ }
70
+
71
+ /**
72
+ * Write or refresh the launcher for this AppImage.
73
+ *
74
+ * @param {{platform?: string, env?: NodeJS.ProcessEnv, home?: string, iconSource?: string}} [deps]
75
+ * @returns {{status: "not-appimage" | "package-installed" | "kept-existing" | "current" | "written", entry?: string}}
76
+ * @throws {Error} When the launcher or its icon can't be written.
77
+ */
78
+ function installAppImageLauncher({
79
+ platform = process.platform,
80
+ env = process.env,
81
+ home = os.homedir(),
82
+ iconSource = notificationIconPath(),
83
+ } = {}) {
84
+ const appImage = env.APPIMAGE;
85
+ if (platform !== "linux" || !appImage) return { status: "not-appimage" };
86
+
87
+ // An AppImage's own mount can be on XDG_DATA_DIRS; its bundled entry isn't an install.
88
+ const systemDirs = (env.XDG_DATA_DIRS || "/usr/local/share:/usr/share")
89
+ .split(":")
90
+ .filter((dir) => dir && !(env.APPDIR && isInside(dir, env.APPDIR)));
91
+ const packaged = systemDirs.find((dir) => fs.existsSync(path.join(dir, "applications", DESKTOP_FILE)));
92
+ if (packaged) return { status: "package-installed", entry: path.join(packaged, "applications", DESKTOP_FILE) };
93
+
94
+ const { entry, icon } = launcherPaths(env, home);
95
+ const wanted = entryText(appImage, icon);
96
+ try {
97
+ const current = fs.existsSync(entry) ? fs.readFileSync(entry, "utf8") : null;
98
+ if (current !== null && !current.split("\n").includes(OWNED)) return { status: "kept-existing", entry };
99
+ const image = fs.readFileSync(iconSource);
100
+ const iconCurrent = fs.existsSync(icon) && fs.readFileSync(icon).equals(image);
101
+ if (current === wanted && iconCurrent) return { status: "current", entry };
102
+ fs.mkdirSync(path.dirname(icon), { recursive: true });
103
+ fs.writeFileSync(icon, image);
104
+ fs.mkdirSync(path.dirname(entry), { recursive: true });
105
+ fs.writeFileSync(entry, wanted, "utf8");
106
+ } catch (err) {
107
+ throw new Error(
108
+ `Could not write GAIA's launcher ${entry}: ${err.message}. ` +
109
+ "GAIA still runs, but the desktop shows its window without a name or icon. " +
110
+ "Check that the folder is writable."
111
+ );
112
+ }
113
+ return { status: "written", entry };
114
+ }
115
+
116
+ module.exports = { installAppImageLauncher, desktopExecArg, launcherPaths, APP_ID, DESKTOP_FILE, OWNED };
@@ -25,6 +25,7 @@ const os = require("os");
25
25
  const { drawStateIcon, drawOverlayIcon, STATES } = require("./tray-icons.cjs");
26
26
  const { validateActivity, deriveTrayView, buildMenuTemplate } = require("./tray-state.cjs");
27
27
  const { backendJson, fetchWorkInProgress } = require("./quit-guard.cjs");
28
+ const { desktopExecArg } = require("./appimage-launcher.cjs");
28
29
 
29
30
  /** Why the model can't be freed right now, from the backend's work list; null when it can. */
30
31
  function describeBusy(work) {
@@ -140,16 +141,6 @@ function validateAgents(agents, where) {
140
141
  return out;
141
142
  }
142
143
 
143
- /**
144
- * A path as one quoted Exec= argument: the Desktop Entry spec escapes " ` $ \
145
- * inside the quotes, then escapes every backslash again as a string value.
146
- */
147
- function desktopExecArg(file) {
148
- // "%" starts a field code (%f, %u…) anywhere in Exec=, so it is doubled.
149
- const quoted = `"${file.replace(/%/g, "%%").replace(/["`$\\]/g, (c) => `\\${c}`)}"`;
150
- return quoted.replace(/\\/g, "\\\\");
151
- }
152
-
153
144
  // ── TrayManager ──────────────────────────────────────────────────────────
154
145
 
155
146
  class TrayManager {
@@ -340,7 +331,7 @@ class TrayManager {
340
331
 
341
332
  /**
342
333
  * What closing the window does. With no tray to find a hidden window in,
343
- * GAIA minimizes instead, so the dock still shows it and offers Quit.
334
+ * GAIA minimizes instead, so the dock or overview still shows it and offers Quit.
344
335
  * @returns {"hide" | "minimize" | "quit"}
345
336
  */
346
337
  get closeAction() {
@@ -416,8 +407,8 @@ class TrayManager {
416
407
  const loaded = "Closing the window keeps your model loaded, so the next chat starts quickly.";
417
408
  if (this.closeAction === "minimize") {
418
409
  return {
419
- message: "GAIA is still running in the dock.",
420
- detail: `${loaded} Click GAIA in the dock to bring it back. To stop it, right-click GAIA there and choose Quit.`,
410
+ message: "GAIA is still running, minimized.",
411
+ detail: `${loaded} Click GAIA in your dock or the Activities overview to bring it back. To stop it, right-click GAIA there and choose Quit.`,
421
412
  };
422
413
  }
423
414
  const where = process.platform === "darwin" ? "menu bar" : "tray";
Binary file
Binary file
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{I as t,J as n,P as r,a as i,c as a,f as o,i as s,k as c,l,q as u,r as d,t as f,u as p}from"./useT-B4DSIvt0.js";import{n as m,t as h}from"./zap-D7Qg7Qny.js";import{xt as g}from"./api-Dz-kUmy_.js";import{Lt as _,Z as v,bt as y,ft as b,n as x,ot as S,st as C,u as w,vt as T}from"./index-BGIyiDas.js";var E={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`}]]};E.node;var D=u(E),O=e(n(),1),k=8e3,A={active:`schedules.status.active`,paused:`schedules.status.paused`,cancelled:`schedules.status.cancelled`};function j(e,t,n,r){if(!e)return t(`schedules.time.never`);let i=new Date(e),a=(n||new Date).getTime()-i.getTime(),o=Math.floor(a/1e3);if(o<0){let e=Math.abs(o);if(e<60)return t(`schedules.time.inSeconds`,{n:e});let n=Math.floor(e/60);if(n<60)return t(`schedules.time.inMinutes`,{n});let r=Math.floor(n/60);return r<24?t(`schedules.time.inHours`,{n:r}):t(`schedules.time.inDays`,{n:Math.floor(r/24)})}if(o<60)return t(`time.justNow`);let s=Math.floor(o/60);if(s<60)return t(`time.minutesAgo`,{n:s});let c=Math.floor(s/60);return c<24?t(`time.hoursAgo`,{n:c}):i.toLocaleDateString(r,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function M(e,t,n=d.bare,r){if(!e)return n(`schedules.time.never`);let i=j(e,n,t,r),a=new Date(e);return a.getTime()<=(t||new Date).getTime()?i:n(`schedules.time.clockIn`,{clock:a.toLocaleString(r,{weekday:`short`,hour:`numeric`,minute:`2-digit`}),relative:i})}function N(e){if(!e)return!1;let t=new Date(e).getTime()-Date.now();return t>0&&t<6e4}function P(e,t,n=0){let r=new Date(2e3,0,1,t,n);return new Intl.DateTimeFormat(f(e),{hour:`numeric`,minute:`2-digit`}).format(r)}function F(e,t){let[n,r]=e.split(`:`).map(Number);return P(t,n,r)}function I(e,t,n){let r=`${e}.${new Intl.PluralRules(n.locale).select(t)}`;return c(r)?r:null}var L=e=>e.length===5&&e.every(e=>e<5),R=e=>e.length===2&&e.includes(5)&&e.includes(6);function z(e,t,n){if(L(e))return n(`schedules.desc.days.weekdays`);if(R(e))return n(`schedules.desc.days.weekends`);if(e.length===7)return n(`schedules.desc.days.every`);let r=I(`schedules.desc.dayList`,e.length,t);return r?n(r,{days:e.map(e=>n(`schedules.dayName.${e}`)).join(n(`schedules.desc.dayJoin`))}):null}function B(e,t,n,r){let{kind:i,count:a,unit:o,days:s,time:c,start_hour:l,end_hour:u}=e,d=e=>c?n(`schedules.desc.at`,{when:e,time:F(c,r)}):e;if(i===`every`||i===`window`){let e=a&&o?I(`schedules.span.${o}`,a,t):null,c=s?z(s,t,n):void 0;if(!e||c===null)return null;let d=n(e,{n:a});if(i===`every`)return c?n(`schedules.desc.everyOn`,{span:d,days:c}):n(`schedules.desc.every`,{span:d});if(l==null||u==null)return null;let f=n(`schedules.hours`,{start:P(r,l),end:P(r,u)});return c?n(`schedules.desc.windowOn`,{span:d,hours:f,days:c}):n(`schedules.desc.window`,{span:d,hours:f})}if(i===`daily`)return c?d(n(`schedules.desc.daily`)):null;if(i!==`days`||!s?.length)return null;if(s.length===7)return d(n(`schedules.desc.daily`));if(L(s))return d(n(`schedules.desc.weekdays`));if(R(s))return d(n(`schedules.desc.weekends`));let f=z(s,t,n);return f&&d(n(`schedules.desc.onDays`,{days:f}))}function V(e,t){return!e||B(e,t,t.bare,t)===null?null:t.compose((n,r)=>B(e,t,n,s(r))??``)}function H(e,t){return e.length===5&&!e.includes(5)&&!e.includes(6)?t(`schedules.days.weekdays`):e.length===2&&e.includes(5)&&e.includes(6)?t(`schedules.days.weekends`):e.length===7?t(`schedules.days.every`):e.map(e=>t(`schedules.day.${e}`)).join(t(`schedules.days.join`))}function U({schedule:e}){let n=i(),{selectedSchedule:s,selectSchedule:c,updateScheduleStatus:u,runScheduleNow:d,deleteSchedule:g,results:v,resultsLoading:S,loadSchedules:C,loadResults:w}=x(),{setCurrentSession:T,setShowSchedules:E}=o(),P=s===e.name,F=V(e.description_parts,n),[I,L]=(0,O.useState)(!1),R=(0,O.useRef)(null),z=(0,O.useCallback)(()=>{R.current&&=(clearTimeout(R.current),null)},[]);(0,O.useEffect)(()=>z,[z]);let[B,H]=(0,O.useState)(()=>new Date),U=(0,O.useRef)(null);(0,O.useEffect)(()=>{let t=e.status===`active`&&N(e.next_run_at);return t&&!U.current?U.current=setInterval(()=>{H(new Date),e.next_run_at&&new Date(e.next_run_at).getTime()<=Date.now()&&C()},1e3):!t&&U.current&&(clearInterval(U.current),U.current=null),()=>{U.current&&=(clearInterval(U.current),null)}},[e.status,e.next_run_at,C]);let W=(0,O.useRef)(e.last_run_at);(0,O.useEffect)(()=>{P&&e.last_run_at!==W.current&&(W.current=e.last_run_at,w(e.name))},[P,e.last_run_at,e.name,w]);let G=e.last_run_at&&Date.now()-new Date(e.last_run_at).getTime()<5e3,K=(0,O.useCallback)(n=>{n.stopPropagation();let r=e.status===`active`?`paused`:`active`;t.ui.info(`Schedule "${e.name}": ${e.status} -> ${r}`),u(e.name,r)},[e.name,e.status,u]),q=(0,O.useCallback)(n=>{n.stopPropagation(),t.ui.info(`Schedule "${e.name}": run now`),d(e.name)},[e.name,d]),J=(0,O.useCallback)(n=>{n.stopPropagation(),z(),I?(t.ui.info(`Deleting schedule "${e.name}"`),g(e.name)):(L(!0),R.current=setTimeout(()=>{R.current=null,L(!1)},k))},[e.name,I,g,z]),Y=(0,O.useCallback)(n=>{n.stopPropagation(),e.session_id&&(t.ui.info(`Opening chat session for schedule "${e.name}"`),T(e.session_id),E(!1))},[e.session_id,e.name,T,E]);return p(`div`,{className:`schedule-card ${P?`selected`:``} ${G?`just-ran`:``}`,onClick:()=>c(P?null:e.name),children:[p(`div`,{className:`schedule-card-header`,children:[l(`span`,{className:`schedule-card-name`,dir:`auto`,children:e.name}),l(`span`,{className:`schedule-card-status ${e.status}`,children:n(A[e.status])})]}),l(`div`,{className:`schedule-card-prompt`,dir:`auto`,children:e.prompt}),p(`div`,{className:`schedule-card-meta`,children:[p(`span`,{title:r(F??e.description),children:[l(_,{size:11}),` `,F??l(`bdi`,{children:e.description})]}),l(`span`,{children:n(`schedules.card.runs`,{n:e.run_count})}),e.error_count>0&&l(`span`,{children:n(`schedules.card.errors`,{n:e.error_count})}),l(`span`,{children:n.compose(t=>t(`schedules.card.last`,{when:j(e.last_run_at,t,void 0,f(n))}))}),l(`span`,{children:n.compose(t=>t(`schedules.card.next`,{when:M(e.next_run_at,B,t,f(n))}))})]}),e.last_error&&l(`div`,{className:`schedule-card-error`,children:n(`schedules.card.lastFailed`,{error:e.last_error})}),p(`div`,{className:`schedule-card-actions`,children:[e.session_id&&p(`button`,{className:`btn-sm chat`,onClick:Y,title:n(`schedules.card.openChatTitle`),children:[l(m,{size:11}),` `,n(`schedules.card.openChat`)]}),p(`button`,{className:`btn-sm`,onClick:q,disabled:e.running,title:n(`schedules.card.runNowTitle`),children:[l(h,{size:11}),` `,n(e.running?`schedules.card.running`:`schedules.card.runNow`)]}),l(`button`,{className:`btn-sm`,onClick:K,title:n(e.status===`active`?`schedules.card.pause`:`schedules.card.resume`),children:e.status===`active`?p(a.Fragment,{children:[l(y,{size:11}),` `,n(`schedules.card.pause`)]}):p(a.Fragment,{children:[l(D,{size:11}),` `,n(`schedules.card.resume`)]})}),p(`button`,{className:`btn-sm danger`,onClick:J,title:n(`schedules.card.delete`),children:[l(b,{size:11}),` `,n(I?`schedules.card.confirmDelete`:`schedules.card.delete`)]})]}),P&&p(`div`,{className:`schedule-results`,children:[l(`h4`,{children:n(`schedules.history`)}),S?l(`p`,{className:`schedule-results-empty`,children:n(`schedules.historyLoading`)}):v.length===0?l(`p`,{className:`schedule-results-empty`,children:n(`schedules.historyEmpty`)}):l(`div`,{className:`schedule-results-list`,children:v.map(e=>p(`div`,{className:`schedule-result-item`,children:[l(`div`,{className:`schedule-result-time`,children:n.compose(t=>j(e.executed_at,t,void 0,f(n)))}),e.error?l(`div`,{className:`schedule-result-content schedule-result-error`,children:l(`bdi`,{children:e.error})}):l(`div`,{className:`schedule-result-content`,children:e.result?l(`bdi`,{children:e.result}):n(`schedules.noOutput`)})]},e.id))})]})]})}function W(){let e=i(),{setShowSchedules:n}=o(),{schedules:r,loading:c,error:u,actionError:d,loadSchedules:m,createSchedule:h,dismissActionError:y}=x(),b=(0,O.useCallback)(()=>n(!1),[n]);S(!0,b);let E=(0,O.useRef)(null);v(E,!0),w(E,!0);let[D,k]=(0,O.useState)(!1),[A,j]=(0,O.useState)(``),[M,N]=(0,O.useState)(``),[I,L]=(0,O.useState)(``),[R,z]=(0,O.useState)(null),[B,W]=(0,O.useState)(!1),[G,K]=(0,O.useState)(!1),[q,J]=(0,O.useState)(null),Y=(0,O.useId)(),X=`${Y}-when`,ee=`${Y}-when-error`,te=`${Y}-name`,ne=`${Y}-prompt`,re=!B&&R!==null&&!R.valid,Z=(0,O.useRef)(null);(0,O.useEffect)(()=>{if(!A.trim())z(null);else return Z.current&&clearTimeout(Z.current),Z.current=window.setTimeout(async()=>{W(!0);try{let e=await g(A);z(e)}catch{z(null)}finally{W(!1)}},400),()=>{Z.current&&clearTimeout(Z.current)}},[A]);let Q=(0,O.useRef)(null);(0,O.useEffect)(()=>(t.ui.info(`Schedule Manager opened`),m(),Q.current=window.setInterval(()=>m(),5e3),()=>{Q.current&&clearInterval(Q.current),y()}),[m,y]);let $=A.trim()&&M.trim()&&I.trim()&&(R===null||R.valid),ie=(0,O.useCallback)(async()=>{if($){K(!0),J(null);try{await h(M.trim(),A.trim(),I.trim()),j(``),N(``),L(``),z(null),k(!1),t.ui.info(`Schedule "${M}" created`)}catch(t){J(t instanceof Error?t.message:e(`schedules.createFailed`))}finally{K(!1)}}},[$,M,A,I,h,e]);return l(`div`,{ref:E,className:`modal-overlay`,onClick:()=>n(!1),role:`dialog`,"aria-modal":`true`,"aria-label":e(`schedules.title`),children:p(`div`,{className:`modal-panel schedule-modal`,onClick:e=>e.stopPropagation(),children:[p(`div`,{className:`modal-header`,children:[l(`h3`,{children:e(`schedules.title`)}),l(`button`,{className:`btn-icon`,onClick:()=>n(!1),"aria-label":e(`schedules.close`),children:l(C,{size:18})})]}),p(`div`,{className:`modal-body`,children:[l(`section`,{className:`schedule-section`,children:D?p(`div`,{className:`schedule-create-form`,children:[p(`div`,{className:`schedule-field`,children:[l(`label`,{className:`schedule-field-label`,htmlFor:X,children:e(`schedules.when`)}),l(`textarea`,{id:X,className:`schedule-nl-input`,placeholder:e.bare(`schedules.whenPlaceholder`),value:A,onChange:e=>j(e.target.value),"aria-invalid":re,"aria-describedby":re?ee:void 0,autoFocus:!0,rows:2})]}),(R||B)&&l(`div`,{className:`schedule-parsed-preview ${R?.valid?`valid`:`invalid`}`,"aria-live":`polite`,children:B?l(`span`,{className:`schedule-parsed-loading`,children:e(`schedules.parsing`)}):R?p(a.Fragment,{children:[R.valid?l(`div`,{className:`schedule-parsed-description`,children:V(R.description_parts,e)??l(`bdi`,{children:R.description})}):p(`div`,{id:ee,children:[l(`div`,{className:`schedule-parsed-description`,children:e(`schedules.notUnderstood`)}),l(`div`,{className:`schedule-parsed-hint`,children:l(`bdi`,{children:R.description})})]}),R.valid&&R.next_run_at&&l(`div`,{className:`schedule-parsed-next`,children:e(`schedules.nextRun`,{when:new Date(R.next_run_at).toLocaleString(f(e))})}),R.valid&&p(`div`,{className:`schedule-parsed-details`,children:[R.time_of_day&&p(`span`,{className:`schedule-parsed-tag`,children:[l(_,{size:10}),` `,F(R.time_of_day,e)]}),R.start_hour!=null&&R.end_hour!=null&&p(`span`,{className:`schedule-parsed-tag`,children:[l(_,{size:10}),` `,e.compose((e,t)=>e(`schedules.hours`,{start:P(s(t),R.start_hour),end:P(s(t),R.end_hour)}))]}),R.days_of_week&&l(`span`,{className:`schedule-parsed-tag`,children:e.compose(e=>H(R.days_of_week,e))})]})]}):null}),p(`div`,{className:`schedule-field`,children:[l(`label`,{className:`schedule-field-label`,htmlFor:te,children:e(`schedules.name`)}),l(`div`,{className:`schedule-form-row`,children:l(`input`,{id:te,type:`text`,placeholder:e(`schedules.namePlaceholder`),value:M,onChange:e=>N(e.target.value),className:!M.trim()&&A.trim()?`schedule-field-missing`:``})})]}),p(`div`,{className:`schedule-field`,children:[l(`label`,{className:`schedule-field-label`,htmlFor:ne,children:e(`schedules.prompt`)}),l(`textarea`,{id:ne,className:`schedule-prompt-input ${!I.trim()&&A.trim()?`schedule-field-missing`:``}`,placeholder:e(`schedules.promptPlaceholder`),value:I,onChange:e=>L(e.target.value)})]}),q&&l(`p`,{className:`schedule-form-error`,children:l(`bdi`,{children:q})}),p(`div`,{className:`schedule-create-actions`,children:[l(`button`,{className:`btn-secondary`,onClick:()=>{k(!1),J(null),z(null),j(``),N(``),L(``)},children:e(`schedules.cancel`)}),l(`button`,{className:`btn-primary`,onClick:ie,disabled:!$||G,children:e(G?`schedules.creating`:`schedules.create`)})]})]}):p(`button`,{className:`btn-primary`,onClick:()=>k(!0),children:[l(T,{size:14}),` `,e(`schedules.new`)]})}),p(`section`,{className:`schedule-section`,children:[l(`h4`,{children:e(`schedules.list`)}),d&&p(`div`,{className:`schedule-action-error`,role:`alert`,children:[l(`span`,{children:l(`bdi`,{children:d})}),l(`button`,{className:`btn-icon`,onClick:y,"aria-label":e(`schedules.dismissError`),children:l(C,{size:14})})]}),c?l(`p`,{className:`schedule-empty`,children:e(`schedules.loading`)}):u?l(`p`,{className:`schedule-empty`,children:e(`schedules.loadFailed`)}):r.length===0?l(`p`,{className:`schedule-empty`,children:e(`schedules.empty`)}):l(`div`,{className:`schedule-list`,children:r.map(e=>l(U,{schedule:e},e.id))})]})]})]})})}export{W as ScheduleManager};