-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ELIZAAI-9 Added code review fixes. Eslint config refactor
- Loading branch information
1 parent
b3f5435
commit 207f87c
Showing
6 changed files
with
322 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
270
packages/plugin-cosmos/src/actions/walletProviderTestAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.