feat(vom): two channels to deal with canvas

This commit is contained in:
Ljy-0827
2026-08-28 15:10:36 +08:00
parent 6072db8c11
commit f33e1a7876
6 changed files with 13 additions and 9 deletions
@@ -497,7 +497,8 @@ export function registerTools(deps: ToolDeps): () => void {
? "Capture an indented aria-tree snapshot of the session's active tab. Interactive elements " +
"carry @eN refs for browser_click / browser_fill. Prefer browser_observe for a richer semantic view."
: "Produce a semantic VOM observation of the session's active tab (roles, states, perception " +
"probes) with @eN refs. Visual surface refs are screenshot-only; DOM refs support interaction. " +
"probes) with @eN refs. Visual-only surfaces require image understanding and their refs are " +
"screenshot-only; keep using any DOM/AX semantics rendered alongside them. " +
"Read-only: never submits input.";
register(
defineTool({
@@ -761,8 +762,11 @@ export function registerTools(deps: ToolDeps): () => void {
name: "browser_screenshot",
description:
"Capture a PNG screenshot of the session's active tab, or crop to a snapshot ref element. " +
"This is the supported operation for visual surface refs emitted by browser_observe. Returns " +
"the image itself when the deployment supports image input, otherwise a file path.",
"This is the supported operation for visual surface refs emitted by browser_observe. Only use " +
"it to interpret a visual-only surface when you can inspect image output. If you lack multimodal " +
"or image-reading capability, tell the user to switch to a model with image understanding; do " +
"not guess content or coordinates. " +
"Returns the image itself when the deployment supports image input, otherwise a file path.",
parameters: {
session: SESSION_PARAM,
ref: {
+2 -2
View File
@@ -48,7 +48,7 @@ describe("renderVom single-layer page", () => {
const out = renderVom(input);
expect(out.text).toContain(
'@e1 surface "Data grid" [rendering=canvas; layers=2; visual-only; use: bsk screenshot --ref @e1]',
'@e1 surface "Data grid" [rendering=canvas; layers=2; visual-only; requires=image-understanding; use: bsk screenshot --ref @e1]',
);
expect(out.refs).toContainEqual(
expect.objectContaining({
@@ -77,7 +77,7 @@ describe("renderVom single-layer page", () => {
const out = renderVom(input);
expect(out.text).toContain(
'@e1 surface "canvas visual surface" [rendering=canvas; visual-only; use: bsk screenshot --ref @e1]',
'@e1 surface "canvas visual surface" [rendering=canvas; visual-only; requires=image-understanding; use: bsk screenshot --ref @e1]',
);
expect(out.refs).toContainEqual(
expect.objectContaining({
+1 -1
View File
@@ -763,7 +763,7 @@ function emitVisualEntries(parentId: number | null, depth: number, state: Render
const ref = `e${state.nextRef}`;
const label = cleaned(surface.label) ?? `${surface.renderingKind} visual surface`;
const layers = surface.memberCount > 1 ? `; layers=${surface.memberCount}` : "";
const line = `${" ".repeat(depth)}@${ref} surface ${JSON.stringify(label)} [rendering=${surface.renderingKind}${layers}; visual-only; use: bsk screenshot --ref @${ref}]`;
const line = `${" ".repeat(depth)}@${ref} surface ${JSON.stringify(label)} [rendering=${surface.renderingKind}${layers}; visual-only; requires=image-understanding; use: bsk screenshot --ref @${ref}]`;
const nextTokens = state.tokens + estimateTokens(line);
if (nextTokens > state.maxTokens) {
state.truncated = true;