Skip to content
Open
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
6 changes: 3 additions & 3 deletions core/langchain-decorator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"@eggjs/tegg-metadata": "^3.70.0",
"@eggjs/tegg-types": "^3.70.0",
"@langchain/community": "^1.0.5",
"@langchain/core": "^1.1.1",
"@langchain/langgraph": "^1.0.2",
"@langchain/core": "1.1.11",
"@langchain/langgraph": "1.0.7",
"@langchain/openai": "^1.1.0",
"langchain": "^1.1.2",
"langchain": "1.1.6",
Comment on lines +44 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While you've pinned the versions for @langchain/core, @langchain/langgraph, and langchain, other langchain-related dependencies like @langchain/community (line 43) and @langchain/openai (line 46) are still using version ranges. For consistency and to fully achieve the goal of locking langchain versions, consider pinning these as well.

"lodash": "^4.17.21",
"pluralize": "^8.0.0"
},
Expand Down
10 changes: 10 additions & 0 deletions core/langchain-decorator/src/type/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createMiddleware } from 'langchain';

type createMiddlewareParams = Parameters<typeof createMiddleware>['0'];

export abstract class TeggAgentMiddleware implements createMiddlewareParams {
name;
constructor() {
this.name = this.constructor.name;
}
}
Comment on lines +1 to +10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

langchain createMiddleware API TypeScript type definition

💡 Result:

Signature (TypeScript, simplified):

import { AgentMiddleware } from "langchain";

declare function createMiddleware<
TSchema = undefined,
TContextSchema = undefined

(config: {
name: string;
stateSchema?: TSchema;
contextSchema?: TContextSchema;
beforeAgent?: BeforeAgentHook<TSchema, NormalizeContextSchema>;
afterAgent?: AfterAgentHook<TSchema, NormalizeContextSchema>;
beforeModel?: BeforeModelHook<TSchema, NormalizeContextSchema>;
afterModel?: AfterModelHook<TSchema, NormalizeContextSchema>;
wrapModelCall?: WrapModelCallHook<TSchema, NormalizeContextSchema>;
wrapToolCall?: WrapToolCallHook<TSchema, NormalizeContextSchema>;
tools?: any[];
}): AgentMiddleware<TSchema, TContextSchema, any>;

References: LangChain createMiddleware docs and AgentMiddleware/type refs. [1][2][3]

Sources
[1] createMiddleware docs. [2] AgentMiddleware interface/type. [3] middleware types (InferMiddlewareContext/State).


🏁 Script executed:

# Search the codebase for any imports or usage of createMiddleware
rg "createMiddleware" --type ts --type tsx -B 2 -A 2

# Look for langchain imports in the codebase
rg "from 'langchain'" --type ts --type tsx | head -20

# Check if there's a package.json to see langchain version
cat package.json | grep -A 5 -B 5 langchain

Repository: eggjs/tegg

Length of output: 164


TypeScript implementation error: class cannot safely implement createMiddlewareParams and name is implicitly any.

The config object expected by createMiddleware requires a name: string property along with optional hooks (beforeAgent, afterAgent, beforeModel, afterModel, wrapModelCall, wrapToolCall, tools). Implementing this type on the class doesn't make semantic sense—it suggests instances are themselves valid middleware config objects, which they are not. The untyped name property will also fail under noImplicitAny.

Remove the implements clause, explicitly type name: string, and have subclasses provide the actual config object via a method if middleware parameters need to be constructed:

Suggested approach
 import { createMiddleware } from 'langchain';

-type createMiddlewareParams = Parameters<typeof createMiddleware>['0'];
+export type CreateMiddlewareParams = Parameters<typeof createMiddleware>[0];

-export abstract class TeggAgentMiddleware implements createMiddlewareParams {
-  name;
+export abstract class TeggAgentMiddleware {
+  public readonly name: string;
   constructor() {
     this.name = this.constructor.name;
   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { createMiddleware } from 'langchain';
type createMiddlewareParams = Parameters<typeof createMiddleware>['0'];
export abstract class TeggAgentMiddleware implements createMiddlewareParams {
name;
constructor() {
this.name = this.constructor.name;
}
}
import { createMiddleware } from 'langchain';
export type CreateMiddlewareParams = Parameters<typeof createMiddleware>[0];
export abstract class TeggAgentMiddleware {
public readonly name: string;
constructor() {
this.name = this.constructor.name;
}
}
🤖 Prompt for AI Agents
In @core/langchain-decorator/src/type/middleware.ts around lines 1 - 10, The
class TeggAgentMiddleware should not implement createMiddlewareParams; remove
the "implements createMiddlewareParams" clause, explicitly type the name
property as "name: string" on the class, and add an abstract method (e.g.,
getMiddlewareConfig(): createMiddlewareParams) that subclasses must implement to
return the actual middleware config object to be passed into createMiddleware;
keep the constructor that assigns this.name = this.constructor.name and update
any callers to use instance.getMiddlewareConfig() when constructing middleware
via createMiddleware.

Loading
Loading