Files
hermes-agent/apps/desktop/src/lib/preview-annotate/flush.ts
T
Adolanium 10f2a20966 feat(desktop): add comment mode to the in-app browser
Click or drag on the preview page to pin a numbered comment. Saving a pin only adds it to the stack. Add comments drops the crops and a short prompt into the composer and never sends the turn.

Capture takes the visible page then crops in bitmap space, because Electron's rect crop on guest webviews is empty on Windows and shifted on high-DPI.
2026-09-01 00:30:56 -07:00

42 lines
1.1 KiB
TypeScript

import { annotateFlushPrompt, dataUrlToFile, packageAnnotateStack } from './pack'
import type { AnnotatePin } from './stack'
export interface AnnotateFlushPorts {
attachImage: (blob: Blob) => void | Promise<void>
insertText: (text: string) => void
send?: () => void
}
export interface AnnotateFlushResult {
count: number
prompt: string
sent: false
}
/**
* Attach every pin to the composer as a numbered crop plus the packed prompt.
* Saving / flushing never submits a turn — `send` is accepted so tests can
* prove it stays untouched.
*/
export async function flushAnnotateStack(
pins: readonly AnnotatePin[],
ports: AnnotateFlushPorts,
pageUrl?: string
): Promise<AnnotateFlushResult> {
const items = packageAnnotateStack(pins)
for (const item of items) {
if (item.imageDataUrl) {
await ports.attachImage(dataUrlToFile(item.imageDataUrl, `Comment_${item.number}.png`))
}
}
const prompt = annotateFlushPrompt(items, pageUrl)
if (prompt.trim()) {
ports.insertText(prompt)
}
return { count: items.length, prompt, sent: false }
}