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

Function extractTextFromMessageItem

apps/sim/providers/openai/utils.ts:159–193  ·  view source on GitHub ↗
(item: unknown)

Source from the content-addressed store, hash-verified

157}
158
159function extractTextFromMessageItem(item: unknown): string {
160 if (!isRecord(item)) {
161 return ''
162 }
163
164 if (typeof item.content === 'string') {
165 return item.content
166 }
167
168 if (!Array.isArray(item.content)) {
169 return ''
170 }
171
172 const textParts: string[] = []
173 for (const part of item.content) {
174 if (!isRecord(part)) {
175 continue
176 }
177
178 if ((part.type === 'output_text' || part.type === 'text') && typeof part.text === 'string') {
179 textParts.push(part.text)
180 continue
181 }
182
183 if (part.type === 'output_json') {
184 if (typeof part.text === 'string') {
185 textParts.push(part.text)
186 } else if (part.json !== undefined) {
187 textParts.push(JSON.stringify(part.json))
188 }
189 }
190 }
191
192 return textParts.join('')
193}
194
195/**
196 * Extracts plain text from Responses API output items.

Callers 2

extractResponseTextFunction · 0.85

Calls 3

joinMethod · 0.80
isRecordFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected