feat: add named profile support#52
feat: add named profile support#52Mukil Loganathan (langchain-infra) wants to merge 5 commits intofeature/api-commandfrom
Conversation
…uthenticated requests Adds a new `langsmith api` command inspired by `gh api`, `vercel api`, and `az rest`. Three modes: browse endpoints via OpenAPI spec, inspect endpoint details, and make authenticated HTTP requests with automatic header injection. New commands: - `langsmith api ls` — list all API endpoints with --tag and --search filters - `langsmith api info METHOD path` — show endpoint params, request body, response schema - `langsmith api METHOD path` — make authenticated requests with --body, -H, --include OpenAPI spec is fetched from /openapi.json and cached locally with 24h TTL.
Export the shared helper functions from the cmd package so they can be used by sub-packages. The api sub-package still uses cobra flag inheritance (different mechanism) due to circular import constraints, but the rest of the codebase now uses the exported names consistently.
When a full URL to a different host is passed (e.g., https://other.host/foo), use an empty-base client so RawDo doesn't prepend the default apiURL. Fixes malformed URL bug reported in PR review.
d907ae8 to
bd57e1b
Compare
Add profile management to the CLI, allowing users to store and switch between multiple LangSmith configurations (API key, endpoint, workspace) via ~/.langsmith/config.toml. New subcommands: langsmith profile create/list/show/delete/use New flags: --profile, LANGSMITH_PROFILE env var Resolution priority: flags > env vars > named profile > default profile. Includes internal/config package for TOML config read/write and comprehensive test coverage across config, profile commands, and resolution logic.
bd57e1b to
dfb1e28
Compare
| func TestRawRequest_NoWorkspaceHeaderWhenUnset(t *testing.T) { | ||
| t.Setenv("LANGSMITH_WORKSPACE_ID", "") | ||
|
|
||
| ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if got := r.Header.Get("x-tenant-id"); got != "" { | ||
| t.Errorf("expected empty x-tenant-id, got %q", got) |
There was a problem hiding this comment.
🟡 Test TestRawRequest_NoWorkspaceHeaderWhenUnset is environment-dependent after removing t.Setenv
The removal of t.Setenv("LANGSMITH_WORKSPACE_ID", "") from TestRawRequest_NoWorkspaceHeaderWhenUnset makes the test fail if the developer or CI environment has LANGSMITH_WORKSPACE_ID set to a non-empty value. The client.New() function (internal/client/client.go:50) and rawRequest() (internal/client/client.go:162) both read this env var and will set the x-tenant-id header, causing the assertion at line 243 to fail. The previous code explicitly cleared this variable, ensuring the test was self-contained regardless of the environment.
(Refers to lines 241-253)
Was this helpful? React with 👍 or 👎 to provide feedback.
1225f28 to
54d5771
Compare
Summary
langsmith profilesubcommand group (create,list,show,delete,use) for managing named CLI profiles~/.langsmith/config.toml(TOML format)--profileflag andLANGSMITH_PROFILEenv var for selecting active profileclient.Newnow accepts workspace ID as a parameter instead of reading env directlyUsage
Config file format (
~/.langsmith/config.toml)Test plan
GetAPIKey/GetAPIURL/GetWorkspaceIDgo test ./...)golangci-lint run)