tensaikit-test
Version:
An autonomous DeFi AI Agent Kit on Katana enabling AI agents to plan and execute on-chain financial operations.
70 lines (69 loc) • 2.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TensaiKit = void 0;
const actionProviders_1 = require("./actionProviders");
/**
* TensaiKit – Core SDK class for building autonomous DeFi AI agents on Katana.
*
* Provides integration with wallet and action providers to discover and perform
* supported financial operations on-chain.
*/
class TensaiKit {
/**
* Internal constructor for TensaiKit. Use `TensaiKit.from()` to initialize.
*
* @param config - Configuration options for the TensaiKit
* @param config.walletProvider - The wallet provider to use
* @param config.actionProviders - The action providers to use
* @param config.actions - The actions to use
*/
constructor(config) {
this.walletProvider = config.walletProvider;
this.actionProviders = config.actionProviders || [(0, actionProviders_1.walletActionProvider)()];
}
/**
* Factory method to asynchronously initialize a TensaiKit instance.
*
* @param config - Optional configuration object including wallet and action providers.
* @param config.walletProvider - The wallet provider to use
* @param config.actionProviders - The action providers to use
* @param config.actions - The actions to use
*
* @returns A promise that resolves to an initialized TensaiKit instance.
*
* @throws If `walletProvider` is not provided in the config.
*/
static async from(config = { actionProviders: [(0, actionProviders_1.walletActionProvider)()] }) {
let walletProvider = config.walletProvider;
if (!walletProvider) {
throw new Error("WalletProvider is required to initialize TensaiKit.");
}
return new TensaiKit({ ...config, walletProvider: walletProvider });
}
/**
* Retrieves all supported actions from available action providers.
*
* This filters out any action providers that do not support the current network
* and logs a warning for each unsupported provider.
*
* @returns An array of supported actions available for execution.
*/
getActions() {
const actions = [];
const unsupportedProviders = [];
for (const actionProvider of this.actionProviders) {
if (actionProvider.supportsNetwork(this.walletProvider.getNetwork())) {
actions.push(...actionProvider.getActions(this.walletProvider));
}
else {
unsupportedProviders.push(actionProvider.name);
}
}
if (unsupportedProviders.length > 0) {
console.warn(`Warning: The following action providers are not supported on the current network and will be skipped: ${unsupportedProviders.join(", ")}`);
console.info("Current network:", this.walletProvider.getNetwork());
}
return actions;
}
}
exports.TensaiKit = TensaiKit;