From 4acefb5cd3ccd0479fafff45fdb9f9c2479e06cf Mon Sep 17 00:00:00 2001 From: AIFlow_ML Date: Fri, 31 Jan 2025 16:52:09 +0700 Subject: [PATCH] fix: add biome configuration and fix linting issues in plugin-autonome --- packages/plugin-autonome/biome.json | 42 +++++++++++++++++++ packages/plugin-autonome/package.json | 9 ++-- .../src/actions/launchAgent.ts | 35 +++++++++------- packages/plugin-autonome/src/index.ts | 1 + 4 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 packages/plugin-autonome/biome.json diff --git a/packages/plugin-autonome/biome.json b/packages/plugin-autonome/biome.json new file mode 100644 index 00000000000..ec7d14c614f --- /dev/null +++ b/packages/plugin-autonome/biome.json @@ -0,0 +1,42 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.5.3/schema.json", + "organizeImports": { + "enabled": false + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "correctness": { + "noUnusedVariables": "error" + }, + "suspicious": { + "noExplicitAny": "error" + }, + "style": { + "useConst": "error", + "useImportType": "off" + } + } + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentWidth": 4, + "lineWidth": 100 + }, + "javascript": { + "formatter": { + "quoteStyle": "single", + + "trailingCommas": "es5" + } + }, + "files": { + "ignore": [ + "dist/**/*", + "extra/**/*", + "node_modules/**/*" + ] + } +} \ No newline at end of file diff --git a/packages/plugin-autonome/package.json b/packages/plugin-autonome/package.json index ee318fd2a37..807768126f6 100644 --- a/packages/plugin-autonome/package.json +++ b/packages/plugin-autonome/package.json @@ -12,14 +12,17 @@ "axios": "^1.7.9" }, "devDependencies": { - "vitest": "^2.1.8" + "@biomejs/biome": "1.9.4" }, "scripts": { "build": "tsup --format esm --dts", "dev": "tsup --format esm --dts --watch", "test": "vitest run", - "test:watch": "vitest watch", - "test:coverage": "vitest run --coverage" + + "lint": "biome lint .", + "lint:fix": "biome check --apply .", + "format": "biome format .", + "format:fix": "biome format --write ." }, "peerDependencies": { "form-data": "4.0.1", diff --git a/packages/plugin-autonome/src/actions/launchAgent.ts b/packages/plugin-autonome/src/actions/launchAgent.ts index 08e34ce6baf..241d258bdac 100644 --- a/packages/plugin-autonome/src/actions/launchAgent.ts +++ b/packages/plugin-autonome/src/actions/launchAgent.ts @@ -18,9 +18,17 @@ export interface LaunchAgentContent extends Content { config: string; } -function isLaunchAgentContent(content: any): content is LaunchAgentContent { +// Rafactoring +function isLaunchAgentContent(content: unknown): content is LaunchAgentContent { elizaLogger.log("Content for launchAgent", content); - return typeof content.name === "string" && typeof content.config === "string"; + return ( + typeof content === "object" && + content !== null && + "name" in content && + "config" in content && + typeof (content as LaunchAgentContent).name === "string" && + typeof (content as LaunchAgentContent).config === "string" + ); } const launchTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined. @@ -54,16 +62,18 @@ export default { callback?: HandlerCallback ): Promise => { elizaLogger.log("Starting LAUNCH_AGENT handler..."); - // Initialize or update state - if (!state) { - state = (await runtime.composeState(message)) as State; + + // Initialize or update state also in lanuchContext + let currentState = state; + if (!currentState) { + currentState = (await runtime.composeState(message)) as State; } else { - state = await runtime.updateRecentMessageState(state); + currentState = await runtime.updateRecentMessageState(currentState); } // Compose launch context const launchContext = composeContext({ - state, + state: currentState, template: launchTemplate, }); @@ -113,14 +123,12 @@ export default { try { const resp = await sendPostRequest(); - if (resp && resp.data && resp.data.app && resp.data.app.id) { + if (resp?.data?.app?.id) { elizaLogger.log( "Launching successful, please find your agent on" ); elizaLogger.log( - "https://dev.autonome.fun/autonome/" + - resp.data.app.id + - "/details" + `https://dev.autonome.fun/autonome/${resp.data.app.id}/details` ); } if (callback) { @@ -128,10 +136,7 @@ export default { text: `Successfully launch agent ${content.name}`, content: { success: true, - appId: - "https://dev.autonome.fun/autonome/" + - resp.data.app.id + - "/details", + appId: `https://dev.autonome.fun/autonome/${resp.data.app.id}/details`, }, }); } diff --git a/packages/plugin-autonome/src/index.ts b/packages/plugin-autonome/src/index.ts index 0173ecb1270..e1a23ac24b8 100644 --- a/packages/plugin-autonome/src/index.ts +++ b/packages/plugin-autonome/src/index.ts @@ -1,6 +1,7 @@ import type { Plugin } from "@elizaos/core"; import launchAgent from "./actions/launchAgent"; +// Action setup export const autonomePlugin: Plugin = { name: "autonome", description: "Autonome Plugin for Eliza",