Skip to content

Commit

Permalink
Merge pull request #3179 from AIFlowML/fix-plugin-0g
Browse files Browse the repository at this point in the history
fix: plugin-0g
  • Loading branch information
shakkernerd authored Feb 2, 2025
2 parents 41d6d0f + db3c8da commit e2636a4
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 18 deletions.
41 changes: 41 additions & 0 deletions packages/plugin-0g/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/**/*"
]
}
}
3 changes: 0 additions & 3 deletions packages/plugin-0g/eslint.config.mjs

This file was deleted.

6 changes: 5 additions & 1 deletion packages/plugin-0g/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
"tsup": "8.3.5"
},
"devDependencies": {
"@biomejs/biome": "1.5.3",
"vitest": "^1.2.1"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"test": "vitest run",
"lint": "eslint --fix --cache ."
"lint": "biome check src/",
"lint:fix": "biome check --apply src/",
"format": "biome format src/",
"format:fix": "biome format --write src/"
}
}
26 changes: 14 additions & 12 deletions packages/plugin-0g/src/actions/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
elizaLogger,
} from "@elizaos/core";
import { Indexer, ZgFile, getFlowContract } from "@0glabs/0g-ts-sdk";
import { ethers } from "ethers";
import { ethers, Wallet } from "ethers";
import { composeContext } from "@elizaos/core";
import { promises as fs } from "fs";
import { promises as fs, type Stats } from "node:fs";
import { FileSecurityValidator } from "../utils/security";
import { logSecurityEvent, monitorUpload, monitorFileValidation, monitorCleanup } from '../utils/monitoring';
import { uploadTemplate } from "../templates/upload";
Expand All @@ -24,10 +24,10 @@ export interface UploadContent extends Content {

function isUploadContent(
_runtime: IAgentRuntime,
content: any
content: unknown
): content is UploadContent {
elizaLogger.debug("Validating upload content", { content });
return typeof content.filePath === "string";
return typeof content === "object" && content !== null && "filePath" in content && typeof (content as UploadContent).filePath === "string";
}

export const zgUpload: Action = {
Expand Down Expand Up @@ -82,7 +82,7 @@ export const zgUpload: Action = {
};

// Validate config values
if (isNaN(config.maxFileSize) || config.maxFileSize <= 0) {
if (Number.isNaN(config.maxFileSize) || config.maxFileSize <= 0) {
elizaLogger.error("Invalid ZEROG_MAX_FILE_SIZE setting", {
value: runtime.getSetting("ZEROG_MAX_FILE_SIZE"),
messageId: message.id
Expand Down Expand Up @@ -117,7 +117,7 @@ export const zgUpload: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State,
_options: any,
_options: Record<string, unknown>,
callback: HandlerCallback
) => {
elizaLogger.info("ZG_UPLOAD action started", {
Expand All @@ -131,18 +131,20 @@ export const zgUpload: Action = {

try {
// Update state if needed
if (!state) {
// Initialize or update state
let currentState = state;
if (!currentState) {
elizaLogger.debug("No state provided, composing new state");
state = (await runtime.composeState(message)) as State;
currentState = (await runtime.composeState(message)) as State;
} else {
elizaLogger.debug("Updating existing state");
state = await runtime.updateRecentMessageState(state);
currentState = await runtime.updateRecentMessageState(currentState);
}

// Compose upload context
elizaLogger.debug("Composing upload context");
const uploadContext = composeContext({
state,
state: currentState,
template: uploadTemplate,
});

Expand Down Expand Up @@ -307,7 +309,7 @@ export const zgUpload: Action = {

// Start upload monitoring
const startTime = Date.now();
let fileStats;
let fileStats: Stats;
try {
fileStats = await fs.stat(sanitizedPath);
elizaLogger.debug("File stats retrieved", {
Expand Down Expand Up @@ -365,7 +367,7 @@ export const zgUpload: Action = {
const provider = new ethers.JsonRpcProvider(runtime.getSetting("ZEROG_EVM_RPC"));
const signer = new ethers.Wallet(runtime.getSetting("ZEROG_PRIVATE_KEY"), provider);
const indexer = new Indexer(runtime.getSetting("ZEROG_INDEXER_RPC"));
const flowContract = getFlowContract(runtime.getSetting("ZEROG_FLOW_ADDRESS"), signer);
const flowContract = getFlowContract(runtime.getSetting("ZEROG_FLOW_ADDRESS"), signer as any);

// Upload file to ZeroG
elizaLogger.info("Starting file upload to ZeroG", {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-0g/src/utils/security.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fs } from 'fs';
import path from 'path';
import { promises as fs } from 'node:fs';
import path from 'node:path';

export interface SecurityConfig {
maxFileSize: number;
Expand Down

0 comments on commit e2636a4

Please # to comment.