diff --git a/package-lock.json b/package-lock.json index 709c19b64..4c18e660d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -549,7 +549,6 @@ "resolved": "https://registry.npmjs.org/@jimp/custom/-/custom-0.22.12.tgz", "integrity": "sha512-xcmww1O/JFP2MrlGUMd3Q78S3Qu6W3mYTXYuIqFq33EorgYHV/HqymHfXy9GjiCJ7OI+7lWx6nYFOzU7M4rd1Q==", "license": "MIT", - "peer": true, "dependencies": { "@jimp/core": "^0.22.12" } @@ -1011,7 +1010,6 @@ "resolved": "https://registry.npmjs.org/@jimp/plugin-resize/-/plugin-resize-1.6.0.tgz", "integrity": "sha512-uSUD1mqXN9i1SGSz5ov3keRZ7S9L32/mAQG08wUwZiEi5FpbV0K8A8l1zkazAIZi9IJzLlTauRNU41Mi8IF9fA==", "license": "MIT", - "peer": true, "dependencies": { "@jimp/core": "1.6.0", "@jimp/types": "1.6.0", @@ -1043,7 +1041,6 @@ "resolved": "https://registry.npmjs.org/@jimp/plugin-scale/-/plugin-scale-0.22.12.tgz", "integrity": "sha512-dghs92qM6MhHj0HrV2qAwKPMklQtjNpoYgAB94ysYpsXslhRTiPisueSIELRwZGEr0J0VUxpUY7HgJwlSIgGZw==", "license": "MIT", - "peer": true, "dependencies": { "@jimp/utils": "^0.22.12" }, @@ -1139,7 +1136,6 @@ "resolved": "https://registry.npmjs.org/@jimp/plugin-blit/-/plugin-blit-0.22.12.tgz", "integrity": "sha512-xslz2ZoFZOPLY8EZ4dC29m168BtDx95D6K80TzgUi8gqT7LY6CsajWO0FAxDwHz6h0eomHMfyGX0stspBrTKnQ==", "license": "MIT", - "peer": true, "dependencies": { "@jimp/utils": "^0.22.12" }, @@ -1176,7 +1172,6 @@ "resolved": "https://registry.npmjs.org/@jimp/plugin-color/-/plugin-color-0.22.12.tgz", "integrity": "sha512-xImhTE5BpS8xa+mAN6j4sMRWaUgUDLoaGHhJhpC+r7SKKErYDR0WQV4yCE4gP+N0gozD0F3Ka1LUSaMXrn7ZIA==", "license": "MIT", - "peer": true, "dependencies": { "@jimp/utils": "^0.22.12", "tinycolor2": "^1.6.0" @@ -1220,7 +1215,6 @@ "resolved": "https://registry.npmjs.org/@jimp/plugin-crop/-/plugin-crop-0.22.12.tgz", "integrity": "sha512-FNuUN0OVzRCozx8XSgP9MyLGMxNHHJMFt+LJuFjn1mu3k0VQxrzqbN06yIl46TVejhyAhcq5gLzqmSCHvlcBVw==", "license": "MIT", - "peer": true, "dependencies": { "@jimp/utils": "^0.22.12" }, @@ -1308,7 +1302,6 @@ "resolved": "https://registry.npmjs.org/@jimp/plugin-resize/-/plugin-resize-0.22.12.tgz", "integrity": "sha512-3NyTPlPbTnGKDIbaBgQ3HbE6wXbAlFfxHVERmrbqAi8R3r6fQPxpCauA8UVDnieg5eo04D0T8nnnNIX//i/sXg==", "license": "MIT", - "peer": true, "dependencies": { "@jimp/utils": "^0.22.12" }, @@ -1321,7 +1314,6 @@ "resolved": "https://registry.npmjs.org/@jimp/plugin-rotate/-/plugin-rotate-0.22.12.tgz", "integrity": "sha512-9YNEt7BPAFfTls2FGfKBVgwwLUuKqy+E8bDGGEsOqHtbuhbshVGxN2WMZaD4gh5IDWvR+emmmPPWGgaYNYt1gA==", "license": "MIT", - "peer": true, "dependencies": { "@jimp/utils": "^0.22.12" }, @@ -1922,7 +1914,6 @@ "integrity": "sha512-Crp6WY9aTYP3qPi2wGDo9iUe/rceX01UMhnF1jmwDcKCFM6cx7YhGP/Mpr3y9AASpfHixIG0E6azCcL5OcDHsQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/body-parser": "*", "@types/express-serve-static-core": "^4.17.33", @@ -2612,7 +2603,6 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -3232,7 +3222,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", @@ -4567,7 +4556,6 @@ "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -8125,7 +8113,6 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz", "integrity": "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A==", "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -9143,7 +9130,6 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/public/script.js b/public/script.js index 2620fe858..a841fe743 100644 --- a/public/script.js +++ b/public/script.js @@ -4475,21 +4475,27 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro // In group chats, only include reasoning from the currently generating character const isOtherGroupMember = selected_group && coreChat[i].name !== name2; - coreChat[i] = { - ...coreChat[i], - mes: isOtherGroupMember - ? coreChat[i].mes - : promptReasoning.addToMessage( - coreChat[i].mes, - getRegexedString( - String(coreChat[i].extra?.reasoning ?? ''), - regex_placement.REASONING, - { isPrompt: true, depth: depth }, - ), - isPrefix, - coreChat[i].extra?.reasoning_duration, - ), - }; + if (!isOtherGroupMember) { + const reasoning = getRegexedString( + String(coreChat[i].extra?.reasoning ?? ''), + regex_placement.REASONING, + { isPrompt: true, depth: depth }, + ); + const duration = coreChat[i].extra?.reasoning_duration; + + if (Array.isArray(coreChat[i].extra?.tool_invocations)) { + // For tool-call messages, mes is HTML display text — don't prepend reasoning there. + // Instead compute the reasoning prefix with empty content and store it separately. + // Use undefined (not empty string) when there is no reasoning to preserve existing behavior. + const toolCallContent = promptReasoning.addToMessage('', reasoning, isPrefix, duration) || undefined; + coreChat[i] = { ...coreChat[i], toolCallContent }; + } else { + coreChat[i] = { + ...coreChat[i], + mes: promptReasoning.addToMessage(coreChat[i].mes, reasoning, isPrefix, duration), + }; + } + } if (promptReasoning.isLimitReached()) { break; } diff --git a/public/scripts/openai.js b/public/scripts/openai.js index fdba275f3..fbec05dd7 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -621,7 +621,7 @@ function setOpenAIMessages(chat) { }); } - messages[i] = { 'role': role, 'content': content, name: name, 'media': media, 'mediaDisplay': mediaDisplay, 'mediaIndex': mediaIndex, 'invocations': invocations, 'signature': signature, 'reasoning': reasoning }; + messages[i] = { 'role': role, 'content': content, name: name, 'media': media, 'mediaDisplay': mediaDisplay, 'mediaIndex': mediaIndex, 'invocations': invocations, 'signature': signature, 'reasoning': reasoning, 'toolCallContent': chat[j].toolCallContent }; j++; } @@ -1028,7 +1028,7 @@ async function populateChatHistory(messages, prompts, chatCompletion, type = nul } return clone; }); - const toolCallMessage = await Message.createAsync(chatMessage.role, undefined, 'toolCall-' + chatMessage.identifier); + const toolCallMessage = await Message.createAsync(chatMessage.role, chatPrompt.toolCallContent, 'toolCall-' + chatMessage.identifier); const toolResultMessages = await Promise.all(invocations.slice().reverse().map((invocation) => Message.createAsync('tool', invocation.result || '[No content]', invocation.id))); await toolCallMessage.setToolCalls(invocations, includeSignature, includeToolReasoning); if (chatCompletion.canAffordAll([toolCallMessage, ...toolResultMessages])) { diff --git a/public/scripts/reasoning.js b/public/scripts/reasoning.js index 74183c54e..f5bd3235d 100644 --- a/public/scripts/reasoning.js +++ b/public/scripts/reasoning.js @@ -716,6 +716,9 @@ export class PromptReasoning { * @returns {string} Message content with reasoning */ addToMessage(content, reasoning, isPrefix, duration) { + // Normalize content to empty string if not provided + content = content ?? ''; + // Disabled or reached limit of additions if (!isPrefix && (!power_user.reasoning.add_to_prompts || this.counter >= power_user.reasoning.max_additions)) { return content; diff --git a/tests/package-lock.json b/tests/package-lock.json index 9c8244a2c..38c0a1b86 100644 --- a/tests/package-lock.json +++ b/tests/package-lock.json @@ -54,7 +54,6 @@ "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.7.tgz", "integrity": "sha512-nykK+LEK86ahTkX/3TgauT0ikKoNCfKHEaZYTUVupJdTLzGNvrblu4u6fa7DhZONAltdf8e662t/abY8idrd/g==", "license": "MIT", - "peer": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.24.7", @@ -1199,7 +1198,6 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -1447,7 +1445,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001629", "electron-to-chromium": "^1.4.796", @@ -1787,7 +1784,6 @@ "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz", "integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==", "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1",