Tool Calling: Make formatMessage async
| @@ -31,8 +31,8 @@ import { slashCommandReturnHelper } from './slash-commands/SlashCommandReturnHel | ||
| 31 | 31 | * @property {string} description - A description of the tool. |
| 32 | 32 | * @property {object} parameters - The parameters for the tool. |
| 33 | 33 | * @property {function} action - The action to perform when the tool is invoked. |
| 34 | 34 | * @property {function} [formatMessage] - A function to format the tool call message. |
| 35 | 35 | * @property {function} [shouldRegister] - A function to determine if the tool should be registered. |
| 36 | 36 | */ |
| 37 | 37 | |
| 38 | 38 | /** |
| @@ -194,11 +194,11 @@ class ToolDefinition { | ||
| 194 | 194 | /** |
| 195 | 195 | * Formats a message with the tool invocation. |
| 196 | 196 | * @param {object} parameters The parameters to pass to the tool. |
| 197 | 197 | * @returns {Promise<string>} The formatted message. |
| 198 | 198 | */ |
| 199 | 199 | async formatMessage(parameters) { |
| 200 | 200 | return typeof this.#formatMessage === 'function' |
| 201 | 201 | ? await this.#formatMessage(parameters) |
| 202 | 202 | : `Invoking tool: ${this.#displayName || this.#name}`; |
| 203 | 203 | } |
| 204 | 204 | |
| @@ -303,9 +303,9 @@ export class ToolManager { | ||
| 303 | 303 | * Formats a message for a tool call by name. |
| 304 | 304 | * @param {string} name The name of the tool to format the message for. |
| 305 | 305 | * @param {object} parameters Function tool call parameters. |
| 306 | 306 | * @returns {Promise<string>} The formatted message for the tool call. |
| 307 | 307 | */ |
| 308 | 308 | static async formatToolCallMessage(name, parameters) { |
| 309 | 309 | if (!this.#tools.has(name)) { |
| 310 | 310 | return `Invoked unknown tool: ${name}`; |
| 311 | 311 | } |
| @@ -313,7 +313,7 @@ export class ToolManager { | ||
| 313 | 313 | try { |
| 314 | 314 | const tool = this.#tools.get(name); |
| 315 | 315 | const formatParameters = typeof parameters === 'string' ? JSON.parse(parameters) : parameters; |
| 316 | 316 | return await tool.formatMessage(formatParameters); |
| 317 | 317 | } catch (error) { |
| 318 | 318 | console.error(`[ToolManager] An error occurred while formatting the tool call message for "${name}":`, error); |
| 319 | 319 | return `Invoking tool: ${name}`; |
| @@ -590,7 +590,7 @@ export class ToolManager { | ||
| 590 | 590 | const name = toolCall.function.name; |
| 591 | 591 | const displayName = ToolManager.getDisplayName(name); |
| 592 | 592 | |
| 593 | 593 | const message = await ToolManager.formatToolCallMessage(name, parameters); |
| 594 | 594 | const toast = message && toastr.info(message, 'Tool Calling', { timeOut: 0 }); |
| 595 | 595 | const toolResult = await ToolManager.invokeFunctionTool(name, parameters); |
| 596 | 596 | toastr.clear(toast); |
| @@ -878,6 +878,7 @@ export class ToolManager { | ||
| 878 | 878 | parameters: JSON.parse(parameters ?? '{}'), |
| 879 | 879 | action: actionFunc, |
| 880 | 880 | formatMessage: formatMessageFunc, |
| 881 | + shouldRegister: async () => true, // TODO: Implement shouldRegister | |
| 881 | 882 | }); |
| 882 | 883 | |
| 883 | 884 | return ''; |