Files
1f5b6143d6 Enforce shared, client, and server plugin SDK boundaries (#4347)
* fix(plugins): keep React out of the server plugin host

* fix(plugins): align SDK guidance and tests with runtime boundaries

* fix(plugin): loosen the react peer to ~19.1.0

The plugin SDK pins its react peer to exactly 19.1.0, and that pin is
what a downstream `npm i -g @getpaseo/cli` resolves against. So every
user ends up with react 19.1.0 in their global node_modules, where
corporate dependency scanners flag it: the CVE-2025-55182 advisory range
covers 19.1.0 even though the vulnerability itself lives in
react-server-dom-webpack/-parcel/-turbopack, none of which the CLI
installs. The user is then left hand-patching node_modules or
uninstalling Paseo.

Widening the peer to ~19.1.0 lets a downstream install pick the latest
19.1.x patch (19.1.9 today) while this repo stays on 19.1.0, which the
root override still pins.

Keeping the repo itself on 19.1.0 is deliberate. react-native 0.81.5
embeds a 19.1.0 Paper renderer that hard-throws "Incompatible React
versions" on any exact mismatch, and it is reachable from Fabric builds
too: RendererImplementation.js requires the Paper shim unconditionally
in findNodeHandle, unstable_batchedUpdates, sendAccessibilityEvent and
three other entry points, and react-native-gesture-handler re-exports
findNodeHandle. Bumping the app's react is therefore not safe until
react-native moves.

The published CLI tree contains no react-native, so downstream installs
are not subject to that constraint.

Supersedes the earlier 19.1.5/19.1.9 version-bump approach on this
branch, which would have broken the mobile app.

* Enforce example import ownership including client types

* Update Nix dependency hash for plugin peer metadata

* Group plugin APIs under client and server entry trees

* Resolve plugin type dependencies through declarations

* Validate declarations for implicit plugin type imports

* Preserve optional imports and validate declaration references

* Refresh Nix hash for plugin declaration resolver

* Canonicalize plugin paths consistently on Windows

* Normalize plugin ownership paths across resolver boundaries

---------

Co-authored-by: liujin0506 <liujin0506@qq.com>
Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
2026-09-07 23:42:28 +02:00

150 lines
4.8 KiB
TypeScript

import { useCallback, useMemo, useState } from "react";
import { Text, View } from "react-native";
import { useSettings, type PluginSurfaceProps } from "@getpaseo/plugin/client";
import type { SettingsState } from "@getpaseo/plugin/client";
import {
SettingsAction,
SettingsCard,
SettingsInput,
SettingsRow,
SettingsSection,
SettingsSelect,
SettingsSwitch,
} from "@getpaseo/plugin/client/ui";
import { preferences } from "../shared/preferences";
const grouping = [
{ label: "Project", value: "project" },
{ label: "Workspace", value: "workspace" },
{ label: "None", value: "none" },
] as const;
type Preferences = Extract<SettingsState<typeof preferences.schema>, { status: "ready" }>;
function TitleEditor({ settings, onClose }: { settings: Preferences; onClose(): void }) {
// Keep the draft's revision so another client's save produces a conflict.
const [draft, setDraft] = useState(() => ({
values: settings.values,
revision: settings.revision,
}));
const changeTitle = useCallback(
(title: string) =>
setDraft((current) => ({ ...current, values: { ...current.values, title } })),
[],
);
const saveTitle = useCallback(async () => {
if (await settings.save(draft.values, draft.revision)) onClose();
}, [settings, draft, onClose]);
return (
<SettingsCard>
<SettingsInput
label="Monitor title"
initialValue={draft.values.title}
onChangeText={changeTitle}
disabled={settings.saving}
error={settings.saveError}
/>
<SettingsAction
label="Title changes"
actionLabel="Save title"
disabled={settings.saving}
onPress={saveTitle}
/>
<SettingsAction
label="Discard title changes"
actionLabel="Discard"
disabled={settings.saving}
onPress={onClose}
/>
</SettingsCard>
);
}
function DisplayControls({
settings,
theme,
}: {
settings: Preferences;
theme: PluginSurfaceProps["theme"];
}) {
const style = useMemo(() => ({ color: theme.colors.foreground }), [theme]);
const [editingTitle, setEditingTitle] = useState(false);
const closeTitle = useCallback(() => {
setEditingTitle(false);
void settings.reload();
}, [settings]);
const toggleTitle = useCallback(() => setEditingTitle((value) => !value), []);
const changeGrouping = useCallback(
(groupBy: Preferences["values"]["groupBy"]) => {
void settings.save({ ...settings.values, groupBy }, settings.revision);
},
[settings],
);
const changeMetadata = useCallback(
(showMetadata: boolean) => {
void settings.save({ ...settings.values, showMetadata }, settings.revision);
},
[settings],
);
return (
<SettingsSection title="Display">
<SettingsCard>
<SettingsSelect
label="Group agents by"
value={settings.values.groupBy}
options={grouping}
disabled={settings.saving}
onValueChange={changeGrouping}
/>
<SettingsSwitch
label="Show metadata"
value={settings.values.showMetadata}
disabled={settings.saving}
onValueChange={changeMetadata}
/>
<SettingsAction
label="Monitor title"
actionLabel={editingTitle ? "Close editor" : "Edit title"}
disabled={settings.saving}
onPress={toggleTitle}
/>
</SettingsCard>
{editingTitle ? <TitleEditor settings={settings} onClose={closeTitle} /> : null}
{settings.saveError && !editingTitle ? (
<Text accessibilityRole="alert" style={style}>
{settings.saveError}
</Text>
) : null}
<SettingsRow label="Preview">
<View>
<Text style={style}>{settings.values.title}</Text>
<Text style={style}>Grouped by {settings.values.groupBy}</Text>
<Text style={style}>
{settings.values.showMetadata ? "Metadata visible" : "Metadata hidden"}
</Text>
</View>
</SettingsRow>
</SettingsSection>
);
}
export function DisplaySettings({ theme }: PluginSurfaceProps) {
const settings = useSettings(preferences);
const style = useMemo(() => ({ color: theme.colors.foreground }), [theme]);
if (settings.status === "loading") return <Text style={style}>Loading settings…</Text>;
if (settings.status !== "ready")
return (
<SettingsSection title="Display">
<Text style={style}>{settings.error}</Text>
<SettingsAction label="Try again" actionLabel="Reload" onPress={settings.reload} />
{settings.status === "invalid" ? (
<SettingsAction
label="Restore default settings"
actionLabel="Reset"
onPress={settings.reset}
/>
) : null}
</SettingsSection>
);
return <DisplayControls settings={settings} theme={theme} />;
}