@waniwani/sdk 0.11.11 → 0.11.13
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.
- package/README.md +78 -112
- package/dist/chat/embed.js +65 -65
- package/dist/chat/embed.js.map +1 -1
- package/dist/chat/express-js/index.d.ts +8 -1
- package/dist/chat/express-js/index.js.map +1 -1
- package/dist/chat/index.d.ts +9 -22
- package/dist/chat/index.js +7 -7
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/next-js/index.d.ts +5 -3
- package/dist/chat/next-js/index.js.map +1 -1
- package/dist/chat/server/index.js +1 -1
- package/dist/chat/server/index.js.map +1 -1
- package/dist/chat/styles.css +1 -1
- package/dist/{chunk-DGSC74SV.js → chunk-DP6SAQTK.js} +1 -1
- package/dist/chunk-DP6SAQTK.js.map +1 -0
- package/dist/{chunk-5OQXAEHG.js → chunk-RZKVTH7F.js} +1 -1
- package/dist/chunk-RZKVTH7F.js.map +1 -0
- package/dist/legacy/chat/express-js/index.d.ts +407 -0
- package/dist/legacy/chat/express-js/index.js +10 -0
- package/dist/legacy/chat/express-js/index.js.map +1 -0
- package/dist/legacy/chat/next-js/index.d.ts +368 -0
- package/dist/legacy/chat/next-js/index.js +10 -0
- package/dist/legacy/chat/next-js/index.js.map +1 -0
- package/dist/legacy/index.d.ts +335 -0
- package/dist/legacy/index.js +2 -0
- package/dist/legacy/index.js.map +1 -0
- package/dist/legacy/mcp/react.d.ts +573 -0
- package/dist/legacy/mcp/react.js +68 -0
- package/dist/legacy/mcp/react.js.map +1 -0
- package/dist/mcp/index.d.ts +1153 -1117
- package/dist/mcp/index.js +5 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/react.d.ts +170 -74
- package/dist/mcp/react.js +7 -7
- package/dist/mcp/react.js.map +1 -1
- package/dist/{mcp-apps-client-PUL4H54S.js → mcp-apps-client-OFYMQOI3.js} +1 -1
- package/dist/mcp-apps-client-OFYMQOI3.js.map +1 -0
- package/dist/{openai-client-QAC3ZD5W.js → openai-client-TZIOCMXP.js} +2 -2
- package/dist/openai-client-TZIOCMXP.js.map +1 -0
- package/dist/platform-LKQFC3AJ.js +3 -0
- package/package.json +34 -21
- package/dist/chunk-5OQXAEHG.js.map +0 -1
- package/dist/chunk-DGSC74SV.js.map +0 -1
- package/dist/evals/index.d.ts +0 -156
- package/dist/evals/index.js +0 -2
- package/dist/evals/index.js.map +0 -1
- package/dist/evals/scorers.d.ts +0 -92
- package/dist/evals/scorers.js +0 -8
- package/dist/evals/scorers.js.map +0 -1
- package/dist/mcp-apps-client-PUL4H54S.js.map +0 -1
- package/dist/openai-client-QAC3ZD5W.js.map +0 -1
- package/dist/platform-GKYYQBCS.js +0 -3
- /package/dist/{platform-GKYYQBCS.js.map → platform-LKQFC3AJ.js.map} +0 -0
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ContentBlock, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
import React$1, { ReactNode, SetStateAction } from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Initializes & patches Next.js functionality so an app can run as a
|
|
7
|
+
* widget inside a cross-origin iframe. Used by every MCP widget host —
|
|
8
|
+
* ChatGPT's sandbox, the embed's `/api/mcp/chat/resource` proxy, and any
|
|
9
|
+
* future host that renders the widget on a domain other than its own
|
|
10
|
+
* `baseUrl`.
|
|
11
|
+
*
|
|
12
|
+
* See `applyIframePatches` for the patch behavior.
|
|
13
|
+
*
|
|
14
|
+
* More background on the ChatGPT case:
|
|
15
|
+
* https://vercel.com/blog/running-next-js-inside-chatgpt-a-deep-dive-into-native-app-integration
|
|
16
|
+
*
|
|
17
|
+
* @deprecated Legacy MCP-widget-in-host stack (used with `createResource`/`createTool`).
|
|
18
|
+
* Preserved for back-compat; will move to `@waniwani/sdk/legacy/react` in a future minor
|
|
19
|
+
* release.
|
|
20
|
+
*/
|
|
21
|
+
declare function InitializeNextJsInIframe({ baseUrl, passthroughOrigins, }: {
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
/**
|
|
24
|
+
* Origins whose fetches should skip the relative same-origin → baseUrl
|
|
25
|
+
* rewrite. Only needed for relative-URL calls that resolve to an
|
|
26
|
+
* origin you do not want forwarded to `baseUrl` — absolute URLs are
|
|
27
|
+
* never rewritten regardless of this list.
|
|
28
|
+
*/
|
|
29
|
+
passthroughOrigins?: string[];
|
|
30
|
+
}): react_jsx_runtime.JSX.Element;
|
|
31
|
+
|
|
32
|
+
interface DevControlsProps {
|
|
33
|
+
defaultProps?: Record<string, unknown>;
|
|
34
|
+
widgetPaths?: string[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
38
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
39
|
+
*/
|
|
40
|
+
declare function DevModeProvider({ defaultProps, widgetPaths, children, }: DevControlsProps & {
|
|
41
|
+
children: React.ReactNode;
|
|
42
|
+
}): react_jsx_runtime.JSX.Element | null;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Source: https://github.com/openai/openai-apps-sdk-examples/tree/main/src
|
|
46
|
+
*/
|
|
47
|
+
type OpenAIGlobals<ToolInput = UnknownObject, ToolOutput = UnknownObject, ToolResponseMetadata = UnknownObject, WidgetState = UnknownObject> = {
|
|
48
|
+
theme: Theme;
|
|
49
|
+
userAgent: UserAgent;
|
|
50
|
+
locale: string;
|
|
51
|
+
maxHeight: number;
|
|
52
|
+
displayMode: DisplayMode;
|
|
53
|
+
safeArea: SafeArea;
|
|
54
|
+
toolInput: ToolInput;
|
|
55
|
+
toolOutput: ToolOutput | null;
|
|
56
|
+
toolResponseMetadata: ToolResponseMetadata | null;
|
|
57
|
+
widgetState: WidgetState | null;
|
|
58
|
+
setWidgetState: (state: WidgetState) => Promise<void>;
|
|
59
|
+
};
|
|
60
|
+
type API = {
|
|
61
|
+
callTool: CallTool;
|
|
62
|
+
sendFollowUpMessage: (args: {
|
|
63
|
+
prompt: string;
|
|
64
|
+
}) => Promise<void>;
|
|
65
|
+
openExternal(payload: {
|
|
66
|
+
href: string;
|
|
67
|
+
}): void;
|
|
68
|
+
requestDisplayMode: RequestDisplayMode;
|
|
69
|
+
};
|
|
70
|
+
type UnknownObject = Record<string, unknown>;
|
|
71
|
+
type Theme = "light" | "dark";
|
|
72
|
+
type SafeAreaInsets = {
|
|
73
|
+
top: number;
|
|
74
|
+
bottom: number;
|
|
75
|
+
left: number;
|
|
76
|
+
right: number;
|
|
77
|
+
};
|
|
78
|
+
type SafeArea = {
|
|
79
|
+
insets: SafeAreaInsets;
|
|
80
|
+
};
|
|
81
|
+
type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
|
|
82
|
+
type UserAgent = {
|
|
83
|
+
device: {
|
|
84
|
+
type: DeviceType;
|
|
85
|
+
};
|
|
86
|
+
capabilities: {
|
|
87
|
+
hover: boolean;
|
|
88
|
+
touch: boolean;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
/** Display mode */
|
|
92
|
+
type DisplayMode = "pip" | "inline" | "fullscreen";
|
|
93
|
+
type RequestDisplayMode = (args: {
|
|
94
|
+
mode: DisplayMode;
|
|
95
|
+
}) => Promise<{
|
|
96
|
+
/**
|
|
97
|
+
* The granted display mode. The host may reject the request.
|
|
98
|
+
* For mobile, PiP is always coerced to fullscreen.
|
|
99
|
+
*/
|
|
100
|
+
mode: DisplayMode;
|
|
101
|
+
}>;
|
|
102
|
+
type CallToolResponse = {
|
|
103
|
+
result: string;
|
|
104
|
+
};
|
|
105
|
+
/** Calling APIs */
|
|
106
|
+
type CallTool = (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
|
|
107
|
+
/** Extra events */
|
|
108
|
+
declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
109
|
+
declare class SetGlobalsEvent extends CustomEvent<{
|
|
110
|
+
globals: Partial<OpenAIGlobals>;
|
|
111
|
+
}> {
|
|
112
|
+
constructor(detail: {
|
|
113
|
+
globals: Partial<OpenAIGlobals>;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Global oai object injected by the web sandbox for communicating with chatgpt host page.
|
|
118
|
+
*/
|
|
119
|
+
declare global {
|
|
120
|
+
interface Window {
|
|
121
|
+
openai: API & OpenAIGlobals;
|
|
122
|
+
innerBaseUrl: string;
|
|
123
|
+
}
|
|
124
|
+
interface WindowEventMap {
|
|
125
|
+
[SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
declare let mockState: Omit<OpenAIGlobals, "setWidgetState">;
|
|
130
|
+
declare function initializeMockOpenAI(initialToolOutput?: Record<string, unknown>): void;
|
|
131
|
+
declare function updateMockGlobal<K extends keyof OpenAIGlobals>(key: K, value: OpenAIGlobals[K]): void;
|
|
132
|
+
declare function getMockState(): typeof mockState;
|
|
133
|
+
declare function updateMockToolOutput(props: Record<string, unknown>): void;
|
|
134
|
+
declare function updateMockDisplayMode(mode: DisplayMode): void;
|
|
135
|
+
declare function updateMockTheme(theme: Theme): void;
|
|
136
|
+
|
|
137
|
+
type ModelContextContentBlock = ContentBlock;
|
|
138
|
+
type ModelContextUpdate = {
|
|
139
|
+
content?: ModelContextContentBlock[];
|
|
140
|
+
structuredContent?: Record<string, unknown>;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Result from calling a tool
|
|
145
|
+
*/
|
|
146
|
+
type ToolCallResult = CallToolResult;
|
|
147
|
+
/**
|
|
148
|
+
* Tool result notification (what the host pushes to the widget)
|
|
149
|
+
*/
|
|
150
|
+
type ToolResult = CallToolResult;
|
|
151
|
+
/**
|
|
152
|
+
* Host context - all values available from the host.
|
|
153
|
+
*/
|
|
154
|
+
type HostContext = {
|
|
155
|
+
theme: Theme;
|
|
156
|
+
locale: string;
|
|
157
|
+
displayMode: DisplayMode;
|
|
158
|
+
maxHeight: number | null;
|
|
159
|
+
safeArea: SafeArea | null;
|
|
160
|
+
toolOutput: UnknownObject | null;
|
|
161
|
+
toolResponseMetadata: UnknownObject | null;
|
|
162
|
+
widgetState: UnknownObject | null;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Unified widget client interface that works on both OpenAI and MCP Apps.
|
|
166
|
+
*
|
|
167
|
+
* Platform-specific behavior:
|
|
168
|
+
* - Display mode: OpenAI-only. MCP Apps returns "inline" and requestDisplayMode is a no-op.
|
|
169
|
+
* - Follow-up messages: Unified API, different underlying implementations.
|
|
170
|
+
*/
|
|
171
|
+
interface UnifiedWidgetClient {
|
|
172
|
+
/**
|
|
173
|
+
* Connect to the host. Must be called before using other methods.
|
|
174
|
+
* On OpenAI, this is a no-op (already connected via window.openai).
|
|
175
|
+
* On MCP Apps, this establishes the postMessage connection.
|
|
176
|
+
*/
|
|
177
|
+
connect(): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* Close the connection to the host and clean up resources.
|
|
180
|
+
* On OpenAI, this is a no-op.
|
|
181
|
+
* On MCP Apps, this closes the transport and removes event listeners.
|
|
182
|
+
*/
|
|
183
|
+
close(): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* Get the tool output (structured content returned by the tool handler).
|
|
186
|
+
* This is the main data source for widget rendering.
|
|
187
|
+
*/
|
|
188
|
+
getToolOutput<T = Record<string, unknown>>(): T | null;
|
|
189
|
+
/**
|
|
190
|
+
* Register a callback for when tool results are received.
|
|
191
|
+
* On OpenAI, this subscribes to toolOutput changes.
|
|
192
|
+
* On MCP Apps, this sets app.ontoolresult.
|
|
193
|
+
*/
|
|
194
|
+
onToolResult(callback: (result: ToolResult) => void): () => void;
|
|
195
|
+
/**
|
|
196
|
+
* Call another tool on the server.
|
|
197
|
+
*/
|
|
198
|
+
callTool(name: string, args: Record<string, unknown>): Promise<ToolCallResult>;
|
|
199
|
+
/**
|
|
200
|
+
* Open an external URL.
|
|
201
|
+
* On OpenAI: openai.openExternal({ href })
|
|
202
|
+
* On MCP Apps: app.sendOpenLink(url)
|
|
203
|
+
*/
|
|
204
|
+
openExternal(url: string): void;
|
|
205
|
+
/**
|
|
206
|
+
* Send a follow-up message to the AI.
|
|
207
|
+
* On OpenAI: openai.sendFollowUpMessage({ prompt })
|
|
208
|
+
* On MCP Apps: app.sendMessages([{ role: 'user', content: { type: 'text', text: prompt } }])
|
|
209
|
+
*/
|
|
210
|
+
sendFollowUp(prompt: string): void | Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* Update hidden model context for the next assistant turn.
|
|
213
|
+
* On MCP Apps this uses the standard `ui/update-model-context` request.
|
|
214
|
+
* On other hosts this may fall back to best-effort behavior.
|
|
215
|
+
*/
|
|
216
|
+
updateModelContext(context: ModelContextUpdate): Promise<void> | void;
|
|
217
|
+
/**
|
|
218
|
+
* Get the current theme.
|
|
219
|
+
*/
|
|
220
|
+
getTheme(): Theme;
|
|
221
|
+
/**
|
|
222
|
+
* Subscribe to theme changes.
|
|
223
|
+
*/
|
|
224
|
+
onThemeChange(callback: (theme: Theme) => void): () => void;
|
|
225
|
+
/**
|
|
226
|
+
* Get the current locale.
|
|
227
|
+
*/
|
|
228
|
+
getLocale(): string;
|
|
229
|
+
/**
|
|
230
|
+
* Get the current display mode.
|
|
231
|
+
* OpenAI-only: returns "pip" | "inline" | "fullscreen"
|
|
232
|
+
* MCP Apps: always returns "inline"
|
|
233
|
+
*/
|
|
234
|
+
getDisplayMode(): DisplayMode;
|
|
235
|
+
/**
|
|
236
|
+
* Request a display mode change.
|
|
237
|
+
* OpenAI-only: requests the mode from the host.
|
|
238
|
+
* MCP Apps: no-op (returns current mode).
|
|
239
|
+
*/
|
|
240
|
+
requestDisplayMode(mode: DisplayMode): Promise<DisplayMode>;
|
|
241
|
+
/**
|
|
242
|
+
* Subscribe to display mode changes.
|
|
243
|
+
* OpenAI-only: subscribes to displayMode changes.
|
|
244
|
+
* MCP Apps: callback is never called.
|
|
245
|
+
*/
|
|
246
|
+
onDisplayModeChange(callback: (mode: DisplayMode) => void): () => void;
|
|
247
|
+
/**
|
|
248
|
+
* Get the safe area insets.
|
|
249
|
+
* OpenAI-only: returns insets from window.openai.safeArea.
|
|
250
|
+
* MCP Apps: returns null.
|
|
251
|
+
*/
|
|
252
|
+
getSafeArea(): SafeArea | null;
|
|
253
|
+
/**
|
|
254
|
+
* Subscribe to safe area changes.
|
|
255
|
+
* OpenAI-only: subscribes to safeArea changes.
|
|
256
|
+
* MCP Apps: callback is never called.
|
|
257
|
+
*/
|
|
258
|
+
onSafeAreaChange(callback: (safeArea: SafeArea | null) => void): () => void;
|
|
259
|
+
/**
|
|
260
|
+
* Get the max height constraint.
|
|
261
|
+
* OpenAI-only: returns maxHeight from window.openai.maxHeight.
|
|
262
|
+
* MCP Apps: returns null.
|
|
263
|
+
*/
|
|
264
|
+
getMaxHeight(): number | null;
|
|
265
|
+
/**
|
|
266
|
+
* Subscribe to max height changes.
|
|
267
|
+
* OpenAI-only: subscribes to maxHeight changes.
|
|
268
|
+
* MCP Apps: callback is never called.
|
|
269
|
+
*/
|
|
270
|
+
onMaxHeightChange(callback: (maxHeight: number | null) => void): () => void;
|
|
271
|
+
/**
|
|
272
|
+
* Get the tool response metadata.
|
|
273
|
+
* OpenAI: returns metadata from window.openai.toolResponseMetadata.
|
|
274
|
+
* MCP Apps: returns `_meta` from the latest `ui/notifications/tool-result`, if provided by host.
|
|
275
|
+
*/
|
|
276
|
+
getToolResponseMetadata(): UnknownObject | null;
|
|
277
|
+
/**
|
|
278
|
+
* Subscribe to tool response metadata changes.
|
|
279
|
+
* OpenAI: subscribes to toolResponseMetadata changes.
|
|
280
|
+
* MCP Apps: fires when tool result `_meta` changes.
|
|
281
|
+
*/
|
|
282
|
+
onToolResponseMetadataChange(callback: (metadata: UnknownObject | null) => void): () => void;
|
|
283
|
+
/**
|
|
284
|
+
* Get the widget state.
|
|
285
|
+
* OpenAI-only: returns state from window.openai.widgetState.
|
|
286
|
+
* MCP Apps: returns null.
|
|
287
|
+
*/
|
|
288
|
+
getWidgetState(): UnknownObject | null;
|
|
289
|
+
/**
|
|
290
|
+
* Subscribe to widget state changes.
|
|
291
|
+
* OpenAI-only: subscribes to widgetState changes.
|
|
292
|
+
* MCP Apps: callback is never called.
|
|
293
|
+
*/
|
|
294
|
+
onWidgetStateChange(callback: (state: UnknownObject | null) => void): () => void;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Get a function to call other tools.
|
|
299
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
300
|
+
*
|
|
301
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
302
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
303
|
+
* @returns A function to call tools with their name and arguments
|
|
304
|
+
*/
|
|
305
|
+
declare function useCallTool(): (name: string, args: Record<string, unknown>) => Promise<ToolCallResult>;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Get the current display mode.
|
|
309
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
310
|
+
*
|
|
311
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
312
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
313
|
+
* @returns The current display mode ("pip" | "inline" | "fullscreen")
|
|
314
|
+
*/
|
|
315
|
+
declare function useDisplayMode(): DisplayMode;
|
|
316
|
+
|
|
317
|
+
/** Return type of the useFlowAction hook */
|
|
318
|
+
type FlowActionResult<T> = {
|
|
319
|
+
/** Current widget data from structuredContent. */
|
|
320
|
+
data: T | null;
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* Hook for reading flow widget data from structuredContent.
|
|
324
|
+
* Lightweight wrapper over `useToolOutput` — will be extended
|
|
325
|
+
* with flow-specific features in the future.
|
|
326
|
+
*
|
|
327
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
328
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```tsx
|
|
332
|
+
* const { data } = useFlowAction<{ plans: string[] }>();
|
|
333
|
+
* if (!data) return null;
|
|
334
|
+
* return <PricingTable plans={data.plans} />;
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
declare function useFlowAction<T extends Record<string, unknown>>(): FlowActionResult<T>;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Check if running in ChatGPT app (OpenAI-only).
|
|
341
|
+
* Returns false on MCP Apps.
|
|
342
|
+
*
|
|
343
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
344
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
345
|
+
* @returns Whether the widget is running in ChatGPT app
|
|
346
|
+
*/
|
|
347
|
+
declare function useIsChatGptApp(): boolean;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Get the current locale.
|
|
351
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
352
|
+
*
|
|
353
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
354
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
355
|
+
* @returns The current locale string (e.g., "en-US")
|
|
356
|
+
*/
|
|
357
|
+
declare function useLocale(): string;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Get the maximum height available for the widget (OpenAI-only).
|
|
361
|
+
* Useful for responsive layouts that need to adapt to container constraints.
|
|
362
|
+
* Returns null on MCP Apps.
|
|
363
|
+
*
|
|
364
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
365
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
366
|
+
* @returns The maximum height in pixels, or null if not available
|
|
367
|
+
*/
|
|
368
|
+
declare function useMaxHeight(): number | null;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Get a function to open external URLs.
|
|
372
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
373
|
+
*
|
|
374
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
375
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
376
|
+
* @returns A function that opens external URLs
|
|
377
|
+
*/
|
|
378
|
+
declare function useOpenExternal(): (url: string) => void;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Get a function to request display mode changes.
|
|
382
|
+
* On MCP Apps, this may be a no-op depending on host support.
|
|
383
|
+
*
|
|
384
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
385
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
386
|
+
* @returns A function to request a specific display mode
|
|
387
|
+
*/
|
|
388
|
+
declare function useRequestDisplayMode(): (mode: DisplayMode) => Promise<DisplayMode>;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Get safe area insets (OpenAI-only).
|
|
392
|
+
* Useful for ensuring UI elements don't get hidden behind the chat input.
|
|
393
|
+
* Returns null on MCP Apps.
|
|
394
|
+
*
|
|
395
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
396
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
397
|
+
* @returns The safe area insets, or null if not available
|
|
398
|
+
*/
|
|
399
|
+
declare function useSafeArea(): SafeArea | null;
|
|
400
|
+
|
|
401
|
+
interface SendFollowUpOptions {
|
|
402
|
+
modelContext?: ModelContextUpdate | null;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Get a function to send follow-up messages to the AI.
|
|
406
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
407
|
+
*
|
|
408
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
409
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
410
|
+
* @returns A function that sends a follow-up message
|
|
411
|
+
*/
|
|
412
|
+
declare function useSendFollowUp(): (prompt: string, options?: SendFollowUpOptions) => void;
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Get the current theme.
|
|
416
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
417
|
+
*
|
|
418
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
419
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
420
|
+
* @returns The current theme ("light" | "dark")
|
|
421
|
+
*/
|
|
422
|
+
declare function useTheme(): Theme;
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Get the tool output (structured content returned by the tool handler).
|
|
426
|
+
* Works on both OpenAI widgets and MCP Apps.
|
|
427
|
+
*
|
|
428
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
429
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
430
|
+
* @returns The tool output or null
|
|
431
|
+
*/
|
|
432
|
+
declare function useToolOutput<T extends Record<string, unknown>>(): T | null;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Get tool response metadata.
|
|
436
|
+
* Contains host/tool metadata (for example identifiers like
|
|
437
|
+
* `openai/widgetSessionId` and custom tool `_meta` fields).
|
|
438
|
+
* Returns null when the host does not provide metadata.
|
|
439
|
+
*
|
|
440
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
441
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
442
|
+
* @returns The tool response metadata object or null if not available
|
|
443
|
+
*/
|
|
444
|
+
declare function useToolResponseMetadata(): UnknownObject | null;
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Get a function to update hidden model context for the next assistant turn.
|
|
448
|
+
* Uses the MCP Apps `ui/update-model-context` request when available.
|
|
449
|
+
*
|
|
450
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
451
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
452
|
+
*/
|
|
453
|
+
declare function useUpdateModelContext(): (context: ModelContextUpdate) => Promise<void>;
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Provider props
|
|
457
|
+
*/
|
|
458
|
+
interface WidgetProviderProps {
|
|
459
|
+
children: ReactNode;
|
|
460
|
+
/** Optional loading component while connecting */
|
|
461
|
+
loading?: ReactNode;
|
|
462
|
+
/** Optional error component */
|
|
463
|
+
onError?: (error: Error) => ReactNode;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Provider component that initializes the correct widget client based on platform.
|
|
467
|
+
* Wrap your widget component with this provider.
|
|
468
|
+
*
|
|
469
|
+
* @deprecated Part of the legacy MCP-widget-in-host stack (used with `createResource` /
|
|
470
|
+
* `createTool`). Preserved for back-compat; will move to `@waniwani/sdk/legacy/react` in
|
|
471
|
+
* a future minor release. For new code, use `createFlow` from `@waniwani/sdk/mcp` and
|
|
472
|
+
* `useWaniwani` from `@waniwani/sdk/mcp/react`.
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```tsx
|
|
476
|
+
* function App() {
|
|
477
|
+
* return (
|
|
478
|
+
* <WidgetProvider loading={<Spinner />}>
|
|
479
|
+
* <MyWidget />
|
|
480
|
+
* </WidgetProvider>
|
|
481
|
+
* );
|
|
482
|
+
* }
|
|
483
|
+
* ```
|
|
484
|
+
*/
|
|
485
|
+
declare function WidgetProvider({ children, loading, onError, }: WidgetProviderProps): React$1.FunctionComponentElement<React$1.FragmentProps> | React$1.FunctionComponentElement<React$1.ProviderProps<UnifiedWidgetClient | null>>;
|
|
486
|
+
/**
|
|
487
|
+
* Keys that can be selected from the widget client.
|
|
488
|
+
*/
|
|
489
|
+
type WidgetKey = "toolOutput" | "theme" | "displayMode" | "locale" | "safeArea" | "maxHeight" | "toolResponseMetadata" | "widgetState";
|
|
490
|
+
/**
|
|
491
|
+
* Value types for each widget key.
|
|
492
|
+
*/
|
|
493
|
+
type WidgetKeyValues = {
|
|
494
|
+
toolOutput: Record<string, unknown> | null;
|
|
495
|
+
theme: Theme;
|
|
496
|
+
displayMode: DisplayMode;
|
|
497
|
+
locale: string;
|
|
498
|
+
safeArea: SafeArea | null;
|
|
499
|
+
maxHeight: number | null;
|
|
500
|
+
toolResponseMetadata: UnknownObject | null;
|
|
501
|
+
widgetState: UnknownObject | null;
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* Get the unified widget client instance.
|
|
505
|
+
* Must be used within a WidgetProvider.
|
|
506
|
+
*
|
|
507
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
508
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```tsx
|
|
512
|
+
* // Full client for actions
|
|
513
|
+
* const client = useWidgetClient();
|
|
514
|
+
* client.callTool("foo", {});
|
|
515
|
+
*
|
|
516
|
+
* // Key selector for reactive values
|
|
517
|
+
* const toolOutput = useWidgetClient("toolOutput");
|
|
518
|
+
* const theme = useWidgetClient("theme");
|
|
519
|
+
* ```
|
|
520
|
+
*/
|
|
521
|
+
declare function useWidgetClient(): UnifiedWidgetClient;
|
|
522
|
+
declare function useWidgetClient<K extends WidgetKey>(key: K): WidgetKeyValues[K];
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Widget state that persists across widget lifecycles (OpenAI-only).
|
|
526
|
+
* State is synchronized with the ChatGPT parent window and survives widget minimize/restore.
|
|
527
|
+
* On MCP Apps, returns [null, no-op].
|
|
528
|
+
*
|
|
529
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
530
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
531
|
+
* @param defaultState - Initial state value or function to compute it
|
|
532
|
+
* @returns A tuple of [state, setState] similar to useState
|
|
533
|
+
*/
|
|
534
|
+
declare function useWidgetState<T extends UnknownObject>(defaultState?: T | (() => T | null) | null): readonly [T | null, (state: SetStateAction<T | null>) => void];
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Default loading fallback for legacy MCP widgets.
|
|
538
|
+
*
|
|
539
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
540
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
541
|
+
*/
|
|
542
|
+
declare const LoadingWidget: () => react_jsx_runtime.JSX.Element;
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Widget platform types
|
|
546
|
+
*/
|
|
547
|
+
type WidgetPlatform = "openai" | "mcp-apps";
|
|
548
|
+
/**
|
|
549
|
+
* Detects which platform the widget is running on.
|
|
550
|
+
*
|
|
551
|
+
* OpenAI injects a global `window.openai` object.
|
|
552
|
+
* MCP Apps runs in a sandboxed iframe and uses postMessage.
|
|
553
|
+
*
|
|
554
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
555
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
556
|
+
*/
|
|
557
|
+
declare function detectPlatform(): WidgetPlatform;
|
|
558
|
+
/**
|
|
559
|
+
* Check if running on OpenAI platform.
|
|
560
|
+
*
|
|
561
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
562
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
563
|
+
*/
|
|
564
|
+
declare function isOpenAI(): boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Check if running on MCP Apps platform.
|
|
567
|
+
*
|
|
568
|
+
* @deprecated Legacy MCP-widget-in-host stack. Preserved for back-compat; will move to
|
|
569
|
+
* `@waniwani/sdk/legacy/react` in a future minor release.
|
|
570
|
+
*/
|
|
571
|
+
declare function isMCPApps(): boolean;
|
|
572
|
+
|
|
573
|
+
export { DevModeProvider, type DeviceType, type DisplayMode, type FlowActionResult, type HostContext, InitializeNextJsInIframe, LoadingWidget, type ModelContextContentBlock, type ModelContextUpdate, type SafeArea, type SafeAreaInsets, type SendFollowUpOptions, type Theme, type ToolCallResult, type ToolResult, type UnifiedWidgetClient, type UnknownObject, type UserAgent, type WidgetPlatform, WidgetProvider, detectPlatform, getMockState, initializeMockOpenAI, isMCPApps, isOpenAI, updateMockDisplayMode, updateMockGlobal, updateMockTheme, updateMockToolOutput, useCallTool, useDisplayMode, useFlowAction, useIsChatGptApp, useLocale, useMaxHeight, useOpenExternal, useRequestDisplayMode, useSafeArea, useSendFollowUp, useTheme, useToolOutput, useToolResponseMetadata, useUpdateModelContext, useWidgetClient, useWidgetState };
|