@botdojo/chat-sdk 0.0.26 → 0.0.29

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,53 +1,892 @@
1
1
  import React$1 from 'react';
2
- import { ModelContext, FlowResponse, FlowRequestStep, Core_TokenUpdate } from '@botdojo/sdk-types';
3
- 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 { RPCConnection } from 'botdojo-rpc';
4
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
4
 
6
- declare class ConectionOptions {
7
- timeout?: number;
8
- maxDepth?: number;
5
+ /**
6
+ * AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
7
+ *
8
+ * This file is generated by packages/sdk-types/scripts/generate-opensource-snapshots.js
9
+ * It contains a snapshot of @botdojo/sdk-types exports needed by @botdojo/chat-sdk
10
+ *
11
+ * To regenerate this file:
12
+ * 1. cd packages/sdk-types
13
+ * 2. pnpm sync-opensource
14
+ *
15
+ * Generated: 2025-12-28T14:24:46.719Z
16
+ */
17
+ /** Flow canvas configuration (stub type) */
18
+ interface Core_FlowCanvas {
19
+ id?: string;
20
+ type?: string;
21
+ data?: any;
22
+ [key: string]: any;
23
+ }
24
+ /** Tool execution phase (stub type) */
25
+ type Core_ToolExecutionPhase = 'pending' | 'executing' | 'completed' | 'error' | string;
26
+ /** Token update event (stub type) */
27
+ interface Core_TokenUpdate {
28
+ token?: string;
29
+ content?: string;
30
+ [key: string]: any;
31
+ }
32
+ /**
33
+ * Tool definition utilities for BotDojo
34
+ *
35
+ * Provides a simplified API for defining tools and model contexts
36
+ */
37
+ /**
38
+ * JSON Schema definition for tool parameters
39
+ */
40
+ interface JSONSchema {
41
+ type: 'object';
42
+ properties: Record<string, any>;
43
+ required?: string[];
44
+ additionalProperties?: boolean;
45
+ }
46
+ /**
47
+ * Zod-like schema interface (for type compatibility)
48
+ */
49
+ interface ZodSchema {
50
+ _def?: any;
51
+ parse: (data: any) => any;
9
52
  }
10
- declare class CallbackHandlerMethods {
11
- source: any;
12
- func: any;
53
+ /**
54
+ * SDK Tool definition - extends base with parameter schema options
55
+ *
56
+ * Display hints go in _meta with botdojo/ prefix:
57
+ * - 'botdojo/display-name': string
58
+ * - 'botdojo/hide-step': boolean
59
+ * - 'botdojo/hide-step-details': boolean
60
+ */
61
+ interface SDKToolDefinition<TParams = any, TResult = any> {
62
+ description: string;
63
+ parameters?: JSONSchema | ZodSchema;
64
+ execute: (params: TParams) => Promise<ToolExecutionResult<TResult>> | ToolExecutionResult<TResult>;
65
+ /** Tool metadata - use for display hints and resource templates */
66
+ _meta?: ToolMetadata;
13
67
  }
14
- declare class RPCMessage {
68
+ /**
69
+ * Tools record - a map of tool names to tool definitions
70
+ */
71
+ type ToolsRecord = Record<string, SDKToolDefinition>;
72
+ /**
73
+ * Tool handler function
74
+ */
75
+ type ToolHandler<TParams = any, TResult = any> = (params: TParams) => Promise<ToolExecutionResult<TResult>> | ToolExecutionResult<TResult>;
76
+ /**
77
+ * Create a tool definition
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const weatherTool = tool({
82
+ * description: 'Get the weather in a location',
83
+ * parameters: {
84
+ * type: 'object',
85
+ * properties: {
86
+ * location: { type: 'string', description: 'The location to get the weather for' }
87
+ * },
88
+ * required: ['location']
89
+ * },
90
+ * execute: async ({ location }) => ({
91
+ * location,
92
+ * temperature: 72
93
+ * })
94
+ * });
95
+ * ```
96
+ */
97
+ declare function tool<TParams = any, TResult = any>(definition: SDKToolDefinition<TParams, TResult>): SDKToolDefinition<TParams, TResult>;
98
+ /**
99
+ * Create a text result content item
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * return [textResult('Operation completed successfully')];
104
+ * ```
105
+ */
106
+ declare function textResult(text: string): ContentItem;
107
+ /**
108
+ * Create an image result content item
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * return [imageResult(base64Data, 'image/png')];
113
+ * ```
114
+ */
115
+ declare function imageResult(data: string, mimeType?: string): ContentItem;
116
+ /**
117
+ * Create a UI resource content item
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * return [
122
+ * textResult('Product loaded'),
123
+ * uiResource('ui://product/123', {
124
+ * initialData: { product: productData },
125
+ * frameSize: { width: '100%', height: '500px' }
126
+ * })
127
+ * ];
128
+ * ```
129
+ */
130
+ declare function uiResource(uri: string, options?: {
131
+ initialData?: any;
132
+ frameSize?: {
133
+ width: string;
134
+ height: string;
135
+ };
136
+ mimeType?: 'text/uri-list' | 'text/html' | 'text/html+mcp' | 'text/html;profile=mcp-app' | 'application/vnd.botdojo.ui-remote-dom';
137
+ /** Inline HTML content for MCP Apps */
138
+ html?: string;
139
+ /** Allowlist of URLs (url-list style) */
140
+ urlList?: string[];
141
+ /** Base URL applied to inline HTML for relative assets */
142
+ baseUrl?: string;
143
+ /** Force proxy/sandbox rendering even when a URL is present */
144
+ prefersProxy?: boolean;
145
+ /** Allow direct external URL rendering alongside inline HTML */
146
+ allowExternal?: boolean;
147
+ uiMeta?: {
148
+ csp?: {
149
+ connectDomains?: string[];
150
+ resourceDomains?: string[];
151
+ domain?: string;
152
+ allowPopups?: boolean;
153
+ allowForms?: boolean;
154
+ allowSameOrigin?: boolean;
155
+ };
156
+ prefersBorder?: boolean;
157
+ urlList?: string[];
158
+ baseUrl?: string;
159
+ prefersProxy?: boolean;
160
+ allowExternal?: boolean;
161
+ };
162
+ }): ContentItem;
163
+ /**
164
+ * Create a ModelContext resource content item
165
+ * The URI points to a resource handler that returns the ModelContext definition
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * return [
170
+ * textResult('Cart actions available'),
171
+ * mcpResource('mcp://cart/actions')
172
+ * ];
173
+ * ```
174
+ */
175
+ declare function mcpResource(uri: string): ContentItem;
176
+ /**
177
+ * Create a single citation content item
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * return [
182
+ * textResult('Found information about the topic'),
183
+ * citation({ id: 'cite-1', source: 'Wikipedia', url: 'https://...' })
184
+ * ];
185
+ * ```
186
+ */
187
+ declare function citation(data: CitationData): ContentItem;
188
+ /**
189
+ * Create multiple citations content item
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * return [
194
+ * textResult('Found multiple sources'),
195
+ * citations([
196
+ * { id: 'cite-1', source: 'Wikipedia', url: 'https://...' },
197
+ * { id: 'cite-2', source: 'Documentation', url: 'https://...' }
198
+ * ])
199
+ * ];
200
+ * ```
201
+ */
202
+ declare function citations(data: CitationData[]): ContentItem;
203
+ /**
204
+ * Model Context definition options
205
+ */
206
+ interface ModelContextDefinition {
207
+ name: string;
208
+ uri?: string;
209
+ description?: string;
210
+ toolPrefix?: string;
211
+ /**
212
+ * Tools for this model context. Must return ContentItem[] (MCP Apps).
213
+ * Legacy ToolResponse/actions are not supported.
214
+ */
215
+ tools?: ToolsRecord;
216
+ resources?: ResourceDefinition[];
217
+ }
218
+ /**
219
+ * Create a model context with tools and resources
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * import { modelContext, tool, buildResourceProvider } from '@botdojo/chat-embed';
224
+ *
225
+ * const myContext = modelContext({
226
+ * name: 'my_app',
227
+ * uri: 'myapp://mcp',
228
+ * description: 'My application tools',
229
+ * toolPrefix: 'app',
230
+ * tools: {
231
+ * setText: tool({
232
+ * description: 'Update text',
233
+ * parameters: {
234
+ * type: 'object',
235
+ * properties: {
236
+ * text: { type: 'string', description: 'The new text' }
237
+ * },
238
+ * required: ['text']
239
+ * },
240
+ * execute: async ({ text }) => {
241
+ * currentText = text;
242
+ * return toolResponse({
243
+ * result: { success: true },
244
+ * message: 'Text updated',
245
+ * actions: [actions.updateCanvas({ text })]
246
+ * });
247
+ * }
248
+ * }),
249
+ * getText: tool({
250
+ * description: 'Get current text',
251
+ * execute: async () => ({ text: currentText })
252
+ * })
253
+ * },
254
+ * resources: [
255
+ * {
256
+ * uri: 'myapp://help',
257
+ * mimeType: 'text/markdown',
258
+ * description: 'Help documentation',
259
+ * getContent: async () => '# Help\n\nMarkdown content'
260
+ * },
261
+ * {
262
+ * uriTemplate: 'myapp://users/{userId}',
263
+ * mimeType: 'application/json',
264
+ * description: 'User profile by ID',
265
+ * getContent: async ({ userId }) => {
266
+ * const user = await fetchUser(userId);
267
+ * return JSON.stringify(user);
268
+ * }
269
+ * }
270
+ * ]
271
+ * });
272
+ *
273
+ * // Use with BotDojoChat
274
+ * <BotDojoChat apiKey="..." modelContext={myContext} />
275
+ * ```
276
+ */
277
+ declare function modelContext(definition: ModelContextDefinition): ModelContext;
278
+ /**
279
+ * Resource utilities for building ResourceProviders
280
+ *
281
+ * These utilities help users define static and dynamic resources
282
+ * and automatically generate ResourceProvider implementations.
283
+ */
284
+ /**
285
+ * Resource content can be returned in multiple formats:
286
+ * - Simple string (text, markdown, JSON, base64)
287
+ * - URL reference { url: string } for external/large files
288
+ * - Rich object with text, url, mcp, links, and metadata
289
+ */
290
+ type ResourceContentResult = string | {
291
+ url: string;
292
+ } | ResourceContentObject;
293
+ /**
294
+ * Rich resource content object
295
+ */
296
+ interface ResourceContentObject {
297
+ /** Text content (markdown, JSON, base64, etc.) */
298
+ text?: string;
299
+ /** External URL reference (for hosted images, PDFs, etc.) */
300
+ url?: string;
301
+ /** Nested MCPs (for botdojo/mcp mimeType) */
302
+ mcp?: ModelContext[];
303
+ /** Related resource links */
304
+ links?: Array<{
305
+ uri: string;
306
+ rel: string;
307
+ description?: string;
308
+ }>;
309
+ /** Additional metadata */
310
+ meta?: Record<string, any>;
311
+ }
312
+ /**
313
+ * Static resource definition - fixed URI, no parameters
314
+ */
315
+ interface StaticResourceDefinition {
316
+ /** Fixed URI for this resource */
317
+ uri: string;
318
+ /** MIME type (e.g., 'text/markdown', 'image/png', 'botdojo/mcp') */
319
+ mimeType: string;
320
+ /** Human-readable description */
321
+ description?: string;
322
+ /** Display label */
323
+ label?: string;
324
+ /** Get resource content */
325
+ getContent: () => Promise<ResourceContentResult> | ResourceContentResult;
326
+ }
327
+ /**
328
+ * Dynamic resource definition - templated URI with parameters
329
+ */
330
+ interface DynamicResourceDefinition {
331
+ /** URI template following RFC 6570 (e.g., 'myapp://users/{userId}') */
332
+ uriTemplate: string;
333
+ /** MIME type */
334
+ mimeType: string;
335
+ /** Human-readable description */
336
+ description?: string;
337
+ /** Display label */
338
+ label?: string;
339
+ /** Get resource content with extracted parameters */
340
+ getContent: (params: Record<string, any>) => Promise<ResourceContentResult> | ResourceContentResult;
341
+ }
342
+ /**
343
+ * Resource definition - can be static or dynamic
344
+ */
345
+ type ResourceDefinition = StaticResourceDefinition | DynamicResourceDefinition;
346
+ /**
347
+ * Model Context Translation Snapshot
348
+ * AUTO-GENERATED by scripts/sync-model-context-translation.js
349
+ * DO NOT EDIT MANUALLY
350
+ *
351
+ * This file is a build-time copy of modelContextTranslation from botdojo-core
352
+ * It does NOT create a package dependency.
353
+ *
354
+ * Source: botdojo-core/src/utils/modelContextTranslation.ts
355
+ * To update: pnpm sync-model-context-translation
356
+ */
357
+ /**
358
+ * Model Context Translation Utilities
359
+ *
360
+ * Converts SDK ModelContext format (plain objects) to backend CanvasModelContext format.
361
+ * This is the single source of truth - sdk-types will sync this via prebuild script.
362
+ *
363
+ * Note: This function accepts `any` to avoid importing SDK types and creating circular dependencies.
364
+ * The synced version in sdk-types will wrap this with proper SDK types.
365
+ */
366
+ /**
367
+ * Backend format for model context (what the API expects via RPC)
368
+ * These types mirror the CanvasModelContext structure the backend expects when receiving model context.
369
+ */
370
+ interface BackendModelContext {
371
+ name: string;
372
+ description?: string;
373
+ toolPrefix?: string;
374
+ resourceUri?: string;
375
+ tools: BackendToolDef[];
376
+ prompts: BackendPromptDef[];
377
+ resources?: BackendResourceDef[];
378
+ }
379
+ interface BackendToolDef {
380
+ name: string;
381
+ description?: string;
382
+ displayName?: string;
383
+ arguments: any;
384
+ canvasTemplate?: any;
385
+ hideStep?: boolean;
386
+ hideStepDetails?: boolean;
387
+ _meta?: any;
388
+ }
389
+ interface BackendPromptDef {
390
+ name: string;
391
+ description?: string;
392
+ messages: Array<{
393
+ role: string;
394
+ content: string;
395
+ }>;
396
+ }
397
+ interface BackendResourceDef {
398
+ uri: string;
399
+ name?: string;
400
+ description?: string;
401
+ mimeType?: string;
402
+ }
403
+ /**
404
+ * Backend Types Snapshot
405
+ * AUTO-GENERATED by scripts/sync-backend-types.js
406
+ * DO NOT EDIT MANUALLY
407
+ *
408
+ * This file is a build-time snapshot of types from botdojo-sdk-backend-types
409
+ * for validation purposes. It does NOT create a package dependency.
410
+ *
411
+ * To update: pnpm sync-backend-types
412
+ * Generated: 2025-12-27T11:57:43.243Z
413
+ */
414
+ interface ResourceReference {
415
+ /** Resource URI (e.g., 'ui://product/123', 'mcp://actions') */
416
+ uri: string;
417
+ /** MIME type determines how resource is processed */
418
+ mimeType?: string;
419
+ /** Resource content (URL for uri-list, inline HTML for text/html(+mcp), or URI for modelcontext) */
420
+ text?: string;
421
+ /** Inline HTML for `text/html`, `text/html+mcp`, or `text/html;profile=mcp-app` resources */
422
+ html?: string;
423
+ /** Optional allowlist for URL-based resources (matches SEP url-list direction) */
424
+ urlList?: string[];
425
+ /** Base URL to apply to inline HTML (used for relative asset resolution) */
426
+ baseUrl?: string;
427
+ /** Hint to prefer sandbox proxy even when a URL exists */
428
+ prefersProxy?: boolean;
429
+ /** Hint to allow direct external URL rendering even when inline HTML is present */
430
+ allowExternal?: boolean;
431
+ /** Metadata for UI resources only */
432
+ meta?: {
433
+ /** SEP-1865 UI metadata */
434
+ ui?: {
435
+ /** Preferred iframe dimensions (object or tuple) */
436
+ preferredFrameSize?: {
437
+ width: string;
438
+ height: string;
439
+ } | [string, string];
440
+ /** Initial render data/state */
441
+ initialRenderData?: any;
442
+ /** Optional display name for the canvas */
443
+ displayName?: string;
444
+ /** If true, canvas should not be persisted */
445
+ stateless?: boolean;
446
+ /** MIME type hint for the UI resource */
447
+ mimeType?: string;
448
+ /** Optional CSP hints */
449
+ csp?: {
450
+ connectDomains?: string[];
451
+ resourceDomains?: string[];
452
+ domain?: string;
453
+ allowPopups?: boolean;
454
+ allowForms?: boolean;
455
+ allowSameOrigin?: boolean;
456
+ prefersBorder?: boolean;
457
+ };
458
+ /** Optional resource hints for inline/URL handling */
459
+ urlList?: string[];
460
+ baseUrl?: string;
461
+ prefersProxy?: boolean;
462
+ allowExternal?: boolean;
463
+ };
464
+ /** Additional metadata */
465
+ [key: string]: any;
466
+ };
467
+ }
468
+ /**
469
+ * MCP-compliant content item for tool results
470
+ *
471
+ * Tools should return ContentItem[] for rich responses, or plain objects for simple results.
472
+ *
473
+ * @example
474
+ * ```typescript
475
+ * // Simple text response
476
+ * return [{ type: 'text', text: 'Operation successful' }];
477
+ *
478
+ * // UI resource with initial data
479
+ * return [
480
+ * { type: 'text', text: 'Product loaded' },
481
+ * {
482
+ * type: 'resource',
483
+ * resource: {
484
+ * uri: 'ui://product/123',
485
+ * mimeType: 'text/uri-list',
486
+ * meta: { ui: { initialRenderData: { product } } }
487
+ * }
488
+ * }
489
+ * ];
490
+ * ```
491
+ */
492
+ interface ContentItem {
493
+ /** Content type: text, image, or resource */
494
+ type: 'text' | 'image' | 'resource';
495
+ /** Text content (for type: 'text') */
496
+ text?: string;
497
+ /** Base64-encoded image data (for type: 'image') */
498
+ data?: string;
499
+ /** MIME type for images (e.g., 'image/png') */
500
+ mimeType?: string;
501
+ /** Resource reference (for type: 'resource') */
502
+ resource?: ResourceReference;
503
+ }
504
+ /**
505
+ * Citation data for referencing sources
506
+ * Citations are BotDojo primitives, not UI resources
507
+ */
508
+ interface CitationData {
509
+ /** Required unique identifier */
15
510
  id: string;
511
+ /** Source name/title */
16
512
  source: string;
17
- destination: string;
18
- direction: "request" | "response";
19
- functionName: string;
20
- data: any;
21
- sendOnlyIfThereIsAListener?: boolean;
22
- host_id: string;
23
- /** Origin of the PostMessage (for CORS validation) */
24
- origin?: string;
25
- static request(source: string, destination: string, functionName: string, data: any): RPCMessage;
26
- static response(msg: RPCMessage, data: any): RPCMessage;
27
- constructor(source: string, destination: string, direction: "request" | "response", functionName: string, data: any);
28
- }
29
- interface IRPC_Client {
30
- clientId: string;
31
- defaultDestinationId: string;
32
- onMessage: (message: RPCMessage) => Promise<void>;
33
- onConnectionStatusChange?: (status: 'connected' | 'disconnected' | 'reconnecting' | 'reconnect_failed', reason?: string) => void;
34
- init(): Promise<void>;
35
- close(): Promise<void>;
36
- sendMessage(message: RPCMessage): Promise<any>;
37
- }
38
- declare class RPCConnection {
39
- sender: IRPC_Client;
40
- options: ConectionOptions;
41
- callbacks: Map<string, CallbackHandlerMethods>;
42
- onMessage: (msg: RPCMessage) => Promise<any>;
43
- constructor(sender: IRPC_Client, options: ConectionOptions, onMessage?: (msg: RPCMessage) => Promise<any>);
44
- log(msg: string, data?: any, data2?: any): void;
45
- init(): Promise<void>;
46
- close(): void;
47
- sendRequestToHost(functionName: string, data: Array<any> | any): Promise<any>;
48
- sendRequest(destinationId: string, functionName: string, data: Array<any> | any, timeoutMs?: number): Promise<any>;
49
- incommingMessage(msg: RPCMessage): void;
513
+ /** Optional URL */
514
+ url?: string;
515
+ /** Optional quote/excerpt */
516
+ text?: string;
517
+ /** Additional metadata */
518
+ [key: string]: any;
519
+ }
520
+ /**
521
+ * Tool execution result type
522
+ * Tools can return:
523
+ * - ContentItem[] for rich responses (UI, citations, etc.)
524
+ * - Plain object/primitive for simple results
525
+ */
526
+ type ToolExecutionResult<TResult = any> = ContentItem[] | TResult;
527
+ /**
528
+ * Standard MIME types for BotDojo resources
529
+ */
530
+ declare const MIME_TYPES: {
531
+ readonly URI_LIST: "text/uri-list";
532
+ readonly HTML: "text/html";
533
+ readonly HTML_MCP: "text/html+mcp";
534
+ readonly HTML_MCP_PROFILE: "text/html;profile=mcp-app";
535
+ readonly REMOTE_DOM: "application/vnd.mcp-ui.remote-dom";
536
+ readonly REMOTE_DOM_BOTDOJO: "application/vnd.botdojo.ui-remote-dom";
537
+ readonly MODEL_CONTEXT: "application/vnd.botdojo.modelcontext";
538
+ readonly CITATION: "application/vnd.botdojo.citation";
539
+ readonly CITATIONS: "application/vnd.botdojo.citations";
540
+ };
541
+ /**
542
+ * Context provided to tools during execution
543
+ * Includes methods for updating canvas state in real-time.
544
+ *
545
+ * MCP App canvases receive `hostContext.toolInfo` with the tool schema.
546
+ * Tool arguments/results come via ui/notifications/tool-input and tool-result.
547
+ * `hostContext.state` hydrates from UI state persistence (BotDojo extension);
548
+ * use `updateState` strictly for UI state (e.g., counters).
549
+ */
550
+ interface ToolExecutionContext {
551
+ /** Name of the tool being executed (helpful for logging/notifications) */
552
+ toolName?: string;
553
+ /**
554
+ * Update canvas UI state during tool execution (if resource-template is present).
555
+ * Do not mirror tool arguments/results here; the host caches that from
556
+ * `ui/notifications/tool-*`. Keep this for UI persistence only.
557
+ */
558
+ updateState?: (state: any) => Promise<void>;
559
+ /**
560
+ * Send MCP Apps tool notifications to the UI host (SEP-1865).
561
+ * Implementations should emit JSON-RPC notifications using context.toolName:
562
+ * - ui/notifications/tool-input-partial (streaming args)
563
+ * - ui/notifications/tool-input (final args)
564
+ * - ui/notifications/tool-result (result payload)
565
+ */
566
+ notifyToolInputPartial?: (args: Record<string, unknown>) => Promise<void>;
567
+ notifyToolInput?: (args: Record<string, unknown>) => Promise<void>;
568
+ notifyToolResult?: (result: any) => Promise<void>;
569
+ }
570
+ /**
571
+ * Tool metadata following MCP Apps SDK pattern
572
+ * Uses _meta with vendor-namespaced extensions (kebab-case)
573
+ *
574
+ * All BotDojo-specific options use 'botdojo/' prefix with kebab-case keys
575
+ */
576
+ interface ToolMetadata {
577
+ ui?: {
578
+ preferredFrameSize?: {
579
+ width: string;
580
+ height: string;
581
+ } | [string, string];
582
+ initialRenderData?: any;
583
+ displayName?: string;
584
+ stateless?: boolean;
585
+ /** Resource URI for pre-rendering during streaming */
586
+ resourceUri?: string;
587
+ mimeType?: 'text/html+mcp' | 'text/html;profile=mcp-app' | 'text/html' | 'text/uri-list';
588
+ showInline?: boolean;
589
+ agentEnabled?: boolean;
590
+ /** Optional render hints for inline/URL MCP Apps */
591
+ urlList?: string[];
592
+ baseUrl?: string;
593
+ prefersProxy?: boolean;
594
+ allowExternal?: boolean;
595
+ };
596
+ 'botdojo/resource-template'?: {
597
+ uri: string;
598
+ mimeType: string;
599
+ metadata?: {
600
+ ui?: {
601
+ preferredFrameSize?: {
602
+ width: string;
603
+ height: string;
604
+ } | [string, string];
605
+ initialRenderData?: any;
606
+ displayName?: string;
607
+ stateless?: boolean;
608
+ mimeType?: string;
609
+ };
610
+ [key: string]: any;
611
+ };
612
+ };
613
+ 'botdojo/display-name'?: string;
614
+ 'botdojo/hide-step'?: boolean;
615
+ 'botdojo/hide-step-details'?: boolean;
616
+ }
617
+ /**
618
+ * Tool definition for defining tools
619
+ * Can be used in two ways:
620
+ * 1. In an array: tools: ToolDefinition[] (needs 'name' field)
621
+ * 2. In an object: tools: Record<string, ToolDefinition> ('name' is the key, so field is optional)
622
+ *
623
+ * Display hints (displayName, hideStep, hideStepDetails) are in _meta with botdojo/ prefix
624
+ */
625
+ interface ToolDefinition<TParams = any, TResult = any> {
626
+ name?: string;
627
+ description: string;
628
+ /** JSON Schema for parameters (MCP standard) */
629
+ inputSchema?: any;
630
+ /** Tool metadata - display hints and resource templates */
631
+ _meta?: ToolMetadata;
632
+ /** Execute function - returns ContentItem[] or plain result */
633
+ /** Can accept optional ToolExecutionContext as second parameter for notifications */
634
+ execute?: (params: TParams, context?: ToolExecutionContext) => Promise<ToolExecutionResult<TResult>>;
635
+ }
636
+ interface ModelContextMessage {
637
+ role: string;
638
+ content: string;
639
+ }
640
+ interface ModelContextPrompt {
641
+ name: string;
642
+ description: string;
643
+ messages: ModelContextMessage[];
644
+ }
645
+ /**
646
+ * Resource template for dynamic resource discovery
647
+ * Compatible with IResourceProvider pattern in botdojo-core
648
+ */
649
+ interface ResourceTemplate {
650
+ /** URI template following RFC 6570 (e.g., "myapp://users/{userId}") */
651
+ uriTemplate: string;
652
+ /** Unique identifier for this template */
653
+ name: string;
654
+ /** Human-readable name */
655
+ label: string;
656
+ /** Description of this resource type */
657
+ description?: string;
658
+ /** MIME type for resources matching this template */
659
+ mimeType?: string;
660
+ /** Additional metadata */
661
+ meta?: {
662
+ title?: string;
663
+ description?: string;
664
+ icon?: string;
665
+ defaultToolPrefix?: string;
666
+ [key: string]: any;
667
+ };
668
+ }
669
+ /**
670
+ * Resource provider for dynamic resource discovery
671
+ * Compatible with Resource Manager MCP v2
672
+ */
673
+ interface ResourceProvider {
674
+ /** Unique provider ID */
675
+ id: string;
676
+ /** Resource templates this provider supports */
677
+ templates: ResourceTemplate[];
678
+ /**
679
+ * Get a resource by URI
680
+ * @param templateName The name of the template that matched
681
+ * @param uri The resource URI to fetch
682
+ * @param params Extracted template parameters
683
+ * @param onlyMetadata If true, only return metadata (no content)
684
+ */
685
+ getResource: (templateName: string, uri: string, params: any, onlyMetadata?: boolean) => Promise<ResourceContent>;
686
+ }
687
+ /**
688
+ * Resource content returned by a provider
689
+ */
690
+ interface ResourceContent {
691
+ uri: string;
692
+ mimeType?: string;
693
+ text?: string;
694
+ meta?: {
695
+ title?: string;
696
+ description?: string;
697
+ [key: string]: any;
698
+ };
699
+ links?: Array<{
700
+ uri: string;
701
+ rel: string;
702
+ description?: string;
703
+ }>;
704
+ /** If this resource is itself an MCP, include it here */
705
+ mcp?: ModelContext[];
706
+ }
707
+ /**
708
+ * Static resource with fixed URI
709
+ *
710
+ * @example
711
+ * ```typescript
712
+ * {
713
+ * uri: 'myapp://help',
714
+ * mimeType: 'text/markdown',
715
+ * getContent: async () => '# Help...'
716
+ * }
717
+ * ```
718
+ */
719
+ interface ModelContextStaticResource {
720
+ /** Fixed URI for this resource */
721
+ uri: string;
722
+ /** Resource name (optional - can be inferred from uri) */
723
+ name?: string;
724
+ /** Human-readable label */
725
+ label?: string;
726
+ /** MIME type of the resource */
727
+ mimeType?: string;
728
+ /** Description of the resource */
729
+ description?: string;
730
+ /** Additional metadata */
731
+ meta?: {
732
+ title?: string;
733
+ description?: string;
734
+ icon?: string;
735
+ [key: string]: any;
736
+ };
737
+ /** Get resource content (no parameters for static resources) */
738
+ getContent: () => Promise<string | {
739
+ url: string;
740
+ } | ResourceContent>;
741
+ }
742
+ /**
743
+ * Dynamic resource with parameterized URI template
744
+ *
745
+ * @example
746
+ * ```typescript
747
+ * {
748
+ * uriTemplate: 'myapp://file/{filepath}',
749
+ * mimeType: 'botdojo/mcp',
750
+ * getContent: async (params) => {
751
+ * // params.filepath is extracted from URI
752
+ * return { mcp: [...] }
753
+ * }
754
+ * }
755
+ * ```
756
+ */
757
+ interface ModelContextDynamicResource {
758
+ /** URI template with parameters - e.g., "myapp://users/{userId}" */
759
+ uriTemplate: string;
760
+ /** Resource name (optional - can be inferred from template) */
761
+ name?: string;
762
+ /** Human-readable label */
763
+ label?: string;
764
+ /** MIME type of the resource */
765
+ mimeType?: string;
766
+ /** Description of the resource */
767
+ description?: string;
768
+ /** Additional metadata */
769
+ meta?: {
770
+ title?: string;
771
+ description?: string;
772
+ icon?: string;
773
+ [key: string]: any;
774
+ };
775
+ /** Get resource content with extracted parameters */
776
+ getContent: (params: Record<string, any>) => Promise<string | {
777
+ url: string;
778
+ } | ResourceContent>;
50
779
  }
780
+ /**
781
+ * Model context resource - can be either static or dynamic
782
+ */
783
+ type ModelContextResource = ModelContextStaticResource | ModelContextDynamicResource;
784
+ /**
785
+ * MCP-level CORS configuration for tool call security
786
+ * Configured by developers when defining MCP backends
787
+ *
788
+ * IMPORTANT: Only validates parent/canvas → chat tool calls.
789
+ * Agent → parent/canvas tool calls use origin='server' and bypass validation.
790
+ */
791
+ interface ModelContextCorsConfig {
792
+ /**
793
+ * Origins allowed to call tools on this MCP backend
794
+ * Used by chat iframe router to validate tool call origins FROM parent/canvas
795
+ *
796
+ * Default: undefined = ALL origins allowed (permissive by default)
797
+ * Empty array [] = NO origins allowed (block all)
798
+ * 'server' = Reserved, always allowed (agent tool calls)
799
+ *
800
+ * Protocol enforcement: Must match exactly (https:// ≠ http://)
801
+ * Port enforcement: Must match exactly (:443 ≠ :80)
802
+ * Wildcard support: Prefix only, follows CORS spec (*.myshop.com matches any subdomain)
803
+ *
804
+ * Examples:
805
+ * - undefined → Allow all (backward compatible)
806
+ * - [] → Block all parent/canvas tool calls
807
+ * - ["https://myshop.com", "https://admin.myshop.com"] → Exact matches only
808
+ * - ["*.myshop.com"] → Allow any subdomain (app.myshop.com, admin.myshop.com)
809
+ * - ["https://myshop.com"] → Does NOT match http://myshop.com (protocol differs)
810
+ */
811
+ allowedToolCallOrigins?: string[];
812
+ }
813
+ /**
814
+ * Model context definition with tools, prompts, and resources
815
+ * Tools can be defined as either:
816
+ * - An array: tools: ToolDefinition[] (each tool needs 'name' field)
817
+ * - An object: tools: Record<string, ToolDefinition> (key is the tool name)
818
+ *
819
+ * Resources support both static and dynamic patterns:
820
+ * - Static: { uri: 'app://help', getContent: async () => '...' }
821
+ * - Dynamic: { uriTemplate: 'app://file/{id}', getContent: async (params) => '...' }
822
+ */
823
+ interface ModelContext {
824
+ name: string;
825
+ description?: string;
826
+ toolPrefix?: string;
827
+ /** Unique URI identifier for this model context */
828
+ uri?: string;
829
+ tools?: ToolDefinition[] | Record<string, ToolDefinition>;
830
+ prompts?: ModelContextPrompt[];
831
+ /** Unified resources array supporting both static and dynamic resources */
832
+ resources?: ModelContextResource[];
833
+ /**
834
+ * CORS configuration for this MCP
835
+ *
836
+ * **Backend Use**: Server enforces these rules before executing tools
837
+ * - allowedToolCallOrigins: Which parent/canvas origins can call tools from this MCP
838
+ *
839
+ * **Note**: For SDK usage (BotDojoChat/BotDojoConnector), use the
840
+ * constructor-level `cors` parameter with ToolCallCorsConfig instead.
841
+ * This field is primarily for backend per-MCP enforcement.
842
+ */
843
+ cors?: ModelContextCorsConfig;
844
+ }
845
+ /**
846
+ * SDK version of flow request step with clean terminology
847
+ * Maps to internal FlowRequestIntermediateStep but uses cleaner field names
848
+ */
849
+ interface FlowRequestStep {
850
+ stepId: string;
851
+ stepLabel: string;
852
+ stepStatus: 'complete' | 'error' | 'processing';
853
+ error?: string;
854
+ content: string;
855
+ startTime: Date;
856
+ canvas?: Core_FlowCanvas;
857
+ parentStepId?: string;
858
+ subSteps?: FlowRequestStep[];
859
+ stepToolName?: string;
860
+ stepToolArguments?: Record<string, any>;
861
+ stepToolResult?: any;
862
+ stepToolPhase?: Core_ToolExecutionPhase;
863
+ }
864
+ interface ChatMessage$1 {
865
+ id?: string;
866
+ role: 'user' | 'assistant' | 'system';
867
+ content: string;
868
+ timestamp?: Date | string;
869
+ attachments?: any[];
870
+ citations?: any[];
871
+ [key: string]: any;
872
+ }
873
+ interface FlowRequestRecord {
874
+ id: string;
875
+ flow_id: string;
876
+ account_id: string;
877
+ project_id: string;
878
+ status: 'pending' | 'running' | 'complete' | 'error';
879
+ input?: any;
880
+ output?: any;
881
+ error?: string;
882
+ job_id?: string;
883
+ created_at?: string;
884
+ updated_at?: string;
885
+ userMessage?: ChatMessage$1;
886
+ aiMessage?: ChatMessage$1;
887
+ [key: string]: any;
888
+ }
889
+ type FlowResponse = FlowRequestRecord;
51
890
 
52
891
  /**
53
892
  * Configuration class for handling flow request events
@@ -504,6 +1343,11 @@ interface BotDojoChatProps {
504
1343
  * Override the welcome message shown in the chat widget (supports markdown)
505
1344
  */
506
1345
  welcomeMessage?: string;
1346
+ /**
1347
+ * Optional cache key for MCP proxy URL caching.
1348
+ * If not provided, uses the MCP App ID.
1349
+ */
1350
+ cacheKey?: string;
507
1351
  /**
508
1352
  * Whether to auto-focus the chat input on load
509
1353
  * @default true for popup/side-panel modes, false for inline mode
@@ -1082,6 +1926,11 @@ interface BotDojoChatProviderProps {
1082
1926
  * @default false
1083
1927
  */
1084
1928
  debug?: boolean;
1929
+ /**
1930
+ * Optional cache key for MCP proxy URL caching.
1931
+ * If not provided, uses the MCP App ID.
1932
+ */
1933
+ cacheKey?: string;
1085
1934
  /**
1086
1935
  * Called when an MCP App requests to open a link (ui/open-link)
1087
1936
  * The host application should handle navigation - links are NOT automatically opened
@@ -1548,6 +2397,11 @@ type McpProxyUrlOptions = {
1548
2397
  flowId: string;
1549
2398
  resource: string;
1550
2399
  origin?: string;
2400
+ /**
2401
+ * If true, adds noCache=true query param to skip proxy caching.
2402
+ * Use during development when MCP App content changes frequently.
2403
+ */
2404
+ noCache?: boolean;
1551
2405
  };
1552
2406
  /**
1553
2407
  * Build a sandbox-friendly blob URL for MCP HTML content.
@@ -1559,7 +2413,7 @@ declare function createMcpHtmlProxy(options: McpHtmlProxyOptions): {
1559
2413
  };
1560
2414
  /**
1561
2415
  * Build the MCP HTML proxy URL served by the sdk-mcp-app-html-proxy app.
1562
- * Format: /{flowId}/?url=<encodeURIComponent(resource)>
2416
+ * Format: /{flowId}/?url=<encodeURIComponent(resource)>[&noCache=true]
1563
2417
  */
1564
2418
  declare function buildMcpProxyUrl(options: McpProxyUrlOptions): string;
1565
2419
  /**
@@ -1817,4 +2671,4 @@ declare function useBotDojoCanvas(): UseBotDojoCanvasReturn;
1817
2671
  /** @deprecated Use AppAction instead */
1818
2672
  type CanvasAction = AppAction;
1819
2673
 
1820
- export { type AppAction, type AppContextValue, type AppEvent, BotDojoCanvasFrame, type BotDojoCanvasFrameProps, BotDojoCanvasProvider, type BotDojoCanvasProviderProps, BotDojoChat, type BotDojoChatControl, type BotDojoChatDisplayMode, type BotDojoChatHook, type BotDojoChatProps, BotDojoChatProvider, type BotDojoChatProviderProps, BotDojoConnector$1 as BotDojoConnector, type CanvasAction, type CanvasActionOptions, type CanvasEvent, type CanvasMode, type ChatActionsHook, type ChatConfig, type ChatMessage, type ChatMessagesHook, type ChatStatus, type ChatStatusHook, DEFAULT_MCP_HOST_CAPABILITIES, type HeadlessAction, HeadlessChat, type HeadlessChatHandle, type HeadlessChatProps, type HeadlessChatState, type HeadlessEvent, type HeadlessMessageEvent, type HeadlessStatusEvent, type HeadlessStepEvent, type HeadlessTokenEvent, type IframeState, type McpAppData, McpAppHost, McpAppHostContext, type McpAppHostContextValue, type McpAppHostProps, McpAppHostProvider, type McpAppHostProviderProps, type McpHtmlProxyOptions, type McpProxyUrlOptions, MockCanvasProvider, type MockCanvasProviderProps, type PopupOptions, RequestEvents, type ResolvedUiCsp, type SidePanelOptions, type StepUpdate, type ToolInfo, type ToolNotification, type UiCspMeta, type UiSize, type UseBotDojoCanvasReturn, type UseMcpHostBridgeOptions, type UseMcpHostBridgeResult, buildMcpCacheKey, buildMcpProxyUrl, createMcpHtmlProxy, extractMcpAppData, extractUiCspFromResource, getContentKey, parseMaybeJson, processStepUpdate, resolveUiCsp, useBotDojoCanvas, useBotDojoChat, useChatActions, useChatMessages, useChatStatus, useMcpAppHost, useMcpAppHostRequired, useMcpHostBridge, validateToolParams };
2674
+ export { type AppAction, type AppContextValue, type AppEvent, type BackendModelContext, type BackendPromptDef, type BackendResourceDef, type BackendToolDef, BotDojoCanvasFrame, type BotDojoCanvasFrameProps, BotDojoCanvasProvider, type BotDojoCanvasProviderProps, BotDojoChat, type BotDojoChatControl, type BotDojoChatDisplayMode, type BotDojoChatHook, type BotDojoChatProps, BotDojoChatProvider, type BotDojoChatProviderProps, BotDojoConnector$1 as BotDojoConnector, type CanvasAction, type CanvasActionOptions, type CanvasEvent, type CanvasMode, type ChatActionsHook, type ChatConfig, type ChatMessage, type ChatMessagesHook, type ChatStatus, type ChatStatusHook, type CitationData, type ContentItem, DEFAULT_MCP_HOST_CAPABILITIES, type HeadlessAction, HeadlessChat, type HeadlessChatHandle, type HeadlessChatProps, type HeadlessChatState, type HeadlessEvent, type HeadlessMessageEvent, type HeadlessStatusEvent, type HeadlessStepEvent, type HeadlessTokenEvent, type IframeState, type JSONSchema, MIME_TYPES, type McpAppData, McpAppHost, McpAppHostContext, type McpAppHostContextValue, type McpAppHostProps, McpAppHostProvider, type McpAppHostProviderProps, type McpHtmlProxyOptions, type McpProxyUrlOptions, MockCanvasProvider, type MockCanvasProviderProps, type ModelContext, type ModelContextDefinition, type ModelContextMessage, type ModelContextPrompt, type ModelContextResource, type PopupOptions, RequestEvents, type ResolvedUiCsp, type ResourceContent, type ResourceContentObject, type ResourceContentResult, type ResourceProvider, type ResourceReference, type ResourceTemplate, type SDKToolDefinition, type SidePanelOptions, type StepUpdate, type ToolDefinition, type ToolExecutionContext, type ToolExecutionResult, type ToolHandler, type ToolInfo, type ToolMetadata, type ToolNotification, type ToolsRecord, type UiCspMeta, type UiSize, type UseBotDojoCanvasReturn, type UseMcpHostBridgeOptions, type UseMcpHostBridgeResult, type ZodSchema, buildMcpCacheKey, buildMcpProxyUrl, citation, citations, createMcpHtmlProxy, extractMcpAppData, extractUiCspFromResource, getContentKey, imageResult, mcpResource, modelContext, parseMaybeJson, processStepUpdate, resolveUiCsp, textResult, tool, uiResource, useBotDojoCanvas, useBotDojoChat, useChatActions, useChatMessages, useChatStatus, useMcpAppHost, useMcpAppHostRequired, useMcpHostBridge, validateToolParams };