(event: InboundTextEvent, inputText: string)
| 849 | } |
| 850 | |
| 851 | function buildCodexTurnInput(event: InboundTextEvent, inputText: string): CodexTurnInput[] { |
| 852 | const attachments = Array.isArray(event.attachments) ? event.attachments : []; |
| 853 | const normalizedInputText = String(inputText ?? '').trim(); |
| 854 | if (attachments.length === 0) { |
| 855 | return [{ |
| 856 | type: 'text', |
| 857 | text: normalizedInputText, |
| 858 | text_elements: [], |
| 859 | }]; |
| 860 | } |
| 861 | |
| 862 | const textPrompt = shouldReuseAttachmentPrompt(normalizedInputText) |
| 863 | ? normalizedInputText |
| 864 | : buildAttachmentPrompt(normalizedInputText, attachments); |
| 865 | const input: CodexTurnInput[] = [{ |
| 866 | type: 'text', |
| 867 | text: textPrompt, |
| 868 | text_elements: [], |
| 869 | }]; |
| 870 | for (const attachment of attachments) { |
| 871 | if (attachment.kind !== 'image') { |
| 872 | continue; |
| 873 | } |
| 874 | input.push({ |
| 875 | type: 'localImage', |
| 876 | path: attachment.localPath, |
| 877 | }); |
| 878 | } |
| 879 | return input; |
| 880 | } |
| 881 | |
| 882 | function shouldReuseAttachmentPrompt(inputText: string): boolean { |
| 883 | return /we(chat|ixin) attachments:/iu.test(inputText); |
no test coverage detected