@mytegroupinc/myte-core 0.0.21 → 0.0.22

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/cli.js +20 -6
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -22,6 +22,7 @@ const {
22
22
  } = require("./lib/ai-gateway");
23
23
 
24
24
  const DEFAULT_API_BASE = "https://api.myte.dev";
25
+ const DEFAULT_DIFF_LIMIT_CHARS = 500_000;
25
26
  const REMOVED_COMMAND_MESSAGES = {
26
27
  ask: "The `ask` alias has been removed. Use `myte query \"...\"`.",
27
28
  chat: "The `chat` command has been removed. Use repeated `myte query` calls instead.",
@@ -314,7 +315,7 @@ function printHelp() {
314
315
  "",
315
316
  "Options:",
316
317
  " --with-diff Include deterministic git diffs (project-scoped; fails fast if no project repos are configured or resolved)",
317
- " --diff-limit <chars> Truncate diff context to N chars (default: 200000)",
318
+ " --diff-limit <chars> Truncate diff context to N chars (default: 500000)",
318
319
  " --timeout-ms <ms> Request timeout (default: 300000)",
319
320
  " --base-url <url> API base (default: https://api.myte.dev)",
320
321
  " --payload-file <path> Raw OpenAI-style chat-completions payload for `myte ai`",
@@ -604,6 +605,8 @@ async function fetchJsonWithTimeout(fetchFn, url, options, timeoutMs) {
604
605
  } catch {
605
606
  const err = new Error(`Non-JSON response (${resp.status}): ${text.slice(0, 500)}`);
606
607
  err.status = resp.status;
608
+ const retryAfter = resp.headers?.get?.("retry-after");
609
+ if (retryAfter) err.retryAfter = retryAfter;
607
610
  throw err;
608
611
  }
609
612
  return { resp, body };
@@ -1881,6 +1884,10 @@ function resolveRetryAfterMs(err, fallbackMs = 5_000) {
1881
1884
  return fallbackMs;
1882
1885
  }
1883
1886
 
1887
+ function isTransientQueryStatusError(err) {
1888
+ return [408, 429, 500, 502, 503, 504].includes(Number(err?.status));
1889
+ }
1890
+
1884
1891
  async function createAssistantQueryJob({ apiBase, key, payload, timeoutMs, endpoint = "/project-assistant/query" }) {
1885
1892
  const fetchFn = await getFetch();
1886
1893
  const url = `${apiBase}${endpoint}`;
@@ -5002,8 +5009,9 @@ async function runQuery(args) {
5002
5009
  const timeoutMs = Number.isFinite(timeoutParsed) ? timeoutParsed : 300_000;
5003
5010
 
5004
5011
  const charLimitRaw = args["diff-limit"] || args.diffLimit || args.diff_limit;
5005
- const charLimitParsed = charLimitRaw !== undefined && charLimitRaw !== null ? Number(charLimitRaw) : 200_000;
5006
- const diffLimit = Number.isFinite(charLimitParsed) ? charLimitParsed : 200_000;
5012
+ const charLimitParsed =
5013
+ charLimitRaw !== undefined && charLimitRaw !== null ? Number(charLimitRaw) : DEFAULT_DIFF_LIMIT_CHARS;
5014
+ const diffLimit = Number.isFinite(charLimitParsed) ? charLimitParsed : DEFAULT_DIFF_LIMIT_CHARS;
5007
5015
 
5008
5016
  const baseRaw = args["base-url"] || args.baseUrl || args.base_url || process.env.MYTE_API_BASE || DEFAULT_API_BASE;
5009
5017
  const apiBase = normalizeApiBase(baseRaw);
@@ -5077,13 +5085,19 @@ async function runQuery(args) {
5077
5085
  const pollTimeoutMs = Math.max(timeoutMs, 900_000);
5078
5086
  const startedAt = Date.now();
5079
5087
  let finalStatus = null;
5088
+ let pollDelayMs = 2_000;
5080
5089
  do {
5081
- await sleep(2_000);
5090
+ await sleep(pollDelayMs);
5082
5091
  try {
5083
5092
  finalStatus = await fetchAssistantQueryJobStatus({ apiBase, key, timeoutMs, jobId });
5093
+ pollDelayMs = Math.min(10_000, Math.ceil(pollDelayMs * 1.25));
5084
5094
  } catch (err) {
5085
- if (Number(err?.status) === 429) {
5086
- await sleep(resolveRetryAfterMs(err));
5095
+ if (isTransientQueryStatusError(err)) {
5096
+ const fallbackMs =
5097
+ Number(err?.status) === 429 ? 5_000 : Math.min(30_000, Math.max(5_000, pollDelayMs * 2));
5098
+ const waitMs = resolveRetryAfterMs(err, fallbackMs);
5099
+ await sleep(waitMs);
5100
+ pollDelayMs = Math.min(30_000, Math.max(pollDelayMs, waitMs));
5087
5101
  continue;
5088
5102
  }
5089
5103
  throw err;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mytegroupinc/myte-core",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Myte CLI core implementation.",
5
5
  "type": "commonjs",
6
6
  "main": "cli.js",