| 497 | .bind(status, new Date().toISOString(), JSON.stringify(result).slice(0, 200_000), changes.snapshotKey ?? null, changes.forkedFrom ?? null, id) |
| 498 | .run(); |
| 499 | } |
| 500 | |
| 501 | async function storeSnapshot(bucket: R2Bucket | undefined, runId: string, bytes: string): Promise<string> { |
| 502 | if (!bucket) throw new Error("ARTIFACTS binding is required for live run snapshots"); |
| 503 | const key = `snapshots/${runId}/${crypto.randomUUID()}.tar.gz`; |
| 504 | await bucket.put(key, Uint8Array.from(atob(bytes), (character) => character.charCodeAt(0)), { |
| 505 | httpMetadata: { contentType: "application/gzip" }, |
| 506 | customMetadata: { runId, createdAt: new Date().toISOString() }, |
| 507 | }); |
| 508 | return key; |
| 509 | } |
| 510 | |