zen-code 2.0.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-CZS5qXWj.mjs";
1
+ import "./use-input-CQELhJxU.mjs";
2
2
  import "chalk";
3
- import "./app-BYHr8LGb.mjs";
3
+ import "./app-CdJSgzzZ.mjs";
package/dist/zen-init.mjs CHANGED
@@ -1,11 +1,12 @@
1
- import { u as A, r as i, j as e, B as o, T as r, S as U, M as T, a as B, b as O, d as R, g as K, c as v, i as M, e as L } from "./MultiSelect-CZS5qXWj.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 N = ({ onNext: l, onExit: 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 }) => {
4
5
  A((c, d) => {
5
- d.return ? l() : d.ctrl && c === "c" && t();
6
+ d.return ? l() : d.ctrl && c === "c" && i();
6
7
  });
7
- const [j, p] = i.useState(0);
8
- return i.useEffect(() => {
8
+ const [j, p] = t.useState(0);
9
+ return t.useEffect(() => {
9
10
  const u = setInterval(() => {
10
11
  p((m) => (m + 1) % 92);
11
12
  }, 40);
@@ -23,7 +24,7 @@ const N = ({ onNext: l, onExit: t }) => {
23
24
  ███╔╝ ██╔══╝ ██║╚██╗██║
24
25
  ███████╗███████╗██║ ╚████║
25
26
  ╚══════╝╚══════╝╚═╝ ╚═══╝`.split(`
26
- `).map((c) => /* @__PURE__ */ e.jsx(U, { interval: 40, text: c, globalIndex: j }, c)) }),
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
  " ",
@@ -102,8 +103,8 @@ const N = ({ onNext: l, onExit: t }) => {
102
103
  }, k = [
103
104
  { label: "OpenAI (GPT-4, o1 等)", value: "openai" },
104
105
  { label: "Anthropic (Claude)", value: "anthropic" }
105
- ], V = ({ provider: l, onSelect: t, onNext: j, onExit: p }) => {
106
- const c = i.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: [
@@ -126,7 +127,7 @@ const N = ({ onNext: l, onExit: t }) => {
126
127
  options: k,
127
128
  values: c,
128
129
  onChange: (d) => {
129
- d.length > 0 && t(d[0]);
130
+ d.length > 0 && i(d[0]);
130
131
  },
131
132
  onSubmit: j,
132
133
  singleSelect: !0,
@@ -155,7 +156,7 @@ const N = ({ onNext: l, onExit: t }) => {
155
156
  anthropic: "https://console.anthropic.com/settings/keys"
156
157
  }, X = ({
157
158
  provider: l,
158
- apiKey: t,
159
+ apiKey: i,
159
160
  baseUrl: j,
160
161
  onApiKeyChange: p,
161
162
  onBaseUrlChange: c,
@@ -164,7 +165,7 @@ const N = ({ onNext: l, onExit: t }) => {
164
165
  onExit: I,
165
166
  error: u
166
167
  }) => {
167
- const [m, g] = i.useState("apiKey"), [b, y] = i.useState(t), [x, f] = i.useState(j), D = w[l], n = (a) => {
168
+ const [m, g] = t.useState("apiKey"), [b, y] = t.useState(i), [x, f] = t.useState(j), D = w[l], n = (a) => {
168
169
  y(a), p(a);
169
170
  }, s = (a) => {
170
171
  f(a), c(a);
@@ -239,7 +240,7 @@ const N = ({ onNext: l, onExit: t }) => {
239
240
  ] });
240
241
  }, Y = ({
241
242
  provider: l,
242
- models: t,
243
+ models: i,
243
244
  selectedModel: j,
244
245
  onSelect: p,
245
246
  onRefresh: c,
@@ -249,10 +250,10 @@ const N = ({ onNext: l, onExit: t }) => {
249
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 = j ? [j] : [], y = i.useCallback(
256
+ })), b = j ? [j] : [], y = t.useCallback(
256
257
  (x) => {
257
258
  x.length > 0 && (p(x[0]), d());
258
259
  },
@@ -271,13 +272,13 @@ const N = ({ 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
- u && 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
- !u && t.length === 0 && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(r, { color: "yellow", children: "未找到可用模型,请按 R 刷新" }) }),
279
- !u && t.length > 0 && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(r, { color: "gray", children: "选择您偏好的模型:" }) }),
280
- !u && t.length > 0 && /* @__PURE__ */ e.jsx(
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(
281
282
  T,
282
283
  {
283
284
  options: g,
@@ -311,7 +312,7 @@ const N = ({ onNext: l, onExit: t }) => {
311
312
  }, F = {
312
313
  openai: "OpenAI",
313
314
  anthropic: "Anthropic"
314
- }, H = ({ provider: l, model: t, onExit: j }) => (A((p, c) => {
315
+ }, H = ({ provider: l, model: i, onExit: j }) => (A((p, c) => {
315
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: [
@@ -330,11 +331,11 @@ const N = ({ onNext: l, onExit: t }) => {
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: [
@@ -364,8 +365,8 @@ const N = ({ onNext: l, onExit: t }) => {
364
365
  isLoading: !1,
365
366
  error: null
366
367
  }, W = () => {
367
- const [l, t] = i.useState(z), [j, p] = i.useState([]), c = i.useCallback(() => {
368
- t((n) => {
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") {
@@ -376,42 +377,42 @@ const N = ({ onNext: l, onExit: t }) => {
376
377
  const s = ["welcome", "provider", "apiAndBaseUrl", "model", "complete"], h = s.indexOf(n.step);
377
378
  return h < s.length - 1 ? { ...n, step: s[h + 1], error: null } : n;
378
379
  });
379
- }, []), d = i.useCallback(() => {
380
- t((n) => {
380
+ }, []), d = t.useCallback(() => {
381
+ i((n) => {
381
382
  const s = ["welcome", "provider", "apiAndBaseUrl", "model", "complete"], h = s.indexOf(n.step);
382
383
  return h > 0 ? { ...n, step: s[h - 1], error: null } : n;
383
384
  });
384
- }, []), C = i.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
389
  baseUrl: w[n],
389
390
  apiKey: "",
390
391
  selectedModel: ""
391
392
  }));
392
- }, []), I = i.useCallback((n) => {
393
- t((s) => ({ ...s, apiKey: n, error: null }));
394
- }, []), u = i.useCallback((n) => {
395
- t((s) => ({ ...s, baseUrl: n, error: null }));
396
- }, []), m = i.useCallback((n) => {
397
- t((s) => ({ ...s, selectedModel: n, error: null }));
398
- }, []), g = i.useCallback((n) => {
399
- t((s) => ({ ...s, error: n }));
400
- }, []), b = i.useCallback((n) => {
401
- t((s) => ({ ...s, isLoading: n }));
402
- }, []), y = i.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
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 _ = (await K()).filter((P) => P.provider === n);
408
+ const _ = (await M()).filter((P) => P.provider === n);
408
409
  p(_), h && (process.env.MODEL_PROVIDER = h), E && (process.env.OPENAI_API_KEY = E), a && (process.env.ANTHROPIC_API_KEY = a);
409
410
  } catch (h) {
410
411
  g(`加载模型失败: ${h instanceof Error ? h.message : String(h)}`), p([]);
411
412
  } finally {
412
413
  b(!1);
413
414
  }
414
- }, []), x = i.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);
@@ -426,10 +427,10 @@ const N = ({ onNext: l, onExit: t }) => {
426
427
  } finally {
427
428
  b(!1);
428
429
  }
429
- }, [l]), f = i.useCallback(() => {
430
+ }, [l]), f = t.useCallback(() => {
430
431
  process.exit(0);
431
432
  }, []);
432
- i.useEffect(() => {
433
+ t.useEffect(() => {
433
434
  l.step === "model" && l.provider && l.apiKey && y(l.provider, l.apiKey);
434
435
  }, [l.step, l.provider, l.apiKey, y]), A((n, s) => {
435
436
  s.ctrl && n === "c" ? process.exit(0) : s.escape && d();
@@ -490,6 +491,6 @@ const N = ({ onNext: l, onExit: t }) => {
490
491
  return /* @__PURE__ */ e.jsx(o, { flexDirection: "column", height: "100%", width: "100%", children: D() });
491
492
  };
492
493
  async function $() {
493
- await M(), L(/* @__PURE__ */ e.jsx(W, {}));
494
+ await L(), U(/* @__PURE__ */ e.jsx(W, {}));
494
495
  }
495
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": "2.0.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",