fix: params[action] conflict

This commit is contained in:
Shivam Mishra
2025-12-17 19:13:29 +05:30
parent 0cf4ee1e2a
commit 5a3c15e9ba
4 changed files with 26 additions and 26 deletions
@@ -36,25 +36,25 @@ class EditorAPI extends ApiClient {
return this.labelSuggestion(conversationId, signal);
}
// All other types are rewrite actions
return this.rewrite({ content, action: type, conversationId }, signal);
// All other types are rewrite operations
return this.rewrite({ content, operation: type, conversationId }, signal);
}
/**
* Rewrites content with a specific action.
* Rewrites content with a specific operation.
* @param {Object} options - The rewrite options.
* @param {string} options.content - The content to rewrite.
* @param {string} options.action - The rewrite action (fix_spelling_grammar, casual, professional, etc).
* @param {string} options.operation - The rewrite operation (fix_spelling_grammar, casual, professional, etc).
* @param {string} [options.conversationId] - The conversation ID for context (required for 'improve').
* @param {AbortSignal} [signal] - AbortSignal to cancel the request.
* @returns {Promise} A promise that resolves with the rewritten content.
*/
rewrite({ content, action, conversationId }, signal) {
rewrite({ content, operation, conversationId }, signal) {
return axios.post(
`${this.url}/rewrite`,
{
content,
action,
operation,
conversation_display_id: conversationId,
},
{ signal }
@@ -5,7 +5,7 @@ class Api::V1::Accounts::Captain::EditorController < Api::V1::Accounts::BaseCont
result = Captain::RewriteService.new(
account: Current.account,
content: params[:content],
action: params[:action],
operation: params[:operation],
conversation_display_id: params[:conversation_display_id]
).perform
+3 -3
View File
@@ -1,8 +1,8 @@
class Captain::RewriteService < Captain::BaseEditorService
pattr_initialize [:account!, :content!, :action!, { conversation_display_id: nil }]
pattr_initialize [:account!, :content!, :operation!, { conversation_display_id: nil }]
def perform
send(action)
send(operation)
end
private
@@ -62,6 +62,6 @@ class Captain::RewriteService < Captain::BaseEditorService
end
def event_name
action
operation
end
end
+16 -16
View File
@@ -5,8 +5,8 @@ RSpec.describe Captain::RewriteService do
let(:inbox) { create(:inbox, account: account) }
let(:conversation) { create(:conversation, account: account, inbox: inbox) }
let(:content) { 'I need help with my order' }
let(:action) { 'fix_spelling_grammar' }
let(:service) { described_class.new(account: account, content: content, action: action, conversation_display_id: conversation.display_id) }
let(:operation) { 'fix_spelling_grammar' }
let(:service) { described_class.new(account: account, content: content, operation: operation, conversation_display_id: conversation.display_id) }
let(:mock_chat) { instance_double(RubyLLM::Chat) }
let(:mock_context) { instance_double(RubyLLM::Context, chat: mock_chat) }
let(:mock_response) { instance_double(RubyLLM::Message, content: 'Rewritten text', input_tokens: 10, output_tokens: 5) }
@@ -18,8 +18,8 @@ RSpec.describe Captain::RewriteService do
allow(mock_chat).to receive(:ask).and_return(mock_response)
end
describe '#perform with fix_spelling_grammar action' do
let(:action) { 'fix_spelling_grammar' }
describe '#perform with fix_spelling_grammar operation' do
let(:operation) { 'fix_spelling_grammar' }
it 'uses fix_spelling_grammar prompt' do
expect(service).to receive(:prompt_from_file).with('fix_spelling_grammar').and_return('Fix errors')
@@ -41,8 +41,8 @@ RSpec.describe Captain::RewriteService do
allow(service).to receive(:prompt_from_file).with('tone_rewrite').and_return(tone_prompt_template)
end
describe '#perform with casual action' do
let(:action) { 'casual' }
describe '#perform with casual operation' do
let(:operation) { 'casual' }
it 'uses casual tone' do
expect(service).to receive(:make_api_call) do |args|
@@ -54,8 +54,8 @@ RSpec.describe Captain::RewriteService do
end
end
describe '#perform with professional action' do
let(:action) { 'professional' }
describe '#perform with professional operation' do
let(:operation) { 'professional' }
it 'uses professional tone' do
expect(service).to receive(:make_api_call) do |args|
@@ -67,8 +67,8 @@ RSpec.describe Captain::RewriteService do
end
end
describe '#perform with friendly action' do
let(:action) { 'friendly' }
describe '#perform with friendly operation' do
let(:operation) { 'friendly' }
it 'uses friendly tone' do
expect(service).to receive(:make_api_call) do |args|
@@ -80,8 +80,8 @@ RSpec.describe Captain::RewriteService do
end
end
describe '#perform with confident action' do
let(:action) { 'confident' }
describe '#perform with confident operation' do
let(:operation) { 'confident' }
it 'uses confident tone' do
expect(service).to receive(:make_api_call) do |args|
@@ -93,8 +93,8 @@ RSpec.describe Captain::RewriteService do
end
end
describe '#perform with straightforward action' do
let(:action) { 'straightforward' }
describe '#perform with straightforward operation' do
let(:operation) { 'straightforward' }
it 'uses straightforward tone' do
expect(service).to receive(:make_api_call) do |args|
@@ -107,8 +107,8 @@ RSpec.describe Captain::RewriteService do
end
end
describe '#perform with improve action' do
let(:action) { 'improve' }
describe '#perform with improve operation' do
let(:operation) { 'improve' }
let(:improve_template) { 'Context: {{ conversation_context }}\nDraft: {{ draft_message }}' }
before do