Files
Claw3D/src/features/agents/components/GatewayConnectScreen.tsx
T
gsknnftClaude Sonnet 4.6Cursor AgentLuke The DevElias Pfeffercopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>iamlukethedev
083c146aac feat: add runtime seam, Hermes adapter support, and demo gateway mode (#89)
* fix: include kanbanImmersive in immersiveOverlayActive calculation

When Kanban board is open, HUD elements (camera preset buttons, edit toolbar, overlays) should be suppressed. The kanbanImmersive flag was defined but not included in the immersiveOverlayActive condition, causing HUD elements to remain visible.

This fix adds kanbanImmersive to the immersiveOverlayActive calculation so HUD elements are properly hidden when the Kanban board is open.

Co-authored-by: Luke The Dev <iamlukethedev@users.noreply.github.com>

* Fix: Hide mini status bar when Kanban immersive overlay is open

Wraps the bottom-left mini status bar (showing agent stats, vibe score, and
control hints) with !immersiveOverlayActive check to match the behavior of
other HUD elements like camera controls and toolbar.

This ensures the status bar is properly hidden when the Kanban board or any
other immersive overlay is active, maintaining a clean immersive experience.

Co-authored-by: Luke The Dev <iamlukethedev@users.noreply.github.com>

* chore: drop unrelated package-lock line from branch

Co-authored-by: Luke The Dev <iamlukethedev@users.noreply.github.com>

* universal-backend-plan

* backend-neutral runtime seam

* package.json update

* feat: add Hermes gateway adapter as alternative to OpenClaw

Adds a WebSocket adapter that lets Claw3D connect to a Hermes AI agent
runtime without any changes to the frontend. The adapter implements the
full Claw3D gateway protocol and bridges it to the Hermes HTTP API.

Changes:
- server/hermes-gateway-adapter.js: WebSocket bridge implementing the
  Claw3D gateway protocol against the Hermes HTTP API. Supports all
  core methods (agents, sessions, chat streaming, cron, config, files,
  approvals) and multi-agent orchestration via spawn_agent/delegate_task
  tools. Persists conversation history to ~/.hermes/clawd3d-history.json.
- scripts/clawd3d-start.sh: All-in-one startup script that launches
  Hermes, the adapter, and the Next.js dev server with auto port
  conflict resolution. Alias as `claw3d` for convenience.
- src/features/office/hooks/useCronAgents.ts: Hook that polls the
  gateway for cron-scheduled agents and surfaces them in the 3D office.
- package.json: adds `hermes-adapter` npm script
- .env.example: documents Hermes config vars
- docs/hermes-gateway.md: setup guide and protocol reference

Usage:
  npm run hermes-adapter   # start adapter (connect to http://localhost:8642)
  npm run dev              # start Claw3D, point browser at localhost:3000
  # or: bash scripts/clawd3d-start.sh  (starts everything automatically)

Both OpenClaw and Hermes are supported simultaneously — the gateway URL
in NEXT_PUBLIC_GATEWAY_URL determines which backend Claw3D connects to.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: add read_agent_context tool for cross-agent coordination

Agents can now read each other's conversation history via the
read_agent_context tool, enabling the orchestrator to check what
a sub-agent has done before re-delegating work.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat: wire Hermes office UX and role-aware runtime updates

* feature update - demomode & hermes adapter

* fix lint blockers

* lintfix #2

* fix: stabilize retro office camera preset callbacks

* Initial plan

* fix: stabilize retro office overview preset hooks

Agent-Logs-Url: https://github.com/gsknnft/Claw3D/sessions/9cc71555-591e-44cf-aec4-25affbdcb405

Co-authored-by: gsknnft <123185582+gsknnft@users.noreply.github.com>

* feat: add truthful backend selection, Hermes adapter hardening, and demo gateway mode

* fix: address bugbot review and finalize backend selection

* fixed - onboarding and hermes calls

* office systems roadmap

* feat specs in docs

* specs ready

* feat: continue custom runtime seam and gateway alignment

* custom lane wired

* feat: add custom runtime provider path and office runtime alignment

* runtime fixes

* fix lukes findings

* fix lukes findings #2

* stable UI & connect screen page -> overlay

* better baseline for connection

* stable providers & ui rendering

* best launch yet

* nearly no gateway on reconnect

* auto reconnect last state

* fix: preserve selected runtime across reconnects

Keep backend selection aligned with the operator's chosen runtime instead of reviving a mismatched last-known-good adapter, and keep custom runtimes prompting for reconnect when Studio cannot auto-connect them.

Made-with: Cursor

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Luke The Dev <iamlukethedev@users.noreply.github.com>
Co-authored-by: Elias Pfeffer <eliaspfeffer@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: iamlukethedev <lucas.guilherme@smartwayslfl.com>
2026-04-02 15:27:24 -05:00

340 lines
13 KiB
TypeScript

import { useMemo, useState } from "react";
import { Check, Copy, Eye, EyeOff } from "lucide-react";
import type { GatewayStatus } from "@/lib/gateway/GatewayClient";
import { isLocalGatewayUrl } from "@/lib/gateway/local-gateway";
import type { StudioGatewayAdapterType, StudioGatewaySettings } from "@/lib/studio/settings";
import { RunningAvatarLoader } from "@/features/agents/components/RunningAvatarLoader";
type GatewayConnectScreenProps = {
gatewayUrl: string;
token: string;
selectedAdapterType: StudioGatewayAdapterType;
activeAdapterType: StudioGatewayAdapterType;
localGatewayDefaults: StudioGatewaySettings | null;
status: GatewayStatus;
error: string | null;
showApprovalHint: boolean;
onGatewayUrlChange: (value: string) => void;
onTokenChange: (value: string) => void;
onAdapterTypeChange: (value: StudioGatewayAdapterType) => void;
onUseLocalDefaults: () => void;
onConnect: () => void;
};
const resolveLocalGatewayPort = (gatewayUrl: string): number => {
try {
const parsed = new URL(gatewayUrl);
const port = Number(parsed.port);
if (Number.isFinite(port) && port > 0) return port;
} catch {}
return 18789;
};
export const GatewayConnectScreen = ({
gatewayUrl,
token,
selectedAdapterType,
activeAdapterType,
localGatewayDefaults,
status,
error,
showApprovalHint,
onGatewayUrlChange,
onTokenChange,
onAdapterTypeChange,
onUseLocalDefaults,
onConnect,
}: GatewayConnectScreenProps) => {
const [copyStatus, setCopyStatus] = useState<"idle" | "copied" | "failed">("idle");
const [showToken, setShowToken] = useState(false);
const tokenOptional =
selectedAdapterType === "hermes" ||
selectedAdapterType === "demo" ||
selectedAdapterType === "custom";
const isLocal = useMemo(() => isLocalGatewayUrl(gatewayUrl), [gatewayUrl]);
const localPort = useMemo(() => resolveLocalGatewayPort(gatewayUrl), [gatewayUrl]);
const localGatewayCommand = useMemo(
() => `npx openclaw gateway run --bind loopback --port ${localPort} --verbose`,
[localPort]
);
const localGatewayCommandPnpm = useMemo(
() => `pnpm openclaw gateway run --bind loopback --port ${localPort} --verbose`,
[localPort]
);
const localDemoCommand = useMemo(
() => `npm run demo-gateway`,
[]
);
const useDemoPreset = () => {
onAdapterTypeChange("demo");
};
const useHermesPreset = () => {
onAdapterTypeChange("hermes");
};
const useOpenClawPreset = () => {
onAdapterTypeChange("openclaw");
};
const useCustomPreset = () => {
onAdapterTypeChange("custom");
};
const statusCopy = useMemo(() => {
if (status === "connecting" && isLocal) {
return `Local gateway detected on port ${localPort}. Connecting…`;
}
if (status === "connecting") {
return "Connecting to remote gateway…";
}
if (isLocal) {
return "No local gateway found.";
}
return "Not connected to a gateway.";
}, [isLocal, localPort, status]);
const connectDisabled = status === "connecting";
const connectLabel = connectDisabled ? "Connecting…" : "Connect";
const statusDotClass =
status === "connected"
? "ui-dot-status-connected"
: status === "connecting"
? "ui-dot-status-connecting"
: "ui-dot-status-disconnected";
const copyLocalCommand = async () => {
try {
await navigator.clipboard.writeText(localGatewayCommand);
setCopyStatus("copied");
window.setTimeout(() => setCopyStatus("idle"), 1200);
} catch {
setCopyStatus("failed");
window.setTimeout(() => setCopyStatus("idle"), 1800);
}
};
const commandField = (
<div className="space-y-1.5">
<div className="ui-command-surface flex items-center gap-2 rounded-md px-3 py-2">
<code className="min-w-0 flex-1 overflow-x-auto whitespace-nowrap font-mono text-[12px] text-[var(--command-fg)]">
{localGatewayCommand}
</code>
<button
type="button"
className="ui-btn-icon ui-command-copy h-7 w-7 shrink-0"
onClick={copyLocalCommand}
aria-label="Copy local gateway command"
title="Copy command"
>
{copyStatus === "copied" ? <Check className="h-3.5 w-3.5" /> : <Copy className="h-3.5 w-3.5" />}
</button>
</div>
{copyStatus === "copied" ? (
<p className="text-xs text-muted-foreground">Copied</p>
) : copyStatus === "failed" ? (
<p className="ui-text-danger text-xs">Could not copy command.</p>
) : (
<p className="text-xs leading-snug text-muted-foreground">
In a source checkout, use <span className="font-mono text-foreground">{localGatewayCommandPnpm}</span>.
</p>
)}
</div>
);
const remoteForm = (
<div className="mt-2.5 flex flex-col gap-3">
<label className="flex flex-col gap-1 text-[11px] font-medium text-foreground/90">
Upstream URL
<input
className="ui-input h-10 rounded-md px-4 font-sans text-sm text-foreground outline-none"
type="text"
value={gatewayUrl}
onChange={(event) => onGatewayUrlChange(event.target.value)}
placeholder="wss://your-gateway.example.com"
spellCheck={false}
/>
</label>
<div className="space-y-0.5 text-xs text-muted-foreground">
<p className="font-medium text-foreground">Using Tailscale?</p>
<p>
URL: <span className="font-mono">wss://&lt;your-tailnet-host&gt;</span>
</p>
</div>
<label className="flex flex-col gap-1 text-[11px] font-medium text-foreground/90">
{tokenOptional ? "Upstream token (optional)" : "Upstream token"}
<div className="relative">
<input
className="ui-input h-10 w-full rounded-md px-4 pr-10 font-sans text-sm text-foreground outline-none"
type={showToken ? "text" : "password"}
value={token}
onChange={(event) => onTokenChange(event.target.value)}
placeholder={tokenOptional ? "optional token" : "gateway token"}
spellCheck={false}
/>
<button
type="button"
className="ui-btn-icon absolute inset-y-0 right-1 my-auto h-8 w-8 border-transparent bg-transparent text-muted-foreground hover:bg-transparent hover:text-foreground"
aria-label={showToken ? "Hide token" : "Show token"}
onClick={() => setShowToken((prev) => !prev)}
>
{showToken ? (
<EyeOff className="h-4 w-4 transition-transform duration-150" />
) : (
<Eye className="h-4 w-4 transition-transform duration-150" />
)}
</button>
</div>
</label>
<button
type="button"
className="ui-btn-primary mt-1 h-11 w-full px-4 text-xs font-semibold tracking-[0.05em] disabled:cursor-not-allowed disabled:opacity-60"
onClick={onConnect}
disabled={connectDisabled || !gatewayUrl.trim()}
>
{connectLabel}
</button>
{status === "connecting" ? (
<div className="inline-flex items-center gap-1.5 text-xs text-muted-foreground">
<RunningAvatarLoader size={16} trackWidth={32} inline />
Connecting
</div>
) : null}
{error ? <p className="ui-text-danger text-xs leading-snug">{error}</p> : null}
{showApprovalHint && selectedAdapterType === "openclaw" ? (
<div className="rounded-md border border-border bg-muted/40 px-3 py-3 text-xs text-muted-foreground">
<p className="leading-snug">
If the first connection attempt did not work, go to your OpenClaw computer and approve this
device:
</p>
<code className="mt-2 block overflow-x-auto whitespace-nowrap rounded-md bg-[var(--command-bg)] px-2.5 py-2 font-mono text-[11px] text-[var(--command-fg)]">
openclaw devices approve --latest
</code>
</div>
) : null}
</div>
);
return (
<div className="mx-auto flex min-h-0 w-full max-w-[820px] flex-1 flex-col gap-5">
<div className="ui-card px-4 py-2">
<div className="flex items-center gap-2">
{status === "connecting" ? (
<RunningAvatarLoader size={18} trackWidth={36} inline />
) : (
<span
className={`h-2.5 w-2.5 ${statusDotClass}`}
/>
)}
<p className="text-sm font-semibold text-foreground">{statusCopy}</p>
</div>
</div>
<div className="ui-card px-4 py-5 sm:px-6">
<div>
<p className="font-mono text-[10px] font-medium tracking-[0.06em] text-muted-foreground">
Remote gateway (recommended)
</p>
<p className="mt-2 text-sm text-foreground/90">
Choose a backend, then connect to its gateway URL.
</p>
<p className="mt-2 font-mono text-[11px] text-muted-foreground">
Selected backend: {selectedAdapterType} | Active backend: {activeAdapterType}
</p>
<p className="mt-1 text-xs text-muted-foreground">
Each backend keeps its own saved URL and token.
</p>
<div className="mt-3 flex flex-wrap gap-2">
<button
type="button"
className="ui-btn-secondary px-3 py-1.5 text-[11px] font-semibold tracking-[0.05em]"
onClick={useDemoPreset}
>
Demo backend
</button>
<button
type="button"
className="ui-btn-secondary px-3 py-1.5 text-[11px] font-semibold tracking-[0.05em]"
onClick={useHermesPreset}
>
Hermes backend
</button>
<button
type="button"
className="ui-btn-secondary px-3 py-1.5 text-[11px] font-semibold tracking-[0.05em]"
onClick={useCustomPreset}
>
Custom backend
</button>
<button
type="button"
className="ui-btn-secondary px-3 py-1.5 text-[11px] font-semibold tracking-[0.05em]"
onClick={useOpenClawPreset}
>
OpenClaw backend
</button>
</div>
</div>
{remoteForm}
</div>
<div className="ui-card px-4 py-4 sm:px-6 sm:py-5">
<div className="space-y-1.5">
<p className="font-mono text-[10px] font-semibold tracking-[0.06em] text-muted-foreground">
Run locally (optional)
</p>
<p className="text-sm text-foreground/90">
Start a local gateway process on this machine, then connect.
</p>
</div>
<div className="mt-3 space-y-3">
{commandField}
<div className="rounded-md border border-border bg-muted/30 px-3 py-3">
<p className="text-xs font-medium text-foreground">Just want to see the office?</p>
<p className="mt-1 text-xs leading-snug text-muted-foreground">
Run <span className="font-mono text-foreground">{localDemoCommand}</span> to start a built-in mock gateway with demo agents.
Then choose <span className="font-mono text-foreground">Demo backend</span> and connect.
</p>
</div>
<div className="rounded-md border border-border bg-muted/30 px-3 py-3">
<p className="text-xs font-medium text-foreground">Using Hermes locally?</p>
<p className="mt-1 text-xs leading-snug text-muted-foreground">
Run <span className="font-mono text-foreground">npm run hermes-adapter</span>, then choose
<span className="font-mono text-foreground"> Hermes backend</span>. The default local URL is
<span className="font-mono text-foreground"> ws://localhost:18789</span>.
</p>
</div>
<div className="rounded-md border border-border bg-muted/30 px-3 py-3">
<p className="text-xs font-medium text-foreground">Using a custom runtime locally?</p>
<p className="mt-1 text-xs leading-snug text-muted-foreground">
Choose <span className="font-mono text-foreground">Custom backend</span> and point the URL
at your orchestrator or runtime boundary, for example
<span className="font-mono text-foreground"> http://localhost:7770</span>. Direct custom
runtime chat flows are not wired into Studio yet in this slice, but the provider seam and
metadata scaffold are now in place.
</p>
</div>
{localGatewayDefaults ? (
<div className="ui-input rounded-md px-3 py-3">
<div className="space-y-2">
<p className="text-xs text-muted-foreground">
Use token from <span className="font-mono">~/.openclaw/openclaw.json</span>.
</p>
<p className="font-mono text-[11px] text-foreground">
{localGatewayDefaults.url}
</p>
<button
type="button"
className="ui-btn-secondary h-9 w-full px-3 text-xs font-semibold tracking-[0.05em]"
onClick={onUseLocalDefaults}
>
Use local defaults
</button>
</div>
</div>
) : null}
</div>
</div>
</div>
);
};