fix: change size-changed to be in correct tense (#83)

* fix: change size-changed to be in correct tense

* sdk changes
This commit is contained in:
Liad Yosef 2025-12-08 13:14:56 +02:00 • committed by GitHub
commit ba1a27e465
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 41 additions and 41 deletions

View file

@ -632,12 +632,12 @@ Host MUST send this notification if the tool execution was cancelled, for any re
Host MUST send this notification before tearing down the UI resource, for any reason, including user action, resource re-allocation, etc. The Host MAY specify the reason.
Host SHOULD wait for a response before tearing down the resource (to prevent data loss).
`ui/notifications/size-change` - UI’s size changed
`ui/notifications/size-changed` - UI’s size changed
```typescript
{
jsonrpc: "2.0",
method: "ui/notifications/size-change",
method: "ui/notifications/size-changed",
params: {
width: number, // Viewport width in pixels
height: number // Viewport height in pixels
@ -774,7 +774,7 @@ sequenceDiagram
H --> UI: resources/read response
end
opt UI notifications
UI ->> H: notifications (e.g., ui/notifications/size-change)
UI ->> H: notifications (e.g., ui/notifications/size-changed)
end
opt Host notifications
H ->> UI: notifications (e.g., ui/notifications/host-context-changed)

View file

@ -180,14 +180,14 @@ describe("App <-> AppBridge integration", () => {
await bridge.connect(bridgeTransport);
});
it("app.sendSizeChange triggers bridge.onsizechange", async () => {
it("app.sendSizeChanged triggers bridge.onsizechange", async () => {
const receivedSizes: unknown[] = [];
bridge.onsizechange = (params) => {
receivedSizes.push(params);
};
await app.connect(appTransport);
await app.sendSizeChange({ width: 400, height: 600 });
await app.sendSizeChanged({ width: 400, height: 600 });
expect(receivedSizes).toEqual([{ width: 400, height: 600 }]);
});

View file

@ -33,7 +33,7 @@ import {
import {
type McpUiSandboxResourceReadyNotification,
type McpUiSizeChangeNotification,
type McpUiSizeChangedNotification,
type McpUiToolInputNotification,
type McpUiToolInputPartialNotification,
type McpUiToolResultNotification,
@ -57,7 +57,7 @@ import {
McpUiResourceTeardownResultSchema,
McpUiSandboxProxyReadyNotification,
McpUiSandboxProxyReadyNotificationSchema,
McpUiSizeChangeNotificationSchema,
McpUiSizeChangedNotificationSchema,
} from "./types";
export * from "./types";
export { PostMessageTransport } from "./message-transport";
@ -265,12 +265,12 @@ export class AppBridge extends Protocol<Request, Notification, Result> {
/**
* Register a handler for size change notifications from the Guest UI.
*
* The Guest UI sends `ui/notifications/size-change` when its rendered content
* The Guest UI sends `ui/notifications/size-changed` when its rendered content
* size changes, typically via ResizeObserver. Set this callback to dynamically
* adjust the iframe container dimensions based on the Guest UI's content.
*
* Note: This is for Guest UI → Host communication. To notify the Guest UI of
* host viewport changes, use {@link app.App.sendSizeChange}.
* host viewport changes, use {@link app.App.sendSizeChanged}.
*
* @example
* ```typescript
@ -284,13 +284,13 @@ export class AppBridge extends Protocol<Request, Notification, Result> {
* };
* ```
*
* @see {@link McpUiSizeChangeNotification} for the notification type
* @see {@link app.App.sendSizeChange} for Host → Guest UI size notifications
* @see {@link McpUiSizeChangedNotification} for the notification type
* @see {@link app.App.sendSizeChanged} for Host → Guest UI size notifications
*/
set onsizechange(
callback: (params: McpUiSizeChangeNotification["params"]) => void,
callback: (params: McpUiSizeChangedNotification["params"]) => void,
) {
this.setNotificationHandler(McpUiSizeChangeNotificationSchema, (n) =>
this.setNotificationHandler(McpUiSizeChangedNotificationSchema, (n) =>
callback(n.params),
);
}

View file

@ -31,7 +31,7 @@ import {
McpUiMessageResultSchema,
McpUiOpenLinkRequest,
McpUiOpenLinkResultSchema,
McpUiSizeChangeNotification,
McpUiSizeChangedNotification,
McpUiToolInputNotification,
McpUiToolInputNotificationSchema,
McpUiToolInputPartialNotification,
@ -88,7 +88,7 @@ type AppOptions = ProtocolOptions & {
* Automatically report size changes to the host using ResizeObserver.
*
* When enabled, the App monitors `document.body` and `document.documentElement`
* for size changes and automatically sends `ui/notifications/size-change`
* for size changes and automatically sends `ui/notifications/size-changed`
* notifications to the host.
*
* @default true
@ -723,7 +723,7 @@ export class App extends Protocol<Request, Notification, Result> {
*
* @example Manually notify host of size change
* ```typescript
* app.sendSizeChange({
* app.sendSizeChanged({
* width: 400,
* height: 600
* });
@ -731,11 +731,11 @@ export class App extends Protocol<Request, Notification, Result> {
*
* @returns Promise that resolves when the notification is sent
*
* @see {@link McpUiSizeChangeNotification} for notification structure
* @see {@link McpUiSizeChangedNotification} for notification structure
*/
sendSizeChange(params: McpUiSizeChangeNotification["params"]) {
return this.notification(<McpUiSizeChangeNotification>{
method: "ui/notifications/size-change",
sendSizeChanged(params: McpUiSizeChangedNotification["params"]) {
return this.notification(<McpUiSizeChangedNotification>{
method: "ui/notifications/size-changed",
params,
});
}
@ -744,7 +744,7 @@ export class App extends Protocol<Request, Notification, Result> {
* Set up automatic size change notifications using ResizeObserver.
*
* Observes both `document.documentElement` and `document.body` for size changes
* and automatically sends `ui/notifications/size-change` notifications to the host.
* and automatically sends `ui/notifications/size-changed` notifications to the host.
* The notifications are debounced using requestAnimationFrame to avoid duplicates.
*
* Note: This method is automatically called by `connect()` if the `autoResize`
@ -759,18 +759,18 @@ export class App extends Protocol<Request, Notification, Result> {
* await app.connect(transport);
*
* // Later, enable auto-resize manually
* const cleanup = app.setupSizeChangeNotifications();
* const cleanup = app.setupSizeChangedNotifications();
*
* // Clean up when done
* cleanup();
* ```
*/
setupSizeChangeNotifications() {
setupSizeChangedNotifications() {
let scheduled = false;
let lastWidth = 0;
let lastHeight = 0;
const sendBodySizeChange = () => {
const sendBodySizeChanged = () => {
if (scheduled) {
return;
}
@ -801,14 +801,14 @@ export class App extends Protocol<Request, Notification, Result> {
if (width !== lastWidth || height !== lastHeight) {
lastWidth = width;
lastHeight = height;
this.sendSizeChange({ width, height });
this.sendSizeChanged({ width, height });
}
});
};
sendBodySizeChange();
sendBodySizeChanged();
const resizeObserver = new ResizeObserver(sendBodySizeChange);
const resizeObserver = new ResizeObserver(sendBodySizeChanged);
// Observe both html and body to catch all size changes
resizeObserver.observe(document.documentElement);
resizeObserver.observe(document.body);
@ -824,7 +824,7 @@ export class App extends Protocol<Request, Notification, Result> {
* 2. Sends `ui/initialize` request with app info and capabilities
* 3. Receives host capabilities and context in response
* 4. Sends `ui/notifications/initialized` notification
* 5. Sets up auto-resize using {@link setupSizeChangeNotifications} if enabled (default)
* 5. Sets up auto-resize using {@link setupSizeChangedNotifications} if enabled (default)
*
* If initialization fails, the connection is automatically closed and an error
* is thrown.
@ -885,7 +885,7 @@ export class App extends Protocol<Request, Notification, Result> {
});
if (this.options?.autoResize) {
this.setupSizeChangeNotifications();
this.setupSizeChangedNotifications();
}
} catch (error) {
// Disconnect if initialization fails.

View file

@ -5,7 +5,7 @@ import { App } from "../app";
* React hook that automatically reports UI size changes to the host.
*
* Uses ResizeObserver to watch `document.body` and `document.documentElement` for
* size changes and sends `ui/notifications/size-change` notifications.
* size changes and sends `ui/notifications/size-changed` notifications.
*
* **Note**: This hook is rarely needed since the {@link useApp} hook automatically enables
* auto-resize by default. This hook is provided for advanced cases where you
@ -45,7 +45,7 @@ import { App } from "../app";
* }
* ```
*
* @see {@link App.setupSizeChangeNotifications} for the underlying implementation
* @see {@link App.setupSizeChangedNotifications} for the underlying implementation
* @see {@link useApp} which enables auto-resize by default
* @see {@link App} constructor for configuring `autoResize` option
*/
@ -58,6 +58,6 @@ export function useAutoResize(
return;
}
return app.setupSizeChangeNotifications();
return app.setupSizeChangedNotifications();
}, [app, elementRef]);
}

View file

@ -258,11 +258,11 @@ type _VerifySandboxResourceReadyNotification = VerifySchemaMatches<
* **Host → Guest UI**: Sent by the Host when the viewport size changes (e.g.,
* window resize, orientation change). This allows the Guest UI to adjust its layout.
*
* @see {@link app.App.sendSizeChange} for the method to send this from Guest UI
* @see {@link app.App.setupSizeChangeNotifications} for automatic size reporting
* @see {@link app.App.sendSizeChanged} for the method to send this from Guest UI
* @see {@link app.App.setupSizeChangedNotifications} for automatic size reporting
*/
export interface McpUiSizeChangeNotification {
method: "ui/notifications/size-change";
export interface McpUiSizeChangedNotification {
method: "ui/notifications/size-changed";
params: {
/** New width in pixels */
width?: number;
@ -272,11 +272,11 @@ export interface McpUiSizeChangeNotification {
}
/**
* Runtime validation schema for {@link McpUiSizeChangeNotification}.
* Runtime validation schema for {@link McpUiSizeChangedNotification}.
* @internal
*/
export const McpUiSizeChangeNotificationSchema = z.object({
method: z.literal("ui/notifications/size-change"),
export const McpUiSizeChangedNotificationSchema = z.object({
method: z.literal("ui/notifications/size-changed"),
params: z.object({
width: z.number().optional(),
height: z.number().optional(),
@ -285,8 +285,8 @@ export const McpUiSizeChangeNotificationSchema = z.object({
/** @internal - Compile-time verification that schema matches interface */
type _VerifySizeChangeNotification = VerifySchemaMatches<
typeof McpUiSizeChangeNotificationSchema,
McpUiSizeChangeNotification
typeof McpUiSizeChangedNotificationSchema,
McpUiSizeChangedNotification
>;
/**