zen-code 1.8.0 → 1.9.1
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/README.md +5 -10
- package/cli.js +7 -1
- package/dist/MultiSelect-C5LXDu1p.mjs +24274 -0
- package/dist/app-dNpdvtea.mjs +55893 -0
- package/dist/{checkpoint-1sAx_j1E-CGNACjWe.mjs → checkpoint-1sAx_j1E-B2oVQ-03.mjs} +1 -1
- package/dist/{checkpoint-DxiUsHMy-CzFo6OBy.mjs → checkpoint-DxiUsHMy-Coy2CQY_.mjs} +1 -1
- package/dist/{id-C6V2Pn12.mjs → id-D9qJdFn4.mjs} +1 -1
- package/dist/{index-UuLiZHHI.mjs → index-DmaXUmsR.mjs} +2 -2
- package/dist/{queue-BSCnCent-DCmm6lhO.mjs → queue-BSCnCent-CyRq3_Gj.mjs} +1 -1
- package/dist/{shallow-BIK7y1MI.mjs → shallow-ClMaoEQ_.mjs} +2 -2
- package/dist/zen-code.mjs +2 -1
- package/dist/zen-init.mjs +495 -0
- package/package.json +2 -4
- package/dist/app-DaHI5Ky6.mjs +0 -80138
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { K as T } from "./kysely-Bchvsze0.mjs";
|
|
2
2
|
import { F as r } from "./sql-CJsUpKEQ.mjs";
|
|
3
|
-
import { B as f, T as l, c as y, m } from "./app-
|
|
3
|
+
import { B as f, T as l, c as y, m } from "./app-dNpdvtea.mjs";
|
|
4
4
|
const g = ["source", "step", "parents"];
|
|
5
5
|
const E = g;
|
|
6
6
|
class w extends f {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { u as C } from "./id-
|
|
2
|
-
import { B as v, c as x, T as $, m as I } from "./app-
|
|
1
|
+
import { u as C } from "./id-D9qJdFn4.mjs";
|
|
2
|
+
import { B as v, c as x, T as $, m as I } from "./app-dNpdvtea.mjs";
|
|
3
3
|
import { createClient as O, createCluster as N } from "redis";
|
|
4
4
|
const W = [
|
|
5
5
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { u as $ } from "./id-
|
|
2
|
-
import { B as g } from "./app-
|
|
1
|
+
import { u as $ } from "./id-D9qJdFn4.mjs";
|
|
2
|
+
import { B as g } from "./app-dNpdvtea.mjs";
|
|
3
3
|
import { createClient as T } from "redis";
|
|
4
4
|
function k(u) {
|
|
5
5
|
if (u === null || typeof u != "object") return JSON.stringify(u);
|
package/dist/zen-code.mjs
CHANGED
|
@@ -0,0 +1,495 @@
|
|
|
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";
|
|
2
|
+
import "chalk";
|
|
3
|
+
const L = ({ onNext: l, onExit: t }) => {
|
|
4
|
+
A((a, d) => {
|
|
5
|
+
d.return ? l() : d.ctrl && a === "c" && t();
|
|
6
|
+
});
|
|
7
|
+
const [h, u] = c.useState(0);
|
|
8
|
+
return c.useEffect(() => {
|
|
9
|
+
const p = setInterval(() => {
|
|
10
|
+
u((m) => (m + 1) % 92);
|
|
11
|
+
}, 40);
|
|
12
|
+
return () => clearInterval(p);
|
|
13
|
+
}, []), /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", flexGrow: 1, justifyContent: "center", paddingX: 2, children: [
|
|
14
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "column", borderStyle: "round", borderColor: "cyan", paddingX: 1, marginBottom: 1, children: [
|
|
15
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "row", justifyContent: "space-between", borderBottom: !1, children: [
|
|
16
|
+
/* @__PURE__ */ e.jsx(r, { color: "cyan", bold: !0, children: "设置向导" }),
|
|
17
|
+
/* @__PURE__ */ e.jsx(r, { color: "gray", children: "[1/4]" })
|
|
18
|
+
] }),
|
|
19
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "row", marginTop: 1, gap: 2, children: [
|
|
20
|
+
/* @__PURE__ */ e.jsx(o, { flexDirection: "column", children: `███████╗███████╗███╗ ██╗
|
|
21
|
+
╚══███╔╝██╔════╝████╗ ██║
|
|
22
|
+
███╔╝ █████╗ ██╔██╗ ██║
|
|
23
|
+
███╔╝ ██╔══╝ ██║╚██╗██║
|
|
24
|
+
███████╗███████╗██║ ╚████║
|
|
25
|
+
╚══════╝╚══════╝╚═╝ ╚═══╝`.split(`
|
|
26
|
+
`).map((a) => /* @__PURE__ */ e.jsx(P, { interval: 40, text: a, globalIndex: h }, a)) }),
|
|
27
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "column", justifyContent: "center", flexGrow: 1, children: [
|
|
28
|
+
/* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { color: "yellow", bold: !0, children: [
|
|
29
|
+
" ",
|
|
30
|
+
"⚡ 初始化中"
|
|
31
|
+
] }) }),
|
|
32
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "column", gap: 0, children: [
|
|
33
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
34
|
+
/* @__PURE__ */ e.jsx(r, { color: "blue", children: "产品 ::" }),
|
|
35
|
+
/* @__PURE__ */ e.jsx(r, { color: "white", children: "Zen Code" })
|
|
36
|
+
] }),
|
|
37
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
38
|
+
/* @__PURE__ */ e.jsx(r, { color: "blue", children: "类型 ::" }),
|
|
39
|
+
/* @__PURE__ */ e.jsx(r, { color: "white", children: "AI 驱动的命令行助手" })
|
|
40
|
+
] }),
|
|
41
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
42
|
+
/* @__PURE__ */ e.jsx(r, { color: "blue", children: "状态 ::" }),
|
|
43
|
+
/* @__PURE__ */ e.jsx(r, { color: "green", children: "准备配置" })
|
|
44
|
+
] })
|
|
45
|
+
] }),
|
|
46
|
+
/* @__PURE__ */ e.jsxs(o, { marginTop: 1, flexDirection: "column", gap: 0, children: [
|
|
47
|
+
/* @__PURE__ */ e.jsx(r, { color: "gray", bold: !0, children: "设置步骤:" }),
|
|
48
|
+
/* @__PURE__ */ e.jsxs(r, { color: "white", children: [
|
|
49
|
+
" ",
|
|
50
|
+
"● 选择提供商"
|
|
51
|
+
] }),
|
|
52
|
+
/* @__PURE__ */ e.jsxs(r, { color: "white", children: [
|
|
53
|
+
" ",
|
|
54
|
+
"● API 配置"
|
|
55
|
+
] }),
|
|
56
|
+
/* @__PURE__ */ e.jsxs(r, { color: "white", children: [
|
|
57
|
+
" ",
|
|
58
|
+
"● 选择模型"
|
|
59
|
+
] }),
|
|
60
|
+
/* @__PURE__ */ e.jsxs(r, { color: "white", children: [
|
|
61
|
+
" ",
|
|
62
|
+
"● 完成"
|
|
63
|
+
] })
|
|
64
|
+
] })
|
|
65
|
+
] })
|
|
66
|
+
] }),
|
|
67
|
+
/* @__PURE__ */ e.jsxs(o, { marginTop: 1, paddingTop: 1, borderTop: !1, flexDirection: "row", justifyContent: "space-between", children: [
|
|
68
|
+
/* @__PURE__ */ e.jsxs(o, { gap: 3, children: [
|
|
69
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
70
|
+
/* @__PURE__ */ e.jsx(r, { color: "green", children: "●" }),
|
|
71
|
+
/* @__PURE__ */ e.jsxs(r, { color: "white", dimColor: !0, children: [
|
|
72
|
+
" ",
|
|
73
|
+
"AI 智能体"
|
|
74
|
+
] })
|
|
75
|
+
] }),
|
|
76
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
77
|
+
/* @__PURE__ */ e.jsx(r, { color: "green", children: "●" }),
|
|
78
|
+
/* @__PURE__ */ e.jsxs(r, { color: "white", dimColor: !0, children: [
|
|
79
|
+
" ",
|
|
80
|
+
"文件系统"
|
|
81
|
+
] })
|
|
82
|
+
] }),
|
|
83
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
84
|
+
/* @__PURE__ */ e.jsx(r, { color: "green", children: "●" }),
|
|
85
|
+
/* @__PURE__ */ e.jsxs(r, { color: "white", dimColor: !0, children: [
|
|
86
|
+
" ",
|
|
87
|
+
"记忆系统"
|
|
88
|
+
] })
|
|
89
|
+
] })
|
|
90
|
+
] }),
|
|
91
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
92
|
+
/* @__PURE__ */ e.jsx(r, { color: "cyan", bold: !0, children: ">>> 按 [Enter] 开始" }),
|
|
93
|
+
/* @__PURE__ */ e.jsxs(r, { color: "cyan", dimColor: !0, children: [
|
|
94
|
+
" ",
|
|
95
|
+
"▌"
|
|
96
|
+
] })
|
|
97
|
+
] })
|
|
98
|
+
] })
|
|
99
|
+
] }),
|
|
100
|
+
/* @__PURE__ */ e.jsx(o, { flexDirection: "row", justifyContent: "center", children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "[Ctrl+C 退出]" }) })
|
|
101
|
+
] });
|
|
102
|
+
}, N = [
|
|
103
|
+
{ label: "OpenAI (GPT-4, o1 等)", value: "openai" },
|
|
104
|
+
{ label: "Anthropic (Claude)", value: "anthropic" }
|
|
105
|
+
], k = ({ provider: l, onSelect: t, onNext: h, onExit: u }) => {
|
|
106
|
+
const a = c.useMemo(() => l ? [l] : [], [l]);
|
|
107
|
+
return /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", flexGrow: 1, justifyContent: "center", paddingX: 2, children: [
|
|
108
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "column", borderStyle: "round", borderColor: "cyan", paddingX: 1, marginBottom: 1, children: [
|
|
109
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "row", justifyContent: "space-between", borderBottom: !1, children: [
|
|
110
|
+
/* @__PURE__ */ e.jsx(r, { color: "cyan", bold: !0, children: "选择提供商" }),
|
|
111
|
+
/* @__PURE__ */ e.jsx(r, { color: "gray", children: "[2/4]" })
|
|
112
|
+
] }),
|
|
113
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "column", marginTop: 1, children: [
|
|
114
|
+
/* @__PURE__ */ e.jsxs(o, { marginBottom: 1, children: [
|
|
115
|
+
/* @__PURE__ */ e.jsx(r, { color: "blue", children: "步骤 ::" }),
|
|
116
|
+
/* @__PURE__ */ e.jsx(r, { color: "white", children: " 选择 AI 提供商" })
|
|
117
|
+
] }),
|
|
118
|
+
/* @__PURE__ */ e.jsxs(o, { marginBottom: 1, flexDirection: "column", gap: 0, children: [
|
|
119
|
+
/* @__PURE__ */ e.jsx(r, { color: "gray", children: "选择您要使用的 AI 服务:" }),
|
|
120
|
+
/* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "• OpenAI: GPT-4, o1 等模型" }),
|
|
121
|
+
/* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "• Anthropic: Claude 3.5 Sonnet, Opus" })
|
|
122
|
+
] }),
|
|
123
|
+
/* @__PURE__ */ e.jsx(o, { marginTop: 1, marginBottom: 1, children: /* @__PURE__ */ e.jsx(
|
|
124
|
+
B,
|
|
125
|
+
{
|
|
126
|
+
options: N,
|
|
127
|
+
values: a,
|
|
128
|
+
onChange: (d) => {
|
|
129
|
+
d.length > 0 && t(d[0]);
|
|
130
|
+
},
|
|
131
|
+
onSubmit: h,
|
|
132
|
+
singleSelect: !0,
|
|
133
|
+
autoFocus: !0
|
|
134
|
+
}
|
|
135
|
+
) })
|
|
136
|
+
] }),
|
|
137
|
+
/* @__PURE__ */ e.jsxs(o, { marginTop: 1, paddingTop: 1, borderTop: !1, flexDirection: "row", justifyContent: "space-between", children: [
|
|
138
|
+
/* @__PURE__ */ e.jsx(o, { children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "↑/↓ 导航 | Enter 确认" }) }),
|
|
139
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
140
|
+
/* @__PURE__ */ e.jsx(r, { color: "cyan", bold: !0, children: ">>> 选择提供商" }),
|
|
141
|
+
/* @__PURE__ */ e.jsxs(r, { color: "cyan", dimColor: !0, children: [
|
|
142
|
+
" ",
|
|
143
|
+
"▌"
|
|
144
|
+
] })
|
|
145
|
+
] })
|
|
146
|
+
] })
|
|
147
|
+
] }),
|
|
148
|
+
/* @__PURE__ */ e.jsx(o, { flexDirection: "row", justifyContent: "center", children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "[Ctrl+C 退出]" }) })
|
|
149
|
+
] });
|
|
150
|
+
}, C = {
|
|
151
|
+
openai: "https://api.openai.com/v1",
|
|
152
|
+
anthropic: "https://api.anthropic.com"
|
|
153
|
+
}, V = {
|
|
154
|
+
openai: "https://platform.openai.com/api-keys",
|
|
155
|
+
anthropic: "https://console.anthropic.com/settings/keys"
|
|
156
|
+
}, G = ({
|
|
157
|
+
provider: l,
|
|
158
|
+
apiKey: t,
|
|
159
|
+
baseUrl: h,
|
|
160
|
+
onApiKeyChange: u,
|
|
161
|
+
onBaseUrlChange: a,
|
|
162
|
+
onNext: d,
|
|
163
|
+
onBack: y,
|
|
164
|
+
onExit: w,
|
|
165
|
+
error: p
|
|
166
|
+
}) => {
|
|
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();
|
|
175
|
+
};
|
|
176
|
+
return A((i, I) => {
|
|
177
|
+
if (I.ctrl && i === "c" && w(), I.escape) {
|
|
178
|
+
y();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
}), /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", flexGrow: 1, justifyContent: "center", paddingX: 2, children: [
|
|
182
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "column", borderStyle: "round", borderColor: "cyan", paddingX: 1, marginBottom: 1, children: [
|
|
183
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "row", justifyContent: "space-between", borderBottom: !1, children: [
|
|
184
|
+
/* @__PURE__ */ e.jsx(r, { color: "cyan", bold: !0, children: "API CONFIGURATION" }),
|
|
185
|
+
/* @__PURE__ */ e.jsx(r, { color: "gray", children: "[3/4]" })
|
|
186
|
+
] }),
|
|
187
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "column", marginTop: 1, children: [
|
|
188
|
+
/* @__PURE__ */ e.jsxs(o, { marginBottom: 1, children: [
|
|
189
|
+
/* @__PURE__ */ e.jsx(r, { color: "blue", children: "PROVIDER::" }),
|
|
190
|
+
/* @__PURE__ */ e.jsx(r, { color: "white", children: l.toUpperCase() })
|
|
191
|
+
] }),
|
|
192
|
+
/* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(r, { bold: !0, children: "Base URL (可选)" }) }),
|
|
193
|
+
/* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { color: "gray", children: [
|
|
194
|
+
"默认值: ",
|
|
195
|
+
E
|
|
196
|
+
] }) }),
|
|
197
|
+
/* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(
|
|
198
|
+
S,
|
|
199
|
+
{
|
|
200
|
+
value: x,
|
|
201
|
+
onChange: j,
|
|
202
|
+
onSubmit: s,
|
|
203
|
+
placeholder: E
|
|
204
|
+
}
|
|
205
|
+
) }),
|
|
206
|
+
/* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsx(r, { bold: !0, children: "API 密钥" }) }),
|
|
207
|
+
/* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { color: "gray", children: [
|
|
208
|
+
"获取地址: ",
|
|
209
|
+
V[l]
|
|
210
|
+
] }) }),
|
|
211
|
+
/* @__PURE__ */ e.jsx(o, { marginBottom: m === "apiKey" && p ? 0 : 1, children: /* @__PURE__ */ e.jsx(
|
|
212
|
+
S,
|
|
213
|
+
{
|
|
214
|
+
value: b,
|
|
215
|
+
onChange: f,
|
|
216
|
+
onSubmit: n,
|
|
217
|
+
placeholder: "sk-...",
|
|
218
|
+
autoFocus: !1
|
|
219
|
+
}
|
|
220
|
+
) }),
|
|
221
|
+
p && m === "apiKey" && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { color: "red", children: [
|
|
222
|
+
"✗ ",
|
|
223
|
+
p
|
|
224
|
+
] }) }),
|
|
225
|
+
m === "baseUrl" && !x && /* @__PURE__ */ e.jsx(o, { children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "💡 留空使用默认值" }) })
|
|
226
|
+
] }),
|
|
227
|
+
/* @__PURE__ */ e.jsxs(o, { marginTop: 1, paddingTop: 1, borderTop: !1, flexDirection: "row", justifyContent: "space-between", children: [
|
|
228
|
+
/* @__PURE__ */ e.jsx(o, { children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "Tab/Shift+Tab 切换 | Enter 确认 | Esc 返回" }) }),
|
|
229
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
230
|
+
/* @__PURE__ */ e.jsx(r, { color: "cyan", bold: !0, children: ">>> 输入 API 密钥" }),
|
|
231
|
+
/* @__PURE__ */ e.jsxs(r, { color: "cyan", dimColor: !0, children: [
|
|
232
|
+
" ",
|
|
233
|
+
"▌"
|
|
234
|
+
] })
|
|
235
|
+
] })
|
|
236
|
+
] })
|
|
237
|
+
] }),
|
|
238
|
+
/* @__PURE__ */ e.jsx(o, { flexDirection: "row", justifyContent: "center", children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "[Ctrl+C 退出]" }) })
|
|
239
|
+
] });
|
|
240
|
+
}, X = ({
|
|
241
|
+
provider: l,
|
|
242
|
+
models: t,
|
|
243
|
+
selectedModel: h,
|
|
244
|
+
onSelect: u,
|
|
245
|
+
onRefresh: a,
|
|
246
|
+
onNext: d,
|
|
247
|
+
onBack: y,
|
|
248
|
+
onExit: w,
|
|
249
|
+
isLoading: p,
|
|
250
|
+
error: m
|
|
251
|
+
}) => {
|
|
252
|
+
const g = t.map((x) => ({
|
|
253
|
+
label: x.name,
|
|
254
|
+
value: x.id
|
|
255
|
+
})), b = h ? [h] : [], f = c.useCallback(
|
|
256
|
+
(x) => {
|
|
257
|
+
x.length > 0 && (u(x[0]), d());
|
|
258
|
+
},
|
|
259
|
+
[u, d]
|
|
260
|
+
);
|
|
261
|
+
return A((x, j) => {
|
|
262
|
+
(x === "r" || x === "R") && !p && a(), j.escape && y();
|
|
263
|
+
}), /* @__PURE__ */ e.jsxs(o, { flexDirection: "column", flexGrow: 1, justifyContent: "center", paddingX: 2, children: [
|
|
264
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "column", borderStyle: "round", borderColor: "cyan", paddingX: 1, marginBottom: 1, children: [
|
|
265
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "row", justifyContent: "space-between", borderBottom: !1, children: [
|
|
266
|
+
/* @__PURE__ */ e.jsx(r, { color: "cyan", bold: !0, children: "选择模型" }),
|
|
267
|
+
/* @__PURE__ */ e.jsx(r, { color: "gray", children: "[4/4]" })
|
|
268
|
+
] }),
|
|
269
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "column", marginTop: 1, children: [
|
|
270
|
+
/* @__PURE__ */ e.jsxs(o, { marginBottom: 1, children: [
|
|
271
|
+
/* @__PURE__ */ e.jsx(r, { color: "blue", children: "提供商 ::" }),
|
|
272
|
+
/* @__PURE__ */ e.jsx(r, { color: "white", children: l.toUpperCase() })
|
|
273
|
+
] }),
|
|
274
|
+
p && t.length === 0 && /* @__PURE__ */ e.jsx(o, { marginBottom: 1, children: /* @__PURE__ */ e.jsxs(r, { children: [
|
|
275
|
+
/* @__PURE__ */ e.jsx(O, { type: "dots" }),
|
|
276
|
+
" 检测可用模型中..."
|
|
277
|
+
] }) }),
|
|
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,
|
|
282
|
+
{
|
|
283
|
+
options: g,
|
|
284
|
+
values: b,
|
|
285
|
+
onChange: (x) => {
|
|
286
|
+
x.length > 0 && u(x[0]);
|
|
287
|
+
},
|
|
288
|
+
onSubmit: f,
|
|
289
|
+
singleSelect: !0,
|
|
290
|
+
autoFocus: !0
|
|
291
|
+
}
|
|
292
|
+
),
|
|
293
|
+
m && /* @__PURE__ */ e.jsx(o, { marginTop: 1, children: /* @__PURE__ */ e.jsxs(r, { color: "red", children: [
|
|
294
|
+
"✗ ",
|
|
295
|
+
m
|
|
296
|
+
] }) })
|
|
297
|
+
] }),
|
|
298
|
+
/* @__PURE__ */ e.jsxs(o, { marginTop: 1, paddingTop: 1, borderTop: !1, flexDirection: "row", justifyContent: "space-between", children: [
|
|
299
|
+
/* @__PURE__ */ e.jsx(o, { children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "↑/↓ 导航 | Enter 确认 | R 刷新 | Esc 返回" }) }),
|
|
300
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
301
|
+
/* @__PURE__ */ e.jsx(r, { color: "cyan", bold: !0, children: ">>> 选择模型" }),
|
|
302
|
+
/* @__PURE__ */ e.jsxs(r, { color: "cyan", dimColor: !0, children: [
|
|
303
|
+
" ",
|
|
304
|
+
"▌"
|
|
305
|
+
] })
|
|
306
|
+
] })
|
|
307
|
+
] })
|
|
308
|
+
] }),
|
|
309
|
+
/* @__PURE__ */ e.jsx(o, { flexDirection: "row", justifyContent: "center", children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "[Ctrl+C 退出]" }) })
|
|
310
|
+
] });
|
|
311
|
+
}, Y = {
|
|
312
|
+
openai: "OpenAI",
|
|
313
|
+
anthropic: "Anthropic"
|
|
314
|
+
}, F = ({ provider: l, model: t, onExit: h }) => (A((u, a) => {
|
|
315
|
+
(u || a.return) && h();
|
|
316
|
+
}), /* @__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
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "row", justifyContent: "space-between", borderBottom: !1, children: [
|
|
318
|
+
/* @__PURE__ */ e.jsx(r, { color: "green", bold: !0, children: "✓ 配置完成" }),
|
|
319
|
+
/* @__PURE__ */ e.jsx(r, { color: "gray", children: "[完成]" })
|
|
320
|
+
] }),
|
|
321
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "column", marginTop: 1, children: [
|
|
322
|
+
/* @__PURE__ */ e.jsxs(o, { marginBottom: 1, children: [
|
|
323
|
+
/* @__PURE__ */ e.jsx(r, { color: "blue", children: "状态 ::" }),
|
|
324
|
+
/* @__PURE__ */ e.jsx(r, { color: "green", children: "配置已保存" })
|
|
325
|
+
] }),
|
|
326
|
+
/* @__PURE__ */ e.jsxs(o, { flexDirection: "column", marginBottom: 2, gap: 1, children: [
|
|
327
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
328
|
+
/* @__PURE__ */ e.jsx(r, { color: "blue", children: "提供商 ::" }),
|
|
329
|
+
/* @__PURE__ */ e.jsx(r, { color: "white", children: Y[l] })
|
|
330
|
+
] }),
|
|
331
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
332
|
+
/* @__PURE__ */ e.jsx(r, { color: "blue", children: "模型 ::" }),
|
|
333
|
+
/* @__PURE__ */ e.jsx(r, { color: "white", children: t })
|
|
334
|
+
] }),
|
|
335
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
336
|
+
/* @__PURE__ */ e.jsx(r, { color: "blue", children: "配置路径 ::" }),
|
|
337
|
+
/* @__PURE__ */ e.jsx(r, { color: "gray", children: R })
|
|
338
|
+
] })
|
|
339
|
+
] }),
|
|
340
|
+
/* @__PURE__ */ e.jsxs(o, { marginBottom: 1, flexDirection: "column", gap: 0, children: [
|
|
341
|
+
/* @__PURE__ */ e.jsxs(r, { color: "green", bold: !0, children: [
|
|
342
|
+
" ",
|
|
343
|
+
"✓ 准备就绪!"
|
|
344
|
+
] }),
|
|
345
|
+
/* @__PURE__ */ e.jsx(r, { color: "gray", children: "请重新启动 zen-code 开始使用" })
|
|
346
|
+
] })
|
|
347
|
+
] }),
|
|
348
|
+
/* @__PURE__ */ e.jsxs(o, { marginTop: 1, paddingTop: 1, borderTop: !1, flexDirection: "row", justifyContent: "space-between", children: [
|
|
349
|
+
/* @__PURE__ */ e.jsx(o, { children: /* @__PURE__ */ e.jsx(r, { color: "gray", dimColor: !0, children: "按任意键退出" }) }),
|
|
350
|
+
/* @__PURE__ */ e.jsxs(o, { children: [
|
|
351
|
+
/* @__PURE__ */ e.jsx(r, { color: "green", bold: !0, children: ">>> 全部完成" }),
|
|
352
|
+
/* @__PURE__ */ e.jsxs(r, { color: "green", dimColor: !0, children: [
|
|
353
|
+
" ",
|
|
354
|
+
"▌"
|
|
355
|
+
] })
|
|
356
|
+
] })
|
|
357
|
+
] })
|
|
358
|
+
] }) })), H = {
|
|
359
|
+
step: "welcome",
|
|
360
|
+
provider: null,
|
|
361
|
+
apiKey: "",
|
|
362
|
+
baseUrl: "",
|
|
363
|
+
selectedModel: "",
|
|
364
|
+
isLoading: !1,
|
|
365
|
+
error: null
|
|
366
|
+
}, z = () => {
|
|
367
|
+
const [l, t] = c.useState(H), [h, u] = c.useState([]), a = c.useCallback(() => {
|
|
368
|
+
t((n) => {
|
|
369
|
+
if (n.step === "model" && !n.selectedModel)
|
|
370
|
+
return { ...n, error: "请选择一个模型" };
|
|
371
|
+
if (n.step === "apiAndBaseUrl") {
|
|
372
|
+
if (!n.apiKey)
|
|
373
|
+
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
|
+
}
|
|
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;
|
|
378
|
+
});
|
|
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;
|
|
383
|
+
});
|
|
384
|
+
}, []), y = c.useCallback((n) => {
|
|
385
|
+
process.env.MODEL_PROVIDER = n, t((s) => ({
|
|
386
|
+
...s,
|
|
387
|
+
provider: n,
|
|
388
|
+
baseUrl: C[n],
|
|
389
|
+
apiKey: "",
|
|
390
|
+
selectedModel: ""
|
|
391
|
+
}));
|
|
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) => {
|
|
403
|
+
b(!0), g(null);
|
|
404
|
+
try {
|
|
405
|
+
const i = process.env.MODEL_PROVIDER, I = process.env.OPENAI_API_KEY, D = process.env.ANTHROPIC_API_KEY;
|
|
406
|
+
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([]);
|
|
411
|
+
} finally {
|
|
412
|
+
b(!1);
|
|
413
|
+
}
|
|
414
|
+
}, []), x = c.useCallback(async () => {
|
|
415
|
+
if (!l.provider || !l.apiKey || !l.selectedModel)
|
|
416
|
+
return g("配置不完整"), !1;
|
|
417
|
+
b(!0), g(null);
|
|
418
|
+
try {
|
|
419
|
+
const n = {
|
|
420
|
+
main_model: l.selectedModel,
|
|
421
|
+
model_provider: l.provider
|
|
422
|
+
};
|
|
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
|
+
} catch (n) {
|
|
425
|
+
return g(`保存配置失败: ${n instanceof Error ? n.message : String(n)}`), !1;
|
|
426
|
+
} finally {
|
|
427
|
+
b(!1);
|
|
428
|
+
}
|
|
429
|
+
}, [l]), j = c.useCallback(() => {
|
|
430
|
+
process.exit(0);
|
|
431
|
+
}, []);
|
|
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) => {
|
|
435
|
+
s.ctrl && n === "c" ? process.exit(0) : s.escape && d();
|
|
436
|
+
});
|
|
437
|
+
const E = () => {
|
|
438
|
+
switch (l.step) {
|
|
439
|
+
case "welcome":
|
|
440
|
+
return /* @__PURE__ */ e.jsx(L, { onNext: a, onExit: j });
|
|
441
|
+
case "provider":
|
|
442
|
+
return /* @__PURE__ */ e.jsx(
|
|
443
|
+
k,
|
|
444
|
+
{
|
|
445
|
+
provider: l.provider,
|
|
446
|
+
onSelect: (n) => {
|
|
447
|
+
y(n);
|
|
448
|
+
},
|
|
449
|
+
onNext: a,
|
|
450
|
+
onExit: j
|
|
451
|
+
}
|
|
452
|
+
);
|
|
453
|
+
case "apiAndBaseUrl":
|
|
454
|
+
return /* @__PURE__ */ e.jsx(
|
|
455
|
+
G,
|
|
456
|
+
{
|
|
457
|
+
provider: l.provider,
|
|
458
|
+
apiKey: l.apiKey,
|
|
459
|
+
baseUrl: l.baseUrl,
|
|
460
|
+
onApiKeyChange: w,
|
|
461
|
+
onBaseUrlChange: p,
|
|
462
|
+
onNext: a,
|
|
463
|
+
onBack: d,
|
|
464
|
+
onExit: j,
|
|
465
|
+
error: l.error
|
|
466
|
+
}
|
|
467
|
+
);
|
|
468
|
+
case "model":
|
|
469
|
+
return /* @__PURE__ */ e.jsx(
|
|
470
|
+
X,
|
|
471
|
+
{
|
|
472
|
+
provider: l.provider,
|
|
473
|
+
models: h,
|
|
474
|
+
selectedModel: l.selectedModel,
|
|
475
|
+
onSelect: m,
|
|
476
|
+
onRefresh: () => f(l.provider, l.apiKey),
|
|
477
|
+
onNext: async () => {
|
|
478
|
+
await x() && a();
|
|
479
|
+
},
|
|
480
|
+
onBack: d,
|
|
481
|
+
onExit: j,
|
|
482
|
+
isLoading: l.isLoading,
|
|
483
|
+
error: l.error
|
|
484
|
+
}
|
|
485
|
+
);
|
|
486
|
+
case "complete":
|
|
487
|
+
return /* @__PURE__ */ e.jsx(F, { provider: l.provider, model: l.selectedModel, onExit: j });
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
return /* @__PURE__ */ e.jsx(o, { flexDirection: "column", height: "100%", width: "100%", children: E() });
|
|
491
|
+
};
|
|
492
|
+
async function W() {
|
|
493
|
+
await v(), M(/* @__PURE__ */ e.jsx(z, {}));
|
|
494
|
+
}
|
|
495
|
+
W();
|