@botdojo/chat-sdk 0.0.29 → 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 +1 -1
- package/lib/index.js +56 -38
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
12
12
|
* 1. cd packages/sdk-types
|
|
13
13
|
* 2. pnpm sync-opensource
|
|
14
14
|
*
|
|
15
|
-
* Generated: 2025-12-
|
|
15
|
+
* Generated: 2025-12-28T18:13:44.883Z
|
|
16
16
|
*/
|
|
17
17
|
/** Flow canvas configuration (stub type) */
|
|
18
18
|
interface Core_FlowCanvas {
|
package/lib/index.js
CHANGED
|
@@ -4991,7 +4991,7 @@ function BotDojoChatProvider(props) {
|
|
|
4991
4991
|
console.warn(`[BotDojoChatProvider] No step update callback registered for app: ${appId}`);
|
|
4992
4992
|
}
|
|
4993
4993
|
}, []);
|
|
4994
|
-
const executeToolCall = useCallback(async (toolName, args, targetAppId) => {
|
|
4994
|
+
const executeToolCall = useCallback(async (toolName, args, targetAppId, stepId) => {
|
|
4995
4995
|
const ctx = modelContextRef.current;
|
|
4996
4996
|
if (!ctx) {
|
|
4997
4997
|
throw new Error("No model context available");
|
|
@@ -5002,18 +5002,29 @@ function BotDojoChatProvider(props) {
|
|
|
5002
5002
|
const toolsArray = Array.isArray(context.tools) ? context.tools : Object.values(context.tools);
|
|
5003
5003
|
const tool2 = toolsArray.find((t) => t.name === toolName);
|
|
5004
5004
|
if (tool2 && typeof tool2.execute === "function") {
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
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) {
|
|
5009
5015
|
const prefixedToolName = `${context.name}_${toolName}`;
|
|
5010
|
-
|
|
5016
|
+
fromToolName = activeAppByToolRef.current.get(prefixedToolName);
|
|
5011
5017
|
}
|
|
5012
|
-
|
|
5013
|
-
|
|
5018
|
+
return fromToolName;
|
|
5019
|
+
};
|
|
5020
|
+
const initialAppId = resolveAppIdDynamic();
|
|
5021
|
+
console.log(`[BotDojoChatProvider] Executing tool "${toolName}" for app: ${initialAppId || "PENDING"}, stepId: ${stepId || "none"}`);
|
|
5014
5022
|
toolArgumentsCacheRef.current.set(toolName, args);
|
|
5015
|
-
if (
|
|
5016
|
-
toolArgumentsCacheRef.current.set(
|
|
5023
|
+
if (initialAppId) {
|
|
5024
|
+
toolArgumentsCacheRef.current.set(initialAppId, args);
|
|
5025
|
+
}
|
|
5026
|
+
if (stepId) {
|
|
5027
|
+
toolArgumentsCacheRef.current.set(stepId, args);
|
|
5017
5028
|
}
|
|
5018
5029
|
const executionContext = {
|
|
5019
5030
|
toolName,
|
|
@@ -5030,24 +5041,21 @@ function BotDojoChatProvider(props) {
|
|
|
5030
5041
|
stepToolProgress: isProgressUpdate ? data : void 0,
|
|
5031
5042
|
stepStatus: "processing"
|
|
5032
5043
|
};
|
|
5033
|
-
|
|
5034
|
-
|
|
5044
|
+
const currentAppId = resolveAppIdDynamic();
|
|
5045
|
+
if (currentAppId) {
|
|
5046
|
+
const callback = stepUpdateCallbacksRef.current.get(currentAppId);
|
|
5035
5047
|
if (callback) {
|
|
5036
|
-
console.log(`[BotDojoChatProvider] Sending partial update via step callback to: ${
|
|
5048
|
+
console.log(`[BotDojoChatProvider] Sending partial update via step callback to: ${currentAppId}`);
|
|
5037
5049
|
callback(stepUpdate);
|
|
5038
5050
|
} else {
|
|
5039
|
-
console.log(`[BotDojoChatProvider] Callback not registered for ${
|
|
5040
|
-
if (!pendingStepUpdatesRef.current.has(
|
|
5041
|
-
pendingStepUpdatesRef.current.set(
|
|
5051
|
+
console.log(`[BotDojoChatProvider] Callback not registered for ${currentAppId}, queueing`);
|
|
5052
|
+
if (!pendingStepUpdatesRef.current.has(currentAppId)) {
|
|
5053
|
+
pendingStepUpdatesRef.current.set(currentAppId, []);
|
|
5042
5054
|
}
|
|
5043
|
-
pendingStepUpdatesRef.current.get(
|
|
5055
|
+
pendingStepUpdatesRef.current.get(currentAppId).push(stepUpdate);
|
|
5044
5056
|
}
|
|
5045
5057
|
} else {
|
|
5046
|
-
console.
|
|
5047
|
-
stepUpdateCallbacksRef.current.forEach((callback, appId) => {
|
|
5048
|
-
console.log(`[BotDojoChatProvider] Sending to: ${appId}`);
|
|
5049
|
-
callback(stepUpdate);
|
|
5050
|
-
});
|
|
5058
|
+
console.warn(`[BotDojoChatProvider] Cannot route partial update - no appId resolved for ${toolName}, stepId: ${stepId}`);
|
|
5051
5059
|
}
|
|
5052
5060
|
},
|
|
5053
5061
|
notifyToolResult: async (data) => {
|
|
@@ -5060,24 +5068,21 @@ function BotDojoChatProvider(props) {
|
|
|
5060
5068
|
result: (_b = data == null ? void 0 : data.result) != null ? _b : data,
|
|
5061
5069
|
stepStatus: "complete"
|
|
5062
5070
|
};
|
|
5063
|
-
|
|
5064
|
-
|
|
5071
|
+
const currentAppId = resolveAppIdDynamic();
|
|
5072
|
+
if (currentAppId) {
|
|
5073
|
+
const callback = stepUpdateCallbacksRef.current.get(currentAppId);
|
|
5065
5074
|
if (callback) {
|
|
5066
|
-
console.log(`[BotDojoChatProvider] Sending result via step callback to: ${
|
|
5075
|
+
console.log(`[BotDojoChatProvider] Sending result via step callback to: ${currentAppId}`);
|
|
5067
5076
|
callback(stepUpdate);
|
|
5068
5077
|
} else {
|
|
5069
|
-
console.log(`[BotDojoChatProvider] Callback not registered for ${
|
|
5070
|
-
if (!pendingStepUpdatesRef.current.has(
|
|
5071
|
-
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, []);
|
|
5072
5081
|
}
|
|
5073
|
-
pendingStepUpdatesRef.current.get(
|
|
5082
|
+
pendingStepUpdatesRef.current.get(currentAppId).push(stepUpdate);
|
|
5074
5083
|
}
|
|
5075
5084
|
} else {
|
|
5076
|
-
console.
|
|
5077
|
-
stepUpdateCallbacksRef.current.forEach((callback, appId) => {
|
|
5078
|
-
console.log(`[BotDojoChatProvider] Sending result to: ${appId}`);
|
|
5079
|
-
callback(stepUpdate);
|
|
5080
|
-
});
|
|
5085
|
+
console.warn(`[BotDojoChatProvider] Cannot route tool result - no appId resolved for ${toolName}, stepId: ${stepId}`);
|
|
5081
5086
|
}
|
|
5082
5087
|
}
|
|
5083
5088
|
};
|
|
@@ -5310,11 +5315,16 @@ function BotDojoChatProvider(props) {
|
|
|
5310
5315
|
sendModelContextToHeadless();
|
|
5311
5316
|
break;
|
|
5312
5317
|
case "tool_call":
|
|
5313
|
-
debugLog(" Tool call from HeadlessEmbed:", data.toolName, "appId:", data.appId || data.canvasId || "none");
|
|
5318
|
+
debugLog(" Tool call from HeadlessEmbed:", data.toolName, "appId:", data.appId || data.canvasId || "none", "stepId:", data.stepId || "none");
|
|
5314
5319
|
(async () => {
|
|
5315
5320
|
var _a2, _b, _c, _d;
|
|
5316
5321
|
try {
|
|
5317
|
-
|
|
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);
|
|
5318
5328
|
console.log(`[BotDojoChatProvider] \u2705 Tool "${data.toolName}" executed successfully`);
|
|
5319
5329
|
(_b = (_a2 = iframeRef.current) == null ? void 0 : _a2.contentWindow) == null ? void 0 : _b.postMessage({
|
|
5320
5330
|
type: "tool_response",
|
|
@@ -5982,7 +5992,15 @@ function useMcpHostBridge(options) {
|
|
|
5982
5992
|
}
|
|
5983
5993
|
}, [toolInfo, toolArguments, toolResult, isComplete, log]);
|
|
5984
5994
|
const handleMessage = useCallback((event) => {
|
|
5985
|
-
var _a;
|
|
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;
|
|
6003
|
+
}
|
|
5986
6004
|
if (!event.data || event.data.jsonrpc !== "2.0")
|
|
5987
6005
|
return;
|
|
5988
6006
|
const data = event.data;
|
|
@@ -6148,7 +6166,7 @@ function useMcpHostBridge(options) {
|
|
|
6148
6166
|
}
|
|
6149
6167
|
setIframeState("ready");
|
|
6150
6168
|
sendHydrationData();
|
|
6151
|
-
if (pendingNotificationsRef.current.length > 0 && ((
|
|
6169
|
+
if (pendingNotificationsRef.current.length > 0 && ((_b = iframeRef.current) == null ? void 0 : _b.contentWindow)) {
|
|
6152
6170
|
log(`Replaying ${pendingNotificationsRef.current.length} queued notifications`);
|
|
6153
6171
|
pendingNotificationsRef.current.forEach(({ method: method2, params: params2 }) => {
|
|
6154
6172
|
iframeRef.current.contentWindow.postMessage({ jsonrpc: "2.0", method: method2, params: params2 }, "*");
|