Skip to content

Gemini 3.8 Live - #41

Merged
thorwebdev merged 14 commits into
mainfrom
thor/gemini-3p8-live
Sep 15, 2026
Merged

thorwebdev merged 14 commits into
mainfrom
thor/gemini-3p8-live

Conversation

@thorwebdev

Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the default model to gemini-3.8-live, switches the API version to v1beta, and introduces support for interaction_status to handle asynchronous reasoning. It also significantly upgrades the frontend UI with a premium layout, enables concurrent execution of tool calls, and adds new custom tools for fetching orders and drawing SVGs. The review feedback highlights a potential XSS vulnerability when directly injecting SVG strings via innerHTML, a discrepancy in the mock order fetch delay (15 seconds instead of the documented 5 seconds), and recommends adding defensive checks to handle unregistered functions and malformed tool call payloads.

Comment on lines +218 to +257
functionToCall(parameters) {
const svgString = parameters.svg;
if (!svgString) {
console.warn("draw_svg tool: No SVG string provided");
return "failed: No SVG string provided";
}

const container = document.getElementById("svgContainer");
const section = document.getElementById("svgSection");
const chatContainer = document.getElementById("chatContainer");

// 1. Render inline message bubble in the chat flow
if (chatContainer) {
const msgDiv = document.createElement("div");
msgDiv.className = "assistant svg-chat-bubble";
msgDiv.style.background = "#ffffff";
msgDiv.style.border = "1px solid #cbd5e1";
msgDiv.style.borderLeft = "4px solid #2563eb";
msgDiv.style.padding = "20px";
msgDiv.style.borderRadius = "16px";
msgDiv.style.margin = "12px 0";
msgDiv.style.boxShadow = "0 4px 16px rgba(0, 0, 0, 0.06)";

msgDiv.innerHTML = `
<div style="font-size:0.75rem; font-weight:700; text-transform:uppercase; letter-spacing:0.06em; color:#2563eb; margin-bottom:12px; display:flex; align-items:center; gap:6px;">
<span>✦ RENDERED SVG GRAPHIC</span>
</div>
<div class="svg-inline-render" style="display:flex; justify-content:center; align-items:center; width:100%; overflow:auto; background:#ffffff; padding:12px; border-radius:8px; border:1px solid #f1f5f9;">
${svgString}
</div>
`;

chatContainer.appendChild(msgDiv);
}

// 2. Also populate standalone container if present
if (container && section) {
container.innerHTML = svgString;
section.style.display = "block";
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-high high

Directly injecting model-generated SVG strings into the DOM using innerHTML introduces a Cross-Site Scripting (XSS) vulnerability, as the SVG could contain malicious <script> tags or event handlers (e.g., onload). Use DOMParser to parse the SVG XML, sanitize it by removing any <script> elements, and append the parsed element safely.

  functionToCall(parameters) {
    const svgString = parameters.svg;
    if (!svgString) {
      console.warn("draw_svg tool: No SVG string provided");
      return "failed: No SVG string provided";
    }

    const parser = new DOMParser();
    const svgDoc = parser.parseFromString(svgString, "image/svg+xml");
    const parserError = svgDoc.querySelector("parsererror");
    if (parserError) {
      console.warn("draw_svg tool: Invalid SVG XML", parserError.textContent);
      return "failed: Invalid SVG XML";
    }

    // Remove any script tags to prevent XSS
    const scripts = svgDoc.querySelectorAll("script");
    scripts.forEach(s => s.remove());

    const container = document.getElementById("svgContainer");
    const section = document.getElementById("svgSection");
    const chatContainer = document.getElementById("chatContainer");

    // 1. Render inline message bubble in the chat flow
    if (chatContainer) {
      const msgDiv = document.createElement("div");
      msgDiv.className = "assistant svg-chat-bubble";
      msgDiv.style.background = "#ffffff";
      msgDiv.style.border = "1px solid #cbd5e1";
      msgDiv.style.borderLeft = "4px solid #2563eb";
      msgDiv.style.padding = "20px";
      msgDiv.style.borderRadius = "16px";
      msgDiv.style.margin = "12px 0";
      msgDiv.style.boxShadow = "0 4px 16px rgba(0, 0, 0, 0.06)";

      msgDiv.innerHTML = `
        <div style="font-size:0.75rem; font-weight:700; text-transform:uppercase; letter-spacing:0.06em; color:#2563eb; margin-bottom:12px; display:flex; align-items:center; gap:6px;">
          <span>✦ RENDERED SVG GRAPHIC</span>
        </div>
        <div class="svg-inline-render" style="display:flex; justify-content:center; align-items:center; width:100%; overflow:auto; background:#ffffff; padding:12px; border-radius:8px; border:1px solid #f1f5f9;">
        </div>
      `;

      msgDiv.querySelector(".svg-inline-render").appendChild(svgDoc.documentElement.cloneNode(true));
      chatContainer.appendChild(msgDiv);
    }

    // 2. Also populate standalone container if present
    if (container && section) {
      container.innerHTML = "";
      container.appendChild(svgDoc.documentElement);
      section.style.display = "block";
    }

Comment on lines +275 to 278
async callFunction(functionName, parameters) {
const functionToCall = this.functionsMap[functionName];
return functionToCall.runFunction(parameters);
return await functionToCall.runFunction(parameters);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Add a defensive check to ensure functionToCall is defined before attempting to call runFunction. If the model attempts to call an unregistered or misspelled function, this will throw a clear and descriptive error instead of a generic TypeError.

  async callFunction(functionName, parameters) {
    const functionToCall = this.functionsMap[functionName];
    if (!functionToCall) {
      throw new Error(`Function '${functionName}' is not registered.`);
    }
    return await functionToCall.runFunction(parameters);
  }

Comment on lines +167 to +170
console.log(`📦 get_order called for ${orderId} — waiting 5s to simulate backend fetch...`);

// Non-blocking 5-second delay simulating an async backend request
await new Promise((resolve) => setTimeout(resolve, 15000));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

There is a discrepancy between the code and the documentation/logs. The log message and comments indicate a 5-second delay, but the setTimeout is configured for 15 seconds (15000 ms). Update the timeout to 5000 ms to match the documented behavior.

Suggested change
console.log(`📦 get_order called for ${orderId} — waiting 5s to simulate backend fetch...`);
// Non-blocking 5-second delay simulating an async backend request
await new Promise((resolve) => setTimeout(resolve, 15000));
console.log(`📦 get_order called for ${orderId} — waiting 5s to simulate backend fetch...`);
// Non-blocking 5-second delay simulating an async backend request
await new Promise((resolve) => setTimeout(resolve, 5000));

Comment on lines 313 to +318
const functionCalls = message.data.functionCalls;
const functionResponses = [];
for (let index = 0; index < functionCalls.length; index++) {
const functionCall = functionCalls[index];
const functionName = functionCall.name;
const functionCallId = functionCall.id;
const parameters = functionCall.args;
console.log(
`Calling function ${functionName} with parameters: ${JSON.stringify(
parameters
)}`
);
let result;
try {
result = state.client.callFunction(functionName, parameters);
functionResponses.push({
id: functionCallId,
name: functionName,
response: { result: result ?? "ok" },
});
} catch (err) {
console.error(`Error calling function ${functionName}:`, err);
functionResponses.push({
id: functionCallId,
name: functionName,
response: { error: err.message },
});
}
}
// Send all function responses back to the API
state.client.sendToolResponse(functionResponses);

// Fan out all function calls concurrently (non-blocking — async tools
// like get_order run in parallel and don't stall each other or the UI)
Promise.all(
functionCalls.map(async (functionCall) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Add a defensive check to ensure functionCalls is a valid array before calling .map(). If the server sends a malformed TOOL_CALL message or message.data is empty, this prevents a potential runtime crash.

Suggested change
const functionCalls = message.data.functionCalls;
const functionResponses = [];
for (let index = 0; index < functionCalls.length; index++) {
const functionCall = functionCalls[index];
const functionName = functionCall.name;
const functionCallId = functionCall.id;
const parameters = functionCall.args;
console.log(
`Calling function ${functionName} with parameters: ${JSON.stringify(
parameters
)}`
);
let result;
try {
result = state.client.callFunction(functionName, parameters);
functionResponses.push({
id: functionCallId,
name: functionName,
response: { result: result ?? "ok" },
});
} catch (err) {
console.error(`Error calling function ${functionName}:`, err);
functionResponses.push({
id: functionCallId,
name: functionName,
response: { error: err.message },
});
}
}
// Send all function responses back to the API
state.client.sendToolResponse(functionResponses);
// Fan out all function calls concurrently (non-blocking — async tools
// like get_order run in parallel and don't stall each other or the UI)
Promise.all(
functionCalls.map(async (functionCall) => {
const functionCalls = message.data?.functionCalls;
if (!functionCalls || !Array.isArray(functionCalls)) {
console.warn("No function calls found in TOOL_CALL message");
break;
}
// Fan out all function calls concurrently (non-blocking — async tools
// like get_order run in parallel and don't stall each other or the UI)
Promise.all(
functionCalls.map(async (functionCall) => {

@thorwebdev
thorwebdev merged commit 3bcae11 into main Sep 15, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants