Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: add CLI command to list aibridge interceptions#19935

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
deansheather merged 2 commits intomainfrompb/aibridge-api-list-cli
Sep 26, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletionscli/exp.go
View file
Open in desktop

This file was deleted.

31 changes: 30 additions & 1 deletioncli/root.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -128,7 +128,6 @@ func (r *RootCmd) CoreSubcommands() []*serpent.Command {

// Hidden
r.connectCmd(),
r.expCmd(),
gitssh(),
r.support(),
r.vpnDaemon(),
Expand All@@ -137,15 +136,45 @@ func (r *RootCmd) CoreSubcommands() []*serpent.Command {
}
}

// AGPLExperimental returns all AGPL experimental subcommands.
func (r *RootCmd) AGPLExperimental() []*serpent.Command {
return []*serpent.Command{
r.scaletestCmd(),
r.errorExample(),
r.mcpCommand(),
r.promptExample(),
r.rptyCommand(),
r.tasksCommand(),
}
}

// AGPL returns all AGPL commands including any non-core commands that are
// duplicated in the Enterprise CLI.
func (r *RootCmd) AGPL() []*serpent.Command {
all := append(
r.CoreSubcommands(),
r.Server( /* Do not import coderd here. */ nil),
r.Provisioners(),
ExperimentalCommand(r.AGPLExperimental()),
)
return all
}

// ExperimentalCommand creates an experimental command that is hidden and has
// the given subcommands.
func ExperimentalCommand(subcommands []*serpent.Command) *serpent.Command {
cmd := &serpent.Command{
Use: "exp",
Short: "Internal commands for testing and experimentation. These are prone to breaking changes with no notice.",
Handler: func(i *serpent.Invocation) error {
return i.Command.HelpHandler(i)
},
Hidden: true,
Children: subcommands,
}
return cmd
}

// RunWithSubcommands runs the root command with the given subcommands.
// It is abstracted to enable the Enterprise code to add commands.
func (r *RootCmd) RunWithSubcommands(subcommands []*serpent.Command) {
Expand Down
2 changes: 1 addition & 1 deletiondocs/reference/cli/index.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

166 changes: 166 additions & 0 deletionsenterprise/cli/exp_aibridge.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
package cli

import (
"encoding/json"
"fmt"
"time"

"github.com/google/uuid"
"golang.org/x/xerrors"

"github.com/coder/coder/v2/codersdk"
"github.com/coder/serpent"
)

const maxInterceptionsLimit = 1000

func (r *RootCmd) aibridge() *serpent.Command {
cmd := &serpent.Command{
Use: "aibridge",
Short: "Manage AIBridge.",
Handler: func(inv *serpent.Invocation) error {
return inv.Command.HelpHandler(inv)
},
Children: []*serpent.Command{
r.aibridgeInterceptions(),
},
}
return cmd
}

func (r *RootCmd) aibridgeInterceptions() *serpent.Command {
cmd := &serpent.Command{
Use: "interceptions",
Short: "Manage AIBridge interceptions.",
Handler: func(inv *serpent.Invocation) error {
return inv.Command.HelpHandler(inv)
},
Children: []*serpent.Command{
r.aibridgeInterceptionsList(),
},
}
return cmd
}

func (r *RootCmd) aibridgeInterceptionsList() *serpent.Command {
var (
initiator string
startedBeforeRaw string
startedAfterRaw string
provider string
model string
afterIDRaw string
limit int64
)

return &serpent.Command{
Use: "list",
Short: "List AIBridge interceptions as JSON.",
Options: serpent.OptionSet{
{
Flag: "initiator",
Description: `Only return interceptions initiated by this user. Accepts a user ID, username, or "me".`,
Default: "",
Value: serpent.StringOf(&initiator),
},
{
Flag: "started-before",
Description: fmt.Sprintf("Only return interceptions started before this time. Must be after 'started-after' if set. Accepts a time in the RFC 3339 format, e.g. %q.", time.RFC3339),
Default: "",
Value: serpent.StringOf(&startedBeforeRaw),
},
{
Flag: "started-after",
Description: fmt.Sprintf("Only return interceptions started after this time. Must be before 'started-before' if set. Accepts a time in the RFC 3339 format, e.g. %q.", time.RFC3339),
Default: "",
Value: serpent.StringOf(&startedAfterRaw),
},
{
Flag: "provider",
Description: `Only return interceptions from this provider.`,
Default: "",
Value: serpent.StringOf(&provider),
},
{
Flag: "model",
Description: `Only return interceptions from this model.`,
Default: "",
Value: serpent.StringOf(&model),
},
{
Flag: "after-id",
Description: "The ID of the last result on the previous page to use as a pagination cursor.",
Default: "",
Value: serpent.StringOf(&afterIDRaw),
},
{
Flag: "limit",
Description: fmt.Sprintf(`The limit of results to return. Must be between 1 and %d.`, maxInterceptionsLimit),
Default: "100",
Value: serpent.Int64Of(&limit),
},
},
Handler: func(inv *serpent.Invocation) error {
client, err := r.InitClient(inv)
if err != nil {
return err
}

startedBefore := time.Time{}
if startedBeforeRaw != "" {
startedBefore, err = time.Parse(time.RFC3339, startedBeforeRaw)
if err != nil {
return xerrors.Errorf("parse started before filter value %q: %w", startedBeforeRaw, err)
}
}

startedAfter := time.Time{}
if startedAfterRaw != "" {
startedAfter, err = time.Parse(time.RFC3339, startedAfterRaw)
if err != nil {
return xerrors.Errorf("parse started after filter value %q: %w", startedAfterRaw, err)
}
}

afterID := uuid.Nil
if afterIDRaw != "" {
afterID, err = uuid.Parse(afterIDRaw)
if err != nil {
return xerrors.Errorf("parse after_id filter value %q: %w", afterIDRaw, err)
}
}

if limit < 1 || limit > maxInterceptionsLimit {
return xerrors.Errorf("limit value must be between 1 and %d", maxInterceptionsLimit)
}

expCli := codersdk.NewExperimentalClient(client)
resp, err := expCli.AIBridgeListInterceptions(inv.Context(), codersdk.AIBridgeListInterceptionsFilter{
Pagination: codersdk.Pagination{
AfterID: afterID,
// #nosec G115 - Checked above.
Limit: int(limit),
},
Initiator: initiator,
StartedBefore: startedBefore,
StartedAfter: startedAfter,
Provider: provider,
Model: model,
})
if err != nil {
return xerrors.Errorf("list interceptions: %w", err)
}

// We currently only support JSON output, so we don't use a
// formatter.
enc := json.NewEncoder(inv.Stdout)
enc.SetIndent("", " ")
err = enc.Encode(resp.Results)
if err != nil {
return err
}

return err
},
}
}
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp