@waniwani/sdk 0.21.3 → 0.21.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -959,6 +959,14 @@ type WebMcpContentBlock = {
959
959
  text?: string;
960
960
  [key: string]: unknown;
961
961
  };
962
+ /** A tool as `tools/list` describes it. */
963
+ type WebMcpTool = {
964
+ name: string;
965
+ description?: string;
966
+ inputSchema?: Record<string, unknown>;
967
+ annotations?: Record<string, unknown>;
968
+ _meta?: Record<string, unknown>;
969
+ };
962
970
  /**
963
971
  * Everything the page needs to mount a widget itself.
964
972
  *
@@ -997,6 +1005,46 @@ type WebMcpWidgetPayload = {
997
1005
  */
998
1006
  preview?: boolean;
999
1007
  };
1008
+ type WebMcpCallResponse = {
1009
+ content: WebMcpContentBlock[];
1010
+ structuredContent?: Record<string, unknown>;
1011
+ isError?: boolean;
1012
+ _meta?: Record<string, unknown>;
1013
+ /** Present and non-null only when the call produced a resolvable widget step. */
1014
+ widget: WebMcpWidgetPayload | null;
1015
+ };
1016
+
1017
+ /**
1018
+ * The WebMCP bridge.
1019
+ *
1020
+ * A browsing agent standing on a page never speaks to the MCP server. It speaks
1021
+ * to the page, through `document.modelContext`, and this is what puts the
1022
+ * server's tools there. Every `execute()` the agent calls lands on the endpoint
1023
+ * below, which stamps attribution server-side and answers.
1024
+ *
1025
+ * Nothing here discovers its own configuration. The endpoint, both ids, and the
1026
+ * widget callback are arguments, because there are two callers with two
1027
+ * different ways of knowing them: the chat embed reads them from its remote
1028
+ * config, and the standalone loader derives them from its own script tag.
1029
+ * Sniffing `document.currentScript` inside a bundle that may be loaded twenty
1030
+ * modules deep finds the wrong script or none.
1031
+ */
1032
+
1033
+ /** Live for as long as the bridge is registered. */
1034
+ type WebMcpBridge = {
1035
+ /** Tools successfully registered with the browser. */
1036
+ readonly tools: WebMcpTool[];
1037
+ /**
1038
+ * Call a tool with the bridge's auth and identity, for a mounted view's own
1039
+ * `tools/call`. Resolves to the raw response; widgets are not re-dispatched.
1040
+ */
1041
+ callTool: (params: {
1042
+ name: string;
1043
+ arguments?: Record<string, unknown>;
1044
+ }) => Promise<WebMcpCallResponse>;
1045
+ /** Unregister everything. Idempotent. */
1046
+ dispose: () => void;
1047
+ };
1000
1048
 
1001
1049
  /**
1002
1050
  * `McpAppFrame` is used exactly as the chat uses it, with no new props.
@@ -1019,9 +1067,14 @@ type WebMcpWidgetPayload = {
1019
1067
  type WebMcpOverlayProps = {
1020
1068
  /** The step to show, or `null` for nothing. */
1021
1069
  widget: WebMcpWidgetPayload | null;
1022
- /** The tools endpoint, so a view's own `tools/call` can be proxied. */
1023
- toolsEndpoint: string;
1024
- /** Auth for that endpoint, matching what the bridge sends. */
1070
+ /**
1071
+ * Proxies a view's own `tools/call`. Pass the bridge's `callTool` so the
1072
+ * request carries the same auth and session identity as the agent's calls.
1073
+ */
1074
+ onCallTool?: WebMcpBridge["callTool"];
1075
+ /** @deprecated Pass `onCallTool`. Removed in 0.23.0. */
1076
+ toolsEndpoint?: string;
1077
+ /** @deprecated Pass `onCallTool`. Removed in 0.23.0. */
1025
1078
  headers?: Record<string, string>;
1026
1079
  /**
1027
1080
  * Where view HTML is fetched from, resolved from the token the same way the
@@ -1032,7 +1085,7 @@ type WebMcpOverlayProps = {
1032
1085
  onClose: () => void;
1033
1086
  isDark?: boolean;
1034
1087
  };
1035
- declare function WebMcpOverlay({ widget, toolsEndpoint, resourceEndpoint, headers, onClose, isDark, }: WebMcpOverlayProps): react_jsx_runtime.JSX.Element | null;
1088
+ declare function WebMcpOverlay({ widget, onCallTool, toolsEndpoint, headers, resourceEndpoint, onClose, isDark, }: WebMcpOverlayProps): react_jsx_runtime.JSX.Element | null;
1036
1089
 
1037
1090
  /**
1038
1091
  * **Bare-bones, bring-your-own-backend chat primitive.** Most apps want