-
Notifications
You must be signed in to change notification settings - Fork 9
feat: add named profile support #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Mukil Loganathan (langchain-infra)
wants to merge
5
commits into
feature/api-command
from
feature/profiles
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3a93e1e
feat: add `langsmith api` command for browsing endpoints and making a…
langchain-infra 6471b70
refactor: export cmd helpers (GetAPIKey, GetAPIURL, etc.)
langchain-infra c1317ba
fix: handle full URLs with different host in api request
langchain-infra dfb1e28
feat: add named profile support
langchain-infra c7cb8c7
feat: add bearer_token field to profile config
langchain-infra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // NewCmd creates the top-level `langsmith api` command. | ||
| func NewCmd() *cobra.Command { | ||
| var ( | ||
| body string | ||
| headers []string | ||
| include bool | ||
| ) | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "api", | ||
| Short: "Browse API endpoints and make authenticated requests", | ||
| Long: `Browse LangSmith API endpoints and make authenticated HTTP requests. | ||
|
|
||
| Browse endpoints: | ||
| langsmith api ls List all endpoints | ||
| langsmith api ls --tag datasets Filter by tag | ||
| langsmith api ls --search "create" Search endpoints | ||
| langsmith api info GET sessions Show endpoint details | ||
|
|
||
| Make requests: | ||
| langsmith api GET sessions?limit=5 | ||
| langsmith api POST runs/query --body '{"session_id":"abc"}' | ||
| langsmith api DELETE sessions/abc-123 | ||
| langsmith api POST datasets --body @body.json | ||
| echo '{"name":"x"}' | langsmith api POST sessions --body @- | ||
| langsmith api GET sessions --include`, | ||
| Args: cobra.ArbitraryArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if len(args) < 2 { | ||
| return cmd.Help() | ||
| } | ||
|
|
||
| method := strings.ToUpper(args[0]) | ||
| if !isHTTPMethod(method) { | ||
| return fmt.Errorf("unknown subcommand or HTTP method: %q\nRun 'langsmith api --help' for usage", args[0]) | ||
| } | ||
|
|
||
| path := args[1] | ||
|
|
||
| apiKey := resolveAPIKey(cmd) | ||
| if apiKey == "" { | ||
| return fmt.Errorf("LANGSMITH_API_KEY not set") | ||
| } | ||
| apiURL := resolveAPIURL(cmd) | ||
|
|
||
| w := cmd.OutOrStdout() | ||
| statusCode, err := runRequest(apiURL, apiKey, method, path, body, headers, include, w) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if statusCode >= 400 { | ||
| os.Exit(1) | ||
| } | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| // Flags for request mode | ||
| cmd.Flags().StringVar(&body, "body", "", `Request body (JSON string, @file, or @- for stdin)`) | ||
| cmd.Flags().StringArrayVarP(&headers, "header", "H", nil, "Additional headers (Key:Value, repeatable)") | ||
| cmd.Flags().BoolVarP(&include, "include", "i", false, "Include HTTP response headers in output") | ||
|
|
||
| // These persistent flags mirror root's so the api command works standalone | ||
| // in tests. When registered under root, cobra's flag inheritance means | ||
| // the root's values take precedence when set via CLI. | ||
| cmd.PersistentFlags().String("api-key", "", "LangSmith API key [env: LANGSMITH_API_KEY]") | ||
| cmd.PersistentFlags().String("api-url", "", "LangSmith API URL [env: LANGSMITH_ENDPOINT]") | ||
| cmd.PersistentFlags().String("format", "json", "Output format: json or pretty") | ||
|
|
||
| cmd.AddCommand(newLsCmd()) | ||
| cmd.AddCommand(newInfoCmd()) | ||
|
|
||
| return cmd | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Test
TestRawRequest_NoWorkspaceHeaderWhenUnsetis environment-dependent after removingt.SetenvThe removal of
t.Setenv("LANGSMITH_WORKSPACE_ID", "")fromTestRawRequest_NoWorkspaceHeaderWhenUnsetmakes the test fail if the developer or CI environment hasLANGSMITH_WORKSPACE_IDset to a non-empty value. Theclient.New()function (internal/client/client.go:50) andrawRequest()(internal/client/client.go:162) both read this env var and will set thex-tenant-idheader, 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.