Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions limacharlie/sdk/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def add_note(
content: str,
note_type: str | None = None,
is_public: bool | None = None,
ai_session_id: str | None = None,
) -> dict[str, Any]:
"""Add a note to a case.

Expand All @@ -204,12 +205,19 @@ def add_note(
escalation, handoff, to_stakeholder, from_stakeholder).
is_public: Whether the note is visible to stakeholders
(default false).
ai_session_id: Originating AI session id, for cost attribution.
When omitted, it is read from the ``LC_AI_SESSION_ID``
environment variable (set by the ai-sessions runner), so notes
written by an AI agent are attributed automatically.
"""
body: dict[str, Any] = {"content": content}
if note_type:
body["note_type"] = note_type
if is_public is not None:
body["is_public"] = is_public
session_id = ai_session_id or os.environ.get("LC_AI_SESSION_ID")
if session_id:
body["ai_session_id"] = session_id
return self._request(
"POST",
f"cases/{case_number}/notes",
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/test_sdk_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,33 @@ def test_is_public_none_excluded(self, cases, mock_org):
body = _extract_body(mock_org)
assert "is_public" not in body

def test_ai_session_id_explicit(self, cases, mock_org):
mock_org.client.request.return_value = {}
cases.add_note(42, "AI findings", ai_session_id="sess-1")
body = _extract_body(mock_org)
assert body["ai_session_id"] == "sess-1"

def test_ai_session_id_from_env(self, cases, mock_org, monkeypatch):
monkeypatch.setenv("LC_AI_SESSION_ID", "sess-env")
mock_org.client.request.return_value = {}
cases.add_note(42, "AI findings")
body = _extract_body(mock_org)
assert body["ai_session_id"] == "sess-env"

def test_explicit_ai_session_id_overrides_env(self, cases, mock_org, monkeypatch):
monkeypatch.setenv("LC_AI_SESSION_ID", "sess-env")
mock_org.client.request.return_value = {}
cases.add_note(42, "AI findings", ai_session_id="sess-explicit")
body = _extract_body(mock_org)
assert body["ai_session_id"] == "sess-explicit"

def test_no_ai_session_id_when_unset(self, cases, mock_org, monkeypatch):
monkeypatch.delenv("LC_AI_SESSION_ID", raising=False)
mock_org.client.request.return_value = {}
cases.add_note(42, "Note text")
body = _extract_body(mock_org)
assert "ai_session_id" not in body


class TestUpdateNoteVisibility:
def test_set_public(self, cases, mock_org):
Expand Down