| 61 | ) |
| 62 | |
| 63 | func NewDeps(client *codersdk.Client, opts ...func(*Deps)) (Deps, error) { |
| 64 | d := Deps{ |
| 65 | coderClient: client, |
| 66 | } |
| 67 | for _, opt := range opts { |
| 68 | opt(&d) |
| 69 | } |
| 70 | if d.agentConnFn == nil && d.coderClient != nil { |
| 71 | workspaceClient := workspacesdk.New(d.coderClient) |
| 72 | d.agentConnFn = func(ctx context.Context, agentID uuid.UUID) (workspacesdk.AgentConn, func(), error) { |
| 73 | conn, err := workspaceClient.DialAgent(ctx, agentID, nil) |
| 74 | if err != nil { |
| 75 | return nil, nil, err |
| 76 | } |
| 77 | return conn, nil, nil |
| 78 | } |
| 79 | } |
| 80 | // Allow nil client for unauthenticated operation |
| 81 | // This enables tools that don't require user authentication to function |
| 82 | return d, nil |
| 83 | } |
| 84 | |
| 85 | // Deps provides access to tool dependencies. |
| 86 | type Deps struct { |