Saltar al contenido principal

File attachments

Indica los ficheros o directorios como array, tal como se muestra a continuación.
use Revolution\Copilot\Facades\Copilot;

$attachments = [
    [
        'type' => 'file',
        'path' => '/path/to/file.php',
        'displayName' => 'My File',// opcional
    ],
    [
        'type' => 'directory',
        'path' => '/path/to/dir/',
        'displayName' => 'dir',// opcional
    ],
    [
        'type' => 'selection',
        'filePath' => '/path/to/file.php',
        'displayName' => 'My File',// aquí no se puede omitir
        'selection' => [
            'start' => ['line' => 1, 'character' => 10],
            'end' => ['line' => 5, 'character' => 10],
        ],
        'text' => '...',
    ],
    [
        'type' => 'blob',
        'data' => base64_encode(file_get_contents('/path/to/image.png')),
        'mimeType' => 'image/png',
        'displayName' => 'screenshot.png',// opcional
    ],
];

$response = Copilot::run(prompt: '...', attachments: $attachments);
Como es difícil memorizar este formato, se ofrecen helpers para facilitar el uso.
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Support\Attachment;

$attachments = [
    Attachment::file(path: '/path/to/file.php', displayName: 'My File'),
    Attachment::directory(path: '/path/to/dir/', displayName: 'dir'),
    Attachment::selection(filePath: '/path/to/file.php', displayName: 'My File', selection: ['start' => ['line' => 1, 'character' => 10], 'end' => ['line' => 5, 'character' => 10]], text: '...'),
    Attachment::blob(data: base64_encode(file_get_contents('/path/to/image.png')), mimeType: 'image/png', displayName: 'screenshot.png'),
];

$response = Copilot::run(prompt: '...', attachments: $attachments);

Blob attachments

El tipo blob sirve para adjuntar datos codificados en Base64 en línea. Permite enviar directamente datos binarios como imágenes sin necesidad de I/O de disco.
use Revolution\Copilot\Support\Attachment;

// Adjunta una imagen codificada en Base64
$attachment = Attachment::blob(
    data: base64_encode(file_get_contents('/path/to/image.png')),
    mimeType: 'image/png',
    displayName: 'screenshot.png',
);
selection no está documentado todavía en el SDK oficial, por lo que los detalles se desconocen. github_reference tampoco tiene información oficial suficiente, por lo que se abordará más adelante.
Consulta la información más reciente en el repositorio de GitHub.
Última modificación el 13 de julio de 2026