Файли
openidea/src/features/plugins/secrets.tsx
T
1c5a92f952 feat(plugins): plugin system with extension points, consent, Wasm runtime and plugin API 1.0 (#971)
A plugin system built on WebAssembly components (wasmtime, WASI p2), with a
typed WIT API (`openidea:[email protected]`) and a Rust SDK, shipped as a preview.

- Extension points declared in `plugin.toml` (commands, languages, themes,
  icon themes, menus, key bindings, status items, settings, views, custom
  editors, file icons and templates, run detectors, editor providers),
  validated before anything takes effect and projected onto the workbench's
  own registries: plugin themes and file icon themes are chosen in
  Settings › Appearance and Quick Switch, plugin shortcuts are edited in
  Settings › Keymap, plugin problems are grouped in Settings › Inspections.
- Capabilities with risk levels and consent at install, pinned `process:`
  programs, secrets in the OS keychain.
- Runtime: one thread per active plugin, fuel/time/memory budgets, soft and
  hard deadlines on the editing path, cancellation, crash backoff, idle
  reclaim, a precompiled-component cache; remote projects run code plugins on
  `openidea-server`.
- Web views and custom editors with a sandboxed page, a document bridge
  joined to the text editor's undo history, and split or preview layouts.
- Distribution: signed `.oiplugin` packages, a static marketplace index with
  revocation, versioned installs with rollback, install from a `.zip` or a
  folder. The release workflow signs and publishes the official plugins and
  their index, which released builds use as the default marketplace.
- Official plugins: String Tools, Key Promoter, Git Toolbox, AI Completion,
  Checkstyle, MyBatis Navigator, CSV Editor, Solidity, Material Icons, Harbor
  Night, Excalidraw, Graphviz, Regex Tester, License Header.

Closes #732

Co-authored-by: Deng Liu <[email protected]>
Co-authored-by: florentvdry <[email protected]>
2026-11-04 02:54:31 +08:00

115 рядки
3.3 KiB
TypeScript

/**
* `[[contributes.secrets]]` on the plugin details page: a password field per
* declared secret. Values go to the backend's secret store (the macOS
* Keychain in the desktop app) and never come back to the UI; plugins use
* them only as `{{secret:<name>}}` placeholders in `net` request headers.
*/
import { useCallback, useEffect, useState } from "react";
import type { PluginInfo, PluginSecretState } from "@/bindings";
import { tx } from "@/platform/i18n";
import { Badge, Button, Input, T } from "@/ui";
import { pluginsBackend } from "./backend";
import type { UiItem } from "./projection";
import styles from "./PluginsPage.module.css";
export interface SecretDecl {
name: string;
label: string;
description?: string | null;
}
function SecretRow({
plugin,
decl,
isSet,
onChanged,
}: {
plugin: PluginInfo;
decl: SecretDecl;
isSet: boolean;
onChanged: () => void;
}) {
const [value, setValue] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const save = async (v: string | null) => {
setBusy(true);
setError(null);
try {
await pluginsBackend().setSecret(plugin.id, decl.name, v);
setValue("");
onChanged();
} catch (e) {
setError(e instanceof Error ? e.message : String(e));
} finally {
setBusy(false);
}
};
return (
<li className={styles.item}>
<span className={styles.itemMain} title={decl.description ?? undefined}>
{decl.label}
</span>
{isSet ? <Badge tone="success">{tx("Stored")}</Badge> : <Badge tone="neutral">{tx("Not set")}</Badge>}
<Input
type="password"
value={value}
disabled={busy}
placeholder={isSet ? "Replace…" : "Value"}
aria-label={tx`Value of ${decl.label}`}
onChange={(e) => setValue(e.target.value)}
onKeyDown={(e) => {
if (e.key === "Enter" && value) void save(value);
}}
/>
<Button size="small" variant="ghost" disabled={busy || !value} onClick={() => void save(value)}>
<T>Save</T>
</Button>
{isSet && (
<Button
size="small"
variant="ghost"
disabled={busy}
onClick={() => void save(null)}
aria-label={tx`Remove ${decl.label}`}
>
<T>Remove</T>
</Button>
)}
{error && (
<span className={styles.error} role="alert">
{error}
</span>
)}
</li>
);
}
export function SecretsDetails({ plugin, items }: { plugin: PluginInfo; items: UiItem<SecretDecl>[] }) {
const [state, setState] = useState<PluginSecretState[]>([]);
const refresh = useCallback(() => {
pluginsBackend()
.secrets(plugin.id)
.then(setState, () => setState([]));
}, [plugin.id]);
useEffect(refresh, [refresh]);
return (
<>
<ul className={styles.items} aria-label={tx("Secrets")}>
{items.map(({ decl }) => (
<SecretRow
key={decl.name}
plugin={plugin}
decl={decl}
isSet={state.some((s) => s.name === decl.name && s.set)}
onChanged={refresh}
/>
))}
</ul>
<div className={styles.muted}>
<T>The plugin can only send these with its network requests; it cannot read them.</T>
</div>
</>
);
}