@mcp-use/client 2.0.0-beta.2 → 2.0.0-beta.4

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.
@@ -128,7 +128,7 @@ var Logger = class {
128
128
  var logger = Logger.get();
129
129
 
130
130
  // src/utils/version.ts
131
- var VERSION = "2.0.0-beta.1";
131
+ var VERSION = "2.0.0-beta.3";
132
132
  function getPackageVersion() {
133
133
  return VERSION;
134
134
  }
package/dist/index.js CHANGED
@@ -1108,7 +1108,7 @@ init_connector_telemetry();
1108
1108
  init_logging();
1109
1109
 
1110
1110
  // src/utils/version.ts
1111
- var VERSION = "2.0.0-beta.1";
1111
+ var VERSION = "2.0.0-beta.3";
1112
1112
  function getPackageVersion() {
1113
1113
  return VERSION;
1114
1114
  }
@@ -1473,7 +1473,7 @@ var HttpConnector = class extends BaseConnector {
1473
1473
  };
1474
1474
 
1475
1475
  // src/utils/version.ts
1476
- var VERSION = "2.0.0-beta.1";
1476
+ var VERSION = "2.0.0-beta.3";
1477
1477
  function getPackageVersion() {
1478
1478
  return VERSION;
1479
1479
  }
@@ -6903,6 +6903,53 @@ function parseCustomProps(customProps) {
6903
6903
  return parsed;
6904
6904
  }
6905
6905
 
6906
+ // src/react/view/inject-openai-file-apis.ts
6907
+ var OPENAI_FILE_APIS_SCRIPT = `<script>
6908
+ (function () {
6909
+ var files = new Map();
6910
+ window.openai = window.openai || {};
6911
+ window.openai.uploadFile = async function (file) {
6912
+ var fileId = crypto.randomUUID();
6913
+ files.set(fileId, file);
6914
+ return { fileId: fileId };
6915
+ };
6916
+ window.openai.getFileDownloadUrl = async function (ref) {
6917
+ var file = files.get(ref.fileId);
6918
+ if (!file) {
6919
+ throw new Error("File not found: " + ref.fileId);
6920
+ }
6921
+ return { downloadUrl: URL.createObjectURL(file) };
6922
+ };
6923
+ })();
6924
+ </script>`;
6925
+ function injectOpenAiFileApis(html) {
6926
+ if (html.includes("<head>")) {
6927
+ return html.replace("<head>", "<head>" + OPENAI_FILE_APIS_SCRIPT);
6928
+ }
6929
+ if (html.includes("<HEAD>")) {
6930
+ return html.replace("<HEAD>", "<HEAD>" + OPENAI_FILE_APIS_SCRIPT);
6931
+ }
6932
+ if (html.includes("<html>")) {
6933
+ return html.replace(
6934
+ "<html>",
6935
+ "<html><head>" + OPENAI_FILE_APIS_SCRIPT + "</head>"
6936
+ );
6937
+ }
6938
+ if (html.includes("<HTML>")) {
6939
+ return html.replace(
6940
+ "<HTML>",
6941
+ "<HTML><head>" + OPENAI_FILE_APIS_SCRIPT + "</head>"
6942
+ );
6943
+ }
6944
+ if (html.includes("<!DOCTYPE") || html.includes("<!doctype")) {
6945
+ return html.replace(
6946
+ /(<!DOCTYPE[^>]*>|<!doctype[^>]*>)/i,
6947
+ "$1<head>" + OPENAI_FILE_APIS_SCRIPT + "</head>"
6948
+ );
6949
+ }
6950
+ return OPENAI_FILE_APIS_SCRIPT + html;
6951
+ }
6952
+
6906
6953
  // src/react/view/resolve-view-resource.ts
6907
6954
  function resolveViewResource(options) {
6908
6955
  const { resourceResult, listingResource, cspMode, resourceUri } = options;
@@ -7339,7 +7386,9 @@ var DEFAULT_HOST_CAPABILITIES = {
7339
7386
  serverTools: {},
7340
7387
  serverResources: {},
7341
7388
  logging: {},
7342
- updateModelContext: { text: {} }
7389
+ updateModelContext: { text: {} },
7390
+ // ponytail: always advertised; bridge.onmessage no-ops when onMessage unset
7391
+ message: { text: {} }
7343
7392
  };
7344
7393
  function waitForSandboxProxyReady(iframe) {
7345
7394
  return new Promise((resolve) => {
@@ -7401,6 +7450,7 @@ function ViewRendererBase({
7401
7450
  onResourceResolved,
7402
7451
  wrapTransport,
7403
7452
  toolCallTimeout = DEFAULT_TOOL_CALL_TIMEOUT,
7453
+ mockOpenAiFileApis = false,
7404
7454
  className,
7405
7455
  testId = "mcp-app-frame",
7406
7456
  invoking,
@@ -7428,6 +7478,8 @@ function ViewRendererBase({
7428
7478
  onMessageRef.current = onMessage;
7429
7479
  const toolInputRef = useRef4(toolInput);
7430
7480
  toolInputRef.current = toolInput;
7481
+ const partialToolInputRef = useRef4(partialToolInput);
7482
+ partialToolInputRef.current = partialToolInput;
7431
7483
  const toolOutputRef = useRef4(toolOutput);
7432
7484
  toolOutputRef.current = toolOutput;
7433
7485
  const customPropsRef = useRef4(customProps);
@@ -7450,6 +7502,8 @@ function ViewRendererBase({
7450
7502
  sandboxUrlRef.current = sandboxUrl;
7451
7503
  const cspModeRef = useRef4(cspMode);
7452
7504
  cspModeRef.current = cspMode;
7505
+ const mockOpenAiFileApisRef = useRef4(mockOpenAiFileApis);
7506
+ mockOpenAiFileApisRef.current = mockOpenAiFileApis;
7453
7507
  const resolveSandboxUrl = useCallback6((next) => {
7454
7508
  const custom = sandboxUrlRef.current;
7455
7509
  if (custom) {
@@ -7716,7 +7770,7 @@ function ViewRendererBase({
7716
7770
  await bridge.connect(transport);
7717
7771
  if (disposed) return;
7718
7772
  await bridge.sendSandboxResourceReady({
7719
- html: resolved.html,
7773
+ html: mockOpenAiFileApisRef.current ? injectOpenAiFileApis(resolved.html) : resolved.html,
7720
7774
  csp: resolved.csp,
7721
7775
  permissions: resolved.permissions
7722
7776
  });
@@ -7725,11 +7779,18 @@ function ViewRendererBase({
7725
7779
  bridgeRef.current = bridge;
7726
7780
  setInitCount((c) => c + 1);
7727
7781
  onLifecycleChangeRef.current?.({ status: "initialized" });
7728
- const mergedArgs = {
7729
- ...toolInputRef.current,
7730
- ...parseCustomProps(customPropsRef.current)
7731
- };
7732
- bridge.sendToolInput({ arguments: mergedArgs });
7782
+ const currentPartialToolInput = partialToolInputRef.current;
7783
+ if (currentPartialToolInput) {
7784
+ bridge.sendToolInputPartial({
7785
+ arguments: currentPartialToolInput
7786
+ });
7787
+ } else {
7788
+ const mergedArgs = {
7789
+ ...toolInputRef.current,
7790
+ ...parseCustomProps(customPropsRef.current)
7791
+ };
7792
+ bridge.sendToolInput({ arguments: mergedArgs });
7793
+ }
7733
7794
  const toolResultPayload = buildToolResultPayload(
7734
7795
  toolOutputRef.current,
7735
7796
  customPropsRef.current
@@ -7778,7 +7839,8 @@ function ViewRendererBase({
7778
7839
  cspMode,
7779
7840
  viewId,
7780
7841
  wrapTransport,
7781
- toolCallTimeout
7842
+ toolCallTimeout,
7843
+ mockOpenAiFileApis
7782
7844
  ]);
7783
7845
  useEffect5(() => {
7784
7846
  const bridge = bridgeRef.current;
@@ -7792,13 +7854,13 @@ function ViewRendererBase({
7792
7854
  }, [initCount, partialToolInput]);
7793
7855
  useEffect5(() => {
7794
7856
  const bridge = bridgeRef.current;
7795
- if (!bridge || initCount === 0) return;
7857
+ if (!bridge || initCount === 0 || partialToolInput) return;
7796
7858
  const mergedArgs = {
7797
7859
  ...toolInput,
7798
7860
  ...parseCustomProps(customProps)
7799
7861
  };
7800
7862
  bridge.sendToolInput({ arguments: mergedArgs });
7801
- }, [initCount, toolInput, customProps]);
7863
+ }, [initCount, toolInput, partialToolInput, customProps]);
7802
7864
  useEffect5(() => {
7803
7865
  const bridge = bridgeRef.current;
7804
7866
  if (!bridge || initCount === 0) return;
@@ -7902,6 +7964,7 @@ function viewRendererAreEqual(prev, next) {
7902
7964
  if (prev.hostContext !== next.hostContext) return false;
7903
7965
  if (prev.hostCapabilities !== next.hostCapabilities) return false;
7904
7966
  if (prev.cspMode !== next.cspMode) return false;
7967
+ if (prev.mockOpenAiFileApis !== next.mockOpenAiFileApis) return false;
7905
7968
  if (prev.className !== next.className) return false;
7906
7969
  if (prev.onReady !== next.onReady) return false;
7907
7970
  if (prev.onLifecycleChange !== next.onLifecycleChange) return false;