feat: add scenarios model

This commit is contained in:
Shivam Mishra
2025-07-09 13:43:36 +05:30
parent 3e5ca9bca9
commit 96746cc592
5 changed files with 96 additions and 1 deletions
@@ -0,0 +1,18 @@
class CreateCaptainScenarios < ActiveRecord::Migration[7.1]
def change
create_table :captain_scenarios do |t|
t.string :title
t.text :description
t.text :instruction
t.jsonb :tools
t.boolean :enabled, default: true, null: false
t.references :assistant, null: false, foreign_key: { to_table: :captain_assistants }
t.references :account, null: false
t.timestamps
end
add_index :captain_scenarios, :enabled
add_index :captain_scenarios, [:assistant_id, :enabled]
end
end
+18 -1
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2025_06_27_195529) do
ActiveRecord::Schema[7.1].define(version: 2025_07_09_075622) do
# These extensions should be enabled to support this database
enable_extension "pg_stat_statements"
enable_extension "pg_trgm"
@@ -305,6 +305,22 @@ ActiveRecord::Schema[7.1].define(version: 2025_06_27_195529) do
t.index ["inbox_id"], name: "index_captain_inboxes_on_inbox_id"
end
create_table "captain_scenarios", force: :cascade do |t|
t.string "title"
t.text "description"
t.text "instruction"
t.jsonb "tools"
t.boolean "enabled", default: true, null: false
t.bigint "assistant_id", null: false
t.bigint "account_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["account_id"], name: "index_captain_scenarios_on_account_id"
t.index ["assistant_id", "enabled"], name: "index_captain_scenarios_on_assistant_id_and_enabled"
t.index ["assistant_id"], name: "index_captain_scenarios_on_assistant_id"
t.index ["enabled"], name: "index_captain_scenarios_on_enabled"
end
create_table "categories", force: :cascade do |t|
t.integer "account_id", null: false
t.integer "portal_id", null: false
@@ -1114,6 +1130,7 @@ ActiveRecord::Schema[7.1].define(version: 2025_06_27_195529) do
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "captain_scenarios", "captain_assistants", column: "assistant_id"
add_foreign_key "inboxes", "portals"
create_trigger("accounts_after_insert_row_tr", :generated => true, :compatibility => 1).
on("accounts").
@@ -30,6 +30,7 @@ class Captain::Assistant < ApplicationRecord
through: :captain_inboxes
has_many :messages, as: :sender, dependent: :nullify
has_many :copilot_threads, dependent: :destroy_async
has_many :scenarios, class_name: 'Captain::Scenario', dependent: :destroy_async
validates :name, presence: true
validates :description, presence: true
+48
View File
@@ -0,0 +1,48 @@
# == Schema Information
#
# Table name: captain_scenarios
#
# id :bigint not null, primary key
# description :text
# enabled :boolean default(TRUE), not null
# instruction :text
# title :string
# tools :jsonb
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
# assistant_id :bigint not null
#
# Indexes
#
# index_captain_scenarios_on_account_id (account_id)
# index_captain_scenarios_on_assistant_id (assistant_id)
# index_captain_scenarios_on_assistant_id_and_enabled (assistant_id,enabled)
# index_captain_scenarios_on_enabled (enabled)
#
# Foreign Keys
#
# fk_rails_... (assistant_id => captain_assistants.id)
#
class Captain::Scenario < ApplicationRecord
self.table_name = 'captain_scenarios'
belongs_to :assistant, class_name: 'Captain::Assistant'
belongs_to :account
validates :title, presence: true
validates :description, presence: true
validates :instruction, presence: true
validates :assistant_id, presence: true
validates :account_id, presence: true
scope :enabled, -> { where(enabled: true) }
before_save :populate_tools
private
def populate_tools
# TODO: Implement tools population logic
end
end
+11
View File
@@ -0,0 +1,11 @@
FactoryBot.define do
factory :captain_scenario, class: 'Captain::Scenario' do
sequence(:title) { |n| "Scenario #{n}" }
description { 'Test scenario description' }
instruction { 'Test scenario instruction for the assistant to follow' }
tools { nil }
enabled { true }
association :assistant, factory: :captain_assistant
association :account
end
end