@mcp-use/agent 2.0.16-canary.3 → 2.0.16

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/index.js CHANGED
@@ -1601,7 +1601,8 @@ async function chat3(params) {
1601
1601
  };
1602
1602
  }
1603
1603
 
1604
- // src/llm/providers/openai-chat-completions.ts
1604
+ // src/llm/providers/openai-shared.ts
1605
+ var OPENAI_BASE_URL = "https://api.openai.com/v1";
1605
1606
  var LlmRequestError = class extends Error {
1606
1607
  /** HTTP response status. */
1607
1608
  status;
@@ -1619,6 +1620,20 @@ var LlmRequestError = class extends Error {
1619
1620
  this.body = body;
1620
1621
  }
1621
1622
  };
1623
+ function buildEndpoint(config, path) {
1624
+ const base = config.baseUrl ?? OPENAI_BASE_URL;
1625
+ return `${base.replace(/\/$/, "")}${path}`;
1626
+ }
1627
+ function buildHeaders2(config) {
1628
+ const headers = {
1629
+ "Content-Type": "application/json",
1630
+ ...config.extraHeaders
1631
+ };
1632
+ if (config.apiKey) {
1633
+ headers.Authorization = `Bearer ${config.apiKey}`;
1634
+ }
1635
+ return headers;
1636
+ }
1622
1637
  async function throwLlmRequestError(res) {
1623
1638
  const text = await res.text().catch(() => "");
1624
1639
  let body = text;
@@ -1634,11 +1649,13 @@ async function throwLlmRequestError(res) {
1634
1649
  body
1635
1650
  );
1636
1651
  }
1637
- var OPENAI_BASE_URL = "https://api.openai.com/v1";
1638
- function buildEndpoint(config, path) {
1639
- return `${config.baseUrl ?? OPENAI_BASE_URL}${path}`;
1652
+
1653
+ // src/llm/providers/openai-chat-completions.ts
1654
+ var OPENAI_BASE_URL2 = "https://api.openai.com/v1";
1655
+ function buildEndpoint2(config, path) {
1656
+ return `${config.baseUrl ?? OPENAI_BASE_URL2}${path}`;
1640
1657
  }
1641
- function buildHeaders2(config) {
1658
+ function buildHeaders3(config) {
1642
1659
  const headers = {
1643
1660
  "Content-Type": "application/json",
1644
1661
  ...config.extraHeaders
@@ -1722,10 +1739,10 @@ async function* streamChat4(params) {
1722
1739
  }
1723
1740
  }));
1724
1741
  }
1725
- const endpoint = buildEndpoint(config, "/chat/completions");
1742
+ const endpoint = buildEndpoint2(config, "/chat/completions");
1726
1743
  const res = await fetch(endpoint, {
1727
1744
  method: "POST",
1728
- headers: buildHeaders2(config),
1745
+ headers: buildHeaders3(config),
1729
1746
  body: JSON.stringify(body),
1730
1747
  signal,
1731
1748
  ...config.credentials ? { credentials: config.credentials } : {}
@@ -1838,10 +1855,10 @@ async function chat4(params) {
1838
1855
  }
1839
1856
  }));
1840
1857
  }
1841
- const endpoint = buildEndpoint(config, "/chat/completions");
1858
+ const endpoint = buildEndpoint2(config, "/chat/completions");
1842
1859
  const res = await fetch(endpoint, {
1843
1860
  method: "POST",
1844
- headers: buildHeaders2(config),
1861
+ headers: buildHeaders3(config),
1845
1862
  body: JSON.stringify(body),
1846
1863
  signal,
1847
1864
  ...config.credentials ? { credentials: config.credentials } : {}
@@ -1869,17 +1886,21 @@ async function chat4(params) {
1869
1886
  }
1870
1887
 
1871
1888
  // src/llm/providers/index.ts
1889
+ function withOpenRouterConfig(config) {
1890
+ return {
1891
+ ...config,
1892
+ baseUrl: "https://openrouter.ai/api/v1",
1893
+ extraHeaders: {
1894
+ ...config.extraHeaders,
1895
+ "HTTP-Referer": "https://inspector.mcp-use.com",
1896
+ "X-Title": "mcp-use Inspector"
1897
+ }
1898
+ };
1899
+ }
1872
1900
  function withOpenRouter(params) {
1873
1901
  return {
1874
1902
  ...params,
1875
- config: {
1876
- ...params.config,
1877
- baseUrl: "https://openrouter.ai/api/v1",
1878
- extraHeaders: {
1879
- "HTTP-Referer": "https://inspector.mcp-use.com",
1880
- "X-Title": "mcp-use Inspector"
1881
- }
1882
- }
1903
+ config: withOpenRouterConfig(params.config)
1883
1904
  };
1884
1905
  }
1885
1906
  function streamChat5(params) {
@@ -1923,27 +1944,6 @@ function chat5(params) {
1923
1944
  }
1924
1945
  }
1925
1946
 
1926
- // src/llm/providers/openai-shared.ts
1927
- var OPENAI_BASE_URL2 = "https://api.openai.com/v1";
1928
- function buildEndpoint2(config, path) {
1929
- const base = config.baseUrl ?? OPENAI_BASE_URL2;
1930
- return `${base.replace(/\/$/, "")}${path}`;
1931
- }
1932
- function buildHeaders3(config) {
1933
- const headers = {
1934
- "Content-Type": "application/json",
1935
- ...config.extraHeaders
1936
- };
1937
- if (config.apiKey) {
1938
- headers.Authorization = `Bearer ${config.apiKey}`;
1939
- }
1940
- return headers;
1941
- }
1942
- async function readOpenAIError(res) {
1943
- const text = await res.text().catch(() => "");
1944
- return `OpenAI request failed (${res.status} ${res.statusText}): ${text}`;
1945
- }
1946
-
1947
1947
  // src/llm/providers/openai-responses.ts
1948
1948
  function toResponsesUserContent(content) {
1949
1949
  if (typeof content === "string") return content;
@@ -2080,6 +2080,9 @@ function buildResponsesBody(params, stream) {
2080
2080
  if (params.config.maxTokens !== void 0) {
2081
2081
  body.max_output_tokens = params.config.maxTokens;
2082
2082
  }
2083
+ if (params.config.provider === "openrouter" && params.config.temperature !== void 0) {
2084
+ body.temperature = params.config.temperature;
2085
+ }
2083
2086
  return body;
2084
2087
  }
2085
2088
  function extractFunctionCalls(output) {
@@ -2126,15 +2129,15 @@ function parseArgs(argsJson) {
2126
2129
  }
2127
2130
  }
2128
2131
  async function* streamResponsesTurn(params) {
2129
- const res = await fetch(buildEndpoint2(params.config, "/responses"), {
2132
+ const res = await fetch(buildEndpoint(params.config, "/responses"), {
2130
2133
  method: "POST",
2131
- headers: buildHeaders3(params.config),
2134
+ headers: buildHeaders2(params.config),
2132
2135
  body: JSON.stringify(buildResponsesBody(params, true)),
2133
- signal: params.signal
2136
+ signal: params.signal,
2137
+ ...params.config.credentials ? { credentials: params.config.credentials } : {}
2134
2138
  });
2135
- if (!res.ok || !res.body) {
2136
- throw new Error(await readOpenAIError(res));
2137
- }
2139
+ if (!res.ok) await throwLlmRequestError(res);
2140
+ if (!res.body) throw new Error("OpenAI Responses stream has no body");
2138
2141
  const callBuffers = /* @__PURE__ */ new Map();
2139
2142
  let nextIndex = 0;
2140
2143
  let completedOutput = [];
@@ -2228,15 +2231,14 @@ async function* streamResponsesTurn(params) {
2228
2231
  return completedOutput;
2229
2232
  }
2230
2233
  async function completeResponsesTurn(params) {
2231
- const res = await fetch(buildEndpoint2(params.config, "/responses"), {
2234
+ const res = await fetch(buildEndpoint(params.config, "/responses"), {
2232
2235
  method: "POST",
2233
- headers: buildHeaders3(params.config),
2236
+ headers: buildHeaders2(params.config),
2234
2237
  body: JSON.stringify(buildResponsesBody(params, false)),
2235
- signal: params.signal
2238
+ signal: params.signal,
2239
+ ...params.config.credentials ? { credentials: params.config.credentials } : {}
2236
2240
  });
2237
- if (!res.ok) {
2238
- throw new Error(await readOpenAIError(res));
2239
- }
2241
+ if (!res.ok) await throwLlmRequestError(res);
2240
2242
  const json = await res.json();
2241
2243
  const status = json.status;
2242
2244
  if (status !== "completed" && status !== void 0) {
@@ -2400,10 +2402,16 @@ var OpenAIResponsesDriver = class {
2400
2402
  };
2401
2403
 
2402
2404
  // src/llm/driver.ts
2405
+ function isOpenRouterOpenAIModel(model) {
2406
+ return /^~?openai\//i.test(model);
2407
+ }
2403
2408
  function createLlmDriver(config) {
2404
2409
  if (config.provider === "openai") {
2405
2410
  return new OpenAIResponsesDriver(config);
2406
2411
  }
2412
+ if (config.provider === "openrouter" && isOpenRouterOpenAIModel(config.model)) {
2413
+ return new OpenAIResponsesDriver(withOpenRouterConfig(config));
2414
+ }
2407
2415
  return new RestLlmDriver(config);
2408
2416
  }
2409
2417
  var RestLlmDriver = class {
@@ -2693,7 +2701,7 @@ function providerConfigFromOptions(provider, model, config) {
2693
2701
  }
2694
2702
 
2695
2703
  // src/version.ts
2696
- var VERSION = "2.0.16-canary.3";
2704
+ var VERSION = "2.0.16";
2697
2705
  function getPackageVersion() {
2698
2706
  return VERSION;
2699
2707
  }