eca icon indicating copy to clipboard operation
eca copied to clipboard

FEATURE: variable reference

Open sg-qwt opened this issue 1 year ago • 9 comments

right now in eca config we have:

urlEnv	string	Environment variable name containing the API URL	No*
url	string	Direct API URL (use instead of urlEnv)	No*
keyEnv	string	Environment variable name containing the API key	No*
keyRc	string	Lookup specification to read the API key from Unix RC [credential files](https://eca.dev/models/#credential-file-authentication)	No*
key	string	Direct API key (use instead of keyEnv)	No*

They are limit to provider config, and is probably duplicated and inflexible, it'd be good if we can migrate to a variable reference model for example:

{
  "providers": {
    "openai": {
      "key": "${env:MY_OPENAI_KEY}"
      }
    }
}
{
  "providers": {
    "openai": {
      "key": "${keyRc:api.openai.com}"
      }
    }
}
{
  "providers": {
    "openai": {
      "key": "myplaintextkey"
      }
    }
}

notice we only have key as name, and it'd be more flexible to add more type of variable references later. syntax is taken from https://code.visualstudio.com/docs/reference/variables-reference

Another benefit would be to reuse the stuff in other section of configs: for example in mcp server I can have this without worry about put plain cred in config.

{
  "mcpServers": {
    "brave-search": {
      "command": "npx",
      "args": ["-y", "@brave/brave-search-mcp-server", "--transport", "http"],
      "env": {
        "BRAVE_API_KEY": "${keyRc:brave.com}",
        "SOMTHING": "{env:MY_ANOTHER_ENV}",
      }
    }
  }
}

sg-qwt avatar Nov 07 '25 22:11 sg-qwt

Interesting, I never saw that standard before, I wonder if that adds a new layer of complexity to user, what before was just json with fields and values, now have values with special values. I liked the idea of extending to other fields too tho, so not sure

Any thoughts @editor-code-assistant/maintainers ?

ericdallo avatar Nov 07 '25 22:11 ericdallo

Hey @sg-qwt I started to support that! But we do support now for every string value in config, for now only ${file:path} and ${env:value}, but it's flexible to add others like keyRc!

ericdallo avatar Nov 27 '25 13:11 ericdallo

I will update configs deprecating the ones that mention fileor env and leave documentation only pointing to this new style

ericdallo avatar Nov 27 '25 13:11 ericdallo

@ericdallo I think you missed two parse-dynamic-string-values in L216 and L224 Or wrap that into one function in case forget

Image

sg-qwt avatar Nov 27 '25 15:11 sg-qwt

Not sure I got, those lines are just the path to the file, it's used in functions that then use the parse-dynamic, am I missing something?

ericdallo avatar Nov 27 '25 15:11 ericdallo

Also, I don't want to wrap in the final config function as it's not memoized, maybe a improvement for the future to memorize the final config

ericdallo avatar Nov 27 '25 15:11 ericdallo

Does dynamic string get parsed with custom config file or ECA_CONFIG? Looks like you only parsed dynamic string in global/local config? That's what I understand from the code, maybe I'm wrong.

sg-qwt avatar Nov 27 '25 15:11 sg-qwt

Ah got it, yeah, I missed those 2 places, will do!

ericdallo avatar Nov 27 '25 15:11 ericdallo

Done! also added support for ${netrc:...}, thank you for the help and suggestion

ericdallo avatar Nov 27 '25 16:11 ericdallo