-
Notifications
You must be signed in to change notification settings - Fork 6
CLI: Update SDK to v0.30.0 and add new flags #102
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
base: main
Are you sure you want to change the base?
Changes from all commits
899caee
a6ea28d
440c557
91545de
2658014
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,11 +35,20 @@ var invocationHistoryCmd = &cobra.Command{ | |
| RunE: runInvocationHistory, | ||
| } | ||
|
|
||
| var invocationBrowsersCmd = &cobra.Command{ | ||
| Use: "browsers <invocation_id>", | ||
| Short: "List browser sessions for an invocation", | ||
| Long: "List all active browser sessions created within a specific invocation.", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: runInvocationBrowsers, | ||
| } | ||
|
|
||
| func init() { | ||
| invokeCmd.Flags().StringP("version", "v", "latest", "Specify a version of the app to invoke (optional, defaults to 'latest')") | ||
| invokeCmd.Flags().StringP("payload", "p", "", "JSON payload for the invocation (optional)") | ||
| invokeCmd.Flags().StringP("payload-file", "f", "", "Path to a JSON file containing the payload (use '-' for stdin)") | ||
| invokeCmd.Flags().BoolP("sync", "s", false, "Invoke synchronously (default false). A synchronous invocation will open a long-lived HTTP POST to the Kernel API to wait for the invocation to complete. This will time out after 60 seconds, so only use this option if you expect your invocation to complete in less than 60 seconds. The default is to invoke asynchronously, in which case the CLI will open an SSE connection to the Kernel API after submitting the invocation and wait for the invocation to complete.") | ||
| invokeCmd.Flags().Int64("async-timeout", 0, "Timeout in seconds for async invocations (min 10, max 3600). Only applies when async mode is used.") | ||
| invokeCmd.Flags().StringP("output", "o", "", "Output format: json for JSONL streaming output") | ||
| invokeCmd.MarkFlagsMutuallyExclusive("payload", "payload-file") | ||
|
|
||
|
|
@@ -48,6 +57,9 @@ func init() { | |
| invocationHistoryCmd.Flags().String("version", "", "Filter by invocation version") | ||
| invocationHistoryCmd.Flags().StringP("output", "o", "", "Output format: json for raw API response") | ||
| invokeCmd.AddCommand(invocationHistoryCmd) | ||
|
|
||
| invocationBrowsersCmd.Flags().StringP("output", "o", "", "Output format: json for raw API response") | ||
| invokeCmd.AddCommand(invocationBrowsersCmd) | ||
| } | ||
|
|
||
| func runInvoke(cmd *cobra.Command, args []string) error { | ||
|
|
@@ -70,12 +82,16 @@ func runInvoke(cmd *cobra.Command, args []string) error { | |
| return fmt.Errorf("version cannot be an empty string") | ||
| } | ||
| isSync, _ := cmd.Flags().GetBool("sync") | ||
| asyncTimeout, _ := cmd.Flags().GetInt64("async-timeout") | ||
| params := kernel.InvocationNewParams{ | ||
| AppName: appName, | ||
| ActionName: actionName, | ||
| Version: version, | ||
| Async: kernel.Opt(!isSync), | ||
| } | ||
| if asyncTimeout > 0 { | ||
| params.AsyncTimeoutSeconds = kernel.Opt(asyncTimeout) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing validation for async-timeout documented boundsLow Severity The Additional Locations (1) |
||
|
|
||
| payloadStr, hasPayload, err := getPayload(cmd) | ||
| if err != nil { | ||
|
|
@@ -428,3 +444,56 @@ func runInvocationHistory(cmd *cobra.Command, args []string) error { | |
| } | ||
| return nil | ||
| } | ||
|
|
||
| func runInvocationBrowsers(cmd *cobra.Command, args []string) error { | ||
| client := getKernelClient(cmd) | ||
| invocationID := args[0] | ||
| output, _ := cmd.Flags().GetString("output") | ||
|
|
||
| if output != "" && output != "json" { | ||
| return fmt.Errorf("unsupported --output value: use 'json'") | ||
| } | ||
|
|
||
| resp, err := client.Invocations.ListBrowsers(cmd.Context(), invocationID) | ||
| if err != nil { | ||
| pterm.Error.Printf("Failed to list browsers for invocation: %v\n", err) | ||
| return nil | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. API error returns success exit code in new commandMedium Severity The new |
||
|
|
||
| if output == "json" { | ||
| if len(resp.Browsers) == 0 { | ||
| fmt.Println("[]") | ||
| return nil | ||
| } | ||
| return util.PrintPrettyJSONSlice(resp.Browsers) | ||
| } | ||
|
|
||
| if len(resp.Browsers) == 0 { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing nil check on API response causes potential panicMedium Severity The |
||
| pterm.Info.Printf("No active browsers found for invocation %s\n", invocationID) | ||
| return nil | ||
| } | ||
|
|
||
| table := pterm.TableData{{"Session ID", "Created At", "Headless", "Stealth", "Timeout", "CDP WS URL", "Live View URL"}} | ||
|
|
||
| for _, browser := range resp.Browsers { | ||
| created := util.FormatLocal(browser.CreatedAt) | ||
| liveView := browser.BrowserLiveViewURL | ||
| if liveView == "" { | ||
| liveView = "-" | ||
| } | ||
|
|
||
| table = append(table, []string{ | ||
| browser.SessionID, | ||
| created, | ||
| fmt.Sprintf("%v", browser.Headless), | ||
| fmt.Sprintf("%v", browser.Stealth), | ||
| fmt.Sprintf("%d", browser.TimeoutSeconds), | ||
| truncateURL(browser.CdpWsURL, 40), | ||
| truncateURL(liveView, 40), | ||
| }) | ||
| } | ||
|
|
||
| pterm.Info.Printf("Browsers for invocation %s:\n", invocationID) | ||
| pterm.DefaultTable.WithHasHeader().WithData(table).Render() | ||
| return nil | ||
| } | ||


Uh oh!
There was an error while loading. Please reload this page.