From 79d18a10ecc4e073ae728871c7367487d25b503c Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Thu, 3 Sep 2026 21:40:09 +0800 Subject: [PATCH] Fix gemini-model node ignoring api key and model changes run() checked the new inputs against this.lastInputs, but PureFunctionNode.forcedRun() overwrites lastInputs with the current inputs before calling run(), so the comparison was always equal and the GoogleGenAI client / selected model were never rebuilt. Changing the api key or the model dropdown therefore had no effect after the first run. Remember which key the client was built with and rebuild only when that changes. --- custom_nodes/packages/gemini/src/gemini_model.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/custom_nodes/packages/gemini/src/gemini_model.ts b/custom_nodes/packages/gemini/src/gemini_model.ts index 904f33a..89ec46c 100644 --- a/custom_nodes/packages/gemini/src/gemini_model.ts +++ b/custom_nodes/packages/gemini/src/gemini_model.ts @@ -91,6 +91,11 @@ type NestedArray = T extends Array ? never : Array>; export class GeminiModel extends PureFunctionNode { private genAI?: GoogleGenAI; private model?: string; + // The API key the current genAI client was built with. The client pins the + // key at construction time, so we need to remember it separately: by the + // time run() fires, PureFunctionNode has already overwritten lastInputs + // with the new inputs, so it can't be used to detect a key change here. + private genAIKey?: string; constructor() { super(); @@ -111,18 +116,20 @@ export class GeminiModel extends PureFunctionNode { throw new Error('Please set your API key'); } - // Rebuild if api key is different. - if (inputs.apiKey !== this.lastInputs?.apiKey || !this.genAI) { + // Rebuild the client when the api key changes. GoogleGenAI keeps using + // the key it was constructed with, so a new key needs a new client. + if (inputs.apiKey !== this.genAIKey || !this.genAI) { this.genAI = new GoogleGenAI({ apiKey: inputs.apiKey, }); + this.genAIKey = inputs.apiKey; } // Get the selected model. if (!inputs.modelId) { throw new Error('Please select a model'); } - if (inputs.modelId !== this.lastInputs?.modelId || !this.model) { + if (inputs.modelId !== this.model) { this.model = inputs.modelId; }