feat(basic-host): URL params, fullscreen mode, unified layout (#266)
* basic-host: handle containerDimensions * feat(basic-host): Unified tool call layout with shared collapsible panels * snapshots * format
This commit is contained in:
parent
75ecd62384
commit
75cbf8612c
1 changed files with 218 additions and 141 deletions
|
|
@ -228,12 +228,19 @@ export type AppMessage = McpUiMessageRequest["params"];
|
|||
export interface AppBridgeCallbacks {
|
||||
onContextUpdate?: (context: ModelContext | null) => void;
|
||||
onMessage?: (message: AppMessage) => void;
|
||||
onDisplayModeChange?: (mode: "inline" | "fullscreen") => void;
|
||||
}
|
||||
|
||||
export interface AppBridgeOptions {
|
||||
containerDimensions?: { maxHeight?: number; width?: number } | { height: number; width?: number };
|
||||
displayMode?: "inline" | "fullscreen";
|
||||
}
|
||||
|
||||
export function newAppBridge(
|
||||
serverInfo: ServerInfo,
|
||||
iframe: HTMLIFrameElement,
|
||||
callbacks?: AppBridgeCallbacks,
|
||||
options?: AppBridgeOptions,
|
||||
): AppBridge {
|
||||
const serverCapabilities = serverInfo.client.getServerCapabilities();
|
||||
const appBridge = new AppBridge(serverInfo.client, IMPLEMENTATION, {
|
||||
|
|
@ -242,6 +249,12 @@ export function newAppBridge(
|
|||
serverResources: serverCapabilities?.resources,
|
||||
// Declare support for model context updates
|
||||
updateModelContext: { text: {} },
|
||||
}, {
|
||||
hostContext: {
|
||||
containerDimensions: options?.containerDimensions ?? { maxHeight: 600 },
|
||||
displayMode: options?.displayMode ?? "inline",
|
||||
availableDisplayModes: ["inline", "fullscreen"],
|
||||
},
|
||||
});
|
||||
|
||||
// Register all handlers before calling connect(). The Guest UI can start
|
||||
|
|
@ -308,5 +321,18 @@ export function newAppBridge(
|
|||
iframe.animate([from, to], { duration: 300, easing: "ease-out" });
|
||||
};
|
||||
|
||||
// Handle display mode change requests from the app
|
||||
appBridge.onrequestdisplaymode = async (params) => {
|
||||
log.info("Display mode request from MCP App:", params);
|
||||
const newMode = params.mode === "fullscreen" ? "fullscreen" : "inline";
|
||||
// Update host context and notify the app
|
||||
appBridge.sendHostContextChange({
|
||||
displayMode: newMode,
|
||||
});
|
||||
// Notify the host UI (via callback)
|
||||
callbacks?.onDisplayModeChange?.(newMode);
|
||||
return { mode: newMode };
|
||||
};
|
||||
|
||||
return appBridge;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue