agentenv-framework 0.9.1254__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.
- agent_env/__init__.py +0 -0
- agent_env/a2a_agent/__init__.py +23 -0
- agent_env/a2a_agent/a2a_agent.py +600 -0
- agent_env/a2a_agent/conversation_store.py +356 -0
- agent_env/a2a_agent/object_transfer.py +609 -0
- agent_env/a2a_agent/protocol.py +238 -0
- agent_env/a2a_agent/store.py +201 -0
- agent_env/a2a_agent/validator.py +901 -0
- agent_env/artifact/__init__.py +48 -0
- agent_env/artifact/artifact.py +74 -0
- agent_env/artifact/artifacts/__init__.py +0 -0
- agent_env/artifact/artifacts/cli.py +83 -0
- agent_env/artifact/artifacts/docker_image.py +457 -0
- agent_env/artifact/artifacts/environment.py +89 -0
- agent_env/artifact/artifacts/environment_universe.py +156 -0
- agent_env/artifact/artifacts/file.py +214 -0
- agent_env/artifact/artifacts/file_artifact_universe.py +206 -0
- agent_env/artifact/artifacts/skill.py +206 -0
- agent_env/artifact/artifacts/vm_image.py +95 -0
- agent_env/artifact/ref.py +15 -0
- agent_env/artifact/registry.py +251 -0
- agent_env/artifact/store.py +295 -0
- agent_env/artifact/universe.py +38 -0
- agent_env/attribution.py +41 -0
- agent_env/bundle/__init__.py +4 -0
- agent_env/bundle/_fs.py +128 -0
- agent_env/bundle/authoring.py +239 -0
- agent_env/bundle/installed.py +175 -0
- agent_env/bundle/ledger.py +269 -0
- agent_env/bundle/materialize.py +204 -0
- agent_env/bundle/parse.py +594 -0
- agent_env/bundle/plan.py +414 -0
- agent_env/bundle/resolve.py +404 -0
- agent_env/bundle/run.py +361 -0
- agent_env/cli/__init__.py +69 -0
- agent_env/cli/__main__.py +10 -0
- agent_env/cli/_installers.py +576 -0
- agent_env/cli/_plugin_changes.py +947 -0
- agent_env/cli/a2a_agent/__init__.py +22 -0
- agent_env/cli/a2a_agent/add_skill.py +97 -0
- agent_env/cli/a2a_agent/deploy.py +60 -0
- agent_env/cli/a2a_agent/get.py +15 -0
- agent_env/cli/a2a_agent/get_instance.py +26 -0
- agent_env/cli/a2a_agent/put.py +78 -0
- agent_env/cli/a2a_agent/validate.py +56 -0
- agent_env/cli/artifact/__init__.py +20 -0
- agent_env/cli/artifact/cli.py +83 -0
- agent_env/cli/artifact/environment.py +44 -0
- agent_env/cli/artifact/environment_universe.py +163 -0
- agent_env/cli/artifact/file_artifact_universe.py +281 -0
- agent_env/cli/artifact/skill.py +128 -0
- agent_env/cli/banner.py +25 -0
- agent_env/cli/config.py +263 -0
- agent_env/cli/env/__init__.py +31 -0
- agent_env/cli/env/deploy.py +112 -0
- agent_env/cli/env/gateway.py +57 -0
- agent_env/cli/env/get_instance.py +40 -0
- agent_env/cli/env/mcp_server.py +410 -0
- agent_env/cli/env/multi.py +282 -0
- agent_env/cli/env/service_db.py +99 -0
- agent_env/cli/env/snapshot.py +35 -0
- agent_env/cli/env/state/__init__.py +6 -0
- agent_env/cli/env/state/init.py +108 -0
- agent_env/cli/env/state/teardown.py +44 -0
- agent_env/cli/env/website.py +216 -0
- agent_env/cli/env/website_browser.py +67 -0
- agent_env/cli/eval/__init__.py +16 -0
- agent_env/cli/eval/add_tasks.py +63 -0
- agent_env/cli/eval/create.py +49 -0
- agent_env/cli/eval/run.py +194 -0
- agent_env/cli/identity/__init__.py +5 -0
- agent_env/cli/identity/client_identity.py +37 -0
- agent_env/cli/plugin.py +438 -0
- agent_env/cli/run.py +285 -0
- agent_env/cli/task/__init__.py +21 -0
- agent_env/cli/task/create.py +109 -0
- agent_env/cli/task/get.py +17 -0
- agent_env/cli/task/get_instance.py +34 -0
- agent_env/cli/task/run.py +615 -0
- agent_env/cli/task/validate.py +31 -0
- agent_env/cli/up.py +123 -0
- agent_env/cli/utils.py +183 -0
- agent_env/config/__init__.py +50 -0
- agent_env/config/describe.py +1067 -0
- agent_env/config/errors.py +13 -0
- agent_env/config/loader.py +245 -0
- agent_env/config/model.py +154 -0
- agent_env/config/paths.py +25 -0
- agent_env/config/plugin_tables.py +101 -0
- agent_env/config/provenance.py +134 -0
- agent_env/config/runtime.py +1064 -0
- agent_env/config/snapshot.py +81 -0
- agent_env/entity_refs.py +186 -0
- agent_env/env/__init__.py +49 -0
- agent_env/env/env.py +433 -0
- agent_env/env/env_artifact_store.py +87 -0
- agent_env/env/envs/__init__.py +7 -0
- agent_env/env/envs/_deployment.py +281 -0
- agent_env/env/envs/gateway_server.py +32 -0
- agent_env/env/envs/mcp_server.py +387 -0
- agent_env/env/envs/multi_env.py +780 -0
- agent_env/env/envs/service_db/Dockerfile +20 -0
- agent_env/env/envs/service_db/Dockerfile.db-mcp +42 -0
- agent_env/env/envs/service_db/Dockerfile.db-web +8 -0
- agent_env/env/envs/service_db.py +92 -0
- agent_env/env/envs/website.py +294 -0
- agent_env/env/envs/website_browser/Dockerfile +40 -0
- agent_env/env/envs/website_browser/__init__.py +17 -0
- agent_env/env/envs/website_browser/entrypoint.sh +13 -0
- agent_env/env/gateway/Dockerfile +14 -0
- agent_env/env/gateway/__init__.py +37 -0
- agent_env/env/gateway/clock.py +184 -0
- agent_env/env/gateway/constants.py +190 -0
- agent_env/env/gateway/entrypoint.py +156 -0
- agent_env/env/gateway/gateway.py +1095 -0
- agent_env/env/gateway/get_time.py +60 -0
- agent_env/env/gateway/requirements.txt +4 -0
- agent_env/env/gateway/triggers.py +1193 -0
- agent_env/env/legacy_protocol.py +146 -0
- agent_env/env/registry.py +93 -0
- agent_env/env/snapshot_store.py +372 -0
- agent_env/env/store.py +411 -0
- agent_env/eval/__init__.py +14 -0
- agent_env/eval/eval.py +68 -0
- agent_env/eval/store.py +116 -0
- agent_env/examples/hello/README.md +9 -0
- agent_env/examples/hello/artifacts/greeting/check.sh +1 -0
- agent_env/examples/hello/artifacts/greeting/hello.txt +1 -0
- agent_env/examples/hello/tasks/hello.json +10 -0
- agent_env/explorer/__init__.py +12 -0
- agent_env/explorer/app.py +277 -0
- agent_env/explorer/openapi_docs.py +242 -0
- agent_env/explorer/plugin.py +95 -0
- agent_env/explorer/routers/__init__.py +1 -0
- agent_env/explorer/routers/common.py +174 -0
- agent_env/explorer/routers/conversations.py +25 -0
- agent_env/explorer/routers/objects.py +112 -0
- agent_env/explorer/routers/runs.py +475 -0
- agent_env/plugins/__init__.py +59 -0
- agent_env/plugins/_cli.py +244 -0
- agent_env/plugins/_discovery.py +97 -0
- agent_env/plugins/_inventory.py +262 -0
- agent_env/plugins/_registration.py +268 -0
- agent_env/plugins/_report.py +47 -0
- agent_env/plugins/_requirements.py +55 -0
- agent_env/providers/__init__.py +37 -0
- agent_env/providers/env_providers/__init__.py +12 -0
- agent_env/providers/env_providers/constants.py +13 -0
- agent_env/providers/env_providers/env_gateway_provider.py +1354 -0
- agent_env/providers/env_providers/env_provider.py +237 -0
- agent_env/providers/env_providers/env_server_provider.py +133 -0
- agent_env/providers/env_state/__init__.py +49 -0
- agent_env/providers/env_state/env_state_provider.py +554 -0
- agent_env/providers/env_state/local_postgres.py +390 -0
- agent_env/providers/env_state/store.py +112 -0
- agent_env/providers/sandbox_providers/__init__.py +29 -0
- agent_env/providers/sandbox_providers/chained_sandbox_provider.py +93 -0
- agent_env/providers/sandbox_providers/e2b/__init__.py +6 -0
- agent_env/providers/sandbox_providers/e2b/provider.py +376 -0
- agent_env/providers/sandbox_providers/e2b/sandbox.py +342 -0
- agent_env/providers/sandbox_providers/e2b/template.py +158 -0
- agent_env/providers/sandbox_providers/local_sandbox.py +408 -0
- agent_env/providers/sandbox_providers/modal_sandbox.py +500 -0
- agent_env/providers/sandbox_providers/modal_vm_sandbox.py +466 -0
- agent_env/providers/sandbox_providers/sandbox.py +387 -0
- agent_env/providers/sandbox_providers/sandbox_provider.py +614 -0
- agent_env/py.typed +0 -0
- agent_env/runner/__init__.py +16 -0
- agent_env/runner/local_runner.py +190 -0
- agent_env/runner/runner.py +127 -0
- agent_env/runner/store.py +94 -0
- agent_env/store/__init__.py +126 -0
- agent_env/store/_google.py +68 -0
- agent_env/store/base.py +33 -0
- agent_env/store/document_store/__init__.py +60 -0
- agent_env/store/document_store/document_store.py +519 -0
- agent_env/store/document_store/dynamodb_document_store.py +306 -0
- agent_env/store/document_store/evaluation.py +199 -0
- agent_env/store/document_store/firestore_mongo_document_store.py +242 -0
- agent_env/store/document_store/mongo_document_store.py +259 -0
- agent_env/store/document_store/sqlite_document_store.py +314 -0
- agent_env/store/ids.py +123 -0
- agent_env/store/image_store/__init__.py +34 -0
- agent_env/store/image_store/ecr_image_store.py +131 -0
- agent_env/store/image_store/google_credentials.py +113 -0
- agent_env/store/image_store/image_store.py +113 -0
- agent_env/store/image_store/local_registry_image_store.py +106 -0
- agent_env/store/image_store/oci_registry_credentials.py +196 -0
- agent_env/store/local_state.py +27 -0
- agent_env/store/object_store/__init__.py +24 -0
- agent_env/store/object_store/gcs_object_store.py +415 -0
- agent_env/store/object_store/local_object_store.py +143 -0
- agent_env/store/object_store/object_store.py +198 -0
- agent_env/store/object_store/s3_object_store.py +354 -0
- agent_env/store/query.py +112 -0
- agent_env/store/routing.py +609 -0
- agent_env/store/secret_store/__init__.py +19 -0
- agent_env/store/secret_store/aws_secrets_manager_secret_store.py +293 -0
- agent_env/store/secret_store/gcp_secret_manager_secret_store.py +319 -0
- agent_env/store/secret_store/local_secret_store.py +47 -0
- agent_env/store/secret_store/secret_store.py +19 -0
- agent_env/task/__init__.py +27 -0
- agent_env/task/interrupts.py +109 -0
- agent_env/task/registry.py +27 -0
- agent_env/task/step_journal.py +99 -0
- agent_env/task/store.py +940 -0
- agent_env/task/task.py +815 -0
- agent_env/task/teardown.py +142 -0
- agent_env/task_step/__init__.py +47 -0
- agent_env/task_step/context.py +195 -0
- agent_env/task_step/context_ops.py +224 -0
- agent_env/task_step/registry.py +182 -0
- agent_env/task_step/review_store.py +118 -0
- agent_env/task_step/snapshot_utils/__init__.py +2 -0
- agent_env/task_step/snapshot_utils/agent_state_capture.py +261 -0
- agent_env/task_step/snapshot_utils/snapshot_series.py +631 -0
- agent_env/task_step/store.py +129 -0
- agent_env/task_step/task_step.py +173 -0
- agent_env/task_step/task_steps/__init__.py +27 -0
- agent_env/task_step/task_steps/a2a_agent_validator/__init__.py +31 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/README.md +158 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.m4a +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.mp3 +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.mp4 +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.ogg +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.wav +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/document.pdf +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.gif +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.jpg +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.png +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_card.py +103 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_config_identity.py +69 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_mcp.py +178 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_core_protocol.py +67 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_install.py +115 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_litellm_attribution.py +124 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_litellm_attribution_runtime.py +173 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_modalities.py +270 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_peer_agents.py +102 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_role.py +151 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_skill_config.py +194 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_snapshot.py +111 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_system_prompt.py +215 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_trajectory.py +164 -0
- agent_env/task_step/task_steps/add_skills.py +240 -0
- agent_env/task_step/task_steps/apply_server_config.py +288 -0
- agent_env/task_step/task_steps/collect_artifacts.py +940 -0
- agent_env/task_step/task_steps/deploy_agent.py +626 -0
- agent_env/task_step/task_steps/deploy_env.py +197 -0
- agent_env/task_step/task_steps/deploy_human_agent.py +100 -0
- agent_env/task_step/task_steps/deploy_sandbox.py +170 -0
- agent_env/task_step/task_steps/env_card_validator/__init__.py +4 -0
- agent_env/task_step/task_steps/env_card_validator/verify_env_card.py +109 -0
- agent_env/task_step/task_steps/env_card_validator/verify_env_core_protocol.py +108 -0
- agent_env/task_step/task_steps/install_agent.py +376 -0
- agent_env/task_step/task_steps/load_artifact.py +775 -0
- agent_env/task_step/task_steps/mcp_cli_builder/__init__.py +4 -0
- agent_env/task_step/task_steps/mcp_cli_builder/build_mcp_cli.py +201 -0
- agent_env/task_step/task_steps/mcp_cli_builder/codegen.py +627 -0
- agent_env/task_step/task_steps/mcp_env_validator/__init__.py +44 -0
- agent_env/task_step/task_steps/mcp_env_validator/validation_gate_aggregator.py +102 -0
- agent_env/task_step/task_steps/mcp_env_validator/verify_mcp_env_assessment.py +78 -0
- agent_env/task_step/task_steps/mcp_env_validator/verify_mcp_tool_schema.py +152 -0
- agent_env/task_step/task_steps/mcp_env_validator/verify_spec_conformance.py +486 -0
- agent_env/task_step/task_steps/modify_env_tool_access.py +80 -0
- agent_env/task_step/task_steps/multienv_validator/__init__.py +3 -0
- agent_env/task_step/task_steps/multienv_validator/combine_universe_verdicts.py +107 -0
- agent_env/task_step/task_steps/multienv_validator/universe_comparison.py +253 -0
- agent_env/task_step/task_steps/multienv_validator/verify_universe_agent_judge.py +180 -0
- agent_env/task_step/task_steps/multienv_validator/verify_universe_roundtrip.py +241 -0
- agent_env/task_step/task_steps/peer_agents.py +92 -0
- agent_env/task_step/task_steps/prompt_agent.py +900 -0
- agent_env/task_step/task_steps/register_agent_triggers.py +113 -0
- agent_env/task_step/task_steps/register_env_triggers.py +97 -0
- agent_env/task_step/task_steps/reset_env.py +71 -0
- agent_env/task_step/task_steps/review.py +152 -0
- agent_env/task_step/task_steps/run_code.py +461 -0
- agent_env/task_step/task_steps/run_code_runner.py +52 -0
- agent_env/task_step/task_steps/run_docker_container.py +380 -0
- agent_env/task_step/task_steps/sandbox_utils/__init__.py +0 -0
- agent_env/task_step/task_steps/sandbox_utils/sandbox_utils.py +79 -0
- agent_env/task_step/task_steps/snapshot_agent_state.py +205 -0
- agent_env/task_step/task_steps/snapshot_env.py +637 -0
- agent_env/task_step/task_steps/sync_env_clock.py +132 -0
- agent_env/task_step/task_steps/teardown_sandboxes.py +170 -0
- agent_env/task_step/task_steps/verifiers/__init__.py +23 -0
- agent_env/task_step/task_steps/verifiers/agent_prompt_response_verifier.py +166 -0
- agent_env/task_step/task_steps/verifiers/aggregate_verifiers.py +90 -0
- agent_env/task_step/task_steps/verifiers/env_outcome_verifier.py +127 -0
- agent_env/task_step/task_steps/verifiers/judge_utils/__init__.py +2 -0
- agent_env/task_step/task_steps/verifiers/judge_utils/frame_selection.py +377 -0
- agent_env/task_step/task_steps/verifiers/judge_utils/judge_output_format.py +1293 -0
- agent_env/task_step/task_steps/verifiers/judge_utils/trajectory_filter.py +514 -0
- agent_env/task_step/task_steps/verifiers/rubrics_verifier.py +1318 -0
- agent_env/task_step/task_steps/verifiers/run_container_unit_tests_verifier.py +434 -0
- agent_env/task_step/task_steps/verifiers/scoring.py +40 -0
- agent_env/task_step/task_steps/verifiers/verify_sandbox.py +308 -0
- agent_env/task_step/thread_work.py +61 -0
- agent_env/utils/__init__.py +0 -0
- agent_env/utils/card_naming.py +108 -0
- agent_env/utils/deprecation.py +109 -0
- agent_env/utils/docker_build.py +29 -0
- agent_env/utils/exec_retry.py +77 -0
- agent_env/utils/litellm_attribution.py +59 -0
- agent_env/utils/paths.py +20 -0
- agentenv_framework-0.9.1254.dist-info/METADATA +394 -0
- agentenv_framework-0.9.1254.dist-info/RECORD +312 -0
- agentenv_framework-0.9.1254.dist-info/WHEEL +4 -0
- agentenv_framework-0.9.1254.dist-info/entry_points.txt +5 -0
- agentenv_framework-0.9.1254.dist-info/licenses/LICENSE +202 -0
- agentenv_framework-0.9.1254.dist-info/licenses/NOTICE +4 -0
- agentenv_framework-0.9.1254.dist-info/licenses/THIRD_PARTY_NOTICES.md +7665 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Resolving the config document: discover a path, parse it, answer sections from it.
|
|
2
|
+
|
|
3
|
+
The result is held by a ``Config``, which resolves once and keeps it. Nothing is cached here,
|
|
4
|
+
so two Configs can hold different documents on purpose and neither can drift from its own.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import copy
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any, Mapping, Optional
|
|
13
|
+
|
|
14
|
+
from agent_env.config import loader
|
|
15
|
+
from agent_env.config.errors import ConfigError
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class Snapshot:
|
|
20
|
+
"""Where the document came from, and what it said."""
|
|
21
|
+
|
|
22
|
+
path: Optional[Path]
|
|
23
|
+
_document: Mapping[str, Any]
|
|
24
|
+
error: Optional[Exception] = None
|
|
25
|
+
|
|
26
|
+
def section(self, *names: str) -> Mapping[str, Any]:
|
|
27
|
+
"""The table at ``names`` as a copy; ``{}`` when absent, an error when mis-shaped.
|
|
28
|
+
|
|
29
|
+
Absent is ``{}`` because every caller has a built-in default. *Present but not a
|
|
30
|
+
table* raises, because someone wrote it and meant something by it: ``sandbox = 5``
|
|
31
|
+
used to leave the reader on its built-in ``local`` while `config show` printed the
|
|
32
|
+
5 back, which is the report lying about a value the process never used. The aliased
|
|
33
|
+
sections in ``runtime`` have always raised here; this is the same rule.
|
|
34
|
+
|
|
35
|
+
Copied, not frozen: fifteen ``isinstance(x, dict)`` sites read a non-dict as absent,
|
|
36
|
+
so a ``MappingProxyType`` would turn nested tables into silent defaults.
|
|
37
|
+
"""
|
|
38
|
+
if self.error is not None:
|
|
39
|
+
raise self.error
|
|
40
|
+
node: Any = self._document
|
|
41
|
+
walked: list[str] = []
|
|
42
|
+
for name in names:
|
|
43
|
+
if node is None:
|
|
44
|
+
return {}
|
|
45
|
+
self._require_table(node, walked)
|
|
46
|
+
walked.append(name)
|
|
47
|
+
node = node.get(name)
|
|
48
|
+
if node is None:
|
|
49
|
+
return {}
|
|
50
|
+
self._require_table(node, walked)
|
|
51
|
+
return copy.deepcopy(node)
|
|
52
|
+
|
|
53
|
+
@staticmethod
|
|
54
|
+
def _require_table(node: Any, walked: list) -> None:
|
|
55
|
+
if not isinstance(node, dict):
|
|
56
|
+
raise ConfigError(
|
|
57
|
+
f"config.toml [{'.'.join(walked)}] must be a table, got {type(node).__name__}"
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _parse(path: Optional[Path]) -> Snapshot:
|
|
62
|
+
"""A parse error rides on the snapshot so the path stays reportable — `config show` needs
|
|
63
|
+
to name the file most when the file is the broken thing."""
|
|
64
|
+
if path is None:
|
|
65
|
+
return Snapshot(path=None, _document={})
|
|
66
|
+
try:
|
|
67
|
+
# A strict read, with no existence check in front of it: discovery returned this
|
|
68
|
+
# path a moment ago, so a missing file is a race and must be loud. Checking first
|
|
69
|
+
# and reading second would only narrow the window, which is not the same as closing
|
|
70
|
+
# it — the open is the check.
|
|
71
|
+
return Snapshot(path=path, _document=loader.read_config_file(path))
|
|
72
|
+
except FileNotFoundError:
|
|
73
|
+
return Snapshot(path=path, _document={}, error=ConfigError(
|
|
74
|
+
f"config.toml at {path} vanished between discovery and read"))
|
|
75
|
+
except (ConfigError, OSError) as e:
|
|
76
|
+
return Snapshot(path=path, _document={}, error=e)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def resolve() -> Snapshot:
|
|
80
|
+
"""Discover and parse, with no caching — the Config holds the result."""
|
|
81
|
+
return _parse(loader.discover_config_path())
|
agent_env/entity_refs.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""Which fields of a step dict, or keys of an entity's toml, hold env, A2A agent, artifact or task ids.
|
|
2
|
+
|
|
3
|
+
A type declares them on its class so a tool that rewrites ids before a run, such as a bundle
|
|
4
|
+
resolver, finds every one without guessing from field names. Nothing at run time reads the
|
|
5
|
+
declarations. Step types declare ``entity_refs``; env, agent, artifact and eval types declare the keys
|
|
6
|
+
of their toml as ``toml_refs``. For example::
|
|
7
|
+
|
|
8
|
+
class LoadArtifactTaskStep(TaskStep):
|
|
9
|
+
entity_refs = (
|
|
10
|
+
EntityRef.env("env_id"),
|
|
11
|
+
EntityRef.artifact("artifact_id", version_field="artifact_version"),
|
|
12
|
+
EntityRef.artifact("artifacts[].id", version_field="version"),
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
A toml pins a ref inline, with a table keyed by the ref's kind, which also lets a list element be
|
|
16
|
+
pinned: ``mcp_server_envs = ["tickets", { env = "crm", version = 2 }]``; ``ref_sites`` reads that
|
|
17
|
+
form when asked to.
|
|
18
|
+
|
|
19
|
+
Fields that name something else, such as another step's id, are left out. A step type's
|
|
20
|
+
declarations are not inherited, so a subclass declares its own; ``toml_refs`` are, as ``from_toml``
|
|
21
|
+
is.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import re
|
|
27
|
+
from collections.abc import Callable, Iterable, Iterator
|
|
28
|
+
from dataclasses import KW_ONLY, dataclass
|
|
29
|
+
from enum import StrEnum
|
|
30
|
+
from typing import Any, NamedTuple
|
|
31
|
+
|
|
32
|
+
# Yields (path parts relative to ``value``, dict) for every dict under ``value`` that holds the ref's key.
|
|
33
|
+
Walker = Callable[[Any], Iterator[tuple[tuple[str, ...], dict]]]
|
|
34
|
+
|
|
35
|
+
_PATH = re.compile(r"[A-Za-z_]\w*(\[\])?(\.[A-Za-z_]\w*(\[\])?)*")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class EntityKind(StrEnum):
|
|
39
|
+
ENV = "env"
|
|
40
|
+
AGENT = "agent"
|
|
41
|
+
ARTIFACT = "artifact"
|
|
42
|
+
TASK = "task"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class RefRole(StrEnum):
|
|
46
|
+
INPUT = "input"
|
|
47
|
+
OUTPUT = "output"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass(frozen=True)
|
|
51
|
+
class EntityRef:
|
|
52
|
+
"""One ref-holding field. ``path`` is dotted keys into the step dict or toml, ``[]`` meaning each
|
|
53
|
+
element of a list (``env_ids[]``, ``artifacts[].id``); ``version_field`` is the key beside the
|
|
54
|
+
ref, in the same dict, that pins its version. ``walk``, for a shape a path cannot spell, maps
|
|
55
|
+
the value at the path's parent to the dicts that hold the last key, each with its path parts.
|
|
56
|
+
Declarations build one with ``EntityRef.env``, ``EntityRef.agent`` or ``EntityRef.artifact``,
|
|
57
|
+
passing the keyword fields."""
|
|
58
|
+
|
|
59
|
+
path: str
|
|
60
|
+
kind: EntityKind
|
|
61
|
+
_: KW_ONLY
|
|
62
|
+
version_field: str | None = None
|
|
63
|
+
role: RefRole = RefRole.INPUT
|
|
64
|
+
artifact_type: str | None = None
|
|
65
|
+
walk: Walker | None = None
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def env(cls, path: str, **options: Any) -> EntityRef:
|
|
69
|
+
return cls(path, EntityKind.ENV, **options)
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def agent(cls, path: str, **options: Any) -> EntityRef:
|
|
73
|
+
return cls(path, EntityKind.AGENT, **options)
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def artifact(cls, path: str, **options: Any) -> EntityRef:
|
|
77
|
+
return cls(path, EntityKind.ARTIFACT, **options)
|
|
78
|
+
|
|
79
|
+
@classmethod
|
|
80
|
+
def task(cls, path: str, **options: Any) -> EntityRef:
|
|
81
|
+
return cls(path, EntityKind.TASK, **options)
|
|
82
|
+
|
|
83
|
+
def __post_init__(self) -> None:
|
|
84
|
+
if not _PATH.fullmatch(self.path):
|
|
85
|
+
raise ValueError(f"entity ref path {self.path!r} is not dotted keys with optional [] suffixes")
|
|
86
|
+
if not isinstance(self.kind, EntityKind) or not isinstance(self.role, RefRole):
|
|
87
|
+
raise ValueError(
|
|
88
|
+
f"entity ref {self.path!r}: kind {self.kind!r} / role {self.role!r} "
|
|
89
|
+
"must be EntityKind / RefRole members"
|
|
90
|
+
)
|
|
91
|
+
if self.version_field is not None and self.path.endswith("[]"):
|
|
92
|
+
raise ValueError(f"entity ref {self.path!r}: a list element has no sibling key to hold a version")
|
|
93
|
+
if self.artifact_type is not None and self.kind is not EntityKind.ARTIFACT:
|
|
94
|
+
raise ValueError(f"entity ref {self.path!r}: artifact_type is only for EntityKind.ARTIFACT")
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def field(self) -> str:
|
|
98
|
+
"""The top-level step field the path starts at."""
|
|
99
|
+
return self.path.split(".", 1)[0].removesuffix("[]")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class RefSite(NamedTuple):
|
|
103
|
+
"""One ref found in a step dict or toml: ``owner[key]`` holds ``value``; ``path`` is concrete
|
|
104
|
+
(``artifacts[1].id``, ``mcp_server_envs[1].env``). ``version`` is its pin, None when unset;
|
|
105
|
+
``version_key`` is the key of ``owner`` that holds a pin, None when the ref can't be pinned."""
|
|
106
|
+
|
|
107
|
+
path: str
|
|
108
|
+
ref: EntityRef
|
|
109
|
+
value: Any
|
|
110
|
+
version: Any
|
|
111
|
+
owner: dict | list
|
|
112
|
+
key: str | int
|
|
113
|
+
version_key: str | None = None
|
|
114
|
+
|
|
115
|
+
def rewrite(self, value: Any, version: int | None = None) -> None:
|
|
116
|
+
"""Replace the ref where it was found and, when ``version`` is given, pin it: beside the ref
|
|
117
|
+
in a step dict, inside its table in a toml."""
|
|
118
|
+
if version is not None and self.version_key is None:
|
|
119
|
+
raise ValueError(f"entity ref {self.path!r} has no version field to pin")
|
|
120
|
+
self.owner[self.key] = value
|
|
121
|
+
if version is not None:
|
|
122
|
+
self.owner[self.version_key] = version
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def parse_toml_ref(kind: EntityKind, value: Any) -> tuple[str, int | None]:
|
|
126
|
+
"""The id and version a toml ref names: an id, or ``{ <kind> = "<id>", version = <n> }`` with the
|
|
127
|
+
version optional. Raises ValueError naming the expected form."""
|
|
128
|
+
table = isinstance(value, dict)
|
|
129
|
+
entity_id, version = (value.get(kind.value), value.get("version")) if table else (value, None)
|
|
130
|
+
known_keys = not table or value.keys() <= {kind.value, "version"}
|
|
131
|
+
positive = version is None or (isinstance(version, int) and not isinstance(version, bool) and version >= 1)
|
|
132
|
+
if not (known_keys and isinstance(entity_id, str) and entity_id and positive):
|
|
133
|
+
raise ValueError(f'expected an id or {{ {kind.value} = "<id>", version = <n> }}, the version optional, '
|
|
134
|
+
f"not {value!r}")
|
|
135
|
+
return entity_id, version
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def ref_sites(refs: Iterable[EntityRef], data: dict, *, inline_pins: bool = False) -> Iterator[RefSite]:
|
|
139
|
+
"""Every ref ``refs`` declares that is present, and not None, in ``data``. With ``inline_pins``,
|
|
140
|
+
for a toml, a table holding the ref's kind is a pinned ref and its site points inside the table;
|
|
141
|
+
any other value is reported as it is."""
|
|
142
|
+
for ref in refs:
|
|
143
|
+
*parents, leaf = ref.path.split(".")
|
|
144
|
+
for trail, node in _descend(data, parents, ()):
|
|
145
|
+
for rel, holder in ref.walk(node) if ref.walk else [((), node)]:
|
|
146
|
+
if isinstance(holder, dict):
|
|
147
|
+
yield from _leaf(ref, holder, leaf, (*trail, *rel), inline_pins)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _descend(node: Any, segments: list[str], trail: tuple[str, ...]) -> Iterator[tuple[tuple[str, ...], Any]]:
|
|
151
|
+
if not segments:
|
|
152
|
+
yield trail, node
|
|
153
|
+
return
|
|
154
|
+
key, each = segments[0].removesuffix("[]"), segments[0].endswith("[]")
|
|
155
|
+
child = node.get(key) if isinstance(node, dict) else None
|
|
156
|
+
if child is None:
|
|
157
|
+
return
|
|
158
|
+
if not each:
|
|
159
|
+
yield from _descend(child, segments[1:], (*trail, key))
|
|
160
|
+
elif isinstance(child, list):
|
|
161
|
+
for i, item in enumerate(child):
|
|
162
|
+
yield from _descend(item, segments[1:], (*trail, f"{key}[{i}]"))
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _leaf(ref: EntityRef, holder: dict, leaf: str, trail: tuple[str, ...], inline_pins: bool) -> Iterator[RefSite]:
|
|
166
|
+
key = leaf.removesuffix("[]")
|
|
167
|
+
value = holder.get(key)
|
|
168
|
+
if value is None:
|
|
169
|
+
return
|
|
170
|
+
path = ".".join((*trail, key))
|
|
171
|
+
if not leaf.endswith("[]"):
|
|
172
|
+
yield _site(ref, path, holder, key, ref.version_field, inline_pins)
|
|
173
|
+
elif isinstance(value, list):
|
|
174
|
+
for i, item in enumerate(value):
|
|
175
|
+
if item is not None:
|
|
176
|
+
yield _site(ref, f"{path}[{i}]", value, i, None, inline_pins)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _site(ref: EntityRef, path: str, owner: dict | list, key: str | int, version_key: str | None,
|
|
180
|
+
inline_pins: bool) -> RefSite:
|
|
181
|
+
value = owner[key]
|
|
182
|
+
if inline_pins and isinstance(value, dict) and value.get(ref.kind.value) is not None:
|
|
183
|
+
return RefSite(f"{path}.{ref.kind.value}", ref, value[ref.kind.value], value.get("version"),
|
|
184
|
+
value, ref.kind.value, "version")
|
|
185
|
+
version = owner.get(version_key) if version_key else None
|
|
186
|
+
return RefSite(path, ref, value, version, owner, key, version_key)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from .env import DeployedEnv, DeployedGatewayEnv, DeployedSandboxEnv, Env, EnvCapabilityUnsupported, EnvNeedsGateway, LoadEnvironmentUniverseArtifactResult
|
|
2
|
+
from .envs import GatewayEnv, MCPServerEnv, MultiEnv
|
|
3
|
+
from .snapshot_store import (
|
|
4
|
+
EnvSnapshot,
|
|
5
|
+
EnvSnapshotStore,
|
|
6
|
+
get_env_snapshot_store,
|
|
7
|
+
reset_env_snapshot_store,
|
|
8
|
+
set_env_snapshot_store,
|
|
9
|
+
)
|
|
10
|
+
from .store import (
|
|
11
|
+
EnvInstanceStore,
|
|
12
|
+
EnvQuery,
|
|
13
|
+
EnvStore,
|
|
14
|
+
get_env_instance_store,
|
|
15
|
+
get_env_store,
|
|
16
|
+
reset_env_instance_store,
|
|
17
|
+
reset_env_store,
|
|
18
|
+
set_env_instance_store,
|
|
19
|
+
set_env_store,
|
|
20
|
+
update_env_instance_environment_universe,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"DeployedEnv",
|
|
25
|
+
"DeployedGatewayEnv",
|
|
26
|
+
"DeployedSandboxEnv",
|
|
27
|
+
"Env",
|
|
28
|
+
"EnvCapabilityUnsupported",
|
|
29
|
+
"EnvNeedsGateway",
|
|
30
|
+
"LoadEnvironmentUniverseArtifactResult",
|
|
31
|
+
"GatewayEnv",
|
|
32
|
+
"MCPServerEnv",
|
|
33
|
+
"MultiEnv",
|
|
34
|
+
"EnvStore",
|
|
35
|
+
"EnvInstanceStore",
|
|
36
|
+
"EnvSnapshot",
|
|
37
|
+
"EnvSnapshotStore",
|
|
38
|
+
"EnvQuery",
|
|
39
|
+
"get_env_store",
|
|
40
|
+
"set_env_store",
|
|
41
|
+
"reset_env_store",
|
|
42
|
+
"get_env_instance_store",
|
|
43
|
+
"set_env_instance_store",
|
|
44
|
+
"reset_env_instance_store",
|
|
45
|
+
"get_env_snapshot_store",
|
|
46
|
+
"set_env_snapshot_store",
|
|
47
|
+
"reset_env_snapshot_store",
|
|
48
|
+
"update_env_instance_environment_universe",
|
|
49
|
+
]
|