Files
paseo/plugin-examples/hosts/client/hosts.tsx
Mohamed Boudra 6ce6f4c961 Let plugins discover hosts and use host-targeted SDK clients (#4971)
* feat(plugins): expose hosts and host-targeted SDK clients

* test(plugins): verify exact cross-host observation cleanup

* fix(plugins): reacquire explicitly disposed host clients

* docs(plugins): clarify host client usage and lifecycle

* docs(plugins): use theme colors in host discovery example
2026-09-16 22:45:18 +02:00

60 lines
1.7 KiB
TypeScript

import {
getPaseoClient,
useHosts,
usePaseo,
type PluginSurfaceProps,
} from "@getpaseo/plugin/client";
import { useCallback, useMemo, useState } from "react";
import { Pressable, Text, View } from "react-native";
export function Hosts({ theme }: PluginSurfaceProps) {
const hosts = useHosts();
const selected = usePaseo();
const [result, setResult] = useState("");
const list = useCallback(
async (serverId?: string) => {
try {
const client = serverId ? getPaseoClient(serverId) : selected;
const { entries } = await client.agents.list();
setResult(`${serverId ?? "Selected host"}: ${entries.length} agents`);
} catch (error) {
setResult(error instanceof Error ? error.message : String(error));
}
},
[selected],
);
const styles = useMemo(
() => ({
root: { padding: 16, gap: 12, backgroundColor: theme.colors.surface0 },
text: { color: theme.colors.foreground },
}),
[theme],
);
const listSelected = useCallback(() => {
void list();
}, [list]);
const rows = hosts.map((host) => ({
serverId: host.serverId,
label: host.label,
status: host.status,
onPress() {
void list(host.serverId);
},
}));
return (
<View style={styles.root}>
<Pressable accessibilityRole="button" onPress={listSelected}>
<Text style={styles.text}>List selected host agents</Text>
</Pressable>
{rows.map((host) => (
<Pressable key={host.serverId} accessibilityRole="button" onPress={host.onPress}>
<Text style={styles.text}>
{host.label}: {host.status}
</Text>
</Pressable>
))}
<Text style={styles.text}>{result}</Text>
</View>
);
}