diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/ResourceTools/Settings.cs b/WelsonJS.Toolkit/WelsonJS.Launcher/ResourceTools/Settings.cs index 4886404..8b3a005 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/ResourceTools/Settings.cs +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/ResourceTools/Settings.cs @@ -49,12 +49,9 @@ namespace WelsonJS.Launcher.ResourceTools var resourceStrings = new Dictionary(); foreach (System.Collections.DictionaryEntry entry in resourceSet) { - string key = (string)entry.Key; - object value = entry.Value; - - if (value is string strValue) + if (entry.Value is string strValue) { - resourceStrings[key] = strValue; + resourceStrings[(string)entry.Key] = strValue; } } @@ -62,16 +59,11 @@ namespace WelsonJS.Launcher.ResourceTools var appConfig = ConfigurationManager.AppSettings.AllKeys .ToDictionary(k => k, k => ConfigurationManager.AppSettings[k]); - // Merge keys from both sources (app.config has priority) - var allKeys = new HashSet(resourceStrings.Keys.Concat(appConfig.Keys)); - var finalConfig = new Dictionary(); - - foreach (var key in allKeys) + // Merge by starting with resourceStrings and letting app.config override + var finalConfig = new Dictionary(resourceStrings); + foreach (var kv in appConfig) { - if (appConfig.ContainsKey(key)) - finalConfig[key] = appConfig[key]; - else if (resourceStrings.ContainsKey(key)) - finalConfig[key] = resourceStrings[key]; + finalConfig[kv.Key] = kv.Value; } // Generate XML using XElement diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/editor.html b/WelsonJS.Toolkit/WelsonJS.Launcher/editor.html index 342d8c8..653b088 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/editor.html +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/editor.html @@ -164,6 +164,13 @@ }); } + function pushPromptMessage(role, content) { + promptMessages.push({ + role: role, + content: content + }); + } + require(["vs/editor/editor.main"], function () { editor = monaco.editor.create(document.getElementById('container'), { value: ['// lib/sayhello.js', 'function say() {', ' console.log("hello");', '}', '', 'exports.say = say;', '', 'exports.VERSIONINFO = "SayHello (sayhello.js) version 0.1";', 'exports.AUTHOR = "abuse@catswords.net";', 'exports.global = global;', 'exports.require = global.require;'].join('\n'), @@ -270,11 +277,7 @@ } appendTextToEditor(`\n// ${promptMessage}... Generating text with Copilot...`); - - promptMessages.push({ - role: 'user', - content: promptMessage - }) + pushPromptMessage("user", promptMessage); (async function () { const targetWsUrl = await getTargetByUrl('copilot.microsoft.com'); @@ -294,15 +297,11 @@ } appendTextToEditor(`\n// ${promptMessage}... Generating text with Azure AI...`); + pushPromptMessage("user", promptMessage); const apiKey = settings.AzureAiServiceApiKey; const url = `${settings.AzureAiServicePrefix}models/chat/completions?api-version=${settings.AzureAiServiceApiVersion}`; - promptMessages.push({ - role: 'user', - content: promptMessage - }) - const data = { messages: promptMessages, max_tokens: 2048, @@ -322,10 +321,7 @@ .then(response => { response.data.choices.forEach(x => { const responseContent = x.message.content; - promptMessages.push({ - role: 'assistant', - content: responseContent - }); + pushPromptMessage("assistant", responseContent); const responseText = DOMPurify.sanitize(responseContent, { ALLOWED_TAGS: [], ALLOWED_ATTR: [] }); appendTextToEditor(`/*\n${responseText}\n*/`); @@ -457,12 +453,9 @@ if (response.id == 3) { const responseContent = response.result.result.value; - promptMessages.push({ - role: 'assistant', - content: responseContent - }); - appendTextToEditor(responseContent); + pushPromptMessage("assistant", responseContent); + socket.close(); } };