PluginUiSidePane.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import { memo, useMemo } from "react";
  2. import type { PluginUiScopeRef } from "@zcode/shared/mcp-apps";
  3. import { readPluginUiScopeRef, type PluginUiSidePaneTab } from "@/plugin-ui/contract.js";
  4. import {
  5. PluginUiConversationScope,
  6. usePluginUiSidePaneModel,
  7. } from "@/plugin-ui/adapters/usePluginUiSidePaneModel.js";
  8. import { PluginUiSidePaneView } from "@/plugin-ui/components/PluginUiSidePane.js";
  9. type Props = {
  10. tab: PluginUiSidePaneTab;
  11. onOpenBrowserUrl?: (url: string) => void;
  12. /** 页面请求回到 inline 时宿主关闭本 tab。 */
  13. onCloseTab?: (tabId: string) => void;
  14. };
  15. function Content(props: Props & { scopeRef: PluginUiScopeRef }) {
  16. return <PluginUiSidePaneView {...usePluginUiSidePaneModel(props)} />;
  17. }
  18. /** 模块组装入口:将只读会话适配器与纯视图连接。 */
  19. export const PluginUiSidePane = memo(function PluginUiSidePane(props: Props) {
  20. const scopeRef = useMemo(
  21. () => readPluginUiScopeRef(props.tab),
  22. [props.tab.surfaceId, props.tab.toolCallId],
  23. );
  24. if (!scopeRef) return null;
  25. return (
  26. <PluginUiConversationScope tab={props.tab}>
  27. <Content {...props} scopeRef={scopeRef} />
  28. </PluginUiConversationScope>
  29. );
  30. });