MCPcopy Index your code
hub / github.com/simstudioai/sim / collapseMessagesToInput

Function collapseMessagesToInput

apps/sim/providers/gemini/core.ts:437–465  ·  view source on GitHub ↗

* Collapses a ProviderRequest into a single input string and optional system instruction * for the Interactions API, which takes a flat input rather than a messages array. * * Deep research is single-turn only — it takes one research query and returns a report. * Memory/conversation history is h

(request: ProviderRequest)

Source from the content-addressed store, hash-verified

435 * the last user message is used as input. System messages are passed via system_instruction.
436 */
437function collapseMessagesToInput(request: ProviderRequest): {
438 input: string
439 systemInstruction: string | undefined
440} {
441 const systemParts: string[] = []
442 const userParts: string[] = []
443
444 if (request.systemPrompt) {
445 systemParts.push(request.systemPrompt)
446 }
447
448 if (request.messages) {
449 for (const msg of request.messages) {
450 if (msg.role === 'system' && msg.content) {
451 systemParts.push(msg.content)
452 } else if (msg.role === 'user' && msg.content) {
453 userParts.push(msg.content)
454 }
455 }
456 }
457
458 return {
459 input:
460 userParts.length > 0
461 ? userParts[userParts.length - 1]
462 : 'Please conduct research on the provided topic.',
463 systemInstruction: systemParts.length > 0 ? systemParts.join('\n\n') : undefined,
464 }
465}
466
467/**
468 * Extracts text content from a completed interaction's outputs array.

Callers 1

Calls 2

joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected