dap-schemas 0.3.0__tar.gz
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.
- dap_schemas-0.3.0/.gitignore +87 -0
- dap_schemas-0.3.0/PKG-INFO +18 -0
- dap_schemas-0.3.0/README.md +10 -0
- dap_schemas-0.3.0/pyproject.toml +21 -0
- dap_schemas-0.3.0/src/dap_types/__init__.py +56 -0
- dap_schemas-0.3.0/src/dap_types/agent.py +92 -0
- dap_schemas-0.3.0/src/dap_types/pipeline.py +98 -0
- dap_schemas-0.3.0/src/dap_types/project.py +74 -0
- dap_schemas-0.3.0/src/dap_types/py.typed +0 -0
- dap_schemas-0.3.0/src/dap_types/role_outputs.py +169 -0
- dap_schemas-0.3.0/src/dap_types/run.py +87 -0
- dap_schemas-0.3.0/src/dap_types/runtime.py +67 -0
- dap_schemas-0.3.0/src/dap_types/state.py +69 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# --- Python ---
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
.venv/
|
|
8
|
+
venv/
|
|
9
|
+
env/
|
|
10
|
+
*.egg-info/
|
|
11
|
+
*.egg
|
|
12
|
+
dist/
|
|
13
|
+
build/
|
|
14
|
+
.eggs/
|
|
15
|
+
pip-log.txt
|
|
16
|
+
pip-delete-this-directory.txt
|
|
17
|
+
|
|
18
|
+
# uv
|
|
19
|
+
.uv-cache/
|
|
20
|
+
|
|
21
|
+
# Type checkers / linters
|
|
22
|
+
.mypy_cache/
|
|
23
|
+
.ruff_cache/
|
|
24
|
+
.pyright/
|
|
25
|
+
.pytype/
|
|
26
|
+
|
|
27
|
+
# pytest / coverage
|
|
28
|
+
.pytest_cache/
|
|
29
|
+
.coverage
|
|
30
|
+
.coverage.*
|
|
31
|
+
htmlcov/
|
|
32
|
+
.tox/
|
|
33
|
+
.nox/
|
|
34
|
+
coverage.xml
|
|
35
|
+
*.cover
|
|
36
|
+
|
|
37
|
+
# --- Node (dashboard) ---
|
|
38
|
+
node_modules/
|
|
39
|
+
.pnpm-store/
|
|
40
|
+
.next/
|
|
41
|
+
out/
|
|
42
|
+
*.tsbuildinfo
|
|
43
|
+
.turbo/
|
|
44
|
+
|
|
45
|
+
# --- Environment ---
|
|
46
|
+
.env
|
|
47
|
+
.env.local
|
|
48
|
+
.env.*.local
|
|
49
|
+
|
|
50
|
+
# --- DAP local state ---
|
|
51
|
+
.dap/
|
|
52
|
+
*.db
|
|
53
|
+
*.db-journal
|
|
54
|
+
*.db-wal
|
|
55
|
+
*.db-shm
|
|
56
|
+
|
|
57
|
+
# --- Logs ---
|
|
58
|
+
logs/
|
|
59
|
+
*.log
|
|
60
|
+
npm-debug.log*
|
|
61
|
+
pnpm-debug.log*
|
|
62
|
+
|
|
63
|
+
# --- IDE / Agents ---
|
|
64
|
+
.vscode/
|
|
65
|
+
.idea/
|
|
66
|
+
*.swp
|
|
67
|
+
*.swo
|
|
68
|
+
.claude/
|
|
69
|
+
|
|
70
|
+
# --- OS ---
|
|
71
|
+
.DS_Store
|
|
72
|
+
Thumbs.db
|
|
73
|
+
|
|
74
|
+
# --- Cache ---
|
|
75
|
+
.cache/
|
|
76
|
+
.eslintcache
|
|
77
|
+
|
|
78
|
+
# --- Built artefacts ---
|
|
79
|
+
# Dashboard bundle staged into the dap-cli wheel by
|
|
80
|
+
# scripts/build-dashboard-bundle.sh — regenerated on demand from
|
|
81
|
+
# apps/dashboard/.next. The ``.gitkeep`` is retained so hatchling's
|
|
82
|
+
# ``force-include`` always finds the directory; dev wheels built
|
|
83
|
+
# without running the bundle script ship an effectively-empty
|
|
84
|
+
# ``_dashboard/`` and ``dap start`` falls back to "dashboard not
|
|
85
|
+
# bundled".
|
|
86
|
+
apps/cli/src/dap_cli/_dashboard/*
|
|
87
|
+
!apps/cli/src/dap_cli/_dashboard/.gitkeep
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dap-schemas
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Shared Pydantic schemas for DAP (Agent, Pipeline, Run, State, Runtime)
|
|
5
|
+
Requires-Python: >=3.13
|
|
6
|
+
Requires-Dist: pydantic>=2.9.2
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# dap-schemas
|
|
10
|
+
|
|
11
|
+
Shared Pydantic v2 types używane przez engine, runtimes i CLI.
|
|
12
|
+
|
|
13
|
+
Typy: `Agent`, `Pipeline`, `Run`, `PipelineState`, `RuntimeAdapter` (Protocol), `RuntimeTask`, `RuntimeResult`.
|
|
14
|
+
|
|
15
|
+
Wewnątrz monorepo importowane jako:
|
|
16
|
+
```python
|
|
17
|
+
from dap_types import Agent, Pipeline, PipelineState
|
|
18
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# dap-schemas
|
|
2
|
+
|
|
3
|
+
Shared Pydantic v2 types używane przez engine, runtimes i CLI.
|
|
4
|
+
|
|
5
|
+
Typy: `Agent`, `Pipeline`, `Run`, `PipelineState`, `RuntimeAdapter` (Protocol), `RuntimeTask`, `RuntimeResult`.
|
|
6
|
+
|
|
7
|
+
Wewnątrz monorepo importowane jako:
|
|
8
|
+
```python
|
|
9
|
+
from dap_types import Agent, Pipeline, PipelineState
|
|
10
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
# PyPI distribution name. The Python import path stays ``dap_types`` —
|
|
3
|
+
# that's the source directory ``src/dap_types/`` configured below. The
|
|
4
|
+
# distribution name moved off ``dap-types`` because a squatter holds
|
|
5
|
+
# that name on PyPI; ``dap-schemas`` is more accurate anyway (this
|
|
6
|
+
# package is the Pydantic schema bag, not a generic types module).
|
|
7
|
+
name = "dap-schemas"
|
|
8
|
+
version = "0.3.0"
|
|
9
|
+
description = "Shared Pydantic schemas for DAP (Agent, Pipeline, Run, State, Runtime)"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
requires-python = ">=3.13"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"pydantic>=2.9.2",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[build-system]
|
|
17
|
+
requires = ["hatchling"]
|
|
18
|
+
build-backend = "hatchling.build"
|
|
19
|
+
|
|
20
|
+
[tool.hatch.build.targets.wheel]
|
|
21
|
+
packages = ["src/dap_types"]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from dap_types.agent import Agent, AgentRole
|
|
2
|
+
from dap_types.pipeline import (
|
|
3
|
+
ComparisonCondition,
|
|
4
|
+
EdgeCondition,
|
|
5
|
+
LogicalCondition,
|
|
6
|
+
Pipeline,
|
|
7
|
+
PipelineDefaults,
|
|
8
|
+
PipelineEdge,
|
|
9
|
+
PipelineNode,
|
|
10
|
+
)
|
|
11
|
+
from dap_types.project import RECOMMENDED_PIPELINE_KINDS, Project
|
|
12
|
+
from dap_types.role_outputs import (
|
|
13
|
+
ROLE_FIELDS,
|
|
14
|
+
agent_output_model,
|
|
15
|
+
resolve_output_validator,
|
|
16
|
+
role_output_model,
|
|
17
|
+
)
|
|
18
|
+
from dap_types.run import NodeExecutionLog, NodeStatus, Run
|
|
19
|
+
from dap_types.runtime import (
|
|
20
|
+
HealthStatus,
|
|
21
|
+
RuntimeAdapter,
|
|
22
|
+
RuntimeKind,
|
|
23
|
+
RuntimeResult,
|
|
24
|
+
RuntimeTask,
|
|
25
|
+
)
|
|
26
|
+
from dap_types.state import FinalStatus, PipelineState, StateSnapshot, VerificationStatus
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"RECOMMENDED_PIPELINE_KINDS",
|
|
30
|
+
"ROLE_FIELDS",
|
|
31
|
+
"Agent",
|
|
32
|
+
"AgentRole",
|
|
33
|
+
"ComparisonCondition",
|
|
34
|
+
"EdgeCondition",
|
|
35
|
+
"FinalStatus",
|
|
36
|
+
"HealthStatus",
|
|
37
|
+
"LogicalCondition",
|
|
38
|
+
"NodeExecutionLog",
|
|
39
|
+
"NodeStatus",
|
|
40
|
+
"Pipeline",
|
|
41
|
+
"PipelineDefaults",
|
|
42
|
+
"PipelineEdge",
|
|
43
|
+
"PipelineNode",
|
|
44
|
+
"PipelineState",
|
|
45
|
+
"Project",
|
|
46
|
+
"Run",
|
|
47
|
+
"RuntimeAdapter",
|
|
48
|
+
"RuntimeKind",
|
|
49
|
+
"RuntimeResult",
|
|
50
|
+
"RuntimeTask",
|
|
51
|
+
"StateSnapshot",
|
|
52
|
+
"VerificationStatus",
|
|
53
|
+
"agent_output_model",
|
|
54
|
+
"resolve_output_validator",
|
|
55
|
+
"role_output_model",
|
|
56
|
+
]
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
|
7
|
+
|
|
8
|
+
from dap_types.state import PipelineState
|
|
9
|
+
|
|
10
|
+
AgentRole = str # "task_selector" | "test_author" | "implementer" | "verifier" | ... | custom
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def coerce_legacy_field_list(value: Any) -> Any:
|
|
14
|
+
"""Normalise legacy dict-shaped schemas to ``list[str]``.
|
|
15
|
+
|
|
16
|
+
Older Agent rows persisted ``input_schema`` / ``output_schema`` as
|
|
17
|
+
``dict[str, Any]`` (placeholder JSON-Schema-ish blobs). v0.5 narrows
|
|
18
|
+
the contract to a list of PipelineState field names. We coerce
|
|
19
|
+
``dict``/``None`` to ``[]`` here so existing rows survive a read-back
|
|
20
|
+
without a database migration. The shim is removed in v0.6.
|
|
21
|
+
|
|
22
|
+
Anything else (lists, primitives, …) is returned untouched so
|
|
23
|
+
Pydantic's ``list[str]`` annotation does its own type checking and
|
|
24
|
+
rejects non-string elements with the standard validation error
|
|
25
|
+
instead of a silent ``str(item)`` coercion.
|
|
26
|
+
"""
|
|
27
|
+
if value is None or isinstance(value, dict):
|
|
28
|
+
# ``{}`` and any non-empty placeholder dict (legacy JSON-Schema-ish
|
|
29
|
+
# blob) collapse to ``[]`` — there's no real contract to recover.
|
|
30
|
+
return []
|
|
31
|
+
return value
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def validate_field_list(fields: list[str]) -> list[str]:
|
|
35
|
+
"""Reject any name that doesn't exist in ``PipelineState.model_fields``."""
|
|
36
|
+
if not fields:
|
|
37
|
+
return fields
|
|
38
|
+
known = set(PipelineState.model_fields.keys())
|
|
39
|
+
unknown = sorted({f for f in fields if f not in known})
|
|
40
|
+
if unknown:
|
|
41
|
+
msg = (
|
|
42
|
+
"input_schema/output_schema reference unknown PipelineState "
|
|
43
|
+
f"field(s): {', '.join(unknown)}. Known fields: {', '.join(sorted(known))}"
|
|
44
|
+
)
|
|
45
|
+
raise ValueError(msg)
|
|
46
|
+
duplicates = sorted({f for f in fields if fields.count(f) > 1})
|
|
47
|
+
if duplicates:
|
|
48
|
+
msg = f"input_schema/output_schema contain duplicate field(s): {', '.join(duplicates)}"
|
|
49
|
+
raise ValueError(msg)
|
|
50
|
+
return fields
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class Agent(BaseModel):
|
|
54
|
+
"""Wersjonowana definicja agenta — runtime + config + prompt template."""
|
|
55
|
+
|
|
56
|
+
model_config = ConfigDict(extra="forbid")
|
|
57
|
+
|
|
58
|
+
id: str
|
|
59
|
+
name: str
|
|
60
|
+
role: AgentRole
|
|
61
|
+
version: int
|
|
62
|
+
|
|
63
|
+
runtime_id: str
|
|
64
|
+
runtime_config: dict[str, Any] = Field(default_factory=dict)
|
|
65
|
+
|
|
66
|
+
prompt_template: str
|
|
67
|
+
|
|
68
|
+
input_schema: list[str] = Field(default_factory=list)
|
|
69
|
+
output_schema: list[str] = Field(default_factory=list)
|
|
70
|
+
constraints: list[str] = Field(default_factory=list)
|
|
71
|
+
|
|
72
|
+
budget_limit_usd: float | None = None
|
|
73
|
+
timeout_ms: int = 60_000
|
|
74
|
+
|
|
75
|
+
created_at: datetime
|
|
76
|
+
updated_at: datetime
|
|
77
|
+
is_active: bool = True
|
|
78
|
+
|
|
79
|
+
# Populated only on list responses; None on detail / create / update /
|
|
80
|
+
# version endpoints, which don't compute usage. Treat None as "unknown",
|
|
81
|
+
# not "zero".
|
|
82
|
+
used_in_pipelines: int | None = None
|
|
83
|
+
|
|
84
|
+
@field_validator("input_schema", "output_schema", mode="before")
|
|
85
|
+
@classmethod
|
|
86
|
+
def _coerce_legacy_dict_schema(cls, value: Any) -> Any:
|
|
87
|
+
return coerce_legacy_field_list(value)
|
|
88
|
+
|
|
89
|
+
@field_validator("input_schema", "output_schema")
|
|
90
|
+
@classmethod
|
|
91
|
+
def _check_known_fields(cls, value: list[str]) -> list[str]:
|
|
92
|
+
return validate_field_list(value)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Annotated, Any, Literal
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
7
|
+
|
|
8
|
+
ComparisonOperator = Literal["==", "!=", "<", "<=", ">", ">="]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ComparisonCondition(BaseModel):
|
|
12
|
+
model_config = ConfigDict(extra="forbid")
|
|
13
|
+
|
|
14
|
+
type: Literal["comparison"] = "comparison"
|
|
15
|
+
field: str
|
|
16
|
+
operator: ComparisonOperator
|
|
17
|
+
value: str | int | float | bool | None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class LogicalCondition(BaseModel):
|
|
21
|
+
model_config = ConfigDict(extra="forbid")
|
|
22
|
+
|
|
23
|
+
type: Literal["and", "or"]
|
|
24
|
+
children: list[EdgeCondition]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
EdgeCondition = Annotated[
|
|
28
|
+
ComparisonCondition | LogicalCondition,
|
|
29
|
+
Field(discriminator="type"),
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class NodePosition(BaseModel):
|
|
34
|
+
model_config = ConfigDict(extra="forbid")
|
|
35
|
+
x: float = 0
|
|
36
|
+
y: float = 0
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class NodeOverrides(BaseModel):
|
|
40
|
+
model_config = ConfigDict(extra="forbid")
|
|
41
|
+
runtime_config: dict[str, Any] | None = None
|
|
42
|
+
budget_limit_usd: float | None = None
|
|
43
|
+
timeout_ms: int | None = None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class PipelineNode(BaseModel):
|
|
47
|
+
model_config = ConfigDict(extra="forbid")
|
|
48
|
+
|
|
49
|
+
id: str
|
|
50
|
+
agent_id: str
|
|
51
|
+
position: NodePosition = Field(default_factory=NodePosition)
|
|
52
|
+
overrides: NodeOverrides | None = None
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class PipelineEdge(BaseModel):
|
|
56
|
+
model_config = ConfigDict(extra="forbid")
|
|
57
|
+
|
|
58
|
+
id: str
|
|
59
|
+
source: str
|
|
60
|
+
target: str
|
|
61
|
+
condition: EdgeCondition | None = None
|
|
62
|
+
label: str | None = None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class PipelineDefaults(BaseModel):
|
|
66
|
+
model_config = ConfigDict(extra="forbid")
|
|
67
|
+
max_attempts: int = 3
|
|
68
|
+
budget_limit_usd: float = 5.0
|
|
69
|
+
approval_required_nodes: list[str] = Field(default_factory=list)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class Pipeline(BaseModel):
|
|
73
|
+
"""LangGraph-compatible DAG definition."""
|
|
74
|
+
|
|
75
|
+
model_config = ConfigDict(extra="forbid")
|
|
76
|
+
|
|
77
|
+
id: str
|
|
78
|
+
name: str
|
|
79
|
+
description: str = ""
|
|
80
|
+
version: int
|
|
81
|
+
schema_version: Literal["langgraph/1.0"] = "langgraph/1.0"
|
|
82
|
+
|
|
83
|
+
state_schema_ref: str
|
|
84
|
+
entry_point: str
|
|
85
|
+
|
|
86
|
+
nodes: list[PipelineNode]
|
|
87
|
+
edges: list[PipelineEdge]
|
|
88
|
+
|
|
89
|
+
defaults: PipelineDefaults = Field(default_factory=PipelineDefaults)
|
|
90
|
+
|
|
91
|
+
created_at: datetime
|
|
92
|
+
updated_at: datetime
|
|
93
|
+
is_active: bool = True
|
|
94
|
+
ui_metadata: dict[str, Any] | None = None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# Resolve forward reference for self-referential LogicalCondition.children
|
|
98
|
+
LogicalCondition.model_rebuild()
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Project — workspace abstraction owning a working directory + workflow bindings.
|
|
2
|
+
|
|
3
|
+
A Project composes existing Pipelines into a workflow: it carries the
|
|
4
|
+
context (working directory or remote repo, default branch, env vars)
|
|
5
|
+
and binds *workflow kinds* (configure / plan / develop / ...) to
|
|
6
|
+
specific pipeline IDs. Pipelines stay reusable; the project glues
|
|
7
|
+
context onto them.
|
|
8
|
+
|
|
9
|
+
The list ``RECOMMENDED_PIPELINE_KINDS`` is a UX hint, not an enforced
|
|
10
|
+
enum — the dashboard surfaces these slots first-class, but custom
|
|
11
|
+
keys are accepted at the API layer. That keeps users free to invent
|
|
12
|
+
new workflow phases (``release``, ``hotfix``, ``backfill``, …) without
|
|
13
|
+
a code change.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from datetime import datetime
|
|
19
|
+
from typing import Final
|
|
20
|
+
|
|
21
|
+
from pydantic import BaseModel, ConfigDict, Field, computed_field
|
|
22
|
+
|
|
23
|
+
RECOMMENDED_PIPELINE_KINDS: Final = (
|
|
24
|
+
"configure",
|
|
25
|
+
"plan",
|
|
26
|
+
"develop",
|
|
27
|
+
"verify",
|
|
28
|
+
"release",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Project(BaseModel):
|
|
33
|
+
"""A workspace + a binding of workflow kinds to pipelines."""
|
|
34
|
+
|
|
35
|
+
model_config = ConfigDict(extra="forbid")
|
|
36
|
+
|
|
37
|
+
id: str
|
|
38
|
+
name: str
|
|
39
|
+
description: str = ""
|
|
40
|
+
|
|
41
|
+
# Either a local path the engine should run subprocesses in, or a
|
|
42
|
+
# remote repo URL that the user clones manually before running. The
|
|
43
|
+
# engine treats both as opaque strings — no validation, no auth — so
|
|
44
|
+
# a single-user local-trust setup works without auth plumbing.
|
|
45
|
+
working_directory: str | None = None
|
|
46
|
+
repo_url: str | None = None
|
|
47
|
+
default_branch: str = "main"
|
|
48
|
+
|
|
49
|
+
# Workflow bindings. Keys are kinds (recommended or custom),
|
|
50
|
+
# values are pipeline ids. The engine validates that every value
|
|
51
|
+
# is an existing non-archived pipeline at write time.
|
|
52
|
+
pipelines: dict[str, str] = Field(default_factory=dict)
|
|
53
|
+
|
|
54
|
+
# Project-scoped env vars layered onto subprocess environments via
|
|
55
|
+
# the bash / cli runtimes. Engine process env provides the base
|
|
56
|
+
# layer, project ``env_vars`` override that, and per-agent
|
|
57
|
+
# ``runtime_config.env`` wins over both. Secrets should stay in
|
|
58
|
+
# engine env — these are convenience for non-sensitive values
|
|
59
|
+
# like ``WORKSPACE_NAME`` or feature flags.
|
|
60
|
+
env_vars: dict[str, str] = Field(default_factory=dict)
|
|
61
|
+
|
|
62
|
+
created_at: datetime
|
|
63
|
+
updated_at: datetime
|
|
64
|
+
archived_at: datetime | None = None
|
|
65
|
+
|
|
66
|
+
@computed_field # type: ignore[prop-decorator]
|
|
67
|
+
@property
|
|
68
|
+
def is_active(self) -> bool:
|
|
69
|
+
"""Soft-delete flag — ``archived_at is None``.
|
|
70
|
+
|
|
71
|
+
Exposed as a ``computed_field`` so it round-trips through
|
|
72
|
+
``model_dump`` / FastAPI responses for the dashboard.
|
|
73
|
+
"""
|
|
74
|
+
return self.archived_at is None
|
|
File without changes
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""Per-agent / per-role contracts for what an agent's output may write.
|
|
2
|
+
|
|
3
|
+
Two layers of contract:
|
|
4
|
+
|
|
5
|
+
1. **Per-agent** (preferred, v0.5+) — ``Agent.output_schema`` declares the
|
|
6
|
+
exact subset of ``PipelineState`` fields the agent writes. Resolved
|
|
7
|
+
via ``agent_output_model(agent)``.
|
|
8
|
+
2. **Per-role** (legacy) — ``ROLE_FIELDS`` ships hardcoded contracts for
|
|
9
|
+
well-known role names. Used as a fallback when ``output_schema`` is
|
|
10
|
+
empty so existing pipelines keep working without a migration.
|
|
11
|
+
|
|
12
|
+
Both layers build a dynamic Pydantic model that:
|
|
13
|
+
|
|
14
|
+
- exposes only the declared fields,
|
|
15
|
+
- copies their type annotations from ``PipelineState`` (single source of
|
|
16
|
+
truth — no parallel type table to keep in sync),
|
|
17
|
+
- treats every field as optional (a node may write a subset),
|
|
18
|
+
- rejects unknown keys via ``extra="forbid"``.
|
|
19
|
+
|
|
20
|
+
Custom roles with no declared schema are not enforced — the engine
|
|
21
|
+
falls back to permissive ``RuntimeResult.structured`` merging for those.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from functools import cache
|
|
27
|
+
from typing import TYPE_CHECKING, Any
|
|
28
|
+
|
|
29
|
+
from pydantic import BaseModel, ConfigDict, create_model
|
|
30
|
+
|
|
31
|
+
from dap_types.state import PipelineState
|
|
32
|
+
|
|
33
|
+
if TYPE_CHECKING:
|
|
34
|
+
from dap_types.agent import Agent
|
|
35
|
+
|
|
36
|
+
# Allow-list of state fields each well-known role may write. Add a role here
|
|
37
|
+
# AND wire its prompt template; the engine handles the rest automatically.
|
|
38
|
+
ROLE_FIELDS: dict[str, frozenset[str]] = {
|
|
39
|
+
"task_selector": frozenset({"selected_issue_ids"}),
|
|
40
|
+
"test_author": frozenset(
|
|
41
|
+
{
|
|
42
|
+
"tests_generated",
|
|
43
|
+
"test_files",
|
|
44
|
+
"test_generation_errors",
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
"implementer": frozenset(
|
|
48
|
+
{
|
|
49
|
+
"modified_files",
|
|
50
|
+
"implementation_notes",
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
"verifier": frozenset(
|
|
54
|
+
{
|
|
55
|
+
"verification_status",
|
|
56
|
+
"verification_reason",
|
|
57
|
+
"tests_passed",
|
|
58
|
+
"last_test_output",
|
|
59
|
+
}
|
|
60
|
+
),
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@cache
|
|
65
|
+
def role_output_model(role: str) -> type[BaseModel] | None:
|
|
66
|
+
"""Build (and cache) a Pydantic model that validates a role's output.
|
|
67
|
+
|
|
68
|
+
Legacy entry point — callers with an ``Agent`` instance should
|
|
69
|
+
prefer :func:`agent_output_model`, which honours per-agent
|
|
70
|
+
``output_schema`` overrides.
|
|
71
|
+
|
|
72
|
+
Returns ``None`` for roles without a declared field allow-list — callers
|
|
73
|
+
should fall back to permissive merging in that case.
|
|
74
|
+
"""
|
|
75
|
+
fields = ROLE_FIELDS.get(role)
|
|
76
|
+
if fields is None:
|
|
77
|
+
return None
|
|
78
|
+
return _build_model_from_field_subset(fields, name=f"{role.title().replace('_', '')}Output")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def agent_output_model(agent: Agent) -> type[BaseModel] | None:
|
|
82
|
+
"""Resolve the output validator for ``agent``.
|
|
83
|
+
|
|
84
|
+
Convenience wrapper around :func:`resolve_output_validator` for
|
|
85
|
+
callers holding a Pydantic ``Agent``. The model is named after the
|
|
86
|
+
agent + version so cached classes don't collide across agents that
|
|
87
|
+
happen to declare the same field subset.
|
|
88
|
+
"""
|
|
89
|
+
if agent.output_schema:
|
|
90
|
+
return _build_model_from_field_subset(
|
|
91
|
+
tuple(agent.output_schema),
|
|
92
|
+
name=f"Agent_{agent.id}_v{agent.version}_Output",
|
|
93
|
+
)
|
|
94
|
+
return role_output_model(agent.role)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def resolve_output_validator(
|
|
98
|
+
role: str,
|
|
99
|
+
output_schema: list[str] | tuple[str, ...],
|
|
100
|
+
) -> type[BaseModel] | None:
|
|
101
|
+
"""Resolve a validator from raw ``role`` + ``output_schema`` scalars.
|
|
102
|
+
|
|
103
|
+
Same resolution order as :func:`agent_output_model`, but takes the
|
|
104
|
+
contract as two arguments so engine callers holding an ORM split
|
|
105
|
+
(``AgentORM`` + ``AgentVersionORM``) don't need to construct a
|
|
106
|
+
Pydantic ``Agent`` just to parse output.
|
|
107
|
+
|
|
108
|
+
1. ``output_schema`` non-empty → per-agent validator. Fields are
|
|
109
|
+
sorted before lookup so two agents that declare the same set in
|
|
110
|
+
different orders share a single cached class.
|
|
111
|
+
2. Otherwise falls back to ``ROLE_FIELDS[role]``.
|
|
112
|
+
3. Returns ``None`` for custom roles with no declared schema, or
|
|
113
|
+
when the schema references a field that doesn't exist in
|
|
114
|
+
:class:`PipelineState` — caller falls back to permissive merging
|
|
115
|
+
rather than crashing on a stale or hand-edited DB row.
|
|
116
|
+
"""
|
|
117
|
+
if output_schema:
|
|
118
|
+
fields = tuple(sorted(output_schema))
|
|
119
|
+
cache_name = f"FieldSubsetOutput[{','.join(fields)}]"
|
|
120
|
+
return _build_model_from_field_subset(fields, name=cache_name)
|
|
121
|
+
return role_output_model(role)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@cache
|
|
125
|
+
def _build_model_from_field_subset(
|
|
126
|
+
fields: tuple[str, ...] | frozenset[str],
|
|
127
|
+
*,
|
|
128
|
+
name: str,
|
|
129
|
+
) -> type[BaseModel] | None:
|
|
130
|
+
"""Compile a Pydantic model exposing exactly ``fields`` from PipelineState.
|
|
131
|
+
|
|
132
|
+
The resulting model:
|
|
133
|
+
- has only the fields named in ``fields``,
|
|
134
|
+
- copies their type annotations from ``PipelineState`` (single source
|
|
135
|
+
of truth for types),
|
|
136
|
+
- makes every field optional (a node may write a subset),
|
|
137
|
+
- rejects unknown keys via ``extra="forbid"``.
|
|
138
|
+
|
|
139
|
+
Returns ``None`` when ``fields`` references a name that doesn't
|
|
140
|
+
exist in :class:`PipelineState` — the validator API at
|
|
141
|
+
:func:`resolve_output_validator` rejects unknown fields up front,
|
|
142
|
+
so this guard only fires for stale or hand-edited DB rows.
|
|
143
|
+
Returning ``None`` makes the caller fall back to permissive merge
|
|
144
|
+
rather than crash a run on a ``KeyError``.
|
|
145
|
+
|
|
146
|
+
Cached on ``(fields, name)`` — repeated lookups for the same agent /
|
|
147
|
+
role return the same compiled class so equality checks behave.
|
|
148
|
+
"""
|
|
149
|
+
pipeline_fields = PipelineState.model_fields
|
|
150
|
+
model_fields: dict[str, Any] = {}
|
|
151
|
+
for field_name in fields:
|
|
152
|
+
info = pipeline_fields.get(field_name)
|
|
153
|
+
if info is None:
|
|
154
|
+
# Stale/hand-edited row referencing a renamed or removed
|
|
155
|
+
# PipelineState field. Fall back to permissive merge.
|
|
156
|
+
return None
|
|
157
|
+
annotation = info.annotation
|
|
158
|
+
if annotation is None:
|
|
159
|
+
# Shouldn't happen — every PipelineState field is annotated —
|
|
160
|
+
# but guard so create_model gets a usable type.
|
|
161
|
+
annotation = Any
|
|
162
|
+
# All output fields are optional — nodes may write a subset.
|
|
163
|
+
model_fields[field_name] = (annotation | None, None)
|
|
164
|
+
|
|
165
|
+
return create_model(
|
|
166
|
+
name,
|
|
167
|
+
__config__=ConfigDict(extra="forbid"),
|
|
168
|
+
**model_fields,
|
|
169
|
+
)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Any, Literal
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
7
|
+
|
|
8
|
+
from dap_types.state import FinalStatus, PipelineState
|
|
9
|
+
|
|
10
|
+
NodeStatus = Literal["pending", "running", "success", "failed", "skipped"]
|
|
11
|
+
TriggerSource = Literal["dashboard", "cli", "api"]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Run(BaseModel):
|
|
15
|
+
"""Instancja wykonania pipeline'u — immutable FK do wersji pipeline'u."""
|
|
16
|
+
|
|
17
|
+
model_config = ConfigDict(extra="forbid")
|
|
18
|
+
|
|
19
|
+
id: str
|
|
20
|
+
|
|
21
|
+
# Owning project (v0.6). ``None`` for ad-hoc / legacy runs that
|
|
22
|
+
# were triggered directly via ``POST /runs`` without a project
|
|
23
|
+
# association. Populated automatically by
|
|
24
|
+
# ``POST /projects/{id}/run/{kind}`` (#66).
|
|
25
|
+
project_id: str | None = None
|
|
26
|
+
|
|
27
|
+
pipeline_id: str
|
|
28
|
+
pipeline_version: int
|
|
29
|
+
|
|
30
|
+
trigger_source: TriggerSource
|
|
31
|
+
initial_state: PipelineState
|
|
32
|
+
|
|
33
|
+
current_node: str | None = None
|
|
34
|
+
node_statuses: dict[str, NodeStatus] = Field(default_factory=dict)
|
|
35
|
+
|
|
36
|
+
final_status: FinalStatus = "running"
|
|
37
|
+
# Operator-facing reason for a non-clean termination (#260). Populated
|
|
38
|
+
# when ``mark_stale_running_runs_as_failed`` finalises orphan runs on
|
|
39
|
+
# engine restart; otherwise ``None``.
|
|
40
|
+
failure_reason: str | None = None
|
|
41
|
+
started_at: datetime
|
|
42
|
+
ended_at: datetime | None = None
|
|
43
|
+
|
|
44
|
+
tokens_used: int = 0
|
|
45
|
+
cost_usd: float = 0.0
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class NodeExecutionLog(BaseModel):
|
|
49
|
+
"""Log wykonania pojedynczego node'a w runie."""
|
|
50
|
+
|
|
51
|
+
model_config = ConfigDict(extra="forbid")
|
|
52
|
+
|
|
53
|
+
id: str
|
|
54
|
+
run_id: str
|
|
55
|
+
node_id: str
|
|
56
|
+
agent_id: str
|
|
57
|
+
runtime_id: str
|
|
58
|
+
|
|
59
|
+
started_at: datetime
|
|
60
|
+
ended_at: datetime | None = None
|
|
61
|
+
|
|
62
|
+
prompt_xml: str
|
|
63
|
+
stdout: str = ""
|
|
64
|
+
stderr: str = ""
|
|
65
|
+
output_json: dict[str, Any] | None = None
|
|
66
|
+
|
|
67
|
+
tokens_used: int = 0
|
|
68
|
+
cost_usd: float = 0.0
|
|
69
|
+
duration_ms: int = 0
|
|
70
|
+
|
|
71
|
+
status: NodeStatus
|
|
72
|
+
error_message: str | None = None
|
|
73
|
+
extra_data: dict[str, Any] | None = Field(
|
|
74
|
+
default=None,
|
|
75
|
+
description=(
|
|
76
|
+
"Adapter-supplied audit metadata, populated from ``result.structured['audit']`` "
|
|
77
|
+
"when a python-func node returns ``__audit`` in its output dict. "
|
|
78
|
+
"Shape is intentionally open — the engine does not validate or interpret keys. "
|
|
79
|
+
"Common keys written by python-func adapters: "
|
|
80
|
+
"``github_user`` (str), ``section`` (str), "
|
|
81
|
+
"``content_before`` / ``content_after`` (str, truncated diffs), "
|
|
82
|
+
"``operation`` (str, e.g. 'create_branch' / 'push' / 'create_pr'), "
|
|
83
|
+
"``commit_sha`` (str), ``tokens_used`` (int), ``cost_usd`` (float). "
|
|
84
|
+
"Consumers (API, dashboard) should treat every key as optional. "
|
|
85
|
+
"``None`` for CLI/LLM adapter nodes that do not produce audit data."
|
|
86
|
+
),
|
|
87
|
+
)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Literal, Protocol, runtime_checkable
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
6
|
+
|
|
7
|
+
RuntimeKind = Literal["cli", "api", "shell", "http"]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class RuntimeContext(BaseModel):
|
|
11
|
+
model_config = ConfigDict(extra="forbid")
|
|
12
|
+
input_fields: dict[str, Any] = Field(default_factory=dict)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class RuntimeTask(BaseModel):
|
|
16
|
+
model_config = ConfigDict(extra="forbid")
|
|
17
|
+
|
|
18
|
+
execution_id: str
|
|
19
|
+
prompt_xml: str
|
|
20
|
+
working_directory: str
|
|
21
|
+
allowed_files: list[str] | None = None
|
|
22
|
+
allowed_tools: list[str] | None = None
|
|
23
|
+
timeout_ms: int | None = 60_000
|
|
24
|
+
budget_usd: float | None = None
|
|
25
|
+
runtime_config: dict[str, Any] = Field(default_factory=dict)
|
|
26
|
+
context: RuntimeContext = Field(default_factory=RuntimeContext)
|
|
27
|
+
# Project-scoped env overlay (#65). Subprocess-spawning adapters
|
|
28
|
+
# layer these onto the inherited engine env, *before* per-agent
|
|
29
|
+
# ``runtime_config.env`` is applied — so agent overrides still win,
|
|
30
|
+
# project env still beats engine env, engine env is the base.
|
|
31
|
+
# Empty dict for ad-hoc runs and api-call style adapters that
|
|
32
|
+
# don't spawn subprocesses.
|
|
33
|
+
project_env_vars: dict[str, str] = Field(default_factory=dict)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class RuntimeResult(BaseModel):
|
|
37
|
+
model_config = ConfigDict(extra="forbid")
|
|
38
|
+
|
|
39
|
+
success: bool
|
|
40
|
+
output: str
|
|
41
|
+
structured: dict[str, Any] | None = None
|
|
42
|
+
files_changed: list[str] = Field(default_factory=list)
|
|
43
|
+
tokens_used: int | None = None
|
|
44
|
+
cost_usd: float | None = None
|
|
45
|
+
duration_ms: int = 0
|
|
46
|
+
errors: list[str] = Field(default_factory=list)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class HealthStatus(BaseModel):
|
|
50
|
+
model_config = ConfigDict(extra="forbid")
|
|
51
|
+
|
|
52
|
+
available: bool
|
|
53
|
+
version: str | None = None
|
|
54
|
+
missing: list[str] | None = None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@runtime_checkable
|
|
58
|
+
class RuntimeAdapter(Protocol):
|
|
59
|
+
"""Protocol dla runtime adapterów — implementujemy w packages/runtimes."""
|
|
60
|
+
|
|
61
|
+
id: str
|
|
62
|
+
display_name: str
|
|
63
|
+
kind: RuntimeKind
|
|
64
|
+
|
|
65
|
+
async def healthcheck(self) -> HealthStatus: ...
|
|
66
|
+
|
|
67
|
+
async def execute(self, task: RuntimeTask) -> RuntimeResult: ...
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Any, Literal
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
7
|
+
|
|
8
|
+
VerificationStatus = Literal["pending", "approved", "rejected"]
|
|
9
|
+
FinalStatus = Literal["running", "success", "failed", "aborted", "paused"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PipelineState(BaseModel):
|
|
13
|
+
"""Jawny, typowany stan pipeline'u — single source of truth."""
|
|
14
|
+
|
|
15
|
+
model_config = ConfigDict(extra="forbid")
|
|
16
|
+
|
|
17
|
+
# ---- METADATA / CONTROL ----
|
|
18
|
+
run_id: str
|
|
19
|
+
repo: str
|
|
20
|
+
branch: str
|
|
21
|
+
commit_sha: str | None = None
|
|
22
|
+
description: str | None = None
|
|
23
|
+
|
|
24
|
+
# ---- TASK SELECTION ----
|
|
25
|
+
available_issues: list[dict[str, Any]] = Field(default_factory=list)
|
|
26
|
+
selected_issue_ids: list[int] = Field(default_factory=list)
|
|
27
|
+
|
|
28
|
+
# ---- TEST GENERATION ----
|
|
29
|
+
tests_generated: bool = False
|
|
30
|
+
test_files: list[str] = Field(default_factory=list)
|
|
31
|
+
test_generation_errors: list[str] = Field(default_factory=list)
|
|
32
|
+
|
|
33
|
+
# ---- EXECUTION LOOP ----
|
|
34
|
+
max_attempts: int = 3
|
|
35
|
+
attempt: int = 0
|
|
36
|
+
tests_passed: bool = False
|
|
37
|
+
last_test_output: str = ""
|
|
38
|
+
|
|
39
|
+
# ---- IMPLEMENTATION ----
|
|
40
|
+
modified_files: list[str] = Field(default_factory=list)
|
|
41
|
+
implementation_notes: str | None = None
|
|
42
|
+
|
|
43
|
+
# ---- VERIFICATION ----
|
|
44
|
+
verification_status: VerificationStatus = "pending"
|
|
45
|
+
verification_reason: str | None = None
|
|
46
|
+
|
|
47
|
+
# ---- FINAL OUTPUT ----
|
|
48
|
+
final_status: FinalStatus = "running"
|
|
49
|
+
|
|
50
|
+
# ---- EXTENSIONS ----
|
|
51
|
+
extensions: dict[str, Any] = Field(
|
|
52
|
+
default_factory=dict,
|
|
53
|
+
description=(
|
|
54
|
+
"Per-pipeline extra state. Keys are pipeline-defined. "
|
|
55
|
+
"Values must be JSON-serializable. "
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class StateSnapshot(BaseModel):
|
|
61
|
+
"""Snapshot stanu po wykonaniu konkretnego node'a."""
|
|
62
|
+
|
|
63
|
+
model_config = ConfigDict(extra="forbid")
|
|
64
|
+
|
|
65
|
+
id: str
|
|
66
|
+
run_id: str
|
|
67
|
+
node_id: str
|
|
68
|
+
timestamp: datetime
|
|
69
|
+
state: PipelineState
|