MCPcopy Index your code
hub / github.com/anomalyco/opencode / toModelOutput

Function toModelOutput

packages/opencode/src/session/message-v2.ts:161–193  ·  view source on GitHub ↗
(options: { toolCallId: string; input: unknown; output: unknown })

Source from the content-addressed store, hash-verified

159 }
160
161 const toModelOutput = (options: { toolCallId: string; input: unknown; output: unknown }) => {
162 const output = options.output
163 if (typeof output === "string") {
164 return { type: "text", value: output }
165 }
166
167 if (typeof output === "object") {
168 const outputObject = output as {
169 text: string
170 attachments?: Array<{ mime: string; url: string }>
171 }
172 const attachments = (outputObject.attachments ?? []).filter((attachment) => {
173 return attachment.url.startsWith("data:") && attachment.url.includes(",")
174 })
175
176 return {
177 type: "content",
178 value: [
179 ...(outputObject.text ? [{ type: "text", text: outputObject.text }] : []),
180 ...attachments.map((attachment) => ({
181 type: "media",
182 mediaType: attachment.mime,
183 data: iife(() => {
184 const commaIndex = attachment.url.indexOf(",")
185 return commaIndex === -1 ? attachment.url : attachment.url.slice(commaIndex + 1)
186 }),
187 })),
188 ],
189 }
190 }
191
192 return { type: "json", value: output as never }
193 }
194
195 for (const msg of input) {
196 if (msg.parts.length === 0) continue

Callers

nothing calls this directly

Calls 1

iifeFunction · 0.90

Tested by

no test coverage detected