zen-code 1.11.0 → 2.1.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/dist/zen-code.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import "./MultiSelect-C5LXDu1p.mjs";
1
+ import "./use-input-CQELhJxU.mjs";
2
2
  import "chalk";
3
- import "./app-BhZo0DLj.mjs";
3
+ import "./app-CdJSgzzZ.mjs";
package/dist/zen-init.mjs CHANGED
@@ -1,15 +1,16 @@
1
- import { u as A, r as c, j as e, B as o, T as r, S as P, M as B, a as S, b as O, d as R, g as U, c as K, i as v, e as M } from "./MultiSelect-C5LXDu1p.mjs";
1
+ import { a as t, j as e, B as o, T as r, r as U } from "./use-input-CQELhJxU.mjs";
2
2
  import "chalk";
3
- const L = ({ onNext: l, onExit: t }) => {
4
- A((a, d) => {
5
- d.return ? l() : d.ctrl && a === "c" && t();
3
+ import { u as A, S as O, M as T, a as B, b as R, d as K, g as M, c as v, i as L } from "./MultiSelect-C_hSPGpl.mjs";
4
+ const N = ({ onNext: l, onExit: i }) => {
5
+ A((c, d) => {
6
+ d.return ? l() : d.ctrl && c === "c" && i();
6
7
  });
7
- const [h, u] = c.useState(0);
8
- return c.useEffect(() => {
9
- const p = setInterval(() => {
10
- u((m) => (m + 1) % 92);
8
+ const [j, p] = t.useState(0);
9
+ return t.useEffect(() => {
10
+ const u = setInterval(() => {
11
+ p((m) => (m + 1) % 92);
11
12
  }, 40);
12
- return () => clearInterval(p);
13
+ return () => clearInterval(u);
13
14
  }, []), /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", flexGrow: 1, justifyContent: "center", paddingX: 2, children: [
14
15
  /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", borderStyle: "round", borderColor: "cyan", paddingX: 1, marginBottom: 1, children: [
15
16
  /* @__PURE__ */ e.jsxs(o, { flexDirection: "row", justifyContent: "space-between", borderBottom: !1, children: [
@@ -23,7 +24,7 @@ const L = ({ onNext: l, onExit: t }) => {
23
24
  ███╔╝ ██╔══╝ ██║╚██╗██║
24
25
  ███████╗███████╗██║ ╚████║
25
26
  ╚══════╝╚══════╝╚═╝ ╚═══╝`.split(`
26
- `).map((a) => /* @__PURE__ */ e.jsx(P, { interval: 40, text: a, globalIndex: h }, a)) }),
27
+ `).map((c) => /* @__PURE__ */ e.jsx(O, { interval: 40, text: c, globalIndex: j }, c)) }),
27
28
  /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", justifyContent: "center", flexGrow: 1, children: [
28
29
  /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { color: "yellow", bold: !0, children: [
29
30
  " ",
@@ -99,11 +100,11 @@ const L = ({ onNext: l, onExit: t }) => {
99
100
  ] }),
100
101
  /* @__PURE__ */ e.jsx(o, { flexDirection: "row", justifyContent: "center", children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "[Ctrl+C 退出]" }) })
101
102
  ] });
102
- }, N = [
103
+ }, k = [
103
104
  { label: "OpenAI (GPT-4, o1 等)", value: "openai" },
104
105
  { label: "Anthropic (Claude)", value: "anthropic" }
105
- ], k = ({ provider: l, onSelect: t, onNext: h, onExit: u }) => {
106
- const a = c.useMemo(() => l ? [l] : [], [l]);
106
+ ], V = ({ provider: l, onSelect: i, onNext: j, onExit: p }) => {
107
+ const c = t.useMemo(() => l ? [l] : [], [l]);
107
108
  return /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", flexGrow: 1, justifyContent: "center", paddingX: 2, children: [
108
109
  /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", borderStyle: "round", borderColor: "cyan", paddingX: 1, marginBottom: 1, children: [
109
110
  /* @__PURE__ */ e.jsxs(o, { flexDirection: "row", justifyContent: "space-between", borderBottom: !1, children: [
@@ -121,14 +122,14 @@ const L = ({ onNext: l, onExit: t }) => {
121
122
  /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "• Anthropic: Claude 3.5 Sonnet, Opus" })
122
123
  ] }),
123
124
  /* @__PURE__ */ e.jsx(o, { marginTop: 1, marginBottom: 1, children: /* @__PURE__ */ e.jsx(
124
- B,
125
+ T,
125
126
  {
126
- options: N,
127
- values: a,
127
+ options: k,
128
+ values: c,
128
129
  onChange: (d) => {
129
- d.length > 0 && t(d[0]);
130
+ d.length > 0 && i(d[0]);
130
131
  },
131
- onSubmit: h,
132
+ onSubmit: j,
132
133
  singleSelect: !0,
133
134
  autoFocus: !0
134
135
  }
@@ -147,35 +148,35 @@ const L = ({ onNext: l, onExit: t }) => {
147
148
  ] }),
148
149
  /* @__PURE__ */ e.jsx(o, { flexDirection: "row", justifyContent: "center", children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "[Ctrl+C 退出]" }) })
149
150
  ] });
150
- }, C = {
151
+ }, w = {
151
152
  openai: "https://api.openai.com/v1",
152
153
  anthropic: "https://api.anthropic.com"
153
- }, V = {
154
+ }, G = {
154
155
  openai: "https://platform.openai.com/api-keys",
155
156
  anthropic: "https://console.anthropic.com/settings/keys"
156
- }, G = ({
157
+ }, X = ({
157
158
  provider: l,
158
- apiKey: t,
159
- baseUrl: h,
160
- onApiKeyChange: u,
161
- onBaseUrlChange: a,
159
+ apiKey: i,
160
+ baseUrl: j,
161
+ onApiKeyChange: p,
162
+ onBaseUrlChange: c,
162
163
  onNext: d,
163
- onBack: y,
164
- onExit: w,
165
- error: p
164
+ onBack: C,
165
+ onExit: I,
166
+ error: u
166
167
  }) => {
167
- const [m, g] = c.useState("apiKey"), [b, f] = c.useState(t), [x, j] = c.useState(h), E = C[l];
168
- c.useEffect(() => {
169
- f(t), j(h);
170
- }, [t, h]);
171
- const n = (i) => {
172
- i = i.trim(), f(i), u(i), d();
173
- }, s = (i) => {
174
- i = i.trim(), j(i), a(i), d();
168
+ const [m, g] = t.useState("apiKey"), [b, y] = t.useState(i), [x, f] = t.useState(j), D = w[l], n = (a) => {
169
+ y(a), p(a);
170
+ }, s = (a) => {
171
+ f(a), c(a);
172
+ }, h = (a) => {
173
+ a = a.trim(), n(a), d();
174
+ }, E = (a) => {
175
+ a = a.trim(), s(a), d();
175
176
  };
176
- return A((i, I) => {
177
- if (I.ctrl && i === "c" && w(), I.escape) {
178
- y();
177
+ return A((a, S) => {
178
+ if (S.ctrl && a === "c" && I(), S.escape) {
179
+ C();
179
180
  return;
180
181
  }
181
182
  }), /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", flexGrow: 1, justifyContent: "center", paddingX: 2, children: [
@@ -192,35 +193,35 @@ const L = ({ onNext: l, onExit: t }) => {
192
193
  /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(r, { bold: !0, children: "Base URL (可选)" }) }),
193
194
  /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { color: "gray", children: [
194
195
  "默认值: ",
195
- E
196
+ D
196
197
  ] }) }),
197
198
  /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(
198
- S,
199
+ B,
199
200
  {
200
201
  value: x,
201
- onChange: j,
202
- onSubmit: s,
203
- placeholder: E
202
+ onChange: s,
203
+ onSubmit: E,
204
+ placeholder: D
204
205
  }
205
206
  ) }),
206
207
  /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(r, { bold: !0, children: "API 密钥" }) }),
207
208
  /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { color: "gray", children: [
208
209
  "获取地址: ",
209
- V[l]
210
+ G[l]
210
211
  ] }) }),
211
- /* @__PURE__ */ e.jsx(o, { marginBottom: m === "apiKey" && p ? 0 : 1, children: /* @__PURE__ */ e.jsx(
212
- S,
212
+ /* @__PURE__ */ e.jsx(o, { marginBottom: m === "apiKey" && u ? 0 : 1, children: /* @__PURE__ */ e.jsx(
213
+ B,
213
214
  {
214
215
  value: b,
215
- onChange: f,
216
- onSubmit: n,
216
+ onChange: n,
217
+ onSubmit: h,
217
218
  placeholder: "sk-...",
218
219
  autoFocus: !1
219
220
  }
220
221
  ) }),
221
- p && m === "apiKey" && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { color: "red", children: [
222
+ u && m === "apiKey" && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { color: "red", children: [
222
223
  "✗ ",
223
- p
224
+ u
224
225
  ] }) }),
225
226
  m === "baseUrl" && !x && /* @__PURE__ */ e.jsx(o, { children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "💡 留空使用默认值" }) })
226
227
  ] }),
@@ -237,29 +238,29 @@ const L = ({ onNext: l, onExit: t }) => {
237
238
  ] }),
238
239
  /* @__PURE__ */ e.jsx(o, { flexDirection: "row", justifyContent: "center", children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "[Ctrl+C 退出]" }) })
239
240
  ] });
240
- }, X = ({
241
+ }, Y = ({
241
242
  provider: l,
242
- models: t,
243
- selectedModel: h,
244
- onSelect: u,
245
- onRefresh: a,
243
+ models: i,
244
+ selectedModel: j,
245
+ onSelect: p,
246
+ onRefresh: c,
246
247
  onNext: d,
247
- onBack: y,
248
- onExit: w,
249
- isLoading: p,
248
+ onBack: C,
249
+ onExit: I,
250
+ isLoading: u,
250
251
  error: m
251
252
  }) => {
252
- const g = t.map((x) => ({
253
+ const g = i.map((x) => ({
253
254
  label: x.name,
254
255
  value: x.id
255
- })), b = h ? [h] : [], f = c.useCallback(
256
+ })), b = j ? [j] : [], y = t.useCallback(
256
257
  (x) => {
257
- x.length > 0 && (u(x[0]), d());
258
+ x.length > 0 && (p(x[0]), d());
258
259
  },
259
- [u, d]
260
+ [p, d]
260
261
  );
261
- return A((x, j) => {
262
- (x === "r" || x === "R") && !p && a(), j.escape && y();
262
+ return A((x, f) => {
263
+ (x === "r" || x === "R") && !u && c(), f.escape && C();
263
264
  }), /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", flexGrow: 1, justifyContent: "center", paddingX: 2, children: [
264
265
  /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", borderStyle: "round", borderColor: "cyan", paddingX: 1, marginBottom: 1, children: [
265
266
  /* @__PURE__ */ e.jsxs(o, { flexDirection: "row", justifyContent: "space-between", borderBottom: !1, children: [
@@ -271,21 +272,21 @@ const L = ({ onNext: l, onExit: t }) => {
271
272
  /* @__PURE__ */ e.jsx(r, { color: "blue", children: "提供商 ::" }),
272
273
  /* @__PURE__ */ e.jsx(r, { color: "white", children: l.toUpperCase() })
273
274
  ] }),
274
- p && t.length === 0 && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { children: [
275
- /* @__PURE__ */ e.jsx(O, { type: "dots" }),
275
+ u && i.length === 0 && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { children: [
276
+ /* @__PURE__ */ e.jsx(R, { type: "dots" }),
276
277
  " 检测可用模型中..."
277
278
  ] }) }),
278
- !p && t.length === 0 && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(r, { color: "yellow", children: "未找到可用模型,请按 R 刷新" }) }),
279
- !p && t.length > 0 && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(r, { color: "gray", children: "选择您偏好的模型:" }) }),
280
- !p && t.length > 0 && /* @__PURE__ */ e.jsx(
281
- B,
279
+ !u && i.length === 0 && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(r, { color: "yellow", children: "未找到可用模型,请按 R 刷新" }) }),
280
+ !u && i.length > 0 && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(r, { color: "gray", children: "选择您偏好的模型:" }) }),
281
+ !u && i.length > 0 && /* @__PURE__ */ e.jsx(
282
+ T,
282
283
  {
283
284
  options: g,
284
285
  values: b,
285
286
  onChange: (x) => {
286
- x.length > 0 && u(x[0]);
287
+ x.length > 0 && p(x[0]);
287
288
  },
288
- onSubmit: f,
289
+ onSubmit: y,
289
290
  singleSelect: !0,
290
291
  autoFocus: !0
291
292
  }
@@ -308,11 +309,11 @@ const L = ({ onNext: l, onExit: t }) => {
308
309
  ] }),
309
310
  /* @__PURE__ */ e.jsx(o, { flexDirection: "row", justifyContent: "center", children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "[Ctrl+C 退出]" }) })
310
311
  ] });
311
- }, Y = {
312
+ }, F = {
312
313
  openai: "OpenAI",
313
314
  anthropic: "Anthropic"
314
- }, F = ({ provider: l, model: t, onExit: h }) => (A((u, a) => {
315
- (u || a.return) && h();
315
+ }, H = ({ provider: l, model: i, onExit: j }) => (A((p, c) => {
316
+ (p || c.return) && j();
316
317
  }), /* @__PURE__ */ e.jsx(o, { flexDirection: "column", flexGrow: 1, justifyContent: "center", paddingX: 2, children: /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", borderStyle: "round", borderColor: "green", paddingX: 1, marginBottom: 1, children: [
317
318
  /* @__PURE__ */ e.jsxs(o, { flexDirection: "row", justifyContent: "space-between", borderBottom: !1, children: [
318
319
  /* @__PURE__ */ e.jsx(r, { color: "green", bold: !0, children: "✓ 配置完成" }),
@@ -326,15 +327,15 @@ const L = ({ onNext: l, onExit: t }) => {
326
327
  /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", marginBottom: 2, gap: 1, children: [
327
328
  /* @__PURE__ */ e.jsxs(o, { children: [
328
329
  /* @__PURE__ */ e.jsx(r, { color: "blue", children: "提供商 ::" }),
329
- /* @__PURE__ */ e.jsx(r, { color: "white", children: Y[l] })
330
+ /* @__PURE__ */ e.jsx(r, { color: "white", children: F[l] })
330
331
  ] }),
331
332
  /* @__PURE__ */ e.jsxs(o, { children: [
332
333
  /* @__PURE__ */ e.jsx(r, { color: "blue", children: "模型 ::" }),
333
- /* @__PURE__ */ e.jsx(r, { color: "white", children: t })
334
+ /* @__PURE__ */ e.jsx(r, { color: "white", children: i })
334
335
  ] }),
335
336
  /* @__PURE__ */ e.jsxs(o, { children: [
336
337
  /* @__PURE__ */ e.jsx(r, { color: "blue", children: "配置路径 ::" }),
337
- /* @__PURE__ */ e.jsx(r, { color: "gray", children: R })
338
+ /* @__PURE__ */ e.jsx(r, { color: "gray", children: K })
338
339
  ] })
339
340
  ] }),
340
341
  /* @__PURE__ */ e.jsxs(o, { marginBottom: 1, flexDirection: "column", gap: 0, children: [
@@ -355,7 +356,7 @@ const L = ({ onNext: l, onExit: t }) => {
355
356
  ] })
356
357
  ] })
357
358
  ] })
358
- ] }) })), H = {
359
+ ] }) })), z = {
359
360
  step: "welcome",
360
361
  provider: null,
361
362
  apiKey: "",
@@ -363,55 +364,55 @@ const L = ({ onNext: l, onExit: t }) => {
363
364
  selectedModel: "",
364
365
  isLoading: !1,
365
366
  error: null
366
- }, z = () => {
367
- const [l, t] = c.useState(H), [h, u] = c.useState([]), a = c.useCallback(() => {
368
- t((n) => {
367
+ }, W = () => {
368
+ const [l, i] = t.useState(z), [j, p] = t.useState([]), c = t.useCallback(() => {
369
+ i((n) => {
369
370
  if (n.step === "model" && !n.selectedModel)
370
371
  return { ...n, error: "请选择一个模型" };
371
372
  if (n.step === "apiAndBaseUrl") {
372
373
  if (!n.apiKey)
373
374
  return { ...n, error: "请输入 API Key" };
374
- n.provider && (process.env.MODEL_PROVIDER = n.provider, n.provider === "openai" ? (process.env.OPENAI_API_KEY = n.apiKey, n.baseUrl && n.baseUrl !== C.openai && (process.env.OPENAI_BASE_URL = n.baseUrl)) : (process.env.ANTHROPIC_API_KEY = n.apiKey, n.baseUrl && n.baseUrl !== C.anthropic && (process.env.ANTHROPIC_BASE_URL = n.baseUrl)));
375
+ n.provider && (process.env.MODEL_PROVIDER = n.provider, n.provider === "openai" ? (process.env.OPENAI_API_KEY = n.apiKey, n.baseUrl && n.baseUrl !== w.openai && (process.env.OPENAI_BASE_URL = n.baseUrl)) : (process.env.ANTHROPIC_API_KEY = n.apiKey, n.baseUrl && n.baseUrl !== w.anthropic && (process.env.ANTHROPIC_BASE_URL = n.baseUrl)));
375
376
  }
376
- const s = ["welcome", "provider", "apiAndBaseUrl", "model", "complete"], i = s.indexOf(n.step);
377
- return i < s.length - 1 ? { ...n, step: s[i + 1], error: null } : n;
377
+ const s = ["welcome", "provider", "apiAndBaseUrl", "model", "complete"], h = s.indexOf(n.step);
378
+ return h < s.length - 1 ? { ...n, step: s[h + 1], error: null } : n;
378
379
  });
379
- }, []), d = c.useCallback(() => {
380
- t((n) => {
381
- const s = ["welcome", "provider", "apiAndBaseUrl", "model", "complete"], i = s.indexOf(n.step);
382
- return i > 0 ? { ...n, step: s[i - 1], error: null } : n;
380
+ }, []), d = t.useCallback(() => {
381
+ i((n) => {
382
+ const s = ["welcome", "provider", "apiAndBaseUrl", "model", "complete"], h = s.indexOf(n.step);
383
+ return h > 0 ? { ...n, step: s[h - 1], error: null } : n;
383
384
  });
384
- }, []), y = c.useCallback((n) => {
385
- process.env.MODEL_PROVIDER = n, t((s) => ({
385
+ }, []), C = t.useCallback((n) => {
386
+ process.env.MODEL_PROVIDER = n, i((s) => ({
386
387
  ...s,
387
388
  provider: n,
388
- baseUrl: C[n],
389
+ baseUrl: w[n],
389
390
  apiKey: "",
390
391
  selectedModel: ""
391
392
  }));
392
- }, []), w = c.useCallback((n) => {
393
- t((s) => ({ ...s, apiKey: n, error: null }));
394
- }, []), p = c.useCallback((n) => {
395
- t((s) => ({ ...s, baseUrl: n, error: null }));
396
- }, []), m = c.useCallback((n) => {
397
- t((s) => ({ ...s, selectedModel: n, error: null }));
398
- }, []), g = c.useCallback((n) => {
399
- t((s) => ({ ...s, error: n }));
400
- }, []), b = c.useCallback((n) => {
401
- t((s) => ({ ...s, isLoading: n }));
402
- }, []), f = c.useCallback(async (n, s) => {
393
+ }, []), I = t.useCallback((n) => {
394
+ i((s) => ({ ...s, apiKey: n, error: null }));
395
+ }, []), u = t.useCallback((n) => {
396
+ i((s) => ({ ...s, baseUrl: n, error: null }));
397
+ }, []), m = t.useCallback((n) => {
398
+ i((s) => ({ ...s, selectedModel: n, error: null }));
399
+ }, []), g = t.useCallback((n) => {
400
+ i((s) => ({ ...s, error: n }));
401
+ }, []), b = t.useCallback((n) => {
402
+ i((s) => ({ ...s, isLoading: n }));
403
+ }, []), y = t.useCallback(async (n, s) => {
403
404
  b(!0), g(null);
404
405
  try {
405
- const i = process.env.MODEL_PROVIDER, I = process.env.OPENAI_API_KEY, D = process.env.ANTHROPIC_API_KEY;
406
+ const h = process.env.MODEL_PROVIDER, E = process.env.OPENAI_API_KEY, a = process.env.ANTHROPIC_API_KEY;
406
407
  process.env.MODEL_PROVIDER = n, n === "openai" ? process.env.OPENAI_API_KEY = s || "temp" : process.env.ANTHROPIC_API_KEY = s || "temp";
407
- const T = (await U()).filter((_) => _.provider === n);
408
- u(T), i && (process.env.MODEL_PROVIDER = i), I && (process.env.OPENAI_API_KEY = I), D && (process.env.ANTHROPIC_API_KEY = D);
409
- } catch (i) {
410
- g(`加载模型失败: ${i instanceof Error ? i.message : String(i)}`), u([]);
408
+ const _ = (await M()).filter((P) => P.provider === n);
409
+ p(_), h && (process.env.MODEL_PROVIDER = h), E && (process.env.OPENAI_API_KEY = E), a && (process.env.ANTHROPIC_API_KEY = a);
410
+ } catch (h) {
411
+ g(`加载模型失败: ${h instanceof Error ? h.message : String(h)}`), p([]);
411
412
  } finally {
412
413
  b(!1);
413
414
  }
414
- }, []), x = c.useCallback(async () => {
415
+ }, []), x = t.useCallback(async () => {
415
416
  if (!l.provider || !l.apiKey || !l.selectedModel)
416
417
  return g("配置不完整"), !1;
417
418
  b(!0), g(null);
@@ -420,76 +421,76 @@ const L = ({ onNext: l, onExit: t }) => {
420
421
  main_model: l.selectedModel,
421
422
  model_provider: l.provider
422
423
  };
423
- return l.provider === "openai" ? (n.openai_api_key = l.apiKey, l.baseUrl && l.baseUrl !== C.openai && (n.openai_base_url = l.baseUrl)) : (n.anthropic_api_key = l.apiKey, l.baseUrl && l.baseUrl !== C.anthropic && (n.anthropic_base_url = l.baseUrl)), await K(n), !0;
424
+ return l.provider === "openai" ? (n.openai_api_key = l.apiKey, l.baseUrl && l.baseUrl !== w.openai && (n.openai_base_url = l.baseUrl)) : (n.anthropic_api_key = l.apiKey, l.baseUrl && l.baseUrl !== w.anthropic && (n.anthropic_base_url = l.baseUrl)), await v(n), !0;
424
425
  } catch (n) {
425
426
  return g(`保存配置失败: ${n instanceof Error ? n.message : String(n)}`), !1;
426
427
  } finally {
427
428
  b(!1);
428
429
  }
429
- }, [l]), j = c.useCallback(() => {
430
+ }, [l]), f = t.useCallback(() => {
430
431
  process.exit(0);
431
432
  }, []);
432
- c.useEffect(() => {
433
- l.step === "model" && l.provider && l.apiKey && f(l.provider, l.apiKey);
434
- }, [l.step, l.provider, l.apiKey, f]), A((n, s) => {
433
+ t.useEffect(() => {
434
+ l.step === "model" && l.provider && l.apiKey && y(l.provider, l.apiKey);
435
+ }, [l.step, l.provider, l.apiKey, y]), A((n, s) => {
435
436
  s.ctrl && n === "c" ? process.exit(0) : s.escape && d();
436
437
  });
437
- const E = () => {
438
+ const D = () => {
438
439
  switch (l.step) {
439
440
  case "welcome":
440
- return /* @__PURE__ */ e.jsx(L, { onNext: a, onExit: j });
441
+ return /* @__PURE__ */ e.jsx(N, { onNext: c, onExit: f });
441
442
  case "provider":
442
443
  return /* @__PURE__ */ e.jsx(
443
- k,
444
+ V,
444
445
  {
445
446
  provider: l.provider,
446
447
  onSelect: (n) => {
447
- y(n);
448
+ C(n);
448
449
  },
449
- onNext: a,
450
- onExit: j
450
+ onNext: c,
451
+ onExit: f
451
452
  }
452
453
  );
453
454
  case "apiAndBaseUrl":
454
455
  return /* @__PURE__ */ e.jsx(
455
- G,
456
+ X,
456
457
  {
457
458
  provider: l.provider,
458
459
  apiKey: l.apiKey,
459
460
  baseUrl: l.baseUrl,
460
- onApiKeyChange: w,
461
- onBaseUrlChange: p,
462
- onNext: a,
461
+ onApiKeyChange: I,
462
+ onBaseUrlChange: u,
463
+ onNext: c,
463
464
  onBack: d,
464
- onExit: j,
465
+ onExit: f,
465
466
  error: l.error
466
467
  }
467
468
  );
468
469
  case "model":
469
470
  return /* @__PURE__ */ e.jsx(
470
- X,
471
+ Y,
471
472
  {
472
473
  provider: l.provider,
473
- models: h,
474
+ models: j,
474
475
  selectedModel: l.selectedModel,
475
476
  onSelect: m,
476
- onRefresh: () => f(l.provider, l.apiKey),
477
+ onRefresh: () => y(l.provider, l.apiKey),
477
478
  onNext: async () => {
478
- await x() && a();
479
+ await x() && c();
479
480
  },
480
481
  onBack: d,
481
- onExit: j,
482
+ onExit: f,
482
483
  isLoading: l.isLoading,
483
484
  error: l.error
484
485
  }
485
486
  );
486
487
  case "complete":
487
- return /* @__PURE__ */ e.jsx(F, { provider: l.provider, model: l.selectedModel, onExit: j });
488
+ return /* @__PURE__ */ e.jsx(H, { provider: l.provider, model: l.selectedModel, onExit: f });
488
489
  }
489
490
  };
490
- return /* @__PURE__ */ e.jsx(o, { flexDirection: "column", height: "100%", width: "100%", children: E() });
491
+ return /* @__PURE__ */ e.jsx(o, { flexDirection: "column", height: "100%", width: "100%", children: D() });
491
492
  };
492
- async function W() {
493
- await v(), M(/* @__PURE__ */ e.jsx(z, {}));
493
+ async function $() {
494
+ await L(), U(/* @__PURE__ */ e.jsx(W, {}));
494
495
  }
495
- W();
496
+ $();
@@ -0,0 +1,13 @@
1
+ import { r as a, j as n, a as c, u as f, T as x } from "./use-input-CQELhJxU.mjs";
2
+ a(/* @__PURE__ */ n.jsx(l, {}));
3
+ function l() {
4
+ const [r, u] = c.useState(`Press any key...
5
+ `);
6
+ return f((i, o, p) => {
7
+ const t = ["\x1B[2J\x1B[H", "input:", JSON.stringify(i), "", "key:"], e = Object.entries(o).filter(([, s]) => s === !0);
8
+ for (const [s] of e)
9
+ t.push(` ${s}: true`);
10
+ e.length === 0 && t.push(" (no true values)"), t.push(JSON.stringify(p, null, 2)), u(t.join(`
11
+ `));
12
+ }), /* @__PURE__ */ n.jsx(x, { children: r });
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-code",
3
- "version": "1.11.0",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "cli.js",
6
6
  "bin": "cli.js",
@@ -30,6 +30,7 @@
30
30
  "node-sqlite3-wasm": "^0.8.52",
31
31
  "openai": "^6.15.0",
32
32
  "path-exists": "^5.0.0",
33
+ "string-width": "^8.1.0",
33
34
  "tempy": "^3.1.0",
34
35
  "xdg-basedir": "^5.1.0",
35
36
  "yaml": "^2.8.2",