• Adds a new storage engine to the storage registry for use within the swarm system.

    This function registers a new storage engine, enabling the swarm to manage and utilize it for persistent data storage across agents or sessions. Only storages registered through this function are recognized by the swarm. If the storage is marked as shared, it initializes a connection to the shared storage service and waits for its initialization. The execution is wrapped in beginContext to ensure it runs outside of existing method and execution contexts, providing a clean execution environment. The function logs the operation if enabled and returns the storage's name upon successful registration.

    Type Parameters

    • T extends IStorageData = IStorageData

      The type of data stored in the storage, extending IStorageData (defaults to IStorageData if unspecified).

    Parameters

    • storageSchema: IStorageSchema<T>

      Partial storage schema with updates to be applied to the existing storage configuration.

    Returns string

    If the storage schema is invalid, registration fails (e.g., duplicate storage name), or shared storage initialization encounters an error.

    const storageSchema = { storageName: "UserData", shared: true, type: "key-value" };
    const storageName = addStorage(storageSchema);
    console.log(storageName); // Outputs "UserData"