Class: Insika::Tools::CancelFollowup

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/insika/tools/schedule_followup.rb

Overview

cancel_followup — the sibling of schedule. Refuses a record that is already fired (":fired — it is in the air; it fires once"), refuses a record of another tenant (WS1), and is an idempotent no-op for an already-cancelled one.

Instance Method Summary collapse

Constructor Details

#initialize(followup_store:, state:) ⇒ CancelFollowup

Returns a new instance of CancelFollowup.



134
135
136
137
138
# File 'lib/insika/tools/schedule_followup.rb', line 134

def initialize(followup_store:, state:, **)
  @followup_store = followup_store
  @state = state
  super()
end

Instance Method Details

#execute(id:) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/insika/tools/schedule_followup.rb', line 140

def execute(id:)
  record = @followup_store.find(id.to_s)
  return { error: "no follow-up with id #{id}" } if record.nil?
  if record.status == "fired"
    return { error: "follow-up #{id} is already fired — it is in the air; it fires once" }
  end
  if record.status == "blocked"
    return { error: "follow-up #{id} is already blocked (#{record.blocked_reason})" }
  end

  tenant = (@state.respond_to?(:tenant) ? @state.tenant : nil).to_s
  unless record.tenant == (tenant.empty? ? "platform" : tenant)
    return { error: "follow-up #{id} belongs to another tenant" }
  end

  return { cancelled: record.id } if record.status == "cancelled" # idempotent

  @followup_store.cancel(id: record.id)
  { cancelled: record.id }
rescue Insika::ValidationError => e
  { error: e.message }
end

#nameObject



132
# File 'lib/insika/tools/schedule_followup.rb', line 132

def name = "cancel_followup"