@botdojo/chat-sdk 0.0.19 → 0.0.21

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/lib/index.d.ts CHANGED
@@ -367,7 +367,7 @@ interface ModelContext$1 {
367
367
  name: string;
368
368
  description?: string;
369
369
  toolPrefix?: string;
370
- resourceUri?: string;
370
+ /** Unique URI identifier for this model context */
371
371
  uri?: string;
372
372
  tools?: ToolDefinition$1[] | Record<string, ToolDefinition$1>;
373
373
  prompts?: ModelContextPrompt$1[];
@@ -1364,7 +1364,7 @@ interface ModelContext {
1364
1364
  name: string;
1365
1365
  description?: string;
1366
1366
  toolPrefix?: string;
1367
- resourceUri?: string;
1367
+ /** Unique URI identifier for this model context */
1368
1368
  uri?: string;
1369
1369
  tools?: ToolDefinition[] | Record<string, ToolDefinition>;
1370
1370
  prompts?: ModelContextPrompt[];
@@ -1402,6 +1402,84 @@ interface FlowRequestStep {
1402
1402
  stepToolPhase?: Core_ToolExecutionPhase;
1403
1403
  }
1404
1404
 
1405
+ /**
1406
+ * McpAppHostContext
1407
+ *
1408
+ * Context for managing MCP App hosts in headless chat.
1409
+ * Handles registration, event routing, and bidirectional communication.
1410
+ */
1411
+
1412
+ /**
1413
+ * Data structure for MCP App content and state
1414
+ */
1415
+ interface McpAppData {
1416
+ mcpAppId: string;
1417
+ mcpAppType?: 'mcp-app' | 'dojo-canvas' | 'iframe';
1418
+ url?: string;
1419
+ html?: string;
1420
+ state?: Record<string, any>;
1421
+ height?: string;
1422
+ width?: string;
1423
+ toolInfo?: {
1424
+ id?: string | number;
1425
+ tool: {
1426
+ name: string;
1427
+ description?: string;
1428
+ inputSchema?: Record<string, unknown>;
1429
+ };
1430
+ };
1431
+ arguments?: Record<string, unknown>;
1432
+ result?: unknown;
1433
+ isComplete?: boolean;
1434
+ }
1435
+ /**
1436
+ * Context value for MCP App host management
1437
+ */
1438
+ interface McpAppHostContextValue {
1439
+ registerApp: (mcpAppId: string, iframeWindow: Window) => void;
1440
+ unregisterApp: (mcpAppId: string) => void;
1441
+ registeredApps: Set<string>;
1442
+ findAppIdBySource: (source: Window | MessageEventSource | null) => string | null;
1443
+ sendToApp: (mcpAppId: string, method: string, params?: any) => Promise<any>;
1444
+ broadcastToApps: (method: string, params?: any) => void;
1445
+ onOpenLink?: (url: string, target: string, mcpAppId: string) => void;
1446
+ onToolCall?: (tool: string, params: any, mcpAppId: string) => Promise<any>;
1447
+ onUiMessage?: (message: string, params: any, mcpAppId: string) => void;
1448
+ onPersistState?: (state: Record<string, any>, mcpAppId: string) => void;
1449
+ }
1450
+ declare const McpAppHostContext: React$1.Context<McpAppHostContextValue>;
1451
+ /**
1452
+ * Props for McpAppHostProvider
1453
+ */
1454
+ interface McpAppHostProviderProps {
1455
+ children: React$1.ReactNode;
1456
+ /**
1457
+ * Called when an MCP App requests to open a link (ui/open-link)
1458
+ */
1459
+ onOpenLink?: (url: string, target: string, mcpAppId: string) => void;
1460
+ /**
1461
+ * Called when an MCP App requests a tool execution (tools/call)
1462
+ * Return value is sent back to the app as the response
1463
+ */
1464
+ onToolCall?: (tool: string, params: any, mcpAppId: string) => Promise<any>;
1465
+ /**
1466
+ * Called when an MCP App sends a UI message (ui/message)
1467
+ */
1468
+ onUiMessage?: (message: string, params: any, mcpAppId: string) => void;
1469
+ /**
1470
+ * Called when an MCP App wants to persist state (ui/message with botdojo/messageType: 'persist-state')
1471
+ */
1472
+ onPersistState?: (state: Record<string, any>, mcpAppId: string) => void;
1473
+ /**
1474
+ * Enable debug logging
1475
+ */
1476
+ debug?: boolean;
1477
+ }
1478
+ /**
1479
+ * Provider component for MCP App host management
1480
+ */
1481
+ declare function McpAppHostProvider(props: McpAppHostProviderProps): JSX.Element;
1482
+
1405
1483
  /**
1406
1484
  * Headless Chat Types
1407
1485
  *
@@ -1579,6 +1657,42 @@ interface BotDojoChatProviderProps {
1579
1657
  */
1580
1658
  onUiMessage?: (message: string, params: any, appId: string) => void;
1581
1659
  }
1660
+ /**
1661
+ * Parse a value that may be a JSON string into an object.
1662
+ * Returns the original value if it's already an object or can't be parsed.
1663
+ * Returns undefined for empty/null/undefined values.
1664
+ *
1665
+ * @param value - Value to parse (can be string, object, or any)
1666
+ * @returns Parsed object, original value, or undefined
1667
+ */
1668
+ declare function parseMaybeJson(value: any): Record<string, unknown> | any;
1669
+ /**
1670
+ * Extract MCP App data from a step for hydration.
1671
+ *
1672
+ * This handles multiple data sources and formats that occur during:
1673
+ * - Live streaming (stepToolArguments, stepToolResult populated)
1674
+ * - Hydration from server (arguments as JSON string, result in canvasData)
1675
+ * - Persisted state (state in canvasData)
1676
+ *
1677
+ * @param step - The step from ChatMessage.steps (FlowRequestStep or raw server step)
1678
+ * @param options - Additional options
1679
+ * @returns McpAppData object ready for McpAppHost, or null if step has no canvas
1680
+ *
1681
+ * @example
1682
+ * ```tsx
1683
+ * const mcpApps = message.steps
1684
+ * .map(step => extractMcpAppData(step, { isComplete: message.status === 'complete' }))
1685
+ * .filter(Boolean);
1686
+ *
1687
+ * {mcpApps.map(app => (
1688
+ * <McpAppHost key={app.mcpAppId} mcpAppId={app.mcpAppId} mcpAppData={app} />
1689
+ * ))}
1690
+ * ```
1691
+ */
1692
+ declare function extractMcpAppData(step: FlowRequestStep | any, options?: {
1693
+ /** Whether the parent message is complete */
1694
+ isComplete?: boolean;
1695
+ }): McpAppData | null;
1582
1696
 
1583
1697
  /**
1584
1698
  * BotDojo Chat Provider
@@ -1648,84 +1762,6 @@ interface BotDojoCanvasFrameProps {
1648
1762
  */
1649
1763
  declare function BotDojoCanvasFrame(props: BotDojoCanvasFrameProps): JSX.Element;
1650
1764
 
1651
- /**
1652
- * McpAppHostContext
1653
- *
1654
- * Context for managing MCP App hosts in headless chat.
1655
- * Handles registration, event routing, and bidirectional communication.
1656
- */
1657
-
1658
- /**
1659
- * Data structure for MCP App content and state
1660
- */
1661
- interface McpAppData {
1662
- mcpAppId: string;
1663
- mcpAppType?: 'mcp-app' | 'dojo-canvas' | 'iframe';
1664
- url?: string;
1665
- html?: string;
1666
- state?: Record<string, any>;
1667
- height?: string;
1668
- width?: string;
1669
- toolInfo?: {
1670
- id?: string | number;
1671
- tool: {
1672
- name: string;
1673
- description?: string;
1674
- inputSchema?: Record<string, unknown>;
1675
- };
1676
- };
1677
- arguments?: Record<string, unknown>;
1678
- result?: unknown;
1679
- isComplete?: boolean;
1680
- }
1681
- /**
1682
- * Context value for MCP App host management
1683
- */
1684
- interface McpAppHostContextValue {
1685
- registerApp: (mcpAppId: string, iframeWindow: Window) => void;
1686
- unregisterApp: (mcpAppId: string) => void;
1687
- registeredApps: Set<string>;
1688
- findAppIdBySource: (source: Window | MessageEventSource | null) => string | null;
1689
- sendToApp: (mcpAppId: string, method: string, params?: any) => Promise<any>;
1690
- broadcastToApps: (method: string, params?: any) => void;
1691
- onOpenLink?: (url: string, target: string, mcpAppId: string) => void;
1692
- onToolCall?: (tool: string, params: any, mcpAppId: string) => Promise<any>;
1693
- onUiMessage?: (message: string, params: any, mcpAppId: string) => void;
1694
- onPersistState?: (state: Record<string, any>, mcpAppId: string) => void;
1695
- }
1696
- declare const McpAppHostContext: React$1.Context<McpAppHostContextValue>;
1697
- /**
1698
- * Props for McpAppHostProvider
1699
- */
1700
- interface McpAppHostProviderProps {
1701
- children: React$1.ReactNode;
1702
- /**
1703
- * Called when an MCP App requests to open a link (ui/open-link)
1704
- */
1705
- onOpenLink?: (url: string, target: string, mcpAppId: string) => void;
1706
- /**
1707
- * Called when an MCP App requests a tool execution (tools/call)
1708
- * Return value is sent back to the app as the response
1709
- */
1710
- onToolCall?: (tool: string, params: any, mcpAppId: string) => Promise<any>;
1711
- /**
1712
- * Called when an MCP App sends a UI message (ui/message)
1713
- */
1714
- onUiMessage?: (message: string, params: any, mcpAppId: string) => void;
1715
- /**
1716
- * Called when an MCP App wants to persist state (ui/message with botdojo/messageType: 'persist-state')
1717
- */
1718
- onPersistState?: (state: Record<string, any>, mcpAppId: string) => void;
1719
- /**
1720
- * Enable debug logging
1721
- */
1722
- debug?: boolean;
1723
- }
1724
- /**
1725
- * Provider component for MCP App host management
1726
- */
1727
- declare function McpAppHostProvider(props: McpAppHostProviderProps): JSX.Element;
1728
-
1729
1765
  /**
1730
1766
  * McpAppHost Component
1731
1767
  *
@@ -1735,16 +1771,17 @@ declare function McpAppHostProvider(props: McpAppHostProviderProps): JSX.Element
1735
1771
 
1736
1772
  /**
1737
1773
  * Props for McpAppHost component
1774
+ *
1775
+ * The component gets all MCP App data (HTML, arguments, result, etc.) automatically
1776
+ * from BotDojoChatProvider via context. Parents only need to pass the mcpAppId.
1738
1777
  */
1739
1778
  interface McpAppHostProps {
1740
1779
  /**
1741
- * Unique identifier for this MCP App instance
1780
+ * Unique identifier for this MCP App instance.
1781
+ * McpAppHost will get HTML, arguments, result, and other data from
1782
+ * BotDojoChatProvider's cache using this ID.
1742
1783
  */
1743
1784
  mcpAppId: string;
1744
- /**
1745
- * MCP App data containing URL, HTML, state, and tool context
1746
- */
1747
- mcpAppData: McpAppData;
1748
1785
  /**
1749
1786
  * Called when app requests to open a link (ui/open-link)
1750
1787
  * Links are NOT automatically opened - host must handle this
@@ -1760,8 +1797,7 @@ interface McpAppHostProps {
1760
1797
  */
1761
1798
  onUiMessage?: (message: string, params: any, mcpAppId: string) => void;
1762
1799
  /**
1763
- * Called when app wants to persist state (ui/message with botdojo/messageType: 'persist-state')
1764
- * The state should be saved and provided back in mcpAppData.state on next render
1800
+ * Called when app wants to persist state
1765
1801
  */
1766
1802
  onPersistState?: (state: Record<string, any>, mcpAppId: string) => void;
1767
1803
  /**
@@ -1779,7 +1815,7 @@ interface McpAppHostProps {
1779
1815
  width?: string | number;
1780
1816
  /**
1781
1817
  * Height of the iframe
1782
- * @default '400px'
1818
+ * @default '100%'
1783
1819
  */
1784
1820
  height?: string | number;
1785
1821
  /**
@@ -1798,22 +1834,19 @@ interface McpAppHostProps {
1798
1834
  /**
1799
1835
  * McpAppHost - Hosts an MCP App iframe with full event handling
1800
1836
  *
1837
+ * All MCP App data (HTML, arguments, result, etc.) is automatically provided
1838
+ * by BotDojoChatProvider via context. Parents only need to pass the mcpAppId.
1839
+ *
1801
1840
  * @example
1802
1841
  * ```tsx
1842
+ * // Simple usage - just pass the mcpAppId
1843
+ * <McpAppHost mcpAppId={step.canvas.canvasId} />
1844
+ *
1845
+ * // With event handlers
1803
1846
  * <McpAppHost
1804
- * mcpAppId={step.mcpApp.mcpAppId}
1805
- * mcpAppData={step.mcpApp}
1806
- * onToolCall={async (tool, params, appId) => {
1807
- * // Handle tool call, return result
1808
- * return { success: true };
1809
- * }}
1810
- * onOpenLink={(url, target, appId) => {
1811
- * // Handle link - NOT auto-opened
1812
- * window.open(url, target);
1813
- * }}
1814
- * onUiMessage={(message, params, appId) => {
1815
- * console.log('App says:', message);
1816
- * }}
1847
+ * mcpAppId={step.canvas.canvasId}
1848
+ * onOpenLink={(url, target, appId) => window.open(url, target)}
1849
+ * onReady={(appId) => console.log('App ready:', appId)}
1817
1850
  * />
1818
1851
  * ```
1819
1852
  */
@@ -2112,4 +2145,4 @@ declare function useBotDojoCanvas(): UseBotDojoCanvasReturn;
2112
2145
  /** @deprecated Use AppAction instead */
2113
2146
  type CanvasAction = AppAction;
2114
2147
 
2115
- export { type AppAction, type AppContextValue, type AppEvent, BotDojoCanvasFrame, type BotDojoCanvasFrameProps, BotDojoCanvasProvider, type BotDojoCanvasProviderProps, BotDojoChat, type BotDojoChatConfig, BotDojoChatConfigurator, type BotDojoChatConfiguratorProps, type BotDojoChatControl, type BotDojoChatDisplayMode, type BotDojoChatHook, type BotDojoChatProps, BotDojoChatProvider, type BotDojoChatProviderProps, type CanvasAction, type CanvasActionOptions, type CanvasEvent, type CanvasMode, type ChatActionsHook, type ChatConfig, type ChatMessage, type ChatMessagesHook, type ChatStatus, type ChatStatusHook, type CitationData, type ContentItem, type HeadlessAction, HeadlessChat, type HeadlessChatHandle, type HeadlessChatProps, type HeadlessChatState, type HeadlessEvent, type HeadlessMessageEvent, type HeadlessStatusEvent, type HeadlessStepEvent, type HeadlessTokenEvent, MIME_TYPES, type McpAppData, McpAppHost, McpAppHostContext, type McpAppHostContextValue, type McpAppHostProps, McpAppHostProvider, type McpAppHostProviderProps, MockCanvasProvider, type MockCanvasProviderProps, type ModelContext, type ModelContextMessage, type ModelContextPrompt, type ModelContextResource, type PopupOptions, type ResourceContent, type ResourceProvider, type ResourceReference, type ResourceTemplate, type SidePanelOptions, type ToolDefinition, type ToolExecutionContext, type ToolExecutionResult, type ToolMetadata, type UiSize, type UseBotDojoCanvasReturn, useBotDojoCanvas, useBotDojoChat, useChatActions, useChatMessages, useChatStatus, useMcpAppHost, useMcpAppHostRequired };
2148
+ export { type AppAction, type AppContextValue, type AppEvent, BotDojoCanvasFrame, type BotDojoCanvasFrameProps, BotDojoCanvasProvider, type BotDojoCanvasProviderProps, BotDojoChat, type BotDojoChatConfig, BotDojoChatConfigurator, type BotDojoChatConfiguratorProps, type BotDojoChatControl, type BotDojoChatDisplayMode, type BotDojoChatHook, type BotDojoChatProps, BotDojoChatProvider, type BotDojoChatProviderProps, type CanvasAction, type CanvasActionOptions, type CanvasEvent, type CanvasMode, type ChatActionsHook, type ChatConfig, type ChatMessage, type ChatMessagesHook, type ChatStatus, type ChatStatusHook, type CitationData, type ContentItem, type HeadlessAction, HeadlessChat, type HeadlessChatHandle, type HeadlessChatProps, type HeadlessChatState, type HeadlessEvent, type HeadlessMessageEvent, type HeadlessStatusEvent, type HeadlessStepEvent, type HeadlessTokenEvent, MIME_TYPES, type McpAppData, McpAppHost, McpAppHostContext, type McpAppHostContextValue, type McpAppHostProps, McpAppHostProvider, type McpAppHostProviderProps, MockCanvasProvider, type MockCanvasProviderProps, type ModelContext, type ModelContextMessage, type ModelContextPrompt, type ModelContextResource, type PopupOptions, type ResourceContent, type ResourceProvider, type ResourceReference, type ResourceTemplate, type SidePanelOptions, type ToolDefinition, type ToolExecutionContext, type ToolExecutionResult, type ToolMetadata, type UiSize, type UseBotDojoCanvasReturn, extractMcpAppData, parseMaybeJson, useBotDojoCanvas, useBotDojoChat, useChatActions, useChatMessages, useChatStatus, useMcpAppHost, useMcpAppHostRequired };