Apply empty-mode environment_context stripping to a system message dict. The caller passes the already-normalized wire payload (a ``dict`` with ``mode`` / ``content`` / ``sections``) or ``None``. The caller's value wins if it already specifies an ``environment_context`` override.
(
mode: CopilotClientMode | None,
supplied: Any,
)
| 140 | |
| 141 | |
| 142 | def _system_message_for_mode( |
| 143 | mode: CopilotClientMode | None, |
| 144 | supplied: Any, |
| 145 | ) -> Any: |
| 146 | """Apply empty-mode environment_context stripping to a system message dict. |
| 147 | |
| 148 | The caller passes the already-normalized wire payload (a ``dict`` with |
| 149 | ``mode`` / ``content`` / ``sections``) or ``None``. The caller's value |
| 150 | wins if it already specifies an ``environment_context`` override. |
| 151 | """ |
| 152 | if mode != "empty": |
| 153 | return supplied |
| 154 | remove_action = {"action": "remove"} |
| 155 | if supplied is None: |
| 156 | return {"mode": "customize", "sections": {"environment_context": remove_action}} |
| 157 | supplied_mode = supplied.get("mode", "") |
| 158 | if supplied_mode == "replace": |
| 159 | return supplied |
| 160 | if supplied_mode == "customize": |
| 161 | sections = supplied.get("sections") or {} |
| 162 | if "environment_context" in sections: |
| 163 | return supplied |
| 164 | merged = {**supplied, "sections": {**sections, "environment_context": remove_action}} |
| 165 | return merged |
| 166 | # append (or unspecified): promote to customize so we can also strip |
| 167 | # environment_context. The runtime appends ``content`` in both modes, so |
| 168 | # the caller's text is preserved verbatim. |
| 169 | out: dict[str, Any] = { |
| 170 | "mode": "customize", |
| 171 | "sections": {"environment_context": remove_action}, |
| 172 | } |
| 173 | if "content" in supplied and supplied["content"] is not None: |
| 174 | out["content"] = supplied["content"] |
| 175 | return out |
| 176 | |
| 177 | |
| 178 | def _empty_mode_bool_default( |
searching dependent graphs…