tide-commander 1.40.2 → 1.40.4

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.
Files changed (58) hide show
  1. package/dist/assets/{BossLogsModal-CaDrNfm1.js → BossLogsModal-CehuxNwV.js} +1 -1
  2. package/dist/assets/{BossSpawnModal-DLJInoVf.js → BossSpawnModal-Cohl0WaH.js} +1 -1
  3. package/dist/assets/{ControlsModal-Cnnhwfr_.js → ControlsModal-CAVkg9mM.js} +1 -1
  4. package/dist/assets/{DockerLogsModal-D4CbWK3-.js → DockerLogsModal-BXv9Hzg-.js} +1 -1
  5. package/dist/assets/{EmbeddedEditor-36YBGNE2.js → EmbeddedEditor-CTlTVKdD.js} +1 -1
  6. package/dist/assets/{GmailOAuthSetup-DI5j7wkF.js → GmailOAuthSetup-B1zQWbRR.js} +1 -1
  7. package/dist/assets/{GoogleOAuthSetup-Bsj02mND.js → GoogleOAuthSetup-CmayoZ-D.js} +1 -1
  8. package/dist/assets/{IframeModal-BJ4oeDBn.js → IframeModal-DlS7y7PK.js} +1 -1
  9. package/dist/assets/{IntegrationsPanel-DLmIJEUy.js → IntegrationsPanel-BPKoNwZm.js} +2 -2
  10. package/dist/assets/{LogViewerModal-D7CXMmZf.js → LogViewerModal-Bx9IDiFM.js} +1 -1
  11. package/dist/assets/{MonitoringModal-PnEKvezF.js → MonitoringModal-DzqEa0fQ.js} +1 -1
  12. package/dist/assets/{PM2LogsModal-EB_Au0iK.js → PM2LogsModal-DZXPRV5-.js} +1 -1
  13. package/dist/assets/{RestoreArchivedAreaModal-C-X90Qxe.js → RestoreArchivedAreaModal-BajWqtWn.js} +1 -1
  14. package/dist/assets/{SaveSnapshotModal-D6XAjL2T.js → SaveSnapshotModal-LqaLezB-.js} +1 -1
  15. package/dist/assets/{Scene2DCanvas-DlVguRVM.js → Scene2DCanvas-DWDmyh_y.js} +1 -1
  16. package/dist/assets/{SceneManager-OOaJ_z8v.js → SceneManager-BgkqWsDb.js} +1 -1
  17. package/dist/assets/{SkillsPanel-D5wo2MHh.js → SkillsPanel-CO-Zt0Tq.js} +1 -1
  18. package/dist/assets/{SnapshotManager-BLjpctX_.js → SnapshotManager-D4Uzw6Tp.js} +1 -1
  19. package/dist/assets/{SpawnModal-DQ4uUm1y.js → SpawnModal-BdCgTKpM.js} +1 -1
  20. package/dist/assets/{SubordinateAssignmentModal-BDUDt6WC.js → SubordinateAssignmentModal-BoaofULj.js} +1 -1
  21. package/dist/assets/{SupervisorPanel-BZaBI9BA.js → SupervisorPanel-D8Cp77my.js} +1 -1
  22. package/dist/assets/{TriggerManagerPanel-DuBiclsE.js → TriggerManagerPanel-CFf3Tud5.js} +1 -1
  23. package/dist/assets/{WorkflowEditorPanel-D49yDqth.js → WorkflowEditorPanel-EtzhBZWw.js} +1 -1
  24. package/dist/assets/{index-DZ3f9mNd.js → index-2YWd58Wh.js} +1 -1
  25. package/dist/assets/{index-DJdXbeWz.js → index-BKRKKMPQ.js} +3 -3
  26. package/dist/assets/{index-BwkNteiZ.js → index-BgTRovwT.js} +1 -1
  27. package/dist/assets/{index-mQmnkGdF.js → index-BiJ_hIit.js} +1 -1
  28. package/dist/assets/{index-Bxjd0N-j.js → index-CDAtstMx.js} +1 -1
  29. package/dist/assets/{index-BxbFh16W.js → index-DBpmD8r7.js} +2 -2
  30. package/dist/assets/{index-BiGvhrCO.js → index-DByGRjfY.js} +1 -1
  31. package/dist/assets/index-VO6fNr63.js +1 -0
  32. package/dist/assets/main-BFSqr5mR.css +1 -0
  33. package/dist/assets/main-BSyGZK2z.js +152 -0
  34. package/dist/assets/{web-DAqM9uoZ.js → web-1BwWjkKM.js} +1 -1
  35. package/dist/assets/{web-DQ10iSod.js → web-BXQj42md.js} +1 -1
  36. package/dist/index.html +2 -2
  37. package/dist/locales/en/config.json +1 -0
  38. package/dist/src/packages/server/claude/backend.js +9 -0
  39. package/dist/src/packages/server/claude/runner/process-lifecycle.js +79 -7
  40. package/dist/src/packages/server/claude/runner/recovery-store.js +73 -10
  41. package/dist/src/packages/server/claude/runner/restart-policy.js +9 -0
  42. package/dist/src/packages/server/claude/runner/stdout-pipeline.js +28 -4
  43. package/dist/src/packages/server/claude/runner/tmux-helper.js +264 -0
  44. package/dist/src/packages/server/claude/runner/watchdog.js +27 -0
  45. package/dist/src/packages/server/claude/runner.js +84 -9
  46. package/dist/src/packages/server/cli.js +17 -1
  47. package/dist/src/packages/server/data/builtin-skills/boss-instructions.js +2 -2
  48. package/dist/src/packages/server/data/index.js +6 -0
  49. package/dist/src/packages/server/opencode/backend.js +1 -0
  50. package/dist/src/packages/server/opencode/index.js +1 -0
  51. package/dist/src/packages/server/routes/agents.js +29 -1
  52. package/dist/src/packages/server/services/system-prompt-service.js +38 -0
  53. package/dist/src/packages/server/websocket/handlers/boss-response-handler.js +5 -1
  54. package/dist/src/packages/server/websocket/listeners/runtime-listeners.js +19 -1
  55. package/package.json +1 -1
  56. package/dist/assets/index-BSl18-4e.js +0 -1
  57. package/dist/assets/main-CUx2B9bn.css +0 -1
  58. package/dist/assets/main-DULfVodw.js +0 -152
@@ -1,5 +1,6 @@
1
1
  import { createLogger } from '../../utils/logger.js';
2
2
  import { isProcessRunning } from '../../data/index.js';
3
+ import { hasTmuxSession } from './tmux-helper.js';
3
4
  const log = createLogger('Runner');
4
5
  const MAX_DEATH_HISTORY = 50;
5
6
  export class RunnerWatchdog {
@@ -18,6 +19,32 @@ export class RunnerWatchdog {
18
19
  log.log(`🐕 [WATCHDOG] Checking ${activeCount} process(es)...`);
19
20
  }
20
21
  for (const [agentId, activeProcess] of this.activeProcesses) {
22
+ // tmux mode: the launcher PID exits immediately — check the tmux session instead
23
+ if (activeProcess.tmuxSession) {
24
+ if (!hasTmuxSession(agentId)) {
25
+ log.error(`🐕 [WATCHDOG] Agent ${agentId}: tmux session ${activeProcess.tmuxSession} no longer exists!`);
26
+ activeProcess.tmuxTailer?.stop();
27
+ this.recordDeath({
28
+ agentId,
29
+ pid: activeProcess.process.pid ?? 0,
30
+ exitCode: null,
31
+ signal: null,
32
+ runtime: Date.now() - activeProcess.startTime,
33
+ wasTracked: true,
34
+ timestamp: Date.now(),
35
+ stderr: this.lastStderr.get(agentId),
36
+ });
37
+ this.activeProcesses.delete(agentId);
38
+ this.lastStderr.delete(agentId);
39
+ this.bus.emit({
40
+ type: 'runner.watchdog_missing_process',
41
+ agentId,
42
+ pid: activeProcess.process.pid ?? 0,
43
+ activeProcess,
44
+ });
45
+ }
46
+ continue;
47
+ }
21
48
  const pid = activeProcess.process.pid;
22
49
  if (!pid)
23
50
  continue;
@@ -5,6 +5,8 @@
5
5
  import { ClaudeBackend } from './backend.js';
6
6
  import { createLogger } from '../utils/logger.js';
7
7
  import { isProcessRunning } from '../data/index.js';
8
+ import { sendToTmux, hasTmuxSession, tmuxSessionName, getTmuxPanePid } from './runner/tmux-helper.js';
9
+ import { spawn } from 'child_process';
8
10
  import * as agentService from '../services/agent-service.js';
9
11
  import { RunnerInternalEventBus } from './runner/internal-events.js';
10
12
  import { RunnerStdoutPipeline } from './runner/stdout-pipeline.js';
@@ -45,6 +47,9 @@ export class ClaudeRunner {
45
47
  backend: this.backend,
46
48
  activeProcesses: this.activeProcesses,
47
49
  run: (request) => this.run(request),
50
+ reconnectTmux: (agentId, logFile, offset, savedProcess) => {
51
+ this.reconnectToTmuxSession(agentId, logFile, offset, savedProcess);
52
+ },
48
53
  });
49
54
  this.lifecycle = new RunnerProcessLifecycle({
50
55
  backend: this.backend,
@@ -217,15 +222,26 @@ export class ClaudeRunner {
217
222
  }
218
223
  getActiveProcessesState() {
219
224
  const now = Date.now();
220
- return Array.from(this.activeProcesses.entries()).map(([agentId, proc]) => ({
221
- agentId,
222
- pid: proc.process.pid,
223
- runtimeSec: (now - proc.startTime) / 1000,
224
- lastActivitySec: proc.lastActivityTime ? (now - proc.lastActivityTime) / 1000 : -1,
225
- hasError: !!proc.lastError,
226
- stdinWritable: !!(proc.process.stdin && proc.process.stdin.writable),
227
- turnState: proc.turnState || 'unknown',
228
- }));
225
+ return Array.from(this.activeProcesses.entries()).map(([agentId, proc]) => {
226
+ // For tmux processes, the launcher PID exits quickly — resolve the real
227
+ // PID from the tmux pane so witr/debug tools can find the process.
228
+ let pid = proc.process.pid;
229
+ if (proc.tmuxSession) {
230
+ const panePid = getTmuxPanePid(agentId);
231
+ if (panePid) {
232
+ pid = panePid;
233
+ }
234
+ }
235
+ return {
236
+ agentId,
237
+ pid,
238
+ runtimeSec: (now - proc.startTime) / 1000,
239
+ lastActivitySec: proc.lastActivityTime ? (now - proc.lastActivityTime) / 1000 : -1,
240
+ hasError: !!proc.lastError,
241
+ stdinWritable: !!(proc.process.stdin && proc.process.stdin.writable),
242
+ turnState: proc.turnState || 'unknown',
243
+ };
244
+ });
229
245
  }
230
246
  logProcessDiagnostics() {
231
247
  const state = this.getActiveProcessesState();
@@ -251,6 +267,16 @@ export class ClaudeRunner {
251
267
  log.error(`❌ [SEND_MESSAGE] No active process for agent ${agentId}`);
252
268
  return false;
253
269
  }
270
+ // tmux mode: send via tmux send-keys
271
+ if (activeProcess.tmuxSession) {
272
+ const stdinInput = this.backend.formatStdinInput(message);
273
+ log.log(`📨 [SEND_MESSAGE] Agent ${agentId} (tmux mode), sending via tmux send-keys (${stdinInput.length} chars)`);
274
+ const ok = sendToTmux(agentId, stdinInput);
275
+ if (ok) {
276
+ activeProcess.turnState = 'processing';
277
+ }
278
+ return ok;
279
+ }
254
280
  const stdin = activeProcess.process.stdin;
255
281
  if (!stdin) {
256
282
  log.error(`❌ [SEND_MESSAGE] stdin is null for agent ${agentId}`);
@@ -299,6 +325,43 @@ export class ClaudeRunner {
299
325
  });
300
326
  return true;
301
327
  }
328
+ /**
329
+ * Reconnect to a live tmux session after a server restart.
330
+ * Creates a minimal ActiveProcess and starts tailing the log file from the saved offset.
331
+ */
332
+ reconnectToTmuxSession(agentId, logFile, offset, savedProcess) {
333
+ const sessionName = tmuxSessionName(agentId);
334
+ log.log(`🔄 [TMUX] Reconnecting to tmux session ${sessionName} for agent ${agentId}, log offset=${offset}`);
335
+ // Create a dummy child process (we don't own the real one — tmux does)
336
+ const dummyProcess = spawn('true', [], { stdio: 'ignore' });
337
+ dummyProcess.unref();
338
+ const activeProcess = {
339
+ agentId,
340
+ sessionId: savedProcess?.sessionId,
341
+ startTime: savedProcess?.startTime ?? Date.now(),
342
+ process: dummyProcess,
343
+ lastRequest: savedProcess?.lastRequest,
344
+ restartCount: 0,
345
+ turnState: 'waiting_for_input',
346
+ tmuxSession: sessionName,
347
+ tmuxLogFile: logFile,
348
+ isReconnected: true,
349
+ };
350
+ this.activeProcesses.set(agentId, activeProcess);
351
+ // Resume tailing the log file from where we left off
352
+ const tailer = this.stdoutPipeline.handleTmuxLog(agentId, logFile, offset);
353
+ activeProcess.tmuxTailer = tailer;
354
+ // Ensure the agent status reflects that we're connected
355
+ const agent = agentService.getAgent(agentId);
356
+ if (agent && agent.status === 'working') {
357
+ // Keep it as working — it was mid-task when the server restarted
358
+ }
359
+ else if (agent) {
360
+ // Set to idle — the tmux session is alive but waiting for input
361
+ agentService.updateAgent(agentId, { status: 'idle' });
362
+ }
363
+ log.log(`✅ [TMUX] Reconnected to tmux session ${sessionName} for agent ${agentId}`);
364
+ }
302
365
  interrupt(agentId) {
303
366
  return this.lifecycle.interrupt(agentId);
304
367
  }
@@ -324,6 +387,18 @@ export class ClaudeRunner {
324
387
  if (!activeProcess) {
325
388
  return false;
326
389
  }
390
+ // tmux mode: check if the tmux session still exists
391
+ if (activeProcess.tmuxSession) {
392
+ const alive = hasTmuxSession(agentId);
393
+ if (!alive) {
394
+ // Stop tailer if running
395
+ activeProcess.tmuxTailer?.stop();
396
+ this.activeProcesses.delete(agentId);
397
+ this.lastStderr.delete(agentId);
398
+ return false;
399
+ }
400
+ return true;
401
+ }
327
402
  const pid = activeProcess.process.pid;
328
403
  if (!pid) {
329
404
  this.activeProcesses.delete(agentId);
@@ -644,7 +644,23 @@ async function main() {
644
644
  || options.generateAuthToken === true
645
645
  || options.foreground === true;
646
646
  if (existingPid && isRunning(existingPid)) {
647
- if (hasStartupOverrides) {
647
+ if (runInForeground) {
648
+ // In foreground mode (PM2 managed), the process manager handles lifecycle.
649
+ // The old process is already being killed by PM2 — just wait for it to exit
650
+ // and clear the stale PID file instead of trying to send another SIGTERM.
651
+ const stopped = await waitForProcessExit(existingPid);
652
+ if (!stopped) {
653
+ // Force kill as last resort — PM2's SIGTERM may not have been enough
654
+ try {
655
+ process.kill(existingPid, 'SIGKILL');
656
+ }
657
+ catch { }
658
+ await waitForProcessExit(existingPid, 3000);
659
+ }
660
+ clearPidFile();
661
+ clearServerMeta();
662
+ }
663
+ else if (hasStartupOverrides) {
648
664
  try {
649
665
  process.kill(existingPid, 'SIGTERM');
650
666
  }
@@ -272,7 +272,7 @@ When the user asks to **plan**, **create a work plan**, or requests something co
272
272
  {
273
273
  "id": "task-1",
274
274
  "description": "<What needs to be done>",
275
- "suggestedClass": "scout|builder|debugger|architect|warrior|support",
275
+ "suggestedClass": "<any valid agent class slug>",
276
276
  "assignToAgent": "<agent id>",
277
277
  "assignToAgentName": "<agent name>",
278
278
  "priority": "high|medium|low",
@@ -468,5 +468,5 @@ You can ONLY spawn new agents when the user EXPLICITLY requests it.
468
468
  [{"name": "<Agent Name>", "class": "<agent class>", "cwd": "<optional working directory>"}]
469
469
  \\\`\\\`\\\`
470
470
 
471
- Valid classes: scout, builder, debugger, architect, warrior, support`,
471
+ Valid classes: Any registered agent class in the system, including built-in classes (scout, builder, debugger, architect, warrior, support) and custom classes. Use the class slug (e.g. "growey", "espeon", "charming"). If the user requests a specific class, use that class name exactly as they specify it.`,
472
472
  };
@@ -546,6 +546,12 @@ export function clearRunningProcesses() {
546
546
  fs.unlinkSync(RUNNING_PROCESSES_FILE);
547
547
  log.log(' Cleared running processes file');
548
548
  }
549
+ // Also remove the .bak file to prevent safeReadJsonSync from resurrecting stale data
550
+ const bakFile = RUNNING_PROCESSES_FILE + '.bak';
551
+ if (fs.existsSync(bakFile)) {
552
+ fs.unlinkSync(bakFile);
553
+ log.log(' Cleared running processes backup file');
554
+ }
549
555
  }
550
556
  catch (err) {
551
557
  log.error(' Failed to clear running processes file:', err);
@@ -8,6 +8,7 @@ import { TIDE_COMMANDER_APPENDED_PROMPT } from '../prompts/tide-commander.js';
8
8
  import { getSystemPrompt, isEchoPromptEnabled } from '../services/system-prompt-service.js';
9
9
  import { loadAreas } from '../data/index.js';
10
10
  import { createLogger } from '../utils/logger.js';
11
+ // Backend adapter for OpenCode CLI sessions.
11
12
  const log = createLogger('OpencodeBackend');
12
13
  function buildOpencodePrompt(config) {
13
14
  const userPrompt = config.prompt?.trim() || 'Continue the task.';
@@ -1,2 +1,3 @@
1
1
  export { OpencodeBackend } from './backend.js';
2
2
  export { OpencodeJsonEventParser } from './json-event-parser.js';
3
+ export const OPENCODE_PROVIDER_NAME = 'opencode';
@@ -14,7 +14,7 @@ import { getAllCustomClasses } from '../services/custom-class-service.js';
14
14
  import { createLogger } from '../utils/logger.js';
15
15
  import { buildCustomAgentConfig } from '../websocket/handlers/command-handler.js';
16
16
  import { clearDelegation, getBossForSubordinate } from '../websocket/handlers/boss-response-handler.js';
17
- import { getSystemPrompt, setSystemPrompt, clearSystemPrompt, isEchoPromptEnabled, setEchoPromptEnabled, getCodexBinaryPath, setCodexBinaryPath } from '../services/system-prompt-service.js';
17
+ import { getSystemPrompt, setSystemPrompt, clearSystemPrompt, isEchoPromptEnabled, setEchoPromptEnabled, getCodexBinaryPath, setCodexBinaryPath, isTmuxModeEnabled, setTmuxModeEnabled } from '../services/system-prompt-service.js';
18
18
  const log = createLogger('Routes');
19
19
  const router = Router();
20
20
  // Store for broadcasting via WebSocket
@@ -786,4 +786,32 @@ router.post('/system-settings/codex-binary', (req, res) => {
786
786
  res.status(500).json({ error: err.message });
787
787
  }
788
788
  });
789
+ // GET /api/system-settings/tmux-mode - Get tmux mode setting
790
+ router.get('/system-settings/tmux-mode', (_req, res) => {
791
+ try {
792
+ const enabled = isTmuxModeEnabled();
793
+ res.json({ enabled });
794
+ }
795
+ catch (err) {
796
+ log.error(' Failed to get tmux mode setting:', err);
797
+ res.status(500).json({ error: err.message });
798
+ }
799
+ });
800
+ // POST /api/system-settings/tmux-mode - Update tmux mode setting
801
+ router.post('/system-settings/tmux-mode', (req, res) => {
802
+ try {
803
+ const { enabled } = req.body;
804
+ if (typeof enabled !== 'boolean') {
805
+ res.status(400).json({ error: 'enabled must be a boolean' });
806
+ return;
807
+ }
808
+ setTmuxModeEnabled(enabled);
809
+ log.log(` Tmux mode setting updated: enabled=${enabled}`);
810
+ res.json({ success: true, enabled });
811
+ }
812
+ catch (err) {
813
+ log.error(' Failed to set tmux mode setting:', err);
814
+ res.status(500).json({ error: err.message });
815
+ }
816
+ });
789
817
  export default router;
@@ -170,3 +170,41 @@ export function clearCodexBinaryPath() {
170
170
  throw error;
171
171
  }
172
172
  }
173
+ // ============================================================================
174
+ // Tmux Mode Setting
175
+ // ============================================================================
176
+ const TMUX_MODE_FILE = path.join(DATA_DIR, 'tmux-mode-setting.json');
177
+ /**
178
+ * Check if tmux mode is enabled
179
+ */
180
+ export function isTmuxModeEnabled() {
181
+ ensureDataDir();
182
+ try {
183
+ if (fs.existsSync(TMUX_MODE_FILE)) {
184
+ const data = JSON.parse(fs.readFileSync(TMUX_MODE_FILE, 'utf-8'));
185
+ return data.enabled;
186
+ }
187
+ }
188
+ catch (error) {
189
+ log.error(` Failed to load tmux mode setting: ${error.message}`);
190
+ }
191
+ return false;
192
+ }
193
+ /**
194
+ * Set tmux mode enabled/disabled
195
+ */
196
+ export function setTmuxModeEnabled(enabled) {
197
+ ensureDataDir();
198
+ const data = {
199
+ enabled,
200
+ updatedAt: Date.now(),
201
+ };
202
+ try {
203
+ fs.writeFileSync(TMUX_MODE_FILE, JSON.stringify(data, null, 2), 'utf-8');
204
+ log.log(` Tmux mode setting updated: enabled=${enabled}`);
205
+ }
206
+ catch (error) {
207
+ log.error(` Failed to save tmux mode setting: ${error.message}`);
208
+ throw error;
209
+ }
210
+ }
@@ -2,7 +2,9 @@
2
2
  * Boss Response Handler
3
3
  * Parses delegation, spawn, work-plan, and analysis-request blocks from boss agent responses
4
4
  */
5
+ import { BUILT_IN_AGENT_CLASSES } from '../../../shared/agent-types.js';
5
6
  import { agentService, runtimeService, bossService, workPlanService } from '../../services/index.js';
7
+ import { getAllCustomClasses } from '../../services/custom-class-service.js';
6
8
  import { logger } from '../../utils/index.js';
7
9
  import { getLastBossCommand, buildCustomAgentConfig } from './command-handler.js';
8
10
  const log = logger.ws;
@@ -301,7 +303,9 @@ export async function parseBossSpawn(bossId, bossName, resultText, broadcast, se
301
303
  log.log(` Parsed ${spawns.length} spawn request(s) from boss ${bossName}`);
302
304
  const boss = agentService.getAgent(bossId);
303
305
  const bossCwd = boss?.cwd || process.cwd();
304
- const validClasses = ['scout', 'builder', 'debugger', 'architect', 'warrior', 'support'];
306
+ const builtInClassIds = Object.keys(BUILT_IN_AGENT_CLASSES).filter(c => c !== 'boss');
307
+ const customClassIds = getAllCustomClasses().map(c => c.id);
308
+ const validClasses = [...builtInClassIds, ...customClassIds];
305
309
  for (const spawnRequest of spawns) {
306
310
  const { name, class: agentClass, cwd } = spawnRequest;
307
311
  if (!name || !agentClass) {
@@ -29,7 +29,17 @@ export function setupRuntimeListeners(ctx) {
29
29
  // delegation/spawn blocks even when the boss calls a tool after outputting them
30
30
  // (resultText in step_complete only contains the final text, not earlier text blocks).
31
31
  const bossAccumulatedText = new Map();
32
+ // Track agents currently in compacting state so we can clear it when they resume
33
+ const compactingAgents = new Set();
32
34
  runtimeService.on('event', (agentId, event) => {
35
+ // Clear compacting state when agent resumes with new output after compaction
36
+ if (compactingAgents.has(agentId) && event.type !== 'compacting') {
37
+ compactingAgents.delete(agentId);
38
+ ctx.broadcast({
39
+ type: 'compacting_status',
40
+ payload: { agentId, active: false },
41
+ });
42
+ }
33
43
  // Accumulate text for boss agents to ensure delegation blocks are captured
34
44
  // even when the boss calls tools after outputting the delegation
35
45
  if (event.type === 'text' && event.text && !event.parentToolUseId) {
@@ -39,7 +49,15 @@ export function setupRuntimeListeners(ctx) {
39
49
  bossAccumulatedText.set(agentId, prev + event.text);
40
50
  }
41
51
  }
42
- if (event.type === 'init') {
52
+ if (event.type === 'compacting') {
53
+ compactingAgents.add(agentId);
54
+ ctx.broadcast({
55
+ type: 'compacting_status',
56
+ payload: { agentId, active: true },
57
+ });
58
+ ctx.sendActivity(agentId, 'Compacting context...');
59
+ }
60
+ else if (event.type === 'init') {
43
61
  ctx.sendActivity(agentId, `Session initialized (${event.model})`);
44
62
  }
45
63
  else if (event.type === 'tool_start') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tide-commander",
3
- "version": "1.40.2",
3
+ "version": "1.40.4",
4
4
  "description": "Visual multi-agent orchestrator and manager for Claude Code with 3D/2D interface",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
1
- import{r as g,a5 as te,a6 as pe,j as e,u as U,a7 as be,a8 as je,f as ie,s as j,a9 as Pe,v as Ee,w as K,aa as z,ab as Le,Y as Fe,ac as Oe,V as ee,ad as $e,ae as _e,af as De,ag as Re,ah as G,ai as Be,aj as Ue,ak as ze,O as Ve,al as ae,am as ne,an as Ke,a1 as qe,S as He}from"./main-DULfVodw.js";import"./modulepreload-polyfill-B5Qt9EMX.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const le="deivid11/tide-commander",Me=`https://api.github.com/repos/${le}/releases/latest`,Ge=`https://api.github.com/repos/${le}/releases?per_page=3`,Ye=3600*1e3,fe="app_update_dismissed_version",xe="1.40.2";function We(){var x,y;const[s,i]=g.useState({isChecking:!1,updateAvailable:!1,updateInfo:null,recentReleases:[],error:null,currentVersion:xe}),n=((y=(x=te)==null?void 0:x.getPlatform)==null?void 0:y.call(x))==="android"||!1,o=r=>r.replace(/^v/,"").split(".").map(c=>parseInt(c,10)||0),d=(r,u)=>{const c=o(r),k=o(u),w=Math.max(c.length,k.length);for(let I=0;I<w;I++){const T=c[I]||0,F=k[I]||0;if(T>F)return 1;if(T<F)return-1}return 0},p=async r=>{var c,k;if(te&&pe&&((k=(c=te).isNativePlatform)==null?void 0:k.call(c))===!0){const w=await pe.get({url:r,headers:{Accept:"application/vnd.github.v3+json"}});return{data:w.data,status:w.status}}else{const w=await fetch(r,{headers:{Accept:"application/vnd.github.v3+json"}});return w.ok?{data:await w.json(),status:w.status}:{data:null,status:w.status}}},l=g.useCallback(async(r=!1)=>{i(u=>({...u,isChecking:!0,error:null}));try{const[u,c]=await Promise.all([p(Me),p(Ge)]);if(u.status!==200)throw new Error(`GitHub API error: ${u.status}`);const k=u.data,w=k.tag_name;let I=[];c.status===200&&c.data&&(I=c.data.map(S=>({version:S.tag_name,name:S.name,publishedAt:S.published_at,releaseUrl:S.html_url})));const T=localStorage.getItem(fe);if(!r&&T===w)return i(S=>({...S,isChecking:!1,updateAvailable:!1,recentReleases:I})),null;if(!(d(w,xe)>0))return i(S=>({...S,isChecking:!1,updateAvailable:!1,recentReleases:I})),null;const _=k.assets.find(S=>S.name.endsWith(".apk")&&S.content_type==="application/vnd.android.package-archive"),m={version:w,name:k.name,changelog:k.body,releaseUrl:k.html_url,apkUrl:(_==null?void 0:_.browser_download_url)||null,apkSize:(_==null?void 0:_.size)||null,publishedAt:k.published_at};return i(S=>({...S,isChecking:!1,updateAvailable:!0,updateInfo:m,recentReleases:I})),m}catch(u){const c=u instanceof Error?u.message:"Failed to check for updates";return i(k=>({...k,isChecking:!1,error:c})),null}},[]),a=g.useCallback(async()=>{var r,u,c;if(!((r=s.updateInfo)!=null&&r.apkUrl)){(u=s.updateInfo)!=null&&u.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}if(!n){(c=s.updateInfo)!=null&&c.releaseUrl&&window.open(s.updateInfo.releaseUrl,"_blank");return}try{window.open(s.updateInfo.apkUrl,"_system"),i(k=>({...k,error:null}))}catch(k){const w=k instanceof Error?k.message:"Failed to open download";i(I=>({...I,error:w}))}},[s.updateInfo,n]),f=g.useCallback(()=>{s.updateInfo&&localStorage.setItem(fe,s.updateInfo.version),i(r=>({...r,updateAvailable:!1,updateInfo:null}))},[s.updateInfo]),N=g.useCallback(()=>{var r;(r=s.updateInfo)!=null&&r.releaseUrl?window.open(s.updateInfo.releaseUrl,"_blank"):window.open(`https://github.com/${le}/releases`,"_blank")},[s.updateInfo]);return g.useEffect(()=>{if(!n)return;const r=setTimeout(()=>{l()},5e3),u=setInterval(()=>{l()},Ye);return()=>{clearTimeout(r),clearInterval(u)}},[n,l]),{...s,isAndroid:n,checkForUpdate:l,downloadAndInstall:a,dismissUpdate:f,openReleasePage:N}}const ve="tide-toolbox-collapse";function Je(s,i){try{const n=localStorage.getItem(`${ve}-${s}`);if(n!==null)return n==="true"}catch{}return i}function Ze(s,i){try{localStorage.setItem(`${ve}-${s}`,String(i))}catch{}}function O({title:s,storageKey:i,defaultOpen:n=!1,forceOpen:o=!1,children:d,headerExtra:p}){const[l,a]=g.useState(()=>i?Je(i,n):n),f=()=>{const x=!l;a(x),i&&Ze(i,x)},N=o||l;return e.jsxs("div",{className:`collapsible-section ${N?"open":"collapsed"}`,children:[e.jsxs("button",{className:"collapsible-header",onClick:f,children:[e.jsx("span",{className:"collapsible-title",children:s}),e.jsxs("span",{className:"collapsible-header-right",children:[p,e.jsx("span",{className:"collapsible-arrow",children:N?"▼":"▶"})]})]}),N&&e.jsx("div",{className:"collapsible-content",children:d})]})}function Xe({area:s,isSelected:i,onClick:n,onDelete:o}){const{t:d}=U(["config","common"]),p=s.assignedAgentIds.length,l=s.type==="rectangle"?d("config:areas.rect"):d("config:areas.circle");return e.jsxs("div",{className:`area-item ${i?"selected":""}`,onClick:n,children:[e.jsx("div",{className:"area-color-dot",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"area-info",children:[e.jsx("div",{className:"area-name",children:s.name}),e.jsxs("div",{className:"area-meta",children:[l," ",p>0&&`• ${p} ${p>1?d("common:labels.agents").toLowerCase():d("common:labels.agent").toLowerCase()}`]})]}),e.jsx("button",{className:"area-delete-btn",onClick:o,title:d("config:areas.deleteArea"),children:"×"})]})}function Qe({building:s,isSelected:i,onClick:n,onEdit:o}){var f;const{t:d}=U(["config"]),p=be[s.type],l=((f=s.pm2Status)==null?void 0:f.ports)||[],a=(N,x)=>{N.stopPropagation(),window.open(`http://localhost:${x}`,"_blank")};return e.jsxs("div",{className:`building-item ${i?"selected":""}`,onClick:n,children:[e.jsx("div",{className:"building-status-dot",style:{backgroundColor:je[s.status]},title:s.status}),e.jsx("div",{className:"building-icon",children:p.icon}),e.jsxs("div",{className:"building-info",children:[e.jsx("div",{className:"building-name",children:s.name}),e.jsxs("div",{className:"building-meta",children:[s.type,l.length>0&&e.jsx("span",{className:"building-ports",children:l.map(N=>e.jsxs("a",{href:`http://localhost:${N}`,className:"building-port-link",onClick:x=>a(x,N),title:`Open :${N}`,children:[":",N]},N))})]})]}),e.jsx("button",{className:"building-edit-btn",onClick:N=>{N.stopPropagation(),o()},title:d("config:buildings.editBuilding"),children:"⚙"})]})}function es({building:s,onClose:i,onOpenModal:n}){var x,y,r,u,c,k,w,I;const{t:o}=U(["config","common"]),{buildingLogs:d}=ie(),p=j.getBuildingLogs(s.id),l=be[s.type],a=Pe[s.style||"server-rack"],f=T=>{j.sendBuildingCommand(s.id,T)},N=T=>{window.open(T,"_blank")};return e.jsxs("div",{className:"building-editor",children:[e.jsxs("div",{className:"building-editor-header",children:[e.jsxs("div",{className:"building-editor-title-row",children:[e.jsx("span",{className:"building-editor-icon",children:l.icon}),e.jsx("span",{className:"building-editor-title",children:s.name}),e.jsx("span",{className:"building-editor-status",style:{backgroundColor:je[s.status]},children:s.status})]}),e.jsx("button",{className:"building-editor-close",onClick:i,children:"×"})]}),e.jsx("div",{className:"building-editor-section",children:e.jsxs("div",{className:"building-editor-info-grid",children:[e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("common:labels.type")}),e.jsx("span",{className:"building-editor-info-value",children:s.type})]}),e.jsxs("div",{className:"building-editor-info-item",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.style")}),e.jsx("span",{className:"building-editor-info-value",children:a.label})]}),s.cwd&&e.jsxs("div",{className:"building-editor-info-item building-editor-info-wide",children:[e.jsx("span",{className:"building-editor-info-label",children:o("config:buildings.directory")}),e.jsx("span",{className:"building-editor-info-value building-editor-cwd",title:s.cwd,children:s.cwd.split("/").pop()||s.cwd})]})]})}),s.type==="server"&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.actions")}),e.jsxs("div",{className:"building-editor-actions",children:[e.jsxs("button",{className:"building-editor-action-btn start",onClick:()=>f("start"),disabled:!((x=s.commands)!=null&&x.start)||s.status==="running",title:((y=s.commands)==null?void 0:y.start)||o("config:buildings.noStartCommand"),children:["▶ ",o("common:buttons.start")]}),e.jsxs("button",{className:"building-editor-action-btn stop",onClick:()=>f("stop"),disabled:!((r=s.commands)!=null&&r.stop)||s.status==="stopped",title:((u=s.commands)==null?void 0:u.stop)||o("config:buildings.noStopCommand"),children:["■ ",o("common:buttons.stop")]}),e.jsxs("button",{className:"building-editor-action-btn restart",onClick:()=>f("restart"),disabled:!((c=s.commands)!=null&&c.restart),title:((k=s.commands)==null?void 0:k.restart)||o("config:buildings.noRestartCommand"),children:["⟳ ",o("common:buttons.retry")]}),e.jsx("button",{className:"building-editor-action-btn health",onClick:()=>f("healthCheck"),disabled:!((w=s.commands)!=null&&w.healthCheck),title:((I=s.commands)==null?void 0:I.healthCheck)||o("config:buildings.noHealthCheck"),children:"♥ Health"})]})]}),s.urls&&s.urls.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsx("div",{className:"building-editor-section-title",children:o("config:buildings.links")}),e.jsx("div",{className:"building-editor-links",children:s.urls.map((T,F)=>e.jsxs("button",{className:"building-editor-link",onClick:()=>N(T.url),title:T.url,children:["🔗 ",T.label||T.url]},F))})]}),p.length>0&&e.jsxs("div",{className:"building-editor-section",children:[e.jsxs("div",{className:"building-editor-section-title",children:[o("config:buildings.recentLogs"),e.jsx("button",{className:"building-editor-clear-logs",onClick:()=>j.clearBuildingLogs(s.id),title:o("common:buttons.clear"),children:o("common:buttons.clear")})]}),e.jsx("div",{className:"building-editor-logs",children:p.slice(-5).map((T,F)=>e.jsx("div",{className:"building-editor-log-entry",children:T},F))})]}),e.jsx("div",{className:"building-editor-footer",children:e.jsxs("button",{className:"building-editor-edit-btn",onClick:n,children:["⚙ ",o("config:buildings.fullSettings")]})})]})}async function ss(s,i){const n=z(),o=await fetch(K(`/api/areas/${s}/logo`),{method:"POST",headers:{"Content-Type":i.type||"image/png","X-Filename":encodeURIComponent(i.name),...n?{Authorization:`Bearer ${n}`}:{}},body:i});if(!o.ok){const d=await o.json().catch(()=>({error:o.statusText}));throw new Error(d.error||`Upload failed: ${o.statusText}`)}return o.json()}async function ts(s){const i=z(),n=await fetch(K(`/api/areas/${s}/logo`),{method:"DELETE",headers:{...i?{Authorization:`Bearer ${i}`}:{}}});if(!n.ok)throw new Error(`Failed to delete logo: ${n.statusText}`)}function as(s){return Ee(K(`/api/areas/logos/${s}`))}const ns=[{key:"center",labelKey:"posCenter"},{key:"top-left",labelKey:"posTopLeft"},{key:"top-right",labelKey:"posTopRight"},{key:"bottom-left",labelKey:"posBottomLeft"},{key:"bottom-right",labelKey:"posBottomRight"}];function os({area:s,onClose:i,onOpenFolder:n}){var R;const{t:o}=U(["config","common"]),[d,p]=g.useState(s.name),[l,a]=g.useState(s.prompt||""),[f,N]=g.useState(!1),[x,y]=g.useState(""),[r,u]=g.useState(!1),c=g.useRef(null);g.useEffect(()=>{p(s.name)},[s.id,s.name]),g.useEffect(()=>{a(s.prompt||"")},[s.id,s.prompt]);const k=h=>{const C=h.target.value;p(C),j.updateArea(s.id,{name:C})},w=h=>{j.updateArea(s.id,{color:h})},I=h=>{const C=h.target.value;a(C),j.updateArea(s.id,{prompt:C})},T=()=>{x.trim()&&(j.addDirectoryToArea(s.id,x.trim()),y(""),N(!1))},F=(h,C)=>{C.stopPropagation(),j.removeDirectoryFromArea(s.id,h)},_=()=>{j.bringAreaToFront(s.id)},m=()=>{j.sendAreaToBack(s.id)},S=g.useCallback(()=>{let h=2,C=2;s.type==="rectangle"&&s.width&&s.height?(h=s.width,C=s.height):s.type==="circle"&&s.radius&&(h=s.radius*1.414,C=s.radius*1.414);const L=Math.min(h,C)*.4;return{width:Math.round(L*10)/10,height:Math.round(L*10)/10}},[s.type,s.width,s.height,s.radius]),Q=async h=>{var L;const C=(L=h.target.files)==null?void 0:L[0];if(C){u(!0);try{const q=await ss(s.id,C),H=S();j.updateArea(s.id,{logo:{filename:q.filename,position:"center",width:H.width,height:H.height,keepAspectRatio:!0,opacity:.8}})}catch(q){console.error("Failed to upload logo:",q)}finally{u(!1),c.current&&(c.current.value="")}}},Y=async()=>{try{await ts(s.id),j.updateArea(s.id,{logo:void 0})}catch(h){console.error("Failed to remove logo:",h)}},W=h=>{s.logo&&j.updateArea(s.id,{logo:{...s.logo,position:h}})},J=h=>{if(!s.logo)return;const C=parseFloat(h.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.width>0){const L=s.logo.height/s.logo.width;j.updateArea(s.id,{logo:{...s.logo,width:C,height:Math.round(C*L*10)/10}})}else j.updateArea(s.id,{logo:{...s.logo,width:C}})},b=h=>{if(!s.logo)return;const C=parseFloat(h.target.value)||.1;if(s.logo.keepAspectRatio&&s.logo.height>0){const L=s.logo.width/s.logo.height;j.updateArea(s.id,{logo:{...s.logo,height:C,width:Math.round(C*L*10)/10}})}else j.updateArea(s.id,{logo:{...s.logo,height:C}})},E=()=>{s.logo&&j.updateArea(s.id,{logo:{...s.logo,keepAspectRatio:!s.logo.keepAspectRatio}})},P=h=>{s.logo&&j.updateArea(s.id,{logo:{...s.logo,opacity:parseFloat(h.target.value)}})};return e.jsxs("div",{className:"area-editor",children:[e.jsxs("div",{className:"area-editor-header",children:[e.jsx("span",{className:"area-editor-title",children:o("config:areas.editArea")}),e.jsx("button",{className:"area-editor-close",onClick:i,children:"×"})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("common:labels.name")}),e.jsx("input",{type:"text",className:"area-editor-input",value:d,onChange:k,placeholder:o("config:areas.areaName")})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.color")}),e.jsx("div",{className:"color-picker-row",children:Le.map(h=>e.jsx("div",{className:`color-swatch ${s.color===h?"selected":""}`,style:{backgroundColor:h},onClick:()=>w(h)},h))})]}),e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.layer")}),e.jsxs("div",{className:"area-layer-buttons",children:[e.jsxs("button",{className:"area-layer-btn",onClick:_,title:o("config:areas.bringToFront"),children:["↑ ",o("config:areas.front")]}),e.jsxs("button",{className:"area-layer-btn",onClick:m,title:o("config:areas.sendToBack"),children:["↓ ",o("config:areas.back")]})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.logo")}),e.jsxs("div",{className:"area-logo-section",children:[(R=s.logo)!=null&&R.filename?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"area-logo-preview",children:[e.jsx("img",{src:as(s.logo.filename),alt:"Logo",className:"area-logo-thumbnail"}),e.jsx("button",{className:"area-logo-remove-btn",onClick:Y,children:o("config:areas.removeLogo")}),e.jsx("button",{className:"area-logo-replace-btn",onClick:()=>{var h;return(h=c.current)==null?void 0:h.click()},disabled:r,children:r?"...":"↻"})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoPosition")}),e.jsx("div",{className:"area-logo-position-row",children:ns.map(({key:h,labelKey:C})=>{var L;return e.jsx("button",{className:`area-logo-pos-btn ${((L=s.logo)==null?void 0:L.position)===h?"active":""}`,onClick:()=>W(h),children:o(`config:areas.${C}`)},h)})})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoSize")}),e.jsxs("div",{className:"area-logo-size-row",children:[e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoWidth")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.width,onChange:J,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-size-field",children:[e.jsx("span",{children:o("config:areas.logoHeight")}),e.jsx("input",{type:"number",className:"area-logo-size-input",value:s.logo.height,onChange:b,min:.1,step:.1})]}),e.jsxs("label",{className:"area-logo-aspect-label",title:o("config:areas.keepAspectRatio"),children:[e.jsx("input",{type:"checkbox",checked:s.logo.keepAspectRatio,onChange:E}),o("config:areas.keepAspectRatio")]})]})]}),e.jsxs("div",{className:"area-logo-config-row",children:[e.jsx("span",{className:"area-logo-config-label",children:o("config:areas.logoOpacity")}),e.jsxs("div",{className:"area-logo-opacity-row",children:[e.jsx("input",{type:"range",min:0,max:1,step:.05,value:s.logo.opacity??.8,onChange:P,className:"area-logo-opacity-slider"}),e.jsxs("span",{className:"area-logo-opacity-value",children:[Math.round((s.logo.opacity??.8)*100),"%"]})]})]})]}):e.jsx("button",{className:"area-logo-upload-btn",onClick:()=>{var h;return(h=c.current)==null?void 0:h.click()},disabled:r,children:r?"...":o("config:areas.uploadLogo")}),e.jsx("input",{ref:c,type:"file",accept:"image/*",style:{display:"none"},onChange:Q})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.folders",{count:s.directories.length})}),e.jsxs("div",{className:"area-folders-list",children:[s.directories.map(h=>e.jsxs("div",{className:"area-folder-item",title:h,children:[e.jsx("span",{className:"area-folder-icon clickable",onClick:()=>n==null?void 0:n(s.id),title:o("config:areas.openFolder"),children:"📁"}),e.jsx("span",{className:"area-folder-path",children:h.split("/").pop()||h}),e.jsx("button",{className:"area-folder-remove",onClick:C=>F(h,C),title:o("config:areas.removeFolder"),children:"×"})]},h)),f?e.jsxs("div",{className:"area-add-folder-inline",children:[e.jsx(Fe,{value:x,onChange:y,onSubmit:T,placeholder:o("config:areas.folderPlaceholder"),className:"area-add-folder-input",directoriesOnly:!0,autoFocus:!0}),e.jsx("button",{className:"area-add-folder-confirm",onClick:T,children:"+"})]}):e.jsx("button",{className:"area-add-folder-btn",onClick:()=>N(!0),children:o("config:areas.addFolder")})]})]}),e.jsxs("div",{className:"area-editor-row",style:{flexDirection:"column",alignItems:"stretch"},children:[e.jsx("div",{className:"area-editor-label",style:{marginBottom:6},children:o("config:areas.prompt","Prompt")}),e.jsx("textarea",{className:"area-editor-input",value:l,onChange:I,placeholder:o("config:areas.promptPlaceholder","System prompt for agents in this area..."),rows:4,style:{resize:"vertical",fontFamily:"monospace",fontSize:12}}),e.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4},children:o("config:areas.promptHint","This prompt is injected into agents assigned to this area. Takes effect on next context refresh.")})]}),s.assignedAgentIds.length>0&&e.jsxs("div",{className:"area-editor-row",children:[e.jsx("div",{className:"area-editor-label",children:o("config:areas.assignedAgents",{count:s.assignedAgentIds.length})}),e.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:o("config:areas.rightClickUnassign")})]})]})}function is(){const{t:s}=U(["config","common"]),i=Oe(),[n,o]=g.useState(!1),[d,p]=g.useState(null),[l,a]=g.useState({name:"",key:"",value:"",description:""}),f=()=>{o(!0),p(null),a({name:"",key:"",value:"",description:""})},N=c=>{p(c.id),o(!1),a({name:c.name,key:c.key,value:c.value,description:c.description||""})},x=()=>{o(!1),p(null),a({name:"",key:"",value:"",description:""})},y=()=>{!l.name.trim()||!l.key.trim()||(d?j.updateSecret(d,{name:l.name.trim(),key:l.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:l.value,description:l.description.trim()||void 0}):j.createSecret({name:l.name.trim(),key:l.key.trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_"),value:l.value,description:l.description.trim()||void 0}),x())},r=c=>{confirm(s("config:secrets.deleteConfirm"))&&(j.deleteSecret(c),d===c&&x())},u=c=>{navigator.clipboard.writeText(`{{${c}}}`)};return e.jsxs("div",{className:"secrets-section",children:[e.jsx("div",{className:"secrets-description",children:s("config:secrets.description",{placeholder:"{{KEY}}"})}),e.jsx("div",{className:"secrets-list",children:i.length===0&&!n?e.jsx("div",{className:"secrets-empty",children:s("config:secrets.noSecrets")}):i.map(c=>e.jsxs("div",{className:`secret-item ${d===c.id?"editing":""}`,children:[e.jsxs("div",{className:"secret-item-header",children:[e.jsxs("div",{className:"secret-item-info",children:[e.jsx("span",{className:"secret-item-name",children:c.name}),e.jsx("code",{className:"secret-item-key",onClick:()=>u(c.key),title:s("config:secrets.copyPlaceholder"),children:`{{${c.key}}}`})]}),e.jsxs("div",{className:"secret-item-actions",children:[e.jsx("button",{className:"secret-item-btn edit",onClick:()=>N(c),title:s("common:buttons.edit"),children:"✎"}),e.jsx("button",{className:"secret-item-btn delete",onClick:()=>r(c.id),title:s("common:buttons.delete"),children:"×"})]})]}),c.description&&e.jsx("div",{className:"secret-item-description",children:c.description})]},c.id))}),(n||d)&&e.jsxs("div",{className:"secret-form",children:[e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.name")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.namePlaceholder"),value:l.name,onChange:c=>a({...l,name:c.target.value}),autoFocus:!0})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:"Key"}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.keyPlaceholder"),value:l.key,onChange:c=>a({...l,key:c.target.value.toUpperCase().replace(/[^A-Z0-9_]/g,"")})}),e.jsx("span",{className:"secret-form-hint",children:s("config:secrets.usedAs",{placeholder:`{{${l.key||"KEY"}}}`})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("config:secrets.secretValue")}),e.jsx("input",{type:"password",className:"secret-form-input",placeholder:s("config:secrets.valuePlaceholder"),value:l.value,onChange:c=>a({...l,value:c.target.value})})]}),e.jsxs("div",{className:"secret-form-row",children:[e.jsx("label",{className:"secret-form-label",children:s("common:labels.description")}),e.jsx("input",{type:"text",className:"secret-form-input",placeholder:s("config:secrets.descriptionPlaceholder"),value:l.description,onChange:c=>a({...l,description:c.target.value})})]}),e.jsxs("div",{className:"secret-form-actions",children:[e.jsx("button",{className:"secret-form-btn cancel",onClick:x,children:s("common:buttons.cancel")}),e.jsx("button",{className:"secret-form-btn save",onClick:y,disabled:!l.name.trim()||!l.key.trim(),children:s(d?"config:secrets.update":"common:buttons.add")})]})]}),!n&&!d&&e.jsx("button",{className:"secrets-add-btn",onClick:f,children:s("config:secrets.addSecret")})]})}function ls(){const{t:s}=U(["config","common"]),[i,n]=g.useState([]),[o,d]=g.useState(new Set),[p,l]=g.useState(new Set),[a,f]=g.useState(!1),[N,x]=g.useState(!1),[y,r]=g.useState(null),[u,c]=g.useState(null),[k,w]=g.useState(null);g.useEffect(()=>{ee(K("/api/config/categories")).then(b=>b.json()).then(b=>{const E=Array.isArray(b)?b:[];n(E),d(new Set(E.map(P=>P.id)))}).catch(b=>console.error("Failed to fetch config categories:",b))},[]);const I=b=>{d(E=>{const P=new Set(E);return P.has(b)?P.delete(b):P.add(b),P})},T=b=>{l(E=>{const P=new Set(E);return P.has(b)?P.delete(b):P.add(b),P})},F=()=>d(new Set(i.map(b=>b.id))),_=()=>d(new Set),m=()=>{u&&l(new Set(u.categories.map(b=>b.id)))},S=()=>l(new Set),Q=async()=>{var b;if(o.size!==0){f(!0),w(null);try{const E=Array.from(o).join(","),P=await ee(K(`/api/config/export?categories=${E}`));if(!P.ok)throw new Error("Export failed");const R=await P.blob(),h=window.URL.createObjectURL(R),C=document.createElement("a");C.href=h;const L=P.headers.get("Content-Disposition"),q=((b=L==null?void 0:L.match(/filename="(.+)"/))==null?void 0:b[1])||"tide-commander-config.zip";C.download=q,document.body.appendChild(C),C.click(),document.body.removeChild(C),window.URL.revokeObjectURL(h),w({type:"success",text:s("config:data.exportSuccess")})}catch(E){w({type:"error",text:E.message||"Export failed"})}finally{f(!1)}}},Y=async b=>{var P;const E=(P=b.target.files)==null?void 0:P[0];if(E){r(E),w(null),c(null),l(new Set);try{const R=await ee(K("/api/config/preview"),{method:"POST",headers:{"Content-Type":"application/zip"},body:await E.arrayBuffer()});if(!R.ok){const L=await R.json();throw new Error(L.error||"Failed to preview config file")}const h=await R.json(),C=Array.isArray(h.categories)?h.categories:[];c({...h,categories:C}),l(new Set(C.map(L=>L.id)))}catch(R){w({type:"error",text:R.message||"Failed to read config file"}),r(null)}}},W=async()=>{if(!(!y||p.size===0)){x(!0),w(null);try{const b=Array.from(p).join(","),E=await ee(K(`/api/config/import?categories=${b}`),{method:"POST",headers:{"Content-Type":"application/zip"},body:await y.arrayBuffer()}),P=await E.json();if(!E.ok)throw new Error(P.error||"Import failed");w({type:"success",text:P.message||s("config:data.importSuccess")}),r(null),c(null),l(new Set)}catch(b){w({type:"error",text:b.message||"Import failed"})}finally{x(!1)}}},J=()=>{r(null),c(null),l(new Set),w(null)};return e.jsxs("div",{className:"data-section",children:[k&&e.jsx("div",{className:`data-message data-message-${k.type}`,children:k.text}),e.jsxs("div",{className:"data-subsection",children:[e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-title",children:s("config:data.exportData")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:F,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:_,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:i.map(b=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:o.has(b.id),onChange:()=>I(b.id)}),e.jsx("span",{className:"data-category-name",children:b.name})]},b.id))}),e.jsx("button",{className:"data-action-btn export",onClick:Q,disabled:a||o.size===0,children:a?s("config:data.exporting"):s("config:data.exportCount",{count:o.size})})]}),e.jsxs("div",{className:"data-subsection",children:[e.jsx("div",{className:"data-subsection-header",children:e.jsx("span",{className:"data-subsection-title",children:s("config:data.importData")})}),y?u?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"data-import-info",children:[e.jsx("div",{className:"data-import-file",children:y.name}),e.jsxs("div",{className:"data-import-date",children:[s("config:data.exported"),": ",new Date(u.exportedAt).toLocaleDateString()]})]}),e.jsxs("div",{className:"data-subsection-header",children:[e.jsx("span",{className:"data-subsection-subtitle",children:s("config:data.selectToImport")}),e.jsxs("div",{className:"data-select-controls",children:[e.jsx("button",{className:"data-select-btn",onClick:m,children:s("common:labels.all")}),e.jsx("button",{className:"data-select-btn",onClick:S,children:s("common:labels.none")})]})]}),e.jsx("div",{className:"data-category-list",children:u.categories.map(b=>e.jsxs("label",{className:"data-category-item",children:[e.jsx("input",{type:"checkbox",checked:p.has(b.id),onChange:()=>T(b.id)}),e.jsx("span",{className:"data-category-name",children:b.name}),b.fileCount&&e.jsxs("span",{className:"data-category-count",children:["(",b.fileCount," ",s("config:data.files"),")"]})]},b.id))}),e.jsxs("div",{className:"data-import-actions",children:[e.jsx("button",{className:"data-action-btn cancel",onClick:J,children:s("common:buttons.cancel")}),e.jsx("button",{className:"data-action-btn import",onClick:W,disabled:N||p.size===0,children:N?s("config:data.importing"):s("config:data.importCount",{count:p.size})})]})]}):e.jsx("div",{className:"data-loading",children:s("config:data.readingFile")}):e.jsxs("label",{className:"data-file-input",children:[e.jsx("input",{type:"file",accept:".zip",onChange:Y,style:{display:"none"}}),e.jsx("span",{className:"data-file-input-label",children:s("config:data.selectFile")})]})]})]})}function cs(){const[s,i]=g.useState(()=>$e()),n=o=>{i(o);const d=De(o);Re(d)};return e.jsx("div",{className:"theme-selector",children:e.jsx("div",{className:"theme-selector-grid",children:_e.map(o=>e.jsxs("button",{className:`theme-option ${s===o.id?"active":""}`,onClick:()=>n(o.id),title:o.description,children:[e.jsx("div",{className:"theme-preview",children:e.jsxs("div",{className:"theme-preview-bg",style:{backgroundColor:o.colors.bgPrimary},children:[e.jsx("div",{className:"theme-preview-accent",style:{backgroundColor:o.colors.accentBlue}}),e.jsx("div",{className:"theme-preview-claude",style:{backgroundColor:o.colors.accentClaude}})]})}),e.jsx("span",{className:"theme-name",children:o.name})]},o.id))})})}function rs(){const{t:s}=U(["config"]),{updateAvailable:i,updateInfo:n,recentReleases:o,isChecking:d,error:p,currentVersion:l,isAndroid:a,checkForUpdate:f,downloadAndInstall:N,openReleasePage:x}=We(),y=u=>u?`${(u/(1024*1024)).toFixed(1)} MB`:"",r=u=>new Date(u).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return e.jsxs("div",{className:"about-section",children:[e.jsxs("div",{className:"about-logo",children:[e.jsx("span",{className:"about-logo-icon",children:"🌊"}),e.jsx("span",{className:"about-logo-text",children:"Tide Commander"})]}),e.jsxs("div",{className:"about-version",children:[e.jsx("span",{className:"about-version-label",children:s("config:about.version")}),e.jsxs("div",{className:"about-version-info",children:[e.jsx("span",{className:"about-version-value",children:l}),i&&n?e.jsx("span",{className:"about-version-update-badge",onClick:x,title:`Update available: ${n.version}`,children:n.version}):e.jsxs("a",{href:"https://github.com/deivid11/tide-commander/releases",target:"_blank",rel:"noopener noreferrer",className:"about-version-status",children:["(",s("config:about.updated"),")"]})]})]}),e.jsxs("div",{className:"about-update",children:[i&&n?e.jsxs("div",{className:"about-update-available",children:[e.jsxs("div",{className:"about-update-header",children:[e.jsx("span",{className:"about-update-badge",children:s("config:about.updateAvailable")}),e.jsx("span",{className:"about-update-version",children:n.version})]}),n.apkSize&&e.jsxs("div",{className:"about-update-size",children:[s("config:about.sizeLabel"),": ",y(n.apkSize)]}),p&&e.jsx("div",{className:"about-update-error",children:p}),e.jsxs("div",{className:"about-update-actions",children:[e.jsx("button",{className:"about-update-btn changelog",onClick:x,children:s("config:about.changelog")}),a&&n.apkUrl?e.jsx("button",{className:"about-update-btn download",onClick:N,children:s("config:about.downloadAPK")}):e.jsx("button",{className:"about-update-btn download",onClick:x,children:s("config:about.viewRelease")})]})]}):e.jsxs("div",{className:"about-update-check",children:[e.jsx("span",{className:"about-update-status",children:s(d?"config:about.checkingUpdates":"config:about.upToDate")}),e.jsx("button",{className:"about-update-btn check",onClick:()=>f(!0),disabled:d,children:d?"...":s("config:about.check")})]}),o.length>0&&e.jsxs("div",{className:"about-releases",children:[e.jsx("div",{className:"about-releases-title",children:s("config:about.recentReleases")}),e.jsx("div",{className:"about-releases-list",children:o.map(u=>e.jsxs("a",{href:u.releaseUrl,target:"_blank",rel:"noopener noreferrer",className:`about-release-item ${u.version===`v${l}`||u.version===l?"current":""}`,children:[e.jsx("span",{className:"about-release-version",children:u.version}),e.jsx("span",{className:"about-release-date",children:r(u.publishedAt)})]},u.version))})]})]}),e.jsx("div",{className:"about-description",children:s("config:about.tagline")}),e.jsxs("div",{className:"about-principles",children:[e.jsx("div",{className:"about-principles-title",children:s("config:about.corePrinciples")}),e.jsxs("ul",{className:"about-principles-list",children:[e.jsx("li",{children:s("config:about.principle1")}),e.jsx("li",{children:s("config:about.principle2")}),e.jsx("li",{children:s("config:about.principle3")}),e.jsx("li",{children:s("config:about.principle4")})]})]}),e.jsx("div",{className:"about-links",children:e.jsxs("a",{href:"https://github.com/deivid11/tide-commander",target:"_blank",rel:"noopener noreferrer",className:"about-link",children:[e.jsx("span",{className:"about-link-icon",children:"📦"}),e.jsx("span",{children:s("config:about.repository")})]})}),e.jsxs("div",{className:"about-credits",children:[e.jsx("div",{className:"about-credits-title",children:s("config:about.specialThanks")}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://kenney.nl",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Kenney.nl"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.kenneyCredit")})]}),e.jsxs("div",{className:"about-credit-item",children:[e.jsx("a",{href:"https://claude.ai/code",target:"_blank",rel:"noopener noreferrer",className:"about-credit-link",children:"Claude Code"}),e.jsx("span",{className:"about-credit-desc",children:s("config:about.claudeCodeCredit")})]})]})]})}const ds={gmail:"✉️",slack:"💬",jira:"📋","google-calendar":"📅",docx:"📄"};function ms({onOpenModal:s}){const[i,n]=g.useState([]),[o,d]=g.useState(!0),p=g.useCallback(async()=>{try{const l=await ee(K("/api/integrations"));if(!l.ok)return;const a=await l.json();n(a)}catch{}finally{d(!1)}},[]);return g.useEffect(()=>{p()},[p]),o?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"Loading..."}):i.length===0?e.jsx("div",{style:{color:"var(--text-secondary, #a6adc8)",fontSize:12,padding:"4px 0"},children:"No integrations available."}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[i.map(l=>{const a=ds[l.id]||"🔌",f=!!l.status.error,N=l.status.connected,x=f?"#f38ba8":N?"#a6e3a1":"#fab387",y=f?"Error":N?"Connected":"Setup Required",r=f?"✗":N?"✓":"⚠";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:6,background:"var(--surface-1, #181825)",border:"1px solid var(--border, #313244)",fontSize:13},children:[e.jsx("span",{style:{fontSize:15,flexShrink:0},children:a}),e.jsx("span",{style:{flex:1,color:"var(--text-primary, #cdd6f4)",fontWeight:500},children:l.name}),e.jsxs("span",{style:{color:x,fontSize:11,fontWeight:500,whiteSpace:"nowrap"},children:[r," ",y]}),e.jsx("button",{onClick:()=>s(l.id),title:`Configure ${l.name}`,style:{background:"none",border:"none",cursor:"pointer",padding:"2px 4px",fontSize:14,color:"var(--text-secondary, #a6adc8)",borderRadius:4,flexShrink:0},onMouseEnter:u=>{u.target.style.color="var(--text-primary, #cdd6f4)"},onMouseLeave:u=>{u.target.style.color="var(--text-secondary, #a6adc8)"},children:"⚙️"})]},l.id)}),e.jsx("button",{onClick:()=>s(),style:{background:"none",border:"1px dashed var(--border, #313244)",borderRadius:6,padding:"6px 8px",cursor:"pointer",color:"var(--text-secondary, #a6adc8)",fontSize:12,textAlign:"center",marginTop:2},onMouseEnter:l=>{l.target.style.borderColor="var(--accent, #89b4fa)",l.target.style.color="var(--accent, #89b4fa)"},onMouseLeave:l=>{l.target.style.borderColor="var(--border, #313244)",l.target.style.color="var(--text-secondary, #a6adc8)"},children:"Manage All Integrations"})]})}async function us(){const s=z(),i=await fetch(`${G()}/api/agents/system-settings/prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch system prompt: ${i.statusText}`);return(await i.json()).prompt||""}async function gs(s){const i=z(),n=await fetch(`${G()}/api/agents/system-settings/prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({prompt:s})});if(!n.ok)throw new Error(`Failed to update system prompt: ${n.statusText}`)}async function hs(){const s=z(),i=await fetch(`${G()}/api/agents/system-settings/prompt`,{method:"DELETE",headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to clear system prompt: ${i.statusText}`)}async function ps(){const s=z(),i=await fetch(`${G()}/api/agents/system-settings/echo-prompt`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch echo prompt setting: ${i.statusText}`);return(await i.json()).enabled||!1}async function fs(s){const i=z(),n=await fetch(`${G()}/api/agents/system-settings/echo-prompt`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({enabled:s})});if(!n.ok)throw new Error(`Failed to update echo prompt setting: ${n.statusText}`)}async function xs(){const s=z(),i=await fetch(`${G()}/api/agents/system-settings/codex-binary`,{headers:{Authorization:`Bearer ${s}`}});if(!i.ok)throw new Error(`Failed to fetch codex binary path: ${i.statusText}`);return(await i.json()).path||""}async function bs(s){const i=z(),n=await fetch(`${G()}/api/agents/system-settings/codex-binary`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({path:s})});if(!n.ok)throw new Error(`Failed to update codex binary path: ${n.statusText}`)}function js({isOpen:s,onClose:i}){const{t:n}=U(["config"]),[o,d]=g.useState(""),[p,l]=g.useState(""),[a,f]=g.useState(!0),[N,x]=g.useState(null),[y,r]=g.useState(null),[u,c]=g.useState(!1);g.useEffect(()=>{s&&k()},[s]);const k=async()=>{try{f(!0),x(null),r(null);const m=await us();d(m),l(m),c(!1)}catch(m){x(m instanceof Error?m.message:"Failed to load system prompt")}finally{f(!1)}},w=m=>{const S=m.target.value;d(S),c(S!==p),x(null),r(null)},I=async()=>{try{x(null),r(null),await gs(o),l(o),c(!1),r(n("config:systemPrompt.saved"))}catch(m){x(m instanceof Error?m.message:"Failed to save system prompt")}},T=async()=>{if(window.confirm(n("config:systemPrompt.confirmClear")))try{x(null),r(null),await hs(),d(""),l(""),c(!1),r(n("config:systemPrompt.cleared"))}catch(m){x(m instanceof Error?m.message:"Failed to clear system prompt")}},F=()=>{d(p),c(!1),x(null),r(null)},_=m=>{if(m.key==="Escape"){if(u&&!window.confirm("You have unsaved changes. Close anyway?")){m.preventDefault();return}i()}};return s?e.jsx(Be,{children:e.jsx("div",{className:`modal-overlay ${s?"visible":""}`,onClick:i,children:e.jsxs("div",{className:"system-prompt-modal",onClick:m=>m.stopPropagation(),onKeyDown:_,children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h2",{children:n("config:systemPrompt.title")}),e.jsx("button",{className:"modal-close",onClick:i,"aria-label":"Close",children:"✕"})]}),e.jsx("div",{className:"modal-body",children:a?e.jsxs("div",{className:"loading-state",children:[e.jsx("div",{className:"spinner"}),e.jsx("p",{children:"Loading system prompt..."})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"modal-description",children:n("config:systemPrompt.description")}),N&&e.jsxs("div",{className:"alert alert-error",children:[e.jsx("span",{className:"alert-icon",children:"⚠️"}),N]}),y&&e.jsxs("div",{className:"alert alert-success",children:[e.jsx("span",{className:"alert-icon",children:"✓"}),y]}),e.jsxs("div",{className:"editor-wrapper",children:[e.jsxs("div",{className:"editor-header",children:[e.jsx("label",{htmlFor:"prompt-input",className:"editor-label",children:n("config:systemPrompt.editPrompt")}),e.jsxs("span",{className:"char-count",children:[o.length," ",n("config:systemPrompt.characters")]})]}),e.jsx("textarea",{id:"prompt-input",className:"prompt-editor",value:o,onChange:w,placeholder:n("config:systemPrompt.placeholder"),rows:18,autoFocus:!0}),e.jsx("div",{className:"editor-hint",children:n("config:systemPrompt.hint")})]})]})}),e.jsxs("div",{className:"modal-footer",children:[e.jsx("div",{className:"footer-buttons-left",children:e.jsx("button",{className:"btn btn-danger",onClick:T,disabled:!o||a,children:n("config:systemPrompt.clear")})}),e.jsxs("div",{className:"footer-buttons-right",children:[e.jsx("button",{className:"btn btn-secondary",onClick:i,children:"Close"}),e.jsx("button",{className:"btn btn-secondary",onClick:F,disabled:!u||a,children:n("config:systemPrompt.reset")}),e.jsx("button",{className:"btn btn-primary",onClick:I,disabled:!u||a,children:n("config:systemPrompt.save")})]})]})]})})}):null}const vs=[{value:"auto",label:"Auto",icon:"🕐"},{value:"dawn",label:"Dawn",icon:"🌅"},{value:"day",label:"Day",icon:"☀️"},{value:"dusk",label:"Dusk",icon:"🌇"},{value:"night",label:"Night",icon:"🌙"}],Ns=[{value:"none",label:"Grass",icon:"🌱"},{value:"concrete",label:"Concrete",icon:"🏗️"},{value:"galactic",label:"Galactic",icon:"🌌"},{value:"metal",label:"Metal",icon:"⚙️"},{value:"hex",label:"Hex",icon:"⬡"},{value:"circuit",label:"Circuit",icon:"🔌"},{value:"pokemon-stadium",label:"Pokemon",icon:"🔴"}],ys=[{value:"static",label:"Static",icon:"🧍"},{value:"idle",label:"Idle",icon:"🚶"},{value:"walk",label:"Walk",icon:"🚶‍♂️"},{value:"sprint",label:"Sprint",icon:"🏃"},{value:"jump",label:"Jump",icon:"⬆️"},{value:"fall",label:"Fall",icon:"⬇️"},{value:"crouch",label:"Crouch",icon:"🧎"},{value:"sit",label:"Sit",icon:"🪑"},{value:"die",label:"Die",icon:"💀"},{value:"emote-yes",label:"Yes",icon:"👍"},{value:"emote-no",label:"No",icon:"👎"}],ks=[{value:"normal",label:"Normal",icon:"🎨"},{value:"bw",label:"B&W",icon:"⬛"},{value:"sepia",label:"Sepia",icon:"🟤"},{value:"cool",label:"Cool",icon:"❄️"},{value:"warm",label:"Warm",icon:"🔥"},{value:"neon",label:"Neon",icon:"💜"}],ws=[{key:"showTrees",icon:"🌳",label:"Trees"},{key:"showBushes",icon:"🌿",label:"Bushes"},{key:"showHouse",icon:"🏠",label:"House"},{key:"showLamps",icon:"💡",label:"Lamps"},{key:"showGrass",icon:"🟩",label:"Grass"},{key:"showClouds",icon:"☁️",label:"Clouds"}],Ss=[{value:null,label:"Auto",color:"linear-gradient(135deg, #4a90d9 0%, #0a1a2a 100%)"},{value:"#4a90d9",label:"Day Blue",color:"#4a90d9"},{value:"#0a1a2a",label:"Night",color:"#0a1a2a"},{value:"#ff6b35",label:"Sunset",color:"#ff6b35"},{value:"#1a0a2e",label:"Purple",color:"#1a0a2e"},{value:"#2d5a27",label:"Matrix",color:"#2d5a27"},{value:"#8b0000",label:"Blood",color:"#8b0000"},{value:"#000000",label:"Void",color:"#000000"}],Cs={showTrees:"trees",showBushes:"bushes",showHouse:"house",showLamps:"lamps",showGrass:"grass",showClouds:"clouds"},As={none:"grass","pokemon-stadium":"pokemon"},Ts={"emote-yes":"yes","emote-no":"no"},Is={"":"auto","#4a90d9":"dayBlue","#0a1a2a":"night","#ff6b35":"sunset","#1a0a2e":"purple","#2d5a27":"matrix","#8b0000":"blood","#000000":"void"};function B({checked:s,onChange:i}){return e.jsxs("label",{className:"config-toggle",children:[e.jsx("input",{type:"checkbox",className:"config-toggle-input",checked:s,onChange:n=>i(n.target.checked)}),e.jsx("span",{className:"config-toggle-track",children:e.jsx("span",{className:"config-toggle-thumb"})})]})}function X({options:s,value:i,onChange:n,iconOnly:o=!1}){return e.jsx("div",{className:"chip-selector",children:s.map(d=>e.jsxs("button",{className:`chip ${i===d.value?"active":""}`,onClick:()=>n(d.value),title:d.label,children:[e.jsx("span",{className:"chip-icon",children:d.icon}),!o&&e.jsx("span",{className:"chip-label",children:d.label})]},d.value))})}function v({text:s,query:i}){if(!i.trim())return e.jsx(e.Fragment,{children:s});const n=s.toLowerCase(),o=i.toLowerCase(),d=n.indexOf(o);if(d===-1)return e.jsx(e.Fragment,{children:s});const p=s.slice(0,d),l=s.slice(d,d+i.length),a=s.slice(d+i.length);return e.jsxs(e.Fragment,{children:[p,e.jsx("mark",{className:"search-highlight",children:l}),a]})}const Ps=[{id:"general",title:"General",keywords:["history","hide costs","grid","fps","power saving","performance","limit","editor","external editor","language","idioma","语言","vibration","haptic","intensity","tab title"]},{id:"agentNames",title:"Agent Names",keywords:["agent","names","custom","characters","rename"]},{id:"appearance",title:"Appearance",keywords:["theme","appearance","color","dark","light","style","look"]},{id:"connection",title:"Connection",keywords:["backend","url","auth","token","reconnect","server","api","connect","codex","opencode","binary","path"]},{id:"scene",title:"Scene",keywords:["character","size","indicator","scale","time","dawn","day","dusk","night","auto"]},{id:"terrain",title:"Terrain",keywords:["trees","bushes","house","lamps","grass","clouds","fog","brightness","floor","sky","color","environment","battlefield","size","grid"]},{id:"modelStyle",title:"Agent Model Style",keywords:["saturation","roughness","metalness","glow","emissive","reflections","wireframe","color mode","material","shader"]},{id:"animations",title:"Animations",keywords:["idle","working","animation","walk","run","sprint","jump","sit","crouch"]},{id:"secrets",title:"Secrets",keywords:["secrets","api","key","password","credentials","env","environment"]},{id:"systemPrompt",title:"System Prompt",keywords:["system","prompt","global","instructions","ai","agent","rules","guidelines"]},{id:"data",title:"Data",keywords:["export","import","backup","restore","save","load","json"]},{id:"integrations",title:"Integrations",keywords:["integrations","plugins","gmail","slack","jira","calendar","docx","email","config","setup"]},{id:"workflows",title:"Workflows",keywords:["workflow","automation","state machine","editor","actions","transitions","pipeline"]},{id:"triggers",title:"Triggers",keywords:["trigger","event","webhook","cron","slack","email","jira","matching","fire"]},{id:"monitoring",title:"Monitoring",keywords:["monitoring","logs","triggers","events","history","workflow","traces","audit","timeline"]},{id:"experimental",title:"Experimental",keywords:["experimental","2d","view","voice","assistant","speech","tts","text to speech","echo","prompt","duplicate"]},{id:"about",title:"About",keywords:["about","version","update","credits","github","releases"]}],oe=[{value:"auto",label:"Auto",icon:"🌐"},{value:"en",label:"English",icon:"🇺🇸"},{value:"zh-CN",label:"中文",icon:"🇨🇳"},{value:"es",label:"Español",icon:"🇪🇸"},{value:"hi",label:"हिन्दी",icon:"🇮🇳"},{value:"pt",label:"Português",icon:"🇧🇷"},{value:"ru",label:"Русский",icon:"🇷🇺"},{value:"ja",label:"日本語",icon:"🇯🇵"},{value:"de",label:"Deutsch",icon:"🇩🇪"},{value:"fr",label:"Français",icon:"🇫🇷"},{value:"it",label:"Italiano",icon:"🇮🇹"}];function Es({config:s,onChange:i,searchQuery:n="",onOpenIntegrationsModal:o,onOpenMonitoringModal:d,onOpenWorkflowEditor:p,onOpenTriggerManager:l}){var ge;const{t:a}=U(["config","common"]),f=ie(),[N,x]=g.useState(f.settings.historyLimit),[y,r]=g.useState(()=>Ue()),[u,c]=g.useState(!1),[k,w]=g.useState(()=>z()),[I,T]=g.useState(!1),[F,_]=g.useState(!1),[m,S]=g.useState(""),[Q,Y]=g.useState(!1),[W,J]=g.useState(""),[b,E]=g.useState(!1);g.useEffect(()=>{xs().then(J).catch(()=>{})},[]),g.useEffect(()=>{ps().then(t=>{t!==f.settings.experimentalEchoPrompt&&j.updateSettings({experimentalEchoPrompt:t})}).catch(()=>{})},[]),g.useEffect(()=>ze(t=>{r(t),c(!1)}),[]);const P=vs.map(t=>({...t,label:a(`config:time.${t.value}`)})),R=Ns.map(t=>({...t,label:a(`config:floor.${As[t.value]||t.value}`)})),h=ys.map(t=>({...t,label:a(`config:animation.${Ts[t.value]||t.value}`)})),C=ks.map(t=>({...t,label:a(`config:colorMode.${t.value}`)})),L=ws.map(t=>({...t,label:a(`config:terrain.${Cs[t.key]}`)})),q=Ss.map(t=>({...t,label:a(`config:sky.${Is[t.value??""]}`)})),H=n.trim()?Ps.filter(t=>{const D=n.toLowerCase();return t.title.toLowerCase().includes(D)||t.keywords.some(se=>se.toLowerCase().includes(D))}).map(t=>t.id):null,A=t=>H?H.includes(t):!0,V=f.settings.customAgentNames||[],Ne=V.length>0?V:Ve,ce=()=>{const t=m.trim();t&&!V.includes(t)&&(j.updateSettings({customAgentNames:[...V,t]}),S(""))},ye=t=>{j.updateSettings({customAgentNames:V.filter(D=>D!==t)})},ke=()=>{j.updateSettings({customAgentNames:[]})},we=t=>{r(t),c(!0)},re=()=>{Ke(y),c(!1),ne()},Se=t=>{w(t),T(!0)},de=()=>{qe(He.AUTH_TOKEN,k),T(!1),ne()},Ce=t=>{J(t),E(!0)},me=()=>{bs(W).catch(()=>{}),E(!1)},Z=t=>{i({...s,terrain:{...s.terrain,...t}})},M=t=>{i({...s,modelStyle:{...s.modelStyle,...t}})},ue=t=>{i({...s,animations:{...s.animations,...t}})},Ae=t=>{x(t),j.updateSettings({historyLimit:t})},Te=t=>{const D=s.terrain[t];typeof D=="boolean"&&Z({[t]:!D})},$=n.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"config-section",children:[H&&H.length===0&&e.jsx("div",{className:"config-no-results",children:a("config:noResults",{query:n})}),A("general")&&e.jsxs(O,{title:a("config:sections.general"),storageKey:"general",defaultOpen:!0,forceOpen:$&&A("general"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:general.history"),query:n})}),e.jsx("input",{type:"number",className:"config-input config-input-sm",value:N,onChange:t=>Ae(parseInt(t.target.value)||100),min:50,max:2e3,step:50})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:general.hideCosts"),query:n})}),e.jsx(B,{checked:f.settings.hideCost,onChange:t=>j.updateSettings({hideCost:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:general.grid"),query:n})}),e.jsx(B,{checked:s.gridVisible,onChange:t=>i({...s,gridVisible:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:general.showFPS"),query:n})}),e.jsx(B,{checked:f.settings.showFPS,onChange:t=>j.updateSettings({showFPS:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:general.fpsLimit"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"120",step:"10",value:s.fpsLimit,onChange:t=>i({...s,fpsLimit:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.fpsLimit===0?"∞":s.fpsLimit})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Experimental: Reduce FPS when idle to save power",children:[e.jsx(v,{text:a("config:general.powerSaving"),query:n})," ⚡"]}),e.jsx(B,{checked:f.settings.powerSaving,onChange:t=>j.updateSettings({powerSaving:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:general.vibrationIntensity"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"5",step:"1",value:f.settings.vibrationIntensity,onChange:t=>j.updateSettings({vibrationIntensity:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:f.settings.vibrationIntensity===0?a("config:vibrationValues.off"):f.settings.vibrationIntensity===1?a("config:vibrationValues.ultraLight"):f.settings.vibrationIntensity===2?a("config:vibrationValues.veryLight"):f.settings.vibrationIntensity===3?a("config:vibrationValues.light"):f.settings.vibrationIntensity===4?a("config:vibrationValues.medium"):a("config:vibrationValues.heavy")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:general.externalEditor"),query:n})}),e.jsx("input",{type:"text",className:"config-input",placeholder:a("config:general.externalEditorPlaceholder"),value:f.settings.externalEditorCommand||"",onChange:t=>j.updateSettings({externalEditorCommand:t.target.value})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:general.tabTitle"),query:n})}),e.jsx("input",{type:"text",className:"config-input",placeholder:a("config:general.tabTitlePlaceholder"),value:f.settings.tabTitle||"",onChange:t=>j.updateSettings({tabTitle:t.target.value})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:general.language"),query:n})}),e.jsx(X,{options:oe,value:localStorage.getItem("tide-commander-language-mode")==="manual"?((ge=oe.find(t=>t.value!=="auto"&&ae.language.startsWith(t.value.split("-")[0])))==null?void 0:ge.value)||"en":"auto",onChange:t=>{var D;if(t==="auto"){localStorage.setItem("tide-commander-language-mode","auto");const se=navigator.language,Ie=((D=oe.find(he=>he.value!=="auto"&&se.startsWith(he.value.split("-")[0])))==null?void 0:D.value)||"en";ae.changeLanguage(Ie)}else localStorage.setItem("tide-commander-language-mode","manual"),ae.changeLanguage(t)}})]})]}),A("agentNames")&&e.jsx(O,{title:a("config:sections.agentNames"),storageKey:"agentNames",defaultOpen:!1,forceOpen:$&&A("agentNames"),children:e.jsxs("div",{className:"agent-names-section",children:[e.jsx("span",{className:"config-hint",children:V.length>0?a("config:agentNames.customConfigured",{count:V.length}):a("config:agentNames.usingDefaults")}),e.jsxs("div",{className:"agent-names-input-row",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",placeholder:a("config:agentNames.addPlaceholder"),value:m,onChange:t=>S(t.target.value),onKeyDown:t=>{t.key==="Enter"&&ce()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:ce,disabled:!m.trim(),title:a("config:agentNames.addName"),children:"+"})]}),e.jsx("div",{className:"agent-names-list",children:Ne.map((t,D)=>e.jsxs("div",{className:"agent-name-chip",children:[e.jsx("span",{className:"agent-name-text",children:t}),V.length>0&&e.jsx("button",{className:"agent-name-remove",onClick:()=>ye(t),title:a("common:buttons.remove"),children:"x"})]},`${t}-${D}`))}),V.length>0&&e.jsx("button",{className:"config-btn config-btn-link",onClick:ke,children:a("common:buttons.resetToDefaults")})]})}),A("appearance")&&e.jsx(O,{title:a("config:sections.appearance"),storageKey:"appearance",defaultOpen:!1,forceOpen:$&&A("appearance"),children:e.jsx(cs,{})}),A("connection")&&e.jsxs(O,{title:a("config:sections.connection"),storageKey:"connection",defaultOpen:!1,forceOpen:$&&A("connection"),children:[e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:connection.backendUrl"),query:n})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:y,onChange:t=>we(t.target.value),placeholder:"http://localhost:5174",onKeyDown:t=>{t.key==="Enter"&&u&&re()}}),u&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:re,title:a("config:connection.saveAndReconnect"),children:a("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:a("config:connection.autoDetectHint")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:connection.authToken"),query:n})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:F?"text":"password",className:"config-input config-input-full",value:k,onChange:t=>Se(t.target.value),placeholder:a("config:connection.tokenPlaceholder"),onKeyDown:t=>{t.key==="Enter"&&I&&de()}}),e.jsx("button",{className:"config-btn config-btn-sm",onClick:()=>_(!F),title:a(F?"config:connection.hideToken":"config:connection.showToken"),children:F?"🙈":"👁️"}),I&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:de,title:a("config:connection.saveAndReconnect"),children:a("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:a("config:connection.tokenRequired")})]}),e.jsxs("div",{className:"config-row config-row-stacked",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:connection.codexBinaryPath"),query:n})}),e.jsxs("div",{className:"config-input-group",children:[e.jsx("input",{type:"text",className:"config-input config-input-full",value:W,onChange:t=>Ce(t.target.value),placeholder:a("config:connection.codexBinaryPathPlaceholder"),onKeyDown:t=>{t.key==="Enter"&&b&&me()}}),b&&e.jsx("button",{className:"config-btn config-btn-sm",onClick:me,children:a("common:buttons.apply")})]}),e.jsx("span",{className:"config-hint",children:a("config:connection.codexBinaryPathHint")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("common:buttons.reconnect"),query:n})}),e.jsx("button",{className:"config-btn",onClick:()=>ne(),title:"Force reconnect to server",children:a("common:buttons.reconnect")})]})]}),A("scene")&&e.jsxs(O,{title:a("config:sections.scene"),storageKey:"scene",defaultOpen:!1,forceOpen:$&&A("scene"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:scene.characterSize"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"3.0",step:"0.1",value:s.characterScale,onChange:t=>i({...s,characterScale:parseFloat(t.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.characterScale.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:scene.scale2d",{defaultValue:"2D Scale"}),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale2d,onChange:t=>i({...s,scale2d:parseFloat(t.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale2d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:scene.scale3d",{defaultValue:"3D Scale"}),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.3",max:"2.0",step:"0.1",value:s.scale3d,onChange:t=>i({...s,scale3d:parseFloat(t.target.value)})}),e.jsxs("span",{className:"config-value",children:[s.scale3d.toFixed(1),"x"]})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:scene.show2DTaskLabels",{defaultValue:"Show 2D task labels"}),query:n})}),e.jsx(B,{checked:s.show2DTaskLabels,onChange:t=>i({...s,show2DTaskLabels:t})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:scene.time"),query:n})}),e.jsx(X,{options:P,value:s.timeMode,onChange:t=>i({...s,timeMode:t}),iconOnly:!0})]})]}),A("terrain")&&e.jsxs(O,{title:a("config:sections.terrain"),storageKey:"terrain",defaultOpen:!1,forceOpen:$&&A("terrain"),children:[e.jsx("div",{className:"terrain-icons",children:L.map(t=>e.jsx("button",{className:`terrain-icon-btn ${s.terrain[t.key]?"active":""}`,onClick:()=>Te(t.key),title:t.label,children:t.icon},t.key))}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:terrainSettings.fog"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.terrain.fogDensity,onChange:t=>Z({fogDensity:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.fogDensity===0?a("config:fogValues.off"):s.terrain.fogDensity<=1?a("config:fogValues.low"):a("config:fogValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:terrainSettings.brightness"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0.2",max:"2",step:"0.1",value:s.terrain.brightness,onChange:t=>Z({brightness:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.brightness<=.5?a("config:brightnessValues.dark"):s.terrain.brightness<=1.2?a("config:brightnessValues.normal"):a("config:brightnessValues.bright")})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:terrainSettings.floor"),query:n})}),e.jsx(X,{options:R,value:s.terrain.floorStyle,onChange:t=>Z({floorStyle:t}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:terrainSettings.sky"),query:n})}),e.jsx("div",{className:"sky-color-selector",children:q.map(t=>e.jsx("button",{className:`sky-color-btn ${s.terrain.skyColor===t.value?"active":""}`,onClick:()=>Z({skyColor:t.value}),title:t.label,style:{background:t.color}},t.value??"auto"))})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:terrainSettings.battlefieldSize"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"30",max:"200",step:"10",value:s.terrain.battlefieldSize,onChange:t=>Z({battlefieldSize:parseInt(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.terrain.battlefieldSize})]})]}),A("modelStyle")&&e.jsxs(O,{title:a("config:sections.modelStyle"),storageKey:"modelStyle",defaultOpen:!1,forceOpen:$&&A("modelStyle"),children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:modelStyleSettings.saturation"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"2",step:"0.1",value:s.modelStyle.saturation,onChange:t=>M({saturation:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.saturation<=.3?a("config:saturationValues.gray"):s.modelStyle.saturation<=1.2?a("config:saturationValues.normal"):a("config:saturationValues.vivid")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:modelStyleSettings.roughness"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.roughness,onChange:t=>M({roughness:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.roughness<0?a("config:roughnessValues.auto"):s.modelStyle.roughness<=.3?a("config:roughnessValues.glossy"):s.modelStyle.roughness<=.7?a("config:roughnessValues.normal"):a("config:roughnessValues.matte")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:modelStyleSettings.metalness"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"1",step:"0.1",value:s.modelStyle.metalness,onChange:t=>M({metalness:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.metalness<0?a("config:metalnessValues.auto"):s.modelStyle.metalness<=.3?a("config:metalnessValues.plastic"):s.modelStyle.metalness<=.7?a("config:metalnessValues.mixed"):a("config:metalnessValues.metal")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:modelStyleSettings.glow"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"0",max:"1",step:"0.05",value:s.modelStyle.emissiveBoost,onChange:t=>M({emissiveBoost:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.emissiveBoost<=.1?a("config:glowValues.off"):s.modelStyle.emissiveBoost<=.4?a("config:glowValues.low"):s.modelStyle.emissiveBoost<=.7?a("config:glowValues.med"):a("config:glowValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:modelStyleSettings.reflections"),query:n})}),e.jsx("input",{type:"range",className:"config-slider",min:"-1",max:"2",step:"0.1",value:s.modelStyle.envMapIntensity,onChange:t=>M({envMapIntensity:parseFloat(t.target.value)})}),e.jsx("span",{className:"config-value",children:s.modelStyle.envMapIntensity<0?a("config:reflectionValues.auto"):s.modelStyle.envMapIntensity<=.3?a("config:reflectionValues.low"):s.modelStyle.envMapIntensity<=1?a("config:reflectionValues.normal"):a("config:reflectionValues.high")})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:modelStyleSettings.wireframe"),query:n})}),e.jsx(B,{checked:s.modelStyle.wireframe,onChange:t=>M({wireframe:t})})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:modelStyleSettings.colorMode"),query:n})}),e.jsx(X,{options:C,value:s.modelStyle.colorMode,onChange:t=>M({colorMode:t}),iconOnly:!0})]})]}),A("animations")&&e.jsxs(O,{title:a("config:sections.animations"),storageKey:"animations",defaultOpen:!1,forceOpen:$&&A("animations"),children:[e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:animationSettings.idle"),query:n})}),e.jsx(X,{options:h,value:s.animations.idleAnimation,onChange:t=>ue({idleAnimation:t}),iconOnly:!0})]}),e.jsxs("div",{className:"config-group",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:animationSettings.working"),query:n})}),e.jsx(X,{options:h,value:s.animations.workingAnimation,onChange:t=>ue({workingAnimation:t}),iconOnly:!0})]})]}),A("secrets")&&e.jsx(O,{title:a("config:sections.secrets"),storageKey:"secrets",defaultOpen:!1,forceOpen:$&&A("secrets"),children:e.jsx(is,{})}),A("systemPrompt")&&e.jsx(O,{title:a("config:sections.systemPrompt"),storageKey:"systemPrompt",defaultOpen:!1,forceOpen:$&&A("systemPrompt"),children:e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:e.jsx(v,{text:a("config:systemPrompt.title"),query:n})}),e.jsx("button",{className:"config-button",onClick:()=>Y(!0),children:a("config:systemPrompt.editPrompt")})]})}),A("data")&&e.jsx(O,{title:a("config:sections.data"),storageKey:"data",defaultOpen:!1,forceOpen:$&&A("data"),children:e.jsx(ls,{})}),A("integrations")&&e.jsx(O,{title:"Integrations",storageKey:"integrations",defaultOpen:!1,forceOpen:$&&A("integrations"),children:e.jsx(ms,{onOpenModal:t=>o==null?void 0:o(t)})}),A("workflows")&&e.jsxs(O,{title:"Workflows",storageKey:"workflows",defaultOpen:!1,forceOpen:$&&A("workflows"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(v,{text:"Create and manage automated workflow pipelines with visual state machine editor",query:n})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>p==null?void 0:p(),children:"Open Workflow Editor"})})]}),A("triggers")&&e.jsxs(O,{title:"Triggers",storageKey:"triggers",defaultOpen:!1,forceOpen:$&&A("triggers"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(v,{text:"Create and manage event-driven triggers that fire agents with templates",query:n})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>l==null?void 0:l(),children:"Open Trigger Manager"})})]}),A("monitoring")&&e.jsxs(O,{title:"Monitoring",storageKey:"monitoring",defaultOpen:!1,forceOpen:$&&A("monitoring"),children:[e.jsx("div",{className:"config-row",children:e.jsx("span",{className:"config-label",children:e.jsx(v,{text:"View event logs, trigger history, workflow traces, and system stats",query:n})})}),e.jsx("div",{className:"config-row",children:e.jsx("button",{className:"config-button",onClick:()=>d==null?void 0:d(),children:"Open Monitoring & Logs"})})]}),A("experimental")&&e.jsxs(O,{title:a("config:sections.experimental"),storageKey:"experimental",defaultOpen:!1,forceOpen:$&&A("experimental"),children:[e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Lightweight 2D top-down view for better performance",children:[e.jsx(v,{text:a("config:experimental.2dView"),query:n})," 🗺️"]}),e.jsx(B,{checked:f.settings.experimental2DView,onChange:t=>j.updateSettings({experimental2DView:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Voice assistant for hands-free agent control",children:[e.jsx(v,{text:a("config:experimental.voiceAssistant"),query:n})," 🎤"]}),e.jsx(B,{checked:f.settings.experimentalVoiceAssistant,onChange:t=>j.updateSettings({experimentalVoiceAssistant:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsxs("span",{className:"config-label",title:"Text-to-speech for reading agent responses",children:[e.jsx(v,{text:a("config:experimental.tts"),query:n})," 🔊"]}),e.jsx(B,{checked:f.settings.experimentalTTS,onChange:t=>j.updateSettings({experimentalTTS:t})})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",title:"Duplicate system prompt for improved LLM attention coverage. Increases input token usage.",children:e.jsx(v,{text:a("config:experimental.echoPrompt"),query:n})}),e.jsx(B,{checked:f.settings.experimentalEchoPrompt,onChange:async t=>{j.updateSettings({experimentalEchoPrompt:t});try{await fs(t)}catch(D){console.error("Failed to sync echo prompt setting to server:",D)}}})]}),e.jsx("span",{className:"config-hint",children:a("config:experimental.hint")})]}),A("about")&&e.jsx(O,{title:a("config:sections.about"),storageKey:"about",defaultOpen:!1,forceOpen:$&&A("about"),children:e.jsx(rs,{})})]}),e.jsx(js,{isOpen:Q,onClose:()=>Y(!1)})]})}function _s({onConfigChange:s,onToolChange:i,config:n,isOpen:o,onClose:d,onOpenBuildingModal:p,onOpenAreaExplorer:l,onOpenIntegrationsModal:a,onOpenMonitoringModal:f,onOpenWorkflowEditor:N,onOpenTriggerManager:x}){const{t:y}=U(["config","common"]),r=ie(),u=Array.from(r.areas.values()),c=Array.from(r.buildings.values()),[k,w]=g.useState(""),I=g.useRef(null);if(g.useEffect(()=>{const m=S=>{S.key==="Escape"&&o&&d()};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[o,d]),g.useEffect(()=>{if(o&&I.current){const m=setTimeout(()=>{var S;(S=I.current)==null||S.focus()},50);return()=>clearTimeout(m)}},[o]),!o)return null;const T=m=>{const S=r.activeTool===m?null:m;i(S)},F=m=>{j.selectArea(r.selectedAreaId===m?null:m),i("select")},_=(m,S)=>{m.stopPropagation(),j.deleteArea(S)};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"toolbox-backdrop",onClick:d}),e.jsxs("aside",{className:"toolbox",children:[e.jsxs("div",{className:"toolbox-header",children:[e.jsx("span",{children:y("config:title")}),e.jsx("button",{className:"toolbox-close-btn",onClick:d,title:y("common:buttons.close"),children:"×"})]}),e.jsxs("div",{className:"toolbox-search",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),e.jsx("input",{ref:I,type:"text",placeholder:y("config:searchPlaceholder"),value:k,onChange:m=>w(m.target.value),className:"toolbox-search-input"}),k&&e.jsx("button",{className:"toolbox-search-clear",onClick:()=>w(""),children:"×"})]}),e.jsxs("div",{className:"toolbox-content",children:[e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsxs(O,{title:y("config:areas.title",{count:u.length}),storageKey:"areas",children:[e.jsxs("div",{className:"tool-buttons",children:[e.jsx("button",{className:`tool-btn ${r.activeTool==="select"?"active":""}`,onClick:()=>T("select"),title:y("config:tools.select"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"})})})}),e.jsx("button",{className:`tool-btn ${r.activeTool==="rectangle"?"active":""}`,onClick:()=>T("rectangle"),title:y("config:tools.rectangle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"})})})}),e.jsx("button",{className:`tool-btn ${r.activeTool==="circle"?"active":""}`,onClick:()=>T("circle"),title:y("config:tools.circle"),children:e.jsx("span",{children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("circle",{cx:"12",cy:"12",r:"9"})})})})]}),e.jsx("div",{className:"areas-list",children:u.length===0?e.jsx("div",{className:"areas-empty",children:y("config:areas.drawToCreate")}):u.map(m=>e.jsx(Xe,{area:m,isSelected:r.selectedAreaId===m.id,onClick:()=>F(m.id),onDelete:S=>_(S,m.id)},m.id))})]})}),r.selectedAreaId&&e.jsx(os,{area:r.areas.get(r.selectedAreaId),onClose:()=>j.selectArea(null),onOpenFolder:l}),e.jsx("div",{className:"toolbox-section toolbox-section-collapsible",children:e.jsx(O,{title:y("config:buildings.title",{count:c.length}),storageKey:"buildings",headerExtra:e.jsx("button",{className:"add-building-btn",onClick:m=>{m.stopPropagation(),p==null||p()},title:y("config:buildings.addBuilding"),children:"+"}),children:e.jsx("div",{className:"buildings-list",children:c.length===0?e.jsx("div",{className:"buildings-empty",children:y("config:buildings.clickToAdd")}):c.map(m=>e.jsx(Qe,{building:m,isSelected:r.selectedBuildingIds.has(m.id),onClick:()=>{j.selectBuilding(r.selectedBuildingIds.has(m.id)?null:m.id)},onEdit:()=>p==null?void 0:p(m.id)},m.id))})})}),r.selectedBuildingIds.size===1&&(()=>{const m=Array.from(r.selectedBuildingIds)[0],S=r.buildings.get(m);return S?e.jsx(es,{building:S,onClose:()=>j.selectBuilding(null),onOpenModal:()=>p==null?void 0:p(m)}):null})(),e.jsx(Es,{config:n,onChange:s,searchQuery:k,onOpenIntegrationsModal:a,onOpenMonitoringModal:f,onOpenWorkflowEditor:N,onOpenTriggerManager:x})]})]})]})}export{_s as Toolbox};