Skip to content

Commit c030d42

Browse files
committed
fix(ui-tars): actionInputs be null when coordinates has value 0 (close: #403)
1 parent 390345f commit c030d42

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

packages/ui-tars/action-parser/src/actionParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ export function parseActionVlm(
153153
const [widthFactor, heightFactor] = factors;
154154

155155
actionInputs[boxKey] =
156-
x1 && y1 && x2 && y2
156+
x1 !== undefined &&
157+
y1 !== undefined &&
158+
x2 !== undefined &&
159+
y2 !== undefined
157160
? [
158161
(Math.round(
159162
((x1 + x2) / 2) * screenContext?.width * widthFactor,

packages/ui-tars/action-parser/test/actionParser.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,5 +493,45 @@ Action: click(start_box='[287, 111, 313, 124]')`;
493493
},
494494
]);
495495
});
496+
497+
it('should handle zero coordinates correctly', () => {
498+
const input = `Thought: I need to click on the start button
499+
Action: click(start_box='[0, 964, 10, 984]')`;
500+
501+
const result = parseActionVlm(input, [1000, 1000]);
502+
503+
expect(result).toEqual([
504+
{
505+
reflection: null,
506+
thought: 'I need to click on the start button',
507+
action_type: 'click',
508+
action_inputs: {
509+
start_box: '[0,0.964,0.01,0.984]',
510+
},
511+
},
512+
]);
513+
});
514+
515+
it('should handle zero coordinates correctly, v2', () => {
516+
const input = `Thought: I need to click on the start button
517+
Action: click(start_box='[0, 964, 10, 984]')`;
518+
519+
const result = parseActionVlm(input, [1000, 1000], 'bc', {
520+
width: 2560,
521+
height: 1440,
522+
});
523+
524+
expect(result).toEqual([
525+
{
526+
reflection: null,
527+
thought: 'I need to click on the start button',
528+
action_type: 'click',
529+
action_inputs: {
530+
start_box: '[0,0.964,0.01,0.984]',
531+
start_coords: [12.8, 1402.56],
532+
},
533+
},
534+
]);
535+
});
496536
});
497537
});

0 commit comments

Comments
 (0)