Skip to content

Commit cd29039

Browse files
fix(owpenbot): repair settings and devtools wiring (anomalyco#310)
1 parent 2e6b2e9 commit cd29039

9 files changed

Lines changed: 304 additions & 64 deletions

File tree

‎packages/app/src/app/app.tsx‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ import {
123123
readOpencodeConfig,
124124
writeOpencodeConfig,
125125
openworkServerInfo,
126+
owpenbotInfo,
126127
type OpenworkServerInfo,
128+
type OwpenbotInfo,
127129
} from "./lib/tauri";
128130
import {
129131
createOpenworkServerClient,
@@ -229,6 +231,7 @@ export default function App() {
229231
const [openworkServerCheckedAt, setOpenworkServerCheckedAt] = createSignal<number | null>(null);
230232
const [openworkServerWorkspaceId, setOpenworkServerWorkspaceId] = createSignal<string | null>(null);
231233
const [openworkServerHostInfo, setOpenworkServerHostInfo] = createSignal<OpenworkServerInfo | null>(null);
234+
const [owpenbotInfoState, setOwpenbotInfoState] = createSignal<OwpenbotInfo | null>(null);
232235
const [openworkAuditEntries, setOpenworkAuditEntries] = createSignal<OpenworkAuditEntry[]>([]);
233236
const [openworkAuditStatus, setOpenworkAuditStatus] = createSignal<"idle" | "loading" | "error">("idle");
234237
const [openworkAuditError, setOpenworkAuditError] = createSignal<string | null>(null);
@@ -417,6 +420,32 @@ export default function App() {
417420
});
418421
});
419422

423+
createEffect(() => {
424+
if (!isTauriRuntime()) return;
425+
if (!developerMode()) {
426+
setOwpenbotInfoState(null);
427+
return;
428+
}
429+
430+
let active = true;
431+
432+
const run = async () => {
433+
try {
434+
const info = await owpenbotInfo();
435+
if (active) setOwpenbotInfoState(info);
436+
} catch {
437+
if (active) setOwpenbotInfoState(null);
438+
}
439+
};
440+
441+
run();
442+
const interval = window.setInterval(run, 10_000);
443+
onCleanup(() => {
444+
active = false;
445+
window.clearInterval(interval);
446+
});
447+
});
448+
420449
const [client, setClient] = createSignal<Client | null>(null);
421450
const [connectedVersion, setConnectedVersion] = createSignal<string | null>(
422451
null
@@ -3375,6 +3404,7 @@ export default function App() {
33753404
openworkAuditStatus: openworkAuditStatus(),
33763405
openworkAuditError: openworkAuditError(),
33773406
engineInfo: workspaceStore.engine(),
3407+
owpenbotInfo: owpenbotInfoState(),
33783408
updateOpenworkServerSettings,
33793409
resetOpenworkServerSettings,
33803410
testOpenworkServerConnection,

‎packages/app/src/app/lib/tauri.ts‎

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,18 @@ export type OwpenbotStatus = {
432432
opencode: OwpenbotOpencodeStatus;
433433
};
434434

435+
export type OwpenbotInfo = {
436+
running: boolean;
437+
workspacePath: string | null;
438+
opencodeUrl: string | null;
439+
qrData: string | null;
440+
whatsappLinked: boolean;
441+
telegramConfigured: boolean;
442+
pid: number | null;
443+
lastStdout: string | null;
444+
lastStderr: string | null;
445+
};
446+
435447
export type OwpenbotQr = {
436448
qr: string; // base64 encoded
437449
format: "png" | "ascii";
@@ -447,29 +459,16 @@ export type OwpenbotPairingRequest = {
447459
// Owpenbot functions - call Tauri commands that wrap owpenbot CLI
448460
export async function getOwpenbotStatus(): Promise<OwpenbotStatus | null> {
449461
try {
450-
const result = await invoke<Record<string, unknown>>("owpenbot_status");
451-
// Transform CLI JSON output to OwpenbotStatus type
452-
return {
453-
running: (result.running as boolean) ?? false,
454-
config: (result.config as string) ?? "",
455-
whatsapp: {
456-
linked: (result.whatsapp as Record<string, unknown>)?.linked as boolean ?? false,
457-
dmPolicy: ((result.whatsapp as Record<string, unknown>)?.dmPolicy as OwpenbotWhatsAppStatus["dmPolicy"]) ?? "pairing",
458-
allowFrom: ((result.whatsapp as Record<string, unknown>)?.allowFrom as string[]) ?? [],
459-
},
460-
telegram: {
461-
configured: (result.telegram as Record<string, unknown>)?.configured as boolean ?? false,
462-
enabled: (result.telegram as Record<string, unknown>)?.enabled as boolean ?? false,
463-
},
464-
opencode: {
465-
url: (result.opencode as Record<string, unknown>)?.url as string ?? "",
466-
},
467-
};
462+
return await invoke<OwpenbotStatus>("owpenbot_status");
468463
} catch {
469464
return null;
470465
}
471466
}
472467

468+
export async function owpenbotInfo(): Promise<OwpenbotInfo> {
469+
return invoke<OwpenbotInfo>("owpenbot_info");
470+
}
471+
473472
export async function getOwpenbotQr(): Promise<OwpenbotQr | null> {
474473
try {
475474
const qrBase64 = await invoke<string>("owpenbot_qr");
@@ -486,7 +485,7 @@ export async function setOwpenbotDmPolicy(
486485
policy: OwpenbotWhatsAppStatus["dmPolicy"],
487486
): Promise<ExecResult> {
488487
try {
489-
await invoke("owpenbot_config_set", { key: "whatsapp.dmPolicy", value: policy });
488+
await invoke("owpenbot_config_set", { key: "channels.whatsapp.dmPolicy", value: policy });
490489
return { ok: true, status: 0, stdout: "", stderr: "" };
491490
} catch (e) {
492491
return { ok: false, status: 1, stdout: "", stderr: String(e) };
@@ -495,8 +494,10 @@ export async function setOwpenbotDmPolicy(
495494

496495
export async function setOwpenbotAllowlist(allowlist: string[]): Promise<ExecResult> {
497496
try {
498-
// Join allowlist into comma-separated string for CLI
499-
await invoke("owpenbot_config_set", { key: "whatsapp.allowFrom", value: allowlist.join(",") });
497+
await invoke("owpenbot_config_set", {
498+
key: "channels.whatsapp.allowFrom",
499+
value: JSON.stringify(allowlist),
500+
});
500501
return { ok: true, status: 0, stdout: "", stderr: "" };
501502
} catch (e) {
502503
return { ok: false, status: 1, stdout: "", stderr: String(e) };
@@ -505,7 +506,7 @@ export async function setOwpenbotAllowlist(allowlist: string[]): Promise<ExecRes
505506

506507
export async function setOwpenbotTelegramToken(token: string): Promise<ExecResult> {
507508
try {
508-
await invoke("owpenbot_config_set", { key: "telegram.token", value: token });
509+
await invoke("owpenbot_config_set", { key: "channels.telegram.token", value: token });
509510
return { ok: true, status: 0, stdout: "", stderr: "" };
510511
} catch (e) {
511512
return { ok: false, status: 1, stdout: "", stderr: String(e) };
@@ -514,14 +515,22 @@ export async function setOwpenbotTelegramToken(token: string): Promise<ExecResul
514515

515516
export async function getOwpenbotPairingRequests(): Promise<OwpenbotPairingRequest[]> {
516517
try {
517-
const result = await invoke<Record<string, unknown>>("owpenbot_pairing_list");
518-
const requests = (result.requests as Array<Record<string, unknown>>) ?? [];
519-
return requests.map((r) => ({
520-
code: r.code as string,
521-
peerId: r.peerId as string,
522-
platform: r.platform as "whatsapp" | "telegram",
523-
timestamp: r.timestamp as number,
524-
}));
518+
const result = await invoke<unknown>("owpenbot_pairing_list");
519+
const requests = Array.isArray(result) ? result : [];
520+
return requests
521+
.filter((entry): entry is Record<string, unknown> => Boolean(entry && typeof entry === "object"))
522+
.map((entry) => {
523+
const channel = String(entry.channel ?? "whatsapp");
524+
const createdAt = String(entry.createdAt ?? "");
525+
const platform: "whatsapp" | "telegram" = channel === "telegram" ? "telegram" : "whatsapp";
526+
return {
527+
code: String(entry.code ?? ""),
528+
peerId: String(entry.peerId ?? ""),
529+
platform,
530+
timestamp: createdAt ? Date.parse(createdAt) : Date.now(),
531+
};
532+
})
533+
.filter((entry) => entry.code && entry.peerId);
525534
} catch {
526535
return [];
527536
}

‎packages/app/src/app/pages/dashboard.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
import type { McpDirectoryInfo } from "../constants";
1212
import { formatRelativeTime, normalizeDirectoryPath } from "../utils";
1313
import type { OpenworkAuditEntry, OpenworkServerCapabilities, OpenworkServerSettings, OpenworkServerStatus } from "../lib/openwork-server";
14-
import type { EngineInfo, OpenworkServerInfo, WorkspaceInfo } from "../lib/tauri";
14+
import type { EngineInfo, OpenworkServerInfo, OwpenbotInfo, WorkspaceInfo } from "../lib/tauri";
1515

1616
import Button from "../components/button";
1717
import OpenWorkLogo from "../components/openwork-logo";
@@ -57,6 +57,7 @@ export type DashboardViewProps = {
5757
openworkAuditStatus: "idle" | "loading" | "error";
5858
openworkAuditError: string | null;
5959
engineInfo: EngineInfo | null;
60+
owpenbotInfo: OwpenbotInfo | null;
6061
updateOpenworkServerSettings: (next: OpenworkServerSettings) => void;
6162
resetOpenworkServerSettings: () => void;
6263
testOpenworkServerConnection: (next: OpenworkServerSettings) => Promise<boolean>;
@@ -875,6 +876,7 @@ export default function DashboardView(props: DashboardViewProps) {
875876
openworkAuditStatus={props.openworkAuditStatus}
876877
openworkAuditError={props.openworkAuditError}
877878
engineInfo={props.engineInfo}
879+
owpenbotInfo={props.owpenbotInfo}
878880
updateOpenworkServerSettings={props.updateOpenworkServerSettings}
879881
resetOpenworkServerSettings={props.resetOpenworkServerSettings}
880882
testOpenworkServerConnection={props.testOpenworkServerConnection}

‎packages/app/src/app/pages/settings.tsx‎

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import TextInput from "../components/text-input";
77
import SettingsKeybinds, { type KeybindSetting } from "../components/settings-keybinds";
88
import { ChevronDown, HardDrive, MessageCircle, RefreshCcw, Shield, Smartphone, X } from "lucide-solid";
99
import type { OpenworkAuditEntry, OpenworkServerCapabilities, OpenworkServerSettings, OpenworkServerStatus } from "../lib/openwork-server";
10-
import type { EngineInfo, OpenworkServerInfo, OwpenbotStatus, OwpenbotPairingRequest
10+
import type {
11+
EngineInfo,
12+
OpenworkServerInfo,
13+
OwpenbotInfo,
14+
OwpenbotStatus,
15+
OwpenbotPairingRequest,
1116
} from "../lib/tauri";
1217
import {
1318
getOwpenbotStatus,
@@ -35,6 +40,7 @@ export type SettingsViewProps = {
3540
openworkAuditStatus: "idle" | "loading" | "error";
3641
openworkAuditError: string | null;
3742
engineInfo: EngineInfo | null;
43+
owpenbotInfo: OwpenbotInfo | null;
3844
updateOpenworkServerSettings: (next: OpenworkServerSettings) => void;
3945
resetOpenworkServerSettings: () => void;
4046
testOpenworkServerConnection: (next: OpenworkServerSettings) => Promise<boolean>;
@@ -550,6 +556,18 @@ export default function SettingsView(props: SettingsViewProps) {
550556
: "bg-gray-4/60 text-gray-11 border-gray-7/50";
551557
});
552558

559+
const owpenbotStatusLabel = createMemo(() => {
560+
if (!isTauriRuntime()) return "Unavailable";
561+
return props.owpenbotInfo?.running ? "Running" : "Offline";
562+
});
563+
564+
const owpenbotStatusStyle = createMemo(() => {
565+
if (!isTauriRuntime()) return "bg-gray-4/60 text-gray-11 border-gray-7/50";
566+
return props.owpenbotInfo?.running
567+
? "bg-green-7/10 text-green-11 border-green-7/20"
568+
: "bg-gray-4/60 text-gray-11 border-gray-7/50";
569+
});
570+
553571
const openworkAuditStatusLabel = createMemo(() => {
554572
if (!props.openworkServerWorkspaceId) return "Unavailable";
555573
if (props.openworkAuditStatus === "loading") return "Loading";
@@ -601,6 +619,16 @@ export default function SettingsView(props: SettingsViewProps) {
601619
return props.openworkServerHostInfo.lastStderr?.trim() || "No stderr captured yet.";
602620
};
603621

622+
const owpenbotStdout = () => {
623+
if (!isTauriRuntime()) return "Available in the desktop app.";
624+
return props.owpenbotInfo?.lastStdout?.trim() || "No stdout captured yet.";
625+
};
626+
627+
const owpenbotStderr = () => {
628+
if (!isTauriRuntime()) return "Available in the desktop app.";
629+
return props.owpenbotInfo?.lastStderr?.trim() || "No stderr captured yet.";
630+
};
631+
604632
const buildOpenworkSettings = () => ({
605633
...props.openworkServerSettings,
606634
urlOverride: openworkUrl().trim() || undefined,
@@ -1234,7 +1262,7 @@ export default function SettingsView(props: SettingsViewProps) {
12341262
<div class="text-xs text-gray-10">Sidecar health, capabilities, and audit trail.</div>
12351263
</div>
12361264

1237-
<div class="grid md:grid-cols-2 gap-4">
1265+
<div class="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
12381266
<div class="bg-gray-1 p-4 rounded-xl border border-gray-6 space-y-3">
12391267
<div class="flex items-center justify-between gap-3">
12401268
<div>
@@ -1301,6 +1329,41 @@ export default function SettingsView(props: SettingsViewProps) {
13011329
</div>
13021330
</div>
13031331
</div>
1332+
1333+
<div class="bg-gray-1 p-4 rounded-xl border border-gray-6 space-y-3">
1334+
<div class="flex items-center justify-between gap-3">
1335+
<div>
1336+
<div class="text-sm font-medium text-gray-12">Owpenbot sidecar</div>
1337+
<div class="text-xs text-gray-10">Messaging bridge service.</div>
1338+
</div>
1339+
<div class={`text-xs px-2 py-1 rounded-full border ${owpenbotStatusStyle()}`}>
1340+
{owpenbotStatusLabel()}
1341+
</div>
1342+
</div>
1343+
<div class="space-y-1">
1344+
<div class="text-[11px] text-gray-7 font-mono truncate">
1345+
{props.owpenbotInfo?.opencodeUrl?.trim() || "OpenCode URL unavailable"}
1346+
</div>
1347+
<div class="text-[11px] text-gray-7 font-mono truncate">
1348+
{props.owpenbotInfo?.workspacePath?.trim() || "No workspace directory"}
1349+
</div>
1350+
<div class="text-[11px] text-gray-7 font-mono truncate">PID: {props.owpenbotInfo?.pid ?? "—"}</div>
1351+
</div>
1352+
<div class="grid gap-2">
1353+
<div>
1354+
<div class="text-[11px] text-gray-9 mb-1">Last stdout</div>
1355+
<pre class="text-xs text-gray-12 whitespace-pre-wrap break-words max-h-24 overflow-auto bg-gray-2/50 border border-gray-6 rounded-lg p-2">
1356+
{owpenbotStdout()}
1357+
</pre>
1358+
</div>
1359+
<div>
1360+
<div class="text-[11px] text-gray-9 mb-1">Last stderr</div>
1361+
<pre class="text-xs text-gray-12 whitespace-pre-wrap break-words max-h-24 overflow-auto bg-gray-2/50 border border-gray-6 rounded-lg p-2">
1362+
{owpenbotStderr()}
1363+
</pre>
1364+
</div>
1365+
</div>
1366+
</div>
13041367
</div>
13051368

13061369
<div class="bg-gray-1 p-4 rounded-xl border border-gray-6 space-y-3">

0 commit comments

Comments
 (0)