@letta-ai/letta-code 0.33.6 → 0.33.7

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.
@@ -16867,28 +16867,29 @@ class StreamableHTTPClientTransport {
16867
16867
  // src/mcp-client.ts
16868
16868
  var DEFAULT_CLIENT_INFO = {
16869
16869
  name: "letta-code",
16870
- version: "0.33.6"
16870
+ version: "0.33.7"
16871
16871
  };
16872
16872
  async function connectMcpServer(config2, options = {}) {
16873
16873
  let client = new Client(options.clientInfo ?? DEFAULT_CLIENT_INFO);
16874
16874
  try {
16875
+ options.signal?.throwIfAborted();
16875
16876
  const transport = createTransport(config2, options);
16876
16877
  try {
16877
- await client.connect(transport);
16878
+ await client.connect(transport, options.signal ? { signal: options.signal } : undefined);
16878
16879
  } catch (error2) {
16879
16880
  if (!(error2 instanceof UnauthorizedError) || !options.oauth?.waitForAuthorizationCode || !supportsOAuthCompletion(transport)) {
16880
16881
  throw error2;
16881
16882
  }
16882
- const authorizationCode = await options.oauth.waitForAuthorizationCode();
16883
- await transport.finishAuth(authorizationCode);
16883
+ const authorizationCode = await withAbort(options.oauth.waitForAuthorizationCode(), options.signal, () => options.oauth?.close());
16884
+ await withAbort(transport.finishAuth(authorizationCode), options.signal, () => transport.close());
16884
16885
  await client.close().catch(() => transport.close().catch(() => {
16885
16886
  return;
16886
16887
  }));
16887
16888
  client = new Client(options.clientInfo ?? DEFAULT_CLIENT_INFO);
16888
- await client.connect(createTransport(config2, options));
16889
+ await client.connect(createTransport(config2, options), options.signal ? { signal: options.signal } : undefined);
16889
16890
  }
16890
- await options.oauth?.close();
16891
- const response = await client.listTools();
16891
+ await (options.oauth?.closeCallback?.() ?? options.oauth?.close() ?? Promise.resolve());
16892
+ const response = await client.listTools(undefined, options.signal ? { signal: options.signal } : undefined);
16892
16893
  const tools = response.tools.map((tool) => ({
16893
16894
  ...tool,
16894
16895
  inputSchema: normalizeInputSchema(tool.inputSchema),
@@ -16911,7 +16912,13 @@ async function connectMcpServer(config2, options = {}) {
16911
16912
  if (closed)
16912
16913
  return;
16913
16914
  closed = true;
16914
- await client.close();
16915
+ const results = await Promise.allSettled([
16916
+ client.close(),
16917
+ options.oauth?.close()
16918
+ ]);
16919
+ const failure = results.find((result) => result.status === "rejected");
16920
+ if (failure)
16921
+ throw failure.reason;
16915
16922
  }
16916
16923
  };
16917
16924
  } catch (error2) {
@@ -16922,6 +16929,27 @@ async function connectMcpServer(config2, options = {}) {
16922
16929
  throw error2;
16923
16930
  }
16924
16931
  }
16932
+ async function withAbort(operation, signal, onAbort) {
16933
+ if (!signal)
16934
+ return operation;
16935
+ signal.throwIfAborted();
16936
+ let abort;
16937
+ const cancellation = new Promise((_resolve, reject) => {
16938
+ abort = () => {
16939
+ Promise.resolve(onAbort?.()).catch(() => {
16940
+ return;
16941
+ });
16942
+ reject(signal.reason ?? new DOMException("Operation aborted", "AbortError"));
16943
+ };
16944
+ signal.addEventListener("abort", abort, { once: true });
16945
+ });
16946
+ try {
16947
+ return await Promise.race([operation, cancellation]);
16948
+ } finally {
16949
+ if (abort)
16950
+ signal.removeEventListener("abort", abort);
16951
+ }
16952
+ }
16925
16953
  function connectStdioMcpServer(config2, options = {}) {
16926
16954
  return connectMcpServer({ ...config2, transport: "stdio" }, options);
16927
16955
  }
@@ -16930,7 +16958,8 @@ function createTransport(config2, options) {
16930
16958
  const headers = resolveHeaderEnvironment(config2.headers);
16931
16959
  return new StreamableHTTPClientTransport(new URL(config2.url), {
16932
16960
  requestInit: headersRequestInit(headers),
16933
- authProvider: options.oauth?.authProvider
16961
+ authProvider: options.oauth?.authProvider,
16962
+ fetch: abortAwareFetch(options.signal)
16934
16963
  });
16935
16964
  }
16936
16965
  if (config2.transport === "sse") {
@@ -16939,7 +16968,7 @@ function createTransport(config2, options) {
16939
16968
  return new SSEClientTransport(new URL(config2.url), {
16940
16969
  requestInit,
16941
16970
  authProvider: options.oauth?.authProvider,
16942
- fetch: headers ? (url2, init) => fetch(url2, mergeHeaders(init, headers)) : undefined
16971
+ fetch: abortAwareFetch(options.signal, headers)
16943
16972
  });
16944
16973
  }
16945
16974
  return new StdioClientTransport({
@@ -16950,6 +16979,18 @@ function createTransport(config2, options) {
16950
16979
  stderr: options.stderr ?? "inherit"
16951
16980
  });
16952
16981
  }
16982
+ function abortAwareFetch(operationSignal, headers) {
16983
+ if (!operationSignal && !headers)
16984
+ return;
16985
+ return (url2, init) => {
16986
+ const requestInit = headers ? mergeHeaders(init, headers) : { ...init };
16987
+ const requestSignal = requestInit.signal ?? undefined;
16988
+ return fetch(url2, {
16989
+ ...requestInit,
16990
+ signal: operationSignal && requestSignal ? AbortSignal.any([operationSignal, requestSignal]) : operationSignal ?? requestSignal
16991
+ });
16992
+ };
16993
+ }
16953
16994
  function supportsOAuthCompletion(transport) {
16954
16995
  return "finishAuth" in transport && typeof transport.finishAuth === "function";
16955
16996
  }
@@ -16992,4 +17033,4 @@ export {
16992
17033
  connectMcpServer
16993
17034
  };
16994
17035
 
16995
- //# debugId=EA35533720B42BA264756E2164756E21
17036
+ //# debugId=93ABE808CA1D455C64756E2164756E21