mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
ESLint and JSDoc fixes
This commit is contained in:
@ -8180,6 +8180,8 @@ window['SillyTavern'].getContext = function () {
|
|||||||
unregisterMacro: MacrosParser.unregisterMacro.bind(MacrosParser),
|
unregisterMacro: MacrosParser.unregisterMacro.bind(MacrosParser),
|
||||||
registerFunctionTool: ToolManager.registerFunctionTool.bind(ToolManager),
|
registerFunctionTool: ToolManager.registerFunctionTool.bind(ToolManager),
|
||||||
unregisterFunctionTool: ToolManager.unregisterFunctionTool.bind(ToolManager),
|
unregisterFunctionTool: ToolManager.unregisterFunctionTool.bind(ToolManager),
|
||||||
|
isToolCallingSupported: ToolManager.isToolCallingSupported.bind(ToolManager),
|
||||||
|
canPerformToolCalls: ToolManager.canPerformToolCalls.bind(ToolManager),
|
||||||
registerDebugFunction: registerDebugFunction,
|
registerDebugFunction: registerDebugFunction,
|
||||||
/** @deprecated Use renderExtensionTemplateAsync instead. */
|
/** @deprecated Use renderExtensionTemplateAsync instead. */
|
||||||
renderExtensionTemplate: renderExtensionTemplate,
|
renderExtensionTemplate: renderExtensionTemplate,
|
||||||
|
@ -18,6 +18,16 @@ import { Popup } from './popup.js';
|
|||||||
* @property {Error[]} errors Errors that occurred during tool invocation
|
* @property {Error[]} errors Errors that occurred during tool invocation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ToolRegistration
|
||||||
|
* @property {string} name - The name of the tool.
|
||||||
|
* @property {string} displayName - The display name of the tool.
|
||||||
|
* @property {string} description - A description of the tool.
|
||||||
|
* @property {object} parameters - The parameters for the tool.
|
||||||
|
* @property {function} action - The action to perform when the tool is invoked.
|
||||||
|
* @property {function} formatMessage - A function to format the tool call message.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that represents a tool definition.
|
* A class that represents a tool definition.
|
||||||
*/
|
*/
|
||||||
@ -136,13 +146,7 @@ export class ToolManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a new tool with the tool registry.
|
* Registers a new tool with the tool registry.
|
||||||
* @param {object} tool The tool to register.
|
* @param {ToolRegistration} tool The tool to register.
|
||||||
* @param {string} tool.name The name of the tool.
|
|
||||||
* @param {string} tool.displayName A user-friendly display name for the tool.
|
|
||||||
* @param {string} tool.description A description of what the tool does.
|
|
||||||
* @param {object} tool.parameters A JSON schema for the parameters that the tool accepts.
|
|
||||||
* @param {function} tool.action A function that will be called when the tool is executed.
|
|
||||||
* @param {function} tool.formatMessage A function that will be called to format the tool call toast.
|
|
||||||
*/
|
*/
|
||||||
static registerFunctionTool({ name, displayName, description, parameters, action, formatMessage }) {
|
static registerFunctionTool({ name, displayName, description, parameters, action, formatMessage }) {
|
||||||
// Convert WIP arguments
|
// Convert WIP arguments
|
||||||
@ -201,6 +205,12 @@ export class ToolManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a message for a tool call by name.
|
||||||
|
* @param {string} name The name of the tool to format the message for.
|
||||||
|
* @param {object} parameters Function tool call parameters.
|
||||||
|
* @returns {string} The formatted message for the tool call.
|
||||||
|
*/
|
||||||
static formatToolCallMessage(name, parameters) {
|
static formatToolCallMessage(name, parameters) {
|
||||||
if (!this.#tools.has(name)) {
|
if (!this.#tools.has(name)) {
|
||||||
return `Invoked unknown tool: ${name}`;
|
return `Invoked unknown tool: ${name}`;
|
||||||
@ -295,9 +305,14 @@ export class ToolManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply a tool call delta to a target object.
|
||||||
|
* @param {object} target The target object to apply the delta to
|
||||||
|
* @param {object} delta The delta object to apply
|
||||||
|
*/
|
||||||
static #applyToolCallDelta(target, delta) {
|
static #applyToolCallDelta(target, delta) {
|
||||||
for (const key in delta) {
|
for (const key in delta) {
|
||||||
if (!delta.hasOwnProperty(key)) continue;
|
if (!Object.prototype.hasOwnProperty.call(delta, key)) continue;
|
||||||
if (key === '__proto__' || key === 'constructor') continue;
|
if (key === '__proto__' || key === 'constructor') continue;
|
||||||
|
|
||||||
const deltaValue = delta[key];
|
const deltaValue = delta[key];
|
||||||
@ -409,13 +424,6 @@ export class ToolManager {
|
|||||||
errors: [],
|
errors: [],
|
||||||
};
|
};
|
||||||
const toolCalls = ToolManager.#getToolCallsFromData(data);
|
const toolCalls = ToolManager.#getToolCallsFromData(data);
|
||||||
const oaiCompatibleSources = [
|
|
||||||
chat_completion_sources.OPENAI,
|
|
||||||
chat_completion_sources.CUSTOM,
|
|
||||||
chat_completion_sources.MISTRALAI,
|
|
||||||
chat_completion_sources.OPENROUTER,
|
|
||||||
chat_completion_sources.GROQ,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!Array.isArray(toolCalls)) {
|
if (!Array.isArray(toolCalls)) {
|
||||||
return result;
|
return result;
|
||||||
@ -463,7 +471,7 @@ export class ToolManager {
|
|||||||
* @param {ToolInvocation[]} invocations Tool invocations.
|
* @param {ToolInvocation[]} invocations Tool invocations.
|
||||||
* @returns {string} Formatted message with tool invocations.
|
* @returns {string} Formatted message with tool invocations.
|
||||||
*/
|
*/
|
||||||
static #formatMessage(invocations) {
|
static #formatToolInvocationMessage(invocations) {
|
||||||
const tryParse = (x) => { try { return JSON.parse(x); } catch { return x; } };
|
const tryParse = (x) => { try { return JSON.parse(x); } catch { return x; } };
|
||||||
const data = structuredClone(invocations);
|
const data = structuredClone(invocations);
|
||||||
const detailsElement = document.createElement('details');
|
const detailsElement = document.createElement('details');
|
||||||
@ -493,7 +501,7 @@ export class ToolManager {
|
|||||||
force_avatar: system_avatar,
|
force_avatar: system_avatar,
|
||||||
is_system: true,
|
is_system: true,
|
||||||
is_user: false,
|
is_user: false,
|
||||||
mes: ToolManager.#formatMessage(invocations),
|
mes: ToolManager.#formatToolInvocationMessage(invocations),
|
||||||
extra: {
|
extra: {
|
||||||
isSmallSys: true,
|
isSmallSys: true,
|
||||||
tool_invocations: invocations,
|
tool_invocations: invocations,
|
||||||
|
Reference in New Issue
Block a user