Skip to content
← Public packages

@kentcdodds/agent-files

Mint short-lived R2 PUT URLs for agent file handoffs; public download via managed r2.dev.

src/create-upload.ts

28 lines · 1.3 KB · TypeScript
import { createUpload } from './lib/files.ts'
import type { CreateUploadInput } from './lib/files.ts'

/**
 * Mint a short-lived signed R2 PUT URL for moving file bytes between an agent's
 * machine and Kody (either direction). Prefer this when a VM/process will PUT
 * with curl/fetch (not through MCP). After PUT, fetch `downloadUrl` inside
 * `execute` or another package (or hand it to a consumer).
 *
 * Handoffs are short-lived: upload URL TTL ~1h (default `expiresInSeconds`);
 * objects follow a ~7 day lifecycle. Not durable storage.
 *
 * @param input - `filename` required; optional `contentType`, `prefix` (default `handoff`), `expiresInSeconds` (default 3600), `browser`; requires `confirm: true` (or `dryRun: true` to preview)
 * @returns `{ key, upload: { method, url, headers }, downloadUrl, expiresAt }` (or dry-run preview)
 *
 * @example
 * import createUpload from 'kody:@kentcdodds/agent-files/create-upload'
 * const target = await createUpload({
 *   filename: 'report.png',
 *   contentType: 'image/png',
 *   confirm: true,
 * })
 * // On the VM: await fetch(target.upload.url, { method: 'PUT', headers: target.upload.headers, body })
 * // In Kody execute: await fetch(target.downloadUrl)  // or pass downloadUrl to r2-put-object
 */
export default async function createUploadExport(input: CreateUploadInput) {
	return createUpload(input)
}