Repository navigation
Commit c807a93
committed
feat(opencode): optimize media attachments on submit with plugin extensibility
Add a media optimization layer that runs at submit time, right before
sdk.client.session.prompt(), matching the message.parts.before pattern
proposed in anomalyco#24125.
Key design decisions:
- Optimization runs at submit(), not paste() -- plugins see the final
assembled parts array and can act on model context
- registerOptimizer() lets plugins (like SHIFT) override per-modality
optimization, replacing or augmenting built-in handlers
- getMetrics() exposes before/after byte counts, tool name, and duration
for measuring savings (payload size, token reduction)
- OptimizeConfig provides tuning knobs: maxDimension, quality,
minImageSize, maxKeyframes, audioSampleRate, disabled
Built-in optimizers:
- Image: resize + JPEG compress via sips (macOS) or ImageMagick
- Audio: transcode to mono 16kHz WAV via ffmpeg
- Video: extract keyframes + audio via ffmpeg/ffprobe
- PDF: pass-through placeholder
Also widens paste mime gate for audio/video file paths, adds
modality-aware labels, and extends sniffAttachmentMime for audio/video.
Closes anomalyco#241291 parent 63f3e84 commit c807a93
5 files changed
Lines changed: 930 additions & 15 deletions
File tree
- packages/opencode
- src
- cli/cmd/tui
- component/prompt
- util
- util
- test
- cli/cmd/tui
- util
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
1174 | 1175 | | |
1175 | 1176 | | |
1176 | 1177 | | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
1177 | 1191 | | |
1178 | 1192 | | |
1179 | 1193 | | |
| |||
1182 | 1196 | | |
1183 | 1197 | | |
1184 | 1198 | | |
1185 | | - | |
1186 | | - | |
1187 | | - | |
1188 | | - | |
1189 | | - | |
1190 | | - | |
1191 | | - | |
1192 | | - | |
1193 | | - | |
| 1199 | + | |
1194 | 1200 | | |
1195 | 1201 | | |
1196 | 1202 | | |
| |||
1281 | 1287 | | |
1282 | 1288 | | |
1283 | 1289 | | |
1284 | | - | |
| 1290 | + | |
1285 | 1291 | | |
1286 | 1292 | | |
1287 | 1293 | | |
| |||
1319 | 1325 | | |
1320 | 1326 | | |
1321 | 1327 | | |
1322 | | - | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
1323 | 1335 | | |
1324 | 1336 | | |
1325 | | - | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
1326 | 1340 | | |
1327 | 1341 | | |
1328 | | - | |
| 1342 | + | |
1329 | 1343 | | |
1330 | 1344 | | |
1331 | 1345 | | |
| |||
0 commit comments