nova-act 3.3.35.0__1-py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nova_act/__init__.py +122 -0
- nova_act/__version__.py +14 -0
- nova_act/asyncio/__init__.py +105 -0
- nova_act/asyncio/browser_auth/__init__.py +0 -0
- nova_act/asyncio/impl/__init__.py +0 -0
- nova_act/asyncio/impl/backends/__init__.py +0 -0
- nova_act/asyncio/impl/dispatcher.py +321 -0
- nova_act/asyncio/impl/program/__init__.py +0 -0
- nova_act/asyncio/impl/program/runner.py +157 -0
- nova_act/asyncio/nova_act.py +1081 -0
- nova_act/asyncio/tools/__init__.py +0 -0
- nova_act/asyncio/tools/actuator/__init__.py +0 -0
- nova_act/asyncio/tools/actuator/interface/__init__.py +0 -0
- nova_act/asyncio/tools/actuator/interface/actuator.py +94 -0
- nova_act/asyncio/tools/browser/__init__.py +0 -0
- nova_act/asyncio/tools/browser/default/__init__.py +0 -0
- nova_act/asyncio/tools/browser/default/default_nova_local_browser_actuator.py +257 -0
- nova_act/asyncio/tools/browser/default/playwright.py +444 -0
- nova_act/asyncio/tools/browser/default/playwright_instance_options.py +48 -0
- nova_act/asyncio/tools/browser/default/util/__init__.py +0 -0
- nova_act/asyncio/tools/browser/default/util/agent_click.py +187 -0
- nova_act/asyncio/tools/browser/default/util/agent_hover.py +31 -0
- nova_act/asyncio/tools/browser/default/util/agent_scroll.py +295 -0
- nova_act/asyncio/tools/browser/default/util/agent_type.py +238 -0
- nova_act/asyncio/tools/browser/default/util/dispatch_dom_events.py +47 -0
- nova_act/asyncio/tools/browser/default/util/element_helpers.py +389 -0
- nova_act/asyncio/tools/browser/default/util/file_upload_helpers.py +51 -0
- nova_act/asyncio/tools/browser/default/util/get_bbox_values.py +60 -0
- nova_act/asyncio/tools/browser/default/util/go_to_url.py +32 -0
- nova_act/asyncio/tools/browser/default/util/image_helpers.py +252 -0
- nova_act/asyncio/tools/browser/default/util/take_observation.py +69 -0
- nova_act/asyncio/tools/browser/default/util/wait.py +145 -0
- nova_act/asyncio/tools/browser/interface/__init__.py +0 -0
- nova_act/asyncio/tools/browser/interface/browser.py +277 -0
- nova_act/asyncio/tools/browser/interface/playwright_pages.py +29 -0
- nova_act/cli/__init__.py +0 -0
- nova_act/cli/__version__.py +14 -0
- nova_act/cli/cli.py +72 -0
- nova_act/cli/core/__init__.py +14 -0
- nova_act/cli/core/clients/__init__.py +14 -0
- nova_act/cli/core/clients/agentcore/__init__.py +14 -0
- nova_act/cli/core/clients/agentcore/client.py +249 -0
- nova_act/cli/core/clients/agentcore/constants.py +39 -0
- nova_act/cli/core/clients/agentcore/response_parser.py +120 -0
- nova_act/cli/core/clients/agentcore/types.py +147 -0
- nova_act/cli/core/clients/codebuild/__init__.py +14 -0
- nova_act/cli/core/clients/codebuild/client.py +192 -0
- nova_act/cli/core/clients/codebuild/constants.py +32 -0
- nova_act/cli/core/clients/ecr/__init__.py +14 -0
- nova_act/cli/core/clients/ecr/client.py +137 -0
- nova_act/cli/core/clients/ecr/constants.py +17 -0
- nova_act/cli/core/clients/iam/__init__.py +18 -0
- nova_act/cli/core/clients/iam/client.py +67 -0
- nova_act/cli/core/clients/iam/types.py +63 -0
- nova_act/cli/core/clients/nova_act/__init__.py +14 -0
- nova_act/cli/core/clients/nova_act/client.py +88 -0
- nova_act/cli/core/clients/nova_act/constants.py +16 -0
- nova_act/cli/core/clients/nova_act/types.py +75 -0
- nova_act/cli/core/clients/s3/__init__.py +14 -0
- nova_act/cli/core/clients/s3/client.py +94 -0
- nova_act/cli/core/config.py +58 -0
- nova_act/cli/core/constants.py +34 -0
- nova_act/cli/core/error_detection.py +256 -0
- nova_act/cli/core/exceptions.py +72 -0
- nova_act/cli/core/identity.py +63 -0
- nova_act/cli/core/logging.py +42 -0
- nova_act/cli/core/region.py +24 -0
- nova_act/cli/core/state_manager.py +173 -0
- nova_act/cli/core/styling.py +102 -0
- nova_act/cli/core/theme.py +166 -0
- nova_act/cli/core/types.py +97 -0
- nova_act/cli/core/user_config_manager.py +76 -0
- nova_act/cli/group.py +141 -0
- nova_act/cli/workflow/__init__.py +0 -0
- nova_act/cli/workflow/commands/__init__.py +0 -0
- nova_act/cli/workflow/commands/create.py +113 -0
- nova_act/cli/workflow/commands/delete.py +139 -0
- nova_act/cli/workflow/commands/deploy.py +190 -0
- nova_act/cli/workflow/commands/error_handlers.py +54 -0
- nova_act/cli/workflow/commands/list.py +201 -0
- nova_act/cli/workflow/commands/run.py +285 -0
- nova_act/cli/workflow/commands/show.py +85 -0
- nova_act/cli/workflow/commands/update.py +94 -0
- nova_act/cli/workflow/services/__init__.py +14 -0
- nova_act/cli/workflow/services/agentcore/__init__.py +14 -0
- nova_act/cli/workflow/services/agentcore/deployment_service.py +170 -0
- nova_act/cli/workflow/services/agentcore/iam_role.py +265 -0
- nova_act/cli/workflow/services/agentcore/image_builder.py +118 -0
- nova_act/cli/workflow/services/agentcore/source_validator.py +147 -0
- nova_act/cli/workflow/services/agentcore/templates/Dockerfile +43 -0
- nova_act/cli/workflow/services/agentcore/templates/agentcore_handler.py +64 -0
- nova_act/cli/workflow/services/agentcore/templates/requirements.txt +3 -0
- nova_act/cli/workflow/services/constants.py +19 -0
- nova_act/cli/workflow/utils/__init__.py +14 -0
- nova_act/cli/workflow/utils/arn.py +65 -0
- nova_act/cli/workflow/utils/bucket_manager.py +52 -0
- nova_act/cli/workflow/utils/build_strategy.py +67 -0
- nova_act/cli/workflow/utils/codebuild_builder.py +160 -0
- nova_act/cli/workflow/utils/console.py +40 -0
- nova_act/cli/workflow/utils/docker_builder.py +216 -0
- nova_act/cli/workflow/utils/log_tailer.py +124 -0
- nova_act/cli/workflow/utils/tags.py +31 -0
- nova_act/cli/workflow/workflow_deployer.py +173 -0
- nova_act/cli/workflow/workflow_manager.py +410 -0
- nova_act/impl/__init__.py +0 -0
- nova_act/impl/backends/__init__.py +14 -0
- nova_act/impl/backends/base.py +246 -0
- nova_act/impl/backends/burst/__init__.py +0 -0
- nova_act/impl/backends/burst/backend.py +244 -0
- nova_act/impl/backends/burst/client.py +65 -0
- nova_act/impl/backends/burst/types.py +320 -0
- nova_act/impl/backends/common.py +128 -0
- nova_act/impl/backends/factory.py +94 -0
- nova_act/impl/backends/starburst/__init__.py +0 -0
- nova_act/impl/backends/starburst/backend.py +85 -0
- nova_act/impl/backends/starburst/client.py +374 -0
- nova_act/impl/backends/sunburst/__init__.py +0 -0
- nova_act/impl/backends/sunburst/backend.py +53 -0
- nova_act/impl/backends/sunburst/client.py +375 -0
- nova_act/impl/common.py +126 -0
- nova_act/impl/controller.py +89 -0
- nova_act/impl/dispatcher.py +334 -0
- nova_act/impl/extension.py +26 -0
- nova_act/impl/inputs.py +322 -0
- nova_act/impl/interpreter.py +164 -0
- nova_act/impl/keyboard_event_watcher.py +94 -0
- nova_act/impl/program/__init__.py +0 -0
- nova_act/impl/program/base.py +79 -0
- nova_act/impl/program/runner.py +154 -0
- nova_act/impl/run_info_compiler.py +889 -0
- nova_act/impl/thinker.py +132 -0
- nova_act/impl/trajectory/__init__.py +0 -0
- nova_act/impl/trajectory/types.py +52 -0
- nova_act/nova_act.py +1079 -0
- nova_act/py.typed +0 -0
- nova_act/samples/__init__.py +0 -0
- nova_act/samples/async_planet_distances.py +51 -0
- nova_act/samples/booking_with_data_from_tool.py +55 -0
- nova_act/samples/print_number_of_emails.py +79 -0
- nova_act/samples/s3_writer_example.py +73 -0
- nova_act/samples/search_apartments_calculate_commute.py +167 -0
- nova_act/samples/setup_chrome_user_data_dir.py +39 -0
- nova_act/samples/use_bedrock_agentcore_browser.py +41 -0
- nova_act/tools/actuator/interface/actuator.py +94 -0
- nova_act/tools/browser/default/default_nova_local_browser_actuator.py +254 -0
- nova_act/tools/browser/default/dom_actuation/click_events.py +39 -0
- nova_act/tools/browser/default/dom_actuation/create_dom_events.py +69 -0
- nova_act/tools/browser/default/dom_actuation/dispatch_events_dict.py +21 -0
- nova_act/tools/browser/default/dom_actuation/scroll_events.py +34 -0
- nova_act/tools/browser/default/dom_actuation/type_events.py +34 -0
- nova_act/tools/browser/default/playwright.py +448 -0
- nova_act/tools/browser/default/playwright_instance_options.py +48 -0
- nova_act/tools/browser/default/util/agent_click.py +185 -0
- nova_act/tools/browser/default/util/agent_hover.py +31 -0
- nova_act/tools/browser/default/util/agent_scroll.py +293 -0
- nova_act/tools/browser/default/util/agent_type.py +236 -0
- nova_act/tools/browser/default/util/bbox_parser.py +57 -0
- nova_act/tools/browser/default/util/dispatch_dom_events.py +47 -0
- nova_act/tools/browser/default/util/element_helpers.py +389 -0
- nova_act/tools/browser/default/util/file_upload_helpers.py +51 -0
- nova_act/tools/browser/default/util/get_bbox_values.py +60 -0
- nova_act/tools/browser/default/util/get_simplified_dom.js +664 -0
- nova_act/tools/browser/default/util/go_to_url.py +32 -0
- nova_act/tools/browser/default/util/image_helpers.py +258 -0
- nova_act/tools/browser/default/util/take_observation.py +69 -0
- nova_act/tools/browser/default/util/wait.py +145 -0
- nova_act/tools/browser/interface/__init__.py +14 -0
- nova_act/tools/browser/interface/browser.py +277 -0
- nova_act/tools/browser/interface/playwright_pages.py +29 -0
- nova_act/tools/browser/interface/types/__init__.py +18 -0
- nova_act/tools/browser/interface/types/agent_redirect_error.py +20 -0
- nova_act/tools/browser/interface/types/click_options.py +25 -0
- nova_act/tools/browser/interface/types/click_types.py +21 -0
- nova_act/tools/browser/interface/types/dimensions_dict.py +19 -0
- nova_act/tools/browser/interface/types/element_dict.py +22 -0
- nova_act/tools/browser/interface/types/scroll_types.py +24 -0
- nova_act/tools/compatibility.py +121 -0
- nova_act/tools/human/__init__.py +0 -0
- nova_act/tools/human/default/__init__.py +0 -0
- nova_act/tools/human/interface/__init__.py +0 -0
- nova_act/tools/human/interface/human_input_callback.py +266 -0
- nova_act/types/__init__.py +14 -0
- nova_act/types/act_errors.py +275 -0
- nova_act/types/act_metadata.py +134 -0
- nova_act/types/act_result.py +90 -0
- nova_act/types/api/status.py +20 -0
- nova_act/types/api/step.py +201 -0
- nova_act/types/api/trace.py +92 -0
- nova_act/types/errors.py +137 -0
- nova_act/types/events.py +56 -0
- nova_act/types/features.py +80 -0
- nova_act/types/guardrail.py +33 -0
- nova_act/types/hooks.py +35 -0
- nova_act/types/state/__init__.py +14 -0
- nova_act/types/state/act.py +148 -0
- nova_act/types/state/page.py +22 -0
- nova_act/types/state/step.py +89 -0
- nova_act/types/workflow.py +396 -0
- nova_act/types/workflow_run.py +30 -0
- nova_act/util/argument_preparation.py +133 -0
- nova_act/util/common_js_expressions.py +31 -0
- nova_act/util/constants.py +21 -0
- nova_act/util/decode_string.py +88 -0
- nova_act/util/error_messages.py +102 -0
- nova_act/util/event_handler.py +69 -0
- nova_act/util/human_wait_time_tracker.py +68 -0
- nova_act/util/jsonschema.py +77 -0
- nova_act/util/logging.py +170 -0
- nova_act/util/os_path.py +29 -0
- nova_act/util/path_validator.py +229 -0
- nova_act/util/s3_writer.py +292 -0
- nova_act/util/s3_writer_errors.py +84 -0
- nova_act/util/step_server_time_tracker.py +74 -0
- nova_act/util/terminal_manager.py +103 -0
- nova_act/util/url.py +163 -0
- nova_act-3.3.35.0.dist-info/METADATA +1162 -0
- nova_act-3.3.35.0.dist-info/RECORD +222 -0
- nova_act-3.3.35.0.dist-info/WHEEL +5 -0
- nova_act-3.3.35.0.dist-info/entry_points.txt +2 -0
- nova_act-3.3.35.0.dist-info/licenses/LICENSE +73 -0
- nova_act-3.3.35.0.dist-info/licenses/NOTICE +2 -0
- nova_act-3.3.35.0.dist-info/top_level.txt +1 -0
nova_act/__init__.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Copyright 2025 Amazon Inc
|
|
2
|
+
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# flake8: noqa: F821, E402
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
import builtins
|
|
18
|
+
import pdb
|
|
19
|
+
import sys
|
|
20
|
+
|
|
21
|
+
from pydantic import JsonValue as JSONType
|
|
22
|
+
from strands import tool
|
|
23
|
+
|
|
24
|
+
from nova_act.impl.common import rsync_from_default_user_data
|
|
25
|
+
from nova_act.impl.extension import ExtensionActuator
|
|
26
|
+
from nova_act.nova_act import NovaAct
|
|
27
|
+
from nova_act.tools.browser.default.default_nova_local_browser_actuator import DefaultNovaLocalBrowserActuator
|
|
28
|
+
from nova_act.tools.browser.interface.browser import BrowserActuatorBase
|
|
29
|
+
from nova_act.tools.browser.interface.playwright_pages import PlaywrightPageManagerBase
|
|
30
|
+
from nova_act.tools.human.interface.human_input_callback import (
|
|
31
|
+
HumanInputCallbacksProvider,
|
|
32
|
+
)
|
|
33
|
+
from nova_act.types.act_errors import (
|
|
34
|
+
ActActuationError,
|
|
35
|
+
ActAgentError,
|
|
36
|
+
ActAgentFailed,
|
|
37
|
+
ActCanceledError,
|
|
38
|
+
ActClientError,
|
|
39
|
+
ActDispatchError,
|
|
40
|
+
ActError,
|
|
41
|
+
ActExceededMaxStepsError,
|
|
42
|
+
ActExecutionError,
|
|
43
|
+
ActGuardrailsError,
|
|
44
|
+
ActInternalServerError,
|
|
45
|
+
ActInvalidModelGenerationError,
|
|
46
|
+
ActInvalidToolError,
|
|
47
|
+
ActInvalidToolSchemaError,
|
|
48
|
+
ActModelError,
|
|
49
|
+
ActProtocolError,
|
|
50
|
+
ActRateLimitExceededError,
|
|
51
|
+
ActServerError,
|
|
52
|
+
ActStateGuardrailError,
|
|
53
|
+
ActTimeoutError,
|
|
54
|
+
)
|
|
55
|
+
from nova_act.types.act_metadata import ActMetadata
|
|
56
|
+
from nova_act.types.act_result import ActGetResult, ActResult
|
|
57
|
+
from nova_act.types.errors import NovaActError, StartFailed, StopFailed, ValidationFailed
|
|
58
|
+
from nova_act.types.features import SecurityOptions
|
|
59
|
+
from nova_act.types.guardrail import GuardrailDecision, GuardrailInputState
|
|
60
|
+
from nova_act.types.workflow import Workflow, get_current_workflow, workflow
|
|
61
|
+
from nova_act.util.jsonschema import BOOL_SCHEMA, STRING_SCHEMA
|
|
62
|
+
from nova_act.util.logging import setup_logging
|
|
63
|
+
|
|
64
|
+
__all__ = [
|
|
65
|
+
"NovaAct",
|
|
66
|
+
"ActAgentError",
|
|
67
|
+
"ActAgentFailed",
|
|
68
|
+
"ActExecutionError",
|
|
69
|
+
"ActActuationError",
|
|
70
|
+
"ActCanceledError",
|
|
71
|
+
"ActClientError",
|
|
72
|
+
"ActDispatchError",
|
|
73
|
+
"ActError",
|
|
74
|
+
"ActExceededMaxStepsError",
|
|
75
|
+
"ActGuardrailsError",
|
|
76
|
+
"ActInternalServerError",
|
|
77
|
+
"ActInvalidModelGenerationError",
|
|
78
|
+
"ActInvalidToolError",
|
|
79
|
+
"ActInvalidToolSchemaError",
|
|
80
|
+
"ActModelError",
|
|
81
|
+
"ActRateLimitExceededError",
|
|
82
|
+
"ActServerError",
|
|
83
|
+
"ActTimeoutError",
|
|
84
|
+
"ActMetadata",
|
|
85
|
+
"ActResult",
|
|
86
|
+
"ActGetResult",
|
|
87
|
+
"ActStateGuardrailError",
|
|
88
|
+
"NovaActError",
|
|
89
|
+
"SecurityOptions",
|
|
90
|
+
"StartFailed",
|
|
91
|
+
"StopFailed",
|
|
92
|
+
"ValidationFailed",
|
|
93
|
+
"BOOL_SCHEMA",
|
|
94
|
+
"STRING_SCHEMA",
|
|
95
|
+
"BrowserActuatorBase",
|
|
96
|
+
"ExtensionActuator",
|
|
97
|
+
"DefaultNovaLocalBrowserActuator",
|
|
98
|
+
"JSONType",
|
|
99
|
+
"rsync_from_default_user_data",
|
|
100
|
+
"GuardrailDecision",
|
|
101
|
+
"GuardrailInputState",
|
|
102
|
+
"HumanInputCallbacksProvider",
|
|
103
|
+
"tool",
|
|
104
|
+
"Workflow",
|
|
105
|
+
"get_current_workflow",
|
|
106
|
+
"workflow",
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
# Intercept `builtins.breakpoint` to disable KeyboardEventWatcher
|
|
111
|
+
from nova_act.impl.keyboard_event_watcher import DEBUGGER_ATTACHED_EVENT
|
|
112
|
+
|
|
113
|
+
_LOGGER = setup_logging(__name__)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def set_trace_and_signal_event(*args, **kwargs): # type: ignore[no-untyped-def]
|
|
117
|
+
_LOGGER.info("Intercepted breakpoint call. Signaling threads.")
|
|
118
|
+
DEBUGGER_ATTACHED_EVENT.set()
|
|
119
|
+
pdb.Pdb().set_trace(sys._getframe(1))
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
builtins.breakpoint = set_trace_and_signal_event
|
nova_act/__version__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright 2025 Amazon Inc
|
|
2
|
+
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
VERSION = "3.3.35.0" # pragma: no cover
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Copyright 2025 Amazon Inc
|
|
2
|
+
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
"""Async implementation of the Nova Act SDK.
|
|
15
|
+
|
|
16
|
+
Usage::
|
|
17
|
+
|
|
18
|
+
from nova_act.asyncio import NovaAct
|
|
19
|
+
|
|
20
|
+
async with NovaAct(starting_page="https://example.com") as nova:
|
|
21
|
+
result = await nova.act("click the first link")
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from pydantic import JsonValue as JSONType
|
|
25
|
+
from strands import tool
|
|
26
|
+
|
|
27
|
+
from nova_act.asyncio.nova_act import NovaAct
|
|
28
|
+
from nova_act.asyncio.tools.browser.default.default_nova_local_browser_actuator import DefaultNovaLocalBrowserActuator
|
|
29
|
+
from nova_act.asyncio.tools.browser.interface.browser import BrowserActuatorBase
|
|
30
|
+
from nova_act.asyncio.tools.browser.interface.playwright_pages import PlaywrightPageManagerBase
|
|
31
|
+
from nova_act.types.act_errors import (
|
|
32
|
+
ActActuationError,
|
|
33
|
+
ActAgentError,
|
|
34
|
+
ActAgentFailed,
|
|
35
|
+
ActCanceledError,
|
|
36
|
+
ActClientError,
|
|
37
|
+
ActDispatchError,
|
|
38
|
+
ActError,
|
|
39
|
+
ActExceededMaxStepsError,
|
|
40
|
+
ActExecutionError,
|
|
41
|
+
ActGuardrailsError,
|
|
42
|
+
ActInternalServerError,
|
|
43
|
+
ActInvalidModelGenerationError,
|
|
44
|
+
ActInvalidToolError,
|
|
45
|
+
ActInvalidToolSchemaError,
|
|
46
|
+
ActModelError,
|
|
47
|
+
ActRateLimitExceededError,
|
|
48
|
+
ActServerError,
|
|
49
|
+
ActStateGuardrailError,
|
|
50
|
+
ActTimeoutError,
|
|
51
|
+
)
|
|
52
|
+
from nova_act.types.act_metadata import ActMetadata
|
|
53
|
+
from nova_act.types.act_result import ActGetResult, ActResult
|
|
54
|
+
from nova_act.types.errors import NovaActError, StartFailed, StopFailed, ValidationFailed
|
|
55
|
+
from nova_act.types.features import SecurityOptions
|
|
56
|
+
from nova_act.types.guardrail import GuardrailDecision, GuardrailInputState
|
|
57
|
+
from nova_act.types.workflow import Workflow, get_current_workflow, workflow
|
|
58
|
+
from nova_act.util.jsonschema import BOOL_SCHEMA, STRING_SCHEMA
|
|
59
|
+
from nova_act.util.logging import make_trace_logger
|
|
60
|
+
|
|
61
|
+
_TRACE_LOGGER = make_trace_logger()
|
|
62
|
+
_TRACE_LOGGER.info("The async version of Nova Act is currently in preview.\n")
|
|
63
|
+
|
|
64
|
+
__all__ = [
|
|
65
|
+
"NovaAct",
|
|
66
|
+
"ActAgentError",
|
|
67
|
+
"ActAgentFailed",
|
|
68
|
+
"ActExecutionError",
|
|
69
|
+
"ActActuationError",
|
|
70
|
+
"ActCanceledError",
|
|
71
|
+
"ActClientError",
|
|
72
|
+
"ActDispatchError",
|
|
73
|
+
"ActError",
|
|
74
|
+
"ActExceededMaxStepsError",
|
|
75
|
+
"ActGuardrailsError",
|
|
76
|
+
"ActInternalServerError",
|
|
77
|
+
"ActInvalidModelGenerationError",
|
|
78
|
+
"ActInvalidToolError",
|
|
79
|
+
"ActInvalidToolSchemaError",
|
|
80
|
+
"ActModelError",
|
|
81
|
+
"ActRateLimitExceededError",
|
|
82
|
+
"ActServerError",
|
|
83
|
+
"ActTimeoutError",
|
|
84
|
+
"ActMetadata",
|
|
85
|
+
"ActResult",
|
|
86
|
+
"ActGetResult",
|
|
87
|
+
"ActStateGuardrailError",
|
|
88
|
+
"NovaActError",
|
|
89
|
+
"SecurityOptions",
|
|
90
|
+
"StartFailed",
|
|
91
|
+
"StopFailed",
|
|
92
|
+
"ValidationFailed",
|
|
93
|
+
"BOOL_SCHEMA",
|
|
94
|
+
"STRING_SCHEMA",
|
|
95
|
+
"BrowserActuatorBase",
|
|
96
|
+
"DefaultNovaLocalBrowserActuator",
|
|
97
|
+
"JSONType",
|
|
98
|
+
"GuardrailDecision",
|
|
99
|
+
"GuardrailInputState",
|
|
100
|
+
"tool",
|
|
101
|
+
"Workflow",
|
|
102
|
+
"get_current_workflow",
|
|
103
|
+
"workflow",
|
|
104
|
+
"PlaywrightPageManagerBase",
|
|
105
|
+
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# Copyright 2025 Amazon Inc
|
|
2
|
+
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import asyncio
|
|
17
|
+
import functools
|
|
18
|
+
import time
|
|
19
|
+
from typing import Callable, Coroutine
|
|
20
|
+
|
|
21
|
+
from nova_act.asyncio.impl.program.runner import ProgramRunner, format_return_value
|
|
22
|
+
from nova_act.asyncio.tools.actuator.interface.actuator import ActionType, ActuatorBase
|
|
23
|
+
from nova_act.impl.backends.factory import NovaActBackend
|
|
24
|
+
from nova_act.impl.controller import ControlState, NovaStateController
|
|
25
|
+
from nova_act.impl.inputs import validate_viewport_dimensions
|
|
26
|
+
from nova_act.impl.program.base import Call, Program
|
|
27
|
+
from nova_act.impl.thinker import Thinker
|
|
28
|
+
from nova_act.tools.browser.default.util.image_helpers import get_source_image_from_data_url
|
|
29
|
+
from nova_act.tools.browser.interface.types.agent_redirect_error import (
|
|
30
|
+
AgentRedirectError,
|
|
31
|
+
)
|
|
32
|
+
from nova_act.tools.human.interface.human_input_callback import HumanInputCallbacksBase
|
|
33
|
+
from nova_act.types.act_errors import (
|
|
34
|
+
ActAgentFailed,
|
|
35
|
+
ActCanceledError,
|
|
36
|
+
ActError,
|
|
37
|
+
ActExceededMaxStepsError,
|
|
38
|
+
ActExecutionError,
|
|
39
|
+
ActTimeoutError,
|
|
40
|
+
)
|
|
41
|
+
from nova_act.types.act_metadata import ActMetadata, build_trajectory_file_path
|
|
42
|
+
from nova_act.types.act_result import ActGetResult
|
|
43
|
+
from nova_act.types.errors import ClientNotStarted
|
|
44
|
+
from nova_act.types.events import EventType, LogType
|
|
45
|
+
from nova_act.types.guardrail import GuardrailCallable
|
|
46
|
+
from nova_act.types.state.act import Act
|
|
47
|
+
from nova_act.util.decode_string import decode_awl_raw_program
|
|
48
|
+
from nova_act.util.event_handler import EventHandler
|
|
49
|
+
from nova_act.util.human_wait_time_tracker import HumanWaitTimeTracker
|
|
50
|
+
from nova_act.util.logging import (
|
|
51
|
+
SessionState,
|
|
52
|
+
get_session_id_prefix,
|
|
53
|
+
get_session_logs_directory,
|
|
54
|
+
make_trace_logger,
|
|
55
|
+
set_logging_session_state,
|
|
56
|
+
setup_logging,
|
|
57
|
+
trace_log_lines,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
_LOGGER = setup_logging(__name__)
|
|
61
|
+
_TRACE_LOGGER = make_trace_logger()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _handle_act_fail(
|
|
65
|
+
f: "Callable[[ActDispatcher, Act], Coroutine[object, object, ActGetResult]]",
|
|
66
|
+
) -> "Callable[[ActDispatcher, Act], Coroutine[object, object, ActGetResult]]":
|
|
67
|
+
"""Update Act objects with appropriate metadata on Exceptions."""
|
|
68
|
+
|
|
69
|
+
@functools.wraps(f)
|
|
70
|
+
async def wrapper(self: ActDispatcher, act: Act) -> ActGetResult:
|
|
71
|
+
try:
|
|
72
|
+
return await f(self, act)
|
|
73
|
+
except ActError as e:
|
|
74
|
+
# If an ActError is encountered, inject it with metadata.
|
|
75
|
+
act.end_time = act.end_time or time.time()
|
|
76
|
+
|
|
77
|
+
# Calculate time worked even for failed acts
|
|
78
|
+
if act.start_time is not None and act.end_time is not None:
|
|
79
|
+
human_wait_time = self._wait_time_tracker.get_total_wait_time_s()
|
|
80
|
+
time_worked = _calculate_time_worked(act.start_time, act.end_time, human_wait_time)
|
|
81
|
+
|
|
82
|
+
# Build trajectory path directly to avoid depending on
|
|
83
|
+
# act.metadata (which recomputes from current session state
|
|
84
|
+
# and could return a stale or mismatched path).
|
|
85
|
+
session_logs_dir = get_session_logs_directory()
|
|
86
|
+
trajectory_path = (
|
|
87
|
+
build_trajectory_file_path(session_logs_dir, act.id, act.prompt) if session_logs_dir else None
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Create metadata with time worked for the error
|
|
91
|
+
e.metadata = ActMetadata(
|
|
92
|
+
session_id=act.session_id,
|
|
93
|
+
act_id=act.id,
|
|
94
|
+
num_steps_executed=len(act._steps),
|
|
95
|
+
start_time=act.start_time,
|
|
96
|
+
end_time=act.end_time,
|
|
97
|
+
step_server_times_s=act.get_step_server_times_s,
|
|
98
|
+
prompt=act.prompt,
|
|
99
|
+
time_worked_s=time_worked,
|
|
100
|
+
human_wait_time_s=human_wait_time,
|
|
101
|
+
trajectory_file_path=trajectory_path,
|
|
102
|
+
)
|
|
103
|
+
else:
|
|
104
|
+
e.metadata = e.metadata or act.metadata
|
|
105
|
+
|
|
106
|
+
raise e
|
|
107
|
+
finally:
|
|
108
|
+
# Make sure we always set end time.
|
|
109
|
+
act.end_time = act.end_time or time.time()
|
|
110
|
+
set_logging_session_state(SessionState.UNKNOWN)
|
|
111
|
+
|
|
112
|
+
return wrapper
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _calculate_time_worked(start_time: float | None, end_time: float | None, human_wait_time_s: float) -> float | None:
|
|
116
|
+
"""Calculate time worked with error handling."""
|
|
117
|
+
if start_time is None or end_time is None:
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
total_duration = end_time - start_time
|
|
121
|
+
|
|
122
|
+
if total_duration < 0:
|
|
123
|
+
_LOGGER.warning(
|
|
124
|
+
f"Negative duration detected: end_time ({end_time}) < start_time ({start_time}). "
|
|
125
|
+
"Setting time_worked_s to 0.0"
|
|
126
|
+
)
|
|
127
|
+
return 0.0
|
|
128
|
+
|
|
129
|
+
if human_wait_time_s > total_duration:
|
|
130
|
+
_LOGGER.warning(
|
|
131
|
+
f"Human wait time ({human_wait_time_s}s) exceeds total duration ({total_duration}s). "
|
|
132
|
+
"Setting time_worked_s to 0.0"
|
|
133
|
+
)
|
|
134
|
+
return 0.0
|
|
135
|
+
|
|
136
|
+
return max(0.0, total_duration - human_wait_time_s)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _log_time_worked(metadata: ActMetadata) -> None:
|
|
140
|
+
"""Log time worked to console with styling."""
|
|
141
|
+
if metadata.time_worked_s is None:
|
|
142
|
+
return
|
|
143
|
+
|
|
144
|
+
# Import _format_duration from act_metadata
|
|
145
|
+
from nova_act.types.act_metadata import _format_duration
|
|
146
|
+
|
|
147
|
+
time_worked_str = _format_duration(metadata.time_worked_s)
|
|
148
|
+
|
|
149
|
+
if metadata.human_wait_time_s > 0:
|
|
150
|
+
human_wait_str = _format_duration(metadata.human_wait_time_s)
|
|
151
|
+
message = f"⏱️ Approx. Time Worked: {time_worked_str} " f"(excluding {human_wait_str} human wait)"
|
|
152
|
+
else:
|
|
153
|
+
message = f"⏱️ Approx. Time Worked: {time_worked_str}"
|
|
154
|
+
|
|
155
|
+
# Use trace logger only (not standard logger to avoid duplication)
|
|
156
|
+
trace_log_lines(message)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class ActDispatcher:
|
|
160
|
+
def __init__(
|
|
161
|
+
self,
|
|
162
|
+
backend: NovaActBackend,
|
|
163
|
+
controller: NovaStateController,
|
|
164
|
+
event_handler: EventHandler,
|
|
165
|
+
human_input_callbacks: HumanInputCallbacksBase,
|
|
166
|
+
tools: list[ActionType] | None = None,
|
|
167
|
+
state_guardrail: GuardrailCallable | None = None,
|
|
168
|
+
actuator: ActuatorBase | None = None,
|
|
169
|
+
):
|
|
170
|
+
self._backend = backend
|
|
171
|
+
self._tools = (tools or []).copy()
|
|
172
|
+
self._human_input_callbacks = human_input_callbacks
|
|
173
|
+
self._tool_map = {tool.tool_name: tool for tool in self._tools}
|
|
174
|
+
self._actuator = actuator
|
|
175
|
+
|
|
176
|
+
self._canceled = False
|
|
177
|
+
self._event_handler = event_handler
|
|
178
|
+
self._controller = controller
|
|
179
|
+
self._program_runner = ProgramRunner(
|
|
180
|
+
self._event_handler,
|
|
181
|
+
state_guardrail,
|
|
182
|
+
actuator=actuator,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# Create wait time tracker and inject into human input callbacks provider
|
|
186
|
+
self._wait_time_tracker = HumanWaitTimeTracker()
|
|
187
|
+
# Inject the tracker into the provider
|
|
188
|
+
self._human_input_callbacks.provider.set_wait_time_tracker(self._wait_time_tracker)
|
|
189
|
+
|
|
190
|
+
def _cancel_act(self, act: Act) -> None:
|
|
191
|
+
_TRACE_LOGGER.info(f"\n{get_session_id_prefix()}Terminating agent workflow")
|
|
192
|
+
self._event_handler.send_event(
|
|
193
|
+
type=EventType.LOG,
|
|
194
|
+
log_level=LogType.INFO,
|
|
195
|
+
data="Terminating agent workflow",
|
|
196
|
+
)
|
|
197
|
+
raise ActCanceledError()
|
|
198
|
+
|
|
199
|
+
@_handle_act_fail
|
|
200
|
+
async def dispatch(self, act: Act) -> ActGetResult:
|
|
201
|
+
"""Dispatch an Act with given Backend and Actuator."""
|
|
202
|
+
|
|
203
|
+
# Reset wait time tracker for new act
|
|
204
|
+
self._wait_time_tracker.reset()
|
|
205
|
+
|
|
206
|
+
if self._backend is None:
|
|
207
|
+
raise ClientNotStarted("Run start() to start the client before accessing the Playwright Page.")
|
|
208
|
+
|
|
209
|
+
step_object = None
|
|
210
|
+
step_idx = 0
|
|
211
|
+
|
|
212
|
+
# Create and run initial Program
|
|
213
|
+
initial_calls: list[Call] = []
|
|
214
|
+
if act.observation_delay_ms:
|
|
215
|
+
initial_calls.append(Call(name="wait", id="wait", kwargs={"seconds": act.observation_delay_ms / 1000}))
|
|
216
|
+
initial_calls += [
|
|
217
|
+
Call(name="waitForPageToSettle", id="waitForPageToSettle", kwargs={}),
|
|
218
|
+
Call(name="takeObservation", id="takeObservation", kwargs={}),
|
|
219
|
+
]
|
|
220
|
+
program = Program(calls=initial_calls)
|
|
221
|
+
executable = program.compile(self._tool_map)
|
|
222
|
+
program_result = await self._program_runner.run(executable)
|
|
223
|
+
|
|
224
|
+
# Make sure initial Program run succeeded
|
|
225
|
+
if exception_result := program_result.has_exception():
|
|
226
|
+
assert exception_result.error is not None # TODO: improve typing of CallResult
|
|
227
|
+
raise exception_result.error
|
|
228
|
+
|
|
229
|
+
with self._controller as control:
|
|
230
|
+
end_time = time.time() + act.timeout
|
|
231
|
+
|
|
232
|
+
while True:
|
|
233
|
+
# Check time out / max steps
|
|
234
|
+
if time.time() > end_time:
|
|
235
|
+
act.did_timeout = True
|
|
236
|
+
raise ActTimeoutError()
|
|
237
|
+
|
|
238
|
+
if step_idx >= act.max_steps:
|
|
239
|
+
raise ActExceededMaxStepsError(f"Exceeded max steps {act.max_steps} without return.")
|
|
240
|
+
|
|
241
|
+
# Optionally warn for dangerous viewport dimensions in BrowserObservations
|
|
242
|
+
if observation := program_result.has_observation(): # ensure we took an observation
|
|
243
|
+
if browser_observation := self._backend._maybe_observation( # typeguard BrowserObservation
|
|
244
|
+
observation.return_value
|
|
245
|
+
):
|
|
246
|
+
screenshot_b64 = browser_observation["screenshotBase64"]
|
|
247
|
+
screenshot_pil = get_source_image_from_data_url(screenshot_b64)
|
|
248
|
+
validate_viewport_dimensions(*screenshot_pil.size, warn=act.ignore_screen_dims_check)
|
|
249
|
+
|
|
250
|
+
# Get a Program from the model
|
|
251
|
+
set_logging_session_state(SessionState.THINKING)
|
|
252
|
+
with Thinker(tty=self._controller._tty, logger=_TRACE_LOGGER):
|
|
253
|
+
step_object = self._backend.step(act, program_result.call_results, self._tool_map)
|
|
254
|
+
|
|
255
|
+
self._human_input_callbacks.most_recent_screenshot = step_object.model_input.image
|
|
256
|
+
|
|
257
|
+
act.add_step(step_object)
|
|
258
|
+
program = step_object.program
|
|
259
|
+
|
|
260
|
+
# Log the model output
|
|
261
|
+
awl_program = decode_awl_raw_program(step_object.model_output.awl_raw_program)
|
|
262
|
+
trace_log_lines(awl_program)
|
|
263
|
+
|
|
264
|
+
# Handle pause/cancel conditions
|
|
265
|
+
while control.state == ControlState.PAUSED:
|
|
266
|
+
await asyncio.sleep(0.1)
|
|
267
|
+
|
|
268
|
+
if control.state == ControlState.CANCELLED:
|
|
269
|
+
self._cancel_act(act)
|
|
270
|
+
|
|
271
|
+
# Compile and run the program
|
|
272
|
+
try:
|
|
273
|
+
executable = program.compile(self._tool_map)
|
|
274
|
+
set_logging_session_state(SessionState.UNKNOWN)
|
|
275
|
+
with Thinker(tty=self._controller._tty, logger=_TRACE_LOGGER):
|
|
276
|
+
program_result = await self._program_runner.run(executable)
|
|
277
|
+
|
|
278
|
+
if throw_result := program_result.has_throw():
|
|
279
|
+
message = format_return_value(throw_result.return_value)
|
|
280
|
+
raise ActAgentFailed(message=message)
|
|
281
|
+
elif exception_result := program_result.has_exception():
|
|
282
|
+
assert exception_result.error is not None # TODO: improve typing of CallResult
|
|
283
|
+
raise exception_result.error
|
|
284
|
+
|
|
285
|
+
except AgentRedirectError as e:
|
|
286
|
+
# Client wants to redirect the agent to try a different action
|
|
287
|
+
trace_log_lines("AgentRedirect: " + e.error_and_correction)
|
|
288
|
+
|
|
289
|
+
if return_result := program_result.has_return():
|
|
290
|
+
result = return_result.return_value
|
|
291
|
+
act.complete(str(result) if result is not None else None)
|
|
292
|
+
break
|
|
293
|
+
|
|
294
|
+
step_idx += 1
|
|
295
|
+
|
|
296
|
+
if act.result is None:
|
|
297
|
+
raise ActExecutionError("Act completed without a result.")
|
|
298
|
+
|
|
299
|
+
self._event_handler.send_event(
|
|
300
|
+
type=EventType.ACTION,
|
|
301
|
+
action="result",
|
|
302
|
+
data=act.result,
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
# Calculate and set time worked
|
|
306
|
+
if act.start_time is not None and act.end_time is not None:
|
|
307
|
+
human_wait_time = self._wait_time_tracker.get_total_wait_time_s()
|
|
308
|
+
time_worked = _calculate_time_worked(act.start_time, act.end_time, human_wait_time)
|
|
309
|
+
|
|
310
|
+
# Update act metadata with time worked
|
|
311
|
+
# Note: This requires act.set_time_worked() to be implemented (Task 7)
|
|
312
|
+
if hasattr(act, "set_time_worked"):
|
|
313
|
+
act.set_time_worked(time_worked, human_wait_time)
|
|
314
|
+
|
|
315
|
+
# Log time worked to console
|
|
316
|
+
_log_time_worked(act.result.metadata)
|
|
317
|
+
|
|
318
|
+
return act.result
|
|
319
|
+
|
|
320
|
+
def cancel_prompt(self, act: Act | None = None) -> None:
|
|
321
|
+
self._canceled = True
|
|
File without changes
|