mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 17:27:54 +00:00
feat(core): Introduce DeclarativeTool and ToolInvocation. (#5613)
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { FunctionDeclaration, Schema, Type } from '@google/genai';
|
||||
import { Tool, ToolResult, BaseTool, Icon } from './tools.js';
|
||||
import { AnyDeclarativeTool, Icon, ToolResult, BaseTool } from './tools.js';
|
||||
import { Config } from '../config/config.js';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { StringDecoder } from 'node:string_decoder';
|
||||
@@ -125,7 +125,7 @@ Signal: Signal number or \`(none)\` if no signal was received.
|
||||
}
|
||||
|
||||
export class ToolRegistry {
|
||||
private tools: Map<string, Tool> = new Map();
|
||||
private tools: Map<string, AnyDeclarativeTool> = new Map();
|
||||
private config: Config;
|
||||
|
||||
constructor(config: Config) {
|
||||
@@ -136,7 +136,7 @@ export class ToolRegistry {
|
||||
* Registers a tool definition.
|
||||
* @param tool - The tool object containing schema and execution logic.
|
||||
*/
|
||||
registerTool(tool: Tool): void {
|
||||
registerTool(tool: AnyDeclarativeTool): void {
|
||||
if (this.tools.has(tool.name)) {
|
||||
if (tool instanceof DiscoveredMCPTool) {
|
||||
tool = tool.asFullyQualifiedTool();
|
||||
@@ -368,7 +368,7 @@ export class ToolRegistry {
|
||||
/**
|
||||
* Returns an array of all registered and discovered tool instances.
|
||||
*/
|
||||
getAllTools(): Tool[] {
|
||||
getAllTools(): AnyDeclarativeTool[] {
|
||||
return Array.from(this.tools.values()).sort((a, b) =>
|
||||
a.displayName.localeCompare(b.displayName),
|
||||
);
|
||||
@@ -377,8 +377,8 @@ export class ToolRegistry {
|
||||
/**
|
||||
* Returns an array of tools registered from a specific MCP server.
|
||||
*/
|
||||
getToolsByServer(serverName: string): Tool[] {
|
||||
const serverTools: Tool[] = [];
|
||||
getToolsByServer(serverName: string): AnyDeclarativeTool[] {
|
||||
const serverTools: AnyDeclarativeTool[] = [];
|
||||
for (const tool of this.tools.values()) {
|
||||
if ((tool as DiscoveredMCPTool)?.serverName === serverName) {
|
||||
serverTools.push(tool);
|
||||
@@ -390,7 +390,7 @@ export class ToolRegistry {
|
||||
/**
|
||||
* Get the definition of a specific tool.
|
||||
*/
|
||||
getTool(name: string): Tool | undefined {
|
||||
getTool(name: string): AnyDeclarativeTool | undefined {
|
||||
return this.tools.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user