MCPcopy Create free account
hub / github.com/21st-dev/21st-sdk / buildPrompt

Function buildPrompt

packages/agent-runtime/src/runtime.ts:258–294  ·  view source on GitHub ↗
(
  message: string,
  images?: Array<{ base64: string; mediaType: string }>,
)

Source from the content-addressed store, hash-verified

256type ContentBlock = TextBlock | ImageBlock
257
258function buildPrompt(
259 message: string,
260 images?: Array<{ base64: string; mediaType: string }>,
261): string | AsyncIterable<SDKUserMessage> {
262 if (!images || images.length === 0) {
263 return message
264 }
265
266 const content: ContentBlock[] = []
267
268 for (const img of images) {
269 content.push({
270 type: "image",
271 source: {
272 type: "base64",
273 media_type: img.mediaType,
274 data: img.base64,
275 },
276 })
277 }
278
279 content.push({ type: "text", text: message })
280
281 async function* messageGenerator(): AsyncGenerator<SDKUserMessage> {
282 yield {
283 type: "user",
284 message: {
285 role: "user",
286 content,
287 },
288 parent_tool_use_id: null,
289 session_id: "",
290 } as SDKUserMessage
291 }
292
293 return messageGenerator()
294}
295
296// --- SDK options ---
297

Callers 1

executeAgentFunction · 0.85

Calls 1

messageGeneratorFunction · 0.85

Tested by

no test coverage detected