From 5a3c15e9ba4809270f4ffd7c48badc7452532614 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 17 Dec 2025 19:13:29 +0530 Subject: [PATCH] fix: params[action] conflict --- .../dashboard/api/captain/editor.js | 12 +++---- .../v1/accounts/captain/editor_controller.rb | 2 +- lib/captain/rewrite_service.rb | 6 ++-- spec/lib/captain/rewrite_service_spec.rb | 32 +++++++++---------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/javascript/dashboard/api/captain/editor.js b/app/javascript/dashboard/api/captain/editor.js index 6066abcd6..9071ab4d1 100644 --- a/app/javascript/dashboard/api/captain/editor.js +++ b/app/javascript/dashboard/api/captain/editor.js @@ -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 } diff --git a/enterprise/app/controllers/api/v1/accounts/captain/editor_controller.rb b/enterprise/app/controllers/api/v1/accounts/captain/editor_controller.rb index 231f355de..ec245d97d 100644 --- a/enterprise/app/controllers/api/v1/accounts/captain/editor_controller.rb +++ b/enterprise/app/controllers/api/v1/accounts/captain/editor_controller.rb @@ -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 diff --git a/lib/captain/rewrite_service.rb b/lib/captain/rewrite_service.rb index ca2b8f2fb..257c49a47 100644 --- a/lib/captain/rewrite_service.rb +++ b/lib/captain/rewrite_service.rb @@ -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 diff --git a/spec/lib/captain/rewrite_service_spec.rb b/spec/lib/captain/rewrite_service_spec.rb index c62f7b491..f776118c8 100644 --- a/spec/lib/captain/rewrite_service_spec.rb +++ b/spec/lib/captain/rewrite_service_spec.rb @@ -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