@botdojo/chat-sdk 0.0.16 → 0.0.17

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
@@ -1,12 +1,391 @@
1
1
  import React$1 from 'react';
2
- import { ModelContext, BotDojoConnector as BotDojoConnector$1 } from '@botdojo/sdk-canvas';
3
- export { BotDojoConnector } from '@botdojo/sdk-canvas';
4
- import { ModelContext as ModelContext$1, FlowRequestStep, Core_TokenUpdate } from '@botdojo/sdk-types';
5
- export { CitationData, ContentItem, MIME_TYPES, McpUiHostContext, ModelContext, ModelContextMessage, ModelContextPrompt, ModelContextResource, ResourceContent, ResourceProvider, ResourceReference, ResourceTemplate, ToolDefinition, ToolExecutionContext, ToolExecutionResult, ToolMetadata, citation, citations, imageResult, mcpResource, modelContext, textResult, tool, uiResource } from '@botdojo/sdk-types';
2
+ import { BotDojoConnector as BotDojoConnector$1 } from './BotDojoConnector';
3
+ export { BotDojoConnector } from './BotDojoConnector';
4
+ import { Core_FlowCanvas, Core_ToolExecutionPhase, Core_TokenUpdate } from './backend-types-snapshot';
6
5
  import { ChatMessage as ChatMessage$1 } from 'botdojo-core/lib/src/store/session';
7
6
  import { FlowCanvasType } from 'botdojo-core/lib/src/store/flowRequest';
7
+ export { citation, citations, imageResult, mcpResource, modelContext, textResult, tool, uiResource } from './tool-utils';
8
+ export { McpUiHostContext } from './mcp-apps';
8
9
  import * as react_jsx_runtime from 'react/jsx-runtime';
9
10
 
11
+ /**
12
+ * Shared TypeScript types for BotDojo SDK and Canvas Client
13
+ *
14
+ * This package contains pure TypeScript type definitions with no JSX or React dependencies.
15
+ * It can be safely imported by any TypeScript project without requiring JSX configuration.
16
+ */
17
+
18
+ /**
19
+ * Resource reference for UI, ModelContext, or other resources
20
+ *
21
+ * MIME types determine how resource is handled:
22
+ * - 'text/uri-list': External URL loaded in iframe (MCP Apps standard)
23
+ * - 'text/html': Inline HTML rendered in iframe
24
+ * - 'application/vnd.botdojo.ui-remote-dom': Remote DOM script
25
+ * - 'application/vnd.botdojo.modelcontext': Nested ModelContext (URI points to resource)
26
+ * - 'application/vnd.botdojo.citation': Single citation
27
+ * - 'application/vnd.botdojo.citations': Multiple citations
28
+ */
29
+ interface ResourceReference$1 {
30
+ /** Resource URI (e.g., 'ui://product/123', 'mcp://actions') */
31
+ uri: string;
32
+ /** MIME type determines how resource is processed */
33
+ mimeType?: string;
34
+ /** Resource content (URL for uri-list, inline HTML for text/html(+mcp), or URI for modelcontext) */
35
+ text?: string;
36
+ /** Inline HTML for `text/html`, `text/html+mcp`, or `text/html;profile=mcp-app` resources */
37
+ html?: string;
38
+ /** Optional allowlist for URL-based resources (matches SEP url-list direction) */
39
+ urlList?: string[];
40
+ /** Base URL to apply to inline HTML (used for relative asset resolution) */
41
+ baseUrl?: string;
42
+ /** Hint to prefer sandbox proxy even when a URL exists */
43
+ prefersProxy?: boolean;
44
+ /** Hint to allow direct external URL rendering even when inline HTML is present */
45
+ allowExternal?: boolean;
46
+ /** Metadata for UI resources only */
47
+ meta?: {
48
+ /** SEP-1865 UI metadata */
49
+ ui?: {
50
+ /** Preferred iframe dimensions (object or tuple) */
51
+ preferredFrameSize?: {
52
+ width: string;
53
+ height: string;
54
+ } | [string, string];
55
+ /** Initial render data/state */
56
+ initialRenderData?: any;
57
+ /** Optional display name for the canvas */
58
+ displayName?: string;
59
+ /** If true, canvas should not be persisted */
60
+ stateless?: boolean;
61
+ /** MIME type hint for the UI resource */
62
+ mimeType?: string;
63
+ /** Optional CSP hints */
64
+ csp?: {
65
+ connectDomains?: string[];
66
+ resourceDomains?: string[];
67
+ domain?: string;
68
+ allowPopups?: boolean;
69
+ allowForms?: boolean;
70
+ allowSameOrigin?: boolean;
71
+ prefersBorder?: boolean;
72
+ };
73
+ /** Optional resource hints for inline/URL handling */
74
+ urlList?: string[];
75
+ baseUrl?: string;
76
+ prefersProxy?: boolean;
77
+ allowExternal?: boolean;
78
+ };
79
+ /** Additional metadata */
80
+ [key: string]: any;
81
+ };
82
+ }
83
+ /**
84
+ * MCP-compliant content item for tool results
85
+ *
86
+ * Tools should return ContentItem[] for rich responses, or plain objects for simple results.
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * // Simple text response
91
+ * return [{ type: 'text', text: 'Operation successful' }];
92
+ *
93
+ * // UI resource with initial data
94
+ * return [
95
+ * { type: 'text', text: 'Product loaded' },
96
+ * {
97
+ * type: 'resource',
98
+ * resource: {
99
+ * uri: 'ui://product/123',
100
+ * mimeType: 'text/uri-list',
101
+ * meta: { ui: { initialRenderData: { product } } }
102
+ * }
103
+ * }
104
+ * ];
105
+ * ```
106
+ */
107
+ interface ContentItem$1 {
108
+ /** Content type: text, image, or resource */
109
+ type: 'text' | 'image' | 'resource';
110
+ /** Text content (for type: 'text') */
111
+ text?: string;
112
+ /** Base64-encoded image data (for type: 'image') */
113
+ data?: string;
114
+ /** MIME type for images (e.g., 'image/png') */
115
+ mimeType?: string;
116
+ /** Resource reference (for type: 'resource') */
117
+ resource?: ResourceReference$1;
118
+ }
119
+ /**
120
+ * Tool execution result type
121
+ * Tools can return:
122
+ * - ContentItem[] for rich responses (UI, citations, etc.)
123
+ * - Plain object/primitive for simple results
124
+ */
125
+ type ToolExecutionResult$1<TResult = any> = ContentItem$1[] | TResult;
126
+ /**
127
+ * Context provided to tools during execution
128
+ * Includes methods for updating canvas state in real-time.
129
+ *
130
+ * MCP App canvases receive `hostContext.toolInfo` with the tool schema.
131
+ * Tool arguments/results come via ui/notifications/tool-input and tool-result.
132
+ * `hostContext.state` hydrates from UI state persistence (BotDojo extension);
133
+ * use `updateState` strictly for UI state (e.g., counters).
134
+ */
135
+ interface ToolExecutionContext$1 {
136
+ /** Name of the tool being executed (helpful for logging/notifications) */
137
+ toolName?: string;
138
+ /**
139
+ * Update canvas UI state during tool execution (if resource-template is present).
140
+ * Do not mirror tool arguments/results here; the host caches that from
141
+ * `ui/notifications/tool-*`. Keep this for UI persistence only.
142
+ */
143
+ updateState?: (state: any) => Promise<void>;
144
+ /**
145
+ * Send MCP Apps tool notifications to the UI host (SEP-1865).
146
+ * Implementations should emit JSON-RPC notifications using context.toolName:
147
+ * - ui/notifications/tool-input-partial (streaming args)
148
+ * - ui/notifications/tool-input (final args)
149
+ * - ui/notifications/tool-result (result payload)
150
+ */
151
+ notifyToolInputPartial?: (args: Record<string, unknown>) => Promise<void>;
152
+ notifyToolInput?: (args: Record<string, unknown>) => Promise<void>;
153
+ notifyToolResult?: (result: any) => Promise<void>;
154
+ }
155
+ /**
156
+ * Tool metadata following MCP Apps SDK pattern
157
+ * Uses _meta with vendor-namespaced extensions (kebab-case)
158
+ *
159
+ * All BotDojo-specific options use 'botdojo/' prefix with kebab-case keys
160
+ */
161
+ interface ToolMetadata$1 {
162
+ ui?: {
163
+ preferredFrameSize?: {
164
+ width: string;
165
+ height: string;
166
+ } | [string, string];
167
+ initialRenderData?: any;
168
+ displayName?: string;
169
+ stateless?: boolean;
170
+ /** Resource URI for pre-rendering during streaming */
171
+ resourceUri?: string;
172
+ mimeType?: 'text/html+mcp' | 'text/html;profile=mcp-app' | 'text/html' | 'text/uri-list';
173
+ showInline?: boolean;
174
+ agentEnabled?: boolean;
175
+ /** Optional render hints for inline/URL MCP Apps */
176
+ urlList?: string[];
177
+ baseUrl?: string;
178
+ prefersProxy?: boolean;
179
+ allowExternal?: boolean;
180
+ };
181
+ 'botdojo/resource-template'?: {
182
+ uri: string;
183
+ mimeType: string;
184
+ metadata?: {
185
+ ui?: {
186
+ preferredFrameSize?: {
187
+ width: string;
188
+ height: string;
189
+ } | [string, string];
190
+ initialRenderData?: any;
191
+ displayName?: string;
192
+ stateless?: boolean;
193
+ mimeType?: string;
194
+ };
195
+ [key: string]: any;
196
+ };
197
+ };
198
+ 'botdojo/display-name'?: string;
199
+ 'botdojo/hide-step'?: boolean;
200
+ 'botdojo/hide-step-details'?: boolean;
201
+ }
202
+ /**
203
+ * Tool definition for defining tools
204
+ * Can be used in two ways:
205
+ * 1. In an array: tools: ToolDefinition[] (needs 'name' field)
206
+ * 2. In an object: tools: Record<string, ToolDefinition> ('name' is the key, so field is optional)
207
+ *
208
+ * Display hints (displayName, hideStep, hideStepDetails) are in _meta with botdojo/ prefix
209
+ */
210
+ interface ToolDefinition$1<TParams = any, TResult = any> {
211
+ name?: string;
212
+ description: string;
213
+ /** JSON Schema for parameters (MCP standard) */
214
+ inputSchema?: any;
215
+ /** Tool metadata - display hints and resource templates */
216
+ _meta?: ToolMetadata$1;
217
+ /** Execute function - returns ContentItem[] or plain result */
218
+ /** Can accept optional ToolExecutionContext as second parameter for notifications */
219
+ execute?: (params: TParams, context?: ToolExecutionContext$1) => Promise<ToolExecutionResult$1<TResult>>;
220
+ }
221
+ interface ModelContextMessage$1 {
222
+ role: string;
223
+ content: string;
224
+ }
225
+ interface ModelContextPrompt$1 {
226
+ name: string;
227
+ description: string;
228
+ messages: ModelContextMessage$1[];
229
+ }
230
+ /**
231
+ * Resource content returned by a provider
232
+ */
233
+ interface ResourceContent$1 {
234
+ uri: string;
235
+ mimeType?: string;
236
+ text?: string;
237
+ meta?: {
238
+ title?: string;
239
+ description?: string;
240
+ [key: string]: any;
241
+ };
242
+ links?: Array<{
243
+ uri: string;
244
+ rel: string;
245
+ description?: string;
246
+ }>;
247
+ /** If this resource is itself an MCP, include it here */
248
+ mcp?: ModelContext$1[];
249
+ }
250
+ /**
251
+ * Static resource with fixed URI
252
+ *
253
+ * @example
254
+ * ```typescript
255
+ * {
256
+ * uri: 'myapp://help',
257
+ * mimeType: 'text/markdown',
258
+ * getContent: async () => '# Help...'
259
+ * }
260
+ * ```
261
+ */
262
+ interface ModelContextStaticResource$1 {
263
+ /** Fixed URI for this resource */
264
+ uri: string;
265
+ /** Resource name (optional - can be inferred from uri) */
266
+ name?: string;
267
+ /** Human-readable label */
268
+ label?: string;
269
+ /** MIME type of the resource */
270
+ mimeType?: string;
271
+ /** Description of the resource */
272
+ description?: string;
273
+ /** Additional metadata */
274
+ meta?: {
275
+ title?: string;
276
+ description?: string;
277
+ icon?: string;
278
+ [key: string]: any;
279
+ };
280
+ /** Get resource content (no parameters for static resources) */
281
+ getContent: () => Promise<string | {
282
+ url: string;
283
+ } | ResourceContent$1>;
284
+ }
285
+ /**
286
+ * Dynamic resource with parameterized URI template
287
+ *
288
+ * @example
289
+ * ```typescript
290
+ * {
291
+ * uriTemplate: 'myapp://file/{filepath}',
292
+ * mimeType: 'botdojo/mcp',
293
+ * getContent: async (params) => {
294
+ * // params.filepath is extracted from URI
295
+ * return { mcp: [...] }
296
+ * }
297
+ * }
298
+ * ```
299
+ */
300
+ interface ModelContextDynamicResource$1 {
301
+ /** URI template with parameters - e.g., "myapp://users/{userId}" */
302
+ uriTemplate: string;
303
+ /** Resource name (optional - can be inferred from template) */
304
+ name?: string;
305
+ /** Human-readable label */
306
+ label?: string;
307
+ /** MIME type of the resource */
308
+ mimeType?: string;
309
+ /** Description of the resource */
310
+ description?: string;
311
+ /** Additional metadata */
312
+ meta?: {
313
+ title?: string;
314
+ description?: string;
315
+ icon?: string;
316
+ [key: string]: any;
317
+ };
318
+ /** Get resource content with extracted parameters */
319
+ getContent: (params: Record<string, any>) => Promise<string | {
320
+ url: string;
321
+ } | ResourceContent$1>;
322
+ }
323
+ /**
324
+ * Model context resource - can be either static or dynamic
325
+ */
326
+ type ModelContextResource$1 = ModelContextStaticResource$1 | ModelContextDynamicResource$1;
327
+ /**
328
+ * MCP-level CORS configuration for tool call security
329
+ * Configured by developers when defining MCP backends
330
+ *
331
+ * IMPORTANT: Only validates parent/canvas → chat tool calls.
332
+ * Agent → parent/canvas tool calls use origin='server' and bypass validation.
333
+ */
334
+ interface ModelContextCorsConfig$1 {
335
+ /**
336
+ * Origins allowed to call tools on this MCP backend
337
+ * Used by chat iframe router to validate tool call origins FROM parent/canvas
338
+ *
339
+ * Default: undefined = ALL origins allowed (permissive by default)
340
+ * Empty array [] = NO origins allowed (block all)
341
+ * 'server' = Reserved, always allowed (agent tool calls)
342
+ *
343
+ * Protocol enforcement: Must match exactly (https:// ≠ http://)
344
+ * Port enforcement: Must match exactly (:443 ≠ :80)
345
+ * Wildcard support: Prefix only, follows CORS spec (*.myshop.com matches any subdomain)
346
+ *
347
+ * Examples:
348
+ * - undefined → Allow all (backward compatible)
349
+ * - [] → Block all parent/canvas tool calls
350
+ * - ["https://myshop.com", "https://admin.myshop.com"] → Exact matches only
351
+ * - ["*.myshop.com"] → Allow any subdomain (app.myshop.com, admin.myshop.com)
352
+ * - ["https://myshop.com"] → Does NOT match http://myshop.com (protocol differs)
353
+ */
354
+ allowedToolCallOrigins?: string[];
355
+ }
356
+ /**
357
+ * Model context definition with tools, prompts, and resources
358
+ * Tools can be defined as either:
359
+ * - An array: tools: ToolDefinition[] (each tool needs 'name' field)
360
+ * - An object: tools: Record<string, ToolDefinition> (key is the tool name)
361
+ *
362
+ * Resources support both static and dynamic patterns:
363
+ * - Static: { uri: 'app://help', getContent: async () => '...' }
364
+ * - Dynamic: { uriTemplate: 'app://file/{id}', getContent: async (params) => '...' }
365
+ */
366
+ interface ModelContext$1 {
367
+ name: string;
368
+ description?: string;
369
+ toolPrefix?: string;
370
+ resourceUri?: string;
371
+ uri?: string;
372
+ tools?: ToolDefinition$1[] | Record<string, ToolDefinition$1>;
373
+ prompts?: ModelContextPrompt$1[];
374
+ /** Unified resources array supporting both static and dynamic resources */
375
+ resources?: ModelContextResource$1[];
376
+ /**
377
+ * CORS configuration for this MCP
378
+ *
379
+ * **Backend Use**: Server enforces these rules before executing tools
380
+ * - allowedToolCallOrigins: Which parent/canvas origins can call tools from this MCP
381
+ *
382
+ * **Note**: For SDK usage (BotDojoChat/BotDojoConnector), use the
383
+ * constructor-level `cors` parameter with ToolCallCorsConfig instead.
384
+ * This field is primarily for backend per-MCP enforcement.
385
+ */
386
+ cors?: ModelContextCorsConfig$1;
387
+ }
388
+
10
389
  /**
11
390
  * Display modes for BotDojo chat
12
391
  */
@@ -225,7 +604,7 @@ interface BotDojoChatProps {
225
604
  * Can be a single ModelContext or an array of ModelContext objects
226
605
  * Tools should include `execute` functions directly in their definitions
227
606
  */
228
- modelContext?: ModelContext | ModelContext[];
607
+ modelContext?: ModelContext$1 | ModelContext$1[];
229
608
  /**
230
609
  * Called when chat iframe loads
231
610
  */
@@ -416,7 +795,7 @@ interface HeadlessChatProps {
416
795
  * Model context with tools, prompts, and resources
417
796
  * Tools should include `execute` functions directly in their definitions
418
797
  */
419
- modelContext?: ModelContext | ModelContext[];
798
+ modelContext?: ModelContext$1 | ModelContext$1[];
420
799
  /**
421
800
  * Base URL for the headless embed iframe
422
801
  * @default 'http://localhost:3000' (development)
@@ -554,6 +933,475 @@ interface HeadlessChatHandle {
554
933
  isReady: () => boolean;
555
934
  }
556
935
 
936
+ /**
937
+ * Shared TypeScript types for BotDojo SDK and Canvas Client
938
+ *
939
+ * This package contains pure TypeScript type definitions with no JSX or React dependencies.
940
+ * It can be safely imported by any TypeScript project without requiring JSX configuration.
941
+ */
942
+
943
+ /**
944
+ * Resource reference for UI, ModelContext, or other resources
945
+ *
946
+ * MIME types determine how resource is handled:
947
+ * - 'text/uri-list': External URL loaded in iframe (MCP Apps standard)
948
+ * - 'text/html': Inline HTML rendered in iframe
949
+ * - 'application/vnd.botdojo.ui-remote-dom': Remote DOM script
950
+ * - 'application/vnd.botdojo.modelcontext': Nested ModelContext (URI points to resource)
951
+ * - 'application/vnd.botdojo.citation': Single citation
952
+ * - 'application/vnd.botdojo.citations': Multiple citations
953
+ */
954
+ interface ResourceReference {
955
+ /** Resource URI (e.g., 'ui://product/123', 'mcp://actions') */
956
+ uri: string;
957
+ /** MIME type determines how resource is processed */
958
+ mimeType?: string;
959
+ /** Resource content (URL for uri-list, inline HTML for text/html(+mcp), or URI for modelcontext) */
960
+ text?: string;
961
+ /** Inline HTML for `text/html`, `text/html+mcp`, or `text/html;profile=mcp-app` resources */
962
+ html?: string;
963
+ /** Optional allowlist for URL-based resources (matches SEP url-list direction) */
964
+ urlList?: string[];
965
+ /** Base URL to apply to inline HTML (used for relative asset resolution) */
966
+ baseUrl?: string;
967
+ /** Hint to prefer sandbox proxy even when a URL exists */
968
+ prefersProxy?: boolean;
969
+ /** Hint to allow direct external URL rendering even when inline HTML is present */
970
+ allowExternal?: boolean;
971
+ /** Metadata for UI resources only */
972
+ meta?: {
973
+ /** SEP-1865 UI metadata */
974
+ ui?: {
975
+ /** Preferred iframe dimensions (object or tuple) */
976
+ preferredFrameSize?: {
977
+ width: string;
978
+ height: string;
979
+ } | [string, string];
980
+ /** Initial render data/state */
981
+ initialRenderData?: any;
982
+ /** Optional display name for the canvas */
983
+ displayName?: string;
984
+ /** If true, canvas should not be persisted */
985
+ stateless?: boolean;
986
+ /** MIME type hint for the UI resource */
987
+ mimeType?: string;
988
+ /** Optional CSP hints */
989
+ csp?: {
990
+ connectDomains?: string[];
991
+ resourceDomains?: string[];
992
+ domain?: string;
993
+ allowPopups?: boolean;
994
+ allowForms?: boolean;
995
+ allowSameOrigin?: boolean;
996
+ prefersBorder?: boolean;
997
+ };
998
+ /** Optional resource hints for inline/URL handling */
999
+ urlList?: string[];
1000
+ baseUrl?: string;
1001
+ prefersProxy?: boolean;
1002
+ allowExternal?: boolean;
1003
+ };
1004
+ /** Additional metadata */
1005
+ [key: string]: any;
1006
+ };
1007
+ }
1008
+ /**
1009
+ * MCP-compliant content item for tool results
1010
+ *
1011
+ * Tools should return ContentItem[] for rich responses, or plain objects for simple results.
1012
+ *
1013
+ * @example
1014
+ * ```typescript
1015
+ * // Simple text response
1016
+ * return [{ type: 'text', text: 'Operation successful' }];
1017
+ *
1018
+ * // UI resource with initial data
1019
+ * return [
1020
+ * { type: 'text', text: 'Product loaded' },
1021
+ * {
1022
+ * type: 'resource',
1023
+ * resource: {
1024
+ * uri: 'ui://product/123',
1025
+ * mimeType: 'text/uri-list',
1026
+ * meta: { ui: { initialRenderData: { product } } }
1027
+ * }
1028
+ * }
1029
+ * ];
1030
+ * ```
1031
+ */
1032
+ interface ContentItem {
1033
+ /** Content type: text, image, or resource */
1034
+ type: 'text' | 'image' | 'resource';
1035
+ /** Text content (for type: 'text') */
1036
+ text?: string;
1037
+ /** Base64-encoded image data (for type: 'image') */
1038
+ data?: string;
1039
+ /** MIME type for images (e.g., 'image/png') */
1040
+ mimeType?: string;
1041
+ /** Resource reference (for type: 'resource') */
1042
+ resource?: ResourceReference;
1043
+ }
1044
+ /**
1045
+ * Citation data for referencing sources
1046
+ * Citations are BotDojo primitives, not UI resources
1047
+ */
1048
+ interface CitationData {
1049
+ /** Required unique identifier */
1050
+ id: string;
1051
+ /** Source name/title */
1052
+ source: string;
1053
+ /** Optional URL */
1054
+ url?: string;
1055
+ /** Optional quote/excerpt */
1056
+ text?: string;
1057
+ /** Additional metadata */
1058
+ [key: string]: any;
1059
+ }
1060
+ /**
1061
+ * Tool execution result type
1062
+ * Tools can return:
1063
+ * - ContentItem[] for rich responses (UI, citations, etc.)
1064
+ * - Plain object/primitive for simple results
1065
+ */
1066
+ type ToolExecutionResult<TResult = any> = ContentItem[] | TResult;
1067
+ /**
1068
+ * Standard MIME types for BotDojo resources
1069
+ */
1070
+ declare const MIME_TYPES: {
1071
+ readonly URI_LIST: "text/uri-list";
1072
+ readonly HTML: "text/html";
1073
+ readonly HTML_MCP: "text/html+mcp";
1074
+ readonly HTML_MCP_PROFILE: "text/html;profile=mcp-app";
1075
+ readonly REMOTE_DOM: "application/vnd.mcp-ui.remote-dom";
1076
+ readonly REMOTE_DOM_BOTDOJO: "application/vnd.botdojo.ui-remote-dom";
1077
+ readonly MODEL_CONTEXT: "application/vnd.botdojo.modelcontext";
1078
+ readonly CITATION: "application/vnd.botdojo.citation";
1079
+ readonly CITATIONS: "application/vnd.botdojo.citations";
1080
+ };
1081
+ /**
1082
+ * Context provided to tools during execution
1083
+ * Includes methods for updating canvas state in real-time.
1084
+ *
1085
+ * MCP App canvases receive `hostContext.toolInfo` with the tool schema.
1086
+ * Tool arguments/results come via ui/notifications/tool-input and tool-result.
1087
+ * `hostContext.state` hydrates from UI state persistence (BotDojo extension);
1088
+ * use `updateState` strictly for UI state (e.g., counters).
1089
+ */
1090
+ interface ToolExecutionContext {
1091
+ /** Name of the tool being executed (helpful for logging/notifications) */
1092
+ toolName?: string;
1093
+ /**
1094
+ * Update canvas UI state during tool execution (if resource-template is present).
1095
+ * Do not mirror tool arguments/results here; the host caches that from
1096
+ * `ui/notifications/tool-*`. Keep this for UI persistence only.
1097
+ */
1098
+ updateState?: (state: any) => Promise<void>;
1099
+ /**
1100
+ * Send MCP Apps tool notifications to the UI host (SEP-1865).
1101
+ * Implementations should emit JSON-RPC notifications using context.toolName:
1102
+ * - ui/notifications/tool-input-partial (streaming args)
1103
+ * - ui/notifications/tool-input (final args)
1104
+ * - ui/notifications/tool-result (result payload)
1105
+ */
1106
+ notifyToolInputPartial?: (args: Record<string, unknown>) => Promise<void>;
1107
+ notifyToolInput?: (args: Record<string, unknown>) => Promise<void>;
1108
+ notifyToolResult?: (result: any) => Promise<void>;
1109
+ }
1110
+ /**
1111
+ * Tool metadata following MCP Apps SDK pattern
1112
+ * Uses _meta with vendor-namespaced extensions (kebab-case)
1113
+ *
1114
+ * All BotDojo-specific options use 'botdojo/' prefix with kebab-case keys
1115
+ */
1116
+ interface ToolMetadata {
1117
+ ui?: {
1118
+ preferredFrameSize?: {
1119
+ width: string;
1120
+ height: string;
1121
+ } | [string, string];
1122
+ initialRenderData?: any;
1123
+ displayName?: string;
1124
+ stateless?: boolean;
1125
+ /** Resource URI for pre-rendering during streaming */
1126
+ resourceUri?: string;
1127
+ mimeType?: 'text/html+mcp' | 'text/html;profile=mcp-app' | 'text/html' | 'text/uri-list';
1128
+ showInline?: boolean;
1129
+ agentEnabled?: boolean;
1130
+ /** Optional render hints for inline/URL MCP Apps */
1131
+ urlList?: string[];
1132
+ baseUrl?: string;
1133
+ prefersProxy?: boolean;
1134
+ allowExternal?: boolean;
1135
+ };
1136
+ 'botdojo/resource-template'?: {
1137
+ uri: string;
1138
+ mimeType: string;
1139
+ metadata?: {
1140
+ ui?: {
1141
+ preferredFrameSize?: {
1142
+ width: string;
1143
+ height: string;
1144
+ } | [string, string];
1145
+ initialRenderData?: any;
1146
+ displayName?: string;
1147
+ stateless?: boolean;
1148
+ mimeType?: string;
1149
+ };
1150
+ [key: string]: any;
1151
+ };
1152
+ };
1153
+ 'botdojo/display-name'?: string;
1154
+ 'botdojo/hide-step'?: boolean;
1155
+ 'botdojo/hide-step-details'?: boolean;
1156
+ }
1157
+ /**
1158
+ * Tool definition for defining tools
1159
+ * Can be used in two ways:
1160
+ * 1. In an array: tools: ToolDefinition[] (needs 'name' field)
1161
+ * 2. In an object: tools: Record<string, ToolDefinition> ('name' is the key, so field is optional)
1162
+ *
1163
+ * Display hints (displayName, hideStep, hideStepDetails) are in _meta with botdojo/ prefix
1164
+ */
1165
+ interface ToolDefinition<TParams = any, TResult = any> {
1166
+ name?: string;
1167
+ description: string;
1168
+ /** JSON Schema for parameters (MCP standard) */
1169
+ inputSchema?: any;
1170
+ /** Tool metadata - display hints and resource templates */
1171
+ _meta?: ToolMetadata;
1172
+ /** Execute function - returns ContentItem[] or plain result */
1173
+ /** Can accept optional ToolExecutionContext as second parameter for notifications */
1174
+ execute?: (params: TParams, context?: ToolExecutionContext) => Promise<ToolExecutionResult<TResult>>;
1175
+ }
1176
+ interface ModelContextMessage {
1177
+ role: string;
1178
+ content: string;
1179
+ }
1180
+ interface ModelContextPrompt {
1181
+ name: string;
1182
+ description: string;
1183
+ messages: ModelContextMessage[];
1184
+ }
1185
+ /**
1186
+ * Resource template for dynamic resource discovery
1187
+ * Compatible with IResourceProvider pattern in botdojo-core
1188
+ */
1189
+ interface ResourceTemplate {
1190
+ /** URI template following RFC 6570 (e.g., "myapp://users/{userId}") */
1191
+ uriTemplate: string;
1192
+ /** Unique identifier for this template */
1193
+ name: string;
1194
+ /** Human-readable name */
1195
+ label: string;
1196
+ /** Description of this resource type */
1197
+ description?: string;
1198
+ /** MIME type for resources matching this template */
1199
+ mimeType?: string;
1200
+ /** Additional metadata */
1201
+ meta?: {
1202
+ title?: string;
1203
+ description?: string;
1204
+ icon?: string;
1205
+ defaultToolPrefix?: string;
1206
+ [key: string]: any;
1207
+ };
1208
+ }
1209
+ /**
1210
+ * Resource provider for dynamic resource discovery
1211
+ * Compatible with Resource Manager MCP v2
1212
+ */
1213
+ interface ResourceProvider {
1214
+ /** Unique provider ID */
1215
+ id: string;
1216
+ /** Resource templates this provider supports */
1217
+ templates: ResourceTemplate[];
1218
+ /**
1219
+ * Get a resource by URI
1220
+ * @param templateName The name of the template that matched
1221
+ * @param uri The resource URI to fetch
1222
+ * @param params Extracted template parameters
1223
+ * @param onlyMetadata If true, only return metadata (no content)
1224
+ */
1225
+ getResource: (templateName: string, uri: string, params: any, onlyMetadata?: boolean) => Promise<ResourceContent>;
1226
+ }
1227
+ /**
1228
+ * Resource content returned by a provider
1229
+ */
1230
+ interface ResourceContent {
1231
+ uri: string;
1232
+ mimeType?: string;
1233
+ text?: string;
1234
+ meta?: {
1235
+ title?: string;
1236
+ description?: string;
1237
+ [key: string]: any;
1238
+ };
1239
+ links?: Array<{
1240
+ uri: string;
1241
+ rel: string;
1242
+ description?: string;
1243
+ }>;
1244
+ /** If this resource is itself an MCP, include it here */
1245
+ mcp?: ModelContext[];
1246
+ }
1247
+ /**
1248
+ * Static resource with fixed URI
1249
+ *
1250
+ * @example
1251
+ * ```typescript
1252
+ * {
1253
+ * uri: 'myapp://help',
1254
+ * mimeType: 'text/markdown',
1255
+ * getContent: async () => '# Help...'
1256
+ * }
1257
+ * ```
1258
+ */
1259
+ interface ModelContextStaticResource {
1260
+ /** Fixed URI for this resource */
1261
+ uri: string;
1262
+ /** Resource name (optional - can be inferred from uri) */
1263
+ name?: string;
1264
+ /** Human-readable label */
1265
+ label?: string;
1266
+ /** MIME type of the resource */
1267
+ mimeType?: string;
1268
+ /** Description of the resource */
1269
+ description?: string;
1270
+ /** Additional metadata */
1271
+ meta?: {
1272
+ title?: string;
1273
+ description?: string;
1274
+ icon?: string;
1275
+ [key: string]: any;
1276
+ };
1277
+ /** Get resource content (no parameters for static resources) */
1278
+ getContent: () => Promise<string | {
1279
+ url: string;
1280
+ } | ResourceContent>;
1281
+ }
1282
+ /**
1283
+ * Dynamic resource with parameterized URI template
1284
+ *
1285
+ * @example
1286
+ * ```typescript
1287
+ * {
1288
+ * uriTemplate: 'myapp://file/{filepath}',
1289
+ * mimeType: 'botdojo/mcp',
1290
+ * getContent: async (params) => {
1291
+ * // params.filepath is extracted from URI
1292
+ * return { mcp: [...] }
1293
+ * }
1294
+ * }
1295
+ * ```
1296
+ */
1297
+ interface ModelContextDynamicResource {
1298
+ /** URI template with parameters - e.g., "myapp://users/{userId}" */
1299
+ uriTemplate: string;
1300
+ /** Resource name (optional - can be inferred from template) */
1301
+ name?: string;
1302
+ /** Human-readable label */
1303
+ label?: string;
1304
+ /** MIME type of the resource */
1305
+ mimeType?: string;
1306
+ /** Description of the resource */
1307
+ description?: string;
1308
+ /** Additional metadata */
1309
+ meta?: {
1310
+ title?: string;
1311
+ description?: string;
1312
+ icon?: string;
1313
+ [key: string]: any;
1314
+ };
1315
+ /** Get resource content with extracted parameters */
1316
+ getContent: (params: Record<string, any>) => Promise<string | {
1317
+ url: string;
1318
+ } | ResourceContent>;
1319
+ }
1320
+ /**
1321
+ * Model context resource - can be either static or dynamic
1322
+ */
1323
+ type ModelContextResource = ModelContextStaticResource | ModelContextDynamicResource;
1324
+ /**
1325
+ * MCP-level CORS configuration for tool call security
1326
+ * Configured by developers when defining MCP backends
1327
+ *
1328
+ * IMPORTANT: Only validates parent/canvas → chat tool calls.
1329
+ * Agent → parent/canvas tool calls use origin='server' and bypass validation.
1330
+ */
1331
+ interface ModelContextCorsConfig {
1332
+ /**
1333
+ * Origins allowed to call tools on this MCP backend
1334
+ * Used by chat iframe router to validate tool call origins FROM parent/canvas
1335
+ *
1336
+ * Default: undefined = ALL origins allowed (permissive by default)
1337
+ * Empty array [] = NO origins allowed (block all)
1338
+ * 'server' = Reserved, always allowed (agent tool calls)
1339
+ *
1340
+ * Protocol enforcement: Must match exactly (https:// ≠ http://)
1341
+ * Port enforcement: Must match exactly (:443 ≠ :80)
1342
+ * Wildcard support: Prefix only, follows CORS spec (*.myshop.com matches any subdomain)
1343
+ *
1344
+ * Examples:
1345
+ * - undefined → Allow all (backward compatible)
1346
+ * - [] → Block all parent/canvas tool calls
1347
+ * - ["https://myshop.com", "https://admin.myshop.com"] → Exact matches only
1348
+ * - ["*.myshop.com"] → Allow any subdomain (app.myshop.com, admin.myshop.com)
1349
+ * - ["https://myshop.com"] → Does NOT match http://myshop.com (protocol differs)
1350
+ */
1351
+ allowedToolCallOrigins?: string[];
1352
+ }
1353
+ /**
1354
+ * Model context definition with tools, prompts, and resources
1355
+ * Tools can be defined as either:
1356
+ * - An array: tools: ToolDefinition[] (each tool needs 'name' field)
1357
+ * - An object: tools: Record<string, ToolDefinition> (key is the tool name)
1358
+ *
1359
+ * Resources support both static and dynamic patterns:
1360
+ * - Static: { uri: 'app://help', getContent: async () => '...' }
1361
+ * - Dynamic: { uriTemplate: 'app://file/{id}', getContent: async (params) => '...' }
1362
+ */
1363
+ interface ModelContext {
1364
+ name: string;
1365
+ description?: string;
1366
+ toolPrefix?: string;
1367
+ resourceUri?: string;
1368
+ uri?: string;
1369
+ tools?: ToolDefinition[] | Record<string, ToolDefinition>;
1370
+ prompts?: ModelContextPrompt[];
1371
+ /** Unified resources array supporting both static and dynamic resources */
1372
+ resources?: ModelContextResource[];
1373
+ /**
1374
+ * CORS configuration for this MCP
1375
+ *
1376
+ * **Backend Use**: Server enforces these rules before executing tools
1377
+ * - allowedToolCallOrigins: Which parent/canvas origins can call tools from this MCP
1378
+ *
1379
+ * **Note**: For SDK usage (BotDojoChat/BotDojoConnector), use the
1380
+ * constructor-level `cors` parameter with ToolCallCorsConfig instead.
1381
+ * This field is primarily for backend per-MCP enforcement.
1382
+ */
1383
+ cors?: ModelContextCorsConfig;
1384
+ }
1385
+ /**
1386
+ * SDK version of flow request step with clean terminology
1387
+ * Maps to internal FlowRequestIntermediateStep but uses cleaner field names
1388
+ */
1389
+ interface FlowRequestStep {
1390
+ stepId: string;
1391
+ stepLabel: string;
1392
+ stepStatus: 'complete' | 'error' | 'processing';
1393
+ error?: string;
1394
+ content: string;
1395
+ startTime: Date;
1396
+ canvas?: Core_FlowCanvas;
1397
+ parentStepId?: string;
1398
+ subSteps?: FlowRequestStep[];
1399
+ stepToolName?: string;
1400
+ stepToolArguments?: Record<string, any>;
1401
+ stepToolResult?: any;
1402
+ stepToolPhase?: Core_ToolExecutionPhase;
1403
+ }
1404
+
557
1405
  /**
558
1406
  * Headless Chat Types
559
1407
  *
@@ -694,7 +1542,7 @@ interface ChatActionsHook {
694
1542
  }
695
1543
  interface BotDojoChatProviderProps {
696
1544
  apiKey: string;
697
- modelContext?: ModelContext$1 | ModelContext$1[];
1545
+ modelContext?: ModelContext | ModelContext[];
698
1546
  baseUrl?: string;
699
1547
  sessionId?: string;
700
1548
  newSession?: boolean;
@@ -1119,7 +1967,7 @@ interface BotDojoCanvasProviderProps {
1119
1967
  /** Connector from parent chat widget */
1120
1968
  connector?: BotDojoConnector;
1121
1969
  /** Optional canvas tools (agent can call these) */
1122
- modelContext?: ModelContext$1 | ModelContext$1[];
1970
+ modelContext?: ModelContext | ModelContext[];
1123
1971
  /** Debug mode */
1124
1972
  debug?: boolean;
1125
1973
  /** Canvas runtime mode */
@@ -1264,4 +2112,4 @@ declare function useBotDojoCanvas(): UseBotDojoCanvasReturn;
1264
2112
  /** @deprecated Use AppAction instead */
1265
2113
  type CanvasAction = AppAction;
1266
2114
 
1267
- 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 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 };
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 };