@waniwani/sdk 0.5.2 → 0.5.3-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.
@@ -76,8 +76,6 @@ interface ChatBaseProps {
76
76
  onMessageSent?: (message: string) => void;
77
77
  /** Callback fired when a response is received */
78
78
  onResponseReceived?: () => void;
79
- /** Endpoint URL for fetching MCP app resources (HTML widgets). Defaults to "/api/mcp/resource" */
80
- resourceEndpoint?: string;
81
79
  /**
82
80
  * Enable AI-generated suggestions after each response.
83
81
  * `true` enables with defaults (3 suggestions), object allows config, `false`/undefined disables.
@@ -88,17 +86,7 @@ interface ChatBaseProps {
88
86
  * Called when a widget uses `callServerTool` (MCP Apps standard).
89
87
  * If not provided, defaults to POSTing to `${api}/tool`.
90
88
  */
91
- onCallTool?: (params: {
92
- name: string;
93
- arguments: Record<string, unknown>;
94
- }) => Promise<{
95
- content?: Array<{
96
- type: string;
97
- text?: string;
98
- }>;
99
- structuredContent?: Record<string, unknown>;
100
- _meta?: Record<string, unknown>;
101
- }>;
89
+ onCallTool?: CallToolHandler;
102
90
  /**
103
91
  * Enable debug mode. When true, the `_meta` field is shown in tool call
104
92
  * inputs and outputs instead of being filtered out.
@@ -117,6 +105,71 @@ interface ChatBarProps extends ChatBaseProps {
117
105
  /** Title shown in the header when expanded. Defaults to "Assistant". */
118
106
  title?: string;
119
107
  }
108
+ /**
109
+ * MCP Apps configuration for {@link ChatEmbedProps}.
110
+ *
111
+ * Only needed when your backend proxies an MCP server whose tools return
112
+ * widget metadata (`_meta.ui.resourceUri`). Without this, tool calls still
113
+ * render with collapsible input/output — just no iframe widgets.
114
+ */
115
+ interface ChatEmbedMcpConfig {
116
+ /** Endpoint that serves MCP app resources (HTML widgets). Called as `GET ${resourceEndpoint}?uri=...`. */
117
+ resourceEndpoint: string;
118
+ /**
119
+ * Handler for MCP tool calls triggered by widgets via `callServerTool`.
120
+ * If not provided, widget-initiated tool calls will be ignored.
121
+ */
122
+ onCallTool?: CallToolHandler;
123
+ }
124
+ /** Handler signature for MCP tool calls from widgets. */
125
+ type CallToolHandler = (params: {
126
+ name: string;
127
+ arguments: Record<string, unknown>;
128
+ }) => Promise<{
129
+ content?: Array<{
130
+ type: string;
131
+ text?: string;
132
+ }>;
133
+ structuredContent?: Record<string, unknown>;
134
+ _meta?: Record<string, unknown>;
135
+ }>;
136
+ /**
137
+ * Standalone, borderless chat component designed for embedding into existing pages.
138
+ *
139
+ * Unlike {@link ChatCardProps} and {@link ChatBarProps}, ChatEmbed does **not** rely on
140
+ * the WaniWani hosted backend. It does not fetch `/config` or call `/tool` — you bring
141
+ * your own `api` endpoint.
142
+ *
143
+ * The component fills its parent container (`width: 100%; height: 100%`) with no
144
+ * header, border, or shadow — making it ideal for integrating into an existing layout
145
+ * that already provides its own chrome.
146
+ *
147
+ * To enable MCP App widgets (iframes), pass the optional `mcp` config.
148
+ *
149
+ * @example
150
+ * ```tsx
151
+ * // Basic — no MCP Apps
152
+ * <ChatEmbed
153
+ * api="/api/my-chat-endpoint"
154
+ * body={{ environmentId, sessionId }}
155
+ * theme={{ backgroundColor: "#fff" }}
156
+ * />
157
+ *
158
+ * // With MCP Apps support
159
+ * <ChatEmbed
160
+ * api="/api/my-chat-endpoint"
161
+ * mcp={{ resourceEndpoint: "/api/mcp/resource" }}
162
+ * />
163
+ * ```
164
+ */
165
+ interface ChatEmbedProps extends Omit<ChatBaseProps, "api" | "onCallTool"> {
166
+ /** The chat API endpoint URL. Required — there is no default. */
167
+ api: string;
168
+ /** Additional class names applied to the root element (e.g. Tailwind classes). */
169
+ className?: string;
170
+ /** MCP Apps configuration. Only needed if your backend serves widget resources. */
171
+ mcp?: ChatEmbedMcpConfig;
172
+ }
120
173
  interface ChatCardProps extends ChatBaseProps {
121
174
  /** Title shown in the card header. Defaults to "Assistant". */
122
175
  title?: string;
@@ -223,9 +276,30 @@ declare function McpAppFrame({ resourceUri, toolInput, toolResult, resourceEndpo
223
276
 
224
277
  declare const ChatCard: react.ForwardRefExoticComponent<ChatCardProps & react.RefAttributes<ChatHandle>>;
225
278
 
279
+ /**
280
+ * Standalone, borderless chat component — bring your own backend.
281
+ *
282
+ * Fills its parent container with no header, border, or shadow.
283
+ * Does **not** call any WaniWani-specific endpoints (`/config`, `/tool`, `/sessions`).
284
+ * Point `api` at your own AI-SDK-compatible streaming endpoint and pass extra
285
+ * request fields via `body`.
286
+ *
287
+ * Supports the same ref API as ChatCard (`sendMessage`, `sendMessageAndWait`, `focus`).
288
+ *
289
+ * @example
290
+ * ```tsx
291
+ * <ChatEmbed
292
+ * api={`/api/mcp/projects/${projectId}/chat`}
293
+ * body={{ environmentId, chatSessionId }}
294
+ * suggestions={{ initial: ["What can you do?"] }}
295
+ * />
296
+ * ```
297
+ */
298
+ declare const ChatEmbed: react.ForwardRefExoticComponent<ChatEmbedProps & react.RefAttributes<ChatHandle>>;
299
+
226
300
  declare const DEFAULT_THEME: Required<ChatTheme>;
227
301
  declare const DARK_THEME: ChatTheme;
228
302
  declare function mergeTheme(userTheme?: ChatTheme): Required<ChatTheme>;
229
303
  declare function themeToCSSProperties(theme: Required<ChatTheme>): Record<string, string>;
230
304
 
231
- export { ChatBar, type ChatBarProps, type ChatBaseProps, ChatCard, type ChatCardProps, type ChatHandle, type ChatTheme, ChatBar as ChatWidget, type ChatWidgetProps, DARK_THEME, DEFAULT_THEME, EvalPanel, type McpAppDisplayMode, McpAppFrame, type McpAppFrameProps, type SuggestionsConfig, mergeTheme, themeToCSSProperties };
305
+ export { ChatBar, type ChatBarProps, type ChatBaseProps, ChatCard, type ChatCardProps, ChatEmbed, type ChatEmbedMcpConfig, type ChatEmbedProps, type ChatHandle, type ChatTheme, ChatBar as ChatWidget, type ChatWidgetProps, DARK_THEME, DEFAULT_THEME, EvalPanel, type McpAppDisplayMode, McpAppFrame, type McpAppFrameProps, type SuggestionsConfig, mergeTheme, themeToCSSProperties };