@skydiveai/pi-extensions 0.1.0-beta.2291 → 0.1.0-beta.2292

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.
Files changed (2) hide show
  1. package/dist/index.mjs +25 -1
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -956,6 +956,27 @@ function createStderrBuffer({ maxBytes }) {
956
956
  */
957
957
  const DEFAULT_CONNECT_TIMEOUT_MS = 5e3;
958
958
  const STDERR_BUFFER_BYTES = 4096;
959
+ const SESSION_NOT_FOUND_RETRY_DELAYS_MS = [
960
+ 250,
961
+ 500,
962
+ 1e3,
963
+ 2e3,
964
+ 4e3,
965
+ 8e3
966
+ ];
967
+ function delay(ms) {
968
+ return new Promise((resolve) => setTimeout(resolve, ms));
969
+ }
970
+ async function fetchWithSessionNotFoundRetry(input, init) {
971
+ for (let attempt = 0;; attempt += 1) {
972
+ const response = await fetch(input, init);
973
+ const sessionId = new Headers(init?.headers).get("mcp-session-id");
974
+ const retryDelay = SESSION_NOT_FOUND_RETRY_DELAYS_MS[attempt];
975
+ if (!sessionId || response.status !== 404 || retryDelay === void 0 || !(await response.clone().text()).includes("session_not_found")) return response;
976
+ await response.body?.cancel();
977
+ await delay(retryDelay);
978
+ }
979
+ }
959
980
  /**
960
981
  * Sandbox egress variables a stdio MCP server needs to make outbound HTTPS
961
982
  * calls. The SDK's default child environment is a tiny whitelist (HOME,
@@ -1039,7 +1060,10 @@ function probeAlive(pid) {
1039
1060
  }
1040
1061
  }
1041
1062
  async function connectHttp(_id, config, client) {
1042
- const transport = new StreamableHTTPClientTransport(new URL(config.url), { ...config.headers !== null ? { requestInit: { headers: config.headers } } : {} });
1063
+ const transport = new StreamableHTTPClientTransport(new URL(config.url), {
1064
+ ...config.headers !== null ? { requestInit: { headers: config.headers } } : {},
1065
+ fetch: fetchWithSessionNotFoundRetry
1066
+ });
1043
1067
  try {
1044
1068
  await client.connect(transport);
1045
1069
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skydiveai/pi-extensions",
3
- "version": "0.1.0-beta.2291",
3
+ "version": "0.1.0-beta.2292",
4
4
  "homepage": "https://skydive.com",
5
5
  "license": "MIT",
6
6
  "author": "Create, Inc.",