Skip to content

feat(adapta-web): add tool-call translation via webTools prompt injection - #3255

Closed
oyi77 wants to merge 1 commit into
diegosouzapw:release/v3.8.11from
oyi77:feat/adapta-web-tool-calls
Closed

oyi77 wants to merge 1 commit into
diegosouzapw:release/v3.8.11from
oyi77:feat/adapta-web-tool-calls

Conversation

@oyi77

@oyi77 oyi77 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Description

Adapta web API has no native function calling support. This PR adds tool-call translation using the same pattern as deepseek-web (#2820), qwen-web (#3252), ddg-web (#3253), and blackbox-web (#3254).

How it works

  1. Request side: Serialize OpenAI tools[] into a system prompt instruction via serializeToolsToPrompt(). Injects into the buildAdaptaMessages system instruction chain.

  2. Response side: Parse <tool>{...}</tool> blocks from model text response via parseToolCallsFromText(). Returns proper OpenAI tool_calls format.

Files Changed

  • open-sse/executors/adapta-web.ts — +40 lines

Tests

All 5 existing tests pass.

…tion

Adapta web API has no native function calling. Serialize OpenAI tools[] into system prompt instructions (webTools.ts), parse <tool>{...}</tool> blocks from response text back into OpenAI tool_calls.

Pattern: same as deepseek-web (diegosouzapw#2820), qwen-web (diegosouzapw#3252), ddg-web (diegosouzapw#3253), blackbox-web (diegosouzapw#3254). Injects tool prompt into buildAdaptaMessages system instruction chain.
@oyi77
oyi77 requested a review from diegosouzapw as a code owner June 5, 2026 21:01

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

Copy link
Copy Markdown
Contributor

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 introduces tool-calling support for the Adapta executor in open-sse/executors/adapta-web.ts by serializing requested tools into a system prompt and parsing tool calls from the response text. The reviewer feedback highlights three key areas for improvement: first, streaming mode must be disabled when tools are requested to prevent raw tool blocks from breaking client functionality; second, the usage field should be added to the tool-call response to maintain consistency and avoid client parsing errors; and third, corresponding unit tests must be added to comply with the repository style guide's requirement for testing production code changes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

const messages = (Array.isArray(bodyObj.messages) ? bodyObj.messages : []) as OpenAIMessage[];

const requestedTools = bodyObj.tools;
const hasTools = Array.isArray(requestedTools) && requestedTools.length > 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

When hasTools is true, the executor should force non-streaming mode (i.e., stream = false) because transformStream does not support parsing tool calls from the stream. If streaming is kept active, the client will receive raw <tool>...</tool> text blocks instead of proper tool_calls structures, which will break tool-calling functionality.

To fix this, you can reassign stream = false when hasTools is true, or introduce an effectiveStream variable and use it in place of stream at line 454.

@@ -1,4 +1,5 @@
import { BaseExecutor, type ExecuteInput } from "./base.ts";
import { serializeToolsToPrompt, parseToolCallsFromText } from "../translator/webTools.ts";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

According to the Repository Style Guide (Rule 9), you must always include tests when changing production code under open-sse/. Please add or update the corresponding unit tests (e.g., in tests/) to cover the new tool-call translation logic for the Adapta executor.

References
  1. Always include tests when changing production code (src/, open-sse/, electron/, bin/). (link)

Comment on lines +505 to +512
response: new Response(
JSON.stringify({
id: `chatcmpl-adp-${Date.now()}`, object: "chat.completion",
created: Math.floor(Date.now() / 1000), model,
choices: [{ index: 0, message: { role: "assistant", content: null, tool_calls: toolCalls }, finish_reason: "tool_calls" }],
}),
{ status: 200, headers: { "Content-Type": "application/json" } }
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The returned chat completion response for tool calls is missing the usage field. Some clients/SDKs expect this field to be present and may fail to parse the response if it is missing. Please add the usage field to maintain consistency with the other completion responses in this executor.

          response: new Response(
            JSON.stringify({
              id: `chatcmpl-adp-${Date.now()}`,
              object: "chat.completion",
              created: Math.floor(Date.now() / 1000),
              model,
              choices: [
                {
                  index: 0,
                  message: { role: "assistant", content: null, tool_calls: toolCalls },
                  finish_reason: "tool_calls"
                }
              ],
              usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 }
            }),
            { status: 200, headers: { "Content-Type": "application/json" } }
          ),

@oyi77

oyi77 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #3259 (consolidated PR with shared helpers)

@oyi77 oyi77 closed this Jun 5, 2026
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.

1 participant