# frozen_string_literal: true
module DiscourseAi
module Personas
module Tools
class CreateArtifact < Tool
def self.name
"create_artifact"
end
def self.specification_description
<<~DESC
A detailed description of the web artifact you want to create. Your specification should include:
1. Purpose and functionality
2. Visual design requirements
3. Interactive elements and behavior
4. Data handling (if applicable)
5. Specific requirements or constraints
6. DO NOT include full source code of the artifact, just very clear requirements
Good specification examples:
Example: (Calculator):
"Create a modern calculator with a dark theme. It should:
- Have a large display area showing current and previous calculations
- Include buttons for numbers 0-9, basic operations (+,-,*,/), and clear
- Use a grid layout with subtle hover effects on buttons
- Show button press animations
- Keep calculation history visible above current input
- Use a monospace font for numbers
- Support keyboard input for numbers and operations"
Poor specification example:
"Make a website that looks nice and does cool stuff"
(Too vague, lacks specific requirements and functionality details)
Tips for good specifications:
- Be specific about layout and design preferences
- Describe all interactive elements and their behavior
- Include any specific visual effects or animations
- Mention responsive design requirements if needed
- List any specific libraries or frameworks to use/avoid
- Describe error states and edge cases
- Include accessibility requirements
- Include code snippets to help ground the specification
DESC
end
def self.signature
{
name: "create_artifact",
description: "Creates a web artifact based on a specification",
parameters: [
{
name: "name",
description: "A name for the artifact (max 255 chars)",
type: "string",
required: true,
},
{
name: "specification",
type: "string",
description: specification_description,
required: true,
},
],
}
end
def self.accepted_options
[option(:creator_llm, type: :llm)]
end
def self.allow_partial_tool_calls?
true
end
def partial_invoke
if parameters[:specification].present?
in_progress(specification: parameters[:specification])
end
end
def in_progress(specification:, source: nil)
source = (<<~HTML) if source.present?
### Source
````
#{source}
````
HTML
self.custom_raw = <<~HTML
Thinking...
### Specification
````
#{specification}
````
#{source}