MCPcopy
hub / github.com/claude-code-best/claude-code / sideQueryViaGemini

Function sideQueryViaGemini

src/utils/sideQuery.ts:549–740  ·  view source on GitHub ↗

* Gemini side query. Converts Anthropic-format params to Gemini * generateContent format, sends a non-streaming request via fetch, * and wraps the response back into a BetaMessage shape.

(
  opts: SideQueryOptions,
)

Source from the content-addressed store, hash-verified

547 * and wraps the response back into a BetaMessage shape.
548 */
549async function sideQueryViaGemini(
550 opts: SideQueryOptions,
551): Promise<BetaMessage> {
552 const {
553 model,
554 system,
555 messages,
556 tools,
557 tool_choice,
558 max_tokens = 1024,
559 temperature,
560 signal,
561 } = opts
562
563 const normalizedModel = normalizeModelStringForAPI(model)
564 const geminiModel = resolveGeminiModel(normalizedModel)
565
566 // Build Gemini contents from Anthropic MessageParam[]
567 const contents: Array<{
568 role: 'user' | 'model'
569 parts: Array<{ text: string }>
570 }> = []
571 for (const m of messages) {
572 if (m.role !== 'user' && m.role !== 'assistant') continue
573 const text =
574 typeof m.content === 'string'
575 ? m.content
576 : Array.isArray(m.content)
577 ? m.content
578 .filter(
579 (b): b is { type: 'text'; text: string } => b.type === 'text',
580 )
581 .map(b => b.text)
582 .join('\n')
583 : ''
584 if (text) {
585 contents.push({
586 role: m.role === 'assistant' ? 'model' : 'user',
587 parts: [{ text }],
588 })
589 }
590 }
591
592 // Build system instruction
593 const systemText = extractSystemText(system)
594 const systemInstruction = systemText
595 ? { parts: [{ text: systemText }] }
596 : undefined
597
598 // Convert tools and tool_choice
599 const geminiTools =
600 tools && tools.length > 0
601 ? anthropicToolsToGemini(tools as BetaToolUnion[])
602 : undefined
603 const geminiToolConfig = tool_choice
604 ? anthropicToolChoiceToGemini(tool_choice)
605 : undefined
606

Callers 1

sideQueryFunction · 0.85

Calls 13

resolveGeminiModelFunction · 0.90
anthropicToolsToGeminiFunction · 0.90
extractSystemTextFunction · 0.85
fetchFunction · 0.85
logEventFunction · 0.85
nowMethod · 0.80
textMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected