(contentBlocks: ContentBlock[])
| 228 | * 根据 claude-cli-agent-protocol 文档,格式应该是: |
| 229 | * {"type":"user","message":{"role":"user","content":[...]}} |
| 230 | */ |
| 231 | export function buildUserMessageNDJSON(contentBlocks: ContentBlock[]): string { |
| 232 | const message = { |
| 233 | type: 'user', |
| 234 | message: { |
| 235 | role: 'user', |
| 236 | content: contentBlocks, |
| 237 | }, |
| 238 | }; |
| 239 | |
| 240 | const ndjson = JSON.stringify(message) + '\n'; |
| 241 | |
| 242 | // 打印最终消息结构(用于调试) |
| 243 | console.log('[image-utils] buildUserMessageNDJSON:'); |
| 244 | console.log(' message type:', message.type); |
| 245 | console.log(' message.message.role:', message.message.role); |
| 246 | console.log(' message.message.content blocks:', message.message.content.length); |
| 247 | |
| 248 | console.log(' content summary:', message.message.content.map(block => ( |
| 249 | block.type === 'image' |
| 250 | ? { type: 'image', mediaType: block.source.media_type, dataLength: block.source.data.length } |
| 251 | : { type: 'text', length: block.text.length } |
| 252 | ))); |
| 253 | console.log(' NDJSON length:', ndjson.length); |
| 254 | |
| 255 | // 返回 NDJSON 格式(单行 JSON + 换行符) |
| 256 | return ndjson; |
| 257 | } |
no outgoing calls
no test coverage detected