@botdojo/chat-sdk 0.0.12 → 0.0.14

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
@@ -205,6 +205,11 @@ interface BotDojoChatProps {
205
205
  * Override the welcome message shown in the chat widget (supports markdown)
206
206
  */
207
207
  welcomeMessage?: string;
208
+ /**
209
+ * Whether to auto-focus the chat input on load
210
+ * @default true for popup/side-panel modes, false for inline mode
211
+ */
212
+ autoFocus?: boolean;
208
213
  /**
209
214
  * Allow microphone access in iframe
210
215
  * @default false
package/lib/index.js CHANGED
@@ -2325,7 +2325,7 @@ var require_BotDojoConnector = __commonJS({
2325
2325
  }
2326
2326
  };
2327
2327
  exports.RequestEvents = RequestEvents;
2328
- var BotDojoConnector5 = class {
2328
+ var BotDojoConnector6 = class {
2329
2329
  constructor(props) {
2330
2330
  this.sessionId = null;
2331
2331
  this.modelContext = null;
@@ -2518,40 +2518,40 @@ var require_BotDojoConnector = __commonJS({
2518
2518
  const displayName = ((_c = tool2._meta) === null || _c === void 0 ? void 0 : _c["botdojo/display-name"]) || toolName;
2519
2519
  this.connection.callbacks.set(toolName, {
2520
2520
  source: this.connection.sender,
2521
- func: async (...args) => {
2522
- var _a2;
2523
- const firstArg = args[0];
2524
- const argCanvasId = (firstArg === null || firstArg === void 0 ? void 0 : firstArg.__canvasId) || (firstArg === null || firstArg === void 0 ? void 0 : firstArg.canvasId) || (firstArg === null || firstArg === void 0 ? void 0 : firstArg.canvas_id);
2525
- const argStepId = (_a2 = firstArg === null || firstArg === void 0 ? void 0 : firstArg.__stepId) !== null && _a2 !== void 0 ? _a2 : argCanvasId;
2526
- const fallbackCanvasId = this.defaultCanvasId || this.getCanvasIdFromUrl() || this.generateChannelId();
2521
+ // Callback receives (toolArgs, toolContext) where toolContext = { stepId, canvasId }
2522
+ func: async (toolArgs, toolContext) => {
2523
+ const stepId = toolContext === null || toolContext === void 0 ? void 0 : toolContext.stepId;
2524
+ const canvasId = toolContext === null || toolContext === void 0 ? void 0 : toolContext.canvasId;
2525
+ if (!stepId) {
2526
+ console.warn(`[BotDojoConnector] Tool ${toolName} called without stepId in toolContext`);
2527
+ }
2527
2528
  if (hasResourceTemplate) {
2528
- const canvasId = argCanvasId || fallbackCanvasId;
2529
- const stepId = argStepId !== null && argStepId !== void 0 ? argStepId : canvasId;
2530
2529
  const baseToolInfo2 = {
2531
2530
  toolName,
2532
2531
  toolLabel: displayName,
2533
- arguments: firstArg
2532
+ arguments: toolArgs
2534
2533
  };
2535
- if (!canvasId && !stepId) {
2536
- console.warn(`[BotDojoConnector] Tool has resource template but no __canvasId/__stepId found in arguments`, firstArg);
2534
+ if (!canvasId) {
2535
+ console.warn(`[BotDojoConnector] Canvas tool ${toolName} called without canvasId in toolContext`);
2537
2536
  }
2538
2537
  const canvasType = "mcp-app";
2539
- const context2 = {
2538
+ const toolExecContext2 = {
2540
2539
  toolName,
2540
+ stepId,
2541
2541
  canvasId,
2542
2542
  updateState: async (state) => {
2543
2543
  if (canvasId || stepId) {
2544
2544
  await this.sendCanvasUpdate(stepId, canvasId, state, canvasType, baseToolInfo2);
2545
2545
  }
2546
2546
  },
2547
- notifyToolInputPartial: async (args2) => {
2547
+ notifyToolInputPartial: async (args) => {
2548
2548
  if (canvasId || stepId) {
2549
- await this.sendCanvasUpdate(stepId, canvasId, void 0, canvasType, Object.assign(Object.assign({}, baseToolInfo2), { arguments: args2 }));
2549
+ await this.sendCanvasUpdate(stepId, canvasId, void 0, canvasType, Object.assign(Object.assign({}, baseToolInfo2), { arguments: args }));
2550
2550
  }
2551
2551
  },
2552
- notifyToolInput: async (args2) => {
2552
+ notifyToolInput: async (args) => {
2553
2553
  if (canvasId || stepId) {
2554
- await this.sendCanvasUpdate(stepId, canvasId, void 0, canvasType, Object.assign(Object.assign({}, baseToolInfo2), { arguments: args2 }));
2554
+ await this.sendCanvasUpdate(stepId, canvasId, void 0, canvasType, Object.assign(Object.assign({}, baseToolInfo2), { arguments: args }));
2555
2555
  }
2556
2556
  },
2557
2557
  notifyToolResult: async (result) => {
@@ -2560,35 +2560,34 @@ var require_BotDojoConnector = __commonJS({
2560
2560
  }
2561
2561
  }
2562
2562
  };
2563
- const rawresult = await tool2.execute(...args, context2);
2564
- await context2.notifyToolResult(rawresult);
2563
+ const rawresult = await tool2.execute(toolArgs, toolExecContext2);
2564
+ await toolExecContext2.notifyToolResult(rawresult);
2565
2565
  return await (0, sdk_types_1.mapToolResponseToBackend)(rawresult);
2566
2566
  }
2567
- const defaultCanvasId = argCanvasId || fallbackCanvasId;
2568
- const defaultStepId = argStepId !== null && argStepId !== void 0 ? argStepId : defaultCanvasId;
2569
2567
  const baseToolInfo = {
2570
2568
  toolName,
2571
2569
  toolLabel: displayName,
2572
- arguments: firstArg
2570
+ arguments: toolArgs
2573
2571
  };
2574
- const context = {
2572
+ const toolExecContext = {
2575
2573
  toolName,
2576
- canvasId: defaultCanvasId,
2574
+ stepId,
2575
+ canvasId,
2577
2576
  updateState: async (state) => {
2578
- await this.sendCanvasUpdate(defaultStepId, defaultCanvasId, state, void 0, baseToolInfo);
2577
+ await this.sendCanvasUpdate(stepId, canvasId, state, void 0, baseToolInfo);
2579
2578
  },
2580
- notifyToolInputPartial: async (args2) => {
2581
- await this.sendCanvasUpdate(defaultStepId, defaultCanvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { arguments: args2 }));
2579
+ notifyToolInputPartial: async (args) => {
2580
+ await this.sendCanvasUpdate(stepId, canvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { arguments: args }));
2582
2581
  },
2583
- notifyToolInput: async (args2) => {
2584
- await this.sendCanvasUpdate(defaultStepId, defaultCanvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { arguments: args2 }));
2582
+ notifyToolInput: async (args) => {
2583
+ await this.sendCanvasUpdate(stepId, canvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { arguments: args }));
2585
2584
  },
2586
2585
  notifyToolResult: async (result) => {
2587
- await this.sendCanvasUpdate(defaultStepId, defaultCanvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { result }));
2586
+ await this.sendCanvasUpdate(stepId, canvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { result }));
2588
2587
  }
2589
2588
  };
2590
- const rawResult = await tool2.execute(...args, context);
2591
- await context.notifyToolResult(rawResult);
2589
+ const rawResult = await tool2.execute(toolArgs, toolExecContext);
2590
+ await toolExecContext.notifyToolResult(rawResult);
2592
2591
  return await (0, sdk_types_1.mapToolResponseToBackend)(rawResult);
2593
2592
  }
2594
2593
  });
@@ -2910,29 +2909,29 @@ var require_BotDojoConnector = __commonJS({
2910
2909
  console.log(`\u{1F527} Registering modelContext tool on host client: ${toolName}, hasResource: ${hasResourceTemplate}`);
2911
2910
  this._hostClient.callbacks.set(toolName, {
2912
2911
  source: this._hostClient.sender,
2913
- func: async (...args) => {
2914
- var _a2;
2915
- console.log(`\u{1F527} Executing modelContext tool: ${toolName} with args:`, args);
2912
+ // Callback receives (toolArgs, toolContext) where toolContext = { stepId, canvasId }
2913
+ func: async (toolArgs, toolContext) => {
2914
+ console.log(`\u{1F527} Executing modelContext tool: ${toolName}`, { toolArgs, toolContext });
2916
2915
  try {
2917
- const firstArg = args[0];
2918
- const argCanvasId = (firstArg === null || firstArg === void 0 ? void 0 : firstArg.__canvasId) || (firstArg === null || firstArg === void 0 ? void 0 : firstArg.canvasId) || (firstArg === null || firstArg === void 0 ? void 0 : firstArg.canvas_id);
2919
- const argStepId = (_a2 = firstArg === null || firstArg === void 0 ? void 0 : firstArg.__stepId) !== null && _a2 !== void 0 ? _a2 : argCanvasId;
2920
- const fallbackCanvasId = this.defaultCanvasId || this.getCanvasIdFromUrl() || this.generateChannelId();
2916
+ const stepId = toolContext === null || toolContext === void 0 ? void 0 : toolContext.stepId;
2917
+ const canvasId = toolContext === null || toolContext === void 0 ? void 0 : toolContext.canvasId;
2918
+ if (!stepId) {
2919
+ console.warn(`[BotDojoConnector hostClient] Tool ${toolName} called without stepId in toolContext`);
2920
+ }
2921
2921
  if (hasResourceTemplate) {
2922
- const canvasId = argCanvasId || fallbackCanvasId;
2923
- const stepId = argStepId !== null && argStepId !== void 0 ? argStepId : canvasId;
2924
2922
  const baseToolInfo2 = {
2925
2923
  toolName,
2926
2924
  toolLabel: displayName,
2927
- arguments: firstArg
2925
+ arguments: toolArgs
2928
2926
  };
2929
- if (!canvasId && !stepId) {
2930
- console.warn(`[BotDojoConnector hostClient] Tool has resource template but no __canvasId/__stepId found in arguments`, firstArg);
2927
+ if (!canvasId) {
2928
+ console.warn(`[BotDojoConnector hostClient] Canvas tool ${toolName} called without canvasId in toolContext`);
2931
2929
  }
2932
2930
  console.log(`[BotDojoConnector hostClient] Tool has resource, ids \u2192 step: ${stepId}, canvas: ${canvasId}`);
2933
2931
  const canvasType = "mcp-app";
2934
- const context2 = {
2932
+ const toolExecContext2 = {
2935
2933
  toolName,
2934
+ stepId,
2936
2935
  canvasId,
2937
2936
  updateState: async (state) => {
2938
2937
  console.log(`[BotDojoConnector hostClient] updateState called for canvasId: ${canvasId !== null && canvasId !== void 0 ? canvasId : stepId}`, state);
@@ -2940,14 +2939,14 @@ var require_BotDojoConnector = __commonJS({
2940
2939
  await this.sendCanvasUpdate(stepId, canvasId, state, canvasType, baseToolInfo2);
2941
2940
  }
2942
2941
  },
2943
- notifyToolInputPartial: async (args2) => {
2942
+ notifyToolInputPartial: async (args) => {
2944
2943
  if (canvasId || stepId) {
2945
- await this.sendCanvasUpdate(stepId, canvasId, void 0, canvasType, Object.assign(Object.assign({}, baseToolInfo2), { arguments: args2 }));
2944
+ await this.sendCanvasUpdate(stepId, canvasId, void 0, canvasType, Object.assign(Object.assign({}, baseToolInfo2), { arguments: args }));
2946
2945
  }
2947
2946
  },
2948
- notifyToolInput: async (args2) => {
2947
+ notifyToolInput: async (args) => {
2949
2948
  if (canvasId || stepId) {
2950
- await this.sendCanvasUpdate(stepId, canvasId, void 0, canvasType, Object.assign(Object.assign({}, baseToolInfo2), { arguments: args2 }));
2949
+ await this.sendCanvasUpdate(stepId, canvasId, void 0, canvasType, Object.assign(Object.assign({}, baseToolInfo2), { arguments: args }));
2951
2950
  }
2952
2951
  },
2953
2952
  notifyToolResult: async (result3) => {
@@ -2956,37 +2955,36 @@ var require_BotDojoConnector = __commonJS({
2956
2955
  }
2957
2956
  }
2958
2957
  };
2959
- const rawresult2 = await tool2.execute(...args, context2);
2960
- await context2.notifyToolResult(rawresult2);
2958
+ const rawresult2 = await tool2.execute(toolArgs, toolExecContext2);
2959
+ await toolExecContext2.notifyToolResult(rawresult2);
2961
2960
  const result2 = await (0, sdk_types_1.mapToolResponseToBackend)(rawresult2);
2962
2961
  console.log(`\u2705 Tool executed successfully: ${toolName}`);
2963
2962
  return result2;
2964
2963
  }
2965
- const defaultCanvasId = argCanvasId || fallbackCanvasId;
2966
- const defaultStepId = argStepId !== null && argStepId !== void 0 ? argStepId : defaultCanvasId;
2967
2964
  const baseToolInfo = {
2968
2965
  toolName,
2969
2966
  toolLabel: displayName,
2970
- arguments: firstArg
2967
+ arguments: toolArgs
2971
2968
  };
2972
- const context = {
2969
+ const toolExecContext = {
2973
2970
  toolName,
2974
- canvasId: defaultCanvasId,
2971
+ stepId,
2972
+ canvasId,
2975
2973
  updateState: async (state) => {
2976
- await this.sendCanvasUpdate(defaultStepId, defaultCanvasId, state, void 0, baseToolInfo);
2974
+ await this.sendCanvasUpdate(stepId, canvasId, state, void 0, baseToolInfo);
2977
2975
  },
2978
- notifyToolInputPartial: async (args2) => {
2979
- await this.sendCanvasUpdate(defaultStepId, defaultCanvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { arguments: args2 }));
2976
+ notifyToolInputPartial: async (args) => {
2977
+ await this.sendCanvasUpdate(stepId, canvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { arguments: args }));
2980
2978
  },
2981
- notifyToolInput: async (args2) => {
2982
- await this.sendCanvasUpdate(defaultStepId, defaultCanvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { arguments: args2 }));
2979
+ notifyToolInput: async (args) => {
2980
+ await this.sendCanvasUpdate(stepId, canvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { arguments: args }));
2983
2981
  },
2984
2982
  notifyToolResult: async (result2) => {
2985
- await this.sendCanvasUpdate(defaultStepId, defaultCanvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { result: result2 }));
2983
+ await this.sendCanvasUpdate(stepId, canvasId, void 0, void 0, Object.assign(Object.assign({}, baseToolInfo), { result: result2 }));
2986
2984
  }
2987
2985
  };
2988
- const rawresult = await tool2.execute(...args, context);
2989
- await context.notifyToolResult(rawresult);
2986
+ const rawresult = await tool2.execute(toolArgs, toolExecContext);
2987
+ await toolExecContext.notifyToolResult(rawresult);
2990
2988
  const result = await (0, sdk_types_1.mapToolResponseToBackend)(rawresult);
2991
2989
  console.log(`\u2705 Tool executed successfully: ${toolName}`);
2992
2990
  return result;
@@ -3169,45 +3167,28 @@ var require_BotDojoConnector = __commonJS({
3169
3167
  * @param stepId - Optional step ID for canvas updates (if tool has canvas template)
3170
3168
  */
3171
3169
  async executeToolCall(toolName, ...args) {
3172
- var _a, _b, _c;
3173
- let stepId;
3174
- let canvasId;
3175
- let toolArgs = args;
3176
- if (args.length > 0 && typeof args[args.length - 1] === "object" && (((_a = args[args.length - 1]) === null || _a === void 0 ? void 0 : _a.__stepId) || ((_b = args[args.length - 1]) === null || _b === void 0 ? void 0 : _b.__canvasId))) {
3177
- const options = args[args.length - 1];
3178
- stepId = options.__stepId;
3179
- canvasId = options.__canvasId;
3180
- toolArgs = args.slice(0, -1);
3181
- }
3182
- const firstArg = toolArgs[0];
3183
- if (typeof firstArg === "object") {
3184
- canvasId = canvasId !== null && canvasId !== void 0 ? canvasId : firstArg === null || firstArg === void 0 ? void 0 : firstArg.__canvasId;
3185
- stepId = (_c = stepId !== null && stepId !== void 0 ? stepId : firstArg === null || firstArg === void 0 ? void 0 : firstArg.__stepId) !== null && _c !== void 0 ? _c : canvasId;
3186
- }
3187
3170
  console.log("[BotDojoConnector] executeToolCall", {
3188
3171
  transport: this.transport,
3189
3172
  hasConnection: !!this.connection,
3190
3173
  hasHostClient: !!this._hostClient,
3191
3174
  hasInit: this.hasInit,
3192
- stepId,
3193
- canvasId,
3194
3175
  toolName,
3195
- args: toolArgs
3176
+ args
3196
3177
  });
3197
3178
  if (this.transport === "postmessage" && this.connection) {
3198
3179
  const currentOrigin = typeof window !== "undefined" ? window.location.origin : "unknown";
3199
3180
  console.log(`[BotDojoConnector] [CORS DEBUG] Executing tool via PostMessage RPCConnection: ${toolName}`, {
3200
3181
  toolName,
3201
3182
  currentOrigin,
3202
- toolArgs,
3183
+ args,
3203
3184
  hasConnection: !!this.connection,
3204
3185
  connectorClientId: this.clientId
3205
3186
  });
3206
- return await this.connection.sendRequest("agent_host", toolName, toolArgs, 3e4);
3187
+ return await this.connection.sendRequest("agent_host", toolName, args, 3e4);
3207
3188
  }
3208
3189
  if (this._hostClient) {
3209
- console.log(`[BotDojoConnector] Executing tool via Socket.IO RPCConnection: ${toolName}`, toolArgs);
3210
- return await this._hostClient.sendRequest("agent_host", toolName, toolArgs, 3e4);
3190
+ console.log(`[BotDojoConnector] Executing tool via Socket.IO RPCConnection: ${toolName}`, args);
3191
+ return await this._hostClient.sendRequest("agent_host", toolName, args, 3e4);
3211
3192
  }
3212
3193
  throw new Error(`No connection available for tool call: ${toolName}. Tools must be executed remotely via ModelContext.`);
3213
3194
  }
@@ -3347,7 +3328,7 @@ var require_BotDojoConnector = __commonJS({
3347
3328
  }
3348
3329
  }
3349
3330
  };
3350
- exports.BotDojoConnector = BotDojoConnector5;
3331
+ exports.BotDojoConnector = BotDojoConnector6;
3351
3332
  var botdojo_rpc_2 = require_src();
3352
3333
  Object.defineProperty(exports, "detectTransportFromURL", { enumerable: true, get: function() {
3353
3334
  return botdojo_rpc_2.detectTransportFromURL;
@@ -7639,7 +7620,7 @@ var require_uiCsp = __commonJS({
7639
7620
  function buildSources(base, domains, extras = []) {
7640
7621
  return uniq([...base, ...domains, ...extras].map((v) => sanitizeSource(v || "")).filter(Boolean));
7641
7622
  }
7642
- function resolveUiCsp2(meta) {
7623
+ function resolveUiCsp3(meta) {
7643
7624
  const merged = Object.assign(Object.assign({}, DEFAULT_CSP_META), meta || {});
7644
7625
  const connectDomains = ensureArray(merged.connectDomains);
7645
7626
  const resourceDomains = ensureArray(merged.resourceDomains);
@@ -7681,8 +7662,8 @@ var require_uiCsp = __commonJS({
7681
7662
  meta: merged
7682
7663
  };
7683
7664
  }
7684
- exports.resolveUiCsp = resolveUiCsp2;
7685
- function extractUiCspFromResource2(resource) {
7665
+ exports.resolveUiCsp = resolveUiCsp3;
7666
+ function extractUiCspFromResource3(resource) {
7686
7667
  var _a, _b, _c;
7687
7668
  if (!resource || typeof resource !== "object")
7688
7669
  return void 0;
@@ -7690,7 +7671,7 @@ var require_uiCsp = __commonJS({
7690
7671
  const csp = uiMeta === null || uiMeta === void 0 ? void 0 : uiMeta.csp;
7691
7672
  return csp || void 0;
7692
7673
  }
7693
- exports.extractUiCspFromResource = extractUiCspFromResource2;
7674
+ exports.extractUiCspFromResource = extractUiCspFromResource3;
7694
7675
  }
7695
7676
  });
7696
7677
 
@@ -8267,6 +8248,7 @@ var BotDojoChat = ({
8267
8248
  sessionId,
8268
8249
  sessionKeyPrefix,
8269
8250
  welcomeMessage,
8251
+ autoFocus,
8270
8252
  allowMicrophone = false,
8271
8253
  baseUrl,
8272
8254
  modelContext: modelContext2,
@@ -8387,6 +8369,7 @@ var BotDojoChat = ({
8387
8369
  return "https://embed.botdojo.com";
8388
8370
  }, [baseUrl]);
8389
8371
  const hasEventCallbacks = !!(onReady || onError || onMessageStart || onMessageComplete || onStepUpdate || onToken || onSessionCreated || onSessionHydrated || onRequestAborted);
8372
+ const effectiveAutoFocus = autoFocus != null ? autoFocus : mode !== "inline";
8390
8373
  console.log("[BotDojoChat] hasEventCallbacks:", hasEventCallbacks, {
8391
8374
  onReady: !!onReady,
8392
8375
  onToken: !!onToken,
@@ -8424,6 +8407,9 @@ var BotDojoChat = ({
8424
8407
  url2.searchParams.set("theme", theme);
8425
8408
  if (newSession)
8426
8409
  url2.searchParams.set("new-session", "true");
8410
+ if (!effectiveAutoFocus) {
8411
+ url2.searchParams.set("auto-focus", "false");
8412
+ }
8427
8413
  url2.searchParams.set("transport", "postmessage");
8428
8414
  url2.searchParams.set("transport-mode", "iframe");
8429
8415
  if (hasEventCallbacks) {
@@ -8454,6 +8440,7 @@ var BotDojoChat = ({
8454
8440
  backgroundColor,
8455
8441
  theme,
8456
8442
  newSession,
8443
+ effectiveAutoFocus,
8457
8444
  hasEventCallbacks
8458
8445
  ]);
8459
8446
  useEffect(() => {
@@ -10150,6 +10137,7 @@ function chatReducer(state, action) {
10150
10137
  }
10151
10138
 
10152
10139
  // src/headless/context/BotDojoChatProvider.tsx
10140
+ var import_sdk_canvas3 = __toESM(require_src3());
10153
10141
  var import_sdk_types = __toESM(require_lib());
10154
10142
  var import_botdojo_rpc2 = __toESM(require_src());
10155
10143
 
@@ -10767,8 +10755,29 @@ function BotDojoChatProvider(props) {
10767
10755
  try {
10768
10756
  const resource = await getResource(canvasUrl);
10769
10757
  console.log("[BotDojoChatProvider] Resource result:", resource ? "got content" : "no content");
10770
- const htmlContent = (resource == null ? void 0 : resource.text) || (resource == null ? void 0 : resource.content);
10758
+ let htmlContent = (resource == null ? void 0 : resource.text) || (resource == null ? void 0 : resource.content);
10771
10759
  if (htmlContent) {
10760
+ const cspMeta = (0, import_sdk_canvas3.extractUiCspFromResource)(resource);
10761
+ if (cspMeta) {
10762
+ const resolvedCsp = (0, import_sdk_canvas3.resolveUiCsp)(cspMeta);
10763
+ console.log("[BotDojoChatProvider] Injecting CSP into HTML:", resolvedCsp.csp.substring(0, 100) + "...");
10764
+ const cspMetaTag = `<meta http-equiv="Content-Security-Policy" content="${resolvedCsp.csp.replace(/"/g, "&quot;")}">`;
10765
+ if (/<head[^>]*>/i.test(htmlContent)) {
10766
+ htmlContent = htmlContent.replace(/<head([^>]*)>/i, `<head$1>
10767
+ ${cspMetaTag}
10768
+ `);
10769
+ } else if (/<html[^>]*>/i.test(htmlContent)) {
10770
+ htmlContent = htmlContent.replace(/<html([^>]*)>/i, `<html$1>
10771
+ <head>
10772
+ ${cspMetaTag}
10773
+ </head>`);
10774
+ } else {
10775
+ htmlContent = `<head>
10776
+ ${cspMetaTag}
10777
+ </head>
10778
+ ${htmlContent}`;
10779
+ }
10780
+ }
10772
10781
  stepToDispatch = {
10773
10782
  ...rawStep,
10774
10783
  canvas: {
@@ -12605,12 +12614,12 @@ var BotDojoChatConfigurator = ({
12605
12614
  };
12606
12615
 
12607
12616
  // src/index.tsx
12608
- var import_sdk_canvas4 = __toESM(require_src3());
12617
+ var import_sdk_canvas5 = __toESM(require_src3());
12609
12618
  var import_sdk_types2 = __toESM(require_lib());
12610
12619
  var CanvasContext = createContext(null);
12611
12620
 
12612
12621
  // src/canvas/BotDojoCanvasProvider.tsx
12613
- var import_sdk_canvas3 = __toESM(require_src3());
12622
+ var import_sdk_canvas4 = __toESM(require_src3());
12614
12623
  var DEFAULT_ACK_TTL_MS = 3 * 60 * 1e3;
12615
12624
  var DEFAULT_RESPONSE_TIMEOUT_MS = 2e4;
12616
12625
  var MCP_FUNCTION_NAME_MAP = {
@@ -12808,7 +12817,7 @@ function BotDojoCanvasProvider({
12808
12817
  const apiKey = window.BOTDOJO_API_KEY || "embedded-canvas";
12809
12818
  let createdConnector = null;
12810
12819
  try {
12811
- const conn = new import_sdk_canvas3.BotDojoConnector({
12820
+ const conn = new import_sdk_canvas4.BotDojoConnector({
12812
12821
  apiKey,
12813
12822
  accountId: "embedded",
12814
12823
  projectId: "embedded",
@@ -13497,7 +13506,7 @@ function useBotDojoCanvas() {
13497
13506
  }
13498
13507
  return context;
13499
13508
  }
13500
- var export_BotDojoConnector = import_sdk_canvas4.BotDojoConnector;
13509
+ var export_BotDojoConnector = import_sdk_canvas5.BotDojoConnector;
13501
13510
  var export_MIME_TYPES = import_sdk_types2.MIME_TYPES;
13502
13511
  var export_citation = import_sdk_types2.citation;
13503
13512
  var export_citations = import_sdk_types2.citations;