| 459 | } |
| 460 | |
| 461 | export function createUserMessage({ |
| 462 | content, |
| 463 | isMeta, |
| 464 | isVisibleInTranscriptOnly, |
| 465 | isVirtual, |
| 466 | isCompactSummary, |
| 467 | summarizeMetadata, |
| 468 | toolUseResult, |
| 469 | mcpMeta, |
| 470 | uuid, |
| 471 | timestamp, |
| 472 | imagePasteIds, |
| 473 | sourceToolAssistantUUID, |
| 474 | permissionMode, |
| 475 | origin, |
| 476 | }: { |
| 477 | content: string | ContentBlockParam[] |
| 478 | isMeta?: true |
| 479 | isVisibleInTranscriptOnly?: true |
| 480 | isVirtual?: true |
| 481 | isCompactSummary?: true |
| 482 | toolUseResult?: unknown // Matches tool's `Output` type |
| 483 | /** MCP protocol metadata to pass through to SDK consumers (never sent to model) */ |
| 484 | mcpMeta?: { |
| 485 | _meta?: Record<string, unknown> |
| 486 | structuredContent?: Record<string, unknown> |
| 487 | } |
| 488 | uuid?: UUID | string |
| 489 | timestamp?: string |
| 490 | imagePasteIds?: number[] |
| 491 | // For tool_result messages: the UUID of the assistant message containing the matching tool_use |
| 492 | sourceToolAssistantUUID?: UUID |
| 493 | // Permission mode when message was sent (for rewind restoration) |
| 494 | permissionMode?: PermissionMode |
| 495 | summarizeMetadata?: { |
| 496 | messagesSummarized: number |
| 497 | userContext?: string |
| 498 | direction?: PartialCompactDirection |
| 499 | } |
| 500 | // Provenance of this message. undefined = human (keyboard). |
| 501 | origin?: MessageOrigin |
| 502 | }): UserMessage { |
| 503 | const m: UserMessage = { |
| 504 | type: 'user', |
| 505 | message: { |
| 506 | role: 'user', |
| 507 | content: content || NO_CONTENT_MESSAGE, // Make sure we don't send empty messages |
| 508 | }, |
| 509 | isMeta, |
| 510 | isVisibleInTranscriptOnly, |
| 511 | isVirtual, |
| 512 | isCompactSummary, |
| 513 | summarizeMetadata, |
| 514 | uuid: (uuid as UUID | undefined) || randomUUID(), |
| 515 | timestamp: timestamp ?? new Date().toISOString(), |
| 516 | toolUseResult, |
| 517 | mcpMeta, |
| 518 | imagePasteIds, |