MCPcopy Create free account
hub / github.com/TanStack/ai / parseImage

Method parseImage

packages/ai-fal/src/adapters/image.ts:165–191  ·  view source on GitHub ↗
(img: unknown)

Source from the content-addressed store, hash-verified

163 }
164
165 private parseImage(img: unknown): GeneratedImage {
166 let url: string
167 if (typeof img === 'string') {
168 url = img
169 } else if (
170 img &&
171 typeof img === 'object' &&
172 'url' in img &&
173 typeof img.url === 'string'
174 ) {
175 url = (img as { url: string }).url
176 } else {
177 throw new Error(
178 `Invalid image payload from fal response: expected string or { url: string }, received ${
179 img === null ? 'null' : typeof img
180 }`,
181 )
182 }
183
184 if (url.startsWith('data:')) {
185 const base64Match = url.match(/^data:image\/[^;]+;base64,(.+)$/)
186 if (base64Match && base64Match[1]) {
187 return { b64Json: base64Match[1] }
188 }
189 }
190 return { url }
191 }
192}
193
194export function createFalImage<TModel extends FalModel>(

Callers 1

transformResponseMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected