Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix-plugin-di lint #3066

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/plugin-di/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-di/eslint.config.mjs

This file was deleted.

7 changes: 6 additions & 1 deletion packages/plugin-di/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"zod": "3.23.8"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/node": "^20.0.0",
"@types/uuid": "10.0.0",
"tsup": "8.3.5",
Expand All @@ -34,7 +35,11 @@
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache .",
"clean": "rm -rf dist",
"lint": "biome lint .",
"lint:fix": "biome check --apply .",
"format": "biome format .",
"format:fix": "biome format --write .",
"test": "vitest run"
}
}
24 changes: 12 additions & 12 deletions packages/plugin-di/src/actions/baseInjectableAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
import type { ActionOptions, InjectableAction } from "../types";
import { buildContentOutputTemplate } from "../templates";

// type ActionResult = unknown;

/**
* Base abstract class for injectable actions
*/
Expand Down Expand Up @@ -88,7 +90,7 @@ export abstract class BaseInjectableAction<T> implements InjectableAction<T> {
message: Memory,
state?: State,
callback?: HandlerCallback
): Promise<any | null>;
): Promise<unknown | null>;

// -------- Implemented methods for Eliza runtime --------

Expand Down Expand Up @@ -124,14 +126,15 @@ export abstract class BaseInjectableAction<T> implements InjectableAction<T> {
state?: State
): Promise<string> {
// Initialize or update state
if (!state) {
state = (await runtime.composeState(message)) as State;
let currentState = state;
if (!currentState) {
currentState = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
currentState = await runtime.updateRecentMessageState(currentState);
}

// Compose context
return composeContext({ state, template: this.template });
return composeContext({ state: currentState, template: this.template });
}

/**
Expand Down Expand Up @@ -164,7 +167,7 @@ export abstract class BaseInjectableAction<T> implements InjectableAction<T> {
runtime,
context: actionContext,
modelClass: ModelClass.SMALL,
schema: this.contentSchema as z.ZodSchema<any>,
schema: this.contentSchema,
});

elizaLogger.debug("Response: ", resourceDetails.object);
Expand All @@ -179,9 +182,8 @@ export abstract class BaseInjectableAction<T> implements InjectableAction<T> {
JSON.stringify(parsedObj.error?.flatten())
);
return null;
} else {
return parsedObj.data;
}
return parsedObj.data;
}

/**
Expand All @@ -200,7 +202,7 @@ export abstract class BaseInjectableAction<T> implements InjectableAction<T> {
state?: State,
_options?: Record<string, unknown>,
callback?: HandlerCallback
): Promise<any | null> {
): Promise<unknown | null> {
let content: T;
try {
content = await this.processMessages(runtime, message, state);
Expand All @@ -209,9 +211,7 @@ export abstract class BaseInjectableAction<T> implements InjectableAction<T> {

if (callback) {
await callback?.({
text:
"Unable to process transfer request. Invalid content: " +
err.message,
text: `Unable to process transfer request. Invalid content: ${err.message}`,
content: {
error: "Invalid content",
},
Expand Down
16 changes: 8 additions & 8 deletions packages/plugin-di/src/decorators/content.decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ContentPropertyDescription } from "../types";
const CONTENT_METADATA_KEY = "content:properties";

export type ContentClass<T> = {
new (...args: any[]): T;
new (...args: unknown[]): T;
prototype: T;
};

Expand All @@ -14,7 +14,7 @@ interface ContentPropertyConfig extends ContentPropertyDescription {
}

export function property(config: ContentPropertyConfig) {
return (target: any, propertyKey: string) => {
return (target: object, propertyKey: string) => {
const properties =
Reflect.getMetadata(CONTENT_METADATA_KEY, target) || {};
properties[propertyKey] = config;
Expand All @@ -25,12 +25,12 @@ export function property(config: ContentPropertyConfig) {
/**
* Create a Zod schema from a class decorated with @property
*
* @param constructor
* @param cls
* @returns
*/
export function createZodSchema<T>(targetClass: ContentClass<T>): z.ZodType<T> {
export function createZodSchema<T>(cls: ContentClass<T>): z.ZodType<T> {
const properties: Record<string, ContentPropertyConfig> =
Reflect.getMetadata(CONTENT_METADATA_KEY, targetClass.prototype) || {};
Reflect.getMetadata(CONTENT_METADATA_KEY, cls.prototype) || {};
const schemaProperties = Object.entries(properties).reduce(
(acc, [key, { schema }]) => {
acc[key] = schema;
Expand All @@ -44,14 +44,14 @@ export function createZodSchema<T>(targetClass: ContentClass<T>): z.ZodType<T> {
/**
* Load the description of each property from a class decorated with @property
*
* @param constructor
* @param cls
* @returns
*/
export function loadPropertyDescriptions<T>(
targetClass: ContentClass<T>
cls: ContentClass<T>
): Record<string, ContentPropertyDescription> {
const properties: Record<string, ContentPropertyConfig> =
Reflect.getMetadata(CONTENT_METADATA_KEY, targetClass.prototype) || {};
Reflect.getMetadata(CONTENT_METADATA_KEY, cls.prototype) || {};
return Object.entries(properties).reduce(
(acc, [key, { description, examples }]) => {
acc[key] = { description, examples };
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-di/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface InjectableAction<T> extends Action {
message: Memory,
state?: State,
callback?: HandlerCallback
): Promise<any | null>;
): Promise<unknown | null>;
}

/**
Expand Down
Loading