Skip to content

Commit e7ef705

Browse files
committed
use j2 file to template yaml (eek!)
instead of a long unreadable python string, we use a long unreadable j2 template. also had to change some escapings
1 parent ee07e3f commit e7ef705

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

backend/agent/interactem/agent/config.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import uuid
2+
from importlib import resources
23
from pathlib import Path
34

45
import netifaces
@@ -14,12 +15,13 @@
1415
)
1516
from interactem.core.nats.config import NatsMode, get_nats_config
1617

17-
from ._vector_template import VECTOR_CONFIG_TEMPLATE
18-
1918
logger = get_logger()
2019
VECTOR_NATS_CREDS_TARGET = "/nats.creds"
2120

2221

22+
def _load_vector_template() -> str:
23+
return resources.files(__package__).joinpath("templates/vector.yaml.j2").read_text(encoding="utf-8")
24+
2325
class Settings(BaseSettings):
2426
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
2527
ID: uuid.UUID = Field(default_factory=uuid.uuid4)
@@ -167,7 +169,7 @@ def generate_vector_config(self) -> Path | None:
167169
raise RuntimeError(
168170
f"Log directory {self.LOG_DIR} does not exist. Should not happen."
169171
)
170-
templ: Template = Template(VECTOR_CONFIG_TEMPLATE)
172+
templ: Template = Template(_load_vector_template())
171173
vector_yaml = templ.render(
172174
logs_dir=LOGS_DIR_IN_CONTAINER,
173175
agent_id=self.ID,
@@ -183,4 +185,3 @@ def generate_vector_config(self) -> Path | None:
183185

184186

185187
cfg = Settings() # pyright: ignore[reportCallIssue]
186-

backend/agent/interactem/agent/_vector_template.py renamed to backend/agent/interactem/agent/templates/vector.yaml.j2

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VECTOR_CONFIG_TEMPLATE = """sources:
1+
sources:
22
operator_logs:
33
type: file
44
include:
@@ -34,7 +34,7 @@
3434

3535
# Extract deployment_id and operator_id from the file path
3636
# Format: {{ logs_dir }}/<deployment_id>/op-<operator_id>.log
37-
file_match = parse_regex!(string!(.file), r'/(?P<deployment_id>[^/]+)/op-(?P<operator_id>[^.]+)\\.log$')
37+
file_match = parse_regex!(string!(.file), r'/(?P<deployment_id>[^/]+)/op-(?P<operator_id>[^.]+)\.log$')
3838
.deployment_id = file_match.deployment_id
3939
.operator_id = file_match.operator_id
4040
{% endraw %}
@@ -93,7 +93,7 @@
9393
.log_type = "agent"
9494

9595
# Strip ANSI color codes from the message
96-
.log = replace(string!(.message), r'\\x1b\\[[0-9;]*m', "")
96+
.log = replace(string!(.message), r'\x1b\[[0-9;]*m', "")
9797

9898
# Parse the Python logging format: ISO8601_TIMESTAMP - module.name - LEVEL - message
9999
# Example: 2025-10-08T13:02:06.547Z - module.name - INFO - message
@@ -204,4 +204,3 @@
204204
strategy: credentials_file
205205
credentials_file:
206206
path: "{{ nats_creds_path }}"
207-
"""

backend/agent/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ interactem-core = { path = "../core", editable = true }
3434

3535
[tool.poetry]
3636
packages = [{ include = "interactem" }]
37+
include = ["interactem/agent/templates/*.j2"]
38+
39+
[tool.uv.build-backend]
40+
source-include = ["interactem/agent/templates/*.j2"]
3741

3842
[tool.poetry.dependencies]
3943
interactem-core = {path = "../core", develop = true}

0 commit comments

Comments
 (0)