This commit is contained in:
+59
-32
@@ -11,18 +11,51 @@ class ToolSpec:
|
||||
parameters: dict[str, Any]
|
||||
|
||||
|
||||
ACTION_METADATA_PROPERTIES: dict[str, dict[str, Any]] = {
|
||||
"purpose": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 240,
|
||||
"description": "Concise intent for this action, used by later reuse.",
|
||||
},
|
||||
"expected_outcome": {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"maxLength": 240,
|
||||
"description": "Observable screen state expected after this action.",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def _action_parameters(
|
||||
*,
|
||||
required: list[str],
|
||||
properties: dict[str, dict[str, Any]],
|
||||
) -> dict[str, Any]:
|
||||
return {
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"required": [*required, "purpose", "expected_outcome"],
|
||||
"properties": {**properties, **ACTION_METADATA_PROPERTIES},
|
||||
}
|
||||
|
||||
|
||||
TAP_SPEC = ToolSpec(
|
||||
name="tap",
|
||||
description="Tap a point on the screen, given in Scene pixel coordinates.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"required": ["x", "y"],
|
||||
"properties": {
|
||||
"x": {"type": "number", "description": "X coordinate in Scene pixel space."},
|
||||
"y": {"type": "number", "description": "Y coordinate in Scene pixel space."},
|
||||
parameters=_action_parameters(
|
||||
required=["x", "y"],
|
||||
properties={
|
||||
"x": {
|
||||
"type": "number",
|
||||
"description": "X coordinate in Scene pixel space.",
|
||||
},
|
||||
"y": {
|
||||
"type": "number",
|
||||
"description": "Y coordinate in Scene pixel space.",
|
||||
},
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
SWIPE_SPEC = ToolSpec(
|
||||
@@ -31,11 +64,9 @@ SWIPE_SPEC = ToolSpec(
|
||||
"Swipe from a start point to an end point on the screen, given in "
|
||||
"Scene pixel coordinates."
|
||||
),
|
||||
parameters={
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"required": ["start_x", "start_y", "end_x", "end_y"],
|
||||
"properties": {
|
||||
parameters=_action_parameters(
|
||||
required=["start_x", "start_y", "end_x", "end_y"],
|
||||
properties={
|
||||
"start_x": {"type": "number", "description": "Start X coordinate."},
|
||||
"start_y": {"type": "number", "description": "Start Y coordinate."},
|
||||
"end_x": {"type": "number", "description": "End X coordinate."},
|
||||
@@ -46,52 +77,46 @@ SWIPE_SPEC = ToolSpec(
|
||||
"default": 500,
|
||||
},
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
INPUT_TEXT_SPEC = ToolSpec(
|
||||
name="input_text",
|
||||
description="Type text into the currently focused input field.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"required": ["text"],
|
||||
"properties": {
|
||||
parameters=_action_parameters(
|
||||
required=["text"],
|
||||
properties={
|
||||
"text": {"type": "string", "description": "Text to type."},
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
LAUNCH_APP_SPEC = ToolSpec(
|
||||
name="launch_app",
|
||||
description="Launch (foreground) an app by its bundle/package identifier.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"required": ["app_id"],
|
||||
"properties": {
|
||||
parameters=_action_parameters(
|
||||
required=["app_id"],
|
||||
properties={
|
||||
"app_id": {
|
||||
"type": "string",
|
||||
"description": "App bundle/package identifier.",
|
||||
},
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
TERMINATE_APP_SPEC = ToolSpec(
|
||||
name="terminate_app",
|
||||
description="Terminate a running app by its bundle/package identifier.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"required": ["app_id"],
|
||||
"properties": {
|
||||
parameters=_action_parameters(
|
||||
required=["app_id"],
|
||||
properties={
|
||||
"app_id": {
|
||||
"type": "string",
|
||||
"description": "App bundle/package identifier.",
|
||||
},
|
||||
},
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
FINISH_TASK_SPEC = ToolSpec(
|
||||
@@ -126,4 +151,6 @@ ACTION_TOOL_SPECS: list[ToolSpec] = [
|
||||
TERMINATE_APP_SPEC,
|
||||
]
|
||||
|
||||
ACTION_TOOL_NAMES = frozenset(spec.name for spec in ACTION_TOOL_SPECS)
|
||||
|
||||
ALL_TOOL_SPECS: list[ToolSpec] = [*ACTION_TOOL_SPECS, FINISH_TASK_SPEC]
|
||||
|
||||
Reference in New Issue
Block a user