@mcp-use/client 2.1.1 → 2.1.2
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/dist/.tsbuildinfo +1 -1
- package/dist/index-browser.js +1 -1
- package/dist/index.js +1 -1
- package/dist/react/index.js +55 -32
- package/dist/react/index.js.map +1 -1
- package/dist/react/view/ViewRenderer.d.ts.map +1 -1
- package/dist/react/view/initialized-sync.d.ts +13 -0
- package/dist/react/view/initialized-sync.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index-browser.js
CHANGED
package/dist/index.js
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -1926,7 +1926,7 @@ var HttpConnector = class extends BaseConnector {
|
|
|
1926
1926
|
};
|
|
1927
1927
|
|
|
1928
1928
|
// src/utils/version.ts
|
|
1929
|
-
var VERSION = "2.1.
|
|
1929
|
+
var VERSION = "2.1.2";
|
|
1930
1930
|
function getPackageVersion() {
|
|
1931
1931
|
return VERSION;
|
|
1932
1932
|
}
|
|
@@ -8057,6 +8057,24 @@ function insertAt(value, index, addition) {
|
|
|
8057
8057
|
return value.slice(0, index) + addition + value.slice(index);
|
|
8058
8058
|
}
|
|
8059
8059
|
|
|
8060
|
+
// src/react/view/initialized-sync.ts
|
|
8061
|
+
function installInitializedSync(bridge, synchronize, onLaterError) {
|
|
8062
|
+
const previous = bridge.oninitialized;
|
|
8063
|
+
let sawFirstInitialization = false;
|
|
8064
|
+
return new Promise((resolve, reject) => {
|
|
8065
|
+
bridge.oninitialized = (...args) => {
|
|
8066
|
+
previous?.(...args);
|
|
8067
|
+
const synchronization = Promise.resolve().then(synchronize);
|
|
8068
|
+
if (!sawFirstInitialization) {
|
|
8069
|
+
sawFirstInitialization = true;
|
|
8070
|
+
synchronization.then(resolve, reject);
|
|
8071
|
+
return;
|
|
8072
|
+
}
|
|
8073
|
+
void synchronization.catch(onLaterError);
|
|
8074
|
+
};
|
|
8075
|
+
});
|
|
8076
|
+
}
|
|
8077
|
+
|
|
8060
8078
|
// src/react/view/resolve-view-resource.ts
|
|
8061
8079
|
function resolveViewResource(options) {
|
|
8062
8080
|
const { resourceResult, listingResource, cspMode, resourceUri } = options;
|
|
@@ -8589,16 +8607,6 @@ function waitForSandboxProxyReady(iframe) {
|
|
|
8589
8607
|
window.addEventListener("message", listener);
|
|
8590
8608
|
});
|
|
8591
8609
|
}
|
|
8592
|
-
function hookInitialized(bridge) {
|
|
8593
|
-
const prev = bridge.oninitialized;
|
|
8594
|
-
return new Promise((resolve) => {
|
|
8595
|
-
bridge.oninitialized = (...args) => {
|
|
8596
|
-
resolve();
|
|
8597
|
-
bridge.oninitialized = prev;
|
|
8598
|
-
prev?.(...args);
|
|
8599
|
-
};
|
|
8600
|
-
});
|
|
8601
|
-
}
|
|
8602
8610
|
function buildToolResultPayload(toolOutput, customProps) {
|
|
8603
8611
|
const structuredContent = parseCustomProps(customProps);
|
|
8604
8612
|
if (Object.keys(structuredContent).length > 0) {
|
|
@@ -9085,7 +9093,42 @@ function ViewRendererBase({
|
|
|
9085
9093
|
await publishAppTools();
|
|
9086
9094
|
}
|
|
9087
9095
|
);
|
|
9088
|
-
const
|
|
9096
|
+
const syncGuestToolState = async () => {
|
|
9097
|
+
if (!bridge || disposed) return;
|
|
9098
|
+
const currentPartialToolInput = partialToolInputRef.current;
|
|
9099
|
+
const hasCompletedToolResult = toolOutputRef.current !== void 0 && toolOutputRef.current !== null;
|
|
9100
|
+
if (currentPartialToolInput && !hasCompletedToolResult) {
|
|
9101
|
+
await bridge.sendToolInputPartial({
|
|
9102
|
+
arguments: currentPartialToolInput
|
|
9103
|
+
});
|
|
9104
|
+
} else {
|
|
9105
|
+
const mergedArgs = {
|
|
9106
|
+
...toolInputRef.current,
|
|
9107
|
+
...parseCustomProps(customPropsRef.current)
|
|
9108
|
+
};
|
|
9109
|
+
await bridge.sendToolInput({ arguments: mergedArgs });
|
|
9110
|
+
}
|
|
9111
|
+
const toolResultPayload = buildToolResultPayload(
|
|
9112
|
+
toolOutputRef.current,
|
|
9113
|
+
customPropsRef.current
|
|
9114
|
+
);
|
|
9115
|
+
if (toolResultPayload) {
|
|
9116
|
+
await bridge.sendToolResult(toolResultPayload);
|
|
9117
|
+
}
|
|
9118
|
+
};
|
|
9119
|
+
const initPromise = installInitializedSync(
|
|
9120
|
+
bridge,
|
|
9121
|
+
syncGuestToolState,
|
|
9122
|
+
(error) => {
|
|
9123
|
+
if (disposed) return;
|
|
9124
|
+
const message = error instanceof Error ? error.message : "Failed to synchronize view state";
|
|
9125
|
+
onErrorRef.current?.(message);
|
|
9126
|
+
onLifecycleChangeRef.current?.({
|
|
9127
|
+
status: "error",
|
|
9128
|
+
error: message
|
|
9129
|
+
});
|
|
9130
|
+
}
|
|
9131
|
+
);
|
|
9089
9132
|
let transport = new PostMessageTransport(
|
|
9090
9133
|
iframe.contentWindow,
|
|
9091
9134
|
iframe.contentWindow
|
|
@@ -9106,26 +9149,6 @@ function ViewRendererBase({
|
|
|
9106
9149
|
setInitCount((c) => c + 1);
|
|
9107
9150
|
onLifecycleChangeRef.current?.({ status: "initialized" });
|
|
9108
9151
|
await publishAppTools();
|
|
9109
|
-
const currentPartialToolInput = partialToolInputRef.current;
|
|
9110
|
-
const hasCompletedToolResult = toolOutputRef.current !== void 0 && toolOutputRef.current !== null;
|
|
9111
|
-
if (currentPartialToolInput && !hasCompletedToolResult) {
|
|
9112
|
-
await bridge.sendToolInputPartial({
|
|
9113
|
-
arguments: currentPartialToolInput
|
|
9114
|
-
});
|
|
9115
|
-
} else {
|
|
9116
|
-
const mergedArgs = {
|
|
9117
|
-
...toolInputRef.current,
|
|
9118
|
-
...parseCustomProps(customPropsRef.current)
|
|
9119
|
-
};
|
|
9120
|
-
await bridge.sendToolInput({ arguments: mergedArgs });
|
|
9121
|
-
}
|
|
9122
|
-
const toolResultPayload = buildToolResultPayload(
|
|
9123
|
-
toolOutputRef.current,
|
|
9124
|
-
customPropsRef.current
|
|
9125
|
-
);
|
|
9126
|
-
if (toolResultPayload) {
|
|
9127
|
-
await bridge.sendToolResult(toolResultPayload);
|
|
9128
|
-
}
|
|
9129
9152
|
onLifecycleChangeRef.current?.({ status: "ready" });
|
|
9130
9153
|
} catch (err) {
|
|
9131
9154
|
if (!disposed) {
|