@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
51 lines • 2.5 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 "./config.js";
import { DEFAULT_KEY_PREFIX } from "./constants.js";
import { RAMIndexCacheStore } from "./ram.js";
import { RedisIndexCacheStore } from "./redis.js";
/**
* The index store a mount runs its driver under.
*
* A mount builds one when it is placed, from the workspace or mount
* `index` config when there is one and from the driver's own `indexTtl`
* otherwise. Mirrors Python `cache/index/factory.py`.
*
* @param config the configured store, or undefined for a RAM store at the driver's TTL
* @param ttl the driver's `indexTtl`, read when `config` is undefined
* @param clock the clock the store's listings expire on; undefined means the real one
* @param workspaceId scopes a redis store whose config names no prefix, so
* two workspaces on one server never read each other's listings; undefined
* keeps the shared default
* @param ids the workspace's id source, which a redis store draws its
* generation and lease tokens from; undefined means the system source
*/
export function buildIndex(config, ttl, clock, workspaceId, ids) {
const timed = clock === undefined ? {} : { clock };
if (config === undefined)
return new RAMIndexCacheStore({ ttl, ...timed });
if (config.type === IndexType.REDIS) {
const redis = config;
return new RedisIndexCacheStore({
ttl: redis.ttl ?? 600,
...timed,
...(ids !== undefined ? { ids } : {}),
...(redis.url !== undefined ? { url: redis.url } : {}),
keyPrefix: redis.keyPrefix ??
(workspaceId === undefined ? DEFAULT_KEY_PREFIX : `${DEFAULT_KEY_PREFIX}${workspaceId}:`),
});
}
return new RAMIndexCacheStore({ ttl: config.ttl ?? 600, ...timed });
}
//# sourceMappingURL=factory.js.map