Class: Tidewave::Tools::CreateDesignCanvas

Inherits:
Tidewave::Tool show all
Defined in:
lib/tidewave/tools/create_design_canvas.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

DESCRIPTION =
<<~DESCRIPTION.freeze
  Creates a new design canvas, an HTML file for presenting design explorations.

  The tool returns the absolute path of the HTML file. The file includes usage
  instructions, read it, then edit it to author the actual design.
DESCRIPTION
FETCH_TIMEOUT_SECONDS =
15

Instance Method Summary collapse

Methods inherited from Tidewave::Tool

descendants, inherited, #validate_and_call

Constructor Details

#initialize(options = {}) ⇒ CreateDesignCanvas

Returns a new instance of CreateDesignCanvas.



21
22
23
24
# File 'lib/tidewave/tools/create_design_canvas.rb', line 21

def initialize(options = {})
  super
  @client_url = options[:client_url]
end

Instance Method Details

#browser_tool?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/tidewave/tools/create_design_canvas.rb', line 26

def browser_tool?
  true
end

#call(arguments) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tidewave/tools/create_design_canvas.rb', line 48

def call(arguments)
  path = arguments.fetch("path")

  unless Pathname.new(path).absolute? && path.end_with?(".html")
    return error_result("Invalid path #{path.inspect}. It must be an absolute path with the .html file extension.")
  end

  html = fetch_canvas_html
  write_canvas(path, html)

  "Design canvas created at: <path>#{path}</path>. Read the file for usage instructions."
rescue Error => error
  error_result(error.message)
end

#definitionObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tidewave/tools/create_design_canvas.rb', line 30

def definition
  {
    "name" => "create_design_canvas",
    "description" => DESCRIPTION,
    "inputSchema" => {
      "type" => "object",
      "properties" => {
        "path" => {
          "type" => "string",
          "description" =>
            "The absolute path for the canvas file, with .html file extension. The file must not exist yet."
        }
      },
      "required" => [ "path" ]
    }
  }
end