ESLint and JSDoc fixes

4a2989718caf6f8a64515035c01a43f26b38cbe3

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +27 -17Showing whitespace changes
public/script.js+2 -0
@@ -8180,6 +8180,8 @@ window['SillyTavern'].getContext = function () {
8180 unregisterMacro: MacrosParser.unregisterMacro.bind(MacrosParser),8180 unregisterMacro: MacrosParser.unregisterMacro.bind(MacrosParser),
8181 registerFunctionTool: ToolManager.registerFunctionTool.bind(ToolManager),8181 registerFunctionTool: ToolManager.registerFunctionTool.bind(ToolManager),
8182 unregisterFunctionTool: ToolManager.unregisterFunctionTool.bind(ToolManager),8182 unregisterFunctionTool: ToolManager.unregisterFunctionTool.bind(ToolManager),
8183 isToolCallingSupported: ToolManager.isToolCallingSupported.bind(ToolManager),
8184 canPerformToolCalls: ToolManager.canPerformToolCalls.bind(ToolManager),
8183 registerDebugFunction: registerDebugFunction,8185 registerDebugFunction: registerDebugFunction,
8184 /** @deprecated Use renderExtensionTemplateAsync instead. */8186 /** @deprecated Use renderExtensionTemplateAsync instead. */
8185 renderExtensionTemplate: renderExtensionTemplate,8187 renderExtensionTemplate: renderExtensionTemplate,
public/scripts/tool-calling.js+25 -17
@@ -19,6 +19,16 @@ import { Popup } from './popup.js';
19 */19 */
2020
21/**21/**
22 * @typedef {object} ToolRegistration
23 * @property {string} name - The name of the tool.
24 * @property {string} displayName - The display name of the tool.
25 * @property {string} description - A description of the tool.
26 * @property {object} parameters - The parameters for the tool.
27 * @property {function} action - The action to perform when the tool is invoked.
28 * @property {function} formatMessage - A function to format the tool call message.
29 */
30
31/**
22 * A class that represents a tool definition.32 * A class that represents a tool definition.
23 */33 */
24class ToolDefinition {34class ToolDefinition {
@@ -136,13 +146,7 @@ export class ToolManager {
136146
137 /**147 /**
138 * Registers a new tool with the tool registry.148 * Registers a new tool with the tool registry.
139 * @param {object} tool The tool to register.149 * @param {ToolRegistration} tool The tool to register.
140 * @param {string} tool.name The name of the tool.
141 * @param {string} tool.displayName A user-friendly display name for the tool.
142 * @param {string} tool.description A description of what the tool does.
143 * @param {object} tool.parameters A JSON schema for the parameters that the tool accepts.
144 * @param {function} tool.action A function that will be called when the tool is executed.
145 * @param {function} tool.formatMessage A function that will be called to format the tool call toast.
146 */150 */
147 static registerFunctionTool({ name, displayName, description, parameters, action, formatMessage }) {151 static registerFunctionTool({ name, displayName, description, parameters, action, formatMessage }) {
148 // Convert WIP arguments152 // Convert WIP arguments
@@ -201,6 +205,12 @@ export class ToolManager {
201 }205 }
202 }206 }
203207
208 /**
209 * Formats a message for a tool call by name.
210 * @param {string} name The name of the tool to format the message for.
211 * @param {object} parameters Function tool call parameters.
212 * @returns {string} The formatted message for the tool call.
213 */
204 static formatToolCallMessage(name, parameters) {214 static formatToolCallMessage(name, parameters) {
205 if (!this.#tools.has(name)) {215 if (!this.#tools.has(name)) {
206 return `Invoked unknown tool: ${name}`;216 return `Invoked unknown tool: ${name}`;
@@ -295,9 +305,14 @@ export class ToolManager {
295 }305 }
296 }306 }
297307
308 /**
309 * Apply a tool call delta to a target object.
310 * @param {object} target The target object to apply the delta to
311 * @param {object} delta The delta object to apply
312 */
298 static #applyToolCallDelta(target, delta) {313 static #applyToolCallDelta(target, delta) {
299 for (const key in delta) {314 for (const key in delta) {
300 if (!delta.hasOwnProperty(key)) continue;315 if (!Object.prototype.hasOwnProperty.call(delta, key)) continue;
301 if (key === '__proto__' || key === 'constructor') continue;316 if (key === '__proto__' || key === 'constructor') continue;
302317
303 const deltaValue = delta[key];318 const deltaValue = delta[key];
@@ -409,13 +424,6 @@ export class ToolManager {
409 errors: [],424 errors: [],
410 };425 };
411 const toolCalls = ToolManager.#getToolCallsFromData(data);426 const toolCalls = ToolManager.#getToolCallsFromData(data);
412 const oaiCompatibleSources = [
413 chat_completion_sources.OPENAI,
414 chat_completion_sources.CUSTOM,
415 chat_completion_sources.MISTRALAI,
416 chat_completion_sources.OPENROUTER,
417 chat_completion_sources.GROQ,
418 ];
419427
420 if (!Array.isArray(toolCalls)) {428 if (!Array.isArray(toolCalls)) {
421 return result;429 return result;
@@ -463,7 +471,7 @@ export class ToolManager {
463 * @param {ToolInvocation[]} invocations Tool invocations.471 * @param {ToolInvocation[]} invocations Tool invocations.
464 * @returns {string} Formatted message with tool invocations.472 * @returns {string} Formatted message with tool invocations.
465 */473 */
466 static #formatMessage(invocations) {474 static #formatToolInvocationMessage(invocations) {
467 const tryParse = (x) => { try { return JSON.parse(x); } catch { return x; } };475 const tryParse = (x) => { try { return JSON.parse(x); } catch { return x; } };
468 const data = structuredClone(invocations);476 const data = structuredClone(invocations);
469 const detailsElement = document.createElement('details');477 const detailsElement = document.createElement('details');
@@ -493,7 +501,7 @@ export class ToolManager {
493 force_avatar: system_avatar,501 force_avatar: system_avatar,
494 is_system: true,502 is_system: true,
495 is_user: false,503 is_user: false,
496 mes: ToolManager.#formatMessage(invocations),504 mes: ToolManager.#formatToolInvocationMessage(invocations),
497 extra: {505 extra: {
498 isSmallSys: true,506 isSmallSys: true,
499 tool_invocations: invocations,507 tool_invocations: invocations,