@botdojo/chat-sdk 0.0.28 → 0.0.30
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 +898 -44
- package/lib/index.js +534 -887
- package/lib/index.js.map +1 -1
- package/lib/mcp-app-view/host.js.map +1 -1
- package/lib/mcp-app-view/index.js +1 -1
- package/lib/mcp-app-view/index.js.map +1 -1
- package/lib/mcp-app-view/react.js +52 -25
- package/lib/mcp-app-view/react.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -8,12 +8,6 @@ var require = (id) => {
|
|
|
8
8
|
if (id === 'react-dom') return __ReactDOM;
|
|
9
9
|
throw new Error('Dynamic require not supported: ' + id);
|
|
10
10
|
};
|
|
11
|
-
var __create = Object.create;
|
|
12
|
-
var __defProp = Object.defineProperty;
|
|
13
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
16
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
11
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
18
12
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
19
13
|
}) : x)(function(x) {
|
|
@@ -21,748 +15,344 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
21
15
|
return require.apply(this, arguments);
|
|
22
16
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
23
17
|
});
|
|
24
|
-
var __commonJS = (cb, mod) => function __require3() {
|
|
25
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
26
|
-
};
|
|
27
|
-
var __copyProps = (to, from, except, desc) => {
|
|
28
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
-
for (let key of __getOwnPropNames(from))
|
|
30
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
-
}
|
|
33
|
-
return to;
|
|
34
|
-
};
|
|
35
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
36
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
37
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
38
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
39
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
40
|
-
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
41
|
-
mod
|
|
42
|
-
));
|
|
43
18
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
resource.allowExternal = options.allowExternal;
|
|
81
|
-
}
|
|
82
|
-
if ((options == null ? void 0 : options.initialData) || (options == null ? void 0 : options.frameSize) || (options == null ? void 0 : options.uiMeta)) {
|
|
83
|
-
resource.meta = {
|
|
84
|
-
ui: {
|
|
85
|
-
...options.uiMeta || {},
|
|
86
|
-
...options.frameSize ? { preferredFrameSize: options.frameSize } : {},
|
|
87
|
-
...options.initialData ? { initialRenderData: options.initialData } : {}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
19
|
+
// src/generated/sdk-types-snapshot.ts
|
|
20
|
+
function tool(definition) {
|
|
21
|
+
return definition;
|
|
22
|
+
}
|
|
23
|
+
function textResult(text) {
|
|
24
|
+
return { type: "text", text };
|
|
25
|
+
}
|
|
26
|
+
function imageResult(data, mimeType = "image/png") {
|
|
27
|
+
return { type: "image", data, mimeType };
|
|
28
|
+
}
|
|
29
|
+
function uiResource(uri, options) {
|
|
30
|
+
const resource = {
|
|
31
|
+
uri,
|
|
32
|
+
mimeType: (options == null ? void 0 : options.mimeType) || (uri.startsWith("ui://") ? MIME_TYPES.HTML_MCP_PROFILE : MIME_TYPES.URI_LIST)
|
|
33
|
+
};
|
|
34
|
+
if (options == null ? void 0 : options.html) {
|
|
35
|
+
resource.html = options.html;
|
|
36
|
+
}
|
|
37
|
+
if (options == null ? void 0 : options.urlList) {
|
|
38
|
+
resource.urlList = options.urlList;
|
|
39
|
+
}
|
|
40
|
+
if (options == null ? void 0 : options.baseUrl) {
|
|
41
|
+
resource.baseUrl = options.baseUrl;
|
|
42
|
+
}
|
|
43
|
+
if ((options == null ? void 0 : options.prefersProxy) !== void 0) {
|
|
44
|
+
resource.prefersProxy = options.prefersProxy;
|
|
45
|
+
}
|
|
46
|
+
if ((options == null ? void 0 : options.allowExternal) !== void 0) {
|
|
47
|
+
resource.allowExternal = options.allowExternal;
|
|
48
|
+
}
|
|
49
|
+
if ((options == null ? void 0 : options.initialData) || (options == null ? void 0 : options.frameSize) || (options == null ? void 0 : options.uiMeta)) {
|
|
50
|
+
resource.meta = {
|
|
51
|
+
ui: {
|
|
52
|
+
...options.uiMeta || {},
|
|
53
|
+
...options.frameSize ? { preferredFrameSize: options.frameSize } : {},
|
|
54
|
+
...options.initialData ? { initialRenderData: options.initialData } : {}
|
|
90
55
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
exports.mcpResource = mcpResource2;
|
|
106
|
-
function citation2(data) {
|
|
107
|
-
return {
|
|
108
|
-
type: "resource",
|
|
109
|
-
resource: {
|
|
110
|
-
uri: `citation://${data.id}`,
|
|
111
|
-
mimeType: index_1.MIME_TYPES.CITATION,
|
|
112
|
-
text: JSON.stringify(data)
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
exports.citation = citation2;
|
|
117
|
-
function citations2(data) {
|
|
118
|
-
return {
|
|
119
|
-
type: "resource",
|
|
120
|
-
resource: {
|
|
121
|
-
uri: "citations://batch",
|
|
122
|
-
mimeType: index_1.MIME_TYPES.CITATIONS,
|
|
123
|
-
text: JSON.stringify(data)
|
|
124
|
-
}
|
|
125
|
-
};
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return { type: "resource", resource };
|
|
59
|
+
}
|
|
60
|
+
function mcpResource(uri) {
|
|
61
|
+
return {
|
|
62
|
+
type: "resource",
|
|
63
|
+
resource: {
|
|
64
|
+
uri,
|
|
65
|
+
mimeType: MIME_TYPES.MODEL_CONTEXT,
|
|
66
|
+
text: uri
|
|
67
|
+
// URI points to resource handler
|
|
126
68
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function citation(data) {
|
|
72
|
+
return {
|
|
73
|
+
type: "resource",
|
|
74
|
+
resource: {
|
|
75
|
+
uri: `citation://${data.id}`,
|
|
76
|
+
mimeType: MIME_TYPES.CITATION,
|
|
77
|
+
text: JSON.stringify(data)
|
|
130
78
|
}
|
|
131
|
-
|
|
132
|
-
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function citations(data) {
|
|
82
|
+
return {
|
|
83
|
+
type: "resource",
|
|
84
|
+
resource: {
|
|
85
|
+
uri: "citations://batch",
|
|
86
|
+
mimeType: MIME_TYPES.CITATIONS,
|
|
87
|
+
text: JSON.stringify(data)
|
|
133
88
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const baseTool = {
|
|
152
|
-
name: toolName,
|
|
153
|
-
description: toolDef.description,
|
|
154
|
-
inputSchema: jsonSchema,
|
|
155
|
-
execute: toolDef.execute
|
|
156
|
-
};
|
|
157
|
-
if (toolDef._meta) {
|
|
158
|
-
baseTool._meta = toolDef._meta;
|
|
159
|
-
}
|
|
160
|
-
modelTools.push(baseTool);
|
|
161
|
-
}
|
|
162
|
-
const context = {
|
|
163
|
-
name: contextName,
|
|
164
|
-
description: (options == null ? void 0 : options.description) || `Tools for ${contextName}`,
|
|
165
|
-
toolPrefix: options == null ? void 0 : options.toolPrefix,
|
|
166
|
-
uri: (options == null ? void 0 : options.uri) || `app://${contextName}`,
|
|
167
|
-
tools: modelTools,
|
|
168
|
-
prompts: []
|
|
169
|
-
};
|
|
170
|
-
return context;
|
|
171
|
-
}
|
|
172
|
-
exports.toolsToModelContext = toolsToModelContext;
|
|
173
|
-
function extractToolHandlers(tools) {
|
|
174
|
-
const handlers = {};
|
|
175
|
-
if (Array.isArray(tools)) {
|
|
176
|
-
for (const tool3 of tools) {
|
|
177
|
-
if (tool3.execute && tool3.name) {
|
|
178
|
-
handlers[tool3.name] = tool3.execute;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
} else {
|
|
182
|
-
for (const [toolName, toolDef] of Object.entries(tools)) {
|
|
183
|
-
if (toolDef.execute) {
|
|
184
|
-
handlers[toolName] = toolDef.execute;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return handlers;
|
|
189
|
-
}
|
|
190
|
-
exports.extractToolHandlers = extractToolHandlers;
|
|
191
|
-
function modelContext2(definition) {
|
|
192
|
-
const { name, uri, description, toolPrefix, tools, resources } = definition;
|
|
193
|
-
let context;
|
|
194
|
-
if (tools && Object.keys(tools).length > 0) {
|
|
195
|
-
context = toolsToModelContext(name, tools, {
|
|
196
|
-
description,
|
|
197
|
-
toolPrefix,
|
|
198
|
-
uri
|
|
199
|
-
});
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function isZodSchema(schema) {
|
|
92
|
+
return schema && typeof schema.parse === "function";
|
|
93
|
+
}
|
|
94
|
+
function zodToJsonSchema(zodSchema) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
"Zod schemas are not supported in botdojo-sdk-types to keep it dependency-free. Please use JSON Schema directly, or convert your Zod schema using zod-to-json-schema in your own code."
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
function toolsToModelContext(contextName, tools, options) {
|
|
100
|
+
const modelTools = [];
|
|
101
|
+
for (const [toolName, toolDef] of Object.entries(tools)) {
|
|
102
|
+
let jsonSchema;
|
|
103
|
+
if (toolDef.parameters) {
|
|
104
|
+
if (isZodSchema(toolDef.parameters)) {
|
|
105
|
+
jsonSchema = zodToJsonSchema(toolDef.parameters);
|
|
200
106
|
} else {
|
|
201
|
-
|
|
202
|
-
name,
|
|
203
|
-
description: description || `Model context for ${name}`,
|
|
204
|
-
toolPrefix,
|
|
205
|
-
uri,
|
|
206
|
-
tools: [],
|
|
207
|
-
prompts: []
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
return context;
|
|
211
|
-
}
|
|
212
|
-
exports.modelContext = modelContext2;
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
// ../../packages/sdk-types/lib/toolResponseMapper.js
|
|
217
|
-
var require_toolResponseMapper = __commonJS({
|
|
218
|
-
"../../packages/sdk-types/lib/toolResponseMapper.js"(exports) {
|
|
219
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
220
|
-
exports.mapToolResponseToBackend = void 0;
|
|
221
|
-
function isResourceContent(item) {
|
|
222
|
-
return item.type === "resource" && !!item.resource;
|
|
223
|
-
}
|
|
224
|
-
function toCanvasFromResource(resource) {
|
|
225
|
-
var _a;
|
|
226
|
-
const mime = resource.mimeType || "text/uri-list";
|
|
227
|
-
const isMcp = mime === "text/uri-list" || mime === "text/html" || mime === "text/html+mcp" || mime === "text/html;profile=mcp-app";
|
|
228
|
-
if (!isMcp)
|
|
229
|
-
return void 0;
|
|
230
|
-
const meta = resource.meta || {};
|
|
231
|
-
const uiMeta = meta.ui || {};
|
|
232
|
-
const frame = uiMeta.preferredFrameSize || {};
|
|
233
|
-
const initialRenderData = uiMeta.initialRenderData;
|
|
234
|
-
const stateless = uiMeta.stateless;
|
|
235
|
-
const canvasData = {
|
|
236
|
-
url: resource.text || resource.uri,
|
|
237
|
-
mimeType: mime,
|
|
238
|
-
show_inline: (_a = uiMeta.showInline) != null ? _a : true,
|
|
239
|
-
agent_enabled: true,
|
|
240
|
-
width: (frame == null ? void 0 : frame[0]) || (frame == null ? void 0 : frame.width),
|
|
241
|
-
height: (frame == null ? void 0 : frame[1]) || (frame == null ? void 0 : frame.height),
|
|
242
|
-
...initialRenderData && { initialData: initialRenderData },
|
|
243
|
-
...uiMeta.displayName && { displayName: uiMeta.displayName },
|
|
244
|
-
...stateless !== void 0 && { stateless },
|
|
245
|
-
metadata: resource.meta
|
|
246
|
-
};
|
|
247
|
-
return {
|
|
248
|
-
canvasType: "mcp-app",
|
|
249
|
-
canvasData
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
function processContentItems(items) {
|
|
253
|
-
const outputFromToolObject = items;
|
|
254
|
-
const outputFromTool = JSON.stringify(items, null, 2);
|
|
255
|
-
let canvas;
|
|
256
|
-
for (const item of items) {
|
|
257
|
-
if (isResourceContent(item)) {
|
|
258
|
-
const maybe = toCanvasFromResource(item.resource);
|
|
259
|
-
if (maybe) {
|
|
260
|
-
canvas = maybe;
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
107
|
+
jsonSchema = toolDef.parameters;
|
|
264
108
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
async function mapToolResponseToBackend2(response) {
|
|
272
|
-
if (Array.isArray(response)) {
|
|
273
|
-
return processContentItems(response);
|
|
274
|
-
}
|
|
275
|
-
return {
|
|
276
|
-
outputFromTool: response === void 0 ? "" : JSON.stringify(response, null, 2),
|
|
277
|
-
outputFromToolObject: response
|
|
109
|
+
} else {
|
|
110
|
+
jsonSchema = {
|
|
111
|
+
type: "object",
|
|
112
|
+
properties: {},
|
|
113
|
+
required: []
|
|
278
114
|
};
|
|
279
115
|
}
|
|
280
|
-
|
|
116
|
+
const baseTool = {
|
|
117
|
+
name: toolName,
|
|
118
|
+
description: toolDef.description,
|
|
119
|
+
inputSchema: jsonSchema,
|
|
120
|
+
execute: toolDef.execute
|
|
121
|
+
};
|
|
122
|
+
if (toolDef._meta) {
|
|
123
|
+
baseTool._meta = toolDef._meta;
|
|
124
|
+
}
|
|
125
|
+
modelTools.push(baseTool);
|
|
126
|
+
}
|
|
127
|
+
const context = {
|
|
128
|
+
name: contextName,
|
|
129
|
+
description: (options == null ? void 0 : options.description) || `Tools for ${contextName}`,
|
|
130
|
+
toolPrefix: options == null ? void 0 : options.toolPrefix,
|
|
131
|
+
uri: (options == null ? void 0 : options.uri) || `app://${contextName}`,
|
|
132
|
+
tools: modelTools,
|
|
133
|
+
prompts: []
|
|
134
|
+
};
|
|
135
|
+
return context;
|
|
136
|
+
}
|
|
137
|
+
function modelContext(definition) {
|
|
138
|
+
const { name, uri, description, toolPrefix, tools, resources } = definition;
|
|
139
|
+
let context;
|
|
140
|
+
if (tools && Object.keys(tools).length > 0) {
|
|
141
|
+
context = toolsToModelContext(name, tools, {
|
|
142
|
+
description,
|
|
143
|
+
toolPrefix,
|
|
144
|
+
uri
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
context = {
|
|
148
|
+
name,
|
|
149
|
+
description: description || `Model context for ${name}`,
|
|
150
|
+
toolPrefix,
|
|
151
|
+
uri,
|
|
152
|
+
tools: [],
|
|
153
|
+
prompts: []
|
|
154
|
+
};
|
|
281
155
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const templatePart = templateParts[i];
|
|
305
|
-
if (templatePart.startsWith("{") && templatePart.endsWith("}")) {
|
|
306
|
-
const paramName = templatePart.slice(1, -1);
|
|
307
|
-
params[paramName] = uriParts[i];
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return params;
|
|
311
|
-
}
|
|
312
|
-
exports.extractUriParams = extractUriParams;
|
|
313
|
-
function normalizeResourceContent(uri, mimeType, result) {
|
|
314
|
-
if (typeof result === "string") {
|
|
315
|
-
return {
|
|
316
|
-
uri,
|
|
317
|
-
mimeType,
|
|
318
|
-
text: result
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
if ("url" in result && !("text" in result) && !("mcp" in result)) {
|
|
322
|
-
return {
|
|
323
|
-
uri,
|
|
324
|
-
mimeType,
|
|
325
|
-
text: JSON.stringify({ url: result.url })
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
return {
|
|
329
|
-
uri,
|
|
330
|
-
mimeType,
|
|
331
|
-
...result
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
function buildResourceProvider(providerId, resources) {
|
|
335
|
-
const templates = resources.map((resource) => {
|
|
336
|
-
if (isDynamicResource2(resource)) {
|
|
337
|
-
return {
|
|
338
|
-
uriTemplate: resource.uriTemplate,
|
|
339
|
-
name: resource.label || resource.uriTemplate,
|
|
340
|
-
label: resource.label || resource.uriTemplate,
|
|
341
|
-
description: resource.description,
|
|
342
|
-
mimeType: resource.mimeType
|
|
343
|
-
};
|
|
344
|
-
} else {
|
|
345
|
-
return {
|
|
346
|
-
uriTemplate: resource.uri,
|
|
347
|
-
name: resource.label || resource.uri,
|
|
348
|
-
label: resource.label || resource.uri,
|
|
349
|
-
description: resource.description,
|
|
350
|
-
mimeType: resource.mimeType
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
const getResource = async (templateName, uri, params, onlyMetadata) => {
|
|
355
|
-
for (const resource of resources) {
|
|
356
|
-
const template = isDynamicResource2(resource) ? resource.uriTemplate : resource.uri;
|
|
357
|
-
if (matchesUriTemplate(uri, template)) {
|
|
358
|
-
if (onlyMetadata) {
|
|
359
|
-
return {
|
|
360
|
-
uri,
|
|
361
|
-
mimeType: resource.mimeType,
|
|
362
|
-
meta: {
|
|
363
|
-
description: resource.description,
|
|
364
|
-
label: resource.label
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
let result;
|
|
369
|
-
if (isDynamicResource2(resource)) {
|
|
370
|
-
const extractedParams = params || extractUriParams(uri, resource.uriTemplate);
|
|
371
|
-
result = await resource.getContent(extractedParams);
|
|
372
|
-
} else {
|
|
373
|
-
result = await resource.getContent();
|
|
374
|
-
}
|
|
375
|
-
return normalizeResourceContent(uri, resource.mimeType, result);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
throw new Error(`No resource definition found for URI: ${uri}`);
|
|
379
|
-
};
|
|
380
|
-
return {
|
|
381
|
-
id: providerId,
|
|
382
|
-
templates,
|
|
383
|
-
getResource
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
exports.buildResourceProvider = buildResourceProvider;
|
|
156
|
+
return context;
|
|
157
|
+
}
|
|
158
|
+
function isDynamicResource(resource) {
|
|
159
|
+
return "uriTemplate" in resource;
|
|
160
|
+
}
|
|
161
|
+
function translateModelContextToBackend(context) {
|
|
162
|
+
const tools = translateToolsToBackend(context.tools || []);
|
|
163
|
+
const prompts = translatePromptsToBackend(context.prompts || []);
|
|
164
|
+
const resources = translateResourcesToBackend(context);
|
|
165
|
+
return {
|
|
166
|
+
name: context.name,
|
|
167
|
+
description: context.description,
|
|
168
|
+
toolPrefix: context.toolPrefix,
|
|
169
|
+
resourceUri: context.uri,
|
|
170
|
+
tools,
|
|
171
|
+
prompts,
|
|
172
|
+
resources
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function convertUiResourceTemplateToCanvasTemplate(resourceTemplate) {
|
|
176
|
+
if (!resourceTemplate || !resourceTemplate.uri) {
|
|
177
|
+
return void 0;
|
|
387
178
|
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
179
|
+
const metadata = resourceTemplate.metadata || {};
|
|
180
|
+
const uiMeta = metadata.ui || {};
|
|
181
|
+
const frameSize = uiMeta.preferredFrameSize || {};
|
|
182
|
+
const width = Array.isArray(frameSize) ? frameSize[0] : frameSize.width || "100%";
|
|
183
|
+
const height = Array.isArray(frameSize) ? frameSize[1] : frameSize.height || "520px";
|
|
184
|
+
const initialRenderData = uiMeta.initialRenderData || {};
|
|
185
|
+
const displayName = uiMeta.displayName;
|
|
186
|
+
const stateless = uiMeta.stateless === true;
|
|
187
|
+
const mimeType = resourceTemplate.mimeType;
|
|
188
|
+
const html = uiMeta.html;
|
|
189
|
+
const prefersProxy = uiMeta.prefersProxy;
|
|
190
|
+
const allowExternal = uiMeta.allowExternal;
|
|
191
|
+
const baseUrl = uiMeta.baseUrl;
|
|
192
|
+
const urlList = uiMeta.urlList;
|
|
193
|
+
return {
|
|
194
|
+
type: "mcp-app",
|
|
195
|
+
width,
|
|
196
|
+
height,
|
|
197
|
+
stateless,
|
|
198
|
+
initialData: {
|
|
199
|
+
url: resourceTemplate.uri,
|
|
200
|
+
show_inline: true,
|
|
201
|
+
agent_enabled: true,
|
|
202
|
+
...mimeType && { mimeType },
|
|
203
|
+
...html && { html, inlineHtml: true },
|
|
204
|
+
...prefersProxy !== void 0 && { prefersProxy },
|
|
205
|
+
...allowExternal !== void 0 && { allowExternal },
|
|
206
|
+
...baseUrl && { baseUrl },
|
|
207
|
+
...urlList && { urlList },
|
|
208
|
+
...initialRenderData,
|
|
209
|
+
...displayName && { displayName },
|
|
210
|
+
metadata
|
|
408
211
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
const displayName = uiMeta.displayName;
|
|
421
|
-
const stateless = uiMeta.stateless === true;
|
|
422
|
-
const mimeType = resourceTemplate.mimeType;
|
|
423
|
-
const html = uiMeta.html;
|
|
424
|
-
const prefersProxy = uiMeta.prefersProxy;
|
|
425
|
-
const allowExternal = uiMeta.allowExternal;
|
|
426
|
-
const baseUrl = uiMeta.baseUrl;
|
|
427
|
-
const urlList = uiMeta.urlList;
|
|
428
|
-
return {
|
|
429
|
-
type: "mcp-app",
|
|
430
|
-
width,
|
|
431
|
-
height,
|
|
432
|
-
stateless,
|
|
433
|
-
initialData: {
|
|
434
|
-
url: resourceTemplate.uri,
|
|
435
|
-
show_inline: true,
|
|
436
|
-
agent_enabled: true,
|
|
437
|
-
...mimeType && { mimeType },
|
|
438
|
-
...html && { html, inlineHtml: true },
|
|
439
|
-
...prefersProxy !== void 0 && { prefersProxy },
|
|
440
|
-
...allowExternal !== void 0 && { allowExternal },
|
|
441
|
-
...baseUrl && { baseUrl },
|
|
442
|
-
...urlList && { urlList },
|
|
443
|
-
...initialRenderData,
|
|
444
|
-
...displayName && { displayName },
|
|
445
|
-
metadata
|
|
446
|
-
}
|
|
447
|
-
};
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function translateToolsToBackend(tools) {
|
|
215
|
+
const toolsArray = Array.isArray(tools) ? tools : Object.entries(tools || {}).map(([name, tool2]) => ({ ...tool2, name }));
|
|
216
|
+
return toolsArray.map((tool2) => {
|
|
217
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
218
|
+
let canvasTemplate = tool2.canvasTemplate || ((_a = tool2._meta) == null ? void 0 : _a["botdojo/canvas"]);
|
|
219
|
+
if (!canvasTemplate && ((_b = tool2._meta) == null ? void 0 : _b["botdojo/resource-template"])) {
|
|
220
|
+
canvasTemplate = convertUiResourceTemplateToCanvasTemplate(
|
|
221
|
+
tool2._meta["botdojo/resource-template"]
|
|
222
|
+
);
|
|
448
223
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
if (!canvasTemplate && ((_d = (_c = tool2._meta) == null ? void 0 : _c.ui) == null ? void 0 : _d.resourceUri)) {
|
|
458
|
-
canvasTemplate = convertUiResourceTemplateToCanvasTemplate({
|
|
459
|
-
uri: tool2._meta.ui.resourceUri,
|
|
460
|
-
mimeType: tool2._meta.ui.mimeType || "text/html;profile=mcp-app",
|
|
461
|
-
metadata: { ui: tool2._meta.ui }
|
|
462
|
-
});
|
|
224
|
+
if (!canvasTemplate && ((_d = (_c = tool2._meta) == null ? void 0 : _c.ui) == null ? void 0 : _d.resourceUri)) {
|
|
225
|
+
canvasTemplate = convertUiResourceTemplateToCanvasTemplate({
|
|
226
|
+
uri: tool2._meta.ui.resourceUri,
|
|
227
|
+
mimeType: tool2._meta.ui.mimeType || "text/html;profile=mcp-app",
|
|
228
|
+
metadata: {
|
|
229
|
+
ui: tool2._meta.ui,
|
|
230
|
+
...((_e = tool2._meta) == null ? void 0 : _e["botdojo/no-cache"]) === true ? { "botdojo/no-cache": true } : {}
|
|
463
231
|
}
|
|
464
|
-
return {
|
|
465
|
-
name: tool2.name,
|
|
466
|
-
description: tool2.description,
|
|
467
|
-
displayName: tool2.displayName || ((_e = tool2._meta) == null ? void 0 : _e["botdojo/display-name"]) || ((_g = (_f = tool2._meta) == null ? void 0 : _f.ui) == null ? void 0 : _g.displayName) || tool2.name,
|
|
468
|
-
// Convert SDK's inputSchema (MCP standard) to backend's arguments field
|
|
469
|
-
// Keep fallback for legacy: arguments > parameters > inputSchema
|
|
470
|
-
arguments: tool2.arguments || tool2.parameters || tool2.inputSchema,
|
|
471
|
-
canvasTemplate,
|
|
472
|
-
hideStep: (_i = (_h = tool2._meta) == null ? void 0 : _h["botdojo/hide-step"]) != null ? _i : false,
|
|
473
|
-
hideStepDetails: (_k = (_j = tool2._meta) == null ? void 0 : _j["botdojo/hide-step-details"]) != null ? _k : false,
|
|
474
|
-
// Preserve _meta for additional metadata (e.g., streaming-preview, execute function)
|
|
475
|
-
_meta: tool2._meta
|
|
476
|
-
};
|
|
477
232
|
});
|
|
478
233
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
return (prompts || []).map((p) => ({
|
|
482
|
-
name: p.name,
|
|
483
|
-
description: p.description,
|
|
484
|
-
messages: (p.messages || []).map((m) => ({
|
|
485
|
-
role: m.role,
|
|
486
|
-
content: m.content
|
|
487
|
-
}))
|
|
488
|
-
}));
|
|
489
|
-
}
|
|
490
|
-
exports.translatePromptsToBackend = translatePromptsToBackend;
|
|
491
|
-
function translateResourcesToBackend(context) {
|
|
492
|
-
const resources = [];
|
|
493
|
-
if (context.resources) {
|
|
494
|
-
resources.push(...(context.resources || []).map((r) => {
|
|
495
|
-
const uri = "uriTemplate" in r ? r.uriTemplate : r.uri;
|
|
496
|
-
return {
|
|
497
|
-
uri,
|
|
498
|
-
name: r.name,
|
|
499
|
-
description: r.description,
|
|
500
|
-
mimeType: r.mimeType
|
|
501
|
-
};
|
|
502
|
-
}));
|
|
503
|
-
}
|
|
504
|
-
return resources;
|
|
505
|
-
}
|
|
506
|
-
exports.translateResourcesToBackend = translateResourcesToBackend;
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
// ../../packages/sdk-types/lib/type-translation.js
|
|
511
|
-
var require_type_translation = __commonJS({
|
|
512
|
-
"../../packages/sdk-types/lib/type-translation.js"(exports) {
|
|
513
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
514
|
-
exports.translateResourcesToBackend = exports.translatePromptsToBackend = exports.translateToolsToBackend = exports.translateModelContextToBackend = void 0;
|
|
515
|
-
var modelContextTranslation_snapshot_1 = require_modelContextTranslation_snapshot();
|
|
516
|
-
function translateModelContextToBackend3(context) {
|
|
517
|
-
return (0, modelContextTranslation_snapshot_1.translateModelContextToBackend)(context);
|
|
518
|
-
}
|
|
519
|
-
exports.translateModelContextToBackend = translateModelContextToBackend3;
|
|
520
|
-
function translateToolsToBackend(tools) {
|
|
521
|
-
return (0, modelContextTranslation_snapshot_1.translateToolsToBackend)(tools);
|
|
234
|
+
if (((_f = canvasTemplate == null ? void 0 : canvasTemplate.initialData) == null ? void 0 : _f.metadata) && ((_g = tool2._meta) == null ? void 0 : _g["botdojo/no-cache"]) === true) {
|
|
235
|
+
canvasTemplate.initialData.metadata["botdojo/no-cache"] = true;
|
|
522
236
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
if (!sdkStep.stepToolResult && internalStep.toolPhase === "complete" && internalStep.content) {
|
|
557
|
-
const content = internalStep.content;
|
|
558
|
-
if (content.trim().startsWith("{") || content.trim().startsWith("[")) {
|
|
559
|
-
try {
|
|
560
|
-
sdkStep.stepToolResult = JSON.parse(content);
|
|
561
|
-
} catch {
|
|
562
|
-
sdkStep.stepToolResult = content;
|
|
563
|
-
}
|
|
564
|
-
} else {
|
|
565
|
-
sdkStep.stepToolResult = content;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
if (internalStep.toolPhase) {
|
|
569
|
-
sdkStep.stepToolPhase = internalStep.toolPhase;
|
|
570
|
-
}
|
|
571
|
-
return sdkStep;
|
|
572
|
-
}
|
|
573
|
-
exports.toSDKStep = toSDKStep;
|
|
574
|
-
function toInternalStep(sdkStep) {
|
|
575
|
-
var _a;
|
|
576
|
-
const internalStep = {
|
|
577
|
-
...sdkStep,
|
|
578
|
-
subIntermediateSteps: (_a = sdkStep.subSteps) == null ? void 0 : _a.map(toInternalStep)
|
|
579
|
-
};
|
|
580
|
-
delete internalStep.subSteps;
|
|
581
|
-
return internalStep;
|
|
582
|
-
}
|
|
583
|
-
exports.toInternalStep = toInternalStep;
|
|
584
|
-
function toInternalCallbacks(sdkCallbacks) {
|
|
585
|
-
if (!sdkCallbacks)
|
|
586
|
-
return void 0;
|
|
237
|
+
return {
|
|
238
|
+
name: tool2.name,
|
|
239
|
+
description: tool2.description,
|
|
240
|
+
displayName: tool2.displayName || ((_h = tool2._meta) == null ? void 0 : _h["botdojo/display-name"]) || ((_j = (_i = tool2._meta) == null ? void 0 : _i.ui) == null ? void 0 : _j.displayName) || tool2.name,
|
|
241
|
+
// Convert SDK's inputSchema (MCP standard) to backend's arguments field
|
|
242
|
+
// Keep fallback for legacy: arguments > parameters > inputSchema
|
|
243
|
+
arguments: tool2.arguments || tool2.parameters || tool2.inputSchema,
|
|
244
|
+
canvasTemplate,
|
|
245
|
+
hideStep: (_l = (_k = tool2._meta) == null ? void 0 : _k["botdojo/hide-step"]) != null ? _l : false,
|
|
246
|
+
hideStepDetails: (_n = (_m = tool2._meta) == null ? void 0 : _m["botdojo/hide-step-details"]) != null ? _n : false,
|
|
247
|
+
// Preserve _meta for additional metadata (e.g., streaming-preview, execute function)
|
|
248
|
+
_meta: tool2._meta
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
function translatePromptsToBackend(prompts) {
|
|
253
|
+
return (prompts || []).map((p) => ({
|
|
254
|
+
name: p.name,
|
|
255
|
+
description: p.description,
|
|
256
|
+
messages: (p.messages || []).map((m) => ({
|
|
257
|
+
role: m.role,
|
|
258
|
+
content: m.content
|
|
259
|
+
}))
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
function translateResourcesToBackend(context) {
|
|
263
|
+
const resources = [];
|
|
264
|
+
if (context.resources) {
|
|
265
|
+
resources.push(...(context.resources || []).map((r) => {
|
|
266
|
+
const uri = "uriTemplate" in r ? r.uriTemplate : r.uri;
|
|
587
267
|
return {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
} : void 0
|
|
593
|
-
// Note: Other SDK callbacks (onFlowRequestStart, onNewToken, etc.) are not currently mapped
|
|
594
|
-
// as they have incompatible signatures with internal callbacks
|
|
268
|
+
uri,
|
|
269
|
+
name: r.name,
|
|
270
|
+
description: r.description,
|
|
271
|
+
mimeType: r.mimeType
|
|
595
272
|
};
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
return resources;
|
|
276
|
+
}
|
|
277
|
+
function isResourceContent(item) {
|
|
278
|
+
return item.type === "resource" && !!item.resource;
|
|
279
|
+
}
|
|
280
|
+
function toCanvasFromResource(resource) {
|
|
281
|
+
var _a;
|
|
282
|
+
const mime = resource.mimeType || "text/uri-list";
|
|
283
|
+
const isMcp = mime === "text/uri-list" || mime === "text/html" || mime === "text/html+mcp" || mime === "text/html;profile=mcp-app";
|
|
284
|
+
if (!isMcp)
|
|
285
|
+
return void 0;
|
|
286
|
+
const meta = resource.meta || {};
|
|
287
|
+
const uiMeta = meta.ui || {};
|
|
288
|
+
const frame = uiMeta.preferredFrameSize || {};
|
|
289
|
+
const initialRenderData = uiMeta.initialRenderData;
|
|
290
|
+
const stateless = uiMeta.stateless;
|
|
291
|
+
const canvasData = {
|
|
292
|
+
url: resource.text || resource.uri,
|
|
293
|
+
mimeType: mime,
|
|
294
|
+
show_inline: (_a = uiMeta.showInline) != null ? _a : true,
|
|
295
|
+
agent_enabled: true,
|
|
296
|
+
width: (frame == null ? void 0 : frame[0]) || (frame == null ? void 0 : frame.width),
|
|
297
|
+
height: (frame == null ? void 0 : frame[1]) || (frame == null ? void 0 : frame.height),
|
|
298
|
+
...initialRenderData && { initialData: initialRenderData },
|
|
299
|
+
...uiMeta.displayName && { displayName: uiMeta.displayName },
|
|
300
|
+
...stateless !== void 0 && { stateless },
|
|
301
|
+
metadata: resource.meta
|
|
302
|
+
};
|
|
303
|
+
return {
|
|
304
|
+
canvasType: "mcp-app",
|
|
305
|
+
canvasData
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function processContentItems(items) {
|
|
309
|
+
const outputFromToolObject = items;
|
|
310
|
+
const outputFromTool = JSON.stringify(items, null, 2);
|
|
311
|
+
let canvas;
|
|
312
|
+
for (const item of items) {
|
|
313
|
+
if (isResourceContent(item)) {
|
|
314
|
+
const maybe = toCanvasFromResource(item.resource);
|
|
315
|
+
if (maybe) {
|
|
316
|
+
canvas = maybe;
|
|
317
|
+
break;
|
|
612
318
|
}
|
|
613
|
-
return apiConfig;
|
|
614
|
-
}
|
|
615
|
-
function toInternalRunOptions(sdkOptions) {
|
|
616
|
-
if (!sdkOptions)
|
|
617
|
-
return {};
|
|
618
|
-
return {
|
|
619
|
-
flow_id: sdkOptions.flowId,
|
|
620
|
-
flow_session_id: sdkOptions.sessionId,
|
|
621
|
-
// Map sessionId to flow_session_id for server
|
|
622
|
-
stream_events: sdkOptions.streamEvents,
|
|
623
|
-
stream: sdkOptions.stream,
|
|
624
|
-
model_context: sdkOptions.modelContext,
|
|
625
|
-
callbacks: toInternalCallbacks(sdkOptions.callbacks),
|
|
626
|
-
debug: sdkOptions.debug,
|
|
627
|
-
circuitBreaker: convertCircuitBreakerToAPI(sdkOptions.circuitBreaker)
|
|
628
|
-
};
|
|
629
319
|
}
|
|
630
|
-
exports.toInternalRunOptions = toInternalRunOptions;
|
|
631
320
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
// ../../packages/sdk-types/lib/index.js
|
|
642
|
-
var require_lib = __commonJS({
|
|
643
|
-
"../../packages/sdk-types/lib/index.js"(exports) {
|
|
644
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
645
|
-
if (k2 === void 0)
|
|
646
|
-
k2 = k;
|
|
647
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
648
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
649
|
-
desc = { enumerable: true, get: function() {
|
|
650
|
-
return m[k];
|
|
651
|
-
} };
|
|
652
|
-
}
|
|
653
|
-
Object.defineProperty(o, k2, desc);
|
|
654
|
-
} : function(o, m, k, k2) {
|
|
655
|
-
if (k2 === void 0)
|
|
656
|
-
k2 = k;
|
|
657
|
-
o[k2] = m[k];
|
|
658
|
-
});
|
|
659
|
-
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
660
|
-
for (var p in m)
|
|
661
|
-
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
662
|
-
__createBinding(exports2, m, p);
|
|
663
|
-
};
|
|
664
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
665
|
-
exports.toInternalRunOptions = exports.toInternalCallbacks = exports.toInternalStep = exports.toSDKStep = exports.translateResourcesToBackend = exports.translatePromptsToBackend = exports.translateToolsToBackend = exports.translateModelContextToBackend = exports.extractUriParams = exports.matchesUriTemplate = exports.isDynamicResource = exports.buildResourceProvider = exports.mapToolResponseToBackend = exports.citations = exports.citation = exports.mcpResource = exports.uiResource = exports.imageResult = exports.textResult = exports.extractToolHandlers = exports.toolsToModelContext = exports.modelContext = exports.tool = exports.MCP_HTML_MIME_TYPES = exports.MIME_TYPES = void 0;
|
|
666
|
-
exports.MIME_TYPES = {
|
|
667
|
-
// UI Canvas types (MCP Apps standard)
|
|
668
|
-
URI_LIST: "text/uri-list",
|
|
669
|
-
HTML: "text/html",
|
|
670
|
-
HTML_MCP: "text/html+mcp",
|
|
671
|
-
HTML_MCP_PROFILE: "text/html;profile=mcp-app",
|
|
672
|
-
// Remote DOM (both MCP Apps standard and BotDojo alias)
|
|
673
|
-
REMOTE_DOM: "application/vnd.mcp-ui.remote-dom",
|
|
674
|
-
REMOTE_DOM_BOTDOJO: "application/vnd.botdojo.ui-remote-dom",
|
|
675
|
-
// BotDojo extensions
|
|
676
|
-
MODEL_CONTEXT: "application/vnd.botdojo.modelcontext",
|
|
677
|
-
CITATION: "application/vnd.botdojo.citation",
|
|
678
|
-
CITATIONS: "application/vnd.botdojo.citations"
|
|
679
|
-
};
|
|
680
|
-
exports.MCP_HTML_MIME_TYPES = [
|
|
681
|
-
exports.MIME_TYPES.HTML_MCP,
|
|
682
|
-
exports.MIME_TYPES.HTML_MCP_PROFILE
|
|
683
|
-
];
|
|
684
|
-
var tool_utils_1 = require_tool_utils();
|
|
685
|
-
Object.defineProperty(exports, "tool", { enumerable: true, get: function() {
|
|
686
|
-
return tool_utils_1.tool;
|
|
687
|
-
} });
|
|
688
|
-
Object.defineProperty(exports, "modelContext", { enumerable: true, get: function() {
|
|
689
|
-
return tool_utils_1.modelContext;
|
|
690
|
-
} });
|
|
691
|
-
Object.defineProperty(exports, "toolsToModelContext", { enumerable: true, get: function() {
|
|
692
|
-
return tool_utils_1.toolsToModelContext;
|
|
693
|
-
} });
|
|
694
|
-
Object.defineProperty(exports, "extractToolHandlers", { enumerable: true, get: function() {
|
|
695
|
-
return tool_utils_1.extractToolHandlers;
|
|
696
|
-
} });
|
|
697
|
-
Object.defineProperty(exports, "textResult", { enumerable: true, get: function() {
|
|
698
|
-
return tool_utils_1.textResult;
|
|
699
|
-
} });
|
|
700
|
-
Object.defineProperty(exports, "imageResult", { enumerable: true, get: function() {
|
|
701
|
-
return tool_utils_1.imageResult;
|
|
702
|
-
} });
|
|
703
|
-
Object.defineProperty(exports, "uiResource", { enumerable: true, get: function() {
|
|
704
|
-
return tool_utils_1.uiResource;
|
|
705
|
-
} });
|
|
706
|
-
Object.defineProperty(exports, "mcpResource", { enumerable: true, get: function() {
|
|
707
|
-
return tool_utils_1.mcpResource;
|
|
708
|
-
} });
|
|
709
|
-
Object.defineProperty(exports, "citation", { enumerable: true, get: function() {
|
|
710
|
-
return tool_utils_1.citation;
|
|
711
|
-
} });
|
|
712
|
-
Object.defineProperty(exports, "citations", { enumerable: true, get: function() {
|
|
713
|
-
return tool_utils_1.citations;
|
|
714
|
-
} });
|
|
715
|
-
var toolResponseMapper_1 = require_toolResponseMapper();
|
|
716
|
-
Object.defineProperty(exports, "mapToolResponseToBackend", { enumerable: true, get: function() {
|
|
717
|
-
return toolResponseMapper_1.mapToolResponseToBackend;
|
|
718
|
-
} });
|
|
719
|
-
var resource_utils_1 = require_resource_utils();
|
|
720
|
-
Object.defineProperty(exports, "buildResourceProvider", { enumerable: true, get: function() {
|
|
721
|
-
return resource_utils_1.buildResourceProvider;
|
|
722
|
-
} });
|
|
723
|
-
Object.defineProperty(exports, "isDynamicResource", { enumerable: true, get: function() {
|
|
724
|
-
return resource_utils_1.isDynamicResource;
|
|
725
|
-
} });
|
|
726
|
-
Object.defineProperty(exports, "matchesUriTemplate", { enumerable: true, get: function() {
|
|
727
|
-
return resource_utils_1.matchesUriTemplate;
|
|
728
|
-
} });
|
|
729
|
-
Object.defineProperty(exports, "extractUriParams", { enumerable: true, get: function() {
|
|
730
|
-
return resource_utils_1.extractUriParams;
|
|
731
|
-
} });
|
|
732
|
-
var type_translation_1 = require_type_translation();
|
|
733
|
-
Object.defineProperty(exports, "translateModelContextToBackend", { enumerable: true, get: function() {
|
|
734
|
-
return type_translation_1.translateModelContextToBackend;
|
|
735
|
-
} });
|
|
736
|
-
Object.defineProperty(exports, "translateToolsToBackend", { enumerable: true, get: function() {
|
|
737
|
-
return type_translation_1.translateToolsToBackend;
|
|
738
|
-
} });
|
|
739
|
-
Object.defineProperty(exports, "translatePromptsToBackend", { enumerable: true, get: function() {
|
|
740
|
-
return type_translation_1.translatePromptsToBackend;
|
|
741
|
-
} });
|
|
742
|
-
Object.defineProperty(exports, "translateResourcesToBackend", { enumerable: true, get: function() {
|
|
743
|
-
return type_translation_1.translateResourcesToBackend;
|
|
744
|
-
} });
|
|
745
|
-
var converters_1 = require_converters();
|
|
746
|
-
Object.defineProperty(exports, "toSDKStep", { enumerable: true, get: function() {
|
|
747
|
-
return converters_1.toSDKStep;
|
|
748
|
-
} });
|
|
749
|
-
Object.defineProperty(exports, "toInternalStep", { enumerable: true, get: function() {
|
|
750
|
-
return converters_1.toInternalStep;
|
|
751
|
-
} });
|
|
752
|
-
Object.defineProperty(exports, "toInternalCallbacks", { enumerable: true, get: function() {
|
|
753
|
-
return converters_1.toInternalCallbacks;
|
|
754
|
-
} });
|
|
755
|
-
Object.defineProperty(exports, "toInternalRunOptions", { enumerable: true, get: function() {
|
|
756
|
-
return converters_1.toInternalRunOptions;
|
|
757
|
-
} });
|
|
758
|
-
__exportStar(require_mcp_apps(), exports);
|
|
321
|
+
return {
|
|
322
|
+
outputFromTool,
|
|
323
|
+
outputFromToolObject,
|
|
324
|
+
canvas
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
async function mapToolResponseToBackend(response) {
|
|
328
|
+
if (Array.isArray(response)) {
|
|
329
|
+
return processContentItems(response);
|
|
759
330
|
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
331
|
+
return {
|
|
332
|
+
outputFromTool: response === void 0 ? "" : JSON.stringify(response, null, 2),
|
|
333
|
+
outputFromToolObject: response
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
var MIME_TYPES = {
|
|
337
|
+
// UI Canvas types (MCP Apps standard)
|
|
338
|
+
URI_LIST: "text/uri-list",
|
|
339
|
+
HTML: "text/html",
|
|
340
|
+
HTML_MCP: "text/html+mcp",
|
|
341
|
+
HTML_MCP_PROFILE: "text/html;profile=mcp-app",
|
|
342
|
+
// Remote DOM (both MCP Apps standard and BotDojo alias)
|
|
343
|
+
REMOTE_DOM: "application/vnd.mcp-ui.remote-dom",
|
|
344
|
+
REMOTE_DOM_BOTDOJO: "application/vnd.botdojo.ui-remote-dom",
|
|
345
|
+
// BotDojo extensions
|
|
346
|
+
MODEL_CONTEXT: "application/vnd.botdojo.modelcontext",
|
|
347
|
+
CITATION: "application/vnd.botdojo.citation",
|
|
348
|
+
CITATIONS: "application/vnd.botdojo.citations"
|
|
349
|
+
};
|
|
350
|
+
[
|
|
351
|
+
MIME_TYPES.HTML_MCP,
|
|
352
|
+
MIME_TYPES.HTML_MCP_PROFILE
|
|
353
|
+
];
|
|
764
354
|
|
|
765
|
-
//
|
|
355
|
+
// ../../node_modules/.pnpm/botdojo-rpc@0.1.1/node_modules/botdojo-rpc/dist/index.mjs
|
|
766
356
|
var __require2 = /* @__PURE__ */ ((x) => typeof __require !== "undefined" ? __require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
767
357
|
get: (a, b) => (typeof __require !== "undefined" ? __require : a)[b]
|
|
768
358
|
}) : x)(function(x) {
|
|
@@ -1959,7 +1549,7 @@ var BotDojoConnector = class {
|
|
|
1959
1549
|
source: this.connection.sender,
|
|
1960
1550
|
func: async () => {
|
|
1961
1551
|
return Array.from(this.registeredModelContexts.values()).map((ctx) => {
|
|
1962
|
-
const backendFormat =
|
|
1552
|
+
const backendFormat = translateModelContextToBackend(ctx);
|
|
1963
1553
|
const tools = (backendFormat.tools || []).map((tool2) => {
|
|
1964
1554
|
const { execute, ...toolWithoutExecute } = tool2;
|
|
1965
1555
|
return toolWithoutExecute;
|
|
@@ -2092,7 +1682,7 @@ var BotDojoConnector = class {
|
|
|
2092
1682
|
};
|
|
2093
1683
|
const rawresult = await tool2.execute(toolArgs, toolExecContext2);
|
|
2094
1684
|
await toolExecContext2.notifyToolResult(rawresult);
|
|
2095
|
-
return await
|
|
1685
|
+
return await mapToolResponseToBackend(rawresult);
|
|
2096
1686
|
}
|
|
2097
1687
|
const baseToolInfo = {
|
|
2098
1688
|
toolName,
|
|
@@ -2127,7 +1717,7 @@ var BotDojoConnector = class {
|
|
|
2127
1717
|
};
|
|
2128
1718
|
const rawResult = await tool2.execute(toolArgs, toolExecContext);
|
|
2129
1719
|
await toolExecContext.notifyToolResult(rawResult);
|
|
2130
|
-
return await
|
|
1720
|
+
return await mapToolResponseToBackend(rawResult);
|
|
2131
1721
|
}
|
|
2132
1722
|
});
|
|
2133
1723
|
}
|
|
@@ -2172,7 +1762,7 @@ var BotDojoConnector = class {
|
|
|
2172
1762
|
if (msg.functionName === "broadcastAgentHostConnected") {
|
|
2173
1763
|
for (const [contextName, ctx] of this.registeredModelContexts.entries()) {
|
|
2174
1764
|
try {
|
|
2175
|
-
const backendFormat =
|
|
1765
|
+
const backendFormat = translateModelContextToBackend(ctx);
|
|
2176
1766
|
const tools = (backendFormat.tools || []).map((tool2) => {
|
|
2177
1767
|
const { execute, ...toolWithoutExecute } = tool2;
|
|
2178
1768
|
return toolWithoutExecute;
|
|
@@ -2251,7 +1841,7 @@ var BotDojoConnector = class {
|
|
|
2251
1841
|
for (const resource of ctx.resources) {
|
|
2252
1842
|
let matches = false;
|
|
2253
1843
|
let extractedParams = params || {};
|
|
2254
|
-
if (
|
|
1844
|
+
if (isDynamicResource(resource)) {
|
|
2255
1845
|
const template = resource.uriTemplate;
|
|
2256
1846
|
if (this.matchesUriTemplate(resourceUri, template)) {
|
|
2257
1847
|
matches = true;
|
|
@@ -2277,7 +1867,7 @@ var BotDojoConnector = class {
|
|
|
2277
1867
|
}
|
|
2278
1868
|
};
|
|
2279
1869
|
}
|
|
2280
|
-
const content =
|
|
1870
|
+
const content = isDynamicResource(resource) ? await resource.getContent(extractedParams) : await resource.getContent();
|
|
2281
1871
|
let result;
|
|
2282
1872
|
if (typeof content === "string") {
|
|
2283
1873
|
result = {
|
|
@@ -2400,7 +1990,7 @@ var BotDojoConnector = class {
|
|
|
2400
1990
|
console.log("\u{1F3AF} HOST: getModelContexts called");
|
|
2401
1991
|
console.log(`\u{1F3AF} HOST: Current registered contexts: ${this.registeredModelContexts.size}`);
|
|
2402
1992
|
const contexts = Array.from(this.registeredModelContexts.values()).map((ctx) => {
|
|
2403
|
-
const backendFormat =
|
|
1993
|
+
const backendFormat = translateModelContextToBackend(ctx);
|
|
2404
1994
|
const tools = (backendFormat.tools || []).map((tool2) => {
|
|
2405
1995
|
const { execute, ...toolWithoutExecute } = tool2;
|
|
2406
1996
|
return toolWithoutExecute;
|
|
@@ -2528,7 +2118,7 @@ var BotDojoConnector = class {
|
|
|
2528
2118
|
};
|
|
2529
2119
|
const rawresult2 = await tool2.execute(toolArgs, toolExecContext2);
|
|
2530
2120
|
await toolExecContext2.notifyToolResult(rawresult2);
|
|
2531
|
-
const result2 = await
|
|
2121
|
+
const result2 = await mapToolResponseToBackend(rawresult2);
|
|
2532
2122
|
console.log(`\u2705 Tool executed successfully: ${toolName}`);
|
|
2533
2123
|
return result2;
|
|
2534
2124
|
}
|
|
@@ -2565,7 +2155,7 @@ var BotDojoConnector = class {
|
|
|
2565
2155
|
};
|
|
2566
2156
|
const rawresult = await tool2.execute(toolArgs, toolExecContext);
|
|
2567
2157
|
await toolExecContext.notifyToolResult(rawresult);
|
|
2568
|
-
const result = await
|
|
2158
|
+
const result = await mapToolResponseToBackend(rawresult);
|
|
2569
2159
|
console.log(`\u2705 Tool executed successfully: ${toolName}`);
|
|
2570
2160
|
return result;
|
|
2571
2161
|
} catch (error) {
|
|
@@ -3089,7 +2679,11 @@ function buildMcpProxyUrl(options) {
|
|
|
3089
2679
|
const origin = options.origin || "https://mcp-app-proxy.botdojo.com";
|
|
3090
2680
|
const flowId = encodeURIComponent(options.flowId || "unknown");
|
|
3091
2681
|
const encodedResource = encodeURIComponent(options.resource || "");
|
|
3092
|
-
|
|
2682
|
+
let url = `${origin}/${flowId}/?url=${encodedResource}`;
|
|
2683
|
+
if (options.noCache) {
|
|
2684
|
+
url += "&noCache=true";
|
|
2685
|
+
}
|
|
2686
|
+
return url;
|
|
3093
2687
|
}
|
|
3094
2688
|
function buildMcpCacheKey(opts) {
|
|
3095
2689
|
const raw = `${opts.flowId || "unknown"}|${opts.contextResourceUri || ""}|${opts.resourceUri || ""}`;
|
|
@@ -5186,58 +4780,6 @@ function chatReducer(state, action) {
|
|
|
5186
4780
|
return state;
|
|
5187
4781
|
}
|
|
5188
4782
|
}
|
|
5189
|
-
|
|
5190
|
-
// src/headless/context/BotDojoChatProvider.tsx
|
|
5191
|
-
var import_sdk_types2 = __toESM(require_lib());
|
|
5192
|
-
|
|
5193
|
-
// ../../node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/dist/esm-browser/stringify.js
|
|
5194
|
-
var byteToHex = [];
|
|
5195
|
-
for (i = 0; i < 256; ++i) {
|
|
5196
|
-
byteToHex.push((i + 256).toString(16).slice(1));
|
|
5197
|
-
}
|
|
5198
|
-
var i;
|
|
5199
|
-
function unsafeStringify(arr, offset = 0) {
|
|
5200
|
-
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
5201
|
-
}
|
|
5202
|
-
|
|
5203
|
-
// ../../node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/dist/esm-browser/rng.js
|
|
5204
|
-
var getRandomValues;
|
|
5205
|
-
var rnds8 = new Uint8Array(16);
|
|
5206
|
-
function rng() {
|
|
5207
|
-
if (!getRandomValues) {
|
|
5208
|
-
getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
|
|
5209
|
-
if (!getRandomValues) {
|
|
5210
|
-
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
5211
|
-
}
|
|
5212
|
-
}
|
|
5213
|
-
return getRandomValues(rnds8);
|
|
5214
|
-
}
|
|
5215
|
-
|
|
5216
|
-
// ../../node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/dist/esm-browser/native.js
|
|
5217
|
-
var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
5218
|
-
var native_default = {
|
|
5219
|
-
randomUUID
|
|
5220
|
-
};
|
|
5221
|
-
|
|
5222
|
-
// ../../node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/dist/esm-browser/v4.js
|
|
5223
|
-
function v4(options, buf, offset) {
|
|
5224
|
-
if (native_default.randomUUID && !buf && !options) {
|
|
5225
|
-
return native_default.randomUUID();
|
|
5226
|
-
}
|
|
5227
|
-
options = options || {};
|
|
5228
|
-
var rnds = options.random || (options.rng || rng)();
|
|
5229
|
-
rnds[6] = rnds[6] & 15 | 64;
|
|
5230
|
-
rnds[8] = rnds[8] & 63 | 128;
|
|
5231
|
-
if (buf) {
|
|
5232
|
-
offset = offset || 0;
|
|
5233
|
-
for (var i = 0; i < 16; ++i) {
|
|
5234
|
-
buf[offset + i] = rnds[i];
|
|
5235
|
-
}
|
|
5236
|
-
return buf;
|
|
5237
|
-
}
|
|
5238
|
-
return unsafeStringify(rnds);
|
|
5239
|
-
}
|
|
5240
|
-
var v4_default = v4;
|
|
5241
4783
|
var BotDojoChatContext = createContext(null);
|
|
5242
4784
|
function BotDojoChatProvider(props) {
|
|
5243
4785
|
const {
|
|
@@ -5255,6 +4797,8 @@ function BotDojoChatProvider(props) {
|
|
|
5255
4797
|
onConnectorError,
|
|
5256
4798
|
// Debug mode for MCP App rendering
|
|
5257
4799
|
debug = false,
|
|
4800
|
+
// Cache key for MCP proxy URLs
|
|
4801
|
+
cacheKey,
|
|
5258
4802
|
// MCP App handlers (SEP-1865)
|
|
5259
4803
|
onOpenLink,
|
|
5260
4804
|
onToolCall,
|
|
@@ -5264,7 +4808,7 @@ function BotDojoChatProvider(props) {
|
|
|
5264
4808
|
const iframeRef = useRef(null);
|
|
5265
4809
|
const [isIframeReady, setIsIframeReady] = useState(false);
|
|
5266
4810
|
const [isSocketConnected, setIsSocketConnected] = useState(false);
|
|
5267
|
-
const externalUIChannelIdRef = useRef(
|
|
4811
|
+
const externalUIChannelIdRef = useRef(generateUUID2());
|
|
5268
4812
|
const connectorRef = useRef(null);
|
|
5269
4813
|
const connectionRef = useRef(null);
|
|
5270
4814
|
const [connector, setConnector] = useState(null);
|
|
@@ -5293,6 +4837,10 @@ function BotDojoChatProvider(props) {
|
|
|
5293
4837
|
useEffect(() => {
|
|
5294
4838
|
modelContextRef.current = modelContext2;
|
|
5295
4839
|
}, [modelContext2]);
|
|
4840
|
+
const debugLog = useCallback((...args) => {
|
|
4841
|
+
if (debug)
|
|
4842
|
+
console.log("[BotDojoChatProvider]", ...args);
|
|
4843
|
+
}, [debug]);
|
|
5296
4844
|
const iframeUrl = useMemo(() => {
|
|
5297
4845
|
const url = new URL("/embed/headless", baseUrl);
|
|
5298
4846
|
url.searchParams.set("apiKey", apiKey);
|
|
@@ -5316,11 +4864,11 @@ function BotDojoChatProvider(props) {
|
|
|
5316
4864
|
}
|
|
5317
4865
|
}, [isSocketConnected, modelContext2]);
|
|
5318
4866
|
const handleIframeLoad = useCallback(() => {
|
|
5319
|
-
|
|
4867
|
+
debugLog(" Headless iframe loaded");
|
|
5320
4868
|
setIsIframeReady(true);
|
|
5321
4869
|
}, []);
|
|
5322
4870
|
const serializeModelContext = useCallback((ctx) => {
|
|
5323
|
-
const backendFormat =
|
|
4871
|
+
const backendFormat = translateModelContextToBackend(ctx);
|
|
5324
4872
|
const tools = (backendFormat.tools || []).map((tool2) => {
|
|
5325
4873
|
const { execute, ...toolWithoutExecute } = tool2;
|
|
5326
4874
|
return toolWithoutExecute;
|
|
@@ -5339,7 +4887,7 @@ function BotDojoChatProvider(props) {
|
|
|
5339
4887
|
const contexts = Array.isArray(modelContextRef.current) ? modelContextRef.current : [modelContextRef.current];
|
|
5340
4888
|
const ctx = contexts[0];
|
|
5341
4889
|
if (ctx) {
|
|
5342
|
-
|
|
4890
|
+
debugLog(" Sending model context to HeadlessEmbed:", ctx.name);
|
|
5343
4891
|
iframeRef.current.contentWindow.postMessage({
|
|
5344
4892
|
type: "set_model_context",
|
|
5345
4893
|
modelContext: serializeModelContext(ctx)
|
|
@@ -5443,7 +4991,7 @@ function BotDojoChatProvider(props) {
|
|
|
5443
4991
|
console.warn(`[BotDojoChatProvider] No step update callback registered for app: ${appId}`);
|
|
5444
4992
|
}
|
|
5445
4993
|
}, []);
|
|
5446
|
-
const executeToolCall = useCallback(async (toolName, args, targetAppId) => {
|
|
4994
|
+
const executeToolCall = useCallback(async (toolName, args, targetAppId, stepId) => {
|
|
5447
4995
|
const ctx = modelContextRef.current;
|
|
5448
4996
|
if (!ctx) {
|
|
5449
4997
|
throw new Error("No model context available");
|
|
@@ -5454,18 +5002,29 @@ function BotDojoChatProvider(props) {
|
|
|
5454
5002
|
const toolsArray = Array.isArray(context.tools) ? context.tools : Object.values(context.tools);
|
|
5455
5003
|
const tool2 = toolsArray.find((t) => t.name === toolName);
|
|
5456
5004
|
if (tool2 && typeof tool2.execute === "function") {
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
if (
|
|
5005
|
+
const resolveAppIdDynamic = () => {
|
|
5006
|
+
if (targetAppId)
|
|
5007
|
+
return targetAppId;
|
|
5008
|
+
if (stepId) {
|
|
5009
|
+
const fromStepId = stepIdToAppIdRef.current.get(stepId);
|
|
5010
|
+
if (fromStepId)
|
|
5011
|
+
return fromStepId;
|
|
5012
|
+
}
|
|
5013
|
+
let fromToolName = activeAppByToolRef.current.get(toolName);
|
|
5014
|
+
if (!fromToolName && context.name) {
|
|
5461
5015
|
const prefixedToolName = `${context.name}_${toolName}`;
|
|
5462
|
-
|
|
5016
|
+
fromToolName = activeAppByToolRef.current.get(prefixedToolName);
|
|
5463
5017
|
}
|
|
5464
|
-
|
|
5465
|
-
|
|
5018
|
+
return fromToolName;
|
|
5019
|
+
};
|
|
5020
|
+
const initialAppId = resolveAppIdDynamic();
|
|
5021
|
+
console.log(`[BotDojoChatProvider] Executing tool "${toolName}" for app: ${initialAppId || "PENDING"}, stepId: ${stepId || "none"}`);
|
|
5466
5022
|
toolArgumentsCacheRef.current.set(toolName, args);
|
|
5467
|
-
if (
|
|
5468
|
-
toolArgumentsCacheRef.current.set(
|
|
5023
|
+
if (initialAppId) {
|
|
5024
|
+
toolArgumentsCacheRef.current.set(initialAppId, args);
|
|
5025
|
+
}
|
|
5026
|
+
if (stepId) {
|
|
5027
|
+
toolArgumentsCacheRef.current.set(stepId, args);
|
|
5469
5028
|
}
|
|
5470
5029
|
const executionContext = {
|
|
5471
5030
|
toolName,
|
|
@@ -5482,24 +5041,21 @@ function BotDojoChatProvider(props) {
|
|
|
5482
5041
|
stepToolProgress: isProgressUpdate ? data : void 0,
|
|
5483
5042
|
stepStatus: "processing"
|
|
5484
5043
|
};
|
|
5485
|
-
|
|
5486
|
-
|
|
5044
|
+
const currentAppId = resolveAppIdDynamic();
|
|
5045
|
+
if (currentAppId) {
|
|
5046
|
+
const callback = stepUpdateCallbacksRef.current.get(currentAppId);
|
|
5487
5047
|
if (callback) {
|
|
5488
|
-
console.log(`[BotDojoChatProvider] Sending partial update via step callback to: ${
|
|
5048
|
+
console.log(`[BotDojoChatProvider] Sending partial update via step callback to: ${currentAppId}`);
|
|
5489
5049
|
callback(stepUpdate);
|
|
5490
5050
|
} else {
|
|
5491
|
-
console.log(`[BotDojoChatProvider] Callback not registered for ${
|
|
5492
|
-
if (!pendingStepUpdatesRef.current.has(
|
|
5493
|
-
pendingStepUpdatesRef.current.set(
|
|
5051
|
+
console.log(`[BotDojoChatProvider] Callback not registered for ${currentAppId}, queueing`);
|
|
5052
|
+
if (!pendingStepUpdatesRef.current.has(currentAppId)) {
|
|
5053
|
+
pendingStepUpdatesRef.current.set(currentAppId, []);
|
|
5494
5054
|
}
|
|
5495
|
-
pendingStepUpdatesRef.current.get(
|
|
5055
|
+
pendingStepUpdatesRef.current.get(currentAppId).push(stepUpdate);
|
|
5496
5056
|
}
|
|
5497
5057
|
} else {
|
|
5498
|
-
console.
|
|
5499
|
-
stepUpdateCallbacksRef.current.forEach((callback, appId) => {
|
|
5500
|
-
console.log(`[BotDojoChatProvider] Sending to: ${appId}`);
|
|
5501
|
-
callback(stepUpdate);
|
|
5502
|
-
});
|
|
5058
|
+
console.warn(`[BotDojoChatProvider] Cannot route partial update - no appId resolved for ${toolName}, stepId: ${stepId}`);
|
|
5503
5059
|
}
|
|
5504
5060
|
},
|
|
5505
5061
|
notifyToolResult: async (data) => {
|
|
@@ -5512,24 +5068,21 @@ function BotDojoChatProvider(props) {
|
|
|
5512
5068
|
result: (_b = data == null ? void 0 : data.result) != null ? _b : data,
|
|
5513
5069
|
stepStatus: "complete"
|
|
5514
5070
|
};
|
|
5515
|
-
|
|
5516
|
-
|
|
5071
|
+
const currentAppId = resolveAppIdDynamic();
|
|
5072
|
+
if (currentAppId) {
|
|
5073
|
+
const callback = stepUpdateCallbacksRef.current.get(currentAppId);
|
|
5517
5074
|
if (callback) {
|
|
5518
|
-
console.log(`[BotDojoChatProvider] Sending result via step callback to: ${
|
|
5075
|
+
console.log(`[BotDojoChatProvider] Sending result via step callback to: ${currentAppId}`);
|
|
5519
5076
|
callback(stepUpdate);
|
|
5520
5077
|
} else {
|
|
5521
|
-
console.log(`[BotDojoChatProvider] Callback not registered for ${
|
|
5522
|
-
if (!pendingStepUpdatesRef.current.has(
|
|
5523
|
-
pendingStepUpdatesRef.current.set(
|
|
5078
|
+
console.log(`[BotDojoChatProvider] Callback not registered for ${currentAppId}, queueing result`);
|
|
5079
|
+
if (!pendingStepUpdatesRef.current.has(currentAppId)) {
|
|
5080
|
+
pendingStepUpdatesRef.current.set(currentAppId, []);
|
|
5524
5081
|
}
|
|
5525
|
-
pendingStepUpdatesRef.current.get(
|
|
5082
|
+
pendingStepUpdatesRef.current.get(currentAppId).push(stepUpdate);
|
|
5526
5083
|
}
|
|
5527
5084
|
} else {
|
|
5528
|
-
console.
|
|
5529
|
-
stepUpdateCallbacksRef.current.forEach((callback, appId) => {
|
|
5530
|
-
console.log(`[BotDojoChatProvider] Sending result to: ${appId}`);
|
|
5531
|
-
callback(stepUpdate);
|
|
5532
|
-
});
|
|
5085
|
+
console.warn(`[BotDojoChatProvider] Cannot route tool result - no appId resolved for ${toolName}, stepId: ${stepId}`);
|
|
5533
5086
|
}
|
|
5534
5087
|
}
|
|
5535
5088
|
};
|
|
@@ -5544,7 +5097,7 @@ function BotDojoChatProvider(props) {
|
|
|
5544
5097
|
throw new Error(`Tool not found: ${toolName}`);
|
|
5545
5098
|
}, []);
|
|
5546
5099
|
const getMcpAppData = useCallback((appId) => {
|
|
5547
|
-
var _a, _b, _c, _d;
|
|
5100
|
+
var _a, _b, _c, _d, _e;
|
|
5548
5101
|
const cached = mcpAppDataCacheRef.current.get(appId);
|
|
5549
5102
|
if (cached == null ? void 0 : cached.url) {
|
|
5550
5103
|
return { mcpAppId: appId, mcpAppType: "mcp-app", ...cached };
|
|
@@ -5555,9 +5108,28 @@ function BotDojoChatProvider(props) {
|
|
|
5555
5108
|
const canvasUrl = (_b = step.canvas.canvasData) == null ? void 0 : _b.url;
|
|
5556
5109
|
let proxyUrl;
|
|
5557
5110
|
if (canvasUrl == null ? void 0 : canvasUrl.startsWith("ui://")) {
|
|
5558
|
-
const flowId =
|
|
5111
|
+
const flowId = cacheKey || appId;
|
|
5112
|
+
let noCache = false;
|
|
5113
|
+
const toolName = step.stepToolName;
|
|
5114
|
+
debugLog(" Checking no-cache for tool:", toolName, "modelContextRef:", !!modelContextRef.current);
|
|
5115
|
+
if (toolName && modelContextRef.current) {
|
|
5116
|
+
const contexts = Array.isArray(modelContextRef.current) ? modelContextRef.current : [modelContextRef.current];
|
|
5117
|
+
for (const ctx of contexts) {
|
|
5118
|
+
const tools = ctx.tools;
|
|
5119
|
+
debugLog(" Context tools:", Array.isArray(tools) ? tools.length : "not array");
|
|
5120
|
+
if (Array.isArray(tools)) {
|
|
5121
|
+
const tool2 = tools.find((t) => t.name === toolName);
|
|
5122
|
+
debugLog(" Found tool:", tool2 == null ? void 0 : tool2.name, "_meta:", tool2 == null ? void 0 : tool2._meta);
|
|
5123
|
+
if ((_c = tool2 == null ? void 0 : tool2._meta) == null ? void 0 : _c["botdojo/no-cache"]) {
|
|
5124
|
+
noCache = true;
|
|
5125
|
+
break;
|
|
5126
|
+
}
|
|
5127
|
+
}
|
|
5128
|
+
}
|
|
5129
|
+
}
|
|
5130
|
+
debugLog(" noCache result:", noCache);
|
|
5559
5131
|
try {
|
|
5560
|
-
proxyUrl = buildMcpProxyUrl({ flowId: String(flowId), resource: canvasUrl });
|
|
5132
|
+
proxyUrl = buildMcpProxyUrl({ flowId: String(flowId), resource: canvasUrl, noCache });
|
|
5561
5133
|
} catch (err) {
|
|
5562
5134
|
console.warn("[BotDojoChatProvider] Failed to build proxy URL for hydration:", err);
|
|
5563
5135
|
}
|
|
@@ -5570,8 +5142,8 @@ function BotDojoChatProvider(props) {
|
|
|
5570
5142
|
toolInfo: step.stepToolName ? { tool: { name: step.stepToolName } } : void 0,
|
|
5571
5143
|
arguments: step.stepToolArguments,
|
|
5572
5144
|
result: step.stepToolResult,
|
|
5573
|
-
height: (
|
|
5574
|
-
width: (
|
|
5145
|
+
height: (_d = step.canvas.canvasData) == null ? void 0 : _d.height,
|
|
5146
|
+
width: (_e = step.canvas.canvasData) == null ? void 0 : _e.width,
|
|
5575
5147
|
...cached
|
|
5576
5148
|
// Merge any partial cached data
|
|
5577
5149
|
};
|
|
@@ -5586,24 +5158,24 @@ function BotDojoChatProvider(props) {
|
|
|
5586
5158
|
setMcpAppDataVersion((v) => v + 1);
|
|
5587
5159
|
}, []);
|
|
5588
5160
|
const getResource = useCallback(async (uri, params, onlyMetadata) => {
|
|
5589
|
-
|
|
5161
|
+
debugLog(" getResource called for URI:", uri);
|
|
5590
5162
|
const ctx = modelContextRef.current;
|
|
5591
5163
|
if (!ctx) {
|
|
5592
5164
|
console.error("[BotDojoChatProvider] getResource: No model context available");
|
|
5593
5165
|
throw new Error("No model context available");
|
|
5594
5166
|
}
|
|
5595
5167
|
const contexts = Array.isArray(ctx) ? ctx : [ctx];
|
|
5596
|
-
|
|
5168
|
+
debugLog(" getResource: Searching", contexts.length, "context(s)");
|
|
5597
5169
|
for (const context of contexts) {
|
|
5598
5170
|
if (context.resources) {
|
|
5599
|
-
|
|
5171
|
+
debugLog(" getResource: Context has", context.resources.length, "resources");
|
|
5600
5172
|
for (const resource of context.resources) {
|
|
5601
5173
|
const resourceUri = "uri" in resource ? resource.uri : "no-uri";
|
|
5602
|
-
|
|
5174
|
+
debugLog(" getResource: Checking resource URI:", resourceUri, "=== requested URI:", uri, "?", resourceUri === uri);
|
|
5603
5175
|
if ("uri" in resource && resource.uri === uri && resource.getContent) {
|
|
5604
|
-
|
|
5176
|
+
debugLog(" getResource: MATCH FOUND! Calling getContent()");
|
|
5605
5177
|
const content = await resource.getContent();
|
|
5606
|
-
|
|
5178
|
+
debugLog(" getResource: getContent returned:", typeof content, typeof content === "object" && content && "uri" in content ? content.uri : "(no uri)");
|
|
5607
5179
|
return {
|
|
5608
5180
|
uri,
|
|
5609
5181
|
mimeType: resource.mimeType,
|
|
@@ -5617,9 +5189,9 @@ function BotDojoChatProvider(props) {
|
|
|
5617
5189
|
throw new Error(`Resource not found: ${uri}`);
|
|
5618
5190
|
}, []);
|
|
5619
5191
|
const registerMcpApp = useCallback((appId, iframeWindow) => {
|
|
5620
|
-
|
|
5192
|
+
debugLog(" Registering MCP App iframe:", appId);
|
|
5621
5193
|
if (appBridgesRef.current.has(appId)) {
|
|
5622
|
-
|
|
5194
|
+
debugLog(" MCP App already registered, refreshing bridge:", appId);
|
|
5623
5195
|
const existingBridge = appBridgesRef.current.get(appId);
|
|
5624
5196
|
existingBridge == null ? void 0 : existingBridge.stop();
|
|
5625
5197
|
appBridgesRef.current.delete(appId);
|
|
@@ -5633,13 +5205,13 @@ function BotDojoChatProvider(props) {
|
|
|
5633
5205
|
role: "parent",
|
|
5634
5206
|
onMessage: async (msg) => {
|
|
5635
5207
|
var _a;
|
|
5636
|
-
|
|
5208
|
+
debugLog(" Message from MCP App:", appId, msg.functionName);
|
|
5637
5209
|
if (msg.functionName.startsWith("tool_")) {
|
|
5638
5210
|
const toolName = msg.functionName.substring(5);
|
|
5639
5211
|
if (connectorRef.current) {
|
|
5640
|
-
|
|
5212
|
+
debugLog(" Tool call from app:", toolName, msg.data);
|
|
5641
5213
|
} else {
|
|
5642
|
-
|
|
5214
|
+
debugLog(" Forwarding tool call to server:", toolName);
|
|
5643
5215
|
if ((_a = iframeRef.current) == null ? void 0 : _a.contentWindow) {
|
|
5644
5216
|
iframeRef.current.contentWindow.postMessage(
|
|
5645
5217
|
{
|
|
@@ -5663,7 +5235,7 @@ function BotDojoChatProvider(props) {
|
|
|
5663
5235
|
setRegisteredMcpApps((prev) => new Set(prev).add(appId));
|
|
5664
5236
|
const pending = pendingAppEventsRef.current.get(appId);
|
|
5665
5237
|
if (pending && pending.length > 0) {
|
|
5666
|
-
|
|
5238
|
+
debugLog(" Sending pending events to app:", appId, pending.length);
|
|
5667
5239
|
pending.forEach((event) => {
|
|
5668
5240
|
bridge.sendMessage(RPCMessage.request(
|
|
5669
5241
|
`parent-to-app-${appId}`,
|
|
@@ -5674,10 +5246,10 @@ function BotDojoChatProvider(props) {
|
|
|
5674
5246
|
});
|
|
5675
5247
|
pendingAppEventsRef.current.delete(appId);
|
|
5676
5248
|
}
|
|
5677
|
-
|
|
5249
|
+
debugLog(" MCP App registered successfully:", appId);
|
|
5678
5250
|
}, [baseUrl]);
|
|
5679
5251
|
const unregisterMcpApp = useCallback((appId) => {
|
|
5680
|
-
|
|
5252
|
+
debugLog(" Unregistering MCP App iframe:", appId);
|
|
5681
5253
|
const bridge = appBridgesRef.current.get(appId);
|
|
5682
5254
|
if (bridge) {
|
|
5683
5255
|
bridge.stop();
|
|
@@ -5694,7 +5266,7 @@ function BotDojoChatProvider(props) {
|
|
|
5694
5266
|
const forwardEventToApp = useCallback((appId, eventName, data) => {
|
|
5695
5267
|
const bridge = appBridgesRef.current.get(appId);
|
|
5696
5268
|
if (bridge) {
|
|
5697
|
-
|
|
5269
|
+
debugLog(" Forwarding event to app:", appId, eventName);
|
|
5698
5270
|
bridge.sendMessage(RPCMessage.request(
|
|
5699
5271
|
`parent-to-app-${appId}`,
|
|
5700
5272
|
"app",
|
|
@@ -5702,7 +5274,7 @@ function BotDojoChatProvider(props) {
|
|
|
5702
5274
|
data
|
|
5703
5275
|
));
|
|
5704
5276
|
} else {
|
|
5705
|
-
|
|
5277
|
+
debugLog(" Queueing event for app (not ready):", appId, eventName);
|
|
5706
5278
|
if (!pendingAppEventsRef.current.has(appId)) {
|
|
5707
5279
|
pendingAppEventsRef.current.set(appId, []);
|
|
5708
5280
|
}
|
|
@@ -5727,27 +5299,32 @@ function BotDojoChatProvider(props) {
|
|
|
5727
5299
|
if ((_a = data.type) == null ? void 0 : _a.startsWith("botdojo-")) {
|
|
5728
5300
|
return;
|
|
5729
5301
|
}
|
|
5730
|
-
|
|
5302
|
+
debugLog(" Received event:", data.type, data);
|
|
5731
5303
|
switch (data.type) {
|
|
5732
5304
|
case "socket_connected":
|
|
5733
|
-
|
|
5305
|
+
debugLog(" HeadlessEmbed Socket.IO connected");
|
|
5734
5306
|
setIsSocketConnected(true);
|
|
5735
5307
|
sendModelContextToHeadless();
|
|
5736
5308
|
break;
|
|
5737
5309
|
case "request_model_context":
|
|
5738
|
-
|
|
5310
|
+
debugLog(" HeadlessEmbed requesting model context");
|
|
5739
5311
|
sendModelContextToHeadless();
|
|
5740
5312
|
break;
|
|
5741
5313
|
case "get_model_contexts":
|
|
5742
|
-
|
|
5314
|
+
debugLog(" HeadlessEmbed requesting all model contexts");
|
|
5743
5315
|
sendModelContextToHeadless();
|
|
5744
5316
|
break;
|
|
5745
5317
|
case "tool_call":
|
|
5746
|
-
|
|
5318
|
+
debugLog(" Tool call from HeadlessEmbed:", data.toolName, "appId:", data.appId || data.canvasId || "none", "stepId:", data.stepId || "none");
|
|
5747
5319
|
(async () => {
|
|
5748
5320
|
var _a2, _b, _c, _d;
|
|
5749
5321
|
try {
|
|
5750
|
-
|
|
5322
|
+
let targetAppId = data.appId || data.canvasId;
|
|
5323
|
+
if (!targetAppId && data.stepId) {
|
|
5324
|
+
targetAppId = stepIdToAppIdRef.current.get(data.stepId);
|
|
5325
|
+
debugLog(" Resolved appId from stepId:", data.stepId, "\u2192", targetAppId);
|
|
5326
|
+
}
|
|
5327
|
+
const result = await executeToolCall(data.toolName, data.arguments, targetAppId, data.stepId);
|
|
5751
5328
|
console.log(`[BotDojoChatProvider] \u2705 Tool "${data.toolName}" executed successfully`);
|
|
5752
5329
|
(_b = (_a2 = iframeRef.current) == null ? void 0 : _a2.contentWindow) == null ? void 0 : _b.postMessage({
|
|
5753
5330
|
type: "tool_response",
|
|
@@ -5765,7 +5342,7 @@ function BotDojoChatProvider(props) {
|
|
|
5765
5342
|
})();
|
|
5766
5343
|
break;
|
|
5767
5344
|
case "get_resource":
|
|
5768
|
-
|
|
5345
|
+
debugLog(" Resource request from HeadlessEmbed:", data.uri);
|
|
5769
5346
|
(async () => {
|
|
5770
5347
|
var _a2, _b, _c, _d;
|
|
5771
5348
|
try {
|
|
@@ -5786,7 +5363,7 @@ function BotDojoChatProvider(props) {
|
|
|
5786
5363
|
})();
|
|
5787
5364
|
break;
|
|
5788
5365
|
case "model_context_registered":
|
|
5789
|
-
|
|
5366
|
+
debugLog(" \u2705 Model context registered:", data.name);
|
|
5790
5367
|
setIsModelContextRegistered(true);
|
|
5791
5368
|
onConnectorInit == null ? void 0 : onConnectorInit(null);
|
|
5792
5369
|
break;
|
|
@@ -5835,7 +5412,7 @@ function BotDojoChatProvider(props) {
|
|
|
5835
5412
|
case "step_update":
|
|
5836
5413
|
const rawStep = data.step;
|
|
5837
5414
|
if (rawStep == null ? void 0 : rawStep.canvas) {
|
|
5838
|
-
|
|
5415
|
+
debugLog(" Step has MCP App:", rawStep.canvas.canvasId, rawStep.canvas.canvasType, JSON.stringify(rawStep.canvas.canvasData, null, 2));
|
|
5839
5416
|
const toolName = rawStep.stepToolName || rawStep.stepLabel;
|
|
5840
5417
|
const appId = rawStep.canvas.canvasId;
|
|
5841
5418
|
if (toolName && appId) {
|
|
@@ -5847,20 +5424,20 @@ function BotDojoChatProvider(props) {
|
|
|
5847
5424
|
}
|
|
5848
5425
|
}
|
|
5849
5426
|
(async () => {
|
|
5850
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
5427
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
5851
5428
|
let stepToDispatch = rawStep;
|
|
5852
5429
|
const canvasUrl = (_b = (_a2 = rawStep == null ? void 0 : rawStep.canvas) == null ? void 0 : _a2.canvasData) == null ? void 0 : _b.url;
|
|
5853
5430
|
if (canvasUrl && canvasUrl.startsWith("ui://") && !((_d = (_c = rawStep == null ? void 0 : rawStep.canvas) == null ? void 0 : _c.canvasData) == null ? void 0 : _d.html)) {
|
|
5854
|
-
|
|
5431
|
+
debugLog(" Resolving ui:// resource:", canvasUrl);
|
|
5855
5432
|
try {
|
|
5856
5433
|
const resource = await getResource(canvasUrl);
|
|
5857
|
-
|
|
5434
|
+
debugLog(" Resource result:", resource ? "got content" : "no content");
|
|
5858
5435
|
let htmlContent = (resource == null ? void 0 : resource.text) || (resource == null ? void 0 : resource.content);
|
|
5859
5436
|
if (htmlContent) {
|
|
5860
5437
|
const cspMeta = extractUiCspFromResource(resource);
|
|
5861
5438
|
if (cspMeta) {
|
|
5862
5439
|
const resolvedCsp = resolveUiCsp(cspMeta);
|
|
5863
|
-
|
|
5440
|
+
debugLog(" Injecting CSP into HTML:", resolvedCsp.csp.substring(0, 100) + "...");
|
|
5864
5441
|
const cspMetaTag = `<meta http-equiv="Content-Security-Policy" content="${resolvedCsp.csp.replace(/"/g, """)}">`;
|
|
5865
5442
|
if (/<head[^>]*>/i.test(htmlContent)) {
|
|
5866
5443
|
htmlContent = htmlContent.replace(/<head([^>]*)>/i, `<head$1>
|
|
@@ -5888,17 +5465,38 @@ ${htmlContent}`;
|
|
|
5888
5465
|
}
|
|
5889
5466
|
}
|
|
5890
5467
|
};
|
|
5891
|
-
|
|
5468
|
+
debugLog(" \u2705 Resolved ui:// resource to HTML (" + htmlContent.length + " chars)");
|
|
5892
5469
|
let proxyUrl;
|
|
5893
5470
|
const proxyOrigin = process.env.NEXT_PUBLIC_MCP_HTML_PROXY_ORIGIN || void 0;
|
|
5894
|
-
const
|
|
5471
|
+
const canvasId = (_e = rawStep.canvas) == null ? void 0 : _e.canvasId;
|
|
5472
|
+
const flowIdForProxy = cacheKey || canvasId || `unknown-${generateUUID2()}`;
|
|
5473
|
+
let noCache = false;
|
|
5474
|
+
const toolNameForMeta = rawStep.stepToolName || rawStep.stepLabel;
|
|
5475
|
+
debugLog(" handleStepUpdate - Checking no-cache for tool:", toolNameForMeta, "modelContextRef:", !!modelContextRef.current);
|
|
5476
|
+
if (toolNameForMeta && modelContextRef.current) {
|
|
5477
|
+
const contexts = Array.isArray(modelContextRef.current) ? modelContextRef.current : [modelContextRef.current];
|
|
5478
|
+
for (const ctx of contexts) {
|
|
5479
|
+
const tools = ctx.tools;
|
|
5480
|
+
debugLog(" handleStepUpdate - Context tools:", Array.isArray(tools) ? tools.length : "not array");
|
|
5481
|
+
if (Array.isArray(tools)) {
|
|
5482
|
+
const tool2 = tools.find((t) => t.name === toolNameForMeta);
|
|
5483
|
+
debugLog(" handleStepUpdate - Found tool:", tool2 == null ? void 0 : tool2.name, "_meta:", JSON.stringify(tool2 == null ? void 0 : tool2._meta));
|
|
5484
|
+
if ((_f = tool2 == null ? void 0 : tool2._meta) == null ? void 0 : _f["botdojo/no-cache"]) {
|
|
5485
|
+
noCache = true;
|
|
5486
|
+
break;
|
|
5487
|
+
}
|
|
5488
|
+
}
|
|
5489
|
+
}
|
|
5490
|
+
}
|
|
5491
|
+
debugLog(" handleStepUpdate - noCache result:", noCache);
|
|
5895
5492
|
try {
|
|
5896
5493
|
proxyUrl = buildMcpProxyUrl({
|
|
5897
5494
|
flowId: String(flowIdForProxy),
|
|
5898
5495
|
resource: canvasUrl,
|
|
5899
|
-
...proxyOrigin ? { origin: proxyOrigin } : {}
|
|
5496
|
+
...proxyOrigin ? { origin: proxyOrigin } : {},
|
|
5497
|
+
noCache
|
|
5900
5498
|
});
|
|
5901
|
-
|
|
5499
|
+
debugLog(" Using MCP proxy URL:", proxyUrl, noCache ? "(no-cache)" : "");
|
|
5902
5500
|
} catch (err) {
|
|
5903
5501
|
console.warn("[BotDojoChatProvider] Failed to build MCP proxy URL", err);
|
|
5904
5502
|
}
|
|
@@ -5909,8 +5507,8 @@ ${htmlContent}`;
|
|
|
5909
5507
|
html: htmlContent,
|
|
5910
5508
|
url: proxyUrl || canvasUrl,
|
|
5911
5509
|
toolInfo: toolNameForCache ? { tool: { name: toolNameForCache } } : void 0,
|
|
5912
|
-
height: (
|
|
5913
|
-
width: (
|
|
5510
|
+
height: (_g = rawStep.canvas.canvasData) == null ? void 0 : _g.height,
|
|
5511
|
+
width: (_h = rawStep.canvas.canvasData) == null ? void 0 : _h.width
|
|
5914
5512
|
});
|
|
5915
5513
|
}
|
|
5916
5514
|
} else {
|
|
@@ -5926,7 +5524,7 @@ ${htmlContent}`;
|
|
|
5926
5524
|
messageId: data.messageId,
|
|
5927
5525
|
step: stepToDispatch
|
|
5928
5526
|
});
|
|
5929
|
-
const appIdFromCanvas = (
|
|
5527
|
+
const appIdFromCanvas = (_i = stepToDispatch == null ? void 0 : stepToDispatch.canvas) == null ? void 0 : _i.canvasId;
|
|
5930
5528
|
const appIdFromStepId = (stepToDispatch == null ? void 0 : stepToDispatch.stepId) ? stepIdToAppIdRef.current.get(stepToDispatch.stepId) : void 0;
|
|
5931
5529
|
const toolNameForLookup = (stepToDispatch == null ? void 0 : stepToDispatch.stepToolName) || (stepToDispatch == null ? void 0 : stepToDispatch.stepLabel);
|
|
5932
5530
|
const appIdFromToolName = toolNameForLookup ? activeAppByToolRef.current.get(toolNameForLookup) : void 0;
|
|
@@ -5947,12 +5545,12 @@ ${htmlContent}`;
|
|
|
5947
5545
|
}
|
|
5948
5546
|
return value;
|
|
5949
5547
|
};
|
|
5950
|
-
const canvasResult = parseIfJson((
|
|
5548
|
+
const canvasResult = parseIfJson((_k = (_j = stepToDispatch == null ? void 0 : stepToDispatch.canvas) == null ? void 0 : _j.canvasData) == null ? void 0 : _k.result);
|
|
5951
5549
|
const rawStepResult = stepToDispatch.stepToolResult;
|
|
5952
5550
|
const stepResult = rawStepResult !== void 0 && rawStepResult !== "" ? parseIfJson(rawStepResult) : canvasResult !== void 0 ? canvasResult : parseIfJson(stepToDispatch.content);
|
|
5953
5551
|
const rawStepArgs = stepToDispatch.stepToolArguments;
|
|
5954
5552
|
const rawArgsString = stepToDispatch.arguments;
|
|
5955
|
-
const canvasArgs = (
|
|
5553
|
+
const canvasArgs = (_m = (_l = stepToDispatch == null ? void 0 : stepToDispatch.canvas) == null ? void 0 : _l.canvasData) == null ? void 0 : _m.arguments;
|
|
5956
5554
|
let stepArguments = rawStepArgs && typeof rawStepArgs === "object" ? rawStepArgs : null;
|
|
5957
5555
|
if (!stepArguments && rawArgsString && rawArgsString.trim()) {
|
|
5958
5556
|
try {
|
|
@@ -6394,9 +5992,14 @@ function useMcpHostBridge(options) {
|
|
|
6394
5992
|
}
|
|
6395
5993
|
}, [toolInfo, toolArguments, toolResult, isComplete, log]);
|
|
6396
5994
|
const handleMessage = useCallback((event) => {
|
|
6397
|
-
var _a;
|
|
6398
|
-
|
|
6399
|
-
|
|
5995
|
+
var _a, _b;
|
|
5996
|
+
const source = event.source;
|
|
5997
|
+
const ourWindow = (_a = iframeRef.current) == null ? void 0 : _a.contentWindow;
|
|
5998
|
+
if (!ourWindow) {
|
|
5999
|
+
return;
|
|
6000
|
+
}
|
|
6001
|
+
if (source !== ourWindow) {
|
|
6002
|
+
return;
|
|
6400
6003
|
}
|
|
6401
6004
|
if (!event.data || event.data.jsonrpc !== "2.0")
|
|
6402
6005
|
return;
|
|
@@ -6425,15 +6028,71 @@ function useMcpHostBridge(options) {
|
|
|
6425
6028
|
}
|
|
6426
6029
|
case "ui/notifications/sandbox-ready":
|
|
6427
6030
|
case "ui/notifications/sandbox-proxy-ready": {
|
|
6428
|
-
|
|
6031
|
+
const loadedFromCache = params == null ? void 0 : params.loadedFromCache;
|
|
6429
6032
|
const resource = params == null ? void 0 : params.resource;
|
|
6430
|
-
|
|
6431
|
-
|
|
6033
|
+
const flowId = params == null ? void 0 : params.flowId;
|
|
6034
|
+
log("Proxy reported sandbox-ready, loadedFromCache:", loadedFromCache, "resource:", resource);
|
|
6035
|
+
if (loadedFromCache) {
|
|
6036
|
+
log("Proxy loaded from cache, skipping sandbox-resource-ready");
|
|
6037
|
+
break;
|
|
6038
|
+
}
|
|
6039
|
+
if (!resource) {
|
|
6040
|
+
log("No resource in sandbox-ready, cannot send HTML");
|
|
6041
|
+
break;
|
|
6042
|
+
}
|
|
6043
|
+
const cacheKey = `${flowId || "unknown"}|${resource}`;
|
|
6044
|
+
if (sandboxResourceCacheRef.current.has(cacheKey)) {
|
|
6045
|
+
const cached = sandboxResourceCacheRef.current.get(cacheKey);
|
|
6046
|
+
log("Using cached sandbox resource for:", resource);
|
|
6432
6047
|
sendNotification("ui/notifications/sandbox-resource-ready", {
|
|
6433
6048
|
resource,
|
|
6049
|
+
flowId,
|
|
6050
|
+
...cached
|
|
6051
|
+
});
|
|
6052
|
+
break;
|
|
6053
|
+
}
|
|
6054
|
+
if (html) {
|
|
6055
|
+
log("Using inline HTML for sandbox-ready:", resource);
|
|
6056
|
+
const entry = {
|
|
6434
6057
|
html,
|
|
6435
6058
|
sandbox: "allow-scripts allow-same-origin"
|
|
6059
|
+
};
|
|
6060
|
+
sandboxResourceCacheRef.current.set(cacheKey, entry);
|
|
6061
|
+
sendNotification("ui/notifications/sandbox-resource-ready", {
|
|
6062
|
+
resource,
|
|
6063
|
+
flowId,
|
|
6064
|
+
...entry
|
|
6436
6065
|
});
|
|
6066
|
+
break;
|
|
6067
|
+
}
|
|
6068
|
+
if (onSandboxResourceRequest) {
|
|
6069
|
+
(async () => {
|
|
6070
|
+
try {
|
|
6071
|
+
log("Calling onSandboxResourceRequest for sandbox-ready:", resource);
|
|
6072
|
+
const resolved = await onSandboxResourceRequest({ resource, flowId });
|
|
6073
|
+
const payload = typeof resolved === "string" ? { html: resolved } : resolved;
|
|
6074
|
+
if (payload == null ? void 0 : payload.html) {
|
|
6075
|
+
log("Got HTML from onSandboxResourceRequest for:", resource, "length:", payload.html.length);
|
|
6076
|
+
const entry = {
|
|
6077
|
+
html: payload.html,
|
|
6078
|
+
sandbox: payload.sandbox || "allow-scripts allow-same-origin",
|
|
6079
|
+
csp: payload.csp
|
|
6080
|
+
};
|
|
6081
|
+
sandboxResourceCacheRef.current.set(cacheKey, entry);
|
|
6082
|
+
sendNotification("ui/notifications/sandbox-resource-ready", {
|
|
6083
|
+
resource,
|
|
6084
|
+
flowId,
|
|
6085
|
+
...entry
|
|
6086
|
+
});
|
|
6087
|
+
} else {
|
|
6088
|
+
log("onSandboxResourceRequest returned no HTML for:", resource);
|
|
6089
|
+
}
|
|
6090
|
+
} catch (err) {
|
|
6091
|
+
console.warn("[useMcpHostBridge] Failed to resolve sandbox resource on sandbox-ready:", err);
|
|
6092
|
+
}
|
|
6093
|
+
})();
|
|
6094
|
+
} else {
|
|
6095
|
+
log("No onSandboxResourceRequest handler and no inline HTML for:", resource);
|
|
6437
6096
|
}
|
|
6438
6097
|
break;
|
|
6439
6098
|
}
|
|
@@ -6507,7 +6166,7 @@ function useMcpHostBridge(options) {
|
|
|
6507
6166
|
}
|
|
6508
6167
|
setIframeState("ready");
|
|
6509
6168
|
sendHydrationData();
|
|
6510
|
-
if (pendingNotificationsRef.current.length > 0 && ((
|
|
6169
|
+
if (pendingNotificationsRef.current.length > 0 && ((_b = iframeRef.current) == null ? void 0 : _b.contentWindow)) {
|
|
6511
6170
|
log(`Replaying ${pendingNotificationsRef.current.length} queued notifications`);
|
|
6512
6171
|
pendingNotificationsRef.current.forEach(({ method: method2, params: params2 }) => {
|
|
6513
6172
|
iframeRef.current.contentWindow.postMessage({ jsonrpc: "2.0", method: method2, params: params2 }, "*");
|
|
@@ -7127,9 +6786,6 @@ function extractMcpAppData(step, options) {
|
|
|
7127
6786
|
toolInfo: toolName ? { tool: { name: toolName } } : void 0
|
|
7128
6787
|
};
|
|
7129
6788
|
}
|
|
7130
|
-
|
|
7131
|
-
// src/index.tsx
|
|
7132
|
-
var import_sdk_types3 = __toESM(require_lib());
|
|
7133
6789
|
var CanvasContext = createContext(null);
|
|
7134
6790
|
var DEFAULT_ACK_TTL_MS = 3 * 60 * 1e3;
|
|
7135
6791
|
var DEFAULT_RESPONSE_TIMEOUT_MS = 2e4;
|
|
@@ -8017,16 +7673,7 @@ function useBotDojoCanvas() {
|
|
|
8017
7673
|
}
|
|
8018
7674
|
return context;
|
|
8019
7675
|
}
|
|
8020
|
-
var export_MIME_TYPES = import_sdk_types3.MIME_TYPES;
|
|
8021
|
-
var export_citation = import_sdk_types3.citation;
|
|
8022
|
-
var export_citations = import_sdk_types3.citations;
|
|
8023
|
-
var export_imageResult = import_sdk_types3.imageResult;
|
|
8024
|
-
var export_mcpResource = import_sdk_types3.mcpResource;
|
|
8025
|
-
var export_modelContext = import_sdk_types3.modelContext;
|
|
8026
|
-
var export_textResult = import_sdk_types3.textResult;
|
|
8027
|
-
var export_tool = import_sdk_types3.tool;
|
|
8028
|
-
var export_uiResource = import_sdk_types3.uiResource;
|
|
8029
7676
|
|
|
8030
|
-
export { BotDojoCanvasFrame, BotDojoCanvasProvider, BotDojoChat, BotDojoChatProvider, BotDojoConnector, DEFAULT_MCP_HOST_CAPABILITIES, HeadlessChat,
|
|
7677
|
+
export { BotDojoCanvasFrame, BotDojoCanvasProvider, BotDojoChat, BotDojoChatProvider, BotDojoConnector, DEFAULT_MCP_HOST_CAPABILITIES, HeadlessChat, MIME_TYPES, McpAppHost, McpAppHostContext, McpAppHostProvider, MockCanvasProvider, RequestEvents, buildMcpCacheKey, buildMcpProxyUrl, citation, citations, createMcpHtmlProxy, extractMcpAppData, extractUiCspFromResource, getContentKey, imageResult, mcpResource, modelContext, parseMaybeJson2 as parseMaybeJson, processStepUpdate, resolveUiCsp, textResult, tool, uiResource, useBotDojoCanvas, useBotDojoChat, useChatActions, useChatMessages, useChatStatus, useMcpAppHost, useMcpAppHostRequired, useMcpHostBridge, validateToolParams };
|
|
8031
7678
|
//# sourceMappingURL=out.js.map
|
|
8032
7679
|
//# sourceMappingURL=index.js.map
|