cascade-ai 0.12.18 → 0.12.19

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/cli.js CHANGED
@@ -4,6 +4,7 @@ import { GoogleGenAI, HarmBlockThreshold, HarmCategory } from '@google/genai';
4
4
  import dns from 'dns';
5
5
  import http, { createServer } from 'http';
6
6
  import https from 'https';
7
+ import zlib from 'zlib';
7
8
  import { Readable } from 'stream';
8
9
  import { render, Box, Text, useStdout, useApp, useInput, Static } from 'ink';
9
10
  import { Command } from 'commander';
@@ -57,7 +58,7 @@ var __export = (target, all) => {
57
58
  var CASCADE_VERSION, CASCADE_CONFIG_FILE, CASCADE_DB_FILE, CASCADE_DASHBOARD_SECRET_FILE, GLOBAL_CONFIG_DIR, GLOBAL_DB_FILE, GLOBAL_KEYSTORE_FILE, GLOBAL_RUNTIME_DB_FILE, DEFAULT_DASHBOARD_PORT, DEFAULT_CONTEXT_LIMIT, DEFAULT_AUTO_SUMMARIZE_AT, MODELS, T1_MODEL_PRIORITY, T2_MODEL_PRIORITY, T3_MODEL_PRIORITY, VISION_MODEL_PRIORITY, COMPLEXITY_T2_COUNT, THEME_NAMES, DEFAULT_THEME, OLLAMA_BASE_URL, LM_STUDIO_BASE_URL, AZURE_BASE_URL_TEMPLATE, TOOL_NAMES, DEFAULT_APPROVAL_REQUIRED;
58
59
  var init_constants = __esm({
59
60
  "src/constants.ts"() {
60
- CASCADE_VERSION = "0.12.18";
61
+ CASCADE_VERSION = "0.12.19";
61
62
  CASCADE_CONFIG_FILE = ".cascade/config.json";
62
63
  CASCADE_DB_FILE = ".cascade/memory.db";
63
64
  CASCADE_DASHBOARD_SECRET_FILE = ".cascade/dashboard-secret";
@@ -1167,9 +1168,9 @@ function preferIpv4Host(url) {
1167
1168
  if (!url) return url;
1168
1169
  return url.replace(/^(https?:\/\/)localhost(?=[:/]|$)/i, "$1127.0.0.1");
1169
1170
  }
1170
- async function nodeHttpFetch(input, init = {}) {
1171
+ async function nodeHttpFetch(input, init = {}, redirectCount = 0) {
1171
1172
  const urlStr = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
1172
- const u = new URL(urlStr);
1173
+ const u = new URL(preferIpv4Host(urlStr) ?? urlStr);
1173
1174
  const lib = u.protocol === "https:" ? https : http;
1174
1175
  const method = (init.method ?? "GET").toUpperCase();
1175
1176
  const headers = {};
@@ -1179,6 +1180,9 @@ async function nodeHttpFetch(input, init = {}) {
1179
1180
  });
1180
1181
  else if (Array.isArray(h)) for (const [k, v] of h) headers[k] = v;
1181
1182
  else if (h) Object.assign(headers, h);
1183
+ if (!Object.keys(headers).some((k) => k.toLowerCase() === "accept-encoding")) {
1184
+ headers["accept-encoding"] = "gzip, deflate, br";
1185
+ }
1182
1186
  const body = init.body == null ? void 0 : typeof init.body === "string" ? init.body : Buffer.from(init.body);
1183
1187
  return new Promise((resolve, reject) => {
1184
1188
  const req = lib.request(
@@ -1190,14 +1194,30 @@ async function nodeHttpFetch(input, init = {}) {
1190
1194
  headers
1191
1195
  },
1192
1196
  (res) => {
1193
- const stream = Readable.toWeb(res);
1197
+ const status = res.statusCode ?? 200;
1198
+ const location = res.headers.location;
1199
+ if (status >= 300 && status < 400 && location && redirectCount < MAX_REDIRECTS) {
1200
+ res.resume();
1201
+ const nextUrl = new URL(location, u).href;
1202
+ const downgrade = status === 303 || (status === 301 || status === 302) && method !== "GET" && method !== "HEAD";
1203
+ const nextInit = downgrade ? { ...init, method: "GET", body: void 0 } : init;
1204
+ resolve(nodeHttpFetch(nextUrl, nextInit, redirectCount + 1));
1205
+ return;
1206
+ }
1207
+ const encoding = (res.headers["content-encoding"] ?? "").toLowerCase();
1208
+ let bodyStream = res;
1209
+ if (encoding === "gzip" || encoding === "x-gzip") bodyStream = res.pipe(zlib.createGunzip());
1210
+ else if (encoding === "deflate") bodyStream = res.pipe(zlib.createInflate());
1211
+ else if (encoding === "br") bodyStream = res.pipe(zlib.createBrotliDecompress());
1212
+ const stream = Readable.toWeb(bodyStream);
1194
1213
  const respHeaders = new Headers();
1195
1214
  for (const [k, v] of Object.entries(res.headers)) {
1215
+ if (k === "content-encoding" || k === "content-length") continue;
1196
1216
  if (Array.isArray(v)) respHeaders.set(k, v.join(", "));
1197
1217
  else if (typeof v === "string") respHeaders.set(k, v);
1198
1218
  }
1199
1219
  resolve(new Response(stream, {
1200
- status: res.statusCode ?? 200,
1220
+ status,
1201
1221
  statusText: res.statusMessage ?? "",
1202
1222
  headers: respHeaders
1203
1223
  }));
@@ -1209,12 +1229,14 @@ async function nodeHttpFetch(input, init = {}) {
1209
1229
  req.end();
1210
1230
  });
1211
1231
  }
1232
+ var MAX_REDIRECTS;
1212
1233
  var init_net = __esm({
1213
1234
  "src/utils/net.ts"() {
1214
1235
  try {
1215
1236
  dns.setDefaultResultOrder("ipv4first");
1216
1237
  } catch {
1217
1238
  }
1239
+ MAX_REDIRECTS = 5;
1218
1240
  }
1219
1241
  });
1220
1242
 
@@ -8918,7 +8940,7 @@ var SsrfBlockedError = class extends Error {
8918
8940
  }
8919
8941
  };
8920
8942
  var ALLOWED_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
8921
- var MAX_REDIRECTS = 5;
8943
+ var MAX_REDIRECTS2 = 5;
8922
8944
  function allowLocal() {
8923
8945
  return process.env["CASCADE_ALLOW_LOCAL_FETCH"] === "1";
8924
8946
  }
@@ -8986,7 +9008,7 @@ async function assertPublicUrl(rawUrl) {
8986
9008
  }
8987
9009
  async function safeFetch(rawUrl, init = {}) {
8988
9010
  let currentUrl = (await assertPublicUrl(rawUrl)).toString();
8989
- for (let i = 0; i <= MAX_REDIRECTS; i++) {
9011
+ for (let i = 0; i <= MAX_REDIRECTS2; i++) {
8990
9012
  const resp = await fetch(currentUrl, { ...init, redirect: "manual" });
8991
9013
  if (resp.status < 300 || resp.status >= 400) return resp;
8992
9014
  const location = resp.headers.get("location");
@@ -8995,7 +9017,7 @@ async function safeFetch(rawUrl, init = {}) {
8995
9017
  await assertPublicUrl(next.toString());
8996
9018
  currentUrl = next.toString();
8997
9019
  }
8998
- throw new SsrfBlockedError(`Too many redirects (>${MAX_REDIRECTS}).`);
9020
+ throw new SsrfBlockedError(`Too many redirects (>${MAX_REDIRECTS2}).`);
8999
9021
  }
9000
9022
 
9001
9023
  // src/tools/web-fetch.ts