Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const GenAIApp = (function () {
let knowledgeLink = [];
let compaction_enabled = false;
let compaction_threshold = 10000;
let tool_combination_enabled = false;

let previous_response_id;
let last_response_id = null;
Expand Down Expand Up @@ -295,6 +296,18 @@ const GenAIApp = (function () {
return this;
};

/**
* OPTIONAL
*
* Enable or disable server-side tool invocations for Gemini (Tool Combination).
* @param {boolean} enabled - True to enable tool combination.
* @returns {Chat} - The current Chat instance.
*/
this.enableToolCombination = function (enabled) {
tool_combination_enabled = enabled;
return this;
Comment on lines +306 to +308
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify call sites and argument shapes passed to enableToolCombination(...)
rg -nP --type=js -C2 '\benableToolCombination\s*\('

Repository: scriptit-fr/GenAIApp

Length of output: 212


🏁 Script executed:

#!/bin/bash
# First, verify the file exists and check the target lines
if [ -f "src/code.gs" ]; then
  echo "=== Code at lines 306-308 ==="
  sed -n '306,308p' src/code.gs
  echo ""
  echo "=== Context around lines 306-308 ==="
  sed -n '300,315p' src/code.gs
else
  echo "File src/code.gs not found"
fi

Repository: scriptit-fr/GenAIApp

Length of output: 868


🏁 Script executed:

#!/bin/bash
# Search for enableToolCombination calls without type filter
echo "=== Calls to enableToolCombination ==="
rg -nC3 'enableToolCombination\s*\(' src/

Repository: scriptit-fr/GenAIApp

Length of output: 102


🏁 Script executed:

#!/bin/bash
# Check file size first to understand what we're working with
wc -l src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 80


🏁 Script executed:

#!/bin/bash
# Search for any reference to enableToolCombination across all files
echo "=== enableToolCombination references (all files) ==="
rg -n 'enableToolCombination'

Repository: scriptit-fr/GenAIApp

Length of output: 188


🏁 Script executed:

#!/bin/bash
# Search for tool_combination_enabled variable usage
echo "=== tool_combination_enabled usage ==="
rg -n 'tool_combination_enabled' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 281


🏁 Script executed:

#!/bin/bash
# Look for README or examples that might show API usage
echo "=== README and example files ==="
find . -maxdepth 2 -type f \( -name "README*" -o -name "*.md" -o -name "example*" -o -name "test*" \) | head -20

Repository: scriptit-fr/GenAIApp

Length of output: 131


🏁 Script executed:

#!/bin/bash
# Check the structure around the function to understand the API better
echo "=== Full function and surrounding context ==="
sed -n '300,325p' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 965


🏁 Script executed:

#!/bin/bash
# Check testFunctions.gs for enableToolCombination usage
echo "=== testFunctions.gs content (search for enableToolCombination) ==="
grep -n 'enableToolCombination' src/testFunctions.gs
if [ $? -ne 0 ]; then
  echo "No enableToolCombination found in testFunctions.gs"
fi

Repository: scriptit-fr/GenAIApp

Length of output: 182


🏁 Script executed:

#!/bin/bash
# Check README for enableToolCombination or API documentation
echo "=== README.md content (search for enableToolCombination) ==="
grep -n 'enableToolCombination' README.md
if [ $? -ne 0 ]; then
  echo "No enableToolCombination found in README.md"
  echo ""
  echo "=== Checking if README documents the Chat API ==="
  grep -n 'Chat\|API\|method' README.md | head -20
fi

Repository: scriptit-fr/GenAIApp

Length of output: 1734


🏁 Script executed:

#!/bin/bash
# Check if there's a pattern for how this library is used - look for method chaining examples
echo "=== Checking for method chaining patterns in testFunctions.gs ==="
head -100 src/testFunctions.gs

Repository: scriptit-fr/GenAIApp

Length of output: 3313


🏁 Script executed:

#!/bin/bash
# Search for enableBrowsing to compare how similar methods handle boolean parameters
echo "=== enableBrowsing implementation ==="
rg -n -A5 'this.enableBrowsing\s*=' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 286


🏁 Script executed:

#!/bin/bash
# Check if there are other enable* methods and their patterns
echo "=== All enable* methods in code.gs ==="
rg -n 'this\.enable[A-Za-z]*\s*=\s*function' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 273


🏁 Script executed:

#!/bin/bash
# Look at full testKnowledgeLink to see more usage patterns
echo "=== More of testFunctions.gs ==="
sed -n '85,120p' src/testFunctions.gs

Repository: scriptit-fr/GenAIApp

Length of output: 1126


🏁 Script executed:

#!/bin/bash
# Check enableCompaction implementation
echo "=== enableCompaction implementation ==="
sed -n '369,375p' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 314


🏁 Script executed:

#!/bin/bash
# Check all three enable* methods side by side to see patterns
echo "=== All enable* methods implementation ==="
sed -n '289,295p' src/code.gs
echo "---"
sed -n '306,312p' src/code.gs
echo "---"
sed -n '369,375p' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 719


🏁 Script executed:

#!/bin/bash
# Check the JSDoc comments for all three enable methods to understand intended API
echo "=== JSDoc for enableBrowsing ==="
sed -n '284,295p' src/code.gs
echo ""
echo "=== JSDoc for enableToolCombination ==="
sed -n '301,312p' src/code.gs
echo ""
echo "=== JSDoc for enableCompaction ==="
sed -n '364,375p' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 1444


Fix Boolean coercion in enableToolCombination to match JSDoc specification.

The JSDoc declares @param {boolean} but the implementation accepts any truthy value via Boolean(enabled). This creates a silent type mismatch—callers passing "false" (string) will unintentionally enable the feature since Boolean("false") evaluates to true. A public API with explicit boolean documentation should enforce the type rather than silently coerce it.

The same issue exists in enableCompaction at line 369.

Either remove the Boolean() wrapper and assign enabled directly, or add explicit type validation to reject non-boolean values.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/code.gs` around lines 306 - 308, The methods enableToolCombination and
enableCompaction are coercing any truthy value via Boolean(enabled) though their
JSDoc promises a boolean; change them to enforce boolean input by validating
typeof enabled === "boolean" and either assign enabled directly to the internal
flags (e.g., tool_combination_enabled, compaction_enabled) or throw a TypeError
when a non-boolean is passed, and return this for chaining; update the
implementations of enableToolCombination and enableCompaction accordingly.

};

/**
* Includes the content of a web page in the prompt sent to openAI
* @param {string} url - the url of the webpage you want to fetch
Expand Down Expand Up @@ -751,7 +764,8 @@ const GenAIApp = (function () {
'tool_config': {
function_calling_config: {
mode: "AUTO"
}
},
includeServerSideToolInvocations: tool_combination_enabled
},
Comment on lines 764 to 769
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

For Gemini REST APIs (Generative Language v1beta and Vertex AI v1), is tool_config.includeServerSideToolInvocations universally supported across models? Are unknown JSON fields rejected or ignored?

💡 Result:

Is tool_config.includeServerSideToolInvocations supported (Generative Language v1beta / Vertex AI v1)?

No. In the published schemas for these REST APIs, that field doesn’t exist:

  • Generative Language v1beta: ToolConfig only contains function_calling_config (no includeServerSideToolInvocations). [1]
  • Vertex AI v1: ToolConfig only contains function_calling_config and retrieval_config (no includeServerSideToolInvocations). [2]

So it’s not “universally supported across models” in these APIs—it's simply not a recognized request field there.

Are unknown JSON fields rejected or ignored?

They’re rejected (request fails) rather than ignored. Both APIs use protobuf-style JSON parsing and commonly return 400 INVALID_ARGUMENT with messages like “Invalid JSON payload received. Unknown name …: Cannot find field.” when you send unknown fields. Examples:

  • Generative Language v1beta: unknown fields like metadata cause Unknown name ...: Cannot find field. [3]
  • Vertex AI usage also shows unknown fields (e.g., tools, toolConfig when sent to the wrong endpoint/version) being rejected with the same “Unknown name …” error pattern. [4]

Implication: If you send tool_config.includeServerSideToolInvocations to these endpoints, expect an error, not a silent no-op.

Sources: [1] [2] [3] [4]


🏁 Script executed:

# Read the relevant section of the code file
sed -n '750,780p' src/code.gs

Repository: scriptit-fr/GenAIApp

Length of output: 1472


🏁 Script executed:

# Search for API endpoint/version information in the file
rg -n "googleapis|vertex|generative" src/code.gs | head -20

Repository: scriptit-fr/GenAIApp

Length of output: 821


🏁 Script executed:

# Look for URL patterns or API version strings
rg -n "https?://" src/code.gs | head -20

Repository: scriptit-fr/GenAIApp

Length of output: 1896


Gate includeServerSideToolInvocations to enabled-only to prevent API errors.

The code currently sends includeServerSideToolInvocations unconditionally to both Generative Language v1beta and Vertex AI v1 APIs. This field is not a recognized member of ToolConfig in either API schema. Unknown JSON fields in these APIs are rejected with 400 INVALID_ARGUMENT errors (e.g., "Cannot find field"), causing all requests to fail regardless of whether tool combination is used.

Conditionally set the field only when tool_combination_enabled is true:

💡 Proposed defensive change
         const payload = {
           'contents': contents,
           'model': model,
           'generationConfig': {
             maxOutputTokens: max_tokens,
             temperature: temperature,
           },
           'tool_config': {
             function_calling_config: {
               mode: "AUTO"
-            },
-            includeServerSideToolInvocations: tool_combination_enabled
+            }
           },
           tools: []
         };
+
+        if (tool_combination_enabled) {
+          payload.tool_config.includeServerSideToolInvocations = true;
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'tool_config': {
function_calling_config: {
mode: "AUTO"
}
},
includeServerSideToolInvocations: tool_combination_enabled
},
'tool_config': {
function_calling_config: {
mode: "AUTO"
}
},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/code.gs` around lines 764 - 769, The request payload is adding
includeServerSideToolInvocations unconditionally inside the 'tool_config' object
which causes API 400 errors; modify the code that builds the 'tool_config' (the
object containing function_calling_config) so that
includeServerSideToolInvocations is only added when tool_combination_enabled is
true (e.g., construct tool_config, set function_calling_config always, and
conditionally assign includeServerSideToolInvocations = tool_combination_enabled
only when tool_combination_enabled is truthy).

tools: []
};
Expand Down Expand Up @@ -785,9 +799,6 @@ const GenAIApp = (function () {
}

if (browsing) {
tools.push({
google_search: "",
});
payload.tools.push({
url_context: {}
});
Expand Down Expand Up @@ -2443,4 +2454,4 @@ const GenAIApp = (function () {
privateInstanceBaseUrl = baseUrl;
}
}
})();
})();