File size: 888 Bytes
097eaf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module Firecrawl
  module Models
    # Options for starting an agent task.
    class AgentOptions
      FIELDS = %i[
        urls prompt schema integration max_credits
        strict_constrain_to_urls model webhook
      ].freeze

      attr_reader(*FIELDS)

      def initialize(**kwargs)
        FIELDS.each { |f| instance_variable_set(:"@#{f}", kwargs[f]) }
        raise ArgumentError, "Agent prompt is required" if prompt.nil? || prompt.empty?
      end

      def to_h
        {
          "urls" => urls,
          "prompt" => prompt,
          "schema" => schema,
          "integration" => integration,
          "maxCredits" => max_credits,
          "strictConstrainToURLs" => strict_constrain_to_urls,
          "model" => model,
          "webhook" => webhook.is_a?(Hash) ? webhook : webhook&.to_h,
        }.compact
      end
    end
  end
end