@botdojo/chat-sdk 0.0.5 → 0.0.7

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 CHANGED
@@ -109,7 +109,7 @@ Slides in from the side, pushes content. **Best for:** Integrated layouts.
109
109
  ### Inline
110
110
 
111
111
  ```tsx
112
- <BotDojoChat apiKey="YOUR_API_KEY" mode="inline" width="100%" height="600px" />
112
+ <BotDojoChat apiKey="YOUR_API_KEY" mode="inline" width="100%" height="100%" />
113
113
  ```
114
114
 
115
115
  Direct embed in the page. **Best for:** Dedicated chat pages, full-screen experiences.
package/lib/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import React$1 from 'react';
2
2
  import { ModelContext, BotDojoConnector as BotDojoConnector$1 } from '@botdojo/sdk-canvas';
3
3
  export { BotDojoConnector } from '@botdojo/sdk-canvas';
4
- import { ModelContext as ModelContext$1, FlowRequestStep, TokenUpdate } from '@botdojo/sdk-types';
5
- export { FlowCanvas, FlowRequestStep, ModelContext, ModelContextMessage, ModelContextPrompt, ModelContextResource, ResourceContent, ResourceProvider, ResourceTemplate, TokenUpdate, ToolDefinition, ToolExecutionContext, ToolResponse, ToolResponseAction, actions, toolResponse } from '@botdojo/sdk-types';
4
+ import { ModelContext as ModelContext$1, FlowRequestStep, Core_TokenUpdate } from '@botdojo/sdk-types';
5
+ export { CitationData, ContentItem, MIME_TYPES, ModelContext, ModelContextMessage, ModelContextPrompt, ModelContextResource, ResourceContent, ResourceProvider, ResourceReference, ResourceTemplate, ToolDefinition, ToolExecutionContext, ToolExecutionResult, ToolMetadata, citation, citations, imageResult, mcpResource, modelContext, textResult, tool, uiResource } from '@botdojo/sdk-types';
6
6
  import { ChatMessage as ChatMessage$1 } from 'botdojo-core/lib/src/store/session';
7
7
  import { FlowCanvasType } from 'botdojo-core/lib/src/store/flowRequest';
8
8
  import * as react_jsx_runtime from 'react/jsx-runtime';
@@ -135,7 +135,7 @@ interface BotDojoChatProps {
135
135
  width?: string;
136
136
  /**
137
137
  * Height of the chat container
138
- * @default '600px'
138
+ * @default '100%'
139
139
  */
140
140
  height?: string;
141
141
  /**
@@ -195,6 +195,16 @@ interface BotDojoChatProps {
195
195
  * Specific session ID to use
196
196
  */
197
197
  sessionId?: string;
198
+ /**
199
+ * Prefix for the localStorage session key used to persist the session ID
200
+ * - Defaults to "botdojo-chat-session-id"
201
+ * - Set to avoid collisions when embedding multiple agents
202
+ */
203
+ sessionKeyPrefix?: string;
204
+ /**
205
+ * Override the welcome message shown in the chat widget (supports markdown)
206
+ */
207
+ welcomeMessage?: string;
198
208
  /**
199
209
  * Allow microphone access in iframe
200
210
  * @default false
@@ -238,6 +248,65 @@ interface BotDojoChatProps {
238
248
  * - sendFlowRequest(body): Sends a flow request programmatically
239
249
  */
240
250
  onBotDojoChatControl?: (control: BotDojoChatControl) => void;
251
+ /**
252
+ * Called when chat iframe is ready
253
+ */
254
+ onReady?: () => void;
255
+ /**
256
+ * Called when an error occurs
257
+ */
258
+ onError?: (error: Error, messageId?: string, stepId?: string) => void;
259
+ /**
260
+ * Called when a message starts
261
+ */
262
+ onMessageStart?: (role: 'user' | 'assistant' | 'system', messageId: string) => void;
263
+ /**
264
+ * Called when a message completes
265
+ */
266
+ onMessageComplete?: (messageId: string, content: string) => void;
267
+ /**
268
+ * Called when a step update occurs
269
+ */
270
+ onStepUpdate?: (messageId: string, step: any) => void;
271
+ /**
272
+ * Called when a token is streamed
273
+ */
274
+ onToken?: (messageId: string, tokenUpdate: any) => void;
275
+ /**
276
+ * Called when a session is created
277
+ */
278
+ onSessionCreated?: (sessionId: string) => void;
279
+ /**
280
+ * Called when a session is hydrated with history
281
+ */
282
+ onSessionHydrated?: (sessionId: string, messageCount: number) => void;
283
+ /**
284
+ * Called when a request is aborted
285
+ */
286
+ onRequestAborted?: () => void;
287
+ /**
288
+ * Called when an MCP App requests to open a link (ui/open-link)
289
+ * The host application should handle navigation - links are NOT automatically opened
290
+ * @param url - The URL to open
291
+ * @param target - Target window ('_blank', '_self', etc.)
292
+ * @param appId - The MCP App ID that sent the event
293
+ */
294
+ onOpenLink?: (url: string, target: string, appId: string) => void;
295
+ /**
296
+ * Called when an MCP App requests a tool execution (tools/call)
297
+ * @param tool - The tool name to execute
298
+ * @param params - Tool parameters
299
+ * @param appId - The MCP App ID that sent the event
300
+ * @returns Tool execution result (async)
301
+ */
302
+ onToolCall?: (tool: string, params: any, appId: string) => Promise<any> | void;
303
+ /**
304
+ * Called when an MCP App sends a UI message (ui/message)
305
+ * @param message - The message content or payload
306
+ * @param params - Additional message parameters
307
+ * @param appId - The MCP App ID that sent the event
308
+ */
309
+ onUiMessage?: (message: string, params: any, appId: string) => void;
241
310
  }
242
311
  /**
243
312
  * BotDojoChat - Single unified React component for embedding BotDojo chat
@@ -365,13 +434,39 @@ interface HeadlessChatProps {
365
434
  */
366
435
  onStep?: (step: any, messageId?: string) => void;
367
436
  /**
368
- * Callback when canvas is attached to a step
437
+ * Callback when an MCP App UI is attached to a step
438
+ * @param mcpAppData - The MCP App data to render
439
+ * @param stepId - The step ID
440
+ * @param messageId - The message ID
369
441
  */
370
- onCanvas?: (canvasData: any, stepId: string, messageId?: string) => void;
442
+ onMcpApp?: (mcpAppData: any, stepId: string, messageId?: string) => void;
371
443
  /**
372
444
  * Callback when a new message starts
373
445
  */
374
446
  onMessageStart?: (role: 'user' | 'assistant' | 'system', messageId: string) => void;
447
+ /**
448
+ * Called when an MCP App requests to open a link (ui/open-link)
449
+ * The host application should handle navigation - links are NOT automatically opened
450
+ * @param url - The URL to open
451
+ * @param target - Target window ('_blank', '_self', etc.)
452
+ * @param appId - The MCP App ID that sent the event
453
+ */
454
+ onOpenLink?: (url: string, target: string, appId: string) => void;
455
+ /**
456
+ * Called when an MCP App requests a tool execution (tools/call)
457
+ * @param tool - The tool name to execute
458
+ * @param params - Tool parameters
459
+ * @param appId - The MCP App ID that sent the event
460
+ * @returns Tool execution result (async)
461
+ */
462
+ onToolCall?: (tool: string, params: any, appId: string) => Promise<any> | void;
463
+ /**
464
+ * Called when an MCP App sends a UI message (ui/message)
465
+ * @param message - The message content or payload
466
+ * @param params - Additional message parameters
467
+ * @param appId - The MCP App ID that sent the event
468
+ */
469
+ onUiMessage?: (message: string, params: any, appId: string) => void;
375
470
  /**
376
471
  * Callback when a message is complete
377
472
  */
@@ -511,7 +606,7 @@ type HeadlessEvent = {
511
606
  } | {
512
607
  type: 'token';
513
608
  messageId: string;
514
- tokenUpdate: TokenUpdate;
609
+ tokenUpdate: Core_TokenUpdate;
515
610
  } | {
516
611
  type: 'session_hydrated';
517
612
  sessionId: string;
@@ -542,7 +637,7 @@ type HeadlessAction = {
542
637
  } | {
543
638
  type: 'TOKEN';
544
639
  messageId: string;
545
- tokenUpdate: TokenUpdate;
640
+ tokenUpdate: Core_TokenUpdate;
546
641
  } | {
547
642
  type: 'SESSION_HYDRATED';
548
643
  sessionId: string;
@@ -584,6 +679,8 @@ interface ChatActionsHook {
584
679
  bargeInRequest: (text: string) => void;
585
680
  setSessionId: (sessionId: string) => void;
586
681
  reload: () => void;
682
+ /** Persist canvas/MCP App state to the server */
683
+ persistCanvasState: (canvasId: string, state: Record<string, any>) => void;
587
684
  }
588
685
  interface BotDojoChatProviderProps {
589
686
  apiKey: string;
@@ -642,13 +739,18 @@ interface BotDojoChatProviderProps {
642
739
  * Main provider component for Headless Chat with full RPC/Connector support.
643
740
  *
644
741
  * This component:
645
- * 1. Creates a hidden iframe with /embed/headless
646
- * 2. Initializes BotDojoConnector for model context and tool calls
647
- * 3. Sets up RPCConnection for parent-embed communication
648
- * 4. Manages canvas iframe bridges for tool call routing
649
- * 5. Listens to postMessage events from iframe
650
- * 6. Updates React state via reducer
651
- * 7. Exposes state, connector, and actions via context
742
+ * 1. Creates a hidden iframe with /embed/headless for all communication
743
+ * 2. Manages canvas iframe bridges for MCP App rendering
744
+ * 3. Listens to postMessage events from iframe
745
+ * 4. Updates React state via reducer
746
+ * 5. Exposes state and actions via context
747
+ *
748
+ * Architecture:
749
+ * - /embed/headless handles:
750
+ * - Flow Request Channel: HTTP streaming for tokens, steps, flow completion
751
+ * - External UI Channel: Socket.IO for model context registration and tool calls
752
+ * - HeadlessEmbed connects to Socket.IO and proxies tool calls to parent
753
+ * - Parent executes tools locally and sends results back
652
754
  */
653
755
 
654
756
  declare function BotDojoChatProvider(props: BotDojoChatProviderProps): JSX.Element;
@@ -685,20 +787,6 @@ declare function useChatStatus(): ChatStatusHook;
685
787
 
686
788
  declare function useChatActions(): ChatActionsHook;
687
789
 
688
- /**
689
- * BotDojoCanvasFrame Component
690
- *
691
- * Creates and manages a canvas iframe in the parent window. This component:
692
- * 1. Creates an iframe for the canvas page
693
- * 2. Registers with BotDojoChatProvider for canvas bridge management
694
- * 3. Handles canvas tool calls and event forwarding via provider
695
- *
696
- * Note: This is for the PARENT page to render canvas iframes.
697
- * For canvas pages running inside iframes, use BotDojoCanvas from @botdojo/sdk-canvas.
698
- *
699
- * Canvas updates flow: BotDojo API → /embed/headless → parent provider → BotDojoCanvasFrame → canvas iframe
700
- */
701
-
702
790
  interface BotDojoCanvasFrameProps {
703
791
  canvasId: string;
704
792
  canvasData: any;
@@ -707,8 +795,202 @@ interface BotDojoCanvasFrameProps {
707
795
  height?: string | number;
708
796
  style?: React$1.CSSProperties;
709
797
  }
798
+ /**
799
+ * Minimal headless canvas iframe renderer.
800
+ * Renders mcp-app (or legacy iframe/dojo) canvases by loading the URL or inline HTML.
801
+ */
710
802
  declare function BotDojoCanvasFrame(props: BotDojoCanvasFrameProps): JSX.Element;
711
803
 
804
+ /**
805
+ * McpAppHostContext
806
+ *
807
+ * Context for managing MCP App hosts in headless chat.
808
+ * Handles registration, event routing, and bidirectional communication.
809
+ */
810
+
811
+ /**
812
+ * Data structure for MCP App content and state
813
+ */
814
+ interface McpAppData {
815
+ mcpAppId: string;
816
+ mcpAppType?: 'mcp-app' | 'dojo-canvas' | 'iframe';
817
+ url?: string;
818
+ html?: string;
819
+ state?: Record<string, any>;
820
+ height?: string;
821
+ width?: string;
822
+ toolInfo?: {
823
+ id?: string | number;
824
+ tool: {
825
+ name: string;
826
+ description?: string;
827
+ inputSchema?: Record<string, unknown>;
828
+ };
829
+ };
830
+ arguments?: Record<string, unknown>;
831
+ result?: unknown;
832
+ isComplete?: boolean;
833
+ }
834
+ /**
835
+ * Context value for MCP App host management
836
+ */
837
+ interface McpAppHostContextValue {
838
+ registerApp: (mcpAppId: string, iframeWindow: Window) => void;
839
+ unregisterApp: (mcpAppId: string) => void;
840
+ registeredApps: Set<string>;
841
+ findAppIdBySource: (source: Window | MessageEventSource | null) => string | null;
842
+ sendToApp: (mcpAppId: string, method: string, params?: any) => Promise<any>;
843
+ broadcastToApps: (method: string, params?: any) => void;
844
+ onOpenLink?: (url: string, target: string, mcpAppId: string) => void;
845
+ onToolCall?: (tool: string, params: any, mcpAppId: string) => Promise<any>;
846
+ onUiMessage?: (message: string, params: any, mcpAppId: string) => void;
847
+ onPersistState?: (state: Record<string, any>, mcpAppId: string) => void;
848
+ }
849
+ declare const McpAppHostContext: React$1.Context<McpAppHostContextValue>;
850
+ /**
851
+ * Props for McpAppHostProvider
852
+ */
853
+ interface McpAppHostProviderProps {
854
+ children: React$1.ReactNode;
855
+ /**
856
+ * Called when an MCP App requests to open a link (ui/open-link)
857
+ */
858
+ onOpenLink?: (url: string, target: string, mcpAppId: string) => void;
859
+ /**
860
+ * Called when an MCP App requests a tool execution (tools/call)
861
+ * Return value is sent back to the app as the response
862
+ */
863
+ onToolCall?: (tool: string, params: any, mcpAppId: string) => Promise<any>;
864
+ /**
865
+ * Called when an MCP App sends a UI message (ui/message)
866
+ */
867
+ onUiMessage?: (message: string, params: any, mcpAppId: string) => void;
868
+ /**
869
+ * Called when an MCP App wants to persist state (ui/message with botdojo/messageType: 'persist-state')
870
+ */
871
+ onPersistState?: (state: Record<string, any>, mcpAppId: string) => void;
872
+ /**
873
+ * Enable debug logging
874
+ */
875
+ debug?: boolean;
876
+ }
877
+ /**
878
+ * Provider component for MCP App host management
879
+ */
880
+ declare function McpAppHostProvider(props: McpAppHostProviderProps): JSX.Element;
881
+
882
+ /**
883
+ * McpAppHost Component
884
+ *
885
+ * Hosts an MCP App in an iframe with full JSON-RPC communication.
886
+ * Handles ui/initialize, ui/message, tools/call, ui/open-link and other MCP-UI events.
887
+ */
888
+
889
+ /**
890
+ * Props for McpAppHost component
891
+ */
892
+ interface McpAppHostProps {
893
+ /**
894
+ * Unique identifier for this MCP App instance
895
+ */
896
+ mcpAppId: string;
897
+ /**
898
+ * MCP App data containing URL, HTML, state, and tool context
899
+ */
900
+ mcpAppData: McpAppData;
901
+ /**
902
+ * Called when app requests to open a link (ui/open-link)
903
+ * Links are NOT automatically opened - host must handle this
904
+ */
905
+ onOpenLink?: (url: string, target: string, mcpAppId: string) => void;
906
+ /**
907
+ * Called when app requests a tool execution (tools/call)
908
+ * Return value is sent back to the app as JSON-RPC response
909
+ */
910
+ onToolCall?: (tool: string, params: any, mcpAppId: string) => Promise<any>;
911
+ /**
912
+ * Called when app sends a UI message (ui/message)
913
+ */
914
+ onUiMessage?: (message: string, params: any, mcpAppId: string) => void;
915
+ /**
916
+ * Called when app wants to persist state (ui/message with botdojo/messageType: 'persist-state')
917
+ * The state should be saved and provided back in mcpAppData.state on next render
918
+ */
919
+ onPersistState?: (state: Record<string, any>, mcpAppId: string) => void;
920
+ /**
921
+ * Called when app reports a size change (ui/notifications/size-change)
922
+ */
923
+ onSizeChange?: (width: number, height: number, mcpAppId: string) => void;
924
+ /**
925
+ * Called when app is initialized and ready
926
+ */
927
+ onReady?: (mcpAppId: string) => void;
928
+ /**
929
+ * Width of the iframe
930
+ * @default '100%'
931
+ */
932
+ width?: string | number;
933
+ /**
934
+ * Height of the iframe
935
+ * @default '400px'
936
+ */
937
+ height?: string | number;
938
+ /**
939
+ * Additional styles for the iframe
940
+ */
941
+ style?: React$1.CSSProperties;
942
+ /**
943
+ * Additional host context to send to the app on initialization
944
+ */
945
+ initialHostContext?: Record<string, any>;
946
+ /**
947
+ * Enable debug logging
948
+ */
949
+ debug?: boolean;
950
+ }
951
+ /**
952
+ * McpAppHost - Hosts an MCP App iframe with full event handling
953
+ *
954
+ * @example
955
+ * ```tsx
956
+ * <McpAppHost
957
+ * mcpAppId={step.mcpApp.mcpAppId}
958
+ * mcpAppData={step.mcpApp}
959
+ * onToolCall={async (tool, params, appId) => {
960
+ * // Handle tool call, return result
961
+ * return { success: true };
962
+ * }}
963
+ * onOpenLink={(url, target, appId) => {
964
+ * // Handle link - NOT auto-opened
965
+ * window.open(url, target);
966
+ * }}
967
+ * onUiMessage={(message, params, appId) => {
968
+ * console.log('App says:', message);
969
+ * }}
970
+ * />
971
+ * ```
972
+ */
973
+ declare function McpAppHost(props: McpAppHostProps): JSX.Element;
974
+
975
+ /**
976
+ * useMcpAppHost Hook
977
+ *
978
+ * Hook to access the MCP App host context for registration and event handling.
979
+ * Returns null if not within a McpAppHostProvider (allows standalone McpAppHost usage).
980
+ */
981
+
982
+ /**
983
+ * Access the MCP App host context.
984
+ * Returns null if not within a McpAppHostProvider, allowing McpAppHost
985
+ * to work both with and without the provider.
986
+ */
987
+ declare function useMcpAppHost(): McpAppHostContextValue | null;
988
+ /**
989
+ * Access the MCP App host context, throwing if not available.
990
+ * Use this when you require the context to be present.
991
+ */
992
+ declare function useMcpAppHostRequired(): McpAppHostContextValue;
993
+
712
994
  interface BotDojoChatConfig {
713
995
  apiKey: string;
714
996
  mode: BotDojoChatDisplayMode;
@@ -742,15 +1024,36 @@ declare const BotDojoChatConfigurator: React$1.FC<BotDojoChatConfiguratorProps>;
742
1024
  * Canvas types for inline canvas cards in chat widgets
743
1025
  */
744
1026
 
1027
+ type CanvasMode = 'dojo' | 'mcp-app';
1028
+ interface MessageAckEntry {
1029
+ status: 'pending' | 'received' | 'responded' | 'error';
1030
+ payload?: any;
1031
+ error?: string;
1032
+ ts: number;
1033
+ }
1034
+ interface UiSize {
1035
+ width: number;
1036
+ height: number;
1037
+ }
1038
+ interface CanvasActionOptions {
1039
+ /** Optional messageId to correlate request/response */
1040
+ messageId?: string;
1041
+ /** Whether to wait for a correlated response */
1042
+ awaitResponse?: boolean;
1043
+ /** Override legacy RPC mirroring */
1044
+ mirrorLegacyCanvasRpc?: boolean;
1045
+ /** Optional timeout for awaiting responses */
1046
+ responseTimeoutMs?: number;
1047
+ }
745
1048
  interface BotDojoConnector {
746
1049
  executeToolCall: (toolName: string, args: any) => Promise<any>;
747
1050
  run: (params: any) => Promise<any>;
748
1051
  init: () => Promise<void>;
749
1052
  close: () => void;
750
- updateCanvasData: (canvasData: any) => Promise<any>;
1053
+ updateState: (state: any) => Promise<any>;
751
1054
  [key: string]: any;
752
1055
  }
753
- type CanvasEvent = 'canvas:ready' | 'canvas:update' | 'message' | 'token' | 'complete' | 'error' | 'tool:args_streaming' | 'tool:executing' | 'tool:complete' | 'tool:error';
1056
+ type CanvasEvent = 'canvas:ready' | 'canvas:update' | 'message' | 'token' | 'complete' | 'error' | 'tool:args_streaming' | 'tool:executing' | 'tool:complete' | 'tool:error' | 'mcp-app:render-data' | 'mcp-app:message-received' | 'mcp-app:message-response' | 'mcp-app:botdojo-tool-update' | 'mcp-app:tool-input' | 'mcp-app:tool-cancelled' | 'mcp-app:tool-result' | 'mcp-app:host-context-changed' | 'mcp-app:initial-data';
754
1057
  interface UseBotDojoCanvasReturn {
755
1058
  /** Whether the canvas is ready */
756
1059
  isReady: boolean;
@@ -758,6 +1061,22 @@ interface UseBotDojoCanvasReturn {
758
1061
  error: Error | null;
759
1062
  /** Canvas data for this card */
760
1063
  canvasData: any | null;
1064
+ /** Render data pushed via host lifecycle */
1065
+ renderData?: any;
1066
+ /** Last correlated ack/response */
1067
+ lastAck?: {
1068
+ messageId: string;
1069
+ status: MessageAckEntry['status'];
1070
+ payload?: any;
1071
+ error?: string;
1072
+ ts: number;
1073
+ };
1074
+ /** Map of messageId -> ack/response state */
1075
+ messageIdMap?: Record<string, MessageAckEntry>;
1076
+ /** Last measured UI size */
1077
+ uiSize?: UiSize | null;
1078
+ /** Active mode */
1079
+ mode: CanvasMode;
761
1080
  /** Tool execution info (for tool canvas templates) */
762
1081
  toolName?: string;
763
1082
  toolDisplayName?: string;
@@ -768,7 +1087,25 @@ interface UseBotDojoCanvasReturn {
768
1087
  parsedArguments?: any;
769
1088
  toolError?: string;
770
1089
  /** Send message in the chat (triggers flow) */
771
- sendMessage: (text: string, params?: any) => Promise<any>;
1090
+ sendMessage: (text: string, params?: any, options?: CanvasActionOptions) => Promise<any>;
1091
+ /** Send a link action to the parent (navigation) */
1092
+ sendLink: (url: string, target?: '_self' | '_blank', options?: CanvasActionOptions) => Promise<any> | void;
1093
+ /** Send an intent action to the parent */
1094
+ sendIntent: (intent: string, params?: Record<string, any>, options?: CanvasActionOptions) => Promise<any> | void;
1095
+ /** Send a notification to the parent */
1096
+ sendNotify: (message: string, params?: Record<string, any>, options?: CanvasActionOptions) => Promise<any> | void;
1097
+ /** Send a prompt to the parent (triggers agent response) */
1098
+ sendPrompt: (prompt: string, params?: Record<string, any>, options?: CanvasActionOptions) => Promise<any> | void;
1099
+ /** Send a tool/callTool action */
1100
+ sendTool?: (toolName: string, args?: any, options?: CanvasActionOptions) => Promise<any>;
1101
+ /** Send an update action (canvas data) */
1102
+ sendUpdate?: (data: any, options?: CanvasActionOptions) => Promise<any>;
1103
+ /** Low-level dispatch hook */
1104
+ dispatchUIAction?: (action: {
1105
+ type: string;
1106
+ payload?: any;
1107
+ messageId?: string;
1108
+ }, options?: CanvasActionOptions) => Promise<any>;
772
1109
  /** Access to chat connector */
773
1110
  connector: BotDojoConnector | null;
774
1111
  /** Listen to events */
@@ -777,7 +1114,7 @@ interface UseBotDojoCanvasReturn {
777
1114
  isMockMode: boolean;
778
1115
  }
779
1116
  interface BotDojoCanvasProviderProps {
780
- children: React.ReactNode;
1117
+ children: React$1.ReactNode;
781
1118
  /** Canvas data for this card */
782
1119
  canvasData?: any;
783
1120
  /** Connector from parent chat widget */
@@ -786,9 +1123,15 @@ interface BotDojoCanvasProviderProps {
786
1123
  modelContext?: ModelContext$1 | ModelContext$1[];
787
1124
  /** Debug mode */
788
1125
  debug?: boolean;
1126
+ /** Canvas runtime mode */
1127
+ mode?: CanvasMode;
1128
+ /** Initial render data for MCP-UI lifecycle */
1129
+ initialRenderData?: any;
1130
+ /** Mirror MCP-UI actions to legacy canvas_* RPCs */
1131
+ mirrorLegacyCanvasRpc?: boolean;
789
1132
  }
790
1133
  interface MockCanvasProviderProps {
791
- children: React.ReactNode;
1134
+ children: React$1.ReactNode;
792
1135
  /** Mock canvas data */
793
1136
  mockCanvasData?: any;
794
1137
  /** Mock message handler */
@@ -796,25 +1139,127 @@ interface MockCanvasProviderProps {
796
1139
  /** Debug mode */
797
1140
  debug?: boolean;
798
1141
  }
1142
+ type AppEvent = 'app:initialized' | 'app:tool-input' | 'app:tool-input-partial' | 'app:tool-result' | 'app:tool-cancelled' | 'app:host-context-changed' | 'app:size-change' | 'app:resource-teardown';
1143
+ interface AppContextValue {
1144
+ /** Whether the app is initialized */
1145
+ isInitialized: boolean;
1146
+ /** Error if any */
1147
+ error: Error | null;
1148
+ /** Host capabilities */
1149
+ hostCapabilities?: {
1150
+ openLinks?: {};
1151
+ 'botdojo/persistence'?: boolean;
1152
+ [key: string]: any;
1153
+ };
1154
+ /** Host context (theme, viewport, etc.) */
1155
+ hostContext?: {
1156
+ theme?: 'light' | 'dark';
1157
+ viewport?: {
1158
+ width: number;
1159
+ height: number;
1160
+ };
1161
+ initialData?: any;
1162
+ [key: string]: any;
1163
+ };
1164
+ /** Current tool being executed */
1165
+ toolName?: string;
1166
+ /** Tool arguments (from tool-input) */
1167
+ toolArguments?: Record<string, unknown>;
1168
+ /** Partial tool arguments (from tool-input-partial, streaming) */
1169
+ partialToolArguments?: Record<string, unknown>;
1170
+ /** Tool result */
1171
+ toolResult?: any;
1172
+ /** UI size */
1173
+ size?: {
1174
+ width: number;
1175
+ height: number;
1176
+ };
1177
+ /** Send message to host */
1178
+ sendMessage: (content: Array<{
1179
+ type: string;
1180
+ text?: string;
1181
+ [key: string]: any;
1182
+ }>) => Promise<void>;
1183
+ /** Open a link */
1184
+ openLink: (url: string) => Promise<void>;
1185
+ /** Send intent action */
1186
+ sendIntent: (intent: string, params?: Record<string, any>) => Promise<any>;
1187
+ /** Send prompt action */
1188
+ sendPrompt: (prompt: string, params?: Record<string, any>) => Promise<any>;
1189
+ /** Send notify action */
1190
+ sendNotify: (message: string, params?: Record<string, any>) => Promise<void>;
1191
+ /** Send update action */
1192
+ sendUpdate: (data: Record<string, any>) => Promise<void>;
1193
+ /** Call a tool */
1194
+ callTool: (tool: string, params?: Record<string, any>) => Promise<any>;
1195
+ /** Read a resource */
1196
+ readResource: (uri: string, mimeType?: string, metadataOnly?: boolean) => Promise<any>;
1197
+ /** Notify host of size change */
1198
+ notifySizeChange: (width: number, height: number) => void;
1199
+ /** Listen to app events */
1200
+ on: (event: AppEvent, handler: (data: any) => void) => () => void;
1201
+ }
799
1202
 
800
1203
  /**
801
1204
  * Canvas provider for inline canvas cards in chat widgets
802
- * Automatically handles postMessage communication when in iframe
1205
+ * Supports dojo (legacy) and MCP Apps mode with BotDojo extensions
1206
+ * @deprecated Prefer BotDojoAppProvider for new MCP Apps; this stays for legacy/dual-mode canvas flows.
803
1207
  */
804
- declare function BotDojoCanvasProvider({ children, canvasData: initialCanvasData, connector: externalConnector, modelContext, debug }: BotDojoCanvasProviderProps): react_jsx_runtime.JSX.Element;
1208
+ declare function BotDojoCanvasProvider({ children, canvasData: initialCanvasData, connector: externalConnector, modelContext, debug, mode, initialRenderData, mirrorLegacyCanvasRpc, }: BotDojoCanvasProviderProps): react_jsx_runtime.JSX.Element;
805
1209
 
806
1210
  /**
807
- * Mock canvas provider for testing canvas cards standalone
808
- * - No connector needed
809
- * - Simulates runtime with callbacks
810
- * - Perfect for development and testing
1211
+ * @deprecated Use `useMcpApp` from `mcp-app-view/react` instead.
1212
+ * This provider will be removed in a future version.
1213
+ *
1214
+ * For testing MCP Apps, create mock data and pass as initialState to useMcpApp.
1215
+ *
1216
+ * Migration:
1217
+ * ```tsx
1218
+ * // Before
1219
+ * import { MockCanvasProvider, useBotDojoCanvas } from '@botdojo/chat-sdk';
1220
+ *
1221
+ * <MockCanvasProvider mockCanvasData={data}>
1222
+ * <MyCanvas />
1223
+ * </MockCanvasProvider>
1224
+ *
1225
+ * // After - no provider needed
1226
+ * import { useMcpApp } from 'mcp-app-view/react';
1227
+ *
1228
+ * function MyCanvas() {
1229
+ * const { state, tool } = useMcpApp({
1230
+ * initialState: mockData,
1231
+ * });
1232
+ * }
1233
+ * ```
811
1234
  */
812
1235
  declare function MockCanvasProvider({ children, mockCanvasData, onSendMessage, debug }: MockCanvasProviderProps): react_jsx_runtime.JSX.Element;
813
1236
 
814
1237
  /**
815
- * Hook to access canvas runtime
816
- * Works with both BotDojoCanvasProvider and MockCanvasProvider
1238
+ * @deprecated Use `useMcpApp` from `mcp-app-view/react` instead.
1239
+ * This hook will be removed in a future version.
1240
+ *
1241
+ * Migration:
1242
+ * ```tsx
1243
+ * // Before
1244
+ * import { BotDojoCanvasProvider, useBotDojoCanvas } from '@botdojo/chat-sdk';
1245
+ *
1246
+ * function MyCanvas() {
1247
+ * const canvas = useBotDojoCanvas();
1248
+ * // canvas.canvasData, canvas.toolPhase, etc.
1249
+ * }
1250
+ *
1251
+ * // After
1252
+ * import { useMcpApp } from 'mcp-app-view/react';
1253
+ *
1254
+ * function MyCanvas() {
1255
+ * const { isInitialized, tool, hostContext, sendMessage, callTool } = useMcpApp({
1256
+ * containerRef,
1257
+ * autoReportSize: true,
1258
+ * });
1259
+ * // tool.arguments, tool.isStreaming, tool.result, etc.
1260
+ * }
1261
+ * ```
817
1262
  */
818
1263
  declare function useBotDojoCanvas(): UseBotDojoCanvasReturn;
819
1264
 
820
- export { 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 CanvasEvent, type ChatActionsHook, type ChatConfig, type ChatMessage, type ChatMessagesHook, type ChatStatus, type ChatStatusHook, type HeadlessAction, HeadlessChat, type HeadlessChatHandle, type HeadlessChatProps, type HeadlessChatState, type HeadlessEvent, type HeadlessMessageEvent, type HeadlessStatusEvent, type HeadlessStepEvent, type HeadlessTokenEvent, MockCanvasProvider, type MockCanvasProviderProps, type PopupOptions, type SidePanelOptions, type UseBotDojoCanvasReturn, useBotDojoCanvas, useBotDojoChat, useChatActions, useChatMessages, useChatStatus };
1265
+ export { 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 HeadlessAction, HeadlessChat, type HeadlessChatHandle, type HeadlessChatProps, type HeadlessChatState, type HeadlessEvent, type HeadlessMessageEvent, type HeadlessStatusEvent, type HeadlessStepEvent, type HeadlessTokenEvent, type McpAppData, McpAppHost, McpAppHostContext, type McpAppHostContextValue, type McpAppHostProps, McpAppHostProvider, type McpAppHostProviderProps, MockCanvasProvider, type MockCanvasProviderProps, type PopupOptions, type SidePanelOptions, type UiSize, type UseBotDojoCanvasReturn, useBotDojoCanvas, useBotDojoChat, useChatActions, useChatMessages, useChatStatus, useMcpAppHost, useMcpAppHostRequired };