open-mcp-app 0.1.4 → 0.1.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.
- package/dist/react/index.d.ts +3 -118
- package/dist/react/index.js +8 -58
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/vite/index.js +45 -27
- package/dist/vite/index.js.map +1 -1
- package/package.json +1 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ToolResult, WidgetState, Environment, DisplayMode, AdapterKind, HostContext, ExperimentalHostApi, WebSocketStatus
|
|
2
|
-
export { BaseHostClient, BaseHostClientEvents, ChatGptAdapter, CreatureAdapter, HostAdapter, HostClientConfig, HostClientState, HostIdentity, KNOWN_HOSTS, LogLevel, McpAppsAdapter, StandaloneAdapter, StructuredWidgetState, UnifiedHostClientEvents, UpgradingMcpAppsClient, WebSocketClient, WebSocketClientConfig, createHost, createHostAsync, createWebSocket, detectEnvironment, getHostIdentity, isHost, parseHostUserAgent } from '../core/index.js';
|
|
1
|
+
import { ToolResult, WidgetState, Environment, DisplayMode, AdapterKind, HostContext, ExperimentalHostApi, 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
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
export { applyDocumentTheme, applyHostFonts, applyHostStyleVariables, getDocumentTheme } from '@modelcontextprotocol/ext-apps';
|
|
@@ -317,17 +317,6 @@ declare function useWebSocket<TSend = unknown, TReceive = unknown>(url: string |
|
|
|
317
317
|
*/
|
|
318
318
|
declare function CreatureIcon({ isDarkMode, showEyes, enableBlink, width, height, className, }: CreatureIconProps): react_jsx_runtime.JSX.Element;
|
|
319
319
|
|
|
320
|
-
/**
|
|
321
|
-
* Get the host client from context.
|
|
322
|
-
*
|
|
323
|
-
* @throws Error if used outside of HostProvider
|
|
324
|
-
*/
|
|
325
|
-
declare function useHostClient(): UnifiedHostClient;
|
|
326
|
-
/**
|
|
327
|
-
* Get the host client from context, or null if not in a provider.
|
|
328
|
-
* Useful for optional host features.
|
|
329
|
-
*/
|
|
330
|
-
declare function useHostClientOptional(): UnifiedHostClient | null;
|
|
331
320
|
interface HostProviderProps {
|
|
332
321
|
/** App name for the host client */
|
|
333
322
|
name: string;
|
|
@@ -366,108 +355,4 @@ interface HostProviderProps {
|
|
|
366
355
|
*/
|
|
367
356
|
declare function HostProvider({ name, version, children, onToolInput, onThemeChange, onTeardown, }: HostProviderProps): react_jsx_runtime.JSX.Element;
|
|
368
357
|
|
|
369
|
-
|
|
370
|
-
* Experimental React Hooks
|
|
371
|
-
*
|
|
372
|
-
* These hooks provide React-idiomatic APIs for non-spec host features.
|
|
373
|
-
* They follow the Vercel AI SDK naming convention with `experimental_` prefix.
|
|
374
|
-
*
|
|
375
|
-
* Usage:
|
|
376
|
-
* ```tsx
|
|
377
|
-
* import {
|
|
378
|
-
* experimental_useWidgetState as useWidgetState,
|
|
379
|
-
* experimental_useTitle as useTitle,
|
|
380
|
-
* } from 'open-mcp-app/react';
|
|
381
|
-
* ```
|
|
382
|
-
*/
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* React hook for managing widget state with host synchronization.
|
|
386
|
-
*
|
|
387
|
-
* Returns a tuple similar to `useState`, but the state is:
|
|
388
|
-
* - Persisted by the host across sessions
|
|
389
|
-
* - Restored when the widget is re-opened
|
|
390
|
-
* - Optionally visible to the AI model (via `modelContent`)
|
|
391
|
-
*
|
|
392
|
-
* **Experimental:** This uses the `ui/notifications/widget-state-changed`
|
|
393
|
-
* notification which is not part of the MCP Apps specification.
|
|
394
|
-
*
|
|
395
|
-
* @returns Tuple of [state, setState] like useState
|
|
396
|
-
*
|
|
397
|
-
* @example
|
|
398
|
-
* ```tsx
|
|
399
|
-
* import { experimental_useWidgetState as useWidgetState } from 'open-mcp-app/react';
|
|
400
|
-
*
|
|
401
|
-
* function Counter() {
|
|
402
|
-
* const [state, setState] = useWidgetState<{ count: number }>();
|
|
403
|
-
*
|
|
404
|
-
* return (
|
|
405
|
-
* <button onClick={() => setState({ count: (state?.count ?? 0) + 1 })}>
|
|
406
|
-
* Count: {state?.count ?? 0}
|
|
407
|
-
* </button>
|
|
408
|
-
* );
|
|
409
|
-
* }
|
|
410
|
-
* ```
|
|
411
|
-
*/
|
|
412
|
-
declare function experimental_useWidgetState<T extends WidgetState = WidgetState>(): [
|
|
413
|
-
T | null,
|
|
414
|
-
(state: T | null) => void
|
|
415
|
-
];
|
|
416
|
-
/**
|
|
417
|
-
* React hook for setting the widget/PiP title.
|
|
418
|
-
*
|
|
419
|
-
* Returns a setter function to update the title displayed in the host UI.
|
|
420
|
-
* This is useful for dynamic titles that change based on widget state.
|
|
421
|
-
*
|
|
422
|
-
* **Experimental:** This uses the `ui/notifications/title-changed`
|
|
423
|
-
* notification which is a Creature-specific extension, not part of
|
|
424
|
-
* the MCP Apps specification. No-op on other hosts.
|
|
425
|
-
*
|
|
426
|
-
* @returns Function to set the title
|
|
427
|
-
*
|
|
428
|
-
* @example
|
|
429
|
-
* ```tsx
|
|
430
|
-
* import { experimental_useTitle as useTitle } from 'open-mcp-app/react';
|
|
431
|
-
*
|
|
432
|
-
* function DocumentEditor() {
|
|
433
|
-
* const setTitle = useTitle();
|
|
434
|
-
* const [docName, setDocName] = useState("Untitled");
|
|
435
|
-
*
|
|
436
|
-
* useEffect(() => {
|
|
437
|
-
* setTitle(`Editing: ${docName}`);
|
|
438
|
-
* }, [docName, setTitle]);
|
|
439
|
-
*
|
|
440
|
-
* return <input value={docName} onChange={(e) => setDocName(e.target.value)} />;
|
|
441
|
-
* }
|
|
442
|
-
* ```
|
|
443
|
-
*/
|
|
444
|
-
declare function experimental_useTitle(): (title: string) => void;
|
|
445
|
-
/**
|
|
446
|
-
* React hook for accessing Creature-specific CSS style variables.
|
|
447
|
-
*
|
|
448
|
-
* Returns the custom CSS variables provided by the Creature host,
|
|
449
|
-
* or null if not running in Creature.
|
|
450
|
-
*
|
|
451
|
-
* **Experimental:** This is a Creature-specific extension, not part of
|
|
452
|
-
* the MCP Apps specification.
|
|
453
|
-
*
|
|
454
|
-
* @returns Creature styles object or null
|
|
455
|
-
*
|
|
456
|
-
* @example
|
|
457
|
-
* ```tsx
|
|
458
|
-
* import { experimental_useCreatureStyles as useCreatureStyles } from 'open-mcp-app/react';
|
|
459
|
-
*
|
|
460
|
-
* function ThemedComponent() {
|
|
461
|
-
* const styles = useCreatureStyles();
|
|
462
|
-
*
|
|
463
|
-
* return (
|
|
464
|
-
* <div style={{ color: styles?.['--creature-accent-color'] }}>
|
|
465
|
-
* Themed content
|
|
466
|
-
* </div>
|
|
467
|
-
* );
|
|
468
|
-
* }
|
|
469
|
-
* ```
|
|
470
|
-
*/
|
|
471
|
-
declare function experimental_useCreatureStyles(): Record<string, string | undefined> | null;
|
|
472
|
-
|
|
473
|
-
export { AdapterKind, CreatureIcon, type CreatureIconProps, DisplayMode, Environment, ExperimentalHostApi, HostContext, HostProvider, type HostProviderProps, type Logger, type ToolCallFunction, type ToolCallState, type ToolCallStatus, type ToolCallTuple, ToolResult, UnifiedHostClient, type UseHostConfig, type UseHostReturn, type UseToolResultReturn, type UseWebSocketConfig, type UseWebSocketReturn, WebSocketStatus, WidgetState, experimental_useCreatureStyles, experimental_useTitle, experimental_useWidgetState, useHost, useHostClient, useHostClientOptional, useToolResult, useWebSocket };
|
|
358
|
+
export { AdapterKind, CreatureIcon, type CreatureIconProps, DisplayMode, Environment, ExperimentalHostApi, HostContext, HostProvider, type HostProviderProps, type Logger, type ToolCallFunction, type ToolCallState, type ToolCallStatus, type ToolCallTuple, ToolResult, type UseHostConfig, type UseHostReturn, type UseToolResultReturn, type UseWebSocketConfig, type UseWebSocketReturn, WebSocketStatus, WidgetState, useHost, useToolResult, useWebSocket };
|
package/dist/react/index.js
CHANGED
|
@@ -10575,15 +10575,6 @@ async function createHostAsync(config) {
|
|
|
10575
10575
|
import { createContext, useContext, useRef, useEffect } from "react";
|
|
10576
10576
|
import { jsx } from "react/jsx-runtime";
|
|
10577
10577
|
var HostContext = createContext(null);
|
|
10578
|
-
function useHostClient() {
|
|
10579
|
-
const client = useContext(HostContext);
|
|
10580
|
-
if (!client) {
|
|
10581
|
-
throw new Error(
|
|
10582
|
-
'useHostClient must be used within a HostProvider. Wrap your app with <HostProvider name="..." version="...">.'
|
|
10583
|
-
);
|
|
10584
|
-
}
|
|
10585
|
-
return client;
|
|
10586
|
-
}
|
|
10587
10578
|
function useHostClientOptional() {
|
|
10588
10579
|
return useContext(HostContext);
|
|
10589
10580
|
}
|
|
@@ -10768,15 +10759,18 @@ function useHost(config) {
|
|
|
10768
10759
|
() => client.getState(),
|
|
10769
10760
|
() => client.getState()
|
|
10770
10761
|
);
|
|
10762
|
+
const setWidgetState = useCallback(
|
|
10763
|
+
(newState) => {
|
|
10764
|
+
client.experimental.setWidgetState(newState);
|
|
10765
|
+
},
|
|
10766
|
+
[client]
|
|
10767
|
+
);
|
|
10771
10768
|
const experimental_widgetState = useCallback(
|
|
10772
10769
|
() => {
|
|
10773
10770
|
const currentState = state.widgetState;
|
|
10774
|
-
|
|
10775
|
-
client.experimental.setWidgetState(newState);
|
|
10776
|
-
};
|
|
10777
|
-
return [currentState, setState];
|
|
10771
|
+
return [currentState, setWidgetState];
|
|
10778
10772
|
},
|
|
10779
|
-
[state.widgetState,
|
|
10773
|
+
[state.widgetState, setWidgetState]
|
|
10780
10774
|
);
|
|
10781
10775
|
const callbacksRef = useRef2({
|
|
10782
10776
|
onToolInput: config?.onToolInput,
|
|
@@ -11031,45 +11025,6 @@ function CreatureIcon({
|
|
|
11031
11025
|
}
|
|
11032
11026
|
);
|
|
11033
11027
|
}
|
|
11034
|
-
|
|
11035
|
-
// src/react/experimental.ts
|
|
11036
|
-
import { useState as useState4, useEffect as useEffect5, useCallback as useCallback4, useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
11037
|
-
function experimental_useWidgetState() {
|
|
11038
|
-
const client = useHostClient();
|
|
11039
|
-
const state = useSyncExternalStore3(
|
|
11040
|
-
(onStoreChange) => client.subscribe(onStoreChange),
|
|
11041
|
-
() => client.getState().widgetState,
|
|
11042
|
-
() => client.getState().widgetState
|
|
11043
|
-
);
|
|
11044
|
-
const setState = useCallback4(
|
|
11045
|
-
(newState) => {
|
|
11046
|
-
client.experimental.setWidgetState(newState);
|
|
11047
|
-
},
|
|
11048
|
-
[client]
|
|
11049
|
-
);
|
|
11050
|
-
return [state, setState];
|
|
11051
|
-
}
|
|
11052
|
-
function experimental_useTitle() {
|
|
11053
|
-
const client = useHostClient();
|
|
11054
|
-
const setTitle = useCallback4(
|
|
11055
|
-
(title) => {
|
|
11056
|
-
client.experimental.setTitle(title);
|
|
11057
|
-
},
|
|
11058
|
-
[client]
|
|
11059
|
-
);
|
|
11060
|
-
return setTitle;
|
|
11061
|
-
}
|
|
11062
|
-
function experimental_useCreatureStyles() {
|
|
11063
|
-
const client = useHostClient();
|
|
11064
|
-
const [styles, setStyles] = useState4(() => client.experimental.getCreatureStyles());
|
|
11065
|
-
useEffect5(() => {
|
|
11066
|
-
const unsub = client.on("theme-change", () => {
|
|
11067
|
-
setStyles(client.experimental.getCreatureStyles());
|
|
11068
|
-
});
|
|
11069
|
-
return unsub;
|
|
11070
|
-
}, [client]);
|
|
11071
|
-
return styles;
|
|
11072
|
-
}
|
|
11073
11028
|
export {
|
|
11074
11029
|
ChatGptAdapter,
|
|
11075
11030
|
CreatureAdapter,
|
|
@@ -11086,16 +11041,11 @@ export {
|
|
|
11086
11041
|
createHostAsync,
|
|
11087
11042
|
createWebSocket,
|
|
11088
11043
|
detectEnvironment,
|
|
11089
|
-
experimental_useCreatureStyles,
|
|
11090
|
-
experimental_useTitle,
|
|
11091
|
-
experimental_useWidgetState,
|
|
11092
11044
|
VU as getDocumentTheme,
|
|
11093
11045
|
getHostIdentity,
|
|
11094
11046
|
isHost,
|
|
11095
11047
|
parseHostUserAgent,
|
|
11096
11048
|
useHost,
|
|
11097
|
-
useHostClient,
|
|
11098
|
-
useHostClientOptional,
|
|
11099
11049
|
useToolResult,
|
|
11100
11050
|
useWebSocket
|
|
11101
11051
|
};
|