Skip to content

Commit

Permalink
Merge pull request #3780 from elizaOS/v2-lint-stuff
Browse files Browse the repository at this point in the history
chore: v2 lint and docs build stuff
  • Loading branch information
wtfsayo authored Mar 5, 2025
2 parents c57d1fe + 003b052 commit 92dbed5
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- name: Run tests
run: cd packages/core && bun test:coverage

- name: Run lint
run: bun run lint

- name: Build packages
run: bun run build

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@types/bun": "latest",
"@types/node": "^22.13.9",
"@vitest/eslint-plugin": "1.0.1",
"bun": "1.2.2",
"concurrently": "9.1.0",
Expand All @@ -38,8 +40,7 @@
"typedoc": "0.26.11",
"typescript": "5.8.2",
"vite": "5.4.12",
"vitest": "3.0.5",
"@types/bun": "latest"
"vitest": "3.0.5"
},
"bun": {
"overrides": {
Expand Down
1 change: 1 addition & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"class-variance-authority": "^0.7.1",
"clsx": "2.1.1",
"cmdk": "^1.0.4",
"date-fns": "^4.1.0",
"dayjs": "^1.11.13",
"lucide-react": "^0.469.0",
"react": "^19.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@rollup/plugin-terser": "0.1.0",
"@rollup/plugin-typescript": "11.1.6",
"@types/mocha": "10.0.10",
"@types/node": "22.8.4",
"@types/node": "^22.13.9",
"@types/uuid": "10.0.0",
"@typescript-eslint/eslint-plugin": "8.16.0",
"@typescript-eslint/parser": "8.16.0",
Expand All @@ -56,6 +56,7 @@
},
"dependencies": {
"dotenv": "16.4.5",
"events": "^3.3.0",
"glob": "11.0.0",
"handlebars": "^4.7.8",
"js-sha1": "0.7.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/services/taskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ export class TaskService extends Service {
// convert updatedAt which is an ISO string to a number
const updateIntervalMs = task.metadata.updateInterval ?? 0; // update immediately


// if tags does not contain "repeat", execute immediately
if (!task.tags?.includes("repeat")) {
await this.executeTask(task.id!);
await this.executeTask(task.id);
continue;
}

Expand All @@ -163,7 +164,7 @@ export class TaskService extends Service {
logger.debug(
`Executing task ${task.name} - interval of ${updateIntervalMs}ms has elapsed`
);
await this.executeTask(task.id!);
await this.executeTask(task.id);
}
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter from "node:events";
import { EventEmitter } from "node:events";

/**
* Represents a UUID string in the format "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Expand Down
3 changes: 2 additions & 1 deletion packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"checkJs": false,
"noEmitOnError": false,
"moduleDetection": "force",
"allowArbitraryExtensions": true
"allowArbitraryExtensions": true,
"types": ["node"]
},
"include": [
"src/**/*",
Expand Down
6 changes: 6 additions & 0 deletions packages/docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ const config = {
treatWarningsAsErrors: false,
treatValidationWarningsAsErrors: false,
searchInComments: true,
disableGit: false,
validation: {
invalidLink: true,
notDocumented: false
},
navigationLinks: {
GitHub: "https://github.com/elizaos/eliza",
Documentation: "/docs/intro",
Expand All @@ -109,6 +114,7 @@ const config = {
routeBasePath: "api",
},
],
require.resolve("./plugin/event-emitter-polyfill"),
],
presets: [
[
Expand Down
13 changes: 10 additions & 3 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@
"dotenv": "^16.4.7",
"prism-react-renderer": "2.3.1",
"react": "^19.0.0",
"react-dom": "^19.0.0"
"react-dom": "^19.0.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "3.7.0",
"@docusaurus/remark-plugin-npm2yarn": "^3.7.0",
"@docusaurus/types": "3.7.0",
"docusaurus-plugin-typedoc": "1.0.5",
"@types/node": "^22.13.9",
"assert": "^2.1.0",
"docusaurus-plugin-typedoc": "1.2.2",
"events": "^3.3.0",
"path-browserify": "^1.0.1",
"stream-browserify": "^3.0.0",
"typedoc": "0.26.11",
"typedoc-plugin-markdown": "4.2.10"
"typedoc-plugin-markdown": "4.2.10",
"util": "^0.12.5"
},
"browserslist": {
"production": [
Expand Down
23 changes: 23 additions & 0 deletions packages/docs/plugin/event-emitter-polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// plugins/event-emitter-polyfill.js

// Polyfill global EventEmitter for server-side if it's not defined.
if (typeof global.EventEmitter === 'undefined') {
global.EventEmitter = require('events').EventEmitter;
}

module.exports = () => ({
name: "event-emitter-polyfill",
configureWebpack(config, isServer) {
if (!isServer) {
return {
resolve: {
fallback: {
// For client-side, map Node's "events" module to the polyfilled version.
events: require.resolve("events/")
}
}
};
}
return {};
},
});
1 change: 0 additions & 1 deletion packages/plugin-discord/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
type TextChannel,
type User,
} from "discord.js";
import { EventEmitter } from "node:events";
import chatWithAttachments from "./actions/chatWithAttachments.ts";
import downloadMedia from "./actions/downloadMedia.ts";
import reply from "./actions/reply.ts";
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-discord/src/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
type VoiceChannel,
type VoiceState,
} from "discord.js";
import EventEmitter from "node:events";
import { EventEmitter } from "node:events";
import { type Readable, pipeline } from "node:stream";
import prism from "prism-media";
import type { DiscordService } from "./index.ts";
Expand Down
26 changes: 14 additions & 12 deletions packages/plugin-solana/src/actions/swap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
type Action,
type ActionExample,
type Client,
composeContext,
type HandlerCallback,
type IAgentRuntime,
Expand All @@ -16,8 +15,9 @@ import { Connection, PublicKey, VersionedTransaction } from '@solana/web3.js';
import BigNumber from 'bignumber.js';
import { SOLANA_SERVICE_NAME } from '../constants';
import { getWalletKey } from '../keypairUtils';
import type { Item } from '../types';
import type { SolanaService } from '../service';

import type { Item } from '../types';
async function getTokenDecimals(connection: Connection, mintAddress: string): Promise<number> {
const mintPublicKey = new PublicKey(mintAddress);
const tokenAccountInfo = await connection.getParsedAccountInfo(mintPublicKey);
Expand All @@ -42,7 +42,7 @@ async function swapToken(
inputTokenCA: string,
outputTokenCA: string,
amount: number,
): Promise<any> {
): Promise<unknown> {
try {
const decimals =
inputTokenCA === settings.SOL_ADDRESS
Expand Down Expand Up @@ -111,7 +111,7 @@ async function getTokenFromWallet(
tokenSymbol: string,
): Promise<string | null> {
try {
const solanaClient = runtime.getService(SOLANA_SERVICE_NAME) as Client;
const solanaClient = runtime.getService(SOLANA_SERVICE_NAME) as SolanaService;
if (!solanaClient) {
throw new Error('SolanaService not initialized');
}
Expand Down Expand Up @@ -182,23 +182,25 @@ export const executeSwap: Action = {
_options: { [key: string]: unknown },
callback?: HandlerCallback,
): Promise<boolean> => {
let currentState = state;

try {
if (!state) {
state = await runtime.composeState(message);
if (!currentState) {
currentState = await runtime.composeState(message);
} else {
state = await runtime.updateRecentMessageState(state);
currentState = await runtime.updateRecentMessageState(currentState);
}

const solanaClient = runtime.getService(SOLANA_SERVICE_NAME) as Client;
const solanaClient = runtime.getService(SOLANA_SERVICE_NAME) as SolanaService;
if (!solanaClient) {
throw new Error('SolanaService not initialized');
}

const walletData = await solanaClient.getCachedData();
state.walletInfo = walletData;
currentState.walletInfo = walletData;

const swapContext = composeContext({
state,
state: currentState,
template: swapTemplate,
});

Expand Down Expand Up @@ -249,13 +251,13 @@ export const executeSwap: Action = {
);
const { publicKey: walletPublicKey } = await getWalletKey(runtime, false);

const swapResult = await swapToken(
const swapResult = (await swapToken(
connection,
walletPublicKey,
response.inputTokenCA as string,
response.outputTokenCA as string,
response.amount as number,
);
)) as { swapTransaction: string };

const transactionBuf = Buffer.from(swapResult.swapTransaction, 'base64');
const transaction = VersionedTransaction.deserialize(transactionBuf);
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-solana/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface TransferContent extends Content {
amount: string | number;
}

function isTransferContent(content: any): content is TransferContent {
function isTransferContent(content: TransferContent): boolean {
logger.log('Content for transfer', content);

// Base validation
Expand Down Expand Up @@ -187,7 +187,9 @@ export default {
else {
const mintPubkey = new PublicKey(content.tokenAddress);
const mintInfo = await connection.getParsedAccountInfo(mintPubkey);
const decimals = (mintInfo.value?.data as any)?.parsed?.info?.decimals ?? 9;
const decimals =
(mintInfo.value?.data as { parsed: { info: { decimals: number } } })?.parsed
?.info?.decimals ?? 9;
const adjustedAmount = BigInt(Number(content.amount) * 10 ** decimals);

const senderATA = getAssociatedTokenAddressSync(
Expand Down
9 changes: 5 additions & 4 deletions packages/plugin-solana/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ const PROVIDER_CONFIG = {

export class SolanaService extends Service {
static serviceType: string = SOLANA_SERVICE_NAME;
capabilityDescription = "The agent is able to interact with the Solana blockchain, and has access to the wallet data";

capabilityDescription =
'The agent is able to interact with the Solana blockchain, and has access to the wallet data';

private updateInterval: NodeJS.Timer | null = null;
private lastUpdate = 0;
private readonly UPDATE_INTERVAL = 120000; // 2 minutes
Expand Down Expand Up @@ -75,7 +76,7 @@ export class SolanaService extends Service {
}
}

private async fetchWithRetry(url: string, options: RequestInit = {}): Promise<any> {
private async fetchWithRetry(url: string, options: RequestInit = {}): Promise<unknown> {
let lastError: Error;

for (let i = 0; i < PROVIDER_CONFIG.MAX_RETRIES; i++) {
Expand Down Expand Up @@ -189,7 +190,7 @@ export class SolanaService extends Service {
totalSol: totalUsd.div(solPriceInUSD).toFixed(6),
prices,
lastUpdated: now,
items: data.items.map((item: any) => ({
items: data.items.map((item: Item) => ({
...item,
valueSol: new BigNumber(item.valueUsd || 0)
.div(solPriceInUSD)
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-tee/src/adapters/sqliteDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../types.ts';
import { sqliteTables } from './sqliteTables.ts';

export class SqliteTeeLogDAO extends TeeLogDAO {
export class SqliteTeeLogDAO extends TeeLogDAO<Database> {
constructor(db: Database) {
super();
this.db = db;
Expand Down
12 changes: 7 additions & 5 deletions packages/plugin-tee/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ async function initializeTEE(config: Record<string, string>, runtime: IAgentRunt
export const teePlugin = (config?: TeePluginConfig): Plugin => {
const vendorType = config?.vendor || TeeVendorNames.PHALA;
const vendor = getVendor(vendorType);
config = {
...config,
vendor: vendorType,
};
return {
name: vendor.getName(),
init: async (config: Record<string, string>, runtime: IAgentRuntime) => {
return await initializeTEE(config, runtime);
return await initializeTEE(
{
...config,
vendor: vendorType,
},
runtime,
);
},
description: vendor.getDescription(),
actions: vendor.getActions(),
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-tee/src/services/teeLogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ export class TeeLogService extends Service implements ITeeLogService {
private teeType: TeeType;
private teeMode: TEEMode = TEEMode.OFF; // Only used for plugin-tee with TDX dstack

private teeLogDAO: TeeLogDAO;
private teeLogDAO: TeeLogDAO<Database.Database>;
private teeLogManager: TeeLogManager;

static serviceType: ServiceType = ServiceTypes.TEE;
capabilityDescription = "The agent is able to log TEE attestation events and is probably running in a TEE";
capabilityDescription =
'The agent is able to log TEE attestation events and is probably running in a TEE';

constructor(runtime: IAgentRuntime) {
super();
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-tee/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export interface TeeAgent {
attestation: string;
}

export interface TeePageQuery<Result = any> {
export interface TeePageQuery<Result> {
page: number;
pageSize: number;
total?: number;
data?: Result;
}

export abstract class TeeLogDAO<DB = any> {
export abstract class TeeLogDAO<DB> {
db: DB;

abstract initialize(): Promise<void>;
Expand Down

0 comments on commit 92dbed5

Please sign in to comment.