The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(plugins): expose Dialog/ConfirmDialog/Toast/useToast/useConfirmDelete on plugin SDK
David Metcalfe7448e7a5065d
diff --git a/web/src/plugins/registry.test.ts b/web/src/plugins/registry.test.tsnew file mode 100644index 00000000000..8fe06478582--- /dev/null+++ b/web/src/plugins/registry.test.ts@@ -0,0 +1,54 @@+/**+ * Smoke test for the plugin SDK surface additions.+ *+ * Verifies that `exposePluginSDK()` writes the new dialog/toast primitives to+ * `window.__HERMES_PLUGIN_SDK__`. Each new key is checked individually so a+ * regression in one helper doesn't mask the others.+ *+ * Companion to the additive PR "feat(plugins): expose Dialog/ConfirmDialog/+ * Toast/useToast/useConfirmDelete on the plugin SDK". See issue #50547.+ */+import { beforeEach, describe, expect, it } from "vitest";+import { exposePluginSDK } from "./registry";++describe("plugin SDK dialog/toast surface", () => {+ beforeEach(() => {+ // Reset window between tests so exposePluginSDK() writes fresh.+ (globalThis as any).window = {+ __HERMES_PLUGINS__: undefined,+ __HERMES_PLUGIN_SDK__: undefined,+ };+ });++ it("exposes Dialog + subcomponents on components", () => {+ exposePluginSDK();+ const sdk = (globalThis as any).window.__HERMES_PLUGIN_SDK__;+ expect(sdk.components.Dialog).toBeDefined();+ expect(sdk.components.DialogContent).toBeDefined();+ expect(sdk.components.DialogHeader).toBeDefined();+ expect(sdk.components.DialogTitle).toBeDefined();+ expect(sdk.components.DialogDescription).toBeDefined();+ expect(sdk.components.DialogFooter).toBeDefined();+ expect(sdk.components.DialogClose).toBeDefined();+ expect(sdk.components.ConfirmDialog).toBeDefined();+ expect(sdk.components.Toast).toBeDefined();+ });++ it("exposes useToast and useConfirmDelete on hooks", () => {+ exposePluginSDK();+ const sdk = (globalThis as any).window.__HERMES_PLUGIN_SDK__;+ expect(typeof sdk.hooks.useToast).toBe("function");+ expect(typeof sdk.hooks.useConfirmDelete).toBe("function");+ // Original React hooks still present (no accidental removal).+ expect(typeof sdk.hooks.useState).toBe("function");+ expect(typeof sdk.hooks.useCallback).toBe("function");+ });++ it("does not bump SDK_CONTRACT_VERSION (additive change)", () => {+ exposePluginSDK();+ const sdk = (globalThis as any).window.__HERMES_PLUGIN_SDK__;+ // Pre-existing version per registry.ts:98. This test fails if a future+ // PR accidentally bumps the major for an additive surface change.+ expect(sdk.sdkVersion).toBe("1.1.0");+ });+});\ No newline at end of filediff --git a/web/src/plugins/registry.ts b/web/src/plugins/registry.tsindex 392c536d0ad..df7c77d8d06 100644--- a/web/src/plugins/registry.ts+++ b/web/src/plugins/registry.ts@@ -22,6 +22,14 @@ import { cn, timeAgo, isoTimeAgo } from "@/lib/utils";import { Badge } from "@nous-research/ui/ui/components/badge";import { Button } from "@nous-research/ui/ui/components/button";import { Checkbox } from "@nous-research/ui/ui/components/checkbox";+import { ConfirmDialog } from "@nous-research/ui/ui/components/confirm-dialog";+import {+ Dialog, DialogClose, DialogContent, DialogDescription,+ DialogFooter, DialogHeader, DialogTitle,+} from "@nous-research/ui/ui/components/dialog";+import { Toast } from "@nous-research/ui/ui/components/toast";+import { useConfirmDelete } from "@nous-research/ui/hooks/use-confirm-delete";+import { useToast } from "@nous-research/ui/hooks/use-toast";import { Select, SelectOption } from "@nous-research/ui/ui/components/select";import { Card, CardHeader, CardTitle, CardContent } from "@nous-research/ui/ui/components/card";import { Input } from "@nous-research/ui/ui/components/input";@@ -121,6 +129,13 @@ export function exposePluginSDK() {useRef,useContext,createContext,+ // useToast returns { showToast, toast } where toast is the current+ // visible toast (or null) and showToast(message, 'success'|'error')+ // replaces it. useConfirmDelete<TId>({ onDelete }) returns the state+ // machine (requestDelete / confirm / cancel / isOpen / isDeleting /+ // pendingId) for single-id delete confirmations.+ useToast,+ useConfirmDelete,},// Hermes API client@@ -148,6 +163,14 @@ export function exposePluginSDK() {Badge,Button,Checkbox,+ ConfirmDialog,+ Dialog,+ DialogClose,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,Input,Label,Select,@@ -156,6 +179,7 @@ export function exposePluginSDK() {Tabs,TabsList,TabsTrigger,+ Toast,PluginSlot,},diff --git a/web/src/plugins/sdk.d.ts b/web/src/plugins/sdk.d.tsindex c55b855ab82..db31b73e516 100644--- a/web/src/plugins/sdk.d.ts+++ b/web/src/plugins/sdk.d.ts@@ -105,6 +105,30 @@ export interface HermesPluginSDK {useRef: typeof import("react").useRef;useContext: typeof import("react").useContext;createContext: typeof import("react").createContext;+ /**+ * Toast feedback. Returns ``{ showToast, toast }`` where ``toast`` is the+ * current visible toast (or null) and ``showToast(message, 'success' | 'error')``+ * replaces it. Mount the ``Toast`` component (also on ``components``) somewhere+ * in your plugin's tree to render the visible toast.+ */+ useToast: () => {+ showToast: (message: string, type: "success" | "error") => void;+ toast: { message: string; type: "success" | "error" } | null;+ };+ /**+ * Single-id delete-confirm state machine. Pass ``onDelete(id)`` (an async+ * function). Returns ``{ requestDelete, confirm, cancel, isOpen, isDeleting,+ * pendingId }``. Pair with the ``ConfirmDialog`` primitive (passed as+ * ``open={isOpen}`` etc.) or any custom dialog.+ */+ useConfirmDelete: <TId,>(opts: { onDelete: (id: TId) => Promise<void> }) => {+ requestDelete: (id: TId) => void;+ confirm: () => Promise<void>;+ cancel: () => void;+ isOpen: boolean;+ isDeleting: boolean;+ pendingId: TId | null;+ };};/**