pi-ext
bugabingas pi extensions
owned by bugabinga
web: show local image preview in understand_image
a64748e64cb130075117e6bdd8bcaf9ae092edae
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (1)
extensions/web/index.ts
Modified 21 21 import { mkdtemp, rm, writeFile }
from "node:fs/promises";
22 22 import { tmpdir }
from "node:os";
23 23 import { join }
from "node:path";
24 -import type { ExtensionAPI }
from "@earendil-works/pi-coding-agent";
25 -import { getMarkdownTheme, keyHint }
from "@earendil-works/pi-coding-agent";
27 +}
from "@earendil-works/pi-coding-agent";
29 + createReadToolDefinition,
32 +}
from "@earendil-works/pi-coding-agent";
26 33 import { Box, Markdown, Text }
from "@earendil-works/pi-tui";
27 34 import { Type }
from "typebox";
56 63 return n
>= 10_000 ? `${(n / 1_000).toFixed(1)}K chars` : `${n} chars`;
66 +async function readLocalImagePreview(
67 + imageSource
: string,
68 + signal
: AbortSignal | undefined,
69 + ctx
: ExtensionContext,
72 + imageSource.
startsWith(
"http://")
|| 73 + imageSource.
startsWith(
"https://")
|| 74 + imageSource.
startsWith(
"data:")
79 + const path
= imageSource.
startsWith(
"@")
? imageSource.
slice(
1)
: imageSource;
81 + const readTool
= createReadToolDefinition(ctx.cwd);
82 + const result
= await readTool.
execute(
83 + "understand_image_preview",
89 + return result.
content.
filter((block)
=> block.
type === "image");
61 97 const tempDirs
= new Set<
string>();
1355 + const imagePreview
= await readLocalImagePreview(
1319 - content: [{ type:
"text", text: content }],
1362 + content: [{ type:
"text", text: content },
...imagePreview],
1320 1363 details: { prompt, image_source },
1322 1365 }
catch (error) {