-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor mention plugin system
- Loading branch information
1 parent
60024ea
commit 36615e8
Showing
93 changed files
with
2,953 additions
and
1,614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,5 +134,6 @@ | |
"xsss", | ||
"Zhipu", | ||
"zustand" | ||
] | ||
], | ||
"testing.automaticallyOpenTestResults": "neverOpen" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { CommandManager } from '@extension/commands/command-manager' | ||
import { | ||
controllers, | ||
type Controllers | ||
} from '@extension/webview-api/controllers' | ||
import type { Controller } from '@extension/webview-api/types' | ||
import * as vscode from 'vscode' | ||
|
||
import { BaseRegister } from './base-register' | ||
import type { RegisterManager } from './register-manager' | ||
|
||
export class ControllerRegister extends BaseRegister { | ||
public controllers: Map<string, Controller> = new Map() | ||
|
||
constructor( | ||
protected context: vscode.ExtensionContext, | ||
protected registerManager: RegisterManager, | ||
protected commandManager: CommandManager | ||
) { | ||
super(context, registerManager, commandManager) | ||
} | ||
|
||
async register(): Promise<void> { | ||
for (const ControllerClass of controllers) { | ||
const controller = new ControllerClass( | ||
this.registerManager, | ||
this.commandManager | ||
) | ||
this.controllers.set(controller.name, controller) | ||
} | ||
} | ||
|
||
api<T extends InstanceType<Controllers[number]>['name']>( | ||
apiName: T | ||
): Extract<InstanceType<Controllers[number]>, { name: T }> { | ||
// Type assertion needed since Map.get doesn't preserve the exact type | ||
return this.controllers.get(apiName) as Extract< | ||
InstanceType<Controllers[number]>, | ||
{ name: T } | ||
> | ||
} | ||
|
||
dispose(): void { | ||
this.controllers.clear() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/extension/webview-api/chat-context-processor/strategies/base/base-agent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { BaseGraphState } from '@extension/webview-api/chat-context-processor/strategies/base/base-state' | ||
import type { BaseStrategyOptions } from '@extension/webview-api/chat-context-processor/strategies/base/base-strategy' | ||
import { DynamicStructuredTool } from '@langchain/core/tools' | ||
import type { Agent } from '@shared/entities' | ||
import { z } from 'zod' | ||
|
||
export interface AgentContext< | ||
State extends BaseGraphState = BaseGraphState, | ||
CreateToolOptions extends Record<string, any> = Record<string, any>, | ||
StrategyOptions extends BaseStrategyOptions = BaseStrategyOptions | ||
> { | ||
state: State | ||
createToolOptions: CreateToolOptions | ||
strategyOptions: StrategyOptions | ||
} | ||
|
||
export abstract class BaseAgent< | ||
State extends BaseGraphState = BaseGraphState, | ||
CreateToolOptions extends Record<string, any> = Record<string, any>, | ||
StrategyOptions extends BaseStrategyOptions = BaseStrategyOptions, | ||
TInput extends z.ZodType = z.ZodType, | ||
TOutput extends z.ZodType = z.ZodType | ||
> { | ||
abstract inputSchema: TInput | ||
|
||
abstract outputSchema: TOutput | ||
|
||
abstract name: string | ||
|
||
abstract logTitle: string | ||
|
||
abstract description: string | ||
|
||
constructor( | ||
public context: AgentContext<State, CreateToolOptions, StrategyOptions> | ||
) {} | ||
|
||
// Abstract method that needs to be implemented by concrete agents | ||
abstract execute(input: z.infer<TInput>): Promise<z.infer<TOutput>> | ||
|
||
// Create the Langchain tool | ||
public async createTool(): Promise<DynamicStructuredTool | null> { | ||
return new DynamicStructuredTool({ | ||
name: this.name, | ||
description: this.description, | ||
schema: this.inputSchema as any, | ||
func: async (input: z.infer<TInput>) => { | ||
const result = await this.execute(input) | ||
return this.outputSchema.parse(result) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
export type GetAgentInput<T extends BaseAgent> = z.infer<T['inputSchema']> | ||
|
||
export type GetAgentOutput<T extends BaseAgent> = z.infer<T['outputSchema']> | ||
|
||
export type GetAgent<T extends BaseAgent> = Agent< | ||
GetAgentInput<T>, | ||
GetAgentOutput<T> | ||
> |
Oops, something went wrong.