trajectoryRequestBlocks function

List<TrajectoryRequestMessageBlock> trajectoryRequestBlocks(
  1. List<ContentBlock> content
)

Implementation

List<TrajectoryRequestMessageBlock> trajectoryRequestBlocks(
  List<ContentBlock> content,
) => [
  for (final block in content)
    switch (block) {
      TextContent(:final text) => _boundedBlock('text', text),
      ThinkingContent(:final thinking) => _boundedBlock('thinking', thinking),
      ToolCall() => () {
        // Unserializable arguments (cyclic handles, raw objects) degrade to
        // the placeholder instead of crashing the capture (issue #385 E3).
        final args = block.partialArguments ?? _safeJsonEncode(block.arguments);
        final (bounded, truncated) = _bound(args);
        return TrajectoryRequestMessageBlock(
          type: 'toolCall',
          chars: _safeJsonEncode(block.arguments).length,
          text: bounded,
          truncated: truncated,
          callId: block.id,
          toolName: block.name,
        );
      }(),
      ImageContent(:final data, :final mimeType) =>
        TrajectoryRequestMessageBlock(
          type: 'image',
          chars: data.length,
          text: '',
          imageMarker: '[image ${_imageDimensions(data, mimeType)}]',
        ),
    },
];