({
input,
pastedContents,
}: BuildRemoteSubmitPayloadOptions)
| 28 | } |
| 29 | |
| 30 | export function buildRemoteSubmitPayload({ |
| 31 | input, |
| 32 | pastedContents, |
| 33 | }: BuildRemoteSubmitPayloadOptions): BuildRemoteSubmitPayloadResult { |
| 34 | const trimmedInput = input.trim() |
| 35 | const pastedValues = Object.values(pastedContents) |
| 36 | const imagePasteIds = pastedValues |
| 37 | .filter( |
| 38 | (pasted): pasted is PastedContent & { type: 'image' } => |
| 39 | pasted.type === 'image', |
| 40 | ) |
| 41 | .map(pasted => pasted.id) |
| 42 | |
| 43 | if (pastedValues.length === 0) { |
| 44 | return { |
| 45 | messageContent: trimmedInput, |
| 46 | remoteContent: trimmedInput, |
| 47 | imagePasteIds: imagePasteIds.length > 0 ? imagePasteIds : undefined, |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | const contentBlocks: ContentBlockParam[] = [] |
| 52 | const remoteBlocks: Array<{ |
| 53 | type: string |
| 54 | [key: string]: unknown |
| 55 | }> = [] |
| 56 | |
| 57 | if (trimmedInput) { |
| 58 | const textBlock = { |
| 59 | type: 'text' as const, |
| 60 | text: trimmedInput, |
| 61 | } |
| 62 | contentBlocks.push(textBlock) |
| 63 | remoteBlocks.push(textBlock) |
| 64 | } |
| 65 | |
| 66 | for (const pasted of pastedValues) { |
| 67 | if (pasted.type === 'image') { |
| 68 | const source: ImageBlockParam['source'] = { |
| 69 | type: 'base64', |
| 70 | media_type: (pasted.mediaType ?? 'image/png') as |
| 71 | | 'image/jpeg' |
| 72 | | 'image/png' |
| 73 | | 'image/gif' |
| 74 | | 'image/webp', |
| 75 | data: pasted.content, |
| 76 | } |
| 77 | const imageBlock = { |
| 78 | type: 'image' as const, |
| 79 | source, |
| 80 | } |
| 81 | contentBlocks.push(imageBlock) |
| 82 | remoteBlocks.push(imageBlock) |
| 83 | continue |
| 84 | } |
| 85 | |
| 86 | const textBlock = { |
| 87 | type: 'text' as const, |
no outgoing calls
no test coverage detected