Skip to content

Commit

Permalink
Merge pull request #3171 from AIFlowML/fix-plugin-akash-v1
Browse files Browse the repository at this point in the history
fix: plugin-akash
  • Loading branch information
shakkernerd authored Feb 2, 2025
2 parents 4a2cf37 + 7167418 commit f7c38a0
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 34 deletions.
41 changes: 41 additions & 0 deletions packages/plugin-akash/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$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/**/*"
]
}
}
9 changes: 5 additions & 4 deletions packages/plugin-akash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"build": "tsup",
"dev": "tsup --watch",
"clean": "rm -rf dist",
"lint:fix": "eslint . --fix",
"lint": "biome lint .",
"lint:fix": "biome check --apply .",
"format": "biome format .",
"format:fix": "biome format --write .",
"test": "vitest",
"test:watch": "vitest watch",
"test:coverage": "vitest run --coverage",
Expand All @@ -32,15 +35,13 @@
"ora": "^8.0.1"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/dotenv": "^8.2.0",
"@types/jest": "^29.5.11",
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@vitest/coverage-v8": "^0.34.6",
"@vitest/ui": "^0.34.6",
"eslint": "^9.16.0",
"tsup": "^8.0.1",
"typescript": "^5.3.3",
"vite": "^5.0.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-akash/src/actions/closeDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export const closeDeploymentAction: Action = {
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
_state: State | undefined,
_options: { [key: string]: unknown } = {},
callback?: HandlerCallback
): Promise<boolean> => {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-akash/src/actions/createCertificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type { CertificatePem } from "@akashnetwork/akashjs/build/certificates/ce
import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate";
import { validateAkashConfig } from "../environment";
import { AkashError, AkashErrorCode, withRetry } from "../error/error";
import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { Registry } from "@cosmjs/proto-signing";
import type { SigningStargateClient as AkashSigningStargateClient } from "@akashnetwork/akashjs/node_modules/@cosmjs/stargate";
import { getCertificatePath } from "../utils/paths";
Expand Down Expand Up @@ -271,7 +271,7 @@ export const createCertificateAction: Action = {
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
_state: State | undefined,
options: { callback?: HandlerCallback } = {}
): Promise<boolean> => {
const actionId = Date.now().toString();
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-akash/src/actions/createDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing";
import { SigningStargateClient } from "@cosmjs/stargate";
import { validateAkashConfig } from "../environment";
import { AkashError, AkashErrorCode, withRetry } from "../error/error";
import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { getCertificatePath, getDefaultSDLPath } from "../utils/paths";
// import { fileURLToPath } from 'url';
import { inspectRuntime, isPluginLoaded } from "../runtime_inspect";
Expand Down
12 changes: 6 additions & 6 deletions packages/plugin-akash/src/actions/getDeploymentApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { IAgentRuntime, Memory, State, HandlerCallback, Content, ActionExam
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { validateAkashConfig } from "../environment";
import { AkashError, AkashErrorCode } from "../error/error";
import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { getDeploymentsPath } from "../utils/paths";

export interface DeploymentInfo {
Expand Down Expand Up @@ -48,7 +48,7 @@ async function fetchWithRetry(url: string, options: RequestInit, retries = 3, de
});

if (i < retries - 1) {
await sleep(delay * Math.pow(2, i)); // Exponential backoff
await sleep(delay * (2 ** i)); // Exponential backoff
continue;
}

Expand All @@ -63,7 +63,7 @@ async function fetchWithRetry(url: string, options: RequestInit, retries = 3, de
elizaLogger.warn(`API request error (attempt ${i + 1}/${retries})`, {
error: error instanceof Error ? error.message : String(error)
});
await sleep(delay * Math.pow(2, i));
await sleep(delay * (2 ** i));
}
}
throw new AkashError(
Expand Down Expand Up @@ -336,7 +336,7 @@ export const getDeploymentApiAction: Action = {
} as ActionExample
]],

validate: async (runtime: IAgentRuntime, message: Memory): Promise<boolean> => {
validate: async (_runtime: IAgentRuntime, message: Memory): Promise<boolean> => {
elizaLogger.debug("Validating get deployments request", { message });
try {
const params = message.content as Partial<GetDeploymentsContent>;
Expand Down Expand Up @@ -381,7 +381,7 @@ export const getDeploymentApiAction: Action = {
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
_state: State | undefined,
_options: { [key: string]: unknown } = {},
callback?: HandlerCallback
): Promise<boolean> => {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-akash/src/actions/getDeploymentStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const getDeploymentStatusAction: Action = {
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
_state: State | undefined,
_options: { [key: string]: unknown } = {},
callback?: HandlerCallback
): Promise<boolean> => {
Expand Down
12 changes: 6 additions & 6 deletions packages/plugin-akash/src/actions/getGPUPricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ export const getGPUPricingAction: Action = {
} as ActionExample
]],

validate: async (runtime: IAgentRuntime, message: Memory): Promise<boolean> => {
validate: async (_runtime: IAgentRuntime, message: Memory): Promise<boolean> => {
elizaLogger.debug("Validating GPU pricing request", { message });
try {
const params = message.content as Partial<GetGPUPricingContent>;

// Validate CPU if provided
if (params.cpu !== undefined && (isNaN(params.cpu) || params.cpu <= 0)) {
if (params.cpu !== undefined && (Number.isNaN(params.cpu) || params.cpu <= 0)) {
throw new GPUPricingError("CPU units must be a positive number", "INVALID_CPU");
}

// Validate memory if provided
if (params.memory !== undefined && (isNaN(params.memory) || params.memory <= 0)) {
if (params.memory !== undefined && (Number.isNaN(params.memory) || params.memory <= 0)) {
throw new GPUPricingError("Memory must be a positive number", "INVALID_MEMORY");
}

// Validate storage if provided
if (params.storage !== undefined && (isNaN(params.storage) || params.storage <= 0)) {
if (params.storage !== undefined && (Number.isNaN(params.storage) || params.storage <= 0)) {
throw new GPUPricingError("Storage must be a positive number", "INVALID_STORAGE");
}

Expand All @@ -91,9 +91,9 @@ export const getGPUPricingAction: Action = {
},

handler: async (
runtime: IAgentRuntime,
_runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
_state: State | undefined,
_options: { [key: string]: unknown; } = {},
callback?: HandlerCallback
): Promise<boolean> => {
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-akash/src/actions/getManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { IAgentRuntime, Memory, State, HandlerCallback, Content, ActionExam
import { SDL } from "@akashnetwork/akashjs/build/sdl";
import { validateAkashConfig } from "../environment";
import { AkashError, AkashErrorCode } from "../error/error";
import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'node:fs';
import * as path from 'node:path';
import yaml from 'js-yaml';
// import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate";
import { getDefaultSDLPath } from "../utils/paths";
Expand Down Expand Up @@ -70,7 +70,7 @@ const loadSDLFromFile = (filePath: string): string => {

// If we get here, none of the paths worked
throw new AkashError(
`SDL file not found in any of the possible locations`,
'SDL file not found in any of the possible locations',
AkashErrorCode.VALIDATION_SDL_FAILED,
{
filePath,
Expand Down Expand Up @@ -185,7 +185,7 @@ export const getManifestAction: Action = {
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
_state: State | undefined,
_options: { [key: string]: unknown; } = {},
callback?: HandlerCallback
): Promise<boolean> => {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-akash/src/actions/getProvidersList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export const getProvidersListAction: Action = {
} as ActionExample
]],

validate: async (runtime: IAgentRuntime, message: Memory): Promise<boolean> => {
validate: async (_runtime: IAgentRuntime, message: Memory): Promise<boolean> => {
elizaLogger.debug("Validating get providers list request", { message });
try {
const params = message.content as Partial<GetProvidersListContent>;
Expand Down Expand Up @@ -210,7 +210,7 @@ export const getProvidersListAction: Action = {
handler: async (
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
_state: State | undefined,
_options: { [key: string]: unknown; } = {},
callback?: HandlerCallback
): Promise<boolean> => {
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-akash/src/error/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export enum AkashErrorCategory {
WALLET = 'WALLET',
DEPLOYMENT = 'DEPLOYMENT',
Expand Down Expand Up @@ -117,7 +116,7 @@ export async function withRetry<T>(
} catch (error) {
lastError = error as Error;
if (i < maxRetries - 1) {
await new Promise(resolve => setTimeout(resolve, delay * Math.pow(2, i)));
await new Promise(resolve => setTimeout(resolve, delay * (2 ** i)));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-akash/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin} from "@elizaos/core";
import type { Plugin} from "@elizaos/core";
import chalk from 'chalk';
import Table from 'cli-table3';
import ora from 'ora';
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-akash/src/runtime_inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function isPluginLoaded(runtime: IAgentRuntime, pluginName: string): bool
// Check plugins array
const plugins = (runtime as any).plugins as Plugin[];
if (!plugins) {
elizaLogger.warn(`No plugins array found in runtime`);
elizaLogger.warn('No plugins array found in runtime');
return false;
}

Expand All @@ -70,7 +70,7 @@ export function isPluginLoaded(runtime: IAgentRuntime, pluginName: string): bool
// Check if actions are registered
const actions = (runtime as any).actions as Action[];
if (!actions || !actions.length) {
elizaLogger.warn(`No actions found in runtime`);
elizaLogger.warn('No actions found in runtime');
return false;
}

Expand Down

0 comments on commit f7c38a0

Please sign in to comment.