feat: add feature key for preference lookup

This commit is contained in:
Shivam Mishra
2026-01-13 19:31:36 +05:30
parent ab1cb7af86
commit eee6ccc6f5
7 changed files with 55 additions and 0 deletions
+8
View File
@@ -25,6 +25,14 @@ class Captain::BaseTaskService
raise NotImplementedError, "#{self.class} must implement #event_name"
end
def feature_key
raise NotImplementedError, "#{self.class} must implement #feature_key"
end
def configured_model
account.public_send("captain_#{feature_key}_model")
end
def conversation
@conversation ||= account.conversations.find_by(display_id: conversation_display_id)
end
+4
View File
@@ -95,4 +95,8 @@ class Captain::FollowUpService < Captain::BaseTaskService
def event_name
'follow_up'
end
def feature_key
'editor'
end
end
+4
View File
@@ -87,6 +87,10 @@ class Captain::LabelSuggestionService < Captain::BaseTaskService
'label_suggestion'
end
def feature_key
'label_suggestion'
end
def build_follow_up_context?
false
end
+4
View File
@@ -15,4 +15,8 @@ class Captain::ReplySuggestionService < Captain::BaseTaskService
def event_name
'reply_suggestion'
end
def feature_key
'editor'
end
end
+4
View File
@@ -56,4 +56,8 @@ class Captain::RewriteService < Captain::BaseTaskService
def event_name
operation
end
def feature_key
'editor'
end
end
+4
View File
@@ -16,4 +16,8 @@ class Captain::SummaryService < Captain::BaseTaskService
def event_name
'summarize'
end
def feature_key
'editor'
end
end
@@ -15,6 +15,10 @@ RSpec.describe Captain::BaseTaskService do
def event_name
'test_event'
end
def feature_key
'editor'
end
end
end
@@ -46,6 +50,29 @@ RSpec.describe Captain::BaseTaskService do
end
end
describe '#feature_key' do
it 'raises NotImplementedError for base class' do
base_service = described_class.new(account: account, conversation_display_id: conversation.display_id)
expect { base_service.send(:feature_key) }.to raise_error(NotImplementedError, /must implement #feature_key/)
end
it 'returns custom feature key in subclass' do
expect(service.send(:feature_key)).to eq('editor')
end
end
describe '#configured_model' do
it 'returns the configured model for the feature_key' do
expect(account).to receive(:captain_editor_model).and_return('gpt-5.1')
expect(service.send(:configured_model)).to eq('gpt-5.1')
end
it 'uses the default model when account model is not set' do
allow(account).to receive(:captain_editor_model).and_return('gpt-4.1-mini')
expect(service.send(:configured_model)).to eq('gpt-4.1-mini')
end
end
describe '#conversation' do
it 'finds conversation by display_id' do
expect(service.send(:conversation)).to eq(conversation)