@miphamai/cli 0.58.0 → 0.59.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miphamai/cli",
3
- "version": "0.58.0",
3
+ "version": "0.59.0",
4
4
  "description": "Mipham Code — Multi-model open-core intelligent coding terminal by MiphamAI",
5
5
  "keywords": [
6
6
  "ai",
@@ -24,8 +24,9 @@ function isRetryableError(err: unknown): boolean {
24
24
  /**
25
25
  * Fetch with optional timeout and retry with exponential backoff.
26
26
  *
27
- * Retries on: network errors, 5xx, 429.
28
- * Does NOT retry on: timeout (AbortError), 4xx (except 429).
27
+ * Retries on: network errors, 5xx, 429, and the internal timeout firing
28
+ * (first-byte never arrived) — retried once as a transient network issue.
29
+ * Does NOT retry on: caller-initiated abort (init.signal), 4xx (except 429).
29
30
  */
30
31
  export async function fetchWithRetry(
31
32
  url: string,
@@ -38,7 +39,11 @@ export async function fetchWithRetry(
38
39
 
39
40
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
40
41
  const controller = new AbortController()
41
- const timer = setTimeout(() => controller.abort(), timeout)
42
+ let timedOut = false
43
+ const timer = setTimeout(() => {
44
+ timedOut = true
45
+ controller.abort()
46
+ }, timeout)
42
47
  const signal = init.signal ? anySignal([init.signal, controller.signal]) : controller.signal
43
48
 
44
49
  try {
@@ -57,7 +62,16 @@ export async function fetchWithRetry(
57
62
  return response
58
63
  } catch (err) {
59
64
  lastErr = err
60
- if (!isRetryableError(err) || attempt >= maxRetries) throw err
65
+ // First-byte timeout is transient → retry once. Caller abort is not.
66
+ const retryable = timedOut || isRetryableError(err)
67
+ if (!retryable || attempt >= maxRetries) {
68
+ if (timedOut) {
69
+ throw new Error(
70
+ `API Error: No response from API (timed out after ${Math.round(timeout / 1000)}s)`,
71
+ )
72
+ }
73
+ throw err
74
+ }
61
75
  await sleep(baseDelay * Math.pow(2, attempt))
62
76
  } finally {
63
77
  clearTimeout(timer)
@@ -9,7 +9,7 @@
9
9
  export const PACKAGE_NAME = '@miphamai/cli' as const
10
10
 
11
11
  /** 当前发布版本 */
12
- export const PACKAGE_VERSION = '0.58.0' as const
12
+ export const PACKAGE_VERSION = '0.59.0' as const
13
13
 
14
14
  /** npm install 全局安装命令 */
15
15
  export const NPM_INSTALL_COMMAND = `npm install -g ${PACKAGE_NAME}` as const