zen-code 4.0.0 → 4.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.
@@ -0,0 +1,91 @@
1
+ import { Low as s } from "lowdb";
2
+ import { JSONFile as p } from "lowdb/node";
3
+ import d from "node:os";
4
+ import n from "node:path";
5
+ import c from "node:fs";
6
+ const r = {
7
+ config: {
8
+ provider_id: "default",
9
+ provider_type: "openai",
10
+ model_id: "gpt-5.2",
11
+ providers: [
12
+ {
13
+ id: "default",
14
+ type: "openai",
15
+ apiKey: "",
16
+ baseUrl: "https://api.openai.com/v1"
17
+ }
18
+ ]
19
+ }
20
+ };
21
+ function h(i) {
22
+ return "main_model" in i && !("providers" in i);
23
+ }
24
+ function _(i) {
25
+ const o = [];
26
+ (i.model_provider === "openai" || i.openai_api_key || i.openai_base_url) && o.push({
27
+ id: "openai",
28
+ type: "openai",
29
+ apiKey: i.openai_api_key || "",
30
+ baseUrl: i.openai_base_url || "https://api.openai.com/v1"
31
+ }), (i.model_provider === "anthropic" || i.anthropic_api_key || i.anthropic_base_url) && o.push({
32
+ id: "anthropic",
33
+ type: "anthropic",
34
+ apiKey: i.anthropic_api_key || "",
35
+ baseUrl: i.anthropic_base_url || "https://api.anthropic.com"
36
+ }), o.length === 0 && o.push({
37
+ id: "default",
38
+ type: "openai",
39
+ apiKey: "",
40
+ baseUrl: "https://api.openai.com/v1"
41
+ });
42
+ const e = i.model_provider === "anthropic" ? "anthropic" : "openai", t = o.find((a) => a.id === e) || o[0];
43
+ return {
44
+ provider_id: t.id,
45
+ provider_type: t.type,
46
+ model_id: i.main_model,
47
+ providers: o,
48
+ mcp_config: i.mcp_config,
49
+ stream_refresh_interval: i.stream_refresh_interval,
50
+ enable_thinking: i.enable_thinking,
51
+ switch_command: i.switch_command,
52
+ compact_mode: i.compact_mode,
53
+ permissions: i.permissions
54
+ };
55
+ }
56
+ class u {
57
+ db;
58
+ zenConfigDir;
59
+ dbPath;
60
+ constructor() {
61
+ const o = d.homedir();
62
+ this.zenConfigDir = n.join(o, ".zen-code");
63
+ const e = n.join(this.zenConfigDir, "settings.json"), t = new p(e);
64
+ this.dbPath = e, this.db = new s(t, r);
65
+ }
66
+ async initialize() {
67
+ await c.promises.mkdir(this.zenConfigDir, { recursive: !0 }), await this.db.read(), !this.db.data || !this.db.data.config ? (this.db.data = r, await this.db.write()) : h(this.db.data.config) && (console.log("Migrating legacy config to new format..."), this.db.data.config = _(this.db.data.config), await this.db.write(), console.log("Config migration completed.")), this.syncEnvFromConfig();
68
+ }
69
+ async getConfig() {
70
+ return await this.db.read(), this.db.data.config;
71
+ }
72
+ async updateConfig(o) {
73
+ await this.db.read(), Object.assign(this.db.data.config, o), await this.db.write(), this.syncEnvFromConfig();
74
+ }
75
+ /**
76
+ * 将配置同步到环境变量
77
+ */
78
+ syncEnvFromConfig() {
79
+ const o = this.db.data.config, e = o.providers.find((t) => t.id === o.provider_id);
80
+ e && (e.type === "openai" ? (process.env.MODEL_PROVIDER = "openai", process.env.OPENAI_API_KEY = e.apiKey, process.env.OPENAI_BASE_URL = e.baseUrl) : e.type === "anthropic" && (process.env.MODEL_PROVIDER = "anthropic", process.env.ANTHROPIC_API_KEY = e.apiKey, process.env.ANTHROPIC_BASE_URL = e.baseUrl));
81
+ }
82
+ /**
83
+ * 获取配置目录路径
84
+ */
85
+ getZenConfigDir() {
86
+ return this.zenConfigDir;
87
+ }
88
+ }
89
+ export {
90
+ u as FileSystemConfigStore
91
+ };