@codelia/config-loader 0.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/index.cjs +226 -0
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +184 -0
- package/package.json +29 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
appendPermissionAllowRule: () => appendPermissionAllowRule,
|
|
34
|
+
appendPermissionAllowRules: () => appendPermissionAllowRules,
|
|
35
|
+
loadConfig: () => loadConfig,
|
|
36
|
+
loadMcpServers: () => loadMcpServers,
|
|
37
|
+
removeMcpServerConfig: () => removeMcpServerConfig,
|
|
38
|
+
setMcpServerEnabled: () => setMcpServerEnabled,
|
|
39
|
+
updateModelConfig: () => updateModelConfig,
|
|
40
|
+
upsertMcpServerConfig: () => upsertMcpServerConfig
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(index_exports);
|
|
43
|
+
var import_promises = require("fs/promises");
|
|
44
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
45
|
+
var import_config = require("@codelia/config");
|
|
46
|
+
var import_cosmiconfig = require("cosmiconfig");
|
|
47
|
+
var MODULE_NAME = "codelia";
|
|
48
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
49
|
+
var isMissingFileError = (error) => typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
50
|
+
var pickDefined = (value) => Object.fromEntries(
|
|
51
|
+
Object.entries(value).filter(([, entry]) => entry !== void 0)
|
|
52
|
+
);
|
|
53
|
+
var pickString = (value) => typeof value === "string" ? value : void 0;
|
|
54
|
+
var readConfigRaw = async (configPath) => {
|
|
55
|
+
let raw;
|
|
56
|
+
try {
|
|
57
|
+
raw = await (0, import_promises.readFile)(configPath, "utf8");
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (isMissingFileError(error)) return null;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = JSON.parse(raw);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
+
throw new Error(`Failed to parse config.json: ${message}`);
|
|
68
|
+
}
|
|
69
|
+
if (!isRecord(parsed)) {
|
|
70
|
+
throw new Error("config.json must be a JSON object");
|
|
71
|
+
}
|
|
72
|
+
return parsed;
|
|
73
|
+
};
|
|
74
|
+
var ensureVersion = (raw, configPath) => {
|
|
75
|
+
const version = raw.version ?? import_config.CONFIG_VERSION;
|
|
76
|
+
if (version !== import_config.CONFIG_VERSION) {
|
|
77
|
+
throw new Error(`${configPath}: unsupported version ${String(version)}`);
|
|
78
|
+
}
|
|
79
|
+
return version;
|
|
80
|
+
};
|
|
81
|
+
var writeConfigRaw = async (configPath, raw) => {
|
|
82
|
+
await (0, import_promises.mkdir)(import_node_path.default.dirname(configPath), { recursive: true });
|
|
83
|
+
await (0, import_promises.writeFile)(configPath, `${JSON.stringify(raw, null, 2)}
|
|
84
|
+
`, "utf8");
|
|
85
|
+
};
|
|
86
|
+
var getRawMcpServerMap = (raw) => {
|
|
87
|
+
if (!isRecord(raw.mcp)) return {};
|
|
88
|
+
const servers = raw.mcp.servers;
|
|
89
|
+
if (!isRecord(servers)) return {};
|
|
90
|
+
return { ...servers };
|
|
91
|
+
};
|
|
92
|
+
var setRawMcpServerMap = (raw, servers) => {
|
|
93
|
+
const next = { ...raw, version: import_config.CONFIG_VERSION };
|
|
94
|
+
if (!Object.keys(servers).length) {
|
|
95
|
+
if (isRecord(next.mcp)) {
|
|
96
|
+
const mcp = { ...next.mcp };
|
|
97
|
+
delete mcp.servers;
|
|
98
|
+
if (Object.keys(mcp).length === 0) {
|
|
99
|
+
delete next.mcp;
|
|
100
|
+
} else {
|
|
101
|
+
next.mcp = mcp;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return next;
|
|
105
|
+
}
|
|
106
|
+
const currentMcp = isRecord(next.mcp) ? next.mcp : {};
|
|
107
|
+
next.mcp = {
|
|
108
|
+
...currentMcp,
|
|
109
|
+
servers
|
|
110
|
+
};
|
|
111
|
+
return next;
|
|
112
|
+
};
|
|
113
|
+
var isSameRule = (entry, rule) => {
|
|
114
|
+
if (!isRecord(entry)) return false;
|
|
115
|
+
const tool = pickString(entry.tool);
|
|
116
|
+
if (tool !== rule.tool) return false;
|
|
117
|
+
const command = pickString(entry.command);
|
|
118
|
+
const commandGlob = pickString(entry.command_glob);
|
|
119
|
+
const skillName = pickString(entry.skill_name);
|
|
120
|
+
return command === rule.command && commandGlob === rule.command_glob && skillName === rule.skill_name;
|
|
121
|
+
};
|
|
122
|
+
var loadConfig = async (configPath) => {
|
|
123
|
+
const explorer = (0, import_cosmiconfig.cosmiconfig)(MODULE_NAME);
|
|
124
|
+
let result = null;
|
|
125
|
+
try {
|
|
126
|
+
result = await explorer.load(configPath);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (isMissingFileError(error)) return null;
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
if (!result?.config) return null;
|
|
132
|
+
return (0, import_config.parseConfig)(result.config, result.filepath);
|
|
133
|
+
};
|
|
134
|
+
var updateModelConfig = async (configPath, model) => {
|
|
135
|
+
const raw = await readConfigRaw(configPath) ?? {};
|
|
136
|
+
const version = ensureVersion(raw, configPath);
|
|
137
|
+
const currentModel = isRecord(raw.model) ? raw.model : {};
|
|
138
|
+
const nextModel = {
|
|
139
|
+
...currentModel,
|
|
140
|
+
...pickDefined(model)
|
|
141
|
+
};
|
|
142
|
+
const nextRaw = {
|
|
143
|
+
...raw,
|
|
144
|
+
version,
|
|
145
|
+
model: nextModel
|
|
146
|
+
};
|
|
147
|
+
await writeConfigRaw(configPath, nextRaw);
|
|
148
|
+
return (0, import_config.parseConfig)(nextRaw, configPath);
|
|
149
|
+
};
|
|
150
|
+
var loadMcpServers = async (configPath) => {
|
|
151
|
+
const config = await loadConfig(configPath);
|
|
152
|
+
return config?.mcp?.servers ?? {};
|
|
153
|
+
};
|
|
154
|
+
var upsertMcpServerConfig = async (configPath, serverId, server) => {
|
|
155
|
+
const raw = await readConfigRaw(configPath) ?? {};
|
|
156
|
+
const version = ensureVersion(raw, configPath);
|
|
157
|
+
const servers = getRawMcpServerMap(raw);
|
|
158
|
+
servers[serverId] = server;
|
|
159
|
+
const nextRaw = setRawMcpServerMap({ ...raw, version }, servers);
|
|
160
|
+
await writeConfigRaw(configPath, nextRaw);
|
|
161
|
+
return (0, import_config.parseConfig)(nextRaw, configPath);
|
|
162
|
+
};
|
|
163
|
+
var removeMcpServerConfig = async (configPath, serverId) => {
|
|
164
|
+
const raw = await readConfigRaw(configPath);
|
|
165
|
+
if (!raw) return false;
|
|
166
|
+
const version = ensureVersion(raw, configPath);
|
|
167
|
+
const servers = getRawMcpServerMap(raw);
|
|
168
|
+
if (servers[serverId] === void 0) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
delete servers[serverId];
|
|
172
|
+
const nextRaw = setRawMcpServerMap({ ...raw, version }, servers);
|
|
173
|
+
await writeConfigRaw(configPath, nextRaw);
|
|
174
|
+
return true;
|
|
175
|
+
};
|
|
176
|
+
var setMcpServerEnabled = async (configPath, serverId, enabled) => {
|
|
177
|
+
const raw = await readConfigRaw(configPath);
|
|
178
|
+
if (!raw) return false;
|
|
179
|
+
const version = ensureVersion(raw, configPath);
|
|
180
|
+
const servers = getRawMcpServerMap(raw);
|
|
181
|
+
if (servers[serverId] === void 0) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const current = isRecord(servers[serverId]) ? { ...servers[serverId] } : {};
|
|
185
|
+
current.enabled = enabled;
|
|
186
|
+
servers[serverId] = current;
|
|
187
|
+
const nextRaw = setRawMcpServerMap({ ...raw, version }, servers);
|
|
188
|
+
await writeConfigRaw(configPath, nextRaw);
|
|
189
|
+
return true;
|
|
190
|
+
};
|
|
191
|
+
var appendPermissionAllowRules = async (configPath, rules) => {
|
|
192
|
+
const raw = await readConfigRaw(configPath) ?? {};
|
|
193
|
+
const version = ensureVersion(raw, configPath);
|
|
194
|
+
const permissions = isRecord(raw.permissions) ? raw.permissions : {};
|
|
195
|
+
const allow = Array.isArray(permissions.allow) ? permissions.allow : [];
|
|
196
|
+
for (const rule of rules) {
|
|
197
|
+
if (!allow.some((entry) => isSameRule(entry, rule))) {
|
|
198
|
+
allow.push(rule);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const nextPermissions = {
|
|
202
|
+
...permissions,
|
|
203
|
+
allow
|
|
204
|
+
};
|
|
205
|
+
const nextRaw = {
|
|
206
|
+
...raw,
|
|
207
|
+
version,
|
|
208
|
+
permissions: nextPermissions
|
|
209
|
+
};
|
|
210
|
+
await writeConfigRaw(configPath, nextRaw);
|
|
211
|
+
return (0, import_config.parseConfig)(nextRaw, configPath);
|
|
212
|
+
};
|
|
213
|
+
var appendPermissionAllowRule = async (configPath, rule) => {
|
|
214
|
+
return appendPermissionAllowRules(configPath, [rule]);
|
|
215
|
+
};
|
|
216
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
217
|
+
0 && (module.exports = {
|
|
218
|
+
appendPermissionAllowRule,
|
|
219
|
+
appendPermissionAllowRules,
|
|
220
|
+
loadConfig,
|
|
221
|
+
loadMcpServers,
|
|
222
|
+
removeMcpServerConfig,
|
|
223
|
+
setMcpServerEnabled,
|
|
224
|
+
updateModelConfig,
|
|
225
|
+
upsertMcpServerConfig
|
|
226
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PermissionRule, CodeliaConfig, McpServerConfig, ModelConfig } from '@codelia/config';
|
|
2
|
+
|
|
3
|
+
declare const loadConfig: (configPath: string) => Promise<CodeliaConfig | null>;
|
|
4
|
+
declare const updateModelConfig: (configPath: string, model: ModelConfig) => Promise<CodeliaConfig>;
|
|
5
|
+
declare const loadMcpServers: (configPath: string) => Promise<Record<string, McpServerConfig>>;
|
|
6
|
+
declare const upsertMcpServerConfig: (configPath: string, serverId: string, server: McpServerConfig) => Promise<CodeliaConfig>;
|
|
7
|
+
declare const removeMcpServerConfig: (configPath: string, serverId: string) => Promise<boolean>;
|
|
8
|
+
declare const setMcpServerEnabled: (configPath: string, serverId: string, enabled: boolean) => Promise<boolean>;
|
|
9
|
+
declare const appendPermissionAllowRules: (configPath: string, rules: PermissionRule[]) => Promise<CodeliaConfig>;
|
|
10
|
+
declare const appendPermissionAllowRule: (configPath: string, rule: PermissionRule) => Promise<CodeliaConfig>;
|
|
11
|
+
|
|
12
|
+
export { appendPermissionAllowRule, appendPermissionAllowRules, loadConfig, loadMcpServers, removeMcpServerConfig, setMcpServerEnabled, updateModelConfig, upsertMcpServerConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PermissionRule, CodeliaConfig, McpServerConfig, ModelConfig } from '@codelia/config';
|
|
2
|
+
|
|
3
|
+
declare const loadConfig: (configPath: string) => Promise<CodeliaConfig | null>;
|
|
4
|
+
declare const updateModelConfig: (configPath: string, model: ModelConfig) => Promise<CodeliaConfig>;
|
|
5
|
+
declare const loadMcpServers: (configPath: string) => Promise<Record<string, McpServerConfig>>;
|
|
6
|
+
declare const upsertMcpServerConfig: (configPath: string, serverId: string, server: McpServerConfig) => Promise<CodeliaConfig>;
|
|
7
|
+
declare const removeMcpServerConfig: (configPath: string, serverId: string) => Promise<boolean>;
|
|
8
|
+
declare const setMcpServerEnabled: (configPath: string, serverId: string, enabled: boolean) => Promise<boolean>;
|
|
9
|
+
declare const appendPermissionAllowRules: (configPath: string, rules: PermissionRule[]) => Promise<CodeliaConfig>;
|
|
10
|
+
declare const appendPermissionAllowRule: (configPath: string, rule: PermissionRule) => Promise<CodeliaConfig>;
|
|
11
|
+
|
|
12
|
+
export { appendPermissionAllowRule, appendPermissionAllowRules, loadConfig, loadMcpServers, removeMcpServerConfig, setMcpServerEnabled, updateModelConfig, upsertMcpServerConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { CONFIG_VERSION, parseConfig } from "@codelia/config";
|
|
5
|
+
import { cosmiconfig } from "cosmiconfig";
|
|
6
|
+
var MODULE_NAME = "codelia";
|
|
7
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
var isMissingFileError = (error) => typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
9
|
+
var pickDefined = (value) => Object.fromEntries(
|
|
10
|
+
Object.entries(value).filter(([, entry]) => entry !== void 0)
|
|
11
|
+
);
|
|
12
|
+
var pickString = (value) => typeof value === "string" ? value : void 0;
|
|
13
|
+
var readConfigRaw = async (configPath) => {
|
|
14
|
+
let raw;
|
|
15
|
+
try {
|
|
16
|
+
raw = await readFile(configPath, "utf8");
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (isMissingFileError(error)) return null;
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
let parsed;
|
|
22
|
+
try {
|
|
23
|
+
parsed = JSON.parse(raw);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
26
|
+
throw new Error(`Failed to parse config.json: ${message}`);
|
|
27
|
+
}
|
|
28
|
+
if (!isRecord(parsed)) {
|
|
29
|
+
throw new Error("config.json must be a JSON object");
|
|
30
|
+
}
|
|
31
|
+
return parsed;
|
|
32
|
+
};
|
|
33
|
+
var ensureVersion = (raw, configPath) => {
|
|
34
|
+
const version = raw.version ?? CONFIG_VERSION;
|
|
35
|
+
if (version !== CONFIG_VERSION) {
|
|
36
|
+
throw new Error(`${configPath}: unsupported version ${String(version)}`);
|
|
37
|
+
}
|
|
38
|
+
return version;
|
|
39
|
+
};
|
|
40
|
+
var writeConfigRaw = async (configPath, raw) => {
|
|
41
|
+
await mkdir(path.dirname(configPath), { recursive: true });
|
|
42
|
+
await writeFile(configPath, `${JSON.stringify(raw, null, 2)}
|
|
43
|
+
`, "utf8");
|
|
44
|
+
};
|
|
45
|
+
var getRawMcpServerMap = (raw) => {
|
|
46
|
+
if (!isRecord(raw.mcp)) return {};
|
|
47
|
+
const servers = raw.mcp.servers;
|
|
48
|
+
if (!isRecord(servers)) return {};
|
|
49
|
+
return { ...servers };
|
|
50
|
+
};
|
|
51
|
+
var setRawMcpServerMap = (raw, servers) => {
|
|
52
|
+
const next = { ...raw, version: CONFIG_VERSION };
|
|
53
|
+
if (!Object.keys(servers).length) {
|
|
54
|
+
if (isRecord(next.mcp)) {
|
|
55
|
+
const mcp = { ...next.mcp };
|
|
56
|
+
delete mcp.servers;
|
|
57
|
+
if (Object.keys(mcp).length === 0) {
|
|
58
|
+
delete next.mcp;
|
|
59
|
+
} else {
|
|
60
|
+
next.mcp = mcp;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return next;
|
|
64
|
+
}
|
|
65
|
+
const currentMcp = isRecord(next.mcp) ? next.mcp : {};
|
|
66
|
+
next.mcp = {
|
|
67
|
+
...currentMcp,
|
|
68
|
+
servers
|
|
69
|
+
};
|
|
70
|
+
return next;
|
|
71
|
+
};
|
|
72
|
+
var isSameRule = (entry, rule) => {
|
|
73
|
+
if (!isRecord(entry)) return false;
|
|
74
|
+
const tool = pickString(entry.tool);
|
|
75
|
+
if (tool !== rule.tool) return false;
|
|
76
|
+
const command = pickString(entry.command);
|
|
77
|
+
const commandGlob = pickString(entry.command_glob);
|
|
78
|
+
const skillName = pickString(entry.skill_name);
|
|
79
|
+
return command === rule.command && commandGlob === rule.command_glob && skillName === rule.skill_name;
|
|
80
|
+
};
|
|
81
|
+
var loadConfig = async (configPath) => {
|
|
82
|
+
const explorer = cosmiconfig(MODULE_NAME);
|
|
83
|
+
let result = null;
|
|
84
|
+
try {
|
|
85
|
+
result = await explorer.load(configPath);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (isMissingFileError(error)) return null;
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
if (!result?.config) return null;
|
|
91
|
+
return parseConfig(result.config, result.filepath);
|
|
92
|
+
};
|
|
93
|
+
var updateModelConfig = async (configPath, model) => {
|
|
94
|
+
const raw = await readConfigRaw(configPath) ?? {};
|
|
95
|
+
const version = ensureVersion(raw, configPath);
|
|
96
|
+
const currentModel = isRecord(raw.model) ? raw.model : {};
|
|
97
|
+
const nextModel = {
|
|
98
|
+
...currentModel,
|
|
99
|
+
...pickDefined(model)
|
|
100
|
+
};
|
|
101
|
+
const nextRaw = {
|
|
102
|
+
...raw,
|
|
103
|
+
version,
|
|
104
|
+
model: nextModel
|
|
105
|
+
};
|
|
106
|
+
await writeConfigRaw(configPath, nextRaw);
|
|
107
|
+
return parseConfig(nextRaw, configPath);
|
|
108
|
+
};
|
|
109
|
+
var loadMcpServers = async (configPath) => {
|
|
110
|
+
const config = await loadConfig(configPath);
|
|
111
|
+
return config?.mcp?.servers ?? {};
|
|
112
|
+
};
|
|
113
|
+
var upsertMcpServerConfig = async (configPath, serverId, server) => {
|
|
114
|
+
const raw = await readConfigRaw(configPath) ?? {};
|
|
115
|
+
const version = ensureVersion(raw, configPath);
|
|
116
|
+
const servers = getRawMcpServerMap(raw);
|
|
117
|
+
servers[serverId] = server;
|
|
118
|
+
const nextRaw = setRawMcpServerMap({ ...raw, version }, servers);
|
|
119
|
+
await writeConfigRaw(configPath, nextRaw);
|
|
120
|
+
return parseConfig(nextRaw, configPath);
|
|
121
|
+
};
|
|
122
|
+
var removeMcpServerConfig = async (configPath, serverId) => {
|
|
123
|
+
const raw = await readConfigRaw(configPath);
|
|
124
|
+
if (!raw) return false;
|
|
125
|
+
const version = ensureVersion(raw, configPath);
|
|
126
|
+
const servers = getRawMcpServerMap(raw);
|
|
127
|
+
if (servers[serverId] === void 0) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
delete servers[serverId];
|
|
131
|
+
const nextRaw = setRawMcpServerMap({ ...raw, version }, servers);
|
|
132
|
+
await writeConfigRaw(configPath, nextRaw);
|
|
133
|
+
return true;
|
|
134
|
+
};
|
|
135
|
+
var setMcpServerEnabled = async (configPath, serverId, enabled) => {
|
|
136
|
+
const raw = await readConfigRaw(configPath);
|
|
137
|
+
if (!raw) return false;
|
|
138
|
+
const version = ensureVersion(raw, configPath);
|
|
139
|
+
const servers = getRawMcpServerMap(raw);
|
|
140
|
+
if (servers[serverId] === void 0) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
const current = isRecord(servers[serverId]) ? { ...servers[serverId] } : {};
|
|
144
|
+
current.enabled = enabled;
|
|
145
|
+
servers[serverId] = current;
|
|
146
|
+
const nextRaw = setRawMcpServerMap({ ...raw, version }, servers);
|
|
147
|
+
await writeConfigRaw(configPath, nextRaw);
|
|
148
|
+
return true;
|
|
149
|
+
};
|
|
150
|
+
var appendPermissionAllowRules = async (configPath, rules) => {
|
|
151
|
+
const raw = await readConfigRaw(configPath) ?? {};
|
|
152
|
+
const version = ensureVersion(raw, configPath);
|
|
153
|
+
const permissions = isRecord(raw.permissions) ? raw.permissions : {};
|
|
154
|
+
const allow = Array.isArray(permissions.allow) ? permissions.allow : [];
|
|
155
|
+
for (const rule of rules) {
|
|
156
|
+
if (!allow.some((entry) => isSameRule(entry, rule))) {
|
|
157
|
+
allow.push(rule);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const nextPermissions = {
|
|
161
|
+
...permissions,
|
|
162
|
+
allow
|
|
163
|
+
};
|
|
164
|
+
const nextRaw = {
|
|
165
|
+
...raw,
|
|
166
|
+
version,
|
|
167
|
+
permissions: nextPermissions
|
|
168
|
+
};
|
|
169
|
+
await writeConfigRaw(configPath, nextRaw);
|
|
170
|
+
return parseConfig(nextRaw, configPath);
|
|
171
|
+
};
|
|
172
|
+
var appendPermissionAllowRule = async (configPath, rule) => {
|
|
173
|
+
return appendPermissionAllowRules(configPath, [rule]);
|
|
174
|
+
};
|
|
175
|
+
export {
|
|
176
|
+
appendPermissionAllowRule,
|
|
177
|
+
appendPermissionAllowRules,
|
|
178
|
+
loadConfig,
|
|
179
|
+
loadMcpServers,
|
|
180
|
+
removeMcpServerConfig,
|
|
181
|
+
setMcpServerEnabled,
|
|
182
|
+
updateModelConfig,
|
|
183
|
+
upsertMcpServerConfig
|
|
184
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codelia/config-loader",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
20
|
+
"typecheck": "tsc --noEmit"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@codelia/config": "0.1.0",
|
|
24
|
+
"cosmiconfig": "^9.0.0"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
}
|
|
29
|
+
}
|