@artinet/sdk
Version:
A TypeScript SDK for building collaborative AI agents.
49 lines (48 loc) • 1.47 kB
JavaScript
/**
* Copyright 2025 The Artinet Project
* SPDX-License-Identifier: Apache-2.0
*/
import { logger } from "../../config/index.js";
//TODO: Add persistence layer plugin support and turn Manager into an LRU cache.
/**
* Manager should optionally take a persistent storage object as a constructor parameter,
* That way we don't need to re-implement the same caching logic for each derived manager.
*/
export class Manager {
_data;
throwOnSet;
constructor(_data = new Map(), throwOnSet = true) {
this._data = _data;
this.throwOnSet = throwOnSet;
}
get data() {
return this._data;
}
async set(id, data) {
logger.debug(`${this.constructor.name}[set]:`, { id });
if (!data && this.throwOnSet) {
throw new Error("Data is required");
}
else if (!data) {
return;
}
this.data.set(id, data);
}
async get(id) {
// logger.debug(`${this.constructor.name}[get]:`, { id });
return this.data.get(id);
}
async delete(id) {
logger.debug(`${this.constructor.name}[delete]:`, { id });
this.data.delete(id);
}
async has(id) {
// logger.debug(`${this.constructor.name}[has]:`, { id });
return this.data.has(id);
}
async list() {
// logger.debug(`${this.constructor.name}[list]:`);
return Array.from(this.data.values());
}
}
export const ResourceManager = Manager;