When configuration can vary by user/environment, resolve it deterministically (following documented precedence), keep it configurable instead of hardcoded, and apply it dynamically if it may change at runtime.
Practical rules:
/settings), don’t decide behavior once during session creation—re-evaluate from the session settings manager when converting requests.Example (dynamic blockImages handling):
// Bad: captures blockImages once at session creation
// const convertToLlmWithBlockImages = blockImages ? filteredConvertToLlm : convertToLlm;
// Good: decide per-use from session manager
function makeConvertToLlm(sessionManager: { getBlockImages(): boolean }) {
return async function convertToLlm(...args: unknown[]) {
const shouldBlock = sessionManager.getBlockImages();
if (shouldBlock) return convertToLlmFilteredImages(...args);
return convertToLlmUnfilteredImages(...args);
};
}
Following this standard prevents stale configuration behavior, reduces deployment brittleness, and makes feature flags and user settings reliably predictable.