Skip to content

Commit

Permalink
ELIZAAI-9 Added code review fixes. Eslint config refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislawkurzypBD committed Dec 31, 2024
1 parent b3f5435 commit 207f87c
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 414 deletions.
2 changes: 1 addition & 1 deletion packages/adapter-sqlite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@ai16z/eliza": "workspace:*",
"@types/better-sqlite3": "7.6.12",
"better-sqlite3": "^11.7.0",
"better-sqlite3": "11.6.0",
"sqlite-vec": "0.1.6"
},
"devDependencies": {
Expand Down
38 changes: 1 addition & 37 deletions packages/plugin-cosmos/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
import eslintGlobalConfig from "../../eslint.config.mjs";

export default [
...eslintGlobalConfig,
{
rules: {
indent: ["error", 2],
'padding-line-between-statements': [
'error',
// Blank line between "use strict" (or other directives) and imports
{ blankLine: 'always', prev: 'directive', next: 'import' },

// No blank lines between import statements
{ blankLine: 'never', prev: 'import', next: 'import' },

// One blank line after the last import statement
{
blankLine: 'always',
prev: 'import',
next: ['const', 'let', 'var', 'function', 'expression', 'if', 'block', 'class', 'export', 'block-like']
},

{ blankLine: 'always', prev: '*', next: 'return' },
{ blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' },
{ blankLine: 'any', prev: ['const', 'let', 'var'], next: ['const', 'let', 'var'] },
{ blankLine: 'always', prev: '*', next: 'block-like' }
],
"no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
'prefer-const': ['error', { ignoreReadBeforeAssign: true }],
},
},
];
export default [...eslintGlobalConfig];
270 changes: 135 additions & 135 deletions packages/plugin-cosmos/src/actions/walletProviderTestAction.ts
Original file line number Diff line number Diff line change
@@ -1,161 +1,161 @@
import {
CosmosWalletProvider,
genCosmosChainsFromRuntime,
initWalletProvider,
CosmosWalletProvider,
genCosmosChainsFromRuntime,
initWalletProvider,
} from "../providers/wallet.ts";
import {
composeContext,
generateObjectDeprecated,
HandlerCallback,
IAgentRuntime,
Memory,
ModelClass,
State,
composeContext,
generateObjectDeprecated,
HandlerCallback,
IAgentRuntime,
Memory,
ModelClass,
State,
} from "@ai16z/eliza";
import { balanceTemplate } from "../templates";
import { z } from "zod";

export class BalanceAction {
constructor(private cosmosWalletProvider: CosmosWalletProvider) {
this.cosmosWalletProvider = cosmosWalletProvider;
}
constructor(private cosmosWalletProvider: CosmosWalletProvider) {
this.cosmosWalletProvider = cosmosWalletProvider;
}

async getBalance() {
try {
const activeChain = this.cosmosWalletProvider.getActiveChain();
const address = this.cosmosWalletProvider.getAddress();
const balance = await this.cosmosWalletProvider.getWalletBalance();
async getBalance() {
try {
const activeChain = this.cosmosWalletProvider.getActiveChain();
const address = this.cosmosWalletProvider.getAddress();
const balance = await this.cosmosWalletProvider.getWalletBalance();

return `Address: ${address}\nBalance: ${JSON.stringify(balance, null, 2)}, chain name: ${activeChain}`;
} catch (error) {
console.error("Error in Cosmos wallet provider:", error);
return `Address: ${address}\nBalance: ${JSON.stringify(balance, null, 2)}, chain name: ${activeChain}`;
} catch (error) {
console.error("Error in Cosmos wallet provider:", error);

return null;
return null;
}
}
}
}

export const balanceAction = {
name: "COSMOS_WALLET_BALANCE",
description: "Action for fetching wallet balance on given chain",
handler: async (
_runtime: IAgentRuntime,
_message: Memory,
state: State,
_options: { [key: string]: unknown },
_callback: HandlerCallback
) => {
console.log("COSMOS_WALLET_BALANCE action handler called");
name: "COSMOS_WALLET_BALANCE",
description: "Action for fetching wallet balance on given chain",
handler: async (
_runtime: IAgentRuntime,
_message: Memory,
state: State,
_options: { [key: string]: unknown },
_callback: HandlerCallback
) => {
console.log("COSMOS_WALLET_BALANCE action handler called");

// Compose transfer context
const transferContext = composeContext({
state: state,
template: balanceTemplate,
templatingEngine: "handlebars",
});
// Compose transfer context
const transferContext = composeContext({
state: state,
template: balanceTemplate,
templatingEngine: "handlebars",
});

// Generate transfer content
const content = await generateObjectDeprecated({
runtime: _runtime,
context: transferContext,
modelClass: ModelClass.SMALL,
});
// Generate transfer content
const content = await generateObjectDeprecated({
runtime: _runtime,
context: transferContext,
modelClass: ModelClass.SMALL,
});

const balanceContentValidator = z.object({
chainName: z.string(),
});
const balanceContentValidator = z.object({
chainName: z.string(),
});

const transferContent = balanceContentValidator.parse(content);
const transferContent = balanceContentValidator.parse(content);

const { chainName } = transferContent;
const { chainName } = transferContent;

try {
const walletProvider = await initWalletProvider(
_runtime,
chainName
);
const action = new BalanceAction(walletProvider);
const responseText = await action.getBalance();
try {
const walletProvider = await initWalletProvider(
_runtime,
chainName
);
const action = new BalanceAction(walletProvider);
const responseText = await action.getBalance();

await _callback({
text: responseText,
});
} catch (error) {
await _callback({
text: error.message,
});
console.error("Error in Cosmos wallet provider:", error);
}
await _callback({
text: responseText,
});
} catch (error) {
await _callback({
text: error.message,
});
console.error("Error in Cosmos wallet provider:", error);
}

return;
},
validate: async (runtime: IAgentRuntime) => {
const recoveryPhrase = runtime.getSetting("COSMOS_RECOVERY_PHRASE");
const chains = genCosmosChainsFromRuntime(runtime);
return;
},
validate: async (runtime: IAgentRuntime) => {
const recoveryPhrase = runtime.getSetting("COSMOS_RECOVERY_PHRASE");
const chains = genCosmosChainsFromRuntime(runtime);

return recoveryPhrase !== undefined && Object.keys(chains).length > 0;
},
examples: [
[
{
user: "{{user1}}",
content: {
text: "Show me balance of my cosmos wallet for chain mantrachaintestnet2",
},
},
{
user: "{{user2}}",
content: {
text: "",
action: "COSMOS_WALLET_BALANCE",
},
},
],
[
{
user: "{{user1}}",
content: {
text: "Show me balance of my cosmos wallet for chain mantrachaintestnet2 use COSMOS_WALLET_BALANCE action",
},
},
{
user: "{{user2}}",
content: {
text: "",
action: "COSMOS_WALLET_BALANCE",
},
},
],
[
{
user: "{{user1}}",
content: {
text: "Show me balance of my wallet for chain mantrachaintestnet2 on cosmos",
},
},
{
user: "{{user2}}",
content: {
text: "",
action: "COSMOS_WALLET_BALANCE",
},
},
],
[
{
user: "{{user1}}",
content: {
text: "What is my balance on the chain mantrachaintestnet2 on cosmos",
},
},
{
user: "{{user2}}",
content: {
text: "",
action: "COSMOS_WALLET_BALANCE",
},
},
return recoveryPhrase !== undefined && Object.keys(chains).length > 0;
},
examples: [
[
{
user: "{{user1}}",
content: {
text: "Show me balance of my cosmos wallet for chain mantrachaintestnet2",
},
},
{
user: "{{user2}}",
content: {
text: "",
action: "COSMOS_WALLET_BALANCE",
},
},
],
[
{
user: "{{user1}}",
content: {
text: "Show me balance of my cosmos wallet for chain mantrachaintestnet2 use COSMOS_WALLET_BALANCE action",
},
},
{
user: "{{user2}}",
content: {
text: "",
action: "COSMOS_WALLET_BALANCE",
},
},
],
[
{
user: "{{user1}}",
content: {
text: "Show me balance of my wallet for chain mantrachaintestnet2 on cosmos",
},
},
{
user: "{{user2}}",
content: {
text: "",
action: "COSMOS_WALLET_BALANCE",
},
},
],
[
{
user: "{{user1}}",
content: {
text: "What is my balance on the chain mantrachaintestnet2 on cosmos",
},
},
{
user: "{{user2}}",
content: {
text: "",
action: "COSMOS_WALLET_BALANCE",
},
},
],
],
],
similes: ["COSMOS_BALANCE", "COSMOS_WALLET_TOKENS"],
similes: ["COSMOS_BALANCE", "COSMOS_WALLET_TOKENS"],
};
12 changes: 6 additions & 6 deletions packages/plugin-cosmos/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import type { Plugin } from "@ai16z/eliza";
import { balanceAction } from "./actions/walletProviderTestAction.ts";

export const cosmosPlugin: Plugin = {
name: "cosmos",
description: "Cosmos blockchain integration plugin",
providers: [cosmosWalletProvider],
evaluators: [],
services: [],
actions: [balanceAction],
name: "cosmos",
description: "Cosmos blockchain integration plugin",
providers: [cosmosWalletProvider],
evaluators: [],
services: [],
actions: [balanceAction],
};

export default cosmosPlugin;
Loading

0 comments on commit 207f87c

Please sign in to comment.