open-mcp-app 0.1.0 → 0.1.1
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/dist/core/index.d.ts +1171 -0
- package/dist/core/index.js +10910 -0
- package/dist/core/index.js.map +1 -0
- package/dist/react/index.d.ts +196 -0
- package/dist/react/index.js +10857 -0
- package/dist/react/index.js.map +1 -0
- package/dist/server/index.d.ts +863 -0
- package/dist/server/index.js +15074 -0
- package/dist/server/index.js.map +1 -0
- package/dist/vite/index.d.ts +69 -0
- package/dist/vite/index.js +362 -0
- package/dist/vite/index.js.map +1 -0
- package/package.json +70 -16
- package/LICENSE +0 -22
- package/README.md +0 -36
- package/index.js +0 -363
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { ToolResult, WidgetState, Environment, DisplayMode, AdapterKind, HostContext, WebSocketStatus } from '../core/index.js';
|
|
2
|
+
export { BaseHostClient, BaseHostClientEvents, ChatGptAdapter, CreatureAdapter, HostAdapter, HostClientConfig, HostClientState, HostIdentity, KNOWN_HOSTS, LogLevel, McpAppsAdapter, StandaloneAdapter, StructuredWidgetState, UnifiedHostClient, UnifiedHostClientEvents, UpgradingMcpAppsClient, WebSocketClient, WebSocketClientConfig, createHost, createHostAsync, createWebSocket, detectEnvironment, getHostIdentity, isHost, parseHostUserAgent } from '../core/index.js';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
export { applyDocumentTheme, applyHostFonts, applyHostStyleVariables, getDocumentTheme } from '@modelcontextprotocol/ext-apps';
|
|
5
|
+
|
|
6
|
+
interface UseHostConfig {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
onToolInput?: (args: Record<string, unknown>) => void;
|
|
10
|
+
onToolResult?: (result: ToolResult) => void;
|
|
11
|
+
onThemeChange?: (theme: "light" | "dark") => void;
|
|
12
|
+
onTeardown?: () => Promise<void>;
|
|
13
|
+
/** Called when widget state changes (restored from host or updated) */
|
|
14
|
+
onWidgetStateChange?: (widgetState: WidgetState | null) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Logger interface with convenience methods for each log level.
|
|
18
|
+
*
|
|
19
|
+
* Provides both a default `log(message, data?)` method (logs at "info" level)
|
|
20
|
+
* and explicit level methods: `debug()`, `info()`, `notice()`, `warn()`, `error()`.
|
|
21
|
+
*/
|
|
22
|
+
interface Logger {
|
|
23
|
+
/**
|
|
24
|
+
* Log a message at "info" level (default).
|
|
25
|
+
* @param message - Log message
|
|
26
|
+
* @param data - Optional structured data
|
|
27
|
+
*/
|
|
28
|
+
(message: string, data?: Record<string, unknown>): void;
|
|
29
|
+
/**
|
|
30
|
+
* Log at "debug" level. Gray in DevConsole, typically hidden by default.
|
|
31
|
+
*/
|
|
32
|
+
debug: (message: string, data?: Record<string, unknown>) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Log at "info" level. Normal text color in DevConsole.
|
|
35
|
+
*/
|
|
36
|
+
info: (message: string, data?: Record<string, unknown>) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Log at "notice" level. Blue in DevConsole, for notable events.
|
|
39
|
+
*/
|
|
40
|
+
notice: (message: string, data?: Record<string, unknown>) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Log at "warning" level. Yellow in DevConsole.
|
|
43
|
+
*/
|
|
44
|
+
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Log at "error" level. Red in DevConsole.
|
|
47
|
+
*/
|
|
48
|
+
error: (message: string, data?: Record<string, unknown>) => void;
|
|
49
|
+
}
|
|
50
|
+
interface UseHostReturn {
|
|
51
|
+
isReady: boolean;
|
|
52
|
+
callTool: <T = Record<string, unknown>>(toolName: string, args: Record<string, unknown>) => Promise<ToolResult<T>>;
|
|
53
|
+
sendNotification: (method: string, params: unknown) => void;
|
|
54
|
+
environment: Environment;
|
|
55
|
+
widgetState: WidgetState | null;
|
|
56
|
+
setWidgetState: (state: WidgetState | null) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Set the pip/widget title displayed in the host UI.
|
|
59
|
+
*
|
|
60
|
+
* Useful for updating the title based on user actions (e.g., switching tabs)
|
|
61
|
+
* without making a tool call.
|
|
62
|
+
*
|
|
63
|
+
* Note: Creature-specific extension, no-op on ChatGPT Apps.
|
|
64
|
+
*
|
|
65
|
+
* @param title - The new title to display
|
|
66
|
+
*/
|
|
67
|
+
setTitle: (title: string) => void;
|
|
68
|
+
requestDisplayMode: (params: {
|
|
69
|
+
mode: DisplayMode;
|
|
70
|
+
}) => Promise<{
|
|
71
|
+
mode: DisplayMode;
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* The adapter kind currently in use.
|
|
75
|
+
* For MCP Apps, this is determined after connection based on hostContext.userAgent.
|
|
76
|
+
* Values: "mcp-apps" | "creature" | "chatgpt" | "standalone"
|
|
77
|
+
*/
|
|
78
|
+
adapterKind: AdapterKind;
|
|
79
|
+
/**
|
|
80
|
+
* Whether this host is Creature (supports Creature-specific extensions).
|
|
81
|
+
* Determined via hostContext.userAgent after connection.
|
|
82
|
+
*/
|
|
83
|
+
isCreature: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Get the host context received from the host.
|
|
86
|
+
* Contains theme, styles, userAgent, and host-specific properties.
|
|
87
|
+
* Returns null before connection is established.
|
|
88
|
+
*/
|
|
89
|
+
hostContext: HostContext | null;
|
|
90
|
+
/**
|
|
91
|
+
* Logger for sending messages to the host's DevConsole.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```tsx
|
|
95
|
+
* const { log } = useHost({ name: "my-app", version: "1.0.0" });
|
|
96
|
+
*
|
|
97
|
+
* // Default level (info)
|
|
98
|
+
* log("User clicked button");
|
|
99
|
+
*
|
|
100
|
+
* // With data
|
|
101
|
+
* log("Processing item", { itemId: 123 });
|
|
102
|
+
*
|
|
103
|
+
* // Specific levels
|
|
104
|
+
* log.debug("Verbose debugging info");
|
|
105
|
+
* log.info("General information");
|
|
106
|
+
* log.notice("Notable event");
|
|
107
|
+
* log.warn("Something looks off");
|
|
108
|
+
* log.error("Something went wrong", { error: err.message });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
log: Logger;
|
|
112
|
+
}
|
|
113
|
+
interface UseToolResultReturn<T> {
|
|
114
|
+
/** Structured data from tool result */
|
|
115
|
+
data: T | null;
|
|
116
|
+
/** Instance ID for this widget */
|
|
117
|
+
instanceId: string | null;
|
|
118
|
+
/** Title for PIP tab */
|
|
119
|
+
title: string | null;
|
|
120
|
+
/** Whether this is an error result */
|
|
121
|
+
isError: boolean;
|
|
122
|
+
/** Text content for AI context */
|
|
123
|
+
text: string | null;
|
|
124
|
+
/** Callback to handle tool result */
|
|
125
|
+
onToolResult: (result: ToolResult) => void;
|
|
126
|
+
/** Reset all state */
|
|
127
|
+
reset: () => void;
|
|
128
|
+
}
|
|
129
|
+
interface UseWebSocketConfig<TReceive = unknown> {
|
|
130
|
+
onMessage?: (message: TReceive) => void;
|
|
131
|
+
enabled?: boolean;
|
|
132
|
+
}
|
|
133
|
+
interface UseWebSocketReturn<TSend = unknown> {
|
|
134
|
+
status: WebSocketStatus;
|
|
135
|
+
error: string | undefined;
|
|
136
|
+
send: (message: TSend) => void;
|
|
137
|
+
}
|
|
138
|
+
interface CreatureIconProps {
|
|
139
|
+
/** Whether the app is in dark mode */
|
|
140
|
+
isDarkMode: boolean;
|
|
141
|
+
/** Whether to show the eyes (default: true) */
|
|
142
|
+
showEyes?: boolean;
|
|
143
|
+
/** Whether to enable eye blinking animation (default: false) */
|
|
144
|
+
enableBlink?: boolean;
|
|
145
|
+
/** Width of the icon in pixels */
|
|
146
|
+
width?: number;
|
|
147
|
+
/** Height of the icon in pixels */
|
|
148
|
+
height?: number;
|
|
149
|
+
/** Optional className for additional styling */
|
|
150
|
+
className?: string;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* React hook for connecting to an MCP Apps host.
|
|
155
|
+
*
|
|
156
|
+
* Creates a host client instance and manages its lifecycle. Automatically
|
|
157
|
+
* connects on mount and disconnects on unmount. Uses refs for callbacks
|
|
158
|
+
* to prevent reconnection loops when consumers pass inline functions.
|
|
159
|
+
*
|
|
160
|
+
* @param config - Configuration including app info and event handlers
|
|
161
|
+
* @returns Current state and methods for interacting with the host
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```tsx
|
|
165
|
+
* const { isReady, callTool, log } = useHost({
|
|
166
|
+
* name: "my-app",
|
|
167
|
+
* version: "1.0.0",
|
|
168
|
+
* onToolResult: (result) => setData(result.structuredContent),
|
|
169
|
+
* });
|
|
170
|
+
*
|
|
171
|
+
* // Logging
|
|
172
|
+
* log("User action"); // default info level
|
|
173
|
+
* log.debug("Verbose info");
|
|
174
|
+
* log.error("Something failed", { error: err.message });
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
declare function useHost(config: UseHostConfig): UseHostReturn;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Hook to access tool result data.
|
|
181
|
+
* Extracts data, instanceId, title, and error state from tool results.
|
|
182
|
+
*/
|
|
183
|
+
declare function useToolResult<T = Record<string, unknown>>(): UseToolResultReturn<T>;
|
|
184
|
+
|
|
185
|
+
declare function useWebSocket<TSend = unknown, TReceive = unknown>(url: string | undefined, config?: UseWebSocketConfig<TReceive>): UseWebSocketReturn<TSend>;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* CreatureIcon Component
|
|
189
|
+
*
|
|
190
|
+
* The Creature mascot icon with theme-aware colors.
|
|
191
|
+
* Uses the main creature shape with optional eyes, adapting colors for dark/light mode.
|
|
192
|
+
* Supports optional eye blinking animation at random intervals.
|
|
193
|
+
*/
|
|
194
|
+
declare function CreatureIcon({ isDarkMode, showEyes, enableBlink, width, height, className, }: CreatureIconProps): react_jsx_runtime.JSX.Element;
|
|
195
|
+
|
|
196
|
+
export { AdapterKind, CreatureIcon, type CreatureIconProps, DisplayMode, Environment, HostContext, type Logger, ToolResult, type UseHostConfig, type UseHostReturn, type UseToolResultReturn, type UseWebSocketConfig, type UseWebSocketReturn, WebSocketStatus, WidgetState, useHost, useToolResult, useWebSocket };
|