@waniwani/sdk 0.21.4 → 0.22.0-beta.0

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.
@@ -590,6 +590,11 @@ interface ChatBaseProps {
590
590
  apiKey?: string;
591
591
  /** Chat API endpoint URL. Defaults to Waniwani hosted endpoint */
592
592
  api?: string;
593
+ /**
594
+ * Builds the transport turns are sent through. Defaults to the chat's own
595
+ * HTTP transport to `api`, which it also hands the factory as `fallback`.
596
+ */
597
+ transport?: ChatTransportFactory;
593
598
  /** Pre-loaded messages to display when the chat mounts. */
594
599
  initialMessages?: ai.UIMessage[];
595
600
  /** Initial greeting shown before user types */
@@ -869,6 +874,23 @@ interface ChatHandle {
869
874
  eventId: string;
870
875
  }>;
871
876
  }
877
+ /** What the chat hands a transport factory. */
878
+ interface ChatTransportContext {
879
+ /** The chat's HTTP transport to `api`. */
880
+ fallback: ai.ChatTransport<ai.UIMessage>;
881
+ headers: () => Record<string, string> | undefined;
882
+ /** The channel and visitor a turn is attributed to. */
883
+ body: () => Record<string, unknown>;
884
+ /** True while the thread needs what only `fallback` carries: attachments, model context, saved history. */
885
+ needsFallback: () => boolean;
886
+ onSession: (sessionId: string) => void;
887
+ }
888
+ /** Optional hooks the chat calls on a transport: ahead of the first message, and on unmount. */
889
+ interface ChatTransportLifecycle {
890
+ prepare?(): void;
891
+ dispose?(): void;
892
+ }
893
+ type ChatTransportFactory = (context: ChatTransportContext) => ai.ChatTransport<ai.UIMessage> & ChatTransportLifecycle;
872
894
 
873
895
  type ModelContextContentBlock = ContentBlock;
874
896
  type ModelContextUpdate = {
@@ -959,6 +981,14 @@ type WebMcpContentBlock = {
959
981
  text?: string;
960
982
  [key: string]: unknown;
961
983
  };
984
+ /** A tool as `tools/list` describes it. */
985
+ type WebMcpTool = {
986
+ name: string;
987
+ description?: string;
988
+ inputSchema?: Record<string, unknown>;
989
+ annotations?: Record<string, unknown>;
990
+ _meta?: Record<string, unknown>;
991
+ };
962
992
  /**
963
993
  * Everything the page needs to mount a widget itself.
964
994
  *
@@ -997,6 +1027,46 @@ type WebMcpWidgetPayload = {
997
1027
  */
998
1028
  preview?: boolean;
999
1029
  };
1030
+ type WebMcpCallResponse = {
1031
+ content: WebMcpContentBlock[];
1032
+ structuredContent?: Record<string, unknown>;
1033
+ isError?: boolean;
1034
+ _meta?: Record<string, unknown>;
1035
+ /** Present and non-null only when the call produced a resolvable widget step. */
1036
+ widget: WebMcpWidgetPayload | null;
1037
+ };
1038
+
1039
+ /**
1040
+ * The WebMCP bridge.
1041
+ *
1042
+ * A browsing agent standing on a page never speaks to the MCP server. It speaks
1043
+ * to the page, through `document.modelContext`, and this is what puts the
1044
+ * server's tools there. Every `execute()` the agent calls lands on the endpoint
1045
+ * below, which stamps attribution server-side and answers.
1046
+ *
1047
+ * Nothing here discovers its own configuration. The endpoint, both ids, and the
1048
+ * widget callback are arguments, because there are two callers with two
1049
+ * different ways of knowing them: the chat embed reads them from its remote
1050
+ * config, and the standalone loader derives them from its own script tag.
1051
+ * Sniffing `document.currentScript` inside a bundle that may be loaded twenty
1052
+ * modules deep finds the wrong script or none.
1053
+ */
1054
+
1055
+ /** Live for as long as the bridge is registered. */
1056
+ type WebMcpBridge = {
1057
+ /** Tools successfully registered with the browser. */
1058
+ readonly tools: WebMcpTool[];
1059
+ /**
1060
+ * Call a tool with the bridge's auth and identity, for a mounted view's own
1061
+ * `tools/call`. Resolves to the raw response; widgets are not re-dispatched.
1062
+ */
1063
+ callTool: (params: {
1064
+ name: string;
1065
+ arguments?: Record<string, unknown>;
1066
+ }) => Promise<WebMcpCallResponse>;
1067
+ /** Unregister everything. Idempotent. */
1068
+ dispose: () => void;
1069
+ };
1000
1070
 
1001
1071
  /**
1002
1072
  * `McpAppFrame` is used exactly as the chat uses it, with no new props.
@@ -1019,9 +1089,14 @@ type WebMcpWidgetPayload = {
1019
1089
  type WebMcpOverlayProps = {
1020
1090
  /** The step to show, or `null` for nothing. */
1021
1091
  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. */
1092
+ /**
1093
+ * Proxies a view's own `tools/call`. Pass the bridge's `callTool` so the
1094
+ * request carries the same auth and session identity as the agent's calls.
1095
+ */
1096
+ onCallTool?: WebMcpBridge["callTool"];
1097
+ /** @deprecated Pass `onCallTool`. Removed in 0.23.0. */
1098
+ toolsEndpoint?: string;
1099
+ /** @deprecated Pass `onCallTool`. Removed in 0.23.0. */
1025
1100
  headers?: Record<string, string>;
1026
1101
  /**
1027
1102
  * Where view HTML is fetched from, resolved from the token the same way the
@@ -1032,7 +1107,7 @@ type WebMcpOverlayProps = {
1032
1107
  onClose: () => void;
1033
1108
  isDark?: boolean;
1034
1109
  };
1035
- declare function WebMcpOverlay({ widget, toolsEndpoint, resourceEndpoint, headers, onClose, isDark, }: WebMcpOverlayProps): react_jsx_runtime.JSX.Element | null;
1110
+ declare function WebMcpOverlay({ widget, onCallTool, toolsEndpoint, headers, resourceEndpoint, onClose, isDark, }: WebMcpOverlayProps): react_jsx_runtime.JSX.Element | null;
1036
1111
 
1037
1112
  /**
1038
1113
  * **Bare-bones, bring-your-own-backend chat primitive.** Most apps want
@@ -1100,6 +1175,12 @@ interface WaniwaniChatOverrides {
1100
1175
  api?: string;
1101
1176
  /** Override the MCP server URL (rarely needed). */
1102
1177
  mcpServerUrl?: string;
1178
+ /**
1179
+ * The app's agent-runtime session route (`/api/mcp/agent/session`). Set,
1180
+ * turns go straight to the agent runtime for a chat the route admits, and
1181
+ * through `api` for one it does not.
1182
+ */
1183
+ sessionApi?: string;
1103
1184
  /**
1104
1185
  * AI transparency notice rendered under the input (EU AI Act compliance).
1105
1186
  * String overrides the default wording; `false` hides it.