Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
shakkernerd authored Feb 2, 2025
2 parents 42ac7a8 + 4827f84 commit a3f326e
Show file tree
Hide file tree
Showing 71 changed files with 908 additions and 203 deletions.
2 changes: 2 additions & 0 deletions packages/client-twitter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export async function buildConversationThread(
text: currentTweet.text,
source: "twitter",
url: currentTweet.permanentUrl,
imageUrls: currentTweet.photos.map((p) => p.url) || [],
inReplyTo: currentTweet.inReplyToStatusId
? stringToUuid(
currentTweet.inReplyToStatusId +
Expand Down Expand Up @@ -278,6 +279,7 @@ export async function sendTweet(
text: tweet.text,
source: "twitter",
url: tweet.permanentUrl,
imageUrls: tweet.photos.map((p) => p.url) || [],
inReplyTo: tweet.inReplyToStatusId
? stringToUuid(
tweet.inReplyToStatusId + "-" + client.runtime.agentId
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
"@ai-sdk/google-vertex": "0.0.43",
"@ai-sdk/groq": "0.0.3",
"@ai-sdk/mistral": "1.0.9",
"@ai-sdk/openai": "1.0.5",
"@ai-sdk/openai": "1.1.9",
"@ai-sdk/amazon-bedrock": "1.1.0",
"@fal-ai/client": "1.2.0",
"@tavily/core": "^0.0.2",
"@types/uuid": "10.0.0",
"ai": "3.4.33",
"ai": "4.1.16",
"anthropic-vertex-ai": "1.0.2",
"dotenv": "16.4.5",
"fastembed": "1.14.1",
Expand All @@ -84,7 +84,7 @@
"js-tiktoken": "1.0.15",
"langchain": "0.3.6",
"ollama-ai-provider": "0.16.1",
"openai": "4.73.0",
"openai": "4.82.0",
"pino": "^9.6.0",
"pino-pretty": "^13.0.0",
"tinyld": "1.3.4",
Expand Down
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
41 changes: 41 additions & 0 deletions packages/plugin-0x/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/**/*"
]
}
}
12 changes: 10 additions & 2 deletions packages/plugin-0x/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"test": "vitest run"
"test": "vitest run",
"lint": "biome check src/",
"lint:fix": "biome check --apply src/",
"format": "biome format src/",
"format:fix": "biome format --write src/"
},
"dependencies": {
"@elizaos/core": "workspace:*",
"whatwg-url": "7.1.0",
"@0x/swap-ts-sdk": "2.1.1"
},
"devDependencies": {
"tsup": "^8.0.1"
"tsup": "^8.0.1",
"@biomejs/biome": "1.5.3",
"vitest": "^2.1.5"
},
"peerDependencies": {
"@elizaos/core": "workspace:*",
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-0x/src/EVMtokenRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { elizaLogger } from "@elizaos/core";
import {
Chains,
TokenMetadata,
TrustWalletGithubJson,
TrustWalletTokenMetadata,
type TokenMetadata,
type TrustWalletGithubJson,
type TrustWalletTokenMetadata,
} from "./types";
import { NATIVE_TOKENS } from "./constants";

Expand Down
30 changes: 15 additions & 15 deletions packages/plugin-0x/src/actions/getIndicativePrice.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
Action,
IAgentRuntime,
Memory,
State,
HandlerCallback,
type Action,
type IAgentRuntime,
type Memory,
type State,
type HandlerCallback,
elizaLogger,
composeContext,
ModelClass,
Expand All @@ -13,7 +13,7 @@ import {
import { createClientV2 } from "@0x/swap-ts-sdk";
import { getIndicativePriceTemplate } from "../templates";
import { z } from "zod";
import { Chains, GetIndicativePriceResponse, PriceInquiry } from "../types";
import { Chains, type GetIndicativePriceResponse, type PriceInquiry } from "../types";
import { parseUnits } from "viem";
import { CHAIN_NAMES, ZX_MEMORY } from "../constants";
import { EVMTokenRegistry } from "../EVMtokenRegistry";
Expand Down Expand Up @@ -45,17 +45,17 @@ export const getIndicativePrice: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State,
options: Record<string, unknown>,
_options: Record<string, unknown>,
callback: HandlerCallback
) => {
const supportedChains = Object.keys(Chains).join(" | ");

state = !state
const localState = !state
? await runtime.composeState(message, { supportedChains })
: await runtime.updateRecentMessageState(state);

const context = composeContext({
state,
state: localState,
template: getIndicativePriceTemplate,
});

Expand Down Expand Up @@ -86,7 +86,7 @@ export const getIndicativePrice: Action = {
text: `Unsupported chain: ${chain}. Supported chains are: ${Object.keys(
Chains
)
.filter((k) => isNaN(Number(k)))
.filter((k) => !Number.isNaN(Number(k)))
.join(", ")}`,
});
return;
Expand Down Expand Up @@ -148,10 +148,10 @@ export const getIndicativePrice: Action = {
// Format amounts to human-readable numbers
const buyAmount =
Number(price.buyAmount) /
Math.pow(10, buyTokenMetadata.decimals);
(10 ** buyTokenMetadata.decimals);
const sellAmount =
Number(price.sellAmount) /
Math.pow(10, sellTokenMetadata.decimals);
(10 ** sellTokenMetadata.decimals);

await storePriceInquiryToMemory(runtime, message, {
sellTokenObject: sellTokenMetadata,
Expand All @@ -163,13 +163,13 @@ export const getIndicativePrice: Action = {

// Updated formatted response to include chain
const formattedResponse = [
`πŸ’± Swap Details:`,
`────────────────`,
"πŸ’± Swap Details:",
"────────────────",
`πŸ“€ Sell: ${sellAmount.toFixed(4)} ${sellTokenMetadata.symbol}`,
`πŸ“₯ Buy: ${buyAmount.toFixed(4)} ${buyTokenMetadata.symbol}`,
`πŸ“Š Rate: 1 ${sellTokenMetadata.symbol} = ${(buyAmount / sellAmount).toFixed(4)} ${buyTokenMetadata.symbol}`,
`πŸ”— Chain: ${CHAIN_NAMES[chainId]}`,
`────────────────`,
"────────────────",
`πŸ’« Happy with the price? Type 'quote' to continue`,
].join("\n");

Expand Down
Loading

0 comments on commit a3f326e

Please sign in to comment.