codemie-cdk-python 0.1.0rc0__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.
Files changed (39) hide show
  1. codemie_cdk_python-0.1.0rc0.dist-info/METADATA +840 -0
  2. codemie_cdk_python-0.1.0rc0.dist-info/RECORD +39 -0
  3. codemie_cdk_python-0.1.0rc0.dist-info/WHEEL +4 -0
  4. codemie_cdk_python-0.1.0rc0.dist-info/entry_points.txt +3 -0
  5. codemie_iac/__init__.py +49 -0
  6. codemie_iac/cli/__init__.py +17 -0
  7. codemie_iac/cli/__main__.py +24 -0
  8. codemie_iac/cli/commands/__init__.py +17 -0
  9. codemie_iac/cli/commands/apply.py +119 -0
  10. codemie_iac/cli/commands/plan.py +72 -0
  11. codemie_iac/cli/documents.py +59 -0
  12. codemie_iac/cli/env_file.py +62 -0
  13. codemie_iac/cli/exit_status.py +80 -0
  14. codemie_iac/cli/main.py +118 -0
  15. codemie_iac/cli/render.py +206 -0
  16. codemie_iac/cli/target_config.py +230 -0
  17. codemie_iac/cli/token_client.py +42 -0
  18. codemie_iac/credentials.py +99 -0
  19. codemie_iac/envelope.py +188 -0
  20. codemie_iac/plan_apply/__init__.py +70 -0
  21. codemie_iac/plan_apply/bulk_create.py +561 -0
  22. codemie_iac/plan_apply/credentials.py +306 -0
  23. codemie_iac/plan_apply/errors.py +223 -0
  24. codemie_iac/plan_apply/field_policy.py +185 -0
  25. codemie_iac/plan_apply/guards.py +221 -0
  26. codemie_iac/plan_apply/kinds.py +815 -0
  27. codemie_iac/plan_apply/lookup.py +313 -0
  28. codemie_iac/plan_apply/ordering.py +177 -0
  29. codemie_iac/plan_apply/single_apply.py +751 -0
  30. codemie_iac/resolver.py +61 -0
  31. codemie_iac/schema.py +106 -0
  32. codemie_iac/serializer.py +64 -0
  33. codemie_iac/specs/__init__.py +13 -0
  34. codemie_iac/specs/assistant.py +509 -0
  35. codemie_iac/specs/category.py +36 -0
  36. codemie_iac/specs/datasource.py +595 -0
  37. codemie_iac/specs/integration.py +103 -0
  38. codemie_iac/specs/skill.py +51 -0
  39. codemie_iac/specs/workflow.py +154 -0
@@ -0,0 +1,51 @@
1
+ # Copyright 2026 EPAM Systems, Inc. ("EPAM")
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
+
15
+ """Spec that mirrors ``codemie_sdk.models.skill.SkillCreateRequest`` for IaC documents.
16
+
17
+ No credential-bearing fields exist on ``SkillCreateRequest``, so this is a
18
+ verbatim copy of its fields plus ``extra="forbid"``.
19
+ """
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field
22
+
23
+ from codemie_sdk.models.skill import SkillCreateRequest, SkillVisibility
24
+
25
+
26
+ class SkillSpec(BaseModel):
27
+ """Narrowed view of ``SkillCreateRequest``."""
28
+
29
+ model_config = ConfigDict(extra="forbid")
30
+
31
+ # Bounds mirror the platform's SkillCreateRequest; the SDK model does not
32
+ # enforce them, so without them a bad document only fails with a 422.
33
+ name: str = Field(..., pattern=r"^[a-z0-9][a-z0-9-]{1,62}[a-z0-9]$")
34
+ description: str = Field(..., min_length=10, max_length=1000)
35
+ content: str = Field(..., min_length=100)
36
+ project: str | None = None
37
+ visibility: SkillVisibility | None = SkillVisibility.PROJECT
38
+ categories: list[str] | None = Field(default_factory=list, max_length=3)
39
+ enabled_builtin_subagents: list[str] | None = None
40
+
41
+ @classmethod
42
+ def from_entity(cls, skill: SkillCreateRequest) -> "SkillSpec":
43
+ return cls(
44
+ name=skill.name,
45
+ description=skill.description,
46
+ content=skill.content,
47
+ project=skill.project,
48
+ visibility=skill.visibility,
49
+ categories=skill.categories,
50
+ enabled_builtin_subagents=skill.enabled_builtin_subagents,
51
+ )
@@ -0,0 +1,154 @@
1
+ # Copyright 2026 EPAM Systems, Inc. ("EPAM")
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
+
15
+ from typing import Any
16
+
17
+ from pydantic import BaseModel, ConfigDict, Field, ValidationError, model_validator
18
+
19
+ from codemie_sdk.builders.workflow.definition import WorkflowDefinition
20
+ from codemie_sdk.models.assistant import MCPServerConfig
21
+
22
+ from ..credentials import CredentialRef
23
+ from .assistant import MCPServerConfigSpec
24
+ from .datasource import _is_auth_config_secret, _literal_secret_paths
25
+ from .integration import CredentialRefEntry
26
+
27
+
28
+ class WorkflowSpec(BaseModel):
29
+ """Wraps a workflow's typed definition for IaC documents.
30
+
31
+ Embeds ``WorkflowDefinition`` directly rather than pointing at a sibling
32
+ file holding the backend's flattened ``yaml_config`` text (CR-011/CR-012,
33
+ superseded) -- a workflow document is one file, like every other kind.
34
+ ``name``/``description``/``shared``/``icon_url`` all live on ``workflow``
35
+ itself, so nothing is duplicated onto a sibling field that could drift
36
+ out of sync with it, and nothing (icon_url included) has a separate path
37
+ to be dropped from on round-trip.
38
+
39
+ This package never re-derives the inner shape: ``WorkflowDefinition`` is
40
+ the SDK's own typed model, unchanged. Deriving the backend's
41
+ flattened ``yaml_config`` string (``workflow.to_yaml_config()``) is left
42
+ to whichever future ``apply`` story actually talks to the platform --
43
+ nothing here pre-renders or stores that string.
44
+
45
+ ``credential_values`` (CR-007, reopened) narrows every credential-bearing
46
+ field an inline MCP server's ``config`` can carry -- not just
47
+ ``auth_token`` -- by reusing ``MCPServerConfigSpec.from_entity`` wholesale.
48
+ This only became possible once ``WorkflowMCPServer.config`` was retyped
49
+ from a bare ``dict`` to ``MCPServerConfig`` (the same type
50
+ ``MCPServerDetails.config`` already has on the backend and on
51
+ ``AssistantCreateRequest.mcp_servers[].config``) -- an earlier pass
52
+ left it untyped even though the model it needed already
53
+ lived in this same SDK package. With a real schema to narrow against,
54
+ there is no longer a residual gap: every field ``MCPServerConfigSpec``
55
+ recognizes elsewhere (``auth_token``, and any ``env``/``headers`` value
56
+ already shaped like a reference) is narrowed here too, the identical way.
57
+
58
+ That narrowing only runs inside ``from_entity``, though: ``workflow``'s
59
+ field type is ``WorkflowDefinition`` itself (unmodified, per the module
60
+ docstring above), so a ``WorkflowSpec`` built directly from model
61
+ instances, or loaded via ``from_yaml``/``validate_document``, has no
62
+ type-level guard on ``auth_token`` the way ``AssistantSpec``'s embedded
63
+ ``MCPServerConfigSpec.auth_token: CredentialRef | None`` does. The
64
+ ``_check_auth_tokens_are_reference_shaped`` validator below re-checks
65
+ that one invariant at the value level on every construction path, not
66
+ just ``from_entity``'s. ``env``/``headers``/``args``/``url``/
67
+ ``arguments``/``mcp_connect_url`` are deliberately not re-checked here:
68
+ per ``MCPServerConfigSpec``'s own docstring, those are a best-effort,
69
+ whole-value match, never enforced -- the same tolerance applies here for
70
+ the same reason, not a separate, inconsistent guarantee for this kind.
71
+ """
72
+
73
+ model_config = ConfigDict(extra="forbid")
74
+
75
+ workflow: WorkflowDefinition
76
+ credential_values: list[CredentialRefEntry] = Field(default_factory=list)
77
+ start_hint: str | None = None
78
+
79
+ @model_validator(mode="after")
80
+ def _check_auth_tokens_are_reference_shaped(self) -> "WorkflowSpec":
81
+ for assistant in self.workflow.assistants.values():
82
+ for server in assistant.mcp_servers:
83
+ self._check_auth_config(assistant, server)
84
+ token = server.config.auth_token if server.config else None
85
+ if token is None:
86
+ continue
87
+ try:
88
+ CredentialRef.model_validate(token)
89
+ except ValidationError as exc:
90
+ raise ValueError(
91
+ f"assistant {assistant.id!r} MCP server "
92
+ f"{server.name!r} has a literal auth_token; use a "
93
+ "CredentialRef-shaped reference (e.g. 'env:NAME') "
94
+ "instead of embedding the secret"
95
+ ) from exc
96
+ return self
97
+
98
+ @staticmethod
99
+ def _check_auth_config(assistant: Any, server: Any) -> None:
100
+ auth_config = server.config.auth_config if server.config else None
101
+ paths = list(
102
+ _literal_secret_paths(
103
+ auth_config or {}, "auth_config", is_secret=_is_auth_config_secret
104
+ )
105
+ )
106
+ if paths:
107
+ raise ValueError(
108
+ f"assistant {assistant.id!r} MCP server {server.name!r}: "
109
+ f"secret-looking setting(s) {', '.join(paths)} must be env: "
110
+ "references, not literal values"
111
+ )
112
+
113
+ @classmethod
114
+ def from_entity(cls, workflow: WorkflowDefinition) -> "WorkflowSpec":
115
+ """Rebuilds each touched layer via ``model_copy(update=...)`` rather
116
+ than mutating ``server``/``assistant``/``workflow`` in place.
117
+
118
+ ``WorkflowMCPServer``, ``WorkflowAssistant`` and ``WorkflowDefinition``
119
+ are frozen -- assigning to an existing instance's
120
+ field (e.g. ``server.config = ...``) raises. ``model_copy`` builds a
121
+ new instance with just the one field swapped and everything else
122
+ (``server.name``/``.enabled``/``.command``, the assistant's other
123
+ fields, the definition's other assistants/states) carried over
124
+ unchanged, without re-running validators a second time.
125
+ """
126
+ credential_values: list[CredentialRefEntry] = []
127
+ new_assistants: dict = {}
128
+ for assistant_key, assistant in workflow.assistants.items():
129
+ new_servers = []
130
+ for server in assistant.mcp_servers:
131
+ if server.config is None:
132
+ new_servers.append(server)
133
+ continue
134
+ narrowed_config = MCPServerConfigSpec.from_entity(
135
+ server.config,
136
+ assistant_name=f"{workflow.name}_{assistant_key}",
137
+ server_name=server.name,
138
+ )
139
+ if narrowed_config.auth_token is not None:
140
+ identifier = f"{workflow.name}_{assistant_key}_{server.name}"
141
+ credential_values.append(
142
+ CredentialRefEntry(
143
+ key=identifier, ref=narrowed_config.auth_token
144
+ )
145
+ )
146
+ new_config = MCPServerConfig.model_validate(
147
+ narrowed_config.model_dump(mode="json")
148
+ )
149
+ new_servers.append(server.model_copy(update={"config": new_config}))
150
+ new_assistants[assistant_key] = assistant.model_copy(
151
+ update={"mcp_servers": new_servers}
152
+ )
153
+ narrowed = workflow.model_copy(update={"assistants": new_assistants})
154
+ return cls(workflow=narrowed, credential_values=credential_values)