Skip to content

Commit 452da1a

Browse files
CLI: Update SDK to v0.44.0 and add clipboard commands
- Updated kernel-go-sdk to v0.44.0 (b03de99) - Added `browsers computer read-clipboard <id>` command - Added `browsers computer write-clipboard <id> --text <text>` command Tested: - browsers computer write-clipboard <id> --text "test" - browsers computer read-clipboard <id> - browsers computer read-clipboard <id> -o json Made-with: Cursor
1 parent 5d4e3bc commit 452da1a

3 files changed

Lines changed: 84 additions & 4 deletions

File tree

cmd/browsers.go

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ type BrowserComputerService interface {
9999
GetMousePosition(ctx context.Context, id string, opts ...option.RequestOption) (res *kernel.BrowserComputerGetMousePositionResponse, err error)
100100
MoveMouse(ctx context.Context, id string, body kernel.BrowserComputerMoveMouseParams, opts ...option.RequestOption) (err error)
101101
PressKey(ctx context.Context, id string, body kernel.BrowserComputerPressKeyParams, opts ...option.RequestOption) (err error)
102+
ReadClipboard(ctx context.Context, id string, opts ...option.RequestOption) (res *kernel.BrowserComputerReadClipboardResponse, err error)
102103
Scroll(ctx context.Context, id string, body kernel.BrowserComputerScrollParams, opts ...option.RequestOption) (err error)
103104
SetCursorVisibility(ctx context.Context, id string, body kernel.BrowserComputerSetCursorVisibilityParams, opts ...option.RequestOption) (res *kernel.BrowserComputerSetCursorVisibilityResponse, err error)
104105
TypeText(ctx context.Context, id string, body kernel.BrowserComputerTypeTextParams, opts ...option.RequestOption) (err error)
106+
WriteClipboard(ctx context.Context, id string, body kernel.BrowserComputerWriteClipboardParams, opts ...option.RequestOption) (err error)
105107
}
106108

107109
// BoolFlag captures whether a boolean flag was set explicitly and its value.
@@ -784,6 +786,16 @@ type BrowsersComputerBatchInput struct {
784786
ActionsJSON string
785787
}
786788

789+
type BrowsersComputerReadClipboardInput struct {
790+
Identifier string
791+
Output string
792+
}
793+
794+
type BrowsersComputerWriteClipboardInput struct {
795+
Identifier string
796+
Text string
797+
}
798+
787799
func (b BrowsersCmd) ComputerClickMouse(ctx context.Context, in BrowsersComputerClickMouseInput) error {
788800
if b.computer == nil {
789801
pterm.Error.Println("computer service not available")
@@ -1063,6 +1075,47 @@ func (b BrowsersCmd) ComputerBatch(ctx context.Context, in BrowsersComputerBatch
10631075
return nil
10641076
}
10651077

1078+
func (b BrowsersCmd) ComputerReadClipboard(ctx context.Context, in BrowsersComputerReadClipboardInput) error {
1079+
if in.Output != "" && in.Output != "json" {
1080+
return fmt.Errorf("unsupported --output value: use 'json'")
1081+
}
1082+
if b.computer == nil {
1083+
pterm.Error.Println("computer service not available")
1084+
return nil
1085+
}
1086+
br, err := b.browsers.Get(ctx, in.Identifier, kernel.BrowserGetParams{})
1087+
if err != nil {
1088+
return util.CleanedUpSdkError{Err: err}
1089+
}
1090+
res, err := b.computer.ReadClipboard(ctx, br.SessionID)
1091+
if err != nil {
1092+
return util.CleanedUpSdkError{Err: err}
1093+
}
1094+
if in.Output == "json" {
1095+
enc := json.NewEncoder(os.Stdout)
1096+
enc.SetIndent("", " ")
1097+
return enc.Encode(res)
1098+
}
1099+
fmt.Println(res.Text)
1100+
return nil
1101+
}
1102+
1103+
func (b BrowsersCmd) ComputerWriteClipboard(ctx context.Context, in BrowsersComputerWriteClipboardInput) error {
1104+
if b.computer == nil {
1105+
pterm.Error.Println("computer service not available")
1106+
return nil
1107+
}
1108+
br, err := b.browsers.Get(ctx, in.Identifier, kernel.BrowserGetParams{})
1109+
if err != nil {
1110+
return util.CleanedUpSdkError{Err: err}
1111+
}
1112+
if err := b.computer.WriteClipboard(ctx, br.SessionID, kernel.BrowserComputerWriteClipboardParams{Text: in.Text}); err != nil {
1113+
return util.CleanedUpSdkError{Err: err}
1114+
}
1115+
pterm.Success.Println("Text written to clipboard")
1116+
return nil
1117+
}
1118+
10661119
// Replays
10671120
type BrowsersReplaysListInput struct {
10681121
Identifier string
@@ -2415,7 +2468,16 @@ func init() {
24152468
computerBatch.Flags().String("actions", "", "JSON object with actions array (e.g., {\"actions\":[{\"type\":\"click_mouse\",...}]})")
24162469
_ = computerBatch.MarkFlagRequired("actions")
24172470

2418-
computerRoot.AddCommand(computerClick, computerMove, computerScreenshot, computerType, computerPressKey, computerScroll, computerDrag, computerSetCursor, computerGetMousePosition, computerBatch)
2471+
// computer read-clipboard
2472+
computerReadClipboard := &cobra.Command{Use: "read-clipboard <id>", Short: "Read text from the browser clipboard", Args: cobra.ExactArgs(1), RunE: runBrowsersComputerReadClipboard}
2473+
computerReadClipboard.Flags().StringP("output", "o", "", "Output format: json for raw API response")
2474+
2475+
// computer write-clipboard
2476+
computerWriteClipboard := &cobra.Command{Use: "write-clipboard <id>", Short: "Write text to the browser clipboard", Args: cobra.ExactArgs(1), RunE: runBrowsersComputerWriteClipboard}
2477+
computerWriteClipboard.Flags().String("text", "", "Text to write to the clipboard")
2478+
_ = computerWriteClipboard.MarkFlagRequired("text")
2479+
2480+
computerRoot.AddCommand(computerClick, computerMove, computerScreenshot, computerType, computerPressKey, computerScroll, computerDrag, computerSetCursor, computerGetMousePosition, computerBatch, computerReadClipboard, computerWriteClipboard)
24192481
browsersCmd.AddCommand(computerRoot)
24202482

24212483
// playwright
@@ -3159,6 +3221,24 @@ func runBrowsersComputerBatch(cmd *cobra.Command, args []string) error {
31593221
return b.ComputerBatch(cmd.Context(), BrowsersComputerBatchInput{Identifier: args[0], ActionsJSON: actionsJSON})
31603222
}
31613223

3224+
func runBrowsersComputerReadClipboard(cmd *cobra.Command, args []string) error {
3225+
client := getKernelClient(cmd)
3226+
svc := client.Browsers
3227+
output, _ := cmd.Flags().GetString("output")
3228+
3229+
b := BrowsersCmd{browsers: &svc, computer: &svc.Computer}
3230+
return b.ComputerReadClipboard(cmd.Context(), BrowsersComputerReadClipboardInput{Identifier: args[0], Output: output})
3231+
}
3232+
3233+
func runBrowsersComputerWriteClipboard(cmd *cobra.Command, args []string) error {
3234+
client := getKernelClient(cmd)
3235+
svc := client.Browsers
3236+
text, _ := cmd.Flags().GetString("text")
3237+
3238+
b := BrowsersCmd{browsers: &svc, computer: &svc.Computer}
3239+
return b.ComputerWriteClipboard(cmd.Context(), BrowsersComputerWriteClipboardInput{Identifier: args[0], Text: text})
3240+
}
3241+
31623242
func truncateURL(url string, maxLen int) string {
31633243
if len(url) <= maxLen {
31643244
return url

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1
1010
github.com/golang-jwt/jwt/v5 v5.2.2
1111
github.com/joho/godotenv v1.5.1
12-
github.com/kernel/kernel-go-sdk v0.43.0
12+
github.com/kernel/kernel-go-sdk v0.44.0
1313
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
1414
github.com/pterm/pterm v0.12.80
1515
github.com/samber/lo v1.51.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
6464
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
6565
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
6666
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
67-
github.com/kernel/kernel-go-sdk v0.43.0 h1:sbvOy5rHomG+0GQfQ6Qeoli1ZXr8jl61bTporsBIzKk=
68-
github.com/kernel/kernel-go-sdk v0.43.0/go.mod h1:EeZzSuHZVeHKxKCPUzxou2bovNGhXaz0RXrSqKNf1AQ=
67+
github.com/kernel/kernel-go-sdk v0.44.0 h1:GQKq4UAcI4WBgl2dTXBuuiEBZE3WCSTxe1S96MDru6w=
68+
github.com/kernel/kernel-go-sdk v0.44.0/go.mod h1:EeZzSuHZVeHKxKCPUzxou2bovNGhXaz0RXrSqKNf1AQ=
6969
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
7070
github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
7171
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=

0 commit comments

Comments
 (0)