Skip to content

Commit

Permalink
[CLI] Add auth param to langgraph.json
Browse files Browse the repository at this point in the history
Preliminary for supporting custom auth.
  • Loading branch information
hinthornw authored Dec 14, 2024
2 parents 9291ae8 + 70f2efc commit cbe92e3
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 127 deletions.
21 changes: 12 additions & 9 deletions libs/cli/langgraph_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,16 +576,18 @@ def dev(
from langgraph_api.cli import run_server
except ImportError:
try:
import pkg_resources

pkg_resources.require("langgraph-api-inmem")
except (ImportError, pkg_resources.DistributionNotFound):
from importlib import util

if not util.find_spec("langgraph_api"):
raise click.UsageError(
"Required package 'langgraph-api' is not installed.\n"
"Please install it with:\n\n"
' pip install -U "langgraph-cli[inmem]"\n\n'
) from None
except ImportError:
raise click.UsageError(
"Required package 'langgraph-api-inmem' is not installed.\n"
"Please install it with:\n\n"
' pip install -U "langgraph-cli[inmem]"\n\n'
"If you're developing the langgraph-cli package locally, you can install in development mode:\n"
" pip install -e ."
"Could not verify package installation. Please ensure Python is up to date and\n"
"langgraph-cli is installed with the 'inmem' extra: pip install -U \"langgraph-cli[inmem]\""
) from None
raise click.UsageError(
"Could not import run_server. This likely means your installation is incomplete.\n"
Expand Down Expand Up @@ -614,6 +616,7 @@ def dev(
env=config_json.get("env"),
store=config_json.get("store"),
wait_for_client=wait_for_client,
auth=config_json.get("auth"),
)


Expand Down
16 changes: 16 additions & 0 deletions libs/cli/langgraph_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class StoreConfig(TypedDict, total=False):
"""Configuration for vector embeddings in store."""


class AuthConfig(TypedDict, total=False):
path: str
disable_studio_auth: bool


class Config(TypedDict, total=False):
python_version: str
node_version: Optional[str]
Expand All @@ -56,6 +61,7 @@ class Config(TypedDict, total=False):
graphs: dict[str, str]
env: Union[dict[str, str], str]
store: Optional[StoreConfig]
auth: Optional[AuthConfig]


def _parse_version(version_str: str) -> tuple[int, int]:
Expand Down Expand Up @@ -88,6 +94,7 @@ def validate_config(config: Config) -> Config:
"graphs": config.get("graphs", {}),
"env": config.get("env", {}),
"store": config.get("store"),
"auth": config.get("auth"),
}
if config.get("node_version")
else {
Expand All @@ -98,6 +105,7 @@ def validate_config(config: Config) -> Config:
"graphs": config.get("graphs", {}),
"env": config.get("env", {}),
"store": config.get("store"),
"auth": config.get("auth"),
}
)

Expand Down Expand Up @@ -400,6 +408,10 @@ def python_config_to_docker(config_path: pathlib.Path, config: Config, base_imag
ENV LANGGRAPH_STORE='{json.dumps(store_config)}'
"""
)
if (auth_config := config.get("auth")) is not None:
env_additional_config += f"""
ENV LANGGRAPH_AUTH='{json.dumps(auth_config)}'
"""
return f"""FROM {base_image}:{config['python_version']}
{os.linesep.join(config["dockerfile_lines"])}
Expand Down Expand Up @@ -445,6 +457,10 @@ def test_file(file_name):
ENV LANGGRAPH_STORE='{json.dumps(store_config)}'
"""
)
if (auth_config := config.get("auth")) is not None:
env_additional_config += f"""
ENV LANGGRAPH_AUTH='{json.dumps(auth_config)}'
"""
return f"""FROM {base_image}:{config['node_version']}
{os.linesep.join(config["dockerfile_lines"])}
Expand Down
Loading

0 comments on commit cbe92e3

Please sign in to comment.