@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
45 lines • 1.95 kB
JavaScript
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import { IndexType } from "../../cache/index/config.js";
import { hasRedactedSecret, REDACTED_SECRET } from "../../vfs/secrets.js";
export function indexConfigDump(config, reveal = false) {
if (config === undefined)
return null;
const data = { type: config.type ?? IndexType.RAM, ttl: config.ttl ?? 600 };
if (data.type === IndexType.REDIS) {
const redis = config;
data.url = redis.url ?? 'redis://localhost:6379/0';
data.key_prefix = redis.keyPrefix ?? null;
const url = new URL(data.url);
if (!reveal && (url.username !== '' || url.password !== ''))
data.url = REDACTED_SECRET;
}
return data;
}
export function restoreIndexConfig(data, override, prefix) {
if (override !== undefined)
return override;
if (data == null)
return undefined;
if (hasRedactedSecret(data)) {
throw new Error(`Workspace.load: mount '${prefix}' needs a Mount override with fresh index credentials`);
}
const config = { type: data.type, ttl: data.ttl };
if (data.url !== undefined)
config.url = data.url;
if (data.key_prefix != null)
config.keyPrefix = data.key_prefix;
return config;
}
//# sourceMappingURL=config.js.map