11diff --git a/dist/index.cjs b/dist/index.cjs
2- index 1c43bac25a1037416fdf2ddfb4534ba0897a2e69..7e2108326f368ccbc48897195d57e370a4553855 100644
2+ index 635f1c0..9214f0b 100644
33--- a/dist/index.cjs
44+++ b/dist/index.cjs
5- @@ -3154 ,6 +3154 ,7 @@ var Client = class extends require_src.Protocol {
5+ @@ -3211 ,6 +3211 ,7 @@ var Client = class extends require_src.Protocol {
66 */
77 async _connectPlainLegacy(transport, options) {
88 await super.connect(transport);
99+ transport.onsessionexpired = () => this._legacyHandshake(transport, options);
1010 if (transport.sessionId !== void 0) {
1111 const negotiatedProtocolVersion = this._negotiatedProtocolVersion;
1212 if (negotiatedProtocolVersion !== void 0) transport.setProtocolVersion?.(negotiatedProtocolVersion);
13- @@ -3170 ,6 +3171 ,7 @@ var Client = class extends require_src.Protocol {
13+ @@ -3227 ,6 +3228 ,7 @@ var Client = class extends require_src.Protocol {
1414 * the handshake; its completion sets the negotiated (legacy) version.
1515 */
1616 async _legacyHandshake(transport, options) {
1717+ transport.onsessionexpired = () => this._legacyHandshake(transport, options);
1818 const legacyVersions = require_src.legacyProtocolVersions(this._supportedProtocolVersions);
1919 try {
2020 const offeredVersion = legacyVersions[0];
21- @@ -3208 ,6 +3210 ,7 @@ var Client = class extends require_src.Protocol {
21+ @@ -3265 ,6 +3267 ,7 @@ var Client = class extends require_src.Protocol {
2222 await super.connect(transport);
2323 const negotiatedProtocolVersion = this._negotiatedProtocolVersion;
2424 if (negotiatedProtocolVersion !== void 0 && transport.setProtocolVersion) transport.setProtocolVersion(negotiatedProtocolVersion);
2525+ if (negotiatedProtocolVersion !== void 0 && !require_src.isModernProtocolVersion(negotiatedProtocolVersion)) transport.onsessionexpired = () => this._legacyHandshake(transport, options);
2626 return;
2727 }
2828 this._resetConnectionState();
29- @@ -5211 ,10 +5214 ,32 @@ var StreamableHTTPClientTransport = class {
29+ @@ -5294 ,10 +5297 ,32 @@ var StreamableHTTPClientTransport = class {
3030 }
3131 }
3232 async send(message, options) {
@@ -61,7 +61,7 @@ index 1c43bac25a1037416fdf2ddfb4534ba0897a2e69..7e2108326f368ccbc48897195d57e370
6161 const { resumptionToken, onresumptiontoken } = options || {};
6262 if (resumptionToken) {
6363 this._startOrAuthSse({
64- @@ -5226 ,8 +5251 ,8 @@ var StreamableHTTPClientTransport = class {
64+ @@ -5309 ,8 +5334 ,8 @@ var StreamableHTTPClientTransport = class {
6565 }
6666 const headers = await this._commonHeaders();
6767 this._applyBodyDerivedHeaders(headers, message);
@@ -71,7 +71,7 @@ index 1c43bac25a1037416fdf2ddfb4534ba0897a2e69..7e2108326f368ccbc48897195d57e370
7171 if (options?.headers !== void 0) for (const [name, value] of Object.entries(options.headers)) {
7272 if (RESERVED_REQUEST_HEADER_NAMES.has(name.toLowerCase())) continue;
7373 headers.set(name, value);
74- @@ -5249 ,8 +5274 ,14 @@ var StreamableHTTPClientTransport = class {
74+ @@ -5332 ,8 +5357 ,14 @@ var StreamableHTTPClientTransport = class {
7575 signal
7676 };
7777 const response = await (this._fetch ?? fetch)(this._url, init);
@@ -87,53 +87,53 @@ index 1c43bac25a1037416fdf2ddfb4534ba0897a2e69..7e2108326f368ccbc48897195d57e370
8787 if (response.status === 401 && this._authProvider) {
8888 if (response.headers.has("www-authenticate")) {
8989 const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
90- @@ -5264 ,7 +5295 ,7 @@ var StreamableHTTPClientTransport = class {
91- fetchFn: this._fetchWithInit
92- });
90+ @@ -5351 ,7 +5382 ,7 @@ var StreamableHTTPClientTransport = class {
91+ throw markAuthSeamEscape(error);
92+ }
9393 await response.text?.().catch(() => {});
9494- return this._send(message, options, true, stepUpRetries);
9595+ return this._send(message, options, true, stepUpRetries, isSessionRetry);
9696 }
9797 await response.text?.().catch(() => {});
98- if (isAuthRetry) throw new require_src.SdkHttpError(require_src.SdkErrorCode.ClientHttpAuthentication, "Server returned 401 after re-authentication", {
99- @@ -5284 ,7 +5315 ,7 @@ var StreamableHTTPClientTransport = class {
98+ if (isAuthRetry) throw markAuthSeamEscape( new require_src.SdkHttpError(require_src.SdkErrorCode.ClientHttpAuthentication, "Server returned 401 after re-authentication", {
99+ @@ -5371 ,7 +5402 ,7 @@ var StreamableHTTPClientTransport = class {
100100 statusText: response.statusText,
101101 text
102- }, stepUpRetries) !== "AUTHORIZED") throw new UnauthorizedError();
102+ }, stepUpRetries) !== "AUTHORIZED") throw markAuthSeamEscape( new UnauthorizedError() );
103103- return this._send(message, options, isAuthRetry, stepUpRetries + 1);
104104+ return this._send(message, options, isAuthRetry, stepUpRetries + 1, isSessionRetry);
105105 }
106106 }
107107 if (response.status === 400 && typeof text === "string" && this._isModernEnvelopedRequest(message)) try {
108108diff --git a/dist/index.mjs b/dist/index.mjs
109- index 77e2389913cb5c5c2b047f95d990ab2892bef923..4b5e4ff2869189d600ca644488a7749668c39747 100644
109+ index f02ce3c..0a5a649 100644
110110--- a/dist/index.mjs
111111+++ b/dist/index.mjs
112- @@ -3151 ,6 +3151 ,7 @@ var Client = class extends Protocol {
112+ @@ -3208 ,6 +3208 ,7 @@ var Client = class extends Protocol {
113113 */
114114 async _connectPlainLegacy(transport, options) {
115115 await super.connect(transport);
116116+ transport.onsessionexpired = () => this._legacyHandshake(transport, options);
117117 if (transport.sessionId !== void 0) {
118118 const negotiatedProtocolVersion = this._negotiatedProtocolVersion;
119119 if (negotiatedProtocolVersion !== void 0) transport.setProtocolVersion?.(negotiatedProtocolVersion);
120- @@ -3167 ,6 +3168 ,7 @@ var Client = class extends Protocol {
120+ @@ -3224 ,6 +3225 ,7 @@ var Client = class extends Protocol {
121121 * the handshake; its completion sets the negotiated (legacy) version.
122122 */
123123 async _legacyHandshake(transport, options) {
124124+ transport.onsessionexpired = () => this._legacyHandshake(transport, options);
125125 const legacyVersions = legacyProtocolVersions(this._supportedProtocolVersions);
126126 try {
127127 const offeredVersion = legacyVersions[0];
128- @@ -3205 ,6 +3207 ,7 @@ var Client = class extends Protocol {
128+ @@ -3262 ,6 +3264 ,7 @@ var Client = class extends Protocol {
129129 await super.connect(transport);
130130 const negotiatedProtocolVersion = this._negotiatedProtocolVersion;
131131 if (negotiatedProtocolVersion !== void 0 && transport.setProtocolVersion) transport.setProtocolVersion(negotiatedProtocolVersion);
132132+ if (negotiatedProtocolVersion !== void 0 && !isModernProtocolVersion(negotiatedProtocolVersion)) transport.onsessionexpired = () => this._legacyHandshake(transport, options);
133133 return;
134134 }
135135 this._resetConnectionState();
136- @@ -5208 ,10 +5211 ,32 @@ var StreamableHTTPClientTransport = class {
136+ @@ -5291 ,10 +5294 ,32 @@ var StreamableHTTPClientTransport = class {
137137 }
138138 }
139139 async send(message, options) {
@@ -168,7 +168,7 @@ index 77e2389913cb5c5c2b047f95d990ab2892bef923..4b5e4ff2869189d600ca644488a77496
168168 const { resumptionToken, onresumptiontoken } = options || {};
169169 if (resumptionToken) {
170170 this._startOrAuthSse({
171- @@ -5223 ,8 +5248 ,8 @@ var StreamableHTTPClientTransport = class {
171+ @@ -5306 ,8 +5331 ,8 @@ var StreamableHTTPClientTransport = class {
172172 }
173173 const headers = await this._commonHeaders();
174174 this._applyBodyDerivedHeaders(headers, message);
@@ -178,7 +178,7 @@ index 77e2389913cb5c5c2b047f95d990ab2892bef923..4b5e4ff2869189d600ca644488a77496
178178 if (options?.headers !== void 0) for (const [name, value] of Object.entries(options.headers)) {
179179 if (RESERVED_REQUEST_HEADER_NAMES.has(name.toLowerCase())) continue;
180180 headers.set(name, value);
181- @@ -5246 ,8 +5271 ,14 @@ var StreamableHTTPClientTransport = class {
181+ @@ -5329 ,8 +5354 ,14 @@ var StreamableHTTPClientTransport = class {
182182 signal
183183 };
184184 const response = await (this._fetch ?? fetch)(this._url, init);
@@ -194,19 +194,19 @@ index 77e2389913cb5c5c2b047f95d990ab2892bef923..4b5e4ff2869189d600ca644488a77496
194194 if (response.status === 401 && this._authProvider) {
195195 if (response.headers.has("www-authenticate")) {
196196 const { resourceMetadataUrl, scope } = extractWWWAuthenticateParams(response);
197- @@ -5261 ,7 +5292 ,7 @@ var StreamableHTTPClientTransport = class {
198- fetchFn: this._fetchWithInit
199- });
197+ @@ -5348 ,7 +5379 ,7 @@ var StreamableHTTPClientTransport = class {
198+ throw markAuthSeamEscape(error);
199+ }
200200 await response.text?.().catch(() => {});
201201- return this._send(message, options, true, stepUpRetries);
202202+ return this._send(message, options, true, stepUpRetries, isSessionRetry);
203203 }
204204 await response.text?.().catch(() => {});
205- if (isAuthRetry) throw new SdkHttpError(SdkErrorCode.ClientHttpAuthentication, "Server returned 401 after re-authentication", {
206- @@ -5281 ,7 +5312 ,7 @@ var StreamableHTTPClientTransport = class {
205+ if (isAuthRetry) throw markAuthSeamEscape( new SdkHttpError(SdkErrorCode.ClientHttpAuthentication, "Server returned 401 after re-authentication", {
206+ @@ -5368 ,7 +5399 ,7 @@ var StreamableHTTPClientTransport = class {
207207 statusText: response.statusText,
208208 text
209- }, stepUpRetries) !== "AUTHORIZED") throw new UnauthorizedError();
209+ }, stepUpRetries) !== "AUTHORIZED") throw markAuthSeamEscape( new UnauthorizedError() );
210210- return this._send(message, options, isAuthRetry, stepUpRetries + 1);
211211+ return this._send(message, options, isAuthRetry, stepUpRetries + 1, isSessionRetry);
212212 }
0 commit comments