Class: Pi::Browser::Taskbar::Rails::Task
- Inherits:
-
Object
- Object
- Pi::Browser::Taskbar::Rails::Task
- Defined in:
- lib/pi/browser/taskbar/rails/task.rb
Defined Under Namespace
Classes: Invalid
Constant Summary collapse
- MAX_REQUEST_BYTES =
128 * 1024
- MAX_CONTEXT_BYTES =
96 * 1024
- MAX_SNAPSHOT_BYTES =
48 * 1024
- MAX_FOCUS_BYTES =
48 * 1024
- MAX_SNAPSHOT_NODES =
750- FIELDS =
%w[context prompt].freeze
- CONTEXT_FIELDS =
%w[contract_version focus_points location route snapshot truncation].freeze
- NODE_FIELDS =
%w[attributes children classes href id name role source src state tag text].freeze
- ATTRIBUTE_FIELDS =
%w[data-testid name placeholder type].freeze
- STATE_FIELDS =
%w[checked disabled expanded invalid pressed required selected].freeze
- SOURCE_STATUSES =
%w[available ambiguous external unavailable].freeze
- SOURCE_ROLES =
%w[template definition caller].freeze
- SOURCE_PRECISIONS =
%w[line template].freeze
- TRUNCATION_REASONS =
%w[bytes nodes depth string].freeze
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value) ⇒ Task
constructor
A new instance of Task.
- #pi_prompt ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(value) ⇒ Task
Returns a new instance of Task.
36 37 38 |
# File 'lib/pi/browser/taskbar/rails/task.rb', line 36 def initialize(value) @value = value end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
30 31 32 |
# File 'lib/pi/browser/taskbar/rails/task.rb', line 30 def context @context end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
30 31 32 |
# File 'lib/pi/browser/taskbar/rails/task.rb', line 30 def prompt @prompt end |
Class Method Details
.parse(value) ⇒ Object
32 33 34 |
# File 'lib/pi/browser/taskbar/rails/task.rb', line 32 def self.parse(value) new(value).tap(&:validate!) end |
Instance Method Details
#pi_prompt ⇒ Object
52 53 54 |
# File 'lib/pi/browser/taskbar/rails/task.rb', line 52 def pi_prompt "#{prompt}\n\n--- BEGIN UNTRUSTED BROWSER CONTEXT ---\n#{safe_json(context)}\n--- END UNTRUSTED BROWSER CONTEXT ---" end |
#validate! ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pi/browser/taskbar/rails/task.rb', line 40 def validate! object!(@value, "task") size!(@value, MAX_REQUEST_BYTES, "request is too large") exact!(@value, FIELDS, "task") @prompt = normalize_prompt(@value["prompt"]) @context = normalize_context(@value["context"]) validate_context! self rescue EncodingError, JSON::GeneratorError invalid!("task contains invalid UTF-8") end |