diff --git a/apps/desktop/package.json b/apps/desktop/package.json index ab5c82bec3..aa9f78f091 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -1,6 +1,6 @@ { "name": "@t3tools/desktop", - "version": "0.0.40", + "version": "0.0.41-hermes.2", "private": true, "type": "module", "main": "dist-electron/main.cjs", diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx index 6c63791ae4..2d735e21d2 100644 --- a/apps/mobile/src/Stack.tsx +++ b/apps/mobile/src/Stack.tsx @@ -63,6 +63,7 @@ import { } from "./features/settings/SettingsOpenSourceLicensesRouteScreen"; import { SettingsProjectGroupingRouteScreen } from "./features/settings/SettingsProjectGroupingRouteScreen"; import { SettingsProvidersRouteScreen } from "./features/settings/SettingsProvidersRouteScreen"; +import { SettingsHermesRouteScreen } from "./features/settings/SettingsHermesRouteScreen"; import { UsageLimitAccountScreen } from "./features/usage/UsageLimitsPooled"; import { UsageRouteScreen } from "./features/usage/UsageRouteScreen"; import { SettingsRouteScreen } from "./features/settings/SettingsRouteScreen"; @@ -172,6 +173,13 @@ const SettingsContentStack = createNativeStackNavigator({ title: "Providers", }, }), + SettingsHermes: createNativeStackScreen({ + screen: SettingsHermesRouteScreen, + linking: "hermes", + options: { + title: "Hermes", + }, + }), SettingsEnvironmentNew: createNativeStackScreen({ screen: ConnectionsNewRouteScreen, linking: "environment-new", diff --git a/apps/mobile/src/features/hermes/HermesWorkspace.tsx b/apps/mobile/src/features/hermes/HermesWorkspace.tsx index 21e54fd44a..d959789a16 100644 --- a/apps/mobile/src/features/hermes/HermesWorkspace.tsx +++ b/apps/mobile/src/features/hermes/HermesWorkspace.tsx @@ -11,6 +11,7 @@ import { hermesRecord, hermesText, hermesArray, + hermesErrorMessage, hermesPretty, hermesCronJobs, hermesCronEditor, @@ -43,11 +44,15 @@ import { environmentServerConfigsAtom } from "../../state/server"; import { useAtomCommand } from "../../state/use-atom-command"; import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry"; import { useSafeAreaInsets } from "react-native-safe-area-context"; +import { useNavigation } from "@react-navigation/native"; +import { SymbolView } from "../../components/AppSymbol"; -type Section = "chat" | "skills" | "memories" | "cron" | "logs"; +type Section = "skills" | "memories" | "cron" | "logs"; const inputClass = "rounded-xl border border-border bg-sheet px-3 py-3 text-foreground"; const HermesForegroundContext = createContext(true); +const prettyHermesCause = (cause: Cause.Cause) => hermesErrorMessage(Cause.pretty(cause)); + function Action({ label, onPress, @@ -141,17 +146,13 @@ function Detail({ } export function HermesMobileWorkspace({ mode = "full" }: { mode?: "full" | "list" | "detail" }) { + const navigation = useNavigation(); const configs = useAtomValue(environmentServerConfigsAtom); const { savedConnectionsById } = useSavedRemoteConnections(); const saved = useAtomValue(hermesConnectionAtom); const setConnection = useAtomSet(hermesConnectionAtom); const selection = useAtomValue(hermesSelectionAtom); const setSelection = useAtomSet(hermesSelectionAtom); - const [sectionState, setSectionState] = useState<{ session: typeof selection; section: Section }>( - { session: selection, section: "chat" }, - ); - const section = sectionState.session === selection ? sectionState.section : "chat"; - const setSection = (section: Section) => setSectionState({ session: selection, section }); const [foreground, setForeground] = useState(AppState.currentState === "active"); const [busy, setBusy] = useState(false); const [error, setError] = useState(""); @@ -213,7 +214,7 @@ export function HermesMobileWorkspace({ mode = "full" }: { mode?: "full" | "list id: hermesText(hermesRecord(result.value.data).stored_session_id), title: "New Hermes chat", }); - else if (AsyncResult.isFailure(result)) setError(Cause.pretty(result.cause)); + else if (AsyncResult.isFailure(result)) setError(prettyHermesCause(result.cause)); }; const createRequested = useEffectEvent(create); const canCreate = mode !== "detail" && connection !== null && foreground && !busy; @@ -228,6 +229,29 @@ export function HermesMobileWorkspace({ mode = "full" }: { mode?: "full" | "list {mode !== "detail" && ( + {mode === "list" && ( + + Hermes + + navigation.navigate("SettingsSheet", { + screen: "SettingsContent", + params: { screen: "SettingsHermes" }, + }) + } + > + + + + )} {choices.length > 1 && ( @@ -252,32 +276,14 @@ export function HermesMobileWorkspace({ mode = "full" }: { mode?: "full" | "list {mode === "full" && selection && ( setSelection(null)} /> )} - void create()} - /> + {(mode !== "full" || Platform.OS !== "android") && ( + void create()} + /> + )} - {mode === "full" && !selection && ( - - - {(["chat", "skills", "memories", "cron", "logs"] as const).map((item) => ( - setSection(item)} - /> - ))} - - - )} {error && } )} @@ -285,51 +291,24 @@ export function HermesMobileWorkspace({ mode = "full" }: { mode?: "full" | "list Enable Hermes in Settings → Providers on a connected environment. No project is needed. - ) : mode === "list" || (mode === "full" && !selection && section === "chat") ? ( + ) : mode === "list" || (mode === "full" && !selection) ? ( setSection("chat")} /> ) : ( <> {selection?.title ?? "Hermes"} - {(mode === "detail" || selection) && ( - - - {(["chat", "skills", "memories", "cron", "logs"] as const).map((item) => ( - setSection(item)} - /> - ))} - - - )} - {section === "chat" ? ( - selection ? ( - - ) : ( - Choose a session or start a new task. - ) - ) : ( - + ) : ( + Choose a session or start a new task. )} )} @@ -338,13 +317,94 @@ export function HermesMobileWorkspace({ mode = "full" }: { mode?: "full" | "list ); } -function HermesSessionList({ - connection, - onOpen, -}: { - connection: HermesConnection; - onOpen: () => void; -}) { +export function HermesSettingsMobileWorkspace() { + const configs = useAtomValue(environmentServerConfigsAtom); + const { savedConnectionsById } = useSavedRemoteConnections(); + const saved = useAtomValue(hermesConnectionAtom); + const setConnection = useAtomSet(hermesConnectionAtom); + const [section, setSection] = useState
("skills"); + const [foreground, setForeground] = useState(AppState.currentState === "active"); + const choices = hermesConnections( + configs, + new Map( + Object.values(savedConnectionsById).map((connection) => [ + connection.environmentId, + connection.environmentLabel, + ]), + ), + ); + const connection = + choices.find( + (choice) => + choice.environmentId === saved?.environmentId && + choice.target.instanceId === saved.target.instanceId, + ) ?? + choices[0] ?? + null; + useEffect(() => { + const listener = AppState.addEventListener("change", (state) => + setForeground(state === "active"), + ); + return () => listener.remove(); + }, []); + useEffect(() => { + if ( + connection && + (saved?.environmentId !== connection.environmentId || + saved.target.instanceId !== connection.target.instanceId) + ) + setConnection(connection); + }, [connection, saved, setConnection]); + return ( + + + + {choices.length > 1 && ( + + + {choices.map((choice) => ( + setConnection(choice)} + /> + ))} + + + )} + + + {(["skills", "memories", "cron", "logs"] as const).map((item) => ( + setSection(item)} + /> + ))} + + + + {connection ? ( + + ) : ( + + Enable Hermes in Settings → Providers on a connected environment. + + )} + + + ); +} + +function HermesSessionList({ connection }: { connection: HermesConnection }) { const foreground = useContext(HermesForegroundContext); const registry = useContext(RegistryContext); const query = (foreground ? hermes.live : hermes.read)({ @@ -352,6 +412,7 @@ function HermesSessionList({ input: { ...connection.target, resource: "sessions" }, }); const result = useAtomValue(query); + const selection = useAtomValue(hermesSelectionAtom); const setSelection = useAtomSet(hermesSelectionAtom); const read = useAtomCommand(hermes.request, { reportFailure: false }); const [older, setOlder] = useState>([]); @@ -363,11 +424,11 @@ function HermesSessionList({ row.title.toLowerCase().includes(search.toLowerCase()))} keyExtractor={(row) => `${row.profile}:${row.id}`} - contentContainerStyle={{ padding: 12, gap: 8, flexGrow: 1 }} + contentContainerStyle={{ paddingHorizontal: 12, flexGrow: 1 }} refreshing={false} onRefresh={() => registry.refresh(query)} ListHeaderComponent={ - + - - Live Hermes sessions · updates every 5 seconds - {AsyncResult.isFailure(result) && ( <> - + registry.refresh(query)} /> )} @@ -395,7 +453,7 @@ function HermesSessionList({ : "No Hermes sessions. Use New task to start chatting."} } - renderItem={({ item }) => ( + renderItem={({ item, index }) => ( { @@ -410,11 +468,10 @@ function HermesSessionList({ id: item.id, title: item.title, }); - onOpen(); }} - className="min-h-16 rounded-xl bg-sheet p-3" + className={`min-h-16 justify-center border-b border-separator px-3 py-2.5 active:bg-subtle ${selection?.id === item.id ? "bg-thread-selected" : ""} ${index === combined.length - 1 ? "border-b-0" : ""}`} > - + {item.title} @@ -436,7 +493,7 @@ function HermesSessionList({ }); if (AsyncResult.isSuccess(next)) setOlder((value) => [...value, ...hermesSessions(next.value.data)]); - else if (AsyncResult.isFailure(next)) setError(Cause.pretty(next.cause)); + else if (AsyncResult.isFailure(next)) setError(prettyHermesCause(next.cause)); }} /> ) : null @@ -494,7 +551,7 @@ function HermesLogin({ setPassword(""); setBusy(false); if (AsyncResult.isSuccess(result)) onSuccess(); - else if (AsyncResult.isFailure(result)) setError(Cause.pretty(result.cause)); + else if (AsyncResult.isFailure(result)) setError(prettyHermesCause(result.cause)); }} /> {error && } @@ -540,7 +597,7 @@ function HermesChat({ connection, id }: { connection: HermesConnection; id: stri environmentId: connection.environmentId, input: { ...connection.target, action: "attach", id }, }).then((next) => { - if (active && AsyncResult.isFailure(next)) setError(Cause.pretty(next.cause)); + if (active && AsyncResult.isFailure(next)) setError(prettyHermesCause(next.cause)); }); return () => { active = false; @@ -567,7 +624,7 @@ function HermesChat({ connection, id }: { connection: HermesConnection; id: stri setCommands([]); setOutput(action === "command" ? hermesPretty(next.value.data) : ""); registry.refresh(query); - } else if (AsyncResult.isFailure(next)) setError(Cause.pretty(next.cause)); + } else if (AsyncResult.isFailure(next)) setError(prettyHermesCause(next.cause)); }; return ( - {AsyncResult.isFailure(result) && } + {AsyncResult.isFailure(result) && ( + + )} {messages.length === 100 && hasEarlier && ( mergeHermesMessages(page, value, messages)); setHasEarlier(page.length === 100); - } else if (AsyncResult.isFailure(next)) setError(Cause.pretty(next.cause)); + } else if (AsyncResult.isFailure(next)) setError(prettyHermesCause(next.cause)); }} /> )} @@ -659,7 +718,7 @@ function HermesChat({ connection, id }: { connection: HermesConnection; id: stri fields: { requestId: request.id, response }, }, }); - if (AsyncResult.isFailure(next)) setError(Cause.pretty(next.cause)); + if (AsyncResult.isFailure(next)) setError(prettyHermesCause(next.cause)); }} /> ))} @@ -726,7 +785,7 @@ function HermesChat({ connection, id }: { connection: HermesConnection; id: stri if (AsyncResult.isSuccess(next)) { setCommands(hermesArray(hermesRecord(next.value.data).items)); setCompletion({ input, replaceFrom: hermesRecord(next.value.data).replace_from }); - } else if (AsyncResult.isFailure(next)) setError(Cause.pretty(next.cause)); + } else if (AsyncResult.isFailure(next)) setError(prettyHermesCause(next.cause)); }} /> @@ -828,7 +887,7 @@ function HermesManager({ section, }: { connection: HermesConnection; - section: Exclude; + section: Section; }) { const foreground = useContext(HermesForegroundContext); const registry = useContext(RegistryContext); @@ -866,7 +925,7 @@ function HermesManager({ if (AsyncResult.isSuccess(next)) { setEditor(null); registry.refresh(query); - } else if (AsyncResult.isFailure(next)) setError(Cause.pretty(next.cause)); + } else if (AsyncResult.isFailure(next)) setError(prettyHermesCause(next.cause)); }; return ( ))} - {AsyncResult.isFailure(result) && } + {AsyncResult.isFailure(result) && ( + + )} {error && } {section === "logs" && ( <> @@ -1010,7 +1071,7 @@ function HermesManager({ if (AsyncResult.isSuccess(next)) { const content = hermesText(hermesRecord(next.value.data).content); setEditor({ id, text: content, original: content }); - } else if (AsyncResult.isFailure(next)) setError(Cause.pretty(next.cause)); + } else if (AsyncResult.isFailure(next)) setError(prettyHermesCause(next.cause)); }} /> {section === "cron" && ( diff --git a/apps/mobile/src/features/home/HomeRouteScreen.tsx b/apps/mobile/src/features/home/HomeRouteScreen.tsx index 1c23964e59..d7d6414fd3 100644 --- a/apps/mobile/src/features/home/HomeRouteScreen.tsx +++ b/apps/mobile/src/features/home/HomeRouteScreen.tsx @@ -1,6 +1,6 @@ import * as Arr from "effect/Array"; -import { useAtomValue } from "@effect/atom-react"; -import { conversationSourceAtom } from "@t3tools/client-runtime/hermes"; +import { useAtomSet, useAtomValue } from "@effect/atom-react"; +import { conversationSourceAtom, hermesNewSessionAtom } from "@t3tools/client-runtime/hermes"; import { ConversationTabs, HermesMobileWorkspace } from "../hermes/HermesWorkspace"; import { AndroidScreenHeader } from "../../components/AndroidScreenHeader"; import * as Order from "effect/Order"; @@ -31,6 +31,7 @@ import { getConnectionAwareBrandHeaderOptions } from "./WorkspaceConnectionTitle export function HomeRouteScreen() { const conversationSource = useAtomValue(conversationSourceAtom); + const requestHermesSession = useAtomSet(hermesNewSessionAtom); const { width: windowWidth } = useWindowDimensions(); const { layout } = useAdaptiveWorkspaceLayout(); const projects = useProjects(); @@ -112,7 +113,7 @@ export function HomeRouteScreen() { // In split layouts the persistent sidebar IS the thread list — Home becomes // an empty detail pane so selecting a thread never transitions layouts. if (conversationSource === "hermes" && !layout.usesSplitView) { - return ( + const content = ( navigation.navigate("SettingsSheet", { screen: "SettingsContent", - params: { screen: "Settings" }, + params: { screen: "SettingsHermes" }, }), }, ]} @@ -137,6 +138,13 @@ export function HomeRouteScreen() { ); + return Platform.OS === "android" ? ( + requestHermesSession((value) => value + 1)}> + {content} + + ) : ( + content + ); } if (layout.usesSplitView) { diff --git a/apps/mobile/src/features/settings/SettingsHermesRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsHermesRouteScreen.tsx new file mode 100644 index 0000000000..e857ff8d28 --- /dev/null +++ b/apps/mobile/src/features/settings/SettingsHermesRouteScreen.tsx @@ -0,0 +1,21 @@ +import { useNavigation } from "@react-navigation/native"; +import { Platform, View } from "react-native"; + +import { AndroidScreenHeader } from "../../components/AndroidScreenHeader"; +import { NativeStackScreenOptions } from "../../native/StackHeader"; +import { HermesSettingsMobileWorkspace } from "../hermes/HermesWorkspace"; + +export function SettingsHermesRouteScreen() { + const navigation = useNavigation(); + return ( + + {Platform.OS === "android" ? ( + <> + + navigation.goBack()} /> + + ) : null} + + + ); +} diff --git a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx index 62219b41aa..f1fdb95795 100644 --- a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx @@ -128,6 +128,7 @@ function LocalSettingsRouteScreen() { target="SettingsEnvironments" /> + @@ -512,6 +513,7 @@ function ConfiguredSettingsRouteScreen() { target="SettingsEnvironments" /> + ) => hermesErrorMessage(Cause.pretty(cause)); export function ConversationTabs() { const source = useAtomValue(conversationSourceAtom); @@ -87,6 +92,7 @@ function useHermesConnection() { } export function HermesSidebar() { + const navigate = useNavigate(); const { choices, connection, setConnection } = useHermesConnection(); const selection = useAtomValue(hermesSelectionAtom); const setSelection = useAtomSet(hermesSelectionAtom); @@ -107,31 +113,41 @@ export function HermesSidebar() { }, [keybindings, newSession]); return (
- +
+ + +
{connection ? ( { @@ -212,16 +228,10 @@ function HermesSessionList({ value={search} onChange={(event) => setSearch(event.target.value)} /> - {error && } {AsyncResult.isFailure(result) ? ( <> - + registry.refresh(atom)} /> ) : null} @@ -230,7 +240,7 @@ function HermesSessionList({ .filter((row) => row.title.toLowerCase().includes(search.toLowerCase())) .map((row) => (
); } @@ -432,7 +475,7 @@ function HermesChat({ connection, id }: { connection: HermesConnection; id: stri input: { ...connection.target, action: "attach", id }, }).then((next) => { if (!active) return; - if (AsyncResult.isFailure(next)) setError(Cause.pretty(next.cause)); + if (AsyncResult.isFailure(next)) setError(prettyHermesCause(next.cause)); }); return () => { active = false; @@ -459,7 +502,7 @@ function HermesChat({ connection, id }: { connection: HermesConnection; id: stri setCommands([]); setOutput(action === "command" ? hermesPretty(next.value.data) : ""); registry.refresh(query); - } else if (AsyncResult.isFailure(next)) setError(Cause.pretty(next.cause)); + } else if (AsyncResult.isFailure(next)) setError(prettyHermesCause(next.cause)); }; const eventRows = AsyncResult.isSuccess(events) ? events.value : []; const messages = AsyncResult.isSuccess(result) ? hermesMessages(result.value.data) : []; @@ -467,7 +510,7 @@ function HermesChat({ connection, id }: { connection: HermesConnection; id: stri return (
- {AsyncResult.isFailure(result) && } + {AsyncResult.isFailure(result) && } {messages.length === 100 && hasEarlier && (