MCPcopy Create free account
hub / github.com/CreminiAI/skillpack / save

Method save

src/runtime/config.ts:301–354  ·  view source on GitHub ↗
(rootDir: string, updates: Partial<DataConfig>)

Source from the content-addressed store, hash-verified

299 this.configData = resolveRuntimeConfig(this.fileConfigData);
300 return this.configData;
301 }
302
303 public getConfig(): DataConfig {
304 return this.configData;
305 }
306
307 public save(rootDir: string, updates: Partial<DataConfig>): void {
308 const configDir = path.join(rootDir, "data");
309 if (!this.configPath) {
310 this.configPath = path.join(rootDir, "data", "config.json");
311 }
312 if (!fs.existsSync(configDir)) {
313 fs.mkdirSync(configDir, { recursive: true });
314 }
315
316 // Merge configuration
317 if (updates.apiKey !== undefined) this.fileConfigData.apiKey = updates.apiKey;
318 if (updates.provider !== undefined) this.fileConfigData.provider = updates.provider;
319 if (updates.baseUrl !== undefined) {
320 this.fileConfigData.baseUrl = updates.baseUrl?.trim() || undefined;
321 }
322 if (updates.modelId !== undefined) {
323 this.fileConfigData.modelId = updates.modelId?.trim() || undefined;
324 }
325 if (updates.apiProtocol !== undefined) {
326 this.fileConfigData.apiProtocol = updates.apiProtocol || undefined;
327 }
328 if (updates.reasoning !== undefined) {
329 this.fileConfigData.reasoning = updates.reasoning;
330 }
331
332 // Per-adapter key handling: null = delete, object = overwrite
333 if (updates.adapters !== undefined) {
334 const merged: DataConfig["adapters"] = { ...(this.fileConfigData.adapters || {}) };
335 for (const [adapterKey, adapterVal] of Object.entries(updates.adapters)) {
336 if (adapterVal === null || adapterVal === undefined) {
337 delete merged[adapterKey];
338 } else {
339 merged[adapterKey] = adapterVal;
340 }
341 }
342 this.fileConfigData.adapters = merged;
343 }
344
345 if (updates._auth !== undefined) {
346 this.fileConfigData._auth = updates._auth;
347 }
348
349 try {
350 this.fileConfigData = normalizeDataConfig(this.fileConfigData);
351 this.configData = resolveRuntimeConfig(this.fileConfigData);
352 fs.writeFileSync(
353 this.configPath,
354 JSON.stringify(this.fileConfigData, null, 2),
355 "utf-8",
356 );
357 } catch (err) {

Callers 3

handleRequestMethod · 0.80
startMethod · 0.80

Calls 2

normalizeDataConfigFunction · 0.85
resolveRuntimeConfigFunction · 0.85

Tested by

no test coverage detected